Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mon / Qt Apps] Fixed filter-function #1591

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion lib/CustomQt/src/QMulticolumnSortFilterProxyModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ QVector<int> QMulticolumnSortFilterProxyModel::filterKeyColumns() const

bool QMulticolumnSortFilterProxyModel::filterDirectAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
QRegularExpression const filter_regexp = filterRegularExpression();
// Qt 5 uses the deprecated QRegExp by default when setting a FilterFixedString. The QRegularExpression is then empty
// QRegularExpression didn't even exist in Qt 5.11 and earlier
// Qt 6 sets the QRegularExpression (QRegExp does not exist anymore) when setting a FilterFixedString.

#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
// For Qt5.11 there only exists the RegExp, so we need to check the QRegExp

QRegExp const filter_regexp = filterRegExp();

for (int column : filter_columns_)
{
Expand All @@ -72,6 +79,65 @@ bool QMulticolumnSortFilterProxyModel::filterDirectAcceptsRow(int source_row, co
}
}
return false;

#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// For Qt5.12 - 5.15 (i.e. pre-Qt6) we need to check the QRegExp and the QRegularExpression
QRegExp const filter_regexp = filterRegExp();

if (!filter_regexp.isEmpty())
{
// Use QRegExp
for (int column : filter_columns_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: replace loop by 'std::any_of()' [readability-use-anyofallof]

    for (int column : filter_columns_)
    ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'column' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
for (int column : filter_columns_)
for (int const column : filter_columns_)

{
QModelIndex index = sourceModel()->index(source_row, column, source_parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'index' of type 'QModelIndex' can be declared 'const' [misc-const-correctness]

Suggested change
QModelIndex index = sourceModel()->index(source_row, column, source_parent);
QModelIndex const index = sourceModel()->index(source_row, column, source_parent);

if (index.isValid())
{
QString data = sourceModel()->data(index, filterRole()).toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'data' of type 'QString' can be declared 'const' [misc-const-correctness]

Suggested change
QString data = sourceModel()->data(index, filterRole()).toString();
QString const data = sourceModel()->data(index, filterRole()).toString();

if (data.contains(filter_regexp))
{
return true;
}
}
}
return false;
}
else
{
// Use QRegularExpression, as QRegExp is empty
QRegularExpression const filter_regularexpression = filterRegularExpression();

for (int column : filter_columns_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: replace loop by 'std::any_of()' [readability-use-anyofallof]

    for (int column : filter_columns_)
    ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'column' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
for (int column : filter_columns_)
for (int const column : filter_columns_)

{
QModelIndex index = sourceModel()->index(source_row, column, source_parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'index' of type 'QModelIndex' can be declared 'const' [misc-const-correctness]

Suggested change
QModelIndex index = sourceModel()->index(source_row, column, source_parent);
QModelIndex const index = sourceModel()->index(source_row, column, source_parent);

if (index.isValid())
{
QString data = sourceModel()->data(index, filterRole()).toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'data' of type 'QString' can be declared 'const' [misc-const-correctness]

Suggested change
QString data = sourceModel()->data(index, filterRole()).toString();
QString const data = sourceModel()->data(index, filterRole()).toString();

if (data.contains(filter_regularexpression))
{
return true;
}
}
}
return false;
}
#else
// For Qt6 we only need to check the QRegularExpression
QRegularExpression const filter_regularexpression = filterRegularExpression();

for (int column : filter_columns_)
{
QModelIndex index = sourceModel()->index(source_row, column, source_parent);
if (index.isValid())
{
QString data = sourceModel()->data(index, filterRole()).toString();
if (data.contains(filter_regularexpression))
{
return true;
}
}
}
return false;
#endif
}

////////////////////////////////////////////
Expand Down
Loading