2013-10-16 15:08:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-10-16 15:08:27 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2013-10-16 15:08:27 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** 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.
|
2013-10-16 15:08:27 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmljsviewercontext.h"
|
|
|
|
|
|
|
|
|
|
namespace QmlJS {
|
|
|
|
|
/*!
|
|
|
|
|
\class QmlJS::ViewerContext
|
|
|
|
|
\brief The ViewerContext class encapsulate selector and paths for a given viewer.
|
|
|
|
|
|
|
|
|
|
Using a a different viewer context can emulate (the pure qml part) of a device.
|
|
|
|
|
This allows checking how a given qml would be interpreted on another platform/viewer.
|
|
|
|
|
|
|
|
|
|
Screen information will also most likely need to be added here.
|
|
|
|
|
*/
|
|
|
|
|
ViewerContext::ViewerContext()
|
2014-07-22 19:06:44 +02:00
|
|
|
: language(Dialect::Qml), flags(AddAllPaths)
|
2013-10-16 15:08:27 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
ViewerContext::ViewerContext(QStringList selectors, QStringList paths,
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlJS::Dialect language,
|
2013-10-16 15:08:27 +02:00
|
|
|
QmlJS::ViewerContext::Flags flags)
|
|
|
|
|
: selectors(selectors), paths(paths), language(language),
|
|
|
|
|
flags(flags)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
which languages might be imported in this context
|
|
|
|
|
*/
|
2014-07-22 19:06:44 +02:00
|
|
|
bool ViewerContext::languageIsCompatible(Dialect l) const
|
2013-10-16 15:08:27 +02:00
|
|
|
{
|
2014-07-22 19:06:44 +02:00
|
|
|
if (l == Dialect::AnyLanguage && language != Dialect::NoLanguage)
|
2014-06-02 19:36:32 +02:00
|
|
|
return true;
|
2014-07-22 19:06:44 +02:00
|
|
|
switch (language.dialect()) {
|
|
|
|
|
case Dialect::JavaScript:
|
|
|
|
|
case Dialect::Json:
|
|
|
|
|
case Dialect::QmlProject:
|
|
|
|
|
case Dialect::QmlQbs:
|
|
|
|
|
case Dialect::QmlTypeInfo:
|
2013-11-20 16:00:35 +01:00
|
|
|
return language == l;
|
2014-07-22 19:06:44 +02:00
|
|
|
case Dialect::Qml:
|
|
|
|
|
return l == Dialect::Qml || l == Dialect::QmlQtQuick1 || l == Dialect::QmlQtQuick2
|
|
|
|
|
|| l == Dialect::JavaScript;
|
|
|
|
|
case Dialect::QmlQtQuick1:
|
|
|
|
|
return l == Dialect::Qml || l == Dialect::QmlQtQuick1 || l == Dialect::JavaScript;
|
|
|
|
|
case Dialect::QmlQtQuick2:
|
2014-10-13 16:46:30 +02:00
|
|
|
case Dialect::QmlQtQuick2Ui:
|
|
|
|
|
return l == Dialect::Qml || l == Dialect::QmlQtQuick2 || l == Dialect::QmlQtQuick2Ui
|
|
|
|
|
|| l == Dialect::JavaScript;
|
2014-07-22 19:06:44 +02:00
|
|
|
case Dialect::AnyLanguage:
|
2014-06-02 19:36:32 +02:00
|
|
|
return true;
|
2014-07-22 19:06:44 +02:00
|
|
|
case Dialect::NoLanguage:
|
2013-11-20 16:00:35 +01:00
|
|
|
break;
|
2013-10-16 15:08:27 +02:00
|
|
|
}
|
2014-06-02 19:36:32 +02:00
|
|
|
return false;
|
2013-10-16 15:08:27 +02:00
|
|
|
}
|
|
|
|
|
|
2014-04-11 23:07:52 +02:00
|
|
|
void ViewerContext::maybeAddPath(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
if (!path.isEmpty() && !paths.contains(path))
|
|
|
|
|
paths.append(path);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
} // namespace QmlJS
|