BibleTime
|
#include <btmenuview.h>
Signals | |
void | triggered (QModelIndex index) |
Public Member Functions | |
BtMenuView (QString const &title, QWidget *parent=nullptr) | |
BtMenuView (QWidget *parent=nullptr) | |
bool | event (QEvent *e) override |
QAbstractItemModel * | model () const |
void | setModel (QAbstractItemModel *model) |
~BtMenuView () override | |
Protected Member Functions | |
virtual QAction * | newAction (QMenu *parentMenu, const QModelIndex &itemIndex) |
virtual QMenu * | newMenu (QMenu *parentMenu, const QModelIndex &itemIndex) |
virtual void | postBuildMenu (QActionGroup *actions) |
virtual void | preBuildMenu (QActionGroup *actions) |
void | rebuildMenu () |
Rebuilds the menu. More... | |
Private Member Functions | |
void | buildMenu (QMenu *parentMenu, const QModelIndex &parentIndex) |
void | removeMenus () |
Private Attributes | |
QActionGroup * | m_actions |
QAbstractItemModel * | m_model |
This is a special menu, which shows the contents of an item model. The menu is repopulated with data from the item model each time before its shown, and it does not in any other way react to changes in the model.
The menu is built from items in the model which are below the given parent index. By default this parent index is invalid. When the menu is about to show, all items directly below the parent index are inserted. If a child item has children of its own it is inserted as a QMenu which will be built recursively. Otherwise the child item is inserted as a QAction which may be triggered by the user.
When subclassing this menu, reimplement preBuildMenu() and postBuildMenu() to add new menu items before or after the menu is populated with data from the associated item model. You can also reimplement newAction() and newMenu() if you further want to tune the appearance or behaviour of this menu.
Definition at line 47 of file btmenuview.h.
BtMenuView::BtMenuView | ( | QWidget * | parent = nullptr | ) |
Definition at line 36 of file btmenuview.cpp.
BtMenuView::BtMenuView | ( | QString const & | title, |
QWidget * | parent = nullptr |
||
) |
Definition at line 40 of file btmenuview.cpp.
|
override |
Definition at line 46 of file btmenuview.cpp.
References m_actions.
|
private |
Definition at line 203 of file btmenuview.cpp.
References BT_ASSERT, m_actions, m_model, newAction(), newMenu(), and anonymous_namespace{btmenuview.cpp}::persistentIndexPropertyName.
Referenced by rebuildMenu().
|
override |
Definition at line 75 of file btmenuview.cpp.
References anonymous_namespace{btmenuview.cpp}::rebuildEventType, and rebuildMenu().
|
inline |
Returns a pointer to the data model associated with this menu.
0 | If this menu is not associated to any model. |
Definition at line 66 of file btmenuview.h.
References m_model.
Referenced by BtOpenWorkActionMenu::BtOpenWorkActionMenu(), setModel(), and BtOpenWorkActionMenu::setSourceModel().
|
protectedvirtual |
This method is called by BtMenuView to initialize an action to add to this menu. If the action corresponding to the given index is not to be added to this menu, please return 0.
[in] | parentMenu | the parent menu under which the new action is to be added. |
[in] | itemIndex | the index of the item corresponding to the action. |
Reimplemented in BtModuleChooserMenu.
Definition at line 93 of file btmenuview.cpp.
References m_model.
Referenced by buildMenu(), and BtModuleChooserMenu::newAction().
This method is called by BtMenuView to initialize a menu to add to this menu. If the menu corresponding to the given index is not to be added to this menu, please return 0. If the menu should not be populated by BtMenuView itself, please use setProperty("BtMenuView_NoPopulate", true) on the menu to be returned by this method.
[in] | parentMenu | the parent menu under which the new menu is to be added. |
[in] | itemIndex | the index of the item corresponding to the menu. |
Definition at line 143 of file btmenuview.cpp.
References m_model.
Referenced by buildMenu().
|
protectedvirtual |
This method is called by BtMenuView after populating itself with data from the model. If there was no model set, this method is still called after preBuildMenu(). Reimplement this method to add any menus/actions to this menu after the items of the menu. The default implementation does nothing.
Reimplemented in BtOpenWorkActionMenu.
Definition at line 89 of file btmenuview.cpp.
Referenced by rebuildMenu().
|
protectedvirtual |
This method is called by BtMenuView before populating itself with data from the model. Reimplement this method to add any menus/actions to this menu before the items of the menu. The default implementation does nothing.
The model might be unset before this method is called. When the menu is about to be shown, this allows for this method to initialize the model on request. If the model is unset after this method returns, the menu is not populated with data from the item model.
Reimplemented in BtModuleChooserMenu.
Definition at line 85 of file btmenuview.cpp.
Referenced by rebuildMenu().
|
protected |
Rebuilds the menu.
Definition at line 180 of file btmenuview.cpp.
References BT_CONNECT, buildMenu(), m_actions, m_model, anonymous_namespace{btmenuview.cpp}::persistentIndexPropertyName, postBuildMenu(), preBuildMenu(), removeMenus(), and triggered().
Referenced by event(), setModel(), and BtModuleChooserMenu::update().
|
private |
Definition at line 237 of file btmenuview.cpp.
Referenced by rebuildMenu().
void BtMenuView::setModel | ( | QAbstractItemModel * | model | ) |
Sets or resets the data model for this menu and resets the parent index to an invalid index.
[in] | model | Pointer to the data model to represent. |
Definition at line 50 of file btmenuview.cpp.
References BT_CONNECT, m_model, model(), anonymous_namespace{btmenuview.cpp}::rebuildEventType, and rebuildMenu().
Referenced by BtModuleChooserMenu::BtModuleChooserMenu(), and BtOpenWorkActionMenu::BtOpenWorkActionMenu().
|
signal |
This signal is emitted when the user activates a menu item corresponding to an index in the associated model.
index | The index of the model which was activated. |
Referenced by BtModuleChooserMenu::BtModuleChooserMenu(), BtOpenWorkActionMenu::BtOpenWorkActionMenu(), BtModuleChooserMenu::preBuildMenu(), and rebuildMenu().
|
private |
Definition at line 130 of file btmenuview.h.
Referenced by buildMenu(), rebuildMenu(), and ~BtMenuView().
|
private |
Definition at line 129 of file btmenuview.h.
Referenced by buildMenu(), model(), newAction(), newMenu(), rebuildMenu(), and setModel().