Salome HOME
Issue #1525: Disable Ok button if parameters are not valid
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 1 Jun 2016 12:13:31 +0000 (15:13 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 1 Jun 2016 12:13:50 +0000 (15:13 +0300)
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_Dialog.cpp
src/ModuleBase/ModuleBase_Dialog.h
src/ModuleBase/ModuleBase_ModelDialogWidget.h [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h

index 0e3066310eb0dfed016bb8e6c189c0f433a0f0e8..c4fc1a27659b647728e65899f565f8190490cc83 100644 (file)
@@ -62,6 +62,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetValidator.h
   ModuleBase_IconFactory.h
   ModuleBase_Dialog.h
+  ModuleBase_ModelDialogWidget.h
 )
 
 SET(PROJECT_SOURCES
index 5a3db14f8de4ed5a978b3d865051f8f1d7b2f8bb..1e148ac72aaad07adc83eef581fd75d43dbe77cc 100644 (file)
@@ -6,6 +6,7 @@
 #include "ModuleBase_IWorkshop.h"
 #include "ModuleBase_IPropertyPanel.h"
 #include "ModuleBase_PageWidget.h"
+#include "ModuleBase_ModelDialogWidget.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Events.h>
@@ -52,9 +53,6 @@ ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QStr
 
   aFactory.createWidget(aPage, false);
   myWidgets = aFactory.getModelWidgets();
-  foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
-    initializeWidget(aWidget);
-  }
 
   QFrame* aFrame = new QFrame(this);
   aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
@@ -63,19 +61,27 @@ ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QStr
   QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
   ModuleBase_Tools::adjustMargins(aBtnLayout);
 
-  QDialogButtonBox* aBtnBox = new QDialogButtonBox(
+  myButtonsBox = new QDialogButtonBox(
     QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
-  aBtnLayout->addWidget(aBtnBox);
+  aBtnLayout->addWidget(myButtonsBox);
+
+  myButtonsBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
+  myButtonsBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
 
-  aBtnBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
-  aBtnBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
+  connect(myButtonsBox, SIGNAL(accepted()), this, SLOT(accept()));
+  connect(myButtonsBox, SIGNAL(rejected()), this, SLOT(reject()));
 
-  connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
-  connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
+  foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
+    initializeWidget(aWidget);
+  }
 }
 
 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
 {
+  ModuleBase_ModelDialogWidget* aDlgWgt = dynamic_cast<ModuleBase_ModelDialogWidget*>(theWidget);
+  if (aDlgWgt)
+    aDlgWgt->setDialogButtons(myButtonsBox);
+
   theWidget->setFeature(myFeature);
   theWidget->restoreValue();
 }
index bb58343f6b9fcb054810d7c54f189a6ec99526fc..6112c407a84d88ef6ff5612fc6a332208380f0e4 100644 (file)
@@ -12,6 +12,8 @@
 
 class ModuleBase_IWorkshop;
 class ModuleBase_ModelWidget;
+class QDialogButtonBox;
+
 
 /**
  * \ingroup GUI
@@ -35,7 +37,6 @@ protected:
   /// Redefinition of virtual method
   virtual void showEvent(QShowEvent* theEvent);
 
-
 private:
   /// Initialising of the widget
   void initializeWidget(ModuleBase_ModelWidget* theWidget);
@@ -57,6 +58,9 @@ private:
 
   /// Pointer on active widget
   ModuleBase_ModelWidget* myActiveWidget;
+
+  /// Buttons of the dialog
+  QDialogButtonBox* myButtonsBox;
 };
 
 #endif
diff --git a/src/ModuleBase/ModuleBase_ModelDialogWidget.h b/src/ModuleBase/ModuleBase_ModelDialogWidget.h
new file mode 100644 (file)
index 0000000..82a3a35
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_ModelDialogWidget.h
+// Created:     01 June 2016
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef MODULEBASE_MODELDIALOGWIDGET_H
+#define MODULEBASE_MODELDIALOGWIDGET_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class QDialogButtonBox;
+
+class MODULEBASE_EXPORT ModuleBase_ModelDialogWidget : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuration. The attribute of the model widget is obtained from
+  /// a low-level API for reading xml definitions of widgets
+  ModuleBase_ModelDialogWidget(QWidget* theParent, const Config_WidgetAPI* theData) :
+                                ModuleBase_ModelWidget(theParent, theData) {}
+
+  /// Set general buttons from dialog
+  /// \param theButtons the dialog buttons
+  void setDialogButtons(QDialogButtonBox* theButtons) { myOkCancelBtn = theButtons; }
+
+protected:
+
+  /// Contains dialog buttons to enable/disable Ok and Cancel buttons
+  QDialogButtonBox* myOkCancelBtn;
+};
+
+#endif
\ No newline at end of file
index eee61404336a233dc84e47cfb984ba6dedb6e019..35df874aa38e0c19babc2394b6a69b2e2c839578 100644 (file)
@@ -30,6 +30,7 @@
 #include <QTimer>
 #include <QEvent>
 #include <QKeyEvent>
+#include <QDialogButtonBox>
 
 enum ColumnType {
   Col_Name,
@@ -155,7 +156,7 @@ void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, QAbstractItemD
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
 ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData)
-  : ModuleBase_ModelWidget(theParent, theData)
+  : ModuleBase_ModelDialogWidget(theParent, theData)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
 
@@ -304,7 +305,7 @@ void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
 void ParametersPlugin_WidgetParamsMgr::updateParametersPart()
 {
   updateItem(myParameters, parametersItems(myParametersList));
-  bool aIsValid = checkIsValid();
+  bool aIsValid = isValid();
   enableButtons(aIsValid);
 }
 
@@ -698,13 +699,16 @@ bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
 void ParametersPlugin_WidgetParamsMgr::sendWarning()
 {
   QMessageBox::warning(this, tr("Warning"), myMessage);
+  QTreeWidgetItem* aItem = myTable->currentItem();
+  if (aItem)
+    myTable->editItem(aItem);
 }
 
 void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
 {
   QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
-  bool isValid = checkIsValid();
-  if (isValid) {
+  bool aIsValid = isValid();
+  if (aIsValid) {
     bool isParameter = false;
     foreach(QTreeWidgetItem* aItem, aItemsList) {
       if (aItem->parent() == myParameters) {
@@ -736,9 +740,10 @@ void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
     myUpBtn->setEnabled(theEnable);
     myDownBtn->setEnabled(theEnable);
   }
+  myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
 }
 
-bool ParametersPlugin_WidgetParamsMgr::checkIsValid()
+bool ParametersPlugin_WidgetParamsMgr::isValid()
 {
   QTreeWidgetItem* aItem;
   bool aIsValid = true;
index 8e32c3767b5046418d04a098070ecb0576eba1d0..0606cf092d52c7a943f1e9266df89c45dc032bf0 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef ParametersPlugin_WidgetParamsMgr_H_
 #define ParametersPlugin_WidgetParamsMgr_H_
 
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_ModelDialogWidget.h>
 #include <QModelIndex>
 #include <QAbstractItemDelegate>
 #include <QTreeWidget>
@@ -43,7 +43,7 @@ protected slots:
  * \ingroup GUI
  * Represent a content of the property panel to show/modify parameters of some feature.
  */
-class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelWidget
+class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelDialogWidget
 {
  Q_OBJECT
 public:
@@ -119,14 +119,15 @@ private:
 
   void updateParametersPart();
 
+  /// Returns true if values in the widget are valid
+  bool isValid();
+
   /// Returns true if parameter with the given name already exists
   bool hasName(const QString& theName) const;
 
   /// Enable or disable buttons for parameters managemnt
   void enableButtons(bool theEnable);
 
-  bool checkIsValid();
-
   QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures, QList<FeaturePtr>& theFeatureList) const;
   QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;