diff options
author | Aleksei German <aleksei.german@qt.io> | 2019-12-05 14:33:42 +0100 |
---|---|---|
committer | Aleksei German <aleksei.german@qt.io> | 2019-12-06 13:26:30 +0000 |
commit | 0adf810587ad97633c4e01a782529aeeb3bd57ac (patch) | |
tree | d08321ca1e6a3427d068885807590b2d7dfe8d41 /src/plugins/qmldesigner/components/bindingeditor | |
parent | 60f27c609a279cf8f6aa4136fd6d35667aabef4c (diff) | |
download | qt-creator-0adf810587ad97633c4e01a782529aeeb3bd57ac.tar.gz |
QmlDesigner Action Editor for Connections View
Task: QDS-1261
Change-Id: I81e6687e31a0f987ba15dc81dd52f240e4ea9689
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/components/bindingeditor')
5 files changed, 243 insertions, 16 deletions
diff --git a/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp new file mode 100644 index 0000000000..e21000a171 --- /dev/null +++ b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "actioneditor.h" + +#include <qmldesignerplugin.h> +#include <coreplugin/icore.h> +#include <coreplugin/actionmanager/actionmanager.h> + +#include <metainfo.h> +#include <qmlmodelnodeproxy.h> +#include <nodeabstractproperty.h> +#include <nodelistproperty.h> +#include <propertyeditorvalue.h> + +namespace QmlDesigner { + +static ActionEditor *s_lastActionEditor = nullptr; + +ActionEditor::ActionEditor(QObject *) + : m_index(QModelIndex()) +{ +} + +ActionEditor::~ActionEditor() +{ + hideWidget(); +} + +void ActionEditor::registerDeclarativeType() +{ + qmlRegisterType<ActionEditor>("HelperWidgets", 2, 0, "ActionEditor"); +} + +void ActionEditor::showWidget(int x, int y) +{ + if (s_lastActionEditor) + s_lastActionEditor->hideWidget(); + s_lastActionEditor = this; + + m_dialog = new BindingEditorDialog(Core::ICore::dialogParent(), + BindingEditorDialog::DialogType::ActionDialog); + + + QObject::connect(m_dialog, &BindingEditorDialog::accepted, + this, &ActionEditor::accepted); + QObject::connect(m_dialog, &BindingEditorDialog::rejected, + this, &ActionEditor::rejected); + + m_dialog->setAttribute(Qt::WA_DeleteOnClose); + m_dialog->showWidget(x, y); + m_dialog->activateWindow(); +} + +void ActionEditor::hideWidget() +{ + if (s_lastActionEditor == this) + s_lastActionEditor = nullptr; + if (m_dialog) + { + m_dialog->unregisterAutoCompletion(); //we have to do it separately, otherwise we have an autocompletion action override + m_dialog->close(); + } +} + +QString ActionEditor::bindingValue() const +{ + if (!m_dialog) + return {}; + + return m_dialog->editorValue(); +} + +void ActionEditor::setBindingValue(const QString &text) +{ + if (m_dialog) + m_dialog->setEditorValue(text); +} + +bool ActionEditor::hasModelIndex() const +{ + return m_index.isValid(); +} + +void ActionEditor::resetModelIndex() +{ + m_index = QModelIndex(); +} + +QModelIndex ActionEditor::modelIndex() const +{ + return m_index; +} + +void ActionEditor::setModelIndex(const QModelIndex &index) +{ + m_index = index; +} + +void ActionEditor::updateWindowName() +{ + if (!m_dialog.isNull()) + { + m_dialog->setWindowTitle(tr("Action Editor")); + m_dialog->raise(); + } +} + +} // QmlDesigner namespace diff --git a/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h new file mode 100644 index 0000000000..b8133224fc --- /dev/null +++ b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#ifndef ACTIONEDITOR_H +#define ACTIONEDITOR_H + +#include <bindingeditor/bindingeditordialog.h> +#include <qmldesignercorelib_global.h> +#include <modelnode.h> + +#include <QtQml> +#include <QObject> +#include <QPointer> + +namespace QmlDesigner { + +class ActionEditor : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString text READ bindingValue WRITE setBindingValue) + +public: + ActionEditor(QObject *parent = nullptr); + ~ActionEditor(); + + static void registerDeclarativeType(); + + Q_INVOKABLE void showWidget(int x, int y); + Q_INVOKABLE void hideWidget(); + + QString bindingValue() const; + void setBindingValue(const QString &text); + + bool hasModelIndex() const; + void resetModelIndex(); + QModelIndex modelIndex() const; + void setModelIndex(const QModelIndex &index); + + Q_INVOKABLE void updateWindowName(); + +signals: + void accepted(); + void rejected(); + +private: + QVariant backendValue() const; + QVariant modelNodeBackend() const; + QVariant stateModelNode() const; + +private: + QPointer<BindingEditorDialog> m_dialog; + QModelIndex m_index; +}; + +} + +QML_DECLARE_TYPE(QmlDesigner::ActionEditor) + +#endif //ACTIONEDITOR_H diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.pri b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.pri index 88b2897c7b..925cea3539 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.pri +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.pri @@ -1,7 +1,9 @@ HEADERS += $$PWD/bindingeditor.h +HEADERS += $$PWD/actioneditor.h HEADERS += $$PWD/bindingeditordialog.h HEADERS += $$PWD/bindingeditorwidget.h SOURCES += $$PWD/bindingeditor.cpp +SOURCES += $$PWD/actioneditor.cpp SOURCES += $$PWD/bindingeditordialog.cpp SOURCES += $$PWD/bindingeditorwidget.cpp diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.cpp b/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.cpp index 228020d238..f368aee38b 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.cpp +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.cpp @@ -41,8 +41,9 @@ namespace QmlDesigner { -BindingEditorDialog::BindingEditorDialog(QWidget *parent) +BindingEditorDialog::BindingEditorDialog(QWidget *parent, DialogType type) : QDialog(parent) + , m_dialogType(type) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlag(Qt::Tool, true); @@ -59,12 +60,14 @@ BindingEditorDialog::BindingEditorDialog(QWidget *parent) QObject::connect(m_editorWidget, &BindingEditorWidget::returnKeyClicked, this, &BindingEditorDialog::accepted); - QObject::connect(m_comboBoxItem, QOverload<int>::of(&QComboBox::currentIndexChanged), - this, &BindingEditorDialog::itemIDChanged); - QObject::connect(m_comboBoxProperty, QOverload<int>::of(&QComboBox::currentIndexChanged), - this, &BindingEditorDialog::propertyIDChanged); - QObject::connect(m_editorWidget, &QPlainTextEdit::textChanged, - this, &BindingEditorDialog::textChanged); + if (m_dialogType == DialogType::BindingDialog) { + QObject::connect(m_comboBoxItem, QOverload<int>::of(&QComboBox::currentIndexChanged), + this, &BindingEditorDialog::itemIDChanged); + QObject::connect(m_comboBoxProperty, QOverload<int>::of(&QComboBox::currentIndexChanged), + this, &BindingEditorDialog::propertyIDChanged); + QObject::connect(m_editorWidget, &QPlainTextEdit::textChanged, + this, &BindingEditorDialog::textChanged); + } } BindingEditorDialog::~BindingEditorDialog() @@ -186,10 +189,12 @@ void BindingEditorDialog::setupJSEditor() void BindingEditorDialog::setupUIComponents() { m_verticalLayout = new QVBoxLayout(this); - m_comboBoxLayout = new QHBoxLayout; - m_comboBoxItem = new QComboBox(this); - m_comboBoxProperty = new QComboBox(this); + if (m_dialogType == DialogType::BindingDialog) { + m_comboBoxLayout = new QHBoxLayout; + m_comboBoxItem = new QComboBox(this); + m_comboBoxProperty = new QComboBox(this); + } m_editorWidget->setParent(this); m_editorWidget->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); @@ -200,11 +205,11 @@ void BindingEditorDialog::setupUIComponents() m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); m_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); - - m_comboBoxLayout->addWidget(m_comboBoxItem); - m_comboBoxLayout->addWidget(m_comboBoxProperty); - - m_verticalLayout->addLayout(m_comboBoxLayout); + if (m_dialogType == DialogType::BindingDialog) { + m_comboBoxLayout->addWidget(m_comboBoxItem); + m_comboBoxLayout->addWidget(m_comboBoxProperty); + m_verticalLayout->addLayout(m_comboBoxLayout); + } m_verticalLayout->addWidget(m_editorWidget); m_verticalLayout->addWidget(m_buttonBox); diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.h b/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.h index 6cb0c00361..7255d528e6 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.h +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditordialog.h @@ -57,8 +57,14 @@ public: QStringList properties; }; + enum DialogType { + Unknown = 0, + BindingDialog = 1, + ActionDialog = 2 + }; + public: - BindingEditorDialog(QWidget *parent = nullptr); + BindingEditorDialog(QWidget *parent = nullptr, DialogType type = DialogType::BindingDialog); ~BindingEditorDialog() override; void showWidget(int x, int y); @@ -84,6 +90,7 @@ public slots: void textChanged(); private: + DialogType m_dialogType = DialogType::BindingDialog; TextEditor::BaseTextEditor *m_editor = nullptr; BindingEditorWidget *m_editorWidget = nullptr; QVBoxLayout *m_verticalLayout = nullptr; |