From 2b19309921a73f672d44f57eeb08a3a32e9fc56a Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 28 Jul 2014 16:19:00 +0400 Subject: [PATCH] Bodies folder in Root data tree --- src/XGUI/XGUI_PartDataModel.cpp | 55 +++++++++++++++++++++++++-------- src/XGUI/XGUI_PartDataModel.h | 4 ++- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 5a5af7888..0b1d2dc9e 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -48,8 +49,9 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); if (aObject) - return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); + return aObject->data()->name().c_str(); } + break; case ConstructFolder: return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); case ConstructObject: @@ -57,7 +59,17 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); if (aObject) - return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); + return aObject->data()->name().c_str(); + } + break; + case BodiesFolder: + return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); + case BodiesObject: + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); } } break; @@ -67,16 +79,12 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const switch (theIndex.internalId()) { case ParamsFolder: return QIcon(":pictures/params_folder.png"); + case BodiesFolder: case ConstructFolder: return QIcon(":pictures/constr_folder.png"); case ConstructObject: + case BodiesObject: return QIcon(":pictures/constr_object.png"); - //{ - // DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - // if (aObject) - // return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); - //} } break; @@ -98,7 +106,7 @@ QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const { if (!theParent.isValid()) - return 2; + return 3; DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); if (theParent.internalId() == ParamsFolder) @@ -106,6 +114,9 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const if (theParent.internalId() == ConstructFolder) return aRootDoc->size(ModelAPI_ResultConstruction::group()); + + if (theParent.internalId() == BodiesFolder) + return aRootDoc->size(ModelAPI_ResultBody::group()); return 0; } @@ -122,6 +133,8 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde return createIndex(theRow, theColumn, (qint32) ParamsFolder); case 1: return createIndex(theRow, theColumn, (qint32) ConstructFolder); + case 2: + return createIndex(theRow, theColumn, (qint32) BodiesFolder); } } else { if (theParent.internalId() == ParamsFolder) @@ -129,6 +142,9 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde if (theParent.internalId() == ConstructFolder) return createIndex(theRow, theColumn, (qint32) ConstructObject); + + if (theParent.internalId() == BodiesFolder) + return createIndex(theRow, theColumn, (qint32) BodiesObject); } return QModelIndex(); } @@ -139,11 +155,14 @@ QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const switch (aId) { case ParamsFolder: case ConstructFolder: + case BodiesFolder: return QModelIndex(); case ParamObject: return createIndex(0, 0, (qint32) ParamsFolder); case ConstructObject: return createIndex(1, 0, (qint32) ConstructFolder); + case BodiesObject: + return createIndex(2, 0, (qint32) BodiesFolder); } return QModelIndex(); } @@ -158,6 +177,7 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const switch (theIndex.internalId()) { case ParamsFolder: case ConstructFolder: + case BodiesFolder: return ObjectPtr(); case ParamObject: { @@ -169,6 +189,11 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); } + case BodiesObject: + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + return aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); + } } return ObjectPtr(); } @@ -181,10 +206,12 @@ QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const QModelIndex XGUI_TopDataModel::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 == ModelAPI_ResultBody::group()) + return createIndex(2, 0, (qint32) BodiesFolder); return QModelIndex(); } @@ -203,10 +230,12 @@ QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const } } if (aRow != -1) { - if (aGroup.compare(ModelAPI_ResultParameters::group()) == 0) + if (aGroup == ModelAPI_ResultParameters::group()) return createIndex(aRow, 0, (qint32) ParamObject); - if (aGroup.compare(ModelAPI_ResultConstruction::group()) == 0) + if (aGroup == ModelAPI_ResultConstruction::group()) return createIndex(aRow, 0, (qint32) ConstructObject); + if (aGroup == ModelAPI_ResultBody::group()) + return createIndex(aRow, 0, (qint32) BodiesObject); } } return aIndex; diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index b170ec1cd..87e5d7f42 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -52,7 +52,9 @@ private: ParamsFolder, ParamObject, ConstructFolder, - ConstructObject + ConstructObject, + BodiesFolder, + BodiesObject }; }; -- 2.39.2