//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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; }