+QModelIndex XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const
+{
+ QModelIndex* aIndexPtr = static_cast<QModelIndex*>(theProxy.internalPointer());
+ return (*aIndexPtr);
+}
+
+
+QModelIndex* XGUI_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const
+{
+ QList<QModelIndex*>::const_iterator aIt;
+ for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) {
+ QModelIndex* aIndex = (*aIt);
+ if ((*aIndex) == theIndex)
+ return aIndex;
+ }
+ return 0;
+}
+
+QModelIndex* XGUI_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const
+{
+ QModelIndex* aIndexPtr = findModelIndex(theIndex);
+ if (!aIndexPtr) {
+ aIndexPtr = new QModelIndex(theIndex);
+ XGUI_DocumentDataModel* that = (XGUI_DocumentDataModel*) this;
+ that->myIndexes.append(aIndexPtr);
+ }
+ return aIndexPtr;
+}
+
+void XGUI_DocumentDataModel::clearModelIndexes()
+{
+ QList<QModelIndex*>::const_iterator aIt;
+ for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt)
+ delete (*aIt);
+ myIndexes.clear();
+}
+
+FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const
+{
+ QModelIndex aIndex = toSourceModelIndex(theIndex);
+ if (!hasSubModel(aIndex.model()))
+ return FeaturePtr();
+
+ const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex.model());
+ return aModel->feature(aIndex);
+}
+
+void XGUI_DocumentDataModel::insertRows(const QModelIndex& theParent, int theStart, int theEnd)
+{
+ beginInsertRows(theParent, theStart, theEnd);
+ endInsertRows();
+ if (theStart == 0) // Update parent if this is a first child in order to update node decoration
+ emit dataChanged(theParent, theParent);
+}
+
+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<XGUI_PartModel*>::const_iterator aIt;
+ for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt)
+ if ((*aIt) == theModel)
+ return true;