]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #219 Corectly define selection type on edit
authorsbh <sergey.belash@opencascade.com>
Mon, 10 Nov 2014 11:52:51 +0000 (14:52 +0300)
committersbh <sergey.belash@opencascade.com>
Mon, 10 Nov 2014 11:52:51 +0000 (14:52 +0300)
src/Model/Model_AttributeSelectionList.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h

index 443eed177df90299df12ba056135db6f98627c5b..e150fb56c0bc83455050b3cace2ee10e8be4e777 100644 (file)
@@ -105,7 +105,7 @@ void Model_AttributeSelectionList::updateSubs()
     if (aNum == 0) {
       mySubs.clear();
     } else {
-      std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter;
+      std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
       for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--;
       mySubs.erase(aSubIter, mySubs.end());
     }
index ec03b722a01195ac98394de20ef55798b6362527..d3acd5c4e1325b488c962855bebd2a60e913a256 100644 (file)
@@ -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<QWidget*> 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<ObjectPtr> 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<TopoDS_Shape>& theShapesToFilter,
                                                   NCollection_List<TopoDS_Shape>& theResult)
@@ -210,36 +208,25 @@ void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_
   }
 }
 
-
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
 {
   QString aShapeTypeName;
+  
   for (int idx = 0; idx < myTypeCombo->count(); ++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<ObjectPtr> 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
index 9396c21e63167184d10598e9b85b3a0dc9b9fcbc..eee5389a1dd11fbb115130362d07b5a7d1f2bc97 100644 (file)
@@ -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<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
 
   //----------- Class members -------------
+ private:
   QWidget* myContainer;
   QLabel* myLabel;
   QLineEdit* myTextLine;