}
}
}
- }
-#ifdef _DEBUG
- else
- Events_Error::send("Problem with Data Model definition of sub-document");
-#endif
+ } else
+ rebuildDataTree();
}
}
// Deleted object event ***********************
std::string aObjType;
for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
ObjectPtr aObject = (*aIt);
- QModelIndex aIndex = objectIndex(aObject);
- if (aIndex.isValid())
- emit dataChanged(aIndex, aIndex);
+ if (aObject->data()->isValid()) {
+ QModelIndex aIndex = objectIndex(aObject);
+ if (aIndex.isValid())
+ emit dataChanged(aIndex, aIndex);
+ } else {
+ rebuildDataTree();
+ break;
+ }
}
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
else
// We have got a new document
rebuildDataTree();
-//#ifdef _DEBUG
-// else
-// Events_Error::send("Problem with Data Model definition of sub-document");
-//#endif
}
}
}
{
beginResetModel();
endResetModel();
+ emit treeRebuilt();
}
//******************************************************
/// Initialises XML data model reader. It must be initialised before DataModel using.
void setXMLReader(Config_DataModelReader* theReader) { myXMLReader = theReader; }
+signals:
+ void treeRebuilt();
+
private:
/// Find a root index which contains objects of the given document
/// \param theDoc the document object
aLabelWgt->setPalette(aPalet);
myDocModel = new XGUI_DataModel(this);
+ connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset()));
+ connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
SLOT(onContextMenuRequested(QContextMenuEvent*)));
//***************************************************
void XGUI_ObjectsBrowser::rebuildDataTree()
{
- QModelIndexList aIndexList = expandedItems();
myDocModel->rebuildDataTree();
- foreach(QModelIndex aIndex, aIndexList) {
- myTreeView->setExpanded(aIndex, true);
- }
update();
}
}
}
return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+ myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+ foreach(QModelIndex aIndex, myExpandedItems) {
+ myTreeView->setExpanded(aIndex, true);
+ }
+}
//! Called when selection in Data Tree is changed
void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
+ void onBeforeReset();
+
+ void onAfterModelReset();
+
private:
QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
XGUI_DataModel* myDocModel;
XGUI_ActiveDocLbl* myActiveDocLbl;
XGUI_DataTree* myTreeView;
+
+ /// A field to store expanded items before model reset
+ QModelIndexList myExpandedItems;
};
#endif
{
QStringList aObjectNames;
foreach (ObjectPtr aObj, theObjects) {
- if (!aObj->data()->isValid())
- continue;
- aObjectNames << QString::fromStdString(aObj->data()->name());
+ if (aObj->data()->isValid())
+ aObjectNames << QString::fromStdString(aObj->data()->name());
}
- return aObjectNames.join(", ");
+ if (aObjectNames.count() == 0)
+ return QString();
+ if (aObjectNames.count() == 1)
+ return aObjectNames.first();
+ return aObjectNames.join(theSeparator);
}
//******************************************************************
if (ModuleBase_Tools::isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures,
aIndirectRefFeatures, desktop(), doDeleteReferences)) {
// start operation
- QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
- aDescription += " " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
+ QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
+ aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
operationMgr()->startOperation(anOpAction);