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

QmlDesigner: Change importAdded and importRemoved in importsChanged

parent 1b3f8c57
......@@ -262,6 +262,7 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
{
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
QList<Import> importToBeAddedList;
m_blockMove = false;
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
......@@ -272,12 +273,14 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
if (!view()->model()->imports().contains(newImport)) {
view()->model()->addImport(newImport);
importToBeAddedList.append(newImport);
}
}
}
view()->model()->changeImports(importToBeAddedList, QList<Import>());
if (!m_rewriterTransaction.isValid()) {
view()->clearSelectedModelNodes();
m_rewriterTransaction = view()->beginRewriterTransaction();
......
......@@ -148,12 +148,7 @@ void FormEditorView::modelAboutToBeDetached(Model *model)
QmlModelView::modelAboutToBeDetached(model);
}
void FormEditorView::importAdded(const Import &)
{
reset();
}
void FormEditorView::importRemoved(const Import &)
void FormEditorView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
reset();
}
......
......@@ -70,8 +70,7 @@ public:
void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void nodeCreated(const ModelNode &createdNode);
void nodeAboutToBeRemoved(const ModelNode &removedNode);
......
......@@ -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::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
......@@ -95,6 +95,7 @@ public:
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;
......
......@@ -481,8 +481,7 @@ void DesignDocumentController::copySelected()
QScopedPointer<Model> model(Model::create("Qt/Rectangle"));
model->setMetaInfo(m_d->model->metaInfo());
model->setFileUrl(m_d->model->fileUrl());
foreach (const Import &import, m_d->model->imports())
model->addImport(import);
model->changeImports(m_d->model->imports(), QList<Import>());
Q_ASSERT(model);
......@@ -578,8 +577,8 @@ void DesignDocumentController::paste()
QScopedPointer<Model> model(Model::create("empty"));
model->setMetaInfo(m_d->model->metaInfo());
model->setFileUrl(m_d->model->fileUrl());
foreach (const Import &import, m_d->model->imports())
model->addImport(import);
model->changeImports(m_d->model->imports(), QList<Import>());
Q_ASSERT(model);
if (!m_d->model)
......
......@@ -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)
{
QString str(QString::fromLatin1(byteArray));
......
......@@ -75,6 +75,8 @@ public:
void actualStateChanged(const ModelNode &node);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); }
void replaceModel(const ModelNode &modelNode)
......
......@@ -32,12 +32,7 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model)
m_widget->setModel(0);
}
void ItemLibraryView::importAdded(const Import &)
{
updateImports();
}
void ItemLibraryView::importRemoved(const Import &)
void ItemLibraryView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
updateImports();
}
......
......@@ -58,8 +58,7 @@ public:
void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
......
......@@ -500,18 +500,20 @@ void ItemLibraryWidget::wheelEvent(QWheelEvent *event)
{
if (!m_d->model)
return;
QList<Import> toBeRemovedImportList;
foreach (const Import &import, m_d->model->imports())
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)
{
if (!m_d->model)
return;
m_d->model->addImport(Import::createLibraryImport(name, version));
m_d->model->changeImports(QList<Import>() << Import::createLibraryImport(name, version), QList<Import>());
}
}
......@@ -111,17 +111,11 @@ void NavigatorView::modelAboutToBeDetached(Model *model)
AbstractView::modelAboutToBeDetached(model);
}
void NavigatorView::importAdded(const Import &)
void NavigatorView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
{
treeWidget()->update();
}
void NavigatorView::importRemoved(const Import &)
{
treeWidget()->update();
}
void NavigatorView::nodeCreated(const ModelNode & /*createdNode*/)
{
}
......
......@@ -66,8 +66,7 @@ public:
void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
......
......@@ -141,7 +141,7 @@ void StatesEditorView::addState()
try {
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);
setCurrentState(newState);
} catch (RewritingException &e) {
......
......@@ -154,8 +154,7 @@ public:
virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex) = 0;
virtual void importAdded(const Import &import);
virtual void importRemoved(const Import &import);
virtual void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports) = 0;
virtual void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
......
......@@ -74,9 +74,7 @@ public:
void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
......@@ -224,12 +222,10 @@ void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listPropert
}
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)
view->importAdded(import);
view->importChanged(addedImport, removedImport);
}
template <class ViewType>
......
......@@ -105,8 +105,7 @@ public:
// Imports:
QList<Import> imports() const;
void addImport(const Import &import);
void removeImport(const Import &import);
void changeImports(const QList<Import> &importsToBeAdded, const QList<Import> &importsToBeRemoved);
RewriterView *rewriterView() const;
......
......@@ -103,8 +103,7 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
......
......@@ -119,6 +119,7 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
protected:
NodeInstance instanceForModelNode(const ModelNode &modelNode);
......
......@@ -152,6 +152,7 @@ public:
void importAdded(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);
......
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