Commit e3376b6d authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Change importAdded and importRemoved in importsChanged

parent 1b3f8c57
......@@ -443,13 +443,7 @@ void NodeInstanceView::instancesCompleted(const QVector<ModelNode> &/*completedN
{
}
void NodeInstanceView::importAdded(const Import & /*import*/)
{
restartProcess();
}
void NodeInstanceView::importRemoved(const Import &/*import*/)
void NodeInstanceView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
restartProcess();
}
......
......@@ -206,22 +206,6 @@ void AbstractView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/
{
}
/*!
\fn AbstractView::importAdded(const Import &import)
\brief Called when an import has been added to the model
*/
void AbstractView::importAdded(const Import &/*import*/)
{
}
/*!
\fn AbstractView::importRemoved(const Import &import)
\brief Called when an import has been removed from the model
*/
void AbstractView::importRemoved(const Import &/*import*/)
{
}
/*!
\fn void AbstractView::nodeAboutToBeRemoved(const ModelNode &)
\brief this is called if a node will be removed
......
......@@ -132,58 +132,36 @@ Model *ModelPrivate::create(QString type, int major, int minor)
return model;
}
void ModelPrivate::addImport(const Import &import)
void ModelPrivate::changeImports(const QList<Import> &toBeAddedImportList, const QList<Import> &toBeRemovedImportList)
{
if (m_imports.contains(import))
return;
m_imports.append(import);
notifyImportAdded(import);
}
void ModelPrivate::removeImport(const Import &import)
{
if (!m_imports.removeOne(import))
return;
notifyImportRemoved(import);
}
void ModelPrivate::notifyImportAdded(const Import &import)
{
bool resetModel = false;
QString description;
try {
if (rewriterView()) {
rewriterView()->importAdded(import);
QList<Import> removedImportList;
foreach (const Import &import, toBeRemovedImportList) {
if (m_imports.contains(import)) {
removedImportList.append(import);
m_imports.removeOne(import);
}
} catch (RewritingException &e) {
description = e.description();
resetModel = true;
}
NodeMetaInfo::clearCache();
if (nodeInstanceView())
nodeInstanceView()->importAdded(import);
foreach (const QWeakPointer<AbstractView> &view, m_viewList)
view->importAdded(import);
if (resetModel) {
resetModelByRewriter(description);
QList<Import> addedImportList;
foreach (const Import &import, toBeAddedImportList) {
if (!m_imports.contains(import)) {
addedImportList.append(import);
m_imports.append(import);
}
}
if (!removedImportList.isEmpty() || !addedImportList.isEmpty())
notifyImportsChanged(addedImportList, removedImportList);
}
void ModelPrivate::notifyImportRemoved(const Import &import)
void ModelPrivate::notifyImportsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
{
bool resetModel = false;
QString description;
try {
if (rewriterView()) {
rewriterView()->importRemoved(import);
rewriterView()->importsChanged(addedImports, removedImports);
}
} catch (RewritingException &e) {
description = e.description();
......@@ -193,10 +171,10 @@ void ModelPrivate::notifyImportRemoved(const Import &import)
NodeMetaInfo::clearCache();
if (nodeInstanceView())
nodeInstanceView()->importRemoved(import);
nodeInstanceView()->importsChanged(addedImports, removedImports);
foreach (const QWeakPointer<AbstractView> &view, m_viewList)
view->importRemoved(import);
view->importsChanged(addedImports, removedImports);
if (resetModel) {
resetModelByRewriter(description);
......@@ -1698,14 +1676,9 @@ QList<Import> Model::imports() const
return m_d->imports();
}
void Model::addImport(const Import &import)
{
m_d->addImport(import);
}
void Model::removeImport(const Import &import)
void Model::changeImports(const QList<Import> &importsToBeAdded, const QList<Import> &importsToBeRemoved)
{
m_d->removeImport(import);
m_d->changeImports(importsToBeAdded, importsToBeRemoved);
}
RewriterView *Model::rewriterView() const
......
......@@ -175,8 +175,8 @@ public:
QList<Import> imports() const { return m_imports; }
void addImport(const Import &import);
void removeImport(const Import &import);
void notifyImportAdded(const Import &import);
void notifyImportRemoved(const Import &import);
void changeImports(const QList<Import> &importsToBeAdded, const QList<Import> &importToBeRemoved);
void notifyImportsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
//node state property manipulation
......
......@@ -158,10 +158,9 @@ static ModelNode createNodeFromNode(const ModelNode &modelNode,const QHash<QStri
ModelNode ModelMerger::insertModel(const ModelNode &modelNode)
{
RewriterTransaction transaction(view()->beginRewriterTransaction());
RewriterTransaction transaction(view()->beginRewriterTransaction());
foreach (const Import &import, modelNode.model()->imports())
view()->model()->addImport(import);
view()->model()->changeImports(modelNode.model()->imports(), QList<Import>());
QHash<QString, QString> idRenamingHash;
setupIdRenamingHash(modelNode, idRenamingHash, view());
......@@ -176,8 +175,7 @@ void ModelMerger::replaceModel(const ModelNode &modelNode)
try {
RewriterTransaction transaction(view()->beginRewriterTransaction());
foreach (const Import &import, modelNode.model()->imports())
view()->model()->addImport(import);
view()->model()->changeImports(modelNode.model()->imports(), QList<Import>());
view()->model()->setFileUrl(modelNode.model()->fileUrl());
ModelNode rootNode(view()->rootModelNode());
......
......@@ -117,7 +117,7 @@ QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, c
}
if (!model()->imports().contains(newImport)) {
model()->addImport(newImport);
model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
QList<QPair<QString, QVariant> > propertyPairList;
......@@ -187,7 +187,7 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
}
if (!model()->imports().contains(newImport)) {
model()->addImport(newImport);
model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
}
......@@ -372,6 +372,10 @@ void QmlModelView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList
}
void QmlModelView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
}
void QmlModelView::rewriterBeginTransaction()
{
......
......@@ -283,6 +283,15 @@ void RewriterView::nodeAboutToBeReparented(const ModelNode &/*node*/, const Node
{
}
void RewriterView::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
{
foreach (const Import &import, addedImports)
importAdded(import);
foreach (const Import &import, removedImports)
importRemoved(import);
}
void RewriterView::importAdded(const Import &import)
{
......
......@@ -1152,12 +1152,12 @@ void ModelValidator::idsDiffer(ModelNode &modelNode, const QString &qmlId)
void ModelAmender::modelMissesImport(const Import &import)
{
m_merger->view()->model()->addImport(import);
m_merger->view()->model()->changeImports(QList<Import>() << import, QList<Import>());
}
void ModelAmender::importAbsentInQMl(const Import &import)
{
m_merger->view()->model()->removeImport(import);
m_merger->view()->model()->changeImports(QList<Import>(), QList<Import>() << import);
}
void ModelAmender::bindingExpressionsDiffer(BindingProperty &modelProperty,
......
......@@ -183,14 +183,18 @@ void ViewLogger::nodeOrderChanged(const NodeListProperty &listProperty, const Mo
m_output << time() << indent("nodeOrderChanged:") << listProperty << movedNode << oldIndex << endl;
}
void ViewLogger::importsChanged()
void ViewLogger::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
{
m_output << time() << indent("importsChanged:") << endl;
m_output << time() << indent("auxiliaryDataChanged:") << node << "\t" << name << "\t" << data.toString() << endl;
}
void ViewLogger::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
void ViewLogger::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
{
m_output << time() << indent("auxiliaryDataChanged:") << node << "\t" << name << "\t" << data.toString() << endl;
m_output << time() << indent("importsChanged:") << endl;
foreach(const Import &import, addedImports)
m_output << time() << indent("import added: ") << import.toString() << endl;
foreach(const Import &import, removedImports)
m_output << time() << indent("import removed: ") << import.toString() << endl;
}
void ViewLogger::customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data)
......
......@@ -70,7 +70,7 @@ public:
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importsChanged();
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
......
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