summaryrefslogtreecommitdiffstats
path: root/tools/qqem/arrowsmodel.h
blob: f19fe627213594d0f9aed20938fe3bff92d30547 (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef ARROWSMODEL_H
#define ARROWSMODEL_H

#include <QObject>
#include <QAbstractListModel>
#include <QtQml/qqmlregistration.h>

class ArrowsModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)

public:
    struct Arrow {
        float startX = 0;
        float startY = 0;
        float endX = 0;
        float endY = 0;
        int startNodeId = 0;
        int endNodeId = 1;
        bool operator==(const Arrow& rhs) const noexcept
        {
           return this->startNodeId == rhs.startNodeId;
        }
    };

    enum NodesModelRoles {
        Type = Qt::UserRole + 1,
        StartX,
        StartY,
        EndX,
        EndY,
        StartNodeId,
        EndNodeId
    };

    explicit ArrowsModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex & = QModelIndex()) const final;
    QVariant data(const QModelIndex &index, int role) const final;
    QHash<int, QByteArray> roleNames() const final;

signals:
    void rowCountChanged();

private:
    friend class NodeView;
    friend class EffectManager;
    QList<Arrow> m_arrowsList;

};

#endif // ARROWSMODEL_H