//-------------------------------------------------------------------------------------------------- /// Refreshes the UI-tree below the supplied root PdmObject //-------------------------------------------------------------------------------------------------- void UiTreeModelPdm::updateUiSubTree(PdmObject* pdmRoot) { // Build the new "Correct" Tree PdmUiTreeItem* tempUpdatedPdmTree = UiTreeItemBuilderPdm::buildViewItems(NULL, -1, pdmRoot); // Find the corresponding entry for "root" in the existing Ui tree QModelIndex uiSubTreeRootModelIdx = getModelIndexFromPdmObject(pdmRoot); PdmUiTreeItem* uiModelSubTreeRoot = NULL; if (uiSubTreeRootModelIdx.isValid()) { uiModelSubTreeRoot = getTreeItemFromIndex(uiSubTreeRootModelIdx); } else { uiModelSubTreeRoot = m_treeItemRoot; } updateModelSubTree(uiSubTreeRootModelIdx, uiModelSubTreeRoot, tempUpdatedPdmTree); delete tempUpdatedPdmTree; }
//-------------------------------------------------------------------------------------------------- /// Enable edit of this item if we have a editable user description field for a pdmObject /// Disable edit for other items //-------------------------------------------------------------------------------------------------- Qt::ItemFlags UiTreeModelPdm::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; Qt::ItemFlags flagMask = QAbstractItemModel::flags(index); PdmUiTreeItem* treeItem = getTreeItemFromIndex(index); if (treeItem) { PdmObject* pdmObject = treeItem->dataObject(); if (pdmObject) { if (pdmObject->userDescriptionField() && !pdmObject->userDescriptionField()->isUiReadOnly()) { flagMask = flagMask | Qt::ItemIsEditable; } if (pdmObject->objectToggleField()) { flagMask = flagMask | Qt::ItemIsUserCheckable; } } } else { flagMask = flagMask & (~Qt::ItemIsEditable); } return flagMask; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimUiTreeModelPdm::deleteInputProperty(const QModelIndex& itemIndex) { if (!itemIndex.isValid()) return; caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex); if (!uiItem) return; caf::PdmObject* object = uiItem->dataObject().p(); RimInputProperty* inputProperty = dynamic_cast<RimInputProperty*>(object); if (!inputProperty) return; // Remove item from UI tree model before delete of project data structure removeRow(itemIndex.row(), itemIndex.parent()); std::vector<caf::PdmObject*> parentObjects; object->parentObjects(parentObjects); CVF_ASSERT(parentObjects.size() == 1); RimInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimInputPropertyCollection*>(parentObjects[0]); if (!inputPropertyCollection) return; std::vector<caf::PdmObject*> parentObjects2; inputPropertyCollection->parentObjects(parentObjects2); CVF_ASSERT(parentObjects2.size() == 1); RimInputReservoir* inputReservoir = dynamic_cast<RimInputReservoir*>(parentObjects2[0]); if (!inputReservoir) return; inputReservoir->removeProperty(inputProperty); delete inputProperty; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex) { CVF_ASSERT(itemIndex.isValid()); caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex); CVF_ASSERT(uiItem); RimCellRangeFilter* rangeFilter = dynamic_cast<RimCellRangeFilter*>(uiItem->dataObject().p()); CVF_ASSERT(rangeFilter); RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer(); CVF_ASSERT(rangeFilterCollection); bool wasFilterActive = rangeFilter->active(); bool wasSomeFilterActive = rangeFilterCollection->hasActiveFilters(); // Remove Ui items pointing at the pdm object to delete removeRow(itemIndex.row(), itemIndex.parent()); rangeFilterCollection->remove(rangeFilter); delete rangeFilter; if (wasFilterActive) { rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::PROPERTY_FILTERED); } if (wasSomeFilterActive) { rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RimUiTreeModelPdm::insertRows(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/) { caf::PdmUiTreeItem* parentItem = getTreeItemFromIndex(parent); bool canCreateChildren = false; QModelIndex parentIndex = parent; if (dynamic_cast<RimCellRangeFilterCollection*>(parentItem->dataObject().p()) || dynamic_cast<RimCellPropertyFilterCollection*>(parentItem->dataObject().p())) { canCreateChildren = true; } else if (dynamic_cast<RimCellFilter*>(parentItem->dataObject().p())) { parentItem = parentItem->parent(); parentIndex = parent.parent(); canCreateChildren = true; } if (canCreateChildren) { beginInsertRows(parent, position, position + rows - 1); int i; for (i = 0; i < rows; i++) { if (dynamic_cast<RimCellRangeFilterCollection*>(parentItem->dataObject().p())) { RimCellRangeFilterCollection* rangeFilterCollection = dynamic_cast<RimCellRangeFilterCollection*>(parentItem->dataObject().p()); RimCellRangeFilter* rangeFilter = rangeFilterCollection->createAndAppendRangeFilter(); caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentItem, position + i, rangeFilter); } else if (dynamic_cast<RimCellPropertyFilterCollection*>(parentItem->dataObject().p())) { RimCellPropertyFilterCollection* propertyFilterCollection = dynamic_cast<RimCellPropertyFilterCollection*>(parentItem->dataObject().p()); RimCellPropertyFilter* propertyFilter = propertyFilterCollection->createAndAppendPropertyFilter(); caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentItem, position + i, propertyFilter); } } endInsertRows(); } return canCreateChildren; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RimUiTreeModelPdm::deleteReservoirView(const QModelIndex& itemIndex) { CVF_ASSERT(itemIndex.isValid()); caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex); CVF_ASSERT(uiItem); RimReservoirView* reservoirView = dynamic_cast<RimReservoirView*>(uiItem->dataObject().p()); CVF_ASSERT(reservoirView); // Remove Ui items pointing at the pdm object to delete removeRow(itemIndex.row(), itemIndex.parent()); reservoirView->eclipseCase()->removeReservoirView(reservoirView); delete reservoirView; return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimCellRangeFilter* RimUiTreeModelPdm::addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex) { caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex); QModelIndex collectionIndex; RimCellRangeFilterCollection* rangeFilterCollection = NULL; caf::PdmUiTreeItem* rangeFilterCollectionItem = NULL; int position = 0; if (dynamic_cast<RimCellRangeFilter*>(currentItem->dataObject().p())) { RimCellRangeFilter* rangeFilter = dynamic_cast<RimCellRangeFilter*>(currentItem->dataObject().p()); rangeFilterCollection = rangeFilter->parentContainer(); rangeFilterCollectionItem = currentItem->parent(); position = itemIndex.row(); collectionIndex = itemIndex.parent(); } else if (dynamic_cast<RimCellRangeFilterCollection*>(currentItem->dataObject().p())) { rangeFilterCollection = dynamic_cast<RimCellRangeFilterCollection*>(currentItem->dataObject().p()); rangeFilterCollectionItem = currentItem; position = rangeFilterCollectionItem->childCount(); collectionIndex = itemIndex; } beginInsertRows(collectionIndex, position, position); RimCellRangeFilter* rangeFilter = rangeFilterCollection->createAndAppendRangeFilter(); caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(rangeFilterCollectionItem, position, rangeFilter); endInsertRows(); insertedModelIndex = index(position, 0, collectionIndex); if (rangeFilterCollection) { rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); } return rangeFilter; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimUiTreeModelPdm::addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames) { caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex); RimInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimInputPropertyCollection*>(currentItem->dataObject().p()); CVF_ASSERT(inputPropertyCollection); std::vector<caf::PdmObject*> parentObjects; inputPropertyCollection->parentObjects(parentObjects); CVF_ASSERT(parentObjects.size() == 1); RimInputReservoir* inputReservoir = dynamic_cast<RimInputReservoir*>(parentObjects[0]); CVF_ASSERT(inputReservoir); if (inputReservoir) { inputReservoir->openDataFileSet(fileNames); } this->rebuildUiSubTree(inputPropertyCollection); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool UiTreeModelPdm::removeRows_special(int position, int count, const QModelIndex &parent /*= QModelIndex()*/) { if (count <= 0) return true; PdmUiTreeItem* parentItem = NULL; if (parent.isValid()) { parentItem = getTreeItemFromIndex(parent); } else { parentItem = m_treeItemRoot; } if (!parentItem) return true; bool success = true; beginRemoveRows(parent, position, position + count - 1); success = parentItem->removeChildren(position, count); endRemoveRows(); return success; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimReservoirView* RimUiTreeModelPdm::addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex) { caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex); if (!currentItem) return NULL; RimReservoirView* reservoirView = dynamic_cast<RimReservoirView*>(currentItem->dataObject().p()); if (!reservoirView) return NULL; RimReservoirView* insertedView = reservoirView->eclipseCase()->createAndAddReservoirView(); caf::PdmUiTreeItem* collectionItem = currentItem->parent(); size_t viewCount = rowCount(itemIndex.parent()); beginInsertRows(itemIndex.parent(), viewCount, viewCount); caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(collectionItem, viewCount, insertedView); endInsertRows(); insertedView->loadDataAndUpdate(); rebuildUiSubTree(insertedView); return insertedView; }