Commit 2d20b695 authored by Tim Jenssen's avatar Tim Jenssen Committed by Thomas Hartmann
Browse files

QmlDesigner: modernize code



 - no behavior change
 - use lambdas instead of extra slot functions
 - rename the comboboxes to the right names

Change-Id: I707bfb359d6bab805e05b514b3395db8d959ee81
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@theqtcompany.com>
parent 7ecd0763
......@@ -550,7 +550,14 @@ QWidget *BindingDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
default: qWarning() << "BindingDelegate::createEditor column" << index.column();
}
connect(bindingComboBox, SIGNAL(activated(QString)), this, SLOT(emitCommitData(QString)));
connect(bindingComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, [=]() {
auto delegate = const_cast<BindingDelegate*>(this);
emit delegate->commitData(bindingComboBox);
// TODO: The combobox does a change while it is opening and this would close it immediately.
// Making sure that this is not connected while data is initialized maybe with using
// QAbstractItemDelegate::setEditorData also this connect should maybe unique.
// emit delegate->closeEditor(bindingComboBox);
});
return widget;
}
......@@ -563,12 +570,6 @@ void BindingDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
QStyledItemDelegate::paint(painter, opt, index);
}
void BindingDelegate::emitCommitData(const QString & /*text*/)
{
BindingComboBox *bindingComboBox = qobject_cast<BindingComboBox*>(sender());
emit commitData(bindingComboBox);
}
BindingComboBox::BindingComboBox(QWidget *parent) : QComboBox(parent)
{
static QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("windows")));
......
......@@ -98,9 +98,6 @@ public:
const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private slots:
void emitCommitData(const QString &text);
};
class BindingComboBox : public QComboBox
......
......@@ -418,7 +418,7 @@ QWidget *ConnectionDelegate::createEditor(QWidget *parent, const QStyleOptionVie
//model->connectionView()->allModelNodes();
ConnectionComboBox *bindingComboBox = qobject_cast<ConnectionComboBox*>(widget);
ConnectionComboBox *connectionComboBox = qobject_cast<ConnectionComboBox*>(widget);
if (!connectionModel) {
qWarning() << "ConnectionDelegate::createEditor no model";
......@@ -430,7 +430,7 @@ QWidget *ConnectionDelegate::createEditor(QWidget *parent, const QStyleOptionVie
return widget;
}
if (!bindingComboBox) {
if (!connectionComboBox) {
qWarning() << "ConnectionDelegate::createEditor no bindingComboBox";
return widget;
}
......@@ -439,12 +439,12 @@ QWidget *ConnectionDelegate::createEditor(QWidget *parent, const QStyleOptionVie
case TargetModelNodeRow: {
foreach (const ModelNode &modelNode, connectionModel->connectionView()->allModelNodes()) {
if (!modelNode.id().isEmpty()) {
bindingComboBox->addItem(modelNode.id());
connectionComboBox->addItem(modelNode.id());
}
}
} break;
case TargetPropertyNameRow: {
bindingComboBox->addItems(prependOnForSignalHandler(connectionModel->getSignalsForRow(index.row())));
connectionComboBox->addItems(prependOnForSignalHandler(connectionModel->getSignalsForRow(index.row())));
} break;
case SourceRow: {
ModelNode rootModelNode = connectionModel->connectionView()->rootModelNode();
......@@ -452,12 +452,12 @@ QWidget *ConnectionDelegate::createEditor(QWidget *parent, const QStyleOptionVie
QString itemText = tr("Change to default state");
QString source = QString::fromLatin1("{ %1.state = \"\" }").arg(rootModelNode.id());
bindingComboBox->addItem(itemText, source);
connectionComboBox->addItem(itemText, source);
foreach (const QmlModelState &state, QmlItemNode(rootModelNode).states().allStates()) {
QString itemText = tr("Change state to %1").arg(state.name());
QString source = QString::fromLatin1("{ %1.state = \"%2\" }").arg(rootModelNode.id()).arg(state.name());
bindingComboBox->addItem(itemText, source);
connectionComboBox->addItem(itemText, source);
}
}
} break;
......@@ -465,7 +465,14 @@ QWidget *ConnectionDelegate::createEditor(QWidget *parent, const QStyleOptionVie
default: qWarning() << "ConnectionDelegate::createEditor column" << index.column();
}
connect(bindingComboBox, SIGNAL(activated(QString)), this, SLOT(emitCommitData(QString)));
connect(connectionComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, [=]() {
auto delegate = const_cast<ConnectionDelegate*>(this);
emit delegate->commitData(connectionComboBox);
// TODO: The combobox does a change while it is opening and this would close it immediately.
// Making sure that this is not connected while data is initialized maybe with using
// QAbstractItemDelegate::setEditorData also this connect should maybe unique.
// emit delegate->closeEditor(connectionComboBox);
});
return widget;
}
......@@ -477,13 +484,6 @@ void ConnectionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QStyledItemDelegate::paint(painter, opt, index);
}
void ConnectionDelegate::emitCommitData(const QString & /*text*/)
{
ConnectionComboBox *bindingComboBox = qobject_cast<ConnectionComboBox*>(sender());
emit commitData(bindingComboBox);
}
ConnectionComboBox::ConnectionComboBox(QWidget *parent) : QComboBox(parent)
{
static QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("windows")));
......
......@@ -99,9 +99,6 @@ public:
const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private slots:
void emitCommitData(const QString &text);
};
class ConnectionComboBox : public QComboBox
......
......@@ -774,19 +774,26 @@ QWidget *DynamicPropertiesDelegate::createEditor(QWidget *parent, const QStyleOp
} break;
case PropertyTypeRow: {
DynamicPropertiesComboBox *bindingComboBox = new DynamicPropertiesComboBox(parent);
connect(bindingComboBox, SIGNAL(activated(QString)), this, SLOT(emitCommitData(QString)));
//bindingComboBox->addItem(QLatin1String("alias"));
//bindingComboBox->addItem(QLatin1String("Item"));
bindingComboBox->addItem(QLatin1String("real"));
bindingComboBox->addItem(QLatin1String("int"));
bindingComboBox->addItem(QLatin1String("string"));
bindingComboBox->addItem(QLatin1String("bool"));
bindingComboBox->addItem(QLatin1String("url"));
bindingComboBox->addItem(QLatin1String("color"));
bindingComboBox->addItem(QLatin1String("variant"));
return bindingComboBox;
DynamicPropertiesComboBox *dynamicPropertiesComboBox = new DynamicPropertiesComboBox(parent);
connect(dynamicPropertiesComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, [=]() {
auto delegate = const_cast<DynamicPropertiesDelegate*>(this);
emit delegate->commitData(dynamicPropertiesComboBox);
// TODO: The combobox does a change while it is opening and this would close it immediately.
// Making sure that this is not connected while data is initialized maybe with using
// QAbstractItemDelegate::setEditorData also this connect should maybe unique.
// emit delegate->closeEditor(dynamicPropertiesComboBox);
});
//dynamicPropertiesComboBox->addItem(QLatin1String("alias"));
//dynamicPropertiesComboBox->addItem(QLatin1String("Item"));
dynamicPropertiesComboBox->addItem(QLatin1String("real"));
dynamicPropertiesComboBox->addItem(QLatin1String("int"));
dynamicPropertiesComboBox->addItem(QLatin1String("string"));
dynamicPropertiesComboBox->addItem(QLatin1String("bool"));
dynamicPropertiesComboBox->addItem(QLatin1String("url"));
dynamicPropertiesComboBox->addItem(QLatin1String("color"));
dynamicPropertiesComboBox->addItem(QLatin1String("variant"));
return dynamicPropertiesComboBox;
} break;
case PropertyValueRow: {
return QStyledItemDelegate::createEditor(parent, option, index);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment