summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-12-17 16:30:45 +0100
committerMontel Laurent <[email protected]>2017-12-17 16:30:45 +0100
commit7f62b5f4a4171fe302cee68dd990814ebe61bb41 (patch)
tree5e509debaf6b9342d71cb4127bd35f0d80e8f8a7
parentd5934729299b1275c57a30b3825f7f3f74749c88 (diff)
Improve regular expression search
-rw-r--r--src/texteditor/commonwidget/texteditfindbarbase.cpp16
-rw-r--r--src/texteditor/commonwidget/texteditfindbarbase.h1
-rw-r--r--src/texteditor/commonwidget/textfindreplacewidget.cpp11
-rw-r--r--src/texteditor/commonwidget/textfindreplacewidget.h2
4 files changed, 27 insertions, 3 deletions
diff --git a/src/texteditor/commonwidget/texteditfindbarbase.cpp b/src/texteditor/commonwidget/texteditfindbarbase.cpp
index 5cefe9d..8782f3a 100644
--- a/src/texteditor/commonwidget/texteditfindbarbase.cpp
+++ b/src/texteditor/commonwidget/texteditfindbarbase.cpp
@@ -19,7 +19,7 @@
#include "texteditfindbarbase.h"
#include "texteditor/commonwidget/textfindreplacewidget.h"
-
+#include "kpimtextedit_debug.h"
#include <QIcon>
#include <KLocalizedString>
#include <kmessagebox.h>
@@ -176,7 +176,12 @@ bool TextEditFindBarBase::searchText(bool backward, bool isAutoSearch)
clearSelections();
}
- const bool found = searchInDocument(mLastSearchStr, searchOptions);
+ bool found = false;
+ if (mFindWidget->isRegularExpression()) {
+ found = searchInDocument(mLastSearchRegExp, searchOptions);
+ } else {
+ found = searchInDocument(mLastSearchStr, searchOptions);
+ }
mFindWidget->setFoundMatch(found);
messageInfo(backward, isAutoSearch, found);
return found;
@@ -196,7 +201,12 @@ void TextEditFindBarBase::slotUpdateSearchOptions()
{
const QTextDocument::FindFlags searchOptions = mFindWidget->searchOptions();
mLastSearchStr = mFindWidget->search()->text();
- searchInDocument(mLastSearchStr, searchOptions);
+ mLastSearchRegExp = mFindWidget->searchRegExp();
+ if (mFindWidget->isRegularExpression()) {
+ searchInDocument(mLastSearchRegExp, searchOptions);
+ } else {
+ searchInDocument(mLastSearchStr, searchOptions);
+ }
}
void TextEditFindBarBase::clearSelections()
diff --git a/src/texteditor/commonwidget/texteditfindbarbase.h b/src/texteditor/commonwidget/texteditfindbarbase.h
index a6027e9..e203c52 100644
--- a/src/texteditor/commonwidget/texteditfindbarbase.h
+++ b/src/texteditor/commonwidget/texteditfindbarbase.h
@@ -79,6 +79,7 @@ private Q_SLOTS:
protected:
QString mLastSearchStr;
+ QRegExp mLastSearchRegExp;
TextFindWidget *mFindWidget = nullptr;
TextReplaceWidget *mReplaceWidget = nullptr;
bool mHideWhenClose = true;
diff --git a/src/texteditor/commonwidget/textfindreplacewidget.cpp b/src/texteditor/commonwidget/textfindreplacewidget.cpp
index d63b457..e5452b0 100644
--- a/src/texteditor/commonwidget/textfindreplacewidget.cpp
+++ b/src/texteditor/commonwidget/textfindreplacewidget.cpp
@@ -179,6 +179,17 @@ bool TextFindWidget::isRegularExpression() const
return mRegExpAct->isChecked();
}
+QRegExp TextFindWidget::searchRegExp() const
+{
+ QRegExp reg;
+ if (mCaseSensitiveAct->isChecked()) {
+ reg.setCaseSensitivity(Qt::CaseInsensitive);
+ }
+ //TODO QTextDocument::FindWholeWords ?
+ reg.setPattern(mSearch->text());
+ return reg;
+}
+
QTextDocument::FindFlags TextFindWidget::searchOptions() const
{
QTextDocument::FindFlags opt = nullptr;
diff --git a/src/texteditor/commonwidget/textfindreplacewidget.h b/src/texteditor/commonwidget/textfindreplacewidget.h
index 88fcbf9..2065277 100644
--- a/src/texteditor/commonwidget/textfindreplacewidget.h
+++ b/src/texteditor/commonwidget/textfindreplacewidget.h
@@ -43,6 +43,8 @@ public:
bool isRegularExpression() const;
+ QRegExp searchRegExp() const;
+
private Q_SLOTS:
void slotAutoSearch(const QString &str);