-
Notifications
You must be signed in to change notification settings - Fork 239
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if nothing is found? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if you are searching for a station with a wrong name? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better (i.e. safer) to use dynamic_cast here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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..."); | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment.
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 ==.