OGS
StationTreeView Class Reference

Detailed Description

A view for the StationTreeModel.

See also
StationTreeModel, ModelTreeItem

Definition at line 16 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 19 of file StationTreeView.cpp.

19 : QTreeView(parent)
20{
21 // setContextMenuPolicy(Qt::CustomContextMenu);
22 // connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
23 // this, SLOT(showContextMenu(const QPoint &)));
24}

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 81 of file StationTreeView.cpp.

82{
83 QModelIndex index = this->selectionModel()->currentIndex();
84 auto* item = static_cast<ModelTreeItem*>(index.internalPointer());
85
86 if (!item)
87 { // Otherwise sometimes it crashes when (unmotivated ;-) ) clicking in a
88 // treeview
89 return;
90 }
91
92 // The current index refers to a parent item (e.g. a listname)
93 if (item->childCount() > 0)
94 {
95 QMenu menu;
96 QAction* mapAction = menu.addAction("Map stations...");
97 QAction* exportAction = menu.addAction("Export to GMS...");
98 menu.addSeparator();
99
100 connect(mapAction, SIGNAL(triggered()), this, SLOT(mapStations()));
101 connect(exportAction, SIGNAL(triggered()), this, SLOT(exportList()));
102 menu.exec(event->globalPos());
103 }
104 // The current index refers to a station object
105 else
106 {
107 QString temp_name;
108 QMenu menu;
109
110 QAction* setNameAction = menu.addAction("Set name...");
111 connect(setNameAction, SIGNAL(triggered()), this,
112 SLOT(setNameForElement()));
113 if (dynamic_cast<GeoLib::StationBorehole*>(
114 static_cast<StationTreeModel*>(model())->stationFromIndex(
115 index, temp_name)))
116 {
117 QAction* stratAction = menu.addAction("Display Stratigraphy...");
118 QAction* exportAction = menu.addAction("Export to GMS...");
119 connect(stratAction, SIGNAL(triggered()), this,
120 SLOT(displayStratigraphy()));
121 connect(exportAction, SIGNAL(triggered()), this,
122 SLOT(exportStation()));
123 menu.exec(event->globalPos());
124 }
125 else
126 {
127 QAction* showDiagramAction = menu.addAction("View Diagram...");
128 connect(showDiagramAction, SIGNAL(triggered()), this,
129 SLOT(showDiagramPrefsDialog()));
130 menu.exec(event->globalPos());
131 }
132 }
133}
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 154 of file StationTreeView.cpp.

155{
156 QModelIndex index = this->selectionModel()->currentIndex();
157
158 QString temp_name;
159 // get list name
160 static_cast<StationTreeModel*>(model())->stationFromIndex(
161 this->selectionModel()->currentIndex(), temp_name);
162 // get color table (horrible way to do it but there you go ...)
163 std::map<std::string, DataHolderLib::Color> colorLookupTable =
164 static_cast<VtkStationSource*>(
165 static_cast<StationTreeModel*>(model())->vtkSource(
166 temp_name.toStdString()))
167 ->getColorLookupTable();
168 auto* stratView = new StratWindow(
169 static_cast<GeoLib::StationBorehole*>(
170 static_cast<StationTreeModel*>(model())->stationFromIndex(
171 index, temp_name)),
172 &colorLookupTable);
173 stratView->setAttribute(
174 Qt::WA_DeleteOnClose); // this fixes the memory leak shown by cppcheck
175 stratView->show();
176}

References VtkStationSource::getColorLookupTable(), and StationTreeModel::vtkSource().

Referenced by contextMenuEvent().

◆ enableRemoveButton

void StationTreeView::enableRemoveButton ( bool )
signal

◆ enableSaveButton

void StationTreeView::enableSaveButton ( bool )
signal

◆ exportList

void StationTreeView::exportList ( )
privateslot

Definition at line 206 of file StationTreeView.cpp.

207{
208 // only a test for the stratigraphy screenshot tool and writer!!
209 // QString Name =
210 // static_cast<StationTreeModel*>(model())->getItem(this->selectionModel()->currentIndex())->data(0).toString();
211 // writeStratigraphiesAsImages(Name);
212
213 TreeItem* item = static_cast<StationTreeModel*>(model())->getItem(
214 this->selectionModel()->currentIndex());
215 QString listName = item->data(0).toString();
216 QString fileName = QFileDialog::getSaveFileName(
217 this, "Export Boreholes to GMS-Format",
218 LastSavedFileDirectory::getDir() + listName, "*.txt");
219 if (!fileName.isEmpty())
220 {
222 emit stationListExportRequested(listName.toStdString(),
223 fileName.toStdString());
224 }
225}
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)
virtual QVariant data(int column) const
Definition TreeItem.cpp:83

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

Referenced by contextMenuEvent().

◆ exportStation

void StationTreeView::exportStation ( )
privateslot

Definition at line 227 of file StationTreeView.cpp.

228{
229 QModelIndex index = this->selectionModel()->currentIndex();
230 QString fileName =
231 QFileDialog::getSaveFileName(this, "Export Borehole to GMS-Format",
233 if (!fileName.isEmpty())
234 {
235 QString temp_name;
236 std::vector<GeoLib::Point*> stations;
237 stations.push_back(static_cast<GeoLib::StationBorehole*>(
238 static_cast<StationTreeModel*>(model())->stationFromIndex(
239 index, temp_name)));
241 fileName.toStdString());
243 }
244}
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 145 of file StationTreeView.cpp.

146{
147 TreeItem const* const item =
148 static_cast<StationTreeModel*>(model())->getItem(
149 this->selectionModel()->currentIndex());
150 std::string const& geo_name(item->data(0).toString().toStdString());
151 emit geometryMappingRequested(geo_name);
152}
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 246 of file StationTreeView.cpp.

