|
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: |
|
15 * |
|
16 * Version : %version: 2 % |
|
17 */ |
|
18 |
|
19 #ifndef HGCACHEPROXYMODEL_H_ |
|
20 #define HGCACHEPROXYMODEL_H_ |
|
21 |
|
22 #include <QAbstractItemModel> |
|
23 #include <QSortFilterProxyModel> |
|
24 |
|
25 #include <hgwidgets/hgdataprovidermodel.h> |
|
26 |
|
27 #ifdef BUILD_CACHEPROXYMODEL |
|
28 #define CACHEPROXYMODEL_EXPORT Q_DECL_EXPORT |
|
29 #else |
|
30 #define CACHEPROXYMODEL_EXPORT Q_DECL_IMPORT |
|
31 #endif |
|
32 |
|
33 class HgBufferManager; |
|
34 |
|
35 const int KDefaultCacheSize = 120; |
|
36 const int KDefaultCacheTreshold = 30; |
|
37 |
|
38 class HgBufferManagerObserver |
|
39 { |
|
40 public: |
|
41 enum HgRequestOrder { |
|
42 HgRequestOrderAscending, |
|
43 HgRequestOrderDescending |
|
44 }; |
|
45 |
|
46 virtual void release(int start, int end) = 0; |
|
47 virtual void request(int start, int end, HgRequestOrder order = HgRequestOrderAscending) = 0; |
|
48 }; |
|
49 |
|
50 class HgCacheProxyModel : public QAbstractItemModel, public HgBufferManagerObserver, public HgDataProviderModelObserver |
|
51 { |
|
52 Q_OBJECT |
|
53 public: |
|
54 CACHEPROXYMODEL_EXPORT HgCacheProxyModel(QObject *parent = 0); |
|
55 CACHEPROXYMODEL_EXPORT ~HgCacheProxyModel(); |
|
56 |
|
57 CACHEPROXYMODEL_EXPORT void setDataProvider(HgDataProviderModel *dataProvider, int cacheSize = KDefaultCacheSize, int cacheTreshold = KDefaultCacheTreshold); |
|
58 CACHEPROXYMODEL_EXPORT HgDataProviderModel* DataProvider(); |
|
59 CACHEPROXYMODEL_EXPORT void resizeCache(int newSize, int newTreshold); |
|
60 |
|
61 //from QAbstractItemModel |
|
62 CACHEPROXYMODEL_EXPORT virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
|
63 CACHEPROXYMODEL_EXPORT virtual QModelIndex parent(const QModelIndex &child) const; |
|
64 CACHEPROXYMODEL_EXPORT virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
65 CACHEPROXYMODEL_EXPORT virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; |
|
66 CACHEPROXYMODEL_EXPORT virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; |
|
67 CACHEPROXYMODEL_EXPORT virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
68 CACHEPROXYMODEL_EXPORT virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); |
|
69 CACHEPROXYMODEL_EXPORT virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
|
70 CACHEPROXYMODEL_EXPORT virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); |
|
71 CACHEPROXYMODEL_EXPORT virtual QMap<int, QVariant> itemData(const QModelIndex &index) const; |
|
72 CACHEPROXYMODEL_EXPORT virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles); |
|
73 CACHEPROXYMODEL_EXPORT virtual QStringList mimeTypes() const; |
|
74 CACHEPROXYMODEL_EXPORT virtual QMimeData *mimeData(const QModelIndexList &indexes) const; |
|
75 CACHEPROXYMODEL_EXPORT virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); |
|
76 CACHEPROXYMODEL_EXPORT virtual Qt::DropActions supportedDropActions() const; |
|
77 CACHEPROXYMODEL_EXPORT virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
78 CACHEPROXYMODEL_EXPORT virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); |
|
79 CACHEPROXYMODEL_EXPORT virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
80 CACHEPROXYMODEL_EXPORT virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); |
|
81 CACHEPROXYMODEL_EXPORT virtual void fetchMore(const QModelIndex &parent); |
|
82 CACHEPROXYMODEL_EXPORT virtual bool canFetchMore(const QModelIndex &parent) const; |
|
83 CACHEPROXYMODEL_EXPORT virtual Qt::ItemFlags flags(const QModelIndex &index) const; |
|
84 CACHEPROXYMODEL_EXPORT virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); |
|
85 CACHEPROXYMODEL_EXPORT virtual QModelIndex buddy(const QModelIndex &index) const; |
|
86 CACHEPROXYMODEL_EXPORT virtual QModelIndexList match(const QModelIndex &start, int role, |
|
87 const QVariant &value, int hits = 1, |
|
88 Qt::MatchFlags flags = |
|
89 Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const; |
|
90 CACHEPROXYMODEL_EXPORT virtual QSize span(const QModelIndex &index) const; |
|
91 |
|
92 // for sorting |
|
93 CACHEPROXYMODEL_EXPORT Qt::CaseSensitivity sortCaseSensitivity() const; |
|
94 CACHEPROXYMODEL_EXPORT void setSortCaseSensitivity(Qt::CaseSensitivity cs); |
|
95 CACHEPROXYMODEL_EXPORT bool isSortLocaleAware() const; |
|
96 CACHEPROXYMODEL_EXPORT void setSortLocaleAware(bool on); |
|
97 CACHEPROXYMODEL_EXPORT int sortColumn() const; |
|
98 CACHEPROXYMODEL_EXPORT Qt::SortOrder sortOrder() const; |
|
99 CACHEPROXYMODEL_EXPORT bool dynamicSortFilter() const; |
|
100 CACHEPROXYMODEL_EXPORT void setDynamicSortFilter(bool enable); |
|
101 CACHEPROXYMODEL_EXPORT int sortRole() const; |
|
102 CACHEPROXYMODEL_EXPORT void setSortRole(int role); |
|
103 |
|
104 //for filtering |
|
105 // CACHEPROXYMODEL_EXPORT QRegExp filterRegExp() const; |
|
106 // CACHEPROXYMODEL_EXPORT void setFilterRegExp(const QRegExp ®Exp); |
|
107 // CACHEPROXYMODEL_EXPORT int filterKeyColumn() const; |
|
108 // CACHEPROXYMODEL_EXPORT void setFilterKeyColumn(int column); |
|
109 // CACHEPROXYMODEL_EXPORT Qt::CaseSensitivity filterCaseSensitivity() const; |
|
110 // CACHEPROXYMODEL_EXPORT void setFilterCaseSensitivity(Qt::CaseSensitivity cs); |
|
111 // CACHEPROXYMODEL_EXPORT int filterRole() const; |
|
112 // CACHEPROXYMODEL_EXPORT void setFilterRole(int role); |
|
113 |
|
114 public slots: |
|
115 virtual bool submit(); |
|
116 virtual void revert(); |
|
117 |
|
118 public: |
|
119 //from HgBufferManagerObserver |
|
120 CACHEPROXYMODEL_EXPORT virtual void release(int start, int end); |
|
121 CACHEPROXYMODEL_EXPORT virtual void request(int start, int end, HgRequestOrder order = HgRequestOrderAscending); |
|
122 |
|
123 private: |
|
124 int count()const; |
|
125 QModelIndex mapToSource(const QModelIndex &index)const; |
|
126 QModelIndex mapToSource(int row, int col) const; |
|
127 int mapToDataProviderIndex(int myIndex) const; |
|
128 int mapFromDataProviderIndex(int myIndex) const; |
|
129 void cleanupForBMResetIfNeeded(); |
|
130 void resetBMIfNeeded(); |
|
131 void releaseAll(); |
|
132 void setBufferPosition(int pos) const; |
|
133 |
|
134 private slots: |
|
135 void sourceReset(); |
|
136 void sourceAboutToBeReset(); |
|
137 void sourceRowsInserted(const QModelIndex &source_parent, int start, int end); |
|
138 void sourceRowsRemoved(const QModelIndex &source_parent, int start, int end); |
|
139 void dataUpdated(QModelIndex from, QModelIndex to); |
|
140 |
|
141 //from HgDataProviderModelObserver |
|
142 public: |
|
143 CACHEPROXYMODEL_EXPORT virtual void dataUpdated(int from, int to); |
|
144 |
|
145 private: |
|
146 HgBufferManager* mBufferManager; |
|
147 QSortFilterProxyModel* mSortFilterProxyModel; |
|
148 HgDataProviderModel* mDataProviderModel; |
|
149 mutable bool mResetNeeded; |
|
150 mutable bool mSupressBM; |
|
151 mutable int mCurrentPos; |
|
152 bool mSortParameterChanged; |
|
153 bool mFilterParameterChanged; |
|
154 |
|
155 }; |
|
156 |
|
157 #endif // HGCACHEPROXYMODEL_H_ |