From: nds Date: Wed, 19 Aug 2015 10:52:32 +0000 (+0300) Subject: Issue #478 Problem of performance with selection: remove last instead of clearing... X-Git-Tag: V_1.4.0_beta4~349 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8f0b2cf49bd24e118ad3fc523eb4a815d067d46c;p=modules%2Fshaper.git Issue #478 Problem of performance with selection: remove last instead of clearing the list. --- diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 98f45e370..362d3d8a3 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -36,6 +36,8 @@ #include #include +//#define DEBUG_ATTRIBUTE_SELECTION + //#define DEBUG_SHAPE_VALIDATION_PREVIOUS class CustomListWidget : public QListWidget @@ -66,7 +68,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId), - mySelectionType(""), mySelectionCount(0) + mySelectionCount(0) { QGridLayout* aMainLay = new QGridLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); @@ -150,6 +152,8 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom() const //******************************************************************** bool ModuleBase_WidgetMultiSelector::restoreValueCustom() { + myIsInValidate = false; + // A rare case when plugin was not loaded. if(!myFeature) return false; @@ -170,6 +174,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValueCustom() //******************************************************************** void ModuleBase_WidgetMultiSelector::storeAttributeValue() { + myIsInValidate = true; DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(aData->attribute(attributeID())); @@ -177,14 +182,17 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue() return; mySelectionType = aSelectionListAttr->selectionType(); - mySelectionCount = aSelectionListAttr->size(); - /*mySelection.clear(); +#ifdef DEBUG_ATTRIBUTE_SELECTION + mySelection.clear(); int aSize = aSelectionListAttr->size(); for (int i = 0; i < aSelectionListAttr->size(); i++) { AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value())); - }*/ + } +#else + mySelectionCount = aSelectionListAttr->size(); +#endif } //******************************************************************** @@ -204,14 +212,16 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(aData->attribute(attributeID())); + int aSelCount = aSelectionListAttr->size(); ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - aSelectionListAttr->append(aResult, theShape); + aSelectionListAttr->append(aResult, theShape/*, myIsInValidate*/); } //******************************************************************** void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) { - //clearAttribute(); +#ifdef DEBUG_ATTRIBUTE_SELECTION + clearAttribute(); // Store shape type DataPtr aData = myFeature->data(); @@ -220,14 +230,21 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) aSelectionListAttr->setSelectionType(mySelectionType); // Store selection in the attribute - //int aSize = mySelection.size(); - //foreach (GeomSelection aSelec, mySelection) { - // setObject(aSelec.first, aSelec.second); - //} + foreach (GeomSelection aSelec, mySelection) { + setObject(aSelec.first, aSelec.second); + } +#else + // Store shape type + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + aSelectionListAttr->setSelectionType(mySelectionType); - //int aCountAppened = aSelectionListAttr->size() - mySelectionCount; - //for ( int i = 0; i < aCountAppened; i++) - // aSelectionListAttr->removeLast(); + // restore selection in the attribute + int aCountAppened = aSelectionListAttr->size() - mySelectionCount; + for ( int i = 0; i < aCountAppened; i++) + aSelectionListAttr->removeLast(); +#endif } //******************************************************************** diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index d44edff7d..03e075882 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -162,8 +162,9 @@ protected: std::string mySelectionType; /// Variable of GeomSelection - //QList mySelection; + QList mySelection; int mySelectionCount; // number of elements in the attribute selection list when store + bool myIsInValidate; // the widget is in validation mode: store is performed, restore is not bool myIsUseChoice; }; diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index 0a5eb7f9e..91404aaeb 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -74,17 +74,9 @@ bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_Viewer return aValid; } -//******************************************************************** -void PartSet_WidgetMultiSelector::storeAttributeValue() -{ - myIsInVaildate = true; - ModuleBase_WidgetMultiSelector::storeAttributeValue(); -} - //******************************************************************** void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid) { - myIsInVaildate = false; ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid); myExternalObjectMgr->removeExternalValidated(sketch(), myFeature, myWorkshop); @@ -109,7 +101,7 @@ void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& t aShape = aResult->shape(); } if (aShape.get() != NULL && !aShape->isNull()) { - if (myIsInVaildate) + if (myIsInValidate) theObject = myExternalObjectMgr->externalObjectValidated(theObject, aShape, sketch()); else theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch()); diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h index e0479547e..bc2b97ac3 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.h +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -58,11 +58,6 @@ protected: /// \return a boolean value virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - /// Creates a backup of the current values of the attribute - /// It should be realized in the specific widget because of different - /// parameters of the current attribute - virtual void storeAttributeValue(); - /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different /// parameters of the current attribute @@ -81,8 +76,6 @@ protected: PartSet_ExternalObjectsMgr* myExternalObjectMgr; /// Pointer to a sketch CompositeFeaturePtr mySketch; - - bool myIsInVaildate; }; #endif \ No newline at end of file