Qt: Add case sensitive find to Follow Stream and Show Packet Bytes
Add a check box for case sensitivity when finding in follow stream and show packet bytes. Note that QPlainTextEdit::find() has a bit unexpected behavior with QRegularExpression (https://bugreports.qt.io/browse/QTBUG-88721). Searches are case-insensitive by default there too, respecting the default options. This is a change from the older QRegExp, where the option to find was ignored, and only the regex option was used, so for the last few releases regexp searches have been case-insensitive as well by default. (?-i) has been available to mode switch. We might want to move the various keyboard handling from FollowStreamDialog and ShowPacketBytesDialog and instead have FindLineEdit install shortcuts on the parents when constructed. That would be a little cleaner separation. We might also want to move the buttons and label to a separate composite widget class, that signals the parent to start a find. Fix #3784
This commit is contained in:
parent
3540bbc969
commit
d22842f662
|
@ -279,15 +279,33 @@ void FollowStreamDialog::findText(bool go_back)
|
|||
if (ui->leFind->text().isEmpty()) return;
|
||||
|
||||
bool found;
|
||||
|
||||
QTextDocument::FindFlags options;
|
||||
if (ui->caseCheckBox->isChecked()) {
|
||||
options |= QTextDocument::FindCaseSensitively;
|
||||
}
|
||||
if (use_regex_find_) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
// https://bugreports.qt.io/browse/QTBUG-88721
|
||||
// QPlainTextEdit::find() searches case-insensitively unless
|
||||
// QTextDocument::FindCaseSensitively is explicitly given.
|
||||
// This *does* apply to QRegularExpression (overriding
|
||||
// CaseInsensitiveOption), but not QRegExp.
|
||||
//
|
||||
// QRegularExpression and QRegExp do not support Perl's /i, but
|
||||
// the former at least does support the mode modifiers (?i) and
|
||||
// (?-i), which can override QTextDocument::FindCaseSensitively.
|
||||
//
|
||||
// To make matters worse, while the QTextDocument::find() documentation
|
||||
// is correct, QPlainTextEdit::find() claims that QRegularExpression
|
||||
// works like QRegExp, which is incorrect.
|
||||
QRegularExpression regex(ui->leFind->text(), QRegularExpression::UseUnicodePropertiesOption);
|
||||
#else
|
||||
QRegExp regex(ui->leFind->text());
|
||||
QRegExp regex(ui->leFind->text(), (options & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
#endif
|
||||
found = ui->teStreamContent->find(regex);
|
||||
found = ui->teStreamContent->find(regex, options);
|
||||
} else {
|
||||
found = ui->teStreamContent->find(ui->leFind->text());
|
||||
found = ui->teStreamContent->find(ui->leFind->text(), options);
|
||||
}
|
||||
|
||||
if (found) {
|
||||
|
|
|
@ -155,6 +155,13 @@
|
|||
<item>
|
||||
<widget class="FindLineEdit" name="leFind"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="caseCheckBox">
|
||||
<property name="text">
|
||||
<string>Case sensitive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bFind">
|
||||
<property name="text">
|
||||
|
|
|
@ -247,15 +247,33 @@ void ShowPacketBytesDialog::findText(bool go_back)
|
|||
if (ui->leFind->text().isEmpty()) return;
|
||||
|
||||
bool found;
|
||||
|
||||
QTextDocument::FindFlags options;
|
||||
if (ui->caseCheckBox->isChecked()) {
|
||||
options |= QTextDocument::FindCaseSensitively;
|
||||
}
|
||||
if (use_regex_find_) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
// https://bugreports.qt.io/browse/QTBUG-88721
|
||||
// QPlainTextEdit::find() searches case-insensitively unless
|
||||
// QTextDocument::FindCaseSensitively is explicitly given.
|
||||
// This *does* apply to QRegularExpression (overriding
|
||||
// CaseInsensitiveOption), but not QRegExp.
|
||||
//
|
||||
// QRegularExpression and QRegExp do not support Perl's /i, but
|
||||
// the former at least does support the mode modifiers (?i) and
|
||||
// (?-i), which can override QTextDocument::FindCaseSensitively.
|
||||
//
|
||||
// To make matters worse, while the QTextDocument::find() documentation
|
||||
// is correct, QPlainTextEdit::find() claims that QRegularExpression
|
||||
// works like QRegExp, which is incorrect.
|
||||
QRegularExpression regex(ui->leFind->text(), QRegularExpression::UseUnicodePropertiesOption);
|
||||
#else
|
||||
QRegExp regex(ui->leFind->text());
|
||||
QRegExp regex(ui->leFind->text(), (options & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
#endif
|
||||
found = ui->tePacketBytes->find(regex);
|
||||
found = ui->tePacketBytes->find(regex, std::move(options));
|
||||
} else {
|
||||
found = ui->tePacketBytes->find(ui->leFind->text());
|
||||
found = ui->tePacketBytes->find(ui->leFind->text(), std::move(options));
|
||||
}
|
||||
|
||||
if (found) {
|
||||
|
|
|
@ -116,6 +116,13 @@
|
|||
<item>
|
||||
<widget class="FindLineEdit" name="leFind"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="caseCheckBox">
|
||||
<property name="text">
|
||||
<string>Case sensitive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bFind">
|
||||
<property name="text">
|
||||
|
|
Loading…
Reference in New Issue