VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxApplianceEditorWgt.h@ 35740

Last change on this file since 35740 was 28800, checked in by vboxsync, 14 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt4 GUI ("VirtualBox"):
4 * VBoxApplianceEditorWgt class declaration
5 */
6
7/*
8 * Copyright (C) 2009 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef __VBoxApplianceEditorWgt_h__
20#define __VBoxApplianceEditorWgt_h__
21
22/* VBox includes */
23#include "COMDefs.h"
24#include "VBoxApplianceEditorWgt.gen.h"
25#include "QIWithRetranslateUI.h"
26
27/* Qt includes */
28#include <QSortFilterProxyModel>
29#include <QItemDelegate>
30
31/* VBox forward declarations */
32class ModelItem;
33
34////////////////////////////////////////////////////////////////////////////////
35// Globals
36
37enum TreeViewSection { DescriptionSection = 0, OriginalValueSection, ConfigValueSection };
38
39////////////////////////////////////////////////////////////////////////////////
40// ModelItem
41
42enum ModelItemType { RootType, VirtualSystemType, HardwareType };
43
44/* This & the following derived classes represent the data items of a Virtual
45 System. All access/manipulation is done with the help of virtual functions
46 to keep the interface clean. ModelItem is able to handle tree structures
47 with a parent & several children's. */
48class ModelItem
49{
50public:
51 ModelItem (int aNumber, ModelItemType aType, ModelItem *aParent = NULL);
52
53 ~ModelItem();
54
55 ModelItem *parent() const { return mParentItem; }
56
57 void appendChild (ModelItem *aChild);
58 ModelItem * child (int aRow) const;
59
60 int row() const;
61
62 int childCount() const;
63 int columnCount() const { return 3; }
64
65 virtual Qt::ItemFlags itemFlags (int /* aColumn */) const { return 0; }
66 virtual bool setData (int /* aColumn */, const QVariant & /* aValue */, int /* aRole */) { return false; }
67 virtual QVariant data (int /* aColumn */, int /* aRole */) const { return QVariant(); }
68 virtual QWidget * createEditor (QWidget * /* aParent */, const QStyleOptionViewItem & /* aOption */, const QModelIndex & /* aIndex */) const { return NULL; }
69 virtual bool setEditorData (QWidget * /* aEditor */, const QModelIndex & /* aIndex */) const { return false; }
70 virtual bool setModelData (QWidget * /* aEditor */, QAbstractItemModel * /* aModel */, const QModelIndex & /* aIndex */) { return false; }
71
72 virtual void restoreDefaults() {}
73 virtual void putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues);
74
75 ModelItemType type() const { return mType; }
76
77protected:
78 /* Protected member vars */
79 int mNumber;
80 ModelItemType mType;
81
82 ModelItem *mParentItem;
83 QList<ModelItem*> mChildItems;
84};
85
86////////////////////////////////////////////////////////////////////////////////
87// VirtualSystemItem
88
89/* This class represent a Virtual System with an index. */
90class VirtualSystemItem: public ModelItem
91{
92public:
93 VirtualSystemItem (int aNumber, CVirtualSystemDescription aDesc, ModelItem *aParent);
94
95 virtual QVariant data (int aColumn, int aRole) const;
96
97 virtual void putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues);
98
99private:
100 CVirtualSystemDescription mDesc;
101};
102
103////////////////////////////////////////////////////////////////////////////////
104// HardwareItem
105
106/* This class represent an hardware item of a Virtual System. All values of
107 KVirtualSystemDescriptionType are supported & handled differently. */
108class HardwareItem: public ModelItem
109{
110 friend class VirtualSystemSortProxyModel;
111public:
112
113 HardwareItem (int aNumber,
114 KVirtualSystemDescriptionType aType,
115 const QString &aRef,
116 const QString &aOrigValue,
117 const QString &aConfigValue,
118 const QString &aExtraConfigValue,
119 ModelItem *aParent);
120
121 virtual void putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues);
122
123 virtual bool setData (int aColumn, const QVariant &aValue, int aRole);
124 virtual QVariant data (int aColumn, int aRole) const;
125
126 virtual Qt::ItemFlags itemFlags (int aColumn) const;
127
128 virtual QWidget * createEditor (QWidget *aParent, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
129 virtual bool setEditorData (QWidget *aEditor, const QModelIndex &aIndex) const;
130
131 virtual bool setModelData (QWidget *aEditor, QAbstractItemModel *aModel, const QModelIndex &aIndex);
132
133 virtual void restoreDefaults()
134 {
135 mConfigValue = mConfigDefaultValue;
136 mCheckState = Qt::Checked;
137 }
138
139private:
140
141 /* Private member vars */
142 KVirtualSystemDescriptionType mType;
143 QString mRef;
144 QString mOrigValue;
145 QString mConfigValue;
146 QString mConfigDefaultValue;
147 QString mExtraConfigValue;
148 Qt::CheckState mCheckState;
149};
150
151////////////////////////////////////////////////////////////////////////////////
152// VirtualSystemModel
153
154class VirtualSystemModel: public QAbstractItemModel
155{
156
157public:
158 VirtualSystemModel (QVector<CVirtualSystemDescription>& aVSDs, QObject *aParent = NULL);
159
160 QModelIndex index (int aRow, int aColumn, const QModelIndex &aParent = QModelIndex()) const;
161 QModelIndex parent (const QModelIndex &aIndex) const;
162 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
163 int columnCount (const QModelIndex &aParent = QModelIndex()) const;
164 bool setData (const QModelIndex &aIndex, const QVariant &aValue, int aRole);
165 QVariant data (const QModelIndex &aIndex, int aRole = Qt::DisplayRole) const;
166 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
167 QVariant headerData (int aSection, Qt::Orientation aOrientation, int aRole) const;
168
169 QModelIndex buddy (const QModelIndex &aIndex) const;
170
171 void restoreDefaults (const QModelIndex& aParent = QModelIndex());
172 void putBack();
173
174private:
175 /* Private member vars */
176 ModelItem *mRootItem;
177};
178
179////////////////////////////////////////////////////////////////////////////////
180// VirtualSystemDelegate
181
182/* The delegate is used for creating/handling the different editors for the
183 various types we support. This class forward the requests to the virtual
184 methods of our different ModelItems. If this is not possible the default
185 methods of QItemDelegate are used to get some standard behavior. Note: We
186 have to handle the proxy model ourself. I really don't understand why Qt is
187 not doing this for us. */
188class VirtualSystemDelegate: public QItemDelegate
189{
190public:
191 VirtualSystemDelegate (QAbstractProxyModel *aProxy, QObject *aParent = NULL);
192
193 QWidget * createEditor (QWidget *aParent, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
194 void setEditorData (QWidget *aEditor, const QModelIndex &aIndex) const;
195 void setModelData (QWidget *aEditor, QAbstractItemModel *aModel, const QModelIndex &aIndex) const;
196 void updateEditorGeometry (QWidget *aEditor, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
197
198 QSize sizeHint (const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const
199 {
200 QSize size = QItemDelegate::sizeHint (aOption, aIndex);
201#ifdef Q_WS_MAC
202 int h = 28;
203#else /* Q_WS_MAC */
204 int h = 24;
205#endif /* Q_WS_MAC */
206 size.setHeight (RT_MAX (h, size.height()));
207 return size;
208 }
209
210protected:
211#ifdef QT_MAC_USE_COCOA
212 bool eventFilter (QObject *aObject, QEvent *aEvent);
213#endif /* QT_MAC_USE_COCOA */
214
215private:
216 /* Private member vars */
217 QAbstractProxyModel *mProxy;
218};
219
220////////////////////////////////////////////////////////////////////////////////
221// VirtualSystemSortProxyModel
222
223class VirtualSystemSortProxyModel: public QSortFilterProxyModel
224{
225public:
226 VirtualSystemSortProxyModel (QObject *aParent = NULL);
227
228protected:
229 bool filterAcceptsRow (int aSourceRow, const QModelIndex & aSourceParent) const;
230 bool lessThan (const QModelIndex &aLeft, const QModelIndex &aRight) const;
231
232 static KVirtualSystemDescriptionType mSortList[];
233
234 QList<KVirtualSystemDescriptionType> mFilterList;
235};
236
237////////////////////////////////////////////////////////////////////////////////
238// VBoxApplianceEditorWgt
239
240class VBoxApplianceEditorWgt : public QIWithRetranslateUI<QWidget>,
241 public Ui::VBoxApplianceEditorWgt
242{
243 Q_OBJECT;
244
245public:
246 VBoxApplianceEditorWgt (QWidget *aParent = NULL);
247
248 bool isValid() const { return mAppliance != NULL; }
249 CAppliance* appliance() const { return mAppliance; }
250
251 static int minGuestRAM() { return mMinGuestRAM; }
252 static int maxGuestRAM() { return mMaxGuestRAM; }
253 static int minGuestCPUCount() { return mMinGuestCPUCount; }
254 static int maxGuestCPUCount() { return mMaxGuestCPUCount; }
255
256public slots:
257 void restoreDefaults();
258
259protected:
260 virtual void retranslateUi();
261
262 /* Protected member vars */
263 CAppliance *mAppliance;
264 VirtualSystemModel *mModel;
265
266private:
267 static void initSystemSettings();
268
269 /* Private member vars */
270 static int mMinGuestRAM;
271 static int mMaxGuestRAM;
272 static int mMinGuestCPUCount;
273 static int mMaxGuestCPUCount;
274};
275
276#endif /* __VBoxApplianceEditorWgt_h__ */
277
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use