|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: caitemmodel.h |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CASTANDARDITEMMODEL_H |
|
19 #define CASTANDARDITEMMODEL_H |
|
20 |
|
21 // System includes |
|
22 #include <QAbstractItemModel> |
|
23 #include <QAbstractItemView> |
|
24 |
|
25 #include "caquery.h" |
|
26 #include "caentry.h" |
|
27 // Forward declarations |
|
28 class CaEntry; |
|
29 |
|
30 // mock Class declaration |
|
31 class CaItemModel: public QAbstractItemModel |
|
32 { |
|
33 |
|
34 Q_OBJECT |
|
35 |
|
36 public: |
|
37 mutable CaQuery mCaItemModelQuery; |
|
38 mutable QVariant mDataResult; |
|
39 mutable QModelIndex mDataIndex; |
|
40 mutable QModelIndex mIndexResult; |
|
41 mutable QModelIndex mRootResult; |
|
42 mutable QModelIndex mParentResult; |
|
43 mutable int mDataRole; |
|
44 mutable int mRowCountResult; |
|
45 mutable int mColumnCountResult; |
|
46 mutable SortAttribute mSetSortAttribute; |
|
47 mutable Qt::SortOrder mSetSortOrder; |
|
48 mutable bool mSecondLineVisibilityResult; |
|
49 mutable bool mIsAutoUpdateResult; |
|
50 mutable QSizeF mGetIconSizeResult; |
|
51 mutable QSharedPointer<CaEntry> mEntryResult; |
|
52 // Data types |
|
53 enum CaItemRole |
|
54 { |
|
55 IdRole = Qt::UserRole + 1, |
|
56 ParentIdRole, |
|
57 TypeRole, |
|
58 FlagsRole, |
|
59 TextRole,//contains title represented as QString, |
|
60 FullTextRole //'title description' convinient for operations such as search |
|
61 }; |
|
62 |
|
63 // Function declarations |
|
64 CaItemModel(const CaQuery &query, QObject *parent = 0): |
|
65 QAbstractItemModel(parent), |
|
66 mCaItemModelQuery(query), |
|
67 mDataRole(0), |
|
68 mSecondLineVisibilityResult(false), |
|
69 mIsAutoUpdateResult(false), |
|
70 mEntryResult(new CaEntry) |
|
71 { |
|
72 } |
|
73 |
|
74 ~CaItemModel(){} |
|
75 |
|
76 int columnCount(const QModelIndex &parent = QModelIndex()) const |
|
77 { |
|
78 Q_UNUSED(parent); |
|
79 return mColumnCountResult; |
|
80 } |
|
81 int rowCount(const QModelIndex &parent = QModelIndex()) const |
|
82 { |
|
83 Q_UNUSED(parent); |
|
84 return mRowCountResult; |
|
85 } |
|
86 virtual QModelIndex index(int row, int column = 0, |
|
87 const QModelIndex &parent = QModelIndex()) const |
|
88 { |
|
89 Q_UNUSED(parent); |
|
90 return createIndex(row, column); |
|
91 } |
|
92 |
|
93 virtual QModelIndex parent(const QModelIndex &index) const |
|
94 { |
|
95 Q_UNUSED(index); |
|
96 return mParentResult; |
|
97 } |
|
98 |
|
99 QModelIndex root() const |
|
100 { |
|
101 return mRootResult; |
|
102 } |
|
103 |
|
104 virtual QVariant data(const QModelIndex &index, int role = |
|
105 Qt::DisplayRole) const |
|
106 { |
|
107 mDataIndex = index; |
|
108 mDataRole = role; |
|
109 return mDataResult; |
|
110 } |
|
111 void setAutoUpdate(bool autoUpdate) |
|
112 { |
|
113 mIsAutoUpdateResult = autoUpdate; |
|
114 } |
|
115 void setSecondLineVisibility(bool secondLineVisible) |
|
116 { |
|
117 mSecondLineVisibilityResult = secondLineVisible; |
|
118 } |
|
119 bool secondLineVisibility() const |
|
120 { |
|
121 return mSecondLineVisibilityResult; |
|
122 } |
|
123 |
|
124 bool isAutoUpdate() const |
|
125 { |
|
126 return mIsAutoUpdateResult; |
|
127 } |
|
128 |
|
129 void setSort(SortAttribute sortAttribute, |
|
130 Qt::SortOrder sortOrder = Qt::AscendingOrder) |
|
131 { |
|
132 mSetSortAttribute = sortAttribute; |
|
133 mSetSortOrder = sortOrder; |
|
134 } |
|
135 |
|
136 void setIconSize(const QSizeF &size) |
|
137 { |
|
138 mGetIconSizeResult = size; |
|
139 } |
|
140 |
|
141 QSizeF getIconSize() const |
|
142 { |
|
143 return mGetIconSizeResult; |
|
144 } |
|
145 void updateModel(){} |
|
146 void setParentId(int parentId) |
|
147 { |
|
148 Q_UNUSED(parentId); |
|
149 } |
|
150 void setFlagsOn(const EntryFlags &onFlags) |
|
151 { |
|
152 Q_UNUSED(onFlags); |
|
153 } |
|
154 void setFlagsOff(const EntryFlags &offFlags) |
|
155 { |
|
156 Q_UNUSED(offFlags); |
|
157 } |
|
158 QSharedPointer<CaEntry> entry(const QModelIndex &index) const |
|
159 { |
|
160 Q_UNUSED(index); |
|
161 return mEntryResult; |
|
162 } |
|
163 QList<int> getUninstallingEntriesIds(int componentId) |
|
164 { |
|
165 Q_UNUSED(componentId); |
|
166 QList<int> ids; |
|
167 ids.append(mEntryResult->id()); |
|
168 ids.append(4); |
|
169 return ids; |
|
170 } |
|
171 void updateProgress(int id, int valueOfProgress) |
|
172 { |
|
173 if (id == mEntryResult->id()) { |
|
174 mEntryResult->setAttribute(QString("uninstall_progress"), |
|
175 QString().setNum(valueOfProgress)); |
|
176 } |
|
177 } |
|
178 }; |
|
179 |
|
180 #endif // CASTANDARDITEMMODEL_H |