From: sbh Date: Mon, 10 Nov 2014 11:52:51 +0000 (+0300) Subject: Issue #219 Corectly define selection type on edit X-Git-Tag: V_0.5~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7981678231adaa3ef7468d7564fef427cffdaf50;p=modules%2Fshaper.git Issue #219 Corectly define selection type on edit --- diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 443eed177..e150fb56c 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -105,7 +105,7 @@ void Model_AttributeSelectionList::updateSubs() if (aNum == 0) { mySubs.clear(); } else { - std::vector >::iterator aSubIter; + std::vector >::iterator aSubIter = mySubs.begin(); for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--; mySubs.erase(aSubIter, mySubs.end()); } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index ec03b722a..d3acd5c4e 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -61,6 +61,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); //TODO_END connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged())); + activateSelection(true); } @@ -139,13 +140,35 @@ QList ModuleBase_WidgetMultiSelector::getControls() const //******************************************************************** bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent) { - if (theObj == myListControl) { - if (theEvent->type() == QEvent::FocusIn) - activateSelection(true); - } + //TODO: Remove maybe? return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) +{ + myIsActive = toActivate; + if (myIsActive) { + connect(myWorkshop, SIGNAL(selectionChanged()), + this, SLOT(onSelectionChanged()), + Qt::UniqueConnection); + activateShapeSelection(); + } else { + disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + myWorkshop->deactivateSubShapesSelection(); + } +} + +//******************************************************************** +void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() +{ + activateShapeSelection(); + QList anEmptyList; + myWorkshop->setSelected(anEmptyList); + // Clear mySelection, myListControl and storeValue() + onSelectionChanged(); +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionChanged() { @@ -168,31 +191,6 @@ void ModuleBase_WidgetMultiSelector::onSelectionChanged() emit valuesChanged(); } - -//******************************************************************** -void ModuleBase_WidgetMultiSelector::updateSelectionList() -{ - QString aType; - if (myTypeCombo->currentText().toLower() == "vertices") - aType = "vertex"; - else if (myTypeCombo->currentText().toLower() == "edges") - aType = "edge"; - else if (myTypeCombo->currentText().toLower() == "faces") - aType = "face"; - else if (myTypeCombo->currentText().toLower() == "solids") - aType = "solid"; - - myListControl->clear(); - int i = 1; - foreach (GeomSelection aSel, mySelection) { - QString aName(aSel.first->data()->name().c_str()); - aName += ":" + aType + QString("_%1").arg(i); - myListControl->addItem(aName); - i++; - } -} - - //******************************************************************** void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List& theShapesToFilter, NCollection_List& theResult) @@ -210,36 +208,25 @@ void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_Listcount(); ++idx) { aShapeTypeName = myTypeCombo->itemText(idx); TopAbs_ShapeEnum aRefType = ModuleBase_WidgetShapeSelector::shapeType(aShapeTypeName); if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) { + activateSelection(false); bool isBlocked = myTypeCombo->blockSignals(true); myTypeCombo->setCurrentIndex(idx); myTypeCombo->blockSignals(isBlocked); + activateSelection(true); break; } } } -//******************************************************************** -void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) -{ - myIsActive = toActivate; - if (myIsActive) { - connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - activateShapeSelection(); - } else { - disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - myWorkshop->deactivateSubShapesSelection(); - } -} - void ModuleBase_WidgetMultiSelector::activateShapeSelection() { QString aNewType = myTypeCombo->currentText(); @@ -249,10 +236,24 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection() } //******************************************************************** -void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() +void ModuleBase_WidgetMultiSelector::updateSelectionList() { - QList anEmptyList; - myWorkshop->setSelected(anEmptyList); - activateShapeSelection(); - onSelectionChanged(); -} + QString aType; + if (myTypeCombo->currentText().toLower() == "vertices") + aType = "vertex"; + else if (myTypeCombo->currentText().toLower() == "edges") + aType = "edge"; + else if (myTypeCombo->currentText().toLower() == "faces") + aType = "face"; + else if (myTypeCombo->currentText().toLower() == "solids") + aType = "solid"; + + myListControl->clear(); + int i = 1; + foreach (GeomSelection aSel, mySelection) { + QString aName(aSel.first->data()->name().c_str()); + aName += ":" + aType + QString("_%1").arg(i); + myListControl->addItem(aName); + i++; + } +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 9396c21e6..eee5389a1 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -64,21 +64,21 @@ Q_OBJECT /// \param theValue the wrapped widget value virtual bool setValue(ModuleBase_WidgetValue* theValue); -public slots: + public slots: /// Activate or deactivate selection void activateSelection(bool toActivate); -private slots: + private slots: void onSelectionChanged(); -protected: + protected: bool eventFilter(QObject* theObj, QEvent* theEvent); void updateSelectionName(); void raisePanel() const; - /// Returns true if Sape of given object corresponds to requested shape type + /// Returns true if shape of given object corresponds to requested shape type /// This method is called only in non sub-shapes selection mode virtual bool acceptObjectShape(const ObjectPtr theObject) const; @@ -95,6 +95,7 @@ protected: void setObject(ObjectPtr theObj, boost::shared_ptr theShape = boost::shared_ptr()); //----------- Class members ------------- + private: QWidget* myContainer; QLabel* myLabel; QLineEdit* myTextLine;