From: vsv Date: Wed, 3 Dec 2014 13:40:21 +0000 (+0300) Subject: Issue #274: hide Groups folder if there are no groups X-Git-Tag: V_0.6.0^2~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a9cbe53dc79a44457cff04f976903e15ba37bd60;p=modules%2Fshaper.git Issue #274: hide Groups folder if there are no groups --- diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index f80e5ae9f..2e95a24aa 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -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(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 diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index 8aec45dab..0d9a394af 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -111,6 +111,8 @@ Q_OBJECT //! Returns document of the current part DocumentPtr partDocument() const; + int getRowsNumber() const; + //! Types of QModelIndexes enum DataIds {