OGS
DiagramList Class Reference

Detailed Description

A List of data points and all the necessary meta-information to draw a graph.

Definition at line 17 of file DiagramList.h.

#include <DiagramList.h>

Public Member Functions

 DiagramList ()
 Constructor containing an empty list.
 ~DiagramList ()
QColor getColor () const
 Returns the colour of the graph.
float height () const
 Returns the height of the bounding box of all data points within the list.
float minXValue () const
 Returns the minimum x-value.
float maxXValue () const
 Returns the maximum x-value.
float minYValue () const
 Returns the minimum y-value.
float maxYValue () const
 Returns the maximum y-value.
const QDateTime getStartDate () const
 Returns the start date of this list.
QString getName () const
 Returns the name of the diagram.
bool getPath (QPainterPath &path, float scaleX, float scaleY)
bool getPoint (QPointF &p, std::size_t i)
QString getXLabel () const
 Returns the label associated with the x-axis.
QString getYLabel () const
 Returns the label associated with the y-axis.
QString getXUnit () const
 Returns the unit associated with the x-axis.
QString getYUnit () const
 Returns the unit associated with the y-axis.
void setColor (QColor c)
 Sets the colour of the graph.
void setName (QString name)
 Sets the name of the graph to be displayed in the caption.
void addNextPoint (float x, float y)
 Adds a point at (x,y) to the list.
void truncateToRange (QDateTime const &start, QDateTime const &end)
 cut list entries not within the given range
void setStartDate (QDateTime date)
 Sets the start date (i.e. the min-value of the x-axis).
void setXLabel (QString label)
 Specifies the meaning of the x Axis.
void setYLabel (QString label)
 Specifies the meaning of the y Axis.
void setList (std::vector< std::pair< float, float > > const &coords)
void setList (std::vector< std::pair< QDateTime, float > > const &coords)
void setXUnit (QString unit)
 Specifies the unit of the x Axis.
void setYUnit (QString unit)
 Specifies the unit of the y Axis.
std::size_t size () const
 Returns the number of data points.
double width () const
 Returns the width of the bounding box of all data points within the list.

Static Public Member Functions

static int readList (const QString &path, std::vector< DiagramList * > &list)
static int readList (const SensorData *data, std::vector< DiagramList * > &list)

Private Member Functions

float calcMinXValue ()
 Returns the minimum x-value of all the data points.
float calcMaxXValue ()
 Returns the maximum x-value of all the data points.
float calcMinYValue ()
 Returns the minimum y-value of all the data points.
float calcMaxYValue ()
 Returns the maximum y-value of all the data points.
int readLine (std::ifstream inFile, QDateTime &cDate, float &cValue)
void update ()
 Updates the bounds of the data points contained in the list.

Private Attributes

float _maxX {0}
float _maxY {0}
float _minX {0}
float _minY {0}
std::vector< std::pair< float, float > > _coords
QString _name
QString _xLabel
QString _yLabel
QString _xUnit
QString _yUnit
QColor _colour
QDateTime _startDate

Constructor & Destructor Documentation

◆ DiagramList()

DiagramList::DiagramList ( )

Constructor containing an empty list.

Definition at line 16 of file DiagramList.cpp.

16: _xLabel(""), _yLabel(""), _xUnit(""), _yUnit("") {}
QString _yLabel
QString _yUnit
QString _xLabel
QString _xUnit

References _xLabel, _xUnit, _yLabel, and _yUnit.

Referenced by readList(), and readList().

◆ ~DiagramList()

DiagramList::~DiagramList ( )
default

Member Function Documentation

◆ addNextPoint()

void DiagramList::addNextPoint ( float x,
float y )
inline

Adds a point at (x,y) to the list.

Definition at line 98 of file DiagramList.h.

98{ _coords.emplace_back(x, y); }
std::vector< std::pair< float, float > > _coords

References _coords.

◆ calcMaxXValue()

float DiagramList::calcMaxXValue ( )
private

Returns the maximum x-value of all the data points.

Definition at line 32 of file DiagramList.cpp.

