From 79f013a896e6a93a0c01ba0930e5bb8f95a55507 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 14 Dec 2016 13:57:57 +0300 Subject: [PATCH] Issue #1908: Fix bug with wrong identification of Index. Remove process blocking. --- src/XGUI/XGUI_DataModel.cpp | 51 ++++++++++++++++++++----------------- src/XGUI/XGUI_DataModel.h | 4 +-- src/XGUI/XGUI_Workshop.cpp | 4 +-- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 3aa3e351c..46ff42386 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -62,8 +62,8 @@ ModelAPI_Document* getSubDocument(void* theObj) // Constructor ************************************************* -XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent), - myIsEventsProcessingBlocked(false) +XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)//, + //myIsEventsProcessingBlocked(false) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); @@ -80,8 +80,8 @@ XGUI_DataModel::~XGUI_DataModel() //****************************************************** void XGUI_DataModel::processEvent(const std::shared_ptr& theMessage) { - if (myIsEventsProcessingBlocked) - return; + //if (myIsEventsProcessingBlocked) + // return; DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); std::string aRootType = myXMLReader->rootType(); std::string aSubType = myXMLReader->subType(); @@ -427,13 +427,14 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const int aRow = theIndexRow; while (aMissedIdx.contains(aRow)) aRow++; - - switch (theRole) { - case Qt::DisplayRole: - return QString(myXMLReader->subFolderName(aRow).c_str()) + - QString(" (%1)").arg(rowCount(theIndex)); - case Qt::DecorationRole: - return QIcon(myXMLReader->subFolderIcon(aRow).c_str()); + if (aRow < myXMLReader->subFoldersNumber()) { + switch (theRole) { + case Qt::DisplayRole: + return QString(myXMLReader->subFolderName(aRow).c_str()) + + QString(" (%1)").arg(rowCount(theIndex)); + case Qt::DecorationRole: + return QIcon(myXMLReader->subFolderIcon(aRow).c_str()); + } } } else { ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer(); @@ -505,8 +506,10 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const int aRow = theParent.row(); while (aMissedIdx.contains(aRow)) aRow++; - std::string aType = myXMLReader->subFolderType(aRow); - return aDoc->size(aType); + if (aRow < myXMLReader->subFoldersNumber()) { + std::string aType = myXMLReader->subFolderType(aRow); + return aDoc->size(aType); + } } else { ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer(); // Check for Part feature @@ -580,10 +583,12 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & 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); + if (aParentRow < myXMLReader->subFoldersNumber()) { + std::string aType = myXMLReader->subFolderType(aParentRow); + if (theRow < aDoc->size(aType)) { + ObjectPtr aObj = aDoc->object(aType, theRow); + aIndex = objectIndex(aObj); + } } } else { ModelAPI_Object* aParentObj = (ModelAPI_Object*)theParent.internalPointer(); @@ -965,9 +970,9 @@ void XGUI_DataModel::rebuildBranch(int theRow, int theCount, const QModelIndex& } //****************************************************** -bool XGUI_DataModel::blockEventsProcessing(const bool theState) -{ - bool aPreviousState = myIsEventsProcessingBlocked; - myIsEventsProcessingBlocked = theState; - return aPreviousState; -} +//bool XGUI_DataModel::blockEventsProcessing(const bool theState) +//{ +// bool aPreviousState = myIsEventsProcessingBlocked; +// myIsEventsProcessingBlocked = theState; +// return aPreviousState; +//} diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 20cfb3aac..1ee25ad29 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -126,7 +126,7 @@ public: void setXMLReader(Config_DataModelReader* theReader) { myXMLReader = theReader; } /// Do not processing anymore events of model loop - bool blockEventsProcessing(const bool theState); + //bool blockEventsProcessing(const bool theState); signals: /// Signal about tree had been rebuilt @@ -165,7 +165,7 @@ private: Config_DataModelReader* myXMLReader; - bool myIsEventsProcessingBlocked; + //bool myIsEventsProcessingBlocked; }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d80fcaf25..615aa3579 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2080,12 +2080,12 @@ void XGUI_Workshop::closeDocument() // data model need not process the document's signals about objects modifications as // the document is closed - bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true); + //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true); SessionPtr aMgr = ModelAPI_Session::get(); aMgr->closeAll(); - objectBrowser()->dataModel()->blockEventsProcessing(isBlocked); + //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked); } void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot) -- 2.39.2