1 | // Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QT3DCORE_QSERVICELOCATOR_H |
4 | #define QT3DCORE_QSERVICELOCATOR_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists for the convenience |
11 | // of other Qt classes. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <Qt3DCore/qt3dcore_global.h> |
18 | #include <QtCore/qobject.h> |
19 | #include <QtCore/qscopedpointer.h> |
20 | #include <private/qglobal_p.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | namespace Qt3DCore { |
25 | |
26 | class QAbstractServiceProviderPrivate; |
27 | |
28 | class Q_3DCORESHARED_EXPORT QAbstractServiceProvider : public QObject |
29 | { |
30 | Q_OBJECT |
31 | public: |
32 | virtual ~QAbstractServiceProvider(); |
33 | |
34 | int type() const; |
35 | QString description() const; |
36 | |
37 | protected: |
38 | explicit QAbstractServiceProvider(int type, const QString &description, QObject* parent = nullptr); |
39 | explicit QAbstractServiceProvider(QAbstractServiceProviderPrivate &dd, QObject* parent = nullptr); |
40 | |
41 | private: |
42 | Q_DISABLE_COPY(QAbstractServiceProvider) |
43 | Q_DECLARE_PRIVATE(QAbstractServiceProvider) |
44 | }; |
45 | |
46 | class QAbstractFrameAdvanceService; |
47 | class QOpenGLInformationService; |
48 | class QSystemInformationService; |
49 | class QServiceLocatorPrivate; |
50 | class QEventFilterService; |
51 | class QDownloadHelperService; |
52 | class QAspectEngine; |
53 | |
54 | class Q_3DCORESHARED_EXPORT QServiceLocator |
55 | { |
56 | public: |
57 | QServiceLocator(QAspectEngine *aspectEngine = nullptr); |
58 | ~QServiceLocator(); |
59 | |
60 | enum ServiceType { |
61 | SystemInformation, |
62 | OpenGLInformation, |
63 | CollisionService, |
64 | FrameAdvanceService, |
65 | EventFilterService, |
66 | DownloadHelperService, |
67 | #if !defined(Q_QDOC) |
68 | DefaultServiceCount, // Add additional default services before here |
69 | #endif |
70 | UserService = 256 |
71 | }; |
72 | |
73 | void registerServiceProvider(int serviceType, QAbstractServiceProvider *provider); |
74 | void unregisterServiceProvider(int serviceType); |
75 | |
76 | int serviceCount() const; |
77 | |
78 | template<class T> |
79 | T *service(int serviceType) |
80 | { |
81 | QAbstractServiceProvider *service_ = _q_getServiceHelper(type: serviceType); |
82 | return static_cast<T *>(service_); |
83 | } |
84 | |
85 | // Convenience accessors for Qt3D provided services |
86 | QSystemInformationService *systemInformation(); |
87 | QOpenGLInformationService *openGLInformation(); |
88 | QAbstractFrameAdvanceService *frameAdvanceService(); |
89 | QEventFilterService *eventFilterService(); |
90 | QDownloadHelperService *downloadHelperService(); |
91 | |
92 | private: |
93 | Q_DISABLE_COPY(QServiceLocator) |
94 | Q_DECLARE_PRIVATE(QServiceLocator) |
95 | QScopedPointer<QServiceLocatorPrivate> d_ptr; |
96 | |
97 | QAbstractServiceProvider *_q_getServiceHelper(int type); |
98 | }; |
99 | |
100 | } |
101 | |
102 | QT_END_NAMESPACE |
103 | |
104 | #endif // QT3DCORE_QSERVICELOCATOR_H |
105 | |