|
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: 6 % |
|
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 CACHEPROXYMODEL_EXPORT HgCacheProxyModel : public QAbstractItemModel, public HgBufferManagerObserver, public HgDataProviderModelObserver |
|
51 { |
|
52 Q_OBJECT |
|
53 public: |
|
54 HgCacheProxyModel(QObject *parent = 0); |
|
55 ~HgCacheProxyModel(); |
|
56 |
|
57 void setDataProvider(HgDataProviderModel *dataProvider, int cacheSize = KDefaultCacheSize, int cacheTreshold = KDefaultCacheTreshold); |
|
58 HgDataProviderModel* DataProvider(); |
|
59 void resizeCache(int newSize, int newTreshold); |
|
60 |
|
61 //from QAbstractItemModel |
|
62 virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
|
63 virtual QModelIndex parent(const QModelIndex &child) const; |
|
64 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
65 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; |
|
66 virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; |
|
67 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
68 virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); |
|
69 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
|
70 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); |
|
71 virtual QMap<int, QVariant> itemData(const QModelIndex &index) const; |
|
72 virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles); |
|
73 virtual QStringList mimeTypes() const; |
|
74 virtual QMimeData *mimeData(const QModelIndexList &indexes) const; |
|
75 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); |
|
76 virtual Qt::DropActions supportedDropActions() const; |
|
77 virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
78 virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); |
|
79 virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
80 virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); |
|
81 virtual void fetchMore(const QModelIndex &parent); |
|
82 virtual bool canFetchMore(const QModelIndex &parent) const; |
|
83 virtual Qt::ItemFlags flags(const QModelIndex &index) const; |
|
84 virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); |
|
85 virtual QModelIndex buddy(const QModelIndex &index) const; |
|
86 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 virtual QSize span(const QModelIndex &index) const; |
|
91 |
|
92 // for sorting |
|
93 Qt::CaseSensitivity sortCaseSensitivity() const; |
|
94 void setSortCaseSensitivity(Qt::CaseSensitivity cs); |
|
95 bool isSortLocaleAware() const; |
|
96 void setSortLocaleAware(bool on); |
|
97 int sortColumn() const; |
|
98 Qt::SortOrder sortOrder() const; |
|
99 bool dynamicSortFilter() const; |
|
100 void setDynamicSortFilter(bool enable); |
|
101 int sortRole() const; |
|
102 void setSortRole(int role); |
|
103 |
|
104 //for filtering |
|
105 QRegExp filterRegExp() const; |
|
106 void setFilterRegExp(const QRegExp ®Exp); |
|
107 int filterKeyColumn() const; |
|
108 void setFilterKeyColumn(int column); |
|
109 Qt::CaseSensitivity filterCaseSensitivity() const; |
|
110 void setFilterCaseSensitivity(Qt::CaseSensitivity cs); |
|
111 int filterRole() const; |
|
112 void setFilterRole(int role); |
|
113 |
|
114 public slots: |
|
115 virtual bool submit(); |
|
116 virtual void revert(); |
|
117 |
|
118 public: |
|
119 //from HgBufferManagerObserver |
|
120 virtual void release(int start, int end); |
|
121 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 releaseAll(); |
|
130 void setBufferPosition(int pos) const; |
|
131 |
|
132 private slots: |
|
133 void sourceColumnsAboutToBeInserted( const QModelIndex & parent, int start, int end); |
|
134 void sourceColumnsAboutToBeMoved( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationColumn ); |
|
135 void sourceColumnsAboutToBeRemoved( const QModelIndex & parent, int start, int end); |
|
136 void sourceColumnsInserted( const QModelIndex & parent, int start, int end ); |
|
137 void sourceColumnsMoved( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationColumn ); |
|
138 void sourceColumnsRemoved( const QModelIndex & parent, int start, int end ); |
|
139 void sourceDataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ); |
|
140 void sourceHeaderDataChanged( Qt::Orientation orientation, int first, int last ); |
|
141 void sourceLayoutAboutToBeChanged(); |
|
142 void sourceLayoutChanged(); |
|
143 void sourceModelAboutToBeReset(); |
|
144 void sourceModelReset(); |
|
145 void sourceRowsAboutToBeInserted( const QModelIndex & parent, int start, int end ); |
|
146 void sourceRowsAboutToBeMoved( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationRow ); |
|
147 void sourceRowsAboutToBeRemoved( const QModelIndex & parent, int start, int end ); |
|
148 void sourceRowsInserted( const QModelIndex & parent, int start, int end ); |
|
149 void sourceRowsMoved( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationRow ); |
|
150 void sourceRowsRemoved( const QModelIndex & parent, int start, int end ); |
|
151 |
|
152 //from HgDataProviderModelObserver |
|
153 public: |
|
154 virtual void dataUpdated(int from, int to); |
|
155 virtual bool isCached(int idx) const; |
|
156 |
|
157 private: |
|
158 HgBufferManager* mBufferManager; |
|
159 QSortFilterProxyModel* mSortFilterProxyModel; |
|
160 HgDataProviderModel* mDataProviderModel; |
|
161 mutable bool mSupressBM; |
|
162 mutable int mCurrentPos; |
|
163 }; |
|
164 |
|
165 #endif // HGCACHEPROXYMODEL_H_ |