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