diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2020-11-11 17:36:57 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2020-11-25 10:11:14 +0000 |
commit | cfa35ff37aacf870bcc643ed9a56c874ad88fc32 (patch) | |
tree | ac98b1f43fba49d4b3a1d43cb57d6fe3c19ca735 | |
parent | 941c9902f85a80f8191f18244788b59f8ba14cfe (diff) |
Add QmlDesignerUsageEventSourcev4.14.0-rc1v4.14.0
This allows collecting 'trace points' created by emitting
QmlDesignerPlugin::handleUsageStatisticsNotifier().
Example of the data layout:
{
"qmlDesignerEvents": {
"Action Executed AnchorsFill": 1,
"Action Executed AnchorsReset": 1,
"Action Executed LivePreview": 5,
"Action Executed ResetPosition": 2,
"Action Executed SELECTION": 1,
"Action Executed ToBack": 1,
"Action Executed ToFront": 2,
"State Added": 14,
"Timeline Added": 1
},
"qmlDesignerTimes": {
"Form Editor": 19282,
"Timeline": 8286
}
}
Change-Id: I734067ed01f46c12035ef54fb2b567341745a940
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/datasources/qmldesignerusageeventsource.cpp | 126 | ||||
-rw-r--r-- | src/datasources/qmldesignerusageeventsource.h | 61 | ||||
-rw-r--r-- | src/src.pro | 2 | ||||
-rw-r--r-- | src/usagestatisticplugin.cpp | 2 |
5 files changed, 192 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd1f721..2660834 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ add_qtc_plugin(UsageStatistic datasources/examplesdatasource.cpp datasources/kitsource.cpp datasources/qmldesignerusagetimesource.cpp + datasources/qmldesignerusageeventsource.cpp datasources/servicesource.cpp ui/usagestatisticpage.cpp ui/usagestatisticwidget.cpp diff --git a/src/datasources/qmldesignerusageeventsource.cpp b/src/datasources/qmldesignerusageeventsource.cpp new file mode 100644 index 0000000..66a335e --- /dev/null +++ b/src/datasources/qmldesignerusageeventsource.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company +** Contact: https://www.qt.io/licensing/ +** +** This file is part of UsageStatistic plugin for Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ +#include "qmldesignerusageeventsource.h" + +#include "common/scopedsettingsgroupsetter.h" + +#include <coreplugin/icore.h> +#include <extensionsystem/iplugin.h> +#include <extensionsystem/pluginmanager.h> +#include <extensionsystem/pluginspec.h> + +#include <KUserFeedback/Provider> + +namespace UsageStatistic { +namespace Internal { + +using namespace KUserFeedback; + +static bool isQmlDesigner(const ExtensionSystem::PluginSpec *spec) +{ + if (!spec) + return false; + + return spec->name().contains("QmlDesigner"); +} + +const char qmlDesignerEventsKey[] = "qmlDesignerEvents"; +const char qmlDesignerTimesKey[] = "qmlDesignerTimes"; + +QmlDesignerUsageEventSource::QmlDesignerUsageEventSource() + : KUserFeedback::AbstractDataSource("qmlDesignerUsageEvents", Provider::DetailedUsageStatistics) +{ + const auto plugins = ExtensionSystem::PluginManager::plugins(); + const auto it = std::find_if(plugins.begin(), plugins.end(), &isQmlDesigner); + if (it != plugins.end()) { + const QObject *qmlDesignerPlugin = (*it)->plugin(); + connect(qmlDesignerPlugin, + SIGNAL(usageStatisticsNotifier(const QString)), + this, + SLOT(handleUsageStatisticsNotifier(const QString))); + connect(qmlDesignerPlugin, + SIGNAL(usageStatisticsUsageTimer(const QString, int)), + this, + SLOT(handleUsageStatisticsUsageTimer(const QString, int))); + } +} + +QString QmlDesignerUsageEventSource::name() const +{ + return tr("Qt Quick Designer usage of views and actions"); +} + +QString QmlDesignerUsageEventSource::description() const +{ + return tr("What views and actions are used in QML Design mode."); +} + +void QmlDesignerUsageEventSource::handleUsageStatisticsNotifier(const QString &identifier) +{ + auto it = m_eventData.find(identifier); + + if (it != m_eventData.end()) + it.value() = it.value().toInt() + 1; + else + m_eventData.insert(identifier, 1); +} + +void QmlDesignerUsageEventSource::handleUsageStatisticsUsageTimer(const QString &identifier, int elapsed) +{ + auto it = m_timeData.find(identifier); + + if (it != m_timeData.end()) + it.value() = it.value().toInt() + elapsed; + else + m_timeData.insert(identifier, elapsed); +} + +QVariant QmlDesignerUsageEventSource::data() +{ + return QVariantMap{{qmlDesignerEventsKey, m_eventData}, {qmlDesignerTimesKey, m_timeData}}; +} + +void QmlDesignerUsageEventSource::loadImpl(QSettings *settings) +{ + auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); + m_eventData = settings->value(qmlDesignerEventsKey).toMap(); + m_timeData = settings->value(qmlDesignerTimesKey).toMap(); +} + +void QmlDesignerUsageEventSource::storeImpl(QSettings *settings) +{ + auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); + settings->setValue(qmlDesignerEventsKey, m_eventData); + settings->setValue(qmlDesignerTimesKey, m_timeData); +} + +void QmlDesignerUsageEventSource::resetImpl(QSettings *settings) +{ + m_eventData.clear(); + storeImpl(settings); +} + +} // namespace Internal +} // namespace UsageStatistic diff --git a/src/datasources/qmldesignerusageeventsource.h b/src/datasources/qmldesignerusageeventsource.h new file mode 100644 index 0000000..c51055b --- /dev/null +++ b/src/datasources/qmldesignerusageeventsource.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company +** Contact: https://www.qt.io/licensing/ +** +** This file is part of UsageStatistic plugin for Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ +#pragma once + +#include <KUserFeedback/AbstractDataSource> + +#include <QMap> + +namespace UsageStatistic { +namespace Internal { + +class QmlDesignerUsageEventSource : public QObject, public KUserFeedback::AbstractDataSource +{ + Q_OBJECT + +public: + QmlDesignerUsageEventSource(); + +public: + QString name() const override; + QString description() const override; + + QVariant data() override; + + void loadImpl(QSettings *settings) override; + void storeImpl(QSettings *settings) override; + void resetImpl(QSettings *settings) override; + +public slots: + void handleUsageStatisticsNotifier(const QString &identifier); + void handleUsageStatisticsUsageTimer(const QString &identifier, int elapsed); + +private: + QMap<QString, QVariant> m_eventData; + QMap<QString, QVariant> m_timeData; +}; + +} // namespace Internal +} // namespace UsageStatistic diff --git a/src/src.pro b/src/src.pro index 6e8f16c..41ab62e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -22,6 +22,7 @@ SOURCES += \ datasources/examplesdatasource.cpp \ datasources/kitsource.cpp \ datasources/qmldesignerusagetimesource.cpp \ + datasources/qmldesignerusageeventsource.cpp \ ui/usagestatisticpage.cpp \ ui/usagestatisticwidget.cpp \ services/datasubmitter.cpp @@ -40,6 +41,7 @@ HEADERS += \ datasources/examplesdatasource.h \ datasources/kitsource.h \ datasources/qmldesignerusagetimesource.h \ + datasources/qmldesignerusageeventsource.h \ ui/usagestatisticpage.h \ ui/usagestatisticwidget.h \ services/datasubmitter.h \ diff --git a/src/usagestatisticplugin.cpp b/src/usagestatisticplugin.cpp index c0e0529..daaedac 100644 --- a/src/usagestatisticplugin.cpp +++ b/src/usagestatisticplugin.cpp @@ -54,6 +54,7 @@ #include "datasources/examplesdatasource.h" #include "datasources/kitsource.h" #include "datasources/qmldesignerusagetimesource.h" +#include "datasources/qmldesignerusageeventsource.h" #include "datasources/servicesource.h" #include "services/datasubmitter.h" @@ -106,6 +107,7 @@ static void addQtCreatorDataSources(KUserFeedback::Provider &provider) provider.addDataSource(new ExamplesDataSource); provider.addDataSource(new KitSource); provider.addDataSource(new QmlDesignerUsageTimeSource); + provider.addDataSource(new QmlDesignerUsageEventSource); } static void addServiceDataSource(const std::shared_ptr<KUserFeedback::Provider> &provider) |