1 | /* $Id: UIApplianceEditorWidget.h 103803 2024-03-12 11:15:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIApplianceEditorWidget class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-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_widgets_UIApplianceEditorWidget_h
|
---|
29 | #define FEQT_INCLUDED_SRC_widgets_UIApplianceEditorWidget_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QAbstractItemModel>
|
---|
36 | #include <QItemDelegate>
|
---|
37 | #include <QSortFilterProxyModel>
|
---|
38 | #include <QWidget>
|
---|
39 |
|
---|
40 | /* GUI includes: */
|
---|
41 | #include "QIWithRetranslateUI.h"
|
---|
42 | #include "UIExtraDataDefs.h"
|
---|
43 |
|
---|
44 | /* COM includes: */
|
---|
45 | #include "CAppliance.h"
|
---|
46 | #include "CVirtualSystemDescription.h"
|
---|
47 |
|
---|
48 | /* Forward declarations: */
|
---|
49 | class UIApplianceModelItem;
|
---|
50 | class QCheckBox;
|
---|
51 | class QLabel;
|
---|
52 | class QTextEdit;
|
---|
53 | class QITreeView;
|
---|
54 | class QVBoxLayout;
|
---|
55 |
|
---|
56 |
|
---|
57 | /** Abstract VSD parameter kinds. */
|
---|
58 | enum AbstractVSDParameterKind
|
---|
59 | {
|
---|
60 | ParameterKind_Invalid,
|
---|
61 | ParameterKind_Bool,
|
---|
62 | ParameterKind_Double,
|
---|
63 | ParameterKind_String,
|
---|
64 | ParameterKind_Array
|
---|
65 | };
|
---|
66 |
|
---|
67 | /** Abstract VSD parameter of Bool type, internal level. */
|
---|
68 | struct AbstractVSDParameterBool
|
---|
69 | {
|
---|
70 | /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
71 | AbstractVSDParameterBool()
|
---|
72 | : value(false) {}
|
---|
73 | /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
74 | AbstractVSDParameterBool(const AbstractVSDParameterBool &other)
|
---|
75 | : value(other.value) {}
|
---|
76 | /** Holds the value. */
|
---|
77 | bool value;
|
---|
78 | };
|
---|
79 | Q_DECLARE_METATYPE(AbstractVSDParameterBool);
|
---|
80 |
|
---|
81 | /** Abstract VSD parameter of Double type, internal level. */
|
---|
82 | struct AbstractVSDParameterDouble
|
---|
83 | {
|
---|
84 | /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
85 | AbstractVSDParameterDouble()
|
---|
86 | : minimum(0), maximum(0), unit(QString()) {}
|
---|
87 | /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
88 | AbstractVSDParameterDouble(const AbstractVSDParameterDouble &other)
|
---|
89 | : minimum(other.minimum), maximum(other.maximum), unit(other.unit) {}
|
---|
90 | /** Holds the minimum/base value. */
|
---|
91 | double minimum;
|
---|
92 | /** Holds the maximum value. */
|
---|
93 | double maximum;
|
---|
94 | /** Holds the unit. */
|
---|
95 | QString unit;
|
---|
96 | };
|
---|
97 | Q_DECLARE_METATYPE(AbstractVSDParameterDouble);
|
---|
98 |
|
---|
99 | /** Abstract VSD parameter of String type, internal level. */
|
---|
100 | struct AbstractVSDParameterString
|
---|
101 | {
|
---|
102 | /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
103 | AbstractVSDParameterString()
|
---|
104 | : value(QString()) {}
|
---|
105 | /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
106 | AbstractVSDParameterString(const AbstractVSDParameterString &other)
|
---|
107 | : value(other.value) {}
|
---|
108 | /** Holds the value. */
|
---|
109 | QString value;
|
---|
110 | };
|
---|
111 | Q_DECLARE_METATYPE(AbstractVSDParameterString);
|
---|
112 |
|
---|
113 | /** Abstract VSD parameter of Array type, internal level. */
|
---|
114 | struct AbstractVSDParameterArray
|
---|
115 | {
|
---|
116 | /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
117 | AbstractVSDParameterArray()
|
---|
118 | : values(QIStringPairList()) {}
|
---|
119 | /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
|
---|
120 | AbstractVSDParameterArray(const AbstractVSDParameterArray &other)
|
---|
121 | : values(other.values) {}
|
---|
122 | /** Holds the values array. */
|
---|
123 | QIStringPairList values;
|
---|
124 | };
|
---|
125 | Q_DECLARE_METATYPE(AbstractVSDParameterArray);
|
---|
126 |
|
---|
127 | /** Abstract VSD parameter interface, facade level. */
|
---|
128 | struct AbstractVSDParameter
|
---|
129 | {
|
---|
130 | /** Holds the parameter name. */
|
---|
131 | QString name;
|
---|
132 | /** Holds the parameter type. */
|
---|
133 | KVirtualSystemDescriptionType type;
|
---|
134 | /** Holds the parameter kind. */
|
---|
135 | AbstractVSDParameterKind kind;
|
---|
136 | /** Holds the parameter abstract getter. */
|
---|
137 | QVariant get;
|
---|
138 | };
|
---|
139 |
|
---|
140 | /** Abstract VSD parameter list. */
|
---|
141 | typedef QList<AbstractVSDParameter> AbstractVSDParameterList;
|
---|
142 | Q_DECLARE_METATYPE(AbstractVSDParameterList);
|
---|
143 |
|
---|
144 |
|
---|
145 | /** Appliance tree-view section types. */
|
---|
146 | enum ApplianceViewSection
|
---|
147 | {
|
---|
148 | ApplianceViewSection_Description = 0,
|
---|
149 | ApplianceViewSection_OriginalValue,
|
---|
150 | ApplianceViewSection_ConfigValue
|
---|
151 | };
|
---|
152 |
|
---|
153 |
|
---|
154 | /** Appliance model item types. */
|
---|
155 | enum ApplianceModelItemType
|
---|
156 | {
|
---|
157 | ApplianceModelItemType_Root,
|
---|
158 | ApplianceModelItemType_VirtualSystem,
|
---|
159 | ApplianceModelItemType_VirtualHardware
|
---|
160 | };
|
---|
161 |
|
---|
162 |
|
---|
163 | /** QAbstractItemModel subclass used as Appliance model. */
|
---|
164 | class UIApplianceModel : public QAbstractItemModel
|
---|
165 | {
|
---|
166 | Q_OBJECT;
|
---|
167 |
|
---|
168 | public:
|
---|
169 |
|
---|
170 | /** Constructs the Appliance model passing @a pParent to the base-class.
|
---|
171 | * @param aVSDs Brings the Virtual System descriptions. */
|
---|
172 | UIApplianceModel(QVector<CVirtualSystemDescription>& aVSDs, QITreeView *pParent);
|
---|
173 | /** Destructs the Appliance model. */
|
---|
174 | ~UIApplianceModel();
|
---|
175 |
|
---|
176 | /** Returns the root index in the model. */
|
---|
177 | virtual QModelIndex root() const;
|
---|
178 | /** Returns the index of the item in the model specified by the given @a iRow, @a iColumn and @a parentIdx. */
|
---|
179 | virtual QModelIndex index(int iRow, int iColumn, const QModelIndex &parentIdx = QModelIndex()) const RT_OVERRIDE;
|
---|
180 | /** Returns the parent of the model item with the given @a idx. */
|
---|
181 | virtual QModelIndex parent(const QModelIndex &idx) const RT_OVERRIDE;
|
---|
182 |
|
---|
183 | /** Returns the number of rows for the children of the given @a parentIdx. */
|
---|
184 | virtual int rowCount(const QModelIndex &parentIdx = QModelIndex()) const RT_OVERRIDE;
|
---|
185 | /** Returns the number of columns for the children of the given @a parentIdx. */
|
---|
186 | virtual int columnCount(const QModelIndex &parentIdx = QModelIndex()) const RT_OVERRIDE;
|
---|
187 |
|
---|
188 | /** Returns the item flags for the given @a idx. */
|
---|
189 | virtual Qt::ItemFlags flags(const QModelIndex &idx) const RT_OVERRIDE;
|
---|
190 | /** Returns the data for the given @a iRole and @a iSection in the header with the specified @a enmOrientation. */
|
---|
191 | virtual QVariant headerData(int iSection, Qt::Orientation enmOrientation, int iRole) const RT_OVERRIDE;
|
---|
192 |
|
---|
193 | /** Defines the @a iRole data for the item at @a idx to @a value. */
|
---|
194 | virtual bool setData(const QModelIndex &idx, const QVariant &value, int iRole) RT_OVERRIDE;
|
---|
195 | /** Returns the data stored under the given @a iRole for the item referred to by the @a idx. */
|
---|
196 | virtual QVariant data(const QModelIndex &idx, int iRole = Qt::DisplayRole) const RT_OVERRIDE;
|
---|
197 |
|
---|
198 | /** Returns a model index for the buddy of the item represented by @a idx. */
|
---|
199 | virtual QModelIndex buddy(const QModelIndex &idx) const RT_OVERRIDE;
|
---|
200 |
|
---|
201 | /** Restores the default values for the item with the given @a parentIdx. */
|
---|
202 | void restoreDefaults(QModelIndex parentIdx = QModelIndex());
|
---|
203 |
|
---|
204 | /** Cache currently stored values. */
|
---|
205 | void putBack();
|
---|
206 |
|
---|
207 | void setVirtualSystemBaseFolder(const QString& path);
|
---|
208 |
|
---|
209 | /** Defines the list of VSD @a hints. */
|
---|
210 | void setVsdHints(const AbstractVSDParameterList &hints);
|
---|
211 | /** Returns a name hint for certain VSD @a enmType. */
|
---|
212 | QString nameHint(KVirtualSystemDescriptionType enmType) const;
|
---|
213 | /** Returns a kind hint for certain VSD @a enmType. */
|
---|
214 | AbstractVSDParameterKind kindHint(KVirtualSystemDescriptionType enmType) const;
|
---|
215 | /** Returns a value hint for certain VSD @a enmType. */
|
---|
216 | QVariant getHint(KVirtualSystemDescriptionType enmType) const;
|
---|
217 |
|
---|
218 | private:
|
---|
219 |
|
---|
220 | /** Holds the list of VSD hints. */
|
---|
221 | AbstractVSDParameterList m_listVsdHints;
|
---|
222 |
|
---|
223 | /** Holds the root item reference. */
|
---|
224 | UIApplianceModelItem *m_pRootItem;
|
---|
225 | };
|
---|
226 |
|
---|
227 |
|
---|
228 | /** QItemDelegate subclass used to create various Appliance model editors. */
|
---|
229 | class UIApplianceDelegate : public QItemDelegate
|
---|
230 | {
|
---|
231 | Q_OBJECT;
|
---|
232 |
|
---|
233 | public:
|
---|
234 |
|
---|
235 | /** Constructs the Appliance Delegate.
|
---|
236 | * @param pProxy Brings the proxy model reference used to redirect requests to. */
|
---|
237 | UIApplianceDelegate(QAbstractProxyModel *pProxy);
|
---|
238 |
|
---|
239 | /** Returns the widget used to edit the item specified by @a idx for editing.
|
---|
240 | * @param pParent Brings the parent to be assigned for newly created editor.
|
---|
241 | * @param styleOption Bring the style option set for the newly created editor. */
|
---|
242 | virtual QWidget *createEditor(QWidget *pParent, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const RT_OVERRIDE;
|
---|
243 |
|
---|
244 | /** Defines the contents of the given @a pEditor to the data for the item at the given @a idx. */
|
---|
245 | virtual void setEditorData(QWidget *pEditor, const QModelIndex &idx) const RT_OVERRIDE;
|
---|
246 | /** Defines the data for the item at the given @a idx in the @a pModel to the contents of the given @a pEditor. */
|
---|
247 | virtual void setModelData(QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex &idx) const RT_OVERRIDE;
|
---|
248 |
|
---|
249 | /** Updates the geometry of the @a pEditor for the item with the given @a idx, according to the rectangle specified in the @a styleOption. */
|
---|
250 | virtual void updateEditorGeometry(QWidget *pEditor, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const RT_OVERRIDE;
|
---|
251 |
|
---|
252 | /** Returns the size hint for the item at the given @a idx and specified @a styleOption. */
|
---|
253 | virtual QSize sizeHint(const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const RT_OVERRIDE;
|
---|
254 |
|
---|
255 | protected:
|
---|
256 |
|
---|
257 | #ifdef VBOX_WS_MAC
|
---|
258 | /** Filters @a pEvent if this object has been installed as an event filter for the watched @a pObject. */
|
---|
259 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
|
---|
260 | #endif
|
---|
261 |
|
---|
262 | private:
|
---|
263 |
|
---|
264 | /** Holds the proxy model reference used to redirect requests to. */
|
---|
265 | QAbstractProxyModel *m_pProxy;
|
---|
266 | };
|
---|
267 |
|
---|
268 |
|
---|
269 | /** QSortFilterProxyModel subclass used as the Appliance Sorting Proxy model. */
|
---|
270 | class UIApplianceSortProxyModel : public QSortFilterProxyModel
|
---|
271 | {
|
---|
272 | Q_OBJECT;
|
---|
273 |
|
---|
274 | public:
|
---|
275 |
|
---|
276 | /** Constructs the Appliance Sorting Proxy model passing @a pParent to the base-class. */
|
---|
277 | UIApplianceSortProxyModel(QObject *pParent = 0);
|
---|
278 |
|
---|
279 | protected:
|
---|
280 |
|
---|
281 | /** Returns whether item in the row indicated by the given @a iSourceRow and @a srcParenIdx should be included in the model. */
|
---|
282 | virtual bool filterAcceptsRow(int iSourceRow, const QModelIndex &srcParenIdx) const RT_OVERRIDE;
|
---|
283 |
|
---|
284 | /** Returns whether value of the item referred to by the given index @a leftIdx is less
|
---|
285 | * than the value of the item referred to by the given index @a rightIdx. */
|
---|
286 | virtual bool lessThan(const QModelIndex &leftIdx, const QModelIndex &rightIdx) const RT_OVERRIDE;
|
---|
287 |
|
---|
288 | /** Holds the array of sorted Virtual System Description types. */
|
---|
289 | static KVirtualSystemDescriptionType s_aSortList[];
|
---|
290 |
|
---|
291 | /** Holds the filtered list of Virtual System Description types. */
|
---|
292 | QList<KVirtualSystemDescriptionType> m_aFilteredList;
|
---|
293 | };
|
---|
294 |
|
---|
295 |
|
---|
296 | /** QWidget subclass used as the Appliance Editor widget. */
|
---|
297 | class UIApplianceEditorWidget : public QIWithRetranslateUI<QWidget>
|
---|
298 | {
|
---|
299 | Q_OBJECT;
|
---|
300 |
|
---|
301 | public:
|
---|
302 |
|
---|
303 | /** Constructs the Appliance Editor widget passing @a pParent to the base-class. */
|
---|
304 | UIApplianceEditorWidget(QWidget *pParent = 0);
|
---|
305 |
|
---|
306 | /** Clears everything. */
|
---|
307 | void clear();
|
---|
308 |
|
---|
309 | /** Defines @a comAppliance wrapper instance. */
|
---|
310 | virtual void setAppliance(const CAppliance &comAppliance);
|
---|
311 |
|
---|
312 | /** Defines the list of VSD @a hints. */
|
---|
313 | void setVsdHints(const AbstractVSDParameterList &hints);
|
---|
314 |
|
---|
315 | /** Defines virtual system base folder @a strPath. */
|
---|
316 | void setVirtualSystemBaseFolder(const QString &strPath);
|
---|
317 |
|
---|
318 | /** Returns the minimum guest RAM. */
|
---|
319 | static int minGuestRAM() { return m_minGuestRAM; }
|
---|
320 | /** Returns the maximum guest RAM. */
|
---|
321 | static int maxGuestRAM() { return m_maxGuestRAM; }
|
---|
322 | /** Returns the minimum guest CPU count. */
|
---|
323 | static int minGuestCPUCount() { return m_minGuestCPUCount; }
|
---|
324 | /** Returns the maximum guest CPU count. */
|
---|
325 | static int maxGuestCPUCount() { return m_maxGuestCPUCount; }
|
---|
326 |
|
---|
327 | public slots:
|
---|
328 |
|
---|
329 | /** Restores the default values. */
|
---|
330 | void restoreDefaults();
|
---|
331 |
|
---|
332 | protected:
|
---|
333 |
|
---|
334 | /** Handles translation event. */
|
---|
335 | virtual void retranslateUi() RT_OVERRIDE;
|
---|
336 |
|
---|
337 | /** Holds the currently set appliance reference. */
|
---|
338 | CAppliance m_comAppliance;
|
---|
339 |
|
---|
340 | /** Holds the list of VSD hints. */
|
---|
341 | AbstractVSDParameterList m_listVsdHints;
|
---|
342 |
|
---|
343 | /** Holds the Appliance model reference. */
|
---|
344 | UIApplianceModel *m_pModel;
|
---|
345 |
|
---|
346 | QVBoxLayout *m_pLayout;
|
---|
347 |
|
---|
348 | /** Holds the information pane instance. */
|
---|
349 | QWidget *m_pPaneInformation;
|
---|
350 | /** Holds the settings tree-view instance. */
|
---|
351 | QITreeView *m_pTreeViewSettings;
|
---|
352 |
|
---|
353 | /** Holds the warning pane instance. */
|
---|
354 | QWidget *m_pPaneWarning;
|
---|
355 | /** Holds the warning label instance. */
|
---|
356 | QLabel *m_pLabelWarning;
|
---|
357 | /** Holds the warning browser instance. */
|
---|
358 | QTextEdit *m_pTextEditWarning;
|
---|
359 |
|
---|
360 | private:
|
---|
361 |
|
---|
362 | /** Performs Appliance settings initialization. */
|
---|
363 | static void initSystemSettings();
|
---|
364 |
|
---|
365 | /** Holds the minimum guest RAM. */
|
---|
366 | static int m_minGuestRAM;
|
---|
367 | /** Holds the maximum guest RAM. */
|
---|
368 | static int m_maxGuestRAM;
|
---|
369 | /** Holds the minimum guest CPU count. */
|
---|
370 | static int m_minGuestCPUCount;
|
---|
371 | /** Holds the maximum guest CPU count. */
|
---|
372 | static int m_maxGuestCPUCount;
|
---|
373 | };
|
---|
374 |
|
---|
375 | #endif /* !FEQT_INCLUDED_SRC_widgets_UIApplianceEditorWidget_h */
|
---|