- Timestamp:
- Apr 14, 2016 2:11:52 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r60362 r60496 526 526 src/extensions/QISplitter.cpp \ 527 527 src/extensions/QIAdvancedToolBar.cpp \ 528 src/extensions/QITableView.cpp \ 528 529 src/extradata/UIExtraDataManager.cpp \ 529 530 src/globals/UIActionPool.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.cpp
r60495 r60496 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* Qt includes: */ 23 # include <QStyledItemDelegate> 24 22 25 /* GUI includes: */ 23 26 # include "QITableView.h" 27 28 /* Other VBox includes: */ 29 # include "iprt/assert.h" 24 30 25 31 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 26 32 27 33 34 /** QStyledItemDelegate extension used with QITableView. */ 35 class QITableViewStyledItemDelegate : public QStyledItemDelegate 36 { 37 Q_OBJECT; 38 39 signals: 40 41 /** Notifies listeners about @a pEditor created for particular model @a index. */ 42 void sigEditorCreated(QWidget *pEditor, const QModelIndex &index) const; 43 44 public: 45 46 /** Constructs table-view styled-item-delegate on the basis of passed @a pParent. */ 47 QITableViewStyledItemDelegate(QObject *pParent); 48 49 private: 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 62 QITableViewStyledItemDelegate::QITableViewStyledItemDelegate(QObject *pParent) 63 : QStyledItemDelegate(pParent) 64 { 65 } 66 67 QWidget* 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 28 82 QITableView::QITableView(QWidget *pParent) 29 83 : QTableView(pParent) 30 84 { 85 /* Prepare all: */ 86 prepare(); 87 } 88 89 void 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 106 void 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 122 void 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 129 void 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); 31 135 } 32 136 … … 39 143 } 40 144 145 #include "QITableView.moc" 146 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.h
r60495 r60496 37 37 QITableView(QWidget *pParent = 0); 38 38 39 /** Makes sure current editor data committed. */ 40 void makeSureEditorDataCommitted(); 41 39 42 protected: 43 44 /** Prepares all. */ 45 void prepare(); 40 46 41 47 /** Handles index change from @a previous to @a current. */ 42 48 virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) /* override */; 49 50 protected 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 57 private: 58 59 /** Holds the map of editors stored for passed indexes. */ 60 QMap<QModelIndex, QObject*> m_editors; 43 61 }; 44 62 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsPortForwardingDlg.cpp
r57384 r60496 86 86 void UIGlobalSettingsPortForwardingDlg::accept() 87 87 { 88 /* Make sure both tables have their data committed: */ 89 m_pIPv4Table->makeSureEditorDataCommitted(); 90 m_pIPv6Table->makeSureEditorDataCommitted(); 88 91 /* Validate table: */ 89 92 bool fPassed = m_pIPv4Table->validate() && m_pIPv6Table->validate(); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsPortForwardingDlg.cpp
r57384 r60496 70 70 void UIMachineSettingsPortForwardingDlg::accept() 71 71 { 72 /* Make sure table has own data committed: */ 73 m_pTable->makeSureEditorDataCommitted(); 72 74 /* Validate table: */ 73 75 bool fPassed = m_pTable->validate(); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp
r60478 r60496 691 691 } 692 692 693 void UIPortForwardingTable::makeSureEditorDataCommitted() 694 { 695 m_pTableView->makeSureEditorDataCommitted(); 696 } 697 693 698 void UIPortForwardingTable::sltAddRule() 694 699 { -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.h
r57384 r60496 139 139 bool isChanged() const { return m_fIsTableDataChanged; } 140 140 141 /** Makes sure current editor data committed. */ 142 void makeSureEditorDataCommitted(); 143 141 144 private slots: 142 145
Note:
See TracChangeset
for help on using the changeset viewer.