1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Designer of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 // 30 // W A R N I N G 31 // ------------- 32 // 33 // This file is not part of the Qt API. It exists for the convenience 34 // of Qt Designer. This header 35 // file may change from version to version without notice, or even be removed. 36 // 37 // We mean it. 38 // 39 40 #ifndef _SIGNALSLOTDIALOG_H 41 #define _SIGNALSLOTDIALOG_H 42 43 #include "shared_global_p.h" 44 #include <QtCore/qstringlist.h> 45 #include <QtWidgets/qdialog.h> 46 #include <QtGui/qstandarditemmodel.h> 47 48 QT_BEGIN_NAMESPACE 49 50 class QDesignerFormEditorInterface; 51 class QDesignerFormWindowInterface; 52 class QDesignerDialogGuiInterface; 53 class QDesignerMemberSheet; 54 class QListView; 55 class QToolButton; 56 class QItemSelection; 57 58 namespace Ui { 59 class SignalSlotDialogClass; 60 } 61 62 namespace qdesigner_internal { 63 64 // Dialog data 65 struct SignalSlotDialogData { 66 void clear(); 67 QStringList m_existingMethods; 68 QStringList m_fakeMethods; 69 }; 70 71 // Internal helper class: A model for signatures that allows for verifying duplicates 72 // (checking signals versus slots and vice versa). 73 class SignatureModel : public QStandardItemModel { 74 Q_OBJECT 75 76 public: 77 SignatureModel(QObject *parent = nullptr); 78 bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 79 80 signals: 81 void checkSignature(const QString &signature, bool *ok); 82 }; 83 84 // Internal helper class: Panel for editing method signatures. List view with validator, 85 // add and remove button 86 class SignaturePanel : public QObject { 87 Q_OBJECT 88 89 public: 90 SignaturePanel(QObject *parent, QListView *listView, QToolButton *addButton, QToolButton *removeButton, const QString &newPrefix); 91 92 QStringList fakeMethods() const; 93 void setData(const SignalSlotDialogData &d); 94 int count(const QString &signature) const; 95 96 signals: 97 void checkSignature(const QString &signature, bool *ok); 98 99 private slots: 100 void slotAdd(); 101 void slotRemove(); 102 void slotSelectionChanged(const QItemSelection &, const QItemSelection &); 103 104 private: 105 void closeEditor(); 106 107 const QString m_newPrefix; 108 SignatureModel *m_model; 109 QListView *m_listView; 110 QToolButton *m_removeButton; 111 }; 112 113 // Dialog for editing signals and slots. 114 // Provides static convenience function 115 // to modify fake signals and slots. They are 116 // handled in 2 ways: 117 // 1) For the MainContainer: Fake signals and slots are stored 118 // in the meta database (per-instance) 119 // 2) For promoted widgets: Fake signals and slots are stored 120 // in the widget database (per-class) 121 // Arguably, we could require the MainContainer to be promoted for that, too, 122 // but that would require entering a header. 123 124 class QDESIGNER_SHARED_EXPORT SignalSlotDialog : public QDialog { 125 Q_OBJECT 126 127 public: 128 enum FocusMode { FocusSlots, FocusSignals }; 129 130 explicit SignalSlotDialog(QDesignerDialogGuiInterface *dialogGui, QWidget *parent = nullptr, FocusMode m = FocusSlots); 131 ~SignalSlotDialog() override; 132 133 DialogCode showDialog(SignalSlotDialogData &slotData, SignalSlotDialogData &signalData); 134 135 // Edit fake methods stored in MetaDataBase (per instance, used for main containers) 136 static bool editMetaDataBase(QDesignerFormWindowInterface *fw, QObject *object, QWidget *parent = nullptr, FocusMode m = FocusSlots); 137 138 // Edit fake methods of a promoted class stored in WidgetDataBase (synthesizes a widget to obtain existing members). 139 static bool editPromotedClass(QDesignerFormEditorInterface *core, const QString &promotedClassName, QWidget *parent = nullptr, FocusMode m = FocusSlots); 140 // Edit fake methods of a promoted class stored in WidgetDataBase on a base class instance. 141 static bool editPromotedClass(QDesignerFormEditorInterface *core, QObject *baseObject, QWidget *parent = nullptr, FocusMode m = FocusSlots); 142 143 private slots: 144 void slotCheckSignature(const QString &signature, bool *ok); 145 146 private: 147 // Edit fake methods of a promoted class stored in WidgetDataBase using an instance of the base class. 148 static bool editPromotedClass(QDesignerFormEditorInterface *core, const QString &promotedClassName, QObject *baseObject, QWidget *parent, FocusMode m); 149 150 const FocusMode m_focusMode; 151 Ui::SignalSlotDialogClass *m_ui; 152 QDesignerDialogGuiInterface *m_dialogGui; 153 SignaturePanel *m_slotPanel; 154 SignaturePanel *m_signalPanel; 155 }; 156 } 157 158 QT_END_NAMESPACE 159 160 #endif 161