forked from qt-creator/qt-creator
QmlDesigner.model: fixing checking for imports
Change-Id: I878f429c94b75c229738dfc26806e29a5673b102 Reviewed-on: http://codereview.qt.nokia.com/955 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
@@ -291,7 +291,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()->hasImport(newImport, true)) {
|
||||
if (!view()->model()->hasImport(newImport, true, true)) {
|
||||
importToBeAddedList.append(newImport);
|
||||
}
|
||||
|
||||
|
@@ -408,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() || model->hasImport(entryToImport(entry), true) || entry.forceImport())) {
|
||||
if (valid && (entry.requiredImport().isEmpty() || model->hasImport(entryToImport(entry), true, true) || entry.forceImport())) {
|
||||
QString itemSectionName = entry.category();
|
||||
ItemLibrarySectionModel *sectionModel;
|
||||
ItemLibraryItemModel *itemModel;
|
||||
|
@@ -379,6 +379,7 @@ void ItemLibraryWidget::emitImportChecked()
|
||||
|
||||
void ItemLibraryWidget::setImportFilter(FilterChangeFlag flag)
|
||||
{
|
||||
return;
|
||||
|
||||
static bool block = false;
|
||||
if (!m_d->model)
|
||||
|
@@ -104,7 +104,7 @@ public:
|
||||
// Imports:
|
||||
QList<Import> imports() const;
|
||||
void changeImports(const QList<Import> &importsToBeAdded, const QList<Import> &importsToBeRemoved);
|
||||
bool hasImport(const Import &import, bool ignoreAlias = true);
|
||||
bool hasImport(const Import &import, bool ignoreAlias = true, bool allowHigherVersion = false);
|
||||
|
||||
RewriterView *rewriterView() const;
|
||||
|
||||
|
@@ -1742,7 +1742,39 @@ void Model::changeImports(const QList<Import> &importsToBeAdded, const QList<Imp
|
||||
m_d->changeImports(importsToBeAdded, importsToBeRemoved);
|
||||
}
|
||||
|
||||
bool Model::hasImport(const Import &import, bool ignoreAlias)
|
||||
|
||||
static bool compareVersions(const QString &version1, const QString &version2, bool allowHigherVersion)
|
||||
{
|
||||
if (version1 == version2)
|
||||
return true;
|
||||
if (!allowHigherVersion)
|
||||
return false;
|
||||
QStringList version1List = version1.split('.');
|
||||
QStringList version2List = version2.split('.');
|
||||
if (version1List.count() == 2 && version2List.count() == 2) {
|
||||
bool ok;
|
||||
int major1 = version1List.first().toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
int major2 = version2List.first().toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
if (major1 >= major2) {
|
||||
int minor1 = version1List.last().toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
int minor2 = version2List.last().toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
if (minor1 >= minor2)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Model::hasImport(const Import &import, bool ignoreAlias, bool allowHigherVersion)
|
||||
{
|
||||
if (imports().contains(import))
|
||||
return true;
|
||||
@@ -1751,10 +1783,10 @@ bool Model::hasImport(const Import &import, bool ignoreAlias)
|
||||
|
||||
foreach (const Import &existingImport, imports()) {
|
||||
if (existingImport.isFileImport() && import.isFileImport())
|
||||
if (existingImport.file() == import.file() && existingImport.version() == import.version())
|
||||
if (existingImport.file() == import.file() && compareVersions(existingImport.version(), import.version(), allowHigherVersion))
|
||||
return true;
|
||||
if (existingImport.isLibraryImport() && import.isLibraryImport())
|
||||
if (existingImport.url() == import.url() && existingImport.version() == import.version())
|
||||
if (existingImport.url() == import.url() && compareVersions(existingImport.version(), import.version(), allowHigherVersion))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -196,7 +196,7 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
|
||||
}
|
||||
}
|
||||
|
||||
if (!model()->hasImport(newImport, true)) {
|
||||
if (!model()->hasImport(newImport, true, true)) {
|
||||
model()->changeImports(QList<Import>() << newImport, QList<Import>());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user