Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpdfsearchmodel.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPDFSEARCHMODEL_H
5#define QPDFSEARCHMODEL_H
6
7#include <QtPdf/qtpdfglobal.h>
8
9#include <QtCore/qabstractitemmodel.h>
10#include <QtPdf/qpdfdocument.h>
11#include <QtPdf/qpdflink.h>
12
13QT_BEGIN_NAMESPACE
14
15class QPdfSearchModelPrivate;
16
17class Q_PDF_EXPORT QPdfSearchModel : public QAbstractListModel
18{
19 Q_OBJECT
20 Q_PROPERTY(QPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged)
21 Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged)
22 Q_PROPERTY(int count READ count NOTIFY countChanged REVISION(6, 8) FINAL)
23
24public:
25 enum class Role : int {
26 Page = Qt::UserRole,
27 IndexOnPage,
28 Location,
29 ContextBefore,
30 ContextAfter,
31 NRoles
32 };
33 Q_ENUM(Role)
34 QPdfSearchModel() : QPdfSearchModel(nullptr) {}
35 explicit QPdfSearchModel(QObject *parent);
36 ~QPdfSearchModel() override;
37
38 QList<QPdfLink> resultsOnPage(int page) const;
39 QPdfLink resultAtIndex(int index) const;
40
41 QPdfDocument *document() const;
42 QString searchString() const;
43
44 QHash<int, QByteArray> roleNames() const override;
45 int rowCount(const QModelIndex &parent) const override;
46 QVariant data(const QModelIndex &index, int role) const override;
47
48 int count() const;
49
50public Q_SLOTS:
51 void setSearchString(const QString &searchString);
52 void setDocument(QPdfDocument *document);
53
54Q_SIGNALS:
55 void documentChanged();
56 void searchStringChanged();
57 Q_REVISION(6, 8) void countChanged();
58
59protected:
60 void updatePage(int page);
61 void timerEvent(QTimerEvent *event) override;
62
63private:
64 QHash<int, QByteArray> m_roleNames;
65 Q_DECLARE_PRIVATE(QPdfSearchModel)
66};
67
68QT_END_NAMESPACE
69
70#endif // QPDFSEARCHMODEL_H
PageAndIndex pageAndIndexForResult(int resultIndex)
The QPdfSearchModel class searches for a string in a PDF document and holds the results.
static const int ContextChars
#define Q_PDF_LOGGING_CATEGORY(name,...)