OGS
GeoTreeView Class Reference

Detailed Description

A view for the GeoTreeModel.

See also
GeoTreeModel, GeoTreeItem

Definition at line 28 of file GeoTreeView.h.

#include <GeoTreeView.h>

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

Signals

void enableSaveButton (bool)
 Saves FEM Conditions associated with the given geometry.
 
void enableRemoveButton (bool)
 
void geoItemSelected (const vtkPolyDataAlgorithm *, int)
 
void geometryMappingRequested (const std::string &)
 
void removeGeoItemSelection ()
 
void listRemoved (std::string name, GeoLib::GEOTYPE)
 
void loadFEMCondFileRequested (std::string)
 
void openGeometryFile (int)
 
void saveToFileRequested (QString, QString) const
 
void requestCondSetupDialog (const std::string &, const GeoLib::GEOTYPE, const std::size_t, bool on_points)
 
void requestLineEditDialog (const std::string &)
 
void requestNameChangeDialog (const std::string &, const GeoLib::GEOTYPE, const std::size_t)
 
void requestPointToStationConversion (std::string const &)
 

Public Member Functions

 GeoTreeView (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 addGeometry ()
 
void loadFEMConditions ()
 Allows to add FEM Conditions to a process.
 
void on_Clicked (QModelIndex idx)
 
void connectPolylines ()
 Calls a LineEditDialog.
 
void convertPointsToStations ()
 
void mapGeometry ()
 
void setNameForElement ()
 Calls a SetNameDialog.
 
void setObjectAsCondition ()
 

Private Member Functions

void contextMenuEvent (QContextMenuEvent *e) override
 Actions to be taken after a right mouse click is performed in the station view.
 
void setElementAsCondition (bool set_on_points=false)
 Calls a FEMConditionSetupDialog.
 
void setObjectPointsAsCondition ()
 
void writeToFile () const
 Saves a geometry in a file.
 
void removeGeometry ()
 Removes a whole geometry or parts of it.
 

Constructor & Destructor Documentation

◆ GeoTreeView()

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

Constructor.

Definition at line 28 of file GeoTreeView.cpp.

28: QTreeView(parent) {}

Member Function Documentation

◆ addGeometry

void GeoTreeView::addGeometry ( )
privateslot

Definition at line 244 of file GeoTreeView.cpp.

References ImportFileType::OGS_GEO, and openGeometryFile().

◆ connectPolylines

void GeoTreeView::connectPolylines ( )
privateslot

Calls a LineEditDialog.

Definition at line 236 of file GeoTreeView.cpp.

237{
238 TreeItem* item = static_cast<GeoTreeModel*>(model())
239 ->getItem(this->selectionModel()->currentIndex())
240 ->parentItem();
241 emit requestLineEditDialog(item->data(0).toString().toStdString());
242}
A model for the GeoTreeView implementing a tree as a double-linked list.
void requestLineEditDialog(const std::string &)
Objects nodes for the TreeModel.
Definition TreeItem.h:28
virtual QVariant data(int column) const
Definition TreeItem.cpp:94

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

Referenced by contextMenuEvent().

◆ contextMenuEvent()

void GeoTreeView::contextMenuEvent ( QContextMenuEvent * e)
overrideprivate

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

Definition at line 133 of file GeoTreeView.cpp.

134{
135 QModelIndex index = this->selectionModel()->currentIndex();
136 auto* item = static_cast<TreeItem*>(index.internalPointer());
137
138 auto* list = dynamic_cast<GeoObjectListItem*>(item);
139 QMenu menu;
140
141 // The current index is a list of points/polylines/surfaces
142 if (list != nullptr)
143 {
144 if (list->getType() == GeoLib::GEOTYPE::POINT)
145 {
146 auto const* convertToStationAction =
147 menu.addAction("Convert to Stations");
148 connect(convertToStationAction, SIGNAL(triggered()), this,
150 }
151 if (list->getType() == GeoLib::GEOTYPE::POLYLINE)
152 {
153 auto const* connectPlyAction =
154 menu.addAction("Connect Polylines...");
155 connect(connectPlyAction, SIGNAL(triggered()), this,
156 SLOT(connectPolylines()));
157 }
158 menu.addSeparator();
159 // QAction* removeAction = menu.addAction("Remove " +
160 // item->data(0).toString()); connect(removeAction, SIGNAL(triggered()),
161 // this, SLOT(removeList()));
162 }
163 else
164 {
165 if (!item)
166 { // Otherwise sometimes it crashes when (unmotivated ;-) ) clicking in
167 // a treeview
168 return;
169 }
170
171 auto* parent = dynamic_cast<GeoObjectListItem*>(item->parentItem());
172
173 // The current index refers to a geo-object
174 if (parent != nullptr)
175 {
176 QMenu* cond_menu = new QMenu("Set FEM Condition");
177 // menu.addMenu(cond_menu);
178 QAction* addCondAction = cond_menu->addAction("On object...");
179 QAction* addCondPointAction =
180 cond_menu->addAction("On all points...");
181 QAction* addNameAction = menu.addAction("Set name...");
182 connect(addCondAction, SIGNAL(triggered()), this,
183 SLOT(setObjectAsCondition()));
184 connect(addNameAction, SIGNAL(triggered()), this,
185 SLOT(setNameForElement()));
186
187 if (parent->getType() == GeoLib::GEOTYPE::POINT)
188 {
189 addCondPointAction->setEnabled(false);
190 }
191 else
192 {
193 connect(addCondPointAction, SIGNAL(triggered()), this,
195 }
196 }
197 // The current index refers to the name of a geometry-object
198 else if (item->childCount() > 0)
199 {
200 if (item->child(0)->data(0).toString().compare("Points") ==
201 0) // clumsy way to find out
202 {
203 // QAction* saveAction = menu.addAction("Save geometry...");
204 QAction* mapAction = menu.addAction("Map geometry...");
205 // QAction* addCNDAction = menu.addAction("Load FEM
206 // Conditions..."); QAction* saveCondAction =
207 // menu.addAction("Save FEM conditions...");
208 menu.addSeparator();
209 // QAction* removeAction = menu.addAction("Remove geometry");
210 // connect(saveAction, SIGNAL(triggered()), this,
211 // SLOT(writeToFile()));
212 connect(mapAction, SIGNAL(triggered()), this,
213 SLOT(mapGeometry()));
214 // connect(addCNDAction, SIGNAL(triggered()), this,
215 // SLOT(loadFEMConditions())); connect(saveCondAction,
216 // SIGNAL(triggered()), this, SLOT(saveFEMConditions()));
217 // connect(removeAction, SIGNAL(triggered()), this,
218 // SLOT(removeList()));
219 }
220 }
221 }
222
223 menu.exec(event->globalPos());
224}
void mapGeometry()
void setObjectAsCondition()
Definition GeoTreeView.h:65
void setNameForElement()
Calls a SetNameDialog.
void connectPolylines()
Calls a LineEditDialog.
void convertPointsToStations()
void setObjectPointsAsCondition()
Definition GeoTreeView.h:66

References connectPolylines(), convertPointsToStations(), mapGeometry(), GeoLib::POINT, GeoLib::POLYLINE, setNameForElement(), setObjectAsCondition(), and setObjectPointsAsCondition().

◆ convertPointsToStations

void GeoTreeView::convertPointsToStations ( )
privateslot

Definition at line 226 of file GeoTreeView.cpp.

227{
228 TreeItem const* const item =
229 static_cast<GeoTreeModel*>(model())
230 ->getItem(this->selectionModel()->currentIndex())
231 ->parentItem();
233 item->data(0).toString().toStdString());
234}
void requestPointToStationConversion(std::string const &)

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

Referenced by contextMenuEvent().

◆ enableRemoveButton

void GeoTreeView::enableRemoveButton ( bool )
signal

Referenced by removeGeometry(), and selectionChanged().

◆ enableSaveButton

void GeoTreeView::enableSaveButton ( bool )
signal

Saves FEM Conditions associated with the given geometry.

Referenced by removeGeometry(), and selectionChanged().

◆ geoItemSelected

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

Referenced by selectionChanged().

◆ geometryMappingRequested

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

Referenced by mapGeometry().

◆ listRemoved

void GeoTreeView::listRemoved ( std::string name,
GeoLib::GEOTYPE  )
signal

Referenced by removeGeometry().

◆ loadFEMCondFileRequested

void GeoTreeView::loadFEMCondFileRequested ( std::string )
signal

Referenced by loadFEMConditions().

◆ loadFEMConditions

void GeoTreeView::loadFEMConditions ( )
privateslot

Allows to add FEM Conditions to a process.

Definition at line 342 of file GeoTreeView.cpp.

343{
344 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
345 this->selectionModel()->currentIndex());
346 emit loadFEMCondFileRequested(item->data(0).toString().toStdString());
347}
void loadFEMCondFileRequested(std::string)

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

◆ mapGeometry

void GeoTreeView::mapGeometry ( )
privateslot

Definition at line 308 of file GeoTreeView.cpp.

309{
310 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
311 this->selectionModel()->currentIndex());
312 std::string geo_name(item->data(0).toString().toStdString());
313 emit geometryMappingRequested(geo_name);
314}
void geometryMappingRequested(const std::string &)

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

