Commit f2360a19 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port some code to qt6 + use Q_REQUIRED_RESULT

parent 7088f3d6
Pipeline #150023 passed with stage
in 2 minutes and 5 seconds
......@@ -5,8 +5,11 @@
*/
#include "akonadisearchsyntaxhighlighter.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QRegExp>
#else
#include <QRegularExpression>
#endif
using namespace Akonadi::Search;
AkonadiSearchSyntaxHighlighter::AkonadiSearchSyntaxHighlighter(QTextDocument *doc)
......@@ -19,6 +22,7 @@ AkonadiSearchSyntaxHighlighter::~AkonadiSearchSyntaxHighlighter() = default;
void AkonadiSearchSyntaxHighlighter::highlightBlock(const QString &text)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
for (const Rule &rule : std::as_const(m_rules)) {
const QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
......@@ -28,6 +32,16 @@ void AkonadiSearchSyntaxHighlighter::highlightBlock(const QString &text)
index = expression.indexIn(text, index + length);
}
}
#else
for (const Rule &rule : std::as_const(m_rules)) {
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext()) {
QRegularExpressionMatch match = matchIterator.next();
setFormat(match.capturedStart(), match.capturedLength(), rule.format);
}
}
#endif
}
void AkonadiSearchSyntaxHighlighter::init()
......@@ -77,7 +91,11 @@ void AkonadiSearchSyntaxHighlighter::init()
testType << QStringLiteral("\\bS");
testType << QStringLiteral("\\bL");
for (const QString &s : std::as_const(testType)) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QRegExp regex(s, Qt::CaseSensitive);
#else
const QRegularExpression regex(s, Qt::CaseSensitive);
#endif
m_rules.append(Rule(regex, testFormat));
}
}
......@@ -5,9 +5,12 @@
*/
#pragma once
#include <QRegExp>
#include <QSyntaxHighlighter>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QRegExp>
#else
#include <QRegularExpression>
#endif
namespace Akonadi
{
namespace Search
......@@ -16,14 +19,20 @@ class Rule
{
public:
Rule() = default;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Rule(const QRegExp &r, const QTextCharFormat &f)
#else
Rule(const QRegularExpression &r, const QTextCharFormat &f)
#endif
: pattern(r)
, format(f)
{
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp pattern;
#else
QRegularExpression pattern;
#endif
QTextCharFormat format;
};
......
......@@ -50,7 +50,7 @@ public:
* Execute the query and return an iterator to fetch
* the results
*/
ResultIterator exec() override;
Q_REQUIRED_RESULT ResultIterator exec() override;
/**
* For testing
......
......@@ -34,8 +34,8 @@ public:
void close(int queryId) override;
bool next(int queryId) override;
QByteArray id(int queryId) override;
QUrl url(int queryId) override;
Q_REQUIRED_RESULT QByteArray id(int queryId) override;
Q_REQUIRED_RESULT QUrl url(int queryId) override;
/**
* Set the path of the xapian database
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment