aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/collectioneditor/collectiondetailssortfiltermodel.h
blob: 10f6e09b0573434722445de46b3354e64dccbf38 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <QPointer>
#include <QSortFilterProxyModel>

namespace QmlDesigner {

class CollectionDetailsModel;

class CollectionDetailsSortFilterModel : public QSortFilterProxyModel
{
    Q_OBJECT

    Q_PROPERTY(int selectedColumn READ selectedColumn WRITE selectColumn NOTIFY selectedColumnChanged)
    Q_PROPERTY(int selectedRow READ selectedRow WRITE selectRow NOTIFY selectedRowChanged)
    Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)

    using Super = QSortFilterProxyModel;

public:
    explicit CollectionDetailsSortFilterModel(QObject *parent = nullptr);
    virtual ~CollectionDetailsSortFilterModel();

    void setSourceModel(CollectionDetailsModel *model);

    int selectedRow() const;
    int selectedColumn() const;

    Q_INVOKABLE bool selectRow(int row);
    Q_INVOKABLE bool selectColumn(int column);
    Q_INVOKABLE void deselectAll();

signals:
    void selectedColumnChanged(int);
    void selectedRowChanged(int);
    void isEmptyChanged(bool);

protected:
    using Super::setSourceModel;
    bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
    bool lessThan(const QModelIndex &sourceleft, const QModelIndex &sourceRight) const override;

private:
    void updateEmpty();
    void updateSelectedRow();
    void updateSelectedColumn();
    void updateRowCountChanges();

    QPointer<CollectionDetailsModel> m_source;
    int m_selectedColumn = -1;
    int m_selectedRow = -1;
    bool m_isEmpty = true;
};

} // namespace QmlDesigner