Referenced by contextMenuEvent().

◆ on_Clicked

void GeoTreeView::on_Clicked ( QModelIndex idx)
privateslot

Definition at line 39 of file GeoTreeView.cpp.

40{
41 qDebug("%d, %d", idx.parent().row(), idx.row());
42}

◆ openGeometryFile

void GeoTreeView::openGeometryFile ( int )
signal

Referenced by addGeometry().

◆ removeGeoItemSelection

void GeoTreeView::removeGeoItemSelection ( )
signal

Referenced by selectionChanged().

◆ removeGeometry()

void GeoTreeView::removeGeometry ( )
private

Removes a whole geometry or parts of it.

Definition at line 249 of file GeoTreeView.cpp.

250{
251 QModelIndex index(this->selectionModel()->currentIndex());
252 if (!index.isValid())
253 {
254 OGSError::box("No geometry selected.");
255 }
256 else
257 {
258 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(index);
259 auto* list = dynamic_cast<GeoObjectListItem*>(item);
260 if (list)
261 {
262 emit listRemoved(
263 (item->parentItem()->data(0).toString()).toStdString(),
264 list->getType());
265 }
266 else
267 {
268 emit listRemoved((item->data(0).toString()).toStdString(),
270 emit listRemoved((item->data(0).toString()).toStdString(),
272 emit listRemoved((item->data(0).toString()).toStdString(),
274 }
275
276 if (this->selectionModel()->selectedIndexes().count() == 0)
277 {
278 emit enableSaveButton(false);
279 emit enableRemoveButton(false);
280 }
281 }
282}
void enableSaveButton(bool)
Saves FEM Conditions associated with the given geometry.
void listRemoved(std::string name, GeoLib::GEOTYPE)
void enableRemoveButton(bool)
static void box(const QString &e)
Definition OGSError.cpp:23
TreeItem * parentItem() const
Definition TreeItem.cpp:115

References OGSError::box(), TreeItem::data(), enableRemoveButton(), enableSaveButton(), listRemoved(), TreeItem::parentItem(), GeoLib::POINT, GeoLib::POLYLINE, and GeoLib::SURFACE.

◆ requestCondSetupDialog

void GeoTreeView::requestCondSetupDialog ( const std::string & ,
const GeoLib::GEOTYPE ,
const std::size_t ,
bool on_points )
signal

Referenced by setElementAsCondition().

◆ requestLineEditDialog

void GeoTreeView::requestLineEditDialog ( const std::string & )
signal

Referenced by connectPolylines().

◆ requestNameChangeDialog

void GeoTreeView::requestNameChangeDialog ( const std::string & ,
const GeoLib::GEOTYPE ,
const std::size_t  )
signal

Referenced by setNameForElement().

◆ requestPointToStationConversion

void GeoTreeView::requestPointToStationConversion ( std::string const & )
signal

Referenced by convertPointsToStations().

◆ saveToFileRequested

void GeoTreeView::saveToFileRequested ( QString ,
QString  ) const
signal

Referenced by writeToFile().

◆ selectionChanged

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

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

Definition at line 44 of file GeoTreeView.cpp.

46{
47 Q_UNUSED(deselected);
48 if (!selected.isEmpty())
49 {
50 const QModelIndex idx = *(selected.indexes().begin());
51 const TreeItem* tree_item =
52 static_cast<TreeModel*>(this->model())->getItem(idx);
54
55 const GeoObjectListItem* geo_object =
56 dynamic_cast<GeoObjectListItem*>(tree_item->parentItem());
57 if (geo_object) // geometry object
58 {
59 emit enableSaveButton(false);
60 emit enableRemoveButton(false);
61 emit geoItemSelected(geo_object->vtkSource(), tree_item->row());
62 }
63 else
64 {
65 if (!idx.parent().isValid()) // geometry item
66 {
67 emit enableSaveButton(true);
68 emit enableRemoveButton(true);
69 }
70 else // line points or surface triangles
71 {
72 emit enableSaveButton(false);
73 const auto* geo_type =
74 dynamic_cast<const GeoObjectListItem*>(tree_item);
75 if (geo_type)
76 { // geometry list item
77 emit enableRemoveButton(true);
78 }
79 else
80 {
81 // highlight a point for an expanded polyline
82 auto* list_item = dynamic_cast<GeoObjectListItem*>(
83 tree_item->parentItem()->parentItem());
84 if (list_item &&
85 list_item->getType() == GeoLib::GEOTYPE::POLYLINE)
86 {
88 tree_item->parentItem()
89 ->parentItem()
90 ->parentItem()
91 ->child(0))
92 ->vtkSource(),
93 tree_item->data(0).toInt());
94 }
95
96 // highlight a point for an expanded surface
97 list_item = dynamic_cast<GeoObjectListItem*>(
98 tree_item->parentItem()->parentItem()->parentItem());
99 if (list_item &&
100 list_item->getType() == GeoLib::GEOTYPE::SURFACE)
101 {
102 geoItemSelected(dynamic_cast<GeoObjectListItem*>(
103 tree_item->parentItem()
104 ->parentItem()
105 ->parentItem()
106 ->parentItem()
107 ->child(0))
108 ->vtkSource(),
109 tree_item->data(0).toInt());
110 }
111 emit enableRemoveButton(false);
112 }
113 }
114 }
115 }
116 // emit itemSelectionChanged(selected, deselected);
117 // return QTreeView::selectionChanged(selected, deselected);
118}
vtkPolyDataAlgorithm * vtkSource() const
Returns the Vtk polydata source object.
void geoItemSelected(const vtkPolyDataAlgorithm *, int)
void removeGeoItemSelection()
TreeItem * child(int row) const
Definition TreeItem.cpp:52
int row() const
Definition TreeItem.cpp:73
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30

References TreeItem::child(), TreeItem::data(), enableRemoveButton(), enableSaveButton(), geoItemSelected(), TreeItem::parentItem(), GeoLib::POLYLINE, removeGeoItemSelection(), TreeItem::row(), GeoLib::SURFACE, and GeoObjectListItem::vtkSource().

◆ selectionChangedFromOutside

void GeoTreeView::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 120 of file GeoTreeView.cpp.

122{
123 QItemSelectionModel* selModel = this->selectionModel();
124
125 selModel->blockSignals(true);
126 selModel->select(deselected, QItemSelectionModel::Deselect);
127 selModel->select(selected, QItemSelectionModel::Select);
128 selModel->blockSignals(false);
129
130 QTreeView::selectionChanged(selected, deselected);
131}

◆ setElementAsCondition()

void GeoTreeView::setElementAsCondition ( bool set_on_points = false)
private

Calls a FEMConditionSetupDialog.

Definition at line 284 of file GeoTreeView.cpp.

285{
286 const TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
287 this->selectionModel()->currentIndex());
288 const std::size_t id = item->row();
289 const GeoLib::GEOTYPE type =
290 static_cast<GeoObjectListItem*>(item->parentItem())->getType();
291 const std::string geometry_name =
292 item->parentItem()->parentItem()->data(0).toString().toStdString();
293 emit requestCondSetupDialog(geometry_name, type, id, set_on_points);
294}
void requestCondSetupDialog(const std::string &, const GeoLib::GEOTYPE, const std::size_t, bool on_points)
GEOTYPE
Definition GeoType.h:23

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

