Skip to content

Commit

Permalink
linguist: Use flags for find filtering options
Browse files Browse the repository at this point in the history
Change-Id: I469c987085c77d5c35296200f3cf28b4c44f5d51
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: Jörg Bornemann <[email protected]>
  • Loading branch information
martonmiklos committed Apr 5, 2022
1 parent 36dd555 commit 397309d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
9 changes: 6 additions & 3 deletions src/linguist/linguist/finddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ void FindDialog::emitFindNext()
(comments->isChecked() ? DataModel::Comments : 0));
else
where = DataModel::Translations;
emit findNext(led->text(), where, matchCase->isChecked(), ignoreAccelerators->isChecked(),
skipObsolete->isChecked(), useRegExp->isChecked(),
statusFilter->currentData().toInt());

FindOptions options((matchCase->isChecked() ? FindOption::MatchCase : 0) |
(ignoreAccelerators->isChecked() ? FindDialog::IgnoreAccelerators : 0) |
(skipObsolete->isChecked() ? FindDialog::SkipObsolete : 0) |
(useRegExp->isChecked() ? FindDialog::UseRegExp : 0));
emit findNext(led->text(), where, options, statusFilter->currentData().toInt());
led->selectAll();
}

Expand Down
10 changes: 8 additions & 2 deletions src/linguist/linguist/finddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ class FindDialog : public QDialog, public Ui::FindDialog
{
Q_OBJECT
public:
enum FindOption {
MatchCase = 0x1,
IgnoreAccelerators = 0x2,
SkipObsolete = 0x4,
UseRegExp = 0x8
};
Q_DECLARE_FLAGS(FindOptions, FindOption)
FindDialog(QWidget *parent = 0);
QRegularExpression &getRegExp() { return m_regExp; }

signals:
void findNext(const QString& text, DataModel::FindLocation where,
bool matchCase, bool ignoreAccelerators, bool skipObsolete, bool useRegExp,
int statusFilter);
FindDialog::FindOptions options, int statusFilter);

public slots:
void find();
Expand Down
30 changes: 12 additions & 18 deletions src/linguist/linguist/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ MainWindow::MainWindow()
: QMainWindow(0, Qt::Window),
m_assistantProcess(0),
m_printer(0),
m_findMatchCase(Qt::CaseInsensitive),
m_findIgnoreAccelerators(true),
m_findSkipObsolete(false),
m_findUseRegExp(false),
m_findWhere(DataModel::NoLocation),
m_translationSettingsDialog(0),
m_settingCurrentMessage(false),
Expand Down Expand Up @@ -979,14 +975,15 @@ bool MainWindow::searchItem(DataModel::FindLocation where, const QString &search

QString text = searchWhat;

if (m_findIgnoreAccelerators)
if (m_findOptions.testFlag(FindDialog::IgnoreAccelerators))
// FIXME: This removes too much. The proper solution might be too slow, though.
text.remove(QLatin1Char('&'));

if (m_findUseRegExp)
if (m_findOptions.testFlag(FindDialog::UseRegExp))
return m_findDialog->getRegExp().match(text).hasMatch();
else
return text.indexOf(m_findText, 0, m_findMatchCase) >= 0;
return text.indexOf(m_findText, 0, m_findOptions.testFlag(FindDialog::MatchCase)
? Qt::CaseSensitive : Qt::CaseInsensitive) >= 0;
}

void MainWindow::findAgain()
Expand All @@ -1003,10 +1000,11 @@ void MainWindow::findAgain()
bool hadMessage = false;
for (int i = 0; i < m_dataModel->modelCount(); ++i) {
if (MessageItem *m = m_dataModel->messageItem(dataIndex, i)) {
if (m_statusFilter != -1 && m_statusFilter != m->type())
if (m_findStatusFilter != -1 && m_findStatusFilter != m->type())
continue;

if (m_findSkipObsolete && m->isObsolete())
if (m_findOptions.testFlag(FindDialog::SkipObsolete)
&& m->isObsolete())
continue;

bool found = true;
Expand Down Expand Up @@ -1780,20 +1778,16 @@ bool MainWindow::doNext(bool checkUnfinished)
}

void MainWindow::findNext(const QString &text, DataModel::FindLocation where,
bool matchCase, bool ignoreAccelerators, bool skipObsolete, bool useRegExp,
int statusFilter)
FindDialog::FindOptions options, int statusFilter)
{
if (text.isEmpty())
return;
m_findText = text;
m_findWhere = where;
m_findMatchCase = matchCase ? Qt::CaseSensitive : Qt::CaseInsensitive;
m_findIgnoreAccelerators = ignoreAccelerators;
m_findSkipObsolete = skipObsolete;
m_findUseRegExp = useRegExp;
m_statusFilter = statusFilter;
if (m_findUseRegExp) {
m_findDialog->getRegExp().setPatternOptions(matchCase
m_findOptions = options;
m_findStatusFilter = statusFilter;
if (options.testFlag(FindDialog::UseRegExp)) {
m_findDialog->getRegExp().setPatternOptions(options.testFlag(FindDialog::MatchCase)
? QRegularExpression::NoPatternOption
: QRegularExpression::CaseInsensitiveOption);
}
Expand Down
12 changes: 4 additions & 8 deletions src/linguist/linguist/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ui_mainwindow.h"
#include "recentfiles.h"
#include "messagemodel.h"
#include "finddialog.h"

#include <QtCore/QHash>
#include <QtCore/QMap>
Expand All @@ -57,7 +58,6 @@ class QTreeView;

class BatchTranslationDialog;
class ErrorsView;
class FindDialog;
class FocusWatcher;
class FormPreviewView;
class MessageEditor;
Expand Down Expand Up @@ -155,8 +155,7 @@ private slots:
void prevUnfinished();
void nextUnfinished();
void findNext(const QString &text, DataModel::FindLocation where,
bool matchCase, bool ignoreAccelerators, bool skipObsolete, bool regularExp,
int statusFilter);
FindDialog::FindOptions options, int statusFilter);
void revalidate();
void toggleStatistics();
void toggleVisualizeWhitespace();
Expand Down Expand Up @@ -228,11 +227,8 @@ private slots:

FindDialog *m_findDialog;
QString m_findText;
Qt::CaseSensitivity m_findMatchCase;
bool m_findIgnoreAccelerators;
bool m_findSkipObsolete;
bool m_findUseRegExp;
int m_statusFilter = -1;
FindDialog::FindOptions m_findOptions;
int m_findStatusFilter = -1;
DataModel::FindLocation m_findWhere;

TranslateDialog *m_translateDialog;
Expand Down

0 comments on commit 397309d

Please sign in to comment.