From 88d06aba0ec66a3d985e6901ae08ec22c9533ddb Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 4 Sep 2015 12:53:18 +0300 Subject: [PATCH] Check a case when created object can be canceled --- src/XGUI/XGUI_DataModel.cpp | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 7d1a27cd5..bc407998b 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -101,14 +101,16 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } // Insert new object int aRow = aRootDoc->size(aObjType) - 1; - if (aObjType == aRootType) { - insertRow(aRow + aNbFolders + 1); - } else { - int aFolderId = myXMLReader.rootFolderId(aObjType); - if (aFolderId != -1) { - insertRow(aRow, createIndex(aFolderId, 0, -1)); - } - } + if (aRow != -1) { + if (aObjType == aRootType) { + insertRow(aRow + aNbFolders + 1); + } else { + int aFolderId = myXMLReader.rootFolderId(aObjType); + if (aFolderId != -1) { + insertRow(aRow, createIndex(aFolderId, 0, -1)); + } + } + } } else { // Object created in sub-document QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get()); @@ -121,18 +123,20 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess insertRow(myXMLReader.subFolderId(aObjType), aDocRoot); } int aRow = aDoc->index(aObject); - int aNbSubFolders = foldersCount(aDoc.get()); - if (aObjType == aSubType) { - // List of objects under document root - insertRow(aRow + aNbSubFolders, aDocRoot); - } else { - // List of objects under a folder - if (aRow != -1) { - int aFolderId = folderId(aObjType, aDoc.get()); - if (aFolderId != -1) { - QModelIndex aParentFolder = createIndex(aFolderId, 0, aDoc.get()); - insertRow(aRow, aParentFolder); - emit dataChanged(aParentFolder, aParentFolder); + if (aRow != -1) { + int aNbSubFolders = foldersCount(aDoc.get()); + if (aObjType == aSubType) { + // List of objects under document root + insertRow(aRow + aNbSubFolders, aDocRoot); + } else { + // List of objects under a folder + if (aRow != -1) { + int aFolderId = folderId(aObjType, aDoc.get()); + if (aFolderId != -1) { + QModelIndex aParentFolder = createIndex(aFolderId, 0, aDoc.get()); + insertRow(aRow, aParentFolder); + emit dataChanged(aParentFolder, aParentFolder); + } } } } -- 2.39.2