Expose QFileSelectorPrivate::selectionHelper()

Let QQuickStyleSelector in Qt Quick Controls 2 re-use the same
selection helper implementation.

Change-Id: I34cbba0aa178e342bb4004313e7ff56811e6be19
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
J-P Nurmi 2016-05-27 10:51:48 +02:00
parent 5c08fed264
commit bbf596890f
2 changed files with 8 additions and 5 deletions

View File

@ -55,8 +55,6 @@ QT_BEGIN_NAMESPACE
//Environment variable to allow tooling full control of file selectors
static const char env_override[] = "QT_NO_BUILTIN_SELECTORS";
static const ushort selectorIndicator = '+';
Q_GLOBAL_STATIC(QFileSelectorSharedData, sharedData);
static QBasicMutex sharedDataMutex;
@ -267,7 +265,7 @@ QUrl QFileSelector::select(const QUrl &filePath) const
return ret;
}
static QString selectionHelper(const QString &path, const QString &fileName, const QStringList &selectors)
QString QFileSelectorPrivate::selectionHelper(const QString &path, const QString &fileName, const QStringList &selectors, const QChar &indicator)
{
/* selectionHelper does a depth-first search of possible selected files. Because there is strict
selector ordering in the API, we can stop checking as soon as we find the file in a directory
@ -276,12 +274,15 @@ static QString selectionHelper(const QString &path, const QString &fileName, con
Q_ASSERT(path.isEmpty() || path.endsWith(QLatin1Char('/')));
for (const QString &s : selectors) {
QString prospectiveBase = path + QLatin1Char(selectorIndicator) + s + QLatin1Char('/');
QString prospectiveBase = path;
if (!indicator.isNull())
prospectiveBase += indicator;
prospectiveBase += s + QLatin1Char('/');
QStringList remainingSelectors = selectors;
remainingSelectors.removeAll(s);
if (!QDir(prospectiveBase).exists())
continue;
QString prospectiveFile = selectionHelper(prospectiveBase, fileName, remainingSelectors);
QString prospectiveFile = selectionHelper(prospectiveBase, fileName, remainingSelectors, indicator);
if (!prospectiveFile.isEmpty())
return prospectiveFile;
}

View File

@ -70,6 +70,8 @@ public:
static void updateSelectors();
static QStringList platformSelectors();
static void addStatics(const QStringList &); //For loading GUI statics from other Qt modules
static QString selectionHelper(const QString &path, const QString &fileName,
const QStringList &selectors, const QChar &indicator = QLatin1Char('+'));
QFileSelectorPrivate();
QString select(const QString &filePath) const;