Salome HOME
Added unit-test that checks the issue #1379 is fixed
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_WidgetParamsMgr.cpp
index 7087b1b9cd2fad45e2903b526af13761cef3d085..96e10edb14c720706a7f03058c5e5c9059301d4f 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        ParametersPlugin_WidgetParamsMgr.cpp
-// Created:     11 Apr 2016
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "ParametersPlugin_WidgetParamsMgr.h"
 #include "ParametersPlugin_Parameter.h"
@@ -102,7 +116,8 @@ void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
 {
   QBrush aBrush = painter->brush();
   QPen aPen = painter->pen();
-//  if (!isEditable(index))
+  //if (!isEditable(index))
+  //  painter->setBrush(Qt::lightGray);
   if (!index.parent().isValid())
     painter->setBrush(Qt::lightGray);
 
@@ -168,7 +183,7 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP
   myTable = new ParametersPlugin_TreeWidget(this);
   myTable->setColumnCount(4);
   QStringList aHeaders;
-  aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment");
+  aHeaders << tr("Name") << tr("Expression") << tr("Result") << tr("Comment");
   myTable->setHeaderLabels(aHeaders);
   myTable->setColumnWidth(Col_Name, 200);
   myTable->setColumnWidth(Col_Equation, 100);
@@ -296,7 +311,7 @@ void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
   int aNbFeatures = aDoc->numInternalFeatures();
   for (int i = 0; i < aNbFeatures; i++) {
     aParamFeature = aDoc->internalFeature(i);
-    if (aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
+    if (aParamFeature && aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
       myParametersList.append(aParamFeature);
     }
   }
@@ -328,7 +343,7 @@ QList<QStringList> ParametersPlugin_WidgetParamsMgr::
     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()) {
+      if (aReferenced.get() && (aReferenced != aParameter)) {
         if (aReferenced->getKind() == ParametersPlugin_Parameter::ID()) {
           // Find referenced feature Recursive
           QList<FeaturePtr> aList;
@@ -519,9 +534,10 @@ QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem
   aValues << NoValue;
 
   QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues);
-  if (theParent == myParameters)
+  if (theParent == myParameters) {
     aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
-  else
+    aItem->setForeground(2, Qt::darkGray);
+  } else
     aItem->setFlags(Qt::NoItemFlags);
   return aItem;
 }
@@ -756,16 +772,14 @@ void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
 bool ParametersPlugin_WidgetParamsMgr::isValid()
 {
   QTreeWidgetItem* aItem;
-  bool aIsValid = true;
   for(int i = 0; i < myParameters->childCount(); i++) {
     aItem = myParameters->child(i);
     if ((aItem->text(Col_Name) == NoName) ||
         (aItem->text(Col_Equation) == NoValue) ||
         (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
-      aIsValid = false;
-      break;
+      return false;
     }
   }
-  return aIsValid;
+  return true;
 }