3
* VBox frontends: Qt4 GUI ("VirtualBox"):
4
* VBoxApplianceEditorWgt class declaration
8
* Copyright (C) 2009 Sun Microsystems, Inc.
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.
18
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19
* Clara, CA 95054 USA or visit http://www.sun.com if you need
20
* additional information or have any questions.
23
#ifndef __VBoxApplianceEditorWgt_h__
24
#define __VBoxApplianceEditorWgt_h__
28
#include "VBoxApplianceEditorWgt.gen.h"
29
#include "QIWithRetranslateUI.h"
32
#include <QSortFilterProxyModel>
33
#include <QItemDelegate>
35
/* VBox forward declarations */
38
////////////////////////////////////////////////////////////////////////////////
41
enum TreeViewSection { DescriptionSection = 0, OriginalValueSection, ConfigValueSection };
43
////////////////////////////////////////////////////////////////////////////////
46
enum ModelItemType { RootType, VirtualSystemType, HardwareType };
48
/* This & the following derived classes represent the data items of a Virtual
49
System. All access/manipulation is done with the help of virtual functions
50
to keep the interface clean. ModelItem is able to handle tree structures
51
with a parent & several children's. */
55
ModelItem (int aNumber, ModelItemType aType, ModelItem *aParent = NULL);
59
ModelItem *parent() const { return mParentItem; }
61
void appendChild (ModelItem *aChild);
62
ModelItem * child (int aRow) const;
66
int childCount() const;
67
int columnCount() const { return 3; }
69
virtual Qt::ItemFlags itemFlags (int /* aColumn */) const { return 0; }
70
virtual bool setData (int /* aColumn */, const QVariant & /* aValue */, int /* aRole */) { return false; }
71
virtual QVariant data (int /* aColumn */, int /* aRole */) const { return QVariant(); }
72
virtual QWidget * createEditor (QWidget * /* aParent */, const QStyleOptionViewItem & /* aOption */, const QModelIndex & /* aIndex */) const { return NULL; }
73
virtual bool setEditorData (QWidget * /* aEditor */, const QModelIndex & /* aIndex */) const { return false; }
74
virtual bool setModelData (QWidget * /* aEditor */, QAbstractItemModel * /* aModel */, const QModelIndex & /* aIndex */) { return false; }
76
virtual void restoreDefaults() {}
77
virtual void putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues);
79
ModelItemType type() const { return mType; }
82
/* Protected member vars */
86
ModelItem *mParentItem;
87
QList<ModelItem*> mChildItems;
90
////////////////////////////////////////////////////////////////////////////////
93
/* This class represent a Virtual System with an index. */
94
class VirtualSystemItem: public ModelItem
97
VirtualSystemItem (int aNumber, CVirtualSystemDescription aDesc, ModelItem *aParent);
99
virtual QVariant data (int aColumn, int aRole) const;
101
virtual void putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues);
104
CVirtualSystemDescription mDesc;
107
////////////////////////////////////////////////////////////////////////////////
110
/* This class represent an hardware item of a Virtual System. All values of
111
KVirtualSystemDescriptionType are supported & handled differently. */
112
class HardwareItem: public ModelItem
114
friend class VirtualSystemSortProxyModel;
117
HardwareItem (int aNumber,
118
KVirtualSystemDescriptionType aType,
120
const QString &aOrigValue,
121
const QString &aConfigValue,
122
const QString &aExtraConfigValue,
125
virtual void putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues);
127
virtual bool setData (int aColumn, const QVariant &aValue, int aRole);
128
virtual QVariant data (int aColumn, int aRole) const;
130
virtual Qt::ItemFlags itemFlags (int aColumn) const;
132
virtual QWidget * createEditor (QWidget *aParent, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
133
virtual bool setEditorData (QWidget *aEditor, const QModelIndex &aIndex) const;
135
virtual bool setModelData (QWidget *aEditor, QAbstractItemModel *aModel, const QModelIndex &aIndex);
137
virtual void restoreDefaults()
139
mConfigValue = mConfigDefaultValue;
140
mCheckState = Qt::Checked;
145
/* Private member vars */
146
KVirtualSystemDescriptionType mType;
149
QString mConfigValue;
150
QString mConfigDefaultValue;
151
QString mExtraConfigValue;
152
Qt::CheckState mCheckState;
155
////////////////////////////////////////////////////////////////////////////////
156
// VirtualSystemModel
158
class VirtualSystemModel: public QAbstractItemModel
162
VirtualSystemModel (QVector<CVirtualSystemDescription>& aVSDs, QObject *aParent = NULL);
164
QModelIndex index (int aRow, int aColumn, const QModelIndex &aParent = QModelIndex()) const;
165
QModelIndex parent (const QModelIndex &aIndex) const;
166
int rowCount (const QModelIndex &aParent = QModelIndex()) const;
167
int columnCount (const QModelIndex &aParent = QModelIndex()) const;
168
bool setData (const QModelIndex &aIndex, const QVariant &aValue, int aRole);
169
QVariant data (const QModelIndex &aIndex, int aRole = Qt::DisplayRole) const;
170
Qt::ItemFlags flags (const QModelIndex &aIndex) const;
171
QVariant headerData (int aSection, Qt::Orientation aOrientation, int aRole) const;
173
QModelIndex buddy (const QModelIndex &aIndex) const;
175
void restoreDefaults (const QModelIndex& aParent = QModelIndex());
179
/* Private member vars */
180
ModelItem *mRootItem;
183
////////////////////////////////////////////////////////////////////////////////
184
// VirtualSystemDelegate
186
/* The delegate is used for creating/handling the different editors for the
187
various types we support. This class forward the requests to the virtual
188
methods of our different ModelItems. If this is not possible the default
189
methods of QItemDelegate are used to get some standard behavior. Note: We
190
have to handle the proxy model ourself. I really don't understand why Qt is
191
not doing this for us. */
192
class VirtualSystemDelegate: public QItemDelegate
195
VirtualSystemDelegate (QAbstractProxyModel *aProxy, QObject *aParent = NULL);
197
QWidget * createEditor (QWidget *aParent, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
198
void setEditorData (QWidget *aEditor, const QModelIndex &aIndex) const;
199
void setModelData (QWidget *aEditor, QAbstractItemModel *aModel, const QModelIndex &aIndex) const;
200
void updateEditorGeometry (QWidget *aEditor, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
202
QSize sizeHint (const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const
204
QSize size = QItemDelegate::sizeHint (aOption, aIndex);
209
#endif /* Q_WS_MAC */
210
size.setHeight (RT_MAX (h, size.height()));
214
/* Private member vars */
215
QAbstractProxyModel *mProxy;
218
////////////////////////////////////////////////////////////////////////////////
219
// VirtualSystemSortProxyModel
221
class VirtualSystemSortProxyModel: public QSortFilterProxyModel
224
VirtualSystemSortProxyModel (QObject *aParent = NULL);
227
bool filterAcceptsRow (int aSourceRow, const QModelIndex & aSourceParent) const;
228
bool lessThan (const QModelIndex &aLeft, const QModelIndex &aRight) const;
230
static KVirtualSystemDescriptionType mSortList[];
232
QList<KVirtualSystemDescriptionType> mFilterList;
235
////////////////////////////////////////////////////////////////////////////////
236
// VBoxApplianceEditorWgt
238
class VBoxApplianceEditorWgt : public QIWithRetranslateUI<QWidget>,
239
public Ui::VBoxApplianceEditorWgt
244
VBoxApplianceEditorWgt (QWidget *aParent = NULL);
246
bool isValid() const { return mAppliance != NULL; }
247
CAppliance* appliance() const { return mAppliance; }
249
static int minGuestRAM() { return mMinGuestRAM; }
250
static int maxGuestRAM() { return mMaxGuestRAM; }
251
static int minGuestCPUCount() { return mMinGuestCPUCount; }
252
static int maxGuestCPUCount() { return mMaxGuestCPUCount; }
255
void restoreDefaults();
258
virtual void retranslateUi();
260
/* Protected member vars */
261
CAppliance *mAppliance;
262
VirtualSystemModel *mModel;
265
static void initSystemSettings();
267
/* Private member vars */
268
static int mMinGuestRAM;
269
static int mMaxGuestRAM;
270
static int mMinGuestCPUCount;
271
static int mMaxGuestCPUCount;
274
#endif /* __VBoxApplianceEditorWgt_h__ */