-
Notifications
You must be signed in to change notification settings - Fork 3
/
base_dialog.h
146 lines (120 loc) · 4.12 KB
/
base_dialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* \file base_dialog.h
* \brief Base class for most screens
* \copyright
* 2021 Andrew Buettner (ABi)
*
* \section LICENSE
*
* QModbusTool - A QT Based Modbus Client
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* \section DESCRIPTION
*
* This class acts as a base class for many of the modal windows used in the
* project. It specifically provides some basic definitions needed to interact
* with the scheduler as well as delayed widget population.
*/
#ifndef BASE_DIALOG_H
#define BASE_DIALOG_H
// c++ includes
#include <QDialog> // QDialog
#include <QResizeEvent> // QResizeEvent
#include <QVBoxLayout> // QVBoxLayout
#include <QAbstractButton> // QAbstractButton
#include <QStyle> // QStyle
// C includes
/* -none- */
// project includes
#include "write_event.h" // WriteRequest
#include "metadata_structs.h" // WindowMetadataRequest
#include "modbusthread.h" // ModbusThread
/**
* \brief Modal window
*/
class BaseDialog : public QDialog
{
Q_OBJECT
public:
/**
* \brief constructor
* @param parent parent QObject owner
* @param create_layout set ``false`` to omit creating the top QVBoxLayout
*/
BaseDialog(QWidget *const parent, const bool create_layout=true);
void add_icon_to_button(QAbstractButton *const button,
const QStyle::StandardPixmap icon_name) const;
/**
* \brief Set metadata callback from scheduler
* @param metadata Metadata returned from poller
* @param node Node (slave ID) that was polled
*/
virtual void set_metadata(std::shared_ptr<Metadata> metadata, const quint8 node);
/**
* \brief Callback from scheduler to poll register data (1-poll)
* @param engine Modbus connection
*/
virtual void poll_register_set(ModbusThread *const engine);
public slots:
/**
* \brief Signal to update a register value.
* @param reg register number
* @param value raw register value
* @param unit_id node / unit ID polled
*/
virtual void on_new_value(const quint16 reg, const quint16 value, const quint8 unit_id);
/**
* \brief Signal that a modbus exception occurred.
* @param requester request source associated with the exception
* @param exception exception text
*/
virtual void on_exception_status(BaseDialog *requester, const QString exception);
signals:
/**
* \brief Emit that the window has been closed.
* @param window this window
*/
void window_closed(BaseDialog *window);
/**
* \brief Emit that the window has been shown for the first time.
* @param window this window
*/
void window_first_display(BaseDialog *window);
/**
* \brief Emit data write request.
* @param req write request structure
*/
void write_requested(WriteRequest req);
/**
* \brief Emit read metadata request.
* @param req read metadata request structure
*/
void metadata_requested(WindowMetadataRequest req);
protected:
/**
* \brief Initialize the UI components.
*/
virtual void setupUi() = 0;
virtual void showEvent(QShowEvent *evt) override;
virtual void resizeEvent(QResizeEvent *evt) override;
virtual void closeEvent(QCloseEvent *evt) override;
QVBoxLayout *const m_top_layout; /**< Window layout control */
bool m_debug_resize = false; /*< derived classes may change this to print window sizes */
private:
bool m_first_display;
bool m_emit_close;
};
#endif // BASE_DIALOG_H