summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/pdf/multipage/viewer.qml2
-rw-r--r--examples/pdf/pdfviewer/viewer.qml2
-rw-r--r--src/pdf/qpdfsearchmodel.cpp14
-rw-r--r--src/pdf/qpdfsearchmodel.h4
-rw-r--r--src/pdfquick/qquickpdfsearchmodel.cpp7
5 files changed, 29 insertions, 0 deletions
diff --git a/examples/pdf/multipage/viewer.qml b/examples/pdf/multipage/viewer.qml
index d0b0a7263..ec9a9fd91 100644
--- a/examples/pdf/multipage/viewer.qml
+++ b/examples/pdf/multipage/viewer.qml
@@ -398,6 +398,7 @@ ApplicationWindow {
action: Action {
icon.source: "qrc:/pdfviewer/resources/go-up-search.svg"
shortcut: StandardKey.FindPrevious
+ enabled: view.searchModel.count > 0
onTriggered: view.searchBack()
}
ToolTip.visible: enabled && hovered
@@ -432,6 +433,7 @@ ApplicationWindow {
action: Action {
icon.source: "qrc:/pdfviewer/resources/go-down-search.svg"
shortcut: StandardKey.FindNext
+ enabled: view.searchModel.count > 0
onTriggered: view.searchForward()
}
ToolTip.visible: enabled && hovered
diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml
index a62035166..277863023 100644
--- a/examples/pdf/pdfviewer/viewer.qml
+++ b/examples/pdf/pdfviewer/viewer.qml
@@ -256,6 +256,7 @@ ApplicationWindow {
action: Action {
icon.source: "qrc:/pdfviewer/resources/go-up-search.svg"
shortcut: StandardKey.FindPrevious
+ enabled: view.searchModel.count > 0
onTriggered: view.searchBack()
}
ToolTip.visible: enabled && hovered
@@ -288,6 +289,7 @@ ApplicationWindow {
action: Action {
icon.source: "qrc:/pdfviewer/resources/go-down-search.svg"
shortcut: StandardKey.FindNext
+ enabled: view.searchModel.count > 0
onTriggered: view.searchForward()
}
ToolTip.visible: enabled && hovered
diff --git a/src/pdf/qpdfsearchmodel.cpp b/src/pdf/qpdfsearchmodel.cpp
index 78dfe06fa..8a997c84e 100644
--- a/src/pdf/qpdfsearchmodel.cpp
+++ b/src/pdf/qpdfsearchmodel.cpp
@@ -65,6 +65,10 @@ QPdfSearchModel::QPdfSearchModel(QObject *parent)
roleName[0] = QChar::toLower(roleName[0]);
m_roleNames.insert(r, roleName);
}
+ connect(this, &QAbstractListModel::dataChanged, this, &QPdfSearchModel::countChanged);
+ connect(this, &QAbstractListModel::modelReset, this, &QPdfSearchModel::countChanged);
+ connect(this, &QAbstractListModel::rowsRemoved, this, &QPdfSearchModel::countChanged);
+ connect(this, &QAbstractListModel::rowsInserted, this, &QPdfSearchModel::countChanged);
}
/*!
@@ -124,6 +128,16 @@ QVariant QPdfSearchModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+/*!
+ \since 6.8
+ \property QPdfSearchModel::count
+ \brief the number of search results found
+*/
+int QPdfSearchModel::count() const
+{
+ return rowCount(QModelIndex());
+}
+
void QPdfSearchModel::updatePage(int page)
{
Q_D(QPdfSearchModel);
diff --git a/src/pdf/qpdfsearchmodel.h b/src/pdf/qpdfsearchmodel.h
index c1e4e64ec..04f8b9140 100644
--- a/src/pdf/qpdfsearchmodel.h
+++ b/src/pdf/qpdfsearchmodel.h
@@ -19,6 +19,7 @@ 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)
+ Q_PROPERTY(int count READ count NOTIFY countChanged REVISION(6, 8) FINAL)
public:
enum class Role : int {
@@ -44,6 +45,8 @@ public:
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
+ int count() const;
+
public Q_SLOTS:
void setSearchString(const QString &searchString);
void setDocument(QPdfDocument *document);
@@ -51,6 +54,7 @@ public Q_SLOTS:
Q_SIGNALS:
void documentChanged();
void searchStringChanged();
+ Q_REVISION(6, 8) void countChanged();
protected:
void updatePage(int page);
diff --git a/src/pdfquick/qquickpdfsearchmodel.cpp b/src/pdfquick/qquickpdfsearchmodel.cpp
index 21fa1a70b..896584ad7 100644
--- a/src/pdfquick/qquickpdfsearchmodel.cpp
+++ b/src/pdfquick/qquickpdfsearchmodel.cpp
@@ -270,6 +270,13 @@ QPdfLink QQuickPdfSearchModel::currentResultLink() const
The string to search for.
*/
+/*!
+ \since 6.8
+ \qmlproperty int PdfSearchModel::count
+
+ The number of search results found.
+*/
+
QT_END_NAMESPACE
#include "moc_qquickpdfsearchmodel_p.cpp"