QtIndustrialWidgets 2.3.0
Modern, High-Performance Industrial Instruments & SCADA Widgets for Qt
Loading...
Searching...
No Matches
LevelMeter.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Paolo Sereno <paolomsereno@gmail.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8
10#include <QtWidgets/QWidget>
11#include <QtGui/QColor>
12#include <QtCore/QVector>
13#include <QtCore/QStringList>
14#include <memory>
15
51namespace QtIndustrialWidgets {
52
53class LevelMeterPrivate;
54
56{
57 Q_OBJECT
58
59 Q_PROPERTY(int channelCount READ channelCount WRITE setChannelCount NOTIFY appearanceChanged)
60 Q_PROPERTY(double minimum READ minimum WRITE setMinimum NOTIFY rangeChanged)
61 Q_PROPERTY(double maximum READ maximum WRITE setMaximum NOTIFY rangeChanged)
62 Q_PROPERTY(double warningThreshold READ warningThreshold WRITE setWarningThreshold NOTIFY appearanceChanged)
63 Q_PROPERTY(double errorThreshold READ errorThreshold WRITE setErrorThreshold NOTIFY appearanceChanged)
64 Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY appearanceChanged)
65 Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode NOTIFY appearanceChanged)
66 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY appearanceChanged)
67 Q_PROPERTY(bool peakHoldEnabled READ isPeakHoldEnabled WRITE setPeakHoldEnabled NOTIFY appearanceChanged)
68 Q_PROPERTY(int peakHoldTimeMs READ peakHoldTimeMs WRITE setPeakHoldTimeMs NOTIFY appearanceChanged)
69 Q_PROPERTY(double peakDecayRate READ peakDecayRate WRITE setPeakDecayRate NOTIFY appearanceChanged)
70 Q_PROPERTY(bool scaleVisible READ isScaleVisible WRITE setScaleVisible NOTIFY appearanceChanged)
71 Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY appearanceChanged)
72 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY appearanceChanged)
73 Q_PROPERTY(QColor normalColor READ normalColor WRITE setNormalColor NOTIFY appearanceChanged)
74 Q_PROPERTY(QColor warningColor READ warningColor WRITE setWarningColor NOTIFY appearanceChanged)
75 Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor NOTIFY appearanceChanged)
76 Q_PROPERTY(QColor peakColor READ peakColor WRITE setPeakColor NOTIFY appearanceChanged)
77 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY appearanceChanged)
78 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY appearanceChanged)
79
80public:
82 enum class DisplayMode {
83 Segmented,
84 Continuous
85 };
86 Q_ENUM(DisplayMode)
87
88
92 explicit LevelMeter(QWidget *parent = nullptr);
93 ~LevelMeter() override;
94
96 [[nodiscard]] int channelCount() const;
98 [[nodiscard]] double minimum() const;
100 [[nodiscard]] double maximum() const;
102 [[nodiscard]] double warningThreshold() const;
104 [[nodiscard]] double errorThreshold() const;
106 [[nodiscard]] int segmentCount() const;
108 [[nodiscard]] DisplayMode displayMode() const;
110 [[nodiscard]] Qt::Orientation orientation() const;
112 [[nodiscard]] bool isPeakHoldEnabled() const;
114 [[nodiscard]] int peakHoldTimeMs() const;
116 [[nodiscard]] double peakDecayRate() const;
118 [[nodiscard]] bool isScaleVisible() const;
120 [[nodiscard]] QString unit() const;
122 [[nodiscard]] QString title() const;
123
125 [[nodiscard]] double value(int channel = 0) const;
127 [[nodiscard]] double peakValue(int channel = 0) const;
129 [[nodiscard]] QVector<double> values() const;
130
132 [[nodiscard]] QStringList channelLabels() const;
133
135 [[nodiscard]] QColor normalColor() const;
137 [[nodiscard]] QColor warningColor() const;
139 [[nodiscard]] QColor errorColor() const;
141 [[nodiscard]] QColor peakColor() const;
143 [[nodiscard]] QColor backgroundColor() const;
145 [[nodiscard]] QColor textColor() const;
146
147 [[nodiscard]] QSize sizeHint() const override;
148 [[nodiscard]] QSize minimumSizeHint() const override;
149
150public Q_SLOTS:
152 void setValue(double value);
154 void setValue(int channel, double value);
156 void setValues(const QVector<double> &values);
158 void resetPeaks();
159
161 void setChannelCount(int count);
163 void setRange(double min, double max);
165 void setMinimum(double min);
167 void setMaximum(double max);
169 void setWarningThreshold(double threshold);
171 void setErrorThreshold(double threshold);
173 void setSegmentCount(int count);
175 void setDisplayMode(DisplayMode mode);
177 void setOrientation(Qt::Orientation orientation);
179 void setPeakHoldEnabled(bool enabled);
181 void setPeakHoldTimeMs(int ms);
183 void setPeakDecayRate(double rate);
185 void setScaleVisible(bool visible);
187 void setUnit(const QString &unit);
189 void setTitle(const QString &title);
191 void setChannelLabels(const QStringList &labels);
193 void setNormalColor(const QColor &color);
195 void setWarningColor(const QColor &color);
197 void setErrorColor(const QColor &color);
199 void setPeakColor(const QColor &color);
201 void setBackgroundColor(const QColor &color);
203 void setTextColor(const QColor &color);
204
205Q_SIGNALS:
207 void valueChanged(int channel, double value);
209 void overloadOccurred(int channel);
211 void rangeChanged(double min, double max);
213 void appearanceChanged();
214
215protected:
216 void paintEvent(QPaintEvent *event) override;
217 void resizeEvent(QResizeEvent *event) override;
218 void changeEvent(QEvent *event) override;
219
220private Q_SLOTS:
221 void updatePeakDecay();
222
223private:
224 void renderStaticBackground();
225 void drawChannelBar(QPainter &painter, int chIndex, const QRectF &barRect);
226 void drawSegmentedBar(QPainter &painter, double val, double peakVal, const QRectF &barRect);
227 void drawContinuousBar(QPainter &painter, double val, double peakVal, const QRectF &barRect);
228 QColor colorForNormalizedValue(double norm) const;
229 QVector<QRectF> calculateBarRects(const QRectF &contentRect) const;
230
231 std::unique_ptr<LevelMeterPrivate> d_ptr;
232 Q_DECLARE_PRIVATE(LevelMeter)
233};
234
235} // namespace QtIndustrialWidgets
Definition LevelMeter.h:56
Definition AnalysisChart.h:21
Library export macros and version definitions for QtIndustrialWidgets.
#define QTINDUSTRIALWIDGETS_EXPORT
Export/import macro for shared library symbol visibility across dynamic linking boundaries.
Definition qtindustrialwidgets_global.h:25