1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_DataModel.h"
22 //#include "XGUI_Workshop.h"
23 #include "XGUI_ObjectsBrowser.h"
24 //#include "XGUI_Displayer.h"
26 #include <ModuleBase_IconFactory.h>
27 #include <ModuleBase_ITreeNode.h>
29 #include <ModelAPI_Session.h>
30 //#include <ModelAPI_Events.h>
31 //#include <ModelAPI_ResultParameter.h>
32 //#include <ModelAPI_AttributeDouble.h>
33 //#include <ModelAPI_ResultPart.h>
34 //#include <ModelAPI_Feature.h>
35 //#include <ModelAPI_CompositeFeature.h>
36 //#include <ModelAPI_ResultCompSolid.h>
37 //#include <ModelAPI_ResultField.h>
38 //#include <ModelAPI_Tools.h>
39 //#include <ModelAPI_Folder.h>
40 //#include <ModelAPI_AttributeReference.h>
42 #include <Config_FeatureMessage.h>
43 //#include <Config_DataModelReader.h>
45 #include <Events_Loop.h>
52 //#define ACTIVE_COLOR QColor(Qt::black)
53 //#define ACTIVE_COLOR QColor(0,72,140)
54 //#define PASSIVE_COLOR Qt::black
56 /// Returns ResultPart object if the given object is a Part feature
57 /// Otherwise returns NULL
59 //#define SELECTABLE_COLOR QColor(110, 110, 110)
60 //#define DISABLED_COLOR QColor(200, 200, 200)
63 //ResultPartPtr getPartResult(ModelAPI_Object* theObj)
65 // ModelAPI_Feature* aFeature = dynamic_cast<ModelAPI_Feature*>(theObj);
67 // ResultPtr aRes = aFeature->firstResult();
68 // if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
69 // ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
70 // // Use only original parts, not a placement results
71 // if (aPartRes == aPartRes->original())
75 // return ResultPartPtr();
78 /// Returns pointer on document if the given object is document object
79 //ModelAPI_Document* getSubDocument(void* theObj)
81 // ModelAPI_Document* aDoc = 0;
83 // aDoc = dynamic_cast<ModelAPI_Document*>((ModelAPI_Entity*)theObj);
91 // Constructor *************************************************
92 XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)//,
93 //myIsEventsProcessingBlocked(false)
95 XGUI_ObjectsBrowser* aOB = qobject_cast<XGUI_ObjectsBrowser*>(theParent);
96 myWorkshop = aOB->workshop();
98 Events_Loop* aLoop = Events_Loop::loop();
99 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
100 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
101 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
102 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_ORDER_UPDATED));
103 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
106 XGUI_DataModel::~XGUI_DataModel()
111 //******************************************************
112 void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMessage)
114 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
115 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
116 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
117 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
118 QObjectPtrList aCreated;
119 std::set<ObjectPtr>::const_iterator aIt;
120 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
121 if ((*aIt)->isInHistory())
122 aCreated.append(*aIt);
124 QTreeNodesList aNodes = myRoot->objectCreated(aCreated);
125 ModuleBase_ITreeNode* aParent;
127 QModelIndex aParentIndex;
128 foreach(ModuleBase_ITreeNode* aNode, aNodes) {
129 aParent = aNode->parent();
130 aRow = aParent->nodeRow(aNode);
131 aParentIndex = getParentIndex(aNode, 0);
132 insertRows(aRow, 1, aParentIndex);
135 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
136 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
137 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
138 DocumentPtr aDoc = aUpdMsg->document();
139 std::set<std::string> aMsgGroups = aUpdMsg->groups();
140 std::set<std::string>::const_iterator aIt;
141 for (aIt = aMsgGroups.cbegin(); aIt != aMsgGroups.cend(); aIt++)
142 QTreeNodesList aList = myRoot->objectsDeleted(aDoc, (*aIt).c_str());
145 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
146 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
147 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
148 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
150 QObjectPtrList aCreated;
151 std::set<ObjectPtr>::const_iterator aIt;
152 bool aRebuildAll = false;
153 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
154 ObjectPtr aObj = (*aIt);
155 if (aObj->data()->isValid()) {
156 if (aObj->groupName() == ModelAPI_Folder::group()) {
160 if (aObj->isInHistory())
161 aCreated.append(*aIt);
168 foreach(ObjectPtr aObj, aCreated) {
169 ModuleBase_ITreeNode* aNode = myRoot->subNode(aObj);
171 QModelIndex aFirstIdx = getIndex(aNode, 0);
172 QModelIndex aLastIdx = getIndex(aNode, 2);
173 dataChanged(aFirstIdx, aLastIdx);
178 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
179 std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
180 std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
181 if (aUpdMsg->reordered().get()) {
182 DocumentPtr aDoc = aUpdMsg->reordered()->document();
183 std::string aGroup = aUpdMsg->reordered()->group();
184 ModuleBase_ITreeNode* aNode = myRoot->findParent(aDoc, aGroup.c_str());
187 updateSubTree(aNode);
191 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
192 DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument();
193 ModuleBase_ITreeNode* aRoot = myRoot->findRoot(aDoc);
195 updateSubTree(aRoot);
198 //if (myIsEventsProcessingBlocked)
200 //DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
201 //std::string aRootType = myXMLReader->rootType();
202 //std::string aSubType = myXMLReader->subType();
203 //int aNbFolders = foldersCount();
205 //// Created object event *******************
206 //if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
207 // std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
208 // std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
209 // std::set<ObjectPtr> aObjects = aUpdMsg->objects();
211 // std::set<ObjectPtr>::const_iterator aIt;
212 // std::string aObjType;
213 // for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
214 // ObjectPtr aObject = (*aIt);
215 // // We do not show objects which does not need to be shown in object browser
216 // if (!aObject->isInHistory())
219 // aObjType = aObject->groupName();
220 // DocumentPtr aDoc = aObject->document();
221 // if (aDoc == aRootDoc) {
222 // // Check that new folders could appear
223 // QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
224 // foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
225 // if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) > 0)) {
226 // // Appears first object in folder which can not be shown empty
227 // if (!hasShownFolder(aRootDoc, aNotEmptyFolder)) {
228 // insertRow(myXMLReader->rootFolderId(aObjType));
229 // addShownFolder(aRootDoc, aNotEmptyFolder);
233 // // Insert new object
234 // int aRow = aRootDoc->size(aObjType) - 1;
236 // if ((aObjType == aRootType) || (aObjType == ModelAPI_Folder::group())) {
237 // insertRow(aRow + aNbFolders + 1);
239 // int aFolderId = myXMLReader->rootFolderId(aObjType);
240 // if (aFolderId != -1) {
241 // insertRow(aRow, createIndex(aFolderId, 0, (void*)Q_NULLPTR));
246 // // Object created in sub-document
247 // QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0);
248 // if (aDocRoot.isValid()) {
249 // // Check that new folders could appear
250 // QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
251 // foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
252 // if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) > 0)) {
253 // // Appears first object in folder which can not be shown empty
254 // if (!hasShownFolder(aDoc, aNotEmptyFolder)) {
255 // insertRow(myXMLReader->subFolderId(aObjType), aDocRoot);
256 // addShownFolder(aDoc, aNotEmptyFolder);
260 // int aRow = aDoc->index(aObject, true);
262 // int aNbSubFolders = foldersCount(aDoc.get());
263 // if ((aObjType == aSubType) || (aObjType == ModelAPI_Folder::group())) {
264 // // List of objects under document root
265 // insertRow(aRow + aNbSubFolders, aDocRoot);
267 // // List of objects under a folder
269 // int aFolderId = folderId(aObjType, aDoc.get());
270 // if (aFolderId != -1) {
271 // QModelIndex aParentFolder = createIndex(aFolderId, 0, aDoc.get());
272 // insertRow(aRow, aParentFolder);
273 // emit dataChanged(aParentFolder, aParentFolder);
278 // rebuildDataTree();
282 // rebuildDataTree();
287 // // Deleted object event ***********************
288 //} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
289 // std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
290 // std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
291 // DocumentPtr aDoc = aUpdMsg->document();
292 // std::set<std::string> aMsgGroups = aUpdMsg->groups();
294 // /// Sort groups because RootType deletion has to be done after others
295 // std::string aType = (aDoc == aRootDoc)? aRootType : aSubType;
296 // std::list<std::string> aGroups;
297 // std::set<std::string>::const_iterator aSetIt;
298 // for (aSetIt = aMsgGroups.begin(); aSetIt != aMsgGroups.end(); ++aSetIt) {
299 // std::string aGroup = (*aSetIt);
300 // if (aGroup == aType)
301 // aGroups.push_back(aGroup);
303 // aGroups.push_front(aGroup);
306 // std::list<std::string>::const_iterator aIt;
307 // for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) {
308 // std::string aGroup = (*aIt);
309 // if (aDoc == aRootDoc) { // If root objects
310 // int aRow = aRootDoc->size(aGroup, true);
311 // if (aGroup == aRootType) {
312 // // Process root folder
313 // // remove optimization due to the issue #2456
314 // //removeRow(aRow + aNbFolders);
315 // //rebuildBranch(aNbFolders, aRow);
316 // rebuildDataTree();
317 // } else if (aGroup == ModelAPI_Folder::group()) {
318 // rebuildDataTree();
320 // // Process root sub-folder
321 // int aFolderId = myXMLReader->rootFolderId(aGroup);
322 // if (aFolderId != -1) {
323 // QModelIndex aFolderIndex = createIndex(aFolderId, 0, (void*)Q_NULLPTR);
324 // removeRow(aRow, aFolderIndex);
325 // //rebuildBranch(0, aRow);
328 // // Check that some folders could erased
329 // QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
330 // foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
331 // if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup, true) == 0)) {
332 // // Appears first object in folder which can not be shown empty
333 // removeRow(myXMLReader->rootFolderId(aGroup));
334 // removeShownFolder(aRootDoc, aNotEmptyFolder);
335 // //rebuildBranch(0, aNbFolders + aDoc->size(myXMLReader->rootType()));
340 // // Remove row for sub-document
341 // QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0);
342 // if (aDocRoot.isValid()) {
343 // int aRow = aDoc->size(aGroup, true);
344 // int aNbSubFolders = foldersCount(aDoc.get());
345 // if (aGroup == aSubType) {
346 // // List of objects under document root
347 // removeRow(aRow + aNbSubFolders, aDocRoot);
348 // rebuildBranch(aNbSubFolders, aRow, aDocRoot);
349 // } if (aGroup == ModelAPI_Folder::group()) {
350 // rebuildDataTree();
352 // // List of objects under a folder
353 // int aFolderId = folderId(aGroup, aDoc.get());
354 // if (aFolderId != -1) {
355 // QModelIndex aFolderRoot = createIndex(aFolderId, 0, aDoc.get());
356 // removeRow(aRow, aFolderRoot);
357 // //rebuildBranch(0, aRow, aFolderRoot);
360 // // Check that some folders could disappear
361 // QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
362 // int aSize = aDoc->size(aGroup, true);
363 // foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
364 // if ((aNotEmptyFolder.toStdString() == aGroup) && (aSize == 0)) {
365 // // Appears first object in folder which can not be shown empty
366 // removeRow(myXMLReader->subFolderId(aGroup), aDocRoot);
367 // removeShownFolder(aDoc, aNotEmptyFolder);
368 // //rebuildBranch(0, aNbSubFolders + aDoc->size(myXMLReader->subType()), aDocRoot);
373 // rebuildDataTree();
378 //} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
379 // std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
380 // std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
381 // std::set<ObjectPtr> aObjects = aUpdMsg->objects();
383 // std::set<ObjectPtr>::const_iterator aIt;
384 // for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
385 // ObjectPtr aObject = (*aIt);
386 // if (aObject->data()->isValid()) {
387 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
388 // if (aFeature.get() && aFeature->firstResult().get()
389 // && (aFeature->firstResult()->groupName() == ModelAPI_ResultField::group())) {
390 // ResultFieldPtr aResult =
391 // std::dynamic_pointer_cast<ModelAPI_ResultField>(aFeature->firstResult());
392 // QModelIndex aIndex = objectIndex(aResult, 0);
393 // removeRows(0, aResult->stepsSize(), aIndex);
395 // if (aObject->groupName() == ModelAPI_Folder::group()) {
396 // rebuildDataTree();
398 // QModelIndex aIndex = objectIndex(aObject, 0);
399 // if (aIndex.isValid()) {
400 // emit dataChanged(aIndex, aIndex);
405 // rebuildDataTree();
409 //} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
410 // std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
411 // std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
412 // if (aUpdMsg->reordered().get()) {
413 // DocumentPtr aDoc = aUpdMsg->reordered()->document();
414 // std::string aGroup = aUpdMsg->reordered()->group();
416 // QModelIndex aParent;
418 // if (aDoc == aRootDoc) {
419 // // Update a group under root
420 // if (aGroup == myXMLReader->rootType()) // Update objects under root
421 // aStartId = foldersCount();
422 // else // Update objects in folder under root
423 // aParent = createIndex(folderId(aGroup), 0, (void*)Q_NULLPTR);
425 // // Update a sub-document
426 // if (aGroup == myXMLReader->subType()) {
427 // // Update sub-document root
428 // aParent = findDocumentRootIndex(aDoc.get(), 0);
429 // aStartId = foldersCount(aDoc.get());
431 // // update folder in sub-document
432 // aParent = createIndex(folderId(aGroup, aDoc.get()), 0, aDoc.get());
434 // int aChildNb = rowCount(aParent);
435 // rebuildBranch(aStartId, aChildNb - aStartId, aParent);
437 // rebuildDataTree();
439 //} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
440 // DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument();
441 // if (aDoc != aRootDoc) {
442 // QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0);
443 // if (aDocRoot.isValid())
444 // emit dataChanged(aDocRoot, aDocRoot);
446 // // We have got a new document
447 // rebuildDataTree();
452 //******************************************************
453 void XGUI_DataModel::clear()
459 //******************************************************
460 void XGUI_DataModel::rebuildDataTree()
467 //******************************************************
468 ObjectPtr XGUI_DataModel::object(const QModelIndex& theIndex) const
470 if (theIndex.isValid()) {
471 ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer();
472 return aNode->object();
476 //if (theIndex.internalId() == 0) // this is a folder
477 // return ObjectPtr();
478 //ModelAPI_Object* aObj = 0;
480 // aObj = dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
484 // return ObjectPtr();
485 //if (getSubDocument(aObj)) // the selected index is a folder of sub-document
486 // return ObjectPtr();
488 //return aObj->data()->owner();
491 //******************************************************
492 QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn) const
494 ModuleBase_ITreeNode* aNode = myRoot->subNode(theObject);
496 return getIndex(aNode, theColumn);
498 return QModelIndex();
500 //std::string aType = theObject->groupName();
501 //DocumentPtr aDoc = theObject->document();
502 //int aRow = aDoc->index(theObject, true);
504 // // it could be a part of complex object
505 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
506 // if (aFeature.get()) {
507 // CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature);
508 // if (aCompFea.get()) {
509 // for (int i = 0; i < aCompFea->numberOfSubs(true); i++) {
510 // if (aCompFea->subFeature(i, true) == theObject) {
517 // FolderPtr aFolder = aDoc->findContainingFolder(aFeature, aFRow);
518 // if (aFolder.get())
521 // ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
522 // if (aResult.get()) {
523 // ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
524 // if (aCompRes.get()) {
525 // aRow = ModelAPI_Tools::compSolidIndex(aResult);
530 // return QModelIndex();
532 // return createIndex(aRow, theColumn, theObject.get());
534 //SessionPtr aSession = ModelAPI_Session::get();
535 //DocumentPtr aRootDoc = aSession->moduleDocument();
536 //if (aDoc == aRootDoc &&
537 // ((myXMLReader->rootType() == aType) || (aType == ModelAPI_Folder::group()))) {
538 // // The object from root document
539 // aRow += foldersCount();
540 //} else if ((myXMLReader->subType() == aType) || (aType == ModelAPI_Folder::group())) {
541 // // The object from sub document
542 // aRow += foldersCount(aDoc.get());
544 //return createIndex(aRow, theColumn, theObject.get());
547 //******************************************************
548 QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
550 if (theIndex.isValid()) {
551 ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer();
552 return aNode->data(theIndex.column(), theRole);
556 //SessionPtr aSession = ModelAPI_Session::get();
557 //DocumentPtr aRootDoc = aSession->moduleDocument();
558 //int aNbFolders = foldersCount();
559 //int theIndexRow = theIndex.row();
561 //if (theRole == Qt::DecorationRole) {
562 // if (theIndex == lastHistoryIndex())
563 // return QIcon(":pictures/arrow.png");
564 // else if (theIndex.column() == 0) {
565 // VisibilityState aState = getVisibilityState(theIndex);
570 // return QIcon(":pictures/eyeopen.png");
572 // return QIcon(":pictures/eyemiclosed.png");
574 // return QIcon(":pictures/eyeclosed.png");
579 ////if (theIndex.column() == 1)
580 //if (theIndex.column() != 1)
581 // return QVariant();
583 //quintptr aParentId = theIndex.internalId();
584 //if (aParentId == 0) { // root folders
585 // switch (theRole) {
586 // case Qt::DisplayRole:
587 // return QString(myXMLReader->rootFolderName(theIndexRow).c_str()) +
588 // QString(" (%1)").arg(rowCount(theIndex));
589 // case Qt::DecorationRole:
590 // return QIcon(myXMLReader->rootFolderIcon(theIndexRow).c_str());
591 // case Qt::ForegroundRole:
593 // Qt::ItemFlags aFlags = theIndex.flags();
594 // if (aFlags == Qt::ItemFlags())
595 // return QBrush(DISABLED_COLOR);
596 // if (!aFlags.testFlag(Qt::ItemIsEditable))
597 // return QBrush(SELECTABLE_COLOR);
599 // return ACTIVE_COLOR;
601 //} else { // an object or sub-document
602 // if (theRole == Qt::ForegroundRole) {
603 // Qt::ItemFlags aFlags = theIndex.flags();
604 // if (aFlags == Qt::ItemFlags())
605 // return QBrush(DISABLED_COLOR);
606 // if (!aFlags.testFlag(Qt::ItemIsEditable))
607 // return QBrush(SELECTABLE_COLOR);
608 // return ACTIVE_COLOR;
611 // ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer());
612 // if (aSubDoc) { // this is a folder of sub document
613 // QIntList aMissedIdx = missedFolderIndexes(aSubDoc);
614 // int aRow = theIndexRow;
615 // while (aMissedIdx.contains(aRow))
617 // if (aRow < myXMLReader->subFoldersNumber()) {
618 // switch (theRole) {
619 // case Qt::DisplayRole:
620 // return QString(myXMLReader->subFolderName(aRow).c_str()) +
621 // QString(" (%1)").arg(rowCount(theIndex));
622 // case Qt::DecorationRole:
623 // return QIcon(myXMLReader->subFolderIcon(aRow).c_str());
627 // ObjectPtr aObj = object(theIndex);
629 // switch (theRole) {
630 // case Qt::DisplayRole:
632 // if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
633 // ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObj);
634 // AttributeDoublePtr aValueAttribute =
635 // aParam->data()->real(ModelAPI_ResultParameter::VALUE());
636 // QString aVal = QString::number(aValueAttribute->value());
637 // QString aTitle = QString(aObj->data()->name().c_str());
638 // return aTitle + " = " + aVal;
641 // if (aObj->groupName() == myXMLReader->subType()) {
642 // ResultPartPtr aPartRes = getPartResult(aObj.get());
643 // if (aPartRes.get()) {
644 // if (aPartRes->partDoc().get() == NULL)
645 // aSuffix = " (Not loaded)";
648 // return aObj->data()->name().c_str() + aSuffix;
650 // case Qt::DecorationRole:
652 // if (aObj->groupName() == ModelAPI_Folder::group())
653 // return QIcon(":pictures/features_folder.png");
655 // return ModuleBase_IconFactory::get()->getIcon(aObj);
659 // switch (theRole) {
660 // case Qt::DisplayRole:
662 // ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
663 // dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>
664 // ((ModelAPI_Entity*)theIndex.internalPointer());
666 // return "Step " + QString::number(aStep->id() + 1) + " " +
667 // aStep->field()->textLine(aStep->id()).c_str();
678 //******************************************************
679 QVariant XGUI_DataModel::headerData(int theSection, Qt::Orientation theOrient, int theRole) const
684 //******************************************************
685 int XGUI_DataModel::rowCount(const QModelIndex& theParent) const
687 ModuleBase_ITreeNode* aParentNode = (theParent.isValid()) ?
688 (ModuleBase_ITreeNode*)theParent.internalPointer() : myRoot;
689 return aParentNode->childrenCount();
691 //SessionPtr aSession = ModelAPI_Session::get();
692 //if (!aSession->hasModuleDocument())
694 //DocumentPtr aRootDoc = aSession->moduleDocument();
696 //if (!theParent.isValid()) {
697 // // Return number of items in root
698 // int aNbFolders = foldersCount();
700 // std::string aType = myXMLReader->rootType();
701 // if (!aType.empty())
702 // aNbItems = aRootDoc->size(aType, true);
703 // return aNbFolders + aNbItems;
706 //quintptr aId = theParent.internalId();
708 // // this is a folder under root
709 // int aParentPos = theParent.row();
710 // std::string aType = myXMLReader->rootFolderType(aParentPos);
711 // return aRootDoc->size(aType);
713 // // It is an object which could have children
714 // ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
716 // // a folder of sub-document
717 // QIntList aMissedIdx = missedFolderIndexes(aDoc);
718 // int aRow = theParent.row();
719 // while (aMissedIdx.contains(aRow))
721 // if (aRow < myXMLReader->subFoldersNumber()) {
722 // std::string aType = myXMLReader->subFolderType(aRow);
723 // return aDoc->size(aType);
726 // ModelAPI_Object* aObj =
727 // dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theParent.internalPointer());
728 // // Check for Part feature
729 // ResultPartPtr aPartRes = getPartResult(aObj);
730 // if (aPartRes.get()) {
731 // DocumentPtr aSubDoc = aPartRes->partDoc();
732 // if (!aSubDoc.get())
735 // int aNbSubFolders = foldersCount(aSubDoc.get());
736 // int aNbSubItems = 0;
737 // std::string aSubType = myXMLReader->subType();
738 // if (!aSubType.empty())
739 // aNbSubItems = aSubDoc->size(aSubType, true);
740 // return aNbSubItems + aNbSubFolders;
742 // // Check for composite object
743 // ModelAPI_CompositeFeature* aCompFeature = dynamic_cast<ModelAPI_CompositeFeature*>(aObj);
745 // return aCompFeature->numberOfSubs(true);
746 // ModelAPI_ResultCompSolid* aCompRes = dynamic_cast<ModelAPI_ResultCompSolid*>(aObj);
748 // return aCompRes->numberOfSubs(true);
749 // ModelAPI_ResultField* aFieldRes = dynamic_cast<ModelAPI_ResultField*>(aObj);
751 // return aFieldRes->stepsSize();
752 // ModelAPI_Folder* aFolder = dynamic_cast<ModelAPI_Folder*>(aObj);
754 // return getNumberOfFolderItems(aFolder);
761 //******************************************************
762 int XGUI_DataModel::columnCount(const QModelIndex& theParent) const
767 //******************************************************
768 QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
770 int aa = theParent.row();
771 ModuleBase_ITreeNode* aParentNode = (theParent.isValid()) ?
772 (ModuleBase_ITreeNode*)theParent.internalPointer() : myRoot;
773 ModuleBase_ITreeNode* aSubNode = aParentNode->subNode(theRow);
775 return createIndex(theRow, theColumn, aSubNode);
777 //SessionPtr aSession = ModelAPI_Session::get();
778 //DocumentPtr aRootDoc = aSession->moduleDocument();
779 //int aNbFolders = foldersCount();
781 //QModelIndex aIndex;
783 //if (!theParent.isValid()) {
784 // if (theRow < aNbFolders) // Return first level folder index
785 // return createIndex(theRow, theColumn, (void*)Q_NULLPTR);
786 // else { // return object under root index
787 // std::string aType = myXMLReader->rootType();
788 // int aObjId = theRow - aNbFolders;
789 // if (aObjId < aRootDoc->size(aType, true)) {
790 // ObjectPtr aObj = aRootDoc->object(aType, aObjId, true);
791 // aIndex = objectIndex(aObj, theColumn);
795 // quintptr aId = theParent.internalId();
796 // int aParentPos = theParent.row();
797 // if (aId == 0) { // return object index inside of first level of folders
798 // std::string aType = myXMLReader->rootFolderType(aParentPos);
799 // if (theRow < aRootDoc->size(aType)) {
800 // ObjectPtr aObj = aRootDoc->object(aType, theRow, true);
801 // aIndex = objectIndex(aObj, theColumn);
804 // // It is an object which could have children
805 // ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
807 // // It is a folder of sub-document
808 // int aParentRow = aParentPos;
809 // QIntList aMissedIdx = missedFolderIndexes(aDoc);
810 // while (aMissedIdx.contains(aParentRow))
812 // if (aParentRow < myXMLReader->subFoldersNumber()) {
813 // std::string aType = myXMLReader->subFolderType(aParentRow);
814 // if (theRow < aDoc->size(aType)) {
815 // ObjectPtr aObj = aDoc->object(aType, theRow);
816 // aIndex = objectIndex(aObj, theColumn);
820 // ModelAPI_Object* aParentObj =
821 // dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theParent.internalPointer());
823 // // Check for Part feature
824 // ResultPartPtr aPartRes = getPartResult(aParentObj);
825 // if (aPartRes.get()) {
826 // DocumentPtr aSubDoc = aPartRes->partDoc();
827 // int aNbSubFolders = foldersCount(aSubDoc.get());
828 // if (theRow < aNbSubFolders) { // Create a Folder of sub-document
829 // aIndex = createIndex(theRow, theColumn, aSubDoc.get());
831 // // this is an object under sub document root
832 // std::string aType = myXMLReader->subType();
833 // ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders, true);
834 // aIndex = objectIndex(aObj, theColumn);
837 // // Check for composite object
838 // ModelAPI_CompositeFeature* aCompFeature =
839 // dynamic_cast<ModelAPI_CompositeFeature*>(aParentObj);
840 // if (aCompFeature) {
841 // aIndex = objectIndex(aCompFeature->subFeature(theRow), theColumn);
843 // ModelAPI_ResultCompSolid* aCompRes =
844 // dynamic_cast<ModelAPI_ResultCompSolid*>(aParentObj);
846 // aIndex = objectIndex(aCompRes->subResult(theRow), theColumn);
848 // ModelAPI_ResultField* aFieldRes =
849 // dynamic_cast<ModelAPI_ResultField*>(aParentObj);
851 // aIndex = createIndex(theRow, theColumn, aFieldRes->step(theRow));
853 // ModelAPI_Folder* aFolder = dynamic_cast<ModelAPI_Folder*>(aParentObj);
854 // ObjectPtr aObj = getObjectInFolder(aFolder, theRow);
856 // aIndex = objectIndex(aObj, theColumn);
867 //******************************************************
868 //static QModelIndex MYLastDeleted;
869 QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const
871 if (theIndex.isValid()) {
872 ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer();
873 return getParentIndex(aNode, 1);
875 return QModelIndex();
877 //if (!theIndex.isValid())
878 // return QModelIndex();
879 //// To avoid additional request about index which was already deleted
880 //if (theIndex == MYLastDeleted)
881 // return QModelIndex();
883 //SessionPtr aSession = ModelAPI_Session::get();
884 //quintptr aId = theIndex.internalId();
885 //if (aId != 0) { // The object is not a root folder
886 // ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer());
888 // // It is a folder of sub-document
889 // return findDocumentRootIndex(aDoc);
891 // ObjectPtr aObj = object(theIndex);
892 // if (!aObj.get()) {
893 // // It can be a step of a field
894 // ModelAPI_ResultField::ModelAPI_FieldStep* aStep = 0;
896 // aStep = dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>
897 // ((ModelAPI_Entity*)theIndex.internalPointer());
901 // ModelAPI_ResultField* aField = aStep->field();
902 // DocumentPtr aDoc = aSession->activeDocument();
904 // for(int i = 0; i < aDoc->size(ModelAPI_ResultField::group()); i++) {
905 // aFld = aDoc->object(ModelAPI_ResultField::group(), i);
906 // if (aFld.get() == aField)
907 // return objectIndex(aFld);
910 // // To avoid additional request about index which was already deleted
911 // // If deleted it causes a crash on delete object from Part
912 // MYLastDeleted = theIndex;
913 // return QModelIndex();
915 // // Check is it object a sub-object of a complex object
916 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
917 // if (aFeature.get()) {
918 // CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature);
919 // if (aCompFea.get()) {
920 // return objectIndex(aCompFea);
922 // DocumentPtr aDoc = aFeature->document();
924 // FolderPtr aFolder = aDoc->findContainingFolder(aFeature, aRow);
925 // if (aFolder.get())
926 // return objectIndex(aFolder);
928 // ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
929 // if (aResult.get()) {
930 // ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
931 // if (aCompRes.get()) {
932 // return objectIndex(aCompRes);
935 // // Use as ordinary object
936 // std::string aType = aObj->groupName();
937 // DocumentPtr aRootDoc = aSession->moduleDocument();
938 // DocumentPtr aSubDoc = aObj->document();
939 // if (aSubDoc == aRootDoc) {
940 // if ((aType == myXMLReader->rootType()) || (aType == ModelAPI_Folder::group()))
941 // return QModelIndex();
943 // // return first level of folder index
944 // int aFolderId = myXMLReader->rootFolderId(aType);
945 // // Items in a one row must have the same parent
946 // return createIndex(aFolderId, 1, (void*)Q_NULLPTR);
949 // if ((aType == myXMLReader->subType()) || (aType == ModelAPI_Folder::group()))
950 // return findDocumentRootIndex(aSubDoc.get());
952 // // return first level of folder index
953 // int aFolderId = folderId(aType, aSubDoc.get());
954 // // Items in a one row must have the same parent
955 // return createIndex(aFolderId, 1, aSubDoc.get());
961 //******************************************************
962 bool XGUI_DataModel::hasChildren(const QModelIndex& theParent) const
964 ModuleBase_ITreeNode* aParentNode = (theParent.isValid()) ?
965 (ModuleBase_ITreeNode*)theParent.internalPointer() : myRoot;
966 return aParentNode->childrenCount() > 0;
969 //******************************************************
970 bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
972 beginInsertRows(theParent, theRow, theRow + theCount - 1);
977 //******************************************************
978 bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent)
980 beginRemoveRows(theParent, theRow, theRow + theCount - 1);
985 //******************************************************
986 Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
988 if (theIndex.isValid()) {
989 ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer();
990 return aNode->flags(theIndex.column());
992 return Qt::ItemFlags();
994 //quintptr aIt = theIndex.internalId();
995 //ModelAPI_Object* aObj = 0;
996 //ModelAPI_Document* aDoc = 0;
997 //SessionPtr aSession = ModelAPI_Session::get();
998 //DocumentPtr aActiveDoc = aSession->activeDocument();
1000 //Qt::ItemFlags aNullFlag;
1001 //Qt::ItemFlags aDefaultFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
1002 //Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
1006 // // Folders under root
1007 // DocumentPtr aRootDoc = aSession->moduleDocument();
1008 // if (aRootDoc != aActiveDoc)
1009 // return aDefaultFlag;
1011 // aDoc = getSubDocument(theIndex.internalPointer());
1013 // aObj = dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
1018 // if (aObj->isDisabled())
1019 // return theIndex.column() == 2? Qt::ItemIsSelectable : aNullFlag;
1021 // if (aSession->moduleDocument() != aObj->document())
1022 // if (aActiveDoc != aObj->document())
1023 // return theIndex.column() == 2? Qt::ItemIsSelectable : aNullFlag;
1025 // bool isCompositeSub = false;
1026 // // An object which is sub-object of a composite object can not be accessible in column 2
1027 // if (theIndex.column() == 2) {
1028 // ObjectPtr aObjPtr = aObj->data()->owner();
1029 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjPtr);
1030 // if (aFeature.get()) {
1031 // CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature);
1032 // if (aCompFea.get())
1033 // isCompositeSub = true;
1035 // ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObjPtr);
1036 // if (aResult.get()) {
1037 // ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
1038 // if (aCompRes.get())
1039 // isCompositeSub = true;
1043 // if (isCompositeSub)
1044 // return Qt::ItemIsSelectable;
1046 // if (aObj->document() != aActiveDoc) {
1047 // // The object could be a root of sub-tree
1048 // ResultPartPtr aPartRes = getPartResult(aObj);
1049 // if (aPartRes.get()) {
1050 // if (aPartRes->partDoc() == aActiveDoc)
1051 // return aEditingFlag;
1053 // return aDefaultFlag;
1055 //} else if (aDoc) {
1056 // // A folder under sub-document
1057 // if (aActiveDoc.get() != aDoc)
1058 // return aNullFlag;
1060 //return aEditingFlag;
1063 //******************************************************
1065 // XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn) const
1067 // SessionPtr aSession = ModelAPI_Session::get();
1068 // DocumentPtr aRootDoc = aSession->moduleDocument();
1069 // if (myXMLReader->isAttachToResult()) { // If document is attached to result
1070 // int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
1072 // ResultPartPtr aPartRes;
1073 // for (int i = 0; i < aNb; i++) {
1074 // aObj = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1075 // aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1076 // if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
1078 // if (myXMLReader->rootType() == ModelAPI_Feature::group()) {
1079 // aRow += foldersCount();
1081 // return createIndex(aRow, aColumn, aObj.get());
1084 // } else { // If document is attached to feature
1085 // int aNb = aRootDoc->size(ModelAPI_Feature::group(), true);
1087 // ResultPartPtr aPartRes;
1088 // for (int i = 0; i < aNb; i++) {
1089 // aObj = aRootDoc->object(ModelAPI_Feature::group(), i, true);
1090 // aPartRes = getPartResult(aObj.get());
1091 // if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
1093 // if (myXMLReader->rootType() == ModelAPI_Feature::group())
1094 // aRow += foldersCount();
1095 // return createIndex(aRow, aColumn, aObj.get());
1099 // return QModelIndex();
1102 //******************************************************
1103 QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc, int theColumn) const
1105 SessionPtr aSession = ModelAPI_Session::get();
1106 DocumentPtr aRootDoc = aSession->moduleDocument();
1107 if (theDoc == aRootDoc)
1108 return QModelIndex();
1110 ModuleBase_ITreeNode* aDocNode = 0;
1111 foreach(ModuleBase_ITreeNode* aNode, myRoot->children()) {
1112 if (aNode->document() == theDoc) {
1118 return getIndex(aDocNode, theColumn);
1120 return QModelIndex();
1121 // return findDocumentRootIndex(theDoc.get(), theColumn);
1124 //******************************************************
1125 //int XGUI_DataModel::foldersCount(ModelAPI_Document* theDoc) const
1128 // SessionPtr aSession = ModelAPI_Session::get();
1129 // DocumentPtr aRootDoc = aSession->moduleDocument();
1130 // if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
1131 // for (int i = 0; i < myXMLReader->rootFoldersNumber(); i++) {
1132 // if (myXMLReader->rootShowEmpty(i))
1135 // if (aRootDoc->size(myXMLReader->rootFolderType(i)) > 0)
1140 // for (int i = 0; i < myXMLReader->subFoldersNumber(); i++) {
1141 // if (myXMLReader->subShowEmpty(i))
1144 // if (theDoc->size(myXMLReader->subFolderType(i)) > 0)
1153 //******************************************************
1154 //QIntList XGUI_DataModel::missedFolderIndexes(ModelAPI_Document* theDoc) const
1157 // SessionPtr aSession = ModelAPI_Session::get();
1158 // DocumentPtr aRootDoc = aSession->moduleDocument();
1159 // if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
1160 // for (int i = 0; i < myXMLReader->rootFoldersNumber(); i++) {
1161 // if (!myXMLReader->rootShowEmpty(i)) {
1162 // if (aRootDoc->size(myXMLReader->rootFolderType(i)) == 0)
1167 // for (int i = 0; i < myXMLReader->subFoldersNumber(); i++) {
1168 // if (!myXMLReader->subShowEmpty(i)) {
1169 // if (theDoc->size(myXMLReader->subFolderType(i)) == 0)
1178 //******************************************************
1179 //QStringList XGUI_DataModel::listOfShowNotEmptyFolders(bool fromRoot) const
1181 // QStringList aResult;
1183 // for (int i = 0; i < myXMLReader->rootFoldersNumber(); i++) {
1184 // if (!myXMLReader->rootShowEmpty(i))
1185 // aResult << myXMLReader->rootFolderType(i).c_str();
1188 // for (int i = 0; i < myXMLReader->subFoldersNumber(); i++) {
1189 // if (!myXMLReader->subShowEmpty(i))
1190 // aResult << myXMLReader->subFolderType(i).c_str();
1196 //******************************************************
1197 //QModelIndex XGUI_DataModel::lastHistoryIndex() const
1199 //SessionPtr aSession = ModelAPI_Session::get();
1200 //DocumentPtr aCurDoc = aSession->activeDocument();
1201 //FeaturePtr aFeature = aCurDoc->currentFeature(true);
1202 //if (aFeature.get()) {
1203 // QModelIndex aInd = objectIndex(aFeature);
1204 // return createIndex(aInd.row(), 2, aInd.internalPointer());
1206 // if (aCurDoc == aSession->moduleDocument())
1207 // return createIndex(foldersCount() - 1, 2, -1);
1209 // return createIndex(foldersCount(aCurDoc.get()) - 1, 2, aCurDoc.get());
1213 //******************************************************
1214 bool XGUI_DataModel::hasHiddenState(const QModelIndex& theIndex)
1217 //return getVisibilityState(theIndex) == Hidden;
1220 //******************************************************
1221 //int XGUI_DataModel::folderId(std::string theType, ModelAPI_Document* theDoc) const
1223 // SessionPtr aSession = ModelAPI_Session::get();
1224 // ModelAPI_Document* aDoc = theDoc;
1226 // aDoc = aSession->moduleDocument().get();
1228 // bool aUseSubDoc = (aDoc != aSession->moduleDocument().get());
1231 // if (aUseSubDoc) {
1232 // int aId = myXMLReader->subFolderId(theType);
1234 // for (int i = 0; i < aId; i++) {
1235 // if (!myXMLReader->subShowEmpty(i)) {
1236 // if (aDoc->size(myXMLReader->subFolderType(i)) == 0)
1241 // int aId = myXMLReader->rootFolderId(theType);
1243 // for (int i = 0; i < aId; i++) {
1244 // if (!myXMLReader->rootShowEmpty(i)) {
1245 // if (aDoc->size(myXMLReader->rootFolderType(i)) == 0)
1253 //******************************************************
1254 //void XGUI_DataModel::rebuildBranch(int theRow, int theCount, const QModelIndex& theParent)
1256 // if (theCount > 0) {
1257 // removeRows(theRow, theCount, theParent);
1258 // insertRows(theRow, theCount, theParent);
1262 //******************************************************
1263 //bool XGUI_DataModel::blockEventsProcessing(const bool theState)
1265 // bool aPreviousState = myIsEventsProcessingBlocked;
1266 // myIsEventsProcessingBlocked = theState;
1267 // return aPreviousState;
1270 //******************************************************
1271 //XGUI_DataModel::VisibilityState
1272 // XGUI_DataModel::getVisibilityState(const QModelIndex& theIndex) const
1274 // Qt::ItemFlags aFlags = theIndex.flags();
1275 // if (aFlags == Qt::ItemFlags())
1276 // return NoneState;
1278 // ObjectPtr aObj = object(theIndex);
1279 // if (aObj.get()) {
1280 // if (aObj->groupName() == ModelAPI_ResultParameter::group())
1281 // return NoneState;
1282 // ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1283 // if (aResObj.get()) {
1284 // XGUI_Displayer* aDisplayer = myWorkshop->displayer();
1285 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
1286 // if (aCompRes.get()) {
1287 // VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
1288 // (aDisplayer->isVisible(aCompRes)? Visible : Hidden) : NoneState;
1289 // for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
1290 // ResultPtr aSubRes = aCompRes->subResult(i, true);
1291 // VisibilityState aS = aDisplayer->isVisible(aSubRes)? Visible : Hidden;
1292 // if (aState == NoneState)
1294 // else if (aState != aS) {
1295 // aState = SemiVisible;
1301 // if (aDisplayer->isVisible(aResObj))
1308 // return NoneState;
1312 //int XGUI_DataModel::getNumberOfFolderItems(const ModelAPI_Folder* theFolder) const
1314 // DocumentPtr aDoc = theFolder->document();
1316 // FeaturePtr aFirstFeatureInFolder;
1317 // AttributeReferencePtr aFirstFeatAttr =
1318 // theFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
1319 // if (aFirstFeatAttr)
1320 // aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
1321 // if (!aFirstFeatureInFolder.get())
1324 // FeaturePtr aLastFeatureInFolder;
1325 // AttributeReferencePtr aLastFeatAttr =
1326 // theFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
1327 // if (aLastFeatAttr)
1328 // aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
1329 // if (!aLastFeatureInFolder.get())
1332 // int aFirst = aDoc->index(aFirstFeatureInFolder);
1333 // int aLast = aDoc->index(aLastFeatureInFolder);
1334 // return aLast - aFirst + 1;
1337 //ObjectPtr XGUI_DataModel::getObjectInFolder(const ModelAPI_Folder* theFolder, int theId) const
1339 // DocumentPtr aDoc = theFolder->document();
1341 // FeaturePtr aFirstFeatureInFolder;
1342 // AttributeReferencePtr aFirstFeatAttr =
1343 // theFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
1344 // if (aFirstFeatAttr)
1345 // aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
1346 // if (!aFirstFeatureInFolder.get())
1347 // return ObjectPtr();
1349 // int aFirst = aDoc->index(aFirstFeatureInFolder);
1350 // return aDoc->object(ModelAPI_Feature::group(), aFirst + theId);
1353 bool XGUI_DataModel::hasIndex(const QModelIndex& theIndex) const
1355 ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer();
1356 return myRoot->hasSubNode(aNode);
1359 QModelIndex XGUI_DataModel::getParentIndex(ModuleBase_ITreeNode* theNode, int thCol) const
1361 ModuleBase_ITreeNode* aParent = theNode->parent();
1362 if (aParent == myRoot) {
1363 return QModelIndex();
1365 return getIndex(aParent, thCol);
1369 QModelIndex XGUI_DataModel::getIndex(ModuleBase_ITreeNode* theNode, int thCol) const
1371 if (theNode == myRoot)
1372 return QModelIndex();
1373 int aRow = theNode->parent()->nodeRow(theNode);
1374 return createIndex(aRow, thCol, theNode);
1378 void XGUI_DataModel::updateSubTree(ModuleBase_ITreeNode* theParent)
1380 int aRows = theParent->childrenCount();
1382 QModelIndex aParent = getIndex(theParent, 0);
1383 QModelIndex aFirstIdx = aParent.child(0, 0);
1384 QModelIndex aLastIdx = aParent.child(aRows - 1, 2);
1385 dataChanged(aFirstIdx, aLastIdx);