OGS
DiagramList Class Reference

Detailed Description

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

Definition at line 28 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 27 of file DiagramList.cpp.

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

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 109 of file DiagramList.h.

109{ _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 43 of file DiagramList.cpp.

44{
45 float max = std::numeric_limits<float>::lowest();
46 std::size_t nCoords = _coords.size();
47 for (std::size_t i = 0; i < nCoords; i++)
48 {
49 if (_coords[i].first > max)
50 {
51 max = _coords[i].first;
52 }
53 }
54 return max;
55}

References _coords.

Referenced by update().

◆ calcMaxYValue()

float DiagramList::calcMaxYValue ( )
private

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

Definition at line 71 of file DiagramList.cpp.

72{
73 float max = std::numeric_limits<float>::lowest();
74 std::size_t nCoords = _coords.size();
75 for (std::size_t i = 0; i < nCoords; i++)
76 {
77 if (_coords[i].second > max)
78 {
79 max = _coords[i].second;
80 }
81 }
82 return max;
83}

References _coords.

Referenced by update().

◆ calcMinXValue()

float DiagramList::calcMinXValue ( )
private

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

Definition at line 31 of file DiagramList.cpp.

32{
33 auto min = std::min_element(_coords.begin(), _coords.end(),
34 [](auto const& c0, auto const& c1)
35 { return c0.first < c1.first; });
36 if (min != _coords.end())
37 {
38 return min->first;
39 }
40 return std::numeric_limits<float>::max();
41}

References _coords.

Referenced by update().

◆ calcMinYValue()

float DiagramList::calcMinYValue ( )
private

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

Definition at line 57 of file DiagramList.cpp.

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

References _coords.

Referenced by update().

◆ getColor()

QColor DiagramList::getColor ( ) const
inline

Returns the colour of the graph.

Definition at line 36 of file DiagramList.h.

36{ 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 57 of file DiagramList.h.

57{ 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 85 of file DiagramList.cpp.

86{
87 QPointF p;
88 if (getPoint(p, 0))
89 {
90 QPainterPath pp(QPointF(p.x() * scaleX, p.y() * scaleY));
91 path = pp;
92
93 std::size_t nCoords = _coords.size();
94 for (std::size_t i = 1; i < nCoords; i++)
95 {
96 getPoint(p, i);
97 path.lineTo(QPointF(p.x() * scaleX, p.y() * scaleY));
98 }
99 return true;
100 }
101
102 return false;
103}
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 105 of file DiagramList.cpp.

106{
107 if (i < _coords.size())
108 {
109 p.setX(_coords[i].first);
110 p.setY(_coords[i].second);
111 return true;
112 }
113
114 return false;
115}

References _coords.

Referenced by getPath().

◆ getStartDate()

const QDateTime DiagramList::getStartDate ( ) const
inline

Returns the start date of this list.

Definition at line 54 of file DiagramList.h.

54{ 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 78 of file DiagramList.h.

78{ 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 84 of file DiagramList.h.

84{ 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 81 of file DiagramList.h.

81{ 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 87 of file DiagramList.h.

87{ 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 39 of file DiagramList.h.

39{ return _maxY - _minY; }

References _maxY, and _minY.

◆ maxXValue()

float DiagramList::maxXValue ( ) const
inline

Returns the maximum x-value.

Definition at line 45 of file DiagramList.h.

45{ return _maxX; }

References _maxX.

Referenced by DiagramScene::setDiagramBoundaries().

◆ maxYValue()

float DiagramList::maxYValue ( ) const
inline

Returns the maximum y-value.

Definition at line 51 of file DiagramList.h.

51{ return _maxY; }

References _maxY.

Referenced by DiagramScene::setDiagramBoundaries().

◆ minXValue()

float DiagramList::minXValue ( ) const
inline

Returns the minimum x-value.

Definition at line 42 of file DiagramList.h.

42{ return _minX; }

References _minX.

Referenced by DiagramScene::setDiagramBoundaries().

◆ minYValue()

float DiagramList::minYValue ( ) const
inline

Returns the minimum y-value.

Definition at line 48 of file DiagramList.h.

48{ 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 157 of file DiagramList.cpp.

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

250{
251 std::vector<SensorDataType> const& time_series_names(
252 data->getTimeSeriesNames());
253 int nLists(time_series_names.size());
254
255 std::vector<std::size_t> time_steps;
256 if (data->getStepSize() > 0)
257 {
258 const std::size_t start = data->getStartTime();
259 const std::size_t end = data->getEndTime();
260 const std::size_t stepsize = data->getStepSize();
261 for (std::size_t i = start; i <= end; i += stepsize)
262 {
263 time_steps.push_back(i);
264 }
265 }
266 else
267 {
268 time_steps = data->getTimeSteps();
269 }
270
271 bool is_date(false);
272
273 if (!(BaseLib::int2date(time_steps[0])).empty())
274 {
275 is_date = true;
276 }
277
278 std::size_t nValues(time_steps.size());
279
280 for (int i = 0; i < nLists; i++)
281 {
282 auto const* time_series = data->getTimeSeries(time_series_names[i]);
283 if (!time_series)
284 {
285 continue;
286 }
287
288 auto* l = new DiagramList;
289 l->setName(QString::fromStdString(
290 SensorData::convertSensorDataType2String(time_series_names[i])));
291 l->setXLabel("Time");
292 lists.push_back(l);
293
294 if (is_date)
295 {
296 l->setXUnit("day");
297 QDateTime const startDate(
298 getDateTime(BaseLib::int2date(time_steps[0])));
299 lists[i]->setStartDate(startDate);
300 for (std::size_t j = 0; j < nValues; j++)
301 {
302 QDateTime const currentDate(
303 getDateTime(BaseLib::int2date(time_steps[j])));
304 auto numberOfSecs =
305 static_cast<float>(startDate.secsTo(currentDate));
306 lists[i]->addNextPoint(numberOfSecs, (*time_series)[j]);
307 }
308 }
309 else
310 {
311 l->setXUnit("time step");
312 for (std::size_t j = 0; j < nValues; j++)
313 {
314 lists[i]->addNextPoint(static_cast<float>(time_steps[j]),
315 (*time_series)[j]);
316 }
317 }
318
319 lists[i]->update();
320 }
321
322 return nLists;
323}
std::size_t getEndTime() const
Returns the last time step.
Definition SensorData.h:104
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:98
std::size_t getStartTime() const
Returns the first time step.
Definition SensorData.h:101
const std::vector< SensorDataType > & getTimeSeriesNames() const
Returns all time series names contained in this container.
Definition SensorData.h:92
std::size_t getStepSize() const
Definition SensorData.h:108
static std::string convertSensorDataType2String(SensorDataType t)
Converts Sensor Data Types to Strings.
std::string int2date(int date)
Definition DateTools.cpp:42

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 103 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 376 of file DiagramList.cpp.

377{
378 if (coords.empty())
379 {
380 return;
381 }
382
383 this->_startDate = QDateTime();
384 std::copy(coords.begin(), coords.end(), std::back_inserter(_coords));
385 update();
386}
void update()
Updates the bounds of the data points contained in the list.
constexpr ranges::views::view_closure coords
Definition Mesh.h:232

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 356 of file DiagramList.cpp.

358{
359 if (coords.empty())
360 {
361 return;
362 }
363
364 _startDate = coords[0].first;
365 std::transform(coords.begin(), coords.end(), std::back_inserter(_coords),
366 [this](auto const& p)
367 {
368 return std::make_pair(
369 static_cast<float>(_startDate.daysTo(p.first)),
370 p.second);
371 });
372
373 update();
374}

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 106 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 115 of file DiagramList.h.

115{ _startDate = date; }

References _startDate.

◆ setXLabel()

void DiagramList::setXLabel ( QString label)
inline

Specifies the meaning of the x Axis.

Definition at line 118 of file DiagramList.h.

118{ _xLabel = label; }

References _xLabel.

◆ setXUnit()

void DiagramList::setXUnit ( QString unit)
inline

Specifies the unit of the x Axis.

Definition at line 138 of file DiagramList.h.

138{ _xUnit = unit; }

References _xUnit.

◆ setYLabel()

void DiagramList::setYLabel ( QString label)
inline

Specifies the meaning of the y Axis.

Definition at line 121 of file DiagramList.h.

121{ _yLabel = label; }

References _yLabel.

◆ setYUnit()

void DiagramList::setYUnit ( QString unit)
inline

Specifies the unit of the y Axis.

Definition at line 141 of file DiagramList.h.

141{ _yUnit = unit; }

References _yUnit.

◆ size()

std::size_t DiagramList::size ( ) const

Returns the number of data points.

Definition at line 388 of file DiagramList.cpp.

389{
390 return _coords.size();
391}

References _coords.

◆ truncateToRange()

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

cut list entries not within the given range

Definition at line 325 of file DiagramList.cpp.

326{
327 auto start_secs = static_cast<float>(_startDate.secsTo(start));
328 if (start_secs < 0)
329 {
330 start_secs = 0;
331 }
332 auto end_secs = static_cast<float>(_startDate.secsTo(end));
333 if (end_secs < start_secs)
334 {
335 end_secs = _coords.back().first;
336 }
337
338 if (start_secs == 0 && end_secs == _coords.back().first)
339 {
340 return;
341 }
342
343 _coords.erase(std::remove_if(
344 _coords.begin(), _coords.end(),
345 [&](std::pair<float, float> const& c)
346 { return (c.first < start_secs || c.first > end_secs); }),
347 _coords.end());
348 _startDate = start;
349 for (auto& c : _coords)
350 {
351 c.first -= start_secs;
352 }
353 update();
354}

References _coords, _startDate, and update().

◆ update()

void DiagramList::update ( )
private

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

Definition at line 393 of file DiagramList.cpp.

394{
399}
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 147 of file DiagramList.h.

147{ return _maxX - _minX; }

References _maxX, and _minX.

Member Data Documentation

◆ _colour

QColor DiagramList::_colour
private

Definition at line 184 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 174 of file DiagramList.h.

174{0};

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

◆ _maxY

float DiagramList::_maxY {0}
private

Definition at line 175 of file DiagramList.h.

175{0};

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

◆ _minX

float DiagramList::_minX {0}
private

Definition at line 176 of file DiagramList.h.

176{0};

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

◆ _minY

float DiagramList::_minY {0}
private

Definition at line 177 of file DiagramList.h.

177{0};

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

◆ _name

QString DiagramList::_name
private

Definition at line 179 of file DiagramList.h.

Referenced by getName(), and setName().

◆ _startDate

QDateTime DiagramList::_startDate
private

Definition at line 185 of file DiagramList.h.

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

◆ _xLabel

QString DiagramList::_xLabel
private

Definition at line 180 of file DiagramList.h.

Referenced by getXLabel(), and setXLabel().

◆ _xUnit

QString DiagramList::_xUnit
private

Definition at line 182 of file DiagramList.h.

Referenced by getXUnit(), and setXUnit().

◆ _yLabel

QString DiagramList::_yLabel
private

Definition at line 181 of file DiagramList.h.

Referenced by getYLabel(), and setYLabel().

◆ _yUnit

QString DiagramList::_yUnit
private

Definition at line 183 of file DiagramList.h.

Referenced by getYUnit(), and setYUnit().


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