]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Optimization of the widget code
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 22 Apr 2016 09:16:17 +0000 (12:16 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 22 Apr 2016 09:16:32 +0000 (12:16 +0300)
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h

index 183708fdb11c1b54949a5c59d226123c623dfccb..508303bba82a400c3732dea1949deb1ce64ee51e 100644 (file)
@@ -247,47 +247,21 @@ void ParametersPlugin_WidgetParamsMgr::activateCustom()
       myParameters->addChild(aItem);
 
       myParametersList.append(aParamFeature);
-
-      // Set features where the parameter is used
-      const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
-      std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
-      for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
-        std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
-        FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
-        if (aReferenced.get()) {
-          QStringList aValNames;
-          aValNames << aReferenced->data()->name().c_str();
-
-          AttributeDoublePtr aDouble = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
-          if (aDouble.get()) {
-            aValNames << aDouble->text().c_str();
-            aValNames << QString::number(aDouble->value());
-          } else {
-            AttributeIntegerPtr aInt = std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
-            if (aInt.get()) {
-              aValNames << aInt->text().c_str();
-              aValNames << QString::number(aInt->value());
-            }
-          }
-
-          aItem = new QTreeWidgetItem(aValNames);
-          myFeatures->addChild(aItem);
-        }
-      }
     }
   }
+  updateFeaturesPart();
+
   myFeatures->setExpanded(true);
   myParameters->setExpanded(true);
 }
 
 
-void ParametersPlugin_WidgetParamsMgr::rebuildFeatures()
+QList<QStringList> ParametersPlugin_WidgetParamsMgr::
+  featuresItems(const QList<FeaturePtr>& theFeatures) const
 {
-  myFeatures->takeChildren(); // Clear list
-
+  QList<QStringList> aItemsList;
   ResultParameterPtr aParam;
-  QTreeWidgetItem* aItem;
-  foreach(FeaturePtr aParameter, myParametersList) {
+  foreach(FeaturePtr aParameter, theFeatures) {
     aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParameter->firstResult());
     const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
     std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
@@ -309,12 +283,11 @@ void ParametersPlugin_WidgetParamsMgr::rebuildFeatures()
             aValNames << QString::number(aInt->value());
           }
         }
-
-        aItem = new QTreeWidgetItem(aValNames);
-        myFeatures->addChild(aItem);
+        aItemsList.append(aValNames);
       }
     }
   }
+  return aItemsList;
 }
 
 
@@ -393,36 +366,24 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
 
 void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
 {
-  std::shared_ptr<ModelAPI_ResultParameter> aParam;
+  QList<QStringList> aFeaturesList = featuresItems(myParametersList);
+  if (aFeaturesList.count() != myFeatures->childCount()) {
+    if (myFeatures->childCount()  < aFeaturesList.count()) {
+      while (myFeatures->childCount() != aFeaturesList.count()) 
+        myFeatures->addChild(new QTreeWidgetItem());
+    } else {
+      while (myFeatures->childCount() != aFeaturesList.count()) 
+        myFeatures->removeChild(myFeatures->child(myFeatures->childCount() - 1));
+    }
+  }
   int i = 0;
-  foreach(FeaturePtr aFeature, myParametersList) {
-    aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aFeature->firstResult());
-    const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
-    std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
-    for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
-      std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
-      FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
-      if (aReferenced.get()) {
-        QStringList aValNames;
-        aValNames << aReferenced->data()->name().c_str();
-
-        AttributeDoublePtr aDouble = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
-        if (aDouble.get()) {
-          aValNames << aDouble->text().c_str();
-          aValNames << QString::number(aDouble->value());
-        } else {
-          AttributeIntegerPtr aInt = std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
-          if (aInt.get()) {
-            aValNames << aInt->text().c_str();
-            aValNames << QString::number(aInt->value());
-          }
-        }
-
-        QTreeWidgetItem* aItem = myFeatures->child(i++);
-        for(int i = 0; i < aValNames.count(); i++)
-          aItem->setText(i, aValNames.at(i));
-      }
+  foreach(QStringList aFeature, aFeaturesList) {
+    int aCol = 0;
+    foreach(QString aText, aFeature) {
+      myFeatures->child(i)->setText(aCol, aText);
+      aCol++;
     }
+    i++;
   }
 }
 
@@ -459,6 +420,8 @@ void ParametersPlugin_WidgetParamsMgr::onAdd()
     return;
 
   QTreeWidgetItem* aItem = createNewItem();
+  if (aFeature->name().length() > 0)
+    aItem->setText(Col_Name, aFeature->name().c_str());
   myParameters->addChild(aItem);
   myParametersList.append(aFeature);
       
@@ -543,7 +506,7 @@ void ParametersPlugin_WidgetParamsMgr::onRemove()
     }
 
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
-    rebuildFeatures();
+    updateFeaturesPart();
   }
 }
 
index ff4d5abb00f1b8b4dc1017da6860dbf837d70240..9f9fda3b06b4b7270c47dee2311ef5783322d431 100644 (file)
@@ -96,8 +96,7 @@ private:
   /// Returns true if parameter with the given name already exists
   bool hasName(const QString& theName) const;
 
-  /// Clear and rebuild children of Features item
-  void rebuildFeatures();
+  QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures) const;
 
   QTreeWidget* myTable;
   QTreeWidgetItem* myFeatures;