OGS
GeoTreeView Class Reference

Detailed Description

A view for the GeoTreeModel.

See also
GeoTreeModel, GeoTreeItem

Definition at line 17 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 17 of file GeoTreeView.cpp.

17: QTreeView(parent) {}

Member Function Documentation

◆ addGeometry

void GeoTreeView::addGeometry ( )
privateslot

Definition at line 233 of file GeoTreeView.cpp.

References ImportFileType::OGS_GEO, and openGeometryFile().

◆ connectPolylines

void GeoTreeView::connectPolylines ( )
privateslot

Calls a LineEditDialog.

Definition at line 225 of file GeoTreeView.cpp.

226{
227 TreeItem* item = static_cast<GeoTreeModel*>(model())
228 ->getItem(this->selectionModel()->currentIndex())
229 ->parentItem();
230 emit requestLineEditDialog(item->data(0).toString().toStdString());
231}
void requestLineEditDialog(const std::string &)
virtual QVariant data(int column) const
Definition TreeItem.cpp:83

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 122 of file GeoTreeView.cpp.

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

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

◆ convertPointsToStations

void GeoTreeView::convertPointsToStations ( )
privateslot

Definition at line 215 of file GeoTreeView.cpp.

216{
217 TreeItem const* const item =
218 static_cast<GeoTreeModel*>(model())
219 ->getItem(this->selectionModel()->currentIndex())
220 ->parentItem();
222 item->data(0).toString().toStdString());
223}
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 331 of file GeoTreeView.cpp.

332{
333 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
334 this->selectionModel()->currentIndex());
335 emit loadFEMCondFileRequested(item->data(0).toString().toStdString());
336}
void loadFEMCondFileRequested(std::string)

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

◆ mapGeometry

void GeoTreeView::mapGeometry ( )
privateslot

Definition at line 297 of file GeoTreeView.cpp.

298{
299 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
300 this->selectionModel()->currentIndex());
301 std::string geo_name(item->data(0).toString().toStdString());
302 emit geometryMappingRequested(geo_name);
303}
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 28 of file GeoTreeView.cpp.

29{
30 qDebug("%d, %d", idx.parent().row(), idx.row());
31}

◆ 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 238 of file GeoTreeView.cpp.

239{
240 QModelIndex index(this->selectionModel()->currentIndex());
241 if (!index.isValid())
242 {
243 OGSError::box("No geometry selected.");
244 }
245 else
246 {
247 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(index);
248 auto* list = dynamic_cast<GeoObjectListItem*>(item);
249 if (list)
250 {
251 emit listRemoved(
252 (item->parentItem()->data(0).toString()).toStdString(),
253 list->getType());
254 }
255 else
256 {
257 emit listRemoved((item->data(0).toString()).toStdString(),
259 emit listRemoved((item->data(0).toString()).toStdString(),
261 emit listRemoved((item->data(0).toString()).toStdString(),
263 }
264
265 if (this->selectionModel()->selectedIndexes().count() == 0)
266 {
267 emit enableSaveButton(false);
268 emit enableRemoveButton(false);
269 }
270 }
271}
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:13
TreeItem * parentItem() const
Definition TreeItem.cpp:104

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 33 of file GeoTreeView.cpp.

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

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 109 of file GeoTreeView.cpp.

111{
112 QItemSelectionModel* selModel = this->selectionModel();
113
114 selModel->blockSignals(true);
115 selModel->select(deselected, QItemSelectionModel::Deselect);
116 selModel->select(selected, QItemSelectionModel::Select);
117 selModel->blockSignals(false);
118
119 QTreeView::selectionChanged(selected, deselected);
120}

◆ setElementAsCondition()

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

Calls a FEMConditionSetupDialog.

Definition at line 273 of file GeoTreeView.cpp.

274{
275 const TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(
276 this->selectionModel()->currentIndex());
277 const std::size_t id = item->row();
278 const GeoLib::GEOTYPE type =
279 static_cast<GeoObjectListItem*>(item->parentItem())->getType();
280 const std::string geometry_name =
281 item->parentItem()->parentItem()->data(0).toString().toStdString();
282 emit requestCondSetupDialog(geometry_name, type, id, set_on_points);
283}
void requestCondSetupDialog(const std::string &, const GeoLib::GEOTYPE, const std::size_t, bool on_points)
GEOTYPE
Definition GeoType.h:12

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

Referenced by setObjectAsCondition(), and setObjectPointsAsCondition().

◆ setNameForElement

void GeoTreeView::setNameForElement ( )
privateslot

Calls a SetNameDialog.

Definition at line 285 of file GeoTreeView.cpp.

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

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

Referenced by contextMenuEvent().

◆ setObjectAsCondition

void GeoTreeView::setObjectAsCondition ( )
inlineprivateslot

Definition at line 54 of file GeoTreeView.h.

54{ 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 55 of file GeoTreeView.h.

55{ 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 19 of file GeoTreeView.cpp.

20{
21 setAlternatingRowColors(true);
22 setColumnWidth(0, 150);
23 setColumnWidth(1, 75);
24 setColumnWidth(2, 75);
25 setColumnWidth(3, 75);
26}

◆ writeToFile()

void GeoTreeView::writeToFile ( ) const
private

Saves a geometry in a file.

Definition at line 305 of file GeoTreeView.cpp.

306{
307 QModelIndex index(this->selectionModel()->currentIndex());
308 if (!index.isValid())
309 {
310 OGSError::box("No geometry selected.");
311 }
312 else
313 {
314 TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(index);
315 QString file_type("GeoSys geometry file (*.gml)");
316#ifndef NDEBUG
317 file_type.append(";;Legacy geometry file (*.gli)");
318#endif // DEBUG
319 QString geoName = item->data(0).toString();
320 QString fileName = QFileDialog::getSaveFileName(
321 nullptr, "Save geometry as",
322 LastSavedFileDirectory::getDir() + geoName, file_type);
323 if (!fileName.isEmpty())
324 {
326 emit saveToFileRequested(geoName, fileName);
327 }
328 }
329}
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: