void StationTreeView::contextMenuEvent( QContextMenuEvent* event ) { QModelIndex index = this->selectionModel()->currentIndex(); ModelTreeItem* item = static_cast<ModelTreeItem*>(index.internalPointer()); if (!item) // Otherwise sometimes it crashes when (unmotivated ;-) ) clicking in a treeview return; // The current index refers to a parent item (e.g. a listname) if (item->childCount() > 0) { QMenu menu; QAction* propertyAction = menu.addAction("Display list properties..."); QAction* exportAction = menu.addAction("Export to GMS..."); QAction* saveAction = menu.addAction("Save to file..."); menu.addSeparator(); QAction* removeAction = menu.addAction("Remove station list"); connect(propertyAction, SIGNAL(triggered()), this, SLOT(showPropertiesDialog())); connect(exportAction, SIGNAL(triggered()), this, SLOT(exportList())); connect(saveAction, SIGNAL(triggered()), this, SLOT(saveList())); connect(removeAction, SIGNAL(triggered()), this, SLOT(removeStationList())); menu.exec(event->globalPos()); } // The current index refers to a station object else { QString temp_name; QMenu menu; if (static_cast<StationTreeModel*>(model())->stationFromIndex(index, temp_name)->type() == GeoLib::Station::BOREHOLE) { QAction* stratAction = menu.addAction("Display Stratigraphy..."); QAction* exportAction = menu.addAction("Export to GMS..."); connect(stratAction, SIGNAL(triggered()), this, SLOT(displayStratigraphy())); connect(exportAction, SIGNAL(triggered()), this, SLOT(exportStation())); menu.exec(event->globalPos()); } else { menu.addAction("View Information..."); QAction* showDiagramAction = menu.addAction("View Diagram..."); connect(showDiagramAction, SIGNAL(triggered()), this, SLOT(showDiagramPrefsDialog())); menu.exec(event->globalPos()); } } }
/** * Filters the station list based on the property boundaries given in bounds. * Technically, the complete station list is removed from the model and only those items are re-loaded that fit the description. * If no station in the list fulfills the given description an error msg is given. */ void StationTreeModel::filterStations(const std::string &listName, const std::vector<GeoLib::Point*>* stations, const std::vector<PropertyBounds> &bounds) { std::vector<GeoLib::Point*>* filteredStations = new std::vector<GeoLib::Point*>; size_t vectorSize = stations->size(); for (size_t i = 0; i < vectorSize; i++) if (static_cast<GeoLib::Station*>((*stations)[i])->inSelection(bounds)) filteredStations->push_back((*stations)[i]); if (filteredStations->empty()) OGSError::box("No object is within the given boundaries."); //The filtered list is empty. else { removeStationList(listName); this->addStationList(QString::fromStdString(listName), filteredStations); INFO("Filter applied to List \"%s\", %d items added.", listName.c_str(), filteredStations->size()); } }
/** * Removes the TreeItem with the given name including all its children */ void StationTreeModel::removeStationList(const std::string &name) { for (size_t i = 0; i < _lists.size(); i++) if ( name.compare( _lists[i]->data(0).toString().toStdString() ) == 0 ) removeStationList(createIndex(_lists[i]->row(), 0, _lists[i])); }