Referenced by setObjectAsCondition(), and setObjectPointsAsCondition().

◆ setNameForElement

void GeoTreeView::setNameForElement ( )
privateslot

Calls a SetNameDialog.

Definition at line 296 of file GeoTreeView.cpp.

297{
298 const TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
299 this->selectionModel()->currentIndex());
300 const std::size_t id = item->row();
301 const GeoLib::GEOTYPE type =
302 static_cast<GeoObjectListItem*>(item->parentItem())->getType();
303 const std::string geometry_name =
304 item->parentItem()->parentItem()->data(0).toString().toStdString();
305 emit requestNameChangeDialog(geometry_name, type, id);
306}
void requestNameChangeDialog(const std::string &, const GeoLib::GEOTYPE, const std::size_t)

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

Referenced by contextMenuEvent().

◆ setObjectAsCondition

void GeoTreeView::setObjectAsCondition ( )
inlineprivateslot

Definition at line 65 of file GeoTreeView.h.

65{ setElementAsCondition(false); };
void setElementAsCondition(bool set_on_points=false)
Calls a FEMConditionSetupDialog.

References setElementAsCondition().

Referenced by contextMenuEvent().

◆ setObjectPointsAsCondition()

void GeoTreeView::setObjectPointsAsCondition ( )
inlineprivate

