diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-12-05 15:07:58 +0000 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-12-13 19:23:18 +0000 |
commit | 7d62c1448721a261c053a3d8adabc21787f1d955 (patch) | |
tree | 020564a5eb5b8a2ad216e663357c14736186c499 | |
parent | 0d16efe6ec938d672f6f442e63cb850eb847a5e6 (diff) |
Implement getting list of aspects from system information class
Change-Id: I999dfbb5c139ff8af2b1de9255f76ac132ae2dc0
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/core/aspects/qaspectengine.cpp | 14 | ||||
-rw-r--r-- | src/core/aspects/qaspectmanager.cpp | 5 | ||||
-rw-r--r-- | src/core/aspects/qaspectmanager_p.h | 4 | ||||
-rw-r--r-- | src/core/services/qservicelocator.cpp | 11 | ||||
-rw-r--r-- | src/core/services/qservicelocator_p.h | 3 | ||||
-rw-r--r-- | src/core/services/qsysteminformationservice.cpp | 36 | ||||
-rw-r--r-- | src/core/services/qsysteminformationservice_p.h | 4 | ||||
-rw-r--r-- | src/core/services/qsysteminformationservice_p_p.h | 3 | ||||
-rw-r--r-- | tests/auto/core/qaspectengine/tst_qaspectengine.cpp | 6 | ||||
-rw-r--r-- | tests/auto/core/qservicelocator/tst_qservicelocator.cpp | 2 |
10 files changed, 57 insertions, 31 deletions
diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp index 426741a61..e16635cb2 100644 --- a/src/core/aspects/qaspectengine.cpp +++ b/src/core/aspects/qaspectengine.cpp @@ -55,6 +55,7 @@ #include <Qt3DCore/private/qpostman_p.h> #include <Qt3DCore/private/qscene_p.h> #include <Qt3DCore/private/qservicelocator_p.h> +#include <Qt3DCore/private/qsysteminformationservice_p.h> #include <Qt3DCore/qt3dcore-config.h> #if QT_CONFIG(qt3d_profile_jobs) @@ -276,6 +277,7 @@ void QAspectEnginePrivate::initialize() arbiter->setScene(m_scene); m_initialized = true; m_aspectManager->setPostConstructorInit(m_scene->postConstructorInit()); + Q_Q(QAspectEngine); #if QT_CONFIG(qt3d_profile_jobs) m_commandDebugger->setAspectEngine(q_func()); m_commandDebugger->initialize(); @@ -419,16 +421,8 @@ QVariant QAspectEngine::executeCommand(const QString &command) if (d->m_aspects.isEmpty()) return QLatin1String("No loaded aspect"); - QString reply; - reply += QLatin1String("Loaded aspects:"); - for (QAbstractAspect *aspect : qAsConst(d->m_aspects)) { - const QString name = d->m_factory.aspectName(aspect); - if (!name.isEmpty()) - reply += QLatin1String("\n * ") + name; - else - reply += QLatin1String("\n * <unnamed>"); - } - return reply; + const QStringList names = d->m_aspectManager->serviceLocator()->systemInformation()->aspectNames(); + return names.join(QLatin1String("\n")); } QStringList args = command.split(QLatin1Char(' ')); diff --git a/src/core/aspects/qaspectmanager.cpp b/src/core/aspects/qaspectmanager.cpp index 240955a06..df90fd57c 100644 --- a/src/core/aspects/qaspectmanager.cpp +++ b/src/core/aspects/qaspectmanager.cpp @@ -99,13 +99,14 @@ int RequestFrameEvent::requestEventType = QEvent::registerEventType(); \class Qt3DCore::QAspectManager \internal */ -QAspectManager::QAspectManager(QObject *parent) +QAspectManager::QAspectManager(QAspectEngine *parent) : QObject(parent) + , m_engine(parent) , m_root(nullptr) , m_scheduler(new QScheduler(this)) , m_jobManager(new QAspectJobManager(this)) , m_changeArbiter(new QChangeArbiter(this)) - , m_serviceLocator(new QServiceLocator()) + , m_serviceLocator(new QServiceLocator(parent)) , m_simulationLoopRunning(false) , m_driveMode(QAspectEngine::Automatic) , m_postConstructorInit(nullptr) diff --git a/src/core/aspects/qaspectmanager_p.h b/src/core/aspects/qaspectmanager_p.h index ebc148324..64c75586a 100644 --- a/src/core/aspects/qaspectmanager_p.h +++ b/src/core/aspects/qaspectmanager_p.h @@ -73,6 +73,7 @@ class QScheduler; class QChangeArbiter; class QAbstractAspect; class QAbstractAspectJobManager; +class QAspectEngine; class QServiceLocator; class NodePostConstructorInit; struct NodeTreeChange; @@ -81,7 +82,7 @@ class Q_3DCORE_PRIVATE_EXPORT QAspectManager : public QObject { Q_OBJECT public: - explicit QAspectManager(QObject *parent = nullptr); + explicit QAspectManager(QAspectEngine *parent = nullptr); ~QAspectManager(); void setRunMode(QAspectEngine::RunMode mode); @@ -115,6 +116,7 @@ private: bool event(QEvent *event) override; void requestNextFrame(); + QAspectEngine *m_engine; QVector<QAbstractAspect *> m_aspects; QEntity *m_root; QVariantMap m_data; diff --git a/src/core/services/qservicelocator.cpp b/src/core/services/qservicelocator.cpp index 5df33dae9..73a40c2e4 100644 --- a/src/core/services/qservicelocator.cpp +++ b/src/core/services/qservicelocator.cpp @@ -86,11 +86,14 @@ QString QAbstractServiceProvider::description() const } +class QAspectEngine; + class QServiceLocatorPrivate { public: - QServiceLocatorPrivate() - : m_nonNullDefaultServices(0) + QServiceLocatorPrivate(QAspectEngine *aspectEngine) + : m_systemInfo(aspectEngine) + , m_nonNullDefaultServices(0) {} QHash<int, QAbstractServiceProvider *> m_services; @@ -129,8 +132,8 @@ public: /* Creates an instance of QServiceLocator. */ -QServiceLocator::QServiceLocator() - : d_ptr(new QServiceLocatorPrivate) +QServiceLocator::QServiceLocator(QAspectEngine *aspectEngine) + : d_ptr(new QServiceLocatorPrivate(aspectEngine)) { } diff --git a/src/core/services/qservicelocator_p.h b/src/core/services/qservicelocator_p.h index 9111a14ab..5bf71a996 100644 --- a/src/core/services/qservicelocator_p.h +++ b/src/core/services/qservicelocator_p.h @@ -85,11 +85,12 @@ class QSystemInformationService; class QServiceLocatorPrivate; class QEventFilterService; class QDownloadHelperService; +class QAspectEngine; class Q_3DCORESHARED_EXPORT QServiceLocator { public: - QServiceLocator(); + QServiceLocator(QAspectEngine *aspectEngine = nullptr); ~QServiceLocator(); enum ServiceType { diff --git a/src/core/services/qsysteminformationservice.cpp b/src/core/services/qsysteminformationservice.cpp index 6a8cbee04..ae7b96f89 100644 --- a/src/core/services/qsysteminformationservice.cpp +++ b/src/core/services/qsysteminformationservice.cpp @@ -50,6 +50,10 @@ #include <QtCore/QDateTime> #include <QtCore/QCoreApplication> +#include <Qt3DCore/QAspectEngine> +#include <Qt3DCore/private/qaspectengine_p.h> +#include <Qt3DCore/QAbstractAspect> + QT_BEGIN_NAMESPACE namespace { @@ -76,8 +80,10 @@ struct FrameHeader } namespace Qt3DCore { -QSystemInformationServicePrivate::QSystemInformationServicePrivate(const QString &description) +QSystemInformationServicePrivate::QSystemInformationServicePrivate(QAspectEngine *aspectEngine, + const QString &description) : QAbstractServiceProviderPrivate(QServiceLocator::SystemInformation, description) + , m_aspectEngine(aspectEngine) , m_submissionStorage(nullptr) , m_frameId(0) { @@ -255,13 +261,13 @@ qint64 QTaskLogger::restart() instantiate a QSystemInformationService object. */ -QSystemInformationService::QSystemInformationService() - : QAbstractServiceProvider(*new QSystemInformationServicePrivate(QLatin1String("Default System Information Service"))) +QSystemInformationService::QSystemInformationService(QAspectEngine *aspectEngine) + : QAbstractServiceProvider(*new QSystemInformationServicePrivate(aspectEngine, QLatin1String("Default System Information Service"))) { } -QSystemInformationService::QSystemInformationService(const QString &description) - : QAbstractServiceProvider(*new QSystemInformationServicePrivate(description)) +QSystemInformationService::QSystemInformationService(QAspectEngine *aspectEngine, const QString &description) + : QAbstractServiceProvider(*new QSystemInformationServicePrivate(aspectEngine, description)) { } @@ -301,7 +307,25 @@ void QSystemInformationService::setTraceEnabled(bool traceEnabled) */ QStringList QSystemInformationService::aspectNames() const { - return {}; + Q_D(const QSystemInformationService); + if (!d->m_aspectEngine) + return {}; + + QStringList res; + const auto aspects = d->m_aspectEngine->aspects(); + if (aspects.isEmpty()) + return { QLatin1String("No loaded aspects") }; + + QAspectEnginePrivate *dengine = QAspectEnginePrivate::get(d->m_aspectEngine); + for (auto aspect: aspects) { + const QString name = dengine->m_factory.aspectName(aspect); + if (!name.isEmpty()) + res << name; + else + res << QLatin1String("<unnamed>"); + } + + return res; } /* diff --git a/src/core/services/qsysteminformationservice_p.h b/src/core/services/qsysteminformationservice_p.h index 6fc1579bc..a524fbfd0 100644 --- a/src/core/services/qsysteminformationservice_p.h +++ b/src/core/services/qsysteminformationservice_p.h @@ -68,7 +68,7 @@ class Q_3DCORESHARED_EXPORT QSystemInformationService : public QAbstractServiceP Q_OBJECT Q_PROPERTY(bool traceEnabled READ isTraceEnabled WRITE setTraceEnabled NOTIFY traceEnabledChanged) public: - QSystemInformationService(); + QSystemInformationService(QAspectEngine *aspectEngine); bool isTraceEnabled() const; void setTraceEnabled(bool traceEnabled); @@ -83,7 +83,7 @@ signals: protected: Q_DECLARE_PRIVATE(QSystemInformationService) - QSystemInformationService(const QString &description); + QSystemInformationService(QAspectEngine *aspectEngine, const QString &description); QSystemInformationService(QSystemInformationServicePrivate &dd); }; diff --git a/src/core/services/qsysteminformationservice_p_p.h b/src/core/services/qsysteminformationservice_p_p.h index 75a6e98e7..00282c28a 100644 --- a/src/core/services/qsysteminformationservice_p_p.h +++ b/src/core/services/qsysteminformationservice_p_p.h @@ -88,7 +88,7 @@ public: quint64 threadId; }; - QSystemInformationServicePrivate(const QString &description); + QSystemInformationServicePrivate(QAspectEngine *aspectEngine, const QString &description); ~QSystemInformationServicePrivate(); static QSystemInformationServicePrivate *get(QSystemInformationService *q); @@ -101,6 +101,7 @@ public: void writeFrameJobLogStats(); + QAspectEngine *m_aspectEngine; bool m_traceEnabled; QElapsedTimer m_jobsStatTimer; diff --git a/tests/auto/core/qaspectengine/tst_qaspectengine.cpp b/tests/auto/core/qaspectengine/tst_qaspectengine.cpp index 4565f0d69..466e103ec 100644 --- a/tests/auto/core/qaspectengine/tst_qaspectengine.cpp +++ b/tests/auto/core/qaspectengine/tst_qaspectengine.cpp @@ -243,21 +243,21 @@ private Q_SLOTS: // THEN QCOMPARE(engine.executeCommand("list aspects").toString(), - QString("Loaded aspects:\n * fake")); + QString("fake")); // WHEN engine.registerAspect("otherfake"); // THEN QCOMPARE(engine.executeCommand("list aspects").toString(), - QString("Loaded aspects:\n * fake\n * otherfake")); + QString("fake\notherfake")); // WHEN engine.registerAspect(new FakeAspect3); // THEN QCOMPARE(engine.executeCommand("list aspects").toString(), - QString("Loaded aspects:\n * fake\n * otherfake\n * <unnamed>")); + QString("fake\notherfake\n<unnamed>")); } void shouldDelegateCommandsToAspects() diff --git a/tests/auto/core/qservicelocator/tst_qservicelocator.cpp b/tests/auto/core/qservicelocator/tst_qservicelocator.cpp index 04e6881aa..40f0610df 100644 --- a/tests/auto/core/qservicelocator/tst_qservicelocator.cpp +++ b/tests/auto/core/qservicelocator/tst_qservicelocator.cpp @@ -52,7 +52,7 @@ class DummySystemInfoService : public QSystemInformationService { public: DummySystemInfoService() - : QSystemInformationService(QStringLiteral("Dummy System Information Service")) + : QSystemInformationService(nullptr, QStringLiteral("Dummy System Information Service")) {} }; |