Index: /tests/modal/modal.cpp
===================================================================
--- /tests/modal/modal.cpp	(revision 938)
+++ /tests/modal/modal.cpp	(revision 939)
@@ -8,15 +8,33 @@
 public:
 
-    MyMainWidget() : mTestNo (0), mCurWidget (0)
-    {
-        mTestNo = 4;
-
-        setWindowTitle ("Primary");
-
-        mPB = new QPushButton ("Next Test", this);
-        connect (mPB, SIGNAL (clicked()), this, SLOT (nextTest()));
+    MyMainWidget (QWidget *aParent = 0, Qt::WindowFlags aFlags = 0)
+        : QWidget (aParent, aFlags)
+    {
+        setWindowTitle (QString ("MyMainWidget (0x%1)")
+                        .arg ((intptr_t) this, 8, 16, QChar('0')));
+
+        QHBoxLayout *pbLayout = new QHBoxLayout();
+
+        for (int i = 1; i <= 10; ++ i)
+        {
+            QPushButton *pb = new QPushButton (QString::number (i), this);
+            connect (pb, SIGNAL (clicked()), this, SLOT (nextTest()));
+            pbLayout->addWidget (pb);
+        }
+
+        mPBClone = new QPushButton ("Clone", this);
+        connect (mPBClone, SIGNAL (clicked()), this, SLOT (clone()));
+
+        mPBCloneModal = new QPushButton ("Modal Clone", this);
+        connect (mPBCloneModal, SIGNAL (clicked()), this, SLOT (cloneModal()));
+
+        mPBCloneAppModal = new QPushButton ("App Modal Clone", this);
+        connect (mPBCloneAppModal, SIGNAL (clicked()), this, SLOT (cloneAppModal()));
 
         QVBoxLayout *layout = new QVBoxLayout();
-        layout->addWidget (mPB);
+        layout->addLayout (pbLayout);
+        layout->addWidget (mPBClone);
+        layout->addWidget (mPBCloneModal);
+        layout->addWidget (mPBCloneAppModal);
         setLayout (layout);
     }
@@ -24,50 +42,47 @@
     virtual ~MyMainWidget()
     {
-        delete mCurWidget;
-    }
-
-    void test (QWidget *w, const QString &text)
-    {
-        w->setWindowTitle ("Secondary");
+    }
+
+    void test (int aNum, QWidget *aWgt, const QString &aText)
+    {
+        aWgt->setAttribute (Qt::WA_DeleteOnClose);
+
+        aWgt->setWindowTitle (QString ("[%1] %2 (0x%3)")
+                              .arg (aNum)
+                              .arg (aWgt->metaObject()->className())
+                              .arg ((intptr_t) aWgt, 8, 16, QChar('0')));
 
         QString newText = QString (
-                    "%1\n\n"
-                    "parentWidget() is %2\n"
-                    "className() is %3\n"
-                    "isWindow() is %4\n"
-                    "windowFlags() is 0x%5\n"
-                    "windowModality() is %6")
-                .arg (text)
-                .arg (w->parentWidget() ? w->parentWidget()->metaObject()
-                                          ->className()
-                                       : "<none>")
-                .arg (w->metaObject()->className())
-                .arg (w->isWindow())
-                .arg (w->windowFlags(), 8, 16, QLatin1Char ('0'))
-                .arg (w->windowModality());
-
-        if (w->inherits ("QMessageBox"))
-        {
-            static_cast <QMessageBox *> (w)->setText (newText);
+                    "[%1] %2\n\n"
+                    "parentWidget() is %3\n"
+                    "className() is %4\n"
+                    "isWindow() is %5\n"
+                    "windowFlags() is 0x%6\n"
+                    "windowModality() is %7")
+                .arg (aNum)
+                .arg (aText)
+                .arg (aWgt->parentWidget() ? aWgt->parentWidget()->metaObject()
+                                             ->className()
+                                           : "<none>")
+                .arg (aWgt->metaObject()->className())
+                .arg (aWgt->isWindow())
+                .arg (aWgt->windowFlags(), 8, 16, QLatin1Char ('0'))
+                .arg (aWgt->windowModality());
+
+        if (aWgt->inherits ("QMessageBox"))
+        {
+            static_cast <QMessageBox *> (aWgt)->setText (newText);
         }
         else
         {
-            QLabel *label = new QLabel (w);
+            QLabel *label = new QLabel (aWgt);
             label->setText (newText);
 
             QVBoxLayout *layout = new QVBoxLayout();
             layout->addWidget (label);
-            w->setLayout (layout);
-        }
-
-        w->show();
-
-        if (mCurWidget)
-        {
-            mCurWidget->close();
-            delete mCurWidget;
-        }
-
-        mCurWidget = w;
+            aWgt->setLayout (layout);
+        }
+
+        aWgt->show();
     }
 
@@ -76,10 +91,11 @@
     void nextTest()
     {
-        switch (mTestNo)
-        {
-        case 0:
+        int num = static_cast <QPushButton *> (sender())->text().toInt();
+        switch (num)
+        {
+        case 1:
         {
             QWidget *w = new QWidget();
-            test (w,
+            test (num, w,
                   "QWidget().\n"
                   "Should have a taskbar entry.\n"
@@ -88,8 +104,8 @@
             break;
         }
-        case 1:
+        case 2:
         {
             QWidget *w = new QWidget (this, Qt::Window);
-            test (w,
+            test (num, w,
                   "QWidget (this, Qt::Window).\n"
                   "Should not have a taskbar entry.\n"
@@ -98,8 +114,8 @@
             break;
         }
-        case 2:
+        case 3:
         {
             QWidget *w = new QDialog();
-            test (w,
+            test (num, w,
                   "QDialog().\n"
                   "Should have a taskbar entry.\n"
@@ -108,8 +124,8 @@
             break;
         }
-        case 3:
+        case 4:
         {
             QWidget *w = new QDialog (this);
-            test (w,
+            test (num, w,
                   "QDialog(this).\n"
                   "Should not have a taskbar entry.\n"
@@ -118,8 +134,8 @@
             break;
         }
-        case 4:
+        case 5:
         {
             QWidget *w = new QMessageBox();
-            test (w,
+            test (num, w,
                   "QMessageBox().\n"
                   "Should have a taskbar entry.\n"
@@ -128,8 +144,8 @@
             break;
         }
-        case 5:
+        case 6:
         {
             QWidget *w = new QMessageBox (this);
-            test (w,
+            test (num, w,
                   "QMessageBox (this).\n"
                   "Should not have a taskbar entry.\n"
@@ -138,9 +154,9 @@
             break;
         }
-        case 6:
+        case 7:
         {
             QWidget *w = new QWidget();
             w->setWindowModality (Qt::WindowModal);
-            test (w,
+            test (num, w,
                   "QWidget() - WindowModal.\n"
                   "Should have a taskbar entry.\n"
@@ -149,9 +165,9 @@
             break;
         }
-        case 7:
+        case 8:
         {
             QWidget *w = new QWidget (this, Qt::Window);
             w->setWindowModality (Qt::WindowModal);
-            test (w,
+            test (num, w,
                   "QWidget (this, Qt::Window) - WindowModal.\n"
                   "Should not have a taskbar entry.\n"
@@ -160,9 +176,9 @@
             break;
         }
-        case 8:
+        case 9:
         {
             QWidget *w = new QWidget(0, Qt::Dialog);
             w->setWindowModality (Qt::ApplicationModal);
-            test (w,
+            test (num, w,
                   "QWidget() - ApplicationModal.\n"
                   "Should have a taskbar entry.\n"
@@ -171,9 +187,9 @@
             break;
         }
-        case 9:
+        case 10:
         {
             QWidget *w = new QWidget (this, Qt::Window);
             w->setWindowModality (Qt::ApplicationModal);
-            test (w,
+            test (num, w,
                   "QWidget (this, Qt::Window) - ApplicationModal.\n"
                   "Should not have a taskbar entry.\n"
@@ -183,17 +199,38 @@
         }
         default:
-            mPB->setText ("No More Tests");
-            mPB->setEnabled (false);
             return;
         }
-
-        ++ mTestNo;
+    }
+
+    void clone()
+    {
+        QWidget *w = new MyMainWidget ();
+        w->setAttribute (Qt::WA_DeleteOnClose);
+        w->show();
+    }
+
+    void cloneModal()
+    {
+        QWidget *w = new MyMainWidget (this, Qt::Window);
+        w->setAttribute (Qt::WA_DeleteOnClose);
+        w->setWindowModality (Qt::WindowModal);
+        w->setWindowTitle (QString("[M] ") + w->windowTitle());
+        w->show();
+    }
+
+    void cloneAppModal()
+    {
+        QWidget *w = new MyMainWidget();
+        w->setAttribute (Qt::WA_DeleteOnClose);
+        w->setWindowModality (Qt::ApplicationModal);
+        w->setWindowTitle (QString("[AM] ") + w->windowTitle());
+        w->show();
     }
 
 private:
 
-    int mTestNo;
-    QPushButton *mPB;
-    QWidget *mCurWidget;
+    QPushButton *mPBClone;
+    QPushButton *mPBCloneModal;
+    QPushButton *mPBCloneAppModal;
 };
 
@@ -203,7 +240,6 @@
     app.setQuitOnLastWindowClosed (true);
 
-    MyMainWidget mainWidget;
-    mainWidget.resize (100, 100);
-    mainWidget.show();
+    MyMainWidget *mainWidget = new MyMainWidget();
+    mainWidget->show();
 
     return app.exec();
