OGS
DiagramPrefsDialog Class Reference

Detailed Description

A dialog that allows for setting preferences for a requested diagram.

A dialog that allows for setting preferences for a requested diagram. Note: In the current version this dialog only works when requesting data from a database. Visualisation of data from an ASCII-file is still possible using the "Load File"-button but setting the preferences will not work (i.e. it is only possible to visualise all the data in the file with default preferences.

Definition at line 38 of file DiagramPrefsDialog.h.

#include <DiagramPrefsDialog.h>

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

Public Member Functions

 DiagramPrefsDialog (const GeoLib::Station *stn, const QString &listName, QDialog *parent=nullptr)
 
 DiagramPrefsDialog (GeoLib::Station *stn, QDialog *parent=nullptr)
 
 DiagramPrefsDialog (const QString &filename, DetailWindow *window=nullptr, QDialog *parent=nullptr)
 
 ~DiagramPrefsDialog () override
 

Private Slots

void accept () override
 
void reject () override
 Instructions if the Cancel-Button has been pressed.
 
void on_loadFileButton_clicked ()
 Instructions if the "Load File"-Button has been pressed.
 

Private Member Functions

void createVisibilityCheckboxes ()
 
int loadFile (const QString &filename)
 
int loadList (const std::vector< std::pair< QDateTime, float > > &coords)
 

Private Attributes

std::vector< DiagramList * > _list
 
std::vector< QCheckBox * > _visability
 
DetailWindow_window
 

Constructor & Destructor Documentation

◆ DiagramPrefsDialog() [1/3]

DiagramPrefsDialog::DiagramPrefsDialog ( const GeoLib::Station stn,
const QString &  listName,
QDialog *  parent = nullptr 
)

Opens a new dialog based on station and the list this station belongs to. If a database connection is available, the program will try to find data associated with the station, otherwise data can be loaded from a file.

Parameters
stnThe station object associated the diagram.
listNameThe station list the station belongs to.
parentThe parent QDialog.

Definition at line 27 of file DiagramPrefsDialog.cpp.

31 : QDialog(parent), _window(nullptr)
32{
33 setAttribute(Qt::WA_DeleteOnClose);
34
35 setupUi(this);
36 stationNameLabel->setText(QString::fromStdString(stn->getName()));
37 stationTypeLabel->setText(listName);
38}
DetailWindow * _window
std::string const & getName() const
Returns the name of the station.
Definition: Station.h:62

References GeoLib::Station::getName().

◆ DiagramPrefsDialog() [2/3]

DiagramPrefsDialog::DiagramPrefsDialog ( GeoLib::Station stn,
QDialog *  parent = nullptr 
)
explicit

Opens a new dialog and automatically reads data from the associated station object.

Parameters
stnThe station object associated the diagram.
parentThe parent QDialog.

Definition at line 40 of file DiagramPrefsDialog.cpp.

41 : QDialog(parent), _window(nullptr)
42{
43 setupUi(this);
44 stationNameLabel->setText(QString::fromStdString(stn->getName()));
45 stationTypeLabel->setText("");
47
48 fromDateLine->setText(
49 QString::number(stn->getSensorData()->getStartTime()));
50 toDateLine->setText(QString::number(stn->getSensorData()->getEndTime()));
52}
static int readList(const QString &path, std::vector< DiagramList * > &list)
std::vector< DiagramList * > _list
const SensorData * getSensorData() const
Returns all the sensor data for this observation site.
Definition: Station.h:91
std::size_t getEndTime() const
Returns the last time step.
Definition: SensorData.h:104
std::size_t getStartTime() const
Returns the first time step.
Definition: SensorData.h:101

References _list, createVisibilityCheckboxes(), SensorData::getEndTime(), GeoLib::Station::getName(), GeoLib::Station::getSensorData(), SensorData::getStartTime(), and DiagramList::readList().

◆ DiagramPrefsDialog() [3/3]

DiagramPrefsDialog::DiagramPrefsDialog ( const QString &  filename,
DetailWindow window = nullptr,
QDialog *  parent = nullptr 
)
explicit

Opens a new dialog and automatically reads data from the specified file. The diagram is not associated with any geometric object.

Parameters
filenameFile containing data for the diagram(s) to be visualised.
[out]windowReturns the created DetailWindow.
parentThe parent QDialog.

Definition at line 54 of file DiagramPrefsDialog.cpp.

57 : QDialog(parent), _window(window)
58{
59 QFileInfo fi(filename);
60 setupUi(this);
61 stationNameLabel->setText(fi.baseName());
62 stationTypeLabel->setText("");
63 this->loadFile(filename);
64}
int loadFile(const QString &filename)

References loadFile().

◆ ~DiagramPrefsDialog()

DiagramPrefsDialog::~DiagramPrefsDialog ( )
override

Definition at line 66 of file DiagramPrefsDialog.cpp.

67{
68 this->destroy();
69}

Member Function Documentation

◆ accept

void DiagramPrefsDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed. Note: Clicking the "Load from file"-button overrides the database input!

Definition at line 71 of file DiagramPrefsDialog.cpp.

72{
73 QDateTime start_date(getDateTime(fromDateLine->text()));
74 QDateTime end_date(getDateTime(toDateLine->text()));
75
76 if (start_date == QDateTime() || end_date == QDateTime() ||
77 start_date > end_date || _list.empty())
78 {
79 OGSError::box("No data found...");
80 return;
81 }
82
83 if (_list[0]->size() == 0)
84 {
85 OGSError::box("Invalid station data.");
86 this->done(QDialog::Rejected);
87 }
88
89 // Data has been loaded.
90 // If loading lists beyond the first one fails at least nothing terrible
91 // will happen.
92 bool window_is_empty(false);
93 if (_window == nullptr)
94 {
95 _window = new DetailWindow();
96 _window->setAttribute(Qt::WA_DeleteOnClose);
97 window_is_empty = true;
98 }
99
100 for (std::size_t i = 0; i < _list.size(); i++)
101 {
102 if (_visability[i]->isChecked())
103 {
104 _list[i]->truncateToRange(start_date, end_date);
105 _window->addList(_list[i]);
106 window_is_empty = false;
107 }
108 }
109
110 if (!window_is_empty)
111 {
112 _window->show();
113 this->done(QDialog::Accepted);
114 }
115 else
116 {
117 delete _window;
118 _window = nullptr;
119 OGSError::box("No dataset selected.");
120 }
121}
QDateTime getDateTime(QString const &stringDate)
Converts string into QDateTime-format.
Definition: GetDateTime.h:18
Creates a window containing a diagram.
Definition: DetailWindow.h:25
void addList(DiagramList *list)
std::vector< QCheckBox * > _visability
static void box(const QString &e)
Definition: OGSError.cpp:23
constexpr int size(int const displacement_dim)
Vectorized tensor size for given displacement dimension.

References _list, _visability, _window, DetailWindow::addList(), OGSError::box(), and getDateTime().

◆ createVisibilityCheckboxes()

void DiagramPrefsDialog::createVisibilityCheckboxes ( )
private

Creates checkboxes for every list of data values found. Per default all of these are checked, i.e. all diagrams will be visualised. Any checkbox the user unchecks will result in the associated data not being visualised.

Definition at line 186 of file DiagramPrefsDialog.cpp.

187{
188 for (auto& item : _list)
189 {
190 QCheckBox* box = new QCheckBox(item->getName());
191 box->setChecked(true);
192 this->CheckBoxLayout->addWidget(box);
193 _visability.push_back(box);
194 }
195}

References _list, and _visability.

Referenced by DiagramPrefsDialog(), and loadFile().

◆ loadFile()

int DiagramPrefsDialog::loadFile ( const QString &  filename)
private

Loading data from a file

Parameters
filenameName of the file containing the data
Returns
1 if everything is okay, 0 and an error message if there were errors

Definition at line 141 of file DiagramPrefsDialog.cpp.

142{
143 if (DiagramList::readList(filename, _list))
144 {
145 for (auto& item : _list)
146 {
147 // item->setName(stationTypeLabel->text() + ": " +
148 // stationNameLabel->text());
149 item->setXLabel("Time");
150 // item->setYLabel("Water Level");
151 item->setXUnit("day");
152 // item->setYUnit("metres");
153 item->setColor(QColor(Qt::red));
154 }
155 fromDateLine->setText(_list[0]->getStartDate().toString("dd.MM.yyyy"));
156 QDateTime endDate = _list[0]->getStartDate().addSecs(
157 static_cast<int>(_list[0]->maxXValue()));
158 toDateLine->setText(endDate.toString("dd.MM.yyyy"));
160 return 1;
161 }
162
163 OGSError::box("Error reading file.");
164 return 0;
165}
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)

