summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-12-15 22:51:18 +0100
committerMontel Laurent <[email protected]>2017-12-15 22:51:18 +0100
commitb64c0ce864730200cfa95c7759fe77f58878cd34 (patch)
tree2dcffd3b0ce2d529739882dd74ccff6c893f4ca4
parentd0796f9068de4897cb10711371a72b4ac31a0049 (diff)
Look at to implement regexp search
-rw-r--r--src/texteditor/commonwidget/texteditfindbarbase.h1
-rw-r--r--src/texteditor/commonwidget/textfindreplacewidget.cpp9
-rw-r--r--src/texteditor/commonwidget/textfindreplacewidget.h3
-rw-r--r--src/texteditor/plaintexteditor/plaintexteditfindbar.cpp7
-rw-r--r--src/texteditor/plaintexteditor/plaintexteditfindbar.h1
-rw-r--r--src/texteditor/richtexteditor/richtexteditfindbar.cpp7
-rw-r--r--src/texteditor/richtexteditor/richtexteditfindbar.h1
7 files changed, 29 insertions, 0 deletions
diff --git a/src/texteditor/commonwidget/texteditfindbarbase.h b/src/texteditor/commonwidget/texteditfindbarbase.h
index 20a6cd6..a6027e9 100644
--- a/src/texteditor/commonwidget/texteditfindbarbase.h
+++ b/src/texteditor/commonwidget/texteditfindbarbase.h
@@ -52,6 +52,7 @@ protected:
virtual bool viewIsReadOnly() const = 0;
virtual bool documentIsEmpty() const = 0;
virtual bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) = 0;
+ virtual bool searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions) = 0;
virtual void autoSearchMoveCursor() = 0;
bool event(QEvent *e) override;
diff --git a/src/texteditor/commonwidget/textfindreplacewidget.cpp b/src/texteditor/commonwidget/textfindreplacewidget.cpp
index c6b29a7..d63b457 100644
--- a/src/texteditor/commonwidget/textfindreplacewidget.cpp
+++ b/src/texteditor/commonwidget/textfindreplacewidget.cpp
@@ -102,6 +102,9 @@ TextFindWidget::TextFindWidget(QWidget *parent)
mWholeWordAct = optionsMenu->addAction(i18n("Whole word"));
mWholeWordAct->setCheckable(true);
+ mRegExpAct = optionsMenu->addAction(i18n("Regular Expression"));
+ mRegExpAct->setCheckable(true);
+
optionsBtn->setMenu(optionsMenu);
lay->addWidget(optionsBtn);
@@ -109,6 +112,7 @@ TextFindWidget::TextFindWidget(QWidget *parent)
connect(mFindPrevBtn, &QPushButton::clicked, this, &TextFindWidget::findPrev);
connect(mCaseSensitiveAct, &QAction::toggled, this, &TextFindWidget::updateSearchOptions);
connect(mWholeWordAct, &QAction::toggled, this, &TextFindWidget::updateSearchOptions);
+ connect(mRegExpAct, &QAction::toggled, this, &TextFindWidget::updateSearchOptions);
connect(mSearch, &QLineEdit::textChanged, this, &TextFindWidget::slotAutoSearch);
}
@@ -170,6 +174,11 @@ QLineEdit *TextFindWidget::search() const
return mSearch;
}
+bool TextFindWidget::isRegularExpression() const
+{
+ return mRegExpAct->isChecked();
+}
+
QTextDocument::FindFlags TextFindWidget::searchOptions() const
{
QTextDocument::FindFlags opt = nullptr;
diff --git a/src/texteditor/commonwidget/textfindreplacewidget.h b/src/texteditor/commonwidget/textfindreplacewidget.h
index eb8b80c..88fcbf9 100644
--- a/src/texteditor/commonwidget/textfindreplacewidget.h
+++ b/src/texteditor/commonwidget/textfindreplacewidget.h
@@ -41,6 +41,8 @@ public:
void setFoundMatch(bool match);
QRegExp findRegExp() const;
+ bool isRegularExpression() const;
+
private Q_SLOTS:
void slotAutoSearch(const QString &str);
@@ -56,6 +58,7 @@ private:
QLineEdit *mSearch = nullptr;
QAction *mCaseSensitiveAct = nullptr;
QAction *mWholeWordAct = nullptr;
+ QAction *mRegExpAct = nullptr;
QPushButton *mFindPrevBtn = nullptr;
QPushButton *mFindNextBtn = nullptr;
diff --git a/src/texteditor/plaintexteditor/plaintexteditfindbar.cpp b/src/texteditor/plaintexteditor/plaintexteditfindbar.cpp
index abae7cf..e1fe1fd 100644
--- a/src/texteditor/plaintexteditor/plaintexteditfindbar.cpp
+++ b/src/texteditor/plaintexteditor/plaintexteditfindbar.cpp
@@ -73,6 +73,13 @@ bool PlainTextEditFindBar::searchInDocument(const QString &text, QTextDocument::
return found;
}
+bool PlainTextEditFindBar::searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions)
+{
+ const bool found = d->mView->find(regExp, searchOptions);
+ mFindWidget->setFoundMatch(found);
+ return found;
+}
+
void PlainTextEditFindBar::autoSearchMoveCursor()
{
QTextCursor cursor = d->mView->textCursor();
diff --git a/src/texteditor/plaintexteditor/plaintexteditfindbar.h b/src/texteditor/plaintexteditor/plaintexteditfindbar.h
index d517fba..9ee882b 100644
--- a/src/texteditor/plaintexteditor/plaintexteditfindbar.h
+++ b/src/texteditor/plaintexteditor/plaintexteditfindbar.h
@@ -39,6 +39,7 @@ protected:
bool viewIsReadOnly() const override;
bool documentIsEmpty() const override;
bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) override;
+ bool searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions) override;
void autoSearchMoveCursor() override;
public Q_SLOTS:
diff --git a/src/texteditor/richtexteditor/richtexteditfindbar.cpp b/src/texteditor/richtexteditor/richtexteditfindbar.cpp
index 2ad9e12..2d5c600 100644
--- a/src/texteditor/richtexteditor/richtexteditfindbar.cpp
+++ b/src/texteditor/richtexteditor/richtexteditfindbar.cpp
@@ -72,6 +72,13 @@ bool RichTextEditFindBar::searchInDocument(const QString &text, QTextDocument::F
return found;
}
+bool RichTextEditFindBar::searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions)
+{
+ const bool found = d->mView->find(regExp, searchOptions);
+ mFindWidget->setFoundMatch(found);
+ return found;
+}
+
void RichTextEditFindBar::autoSearchMoveCursor()
{
QTextCursor cursor = d->mView->textCursor();
diff --git a/src/texteditor/richtexteditor/richtexteditfindbar.h b/src/texteditor/richtexteditor/richtexteditfindbar.h
index 44b1310..edec9da 100644
--- a/src/texteditor/richtexteditor/richtexteditfindbar.h
+++ b/src/texteditor/richtexteditor/richtexteditfindbar.h
@@ -38,6 +38,7 @@ protected:
bool viewIsReadOnly() const override;
bool documentIsEmpty() const override;
bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) override;
+ bool searchInDocument(const QRegExp &regExp, QTextDocument::FindFlags searchOptions) override;
void autoSearchMoveCursor() override;
public Q_SLOTS: