Commit 9b93ac78 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner: using hasImport

This change avoids adding an import if the same import with different alias
already exists.
parent fe2e5432
......@@ -292,7 +292,7 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
if (!view()->model()->imports().contains(newImport)) {
if (!view()->model()->hasImport(newImport, true)) {
importToBeAddedList.append(newImport);
}
......
......@@ -383,10 +383,11 @@ bool ItemLibraryModel::isItemVisible(int itemLibId)
return elementModel(sectionLibId)->isItemVisible(itemLibId);
}
QString entryToImport(const ItemLibraryEntry &entry)
Import entryToImport(const ItemLibraryEntry &entry)
{
return entry.requiredImport() + QLatin1Char(' ') + QString::number(entry.majorVersion())
+ QLatin1Char('.') + QString::number(entry.minorVersion());
return Import::createLibraryImport(entry.requiredImport(), QString::number(entry.majorVersion()) + QLatin1Char('.') +
QString::number(entry.minorVersion()));
}
void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
......@@ -407,7 +408,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
bool valid = model->metaInfo(entry.typeName(), entry.majorVersion(), entry.minorVersion()).isValid();
if (valid && (entry.requiredImport().isEmpty() || imports.contains(entryToImport(entry), Qt::CaseInsensitive))) {
if (valid && (entry.requiredImport().isEmpty() || model->hasImport(entryToImport(entry), true) || entry.forceImport())) {
QString itemSectionName = entry.category();
ItemLibrarySectionModel *sectionModel;
ItemLibraryItemModel *itemModel;
......
......@@ -140,8 +140,8 @@ void StatesEditorView::addState()
try {
if ((rootStateGroup().allStates().count() < 1) && //QtQuick import might be missing
(!model()->imports().contains(Import::createLibraryImport("QtQuick", "1.0")) &&
!model()->imports().contains(Import::createLibraryImport("QtQuick", "1.1"))))
(!model()->hasImport(Import::createLibraryImport("QtQuick", "1.0"), true) &&
!model()->hasImport(Import::createLibraryImport("QtQuick", "1.1"), true)))
model()->changeImports(QList<Import>() << Import::createLibraryImport("QtQuick", "1.0"), QList<Import>());
ModelNode newState = rootStateGroup().addState(newStateName);
setCurrentState(newState);
......
......@@ -159,7 +159,15 @@ ModelNode ModelMerger::insertModel(const ModelNode &modelNode)
{
RewriterTransaction transaction(view()->beginRewriterTransaction());
view()->model()->changeImports(modelNode.model()->imports(), QList<Import>());
QList<Import> newImports;
foreach (const Import &import, modelNode.model()->imports()) {
if (!view()->model()->hasImport(import, true)) {
newImports.append(import);
}
}
view()->model()->changeImports(newImports, QList<Import>());
QHash<QString, QString> idRenamingHash;
setupIdRenamingHash(modelNode, idRenamingHash, view());
......
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