OGS
DetailWindow.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "DetailWindow.h"
5
6#include <QFileDialog>
7#include <QSettings>
8
10#include "DiagramPrefsDialog.h"
11
12DetailWindow::DetailWindow(QWidget* parent) : QWidget(parent)
13{
14 setupUi(this);
15 stationView->setRenderHints(QPainter::Antialiasing);
16
17 /*
18 DiagramList* list = new DiagramList();
19 DiagramList* list2 = new DiagramList();
20
21
22 // ==================================================
23 // input files should be defined in WaterML
24 // inserting the details below into the list-objects
25 // kind of simulates the information that would be
26 // included in a WaterML-file and is needed for
27 // display
28 // ==================================================
29
30 // make up list-object for the first test station
31 list->setName("Water Level Observation Station: Halberstadt 2002");
32 list->setXLabel("Time");
33 list->setYLabel("Water Level");
34 list->setXUnit("day");
35 list->setYUnit("metres");
36 list->setColor(QColor(Qt::red));
37 list->readList("c:\\project\\timeseries-a.stn");
38
39 // make up list-object for the second test station
40 list2->setName("Water Level Observation Station: Oschersleben 2002");
41 list2->setXLabel("Time");
42 list2->setYLabel("Water Level");
43 list2->setXUnit("day");
44 list2->setYUnit("metres");
45 list2->setColor(QColor(Qt::green));
46 list2->readList("c:\\project\\timeseries-b.stn");
47
48 // ==================================================
49
50
51 stationView->addGraph(list);
52 stationView->addGraph(list2);
53
54 resizeWindow();
55 */
56}
57
58DetailWindow::DetailWindow(QString filename, QWidget* parent) : QWidget(parent)
59{
60 setupUi(this);
61 stationView->setRenderHints(QPainter::Antialiasing);
62
63 std::vector<DiagramList*> lists;
64 DiagramList::readList(filename, lists);
65
66 for (auto& list : lists)
67 {
68 stationView->addGraph(list);
69 }
70
72}
73
74DetailWindow::DetailWindow(DiagramList* list, QWidget* parent) : QWidget(parent)
75{
76 setupUi(this);
77 stationView->setRenderHints(QPainter::Antialiasing);
78 stationView->addGraph(list);
80}
81
82DetailWindow::DetailWindow(std::vector<std::size_t> data, QWidget* parent)
83 : QWidget(parent)
84{
85 setupUi(this);
86 std::size_t nEntries = data.size();
87 std::vector<std::pair<float, float>> list_data(nEntries);
88
89 for (std::size_t i = 0; i < nEntries; i++)
90 {
91 list_data.emplace_back(static_cast<float>(i),
92 static_cast<float>(data[i]));
93 }
94
95 auto* list = new DiagramList();
96 list->setList(list_data);
97 list->setXUnit("Value");
98 list->setYUnit("Amount");
99 list->setName("Histogram");
100 stationView->setRenderHints(QPainter::Antialiasing);
101 stationView->addGraph(list);
102 resizeWindow();
103}
104
106
108{
109 this->close();
110}
111
113{
114 int width = (stationView->getWidth() > 800) ? 800 : stationView->getWidth();
115 int height =
116 (stationView->getHeight() > 600) ? 600 : stationView->getHeight();
117 resize(width, height);
118}
119
121{
123 QColor colour(c[0], c[1], c[2]);
124 this->addList(list, colour);
125 resizeWindow();
126}
127
129{
130 list->setColor(c);
131 this->stationView->addGraph(list);
132}
133
135{
136 QSettings settings;
137 QString fileName = QFileDialog::getOpenFileName(
138 this, "Select data file to open",
139 settings.value("lastOpenedFileDirectory").toString(),
140 "Text files (*.txt);;All files (* *.*)");
141 if (!fileName.isEmpty())
142 {
143 QDir dir = QDir(fileName);
144 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
145 auto* prefs = new DiagramPrefsDialog(fileName, this);
146 prefs->setAttribute(Qt::WA_DeleteOnClose);
147 prefs->show();
148 }
149}
void on_addDataButton_clicked()
void on_closeButton_clicked()
void resizeWindow()
Automatically resize window based on the measurements of the included graphs.
DetailWindow(QWidget *parent=nullptr)
Creates an empty diagram window.
void addList(DiagramList *list)
~DetailWindow() override
A List of data points and all the necessary meta-information to draw a graph.
Definition DiagramList.h:18
static int readList(const QString &path, std::vector< DiagramList * > &list)
void setColor(QColor c)
Sets the colour of the graph.
Definition DiagramList.h:92
A dialog that allows for setting preferences for a requested diagram.
Color getRandomColor()
Returns a random RGB colour.
Definition Color.cpp:18
std::array< unsigned char, 4 > Color
Definition Color.h:12