Commit 0fcb086c authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use TextEditFindBarBase::FindFlags directly

parent ec24b93f
Pipeline #144317 passed with stages
in 2 minutes and 52 seconds
......@@ -31,14 +31,14 @@ QTextDocument::FindFlags FindUtils::convertTextEditFindFlags(TextEditFindBarBase
return flags;
}
int FindUtils::replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions)
int FindUtils::replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, TextEditFindBarBase::FindFlags searchOptions)
{
auto document = view->document();
QTextCursor c(document);
c.beginEditBlock();
int count = 0;
// Ignoring FindBackward when replacing all
const QTextDocument::FindFlags flags = searchOptions & ~QTextDocument::FindBackward;
const QTextDocument::FindFlags flags = FindUtils::convertTextEditFindFlags(searchOptions) & ~QTextDocument::FindBackward;
while (!c.isNull()) {
c = document->find(str, c, flags);
if (!c.isNull()) {
......@@ -54,14 +54,14 @@ int FindUtils::replaceAll(QTextEdit *view, const QString &str, const QString &re
return count;
}
int FindUtils::replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceStr, QTextDocument::FindFlags searchOptions)
int FindUtils::replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceStr, TextEditFindBarBase::FindFlags searchOptions)
{
auto document = view->document();
view->textCursor().beginEditBlock();
QTextCursor c(document);
int count = 0;
// Ignoring FindBackward when replacing all
const QTextDocument::FindFlags flags = searchOptions & ~QTextDocument::FindBackward;
const QTextDocument::FindFlags flags = FindUtils::convertTextEditFindFlags(searchOptions) & ~QTextDocument::FindBackward;
while (!c.isNull()) {
c = document->find(str, c, flags);
if (!c.isNull()) {
......@@ -76,13 +76,13 @@ int FindUtils::replaceAll(QPlainTextEdit *view, const QString &str, const QStrin
return count;
}
int FindUtils::replaceAll(QTextDocument *document, const QRegularExpression &regExp, const QString &replaceWidget, QTextDocument::FindFlags searchOptions)
int FindUtils::replaceAll(QTextDocument *document, const QRegularExpression &regExp, const QString &replaceWidget, TextEditFindBarBase::FindFlags searchOptions)
{
QTextCursor c(document);
c.beginEditBlock();
int count = 0;
// Ignoring FindBackward when replacing all
const QTextDocument::FindFlags flags = searchOptions & ~QTextDocument::FindBackward;
const QTextDocument::FindFlags flags = FindUtils::convertTextEditFindFlags(searchOptions) & ~QTextDocument::FindBackward;
while (!c.isNull()) {
c = document->find(regExp, c, flags);
if (!c.isNull()) {
......
......@@ -28,11 +28,11 @@ namespace FindUtils
* @return number of replacements done
*/
Q_REQUIRED_RESULT KPIMTEXTEDIT_TESTS_EXPORT int
replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
replaceAll(QPlainTextEdit *view, const QString &str, const QString &replaceWidget, TextEditFindBarBase::FindFlags searchOptions);
Q_REQUIRED_RESULT KPIMTEXTEDIT_TESTS_EXPORT int
replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
replaceAll(QTextEdit *view, const QString &str, const QString &replaceWidget, TextEditFindBarBase::FindFlags searchOptions);
Q_REQUIRED_RESULT KPIMTEXTEDIT_TESTS_EXPORT int
replaceAll(QTextDocument *document, const QRegularExpression &regExp, const QString &replaceWidget, QTextDocument::FindFlags searchOptions);
replaceAll(QTextDocument *document, const QRegularExpression &regExp, const QString &replaceWidget, TextEditFindBarBase::FindFlags searchOptions);
Q_REQUIRED_RESULT QString normalize(QStringView str);
Q_REQUIRED_RESULT QChar normalize(QChar c);
Q_REQUIRED_RESULT bool find(QPlainTextEdit *view, const QString &searchText, QTextDocument::FindFlags searchOptions);
......
......@@ -97,14 +97,14 @@ void PlainTextEditFindBarTest::shouldReplaceAllText_data()
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("searchText");
QTest::addColumn<QString>("replaceText");
QTest::addColumn<QTextDocument::FindFlags>("flags");
QTest::addColumn<KPIMTextEdit::TextEditFindBarBase::FindFlags>("flags");
QTest::addColumn<int>("nbElement");
QTest::newRow("empty") << QString() << QStringLiteral("blabla") << QStringLiteral("replace") << QTextDocument::FindFlags() << 0;
QTest::newRow("empty") << QString() << QStringLiteral("blabla") << QStringLiteral("replace") << KPIMTextEdit::TextEditFindBarBase::FindFlags() << 0;
{
QTextDocument::FindFlags flags;
flags |= QTextDocument::FindWholeWords;
KPIMTextEdit::TextEditFindBarBase::FindFlags flags;
flags |= KPIMTextEdit::TextEditFindBarBase::FindWholeWords;
QTest::newRow("bla") << QStringLiteral("bla bla") << QStringLiteral("bla") << QStringLiteral("replace") << flags << 2;
}
}
......@@ -114,7 +114,7 @@ void PlainTextEditFindBarTest::shouldReplaceAllText()
QFETCH(QString, text);
QFETCH(QString, searchText);
QFETCH(QString, replaceText);
QFETCH(QTextDocument::FindFlags, flags);
QFETCH(KPIMTextEdit::TextEditFindBarBase::FindFlags, flags);
QFETCH(int, nbElement);
QPlainTextEdit edit;
......
......@@ -113,7 +113,7 @@ void PlainTextEditFindBar::slotReplaceAllText()
{
int count = 0;
const QString replaceStr{mReplaceWidget->replaceLineEdit()->text()};
const QTextDocument::FindFlags searchOptions{FindUtils::convertTextEditFindFlags(mFindWidget->searchOptions())};
const TextEditFindBarBase::FindFlags searchOptions{mFindWidget->searchOptions()};
if (mFindWidget->isRegularExpression()) {
count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchRegularExpression(), replaceStr, searchOptions);
} else {
......
......@@ -103,7 +103,7 @@ void RichTextEditFindBar::slotReplaceAllText()
{
int count = 0;
const QString replaceStr{mReplaceWidget->replaceLineEdit()->text()};
const QTextDocument::FindFlags searchOptions{FindUtils::convertTextEditFindFlags(mFindWidget->searchOptions())};
const TextEditFindBarBase::FindFlags searchOptions{mFindWidget->searchOptions()};
if (mFindWidget->isRegularExpression()) {
count = FindUtils::replaceAll(d->mView->document(), mFindWidget->searchRegularExpression(), replaceStr, searchOptions);
} else {
......
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