aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/modelinglib/qmt/model_ui/sortedtreemodel.h
blob: 797a321132153ff1883278d9542ef4649e3d5613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2016 Jochen Becher
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "qmt/infrastructure/qmt_global.h"
#include "qmt/model_ui/modeltreefilterdata.h"

#include <QSortFilterProxyModel>
#include <QTimer>

namespace qmt {

class TreeModel;

class QMT_EXPORT SortedTreeModel : public QSortFilterProxyModel
{
public:
    explicit SortedTreeModel(QObject *parent = nullptr);
    ~SortedTreeModel() override;

    TreeModel *treeModel() const { return m_treeModel; }
    void setTreeModel(TreeModel *treeModel);

    void setModelTreeViewData(const ModelTreeViewData &viewData);
    void setModelTreeFilterData(const ModelTreeFilterData &filterData);

protected:
    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
    bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;

private:
    void onTreeModelRowsInserted(const QModelIndex &parent, int start, int end);
    void onDataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &);
    void onDelayedSortTimeout();

    void startDelayedSortTimer();

    TreeModel *m_treeModel = nullptr;
    ModelTreeViewData m_modelTreeViewData;
    ModelTreeFilterData m_modelTreeViewFilterData;
    QTimer m_delayedSortTimer;
};

} // namespace qmt