OGS
DetailWindow Class Reference

Detailed Description

Creates a window containing a diagram.

Definition at line 24 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 23 of file DetailWindow.cpp.

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

◆ 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 69 of file DetailWindow.cpp.

69 : 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}
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 85 of file DetailWindow.cpp.

85 : QWidget(parent)
86{
87 setupUi(this);
88 stationView->setRenderHints(QPainter::Antialiasing);
89 stationView->addGraph(list);
91}

References resizeWindow().

◆ DetailWindow() [4/4]

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

Definition at line 93 of file DetailWindow.cpp.

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}
A List of data points and all the necessary meta-information to draw a graph.
Definition DiagramList.h:29

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 131 of file DetailWindow.cpp.

132{
134 QColor colour(c[0], c[1], c[2]);
135 this->addList(list, colour);
136 resizeWindow();
137}
void addList(DiagramList *list)
Color getRandomColor()
Returns a random RGB colour.
Definition Color.cpp:29
std::array< unsigned char, 4 > Color
Definition Color.h:24

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

Referenced by DiagramPrefsDialog::accept(), and 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 139 of file DetailWindow.cpp.

140{
141 list->setColor(c);
142 this->stationView->addGraph(list);
143}
void setColor(QColor c)
Sets the colour of the graph.

References DiagramList::setColor().

◆ on_addDataButton_clicked

void DetailWindow::on_addDataButton_clicked ( )
privateslot

Definition at line 145 of file DetailWindow.cpp.

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}
A dialog that allows for setting preferences for a requested diagram.

◆ on_closeButton_clicked

void DetailWindow::on_closeButton_clicked ( )
privateslot

Definition at line 118 of file DetailWindow.cpp.

119{
120 this->close();
121}

◆ resizeWindow()

void DetailWindow::resizeWindow ( )
private

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

Definition at line 123 of file DetailWindow.cpp.

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}

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


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