VirtualBox

Changeset 78129 in vbox for trunk


Ignore:
Timestamp:
Apr 15, 2019 6:46:32 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9434: Import Appliance wizard: Advance Form Editor widget with corresponding table-model (empty for now).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.cpp

    r78128 r78129  
    3535#include "CVirtualSystemDescriptionForm.h"
    3636
     37/* VirtualBox interface declarations: */
     38#include <VBox/com/VirtualBox.h>
     39
     40
     41/** Form Editor data types. */
     42enum UIFormEditorDataType
     43{
     44    UIFormEditorDataType_Name,
     45    UIFormEditorDataType_Value,
     46    UIFormEditorDataType_Max
     47};
     48
     49
     50/** QITableViewCell extension used as Form Editor table-view cell. */
     51class UIFormEditorCell : public QITableViewCell
     52{
     53    Q_OBJECT;
     54
     55public:
     56
     57    /** Constructs table cell on the basis of certain @a strText, passing @a pParent to the base-class. */
     58    UIFormEditorCell(QITableViewRow *pParent, const QString &strText);
     59
     60    /** Returns the cell text. */
     61    virtual QString text() const /* override */ { return m_strText; }
     62
     63private:
     64
     65    /** Holds the cell text. */
     66    QString  m_strText;
     67};
     68
     69
     70/** QITableViewRow extension used as Form Editor table-view row. */
     71class UIFormEditorRow : public QITableViewRow
     72{
     73    Q_OBJECT;
     74
     75public:
     76
     77    /** Constructs table row on the basis of certain @a comValue, passing @a pParent to the base-class. */
     78    UIFormEditorRow(QITableView *pParent, const CFormValue &comValue);
     79    /** Destructs table row. */
     80    virtual ~UIFormEditorRow() /* override */;
     81
     82    /** Returns value type. */
     83    KFormValueType valueType() const { return m_enmValueType; }
     84
     85protected:
     86
     87    /** Returns the number of children. */
     88    virtual int childCount() const /* override */;
     89    /** Returns the child item with @a iIndex. */
     90    virtual QITableViewCell *childItem(int iIndex) const /* override */;
     91
     92private:
     93
     94    /** Prepares all. */
     95    void prepare();
     96    /** Cleanups all. */
     97    void cleanup();
     98
     99    /** Holds the row value. */
     100    CFormValue  m_comValue;
     101
     102    /** Holds the value type. */
     103    KFormValueType  m_enmValueType;
     104
     105    /** Holds the cell instances. */
     106    QVector<UIFormEditorCell*>  m_cells;
     107};
     108
     109
     110/** QAbstractTableModel subclass used as Form Editor data model. */
     111class UIFormEditorModel : public QAbstractTableModel
     112{
     113    Q_OBJECT;
     114
     115public:
     116
     117    /** Constructs Form Editor model passing @a pParent to the base-class. */
     118    UIFormEditorModel(QITableView *pParent);
     119    /** Destructs Port Forwarding model. */
     120    virtual ~UIFormEditorModel() /* override */;
     121
     122    /** Defines form @a values. */
     123    void setFormValues(const CFormValueVector &values);
     124
     125    /** Returns the number of children. */
     126    int childCount() const;
     127    /** Returns the child item with @a iIndex. */
     128    QITableViewRow *childItem(int iIndex) const;
     129
     130    /** Returns flags for item with certain @a index. */
     131    Qt::ItemFlags flags(const QModelIndex &index) const;
     132
     133    /** Returns row count of certain @a parent. */
     134    int rowCount(const QModelIndex &parent = QModelIndex()) const;
     135
     136    /** Returns column count of certain @a parent. */
     137    int columnCount(const QModelIndex &parent = QModelIndex()) const;
     138
     139    /** Returns header data for @a iSection, @a enmOrientation and @a iRole specified. */
     140    QVariant headerData(int iSection, Qt::Orientation enmOrientation, int iRole) const;
     141
     142    /** Defines the @a iRole data for item with @a index as @a value. */
     143    bool setData(const QModelIndex &index, const QVariant &value, int iRole = Qt::EditRole);
     144    /** Returns the @a iRole data for item with @a index. */
     145    QVariant data(const QModelIndex &index, int iRole) const;
     146
     147private:
     148
     149    /** Return the parent table-view reference. */
     150    QITableView *parentTable() const;
     151
     152    /** Holds the Form Editor row list. */
     153    QList<UIFormEditorRow*>  m_dataList;
     154};
     155
    37156
    38157/** QITableView extension used as Form Editor table-view. */
     
    56175
    57176/*********************************************************************************************************************************
     177*   Class UIFormEditorCell implementation.                                                                                       *
     178*********************************************************************************************************************************/
     179
     180UIFormEditorCell::UIFormEditorCell(QITableViewRow *pParent, const QString &strText)
     181    : QITableViewCell(pParent)
     182    , m_strText(strText)
     183{
     184}
     185
     186
     187/*********************************************************************************************************************************
     188*   Class UIFormEditorRow implementation.                                                                                        *
     189*********************************************************************************************************************************/
     190
     191UIFormEditorRow::UIFormEditorRow(QITableView *pParent, const CFormValue &comValue)
     192    : QITableViewRow(pParent)
     193    , m_comValue(comValue)
     194    , m_enmValueType(KFormValueType_Max)
     195{
     196    prepare();
     197}
     198
     199UIFormEditorRow::~UIFormEditorRow()
     200{
     201    cleanup();
     202}
     203
     204int UIFormEditorRow::childCount() const
     205{
     206    /* Return cell count: */
     207    return UIFormEditorDataType_Max;
     208}
     209
     210QITableViewCell *UIFormEditorRow::childItem(int iIndex) const
     211{
     212    /* Make sure index within the bounds: */
     213    AssertReturn(iIndex >= 0 && iIndex < m_cells.size(), 0);
     214    /* Return corresponding cell: */
     215    return m_cells.at(iIndex);
     216}
     217
     218void UIFormEditorRow::prepare()
     219{
     220    /* Cache value type: */
     221    m_enmValueType = m_comValue.GetType();
     222
     223    /* Create cells on the basis of variables we have: */
     224    m_cells.resize(UIFormEditorDataType_Max);
     225    m_cells[UIFormEditorDataType_Name] = new UIFormEditorCell(this, m_comValue.GetLabel());
     226    switch (m_enmValueType)
     227    {
     228        case KFormValueType_Boolean:
     229        {
     230            CBooleanFormValue comValue(m_comValue);
     231            m_cells[UIFormEditorDataType_Value] = new UIFormEditorCell(this, comValue.GetSelected() ? "True" : "False");
     232            break;
     233        }
     234        case KFormValueType_String:
     235        {
     236            CStringFormValue comValue(m_comValue);
     237            m_cells[UIFormEditorDataType_Value] = new UIFormEditorCell(this, comValue.GetString());
     238            break;
     239        }
     240        case KFormValueType_Choice:
     241        {
     242            CChoiceFormValue comValue(m_comValue);
     243            const QVector<QString> values = comValue.GetValues();
     244            m_cells[UIFormEditorDataType_Value] = new UIFormEditorCell(this, values.at(comValue.GetSelectedIndex()));
     245            break;
     246        }
     247        default:
     248            break;
     249    }
     250}
     251
     252void UIFormEditorRow::cleanup()
     253{
     254    /* Destroy cells: */
     255    qDeleteAll(m_cells);
     256    m_cells.clear();
     257}
     258
     259
     260/*********************************************************************************************************************************
     261*   Class UIFormEditorModel implementation.                                                                                      *
     262*********************************************************************************************************************************/
     263
     264UIFormEditorModel::UIFormEditorModel(QITableView *pParent)
     265    : QAbstractTableModel(pParent)
     266{
     267}
     268
     269UIFormEditorModel::~UIFormEditorModel()
     270{
     271    /* Delete the cached data: */
     272    qDeleteAll(m_dataList);
     273    m_dataList.clear();
     274}
     275
     276void UIFormEditorModel::setFormValues(const CFormValueVector &values)
     277{
     278    /* Delete old lines: */
     279    beginRemoveRows(QModelIndex(), 0, m_dataList.size());
     280    qDeleteAll(m_dataList);
     281    m_dataList.clear();
     282    endRemoveRows();
     283
     284    /* Add new lines: */
     285    beginInsertRows(QModelIndex(), 0, values.size());
     286    foreach (const CFormValue &comValue, values)
     287        m_dataList << new UIFormEditorRow(parentTable(), comValue);
     288    endInsertRows();
     289}
     290
     291int UIFormEditorModel::childCount() const
     292{
     293    return rowCount();
     294}
     295
     296QITableViewRow *UIFormEditorModel::childItem(int iIndex) const
     297{
     298    /* Make sure index within the bounds: */
     299    AssertReturn(iIndex >= 0 && iIndex < m_dataList.size(), 0);
     300    /* Return corresponding row: */
     301    return m_dataList[iIndex];
     302}
     303
     304Qt::ItemFlags UIFormEditorModel::flags(const QModelIndex &index) const
     305{
     306    /* Check index validness: */
     307    if (!index.isValid())
     308        return Qt::NoItemFlags;
     309    /* Return wrong value: */
     310    return Qt::NoItemFlags;
     311}
     312
     313int UIFormEditorModel::rowCount(const QModelIndex &) const
     314{
     315    return m_dataList.size();
     316}
     317
     318int UIFormEditorModel::columnCount(const QModelIndex &) const
     319{
     320    return UIFormEditorDataType_Max;
     321}
     322
     323QVariant UIFormEditorModel::headerData(int iSection, Qt::Orientation enmOrientation, int iRole) const
     324{
     325    Q_UNUSED(iSection);
     326    Q_UNUSED(enmOrientation);
     327    Q_UNUSED(iRole);
     328
     329    /* Return wrong value: */
     330    return QVariant();
     331}
     332
     333bool UIFormEditorModel::setData(const QModelIndex &index, const QVariant &value, int iRole /* = Qt::EditRole */)
     334{
     335    Q_UNUSED(value);
     336
     337    /* Check index validness: */
     338    if (!index.isValid() || iRole != Qt::EditRole)
     339        return false;
     340    /* Return wrong value: */
     341    return false;
     342}
     343
     344QVariant UIFormEditorModel::data(const QModelIndex &index, int iRole) const
     345{
     346    Q_UNUSED(iRole);
     347
     348    /* Check index validness: */
     349    if (!index.isValid())
     350        return QVariant();
     351    /* Return wrong value: */
     352    return QVariant();
     353}
     354
     355QITableView *UIFormEditorModel::parentTable() const
     356{
     357    return qobject_cast<QITableView*>(parent());
     358}
     359
     360
     361/*********************************************************************************************************************************
    58362*   Class UIFormEditorView implementation.                                                                                       *
    59363*********************************************************************************************************************************/
     
    65369int UIFormEditorView::childCount() const
    66370{
    67     /* No model => no children: */
    68     return 0;
     371    /* Redirect request to model: */
     372    AssertPtrReturn(model(), 0);
     373    return qobject_cast<UIFormEditorModel*>(model())->childCount();
    69374}
    70375
    71376QITableViewRow *UIFormEditorView::childItem(int iIndex) const
    72377{
    73     Q_UNUSED(iIndex);
    74 
    75     /* No model => no children: */
    76     return 0;
     378    /* Redirect request to model: */
     379    AssertPtrReturn(model(), 0);
     380    return qobject_cast<UIFormEditorModel*>(model())->childItem(iIndex);
    77381}
    78382
     
    85389    : QWidget(pParent)
    86390    , m_pTableView(0)
     391    , m_pTableModel(0)
    87392{
    88393    prepare();
     394}
     395
     396void UIFormEditorWidget::setVirtualSystemDescriptionForm(const CVirtualSystemDescriptionForm &comForm)
     397{
     398    AssertPtrReturnVoid(m_pTableModel);
     399    /// @todo add some check..
     400    m_pTableModel->setFormValues(comForm.GetValues());
    89401}
    90402
     
    104416            m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection);
    105417
     418            /* Create model: */
     419            m_pTableModel = new UIFormEditorModel(m_pTableView);
     420            if (m_pTableModel)
     421                m_pTableView->setModel(m_pTableModel);
     422
    106423            /* Add into layout: */
    107424            pLayout->addWidget(m_pTableView);
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.h

    r78128 r78129  
    2626
    2727/* Forward declarations: */
     28class UIFormEditorModel;
    2829class UIFormEditorView;
     30class CVirtualSystemDescriptionForm;
    2931
    3032
     
    3941    UIFormEditorWidget(QWidget *pParent = 0);
    4042
     43    /** Defines virtual system description @a comForm to be edited. */
     44    void setVirtualSystemDescriptionForm(const CVirtualSystemDescriptionForm &comForm);
     45
    4146private:
    4247
     
    4651    /** Holds the table-view instance. */
    4752    UIFormEditorView  *m_pTableView;
     53    /** Holds the table-model instance. */
     54    UIFormEditorModel *m_pTableModel;
    4855};
    4956
Note: See TracChangeset for help on using the changeset viewer.

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