+
+ResultPartPtr XGUI_DocumentDataModel::activePart() const
+{
+ if (myActivePart)
+ return myActivePart->part();
+ return ResultPartPtr();
+}
+
+void XGUI_DocumentDataModel::deactivatePart()
+{
+ if (myActivePart)
+ myActivePart->setItemsColor(PASSIVE_COLOR);
+ myActivePart = 0;
+ myActivePartIndex = QModelIndex();
+ myModel->setItemsColor(ACTIVE_COLOR);
+ }
+
+Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
+{
+ Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex);
+ if (object(theIndex)) {
+ aFlags |= Qt::ItemIsEditable;
+ }
+ return aFlags;
+}
+
+QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const
+{
+ int aRow = -1;
+ XGUI_PartModel* aModel = 0;
+ foreach (XGUI_PartModel* aPartModel, myPartModels)
+ {
+ aRow++;
+ if (aPartModel->part() == theObject) {
+ aModel = aPartModel;
+ break;
+ }
+ }
+ if (aModel) {
+ return createIndex(aRow, 0, (void*) getModelIndex(aModel->index(0, 0, QModelIndex())));
+ }
+ return QModelIndex();
+}
+
+QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
+{
+ // Check that this feature belongs to root document
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ DocumentPtr aDoc = theObject->document();
+ if (aDoc == aRootDoc) {
+ // This feature belongs to histrory or top model
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature) {
+ int aId;
+ int aNb = aRootDoc->size(ModelAPI_Feature::group());
+ for (aId = 0; aId < aNb; aId++) {
+ if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId))
+ break;
+ }
+ if (aId < aNb)
+ return index(aId + historyOffset(), 0, QModelIndex());
+ } else {
+ QModelIndex aIndex = myModel->objectIndex(theObject);
+ return
+ aIndex.isValid() ?
+ createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) :
+ QModelIndex();
+ }
+ } else {
+ XGUI_PartModel* aPartModel = 0;
+ foreach(XGUI_PartModel* aModel, myPartModels)
+ {
+ if (aModel->hasDocument(aDoc)) {
+ aPartModel = aModel;
+ break;
+ }
+ }
+ if (aPartModel) {
+ QModelIndex aIndex = aPartModel->objectIndex(theObject);
+ return
+ aIndex.isValid() ?
+ createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) :
+ QModelIndex();
+ }
+ }
+ return QModelIndex();
+}