OGS
SHPImportDialog Class Reference

Detailed Description

Dialog for selecting which information should be loaded from a shape file.

Definition at line 27 of file SHPImportDialog.h.

#include <SHPImportDialog.h>

Inheritance diagram for SHPImportDialog:
[legend]
Collaboration diagram for SHPImportDialog:
[legend]

Signals

void shpLoaded (QString)

Public Member Functions

 SHPImportDialog (std::string filename, GeoLib::GEOObjects &geo_objects, std::string const &gmsh_path, QDialog *parent=nullptr)
 Constructor.
 ~SHPImportDialog () override

Public Attributes

QDialogButtonBox * _buttonBox

Private Slots

void accept () override
 Instructions if the OK-Button has been pressed.
void reject () override
 Instructions if the Cancel-Button has been pressed.

Private Member Functions

void setupDialog ()
 The buttons used in this dialog.

Private Attributes

QGridLayout * _layout
QLabel * _shpContentLabel
QLabel * _nameLabel
QLineEdit * _listName
QRadioButton * _choice1
QRadioButton * _choice2
std::string _filename
short _fileType
FileIO::SHPInterface_shpInterface
std::string const _gmsh_path

Constructor & Destructor Documentation

◆ SHPImportDialog()

SHPImportDialog::SHPImportDialog ( std::string filename,
GeoLib::GEOObjects & geo_objects,
std::string const & gmsh_path,
QDialog * parent = nullptr )

Constructor.

Definition at line 17 of file SHPImportDialog.cpp.

21 : QDialog(parent),
22 _buttonBox(nullptr),
23 _layout(nullptr),
24 _shpContentLabel(nullptr),
25 _nameLabel(nullptr),
26 _listName(new QLineEdit()),
27 _choice1(nullptr),
28 _choice2(nullptr),
29 _filename(std::move(filename)),
30 _fileType(0),
31 _shpInterface(new FileIO::SHPInterface(geo_objects)),
32 _gmsh_path(gmsh_path)
33{
35 show();
36}
QGridLayout * _layout
QRadioButton * _choice2
void setupDialog()
The buttons used in this dialog.
QLineEdit * _listName
QRadioButton * _choice1
QLabel * _shpContentLabel
std::string _filename
QDialogButtonBox * _buttonBox
FileIO::SHPInterface * _shpInterface
std::string const _gmsh_path

References _buttonBox, _choice1, _choice2, _filename, _fileType, _gmsh_path, _layout, _listName, _nameLabel, _shpContentLabel, _shpInterface, and setupDialog().

◆ ~SHPImportDialog()

SHPImportDialog::~SHPImportDialog ( )
override

Definition at line 38 of file SHPImportDialog.cpp.

39{
40 delete _shpInterface;
41 delete _buttonBox;
42 delete _listName;
43 delete _choice1;
44 delete _choice2;
45 delete _shpContentLabel;
46 delete _nameLabel;
47 delete _layout;
48}

References _buttonBox, _choice1, _choice2, _layout, _listName, _nameLabel, _shpContentLabel, and _shpInterface.

Member Function Documentation

◆ accept

void SHPImportDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed.

Definition at line 143 of file SHPImportDialog.cpp.

144{
145 QString list_name(_listName->text());
146 if (list_name.compare("") == 0)
147 {
148 OGSError::box("Please insert a name for the data in this file.");
149 return;
150 }
151
152 if (_fileType == 1 && _choice1->isChecked())
153 {
154 _shpInterface->readSHPFile(_filename,
156 list_name.toStdString(), _gmsh_path);
157 }
158 if (_fileType == 1 && _choice2->isChecked())
159 {
160 _shpInterface->readSHPFile(_filename,
162 list_name.toStdString(), _gmsh_path);
163 }
164 if (_fileType == 2 && _choice1->isChecked())
165 {
166 _shpInterface->readSHPFile(_filename,
168 list_name.toStdString(), _gmsh_path);
169 }
170 if (_fileType == 2 && _choice2->isChecked())
171 {
172 _shpInterface->readSHPFile(_filename,
174 list_name.toStdString(), _gmsh_path);
175 }
176 emit shpLoaded(list_name);
177
178 this->done(QDialog::Accepted);
179}
static void box(const QString &e)
Definition OGSError.cpp:13
void shpLoaded(QString)

References _choice1, _choice2, _filename, _fileType, _gmsh_path, _listName, _shpInterface, OGSError::box(), FileIO::SHPInterface::POINT, FileIO::SHPInterface::POLYGON, FileIO::SHPInterface::POLYLINE, shpLoaded(), and FileIO::SHPInterface::STATION.

Referenced by setupDialog().

◆ reject

void SHPImportDialog::reject ( )
overrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 181 of file SHPImportDialog.cpp.

182{
183 this->done(QDialog::Rejected);
184}

Referenced by setupDialog().

◆ setupDialog()

void SHPImportDialog::setupDialog ( )
private

The buttons used in this dialog.

