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 if (theIndex.model() == this) {
28 if (theIndex.internalId() == ParamsFolder)
29 return tr("Parameters");
31 if (theIndex.internalId() == ParamObject) {
32 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
33 return aFeature->data()->getName().c_str();
35 if (theIndex.internalId() == ConstructFolder)
36 return tr("Constructions");
38 if (theIndex.internalId() == ConstructObject) {
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 if (theIndex.model() == this) {
48 if (theIndex.internalId() == ParamsFolder)
49 return QIcon(":pictures/params_folder.png");
50 else if (theIndex.internalId() == ConstructFolder)
51 return QIcon(":pictures/constr_folder.png");
62 QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const
67 int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
69 if (!theParent.isValid())
72 if (theParent.internalId() == ParamsFolder)
73 return myDocument->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
75 if (theParent.internalId() == ConstructFolder)
76 return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
81 int XGUI_TopDataModel::columnCount(const QModelIndex &parent) const
86 QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
88 if (!theParent.isValid()) {
91 return createIndex(theRow, theColumn, (quintptr) ParamsFolder);
93 return createIndex(theRow, theColumn, (quintptr) ConstructFolder);
96 if (theParent.internalId() == ParamsFolder)
97 return createIndex(theRow, theColumn, (quintptr) ParamObject);
99 if (theParent.internalId() == ConstructFolder)
100 return createIndex(theRow, theColumn, (quintptr) ConstructObject);
102 return QModelIndex();
105 QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const
107 int aId = (int)theIndex.internalId();
110 case ConstructFolder:
111 return QModelIndex();
113 return createIndex(0, 0, (quintptr) ParamsFolder);
114 case ConstructObject:
115 return createIndex(1, 0, (quintptr) ConstructFolder);
117 return QModelIndex();
120 bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const
122 if (!theParent.isValid())
125 int aId = (int)theParent.internalId();
128 return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
129 case ConstructFolder:
130 return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
132 case ConstructObject:
139 //******************************************************************
140 //******************************************************************
141 //******************************************************************
142 XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
143 : QAbstractItemModel(theParent)
148 XGUI_PartDataModel::~XGUI_PartDataModel()
152 QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const
155 case Qt::DisplayRole:
157 if (theIndex.internalId() == MyRoot) {
158 std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
159 return aFeature->data()->getName().c_str();
161 if (theIndex.internalId() == ParamsFolder)
162 return tr("Parameters");
163 if (theIndex.internalId() == ConstructFolder)
164 return tr("Constructions");
166 case Qt::DecorationRole:
168 if (theIndex.internalId() == MyRoot)
169 return QIcon(":pictures/part_ico.png");
170 if (theIndex.internalId() == ParamsFolder)
171 return QIcon(":pictures/params_folder.png");
172 if (theIndex.internalId() == ConstructFolder)
173 return QIcon(":pictures/constr_folder.png");
175 case Qt::ToolTipRole:
182 QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const
187 int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
189 if (!parent.isValid())
190 if (myDocument->feature(PARTS_GROUP, myId))
194 if (parent.internalId() == MyRoot)
199 int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const
204 QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
206 if (!theParent.isValid())
207 return createIndex(theRow, 0, (quintptr) MyRoot);
209 int aId = (int)theParent.internalId();
214 return createIndex(0, 0, (quintptr) ParamsFolder);
216 return createIndex(1, 0, (quintptr) ConstructFolder);
219 return createIndex(theRow, 0, (quintptr) ParamObject);
220 case ConstructFolder:
221 return createIndex(theRow, 0, (quintptr) ConstructObject);
223 return QModelIndex();
226 QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
228 int aId = (int)theIndex.internalId();
231 return QModelIndex();
233 case ConstructFolder:
234 return createIndex(0, 0, (quintptr) MyRoot);
236 return createIndex(0, 0, (quintptr) ParamsFolder);
237 case ConstructObject:
238 return createIndex(1, 0, (quintptr) ConstructFolder);
240 return QModelIndex();
243 bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
245 if (!theParent.isValid())
246 return myDocument->feature(PARTS_GROUP, myId);
248 int aId = (int)theParent.internalId();
253 return false; // TODO
254 case ConstructFolder:
255 return false; // TODO
257 case ConstructObject: