summaryrefslogtreecommitdiffstats
path: root/src/runtime/q3dssourceinfo_p.h
blob: 0c0ae0106f37ac6f07eabb0f842533ac8efea76c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QSOURCEINFO_P_H
#define QSOURCEINFO_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <private/q3dsruntimeglobal_p.h>
#include <private/qobject_p.h>
#include <QtCore/qurl.h>
#include <QtCore/qfileinfo.h>
#include <QtQml/qqmlfile.h>

#include "q3dslogging_p.h"

QT_BEGIN_NAMESPACE

class Q3DSV_PRIVATE_EXPORT Q3DSSourceInfo {
public:
    Q3DSSourceInfo()
    {
        m_variantFilter.reset(new QHash<QStringRef, QVector<QStringRef>>);
        m_internalVariantList.reset(new QVector<QString>);
    }

    ~Q3DSSourceInfo()
    {
        m_variantFilter.reset();
        m_internalVariantList.reset();
    }

    Q3DSSourceInfo(const Q3DSSourceInfo &other)
    {
        operator=(other);
    }

    inline Q3DSSourceInfo &operator=(const Q3DSSourceInfo &other)
    {
        m_url = other.m_url;
        m_fileName = other.m_fileName;
        m_variantList = other.m_variantList;
        m_internalVariantList = other.m_internalVariantList;
        m_variantFilter = other.m_variantFilter;
        return *this;
    }

    inline bool operator==(const Q3DSSourceInfo &other)
    {
        return (this->m_url == other.m_url
                && this->m_variantList == other.m_variantList);
    }

    inline bool operator!=(const Q3DSSourceInfo &other)
    {
        return (this->m_url != other.m_url
                || this->m_variantList != other.m_variantList);
    }

    inline void setUrl(const QUrl &url)
    {
        m_url = url;
        m_fileName = QQmlFile::urlToLocalFileOrQrc(url);
    }

    inline QUrl url() const { return m_url; }

    inline void setFileName(const QString &fileName)
    {
        m_fileName = fileName;
        m_url = QUrl::fromLocalFile(QFileInfo(fileName).absolutePath());
    }

    inline bool isEmpty() const { return m_url.isEmpty(); }

    inline QString fileName() const { return m_fileName; }

    inline void setVariantList(const QStringList &variantList)
    {
        //  Store the QStringList to be returned from the API
        m_variantList = variantList;

        // Note that all instances that share the filter lists will get updated
        m_variantFilter->clear();
        m_internalVariantList->clear();

        // Build a fixed (in mem location) list of the variant strings
        for (const auto &tag : variantList)
            m_internalVariantList->append(tag);

        // Parse the variantGroup:variant list to map using the fixed list
        const auto &internalList = *m_internalVariantList.data();
        for (const auto &tag : internalList) {
            QStringRef refTag = QStringRef(&tag);
            int separatorIdx = refTag.indexOf(QLatin1Char(':'));
            QStringRef group = refTag.left(separatorIdx);
            QStringRef variant = refTag.mid(separatorIdx + 1);
            (*m_variantFilter)[group].append(variant);
        }
    }

    inline const QStringList &variantList() const { return m_variantList; }
    inline const QHash<QStringRef, QVector<QStringRef>> &variantMap() const
    {
        return *m_variantFilter.data();
    }

private:
    QUrl m_url;
    QString m_fileName;
    QStringList m_variantList;
    QSharedPointer<QVector<QString>> m_internalVariantList;
    QSharedPointer<QHash<QStringRef, QVector<QStringRef>>> m_variantFilter;
};

QT_END_NAMESPACE

#endif // QSOURCEINFO_P_H