Commit e3376b6d authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Change importAdded and importRemoved in importsChanged

parent 1b3f8c57
...@@ -262,6 +262,7 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event) ...@@ -262,6 +262,7 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
{ {
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") || if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) { event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
QList<Import> importToBeAddedList;
m_blockMove = false; m_blockMove = false;
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) { if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty()); Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
...@@ -272,12 +273,14 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event) ...@@ -272,12 +273,14 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion); Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
if (!view()->model()->imports().contains(newImport)) { if (!view()->model()->imports().contains(newImport)) {
view()->model()->addImport(newImport); importToBeAddedList.append(newImport);
} }
} }
} }
view()->model()->changeImports(importToBeAddedList, QList<Import>());
if (!m_rewriterTransaction.isValid()) { if (!m_rewriterTransaction.isValid()) {
view()->clearSelectedModelNodes(); view()->clearSelectedModelNodes();
m_rewriterTransaction = view()->beginRewriterTransaction(); m_rewriterTransaction = view()->beginRewriterTransaction();
......
...@@ -148,12 +148,7 @@ void FormEditorView::modelAboutToBeDetached(Model *model) ...@@ -148,12 +148,7 @@ void FormEditorView::modelAboutToBeDetached(Model *model)
QmlModelView::modelAboutToBeDetached(model); QmlModelView::modelAboutToBeDetached(model);
} }
void FormEditorView::importAdded(const Import &) void FormEditorView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
reset();
}
void FormEditorView::importRemoved(const Import &)
{ {
reset(); reset();
} }
......
...@@ -70,8 +70,7 @@ public: ...@@ -70,8 +70,7 @@ public:
void modelAttached(Model *model); void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model); void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import); void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void importRemoved(const Import &import);
void nodeCreated(const ModelNode &createdNode); void nodeCreated(const ModelNode &createdNode);
void nodeAboutToBeRemoved(const ModelNode &removedNode); void nodeAboutToBeRemoved(const ModelNode &removedNode);
......
...@@ -185,6 +185,6 @@ void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, c ...@@ -185,6 +185,6 @@ void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, c
void ComponentView::auxiliaryDataChanged(const ModelNode &/*node*/, const QString &/*name*/, const QVariant &/*data*/) {} void ComponentView::auxiliaryDataChanged(const ModelNode &/*node*/, const QString &/*name*/, const QVariant &/*data*/) {}
void ComponentView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) {} void ComponentView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) {}
void ComponentView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/) {}
} // namespace QmlDesigner } // namespace QmlDesigner
...@@ -95,6 +95,7 @@ public: ...@@ -95,6 +95,7 @@ public:
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data); void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
QStandardItemModel *standardItemModel() const; QStandardItemModel *standardItemModel() const;
......
...@@ -481,8 +481,7 @@ void DesignDocumentController::copySelected() ...@@ -481,8 +481,7 @@ void DesignDocumentController::copySelected()
QScopedPointer<Model> model(Model::create("Qt/Rectangle")); QScopedPointer<Model> model(Model::create("Qt/Rectangle"));
model->setMetaInfo(m_d->model->metaInfo()); model->setMetaInfo(m_d->model->metaInfo());
model->setFileUrl(m_d->model->fileUrl()); model->setFileUrl(m_d->model->fileUrl());
foreach (const Import &import, m_d->model->imports()) model->changeImports(m_d->model->imports(), QList<Import>());
model->addImport(import);
Q_ASSERT(model); Q_ASSERT(model);
...@@ -578,8 +577,8 @@ void DesignDocumentController::paste() ...@@ -578,8 +577,8 @@ void DesignDocumentController::paste()
QScopedPointer<Model> model(Model::create("empty")); QScopedPointer<Model> model(Model::create("empty"));
model->setMetaInfo(m_d->model->metaInfo()); model->setMetaInfo(m_d->model->metaInfo());
model->setFileUrl(m_d->model->fileUrl()); model->setFileUrl(m_d->model->fileUrl());
foreach (const Import &import, m_d->model->imports()) model->changeImports(m_d->model->imports(), QList<Import>());
model->addImport(import);
Q_ASSERT(model); Q_ASSERT(model);
if (!m_d->model) if (!m_d->model)
......
...@@ -107,6 +107,11 @@ void DesignDocumentControllerView::actualStateChanged(const ModelNode &/*node*/) ...@@ -107,6 +107,11 @@ void DesignDocumentControllerView::actualStateChanged(const ModelNode &/*node*/)
{ {
} }
void DesignDocumentControllerView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
}
static QStringList arrayToStringList(const QByteArray &byteArray) static QStringList arrayToStringList(const QByteArray &byteArray)
{ {
QString str(QString::fromLatin1(byteArray)); QString str(QString::fromLatin1(byteArray));
......
...@@ -75,6 +75,8 @@ public: ...@@ -75,6 +75,8 @@ public:
void actualStateChanged(const ModelNode &node); void actualStateChanged(const ModelNode &node);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
ModelNode insertModel(const ModelNode &modelNode) ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); } { return m_modelMerger.insertModel(modelNode); }
void replaceModel(const ModelNode &modelNode) void replaceModel(const ModelNode &modelNode)
......
...@@ -32,12 +32,7 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model) ...@@ -32,12 +32,7 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model)
m_widget->setModel(0); m_widget->setModel(0);
} }
void ItemLibraryView::importAdded(const Import &) void ItemLibraryView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
updateImports();
}
void ItemLibraryView::importRemoved(const Import &)
{ {
updateImports(); updateImports();
} }
......
...@@ -58,8 +58,7 @@ public: ...@@ -58,8 +58,7 @@ public:
void modelAttached(Model *model); void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model); void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import); void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void importRemoved(const Import &import);
void nodeCreated(const ModelNode &createdNode); void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange); void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
......
...@@ -500,18 +500,20 @@ void ItemLibraryWidget::wheelEvent(QWheelEvent *event) ...@@ -500,18 +500,20 @@ void ItemLibraryWidget::wheelEvent(QWheelEvent *event)
{ {
if (!m_d->model) if (!m_d->model)
return; return;
QList<Import> toBeRemovedImportList;
foreach (const Import &import, m_d->model->imports()) foreach (const Import &import, m_d->model->imports())
if (import.isLibraryImport() && import.url().compare(name, Qt::CaseInsensitive) == 0) if (import.isLibraryImport() && import.url().compare(name, Qt::CaseInsensitive) == 0)
m_d->model->removeImport(import); toBeRemovedImportList.append(import);
m_d->model->changeImports(QList<Import>(), toBeRemovedImportList);
} }
void ItemLibraryWidget::addImport(const QString &name, const QString &version) void ItemLibraryWidget::addImport(const QString &name, const QString &version)
{ {
if (!m_d->model) if (!m_d->model)
return; return;
m_d->model->changeImports(QList<Import>() << Import::createLibraryImport(name, version), QList<Import>());
m_d->model->addImport(Import::createLibraryImport(name, version));
} }
} }
...@@ -111,17 +111,11 @@ void NavigatorView::modelAboutToBeDetached(Model *model) ...@@ -111,17 +111,11 @@ void NavigatorView::modelAboutToBeDetached(Model *model)
AbstractView::modelAboutToBeDetached(model); AbstractView::modelAboutToBeDetached(model);
} }
void NavigatorView::importAdded(const Import &) void NavigatorView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{ {
treeWidget()->update(); treeWidget()->update();
} }
void NavigatorView::importRemoved(const Import &)
{
treeWidget()->update();
}
void NavigatorView::nodeCreated(const ModelNode & /*createdNode*/) void NavigatorView::nodeCreated(const ModelNode & /*createdNode*/)
{ {
} }
......
...@@ -66,8 +66,7 @@ public: ...@@ -66,8 +66,7 @@ public:
void modelAttached(Model *model); void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model); void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import); void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void importRemoved(const Import &import);
void nodeCreated(const ModelNode &createdNode); void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange); void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
......
...@@ -141,7 +141,7 @@ void StatesEditorView::addState() ...@@ -141,7 +141,7 @@ void StatesEditorView::addState()
try { try {
if (rootStateGroup().allStates().count() < 1) if (rootStateGroup().allStates().count() < 1)
model()->addImport(Import::createLibraryImport("QtQuick", "1.0")); model()->changeImports(QList<Import>() << Import::createLibraryImport("QtQuick", "1.0"), QList<Import>());
ModelNode newState = rootStateGroup().addState(newStateName); ModelNode newState = rootStateGroup().addState(newStateName);
setCurrentState(newState); setCurrentState(newState);
} catch (RewritingException &e) { } catch (RewritingException &e) {
......
...@@ -154,8 +154,7 @@ public: ...@@ -154,8 +154,7 @@ public:
virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex) = 0; virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex) = 0;
virtual void importAdded(const Import &import); virtual void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports) = 0;
virtual void importRemoved(const Import &import);
virtual void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data); virtual void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
......
...@@ -74,9 +74,7 @@ public: ...@@ -74,9 +74,7 @@ public:
void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl); void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex); void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data); void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
...@@ -224,12 +222,10 @@ void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listPropert ...@@ -224,12 +222,10 @@ void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listPropert
} }
template <class ViewType> template <class ViewType>
void ForwardView<ViewType>::importAdded(const Import &import) void ForwardView<ViewType>::importChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
{ {
AbstractView::importAdded(import);
foreach (const ViewTypePointer &view, m_targetViewList) foreach (const ViewTypePointer &view, m_targetViewList)
view->importAdded(import); view->importChanged(addedImport, removedImport);
} }
template <class ViewType> template <class ViewType>
......
...@@ -105,8 +105,7 @@ public: ...@@ -105,8 +105,7 @@ public:
// Imports: // Imports:
QList<Import> imports() const; QList<Import> imports() const;
void addImport(const Import &import); void changeImports(const QList<Import> &importsToBeAdded, const QList<Import> &importsToBeRemoved);
void removeImport(const Import &import);
RewriterView *rewriterView() const; RewriterView *rewriterView() const;
......
...@@ -103,8 +103,7 @@ public: ...@@ -103,8 +103,7 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList); void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList); void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList); void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void importAdded(const Import &import); void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void importRemoved(const Import &import);
void instanceInformationsChange(const QVector<ModelNode> &nodeList); void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList); void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList); void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
......
...@@ -119,6 +119,7 @@ public: ...@@ -119,6 +119,7 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList); void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList); void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
protected: protected:
NodeInstance instanceForModelNode(const ModelNode &modelNode); NodeInstance instanceForModelNode(const ModelNode &modelNode);
......
...@@ -152,6 +152,7 @@ public: ...@@ -152,6 +152,7 @@ public:
void importAdded(const Import &import); void importAdded(const Import &import);
void importRemoved(const Import &import); void importRemoved(const Import &import);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl); void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
......
...@@ -443,13 +443,7 @@ void NodeInstanceView::instancesCompleted(const QVector<ModelNode> &/*completedN ...@@ -443,13 +443,7 @@ void NodeInstanceView::instancesCompleted(const QVector<ModelNode> &/*completedN
{ {
} }
void NodeInstanceView::importAdded(const Import & /*import*/) void NodeInstanceView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
restartProcess();
}
void NodeInstanceView::importRemoved(const Import &/*import*/)
{ {
restartProcess(); restartProcess();
} }
......
...@@ -206,22 +206,6 @@ void AbstractView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/ ...@@ -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 &) \fn void AbstractView::nodeAboutToBeRemoved(const ModelNode &)
\brief this is called if a node will be removed \brief this is called if a node will be removed
......
...@@ -132,58 +132,36 @@ Model *ModelPrivate::create(QString type, int major, int minor) ...@@ -132,58 +132,36 @@ Model *ModelPrivate::create(QString type, int major, int minor)
return model; return model;
} }
void ModelPrivate::addImport(const Import &import) void ModelPrivate::changeImports(const QList<Import> &toBeAddedImportList, const QList<Import> &toBeRemovedImportList)
{ {
if (m_imports.contains(import)) QList<Import> removedImportList;
return; foreach (const Import &import, toBeRemovedImportList) {
if (m_imports.contains(import)) {
m_imports.append(import); removedImportList.append(import);
notifyImportAdded(import); m_imports.removeOne(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);
} }
} catch (RewritingException &e) {
description = e.description();
resetModel = true;
} }
NodeMetaInfo::clearCache(); QList<Import> addedImportList;
foreach (const Import &import, toBeAddedImportList) {
if (nodeInstanceView()) if (!m_imports.contains(import)) {
nodeInstanceView()->importAdded(import); addedImportList.append(import);
m_imports.append(import);
foreach (const QWeakPointer<AbstractView> &view, m_viewList) }
view->importAdded(import);
if (resetModel) {
resetModelByRewriter(description);
} }
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; bool resetModel = false;
QString description; QString description;
try { try {
if (rewriterView()) { if (rewriterView()) {
rewriterView()->importRemoved(import); rewriterView()->importsChanged(addedImports, removedImports);
} }
} catch (RewritingException &e) { } catch (RewritingException &e) {
description = e.description(); description = e.description();
...@@ -193,10 +171,10 @@ void ModelPrivate::notifyImportRemoved(const Import &import) ...@@ -193,10 +171,10 @@ void ModelPrivate::notifyImportRemoved(const Import &import)
NodeMetaInfo::clearCache(); NodeMetaInfo::clearCache();
if (nodeInstanceView()) if (nodeInstanceView())
nodeInstanceView()->importRemoved(import); nodeInstanceView()->importsChanged(addedImports, removedImports);
foreach (const QWeakPointer<AbstractView> &view, m_viewList) foreach (const QWeakPointer<AbstractView> &view, m_viewList)
view->importRemoved(import); view->importsChanged(addedImports, removedImports);
if (resetModel) { if (resetModel) {
resetModelByRewriter(description); resetModelByRewriter(description);
...@@ -1698,14 +1676,9 @@ QList<Import> Model::imports() const ...@@ -1698,14 +1676,9 @@ QList<Import> Model::imports() const
return m_d->imports(); return m_d->imports();
} }
void Model::addImport(const Import &import) void Model::changeImports(const QList<Import> &importsToBeAdded, const QList<Import> &importsToBeRemoved)
{
m_d->addImport(import);
}
void Model::removeImport(const Import &import)
{ {
m_d->removeImport(import); m_d->changeImports(importsToBeAdded, importsToBeRemoved);
} }
RewriterView *Model::rewriterView() const RewriterView *Model::rewriterView() const
......
...@@ -175,8 +175,8 @@ public: ...@@ -175,8 +175,8 @@ public:
QList<Import> imports() const { return m_imports; } QList<Import> imports() const { return m_imports; }