2
* Copyright 2015 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Zsombor Egri <zsombor.egri@canonical.com>
19
#include "ucimportversionchecker_p.h"
20
#include "ucnamespace.h"
23
#include <QtQml/private/qqmldata_p.h>
24
#include <QtQml/private/qqmlcontext_p.h>
25
#include <QtQml/private/qqmlpropertycache_p.h>
26
#include <QtQml/private/qqmlmetatype_p.h>
31
* The function returns the version the module is imported with based on a QML
32
* component instance. It only checks till reaches 1.2 version. Implementations
33
* must implement the propertyForVersion method and must probvide a property for
34
* each version requested.
36
quint16 UCImportVersionChecker::importVersion(QObject *object)
38
QQmlData *data = QQmlData::get(object);
40
QQmlContextData *cdata = QQmlContextData::get(qmlContext(object));
42
QQmlEngine *engine = qmlEngine(object);
45
// start from the highest available version till we reach 1.2
46
for (quint16 minor = MINOR_VERSION(LATEST_UITK_VERSION); minor > 2; minor--) {
47
quint16 version = BUILD_VERSION(1, minor);
48
const QString property(propertyForVersion(version));
49
Q_ASSERT(!property.isEmpty());
51
QQmlPropertyData *p = QQmlPropertyCache::property(engine, object, property, cdata, l);
52
if (data->propertyCache->isAllowedInRevision(p)) {
56
// if none found, simply fall back to 1.2
57
return BUILD_VERSION(1, 2);