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 QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const
494 int aId = theIndex.internalId();
495 if (aId != -1) { // The object is not a root folder
496 ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer());
498 // It is a folder of sub-document
499 return findDocumentRootIndex(aDoc);
501 ObjectPtr aObj = object(theIndex);
502 // Check is it object a sub-object of a complex object
503 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
504 if (aFeature.get()) {
505 CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature);
506 if (aCompFea.get()) {
507 return objectIndex(aCompFea);
510 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
512 ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
513 if (aCompRes.get()) {
514 return objectIndex(aCompRes);
517 // Use as ordinary object
518 std::string aType = aObj->groupName();
519 SessionPtr aSession = ModelAPI_Session::get();
520 DocumentPtr aRootDoc = aSession->moduleDocument();
521 DocumentPtr aSubDoc = aObj->document();
522 if (aSubDoc == aRootDoc) {
523 if (aType == myXMLReader.rootType())
524 return QModelIndex();
526 // return first level of folder index
527 int aFolderId = myXMLReader.rootFolderId(aType);
528 // Items in a one row must have the same parent
529 return createIndex(aFolderId, 0, -1);
532 if (aType == myXMLReader.subType())
533 return findDocumentRootIndex(aSubDoc.get());
535 // return first level of folder index
536 int aFolderId = myXMLReader.subFolderId(aType);
537 // Items in a one row must have the same parent
538 return createIndex(aFolderId, 0, aSubDoc.get());
542 return QModelIndex();
545 //******************************************************
546 bool XGUI_DataModel::hasChildren(const QModelIndex& theParent) const
548 if (!theParent.isValid()) {
549 int aNbFolders = foldersCount();
552 SessionPtr aSession = ModelAPI_Session::get();
553 DocumentPtr aRootDoc = aSession->moduleDocument();
554 return aRootDoc->size(myXMLReader.rootType()) > 0;
556 if (theParent.internalId() == -1) {
557 std::string aType = myXMLReader.rootFolderType(theParent.row());
558 if (!aType.empty()) {
559 SessionPtr aSession = ModelAPI_Session::get();
560 DocumentPtr aRootDoc = aSession->moduleDocument();
561 return aRootDoc->size(aType) > 0;
564 ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
566 // a folder of sub-document
567 std::string aType = myXMLReader.subFolderType(theParent.row());
568 return aDoc->size(aType) > 0;
570 // Check that it could be an object with children
571 ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
573 // Check for Part feature
574 ResultPartPtr aPartRes = getPartResult(aObj);
578 // Check for composite object
579 ModelAPI_CompositeFeature* aCompFeature = dynamic_cast<ModelAPI_CompositeFeature*>(aObj);
581 return aCompFeature->numberOfSubs(true) > 0;
582 ModelAPI_ResultCompSolid* aCompRes = dynamic_cast<ModelAPI_ResultCompSolid*>(aObj);
584 return aCompRes->numberOfSubs(true) > 0;
591 //******************************************************
592 bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
594 beginInsertRows(theParent, theRow, theRow + theCount - 1);
600 //******************************************************
601 bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent)
603 beginRemoveRows(theParent, theRow, theRow + theCount - 1);
608 //******************************************************
609 Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
611 Qt::ItemFlags aFlags = Qt::ItemIsSelectable;
613 ModelAPI_Object* aObj = 0;
614 if (theIndex.internalId() != -1) {
615 if (!getSubDocument(theIndex.internalPointer()))
616 aObj = (ModelAPI_Object*) theIndex.internalPointer();
619 aFlags |= Qt::ItemIsEditable;
621 if (!aObj->isDisabled())
622 aFlags |= Qt::ItemIsEnabled;
624 aFlags |= Qt::ItemIsEnabled;
628 //******************************************************
629 QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc) const
631 SessionPtr aSession = ModelAPI_Session::get();
632 DocumentPtr aRootDoc = aSession->moduleDocument();
633 if (myXMLReader.isAttachToResult()) { // If document is attached to result
634 int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
636 ResultPartPtr aPartRes;
637 for (int i = 0; i < aNb; i++) {
638 aObj = aRootDoc->object(ModelAPI_ResultPart::group(), i);
639 aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
640 if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
642 if (myXMLReader.rootType() == ModelAPI_Feature::group())
643 aRow += foldersCount();
644 return createIndex(aRow, 0, aObj.get());
647 } else { // If document is attached to feature
648 int aNb = aRootDoc->size(ModelAPI_Feature::group());
650 ResultPartPtr aPartRes;
651 for (int i = 0; i < aNb; i++) {
652 aObj = aRootDoc->object(ModelAPI_Feature::group(), i);
653 aPartRes = getPartResult(aObj.get());
654 if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
656 if (myXMLReader.rootType() == ModelAPI_Feature::group())
657 aRow += foldersCount();
658 return createIndex(aRow, 0, aObj.get());
662 return QModelIndex();
665 //******************************************************
666 QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
668 SessionPtr aSession = ModelAPI_Session::get();
669 DocumentPtr aRootDoc = aSession->moduleDocument();
670 if (theDoc == aRootDoc)
671 return QModelIndex();
673 return findDocumentRootIndex(theDoc.get());
676 //******************************************************
677 int XGUI_DataModel::foldersCount(ModelAPI_Document* theDoc) const
680 SessionPtr aSession = ModelAPI_Session::get();
681 DocumentPtr aRootDoc = aSession->moduleDocument();
682 if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
683 for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
684 if (myXMLReader.rootShowEmpty(i))
687 if (aRootDoc->size(myXMLReader.rootFolderType(i)) > 0)
692 for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
693 if (myXMLReader.subShowEmpty(i))
696 if (theDoc->size(myXMLReader.subFolderType(i)) > 0)
704 //******************************************************
705 QStringList XGUI_DataModel::listOfShowNotEmptyFolders(bool fromRoot) const
709 for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
710 if (!myXMLReader.rootShowEmpty(i))
711 aResult << myXMLReader.rootFolderType(i).c_str();
714 for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
715 if (!myXMLReader.subShowEmpty(i))
716 aResult << myXMLReader.subFolderType(i).c_str();
722 //******************************************************
723 QModelIndex XGUI_DataModel::lastHistoryIndex() const
725 SessionPtr aSession = ModelAPI_Session::get();
726 DocumentPtr aCurDoc = aSession->activeDocument();
727 FeaturePtr aFeature = aCurDoc->currentFeature(true);
728 if (aFeature.get()) {
729 QModelIndex aInd = objectIndex(aFeature);
730 return createIndex(aInd.row(), 1, aInd.internalPointer());
732 if (aCurDoc == aSession->moduleDocument())
733 return createIndex(foldersCount() - 1, 1, -1);
735 return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());