33{
34 float max = std::numeric_limits<float>::lowest();
35 std::size_t nCoords = _coords.size();
36 for (std::size_t i = 0; i < nCoords; i++)
37 {
38 if (_coords[i].first > max)
39 {
40 max = _coords[i].first;
41 }
42 }
43 return max;
44}

References _coords.

Referenced by update().

◆ calcMaxYValue()

float DiagramList::calcMaxYValue ( )
private

Returns the maximum y-value of all the data points.

Definition at line 60 of file DiagramList.cpp.

61{
62 float max = std::numeric_limits<float>::lowest();
63 std::size_t nCoords = _coords.size();
64 for (std::size_t i = 0; i < nCoords; i++)
65 {
66 if (_coords[i].second > max)
67 {
68 max = _coords[i].second;
69 }
70 }
71 return max;
72}

References _coords.

Referenced by update().

◆ calcMinXValue()

float DiagramList::calcMinXValue ( )
private

Returns the minimum x-value of all the data points.

Definition at line 20 of file DiagramList.cpp.

21{
22 auto min = std::min_element(_coords.begin(), _coords.end(),
23 [](auto const& c0, auto const& c1)
24 { return c0.first < c1.first; });
25 if (min != _coords.end())
26 {
27 return min->first;
28 }
29 return std::numeric_limits<float>::max();
30}

References _coords.

Referenced by update().

◆ calcMinYValue()

float DiagramList::calcMinYValue ( )
private

Returns the minimum y-value of all the data points.

Definition at line 46 of file DiagramList.cpp.

47{
48 float min = std::numeric_limits<float>::max();
49 std::size_t nCoords = _coords.size();
50 for (std::size_t i = 0; i < nCoords; i++)
51 {
52 if (_coords[i].second < min)
53 {
54 min = _coords[i].second;
55 }
56 }
57 return min;
58}

References _coords.

Referenced by update().

◆ getColor()

QColor DiagramList::getColor ( ) const
inline

Returns the colour of the graph.

Definition at line 25 of file DiagramList.h.

25{ return _colour; }
QColor _colour

References _colour.

Referenced by DiagramScene::drawGraph().

◆ getName()

QString DiagramList::getName ( ) const
inline

Returns the name of the diagram.

Definition at line 46 of file DiagramList.h.

46{ return _name; }
QString _name

References _name.

Referenced by DiagramScene::drawGraph().

◆ getPath()

bool DiagramList::getPath ( QPainterPath & path,
float scaleX,
float scaleY )

Returns all the data points in form of a QPainterPath in scene coordinates. The order of the points is the same as in the vector of coordinates.

Parameters
pathThe path containing all data points.
scaleXScaling factor in x-direction.
scaleYScaling factor in y-direction.
Returns
true if everything is alright. false if the size of the coordinate arrays don't match.

Definition at line 74 of file DiagramList.cpp.

75{
76 QPointF p;
77 if (getPoint(p, 0))
78 {
79 QPainterPath pp(QPointF(p.x() * scaleX, p.y() * scaleY));
80 path = pp;
81
82 std::size_t nCoords = _coords.size();
83 for (std::size_t i = 1; i < nCoords; i++)
84 {
85 getPoint(p, i);
86 path.lineTo(QPointF(p.x() * scaleX, p.y() * scaleY));
87 }
88 return true;
89 }
90
91 return false;
92}
bool getPoint(QPointF &p, std::size_t i)

References _coords, and getPoint().

Referenced by DiagramScene::drawGraph().

◆ getPoint()

bool DiagramList::getPoint ( QPointF & p,
std::size_t i )

Returns the position of one point in the vector of coordinates.

Parameters
pThe point-object that will be returned.
iNumber of the point to be returned.
Returns
true if everything is alright. false if the point does not exist.

Definition at line 94 of file DiagramList.cpp.

95{
96 if (i < _coords.size())
97 {
98 p.setX(_coords[i].first);
99 p.setY(_coords[i].second);
100 return true;
101 }
102
103 return false;
104}

References _coords.

Referenced by getPath().

◆ getStartDate()

const QDateTime DiagramList::getStartDate ( ) const
inline

Returns the start date of this list.

Definition at line 43 of file DiagramList.h.

43{ return _startDate; }
QDateTime _startDate