Definition at line 66 of file GeoTreeView.h.

66{ setElementAsCondition(true); };

References setElementAsCondition().

Referenced by contextMenuEvent().

◆ updateView()

void GeoTreeView::updateView ( )

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

Definition at line 30 of file GeoTreeView.cpp.

31{
32 setAlternatingRowColors(true);
33 setColumnWidth(0, 150);
34 setColumnWidth(1, 75);
35 setColumnWidth(2, 75);
36 setColumnWidth(3, 75);
37}

◆ writeToFile()

void GeoTreeView::writeToFile ( ) const
private

Saves a geometry in a file.

Definition at line 316 of file GeoTreeView.cpp.

317{
318 QModelIndex index(this->selectionModel()->currentIndex());
319 if (!index.isValid())
320 {
321 OGSError::box("No geometry selected.");
322 }
323 else
324 {
325 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(index);
326 QString file_type("GeoSys geometry file (*.gml)");
327#ifndef NDEBUG
328 file_type.append(";;Legacy geometry file (*.gli)");
329#endif // DEBUG
330 QString geoName = item->data(0).toString();
331 QString fileName = QFileDialog::getSaveFileName(
332 nullptr, "Save geometry as",
333 LastSavedFileDirectory::getDir() + geoName, file_type);
334 if (!fileName.isEmpty())
335 {
337 emit saveToFileRequested(geoName, fileName);
338 }
339 }
340}
void saveToFileRequested(QString, QString) const
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.

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


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