Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b64c0ce8 authored by Laurent Montel's avatar Laurent Montel 😁

Look at to implement regexp search

parent d0796f90
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
......
......@@ -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:
......
......@@ -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();
......
......@@ -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:
......
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