1
/**************************************************************************
2
* Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org> *
3
* Copyright (C) 2007 Will Stephenson <wstephenson@kde.org> *
5
* This program is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU General Public License *
7
* as published by the Free Software Foundation; either version 2 *
8
* of the License, or (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the Free Software *
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19
***************************************************************************/
24
#include <QtCore/QAbstractItemModel>
25
#include "systemsettingsview_export.h"
30
* @brief Provides a menu of the MenuItem objects
32
* Provides a standardised model to be used with views to display the list of modules in a variety of ways.\n
33
* It is recommended to also use this with the MenuProxyModel to provide searching
34
* and correct ordering of modules.
36
* @author Ben Cooksley <bcooksley@kde.org>
37
* @author Will Stephenson <wstephenson@kde.org>
39
class SYSTEMSETTINGSVIEW_EXPORT MenuModel : public QAbstractItemModel
45
* Creates a MenuModel using the MenuItem specified. The MenuItem must always be valid
46
* throughout the life of the MenuModel, otherwise it will cause crashes.
48
* @param menuRoot The MenuItem to use as the basis for providing information.
49
* @param parent The QObject to use as a parent of the MenuModel.
51
explicit MenuModel( MenuItem * menuRoot, QObject *parent = 0 );
54
* Destroys the MenuModel. The menuRoot will not be destroyed.
59
* Please see Qt QAbstractItemModel documentation for more details.\n
60
* Provides the name, tooltip, icon, category, keywords and the internal MenuItem to views.
62
* @param index The QModelIndex you want information about.
63
* @param role The information role you want information about.
64
* @returns The data requested for the role provided from the QModelIndex provided.
66
QVariant data( const QModelIndex &index, int role ) const;
69
* Please see Qt QAbstractItemModel documentation for more details.\n
70
* Provides the status flags for the QModelIndex specified.
71
* The item always has selectable and enabled for its status unless invalid.
73
* @returns The flags for the QModelIndex provided.
75
Qt::ItemFlags flags( const QModelIndex &index ) const;
78
* Please see Qt QAbstractItemModel documentation for more details.\n
79
* Provides a QModelIndex at the row and column specified who belongs to the parent specified.
81
* @param row Vertical position in the grid of children.
82
* @param column Horizontal position in the grid of children.
83
* @param parent The parent of the requested child.
84
* @returns The QModelIndex for the item requested.
86
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
89
* Please see Qt QAbstractItemModel documentation for more details.\n
90
* Provides the parent QModelIndex for the child specified.
92
* @param index The child of the parent.
93
* @returns A QModelIndex for the parent.
95
QModelIndex parent( const QModelIndex &index ) const;
98
* Please see Qt QAbstractItemModel documentation for more details.\n
99
* Provides the number of MenuItems ( categories or modules ) that the specified parent has.
101
* @param parent The QModelIndex the count is performed on.
102
* @returns The number of rows ( children ) in the parent.
104
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
107
* Please see Qt QAbstractItemModel documentation for more details.\n
108
* Returns 1, the number of columns of information about a row.
110
* @param parent This is ignored, as the count is always 1.
111
* @returns The number of columns ( 1 ) in the parent.
113
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
116
* Makes the MenuItem specified be hidden from the list, while still showing its children.\n
117
* Children of exceptions consider their grand parents as their parent.
118
* Parents of exceptions consider the exceptions children as theirs.
120
* @param exception The MenuItem to give an exception to.
122
void addException( MenuItem * exception );
125
* Revokes the exception granted above. After this, the MenuItem's parents will return their children
126
* as normal and the grand children will return their true parents, restoring normal operation.
127
* It has no effect if the MenuItem does not have an exception.
129
* @param exception The MenuItem to revoke an exception from.
131
void removeException( MenuItem * exception );
134
* Role used to request the keywords to filter the items when searching.
136
static const int UserFilterRole;
139
* Role used to request the weight of a module, used to sort the items.
141
static const int UserSortRole;
145
* Provides the MenuItem which is used internally to provide information.
147
* @returns The MenuItem used internally.
149
MenuItem* rootItem() const;
152
* Provides a list of children of an item which has been altered by the exceptions list
154
* @param parent The parent of the children desired
155
* @returns The list of children for the item specified
157
QList<MenuItem*> childrenList( MenuItem * parent ) const;
160
* Provides the parent of the child specified altered by the exceptions list
162
* @param child The child of the parent
163
* @returns The exceptions list affected parent of the child
165
MenuItem* parentItem( MenuItem * child ) const;