References _startDate.

Referenced by DiagramScene::setDiagramBoundaries().

◆ getXLabel()

QString DiagramList::getXLabel ( ) const
inline

Returns the label associated with the x-axis.

Definition at line 67 of file DiagramList.h.

67{ return _xLabel; }

References _xLabel.

Referenced by DiagramScene::addGraph().

◆ getXUnit()

QString DiagramList::getXUnit ( ) const
inline

Returns the unit associated with the x-axis.

Definition at line 73 of file DiagramList.h.

73{ return _xUnit; }

References _xUnit.

Referenced by DiagramScene::addGraph().

◆ getYLabel()

QString DiagramList::getYLabel ( ) const
inline

Returns the label associated with the y-axis.

Definition at line 70 of file DiagramList.h.

70{ return _yLabel; }

References _yLabel.

Referenced by DiagramScene::addGraph().

◆ getYUnit()

QString DiagramList::getYUnit ( ) const
inline

Returns the unit associated with the y-axis.

Definition at line 76 of file DiagramList.h.

76{ return _yUnit; }

References _yUnit.

Referenced by DiagramScene::addGraph().

◆ height()

float DiagramList::height ( ) const
inline

Returns the height of the bounding box of all data points within the list.

Definition at line 28 of file DiagramList.h.

28{ return _maxY - _minY; }

References _maxY, and _minY.

◆ maxXValue()

float DiagramList::maxXValue ( ) const
inline

Returns the maximum x-value.

Definition at line 34 of file DiagramList.h.

34{ return _maxX; }

References _maxX.

Referenced by DiagramScene::setDiagramBoundaries().

◆ maxYValue()

float DiagramList::maxYValue ( ) const
inline

Returns the maximum y-value.

Definition at line 40 of file DiagramList.h.

40{ return _maxY; }

References _maxY.

Referenced by DiagramScene::setDiagramBoundaries().

◆ minXValue()

float DiagramList::minXValue ( ) const
inline

Returns the minimum x-value.

Definition at line 31 of file DiagramList.h.

31{ return _minX; }

References _minX.

Referenced by DiagramScene::setDiagramBoundaries().

◆ minYValue()

float DiagramList::minYValue ( ) const
inline

Returns the minimum y-value.

Definition at line 37 of file DiagramList.h.

37{ return _minY; }

References _minY.

Referenced by DiagramScene::drawGraph(), and DiagramScene::setDiagramBoundaries().

◆ readLine()

int DiagramList::readLine ( std::ifstream inFile,
QDateTime & cDate,
float & cValue )
private

Reads an ASCII file containing the coordinates in the following format: date (tab) value where 'date' is given as 'dd.mm.yyyy'. (Changes to that format are easily implemented using QTimeDate)

Returns
Returns 1 if everything is alright. Returns 0 and displays an error message if there was an error.

◆ readList() [1/2]

int DiagramList::readList ( const QString & path,
std::vector< DiagramList * > & list )
static

Reads information from a file. The reader assumes that values in the file are separated by tabstops. Also, the first row should contain identifiers for the values and the first column should contain timestamps. Currently accepted timestamps are of the following formats: "dd.mm.yyyy" "dd.mm.yyyy.hh.mm.ss" (this is the timestamp format used for the UFZ database) For each column after the timestamps a new diagram list is created.

Definition at line 146 of file DiagramList.cpp.

147{
148 QFile file(path);
149 QTextStream in(&file);
150
151 if (!file.open(QIODevice::ReadOnly))
152 {
153 qDebug("Could not open file...");
154 return 0;
155 }
156
157 QString line = in.readLine();
158 QStringList fields = line.split('\t');
159 int nLists(fields.size() - 1);
160
161 if (fields.size() >= 2)
162 {
163 fields.takeFirst();
164 for (int i = 0; i < nLists; i++)
165 {
166 auto* l = new DiagramList;
167 l->setName(fields.takeFirst());
168 // value = strtod(BaseLib::replaceStringreplaceString(",", ".",
169 // fields.takeFirst().toStdString()).c_str(),0);
170 // l->setStartDate(startDate);
171 // l->addNextPoint(0,value);
172 lists.push_back(l);
173 }
174
175 bool first_loop(true);
176 QDateTime startDate;
177 QDateTime currentDate;
178 unsigned line_count(1);
179
180 while (!in.atEnd())
181 {
182 line = in.readLine();
183 line_count++;
184 fields = line.split('\t');
185 if (fields.size() >= (nLists + 1))
186 {
187 QString const stringDate = fields.takeFirst();
188 currentDate = getDateTime(stringDate);
189 if (first_loop)
190 {
191 startDate = currentDate;
192 for (int i = 0; i < nLists; i++)
193 {
194 lists[i]->setStartDate(startDate);
195 }
196 first_loop = false;
197 }
198
199 auto const numberOfSecs =
200 static_cast<float>(startDate.secsTo(currentDate));
201 for (int i = 0; i < nLists; i++)
202 {
203 float const value = static_cast<float>(
205 ",", ".", fields.takeFirst().toStdString())
206 .c_str(),
207 nullptr));
208 lists[i]->addNextPoint(numberOfSecs, value);
209 }
210 }
211 else
212 {
213 WARN("DiagramList::readList(): Unexpected format in line {:d}.",
214 line_count);
215 file.close();
216 return 0;
217 }
218 }
219 }
220 else
221 {
222 qDebug("Unexpected file format...");
223 file.close();
224 return 0;
225 }
226
227 file.close();
228
229 for (int i = 0; i < nLists; i++)
230 {
231 lists[i]->update();
232 }
233
234 return nLists;
235}
QDateTime getDateTime(QString const &stringDate)
Converts string into QDateTime-format.
Definition GetDateTime.h:11
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
DiagramList()
Constructor containing an empty list.
std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace)

References DiagramList(), getDateTime(), BaseLib::replaceString(), and WARN().

Referenced by DetailWindow::DetailWindow(), DiagramPrefsDialog::DiagramPrefsDialog(), and DiagramPrefsDialog::loadFile().

◆ readList() [2/2]

int DiagramList::readList ( const SensorData * data,
std::vector< DiagramList * > & list )
static

Definition at line 237 of file DiagramList.cpp.

239{
240 std::vector<SensorDataType> const& time_series_names(
241 data->getTimeSeriesNames());
242 int nLists(time_series_names.size());
243
244 std::vector<std::size_t> time_steps;
245 if (data->getStepSize() > 0)
246 {
247 const std::size_t start = data->getStartTime();
248 const std::size_t end = data->getEndTime();
249 const std::size_t stepsize = data->getStepSize();
250 for (std::size_t i = start; i <= end; i += stepsize)
251 {
252 time_steps.push_back(i);
253 }
254 }
255 else
256 {
257 time_steps = data->getTimeSteps();
258 }
259
260 bool is_date(false);
261
262 if (!(BaseLib::int2date(time_steps[0])).empty())
263 {
264 is_date = true;
265 }
266
267 std::size_t nValues(time_steps.size());
268
269 for (int i = 0; i < nLists; i++)
270 {
271 auto const* time_series = data->getTimeSeries(time_series_names[i]);
272 if (!time_series)
273 {
274 continue;
275 }
276
277 auto* l = new DiagramList;
278 l->setName(QString::fromStdString(
279 SensorData::convertSensorDataType2String(time_series_names[i])));
280 l->setXLabel("Time");
281 lists.push_back(l);
282
283 if (is_date)
284 {
285 l->setXUnit("day");
286 QDateTime const startDate(
287 getDateTime(BaseLib::int2date(time_steps[0])));
288 lists[i]->setStartDate(startDate);
289 for (std::size_t j = 0; j < nValues; j++)
290 {
291 QDateTime const currentDate(
292 getDateTime(BaseLib::int2date(time_steps[j])));
293 auto numberOfSecs =
294 static_cast<float>(startDate.secsTo(currentDate));
295 lists[i]->addNextPoint(numberOfSecs, (*time_series)[j]);
296 }
297 }
298 else
299 {
300 l->setXUnit("time step");
301 for (std::size_t j = 0; j < nValues; j++)
302 {
303 lists[i]->addNextPoint(static_cast<float>(time_steps[j]),
304 (*time_series)[j]);
305 }
306 }
307
308 lists[i]->update();
309 }
310
311 return nLists;
312}
std::size_t getEndTime() const
Returns the last time step.
Definition SensorData.h:93
const std::vector< float > * getTimeSeries(SensorDataType time_series_name) const
Returns the time series with the given name.
const std::vector< std::size_t > & getTimeSteps() const
Returns the time step vector (if it exists)
Definition SensorData.h:87
std::size_t getStartTime() const
Returns the first time step.
Definition SensorData.h:90
const std::vector< SensorDataType > & getTimeSeriesNames() const
Returns all time series names contained in this container.
Definition SensorData.h:81
std::size_t getStepSize() const
Definition SensorData.h:97
static std::string convertSensorDataType2String(SensorDataType t)
Converts Sensor Data Types to Strings.
std::string int2date(int date)
Definition DateTools.cpp:31

