QTfrontend/model/ThemeFilterProxyModel.cpp
author Wuzzy <Wuzzy2@mail.ru>
Thu, 11 Jul 2019 16:24:09 +0200
changeset 15252 c10e9261ab9c
parent 14849 8ed0c3761640
permissions -rw-r--r--
Make lowest line of Splash image frames transparent to work around scaling issues The Splash image is scaled. Sometimes, the lowest line is repeated on the top, which caused some weird lines to appear above big splashes (e.g. piano). This has been done fully automated with a script. Only the alpha channel was changed. The color information is preserved.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13247
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     1
/*
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2004-2018 Andrey Korotaev <unC0Rr@gmail.com>
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     4
 *
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     8
 *
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    13
 *
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    17
 */
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    18
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    19
/**
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    20
 * @file
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    21
 * @brief ThemeFilterProxyModel class implementation
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    22
 */
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    23
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    24
#include "ThemeModel.h"
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    25
#include "ThemeFilterProxyModel.h"
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    26
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    27
ThemeFilterProxyModel::ThemeFilterProxyModel(QObject *parent)
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    28
    : QSortFilterProxyModel(parent)
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    29
{
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    30
    isFilteringDLC = false;
13248
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    31
    isFilteringHidden = false;
14849
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    32
    isFilteringBackground = false;
13247
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
}
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    35
bool ThemeFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    36
{
13283
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    37
    QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    38
    bool searchOkay = true;
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    39
    if(!filterRegExp().isEmpty())
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    40
    {
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    41
        // Check regular expression set by the theme chooser search
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    42
        QString name = index.data(ThemeModel::ActualNameRole).toString();
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    43
        int in = filterRegExp().indexIn(name);
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    44
        searchOkay = in != -1;
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    45
    }
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    46
14849
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    47
    if(isFilteringDLC || isFilteringHidden || isFilteringBackground)
13247
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    48
    {
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    49
        bool isDLC = index.data(ThemeModel::IsDlcRole).toBool();
13248
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    50
        bool isHidden = index.data(ThemeModel::IsHiddenRole).toBool();
14849
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    51
        bool isBackground = index.data(ThemeModel::IsBackgroundThemeRole).toBool();
13283
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    52
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    53
        return ( ((isFilteringDLC && !isDLC) || !isFilteringDLC) &&
14849
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    54
                 ((isFilteringHidden && !isHidden) || !isFilteringHidden) &&
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    55
                 ((isFilteringBackground && !isBackground) || !isFilteringBackground) ) &&
13283
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    56
               searchOkay;
13247
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    57
    }
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    58
    else
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    59
    {
13283
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13257
diff changeset
    60
        return searchOkay;
13247
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    61
    }
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    62
}
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    63
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    64
void ThemeFilterProxyModel::setFilterDLC(bool enable)
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    65
{
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    66
    isFilteringDLC = enable;
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    67
    invalidateFilter();
4df9d8cedf7f ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    68
}
13248
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    69
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    70
void ThemeFilterProxyModel::setFilterHidden(bool enable)
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    71
{
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    72
    isFilteringHidden = enable;
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    73
    invalidateFilter();
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 13247
diff changeset
    74
}
14849
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    75
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    76
void ThemeFilterProxyModel::setFilterBackground(bool enable)
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    77
{
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    78
    isFilteringBackground = enable;
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    79
    invalidateFilter();
8ed0c3761640 Change theme to Nature if changing from background-only or hidden theme to a generated map type
Wuzzy <Wuzzy2@mail.ru>
parents: 13283
diff changeset
    80
};