OGS
SHPImportDialog Class Reference

Detailed Description

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

Definition at line 38 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 28 of file SHPImportDialog.cpp.

32 : QDialog(parent),
33 _buttonBox(nullptr),
34 _layout(nullptr),
35 _shpContentLabel(nullptr),
36 _nameLabel(nullptr),
37 _listName(new QLineEdit()),
38 _choice1(nullptr),
39 _choice2(nullptr),
40 _filename(std::move(filename)),
41 _fileType(0),
42 _shpInterface(new FileIO::SHPInterface(geo_objects)),
43 _gmsh_path(gmsh_path)
44{
46 show();
47}
Manages the import of ESRI shape files into GeoLib.
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 setupDialog().

◆ ~SHPImportDialog()

SHPImportDialog::~SHPImportDialog ( )
override

Definition at line 49 of file SHPImportDialog.cpp.

50{
51 delete _shpInterface;
52 delete _buttonBox;
53 delete _listName;
54 delete _choice1;
55 delete _choice2;
56 delete _shpContentLabel;
57 delete _nameLabel;
58 delete _layout;
59}

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 154 of file SHPImportDialog.cpp.

155{
156 QString list_name(_listName->text());
157 if (list_name.compare("") == 0)
158 {
159 OGSError::box("Please insert a name for the data in this file.");
160 return;
161 }
162
163 if (_fileType == 1 && _choice1->isChecked())
164 {
167 list_name.toStdString(), _gmsh_path);
168 }
169 if (_fileType == 1 && _choice2->isChecked())
170 {
173 list_name.toStdString(), _gmsh_path);
174 }
175 if (_fileType == 2 && _choice1->isChecked())
176 {
179 list_name.toStdString(), _gmsh_path);
180 }
181 if (_fileType == 2 && _choice2->isChecked())
182 {
185 list_name.toStdString(), _gmsh_path);
186 }
187 emit shpLoaded(list_name);
188
189 this->done(QDialog::Accepted);
190}
void readSHPFile(const std::string &filename, OGSType choice, const std::string &listName, std::string const &gmsh_path)
Reads data from the shape file.
static void box(const QString &e)
Definition OGSError.cpp:23
void shpLoaded(QString)

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

Referenced by setupDialog().

◆ reject

void SHPImportDialog::reject ( )
overrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 192 of file SHPImportDialog.cpp.

193{
194 this->done(QDialog::Rejected);
195}

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 61 of file SHPImportDialog.cpp.

62{
63 _layout = new QGridLayout(this);
64 int shpType = 0;
65 int numberOfEntities = 0;
66 QString type = "";
67
68 setWindowTitle("Import SHP File");
69
70 if (_shpInterface->readSHPInfo(_filename, shpType, numberOfEntities))
71 {
72 if ((shpType - 1) % 10 == 0)
73 {
74 type = "points";
75 }
76 if ((shpType - 3) % 10 == 0)
77 {
78 type = "polylines";
79 }
80 if ((shpType - 5) % 10 == 0)
81 {
82 type = "polygons";
83 }
84 if ((shpType - 8) % 10 == 0)
85 {
86 type = "multipoints";
87 }
88 if (shpType == 31)
89 {
90 type = "TIN elements";
91 }
92
94 new QLabel("The selected file contains " +
95 QString::number(numberOfEntities) + " " + type,
96 this);
97 _nameLabel = new QLabel("List Name: ", this);
98
99 QFileInfo fi(QString::fromStdString(_filename));
100 _listName->setText(fi.baseName());
101
102 if ((shpType - 1) % 10 == 0 && shpType != 31) // Points
103 {
104 _choice1 = new QRadioButton("Read as Geometry Points");
105 _choice2 = new QRadioButton("Read as Station Points");
106 _choice1->toggle(); // default choice
107 _layout->addWidget(_shpContentLabel);
108 _layout->addWidget(_choice1);
109 _layout->addWidget(_choice2);
110 _layout->addWidget(_nameLabel);
111 _layout->addWidget(_listName);
112 _fileType = 1;
113 }
114 else if ((shpType - 3) % 10 == 0 ||
115 (shpType - 5) % 10 == 0) // Polylines
116 {
117 _choice1 = new QRadioButton("Read Polylines only");
118 _choice2 = new QRadioButton("Read Polylines/Surfaces");
119 if ((shpType - 3) % 10 == 0)
120 {
121 _choice2->setDisabled(true); // disable polygon-choice if file
122 // contains only polylines
123 }
124 _choice1->toggle(); // default choice
125 _layout->addWidget(_shpContentLabel);
126 _layout->addWidget(_choice1);
127 _layout->addWidget(_choice2);
128 _layout->addWidget(_nameLabel);
129 _layout->addWidget(_listName);
130 _fileType = 2;
131 }
132 else
133 {
134 _nameLabel->setText(
135 "This element type is currently not supported.");
136 _layout->addWidget(_shpContentLabel);
137 _layout->addWidget(_nameLabel);
138 }
139
140 _buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
141 QDialogButtonBox::Cancel);
142 connect(_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
143 connect(_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
144 _layout->addWidget(_buttonBox);
145
146 setLayout(_layout);
147 }
148 else
149 {
150 OGSError::box("Error reading shapefile!");
151 }
152}
static bool readSHPInfo(const std::string &filename, int &shapeType, int &numberOfEntities)
Reads the header of the shape file.
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(), FileIO::SHPInterface::readSHPInfo(), and reject().

Referenced by SHPImportDialog().

◆ shpLoaded

void SHPImportDialog::shpLoaded ( QString )
signal

Referenced by accept().

Member Data Documentation

◆ _buttonBox

QDialogButtonBox* SHPImportDialog::_buttonBox

Definition at line 49 of file SHPImportDialog.h.

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

◆ _choice1

QRadioButton* SHPImportDialog::_choice1
private

Definition at line 59 of file SHPImportDialog.h.

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

◆ _choice2

QRadioButton * SHPImportDialog::_choice2
private

Definition at line 59 of file SHPImportDialog.h.

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

◆ _filename

std::string SHPImportDialog::_filename
private

Definition at line 60 of file SHPImportDialog.h.

Referenced by accept(), and setupDialog().

◆ _fileType

short SHPImportDialog::_fileType
private

Definition at line 61 of file SHPImportDialog.h.

Referenced by accept(), and setupDialog().

◆ _gmsh_path

std::string const SHPImportDialog::_gmsh_path
private

Definition at line 63 of file SHPImportDialog.h.

Referenced by accept().

◆ _layout

QGridLayout* SHPImportDialog::_layout
private

Definition at line 55 of file SHPImportDialog.h.

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

◆ _listName

QLineEdit* SHPImportDialog::_listName
private

Definition at line 58 of file SHPImportDialog.h.

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

◆ _nameLabel

QLabel* SHPImportDialog::_nameLabel
private

Definition at line 57 of file SHPImportDialog.h.

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

◆ _shpContentLabel

QLabel* SHPImportDialog::_shpContentLabel
private

Definition at line 56 of file SHPImportDialog.h.

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

◆ _shpInterface

FileIO::SHPInterface* SHPImportDialog::_shpInterface
private

Definition at line 62 of file SHPImportDialog.h.

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


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