Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KPimTextEdit
Commits
1c9e0372
Commit
1c9e0372
authored
Feb 17, 2022
by
Laurent Montel
Browse files
Simplify code
parent
ab5d03ce
Pipeline
#139190
passed with stages
in 2 minutes and 36 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/texteditor/commonwidget/findutils.cpp
View file @
1c9e0372
...
...
@@ -40,7 +40,7 @@ int FindUtils::replaceAll(QTextDocument *document, const TextFindWidget *findWid
return
count
;
}
bool
FindUtils
::
find
(
QPlainTextEdit
*
view
,
const
TextFindWidget
*
findWidget
)
bool
FindUtils
::
find
(
QPlainTextEdit
*
view
,
const
QString
&
searchText
,
QTextDocument
::
FindFlags
searchOptions
)
{
const
QString
text
=
FindUtils
::
normalize
(
view
->
document
()
->
toPlainText
());
QTextDocument
doc
(
text
);
...
...
@@ -48,12 +48,7 @@ bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
QTextCursor
docCusor
(
view
->
textCursor
());
c
.
setPosition
(
docCusor
.
position
());
qDebug
()
<<
" docCusor.position() "
<<
docCusor
.
position
();
QTextDocument
::
FindFlags
flags
=
findWidget
->
searchOptions
()
&
~
QTextDocument
::
FindBackward
;
if
(
findWidget
->
isRegularExpression
())
{
c
=
doc
.
find
(
FindUtils
::
normalize
(
findWidget
->
searchText
()),
c
,
flags
);
}
else
{
c
=
doc
.
find
(
FindUtils
::
normalize
(
findWidget
->
searchText
()),
c
,
flags
);
}
c
=
doc
.
find
(
FindUtils
::
normalize
(
searchText
),
c
,
searchOptions
);
if
(
!
c
.
isNull
())
{
qDebug
()
<<
" c.selectionStart() "
<<
c
.
selectionStart
()
<<
"c.selectionEnd() "
<<
c
.
selectionEnd
();
docCusor
.
setPosition
(
c
.
selectionStart
());
...
...
@@ -65,7 +60,7 @@ bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
return
false
;
}
bool
FindUtils
::
find
(
QTextEdit
*
view
,
const
TextFindWidget
*
findWidget
)
bool
FindUtils
::
find
(
QTextEdit
*
view
,
const
QString
&
searchText
,
QTextDocument
::
FindFlags
searchOptions
)
{
const
QString
text
=
FindUtils
::
normalize
(
view
->
document
()
->
toPlainText
());
QTextDocument
doc
(
text
);
...
...
@@ -73,12 +68,7 @@ bool FindUtils::find(QTextEdit *view, const TextFindWidget *findWidget)
QTextCursor
docCusor
(
view
->
textCursor
());
c
.
setPosition
(
docCusor
.
position
());
qDebug
()
<<
" docCusor.position() "
<<
docCusor
.
position
();
QTextDocument
::
FindFlags
flags
=
findWidget
->
searchOptions
()
&
~
QTextDocument
::
FindBackward
;
if
(
findWidget
->
isRegularExpression
())
{
c
=
doc
.
find
(
FindUtils
::
normalize
(
findWidget
->
searchText
()),
c
,
flags
);
}
else
{
c
=
doc
.
find
(
FindUtils
::
normalize
(
findWidget
->
searchText
()),
c
,
flags
);
}
c
=
doc
.
find
(
FindUtils
::
normalize
(
searchText
),
c
,
searchOptions
);
if
(
!
c
.
isNull
())
{
qDebug
()
<<
" c.selectionStart() "
<<
c
.
selectionStart
()
<<
"c.selectionEnd() "
<<
c
.
selectionEnd
();
docCusor
.
setPosition
(
c
.
selectionStart
());
...
...
src/texteditor/commonwidget/findutils.h
View file @
1c9e0372
...
...
@@ -8,8 +8,8 @@
#include
<QChar>
#include
<QStringView>
#include
<QTextDocument>
#include
<qglobal.h>
class
QTextDocument
;
class
QPlainTextEdit
;
class
QTextEdit
;
namespace
KPIMTextEdit
...
...
@@ -29,8 +29,8 @@ Q_REQUIRED_RESULT int replaceAll(QTextDocument *document, const TextFindWidget *
Q_REQUIRED_RESULT
QString
normalize
(
QStringView
str
);
Q_REQUIRED_RESULT
QChar
normalize
(
QChar
c
);
Q_REQUIRED_RESULT
bool
find
(
QPlainTextEdit
*
view
,
const
TextFindWidget
*
findWidget
);
Q_REQUIRED_RESULT
bool
find
(
QTextEdit
*
view
,
const
TextFindWidget
*
findWidget
);
Q_REQUIRED_RESULT
bool
find
(
QPlainTextEdit
*
view
,
const
QString
&
searchText
,
QTextDocument
::
FindFlags
searchOptions
);
Q_REQUIRED_RESULT
bool
find
(
QTextEdit
*
view
,
const
QString
&
searchText
,
QTextDocument
::
FindFlags
searchOptions
);
}
}
// namespace KPIMTextEdit
src/texteditor/plaintexteditor/plaintexteditfindbar.cpp
View file @
1c9e0372
...
...
@@ -54,7 +54,7 @@ bool PlainTextEditFindBar::documentIsEmpty() const
bool
PlainTextEditFindBar
::
searchInDocument
(
const
QString
&
text
,
QTextDocument
::
FindFlags
searchOptions
)
{
#ifdef SEARCH_DIACRITIC_WORD
const
bool
found
=
FindUtils
::
find
(
d
->
mView
,
mFindWidget
);
const
bool
found
=
FindUtils
::
find
(
d
->
mView
,
text
,
searchOptions
);
#else
const
bool
found
=
d
->
mView
->
find
(
text
,
searchOptions
);
#endif
...
...
src/texteditor/richtexteditor/richtexteditfindbar.cpp
View file @
1c9e0372
...
...
@@ -54,7 +54,7 @@ bool RichTextEditFindBar::documentIsEmpty() const
bool
RichTextEditFindBar
::
searchInDocument
(
const
QString
&
text
,
QTextDocument
::
FindFlags
searchOptions
)
{
#ifdef SEARCH_DIACRITIC_WORD
const
bool
found
=
FindUtils
::
find
(
d
->
mView
,
mFindWidget
);
const
bool
found
=
FindUtils
::
find
(
d
->
mView
,
text
,
searchOptions
);
#else
const
bool
found
=
d
->
mView
->
find
(
text
,
searchOptions
);
#endif
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment