From: vsv Date: Fri, 14 Jun 2019 16:25:01 +0000 (+0300) Subject: Deactivate Accept button if nothing was selected X-Git-Tag: VEDF2019Lot4~101^2~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a3e49a5c9d10805078a0a585282da8eeb9ced42b;hp=27816701ee9b526a56e24a564efa319e66ff5a78;p=modules%2Fshaper.git Deactivate Accept button if nothing was selected --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 0e6514374..0e44c0e90 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -150,7 +150,7 @@ Q_OBJECT //! If the feature is correct, it returns an empty value //! \param theValueStateChecked the boolean flag if the state of the widget should be checked //! \return string value - QString getError(const bool theValueStateChecked = true) const; + virtual QString getError(const bool theValueStateChecked = true) const; /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index faf52833c..77306e017 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -93,18 +93,6 @@ ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature QPushButton* aLaunchBtn = new QPushButton(tr("Selection by filters"), this); connect(aLaunchBtn, SIGNAL(clicked()), SLOT(onFiltersLaunch())); aMainLayout->addWidget(aLaunchBtn); - - myFilterLbl = new QLabel(this); - myFilterLbl->setPixmap(QPixmap(":pictures/filter.png")); - aMainLayout->addWidget(myFilterLbl); - - myModifyLbl = new QLabel(this); - myModifyLbl->setPixmap(QPixmap(":pictures/plus_minus.png")); - aMainLayout->addWidget(myModifyLbl); - aMainLayout->addStretch(1); - - myFilterLbl->hide(); - myModifyLbl->hide(); } void ModuleBase_FilterStarter::onFiltersLaunch() @@ -173,6 +161,7 @@ ModuleBase_FilterItem::ModuleBase_FilterItem( theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*))); connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*))); + connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated())); } aLayout->addWidget(aParamsWgt); } @@ -357,6 +346,7 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex) myFiltersCombo->setCurrentIndex(0); myFiltersCombo->removeItem(theIndex); + updateObject(myFeature); } void ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter) @@ -408,6 +398,8 @@ void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theIt myWorkshop->selectionActivate()->updateSelectionModes(); myWorkshop->selectionActivate()->updateSelectionFilters(); redisplayFeature(); + myFiltersCombo->setFocus(); + updateObject(myFeature); } @@ -470,6 +462,7 @@ void ModuleBase_WidgetSelectionFilter::onSelect() if (myValues.size() > 0) updatePreview(aComp); updateNumberSelected(); + updateObject(myFeature); } void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape) @@ -533,8 +526,17 @@ void ModuleBase_WidgetSelectionFilter::updateSelectBtn() void ModuleBase_WidgetSelectionFilter::updateNumberSelected() { - myNbLbl->setText(QString::number(myValues.size())); + int aNb = myValues.size(); + myNbLbl->setText(QString::number(aNb)); + //QString aErr = () ? tr("Selection is empty") : ""; + if (aNb == 0) + myFeature->setError(tr("Selection is empty").toStdString(), false, false); + else { + myFeature->setError("", false, false); + myFeature->data()->execState(ModelAPI_StateDone); + } } + QList ModuleBase_WidgetSelectionFilter::getControls() const { QList aWidgets; @@ -545,6 +547,7 @@ QList ModuleBase_WidgetSelectionFilter::getControls() const aWidgets.append(aWgt); } } + aWidgets.append(myFiltersCombo); return aWidgets; } @@ -574,6 +577,7 @@ bool ModuleBase_WidgetSelectionFilter::storeValueCustom() ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget(); if (aActive) return aActive->storeValue(); + updateObject(myFeature); return true; } @@ -597,9 +601,6 @@ bool ModuleBase_WidgetSelectionFilter::restoreValueCustom() aAttrList->setFilters(aFiltersFeature); } - ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget(); - if (aActive) - return aActive->restoreValue(); QList aWidgets; QList aItems = myFiltersWgt->findChildren(); foreach(ModuleBase_FilterItem* aItem, aItems) { @@ -610,3 +611,20 @@ bool ModuleBase_WidgetSelectionFilter::restoreValueCustom() } return true; } + +QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const +{ + QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked); + if (aErrorMsg.isEmpty()) { + if (myValues.size() == 0) + aErrorMsg = tr("Selection is empty"); + } + return aErrorMsg; +} + +void ModuleBase_WidgetSelectionFilter::onObjectUpdated() +{ + clearCurrentSelection(true); + updateNumberSelected(); + updateObject(myFeature); +} diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index d2535d662..45b6ec6b6 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -43,69 +43,115 @@ class QCheckBox; class ModuleBase_IWorkshop; +/** +* \ingroup GUI +* An object which lets to start a Filters operation as +* a sub-operation of the current one. +*/ class MODULEBASE_EXPORT ModuleBase_FilterStarter: public QWidget { Q_OBJECT public: + /// Constructor + /// \param theFeature a name of feature for filtering + /// \param theParent a parent widget which will get control after filtering + /// \param theWorkshop a pointer on a current workshop ModuleBase_FilterStarter(const std::string& theFeature, QWidget* theParent, ModuleBase_IWorkshop* theWorkshop); + /// Destructor ~ModuleBase_FilterStarter() {} private slots: + /// A slot to launch filtering operation void onFiltersLaunch(); private: + /// Name of filtering feature std::string myFeatureName; - ModuleBase_IWorkshop* myWorkshop; - QLabel* myFilterLbl; - QLabel* myModifyLbl; + /// A workshop + ModuleBase_IWorkshop* myWorkshop; }; class ModuleBase_WidgetSelectionFilter; - +/** +* \ingroup GUI +* A widget which reperesents a one filter item in filters list +* Also it includes filter GUI if it exists +*/ class ModuleBase_FilterItem : public QWidget { Q_OBJECT public: + + /// Constructor + /// \param theFilter the filter ID + /// \param theParent a parent widget of ModuleBase_WidgetSelectionFilter class ModuleBase_FilterItem(const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent); + /// Returns filter Id std::string filter() const { return myFilterID; } /// Returns list of widget controls /// \return a control list QList getControls() const; + /// Returns list of widgets which reperesent the current filter GUI QList widgets() const { return myWidgets; } signals: + /// The seignal is sent on deletion of the item void deleteItem(ModuleBase_FilterItem* theItem); + + /// The seignal is sent on reversing of the item void reversedItem(ModuleBase_FilterItem* theItem); private slots: + /// A slot to process reverse button click + /// \param theCheck a current state of the button void onReverse(bool theCheck); + + /// A slot to process delete button click void onDelete(); private: + /// A function which adds standard widgets of the item void addItemRow(QWidget* theParent); + /// Current filter Id std::string myFilterID; + + /// Filters feature FiltersFeaturePtr mySelection; + + /// Reverce button QToolButton* myRevBtn; + + /// A list of sub-widgets QList myWidgets; }; +/** +* \ingroup GUI +* A widget for selection by filters +*/ class ModuleBase_WidgetSelectionFilter : 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_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData); + /// Destructor ~ModuleBase_WidgetSelectionFilter(); /// Returns list of widget controls @@ -116,10 +162,15 @@ public: /// By default this slot does nothing virtual void onFeatureAccepted(); + /// Returns current workshop ModuleBase_IWorkshop* workshop() const { return myWorkshop; } + /// Returns a container widget for filter items QWidget* filtersWidget() const { return myFiltersWgt; } + /// Returns error string + virtual QString getError(const bool theValueStateChecked = true) const; + protected: /// Saves the internal parameters to the given feature (not ussed for this widget) /// \return True in success @@ -129,18 +180,42 @@ protected: virtual bool restoreValueCustom(); private slots: + /// Add a filter by Id in combo box void onAddFilter(int); + + /// Add a filter by name void onAddFilter(const std::string& theFilter); + + /// Process deletion of a filter item void onDeleteItem(ModuleBase_FilterItem* theItem); + + /// Process reversion of a filter item void onReverseItem(ModuleBase_FilterItem* theItem); + + /// Process selection void onSelect(); + + /// Show only selected objects void onShowOnly(bool theErase); + /// Process update of a filter item + void onObjectUpdated(); + private: + /// Update state of button State void updateSelectBtn(); + + /// Update number of selected objects void updateNumberSelected(); + + /// Clear selection void clearCurrentSelection(bool toUpdate = false); + + /// Update preview + /// \param theShape a preview shape void updatePreview(const TopoDS_Shape& theShape); + + /// Call to redisplay the fiter feature void redisplayFeature(); private: @@ -154,16 +229,28 @@ private: QLabel* myNbLbl; QCheckBox* myShowBtn; + /// Type of selection mode int mySelectionType; + + /// List of non-used filters std::list myFilters; + + /// List of used filters std::list myUseFilters; + /// Result of filtering QList myValues; + + /// A preview shape Handle(AIS_Shape) myPreview; + /// List of displayed objects before "Show only" AIS_ListOfInteractive myListIO; + /// A Feature which will get result of filtering FeaturePtr mySelectorFeature; + + /// Attribute name which will get result of filtering std::string mySelectorAttribute; };