forked from qt-creator/qt-creator
QmlDesigner: Fix update issues and reflection
* Whenever there are changes on the model we have to update the delegate. * Avoid reflection on source changes * If the target changes the order of the model changes and we have to sync selection Change-Id: I34a87cd5ac329745bf48bb739fcf7555ee46b1c4 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -81,6 +81,7 @@ void ConnectionModel::resetModel()
|
|||||||
addModelNode(modelNode);
|
addModelNode(modelNode);
|
||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
m_delegate->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalHandlerProperty ConnectionModel::signalHandlerPropertyForRow(int rowNumber) const
|
SignalHandlerProperty ConnectionModel::signalHandlerPropertyForRow(int rowNumber) const
|
||||||
@@ -332,6 +333,8 @@ void ConnectionModel::addConnection()
|
|||||||
}
|
}
|
||||||
|
|
||||||
newNode.signalHandlerProperty("onClicked").setSource(source);
|
newNode.signalHandlerProperty("onClicked").setSource(source);
|
||||||
|
|
||||||
|
selectProperty(newNode.signalHandlerProperty("onClicked"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,6 +396,32 @@ void ConnectionModel::remove(int row)
|
|||||||
deleteConnectionByRow(row);
|
deleteConnectionByRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionModel::setCurrentIndex(int i)
|
||||||
|
{
|
||||||
|
if (m_currentIndex != i) {
|
||||||
|
m_currentIndex = i;
|
||||||
|
emit currentIndexChanged();
|
||||||
|
}
|
||||||
|
m_delegate->setCurrentRow(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionModel::currentIndex() const
|
||||||
|
{
|
||||||
|
return m_currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionModel::selectProperty(const SignalHandlerProperty &property)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < rowCount(); i++) {
|
||||||
|
auto otherProperty = signalHandlerPropertyForRow(i);
|
||||||
|
|
||||||
|
if (property == otherProperty) {
|
||||||
|
setCurrentIndex(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionModel::handleException()
|
void ConnectionModel::handleException()
|
||||||
{
|
{
|
||||||
QMessageBox::warning(nullptr, tr("Error"), m_exceptionError);
|
QMessageBox::warning(nullptr, tr("Error"), m_exceptionError);
|
||||||
@@ -559,13 +588,10 @@ QHash<int, QByteArray> ConnectionModel::roleNames() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConnectionModelBackendDelegate::ConnectionModelBackendDelegate(ConnectionModel *parent)
|
ConnectionModelBackendDelegate::ConnectionModelBackendDelegate(ConnectionModel *parent)
|
||||||
: QObject(parent)
|
: QObject(parent), m_signalDelegate(parent->connectionView()), m_okStatementDelegate(parent),
|
||||||
, m_signalDelegate(parent->connectionView())
|
m_koStatementDelegate(parent), m_conditionListModel(parent),
|
||||||
, m_okStatementDelegate(parent)
|
m_propertyTreeModel(parent->connectionView()), m_propertyListProxyModel(&m_propertyTreeModel)
|
||||||
, m_koStatementDelegate(parent)
|
|
||||||
, m_conditionListModel(parent)
|
|
||||||
, m_propertyTreeModel(parent->connectionView())
|
|
||||||
, m_propertyListProxyModel(&m_propertyTreeModel)
|
|
||||||
{
|
{
|
||||||
connect(&m_signalDelegate, &PropertyTreeModelDelegate::commitData, this, [this]() {
|
connect(&m_signalDelegate, &PropertyTreeModelDelegate::commitData, this, [this]() {
|
||||||
handleTargetChanged();
|
handleTargetChanged();
|
||||||
@@ -760,16 +786,17 @@ void ConnectionModelBackendDelegate::setCurrentRow(int i)
|
|||||||
|
|
||||||
m_currentRow = i;
|
m_currentRow = i;
|
||||||
|
|
||||||
m_propertyTreeModel.resetModel();
|
|
||||||
m_propertyListProxyModel.setRowAndInternalId(0, internalRootIndex);
|
|
||||||
|
|
||||||
//setup
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionModelBackendDelegate::update()
|
void ConnectionModelBackendDelegate::update()
|
||||||
{
|
{
|
||||||
|
if (m_blockReflection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_propertyTreeModel.resetModel();
|
||||||
|
m_propertyListProxyModel.setRowAndInternalId(0, internalRootIndex);
|
||||||
|
|
||||||
ConnectionModel *model = qobject_cast<ConnectionModel *>(parent());
|
ConnectionModel *model = qobject_cast<ConnectionModel *>(parent());
|
||||||
|
|
||||||
QTC_ASSERT(model, return );
|
QTC_ASSERT(model, return );
|
||||||
@@ -797,9 +824,6 @@ void ConnectionModelBackendDelegate::update()
|
|||||||
|
|
||||||
setSource(signalHandlerProperty.source());
|
setSource(signalHandlerProperty.source());
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO
|
|
||||||
<< removeOnFromSignalName(QString::fromUtf8(signalHandlerProperty.name()));
|
|
||||||
|
|
||||||
m_signalDelegate.setup(targetNodeName,
|
m_signalDelegate.setup(targetNodeName,
|
||||||
removeOnFromSignalName(QString::fromUtf8(signalHandlerProperty.name())));
|
removeOnFromSignalName(QString::fromUtf8(signalHandlerProperty.name())));
|
||||||
|
|
||||||
@@ -970,14 +994,14 @@ void ConnectionModelBackendDelegate::handleTargetChanged()
|
|||||||
|
|
||||||
const PropertyName handlerName = addOnToSignalName(m_signalDelegate.name()).toUtf8();
|
const PropertyName handlerName = addOnToSignalName(m_signalDelegate.name()).toUtf8();
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << m_signalDelegate.id() << handlerName;
|
|
||||||
|
|
||||||
const auto parentModelNode = signalHandlerProperty.parentModelNode();
|
const auto parentModelNode = signalHandlerProperty.parentModelNode();
|
||||||
|
|
||||||
QTC_ASSERT(parentModelNode.isValid(), return );
|
QTC_ASSERT(parentModelNode.isValid(), return );
|
||||||
|
|
||||||
const auto newId = m_signalDelegate.id();
|
const auto newId = m_signalDelegate.id();
|
||||||
|
|
||||||
|
const int internalId = signalHandlerProperty.parentModelNode().internalId();
|
||||||
|
|
||||||
model->connectionView()
|
model->connectionView()
|
||||||
->executeInTransaction("ConnectionModelBackendDelegate::handleTargetChanged", [&]() {
|
->executeInTransaction("ConnectionModelBackendDelegate::handleTargetChanged", [&]() {
|
||||||
const auto oldTargetNodeName
|
const auto oldTargetNodeName
|
||||||
@@ -996,8 +1020,15 @@ void ConnectionModelBackendDelegate::handleTargetChanged()
|
|||||||
|
|
||||||
if (parent.isValid() && QmlItemNode::isValidQmlVisualNode(parent))
|
if (parent.isValid() && QmlItemNode::isValidQmlVisualNode(parent))
|
||||||
parent.nodeListProperty("data").reparentHere(parentModelNode);
|
parent.nodeListProperty("data").reparentHere(parentModelNode);
|
||||||
|
else
|
||||||
|
model->connectionView()->rootModelNode().nodeListProperty("data").reparentHere(
|
||||||
|
parentModelNode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
model->selectProperty(model->connectionView()
|
||||||
|
->modelNodeForInternalId(internalId)
|
||||||
|
.signalHandlerProperty(handlerName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionModelBackendDelegate::handleOkStatementChanged()
|
void ConnectionModelBackendDelegate::handleOkStatementChanged()
|
||||||
@@ -1051,12 +1082,14 @@ void ConnectionModelBackendDelegate::commitNewSource(const QString &source)
|
|||||||
|
|
||||||
SignalHandlerProperty signalHandlerProperty = model->signalHandlerPropertyForRow(currentRow());
|
SignalHandlerProperty signalHandlerProperty = model->signalHandlerPropertyForRow(currentRow());
|
||||||
|
|
||||||
|
m_blockReflection = true;
|
||||||
model->connectionView()->executeInTransaction("ConnectionModelBackendDelegate::commitNewSource",
|
model->connectionView()->executeInTransaction("ConnectionModelBackendDelegate::commitNewSource",
|
||||||
[&]() {
|
[&]() {
|
||||||
signalHandlerProperty.setSource(source);
|
signalHandlerProperty.setSource(source);
|
||||||
});
|
});
|
||||||
|
|
||||||
setSource(signalHandlerProperty.source());
|
setSource(signalHandlerProperty.source());
|
||||||
|
m_blockReflection = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConnectionEditorStatements::MatchedStatement emptyStatement;
|
static ConnectionEditorStatements::MatchedStatement emptyStatement;
|
||||||
@@ -1637,6 +1670,7 @@ void ConditionListModel::appendToken(const QString &value)
|
|||||||
|
|
||||||
void ConditionListModel::removeToken(int index)
|
void ConditionListModel::removeToken(int index)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(index < m_tokens.count(), return );
|
||||||
beginRemoveRows({}, index, index);
|
beginRemoveRows({}, index, index);
|
||||||
|
|
||||||
m_tokens.remove(index, 1);
|
m_tokens.remove(index, 1);
|
||||||
|
@@ -27,6 +27,9 @@ class ConnectionModel : public QStandardItemModel
|
|||||||
|
|
||||||
Q_PROPERTY(ConnectionModelBackendDelegate *delegate READ delegate CONSTANT)
|
Q_PROPERTY(ConnectionModelBackendDelegate *delegate READ delegate CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ColumnRoles {
|
enum ColumnRoles {
|
||||||
TargetModelNodeRow = 0,
|
TargetModelNodeRow = 0,
|
||||||
@@ -63,6 +66,14 @@ public:
|
|||||||
Q_INVOKABLE void add();
|
Q_INVOKABLE void add();
|
||||||
Q_INVOKABLE void remove(int row);
|
Q_INVOKABLE void remove(int row);
|
||||||
|
|
||||||
|
void setCurrentIndex(int i);
|
||||||
|
int currentIndex() const;
|
||||||
|
|
||||||
|
void selectProperty(const SignalHandlerProperty &property);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentIndexChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addModelNode(const ModelNode &modelNode);
|
void addModelNode(const ModelNode &modelNode);
|
||||||
void addConnection(const ModelNode &modelNode);
|
void addConnection(const ModelNode &modelNode);
|
||||||
@@ -87,6 +98,7 @@ private:
|
|||||||
bool m_lock = false;
|
bool m_lock = false;
|
||||||
QString m_exceptionError;
|
QString m_exceptionError;
|
||||||
ConnectionModelBackendDelegate *m_delegate = nullptr;
|
ConnectionModelBackendDelegate *m_delegate = nullptr;
|
||||||
|
int m_currentIndex = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConditionListModel : public QAbstractListModel
|
class ConditionListModel : public QAbstractListModel
|
||||||
@@ -272,6 +284,7 @@ public:
|
|||||||
Q_INVOKABLE void addElse();
|
Q_INVOKABLE void addElse();
|
||||||
Q_INVOKABLE void removeElse();
|
Q_INVOKABLE void removeElse();
|
||||||
|
|
||||||
|
void setCurrentRow(int i);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -283,8 +296,6 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int currentRow() const;
|
int currentRow() const;
|
||||||
void setCurrentRow(int i);
|
|
||||||
|
|
||||||
void handleException();
|
void handleException();
|
||||||
bool hasCondition() const;
|
bool hasCondition() const;
|
||||||
bool hasElse() const;
|
bool hasElse() const;
|
||||||
@@ -324,6 +335,7 @@ private:
|
|||||||
QString m_source;
|
QString m_source;
|
||||||
PropertyTreeModel m_propertyTreeModel;
|
PropertyTreeModel m_propertyTreeModel;
|
||||||
PropertyListProxyModel m_propertyListProxyModel;
|
PropertyListProxyModel m_propertyListProxyModel;
|
||||||
|
bool m_blockReflection = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user