1 | /* $Id: UIConverter.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIConverter declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
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
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_converter_UIConverter_h
|
---|
29 | #define FEQT_INCLUDED_SRC_converter_UIConverter_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* GUI includes: */
|
---|
35 | #include "UIConverterBackend.h"
|
---|
36 |
|
---|
37 | /** High-level interface for different conversions between GUI classes.
|
---|
38 | * @todo Replace singleton with static template interface. */
|
---|
39 | class SHARED_LIBRARY_STUFF UIConverter
|
---|
40 | {
|
---|
41 | public:
|
---|
42 |
|
---|
43 | /** Returns singleton instance. */
|
---|
44 | static UIConverter *instance() { return s_pInstance; }
|
---|
45 |
|
---|
46 | /** Creates singleton instance. */
|
---|
47 | static void create();
|
---|
48 | /** Destroys singleton instance. */
|
---|
49 | static void destroy();
|
---|
50 |
|
---|
51 | /** Converts QColor <= template class. */
|
---|
52 | template<class T> QColor toColor(const T &data) const
|
---|
53 | {
|
---|
54 | if (canConvert<T>())
|
---|
55 | return ::toColor(data);
|
---|
56 | AssertFailed();
|
---|
57 | return QColor();
|
---|
58 | }
|
---|
59 |
|
---|
60 | /** Converts QIcon <= template class. */
|
---|
61 | template<class T> QIcon toIcon(const T &data) const
|
---|
62 | {
|
---|
63 | if (canConvert<T>())
|
---|
64 | return ::toIcon(data);
|
---|
65 | AssertFailed();
|
---|
66 | return QIcon();
|
---|
67 | }
|
---|
68 | /** Converts QPixmap <= template class. */
|
---|
69 | template<class T> QPixmap toWarningPixmap(const T &data) const
|
---|
70 | {
|
---|
71 | if (canConvert<T>())
|
---|
72 | return ::toWarningPixmap(data);
|
---|
73 | AssertFailed();
|
---|
74 | return QPixmap();
|
---|
75 | }
|
---|
76 |
|
---|
77 | /** Converts QString <= template class. */
|
---|
78 | template<class T> QString toString(const T &data) const
|
---|
79 | {
|
---|
80 | if (canConvert<T>())
|
---|
81 | return ::toString(data);
|
---|
82 | AssertFailed();
|
---|
83 | return QString();
|
---|
84 | }
|
---|
85 | /** Converts template class <= QString. */
|
---|
86 | template<class T> T fromString(const QString &strData) const
|
---|
87 | {
|
---|
88 | if (canConvert<T>())
|
---|
89 | return ::fromString<T>(strData);
|
---|
90 | AssertFailed();
|
---|
91 | return T();
|
---|
92 | }
|
---|
93 |
|
---|
94 | /** Converts QString <= template class. */
|
---|
95 | template<class T> QString toInternalString(const T &data) const
|
---|
96 | {
|
---|
97 | if (canConvert<T>())
|
---|
98 | return ::toInternalString(data);
|
---|
99 | AssertFailed();
|
---|
100 | return QString();
|
---|
101 | }
|
---|
102 | /** Converts template class <= QString. */
|
---|
103 | template<class T> T fromInternalString(const QString &strData) const
|
---|
104 | {
|
---|
105 | if (canConvert<T>())
|
---|
106 | return ::fromInternalString<T>(strData);
|
---|
107 | AssertFailed();
|
---|
108 | return T();
|
---|
109 | }
|
---|
110 |
|
---|
111 | /** Converts int <= template class. */
|
---|
112 | template<class T> int toInternalInteger(const T &data) const
|
---|
113 | {
|
---|
114 | if (canConvert<T>())
|
---|
115 | return ::toInternalInteger(data);
|
---|
116 | AssertFailed();
|
---|
117 | return 0;
|
---|
118 | }
|
---|
119 | /** Converts template class <= int. */
|
---|
120 | template<class T> T fromInternalInteger(const int &iData) const
|
---|
121 | {
|
---|
122 | if (canConvert<T>())
|
---|
123 | return ::fromInternalInteger<T>(iData);
|
---|
124 | AssertFailed();
|
---|
125 | return T();
|
---|
126 | }
|
---|
127 |
|
---|
128 | private:
|
---|
129 |
|
---|
130 | /** Constructs converter. */
|
---|
131 | UIConverter() { s_pInstance = this; }
|
---|
132 | /** Destructs converter. */
|
---|
133 | virtual ~UIConverter() /* override final */ { s_pInstance = 0; }
|
---|
134 |
|
---|
135 | /** Holds the static instance. */
|
---|
136 | static UIConverter *s_pInstance;
|
---|
137 | };
|
---|
138 |
|
---|
139 | /** Singleton UI converter 'official' name. */
|
---|
140 | #define gpConverter UIConverter::instance()
|
---|
141 |
|
---|
142 | #endif /* !FEQT_INCLUDED_SRC_converter_UIConverter_h */
|
---|