X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_DocumentDataModel.cpp;h=1ee46e331e9d07ca4d2c47980bf40cdea6af65a0;hb=d86c77d1c6210bbe04fbc3e5b00f9e212e1ec930;hp=f73c58ce1c253a75b589e41fb988fbeaf6341892;hpb=a1d3e85f42aebdcf8b570ab99f5f4558612573e7;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index f73c58ce1..1ee46e331 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include @@ -19,13 +19,13 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) : QAbstractItemModel(theParent) { // Find Document object - std::shared_ptr aMgr = ModelAPI_PluginManager::get(); + boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); myDocument = aMgr->currentDocument(); // Register in event loop - Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_CREATED)); - Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_UPDATED)); - Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_DELETED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED)); // Create a top part of data tree model myModel = new XGUI_TopDataModel(myDocument, this); @@ -38,13 +38,13 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel() } -void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage) +void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) { // Created object event ******************* if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) { - const ModelAPI_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - std::shared_ptr aDoc = aUpdMsg->document(); - std::shared_ptr aFeature = aUpdMsg->feature(); + const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + boost::shared_ptr aFeature = aUpdMsg->feature(); + boost::shared_ptr aDoc = aFeature->document(); if (aDoc == myDocument) { // If root objects if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Updsate only Parts group @@ -79,16 +79,15 @@ void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage) // Deteted object event *********************** } else if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_DELETED) { - const ModelAPI_FeatureDeletedMessage* aUpdMsg = dynamic_cast(theMessage); - std::shared_ptr aDoc = aUpdMsg->document(); + const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast(theMessage); + boost::shared_ptr aDoc = aUpdMsg->document(); if (aDoc == myDocument) { // If root objects if (aUpdMsg->group().compare(PARTS_GROUP) == 0) { // Updsate only Parts group int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size() - 1; beginRemoveRows(QModelIndex(), aStart, aStart); + removeSubModel(myPartModels.size() - 1); endRemoveRows(); - delete myPartModels.last(); - myPartModels.removeLast(); } else { // Update top groups (other except parts QModelIndex aIndex = myModel->findGroup(aUpdMsg->group()); int aStart = myModel->rowCount(aIndex); @@ -154,6 +153,9 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const return myModel->rowCount(theParent) + myPartModels.size(); } QModelIndex aParent = toSourceModelIndex(theParent); + if (!hasSubModel(aParent.model())) + return 0; + return aParent.model()->rowCount(aParent); } @@ -192,7 +194,9 @@ QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, const QMode QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const { QModelIndex aParent = toSourceModelIndex(theIndex); - const QAbstractItemModel* a = aParent.model(); + if (!hasSubModel(aParent.model())) + return QModelIndex(); + aParent = aParent.model()->parent(aParent); if (aParent.isValid()) return createIndex(aParent.row(), aParent.column(), (void*)getModelIndex(aParent)); @@ -248,6 +252,9 @@ void XGUI_DocumentDataModel::clearModelIndexes() FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const { QModelIndex aIndex = toSourceModelIndex(theIndex); + if (!hasSubModel(aIndex.model())) + return FeaturePtr(); + const XGUI_FeaturesModel* aModel = dynamic_cast(aIndex.model()); return aModel->feature(aIndex); } @@ -258,4 +265,34 @@ void XGUI_DocumentDataModel::insertRows(const QModelIndex& theParent, int theSta endInsertRows(); if (theStart == 0) // Update parent if this is a first child in order to update node decoration emit dataChanged(theParent, theParent); -} \ No newline at end of file +} + +void XGUI_DocumentDataModel::removeSubModel(int theModelId) +{ + XGUI_PartModel* aModel = myPartModels.at(theModelId); + QIntList aToRemove; + for (int i = 0; i < myIndexes.size(); i++) { + if (myIndexes.at(i)->model() == aModel) + aToRemove.append(i); + } + int aId; + while(aToRemove.size() > 0) { + aId = aToRemove.last(); + delete myIndexes.at(aId); + myIndexes.removeAt(aId); + aToRemove.removeLast(); + } + delete aModel; + myPartModels.removeAt(theModelId); +} + +bool XGUI_DocumentDataModel::hasSubModel(const QAbstractItemModel* theModel) const +{ + if (theModel == myModel) + return true; + QList::const_iterator aIt; + for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) + if ((*aIt) == theModel) + return true; + return false; +}