VirtualBox

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

Last change on this file since 82781 was 76581, checked in by vboxsync, 5 years ago

Fe/QT: scm header guard alignment.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use