247{
248 QModelIndex index(this->selectionModel()->currentIndex());
249 if (!index.isValid())
250 {
251 OGSError::box("No station list selected.");
252 }
253 else
254 {
255 TreeItem* item =
256 static_cast<StationTreeModel*>(model())->getItem(index);
257 emit stationListRemoved((item->data(0).toString()).toStdString());
258
259 if (this->selectionModel()->selectedIndexes().count() == 0)
260 {
261 emit enableSaveButton(false);
262 emit enableRemoveButton(false);
263 }
264 }
265}
static void box(const QString &e)
Definition OGSError.cpp:13
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 35 of file StationTreeView.cpp.

37{
38 Q_UNUSED(deselected);
39 if (!selected.isEmpty())
40 {
41 const QModelIndex idx = *(selected.indexes().begin());
42 const TreeItem* tree_item =
43 static_cast<TreeModel*>(this->model())->getItem(idx);
44
45 const auto* list_item =
46 dynamic_cast<const ModelTreeItem*>(tree_item->parentItem());
47 if (list_item->getItem())
48 {
49 if (list_item)
50 {
51 emit geoItemSelected(list_item->getItem()->vtkSource(),
52 tree_item->row());
53 }
54 emit enableRemoveButton(false);
55 emit enableSaveButton(false);
56 }
57 else
58 {
60 emit enableSaveButton(true);
61 emit enableRemoveButton(true);
62 }
63 }
64 // emit itemSelectionChanged(selected, deselected);
65 // return QTreeView::selectionChanged(selected, deselected);
66}
void geoItemSelected(const vtkPolyDataAlgorithm *, int)
void removeGeoItemSelection()
TreeItem * parentItem() const
Definition TreeItem.cpp:104
int row() const
Definition TreeItem.cpp:62

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 68 of file StationTreeView.cpp.

70{
71 QItemSelectionModel* selModel = this->selectionModel();
72
73 selModel->blockSignals(true);
74 selModel->select(deselected, QItemSelectionModel::Deselect);
75 selModel->select(selected, QItemSelectionModel::Select);
76 selModel->blockSignals(false);
77
78 return QTreeView::selectionChanged(selected, deselected);
79}

◆ setNameForElement

void StationTreeView::setNameForElement ( )
privateslot

Calls a SetNameDialog.

Definition at line 135 of file StationTreeView.cpp.

136{
137 TreeItem const* const item =
138 static_cast<StationTreeModel*>(model())->getItem(
139 this->selectionModel()->currentIndex());
140 std::string const stn_vec_name =
141 item->parentItem()->data(0).toString().toStdString();
142 emit requestNameChangeDialog(stn_vec_name, item->row());
143}
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 267 of file StationTreeView.cpp.

268{
269 QModelIndex index = this->selectionModel()->currentIndex();
270 emit diagramRequested(index);
271}
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 26 of file StationTreeView.cpp.

27{
28 setAlternatingRowColors(true);
29 setColumnWidth(0, 150);
30 setColumnWidth(1, 75);
31 setColumnWidth(2, 75);
32 setColumnWidth(3, 75);
33}

◆ writeStratigraphiesAsImages()

void StationTreeView::writeStratigraphiesAsImages ( QString listName)
private

Create image files from all stratigraphies in a borehole vector.

Definition at line 273 of file StationTreeView.cpp.

274{
275 std::map<std::string, DataHolderLib::Color> colorLookupTable =
276 static_cast<VtkStationSource*>(
277 static_cast<StationTreeModel*>(model())->vtkSource(
278 listName.toStdString()))
279 ->getColorLookupTable();
280 std::vector<ModelTreeItem*> lists =
281 static_cast<StationTreeModel*>(model())->getLists();
282 std::size_t nLists = lists.size();
283 for (std::size_t i = 0; i < nLists; i++)
284 {
285 if (listName.compare(lists[i]->data(0).toString()) != 0)
286 {
287 continue;
288 }
289
290 std::vector<GeoLib::Point*> const& stations =
291 *dynamic_cast<BaseItem*>(lists[i]->getItem())->getStations();
292
293 for (auto station : stations)
294 {
295 auto* stratView =
296 new StratWindow(static_cast<GeoLib::StationBorehole*>(station),
297 &colorLookupTable);
298 stratView->setAttribute(Qt::WA_DeleteOnClose);
299 stratView->show();
300 stratView->stationView->saveAsImage(
301 QString::fromStdString(
302 static_cast<GeoLib::StationBorehole*>(station)->getName()) +
303 ".jpg");
304 stratView->close();
305 }
306 }
307}
std::string getName(std::string const &line)
Returns the name/title from the "Zone"-description.

References VtkStationSource::getColorLookupTable(), getName(), BaseItem::getStations(), and StationTreeModel::vtkSource().

◆ writeToFile

void StationTreeView::writeToFile ( )
privateslot

Definition at line 183 of file StationTreeView.cpp.

184{
185 QModelIndex index(this->selectionModel()->currentIndex());
186 if (!index.isValid())
187 {
188 OGSError::box("No station list selected.");
189 }
190 else
191 {
192 TreeItem* item =
193 static_cast<StationTreeModel*>(model())->getItem(index);
194 QString listName = item->data(0).toString();
195 QString fileName = QFileDialog::getSaveFileName(
196 this, "Save station list",
197 LastSavedFileDirectory::getDir() + listName, "*.stn");
198 if (!fileName.isEmpty())
199 {
201 emit stationListSaved(listName, fileName);
202 }
203 }
204}
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: