Browse Source

Merge branch 'ctkMessageBox_settingKey_shows_checkbox'

* ctkMessageBox_settingKey_shows_checkbox:
  ctkMessageBox::setDontShowAgainSettingsKey() turns visibility on
Julien Finet 13 years ago
parent
commit
03fac4cd93

+ 17 - 0
Libs/Widgets/Testing/Cpp/ctkMessageBoxDontShowAgainTest.cpp

@@ -80,6 +80,9 @@ private Q_SLOTS:
   // static utility function
   void testConfirmExit();
   void testConfirmExit_data();
+
+  // test the visibility cases();
+  void testVisible();
   //void testCustomButton();
 };
 
@@ -508,6 +511,20 @@ void ctkMessageBoxDontShowAgainTester::testConfirmExit_data()
   QTest::newRow("DontShowWithRejectRole") << "DontShowWithRejectRole" << false;
 }
 
+
+// ----------------------------------------------------------------------------
+void ctkMessageBoxDontShowAgainTester::testVisible()
+{
+  ctkMessageBox messageBox;
+  QCOMPARE(messageBox.isDontShowAgainVisible(), false);
+
+  messageBox.setDontShowAgainSettingsKey("Non Empty key");
+  QCOMPARE(messageBox.isDontShowAgainVisible(), true);
+
+  messageBox.setDontShowAgainSettingsKey(QString());
+  QCOMPARE(messageBox.isDontShowAgainVisible(), false);
+}
+
 // ----------------------------------------------------------------------------
 CTK_TEST_MAIN(ctkMessageBoxDontShowAgainTest)
 #include "moc_ctkMessageBoxDontShowAgainTest.cpp"

+ 1 - 1
Libs/Widgets/ctkMessageBox.cpp

@@ -220,6 +220,7 @@ void ctkMessageBox::setDontShowAgainSettingsKey(const QString& key)
     }
   d->DontShowAgainSettingsKey = key;
   d->readSettings();
+  this->setDontShowAgainVisible(!key.isEmpty());
 }
 
 //-----------------------------------------------------------------------------
@@ -290,7 +291,6 @@ bool ctkMessageBox
   dialog.setText(tr("Are you sure you want to exit?"));
   dialog.setIcon(QMessageBox::Question);
   dialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
-  dialog.setDontShowAgainVisible(!dontShowAgainKey.isEmpty());
   dialog.setDontShowAgainSettingsKey(dontShowAgainKey);
   return dialog.exec() == QMessageBox::Ok;
 }

+ 11 - 9
Libs/Widgets/ctkMessageBox.h

@@ -35,12 +35,6 @@ class ctkMessageBoxPrivate;
 class CTK_WIDGETS_EXPORT ctkMessageBox : public QMessageBox
 {
   Q_OBJECT
-  /// This property controls the visibility of the "Don't show again" checkbox.
-  /// Even if the checkbox is not visible, the dialog is not not shown if
-  /// \a dontShowAgain is true.
-  /// By default, the "Don't show again" checkbox is not visible.
-  Q_PROPERTY(bool dontShowAgainVisible READ isDontShowAgainVisible WRITE setDontShowAgainVisible)
-
   /// This property holds wether the dialog should be shown next time exec()
   /// is called.
   /// \a dontShowAgain can be changed programatically by calling
@@ -59,9 +53,17 @@ class CTK_WIDGETS_EXPORT ctkMessageBox : public QMessageBox
   /// QMessageBox::InvalidRole, the dialog is shown, otherwise it is skipped by
   /// simulating a click on the button corresponding to the settings value (QMessageButton::StandardButton or
   /// QMessageBox::ButtonRole)
+  /// If a non empty key is set, the check box gets visible, otherwise it is
+  /// hidden.
   /// By default, no key is set.
   Q_PROPERTY(QString dontShowAgainSettingsKey READ dontShowAgainSettingsKey WRITE setDontShowAgainSettingsKey)
 
+  /// This property controls the visibility of the "Don't show again" checkbox.
+  /// Even if the checkbox is not visible, the dialog is not not shown if
+  /// \a dontShowAgain is true.
+  /// By default, the "Don't show again" checkbox is not visible.
+  Q_PROPERTY(bool dontShowAgainVisible READ isDontShowAgainVisible WRITE setDontShowAgainVisible)
+
 public:
   typedef QMessageBox Superclass;
   ctkMessageBox(QWidget* newParent = 0);
@@ -69,14 +71,14 @@ public:
                 QWidget * parent = 0, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint );
   virtual ~ctkMessageBox();
 
-  void setDontShowAgainVisible(bool visible);
-  bool isDontShowAgainVisible()const;
-
   bool dontShowAgain()const;
 
   void setDontShowAgainSettingsKey(const QString& key);
   QString dontShowAgainSettingsKey()const;
 
+  void setDontShowAgainVisible(bool visible);
+  bool isDontShowAgainVisible()const;
+
   /// Utility function that opens a dialog to confirm exit.
   /// If \a dontShowAgainKey is empty, the dontShowAgain checkbox is hidden
   /// and the message box is always open for the user to confirm exit.