From 7949d72fa59228ccd233f482b6883f254e544f8d Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 11 Apr 2014 13:03:50 +0400 Subject: [PATCH] Update just modified part tree in object browser --- src/XGUI/XGUI_DocumentDataModel.cpp | 38 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index b7f65b746..1e53953f7 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -12,6 +12,7 @@ #include +#include XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) @@ -38,21 +39,32 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel() void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage) { - beginResetModel(); - int aNbParts = myDocument->featuresIterator(PARTS_GROUP)->numIterationsLeft(); - if (myPartModels.size() != aNbParts) { // resize internal models - while (myPartModels.size() > aNbParts) { - delete myPartModels.last(); - myPartModels.removeLast(); - } - while (myPartModels.size() < aNbParts) { - myPartModels.append(new XGUI_PartDataModel(myDocument, this)); + if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) { + // Add a new part + int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size(); + beginInsertRows(QModelIndex(), aStart, aStart + 1); + XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this); + aModel->setPartId(myPartModels.count()); + myPartModels.append(aModel); + endInsertRows(); + } else { + // Reset whole tree + beginResetModel(); + int aNbParts = myDocument->featuresIterator(PARTS_GROUP)->numIterationsLeft(); + if (myPartModels.size() != aNbParts) { // resize internal models + while (myPartModels.size() > aNbParts) { + delete myPartModels.last(); + myPartModels.removeLast(); + } + while (myPartModels.size() < aNbParts) { + myPartModels.append(new XGUI_PartDataModel(myDocument, this)); + } + for (int i = 0; i < myPartModels.size(); i++) + myPartModels.at(i)->setPartId(i); } - for (int i = 0; i < myPartModels.size(); i++) - myPartModels.at(i)->setPartId(i); + clearModelIndexes(); + endResetModel(); } - clearModelIndexes(); - endResetModel(); } QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const -- 2.39.2