import.cpp 3.31 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
31

#include "import.h"

32
33
#include <QHash>

34
35
namespace QmlDesigner {

36
37
38
39
Import::Import()
{
}

40
Import Import::createLibraryImport(const QString &url, const QString &version, const QString &alias, const QStringList &importPaths)
41
{
42
    return Import(url, QString(), version, alias, importPaths);
43
44
}

45
Import Import::createFileImport(const QString &file, const QString &version, const QString &alias, const QStringList &importPaths)
46
{
47
    return Import(QString(), file, version, alias, importPaths);
48
49
50
51
}

Import Import::empty()
{
52
    return Import(QString(), QString(), QString(), QString(), QStringList());
53
54
}

55
56
57
58
59
60
61
62
63
QString Import::toImportString() const
{
    QString result = QLatin1String("import ");

    result += toString(false);

    return result;
}

64
Import::Import(const QString &url, const QString &file, const QString &version, const QString &alias, const QStringList &importPaths):
65
66
67
        m_url(url),
        m_file(file),
        m_version(version),
68
69
        m_alias(alias),
        m_importPathList(importPaths)
70
71
72
{
}

73
QString Import::toString(bool skipAlias) const
74
{
75
    QString result;
76
77
78
79

    if (isFileImport())
        result += '"' + file() + '"';
    else if (isLibraryImport())
Erik Verbruggen's avatar
Erik Verbruggen committed
80
        result += url();
81
82
83
84
85
86
    else
        return QString();

    if (hasVersion())
        result += ' ' + version();

87
    if (hasAlias() && !skipAlias)
88
89
90
91
92
93
94
        result += " as " + alias();

    return result;
}

bool Import::operator==(const Import &other) const
{
95
    return url() == other.url() && file() == other.file() && (version() == other.version() || version().isEmpty() || other.version().isEmpty());
96
97
}

98
99
100
101
102
103
104
105
bool Import::isSameModule(const Import &other) const
{
    if (isLibraryImport())
        return url() == other.url();
    else
        return file() == other.file();
}

106
107
uint qHash(const Import &import)
{
Erik Verbruggen's avatar
Erik Verbruggen committed
108
    return ::qHash(import.url()) ^ ::qHash(import.file()) ^ ::qHash(import.version()) ^ ::qHash(import.alias());
109
110
111
}

} // namespace QmlDesigner