References DiagramList(), SensorData::convertSensorDataType2String(), getDateTime(), SensorData::getEndTime(), SensorData::getStartTime(), SensorData::getStepSize(), SensorData::getTimeSeries(), SensorData::getTimeSeriesNames(), SensorData::getTimeSteps(), and BaseLib::int2date().

◆ setColor()

void DiagramList::setColor ( QColor c)
inline

Sets the colour of the graph.

Definition at line 92 of file DiagramList.h.

References _colour.

Referenced by DetailWindow::addList().

◆ setList() [1/2]

void DiagramList::setList ( std::vector< std::pair< float, float > > const & coords)

Sets the list of x/y-coordinates.

Parameters
coordsList of coordinates.

Definition at line 365 of file DiagramList.cpp.

366{
367 if (coords.empty())
368 {
369 return;
370 }
371
372 this->_startDate = QDateTime();
373 std::copy(coords.begin(), coords.end(), std::back_inserter(_coords));
374 update();
375}
void update()
Updates the bounds of the data points contained in the list.
constexpr ranges::views::view_closure coords
Definition Mesh.h:223

References _coords, _startDate, and update().

◆ setList() [2/2]

void DiagramList::setList ( std::vector< std::pair< QDateTime, float > > const & coords)

Sets the list of x/y-coordinates. Note: This function converts QDateTime values to float values of the number of days from the first date (which is set as day 0)

Parameters
coordsList of coordinates.

Definition at line 345 of file DiagramList.cpp.

347{
348 if (coords.empty())
349 {
350 return;
351 }
352
353 _startDate = coords[0].first;
354 std::transform(coords.begin(), coords.end(), std::back_inserter(_coords),
355 [this](auto const& p)
356 {
357 return std::make_pair(
358 static_cast<float>(_startDate.daysTo(p.first)),
359 p.second);
360 });
361
362 update();
363}

References _coords, _startDate, and update().

◆ setName()

void DiagramList::setName ( QString name)
inline

Sets the name of the graph to be displayed in the caption.

Definition at line 95 of file DiagramList.h.

References _name.

Referenced by DiagramPrefsDialog::loadList().

◆ setStartDate()

void DiagramList::setStartDate ( QDateTime date)
inline

Sets the start date (i.e. the min-value of the x-axis).

Definition at line 104 of file DiagramList.h.

104{ _startDate = date; }

References _startDate.

◆ setXLabel()

void DiagramList::setXLabel ( QString label)
inline

Specifies the meaning of the x Axis.

Definition at line 107 of file DiagramList.h.

107{ _xLabel = label; }

References _xLabel.

◆ setXUnit()

void DiagramList::setXUnit ( QString unit)
inline

Specifies the unit of the x Axis.

Definition at line 127 of file DiagramList.h.

127{ _xUnit = unit; }

References _xUnit.

◆ setYLabel()

void DiagramList::setYLabel ( QString label)
inline

Specifies the meaning of the y Axis.

Definition at line 110 of file DiagramList.h.

110{ _yLabel = label; }

References _yLabel.

◆ setYUnit()

void DiagramList::setYUnit ( QString unit)
inline

Specifies the unit of the y Axis.

Definition at line 130 of file DiagramList.h.

