Salome HOME
Issue #1005: To improve user-friendship of error-messages for features and attributes
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.cpp
index 1f1686bab9af6813e37aa510f988730b97a1856c..fe5e99ecc75774a09de5d31c28f4b29f7b17edd5 100755 (executable)
@@ -117,11 +117,11 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
     myTypeCombo->setVisible(false);
   }
 
-  std::string aLabelText = theData->getProperty("label");
-  QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str()
-                                                      : tr("Selected objects:"), this);
+  QString aLabelText = translate(theData->getProperty("label"));
+  QLabel* aListLabel = new QLabel(aLabelText, this);
   aMainLay->addWidget(aListLabel, 1, 0);
-  // if the xml definition contains one type, an information label should be shown near to the latest
+  // if the xml definition contains one type, an information label
+  // should be shown near to the latest
   if (aShapeTypes.size() <= 1) {
     QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
     if (!aLabelIcon.isEmpty()) {
@@ -187,8 +187,8 @@ void ModuleBase_WidgetMultiSelector::deactivate()
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::storeValueCustom()
 {
-  // the value is stored on the selection changed signal processing 
-  // A rare case when plugin was not loaded. 
+  // the value is stored on the selection changed signal processing
+  // A rare case when plugin was not loaded.
   if (!myFeature)
     return false;
 
@@ -204,7 +204,7 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom()
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
 {
-  // A rare case when plugin was not loaded. 
+  // A rare case when plugin was not loaded.
   if (!myFeature)
     return false;
 
@@ -280,7 +280,7 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
 
   if (isDone) // may be the feature's result is not displayed, but attributes should be
     myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
-                                          true);/// hope that something is redisplayed by object updated
+                             true);/// hope that something is redisplayed by object updated
 
   return isDone;
 }
@@ -362,7 +362,7 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
 
     // may be the feature's result is not displayed, but attributes should be
     myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
-                                          true); /// hope that something is redisplayed by object updated
+                              true); /// hope that something is redisplayed by object updated
   }
 
   // Restore selection
@@ -393,11 +393,41 @@ QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
 {
   activateSelectionAndFilters(true);
-  QList<ModuleBase_ViewerPrsPtr> anEmptyList;
-  // This method will call Selection changed event which will call onSelectionChanged
-  // To clear mySelection, myListControl and storeValue()
-  // So, we don't need to call it
-  myWorkshop->setSelected(anEmptyList);
+
+  if (!myFeature)
+    return;
+  /// store the selected type
+  AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
+  std::string aType = anAttribute->attributeType();
+  if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+    aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
+  }
+
+  // clear attribute values
+  DataPtr aData = myFeature->data();
+  if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
+    aSelectionListAttr->clear();
+  }
+  else if (aType == ModelAPI_AttributeRefList::typeId()) {
+    AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
+    aRefListAttr->clear();
+  }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
+    aRefAttrListAttr->clear();
+  }
+
+  // update object is necessary to flush update signal. It leads to objects references map update
+  // and the operation presentation will not contain deleted items visualized as parameters of
+  // the feature.
+  updateObject(myFeature);
+  restoreValue();
+  myWorkshop->setSelected(getAttributeSelection());
+  // may be the feature's result is not displayed, but attributes should be
+  myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
+                            true); /// hope that something is redisplayed by object updated
 }
 
 //********************************************************************
@@ -412,6 +442,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionChanged()
         // it should be postponed to exit from the selectionChanged processing
         static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
         ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
+        Events_Loop::loop()->flush(anEvent);
         return;
       }
     }
@@ -421,7 +452,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionChanged()
 
 void ModuleBase_WidgetMultiSelector::updateFocus()
 {
-  // Set focus to List control in order to make possible 
+  // Set focus to List control in order to make possible
   // to use Tab key for transfer the focus to next widgets
   myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
   ModuleBase_Tools::setFocus(myListControl,
@@ -452,7 +483,7 @@ QIntList ModuleBase_WidgetMultiSelector::shapeTypes() const
 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const int theShapeType)
 {
   QString aShapeTypeName;
-  
+
   for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
     aShapeTypeName = myTypeCombo->itemText(idx);
     int aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
@@ -546,6 +577,21 @@ std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType
   return aType;
 }
 
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::clearSelection()
+{
+  bool isClearInNeutralPoint = myIsNeutralPointClear;
+  myIsNeutralPointClear = true;
+
+  QList<ModuleBase_ViewerPrsPtr> anEmptyList;
+  // This method will call Selection changed event which will call onSelectionChanged
+  // To clear mySelection, myListControl and storeValue()
+  // So, we don't need to call it
+  myWorkshop->setSelected(anEmptyList);
+
+  myIsNeutralPointClear = isClearInNeutralPoint;
+}
+
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::onCopyItem()
 {
@@ -574,7 +620,7 @@ void ModuleBase_WidgetMultiSelector::onListSelection()
   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
   myCopyAction->setEnabled(!aItems.isEmpty());
   myDeleteAction->setEnabled(!aItems.isEmpty());
-  
+
   myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
                                         true);
 }
@@ -591,7 +637,7 @@ void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>&
 }
 
 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
-                                                      QList<ModuleBase_ViewerPrsPtr>& theValues) const
+                                                   QList<ModuleBase_ViewerPrsPtr>& theValues) const
 {
   if(myFeature.get() == NULL)
     return;
@@ -683,7 +729,8 @@ bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
     std::set<AttributePtr> anAttributes;
-    QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
+    QList<ModuleBase_ViewerPrsPtr>::const_iterator
+      anIt = theValues.begin(), aLast = theValues.end();
     ObjectPtr anObject;
     GeomShapePtr aShape;
     for (; anIt != aLast; anIt++) {