qqmlengine.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtQml module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QQMLENGINE_H
  40. #define QQMLENGINE_H
  41. #include <QtCore/qurl.h>
  42. #include <QtCore/qobject.h>
  43. #include <QtCore/qmap.h>
  44. #include <QtQml/qjsengine.h>
  45. #include <QtQml/qqml.h>
  46. #include <QtQml/qqmlerror.h>
  47. #include <QtQml/qqmldebug.h>
  48. QT_BEGIN_NAMESPACE
  49. class QQmlAbstractUrlInterceptor;
  50. class Q_QML_EXPORT QQmlImageProviderBase
  51. {
  52. public:
  53. enum ImageType {
  54. Image,
  55. Pixmap,
  56. Texture,
  57. Invalid,
  58. ImageResponse
  59. // ### Qt6: reorder these, and give Invalid a fixed large value
  60. };
  61. enum Flag {
  62. ForceAsynchronousImageLoading = 0x01
  63. };
  64. Q_DECLARE_FLAGS(Flags, Flag)
  65. virtual ~QQmlImageProviderBase();
  66. virtual ImageType imageType() const = 0;
  67. virtual Flags flags() const = 0;
  68. private:
  69. friend class QQuickImageProvider;
  70. QQmlImageProviderBase();
  71. };
  72. Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlImageProviderBase::Flags)
  73. class QQmlComponent;
  74. class QQmlEnginePrivate;
  75. class QQmlImportsPrivate;
  76. class QQmlExpression;
  77. class QQmlContext;
  78. class QQmlType;
  79. class QUrl;
  80. class QNetworkAccessManager;
  81. class QQmlNetworkAccessManagerFactory;
  82. class QQmlIncubationController;
  83. class Q_QML_EXPORT QQmlEngine : public QJSEngine
  84. {
  85. Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath WRITE setOfflineStoragePath)
  86. Q_OBJECT
  87. public:
  88. explicit QQmlEngine(QObject *p = Q_NULLPTR);
  89. virtual ~QQmlEngine();
  90. QQmlContext *rootContext() const;
  91. void clearComponentCache();
  92. void trimComponentCache();
  93. QStringList importPathList() const;
  94. void setImportPathList(const QStringList &paths);
  95. void addImportPath(const QString& dir);
  96. QStringList pluginPathList() const;
  97. void setPluginPathList(const QStringList &paths);
  98. void addPluginPath(const QString& dir);
  99. bool addNamedBundle(const QString &name, const QString &fileName);
  100. bool importPlugin(const QString &filePath, const QString &uri, QList<QQmlError> *errors);
  101. void setNetworkAccessManagerFactory(QQmlNetworkAccessManagerFactory *);
  102. QQmlNetworkAccessManagerFactory *networkAccessManagerFactory() const;
  103. QNetworkAccessManager *networkAccessManager() const;
  104. void setUrlInterceptor(QQmlAbstractUrlInterceptor* urlInterceptor);
  105. QQmlAbstractUrlInterceptor* urlInterceptor() const;
  106. void addImageProvider(const QString &id, QQmlImageProviderBase *);
  107. QQmlImageProviderBase *imageProvider(const QString &id) const;
  108. void removeImageProvider(const QString &id);
  109. void setIncubationController(QQmlIncubationController *);
  110. QQmlIncubationController *incubationController() const;
  111. void setOfflineStoragePath(const QString& dir);
  112. QString offlineStoragePath() const;
  113. QUrl baseUrl() const;
  114. void setBaseUrl(const QUrl &);
  115. bool outputWarningsToStandardError() const;
  116. void setOutputWarningsToStandardError(bool);
  117. static QQmlContext *contextForObject(const QObject *);
  118. static void setContextForObject(QObject *, QQmlContext *);
  119. enum ObjectOwnership { CppOwnership, JavaScriptOwnership };
  120. static void setObjectOwnership(QObject *, ObjectOwnership);
  121. static ObjectOwnership objectOwnership(QObject *);
  122. protected:
  123. QQmlEngine(QQmlEnginePrivate &dd, QObject *p);
  124. virtual bool event(QEvent *);
  125. Q_SIGNALS:
  126. void quit();
  127. void warnings(const QList<QQmlError> &warnings);
  128. private:
  129. Q_DISABLE_COPY(QQmlEngine)
  130. Q_DECLARE_PRIVATE(QQmlEngine)
  131. };
  132. QT_END_NAMESPACE
  133. #endif // QQMLENGINE_H