DLS  1.6
Layer.h
1 /*****************************************************************************
2  *
3  * Copyright (C) 2009 - 2017 Florian Pose <fp@igh-essen.com>
4  *
5  * This file is part of the DLS widget library.
6  *
7  * The DLS widget library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of the License,
10  * or (at your option) any later version.
11  *
12  * The DLS widget library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the DLS widget library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  ****************************************************************************/
22 
23 #ifndef DLS_LAYER_H
24 #define DLS_LAYER_H
25 
26 #include "export.h"
27 
28 #include <QColor>
29 #include <QMutex>
30 #include <QDomElement>
31 #include <QDir>
32 #include <QCoreApplication> // Q_DECLARE_TR_FUNCTIONS()
33 
34 #include <set>
35 
36 namespace LibDLS {
37  class Channel;
38  class Data;
39  class Directory;
40  class Job;
41  class Time;
42 }
43 
44 namespace QtDls {
45  class Channel;
46  class Model;
47 }
48 
49 namespace DLS {
50 
51 class Section;
52 class GraphWorker;
53 
54 /****************************************************************************/
55 
58 class DLSWIDGETS_PUBLIC Layer
59 {
60  Q_DECLARE_TR_FUNCTIONS(Layer)
61 
62  public:
63  Layer(Section *);
64  Layer(const Layer &, Section *);
65  virtual ~Layer();
66 
67  void load(const QDomElement &, QtDls::Model *, const QDir &);
68  void save(QDomElement &, QDomDocument &) const;
69 
70  void connectChannel(QtDls::Model *, const QDir &);
71  bool dirInUse(const LibDLS::Directory *) const;
72 
73  void setChannel(QtDls::Channel *);
74  QtDls::Channel *getChannel() const { return channel; };
75 
76  const QString &getUrlString() const { return urlString; }
77 
78  void setName(const QString &);
79  const QString &getName() const { return name; }
80  void setUnit(const QString &);
81  const QString &getUnit() const { return unit; }
82  void setColor(QColor);
83  QColor getColor() const { return color; }
84  void setScale(double);
85  double getScale() const { return scale; }
86  void setOffset(double);
87  double getOffset() const { return offset; }
88  void setPrecision(int);
89  int getPrecision() const { return precision; }
90 
91  void loadData(const LibDLS::Time &, const LibDLS::Time &, int,
92  GraphWorker *, std::set<LibDLS::Job *> &);
93 
94  struct MeasureData {
95  const Layer *layer;
96  int x;
97  double minimum;
98  double maximum;
99  int minY;
100  int maxY;
101  int meanY;
102  unsigned int group;
103  int movedY;
104  bool found;
105 
106  bool operator<(const MeasureData &other) const {
107  return minimum < other.minimum;
108  }
109  };
110 
111  void draw(QPainter &, const QRect &, double, double, double,
112  MeasureData * = NULL);
113 
114  double getMinimum() const { return minimum; }
115  double getMaximum() const { return maximum; }
116  double getExtremaValid() const { return extremaValid; }
117 
118  QString title() const;
119  QString formatValue(double) const;
120 
121  class Exception {
122  public:
123  Exception(const QString &msg):
124  msg(msg) {}
125  QString msg;
126  };
127  private:
128  Section * const section;
129  QtDls::Channel *channel;
130  QString urlString;
131  QString name;
132  QString unit;
133  QColor color;
134  double scale;
135  double offset;
136  int precision;
137 
138  QMutex dataMutex;
139  QList<LibDLS::Data *> genericData;
140  QList<LibDLS::Data *> minimumData;
141  QList<LibDLS::Data *> maximumData;
142  double minimum;
143  double maximum;
144  bool extremaValid;
145 
146  void newData(LibDLS::Data *);
147  void clearDataList(QList<LibDLS::Data *> &);
148  void copyDataList(QList<LibDLS::Data *> &,
149  const QList<LibDLS::Data *> &);
150  void updateExtrema();
151  void updateExtremaList(const QList<LibDLS::Data *> &, bool *);
152  void drawGaps(QPainter &, const QRect &, double) const;
153 
154  Layer(); // private
155 };
156 
157 /****************************************************************************/
158 
159 } // namespace
160 
161 #endif
DLS Data Directory.
Definition: Dir.h:82
Definition: Graph.h:51
Graph section layer.
Definition: Layer.h:58
Block of data values.
Definition: Data.h:40
Working class hero.
Definition: Graph.h:65
Definition: Channel.h:44
Datentyp zur Speicherung der Zeit in Mikrosekunden.
Definition: Time.h:46
Definition: Graph.h:56
Graph section.
Definition: Section.h:61