} else {
// List of objects under a folder
if (aRow != -1) {
- int aFolderId = myXMLReader.subFolderId(aObjType);
+ int aFolderId = folderId(aObjType, aDoc.get());
if (aFolderId != -1) {
insertRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
}
removeRow(aRow + aNbSubFolders, aDocRoot);
} else {
// List of objects under a folder
- int aFolderId = myXMLReader.subFolderId(aGroup);
+ int aFolderId = folderId(aGroup, aDoc.get());
if (aFolderId != -1) {
removeRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
}
ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
if (aDoc) {
// It is a folder of sub-document
- std::string aType = myXMLReader.subFolderType(aParentPos);
+ int aParentRow = aParentPos;
+ QIntList aMissedIdx = missedFolderIndexes(aDoc);
+ while (aMissedIdx.contains(aParentRow))
+ aParentRow++;
+ std::string aType = myXMLReader.subFolderType(aParentRow);
if (theRow < aDoc->size(aType)) {
ObjectPtr aObj = aDoc->object(aType, theRow);
aIndex = objectIndex(aObj);
else
return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());
}
-}
\ No newline at end of file
+}
+
+//******************************************************
+int XGUI_DataModel::folderId(std::string theType, ModelAPI_Document* theDoc)
+{
+ SessionPtr aSession = ModelAPI_Session::get();
+ ModelAPI_Document* aDoc = theDoc;
+ if (aDoc == 0)
+ aDoc = aSession->moduleDocument().get();
+
+ bool aUseSubDoc = (aDoc != aSession->moduleDocument().get());
+
+ int aRes = -1;
+ if (aUseSubDoc) {
+ int aId = myXMLReader.subFolderId(theType);
+ aRes = aId;
+ for (int i = 0; i < aId; i++) {
+ if (!myXMLReader.subShowEmpty(i)) {
+ if (aDoc->size(myXMLReader.subFolderType(i)) == 0)
+ aRes--;
+ }
+ }
+ } else {
+ int aId = myXMLReader.rootFolderId(theType);
+ aRes = aId;
+ for (int i = 0; i < aId; i++) {
+ if (!myXMLReader.rootShowEmpty(i)) {
+ if (aDoc->size(myXMLReader.rootFolderType(i)) == 0)
+ aRes--;
+ }
+ }
+ }
+ return aRes;
+}
/// \param theDoc document which has to be checked. If 0 then Root document will be considered
QIntList missedFolderIndexes(ModelAPI_Document* theDoc = 0) const;
+ /// Returns Id (row) of a folder taking into consideration folders which can not be shown non empty
+ /// \param theType Type of the folder
+ /// \param theDoc a document which contains this folder
+ int folderId(std::string theType, ModelAPI_Document* theDoc = 0);
+
/// Returns list of folders types which can not be shown empty
/// \param fromRoot - root document flag
QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const;