OGS
StationTreeView.cpp
Go to the documentation of this file.
1
15#include "StationTreeView.h"
16
17#include <QFileDialog>
18#include <QMenu>
19
23#include "Base/OGSError.h"
26#include "GeoLib/Station.h"
27#include "ModelTreeItem.h"
28#include "StationTreeModel.h"
29
30StationTreeView::StationTreeView(QWidget* parent) : QTreeView(parent)
31{
32 // setContextMenuPolicy(Qt::CustomContextMenu);
33 // connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
34 // this, SLOT(showContextMenu(const QPoint &)));
35}
36
38{
39 setAlternatingRowColors(true);
40 setColumnWidth(0, 150);
41 setColumnWidth(1, 75);
42 setColumnWidth(2, 75);
43 setColumnWidth(3, 75);
44}
45
46void StationTreeView::selectionChanged(const QItemSelection& selected,
47 const QItemSelection& deselected)
48{
49 Q_UNUSED(deselected);
50 if (!selected.isEmpty())
51 {
52 const QModelIndex idx = *(selected.indexes().begin());
53 const TreeItem* tree_item =
54 static_cast<TreeModel*>(this->model())->getItem(idx);
55
56 const auto* list_item =
57 dynamic_cast<const ModelTreeItem*>(tree_item->parentItem());
58 if (list_item->getItem())
59 {
60 if (list_item)
61 {
62 emit geoItemSelected(list_item->getItem()->vtkSource(),
63 tree_item->row());
64 }
65 emit enableRemoveButton(false);
66 emit enableSaveButton(false);
67 }
68 else
69 {
71 emit enableSaveButton(true);
72 emit enableRemoveButton(true);
73 }
74 }
75 // emit itemSelectionChanged(selected, deselected);
76 // return QTreeView::selectionChanged(selected, deselected);
77}
78
80 const QItemSelection& selected, const QItemSelection& deselected)
81{
82 QItemSelectionModel* selModel = this->selectionModel();
83
84 selModel->blockSignals(true);
85 selModel->select(deselected, QItemSelectionModel::Deselect);
86 selModel->select(selected, QItemSelectionModel::Select);
87 selModel->blockSignals(false);
88
89 return QTreeView::selectionChanged(selected, deselected);
90}
91
92void StationTreeView::contextMenuEvent(QContextMenuEvent* event)
93{
94 QModelIndex index = this->selectionModel()->currentIndex();
95 auto* item = static_cast<ModelTreeItem*>(index.internalPointer());
96
97 if (!item)
98 { // Otherwise sometimes it crashes when (unmotivated ;-) ) clicking in a
99 // treeview
100 return;
101 }
102
103 // The current index refers to a parent item (e.g. a listname)
104 if (item->childCount() > 0)
105 {
106 QMenu menu;
107 QAction* mapAction = menu.addAction("Map stations...");
108 QAction* exportAction = menu.addAction("Export to GMS...");
109 menu.addSeparator();
110
111 connect(mapAction, SIGNAL(triggered()), this, SLOT(mapStations()));
112 connect(exportAction, SIGNAL(triggered()), this, SLOT(exportList()));
113 menu.exec(event->globalPos());
114 }
115 // The current index refers to a station object
116 else
117 {
118 QString temp_name;
119 QMenu menu;
120
121 QAction* setNameAction = menu.addAction("Set name...");
122 connect(setNameAction, SIGNAL(triggered()), this,
123 SLOT(setNameForElement()));
124 if (dynamic_cast<GeoLib::StationBorehole*>(
125 static_cast<StationTreeModel*>(model())->stationFromIndex(
126 index, temp_name)))
127 {
128 QAction* stratAction = menu.addAction("Display Stratigraphy...");
129 QAction* exportAction = menu.addAction("Export to GMS...");
130 connect(stratAction, SIGNAL(triggered()), this,
131 SLOT(displayStratigraphy()));
132 connect(exportAction, SIGNAL(triggered()), this,
133 SLOT(exportStation()));
134 menu.exec(event->globalPos());
135 }
136 else
137 {
138 QAction* showDiagramAction = menu.addAction("View Diagram...");
139 connect(showDiagramAction, SIGNAL(triggered()), this,
140 SLOT(showDiagramPrefsDialog()));
141 menu.exec(event->globalPos());
142 }
143 }
144}
145
147{
148 TreeItem const* const item =
149 static_cast<StationTreeModel*>(model())->getItem(
150 this->selectionModel()->currentIndex());
151 std::string const stn_vec_name =
152 item->parentItem()->data(0).toString().toStdString();
153 emit requestNameChangeDialog(stn_vec_name, item->row());
154}
155
157{
158 TreeItem const* const item =
159 static_cast<StationTreeModel*>(model())->getItem(
160 this->selectionModel()->currentIndex());
161 std::string const& geo_name(item->data(0).toString().toStdString());
162 emit geometryMappingRequested(geo_name);
163}
164
166{
167 QModelIndex index = this->selectionModel()->currentIndex();
168
169 QString temp_name;
170 // get list name
171 static_cast<StationTreeModel*>(model())->stationFromIndex(
172 this->selectionModel()->currentIndex(), temp_name);
173 // get color table (horrible way to do it but there you go ...)
174 std::map<std::string, DataHolderLib::Color> colorLookupTable =
175 static_cast<VtkStationSource*>(
176 static_cast<StationTreeModel*>(model())->vtkSource(
177 temp_name.toStdString()))
179 auto* stratView = new StratWindow(
180 static_cast<GeoLib::StationBorehole*>(
181 static_cast<StationTreeModel*>(model())->stationFromIndex(
182 index, temp_name)),
183 &colorLookupTable);
184 stratView->setAttribute(
185 Qt::WA_DeleteOnClose); // this fixes the memory leak shown by cppcheck
186 stratView->show();
187}
188
193
195{
196 QModelIndex index(this->selectionModel()->currentIndex());
197 if (!index.isValid())
198 {
199 OGSError::box("No station list selected.");
200 }
201 else
202 {
203 TreeItem* item =
204 static_cast<StationTreeModel*>(model())->getItem(index);
205 QString listName = item->data(0).toString();
206 QString fileName = QFileDialog::getSaveFileName(
207 this, "Save station list",
208 LastSavedFileDirectory::getDir() + listName, "*.stn");
209 if (!fileName.isEmpty())
210 {
212 emit stationListSaved(listName, fileName);
213 }
214 }
215}
216
218{
219 // only a test for the stratigraphy screenshot tool and writer!!
220 // QString Name =
221 // static_cast<StationTreeModel*>(model())->getItem(this->selectionModel()->currentIndex())->data(0).toString();
222 // writeStratigraphiesAsImages(Name);
223
224 TreeItem* item = static_cast<StationTreeModel*>(model())->getItem(
225 this->selectionModel()->currentIndex());
226 QString listName = item->data(0).toString();
227 QString fileName = QFileDialog::getSaveFileName(
228 this, "Export Boreholes to GMS-Format",
229 LastSavedFileDirectory::getDir() + listName, "*.txt");
230 if (!fileName.isEmpty())
231 {
233 emit stationListExportRequested(listName.toStdString(),
234 fileName.toStdString());
235 }
236}
237
239{
240 QModelIndex index = this->selectionModel()->currentIndex();
241 QString fileName =
242 QFileDialog::getSaveFileName(this, "Export Borehole to GMS-Format",
244 if (!fileName.isEmpty())
245 {
246 QString temp_name;
247 std::vector<GeoLib::Point*> stations;
248 stations.push_back(static_cast<GeoLib::StationBorehole*>(
249 static_cast<StationTreeModel*>(model())->stationFromIndex(
250 index, temp_name)));
252 fileName.toStdString());
254 }
255}
256
258{
259 QModelIndex index(this->selectionModel()->currentIndex());
260 if (!index.isValid())
261 {
262 OGSError::box("No station list selected.");
263 }
264 else
265 {
266 TreeItem* item =
267 static_cast<StationTreeModel*>(model())->getItem(index);
268 emit stationListRemoved((item->data(0).toString()).toStdString());
269
270 if (this->selectionModel()->selectedIndexes().count() == 0)
271 {
272 emit enableSaveButton(false);
273 emit enableRemoveButton(false);
274 }
275 }
276}
277
279{
280 QModelIndex index = this->selectionModel()->currentIndex();
281 emit diagramRequested(index);
282}
283
285{
286 std::map<std::string, DataHolderLib::Color> colorLookupTable =
287 static_cast<VtkStationSource*>(
288 static_cast<StationTreeModel*>(model())->vtkSource(
289 listName.toStdString()))
291 std::vector<ModelTreeItem*> lists =
292 static_cast<StationTreeModel*>(model())->getLists();
293 std::size_t nLists = lists.size();
294 for (std::size_t i = 0; i < nLists; i++)
295 {
296 if (listName.compare(lists[i]->data(0).toString()) != 0)
297 {
298 continue;
299 }
300
301 std::vector<GeoLib::Point*> const& stations =
302 *dynamic_cast<BaseItem*>(lists[i]->getItem())->getStations();
303
304 for (auto station : stations)
305 {
306 auto* stratView =
307 new StratWindow(static_cast<GeoLib::StationBorehole*>(station),
308 &colorLookupTable);
309 stratView->setAttribute(Qt::WA_DeleteOnClose);
310 stratView->show();
311 stratView->stationView->saveAsImage(
312 QString::fromStdString(
313 static_cast<GeoLib::StationBorehole*>(station)->getName()) +
314 ".jpg");
315 stratView->close();
316 }
317 }
318}
Definition of the DiagramPrefsDialog class.
Definition of the GMSInterface class.
Definition of the ImportFileTypes enumeration.
Manages the last directory used for saving a file.
Definition of the ModelTreeItem class.
Definition of the OGSError class.
Definition of the StationTreeModel class.
Definition of the StationTreeView class.
Definition of the Station class.
Definition of the StratWindow class.
std::string getName(std::string const &line)
Returns the name/title from the "Zone"-description.
A BaseItem contains additional Information about a subtree in the StationTreeModel.
Definition BaseItem.h:32
static void writeBoreholesToGMS(const std::vector< GeoLib::Point * > *stations, const std::string &filename)
A borehole as a geometric object.
static void setDir(const QString &path)
Sets the directory last used for saving a file.
static const QString getDir()
Returns the directory last used for saving a file.
A TreeItem containing some additional information used in the StationModel.
static void box(const QString &e)
Definition OGSError.cpp:23
A model for the StationTreeView implementing a tree as a double-linked list.
void updateView()
Update the view to visualise changes made to the underlying data.
void selectionChangedFromOutside(const QItemSelection &selected, const QItemSelection &deselected)
Instructions if the selection of items in the view has changed by events outside the view (i....
void requestNameChangeDialog(const std::string &, std::size_t)
void openStationListFile(int)
void stationListExportRequested(std::string listName, std::string fileName)
void geometryMappingRequested(const std::string &)
void geoItemSelected(const vtkPolyDataAlgorithm *, int)
void diagramRequested(QModelIndex &)
void enableRemoveButton(bool)
void contextMenuEvent(QContextMenuEvent *e) override
Actions to be taken after a right mouse click is performed in the station view.
void setNameForElement()
Calls a SetNameDialog.
void stationListSaved(QString listName, QString fileName)
void removeGeoItemSelection()
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
Instructions if the selection of items in the view has changed.
StationTreeView(QWidget *parent=nullptr)
Constructor.
void enableSaveButton(bool)
void writeStratigraphiesAsImages(QString listName)
Create image files from all stratigraphies in a borehole vector.
void stationListRemoved(std::string name)
Creates a window to visualise the stratigraphy of a borehole.
Definition StratWindow.h:29
Objects nodes for the TreeModel.
Definition TreeItem.h:28
TreeItem * parentItem() const
Definition TreeItem.cpp:115
int row() const
Definition TreeItem.cpp:73
virtual QVariant data(int column) const
Definition TreeItem.cpp:94
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30
VTK source object for the visualisation of station data (including boreholes)
const std::map< std::string, DataHolderLib::Color > & getColorLookupTable() const