References _list, OGSError::box(), createVisibilityCheckboxes(), and DiagramList::readList().

Referenced by DiagramPrefsDialog(), and on_loadFileButton_clicked().

◆ loadList()

int DiagramPrefsDialog::loadList ( const std::vector< std::pair< QDateTime, float > > &  coords)
private

Setting up the QDiagramList object were the time series data will be stored

Parameters
coordsList of coordinates.
Returns
1 if everything is okay, 0 and an error message if there were errors

Definition at line 167 of file DiagramPrefsDialog.cpp.

169{
170 if (!coords.empty())
171 {
172 auto* l = new DiagramList;
173 l->setName(stationTypeLabel->text() + ": " + stationNameLabel->text());
174 l->setXLabel("Time");
175 // l->setYLabel("Water Level");
176 l->setXUnit("day");
177 // l->setYUnit("metres");
178 l->setColor(QColor(Qt::red));
179 l->setList(coords);
180 _list.push_back(l);
181 return 1;
182 }
183 return 0;
184}
A List of data points and all the necessary meta-information to draw a graph.
Definition: DiagramList.h:29
void setName(QString name)
Sets the name of the graph to be displayed in the caption.
Definition: DiagramList.h:106
constexpr ranges::views::view_closure coords
Definition: Mesh.h:232

References _list, and DiagramList::setName().

◆ on_loadFileButton_clicked

void DiagramPrefsDialog::on_loadFileButton_clicked ( )
privateslot

Instructions if the "Load File"-Button has been pressed.

Definition at line 128 of file DiagramPrefsDialog.cpp.

129{
130 QString fileName =
131 QFileDialog::getOpenFileName(this,
132 "Select time series file to open",
133 "",
134 "Time series files (*.stn *.txt)");
135 if (!fileName.isEmpty())
136 {
137 loadFile(fileName);
138 }
139}

References loadFile().

◆ reject

void DiagramPrefsDialog::reject ( )
overrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 123 of file DiagramPrefsDialog.cpp.

124{
125 this->done(QDialog::Rejected);
126}

Member Data Documentation

◆ _list

std::vector<DiagramList*> DiagramPrefsDialog::_list
private

◆ _visability

std::vector<QCheckBox*> DiagramPrefsDialog::_visability
private

Definition at line 100 of file DiagramPrefsDialog.h.

Referenced by accept(), and createVisibilityCheckboxes().

◆ _window

DetailWindow* DiagramPrefsDialog::_window
private

Definition at line 101 of file DiagramPrefsDialog.h.

Referenced by accept().


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