VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIWidgetValidator.h@ 82781

Last change on this file since 82781 was 76581, checked in by vboxsync, 5 years ago

Fe/QT: scm header guard alignment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: QIWidgetValidator.h 76581 2019-01-01 06:24:57Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIWidgetValidator class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef FEQT_INCLUDED_SRC_extensions_QIWidgetValidator_h
19#define FEQT_INCLUDED_SRC_extensions_QIWidgetValidator_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* Qt includes: */
25#include <QMap>
26#include <QPixmap>
27#include <QValidator>
28
29/* GUI includes: */
30#include "UILibraryDefs.h"
31
32/* Forward declarations: */
33class QPixmap;
34class QString;
35class UISettingsPage;
36
37
38/** QObject extension,
39 * providing passed QObject with validation routine. */
40class SHARED_LIBRARY_STUFF QObjectValidator : public QObject
41{
42 Q_OBJECT;
43
44signals:
45
46 /** Notifies listener(s) about validity changed to @a enmState. */
47 void sigValidityChange(QValidator::State enmState);
48
49public:
50
51 /** Constructs object validator passing @a pParent to the base-class.
52 * @param pValidator Brings the validator passed on to the OObject
53 * children and used to perform validation itself. */
54 QObjectValidator(QValidator *pValidator, QObject *pParent = 0);
55
56 /** Returns last validation state. */
57 QValidator::State state() const { return m_enmState; }
58
59public slots:
60
61 /** Performs validation: */
62 void sltValidate(QString strInput = QString());
63
64private:
65
66 /** Prepare routine. */
67 void prepare();
68
69 /** Holds the validator reference. */
70 QValidator *m_pValidator;
71
72 /** Holds the validation state. */
73 QValidator::State m_enmState;
74};
75
76
77/** QObject extension,
78 * which can group various QObjectValidator instances to operate on. */
79class SHARED_LIBRARY_STUFF QObjectValidatorGroup : public QObject
80{
81 Q_OBJECT;
82
83signals:
84
85 /** Notifies listener(s) about validity changed to @a fValid. */
86 void sigValidityChange(bool fValid);
87
88public:
89
90 /** Constructs validation group passing @a pParent to the base-class. */
91 QObjectValidatorGroup(QObject *pParent)
92 : QObject(pParent)
93 , m_fResult(false)
94 {}
95
96 /** Adds @a pObjectValidator.
97 * @note The ownership of @a pObjectValidator is transferred to the group,
98 * and it's the group's responsibility to delete it. */
99 void addObjectValidator(QObjectValidator *pObjectValidator);
100
101 /** Returns last validation result. */
102 bool result() const { return m_fResult; }
103
104private slots:
105
106 /** Performs validation for a passed @a enmState. */
107 void sltValidate(QValidator::State enmState);
108
109private:
110
111 /** Converts QValidator::State to bool result. */
112 static bool toResult(QValidator::State enmState);
113
114 /** Holds object-validators and their states. */
115 QMap<QObjectValidator*, bool> m_group;
116
117 /** Holds validation result. */
118 bool m_fResult;
119};
120
121
122/** Page validator prototype. */
123class SHARED_LIBRARY_STUFF UIPageValidator : public QObject
124{
125 Q_OBJECT;
126
127signals:
128
129 /** Notifies about validity change for @a pValidator. */
130 void sigValidityChanged(UIPageValidator *pValidator);
131
132 /** Asks listener to show warning icon. */
133 void sigShowWarningIcon();
134 /** Asks listener to hide warning icon. */
135 void sigHideWarningIcon();
136
137public:
138
139 /** Constructs page validator for a certain @a pPage,
140 * passing @a pParent to the base-class. */
141 UIPageValidator(QObject *pParent, UISettingsPage *pPage)
142 : QObject(pParent)
143 , m_pPage(pPage)
144 , m_fIsValid(true)
145 {}
146
147 /** Returns page. */
148 UISettingsPage *page() const { return m_pPage; }
149 /** Returns warning pixmap. */
150 QPixmap warningPixmap() const;
151 /** Returns internal name. */
152 QString internalName() const;
153
154 /** Returns whether validator is valid. */
155 bool isValid() const { return m_fIsValid; }
156 /** Defines whether validator @a fIsValid. */
157 void setValid(bool fIsValid) { m_fIsValid = fIsValid; }
158
159 /** Returns last message. */
160 QString lastMessage() const { return m_strLastMessage; }
161 /** Defines @a strLastMessage. */
162 void setLastMessage(const QString &strLastMessage);
163
164public slots:
165
166 /** Performs revalidation. */
167 void revalidate();
168
169private:
170
171 /** Holds the validated page. */
172 UISettingsPage *m_pPage;
173
174 /** Holds whether the page is valid. */
175 bool m_fIsValid;
176
177 /** Holds the last message. */
178 QString m_strLastMessage;
179};
180
181
182/** QValidator extension,
183 * for long number validations. */
184class SHARED_LIBRARY_STUFF QIULongValidator : public QValidator
185{
186public:
187
188 /** Constructs long validator passing @a pParent to the base-class. */
189 QIULongValidator(QObject *pParent)
190 : QValidator(pParent)
191 , m_uBottom(0), m_uTop(ULONG_MAX)
192 {}
193
194 /** Constructs long validator passing @a pParent to the base-class.
195 * @param uMinimum Holds the minimum valid border.
196 * @param uMaximum Holds the maximum valid border. */
197 QIULongValidator(ulong uMinimum, ulong uMaximum,
198 QObject *pParent)
199 : QValidator(pParent)
200 , m_uBottom(uMinimum), m_uTop(uMaximum)
201 {}
202
203 /** Destructs long validator. */
204 virtual ~QIULongValidator() {}
205
206 /** Performs validation for @a strInput at @a iPosition. */
207 State validate(QString &strInput, int &iPosition) const;
208
209 /** Defines @a uBottom. */
210 void setBottom(ulong uBottom) { setRange(uBottom, m_uTop); }
211 /** Defines @a uTop. */
212 void setTop(ulong uTop) { setRange(m_uBottom, uTop); }
213 /** Defines range based on passed @a uBottom and @a uTop. */
214 void setRange(ulong uBottom, ulong uTop) { m_uBottom = uBottom; m_uTop = uTop; }
215 /** Returns bottom. */
216 ulong bottom() const { return m_uBottom; }
217 /** Returns top. */
218 ulong top() const { return m_uTop; }
219
220private:
221
222 /** Holds the bottom. */
223 ulong m_uBottom;
224 /** Holds the top. */
225 ulong m_uTop;
226};
227
228
229#endif /* !FEQT_INCLUDED_SRC_extensions_QIWidgetValidator_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use