Constructs a dialog window based on the information found in the selected shape file

Definition at line 50 of file SHPImportDialog.cpp.

51{
52 _layout = new QGridLayout(this);
53 int shpType = 0;
54 int numberOfEntities = 0;
55 QString type = "";
56
57 setWindowTitle("Import SHP File");
58
59 if (_shpInterface->readSHPInfo(_filename, shpType, numberOfEntities))
60 {
61 if ((shpType - 1) % 10 == 0)
62 {
63 type = "points";
64 }
65 if ((shpType - 3) % 10 == 0)
66 {
67 type = "polylines";
68 }
69 if ((shpType - 5) % 10 == 0)
70 {
71 type = "polygons";
72 }
73 if ((shpType - 8) % 10 == 0)
74 {
75 type = "multipoints";
76 }
77 if (shpType == 31)
78 {
79 type = "TIN elements";
80 }
81
83 new QLabel("The selected file contains " +
84 QString::number(numberOfEntities) + " " + type,
85 this);
86 _nameLabel = new QLabel("List Name: ", this);
87
88 QFileInfo fi(QString::fromStdString(_filename));
89 _listName->setText(fi.baseName());
90
91 if ((shpType - 1) % 10 == 0 && shpType != 31) // Points
92 {
93 _choice1 = new QRadioButton("Read as Geometry Points");
94 _choice2 = new QRadioButton("Read as Station Points");
95 _choice1->toggle(); // default choice
96 _layout->addWidget(_shpContentLabel);
97 _layout->addWidget(_choice1);
98 _layout->addWidget(_choice2);
99 _layout->addWidget(_nameLabel);
100 _layout->addWidget(_listName);
101 _fileType = 1;
102 }
103 else if ((shpType - 3) % 10 == 0 ||
104 (shpType - 5) % 10 == 0) // Polylines
105 {
106 _choice1 = new QRadioButton("Read Polylines only");
107 _choice2 = new QRadioButton("Read Polylines/Surfaces");
108 if ((shpType - 3) % 10 == 0)
109 {
110 _choice2->setDisabled(true); // disable polygon-choice if file
111 // contains only polylines
112 }
113 _choice1->toggle(); // default choice
114 _layout->addWidget(_shpContentLabel);
115 _layout->addWidget(_choice1);
116 _layout->addWidget(_choice2);
117 _layout->addWidget(_nameLabel);
118 _layout->addWidget(_listName);
119 _fileType = 2;
120 }
121 else
122 {
123 _nameLabel->setText(
124 "This element type is currently not supported.");
125 _layout->addWidget(_shpContentLabel);
126 _layout->addWidget(_nameLabel);
127 }
128
129 _buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
130 QDialogButtonBox::Cancel);
131 connect(_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
132 connect(_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
133 _layout->addWidget(_buttonBox);
134
135 setLayout(_layout);
136 }
137 else
138 {
139 OGSError::box("Error reading shapefile!");
140 }
141}
void accept() override
Instructions if the OK-Button has been pressed.
void reject() override
Instructions if the Cancel-Button has been pressed.

References _buttonBox, _choice1, _choice2, _filename, _fileType, _layout, _listName, _nameLabel, _shpContentLabel, _shpInterface, accept(), OGSError::box(), and reject().

Referenced by SHPImportDialog().

◆ shpLoaded

void SHPImportDialog::shpLoaded ( QString )
signal

Referenced by accept().

Member Data Documentation

◆ _buttonBox

QDialogButtonBox* SHPImportDialog::_buttonBox

Definition at line 38 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), and setupDialog().

◆ _choice1

QRadioButton* SHPImportDialog::_choice1
private

Definition at line 48 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), accept(), and setupDialog().

◆ _choice2

QRadioButton * SHPImportDialog::_choice2
private

Definition at line 48 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), accept(), and setupDialog().

◆ _filename

std::string SHPImportDialog::_filename
private

Definition at line 49 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), accept(), and setupDialog().

◆ _fileType

short SHPImportDialog::_fileType
private

Definition at line 50 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), accept(), and setupDialog().

◆ _gmsh_path

std::string const SHPImportDialog::_gmsh_path
private

Definition at line 52 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), and accept().

◆ _layout

QGridLayout* SHPImportDialog::_layout
private

Definition at line 44 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), and setupDialog().

◆ _listName

QLineEdit* SHPImportDialog::_listName
private

Definition at line 47 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), accept(), and setupDialog().

◆ _nameLabel

QLabel* SHPImportDialog::_nameLabel
private

Definition at line 46 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), and setupDialog().

◆ _shpContentLabel

QLabel* SHPImportDialog::_shpContentLabel
private

Definition at line 45 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), and setupDialog().

◆ _shpInterface

FileIO::SHPInterface* SHPImportDialog::_shpInterface
private

Definition at line 51 of file SHPImportDialog.h.

Referenced by SHPImportDialog(), ~SHPImportDialog(), accept(), and setupDialog().


The documentation for this class was generated from the following files: