1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "arrowsmodel.h"
5
6ArrowsModel::ArrowsModel(QObject *parent)
7 : QAbstractListModel(parent)
8{
9 connect(sender: this, signal: &QAbstractListModel::rowsInserted, context: this, slot: &ArrowsModel::rowCountChanged);
10 connect(sender: this, signal: &QAbstractListModel::rowsRemoved, context: this, slot: &ArrowsModel::rowCountChanged);
11 connect(sender: this, signal: &QAbstractListModel::modelReset, context: this, slot: &ArrowsModel::rowCountChanged);
12}
13
14int ArrowsModel::rowCount(const QModelIndex &) const
15{
16 return m_arrowsList.size();
17}
18
19QHash<int, QByteArray> ArrowsModel::roleNames() const
20{
21 QHash<int, QByteArray> roles;
22 roles[StartX] = "startX";
23 roles[StartY] = "startY";
24 roles[EndX] = "endX";
25 roles[EndY] = "endY";
26 roles[StartNodeId] = "startNodeId";
27 roles[EndNodeId] = "endNodeId";
28 return roles;
29}
30
31QVariant ArrowsModel::data(const QModelIndex &index, int role) const
32{
33 if (!index.isValid())
34 return QVariant();
35
36 if (index.row() >= m_arrowsList.size())
37 return false;
38
39 const auto &node = (m_arrowsList)[index.row()];
40
41 if (role == StartX)
42 return QVariant::fromValue(value: node.startX);
43 else if (role == StartY)
44 return QVariant::fromValue(value: node.startY);
45 else if (role == EndX)
46 return QVariant::fromValue(value: node.endX);
47 else if (role == EndY)
48 return QVariant::fromValue(value: node.endY);
49 else if (role == StartNodeId)
50 return QVariant::fromValue(value: node.startNodeId);
51 else if (role == EndNodeId)
52 return QVariant::fromValue(value: node.endNodeId);
53
54 return QVariant();
55}
56

source code of qtquickeffectmaker/tools/qqem/arrowsmodel.cpp