OGS
StationTreeView Class Reference

Detailed Description

A view for the StationTreeModel.

See also
StationTreeModel, ModelTreeItem

Definition at line 27 of file StationTreeView.h.

#include <StationTreeView.h>

Inheritance diagram for StationTreeView:
[legend]
Collaboration diagram for StationTreeView:
[legend]

Signals

void enableSaveButton (bool)
 
void enableRemoveButton (bool)
 
void geoItemSelected (const vtkPolyDataAlgorithm *, int)
 
void geometryMappingRequested (const std::string &)
 
void removeGeoItemSelection ()
 
void itemSelectionChanged (const QItemSelection &selected, 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)
 
void diagramRequested (QModelIndex &)
 

Public Member Functions

 StationTreeView (QWidget *parent=nullptr)
 Constructor.
 
void updateView ()
 Update the view to visualise changes made to the underlying data.
 

Protected Slots

void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) override
 Instructions if the selection of items in the view has changed.
 
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.e. by actions made in the visualisation).
 

Private Slots

void addStationList ()
 
void displayStratigraphy ()
 
void exportList ()
 
void exportStation ()
 
void mapStations ()
 
void removeStationList ()
 
void setNameForElement ()
 Calls a SetNameDialog.
 
void writeToFile ()
 
void showDiagramPrefsDialog ()
 

Private Member Functions

void contextMenuEvent (QContextMenuEvent *e) override
 Actions to be taken after a right mouse click is performed in the station view.
 
void writeStratigraphiesAsImages (QString listName)
 Create image files from all stratigraphies in a borehole vector.
 

Constructor & Destructor Documentation

◆ StationTreeView()

StationTreeView::StationTreeView ( QWidget * parent = nullptr)
explicit

Constructor.

Definition at line 30 of file StationTreeView.cpp.

30 : QTreeView(parent)
31{
32 // setContextMenuPolicy(Qt::CustomContextMenu);
33 // connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
34 // this, SLOT(showContextMenu(const QPoint &)));
35}

Member Function Documentation

◆ addStationList

void StationTreeView::addStationList ( )
privateslot

◆ contextMenuEvent()

void StationTreeView::contextMenuEvent ( QContextMenuEvent * e)
overrideprivate

Actions to be taken after a right mouse click is performed in the station view.

Definition at line 92 of file StationTreeView.cpp.

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}
A borehole as a geometric object.
A TreeItem containing some additional information used in the StationModel.
A model for the StationTreeView implementing a tree as a double-linked list.
void setNameForElement()
Calls a SetNameDialog.

References displayStratigraphy(), exportList(), exportStation(), mapStations(), setNameForElement(), and showDiagramPrefsDialog().

◆ diagramRequested

void StationTreeView::diagramRequested ( QModelIndex & )
signal

Referenced by showDiagramPrefsDialog().

◆ displayStratigraphy

void StationTreeView::displayStratigraphy ( )
privateslot

Definition at line 165 of file StationTreeView.cpp.

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}
Creates a window to visualise the stratigraphy of a borehole.
Definition StratWindow.h:29
VTK source object for the visualisation of station data (including boreholes)
const std::map< std::string, DataHolderLib::Color > & getColorLookupTable() const

References VtkStationSource::getColorLookupTable().

Referenced by contextMenuEvent().

◆ enableRemoveButton

void StationTreeView::enableRemoveButton ( bool )
signal

◆ enableSaveButton

void StationTreeView::enableSaveButton ( bool )
signal

◆ exportList

void StationTreeView::exportList ( )
privateslot

Definition at line 217 of file StationTreeView.cpp.

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}
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.
void stationListExportRequested(std::string listName, std::string fileName)
Objects nodes for the TreeModel.
Definition TreeItem.h:28
virtual QVariant data(int column) const
Definition TreeItem.cpp:94

References TreeItem::data(), LastSavedFileDirectory::getDir(), LastSavedFileDirectory::setDir(), and stationListExportRequested().

Referenced by contextMenuEvent().

◆ exportStation

void StationTreeView::exportStation ( )
privateslot

Definition at line 238 of file StationTreeView.cpp.

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}
static void writeBoreholesToGMS(const std::vector< GeoLib::Point * > *stations, const std::string &filename)

References LastSavedFileDirectory::getDir(), LastSavedFileDirectory::setDir(), and FileIO::GMSInterface::writeBoreholesToGMS().

Referenced by contextMenuEvent().

◆ geoItemSelected

void StationTreeView::geoItemSelected ( const vtkPolyDataAlgorithm * ,
int  )
signal

Referenced by selectionChanged().

◆ geometryMappingRequested

void StationTreeView::geometryMappingRequested ( const std::string & )
signal

