1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: ModuleBase_IDocumentDataModel.cpp
4 // Created: 28 Apr 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "XGUI_DataModel.h"
9 #include <ModuleBase_IconFactory.h>
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Events.h>
13 #include <ModelAPI_ResultParameter.h>
14 #include <ModelAPI_AttributeDouble.h>
15 #include <ModelAPI_ResultPart.h>
16 #include <ModelAPI_Feature.h>
17 #include <ModelAPI_CompositeFeature.h>
18 #include <ModelAPI_ResultCompSolid.h>
19 #include <ModelAPI_Tools.h>
21 #include <Config_FeatureMessage.h>
23 #include <Events_Loop.h>
24 #include <Events_Error.h>
29 #define ACTIVE_COLOR QColor(0,72,140)
30 #define PASSIVE_COLOR Qt::black
32 /// Returns ResultPart object if the given object is a Part feature
33 /// Otherwise returns NULL
34 ResultPartPtr getPartResult(ModelAPI_Object* theObj)
36 ModelAPI_Feature* aFeature = dynamic_cast<ModelAPI_Feature*>(theObj);
38 ResultPtr aRes = aFeature->firstResult();
39 if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
40 return std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
43 return ResultPartPtr();
46 /// Returns pointer on document if the given object is document object
47 ModelAPI_Document* getSubDocument(void* theObj)
49 ModelAPI_Document* aDoc = dynamic_cast<ModelAPI_Document*>((ModelAPI_Entity*)theObj);
56 // Constructor *************************************************
57 XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)
59 myXMLReader.readAll();
61 Events_Loop* aLoop = Events_Loop::loop();
62 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
63 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
66 //******************************************************
67 void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMessage)
69 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
70 std::string aRootType = myXMLReader.rootType();
71 std::string aSubType = myXMLReader.subType();
72 int aNbFolders = foldersCount();
74 // Created object event *******************
75 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
76 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
77 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
78 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
80 std::set<ObjectPtr>::const_iterator aIt;
82 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
83 ObjectPtr aObject = (*aIt);
84 aObjType = aObject->groupName();
85 DocumentPtr aDoc = aObject->document();
86 if (aDoc == aRootDoc) {
87 // Check that new folders could appear
88 QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
89 foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
90 if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) == 1))
91 // Appears first object in folder which can not be shown empty
92 insertRow(myXMLReader.rootFolderId(aObjType));
95 int aRow = aRootDoc->size(aObjType) - 1;
96 if (aObjType == aRootType) {
97 insertRow(aRow + aNbFolders + 1);
99 int aFolderId = myXMLReader.rootFolderId(aObjType);
100 if (aFolderId != -1) {
101 insertRow(aRow, createIndex(aFolderId, 0, -1));
105 // Object created in sub-document
106 QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
107 if (aDocRoot.isValid()) {
108 // Check that new folders could appear
109 QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
110 foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
111 if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) == 1))
112 // Appears first object in folder which can not be shown empty
113 insertRow(myXMLReader.subFolderId(aObjType), aDocRoot);
115 int aRow = aDoc->size(aObjType) - 1;
116 int aNbSubFolders = foldersCount(aDoc.get());
117 if (aObjType == aSubType) {
118 // List of objects under document root
119 insertRow(aRow + aNbSubFolders, aDocRoot);
121 // List of objects under a folder
123 int aFolderId = myXMLReader.subFolderId(aObjType);
124 if (aFolderId != -1) {
125 insertRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
132 Events_Error::send("Problem with Data Model definition of sub-document");
137 // Deleted object event ***********************
138 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
139 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
140 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
141 DocumentPtr aDoc = aUpdMsg->document();
142 std::set<std::string> aGroups = aUpdMsg->groups();
143 std::set<std::string>::const_iterator aIt;
144 for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) {
145 std::string aGroup = (*aIt);
146 if (aDoc == aRootDoc) { // If root objects
147 int aRow = aRootDoc->size(aGroup);
148 if (aGroup == aRootType) {
149 removeRow(aRow + aNbFolders);
151 int aFolderId = myXMLReader.rootFolderId(aGroup);
152 if (aFolderId != -1) {
153 QModelIndex aFolderIndex = createIndex(aFolderId, 0, -1);
154 removeRow(aRow, aFolderIndex);
157 // Check that some folders could erased
158 QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
159 foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
160 if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0))
161 // Appears first object in folder which can not be shown empty
162 removeRow(myXMLReader.rootFolderId(aGroup));
165 // Remove row for sub-document
166 QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
167 if (aDocRoot.isValid()) {
168 int aRow = aDoc->size(aGroup);
169 int aNbSubFolders = foldersCount(aDoc.get());
170 if (aGroup == aSubType) {
171 // List of objects under document root
172 removeRow(aRow + aNbSubFolders, aDocRoot);
174 // List of objects under a folder
175 int aFolderId = myXMLReader.subFolderId(aGroup);
176 if (aFolderId != -1) {
177 removeRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
180 // Check that some folders could disappear
181 QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
182 foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
183 if ((aNotEmptyFolder.toStdString() == aGroup) && (aDoc->size(aGroup) == 1))
184 // Appears first object in folder which can not be shown empty
185 removeRow(myXMLReader.subFolderId(aGroup), aDocRoot);
190 Events_Error::send("Problem with Data Model definition of sub-document");
198 //******************************************************
199 void XGUI_DataModel::clear()
204 //******************************************************
205 void XGUI_DataModel::rebuildDataTree()
210 //******************************************************
211 ObjectPtr XGUI_DataModel::object(const QModelIndex& theIndex) const
213 if (theIndex.internalId() < 0) // this is a folder
215 ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
216 if (getSubDocument(aObj)) // the selected index is a folder of sub-document
219 return aObj->data()->owner();
222 //******************************************************
223 QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const
225 std::string aType = theObject->groupName();
226 DocumentPtr aDoc = theObject->document();
227 int aRow = aDoc->index(theObject);
229 // it could be a part of complex object
230 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
231 if (aFeature.get()) {
232 CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature);
233 if (aCompFea.get()) {
234 for (int i = 0; i < aCompFea->numberOfSubs(true); i++) {
235 if (aCompFea->subFeature(i, true) == theObject) {
242 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
244 ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
245 if (aCompRes.get()) {
246 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
247 if (aCompRes->subResult(i, true) == theObject) {
256 return QModelIndex();
258 return createIndex(aRow, 0, theObject.get());
260 SessionPtr aSession = ModelAPI_Session::get();
261 DocumentPtr aRootDoc = aSession->moduleDocument();
262 if (aDoc == aRootDoc && myXMLReader.rootType() == aType) {
263 // The object from root document
264 aRow += foldersCount();
265 } else if (myXMLReader.subType() == aType) {
266 // The object from sub document
267 aRow += foldersCount(aDoc.get());
269 return createIndex(aRow, 0, theObject.get());
272 //******************************************************
273 QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
275 SessionPtr aSession = ModelAPI_Session::get();
276 DocumentPtr aRootDoc = aSession->moduleDocument();
277 int aNbFolders = foldersCount();
278 int theIndexRow = theIndex.row();
280 if ((theRole == Qt::DecorationRole) && (theIndex == lastHistoryIndex()))
281 return QIcon(":pictures/arrow.png");
283 if (theIndex.column() == 1)
286 int aParentId = theIndex.internalId();
287 if (aParentId == -1) { // root folders
289 case Qt::DisplayRole:
290 return QString(myXMLReader.rootFolderName(theIndexRow).c_str()) +
291 QString(" (%1)").arg(rowCount(theIndex));
292 case Qt::DecorationRole:
293 return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
294 case Qt::ForegroundRole:
295 if (aSession->activeDocument() == aRootDoc)
296 return QBrush(ACTIVE_COLOR);
298 return QBrush(PASSIVE_COLOR);
300 } else { // an object or sub-document
301 ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer());
303 if (theRole == Qt::ForegroundRole) {
304 bool aIsActive = false;
306 aIsActive = (aSession->activeDocument().get() == aSubDoc);
308 ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
309 if (aObj->isDisabled())
310 return QBrush(Qt::lightGray);
311 aIsActive = (aSession->activeDocument() == aObj->document());
314 return QBrush(ACTIVE_COLOR);
316 return QBrush(PASSIVE_COLOR);
319 if (aSubDoc) { // this is a folder of sub document
321 case Qt::DisplayRole:
322 return QString(myXMLReader.subFolderName(theIndexRow).c_str()) +
323 QString(" (%1)").arg(rowCount(theIndex));
324 case Qt::DecorationRole:
325 return QIcon(myXMLReader.subFolderIcon(theIndexRow).c_str());
328 ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
330 case Qt::DisplayRole:
331 if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
332 ModelAPI_ResultParameter* aParam = dynamic_cast<ModelAPI_ResultParameter*>(aObj);
333 AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
334 QString aVal = QString::number(aValueAttribute->value());
335 QString aTitle = QString(aObj->data()->name().c_str());
336 return aTitle + " = " + aVal;
338 return aObj->data()->name().c_str();
339 case Qt::DecorationRole:
340 return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
347 //******************************************************
348 QVariant XGUI_DataModel::headerData(int theSection, Qt::Orientation theOrient, int theRole) const
353 //******************************************************
354 int XGUI_DataModel::rowCount(const QModelIndex& theParent) const
356 SessionPtr aSession = ModelAPI_Session::get();
357 if (!aSession->hasModuleDocument())
359 DocumentPtr aRootDoc = aSession->moduleDocument();
361 if (!theParent.isValid()) {
362 // Return number of items in root
363 int aNbFolders = foldersCount();
365 std::string aType = myXMLReader.rootType();
367 aNbItems = aRootDoc->size(aType);
368 return aNbFolders + aNbItems;
371 int aId = theParent.internalId();
373 // this is a folder under root
374 int aParentPos = theParent.row();
375 std::string aType = myXMLReader.rootFolderType(aParentPos);
376 //qDebug("### %s = %i\n", aType.c_str(), aRootDoc->size(aType));
377 return aRootDoc->size(aType);
379 // It is an object which could have children
380 ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
382 // a folder of sub-document
383 std::string aType = myXMLReader.subFolderType(theParent.row());
384 return aDoc->size(aType);
386 ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
387 // Check for Part feature
388 ResultPartPtr aPartRes = getPartResult(aObj);
389 if (aPartRes.get()) {
390 DocumentPtr aSubDoc = aPartRes->partDoc();
391 int aNbSubFolders = foldersCount(aSubDoc.get());
393 std::string aSubType = myXMLReader.subType();
394 if (!aSubType.empty())
395 aNbSubItems = aSubDoc->size(aSubType);
396 return aNbSubItems + aNbSubFolders;
398 // Check for composite object
399 ModelAPI_CompositeFeature* aCompFeature = dynamic_cast<ModelAPI_CompositeFeature*>(aObj);
401 return aCompFeature->numberOfSubs(true);
402 ModelAPI_ResultCompSolid* aCompRes = dynamic_cast<ModelAPI_ResultCompSolid*>(aObj);
404 return aCompRes->numberOfSubs(true);
411 //******************************************************
412 int XGUI_DataModel::columnCount(const QModelIndex& theParent) const
417 //******************************************************
418 QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
420 SessionPtr aSession = ModelAPI_Session::get();
421 DocumentPtr aRootDoc = aSession->moduleDocument();
422 int aNbFolders = foldersCount();
426 if (!theParent.isValid()) {
427 if (theRow < aNbFolders) // Return first level folder index
428 return createIndex(theRow, theColumn, -1);
429 else { // return object under root index
430 std::string aType = myXMLReader.rootType();
431 int aObjId = theRow - aNbFolders;
432 if (aObjId < aRootDoc->size(aType)) {
433 ObjectPtr aObj = aRootDoc->object(aType, aObjId);
434 aIndex = objectIndex(aObj);
438 int aId = theParent.internalId();
439 int aParentPos = theParent.row();
440 if (aId == -1) { // return object index inside of first level of folders
441 std::string aType = myXMLReader.rootFolderType(aParentPos);
442 if (theRow < aRootDoc->size(aType)) {
443 ObjectPtr aObj = aRootDoc->object(aType, theRow);
444 aIndex = objectIndex(aObj);
447 // It is an object which could have children
448 ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
450 // It is a folder of sub-document
451 std::string aType = myXMLReader.subFolderType(aParentPos);
452 if (theRow < aDoc->size(aType)) {
453 ObjectPtr aObj = aDoc->object(aType, theRow);
454 aIndex = objectIndex(aObj);
457 ModelAPI_Object* aParentObj = (ModelAPI_Object*)theParent.internalPointer();
459 // Check for Part feature
460 ResultPartPtr aPartRes = getPartResult(aParentObj);
461 if (aPartRes.get()) {
462 DocumentPtr aSubDoc = aPartRes->partDoc();
463 int aNbSubFolders = foldersCount(aSubDoc.get());
464 if (theRow < aNbSubFolders) { // Create a Folder of sub-document
465 aIndex = createIndex(theRow, theColumn, aSubDoc.get());
467 // this is an object under sub document root
468 std::string aType = myXMLReader.subType();
469 ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
470 aIndex = objectIndex(aObj);
473 // Check for composite object
474 ModelAPI_CompositeFeature* aCompFeature = dynamic_cast<ModelAPI_CompositeFeature*>(aParentObj);
476 aIndex = objectIndex(aCompFeature->subFeature(theRow));
478 ModelAPI_ResultCompSolid* aCompRes = dynamic_cast<ModelAPI_ResultCompSolid*>(aParentObj);
480 aIndex = objectIndex(aCompRes->subResult(theRow));
487 return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
491 //******************************************************
492 static QModelIndex MYLastDeleted;
493 QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const
495 // To avoid additional request about index which was already deleted
496 if (theIndex == MYLastDeleted)
497 return QModelIndex();
499 int aId = theIndex.internalId();
500 if (aId != -1) { // The object is not a root folder
501 ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer());
503 // It is a folder of sub-document
504 return findDocumentRootIndex(aDoc);
506 ObjectPtr aObj = object(theIndex);
508 // To avoid additional request about index which was already deleted
509 MYLastDeleted = theIndex;
510 return QModelIndex();
512 // Check is it object a sub-object of a complex object
513 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
514 if (aFeature.get()) {
515 CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature);
516 if (aCompFea.get()) {
517 return objectIndex(aCompFea);
520 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
522 ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
523 if (aCompRes.get()) {
524 return objectIndex(aCompRes);
527 // Use as ordinary object
528 std::string aType = aObj->groupName();
529 SessionPtr aSession = ModelAPI_Session::get();
530 DocumentPtr aRootDoc = aSession->moduleDocument();
531 DocumentPtr aSubDoc = aObj->document();
532 if (aSubDoc == aRootDoc) {
533 if (aType == myXMLReader.rootType())
534 return QModelIndex();
536 // return first level of folder index
537 int aFolderId = myXMLReader.rootFolderId(aType);
538 // Items in a one row must have the same parent
539 return createIndex(aFolderId, 0, -1);
542 if (aType == myXMLReader.subType())
543 return findDocumentRootIndex(aSubDoc.get());
545 // return first level of folder index
546 int aFolderId = myXMLReader.subFolderId(aType);
547 // Items in a one row must have the same parent
548 return createIndex(aFolderId, 0, aSubDoc.get());
552 return QModelIndex();
555 //******************************************************
556 bool XGUI_DataModel::hasChildren(const QModelIndex& theParent) const
558 if (!theParent.isValid()) {
559 int aNbFolders = foldersCount();
562 SessionPtr aSession = ModelAPI_Session::get();
563 DocumentPtr aRootDoc = aSession->moduleDocument();
564 return aRootDoc->size(myXMLReader.rootType()) > 0;
566 if (theParent.internalId() == -1) {
567 std::string aType = myXMLReader.rootFolderType(theParent.row());
568 if (!aType.empty()) {
569 SessionPtr aSession = ModelAPI_Session::get();
570 DocumentPtr aRootDoc = aSession->moduleDocument();
571 return aRootDoc->size(aType) > 0;
574 ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
576 // a folder of sub-document
577 std::string aType = myXMLReader.subFolderType(theParent.row());
578 return aDoc->size(aType) > 0;
580 // Check that it could be an object with children
581 ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
583 // Check for Part feature
584 ResultPartPtr aPartRes = getPartResult(aObj);
588 // Check for composite object
589 ModelAPI_CompositeFeature* aCompFeature = dynamic_cast<ModelAPI_CompositeFeature*>(aObj);
591 return aCompFeature->numberOfSubs(true) > 0;
592 ModelAPI_ResultCompSolid* aCompRes = dynamic_cast<ModelAPI_ResultCompSolid*>(aObj);
594 return aCompRes->numberOfSubs(true) > 0;
601 //******************************************************
602 bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
604 beginInsertRows(theParent, theRow, theRow + theCount - 1);
610 //******************************************************
611 bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent)
613 beginRemoveRows(theParent, theRow, theRow + theCount - 1);
618 //******************************************************
619 Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
621 Qt::ItemFlags aFlags = Qt::ItemIsSelectable;
623 ModelAPI_Object* aObj = 0;
624 if (theIndex.internalId() != -1) {
625 if (!getSubDocument(theIndex.internalPointer()))
626 aObj = (ModelAPI_Object*) theIndex.internalPointer();
629 aFlags |= Qt::ItemIsEditable;
631 if (!aObj->isDisabled())
632 aFlags |= Qt::ItemIsEnabled;
634 aFlags |= Qt::ItemIsEnabled;
638 //******************************************************
639 QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc) const
641 SessionPtr aSession = ModelAPI_Session::get();
642 DocumentPtr aRootDoc = aSession->moduleDocument();
643 if (myXMLReader.isAttachToResult()) { // If document is attached to result
644 int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
646 ResultPartPtr aPartRes;
647 for (int i = 0; i < aNb; i++) {
648 aObj = aRootDoc->object(ModelAPI_ResultPart::group(), i);
649 aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
650 if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
652 if (myXMLReader.rootType() == ModelAPI_Feature::group())
653 aRow += foldersCount();
654 return createIndex(aRow, 0, aObj.get());
657 } else { // If document is attached to feature
658 int aNb = aRootDoc->size(ModelAPI_Feature::group());
660 ResultPartPtr aPartRes;
661 for (int i = 0; i < aNb; i++) {
662 aObj = aRootDoc->object(ModelAPI_Feature::group(), i);
663 aPartRes = getPartResult(aObj.get());
664 if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
666 if (myXMLReader.rootType() == ModelAPI_Feature::group())
667 aRow += foldersCount();
668 return createIndex(aRow, 0, aObj.get());
672 return QModelIndex();
675 //******************************************************
676 QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
678 SessionPtr aSession = ModelAPI_Session::get();
679 DocumentPtr aRootDoc = aSession->moduleDocument();
680 if (theDoc == aRootDoc)
681 return QModelIndex();
683 return findDocumentRootIndex(theDoc.get());
686 //******************************************************
687 int XGUI_DataModel::foldersCount(ModelAPI_Document* theDoc) const
690 SessionPtr aSession = ModelAPI_Session::get();
691 DocumentPtr aRootDoc = aSession->moduleDocument();
692 if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
693 for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
694 if (myXMLReader.rootShowEmpty(i))
697 if (aRootDoc->size(myXMLReader.rootFolderType(i)) > 0)
702 for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
703 if (myXMLReader.subShowEmpty(i))
706 if (theDoc->size(myXMLReader.subFolderType(i)) > 0)
714 //******************************************************
715 QStringList XGUI_DataModel::listOfShowNotEmptyFolders(bool fromRoot) const
719 for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
720 if (!myXMLReader.rootShowEmpty(i))
721 aResult << myXMLReader.rootFolderType(i).c_str();
724 for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
725 if (!myXMLReader.subShowEmpty(i))
726 aResult << myXMLReader.subFolderType(i).c_str();
732 //******************************************************
733 QModelIndex XGUI_DataModel::lastHistoryIndex() const
735 SessionPtr aSession = ModelAPI_Session::get();
736 DocumentPtr aCurDoc = aSession->activeDocument();
737 FeaturePtr aFeature = aCurDoc->currentFeature(true);
738 if (aFeature.get()) {
739 QModelIndex aInd = objectIndex(aFeature);
740 return createIndex(aInd.row(), 1, aInd.internalPointer());
742 if (aCurDoc == aSession->moduleDocument())
743 return createIndex(foldersCount() - 1, 1, -1);
745 return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());