Commit 285fc882 authored by Laurent Montel's avatar Laurent Montel 😁

Use new qt5.13 api which uses QRegularExpression

parent d1ed6953
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.10.41")
set(PIM_VERSION "5.10.42")
project(KPimTextEdit VERSION ${PIM_VERSION})
......
......@@ -32,6 +32,7 @@
#include <QKeyEvent>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QRegularExpression>
using namespace KPIMTextEdit;
......
......@@ -23,7 +23,9 @@
#include "kpimtextedit_export.h"
#include <QWidget>
#include <QTextDocument>
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
#include <QRegularExpression>
#endif
namespace KPIMTextEdit {
class TextFindWidget;
class TextReplaceWidget;
......@@ -52,7 +54,11 @@ protected:
virtual bool viewIsReadOnly() const = 0;
virtual bool documentIsEmpty() const = 0;
virtual bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) = 0;
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
virtual bool searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions) = 0;
#else
virtual bool searchInDocument(const QRegularExpression &regExp, QTextDocument::FindFlags searchOptions) = 0;
#endif
virtual void autoSearchMoveCursor() = 0;
bool event(QEvent *e) override;
......@@ -79,7 +85,11 @@ private Q_SLOTS:
protected:
QString mLastSearchStr;
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
QRegExp mLastSearchRegExp;
#else
QRegularExpression mLastSearchRegExp;
#endif
TextFindWidget *mFindWidget = nullptr;
TextReplaceWidget *mReplaceWidget = nullptr;
bool mHideWhenClose = true;
......
......@@ -27,6 +27,7 @@
#include <QLabel>
#include <QMenu>
#include <QHBoxLayout>
#include <QRegularExpression>
using namespace KPIMTextEdit;
......@@ -173,6 +174,7 @@ QString TextFindWidget::searchText() const
return mSearch->text();
}
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
QRegExp TextFindWidget::searchRegExp() const
{
QRegExp reg;
......@@ -188,7 +190,21 @@ QRegExp TextFindWidget::searchRegExp() const
reg.setPattern(searchTextString);
return reg;
}
#else
QRegularExpression TextFindWidget::searchRegExp() const
{
QRegularExpression reg;
if (!mCaseSensitiveAct->isChecked()) {
reg.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
}
QString searchTextString = mSearch->text();
if (mWholeWordAct->isChecked()) {
searchTextString = QStringLiteral("\\b") + searchTextString + QStringLiteral("\\b");
}
reg.setPattern(searchTextString);
return reg;
}
#endif
QTextDocument::FindFlags TextFindWidget::searchOptions() const
{
QTextDocument::FindFlags opt = nullptr;
......
......@@ -41,8 +41,11 @@ public:
void setFoundMatch(bool match);
bool isRegularExpression() const;
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
Q_REQUIRED_RESULT QRegExp searchRegExp() const;
#else
Q_REQUIRED_RESULT QRegularExpression searchRegExp() const;
#endif
Q_REQUIRED_RESULT QString searchText() const;
......
......@@ -24,6 +24,7 @@
#include <klineedit.h>
#include <KColorScheme>
#include <QRegularExpression>
#include <QPlainTextEdit>
using namespace KPIMTextEdit;
......@@ -72,13 +73,21 @@ bool PlainTextEditFindBar::searchInDocument(const QString &text, QTextDocument::
mFindWidget->setFoundMatch(found);
return found;
}
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
bool PlainTextEditFindBar::searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions)
{
const bool found = d->mView->find(regExp, searchOptions);
mFindWidget->setFoundMatch(found);
return found;
}
#else
bool PlainTextEditFindBar::searchInDocument(const QRegularExpression &regExp, QTextDocument::FindFlags searchOptions)
{
const bool found = d->mView->find(regExp, searchOptions);
mFindWidget->setFoundMatch(found);
return found;
}
#endif
void PlainTextEditFindBar::autoSearchMoveCursor()
{
......
......@@ -39,7 +39,11 @@ protected:
bool viewIsReadOnly() const override;
bool documentIsEmpty() const override;
bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) override;
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
bool searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions) override;
#else
bool searchInDocument(const QRegularExpression &regExp, QTextDocument::FindFlags searchOptions) override;
#endif
void autoSearchMoveCursor() override;
public Q_SLOTS:
......
......@@ -25,6 +25,7 @@
#include <KColorScheme>
#include <QTextEdit>
#include <QRegularExpression>
using namespace KPIMTextEdit;
class KPIMTextEdit::RichTextEditFindBarPrivate
......@@ -71,13 +72,22 @@ bool RichTextEditFindBar::searchInDocument(const QString &text, QTextDocument::F
mFindWidget->setFoundMatch(found);
return found;
}
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
bool RichTextEditFindBar::searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions)
{
const bool found = d->mView->find(regExp, searchOptions);
mFindWidget->setFoundMatch(found);
return found;
}
#else
bool RichTextEditFindBar::searchInDocument(const QRegularExpression &regExp, QTextDocument::FindFlags searchOptions)
{
const bool found = d->mView->find(regExp, searchOptions);
mFindWidget->setFoundMatch(found);
return found;
}
#endif
void RichTextEditFindBar::autoSearchMoveCursor()
{
......
......@@ -38,7 +38,11 @@ protected:
bool viewIsReadOnly() const override;
bool documentIsEmpty() const override;
bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) override;
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
bool searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions) override;
#else
bool searchInDocument(const QRegularExpression &regExp, QTextDocument::FindFlags searchOptions) override;
#endif
void autoSearchMoveCursor() override;
public Q_SLOTS:
......
Markdown is supported
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