From 0b779059afbd6c2024e1453d3133044c52bea638 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 19 May 2014 14:43:37 +0400 Subject: [PATCH] Ptr definitiomns added --- src/ModelAPI/ModelAPI_Data.h | 3 +++ src/ModelAPI/ModelAPI_Document.h | 5 ++++ src/ModelAPI/ModelAPI_Feature.h | 4 +++ src/ModelAPI/ModelAPI_Object.h | 5 ++++ src/ModelAPI/ModelAPI_PluginManager.h | 3 +++ src/XGUI/XGUI_Constants.h | 3 --- src/XGUI/XGUI_DataTreeModel.h | 10 ++++--- src/XGUI/XGUI_PartDataModel.cpp | 38 +++++++++++++-------------- src/XGUI/XGUI_PartDataModel.h | 12 ++++----- 9 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 187654cd8..f8dd22896 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -70,4 +70,7 @@ protected: {} }; +typedef boost::shared_ptr DataPtr; + + #endif diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 311745a16..cc188d9d4 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -91,4 +91,9 @@ protected: {} }; + +//! Pointer on document object +typedef boost::shared_ptr DocumentPtr; + + #endif diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 1dd7b12db..eb4ba54f9 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -70,4 +70,8 @@ protected: friend class Model_Document; }; +//! Pointer on feature object +typedef boost::shared_ptr FeaturePtr; + + #endif diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 64240ce38..55ee09527 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -7,6 +7,8 @@ #include "ModelAPI_Feature.h" +#include + /**\class ModelAPI_Object * \ingroup DataModel * \brief Represents the result of some feature in the object browser @@ -30,4 +32,7 @@ public: MODELAPI_EXPORT virtual void setName(std::string theName) = 0; }; + +typedef boost::shared_ptr ObjectPtr; + #endif diff --git a/src/ModelAPI/ModelAPI_PluginManager.h b/src/ModelAPI/ModelAPI_PluginManager.h index ef3fa80df..47c42562f 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.h +++ b/src/ModelAPI/ModelAPI_PluginManager.h @@ -58,4 +58,7 @@ protected: friend class Model_Document; }; +typedef boost::shared_ptr PluginManagerPtr; + + #endif diff --git a/src/XGUI/XGUI_Constants.h b/src/XGUI/XGUI_Constants.h index 9255b5239..02f0001c1 100644 --- a/src/XGUI/XGUI_Constants.h +++ b/src/XGUI/XGUI_Constants.h @@ -10,9 +10,6 @@ typedef QList QIntList; //!< list of int values typedef QList QShortList; //!< list of short int values typedef QList QDoubleList; //!< list of double values - -//! Pointer on feature object -typedef boost::shared_ptr FeaturePtr; typedef QList QFeatureList; //!< List of features namespace XGUI diff --git a/src/XGUI/XGUI_DataTreeModel.h b/src/XGUI/XGUI_DataTreeModel.h index be7111292..42c609dac 100644 --- a/src/XGUI/XGUI_DataTreeModel.h +++ b/src/XGUI/XGUI_DataTreeModel.h @@ -6,6 +6,8 @@ #include "XGUI_Constants.h" #include +#include + #include #include @@ -16,7 +18,7 @@ class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel { public: - XGUI_FeaturesModel(const boost::shared_ptr& theDocument, QObject* theParent): + XGUI_FeaturesModel(const DocumentPtr& theDocument, QObject* theParent): QAbstractItemModel(theParent), myDocument(theDocument), myItemsColor(Qt::black) {} //! Returns Feature object by the given Model index. @@ -24,7 +26,7 @@ public: virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0; //! Returns parent index of the given feature - virtual QModelIndex findParent(const boost::shared_ptr& theFeature) const = 0; + virtual QModelIndex findParent(const FeaturePtr& theFeature) const = 0; //! Returns index corresponded to the group virtual QModelIndex findGroup(const std::string& theGroup) const = 0; @@ -46,13 +48,13 @@ protected: class XGUI_PartModel : public XGUI_FeaturesModel { public: - XGUI_PartModel(const boost::shared_ptr& theDocument, QObject* theParent): + XGUI_PartModel(const DocumentPtr& theDocument, QObject* theParent): XGUI_FeaturesModel(theDocument, theParent) {} void setPartId(int theId) { myId = theId; } //! Returns true if the given document is a sub-document of this tree - virtual bool hasDocument(const boost::shared_ptr& theDoc) const = 0; + virtual bool hasDocument(const DocumentPtr& theDoc) const = 0; //! Return a Part object virtual FeaturePtr part() const = 0; diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index fc5549846..2ce2c5a26 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -6,11 +6,12 @@ #include #include #include +#include #include #include -XGUI_TopDataModel::XGUI_TopDataModel(const boost::shared_ptr& theDocument, QObject* theParent) +XGUI_TopDataModel::XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent) : XGUI_FeaturesModel(theDocument, theParent) { } @@ -30,7 +31,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - boost::shared_ptr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row()); + FeaturePtr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row()); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -38,7 +39,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); case ConstructObject: { - boost::shared_ptr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -149,7 +150,7 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const } -QModelIndex XGUI_TopDataModel::findParent(const boost::shared_ptr& theFeature) const +QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const { QString aGroup(theFeature->getGroup().c_str()); @@ -173,7 +174,7 @@ QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const //****************************************************************** //****************************************************************** //****************************************************************** -XGUI_PartDataModel::XGUI_PartDataModel(const boost::shared_ptr& theDocument, QObject* theParent) +XGUI_PartDataModel::XGUI_PartDataModel(const DocumentPtr& theDocument, QObject* theParent) : XGUI_PartModel(theDocument, theParent) { } @@ -191,7 +192,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons switch (theIndex.internalId()) { case MyRoot: { - boost::shared_ptr aFeature = myDocument->feature(PARTS_GROUP, myId); + FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -203,22 +204,19 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); if (aFeature) return aFeature->data()->getName().c_str(); } case ConstructObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); if (aFeature) return aFeature->data()->getName().c_str(); } case HistoryObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -242,8 +240,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons } case HistoryObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } @@ -341,12 +338,15 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const } -boost::shared_ptr XGUI_PartDataModel::featureDocument() const +DocumentPtr XGUI_PartDataModel::featureDocument() const { - boost::shared_ptr aFeature = myDocument->feature(PARTS_GROUP, myId); + FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId); + ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); + if (aObject) + return aObject->featureRef()->data()->docRef("PartDocument")->value(); return aFeature->data()->docRef("PartDocument")->value(); } - + FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { @@ -366,13 +366,13 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const return FeaturePtr(); } -bool XGUI_PartDataModel::hasDocument(const boost::shared_ptr& theDoc) const +bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const { return (featureDocument() == theDoc); } -QModelIndex XGUI_PartDataModel::findParent(const boost::shared_ptr& theFeature) const +QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const { QString aGroup(theFeature->getGroup().c_str()); diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index 0c857f95b..a44dfb03c 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -14,7 +14,7 @@ class XGUI_EXPORT XGUI_TopDataModel : public XGUI_FeaturesModel { Q_OBJECT public: - XGUI_TopDataModel(const boost::shared_ptr& theDocument, QObject* theParent); + XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent); virtual ~XGUI_TopDataModel(); // Reimpl from QAbstractItemModel @@ -37,7 +37,7 @@ public: virtual FeaturePtr feature(const QModelIndex& theIndex) const; //! Returns parent index of the given feature - virtual QModelIndex findParent(const boost::shared_ptr& theFeature) const; + virtual QModelIndex findParent(const FeaturePtr& theFeature) const; //! Returns index corresponded to the group virtual QModelIndex findGroup(const std::string& theGroup) const; @@ -63,7 +63,7 @@ class XGUI_PartDataModel : public XGUI_PartModel { Q_OBJECT public: - XGUI_PartDataModel(const boost::shared_ptr& theDocument, QObject* theParent); + XGUI_PartDataModel(const DocumentPtr& theDocument, QObject* theParent); virtual ~XGUI_PartDataModel(); // Reimpl from QAbstractItemModel @@ -86,10 +86,10 @@ public: virtual FeaturePtr feature(const QModelIndex& theIndex) const; //! Returns true if the given document is a sub-document of this tree - virtual bool hasDocument(const boost::shared_ptr& theDoc) const; + virtual bool hasDocument(const DocumentPtr& theDoc) const; //! Returns parent index of the given feature - virtual QModelIndex findParent(const boost::shared_ptr& theFeature) const; + virtual QModelIndex findParent(const FeaturePtr& theFeature) const; //! Returns index corresponded to the group virtual QModelIndex findGroup(const std::string& theGroup) const; @@ -98,7 +98,7 @@ public: virtual FeaturePtr part() const; private: - boost::shared_ptr featureDocument() const; + DocumentPtr featureDocument() const; //! Types of QModelIndexes enum DataIds { -- 2.39.2