8000 Adding/changing names of stations by rinkk · Pull Request #1273 · ufz/ogs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding/changing names of stations #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Applications/DataExplorer/DataView/StationTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: You can compare for equality using ==.


if (id >= (*stn_list)->childCount())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if nothing is found?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If child count is 0 everything still works fine. Also, empty station lists are not added when opening a file so this could not even happen.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you are searching for a station with a wrong name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. You need to have clicked on a specific list to set this whole thing into motion, how can it not exist?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add an assertion here. Such things should not happen, but programming errors do happen.

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.
Expand Down
1 change: 1 addition & 0 deletions Applications/DataExplorer/DataView/StationTreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class StationTreeModel : public TreeModel
//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;

Expand Down
16 changes: 12 additions & 4 deletions Applications/DataExplorer/DataView/StationTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better (i.e. safer) to use dynamic_cast here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you plan to rewrite the whole station model without changing this specific line it doesn't matter...

== GeoLib::Station::StationType::BOREHOLE)
{
QAction* stratAction = menu.addAction("Display Stratigraphy...");
QAction* exportAction = menu.addAction("Export to GMS...");
Expand All @@ -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()));
Expand All @@ -127,6 +127,14 @@ void StationTreeView::contextMenuEvent( QContextMenuEvent* event )
}
}

void StationTreeView::setNameForElement()
{
TreeItem const*const item = static_cast<StationTreeModel*>(model())->getItem(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise: dynamic_cast?

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();
Expand Down
3 changes: 3 additions & 0 deletions Applications/DataExplorer/DataView/StationTreeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private slots:
void exportList();
void exportStation();
void removeStationList();
/// Calls a SetNameDialog.
void setNameForElement();
void writeToFile();
void showDiagramPrefsDialog();

Expand All @@ -73,6 +75,7 @@ private slots:
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);
Expand Down
14 changes: 14 additions & 0 deletions Applications/DataExplorer/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Applications/DataExplorer/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions GeoLib/Station.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class Station : public Point
/// 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; }

Expand Down
2 changes: 2 additions & 0 deletions Tests/GeoLib/TestDuplicateGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
0