VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 4 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
RevLine 
[55401]1/* $Id: QIWidgetValidator.h 106061 2024-09-16 14:03:52Z vboxsync $ */
[25177]2/** @file
[52727]3 * VBox Qt GUI - Qt extensions: QIWidgetValidator class declaration.
[25177]4 */
5
6/*
[106061]7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
[25177]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
[25177]26 */
27
[76581]28#ifndef FEQT_INCLUDED_SRC_extensions_QIWidgetValidator_h
29#define FEQT_INCLUDED_SRC_extensions_QIWidgetValidator_h
[76532]30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
[25177]33
[47559]34/* Qt includes: */
[71410]35#include <QMap>
[47559]36#include <QValidator>
37
[71630]38/* GUI includes: */
39#include "UILibraryDefs.h"
40
[47559]41
[100959]42/** QObject sub-class,
[51813]43 * providing passed QObject with validation routine. */
[71630]44class SHARED_LIBRARY_STUFF QObjectValidator : public QObject
[51813]45{
46 Q_OBJECT;
47
48signals:
49
[71410]50 /** Notifies listener(s) about validity changed to @a enmState. */
51 void sigValidityChange(QValidator::State enmState);
[51813]52
53public:
54
[71410]55 /** Constructs object validator passing @a pParent to the base-class.
56 * @param pValidator Brings the validator passed on to the OObject
57 * children and used to perform validation itself. */
[51813]58 QObjectValidator(QValidator *pValidator, QObject *pParent = 0);
59
60 /** Returns last validation state. */
[71410]61 QValidator::State state() const { return m_enmState; }
[51813]62
[68079]63public slots:
[51813]64
65 /** Performs validation: */
66 void sltValidate(QString strInput = QString());
67
68private:
69
70 /** Prepare routine. */
71 void prepare();
72
[71410]73 /** Holds the validator reference. */
[51813]74 QValidator *m_pValidator;
[71410]75
76 /** Holds the validation state. */
77 QValidator::State m_enmState;
[51813]78};
79
[71410]80
[100959]81/** QObject sub-class,
[51813]82 * which can group various QObjectValidator instances to operate on. */
[71630]83class SHARED_LIBRARY_STUFF QObjectValidatorGroup : public QObject
[51813]84{
85 Q_OBJECT;
86
87signals:
88
[71410]89 /** Notifies listener(s) about validity changed to @a fValid. */
[51813]90 void sigValidityChange(bool fValid);
91
92public:
93
[71410]94 /** Constructs validation group passing @a pParent to the base-class. */
[100959]95 QObjectValidatorGroup(QObject *pParent);
[51813]96
[71410]97 /** Adds @a pObjectValidator.
[51813]98 * @note The ownership of @a pObjectValidator is transferred to the group,
99 * and it's the group's responsibility to delete it. */
100 void addObjectValidator(QObjectValidator *pObjectValidator);
101
102 /** Returns last validation result. */
103 bool result() const { return m_fResult; }
104
105private slots:
106
[71410]107 /** Performs validation for a passed @a enmState. */
108 void sltValidate(QValidator::State enmState);
[51813]109
110private:
111
112 /** Converts QValidator::State to bool result. */
[71410]113 static bool toResult(QValidator::State enmState);
[51813]114
115 /** Holds object-validators and their states. */
116 QMap<QObjectValidator*, bool> m_group;
[71410]117
[51813]118 /** Holds validation result. */
119 bool m_fResult;
120};
121
[71410]122
123/** QValidator extension,
124 * for long number validations. */
[71630]125class SHARED_LIBRARY_STUFF QIULongValidator : public QValidator
[25177]126{
127public:
128
[71410]129 /** Constructs long validator passing @a pParent to the base-class. */
130 QIULongValidator(QObject *pParent)
131 : QValidator(pParent)
132 , m_uBottom(0), m_uTop(ULONG_MAX)
133 {}
[25177]134
[71410]135 /** Constructs long validator passing @a pParent to the base-class.
136 * @param uMinimum Holds the minimum valid border.
137 * @param uMaximum Holds the maximum valid border. */
138 QIULongValidator(ulong uMinimum, ulong uMaximum,
139 QObject *pParent)
140 : QValidator(pParent)
141 , m_uBottom(uMinimum), m_uTop(uMaximum)
142 {}
[25177]143
[71410]144 /** Destructs long validator. */
145 virtual ~QIULongValidator() {}
[25177]146
[71410]147 /** Performs validation for @a strInput at @a iPosition. */
[103988]148 State validate(QString &strInput, int &iPosition) const RT_OVERRIDE RT_FINAL;
[25177]149
[71410]150 /** Defines @a uBottom. */
151 void setBottom(ulong uBottom) { setRange(uBottom, m_uTop); }
152 /** Defines @a uTop. */
153 void setTop(ulong uTop) { setRange(m_uBottom, uTop); }
154 /** Defines range based on passed @a uBottom and @a uTop. */
155 void setRange(ulong uBottom, ulong uTop) { m_uBottom = uBottom; m_uTop = uTop; }
156 /** Returns bottom. */
157 ulong bottom() const { return m_uBottom; }
158 /** Returns top. */
159 ulong top() const { return m_uTop; }
160
[25177]161private:
162
[71410]163 /** Holds the bottom. */
164 ulong m_uBottom;
165 /** Holds the top. */
166 ulong m_uTop;
[25177]167};
168
[71410]169
[76581]170#endif /* !FEQT_INCLUDED_SRC_extensions_QIWidgetValidator_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette