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 27 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 16 of file DiagramPrefsDialog.cpp.

20 : QDialog(parent), _window(nullptr)
21{
22 setAttribute(Qt::WA_DeleteOnClose);
23
24 setupUi(this);
25 stationNameLabel->setText(QString::fromStdString(stn->getName()));
26 stationTypeLabel->setText(listName);
27}
std::string const & getName() const
Returns the name of the station.
Definition Station.h:49

References _window, and 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 29 of file DiagramPrefsDialog.cpp.

30 : QDialog(parent), _window(nullptr)
31{
32 setupUi(this);
33 stationNameLabel->setText(QString::fromStdString(stn->getName()));
34 stationTypeLabel->setText("");
36
37 fromDateLine->setText(
38 QString::number(stn->getSensorData()->getStartTime()));
39 toDateLine->setText(QString::number(stn->getSensorData()->getEndTime()));
41}
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:78
std::size_t getEndTime() const
Returns the last time step.
Definition SensorData.h:93
std::size_t getStartTime() const
Returns the first time step.
Definition SensorData.h:90

References _list, _window, 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 43 of file DiagramPrefsDialog.cpp.

46 : QDialog(parent), _window(window)
47{
48 QFileInfo fi(filename);
49 setupUi(this);
50 stationNameLabel->setText(fi.baseName());
51 stationTypeLabel->setText("");
52 this->loadFile(filename);
53}
int loadFile(const QString &filename)

References _window, and loadFile().

◆ ~DiagramPrefsDialog()

DiagramPrefsDialog::~DiagramPrefsDialog ( )
override

Definition at line 55 of file DiagramPrefsDialog.cpp.

56{
57 this->destroy();
58}

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 60 of file DiagramPrefsDialog.cpp.

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

References _list, _visability, _window, 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 175 of file DiagramPrefsDialog.cpp.

176{
177 for (auto& item : _list)
178 {
179 QCheckBox* box = new QCheckBox(item->getName());
180 box->setChecked(true);
181 this->CheckBoxLayout->addWidget(box);
182 _visability.push_back(box);
183 }
184}

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 130 of file DiagramPrefsDialog.cpp.

131{
132 if (DiagramList::readList(filename, _list))
133 {
134 for (auto& item : _list)
135 {
136 // item->setName(stationTypeLabel->text() + ": " +
137 // stationNameLabel->text());
138 item->setXLabel("Time");
139 // item->setYLabel("Water Level");
140 item->setXUnit("day");
141 // item->setYUnit("metres");
142 item->setColor(QColor(Qt::red));
143 }
144 fromDateLine->setText(_list[0]->getStartDate().toString("dd.MM.yyyy"));
145 QDateTime endDate = _list[0]->getStartDate().addSecs(
146 static_cast<int>(_list[0]->maxXValue()));
147 toDateLine->setText(endDate.toString("dd.MM.yyyy"));
149 return 1;
150 }
151
152 OGSError::box("Error reading file.");
153 return 0;
154}
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 156 of file DiagramPrefsDialog.cpp.

158{
159 if (!coords.empty())
160 {
161 auto* l = new DiagramList;
162 l->setName(stationTypeLabel->text() + ": " + stationNameLabel->text());
163 l->setXLabel("Time");
164 // l->setYLabel("Water Level");
165 l->setXUnit("day");
166 // l->setYUnit("metres");
167 l->setColor(QColor(Qt::red));
168 l->setList(coords);
169 _list.push_back(l);
170 return 1;
171 }
172 return 0;
173}
constexpr ranges::views::view_closure coords
Definition Mesh.h:223

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 117 of file DiagramPrefsDialog.cpp.

118{
119 QString fileName =
120 QFileDialog::getOpenFileName(this,
121 "Select time series file to open",
122 "",
123 "Time series files (*.stn *.txt)");
124 if (!fileName.isEmpty())
125 {
126 loadFile(fileName);
127 }
128}

References loadFile().

◆ reject

void DiagramPrefsDialog::reject ( )
overrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 112 of file DiagramPrefsDialog.cpp.

113{
114 this->done(QDialog::Rejected);
115}

Member Data Documentation

◆ _list

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

◆ _visability

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

Definition at line 89 of file DiagramPrefsDialog.h.

Referenced by accept(), and createVisibilityCheckboxes().

◆ _window

DetailWindow* DiagramPrefsDialog::_window
private

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