130{ _yUnit = unit; }

References _yUnit.

◆ size()

std::size_t DiagramList::size ( ) const

Returns the number of data points.

Definition at line 377 of file DiagramList.cpp.

378{
379 return _coords.size();
380}

References _coords.

◆ truncateToRange()

void DiagramList::truncateToRange ( QDateTime const & start,
QDateTime const & end )

cut list entries not within the given range

Definition at line 314 of file DiagramList.cpp.

315{
316 auto start_secs = static_cast<float>(_startDate.secsTo(start));
317 if (start_secs < 0)
318 {
319 start_secs = 0;
320 }
321 auto end_secs = static_cast<float>(_startDate.secsTo(end));
322 if (end_secs < start_secs)
323 {
324 end_secs = _coords.back().first;
325 }
326
327 if (start_secs == 0 && end_secs == _coords.back().first)
328 {
329 return;
330 }
331
332 _coords.erase(std::remove_if(
333 _coords.begin(), _coords.end(),
334 [&](std::pair<float, float> const& c)
335 { return (c.first < start_secs || c.first > end_secs); }),
336 _coords.end());
337 _startDate = start;
338 for (auto& c : _coords)
339 {
340 c.first -= start_secs;
341 }
342 update();
343}

References _coords, _startDate, and update().

◆ update()

void DiagramList::update ( )
private

Updates the bounds of the data points contained in the list.

Definition at line 382 of file DiagramList.cpp.

383{
388}
float calcMinXValue()
Returns the minimum x-value of all the data points.
float calcMaxXValue()
Returns the maximum x-value of all the data points.
float calcMinYValue()
Returns the minimum y-value of all the data points.
float calcMaxYValue()
Returns the maximum y-value of all the data points.

References _maxX, _maxY, _minX, _minY, calcMaxXValue(), calcMaxYValue(), calcMinXValue(), and calcMinYValue().

Referenced by setList(), setList(), and truncateToRange().

◆ width()

double DiagramList::width ( ) const
inline

Returns the width of the bounding box of all data points within the list.

Definition at line 136 of file DiagramList.h.

136{ return _maxX - _minX; }

References _maxX, and _minX.

Member Data Documentation

◆ _colour

QColor DiagramList::_colour
private

Definition at line 173 of file DiagramList.h.

Referenced by getColor(), and setColor().

◆ _coords

std::vector< std::pair<float, float> > DiagramList::_coords
private

◆ _maxX

float DiagramList::_maxX {0}
private

Definition at line 163 of file DiagramList.h.

163{0};

Referenced by maxXValue(), update(), and width().

◆ _maxY

float DiagramList::_maxY {0}
private

Definition at line 164 of file DiagramList.h.

164{0};

Referenced by height(), maxYValue(), and update().

◆ _minX

float DiagramList::_minX {0}
private

Definition at line 165 of file DiagramList.h.

165{0};

Referenced by minXValue(), update(), and width().

◆ _minY

float DiagramList::_minY {0}
private

Definition at line 166 of file DiagramList.h.

166{0};

Referenced by height(), minYValue(), and update().

◆ _name

QString DiagramList::_name
private

Definition at line 168 of file DiagramList.h.

Referenced by getName(), and setName().

◆ _startDate

QDateTime DiagramList::_startDate
private

Definition at line 174 of file DiagramList.h.

Referenced by getStartDate(), setList(), setList(), setStartDate(), and truncateToRange().

◆ _xLabel

QString DiagramList::_xLabel
private

Definition at line 169 of file DiagramList.h.

Referenced by DiagramList(), getXLabel(), and setXLabel().

◆ _xUnit

QString DiagramList::_xUnit
private

Definition at line 171 of file DiagramList.h.

Referenced by DiagramList(), getXUnit(), and setXUnit().

◆ _yLabel

QString DiagramList::_yLabel
private

Definition at line 170 of file DiagramList.h.

Referenced by DiagramList(), getYLabel(), and setYLabel().

◆ _yUnit

QString DiagramList::_yUnit
private

Definition at line 172 of file DiagramList.h.

Referenced by DiagramList(), getYUnit(), and setYUnit().


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