OGS
LineEditDialog.cpp
Go to the documentation of this file.
1
15#include "LineEditDialog.h"
16
17#include <QStringList>
18#include <QStringListModel>
19
20#include "Base/OGSError.h"
21
23 QDialog* parent)
24 : QDialog(parent),
25 _allPly(new QStringListModel),
26 _selPly(new QStringListModel),
27 _geoName(ply_vec.getName())
28{
29 setupUi(this);
30
31 this->proximityEdit->setValidator(new QDoubleValidator(0, 100, 8, this));
32
33 std::size_t nPly(ply_vec.size());
34 QStringList list;
35 for (std::size_t i = 0; i < nPly; i++)
36 {
37 std::string ply_name;
38 ply_vec.getNameOfElementByID(i, ply_name);
39 list.append("Line " + QString::number(i) + " " +
40 QString::fromStdString(ply_name));
41 }
42 _allPly->setStringList(list);
43
44 this->allPlyView->setModel(_allPly);
45 this->selectedPlyView->setModel(_selPly);
46}
47
49{
50 delete _allPly;
51 delete _selPly;
52}
53
55{
56 QModelIndexList selected =
57 this->allPlyView->selectionModel()->selectedIndexes();
58 QStringList list = _selPly->stringList();
59
60 for (auto& index : selected)
61 {
62 list.append(index.data().toString());
63
64 _allPly->removeRow(index.row());
65 }
66 _selPly->setStringList(list);
67}
68
70{
71 QModelIndexList selected =
72 this->selectedPlyView->selectionModel()->selectedIndexes();
73 QStringList list = _allPly->stringList();
74
75 for (auto& index : selected)
76 {
77 list.append(index.data().toString());
78
79 _selPly->removeRow(index.row());
80 }
81 _allPly->setStringList(list);
82}
83
85{
86 std::vector<std::size_t> selectedIndeces =
87 this->getSelectedIndeces(_selPly->stringList());
88
89 if (!selectedIndeces.empty())
90 {
91 std::string prox_string = this->proximityEdit->text().toStdString();
92 double prox =
93 (prox_string.empty()) ? 0.0 : strtod(prox_string.c_str(), nullptr);
94 std::string ply_name = (plyNameEdit->text().toStdString().empty())
95 ? ""
96 : plyNameEdit->text().toStdString();
98 selectedIndeces,
99 prox,
100 ply_name,
101 this->closePlyCheckBox->isChecked(),
102 this->createSfcCheckBox->isChecked());
103 this->done(QDialog::Accepted);
104 }
105 else
106 {
107 OGSError::box("No polylines selected", "Error");
108 }
109}
110
112{
113 this->done(QDialog::Rejected);
114}
115
116std::vector<std::size_t> LineEditDialog::getSelectedIndeces(QStringList list)
117{
118 std::vector<std::size_t> indexList;
119 for (auto& index : list)
120 {
121 QString s = index.mid(5, index.indexOf(" ") - 5);
122 indexList.push_back(s.toInt());
123 }
124 return indexList;
125}
Definition of the LineEditDialog class.
Definition of the OGSError class.
std::string getName(std::string const &line)
Returns the name/title from the "Zone"-description.
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition TemplateVec.h:38
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::size_t size() const
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:23