diff options
| author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-04-08 18:13:29 +0200 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-12 17:11:27 +0200 |
| commit | a0cc1951b30282a367db8fd9933101a6c851c15b (patch) | |
| tree | 63c18a5161d3eacccb1050266e4b9affc04bf3b7 /src/controls | |
| parent | 10947feec131b408dd7f5761d07d5e1cf4511728 (diff) | |
| download | qtquickcontrols-a0cc1951b30282a367db8fd9933101a6c851c15b.tar.gz | |
Menu: Add API for inserting items, separators, submenus
In particular, Menu::insertItem() is now overloaded. It can take
a string as second parameter, in which case it will create a new MenuItem
and return it after inserting it, or it can take any QtMenuBase based class
pointer and just insert it. The latter use case is useful when populating
a menu with the Instantiator type.
Currently, addSeparator and insertSeparator don't return any value since
MenuSeparators are not configurable.
Change-Id: I9659ea0ee9d76ed5163316be1a5c7a8f03eaa28f
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls')
| -rw-r--r-- | src/controls/Menu.qml | 13 | ||||
| -rw-r--r-- | src/controls/qtmenu.cpp | 53 | ||||
| -rw-r--r-- | src/controls/qtmenu_p.h | 12 |
3 files changed, 65 insertions, 13 deletions
diff --git a/src/controls/Menu.qml b/src/controls/Menu.qml index 6c2d3cc4..1df73356 100644 --- a/src/controls/Menu.qml +++ b/src/controls/Menu.qml @@ -105,14 +105,23 @@ MenuPrivate { /*! \internal \omit - See qtmenu.cpp. + Documented in qtmenu.cpp. \endomit */ function addMenu(title) { + return root.insertMenu(items.length, title) + } + + /*! \internal + \omit + Documented in qtmenu.cpp. + \endomit + */ + function insertMenu(index, title) { if (!__selfComponent) __selfComponent = Qt.createComponent("Menu.qml", root) var submenu = __selfComponent.createObject(__selfComponent, { "title": title }) - root.insertItem(items.length, submenu) + root.insertItem(index, submenu) return submenu } diff --git a/src/controls/qtmenu.cpp b/src/controls/qtmenu.cpp index 0c0de48a..f40d4603 100644 --- a/src/controls/qtmenu.cpp +++ b/src/controls/qtmenu.cpp @@ -169,17 +169,49 @@ QT_BEGIN_NAMESPACE \qmlmethod MenuItem Menu::addItem(string text) Adds an item to the menu. Returns the newly created \l MenuItem. + + \sa insertItem(int before, string title) */ /*! - \qmlmethod MenuSeparator Menu::addSeparator() + \qmlmethod MenuItem Menu::insertItem(int before, string title) + + Creates and inserts an item with title \c title at the index \c before in the current menu. + Returns the newly created \l MenuItem. + + \sa addItem() +*/ + +/*! + \qmlmethod void Menu::addSeparator() + + Adds a separator to the menu. - Adds a separator to the menu. Returns the newly created \l MenuSeparator. + \sa insertSeparator() +*/ + +/*! + \qmlmethod void Menu::insertSeparator(int before) + + Creates and inserts a separator at the index \c before in the current menu. + + \sa addSeparator() */ /*! \qmlmethod Menu Menu::addMenu(string title) Adds a submenu to the menu. Returns the newly created \l Menu. + + \sa insertMenu() +*/ + +/*! + \qmlmethod MenuItem Menu::insertMenu(int before, string title) + + Creates and inserts a submenu with title \c title at the index \c before in the current menu. + Returns the newly created \l Menu. + + \sa addMenu() */ /*! @@ -478,17 +510,26 @@ int QtMenu::indexOfMenuItem(QtMenuBase *item) const QtMenuItem *QtMenu::addItem(QString title) { + return insertItem(m_itemsCount, title); +} + +QtMenuItem *QtMenu::insertItem(int index, QString title) +{ QtMenuItem *item = new QtMenuItem(this); item->setText(title); - insertItem(m_itemsCount, item); + insertItem(index, item); return item; } -QtMenuSeparator *QtMenu::addSeparator() +void QtMenu::addSeparator() +{ + insertSeparator(m_itemsCount); +} + +void QtMenu::insertSeparator(int index) { QtMenuSeparator *item = new QtMenuSeparator(this); - insertItem(m_itemsCount, item); - return item; + insertItem(index, item); } void QtMenu::insertItem(int index, QtMenuBase *menuItem) diff --git a/src/controls/qtmenu_p.h b/src/controls/qtmenu_p.h index aa23bba2..a258c131 100644 --- a/src/controls/qtmenu_p.h +++ b/src/controls/qtmenu_p.h @@ -74,15 +74,17 @@ class QtMenu : public QtMenuText public: Q_INVOKABLE void popup(); Q_INVOKABLE QtMenuItem *addItem(QString); - Q_INVOKABLE QtMenuSeparator *addSeparator(); + Q_INVOKABLE QtMenuItem *insertItem(int, QString); + Q_INVOKABLE void addSeparator(); + Q_INVOKABLE void insertSeparator(int); + + Q_INVOKABLE void insertItem(int, QtMenuBase *); + Q_INVOKABLE void removeItem(QtMenuBase *); + Q_INVOKABLE void clear(); Q_INVOKABLE void __popup(qreal x, qreal y, int atActionIndex = -1); public Q_SLOTS: - void insertItem(int, QtMenuBase *); - void removeItem(QtMenuBase *); - void clear(); - void __closeMenu(); void __dismissMenu(); |
