aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/eventlist/eventlistview.h
blob: 1c27f4be32fc5098314f0429dbde5d42a5eaf16a (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once

#include "eventlist.h"

#include <abstractview.h>
#include <QStandardItemModel>

namespace QmlDesigner {

struct Event
{
    QString eventId;
    QString shortcut;
    QString description;
};

class EventListModel : public QStandardItemModel
{
    Q_OBJECT

public:
    enum Columns {
        idColumn = 0,
        descriptionColumn = 1,
        shortcutColumn = 2,
        connectColumn = 3
    };

    enum Roles : unsigned int {
        connectedRole = Qt::UserRole + 1,
    };

    EventListModel(QObject *parent = nullptr);

    QStringList connectedEvents() const;

    QStringList connectEvents(const QStringList &eventIds);
};


class EventListDialog;
class AssignEventDialog;
class ConnectSignalDialog;

class EventListView : public AbstractView
{
    Q_OBJECT

public:
    explicit EventListView(QObject *parent = nullptr);
    ~EventListView() override;

    void nodeRemoved(const ModelNode &removedNode,
                     const NodeAbstractProperty &parentProperty,
                     PropertyChangeFlags propertyChange) override;

    void nodeReparented(const ModelNode &node,
                        const NodeAbstractProperty &newPropertyParent,
                        const NodeAbstractProperty &oldPropertyParent,
                        PropertyChangeFlags propertyChange) override;

    EventListModel *eventListModel() const;

    void addEvent(const Event &event);
    void removeEvent(const QString &name);
    void renameEvent(const QString &oldId, const QString &newId);
    void setShortcut(const QString &id, const QString &text);
    void setDescription(const QString &id, const QString &text);

private:
    void reset();

    EventList m_eventlist;
    EventListModel *m_model;
};

} // namespace QmlDesigner.