NDEVR
API Documentation
BatteryWidget.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: BatteryWidget
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Battery.h>
35#include <NDEVR/Button.h>
36#include <NDEVR/Dictionary.h>
37#include <NDEVR/UUID.h>
38#include <QPointer>
39class QLabel;
40class QGridLayout;
41namespace NDEVR
42{
43 class ProgressWidget;
44 class Battery;
45 class QCustomLabel;
49 class HARDWARE_WIDGETS_API BatteryAlertWatcher : public QObject
50 {
51 Q_OBJECT
52 public:
57 void addSensors(const Buffer<Battery*>& sensors);
62 void removeSensors(const Buffer<Battery*>& sensors);
70 protected slots:
75 void stateChangeSlot(bool originator);
76 protected:
78 };
79
83 class HARDWARE_WIDGETS_API BatteryWidget : public Button
84 {
85 Q_OBJECT
86 public:
91 explicit BatteryWidget(QWidget* parent = nullptr);
96 void setSensors(const Buffer<Battery*>& sensors);
101 void setSensor(Battery* sensor);
107 void addSensor(Battery* sensor, bool update = true);
113 void removeSensor(Battery* sensor, bool update = true);
118 void clearSensors(bool update = true);
123 void setColumnCount(uint04 column_count);
131 bool event(QEvent* event) override;
132 private:
134 void updateUI();
135 protected slots:
138 protected:
146 [[nodiscard]] RGBColor getColor(uint04 state) const;
147 protected:
151 QGridLayout* m_layout;
153 };
154}
Listens for changes to a Battery and reports an error to the user when thresholds are crossed.
void removeSensors(const Buffer< Battery * > &sensors)
Removes battery sensors from monitoring.
void addSensors(const Buffer< Battery * > &sensors)
Adds battery sensors to be monitored for threshold alerts.
Dictionary< UUID, QPointer< Battery > > m_sensors
Map of monitored battery sensors keyed by UUID.
void stateChangeSlot(bool originator)
Slot called when a battery state changes.
static BatteryAlertWatcher & Default()
Returns the singleton default BatteryAlertWatcher instance.
void addLocalBatteries()
Adds all locally detected batteries to the watch list.
void updatedSlot()
Slot called when a battery state is updated.
void addLocalBatteries()
Adds all locally detected batteries to the display.
void addSensor(Battery *sensor, bool update=true)
Adds a battery sensor to the display.
uint04 m_column_count
Number of columns in the battery display grid.
Dictionary< UUID, Battery * > m_sensors
Map of battery sensors keyed by UUID.
RGBColor getColor(uint04 state) const
Returns the display color corresponding to a battery state.
Dictionary< UUID, ProgressWidget * > m_values
Map of progress widgets for each battery.
BatteryWidget(QWidget *parent=nullptr)
Constructs a BatteryWidget.
void updateLayout()
Rebuilds the grid layout based on current sensors.
void removeSensor(Battery *sensor, bool update=true)
Removes a battery sensor from the display.
void setSensor(Battery *sensor)
Sets a single battery sensor, replacing any existing ones.
QGridLayout * m_layout
Grid layout for arranging battery displays.
bool event(QEvent *event) override
Handles Qt events such as tooltip display.
QWidget * m_battery_widget
Container widget for battery progress indicators.
void setColumnCount(uint04 column_count)
Sets the number of columns used in the battery display grid.
void setSensors(const Buffer< Battery * > &sensors)
Replaces all current sensors with the provided set.
void clearSensors(bool update=true)
Removes all battery sensors from the display.
A device which has an associated voltage or percent that changes.
Definition Battery.h:106
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Button(QWidget *parent=nullptr)
Constructs a Button with an optional parent widget.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Displays the progress, either horizontally as a bar or as a round spin dial.
Displays translated text.
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...