~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to systemsettings/core/MenuModel.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 * Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org>                    *
 
3
 * Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>               *
 
4
 *                                                                        *
 
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.                 *
 
9
 *                                                                        *
 
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.                           *
 
14
 *                                                                        *
 
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          *
 
18
 * 02110-1301, USA.                                                       *
 
19
***************************************************************************/
 
20
 
 
21
#ifndef MENUMODEL_H
 
22
#define MENUMODEL_H
 
23
 
 
24
#include <QtCore/QAbstractItemModel>
 
25
#include "systemsettingsview_export.h"
 
26
 
 
27
class MenuItem;
 
28
 
 
29
/**
 
30
 * @brief Provides a menu of the MenuItem objects
 
31
 *
 
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.
 
35
 *
 
36
 * @author Ben Cooksley <bcooksley@kde.org>
 
37
 * @author Will Stephenson <wstephenson@kde.org>
 
38
 */
 
39
class SYSTEMSETTINGSVIEW_EXPORT MenuModel : public QAbstractItemModel
 
40
{
 
41
    Q_OBJECT
 
42
 
 
43
public:
 
44
    /**
 
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.
 
47
     *
 
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.
 
50
     */
 
51
    explicit MenuModel( MenuItem * menuRoot, QObject *parent = 0 );
 
52
 
 
53
    /**
 
54
     * Destroys the MenuModel. The menuRoot will not be destroyed.
 
55
     */
 
56
    ~MenuModel();
 
57
 
 
58
    /**
 
59
     * Please see Qt QAbstractItemModel documentation for more details.\n
 
60
     * Provides the name, tooltip, icon, category, keywords and the internal MenuItem to views.
 
61
     *
 
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.
 
65
     */
 
66
    QVariant data( const QModelIndex &index, int role ) const;
 
67
 
 
68
    /**
 
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.
 
72
     *
 
73
     * @returns The flags for the QModelIndex provided.
 
74
     */
 
75
    Qt::ItemFlags flags( const QModelIndex &index ) const;
 
76
 
 
77
    /**
 
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.
 
80
     *
 
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.
 
85
     */
 
86
    QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
 
87
 
 
88
    /**
 
89
     * Please see Qt QAbstractItemModel documentation for more details.\n
 
90
     * Provides the parent QModelIndex for the child specified.
 
91
     *
 
92
     * @param index The child of the parent.
 
93
     * @returns A QModelIndex for the parent.
 
94
     */
 
95
    QModelIndex parent( const QModelIndex &index ) const;
 
96
 
 
97
    /**
 
98
     * Please see Qt QAbstractItemModel documentation for more details.\n
 
99
     * Provides the number of MenuItems ( categories or modules ) that the specified parent has.
 
100
     *
 
101
     * @param parent The QModelIndex the count is performed on.
 
102
     * @returns The number of rows ( children ) in the parent.
 
103
     */
 
104
    int rowCount( const QModelIndex &parent = QModelIndex() ) const;
 
105
 
 
106
    /**
 
107
     * Please see Qt QAbstractItemModel documentation for more details.\n
 
108
     * Returns 1, the number of columns of information about a row.
 
109
     *
 
110
     * @param parent This is ignored, as the count is always 1.
 
111
     * @returns The number of columns ( 1 ) in the parent.
 
112
     */
 
113
    int columnCount( const QModelIndex &parent = QModelIndex() ) const;
 
114
 
 
115
    /**
 
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.
 
119
     *
 
120
     * @param exception The MenuItem to give an exception to.
 
121
     */
 
122
    void addException( MenuItem * exception );
 
123
 
 
124
    /**
 
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.
 
128
     *
 
129
     * @param exception The MenuItem to revoke an exception from.
 
130
     */
 
131
    void removeException( MenuItem * exception );
 
132
 
 
133
    /**
 
134
     * Role used to request the keywords to filter the items when searching.
 
135
     */
 
136
    static const int UserFilterRole;
 
137
 
 
138
    /**
 
139
     * Role used to request the weight of a module, used to sort the items.
 
140
     */
 
141
    static const int UserSortRole;
 
142
 
 
143
protected:
 
144
    /**
 
145
     * Provides the MenuItem which is used internally to provide information.
 
146
     *
 
147
     * @returns The MenuItem used internally.
 
148
     */
 
149
    MenuItem* rootItem() const;
 
150
 
 
151
    /**
 
152
     * Provides a list of children of an item which has been altered by the exceptions list
 
153
     *
 
154
     * @param parent The parent of the children desired
 
155
     * @returns The list of children for the item specified
 
156
     */
 
157
    QList<MenuItem*> childrenList( MenuItem * parent ) const;
 
158
 
 
159
    /**
 
160
     * Provides the parent of the child specified altered by the exceptions list
 
161
     *
 
162
     * @param child The child of the parent
 
163
     * @returns The exceptions list affected parent of the child
 
164
     */
 
165
    MenuItem* parentItem( MenuItem * child ) const;
 
166
 
 
167
private:
 
168
    class Private;
 
169
    Private *const d;
 
170
};
 
171
 
 
172
#endif