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)
{
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);
......
......@@ -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