1 #include "XGUI_PartDataModel.h"
3 #include <ModelAPI_PluginManager.h>
4 #include <ModelAPI_Iterator.h>
5 #include <ModelAPI_Document.h>
6 #include <ModelAPI_Feature.h>
7 #include <ModelAPI_Object.h>
8 #include <ModelAPI_AttributeDocRef.h>
12 XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent)
13 : QAbstractItemModel(theParent)
17 XGUI_TopDataModel::~XGUI_TopDataModel()
22 QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
27 switch (theIndex.internalId()) {
29 return tr("Parameters");
32 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
33 return aFeature->data()->getName().c_str();
36 return tr("Constructions");
39 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
40 return aFeature->data()->getName().c_str();
45 case Qt::DecorationRole:
47 switch (theIndex.internalId()) {
49 return QIcon(":pictures/params_folder.png");
51 return QIcon(":pictures/constr_folder.png");
53 return QIcon(":pictures/point_ico.png");
64 QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const
69 int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
71 if (!theParent.isValid())
74 if (theParent.internalId() == ParamsFolder)
75 return myDocument->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
77 if (theParent.internalId() == ConstructFolder)
78 return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
83 int XGUI_TopDataModel::columnCount(const QModelIndex &parent) const
88 QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
90 if (!theParent.isValid()) {
93 return createIndex(theRow, theColumn, (quintptr) ParamsFolder);
95 return createIndex(theRow, theColumn, (quintptr) ConstructFolder);
98 if (theParent.internalId() == ParamsFolder)
99 return createIndex(theRow, theColumn, (quintptr) ParamObject);
101 if (theParent.internalId() == ConstructFolder)
102 return createIndex(theRow, theColumn, (quintptr) ConstructObject);
104 return QModelIndex();
107 QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const
109 int aId = (int)theIndex.internalId();
112 case ConstructFolder:
113 return QModelIndex();
115 return createIndex(0, 0, (quintptr) ParamsFolder);
116 case ConstructObject:
117 return createIndex(1, 0, (quintptr) ConstructFolder);
119 return QModelIndex();
122 bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const
124 return rowCount(theParent) > 0;
128 //******************************************************************
129 //******************************************************************
130 //******************************************************************
131 XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
132 : QAbstractItemModel(theParent)
137 XGUI_PartDataModel::~XGUI_PartDataModel()
141 QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const
144 case Qt::DisplayRole:
146 switch (theIndex.internalId()) {
149 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
150 return aFeature->data()->getName().c_str();
153 return tr("Parameters");
154 case ConstructFolder:
155 return tr("Constructions");
158 std::shared_ptr<ModelAPI_Feature> aFeature =
159 featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
160 return aFeature->data()->getName().c_str();
162 case ConstructObject:
164 std::shared_ptr<ModelAPI_Feature> aFeature =
165 featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
166 return aFeature->data()->getName().c_str();
170 case Qt::DecorationRole:
172 switch (theIndex.internalId()) {
174 return QIcon(":pictures/part_ico.png");
176 return QIcon(":pictures/params_folder.png");
177 case ConstructFolder:
178 return QIcon(":pictures/constr_folder.png");
179 case ConstructObject:
180 return QIcon(":pictures/point_ico.png");
183 case Qt::ToolTipRole:
190 QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const
195 int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
197 if (!parent.isValid())
198 if (myDocument->feature(PARTS_GROUP, myId))
202 switch (parent.internalId()) {
206 return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
207 case ConstructFolder:
208 return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
213 int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const
218 QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
220 if (!theParent.isValid())
221 return createIndex(theRow, 0, (quintptr) MyRoot);
223 int aId = (int)theParent.internalId();
228 return createIndex(0, 0, (quintptr) ParamsFolder);
230 return createIndex(1, 0, (quintptr) ConstructFolder);
233 return createIndex(theRow, 0, (quintptr) ParamObject);
234 case ConstructFolder:
235 return createIndex(theRow, 0, (quintptr) ConstructObject);
237 return QModelIndex();
240 QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
242 int aId = (int)theIndex.internalId();
245 return QModelIndex();
247 case ConstructFolder:
248 return createIndex(0, 0, (quintptr) MyRoot);
250 return createIndex(0, 0, (quintptr) ParamsFolder);
251 case ConstructObject:
252 return createIndex(1, 0, (quintptr) ConstructFolder);
254 return QModelIndex();
257 bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
259 return rowCount(theParent) > 0;
263 std::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
265 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
266 return aFeature->data()->docRef("PartDocument")->value();