]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #274: hide Groups folder if there are no groups
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 3 Dec 2014 13:40:21 +0000 (16:40 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 3 Dec 2014 13:40:21 +0000 (16:40 +0300)
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_PartDataModel.h

index f80e5ae9f77161656ce82100fb5f848b1354db27..2e95a24aa7b85abd5e01e0eb02e2e032893d76ce 100644 (file)
@@ -295,7 +295,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
             return aObject->data()->name().c_str();
         }
         case HistoryObject: {
-          ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 4);
+          ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber());
           if (aObject)
             return aObject->data()->name().c_str();
         }
@@ -326,7 +326,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
           return QIcon(":pictures/constr_object.png");
         }
         case HistoryObject: {
-          ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 4);
+          ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber());
           FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
           if (aFeature)
             return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
@@ -361,9 +361,9 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
     case MyRoot:
       {
         DocumentPtr aDoc = partDocument();
-        if (aDoc)
-          return 4 + aDoc->size(ModelAPI_Feature::group());
-        else 
+        if (aDoc) {
+          return getRowsNumber() + aDoc->size(ModelAPI_Feature::group());
+        else 
           return 0;
       }
     case ParamsFolder:
@@ -399,7 +399,13 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd
         case 2:
           return createIndex(theRow, 0, (qint32) BodiesFolder);
         case 3:
-          return createIndex(theRow, 0, (qint32) GroupsFolder);
+          {
+          int aSize = partDocument()->size(ModelAPI_ResultGroup::group());
+          if (aSize > 0)
+            return createIndex(theRow, 0, (qint32) GroupsFolder);
+          else
+            return createIndex(theRow, theColumn, (qint32) HistoryObject);
+          }
         default:
           return createIndex(theRow, theColumn, (qint32) HistoryObject);
       }
@@ -476,7 +482,7 @@ ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const
     case GroupObject:
       return partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row());
     case HistoryObject:
-      return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 4);
+      return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber());
   }
   return ObjectPtr();
 }
@@ -493,13 +499,13 @@ QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const
 
 QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
 {
-  if (theGroup.compare(ModelAPI_ResultParameters::group()) == 0)
+  if (theGroup == ModelAPI_ResultParameters::group())
     return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theGroup.compare(ModelAPI_ResultConstruction::group()) == 0)
+  if (theGroup == ModelAPI_ResultConstruction::group())
     return createIndex(1, 0, (qint32) ConstructFolder);
-  if (theGroup.compare(ModelAPI_ResultBody::group()) == 0)
+  if (theGroup == ModelAPI_ResultBody::group())
     return createIndex(2, 0, (qint32) BodiesFolder);
-  if (theGroup.compare(ModelAPI_ResultGroup::group()) == 0)
+  if (theGroup == ModelAPI_ResultGroup::group())
     return createIndex(3, 0, (qint32) GroupsFolder);
   return QModelIndex();
 }
@@ -539,7 +545,16 @@ QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const
     else if (aGroup == ModelAPI_ResultGroup::group())
       return createIndex(aRow, 0, (qint32) GroupObject);
     else
-      return createIndex(aRow + 4, 0, (qint32) HistoryObject);
+      return createIndex(aRow + getRowsNumber(), 0, (qint32) HistoryObject);
   }
   return aIndex;
 }
+
+
+int XGUI_PartDataModel::getRowsNumber() const
+{
+  int aSize = partDocument()->size(ModelAPI_ResultGroup::group());
+  if (aSize == 0) // If there are no groups then do not show group folder
+    return 3;
+  return 4;
+}
\ No newline at end of file
index 8aec45dabe8475ed6968c7d1a65f953ee63c2348..0d9a394af72ef34037cf1e0bf6e5836b096033a4 100644 (file)
@@ -111,6 +111,8 @@ Q_OBJECT
   //! Returns document of the current part
   DocumentPtr partDocument() const;
 
+  int getRowsNumber() const;
+
   //! Types of QModelIndexes
   enum DataIds
   {