VirtualBox

Changeset 60496 in vbox for trunk


Ignore:
Timestamp:
Apr 14, 2016 2:11:52 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: ​​bugref:7456: Port Forwarding UI: Possibility to manually commit embedded-editor data to QITableView. It's used in Port Forwarding UI to prevent loosing edited data when dialog is closed with Ok while editor still opened.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r60362 r60496  
    526526        src/extensions/QISplitter.cpp \
    527527        src/extensions/QIAdvancedToolBar.cpp \
     528        src/extensions/QITableView.cpp \
    528529        src/extradata/UIExtraDataManager.cpp \
    529530        src/globals/UIActionPool.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.cpp

    r60495 r60496  
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
     22/* Qt includes: */
     23# include <QStyledItemDelegate>
     24
    2225/* GUI includes: */
    2326# include "QITableView.h"
     27
     28/* Other VBox includes: */
     29# include "iprt/assert.h"
    2430
    2531#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2632
    2733
     34/** QStyledItemDelegate extension used with QITableView. */
     35class QITableViewStyledItemDelegate : public QStyledItemDelegate
     36{
     37    Q_OBJECT;
     38
     39signals:
     40
     41    /** Notifies listeners about @a pEditor created for particular model @a index. */
     42    void sigEditorCreated(QWidget *pEditor, const QModelIndex &index) const;
     43
     44public:
     45
     46    /** Constructs table-view styled-item-delegate on the basis of passed @a pParent. */
     47    QITableViewStyledItemDelegate(QObject *pParent);
     48
     49private:
     50
     51    /** Returns the widget used to edit the item specified by @a index for editing.
     52      * The @a pParent widget and style @a option are used to control how the editor widget appears.
     53      * Besides that, we are notifying listener about editor was created for particular model @a index. */
     54    virtual QWidget* createEditor(QWidget *pParent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
     55};
     56
     57
     58/*********************************************************************************************************************************
     59*   Class QITableViewStyledItemDelegate implementation.                                                                          *
     60*********************************************************************************************************************************/
     61
     62QITableViewStyledItemDelegate::QITableViewStyledItemDelegate(QObject *pParent)
     63    : QStyledItemDelegate(pParent)
     64{
     65}
     66
     67QWidget* QITableViewStyledItemDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem &option, const QModelIndex &index) const
     68{
     69    /* Call to base-class: */
     70    QWidget *pEditor = QStyledItemDelegate::createEditor(pParent, option, index);
     71    /* Notify listeners about editor created: */
     72    emit sigEditorCreated(pEditor, index);
     73    /* Return editor: */
     74    return pEditor;
     75}
     76
     77
     78/*********************************************************************************************************************************
     79*   Class QITableView implementation.                                                                                            *
     80*********************************************************************************************************************************/
     81
    2882QITableView::QITableView(QWidget *pParent)
    2983    : QTableView(pParent)
    3084{
     85    /* Prepare all: */
     86    prepare();
     87}
     88
     89void QITableView::makeSureEditorDataCommitted()
     90{
     91    /* Do we have current editor at all? */
     92    QObject *pEditorObject = m_editors.value(currentIndex());
     93    if (pEditorObject && pEditorObject->isWidgetType())
     94    {
     95        /* Cast the editor to widget type: */
     96        QWidget *pEditor = qobject_cast<QWidget*>(pEditorObject);
     97        AssertPtrReturnVoid(pEditor);
     98        {
     99            /* Commit the editor data and closes it: */
     100            commitData(pEditor);
     101            closeEditor(pEditor, QAbstractItemDelegate::SubmitModelCache);
     102        }
     103    }
     104}
     105
     106void QITableView::prepare()
     107{
     108    /* Delete old delegate: */
     109    delete itemDelegate();
     110    /* Create new delegate: */
     111    QITableViewStyledItemDelegate *pStyledItemDelegate = new QITableViewStyledItemDelegate(this);
     112    AssertPtrReturnVoid(pStyledItemDelegate);
     113    {
     114        /* Assign newly created delegate to the table: */
     115        setItemDelegate(pStyledItemDelegate);
     116        /* Connect newly created delegate to the table: */
     117        connect(pStyledItemDelegate, SIGNAL(sigEditorCreated(QWidget *, const QModelIndex &)),
     118                this, SLOT(sltEditorCreated(QWidget *, const QModelIndex &)));
     119    }
     120}
     121
     122void QITableView::sltEditorCreated(QWidget *pEditor, const QModelIndex &index)
     123{
     124    /* Connect created editor to the table and store it: */
     125    connect(pEditor, SIGNAL(destroyed(QObject *)), this, SLOT(sltEditorDestroyed(QObject *)));
     126    m_editors[index] = pEditor;
     127}
     128
     129void QITableView::sltEditorDestroyed(QObject *pEditor)
     130{
     131    /* Clear destroyed editor from the table: */
     132    QModelIndex index = m_editors.key(pEditor);
     133    AssertReturnVoid(index.isValid());
     134    m_editors.remove(index);
    31135}
    32136
     
    39143}
    40144
     145#include "QITableView.moc"
     146
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.h

    r60495 r60496  
    3737    QITableView(QWidget *pParent = 0);
    3838
     39    /** Makes sure current editor data committed. */
     40    void makeSureEditorDataCommitted();
     41
    3942protected:
     43
     44    /** Prepares all. */
     45    void prepare();
    4046
    4147    /** Handles index change from @a previous to @a current. */
    4248    virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous) /* override */;
     49
     50protected slots:
     51
     52    /** Stores the created @a pEditor for passed @a index in the map. */
     53    void sltEditorCreated(QWidget *pEditor, const QModelIndex &index);
     54    /** Clears the destoyed @a pEditor from the map. */
     55    void sltEditorDestroyed(QObject *pEditor);
     56
     57private:
     58
     59    /** Holds the map of editors stored for passed indexes. */
     60    QMap<QModelIndex, QObject*> m_editors;
    4361};
    4462
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsPortForwardingDlg.cpp

    r57384 r60496  
    8686void UIGlobalSettingsPortForwardingDlg::accept()
    8787{
     88    /* Make sure both tables have their data committed: */
     89    m_pIPv4Table->makeSureEditorDataCommitted();
     90    m_pIPv6Table->makeSureEditorDataCommitted();
    8891    /* Validate table: */
    8992    bool fPassed = m_pIPv4Table->validate() && m_pIPv6Table->validate();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsPortForwardingDlg.cpp

    r57384 r60496  
    7070void UIMachineSettingsPortForwardingDlg::accept()
    7171{
     72    /* Make sure table has own data committed: */
     73    m_pTable->makeSureEditorDataCommitted();
    7274    /* Validate table: */
    7375    bool fPassed = m_pTable->validate();
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp

    r60478 r60496  
    691691}
    692692
     693void UIPortForwardingTable::makeSureEditorDataCommitted()
     694{
     695    m_pTableView->makeSureEditorDataCommitted();
     696}
     697
    693698void UIPortForwardingTable::sltAddRule()
    694699{
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.h

    r57384 r60496  
    139139    bool isChanged() const { return m_fIsTableDataChanged; }
    140140
     141    /** Makes sure current editor data committed. */
     142    void makeSureEditorDataCommitted();
     143
    141144private slots:
    142145
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