OGS
MergeGeometriesDialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <QStringList>
7#include <QStringListModel>
8
9#include "Base/OGSError.h"
10#include "GeoLib/GEOObjects.h"
11
13 QDialog* parent)
14 : QDialog(parent),
15 _geo_objects(geoObjects),
16 _allGeo(new QStringListModel),
17 _selGeo(new QStringListModel)
18{
19 setupUi(this);
20
21 auto const geoNames = _geo_objects.getGeometryNames();
22
23 // get station names
24 std::vector<std::string> geo_station_names;
25 _geo_objects.getStationVectorNames(geo_station_names);
26
27 // merge method does currently not merge stations, converter function needed
28 // first
29 // geoNames.reserve(geo_station_names.size());
30 // std::copy(geo_station_names.begin(), geo_station_names.end(),
31 // std::back_inserter(geoNames));
32
33 std::size_t nGeoObjects(geoNames.size());
34
35 QStringList list;
36 for (unsigned i = 0; i < nGeoObjects; ++i)
37 {
38 list.append(QString::fromStdString(geoNames[i]));
39 }
40
41 if (list.empty())
42 {
43 this->selectGeoButton->setDisabled(true);
44 this->deselectGeoButton->setDisabled(true);
45 list.append("(No geometry available.)");
46 }
47 _allGeo->setStringList(list);
48 this->allGeoView->setModel(_allGeo);
49 this->selectedGeoView->setModel(_selGeo);
50
51 std::string new_geo_name("MergedGeometry");
52 _geo_objects.isUniquePointVecName(new_geo_name);
53 this->newGeoNameEdit->setText(QString::fromStdString(new_geo_name));
54}
55
61
63{
64 QModelIndexList selected =
65 this->allGeoView->selectionModel()->selectedIndexes();
66 QStringList list = _selGeo->stringList();
67
68 for (auto& index : selected)
69 {
70 list.append(index.data().toString());
71
72 _allGeo->removeRow(index.row());
73 }
74 _selGeo->setStringList(list);
75}
76
78{
79 QModelIndexList selected =
80 this->selectedGeoView->selectionModel()->selectedIndexes();
81 QStringList list = _allGeo->stringList();
82
83 for (auto& index : selected)
84 {
85 list.append(index.data().toString());
86
87 _selGeo->removeRow(index.row());
88 }
89 _allGeo->setStringList(list);
90}
91
93{
94 if (_selGeo->stringList().size() > 1)
95 {
96 this->done(QDialog::Accepted);
97 }
98 else
99 {
101 "At least two geometries need\n to be selected for merging.");
102 }
103}
104
106{
107 this->done(QDialog::Rejected);
108}
109
110std::vector<std::string> MergeGeometriesDialog::getSelectedGeometries() const
111{
112 std::vector<std::string> indexList;
113 QStringList const& list(_selGeo->stringList());
114 std::transform(list.begin(), list.end(), std::back_inserter(indexList),
115 [](auto const& index) { return index.toStdString(); });
116 return indexList;
117}
118
120{
121 return this->newGeoNameEdit->text().toStdString();
122}
Container class for geometric objects.
Definition GEOObjects.h:46
MergeGeometriesDialog(GeoLib::GEOObjects &geoObjects, QDialog *parent=nullptr)
std::string getGeometryName() const
Returns the name of the new merged geometry.
std::vector< std::string > getSelectedGeometries() const
Returns a vector of selected geometries.
void accept() override
Instructions if the OK-Button has been pressed.
GeoLib::GEOObjects & _geo_objects
void reject() override
Instructions if the Cancel-Button has been pressed.
static void box(const QString &e)
Definition OGSError.cpp:13