QQuickStyleSelector: fix built-in file selectors
While selecting style files, the standard built-in platform and local file selectors ("+linux", "+macos", "+windows"...) must be prefixed with the standard file selector indicator ("+"). Previously the style selector would not pick up platform-specific style files unless they were supplied without the prefix. [ChangeLog][Controls][Styles] Fixed the style selection mechanism so that now it is possible to organize platform and locale-specific files into sub-directories, such as "+linux", "+macos", and "+windows". Change-Id: Ia44b6f14fd0247943486fd27609147827bda9666 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
2b20122b22
commit
ea043d5d83
|
@ -65,13 +65,21 @@ static QString ensureSlash(const QString &path)
|
|||
return path + QLatin1Char('/');
|
||||
}
|
||||
|
||||
static QStringList prefixedPlatformSelectors(const QChar &prefix)
|
||||
{
|
||||
QStringList selectors = QFileSelectorPrivate::platformSelectors();
|
||||
for (int i = 0; i < selectors.count(); ++i)
|
||||
selectors[i].prepend(prefix);
|
||||
return selectors;
|
||||
}
|
||||
|
||||
static QStringList allSelectors(const QString &style = QString())
|
||||
{
|
||||
static const QStringList platformSelectors = QFileSelectorPrivate::platformSelectors();
|
||||
static const QStringList platformSelectors = prefixedPlatformSelectors(QLatin1Char('+'));
|
||||
QStringList selectors = platformSelectors;
|
||||
const QString locale = QLocale().name();
|
||||
if (!locale.isEmpty())
|
||||
selectors += locale;
|
||||
selectors += QLatin1Char('+') + locale;
|
||||
if (!style.isEmpty())
|
||||
selectors.prepend(style);
|
||||
return selectors;
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
import QtQuick.Templates 2.1 as T
|
||||
T.Button { }
|
|
@ -0,0 +1,2 @@
|
|||
import QtQuick.Templates 2.1 as T
|
||||
T.Button { }
|
|
@ -0,0 +1,2 @@
|
|||
import QtQuick.Templates 2.1 as T
|
||||
T.Button { }
|
|
@ -0,0 +1,2 @@
|
|||
import QtQuick.Templates 2.1 as T
|
||||
T.Button { }
|
|
@ -49,6 +49,8 @@ private slots:
|
|||
|
||||
void select_data();
|
||||
void select();
|
||||
|
||||
void platformSelectors();
|
||||
};
|
||||
|
||||
void tst_QQuickStyleSelector::initTestCase()
|
||||
|
@ -139,6 +141,24 @@ void tst_QQuickStyleSelector::select()
|
|||
QCOMPARE(selector.select(file), expected);
|
||||
}
|
||||
|
||||
void tst_QQuickStyleSelector::platformSelectors()
|
||||
{
|
||||
QQuickStyle::setStyle(QDir(dataDirectory()).filePath("PlatformStyle"));
|
||||
|
||||
QQuickStyleSelector selector;
|
||||
selector.setBaseUrl(dataDirectoryUrl());
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/+linux/Button.qml").toString());
|
||||
#elif defined(Q_OS_MACOS)
|
||||
QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/+macos/Button.qml").toString());
|
||||
#elif defined(Q_OS_WIN)
|
||||
QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/+windows/Button.qml").toString());
|
||||
#else
|
||||
QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/Button.qml").toString());
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickStyleSelector)
|
||||
|
||||
#include "tst_qquickstyleselector.moc"
|
||||
|
|
Loading…
Reference in New Issue