]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Apply warning icon to folder only in case if it is not expanded
authorvsv <vsv@opencascade.com>
Fri, 19 Oct 2018 11:58:03 +0000 (14:58 +0300)
committervsv <vsv@opencascade.com>
Fri, 19 Oct 2018 11:58:03 +0000 (14:58 +0300)
src/PartSet/PartSet_IconFactory.cpp
src/PartSet/PartSet_IconFactory.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_TreeNodes.cpp
src/PartSet/PartSet_TreeNodes.h
src/XGUI/XGUI_ObjectsBrowser.h

index da1c13a4a2c42a8a55c3752a8819da37708cefa3..3aebefefbafd428115dcc47837feb00829e7e93b 100644 (file)
 //
 
 #include "PartSet_IconFactory.h"
+#include "PartSet_Tools.h"
+#include "PartSet_Module.h"
+#include "XGUI_DataModel.h"
+
+#include <XGUI_Workshop.h>
+#include <XGUI_ObjectsBrowser.h>
+
 #include <ModuleBase_ActionInfo.h>
 #include <ModuleBase_Tools.h>
 
@@ -33,7 +40,8 @@
 
 QMap<QString, QString> PartSet_IconFactory::myIcons;
 
-PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
+PartSet_IconFactory::PartSet_IconFactory(PartSet_Module* theModule)
+  : ModuleBase_IconFactory(), myModule(theModule)
 {
   Events_Loop::loop()->registerListener(this,
     Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
@@ -42,55 +50,79 @@ PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
 
 QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
 {
-  QIcon anIcon;
-
   if (!theObj.get())
-    return anIcon;
+    return QIcon();
 
+  std::string aGroup = theObj->groupName();
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
   if (aFeature.get()) {
     std::string aKind = aFeature->getKind();
     QString aId(aKind.c_str());
     if (!myIcons.contains(aId))
-      return anIcon;
+      return QIcon();
 
     QString anIconString = myIcons[aId];
 
     ModelAPI_ExecState aState = aFeature->data()->execState();
-    switch(aState) {
-      case ModelAPI_StateDone:
-      case ModelAPI_StateNothing: {
-        anIcon = loadIcon(anIconString);
-      }
+    switch (aState) {
+    case ModelAPI_StateMustBeUpdated:
+      return ModuleBase_Tools::composite(":icons/toWork.png", anIconString);
+      //anIcon = ModuleBase_Tools::lighter(anIconString);
       break;
-      case ModelAPI_StateMustBeUpdated: {
-        anIcon = ModuleBase_Tools::composite(":icons/toWork.png", anIconString);
-        //anIcon = ModuleBase_Tools::lighter(anIconString);
-      }
+    case ModelAPI_StateExecFailed:
+      return ModuleBase_Tools::composite(":icons/isFailed.png", anIconString);
       break;
-      case ModelAPI_StateExecFailed: {
-        anIcon = ModuleBase_Tools::composite(":icons/isFailed.png", anIconString);
-      }
+    case ModelAPI_StateInvalidArgument:
+      return ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
+        anIconString);
       break;
-      case ModelAPI_StateInvalidArgument: {
-        anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
-                                             anIconString);
-      }
+    default:
+      return loadIcon(anIconString);
       break;
-      default: break;
     }
   }
 
   //if (theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
   //  return QIcon(":pictures/constr_object_modified.png");
 
-  std::string aGroup = theObj->groupName();
   if (aGroup == ModelAPI_ResultPart::group())
     return QIcon(":pictures/part_ico.png");
 
   if (aGroup == ModelAPI_ResultConstruction::group())
     return QIcon(":pictures/constr_object.png");
 
+  if (aGroup == ModelAPI_Folder::group()) {
+    static QString anIconString(":pictures/features_folder.png");
+    int aFirst = -1, aLast = -1;
+    PartSet_Tools::getFirstAndLastIndexInFolder(theObj, aFirst, aLast);
+    if ((aFirst != -1) && (aLast != -1)) {
+      int aNbItems = aLast - aFirst + 1;
+      if (aNbItems) {
+        XGUI_ObjectsBrowser* aObBrowser = myModule->getWorkshop()->objectBrowser();
+        XGUI_DataTree* aTree = aObBrowser->treeView();
+        QModelIndex aIndex = aTree->dataModel()->objectIndex(theObj, 0);
+        if (!aTree->isExpanded(aIndex)) {
+          DocumentPtr aDoc = theObj->document();
+          ObjectPtr aSubObj;
+          ModelAPI_ExecState aState;
+          bool aHasWarning = false;
+          for (int i = aFirst; i < aLast + 1; i++) {
+            aSubObj = aDoc->object(ModelAPI_Feature::group(), i);
+            aState = aSubObj->data()->execState();
+            if ((aState == ModelAPI_StateExecFailed) || (aState == ModelAPI_StateMustBeUpdated)) {
+              aHasWarning = true;
+              break;
+            }
+          }
+          if (aHasWarning) {
+            return QIcon(ModuleBase_Tools::composite(":icons/hasWarning.png", anIconString));
+          }
+        }
+      }
+    }
+    return loadIcon(anIconString);
+  }
+
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
   if (aResult.get()) {
     GeomShapePtr aShape = aResult->shape();
@@ -125,7 +157,7 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
       }
     }
   }
-  return anIcon;
+  return QIcon();
 }
 
 void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
index 092754e28e0ba0551b46aead6ecb4b268da741df..34906ae3332a214e1193a04ae119630062508eb0 100644 (file)
@@ -28,6 +28,8 @@
 #include <QMap>
 
 
+class PartSet_Module;
+
 /**\class PartSet_IconFactory
  * \ingroup GUI
  * \brief This is a class is redefined in order to provide
@@ -37,7 +39,7 @@ class PARTSET_EXPORT PartSet_IconFactory : public ModuleBase_IconFactory, public
 {
 public:
   /// Constructor
-  PartSet_IconFactory();
+  PartSet_IconFactory(PartSet_Module* theModule);
 
   /// Returns Icon for the given object
   /// \param theObj an object
@@ -49,6 +51,7 @@ public:
 
 private:
   static QMap<QString, QString> myIcons;
+  PartSet_Module* myModule;
 };
 
 #endif
\ No newline at end of file
index aa7b4e383f47e0d4298d138e4c26fb6407b0a877..c6dcfa2281a349f75478c44aedeb2c48a1e0d581 100755 (executable)
@@ -156,7 +156,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   myRoot(0),
   myIsOperationIsLaunched(false)
 {
-  new PartSet_IconFactory();
+  new PartSet_IconFactory(this);
 
   mySketchMgr = new PartSet_SketcherMgr(this);
   mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
index 4c77d6c16993bb4fd95b4cb1696a2fe57a4fd3be..7e030c5aa470a4c8e0eb5850731eede4c11d9ef8 100755 (executable)
@@ -752,3 +752,29 @@ ResultPtr PartSet_Tools::createFixedByExternalCenter(
 
   return ResultPtr();
 }
+
+void PartSet_Tools::getFirstAndLastIndexInFolder(const ObjectPtr& theFolder,
+  int& theFirst, int& theLast)
+{
+  DocumentPtr aDoc = theFolder->document();
+  FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(theFolder);
+  if (!aFolder.get())
+    return;
+
+  AttributeReferencePtr aFirstFeatAttr = aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+  FeaturePtr aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
+  if (!aFirstFeatureInFolder.get()) {
+    theFirst = -1;
+    return;
+  }
+  AttributeReferencePtr aLastFeatAttr =
+    aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+  FeaturePtr aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+  if (!aLastFeatureInFolder.get()) {
+    theLast = -1;
+    return;
+  }
+
+  theFirst = aDoc->index(aFirstFeatureInFolder);
+  theLast = aDoc->index(aLastFeatureInFolder);
+}
\ No newline at end of file
index b76e1dd4449892fedd0047668f439fcacda3d8c0..2e88b022bca0e8f4be6f98c87e30b2d9f25151e4 100755 (executable)
@@ -292,6 +292,8 @@ public:
                                                bool theTemporary,
                                                FeaturePtr& theCreatedFeature);
 
+
+  static void getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, int& theFirst, int& theLast);
 };
 
 #endif
index 08e9e3681a3fe8c1f15e5e6ddda9ed6097153687..e8acf5f61d42c2321c4de8c27d13b1108de6bcce 100644 (file)
@@ -19,6 +19,7 @@
 //
 
 #include "PartSet_TreeNodes.h"
+#include "PartSet_Tools.h"
 
 #include <ModuleBase_IconFactory.h>
 #include <ModuleBase_IWorkshop.h>
@@ -122,10 +123,7 @@ QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
         return QIcon(":pictures/eyeclosed.png");
       }
     case 1:
-      if (myObject->groupName() == ModelAPI_Folder::group())
-        return QIcon(":pictures/features_folder.png");
-      else
-        return ModuleBase_IconFactory::get()->getIcon(myObject);
+      return ModuleBase_IconFactory::get()->getIcon(myObject);
     case 2:
       if (isCurrentFeature(myObject))
         return QIcon(":pictures/arrow.png");
@@ -1024,8 +1022,8 @@ QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
 //////////////////////////////////////////////////////////////////////////////////
 void PartSet_ObjectFolderNode::update()
 {
-  int aFirst, aLast;
-  getFirstAndLastIndex(aFirst, aLast);
+  int aFirst = -1, aLast = -1;
+  PartSet_Tools::getFirstAndLastIndexInFolder(myObject, aFirst, aLast);
   if ((aFirst == -1) || (aLast == -1)) {
     deleteChildren();
     return;
@@ -1081,8 +1079,8 @@ void PartSet_ObjectFolderNode::update()
 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
 {
   QTreeNodesList aResult;
-  int aFirst, aLast;
-  getFirstAndLastIndex(aFirst, aLast);
+  int aFirst = -1, aLast = -1;
+  PartSet_Tools::getFirstAndLastIndexInFolder(myObject, aFirst, aLast);
   if ((aFirst == -1) || (aLast == -1)) {
     return aResult;
   }
@@ -1114,8 +1112,8 @@ QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDo
   const QString& theGroup)
 {
   QTreeNodesList aResult;
-  int aFirst, aLast;
-  getFirstAndLastIndex(aFirst, aLast);
+  int aFirst = -1, aLast = -1;
+  PartSet_Tools::getFirstAndLastIndexInFolder(myObject, aFirst, aLast);
   if ((aFirst == -1) || (aLast == -1)) {
     return aResult;
   }
@@ -1155,60 +1153,6 @@ QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDo
   return aResult;
 }
 
-FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
-{
-  FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
-  AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
-  if (aFeatAttr)
-    return ModelAPI_Feature::feature(aFeatAttr->value());
-  return FeaturePtr();
-}
-
-void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
-{
-  DocumentPtr aDoc = myObject->document();
-  FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
-
-  FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
-  if (!aFirstFeatureInFolder.get()) {
-    theFirst = -1;
-    return;
-  }
-  FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
-  if (!aLastFeatureInFolder.get()) {
-    theLast = -1;
-    return;
-  }
-
-  theFirst = aDoc->index(aFirstFeatureInFolder);
-  theLast = aDoc->index(aLastFeatureInFolder);
-}
-
-
-QVariant PartSet_ObjectFolderNode::data(int theColumn, int theRole) const
-{
-  const QImage anAditional(":icons/hasWarning.png");
-
-  if ((theRole == Qt::DecorationRole) && (theColumn == 1)) {
-    ObjectPtr aObject;
-    bool aHasWarning = false;
-    foreach(ModuleBase_ITreeNode* aNode, myChildren) {
-      aObject = aNode->object();
-      if (aObject.get()) {
-        ModelAPI_ExecState aState = aObject->data()->execState();
-        if ((aState == ModelAPI_StateExecFailed) || (aState == ModelAPI_StateMustBeUpdated)) {
-          aHasWarning = true;
-          break;
-        }
-      }
-    }
-    if (aHasWarning) {
-      return QIcon(ModuleBase_Tools::composite(":icons/hasWarning.png",
-                                               ":pictures/features_folder.png"));
-    }
-  }
-  return PartSet_ObjectNode::data(theColumn, theRole);
-}
 
 
 //////////////////////////////////////////////////////////////////////////////////
index 4e37df89cf8c9eebf0fce08f6d1b497a3070cacb..5961121e99e4acd9f62bdfa15c060ee612f57049 100644 (file)
@@ -326,14 +326,6 @@ public:
   /// \param theDoc a document where objects were deleted
   /// \param theGroup a name of group where objects were deleted
   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
-
-  /// Returns the node representation according to theRole.
-  virtual QVariant data(int theColumn, int theRole) const;
-
-private:
-  FeaturePtr getFeature(const std::string& theId) const;
-
-  void getFirstAndLastIndex(int& theFirst, int& theLast) const;
 };
 
 
index c0507306554db1acea9b123afedfcdf72bf7e576..e2a4579404b2eaa8217652c051bf1d578a22e85a 100644 (file)
@@ -90,7 +90,7 @@ private:
 * \ingroup GUI
 * Implementation of Data Tree object for Object Browser
 */
-class XGUI_DataTree : public QTreeView
+class XGUI_EXPORT XGUI_DataTree : public QTreeView
 {
 Q_OBJECT
  public: