VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.h

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use