From: vsv Date: Mon, 2 Oct 2017 12:18:08 +0000 (+0300) Subject: Issue #2260: Correction for processing of empty/non-empty folders X-Git-Tag: V_2.8.0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=65c620cd3e21069ec52cb53ecc769ac8e4b53fbb;p=modules%2Fshaper.git Issue #2260: Correction for processing of empty/non-empty folders --- diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 758fb4f23..45dc14790 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -124,9 +124,13 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Check that new folders could appear QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { - if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) == 1)) + if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) > 0)) { // Appears first object in folder which can not be shown empty - insertRow(myXMLReader->rootFolderId(aObjType)); + if (!hasShownFolder(aRootDoc, aNotEmptyFolder)) { + insertRow(myXMLReader->rootFolderId(aObjType)); + addShownFolder(aRootDoc, aNotEmptyFolder); + } + } } // Insert new object int aRow = aRootDoc->size(aObjType) - 1; @@ -147,10 +151,14 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Check that new folders could appear QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { - if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) == 1)) + if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) > 0)) { // Appears first object in folder which can not be shown empty - insertRow(myXMLReader->subFolderId(aObjType), aDocRoot); - } + if (!hasShownFolder(aDoc, aNotEmptyFolder)) { + insertRow(myXMLReader->subFolderId(aObjType), aDocRoot); + addShownFolder(aDoc, aNotEmptyFolder); + } + } + } int aRow = aDoc->index(aObject); if (aRow != -1) { int aNbSubFolders = foldersCount(aDoc.get()); @@ -221,6 +229,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0)) { // Appears first object in folder which can not be shown empty removeRow(myXMLReader->rootFolderId(aGroup)); + removeShownFolder(aRootDoc, aNotEmptyFolder); //rebuildBranch(0, aNbFolders + aDoc->size(myXMLReader->rootType())); break; } @@ -251,6 +260,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess if ((aNotEmptyFolder.toStdString() == aGroup) && (aSize == 0)) { // Appears first object in folder which can not be shown empty removeRow(myXMLReader->subFolderId(aGroup), aDocRoot); + removeShownFolder(aDoc, aNotEmptyFolder); //rebuildBranch(0, aNbSubFolders + aDoc->size(myXMLReader->subType()), aDocRoot); break; } diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 39cbd3dc4..9052260aa 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -176,8 +176,33 @@ private: /// \param fromRoot - root document flag QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const; + void addShownFolder(DocumentPtr theDoc, QString theFolder) + { + if (!myShownFolders.contains(theDoc)) { + myShownFolders[theDoc] = QStringList(); + } + myShownFolders[theDoc].append(theFolder); + } + + void removeShownFolder(DocumentPtr theDoc, QString theFolder) + { + if (myShownFolders.contains(theDoc)) { + myShownFolders[theDoc].removeAll(theFolder); + if (myShownFolders[theDoc].isEmpty()) + myShownFolders.remove(theDoc); + } + } + + bool hasShownFolder(DocumentPtr theDoc, QString theFolder) const + { + if (myShownFolders.contains(theDoc)) + return myShownFolders[theDoc].contains(theFolder); + return false; + } + Config_DataModelReader* myXMLReader; + QMap myShownFolders; //bool myIsEventsProcessingBlocked; };