From: nds Date: Thu, 18 Jun 2015 04:55:43 +0000 (+0300) Subject: The validated values are cached in order to do not check them by mouse moving over... X-Git-Tag: V_1.3.0~225 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9c9c56ddc77486aaec27f8d87d18ae767cfd3772;p=modules%2Fshaper.git The validated values are cached in order to do not check them by mouse moving over an object in the viewer. This cache exists between activate/deactivate of the widget. --- diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index b01892e6a..be3ce6ec6 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -215,27 +215,6 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) } } -//******************************************************************** -void ModuleBase_WidgetMultiSelector::customValidators( - std::list& theValidators, - std::list >& theArguments) const -{ - return; - std::list anArguments; - - theValidators.push_back(myShapeValidator); - if (true/*myIsUseChoice*/) { - QString aType = myTypeCombo->currentText(); - anArguments.push_back(validatorType(aType)); - } - else { - for(int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) { - anArguments.push_back(validatorType(myTypeCombo->itemText(i))); - } - } - theArguments.push_back(anArguments); -} - //******************************************************************** bool ModuleBase_WidgetMultiSelector::acceptSubShape(const TopoDS_Shape& theShape) const { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 9d569d2c4..a9f7c461c 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -122,13 +122,6 @@ protected slots: /// \param theValid a boolean flag, if restore happens for valid parameters virtual void restoreAttributeValue(const bool theValid); - /// Puts additional validators to the given list. A separate validator is created for each of the - /// "type_choice" value - /// \param theValidators a list of validators - /// \param theArguments a list of validators arguments - virtual void customValidators(std::list& theValidators, - std::list >& theArguments) const; - /// Returns true if selected shape corresponds to requested shape types /// \param theShape a shape bool acceptSubShape(const TopoDS_Shape& theShape) const; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 03aaf1fcb..2fe1ab684 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -363,21 +363,6 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) } } -//******************************************************************** -void ModuleBase_WidgetShapeSelector::customValidators( - std::list& theValidators, - std::list >& theArguments) const -{ - return; - theValidators.push_back(myShapeValidator); - - std::list anArguments; - foreach(QString aType, myShapeTypes) { - anArguments.push_back(aType.toStdString().c_str()); - } - theArguments.push_back(anArguments); -} - //******************************************************************** bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index e2b7f6ad6..86494eb5d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -118,13 +118,6 @@ protected: /// \param theValid a boolean flag, if restore happens for valid parameters virtual void restoreAttributeValue(const bool theValid); - /// Puts additional validators to the given list. A separate validator is created for each of the - /// "type_choice" value - /// \param theValidators a list of validators - /// \param theArguments a list of validators arguments - virtual void customValidators(std::list& theValidators, - std::list >& theArguments) const; - /// Computes and updates name of selected object in the widget void updateSelectionName(); diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 1225e1282..c8e76a6c6 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -17,6 +17,8 @@ #include +//#define DEBUG_VALID_STATE + ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) @@ -51,9 +53,16 @@ bool ModuleBase_WidgetValidated::setSelection(QList& theVa //******************************************************************** bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue) { - bool aValid = isValidSelectionCustom(theValue); - if (!aValid) + bool aValid = false; + if (getValidState(theValue, aValid)) { + return aValid; + } + + aValid = isValidSelectionCustom(theValue); + if (!aValid) { + storeValidState(theValue, aValid); return aValid; + } DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); @@ -90,6 +99,7 @@ bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& th aLoop->flush(aDeletedEvent); aLoop->flush(aRedispEvent); + storeValidState(theValue, aValid); return aValid; } @@ -108,8 +118,6 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const std::list > anArguments; aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments); - customValidators(aValidators, anArguments); - DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); @@ -127,18 +135,66 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const } void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop, - const bool toActivate) const + const bool toActivate) { ModuleBase_IViewer* aViewer = theWorkshop->viewer(); Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter(); if (toActivate) aViewer->addSelectionFilter(aSelFilter); - else + else { aViewer->removeSelectionFilter(aSelFilter); + clearValidState(); + } } -void ModuleBase_WidgetValidated::customValidators(std::list& theValidators, - std::list >& theArguments) const +//******************************************************************** +void ModuleBase_WidgetValidated::storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid) { + bool aValidPrs = myInvalidPrs.contains(theValue); + bool anInvalidPrs = myInvalidPrs.contains(theValue); + + if (theValid) { + if (!aValidPrs) + myValidPrs.append(theValue); + // the commented code will be useful when the valid state of the presentation + // will be changable between activate/deactivate. Currently it does not happen. + //if (anInvalidPrs) + // myInvalidPrs.removeOne(theValue); + } + else { // !theValid + if (!anInvalidPrs) + myInvalidPrs.append(theValue); + //if (!aValidPrs) + // myValidPrs.removeOne(theValue); + } +#ifdef DEBUG_VALID_STATE + qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count()) + .arg(myInvalidPrs.count()).toStdString().c_str()); +#endif } + +//******************************************************************** +bool ModuleBase_WidgetValidated::getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid) +{ + bool aValidPrs = myValidPrs.contains(theValue); + bool anInvalidPrs = myInvalidPrs.contains(theValue); + + if (aValidPrs) + theValid = true; + else if (anInvalidPrs) + theValid = false; + + return aValidPrs || anInvalidPrs; +} + +//******************************************************************** +void ModuleBase_WidgetValidated::clearValidState() +{ +#ifdef DEBUG_VALID_STATE + qDebug("clearValidState"); +#endif + myValidPrs.clear(); + myInvalidPrs.clear(); +} + diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index bacba1887..4e6b9aa73 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -16,6 +16,8 @@ #include +#include + class QWidget; class ModuleBase_IWorkshop; class ModuleBase_ISelection; @@ -80,13 +82,24 @@ protected: /// It obtains selection filters from the workshop and activates them in the active viewer /// \param theWorkshop an active workshop /// \param toActivate a flag about activation or deactivation the filters - virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const; + virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate); + + /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored + /// \param theValue a viewer presentation + /// \param theValid a valid state + bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid); + + /// Store the validity state of the presentation in an internal map + /// \param theValue a viewer presentation + /// \param theValid a valid state + void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid); + + // Removes all presentations from internal maps. + void clearValidState(); - /// Puts additional validators to the given list - /// \param theValidators a list of validators - /// \param theArguments a list of validators arguments - virtual void customValidators(std::list& theValidators, - std::list >& theArguments) const; +private: + QList myValidPrs; + QList myInvalidPrs; }; #endif /* MODULEBASE_WIDGETVALIDATED_H_ */