diff --git a/Applications/DataExplorer/DataView/StationTreeModel.cpp b/Applications/DataExplorer/DataView/StationTreeModel.cpp index 64a8693b8942aab271ca7140b46e1b0b16aa12fa..36e4f2474fde2f13b5da064dd373af5ad1d509af 100644 --- a/Applications/DataExplorer/DataView/StationTreeModel.cpp +++ b/Applications/DataExplorer/DataView/StationTreeModel.cpp @@ -102,6 +102,17 @@ vtkPolyDataAlgorithm* StationTreeModel::vtkSource(const std::string &name) const return nullptr; } +void StationTreeModel::setNameForItem(const std::string &stn_vec_name, std::size_t id, std::string const& item_name) +{ + auto const stn_list = find_if(_lists.begin(), _lists.end(), [&stn_vec_name](ModelTreeItem* item) + { return (stn_vec_name.compare( item->data(0).toString().toStdString() ) == 0); }); + + if (id >= (*stn_list)->childCount()) + return; + TreeItem *const item = (*stn_list)->child(id); + item->setData(0, QString::fromStdString(item_name)); +} + /** * Inserts a subtree under _rootItem. * \param listName Name of the new subtree. If no name is given a default name is assigned. diff --git a/Applications/DataExplorer/DataView/StationTreeModel.h b/Applications/DataExplorer/DataView/StationTreeModel.h index 5213b0b12759e3271d2894ff588a714cf8d13463..de78aa234d53b90aa27fe0a5ba75b0f871e9160f 100644 --- a/Applications/DataExplorer/DataView/StationTreeModel.h +++ b/Applications/DataExplorer/DataView/StationTreeModel.h @@ -53,6 +53,7 @@ public: //BaseItem* itemFromIndex( const QModelIndex& index ) const; void removeStationList(QModelIndex index); void removeStationList(const std::string &name); + void setNameForItem(const std::string &stn_vec_name, std::size_t id, std::string const& item_name); GeoLib::Station* stationFromIndex( const QModelIndex& index, QString &listName ) const; vtkPolyDataAlgorithm* vtkSource(const std::string &name) const; diff --git a/Applications/DataExplorer/DataView/StationTreeView.cpp b/Applications/DataExplorer/DataView/StationTreeView.cpp index 80d5d196144a6cd7fb586e0bd0167571e1393080..371d6ae1bcf5a74cf3c9d3b95127ccf497890ea7 100644 --- a/Applications/DataExplorer/DataView/StationTreeView.cpp +++ b/Applications/DataExplorer/DataView/StationTreeView.cpp @@ -106,9 +106,10 @@ void StationTreeView::contextMenuEvent( QContextMenuEvent* event ) QString temp_name; QMenu menu; - if (static_cast<StationTreeModel*>(model())->stationFromIndex(index, - temp_name)->type() == - GeoLib::Station::StationType::BOREHOLE) + QAction* setNameAction = menu.addAction("Set name..."); + connect(setNameAction, SIGNAL(triggered()), this, SLOT(setNameForElement())); + if (static_cast<StationTreeModel*>(model())->stationFromIndex(index, temp_name)->type() + == GeoLib::Station::StationType::BOREHOLE) { QAction* stratAction = menu.addAction("Display Stratigraphy..."); QAction* exportAction = menu.addAction("Export to GMS..."); @@ -118,7 +119,6 @@ void StationTreeView::contextMenuEvent( QContextMenuEvent* event ) } else { - menu.addAction("View Information..."); QAction* showDiagramAction = menu.addAction("View Diagram..."); connect(showDiagramAction, SIGNAL(triggered()), this, SLOT(showDiagramPrefsDialog())); @@ -127,6 +127,14 @@ void StationTreeView::contextMenuEvent( QContextMenuEvent* event ) } } +void StationTreeView::setNameForElement() +{ + TreeItem const*const item = static_cast<StationTreeModel*>(model())->getItem( + this->selectionModel()->currentIndex()); + std::string const stn_vec_name = item->parentItem()->data(0).toString().toStdString(); + emit requestNameChangeDialog(stn_vec_name, item->row()); +} + void StationTreeView::displayStratigraphy() { QModelIndex index = this->selectionModel()->currentIndex(); diff --git a/Applications/DataExplorer/DataView/StationTreeView.h b/Applications/DataExplorer/DataView/StationTreeView.h index 0870b2735ccc114a843bad57ad85d39b5e08908d..d3a89b4509c8dd8803596afe9415b9fa35a9f844 100644 --- a/Applications/DataExplorer/DataView/StationTreeView.h +++ b/Applications/DataExplorer/DataView/StationTreeView.h @@ -61,6 +61,8 @@ private slots: void exportList(); void exportStation(); void removeStationList(); + /// Calls a SetNameDialog. + void setNameForElement(); void writeToFile(); void showDiagramPrefsDialog(); @@ -73,6 +75,7 @@ signals: const QItemSelection & deselected); void openStationListFile(int); void propertiesDialogRequested(std::string name); + void requestNameChangeDialog(const std::string&, std::size_t); void stationListExportRequested(std::string listName, std::string fileName); void stationListRemoved(std::string name); void stationListSaved(QString listName, QString fileName); diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index ffea4aff4af38b478104b1ac93ae4f6a1fb32639..b271204aab86e5ec965e086ad0bd51bfca06a24e 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -131,6 +131,8 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) SLOT(writeStationListToFile(QString, QString))); // save Stationlist to File connect(_geo_model.get(), SIGNAL(stationVectorRemoved(StationTreeModel *, std::string)), this, SLOT(updateDataViews())); // update data view when stations are removed + connect(stationTabWidget->treeView, SIGNAL(requestNameChangeDialog(const std::string&, std::size_t)), + this, SLOT(showStationNameDialog(const std::string&, std::size_t))); connect(stationTabWidget->treeView, SIGNAL(diagramRequested(QModelIndex &)), this, SLOT(showDiagramPrefsDialog(QModelIndex &))); // connect treeview to diagramview @@ -1002,6 +1004,18 @@ void MainWindow::showGeoNameDialog(const std::string &geometry_name, const GeoLi id, _project.getGEOObjects().getElementNameByID(geometry_name, object_type, id)); } +void MainWindow::showStationNameDialog(const std::string& stn_vec_name, std::size_t id) +{ + std::vector<GeoLib::Point*> const* stations = _project.getGEOObjects().getStationVec(stn_vec_name); + GeoLib::Station *const stn = static_cast<GeoLib::Station*>((*stations)[id]); + SetNameDialog dlg("Station", id, stn->getName()); + if (dlg.exec() != QDialog::Accepted) + return; + + stn->setName(dlg.getNewName()); + static_cast<StationTreeModel*>(this->stationTabWidget->treeView->model())->setNameForItem(stn_vec_name, id, stn->getName()); +} + void MainWindow::showCreateStructuredGridDialog() { CreateStructuredGridDialog dlg; diff --git a/Applications/DataExplorer/mainwindow.h b/Applications/DataExplorer/mainwindow.h index 81436b36df9376798b09cb92da553bd56d473c82..9c2b6e6af283f2380b349f885164bb60f7b06b9b 100644 --- a/Applications/DataExplorer/mainwindow.h +++ b/Applications/DataExplorer/mainwindow.h @@ -88,6 +88,8 @@ protected slots: void showDataExplorerSettingsDialog(); /// Allows setting the name for a geometric object void showGeoNameDialog(const std::string &geometry_name, const GeoLib::GEOTYPE object_type, std::size_t id); + /// Allows setting the name for a station + void showStationNameDialog(const std::string& stn_vec_name, std::size_t id); /// Creates a structured grid with user-specified parameters. void showCreateStructuredGridDialog(); /// Removal of mesh elements based on a number of criteria. diff --git a/GeoLib/Station.h b/GeoLib/Station.h index 9305b5af59db255d47eeaaa1c904952e1a55e802..a704924b07fc22e6bd8895db32325d28d2425f41 100644 --- a/GeoLib/Station.h +++ b/GeoLib/Station.h @@ -72,6 +72,8 @@ public: /// Returns the name of the station. std::string const& getName() const { return _name; } + void setName(std::string const& name) { _name = name; } + /// Returns the GeoSys-station-type for the station. StationType type() const { return _type; } diff --git a/Tests/GeoLib/TestDuplicateGeometry.cpp b/Tests/GeoLib/TestDuplicateGeometry.cpp index 84505f668dc8c3595c3e04524cb8955a1bd5806e..90490acb197355907605e673a8bd1c5275f90d93 100644 --- a/Tests/GeoLib/TestDuplicateGeometry.cpp +++ b/Tests/GeoLib/TestDuplicateGeometry.cpp @@ -41,6 +41,8 @@ TEST(GeoLib, DuplicateGeometry) std::rand() % box_size - half_box_size)); } geo.addPointVec(std::move(pnts), input_name); + // update number of points in case because possibly non-unique points have been removed + n_pnts = geo.getPointVec(input_name)->size(); std::string output ("output_geometry"); // duplicate points