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(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());
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;
127 FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
129 switch (theIndex.internalId()) {
131 case ConstructFolder:
134 return myDocument->feature(PARAMETERS_GROUP, theIndex.row());
135 case ConstructObject:
136 return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
142 //******************************************************************
143 //******************************************************************
144 //******************************************************************
145 XGUI_PartDataModel::XGUI_PartDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
146 : XGUI_PartModel(theDocument, theParent)
151 XGUI_PartDataModel::~XGUI_PartDataModel()
155 QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const
158 case Qt::DisplayRole:
160 switch (theIndex.internalId()) {
163 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
164 return aFeature->data()->getName().c_str();
167 return tr("Parameters");
168 case ConstructFolder:
169 return tr("Constructions");
172 std::shared_ptr<ModelAPI_Feature> aFeature =
173 featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
174 return aFeature->data()->getName().c_str();
176 case ConstructObject:
178 std::shared_ptr<ModelAPI_Feature> aFeature =
179 featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
180 return aFeature->data()->getName().c_str();
184 case Qt::DecorationRole:
186 switch (theIndex.internalId()) {
188 return QIcon(":pictures/part_ico.png");
190 return QIcon(":pictures/params_folder.png");
191 case ConstructFolder:
192 return QIcon(":pictures/constr_folder.png");
193 case ConstructObject:
194 return QIcon(":pictures/point_ico.png");
197 case Qt::ToolTipRole:
204 QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const
209 int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
211 if (!parent.isValid())
212 if (myDocument->feature(PARTS_GROUP, myId))
216 switch (parent.internalId()) {
220 return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
221 case ConstructFolder:
222 return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
227 int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const
232 QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
234 if (!theParent.isValid())
235 return createIndex(theRow, 0, (quintptr) MyRoot);
237 int aId = (int)theParent.internalId();
242 return createIndex(0, 0, (quintptr) ParamsFolder);
244 return createIndex(1, 0, (quintptr) ConstructFolder);
247 return createIndex(theRow, 0, (quintptr) ParamObject);
248 case ConstructFolder:
249 return createIndex(theRow, 0, (quintptr) ConstructObject);
251 return QModelIndex();
254 QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
256 switch (theIndex.internalId()) {
258 return QModelIndex();
260 case ConstructFolder:
261 return createIndex(0, 0, (quintptr) MyRoot);
263 return createIndex(0, 0, (quintptr) ParamsFolder);
264 case ConstructObject:
265 return createIndex(1, 0, (quintptr) ConstructFolder);
267 return QModelIndex();
270 bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
272 return rowCount(theParent) > 0;
276 std::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
278 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
279 return aFeature->data()->docRef("PartDocument")->value();
282 FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
284 switch (theIndex.internalId()) {
286 return myDocument->feature(PARTS_GROUP, myId);
288 case ConstructFolder:
291 return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
292 case ConstructObject:
293 return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());