Browse Source

ctkMessageBox::setDontShowAgainSettingsKey() turns visibility on

When the key is set, it's most likely that the checkbox should be visible.
This simplifies the setup of ctkMessageBox.
If the default behavior is unwanted, it's still possible to set the
 visibility back after setting the key.

The order of properties is changed, just in case ctkMessageBox is configured
using Qt Designer, it would set the properties in the same order.
Changing the DontShowAgainSettingsKey property should be done first, so that
DontShowAgainVisible can then override the default behavior.
Julien Finet 13 years ago
parent
commit
ab8a4b3003

+ 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.