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