Applets
Kickoff::MenuView Class Reference
#include <menuview.h>
Inherits KMenu.
Detailed Description
A view for a QAbstractItemModel which displays the model (set with setModel()) as a hierarchical menu.When the menu is executed and an item is triggered, the model index associated with the chosen item can be found by calling indexForAction() with the triggered action. The action associated with a particular model index can be found using actionForIndex().
MenuView creates actions for parts of the model on demand as the user explores the menu. The type of action created for leaf items in the tree can be changed by re-implementing createLeafAction(). When a new action is created or if the corresponding model index's data changes, updateAction() is called to set the action's properties. This can be reimplemented in sub-classes to change the appearance of the actions.
Definition at line 51 of file menuview.h.
Public Types | |
enum | FormatType { Name = 0, Description, NameDescription, DescriptionName } |
Public Slots | |
void | actionTriggered (QAction *action) |
Public Member Functions | |
QAction * | actionForIndex (const QModelIndex &index) const |
int | column () const |
FormatType | formatType () const |
QModelIndex | indexForAction (QAction *action) const |
UrlItemLauncher * | launcher () const |
MenuView (QWidget *parent=0) | |
QAbstractItemModel * | model () const |
void | setColumn (int column) |
void | setFormatType (FormatType formattype) |
void | setModel (QAbstractItemModel *model) |
virtual | ~MenuView () |
Protected Member Functions | |
virtual QAction * | createLeafAction (const QModelIndex &index, QObject *parent) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
virtual void | updateAction (QAction *action, const QModelIndex &index) |
Member Enumeration Documentation
The format type enumeration.
- Enumerator:
-
Name Name only. Description Description only. NameDescription Name (Description). DescriptionName Description (Name).
Definition at line 86 of file menuview.h.
Constructor & Destructor Documentation
MenuView::MenuView | ( | QWidget * | parent = 0 |
) |
MenuView::~MenuView | ( | ) | [virtual] |
Member Function Documentation
QAction * MenuView::actionForIndex | ( | const QModelIndex & | index | ) | const |
Maps an index in the model to its corresponding action in the menu.
If index
is invalid then menuAction() will be returned. If index
is in a part of the tree which the user has not yet explored then 0 will be returned because the menu hierarchy is constructed on-demand as the user explores the menu.
Definition at line 265 of file menuview.cpp.
void MenuView::actionTriggered | ( | QAction * | action | ) | [slot] |
Definition at line 384 of file menuview.cpp.
int MenuView::column | ( | ) | const |
Returns the column from the model which is used to construct the actions in the menu.
Definition at line 369 of file menuview.cpp.
QAction * MenuView::createLeafAction | ( | const QModelIndex & | index, | |
QObject * | parent | |||
) | [protected, virtual] |
Creates a new action to represent a leaf index in the tree.
A leaf index is one which does not have children. The default implementation creates a new QAction with no properties set. updateAction() is immediately called on the return action to set its text and icon.
- Parameters:
-
index The index in the model for which an action should be created parent The object which should be set as the parent of the new action
Definition at line 103 of file menuview.cpp.
Definition at line 165 of file menuview.cpp.
MenuView::FormatType MenuView::formatType | ( | ) | const |
QModelIndex MenuView::indexForAction | ( | QAction * | action | ) | const |
Maps an action in the menu to its corresponding index in model().
Definition at line 256 of file menuview.cpp.
UrlItemLauncher * MenuView::launcher | ( | ) | const |
Returns the UrlItemLauncher used to handle launching of urls.
Definition at line 251 of file menuview.cpp.
QAbstractItemModel * MenuView::model | ( | ) | const |
void MenuView::setColumn | ( | int | column | ) |
Sets the column from the model which is used to construct the actions in the menu.
Definition at line 363 of file menuview.cpp.
void MenuView::setFormatType | ( | MenuView::FormatType | formattype | ) |
void MenuView::setModel | ( | QAbstractItemModel * | model | ) |
void MenuView::updateAction | ( | QAction * | action, | |
const QModelIndex & | index | |||
) | [protected, virtual] |
Sets the text, icon and other properties of action
using the data associated with index
in the model().
This is called whenever the data for a range of indexes in the tree is altered.
The default implementation sets the action's text to the index's Qt::DisplayRole data and the action's icon to the index's Qt::DecorationRole data.
Definition at line 108 of file menuview.cpp.
The documentation for this class was generated from the following files: