Salome HOME
Updated copyright comment
[modules/shaper.git] / src / PartSet / PartSet_TreeNodes.cpp
index c0400d6f74f356aa8abe83c655162f062a9b1b95..54dc64c1052326b70af7e1d41b22e45f8bfa4dd6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -44,6 +44,7 @@
 
 #include <QBrush>
 #include <QMap>
+#include <QPalette>
 
 
 #define ACTIVE_COLOR QColor(Qt::black)
@@ -87,11 +88,20 @@ QVariant PartSet_TreeNode::data(int theColumn, int theRole) const
       return QBrush(DISABLED_COLOR);
     if (!aFlags.testFlag(Qt::ItemIsEditable))
       return QBrush(SELECTABLE_COLOR);
-    return ACTIVE_COLOR;
+    return activeItemColor();
   }
   return ModuleBase_ITreeNode::data(theColumn, theRole);
 }
 
+QColor PartSet_TreeNode::activeItemColor() const
+{
+  // instead of ACTIVE_COLOR (black),
+  // use the color text of the current theme (white or black or other)
+  // to make it readable in dark theme (and light theme as well)
+  QColor color = QPalette().text().color() ;
+  return color;
+}
+
 
 //////////////////////////////////////////////////////////////////////////////////
 QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
@@ -104,10 +114,10 @@ QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
         AttributeDoublePtr aValueAttribute =
           aParam->data()->real(ModelAPI_ResultParameter::VALUE());
         QString aVal = QString::number(aValueAttribute->value());
-        QString aTitle = QString(myObject->data()->name().c_str());
+        QString aTitle = QString::fromStdWString(myObject->data()->name());
         return aTitle + " = " + aVal;
       }
-      return myObject->data()->name().c_str();
+      return QString::fromStdWString(myObject->data()->name());
     }
     break;
   case Qt::DecorationRole:
@@ -131,17 +141,21 @@ QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
       else
         return QIcon();
     }
-  case Qt::ForegroundRole:
-    if (myObject->groupName() == ModelAPI_Feature::group()) {
-      std::vector<int> aColor =
-        Config_PropManager::color("Visualization", "feature_objectbrowser_color");
-      return QColor(aColor[0], aColor[1], aColor[2]);
-    }
-    break;
   }
   return PartSet_TreeNode::data(theColumn, theRole);
 }
 
+QColor PartSet_ObjectNode::activeItemColor() const
+{
+  if (myObject.get() && myObject->groupName() == ModelAPI_Feature::group()) {
+    std::vector<int> aColor =
+      Config_PropManager::color("Visualization", "feature_objectbrowser_color");
+    return QColor(aColor[0], aColor[1], aColor[2]);
+  }
+  return PartSet_TreeNode::activeItemColor();
+}
+
+
 Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
 {
   if (myObject->isDisabled()) {
@@ -149,6 +163,17 @@ Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
   } else {
     DocumentPtr aDoc = myObject->document();
     SessionPtr aSession = ModelAPI_Session::get();
+
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(myObject);
+    if (aFeature.get() && aFeature->getKind() == "Group")
+    {
+      std::shared_ptr<ModelAPI_CompositeFeature> anOwner =
+        ModelAPI_Tools::compositeOwner (aFeature);
+
+      if (anOwner.get() && anOwner->getKind() == "ImportResult")
+        return aDefaultFlag;
+    }
+
     if (aSession->activeDocument() == aDoc)
       return aEditingFlag;
   }
@@ -974,9 +999,9 @@ QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
       ResultPartPtr aPartRes = getPartResult(myObject);
       if (aPartRes.get()) {
         if (aPartRes->partDoc().get() == NULL)
-          return QString(myObject->data()->name().c_str()) + " (Not loaded)";
+          return QString::fromStdWString(myObject->data()->name()) + " (Not loaded)";
       }
-      return QString(myObject->data()->name().c_str());
+      return QString::fromStdWString(myObject->data()->name());
     }
     case Qt::DecorationRole:
       return ModuleBase_IconFactory::get()->getIcon(myObject);
@@ -1211,9 +1236,11 @@ QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& /*the
 QVariant PartSet_ObjectFolderNode::data(int theColumn, int theRole) const
 {
   if (theRole == Qt::ForegroundRole) {
-    std::vector<int> aColor =
-      Config_PropManager::color("Visualization", "feature_objectbrowser_color");
-    return QColor(aColor[0], aColor[1], aColor[2]);
+    if (!myObject->isDisabled()) {
+      std::vector<int> aColor =
+        Config_PropManager::color("Visualization", "feature_objectbrowser_color");
+      return QColor(aColor[0], aColor[1], aColor[2]);
+    }
   }
   return PartSet_ObjectNode::data(theColumn, theRole);