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_Data.h>
8 #include <ModelAPI_AttributeDocRef.h>
12 XGUI_TopDataModel::XGUI_TopDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
13 : XGUI_FeaturesModel(theDocument, 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());
34 return aFeature->data()->getName().c_str();
37 return tr("Constructions");
40 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
42 return aFeature->data()->getName().c_str();
47 case Qt::DecorationRole:
49 switch (theIndex.internalId()) {
51 return QIcon(":pictures/params_folder.png");
53 return QIcon(":pictures/constr_folder.png");
55 return QIcon(":pictures/point_ico.png");
66 QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const
71 int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
73 if (!theParent.isValid())
76 if (theParent.internalId() == ParamsFolder)
77 return myDocument->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
79 if (theParent.internalId() == ConstructFolder)
80 return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
85 int XGUI_TopDataModel::columnCount(const QModelIndex &parent) const
90 QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
92 if (!theParent.isValid()) {
95 return createIndex(theRow, theColumn, (quintptr) ParamsFolder);
97 return createIndex(theRow, theColumn, (quintptr) ConstructFolder);
100 if (theParent.internalId() == ParamsFolder)
101 return createIndex(theRow, theColumn, (quintptr) ParamObject);
103 if (theParent.internalId() == ConstructFolder)
104 return createIndex(theRow, theColumn, (quintptr) ConstructObject);
106 return QModelIndex();
109 QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const
111 int aId = (int)theIndex.internalId();
114 case ConstructFolder:
115 return QModelIndex();
117 return createIndex(0, 0, (quintptr) ParamsFolder);
118 case ConstructObject:
119 return createIndex(1, 0, (quintptr) ConstructFolder);
121 return QModelIndex();
124 bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const
126 return rowCount(theParent) > 0;
129 FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
131 switch (theIndex.internalId()) {
133 case ConstructFolder:
136 return myDocument->feature(PARAMETERS_GROUP, theIndex.row());
137 case ConstructObject:
138 return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
144 QModelIndex XGUI_TopDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
146 QString aGroup(theFeature->getGroup().c_str());
148 if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
149 return createIndex(0, 0, (quintptr) ParamsFolder);
150 if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
151 return createIndex(1, 0, (quintptr) ConstructFolder);
152 return QModelIndex();
156 //******************************************************************
157 //******************************************************************
158 //******************************************************************
159 XGUI_PartDataModel::XGUI_PartDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
160 : XGUI_PartModel(theDocument, theParent)
165 XGUI_PartDataModel::~XGUI_PartDataModel()
169 QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const
172 case Qt::DisplayRole:
174 switch (theIndex.internalId()) {
177 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
179 return aFeature->data()->getName().c_str();
182 return tr("Parameters");
183 case ConstructFolder:
184 return tr("Constructions");
187 std::shared_ptr<ModelAPI_Feature> aFeature =
188 featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
190 return aFeature->data()->getName().c_str();
192 case ConstructObject:
194 std::shared_ptr<ModelAPI_Feature> aFeature =
195 featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
197 return aFeature->data()->getName().c_str();
201 case Qt::DecorationRole:
203 switch (theIndex.internalId()) {
205 return QIcon(":pictures/part_ico.png");
207 return QIcon(":pictures/params_folder.png");
208 case ConstructFolder:
209 return QIcon(":pictures/constr_folder.png");
210 case ConstructObject:
211 return QIcon(":pictures/point_ico.png");
214 case Qt::ToolTipRole:
221 QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const
226 int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
228 if (!parent.isValid())
229 if (myDocument->feature(PARTS_GROUP, myId))
233 switch (parent.internalId()) {
237 return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
238 case ConstructFolder:
239 return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
244 int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const
249 QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
251 if (!theParent.isValid())
252 return createIndex(theRow, 0, (quintptr) MyRoot);
254 int aId = (int)theParent.internalId();
259 return createIndex(0, 0, (quintptr) ParamsFolder);
261 return createIndex(1, 0, (quintptr) ConstructFolder);
264 return createIndex(theRow, 0, (quintptr) ParamObject);
265 case ConstructFolder:
266 return createIndex(theRow, 0, (quintptr) ConstructObject);
268 return QModelIndex();
271 QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
273 switch (theIndex.internalId()) {
275 return QModelIndex();
277 case ConstructFolder:
278 return createIndex(0, 0, (quintptr) MyRoot);
280 return createIndex(0, 0, (quintptr) ParamsFolder);
281 case ConstructObject:
282 return createIndex(1, 0, (quintptr) ConstructFolder);
284 return QModelIndex();
287 bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
289 return rowCount(theParent) > 0;
293 std::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
295 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
296 return aFeature->data()->docRef("PartDocument")->value();
299 FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
301 switch (theIndex.internalId()) {
303 return myDocument->feature(PARTS_GROUP, myId);
305 case ConstructFolder:
308 return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
309 case ConstructObject:
310 return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
315 bool XGUI_PartDataModel::hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const
317 return (featureDocument() == theDoc);
321 QModelIndex XGUI_PartDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
323 QString aGroup(theFeature->getGroup().c_str());
325 if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
326 return createIndex(0, 0, (quintptr) ParamsFolder);
327 if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
328 return createIndex(1, 0, (quintptr) ConstructFolder);
329 return QModelIndex();