| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the QtDocGallery module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and Digia. For licensing terms and |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 24 | ** |
| 25 | ** In addition, as a special exception, Digia gives you certain additional |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 28 | ** |
| 29 | ** GNU General Public License Usage |
| 30 | ** Alternatively, this file may be used under the terms of the GNU |
| 31 | ** General Public License version 3.0 as published by the Free Software |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
| 33 | ** packaging of this file. Please review the following information to |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
| 36 | ** |
| 37 | ** |
| 38 | ** $QT_END_LICENSE$ |
| 39 | ** |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | // |
| 43 | // W A R N I N G |
| 44 | // ------------- |
| 45 | // |
| 46 | // This file is not part of the Qt API. It exists purely as an |
| 47 | // implementation detail. This header file may change from version to |
| 48 | // version without notice, or even be removed. |
| 49 | // |
| 50 | // We mean it. |
| 51 | // |
| 52 | |
| 53 | #ifndef GALLERYQUERYREQUEST_H |
| 54 | #define GALLERYQUERYREQUEST_H |
| 55 | |
| 56 | #include <qgalleryqueryrequest.h> |
| 57 | |
| 58 | #include "qdeclarativedocumentgallery.h" |
| 59 | #include "qdeclarativegalleryfilter.h" |
| 60 | |
| 61 | #include <QtCore/qabstractitemmodel.h> |
| 62 | #include <QtCore/qpointer.h> |
| 63 | #include <QtQml/qqml.h> |
| 64 | #include <QtQml/qjsvalue.h> |
| 65 | |
| 66 | QT_BEGIN_NAMESPACE_DOCGALLERY |
| 67 | |
| 68 | class QDeclarativeGalleryFilterBase; |
| 69 | |
| 70 | class QDeclarativeGalleryQueryModel : public QAbstractListModel, public QQmlParserStatus |
| 71 | { |
| 72 | Q_OBJECT |
| 73 | Q_INTERFACES(QQmlParserStatus) |
| 74 | Q_ENUMS(Status) |
| 75 | Q_ENUMS(Scope) |
| 76 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
| 77 | Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) |
| 78 | Q_PROPERTY(QStringList properties READ propertyNames WRITE setPropertyNames NOTIFY propertyNamesChanged) |
| 79 | Q_PROPERTY(QStringList sortProperties READ sortPropertyNames WRITE setSortPropertyNames NOTIFY sortPropertyNamesChanged) |
| 80 | Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged) |
| 81 | Q_PROPERTY(QVariant rootItem READ rootItem WRITE setRootItem NOTIFY rootItemChanged) |
| 82 | Q_PROPERTY(Scope scope READ scope WRITE setScope NOTIFY scopeChanged) |
| 83 | Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) |
| 84 | Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged) |
| 85 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
| 86 | Q_PROPERTY(QDocGallery::QDeclarativeGalleryFilterBase* filter READ filter WRITE setFilter NOTIFY filterChanged) |
| 87 | public: |
| 88 | enum Status |
| 89 | { |
| 90 | Null = QGalleryAbstractRequest::Inactive, |
| 91 | Active = QGalleryAbstractRequest::Active, |
| 92 | Canceling = QGalleryAbstractRequest::Canceling, |
| 93 | Canceled = QGalleryAbstractRequest::Canceled, |
| 94 | Idle = QGalleryAbstractRequest::Idle, |
| 95 | Finished = QGalleryAbstractRequest::Finished, |
| 96 | Error = QGalleryAbstractRequest::Error |
| 97 | }; |
| 98 | |
| 99 | enum Scope |
| 100 | { |
| 101 | AllDescendants = QGalleryQueryRequest::AllDescendants, |
| 102 | DirectDescendants = QGalleryQueryRequest::DirectDescendants |
| 103 | }; |
| 104 | |
| 105 | enum Roles |
| 106 | { |
| 107 | ItemId = 0, |
| 108 | ItemType, |
| 109 | MetaDataOffset |
| 110 | }; |
| 111 | |
| 112 | ~QDeclarativeGalleryQueryModel(); |
| 113 | |
| 114 | Status status() const { return m_status; } |
| 115 | |
| 116 | qreal progress() const; |
| 117 | |
| 118 | QStringList propertyNames() { return m_request.propertyNames(); } |
| 119 | void setPropertyNames(const QStringList &names); |
| 120 | |
| 121 | QStringList sortPropertyNames() const { return m_request.sortPropertyNames(); } |
| 122 | void setSortPropertyNames(const QStringList &names); |
| 123 | |
| 124 | bool autoUpdate() const { return m_request.autoUpdate(); } |
| 125 | void setAutoUpdate(bool enabled); |
| 126 | |
| 127 | Scope scope() const { return Scope(m_request.scope()); } |
| 128 | void setScope(Scope scope); |
| 129 | |
| 130 | QVariant rootItem() const { return m_request.rootItem(); } |
| 131 | void setRootItem(const QVariant &itemId); |
| 132 | |
| 133 | QDeclarativeGalleryFilterBase *filter() const { return m_filter.data(); } |
| 134 | void setFilter(QDeclarativeGalleryFilterBase *filter); |
| 135 | |
| 136 | int offset() const { return m_request.offset(); } |
| 137 | void setOffset(int offset); |
| 138 | |
| 139 | int limit() const { return m_request.limit(); } |
| 140 | void setLimit(int limit); |
| 141 | |
| 142 | int rowCount(const QModelIndex &parent) const; |
| 143 | |
| 144 | QVariant data(const QModelIndex &index, int role) const; |
| 145 | bool setData(const QModelIndex &index, const QVariant &value, int role); |
| 146 | |
| 147 | QModelIndex index(int row, int column, const QModelIndex &parent) const; |
| 148 | |
| 149 | int count() const { return m_rowCount; } |
| 150 | |
| 151 | Q_INVOKABLE QJSValue get(const QJSValue &index) const; |
| 152 | Q_INVOKABLE QVariant property(int index, const QString &property) const; |
| 153 | |
| 154 | Q_INVOKABLE void set(int index, const QJSValue &value); |
| 155 | Q_INVOKABLE void setProperty(int index, const QString &property, const QVariant &value); |
| 156 | |
| 157 | void componentComplete(); |
| 158 | |
| 159 | public Q_SLOTS: |
| 160 | void reload(); |
| 161 | void cancel(); |
| 162 | void clear(); |
| 163 | |
| 164 | Q_SIGNALS: |
| 165 | void statusChanged(); |
| 166 | void progressChanged(); |
| 167 | void propertyNamesChanged(); |
| 168 | void sortPropertyNamesChanged(); |
| 169 | void autoUpdateChanged(); |
| 170 | void rootItemChanged(); |
| 171 | void scopeChanged(); |
| 172 | void filterChanged(); |
| 173 | void offsetChanged(); |
| 174 | void limitChanged(); |
| 175 | void countChanged(); |
| 176 | |
| 177 | protected Q_SLOTS: |
| 178 | void deferredExecute(); |
| 179 | |
| 180 | protected: |
| 181 | enum UpdateStatus |
| 182 | { |
| 183 | Incomplete, |
| 184 | NoUpdate, |
| 185 | PendingUpdate, |
| 186 | CanceledUpdate |
| 187 | }; |
| 188 | |
| 189 | explicit QDeclarativeGalleryQueryModel(QObject *parent = Q_NULLPTR); |
| 190 | |
| 191 | virtual QVariant itemType(const QString &type) const = 0; |
| 192 | |
| 193 | bool event(QEvent *event); |
| 194 | |
| 195 | QGalleryQueryRequest m_request; |
| 196 | QPointer<QDeclarativeGalleryFilterBase> m_filter; |
| 197 | QGalleryResultSet *m_resultSet; |
| 198 | QVector<QPair<int, QString> > m_propertyNames; |
| 199 | Status m_status; |
| 200 | int m_rowCount; |
| 201 | UpdateStatus m_updateStatus; |
| 202 | |
| 203 | private Q_SLOTS: |
| 204 | void _q_stateChanged(); |
| 205 | void _q_setResultSet(QGalleryResultSet *resultSet); |
| 206 | void _q_itemsInserted(int index, int count); |
| 207 | void _q_itemsRemoved(int index, int count); |
| 208 | void _q_itemsMoved(int from, int to, int count); |
| 209 | void _q_itemsChanged(int index, int count); |
| 210 | }; |
| 211 | |
| 212 | class QDeclarativeDocumentGalleryModel : public QDeclarativeGalleryQueryModel |
| 213 | { |
| 214 | Q_OBJECT |
| 215 | Q_PROPERTY(QDocGallery::QDeclarativeDocumentGallery::ItemType rootType READ rootType WRITE setRootType NOTIFY rootTypeChanged) |
| 216 | public: |
| 217 | explicit QDeclarativeDocumentGalleryModel(QObject *parent = Q_NULLPTR); |
| 218 | ~QDeclarativeDocumentGalleryModel(); |
| 219 | |
| 220 | void classBegin(); |
| 221 | |
| 222 | QDeclarativeDocumentGallery::ItemType rootType() const; |
| 223 | void setRootType(QDeclarativeDocumentGallery::ItemType itemType); |
| 224 | |
| 225 | Q_SIGNALS: |
| 226 | void rootTypeChanged(); |
| 227 | |
| 228 | protected: |
| 229 | QVariant itemType(const QString &type) const; |
| 230 | }; |
| 231 | |
| 232 | QT_END_NAMESPACE_DOCGALLERY |
| 233 | |
| 234 | QML_DECLARE_TYPE(QT_DOCGALLERY_PREPEND_NAMESPACE(QDeclarativeDocumentGalleryModel)) |
| 235 | |
| 236 | #endif |
| 237 | |
| 238 | |