Changeset View
Changeset View
Standalone View
Standalone View
core/MenuModel.cpp
Show All 17 Lines | |||||
18 | * 02110-1301, USA. * | 18 | * 02110-1301, USA. * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "MenuModel.h" | 21 | #include "MenuModel.h" | ||
22 | 22 | | |||
23 | #include <KCategorizedSortFilterProxyModel> | 23 | #include <KCategorizedSortFilterProxyModel> | ||
24 | #include <QIcon> | 24 | #include <QIcon> | ||
25 | #include "MenuItem.h" | 25 | #include "MenuItem.h" | ||
26 | 26 | | |||
meven: not needed | |||||
27 | | ||||
28 | class MenuModel::Private { | 27 | class MenuModel::Private { | ||
29 | public: | 28 | public: | ||
30 | Private() {} | 29 | Private() {} | ||
31 | 30 | | |||
32 | MenuItem *rootItem = nullptr; | 31 | MenuItem *rootItem = nullptr; | ||
33 | QList<MenuItem*> exceptions; | 32 | QList<MenuItem*> exceptions; | ||
34 | }; | 33 | }; | ||
35 | 34 | | |||
Show All 27 Lines | |||||
63 | int MenuModel::rowCount( const QModelIndex &parent ) const | 62 | int MenuModel::rowCount( const QModelIndex &parent ) const | ||
64 | { | 63 | { | ||
65 | MenuItem * mi; | 64 | MenuItem * mi; | ||
66 | if ( parent.isValid() ) { | 65 | if ( parent.isValid() ) { | ||
67 | mi = static_cast<MenuItem*>( parent.internalPointer() ); | 66 | mi = static_cast<MenuItem*>( parent.internalPointer() ); | ||
68 | } else { | 67 | } else { | ||
69 | mi = d->rootItem; | 68 | mi = d->rootItem; | ||
70 | } | 69 | } | ||
71 | | ||||
72 | return childrenList(mi).count(); | 70 | return childrenList(mi).count(); | ||
73 | } | 71 | } | ||
74 | 72 | | |||
75 | QVariant MenuModel::data( const QModelIndex &index, int role ) const | 73 | QVariant MenuModel::data( const QModelIndex &index, int role ) const | ||
76 | { | 74 | { | ||
77 | MenuItem * mi = nullptr; | 75 | MenuItem * mi = nullptr; | ||
78 | QVariant theData; | 76 | QVariant theData; | ||
79 | if ( !index.isValid() ) { | 77 | if ( !index.isValid() ) { | ||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | |||||
206 | { | 204 | { | ||
207 | MenuItem * parent = child->parent(); | 205 | MenuItem * parent = child->parent(); | ||
208 | if( d->exceptions.contains(parent) ) { | 206 | if( d->exceptions.contains(parent) ) { | ||
209 | parent = parentItem(parent); | 207 | parent = parentItem(parent); | ||
210 | } | 208 | } | ||
211 | return parent; | 209 | return parent; | ||
212 | } | 210 | } | ||
213 | 211 | | |||
212 | QModelIndex MenuModel::indexForItem( MenuItem * item ) const | ||||
213 | { | ||||
214 | MenuItem * parent = parentItem(item); | ||||
215 | | ||||
216 | if (!parent) { | ||||
217 | return QModelIndex(); | ||||
218 | } | ||||
219 | | ||||
220 | const int row = childrenList(parent).indexOf(item); | ||||
221 | | ||||
222 | if (row < 0) { | ||||
223 | return QModelIndex(); | ||||
224 | } | ||||
225 | | ||||
226 | return createIndex(row, 0, item); | ||||
227 | } | ||||
228 | | ||||
214 | MenuItem * MenuModel::rootItem() const | 229 | MenuItem * MenuModel::rootItem() const | ||
215 | { | 230 | { | ||
216 | return d->rootItem; | 231 | return d->rootItem; | ||
217 | } | 232 | } | ||
218 | 233 | | |||
219 | void MenuModel::addException( MenuItem * exception ) | 234 | void MenuModel::addException( MenuItem * exception ) | ||
220 | { | 235 | { | ||
221 | if( exception == d->rootItem ) { | 236 | if( exception == d->rootItem ) { | ||
Show All 11 Lines |
not needed