[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdeui
From:       David Faure <faure () kde ! org>
Date:       2010-12-09 23:57:00
Message-ID: 20101209235700.C9E8DAC8A6 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1205005 by dfaure:

Fix assert when setting a default button that doesn't exist yet (e.g. in the old ksnapshot code).
Solution: KDialog should remember and make the button default once it exists. With unittest.


 M  +11 -1     dialogs/kdialog.cpp  
 M  +2 -0      dialogs/kdialog_p.h  
 M  +16 -0     tests/kdialog_unittest.cpp  


--- trunk/KDE/kdelibs/kdeui/dialogs/kdialog.cpp #1205004:1205005
@@ -110,6 +110,8 @@
 
 void KDialogPrivate::appendButton(KDialog::ButtonCode key, const KGuiItem &item)
 {
+    Q_Q(KDialog);
+
   QDialogButtonBox::ButtonRole role = QDialogButtonBox::InvalidRole;
   switch ( key ) {
     case KDialog::Help:
@@ -158,7 +160,12 @@
 
     QObject::connect(button, SIGNAL(clicked()),
            &mButtonSignalMapper, SLOT( map() ) );
+
+    if (key == mDefaultButton) {
+        // Now that it exists, set it as default
+        q->setDefaultButton(mDefaultButton);
 }
+}
 
 void KDialogPrivate::init(KDialog *q)
 {
@@ -279,6 +286,8 @@
 
 void KDialog::setDefaultButton( ButtonCode newDefaultButton )
 {
+    Q_D(KDialog);
+
     if (newDefaultButton == None)
         newDefaultButton = NoDefault; // #148969
 
@@ -308,6 +317,7 @@
             }
         }
     }
+    d->mDefaultButton = newDefaultButton;
     Q_ASSERT(defaultButton() == newDefaultButton);
 }
 
@@ -322,7 +332,7 @@
     }
   }
 
-  return NoDefault;
+    return d->mDefaultButton;
 }
 
 void KDialog::setMainWidget( QWidget *widget )
--- trunk/KDE/kdelibs/kdeui/dialogs/kdialog_p.h #1205004:1205005
@@ -41,6 +41,7 @@
             mDetailsWidget(0),
             mTopLayout(0), mMainWidget(0), mUrlHelp(0), mActionSeparator(0),
             mButtonOrientation(Qt::Horizontal),
+            mDefaultButton(KDialog::NoDefault),
             mButtonBox(0)
         {
         }
@@ -72,6 +73,7 @@
         QString mHelpLinkText;
 
         Qt::Orientation mButtonOrientation;
+        KDialog::ButtonCode mDefaultButton;
         KDialog::ButtonCode mEscapeButton;
 
         QDialogButtonBox *mButtonBox;
--- trunk/KDE/kdelibs/kdeui/tests/kdialog_unittest.cpp #1205004:1205005
@@ -77,6 +77,22 @@
         checkOtherButtonsAreNotDefault(dialog, KDialog::None);
     }
 
+    void testFutureDefaultButton()
+    {
+        // Test setting a default button that doesn't exist yet
+        KDialog dialog;
+        KDialog::ButtonCode id = KDialog::Apply;
+        dialog.setDefaultButton(id);
+        QCOMPARE(dialog.defaultButton(), id);
+        QCOMPARE(dialog.button(id), static_cast<KPushButton *>(0));
+
+        dialog.setButtons(KDialog::Ok | KDialog::Apply
+            | KDialog::Cancel | KDialog::No | KDialog::Yes);
+        QCOMPARE(dialog.defaultButton(), KDialog::Apply);
+        QVERIFY(dialog.button(id)->isDefault());
+        QVERIFY(!dialog.button(KDialog::Ok)->isDefault());
+    }
+
     // Test what happens with giving focus to widgets before the window is shown
     // This is mostly Qt experimentation, unrelated to KDialog's own code
     void testFocus()
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic