Salome HOME
Switching back to qt 4.8.4. Do not forget to fetch the qt product from \\slotex
[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   return aIt->numIterationsLeft() + 2;
59 }
60
61 int XGUI_DocumentDataModel::columnCount(const QModelIndex &parent) const
62 {
63   return 1;
64 }
65
66 QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
67 {
68   switch (theRow) {
69   case 0:
70     return createIndex(theRow, theColumn, (quintptr) &myParamsFolder);
71   case 1:
72     return createIndex(theRow, theColumn, (quintptr) &myConstructFolder);
73   default:
74     {
75       std::shared_ptr<ModelAPI_Iterator> aIt = myDocument->featuresIterator(PARTS_GROUP);
76       if (aIt->numIterationsLeft() <= (theRow - 1)) {
77         return createIndex(theRow, theColumn, (quintptr) 0);
78       }
79     }
80   }
81   return QModelIndex();
82 }
83
84
85 QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex &index) const
86 {
87   return QModelIndex();
88 }
89
90 bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const
91 {
92   if (!theParent.isValid())
93     return true;
94
95   if (theParent.internalId() == quintptr(&myParamsFolder)) 
96     return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
97   if (theParent.internalId() == quintptr(&myConstructFolder))
98     return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
99   if (theParent.internalId() == 0)
100     return false;
101   return false;
102 }