diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-10 10:49:33 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-17 17:50:01 +0100 |
commit | 0b6a4d94945a975390b2574e6aff2568ebb7f061 (patch) | |
tree | 480d54e4146ee0d23dd3f2ce69877408162bb512 /src/pdf/api/qpdfsearchmodel.h | |
parent | e5a33355798d3277c631b0024f389cdca2f2c683 (diff) |
PdfSearchModel: be QALM and find search results on all pages
It's a QAbstractListModel, so now PdfMultiPageView has a ListView in a
left-side Drawer showing all results found so far.
- In PdfMultiPageView, multiple pages exist at once, so it makes sense
to use the same searchmodel for all.
- It's faster and saves memory.
- Search results on each page can be cached.
- It's possible to show search results in a ListView or QListView.
Change-Id: I66fba6975954a09a4d23262be87ff8cc25ee7478
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/pdf/api/qpdfsearchmodel.h')
-rw-r--r-- | src/pdf/api/qpdfsearchmodel.h | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/pdf/api/qpdfsearchmodel.h b/src/pdf/api/qpdfsearchmodel.h index 02d2a20d5..c8190f192 100644 --- a/src/pdf/api/qpdfsearchmodel.h +++ b/src/pdf/api/qpdfsearchmodel.h @@ -39,34 +39,56 @@ #include "qtpdfglobal.h" #include "qpdfdocument.h" +#include "qpdfsearchresult.h" -#include <QObject> +#include <QtCore/qabstractitemmodel.h> QT_BEGIN_NAMESPACE class QPdfSearchModelPrivate; -class Q_PDF_EXPORT QPdfSearchModel : public QObject // TODO QAIM? +class Q_PDF_EXPORT QPdfSearchModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged) + Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged) public: + enum class Role : int { + Page = Qt::UserRole, + IndexOnPage, + Location, + Context, + _Count + }; + Q_ENUM(Role) explicit QPdfSearchModel(QObject *parent = nullptr); ~QPdfSearchModel(); - QVector<QRectF> matches(int page, const QString &searchString); + QVector<QPdfSearchResult> resultsOnPage(int page) const; + QPdfSearchResult resultAtIndex(int index) const; QPdfDocument *document() const; + QString searchString() const; + + QHash<int, QByteArray> roleNames() const override; + int rowCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; public Q_SLOTS: + void setSearchString(QString searchString); void setDocument(QPdfDocument *document); Q_SIGNALS: void documentChanged(); + void searchStringChanged(); + +protected: + void updatePage(int page); private: - QScopedPointer<QPdfSearchModelPrivate> d; + QHash<int, QByteArray> m_roleNames; + Q_DECLARE_PRIVATE(QPdfSearchModel) }; QT_END_NAMESPACE |