OGS
LineEditDialog.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
4#include "LineEditDialog.h"
5
6#include <QStringList>
7#include <QStringListModel>
8
9#include "Base/OGSError.h"
10
12 QDialog* parent)
13 : QDialog(parent),
14 _allPly(new QStringListModel),
15 _selPly(new QStringListModel),
16 _geoName(ply_vec.getName())
17{
18 setupUi(this);
19
20 this->proximityEdit->setValidator(new QDoubleValidator(0, 100, 8, this));
21
22 std::size_t nPly(ply_vec.size());
23 QStringList list;
24 for (std::size_t i = 0; i < nPly; i++)
25 {
26 std::string ply_name;
27 ply_vec.getNameOfElementByID(i, ply_name);
28 list.append("Line " + QString::number(i) + " " +
29 QString::fromStdString(ply_name));
30 }
31 _allPly->setStringList(list);
32
33 this->allPlyView->setModel(_allPly);
34 this->selectedPlyView->setModel(_selPly);
35}
36
38{
39 delete _allPly;
40 delete _selPly;
41}
42
44{
45 QModelIndexList selected =
46 this->allPlyView->selectionModel()->selectedIndexes();
47 QStringList list = _selPly->stringList();
48
49 for (auto& index : selected)
50 {
51 list.append(index.data().toString());
52
53 _allPly->removeRow(index.row());
54 }
55 _selPly->setStringList(list);
56}
57
59{
60 QModelIndexList selected =
61 this->selectedPlyView->selectionModel()->selectedIndexes();
62 QStringList list = _allPly->stringList();
63
64 for (auto& index : selected)
65 {
66 list.append(index.data().toString());
67
68 _selPly->removeRow(index.row());
69 }
70 _allPly->setStringList(list);
71}
72
74{
75 std::vector<std::size_t> selectedIndeces =
76 this->getSelectedIndeces(_selPly->stringList());
77
78 if (!selectedIndeces.empty())
79 {
80 std::string prox_string = this->proximityEdit->text().toStdString();
81 double prox =
82 (prox_string.empty()) ? 0.0 : strtod(prox_string.c_str(), nullptr);
83 std::string ply_name = (plyNameEdit->text().toStdString().empty())
84 ? ""
85 : plyNameEdit->text().toStdString();
87 selectedIndeces,
88 prox,
89 ply_name,
90 this->closePlyCheckBox->isChecked(),
91 this->createSfcCheckBox->isChecked());
92 this->done(QDialog::Accepted);
93 }
94 else
95 {
96 OGSError::box("No polylines selected", "Error");
97 }
98}
99
101{
102 this->done(QDialog::Rejected);
103}
104
105std::vector<std::size_t> LineEditDialog::getSelectedIndeces(QStringList list)
106{
107 std::vector<std::size_t> indexList;
108 for (auto& index : list)
109 {
110 QString s = index.mid(5, index.indexOf(" ") - 5);
111 indexList.push_back(s.toInt());
112 }
113 return indexList;
114}
std::string getName(std::string const &line)
Returns the name/title from the "Zone"-description.
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::size_t size() const
Definition TemplateVec.h:88
void on_deselectPlyButton_pressed()
Instructions when polylines are deselected.
QStringListModel * _selPly
void on_selectPlyButton_pressed()
Instructions when polylines are selected.
std::string _geoName
LineEditDialog(const GeoLib::PolylineVec &ply_vec, QDialog *parent=nullptr)
~LineEditDialog() override
void accept() override
Instructions if the OK-Button has been pressed.
void reject() override
Instructions if the Cancel-Button has been pressed.
QStringListModel * _allPly
void connectPolylines(const std::string &, std::vector< std::size_t >, double, std::string, bool, bool)
std::vector< std::size_t > getSelectedIndeces(QStringList list)
static void box(const QString &e)
Definition OGSError.cpp:13
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
Definition PolylineVec.h:16