From: vsv Date: Wed, 1 Jun 2016 12:13:31 +0000 (+0300) Subject: Issue #1525: Disable Ok button if parameters are not valid X-Git-Tag: V_2.3.1~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f96e7958a6b68c45e722aea764ecc075d0797233;p=modules%2Fshaper.git Issue #1525: Disable Ok button if parameters are not valid --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 0e3066310..c4fc1a276 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -62,6 +62,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetValidator.h ModuleBase_IconFactory.h ModuleBase_Dialog.h + ModuleBase_ModelDialogWidget.h ) SET(PROJECT_SOURCES diff --git a/src/ModuleBase/ModuleBase_Dialog.cpp b/src/ModuleBase/ModuleBase_Dialog.cpp index 5a3db14f8..1e148ac72 100644 --- a/src/ModuleBase/ModuleBase_Dialog.cpp +++ b/src/ModuleBase/ModuleBase_Dialog.cpp @@ -6,6 +6,7 @@ #include "ModuleBase_IWorkshop.h" #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_PageWidget.h" +#include "ModuleBase_ModelDialogWidget.h" #include #include @@ -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(theWidget); + if (aDlgWgt) + aDlgWgt->setDialogButtons(myButtonsBox); + theWidget->setFeature(myFeature); theWidget->restoreValue(); } diff --git a/src/ModuleBase/ModuleBase_Dialog.h b/src/ModuleBase/ModuleBase_Dialog.h index bb58343f6..6112c407a 100644 --- a/src/ModuleBase/ModuleBase_Dialog.h +++ b/src/ModuleBase/ModuleBase_Dialog.h @@ -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 index 000000000..82a3a355b --- /dev/null +++ b/src/ModuleBase/ModuleBase_ModelDialogWidget.h @@ -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 diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index eee614043..35df874aa 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -30,6 +30,7 @@ #include #include #include +#include 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 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; diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index 8e32c3767..0606cf092 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -7,7 +7,7 @@ #ifndef ParametersPlugin_WidgetParamsMgr_H_ #define ParametersPlugin_WidgetParamsMgr_H_ -#include +#include #include #include #include @@ -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 featuresItems(const QList& theFeatures, QList& theFeatureList) const; QList parametersItems(const QList& theFeatures) const;