Referenced by mapStations().

◆ itemSelectionChanged

void StationTreeView::itemSelectionChanged ( const QItemSelection & selected,
const QItemSelection & deselected )
signal

◆ mapStations

void StationTreeView::mapStations ( )
privateslot

Definition at line 156 of file StationTreeView.cpp.

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}
void geometryMappingRequested(const std::string &)

References TreeItem::data(), and geometryMappingRequested().

Referenced by contextMenuEvent().

◆ openStationListFile

void StationTreeView::openStationListFile ( int )
signal

Referenced by addStationList().

◆ propertiesDialogRequested

void StationTreeView::propertiesDialogRequested ( std::string name)
signal

◆ removeGeoItemSelection

void StationTreeView::removeGeoItemSelection ( )
signal

Referenced by selectionChanged().

◆ removeStationList

void StationTreeView::removeStationList ( )
privateslot

Definition at line 257 of file StationTreeView.cpp.

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}
static void box(const QString &e)
Definition OGSError.cpp:23
void enableRemoveButton(bool)
void enableSaveButton(bool)
void stationListRemoved(std::string name)

References OGSError::box(), TreeItem::data(), enableRemoveButton(), enableSaveButton(), and stationListRemoved().

◆ requestNameChangeDialog

void StationTreeView::requestNameChangeDialog ( const std::string & ,
std::size_t  )
signal

Referenced by setNameForElement().

◆ selectionChanged

void StationTreeView::selectionChanged ( const QItemSelection & selected,
const QItemSelection & deselected )
overrideprotectedslot

Instructions if the selection of items in the view has changed.

Definition at line 46 of file StationTreeView.cpp.

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}
void geoItemSelected(const vtkPolyDataAlgorithm *, int)
void removeGeoItemSelection()
TreeItem * parentItem() const
Definition TreeItem.cpp:115
int row() const
Definition TreeItem.cpp:73
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30

References enableRemoveButton(), enableSaveButton(), geoItemSelected(), TreeItem::parentItem(), removeGeoItemSelection(), and TreeItem::row().

◆ selectionChangedFromOutside

void StationTreeView::selectionChangedFromOutside ( const QItemSelection & selected,
const QItemSelection & deselected )
protectedslot

Instructions if the selection of items in the view has changed by events outside the view (i.e. by actions made in the visualisation).

Definition at line 79 of file StationTreeView.cpp.

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}

◆ setNameForElement

void StationTreeView::setNameForElement ( )
privateslot

Calls a SetNameDialog.

Definition at line 146 of file StationTreeView.cpp.

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}
void requestNameChangeDialog(const std::string &, std::size_t)

References TreeItem::data(), TreeItem::parentItem(), requestNameChangeDialog(), and TreeItem::row().

Referenced by contextMenuEvent().

◆ showDiagramPrefsDialog

void StationTreeView::showDiagramPrefsDialog ( )
privateslot

Definition at line 278 of file StationTreeView.cpp.

279{
280 QModelIndex index = this->selectionModel()->currentIndex();
281 emit diagramRequested(index);
282}
void diagramRequested(QModelIndex &)

References diagramRequested().

Referenced by contextMenuEvent().

◆ stationListExportRequested

void StationTreeView::stationListExportRequested ( std::string listName,
std::string fileName )
signal

Referenced by exportList().

◆ stationListRemoved

void StationTreeView::stationListRemoved ( std::string name)
signal

Referenced by removeStationList().

◆ stationListSaved

void StationTreeView::stationListSaved ( QString listName,
QString fileName )
signal

Referenced by writeToFile().

◆ updateView()

void StationTreeView::updateView ( )

Update the view to visualise changes made to the underlying data.

Definition at line 37 of file StationTreeView.cpp.

38{
39 setAlternatingRowColors(true);
40 setColumnWidth(0, 150);
41 setColumnWidth(1, 75);
42 setColumnWidth(2, 75);
43 setColumnWidth(3, 75);
44}

◆ writeStratigraphiesAsImages()

void StationTreeView::writeStratigraphiesAsImages ( QString listName)
private

Create image files from all stratigraphies in a borehole vector.

Definition at line 284 of file StationTreeView.cpp.

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}
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

References VtkStationSource::getColorLookupTable(), and getName().

◆ writeToFile

void StationTreeView::writeToFile ( )
privateslot

Definition at line 194 of file StationTreeView.cpp.

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}
void stationListSaved(QString listName, QString fileName)

References OGSError::box(), TreeItem::data(), LastSavedFileDirectory::getDir(), LastSavedFileDirectory::setDir(), and stationListSaved().


The documentation for this class was generated from the following files: