Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlfileselector.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 BlackBerry Limited. All rights reserved.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/QFileSelector>
5#include <QtQml/QQmlAbstractUrlInterceptor>
6#include <QtQml/private/qqmlengine_p.h>
7#include <QtQml/private/qqmlapplicationengine_p.h>
8#include <qobjectdefs.h>
9#include "qqmlfileselector.h"
10#include "qqmlfileselector_p.h"
11#include "qqmlengine_p.h"
12#include <QDebug>
13
15
67 : QObject(*(new QQmlFileSelectorPrivate), parent)
68{
70 d->engine = engine;
71 d->engine->addUrlInterceptor(d->myInstance.data());
72}
73
78{
80 if (d->engine) {
81 d->engine->removeUrlInterceptor(d->myInstance.data());
82 d->engine = nullptr;
83 }
84}
85
91{
92 Q_D(const QQmlFileSelector);
93 return d->selector;
94}
95
103
109
117{
118 Q_D(QQmlFileSelector);
119 if (selector) {
120 if (d->ownSelector) {
121 delete d->selector;
122 d->ownSelector = false;
123 }
124 d->selector = selector;
125 } else {
126 if (!d->ownSelector) {
127 d->ownSelector = true;
128 d->selector = new QFileSelector(this);
129 } // Do nothing if already using internal selector
130 }
131}
132
139{
140 Q_D(QQmlFileSelector);
141 d->selector->setExtraSelectors(strings);
142}
143
144#if QT_DEPRECATED_SINCE(6, 0)
160QQmlFileSelector* QQmlFileSelector::get(QQmlEngine* engine)
161{
163
164 if (qobject_cast<QQmlApplicationEngine *>(engine)) {
165 auto *appEnginePrivate = static_cast<QQmlApplicationEnginePrivate *>(enginePrivate);
166 appEnginePrivate->ensureInitialized();
167 }
168
169 const QUrl nonEmptyInvalid(QLatin1String(":"));
170 for (QQmlAbstractUrlInterceptor *interceptor : enginePrivate->urlInterceptors) {
171 const QUrl result = interceptor->intercept(
173 if (result.scheme() == QLatin1String("type")
174 && result.path() == QLatin1String("fileselector")) {
175 return static_cast<QQmlFileSelectorInterceptor *>(interceptor)->d->q_func();
176 }
177 }
178 return nullptr;
179}
180#endif
181
189
194{
195 if (!path.isEmpty() && !path.isValid())
196 return QUrl(QLatin1String("type:fileselector"));
197
199 ? path // Don't intercept qmldir files, to prevent double interception
200 : d->selector->select(path);
201}
202
204
205#include "moc_qqmlfileselector.cpp"
\inmodule QtCore
QString select(const QString &filePath) const
This function returns the selected version of the path, based on the conditions at runtime.
\inmodule QtCore
Definition qobject.h:103
DataType
Specifies where URL interception is taking place.
static QQmlEnginePrivate * get(QQmlEngine *e)
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
QQmlFileSelectorPrivate * d
QQmlFileSelectorInterceptor(QQmlFileSelectorPrivate *pd)
QUrl intercept(const QUrl &path, DataType type) override
QScopedPointer< QQmlFileSelectorInterceptor > myInstance
A class for applying a QFileSelector to QML file loading.
QQmlFileSelector(QQmlEngine *engine, QObject *parent=nullptr)
Creates a new QQmlFileSelector with parent object parent, which includes its own QFileSelector.
void setExtraSelectors(const QStringList &strings)
Adds extra selectors contained in strings to the current QFileSelector being used.
~QQmlFileSelector() override
Destroys the QQmlFileSelector object.
QFileSelector * selector() const noexcept
void setSelector(QFileSelector *selector)
Sets the QFileSelector instance for use by the QQmlFileSelector to selector.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\inmodule QtCore
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
GLsizei const GLchar ** strings
[1]
GLenum type
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
QFileSelector selector
[1]
QJSEngine engine
[0]