QmlDesigner: Improve connection editor dialog

* Add ComboBoxes to connection editor dialog
* Add type toggle to dialog
* Add slots and properties to ComboBoxes
* Parse connection expression and fill ComboBoxes

Task-number: QDS-2498
Task-number: QDS-2495
Task-number: QDS-2496
Change-Id: I2cca6d4c85d1508e54d4ad8863056f22ad777ae6
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2020-08-18 17:52:44 +02:00
committed by Henning Gründl
parent a489fc18eb
commit 513d1e7e02
16 changed files with 1526 additions and 233 deletions

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
@@ -41,80 +41,19 @@
namespace QmlDesigner {
BindingEditorDialog::BindingEditorDialog(QWidget *parent, DialogType type)
: QDialog(parent)
, m_dialogType(type)
BindingEditorDialog::BindingEditorDialog(QWidget *parent)
: AbstractEditorDialog(parent, tr("Binding Editor"))
{
setWindowFlag(Qt::Tool, true);
setWindowTitle(defaultTitle());
setModal(false);
setupJSEditor();
setupUIComponents();
QObject::connect(m_buttonBox, &QDialogButtonBox::accepted,
this, &BindingEditorDialog::accepted);
QObject::connect(m_buttonBox, &QDialogButtonBox::rejected,
this, &BindingEditorDialog::rejected);
QObject::connect(m_editorWidget, &BindingEditorWidget::returnKeyClicked,
this, &BindingEditorDialog::accepted);
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);
}
QObject::connect(m_comboBoxItem, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &BindingEditorDialog::itemIDChanged);
QObject::connect(m_comboBoxProperty, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &BindingEditorDialog::propertyIDChanged);
}
BindingEditorDialog::~BindingEditorDialog()
{
delete m_editor; //m_editorWidget is handled by basetexteditor destructor
delete m_buttonBox;
delete m_comboBoxItem;
delete m_comboBoxProperty;
delete m_comboBoxLayout;
delete m_verticalLayout;
}
void BindingEditorDialog::showWidget()
{
this->show();
this->raise();
m_editorWidget->setFocus();
}
void BindingEditorDialog::showWidget(int x, int y)
{
showWidget();
move(QPoint(x, y));
}
QString BindingEditorDialog::editorValue() const
{
if (!m_editorWidget)
return {};
return m_editorWidget->document()->toPlainText();
}
void BindingEditorDialog::setEditorValue(const QString &text)
{
if (m_editorWidget)
m_editorWidget->document()->setPlainText(text);
}
void BindingEditorDialog::setAllBindings(QList<BindingEditorDialog::BindingOption> bindings)
{
m_lock = true;
m_bindings = bindings;
setupComboBoxes();
adjustProperties();
m_lock = false;
}
void BindingEditorDialog::adjustProperties()
@@ -155,69 +94,26 @@ void BindingEditorDialog::adjustProperties()
m_comboBoxProperty->setCurrentText(property);
}
void BindingEditorDialog::unregisterAutoCompletion()
void BindingEditorDialog::setAllBindings(QList<BindingOption> bindings)
{
if (m_editorWidget)
m_editorWidget->unregisterAutoCompletion();
}
m_lock = true;
QString BindingEditorDialog::defaultTitle() const
{
return titleString;
}
m_bindings = bindings;
setupComboBoxes();
adjustProperties();
void BindingEditorDialog::setupJSEditor()
{
static BindingEditorFactory f;
m_editor = qobject_cast<TextEditor::BaseTextEditor*>(f.createEditor());
m_editorWidget = qobject_cast<BindingEditorWidget*>(m_editor->editorWidget());
Core::Context context = m_editor->context();
context.prepend(BINDINGEDITOR_CONTEXT_ID);
m_editorWidget->m_context->setContext(context);
auto qmlDesignerEditor = QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor();
m_editorWidget->qmljsdocument = qobject_cast<QmlJSEditor::QmlJSEditorWidget *>(
qmlDesignerEditor->widget())->qmlJsEditorDocument();
m_editorWidget->setLineNumbersVisible(false);
m_editorWidget->setMarksVisible(false);
m_editorWidget->setCodeFoldingSupported(false);
m_editorWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_editorWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_editorWidget->setTabChangesFocus(true);
m_lock = false;
}
void BindingEditorDialog::setupUIComponents()
{
m_verticalLayout = new QVBoxLayout(this);
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_comboBoxLayout->addWidget(m_comboBoxItem);
m_comboBoxLayout->addWidget(m_comboBoxProperty);
m_editorWidget->setParent(this);
m_editorWidget->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
m_editorWidget->show();
m_buttonBox = new QDialogButtonBox(this);
m_buttonBox->setOrientation(Qt::Horizontal);
m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
m_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
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);
this->resize(660, 240);
//this->resize(660, 240);
}
void BindingEditorDialog::setupComboBoxes()
@@ -260,14 +156,4 @@ void BindingEditorDialog::propertyIDChanged(int propertyID)
m_comboBoxProperty->removeItem(undefinedProperty);
}
void BindingEditorDialog::textChanged()
{
if (m_lock)
return;
m_lock = true;
adjustProperties();
m_lock = false;
}
} // QmlDesigner namespace