tripgroupproxymodel.h 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
15
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*/

#ifndef TRIPGROUPPROXYMODEL_H
#define TRIPGROUPPROXYMODEL_H

#include <QSet>
#include <QSortFilterProxyModel>

class TimelineModel;

/** Proxy model for expanding/collapsing trip groups. */
class TripGroupProxyModel : public QSortFilterProxyModel
{
    Q_OBJECT
    Q_PROPERTY(int todayRow READ todayRow NOTIFY todayRowChanged)
public:
    explicit TripGroupProxyModel(QObject *parent = nullptr);
Laurent Montel's avatar
Laurent Montel committed
33
    ~TripGroupProxyModel() override;
34 35 36 37 38 39 40 41 42 43 44

    void setSourceModel(QAbstractItemModel *sourceModel) override;
    QVariant data(const QModelIndex & index, int role) const override;
    bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;

    Q_INVOKABLE void collapse(const QString &groupId);
    Q_INVOKABLE void expand(const QString &groupId);

    // "override" from TimelineModel
    int todayRow();

45
Q_SIGNALS:
46 47 48
    void todayRowChanged();

private:
49 50
    bool isCollapsed(const QString &groupId) const;

51
    TimelineModel *m_sourceModel = nullptr;
52
    QHash<QString, bool> m_collapsed;
53 54 55
};

#endif // TRIPGROUPPROXYMODEL_H