1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2020 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include <bindingeditor/signallistdialog.h> 29 #include <qmldesignercorelib_global.h> 30 #include <modelnode.h> 31 #include <qmlconnections.h> 32 33 #include <QtQml> 34 #include <QObject> 35 #include <QPointer> 36 #include <QStandardItemModel> 37 38 namespace QmlDesigner { 39 40 class SignalListModel : public QStandardItemModel 41 { 42 Q_OBJECT 43 44 public: 45 enum ColumnRoles : unsigned int { 46 TargetColumn = 0, 47 SignalColumn = 1, 48 ButtonColumn = 2 49 }; 50 enum UserRoles : unsigned int { 51 ConnectionsInternalIdRole = Qt::UserRole + 1, 52 ConnectedRole 53 }; 54 55 SignalListModel(QObject *parent = nullptr); 56 57 void setConnected(int row, bool connected); 58 }; 59 60 class SignalListFilterModel : public QSortFilterProxyModel 61 { 62 Q_OBJECT 63 64 public: 65 SignalListFilterModel(QObject *parent = nullptr); 66 67 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 68 }; 69 70 class SignalList : public QObject 71 { 72 Q_OBJECT 73 74 public: 75 explicit SignalList(QObject *parent = nullptr); 76 ~SignalList(); 77 78 static SignalList* showWidget(const ModelNode &modelNode); 79 80 void setModelNode(const ModelNode &modelNode); 81 void connectClicked(const QModelIndex &modelIndex); 82 83 private: 84 void prepareDialog(); 85 void showWidget(); 86 void hideWidget(); 87 88 void prepareSignals(); 89 90 void appendSignalToModel(const QList<QmlConnections> &connections, 91 ModelNode &node, 92 const PropertyName &signal, 93 const PropertyName &property = ""); 94 95 void addConnection(const QModelIndex &modelIndex); 96 void removeConnection(const QModelIndex &modelIndex); 97 98 private: 99 QPointer<SignalListDialog> m_dialog; 100 SignalListModel *m_model; 101 ModelNode m_modelNode; 102 }; 103 104 } // QmlDesigner namespace 105