~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/plugin/ucimportversionchecker_p.cpp

  • Committer: Zsombor Egri
  • Date: 2015-11-16 06:35:05 UTC
  • mfrom: (1664.1.1 listitemSelectModeBugs)
  • Revision ID: zsombor.egri@canonical.com-20151116063505-cwn2qfks7qzk10g9
re-sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Author: Zsombor Egri <zsombor.egri@canonical.com>
 
17
 */
 
18
 
 
19
#include "ucimportversionchecker_p.h"
 
20
#include "ucnamespace.h"
 
21
 
 
22
#include <QtQuick>
 
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>
 
27
 
 
28
/*!
 
29
 * \internal
 
30
 *
 
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.
 
35
 */
 
36
quint16 UCImportVersionChecker::importVersion(QObject *object)
 
37
{
 
38
    QQmlData *data = QQmlData::get(object);
 
39
    Q_ASSERT(data);
 
40
    QQmlContextData *cdata = QQmlContextData::get(qmlContext(object));
 
41
    Q_ASSERT(cdata);
 
42
    QQmlEngine *engine = qmlEngine(object);
 
43
    Q_ASSERT(engine);
 
44
 
 
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());
 
50
        QQmlPropertyData l;
 
51
        QQmlPropertyData *p = QQmlPropertyCache::property(engine, object, property, cdata, l);
 
52
        if (data->propertyCache->isAllowedInRevision(p)) {
 
53
            return version;
 
54
        }
 
55
    }
 
56
    // if none found, simply fall back to 1.2
 
57
    return BUILD_VERSION(1, 2);
 
58
}