OGS
MergeGeometriesDialog.cpp
Go to the documentation of this file.
1
16
17#include <QStringList>
18#include <QStringListModel>
19
20#include "Base/OGSError.h"
21#include "GeoLib/GEOObjects.h"
22
24 QDialog* parent)
25 : QDialog(parent),
26 _geo_objects(geoObjects),
27 _allGeo(new QStringListModel),
28 _selGeo(new QStringListModel)
29{
30 setupUi(this);
31
32 auto const geoNames = _geo_objects.getGeometryNames();
33
34 // get station names
35 std::vector<std::string> geo_station_names;
36 _geo_objects.getStationVectorNames(geo_station_names);
37
38 // merge method does currently not merge stations, converter function needed
39 // first
40 // geoNames.reserve(geo_station_names.size());
41 // std::copy(geo_station_names.begin(), geo_station_names.end(),
42 // std::back_inserter(geoNames));
43
44 std::size_t nGeoObjects(geoNames.size());
45
46 QStringList list;
47 for (unsigned i = 0; i < nGeoObjects; ++i)
48 {
49 list.append(QString::fromStdString(geoNames[i]));
50 }
51
52 if (list.empty())
53 {
54 this->selectGeoButton->setDisabled(true);
55 this->deselectGeoButton->setDisabled(true);
56 list.append("(No geometry available.)");
57 }
58 _allGeo->setStringList(list);
59 this->allGeoView->setModel(_allGeo);
60 this->selectedGeoView->setModel(_selGeo);
61
62 std::string new_geo_name("MergedGeometry");
64 this->newGeoNameEdit->setText(QString::fromStdString(new_geo_name));
65}
66
72
74{
75 QModelIndexList selected =
76 this->allGeoView->selectionModel()->selectedIndexes();
77 QStringList list = _selGeo->stringList();
78
79 for (auto& index : selected)
80 {
81 list.append(index.data().toString());
82
83 _allGeo->removeRow(index.row());
84 }
85 _selGeo->setStringList(list);
86}
87
89{
90 QModelIndexList selected =
91 this->selectedGeoView->selectionModel()->selectedIndexes();
92 QStringList list = _allGeo->stringList();
93
94 for (auto& index : selected)
95 {
96 list.append(index.data().toString());
97
98 _selGeo->removeRow(index.row());
99 }
100 _allGeo->setStringList(list);
101}
102
104{
105 if (_selGeo->stringList().size() > 1)
106 {
107 this->done(QDialog::Accepted);
108 }
109 else
110 {
112 "At least two geometries need\n to be selected for merging.");
113 }
114}
115
117{
118 this->done(QDialog::Rejected);
119}
120
121std::vector<std::string> MergeGeometriesDialog::getSelectedGeometries() const
122{
123 std::vector<std::string> indexList;
124 QStringList const& list(_selGeo->stringList());
125 std::transform(list.begin(), list.end(), std::back_inserter(indexList),
126 [](auto const& index) { return index.toStdString(); });
127 return indexList;
128}
129
131{
132 return this->newGeoNameEdit->text().toStdString();
133}
Definition of the GEOObjects class.
Definition of the MergeGeometriesDialog class.
Definition of the OGSError class.
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
bool isUniquePointVecName(std::string &name) const
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
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:23