- beginResetModel();
- int aNbParts = myDocument->featuresIterator(PARTS_GROUP)->numIterationsLeft();
- if (myPartModels.size() != aNbParts) { // resize internal models
- while (myPartModels.size() > aNbParts) {
- delete myPartModels.last();
- myPartModels.removeLast();
+ // Created object event *******************
+ if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) {
+ const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+ boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+ boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
+
+ if (aDoc == myDocument) { // If root objects
+ if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Updsate only Parts group
+ // Add a new part
+ int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size() + 1;
+ XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
+ aModel->setPartId(myPartModels.count());
+ myPartModels.append(aModel);
+ insertRows(QModelIndex(), aStart, aStart);
+ } else { // Update top groups (other except parts
+ QModelIndex aIndex = myModel->findParent(aFeature);
+ int aStart = myModel->rowCount(aIndex) - 1;
+ aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
+ insertRows(aIndex, aStart, aStart);
+ }
+ } else { // if sub-objects of first level nodes
+ XGUI_PartModel* aPartModel = 0;
+ QList<XGUI_PartModel*>::const_iterator aIt;
+ for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
+ if ((*aIt)->hasDocument(aDoc)) {
+ aPartModel = (*aIt);
+ break;
+ }
+ }
+ if (aPartModel) {
+ QModelIndex aIndex = aPartModel->findParent(aFeature);
+ int aStart = aPartModel->rowCount(aIndex) - 1;
+ aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
+ insertRows(aIndex, aStart, aStart);
+ }