VirtualBox

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

Last change on this file since 100347 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

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

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