forked from qt-creator/qt-creator
QmlDesigner: Add transactions to NodeInstanceView::valuesModified()
Transactions bypass the rewriter and one transaction is one step on the undo/redo stack. Change-Id: Icd782389f74bde2b14432b8f854f29bad49a9104 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -194,6 +194,8 @@ private: // functions
|
||||
|
||||
private:
|
||||
void handleCrash();
|
||||
void startPuppetTransaction();
|
||||
void endPuppetTransaction();
|
||||
|
||||
private: //variables
|
||||
NodeInstance m_rootNodeInstance;
|
||||
@@ -209,6 +211,7 @@ private: //variables
|
||||
ProjectExplorer::Kit *m_currentKit = nullptr;
|
||||
ProjectExplorer::Project *m_currentProject = nullptr;
|
||||
int m_restartProcessTimerId;
|
||||
RewriterTransaction m_puppetTransaction;
|
||||
};
|
||||
|
||||
} // namespace ProxyNodeInstanceView
|
||||
|
@@ -70,6 +70,7 @@
|
||||
#include "nodeinstanceserverproxy.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QMultiHash>
|
||||
@@ -218,6 +219,30 @@ void NodeInstanceView::handleCrash()
|
||||
emitCustomNotification(QStringLiteral("puppet crashed"));
|
||||
}
|
||||
|
||||
void NodeInstanceView::startPuppetTransaction()
|
||||
{
|
||||
/* We assume no transaction is active. */
|
||||
QTC_ASSERT(!m_puppetTransaction.isValid(), return);
|
||||
m_puppetTransaction = beginRewriterTransaction("NodeInstanceView::PuppetTransaction");
|
||||
}
|
||||
|
||||
void NodeInstanceView::endPuppetTransaction()
|
||||
{
|
||||
/* We assume a transaction is active. */
|
||||
QTC_ASSERT(m_puppetTransaction.isValid(), return);
|
||||
|
||||
/* Committing a transaction should not throw, but if there is
|
||||
* an issue with rewriting we should show an error message, instead
|
||||
* of simply crashing.
|
||||
*/
|
||||
|
||||
try {
|
||||
m_puppetTransaction.commit();
|
||||
} catch (Exception &e) {
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
void NodeInstanceView::restartProcess()
|
||||
{
|
||||
if (rootNodeInstance().isValid())
|
||||
@@ -1195,11 +1220,20 @@ void NodeInstanceView::valuesModified(const ValuesModifiedCommand &command)
|
||||
if (!model())
|
||||
return;
|
||||
|
||||
if (command.transactionOption == ValuesModifiedCommand::TransactionOption::Start)
|
||||
startPuppetTransaction();
|
||||
else if (command.transactionOption == ValuesModifiedCommand::TransactionOption::End)
|
||||
endPuppetTransaction();
|
||||
|
||||
for (const PropertyValueContainer &container : command.valueChanges()) {
|
||||
if (hasInstanceForId(container.instanceId())) {
|
||||
NodeInstance instance = instanceForId(container.instanceId());
|
||||
if (instance.isValid())
|
||||
instance.modelNode().variantProperty(container.name()).setValue(container.value());
|
||||
if (instance.isValid()) {
|
||||
ModelNode node = instance.modelNode();
|
||||
VariantProperty property = instance.modelNode().variantProperty(container.name());
|
||||
if (property.value() != container.value())
|
||||
property.setValue(container.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user