Salome HOME
ccb90aae2a3e3afe9393656009888dc288ce2169
[modules/shaper.git] / src / XGUI / XGUI_DocumentDataModel.cpp
1 #include "XGUI_DocumentDataModel.h"
2
3 #include <ModelAPI_PluginManager.h>
4 #include <ModelAPI_Iterator.h>
5 #include <ModelAPI_Document.h>
6
7
8
9
10 XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
11   : QAbstractItemModel(theParent),
12   myParamsFolder(0),
13   myConstructFolder(0)
14 {
15   //std::shared_ptr<ModelAPI_Feature> myRoot = aMgr->createFeature("Point");
16   std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
17   myDocument = aMgr->currentDocument();
18 }
19
20
21 XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
22 {
23 }
24
25
26 QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const
27 {
28   switch (theRole) {
29   case Qt::DisplayRole:
30     // return a name
31     if (theIndex.internalId() == quintptr(&myParamsFolder))
32       return "Parameters";
33     else if (theIndex.internalId() == quintptr(&myConstructFolder))
34       return "Constructions";
35     else if (theIndex.internalId() == 0) {
36       return "Part";
37     }
38     break;
39   case Qt::DecorationRole:
40     // return an Icon
41     break;
42   case Qt::ToolTipRole:
43     // return Tooltip
44     break;
45   }
46   return QVariant();
47 }
48
49
50 QVariant XGUI_DocumentDataModel::headerData(int section, Qt::Orientation orientation, int role) const
51 {
52   return QVariant();
53 }
54
55 int XGUI_DocumentDataModel::rowCount(const QModelIndex &parent) const
56 {
57   std::shared_ptr<ModelAPI_Iterator> aIt = myDocument->featuresIterator(PARTS_GROUP);
58   int a = aIt->numIterationsLeft();
59   return aIt->numIterationsLeft() + 2;
60 }
61
62 int XGUI_DocumentDataModel::columnCount(const QModelIndex &parent) const
63 {
64   return 1;
65 }
66
67 QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
68 {
69   switch (theRow) {
70   case 0:
71     return createIndex(theRow, theColumn, (quintptr) &myParamsFolder);
72   case 1:
73     return createIndex(theRow, theColumn, (quintptr) &myConstructFolder);
74   default:
75     {
76       std::shared_ptr<ModelAPI_Iterator> aIt = myDocument->featuresIterator(PARTS_GROUP);
77       if (aIt->numIterationsLeft() <= (theRow - 1)) {
78         return createIndex(theRow, theColumn, (quintptr) 0);
79       }
80     }
81   }
82   return QModelIndex();
83 }
84
85
86 QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex &index) const
87 {
88   return QModelIndex();
89 }
90
91 bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const
92 {
93   if (!theParent.isValid())
94     return true;
95
96   if (theParent.internalId() == quintptr(&myParamsFolder)) 
97     return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
98   if (theParent.internalId() == quintptr(&myConstructFolder))
99     return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
100   return false;
101 }