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