OGS
DetailWindow Class Reference

Detailed Description

Creates a window containing a diagram.

Definition at line 13 of file DetailWindow.h.

#include <DetailWindow.h>

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

Public Member Functions

 DetailWindow (QWidget *parent=nullptr)
 Creates an empty diagram window.
 DetailWindow (QString filename, QWidget *parent=nullptr)
 DetailWindow (DiagramList *list, QWidget *parent=nullptr)
 DetailWindow (std::vector< std::size_t > data, QWidget *parent=nullptr)
 ~DetailWindow () override
void addList (DiagramList *list)
void addList (DiagramList *list, QColor c)

Private Slots

void on_addDataButton_clicked ()
void on_closeButton_clicked ()

Private Member Functions

void resizeWindow ()
 Automatically resize window based on the measurements of the included graphs.

Constructor & Destructor Documentation

◆ DetailWindow() [1/4]

DetailWindow::DetailWindow ( QWidget * parent = nullptr)
explicit

Creates an empty diagram window.

Definition at line 12 of file DetailWindow.cpp.

12 : 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}

◆ DetailWindow() [2/4]

DetailWindow::DetailWindow ( QString filename,
QWidget * parent = nullptr )
explicit

Creates a window containing a diagram.

Parameters
filenameASCII file containing x and y values for the graph to be displayed.
parentThe parent QWidget.

Definition at line 58 of file DetailWindow.cpp.

58 : 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}
void resizeWindow()
Automatically resize window based on the measurements of the included graphs.
static int readList(const QString &path, std::vector< DiagramList * > &list)

References DiagramList::readList(), and resizeWindow().

◆ DetailWindow() [3/4]

DetailWindow::DetailWindow ( DiagramList * list,
QWidget * parent = nullptr )
explicit

Creates a window containing a diagram

Parameters
listA QDiagramList containing all the data points and necessary metainformation for a graph to be displayed
parentThe parent QWidget.

Definition at line 74 of file DetailWindow.cpp.

74 : QWidget(parent)
75{
76 setupUi(this);
77 stationView->setRenderHints(QPainter::Antialiasing);
78 stationView->addGraph(list);
80}

References resizeWindow().

◆ DetailWindow() [4/4]

DetailWindow::DetailWindow ( std::vector< std::size_t > data,
QWidget * parent = nullptr )
explicit

Definition at line 82 of file DetailWindow.cpp.

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}

References resizeWindow().

◆ ~DetailWindow()

DetailWindow::~DetailWindow ( )
overridedefault

Member Function Documentation

◆ addList() [1/2]

void DetailWindow::addList ( DiagramList * list)

Adds another plot to window. Axes are automatically resized, a random color is used.

Definition at line 120 of file DetailWindow.cpp.

121{
123 QColor colour(c[0], c[1], c[2]);
124 this->addList(list, colour);
125 resizeWindow();
126}
void addList(DiagramList *list)
Color getRandomColor()
Returns a random RGB colour.
Definition Color.cpp:18
std::array< unsigned char, 4 > Color
Definition Color.h:12

References addList(), DataHolderLib::getRandomColor(), and resizeWindow().

Referenced by addList().

◆ addList() [2/2]

void DetailWindow::addList ( DiagramList * list,
QColor c )

Adds another plot with a given colour to window. Axes are automatically resized.

Definition at line 128 of file DetailWindow.cpp.

129{
130 list->setColor(c);
131 this->stationView->addGraph(list);
132}
void setColor(QColor c)
Sets the colour of the graph.
Definition DiagramList.h:92

References DiagramList::setColor().

◆ on_addDataButton_clicked

void DetailWindow::on_addDataButton_clicked ( )
privateslot

Definition at line 134 of file DetailWindow.cpp.

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}

◆ on_closeButton_clicked

void DetailWindow::on_closeButton_clicked ( )
privateslot

Definition at line 107 of file DetailWindow.cpp.

108{
109 this->close();
110}

◆ resizeWindow()

void DetailWindow::resizeWindow ( )
private

Automatically resize window based on the measurements of the included graphs.

Definition at line 112 of file DetailWindow.cpp.

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}

Referenced by DetailWindow(), DetailWindow(), DetailWindow(), and addList().


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