Skip to content
Snippets Groups Projects
Commit 85405c89 authored by Vitaly Fanaskov's avatar Vitaly Fanaskov
Browse files

Implemented data source for tracking qml files editing time

parent 95c58be1
No related branches found
No related tags found
No related merge requests found
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company
** Contact: https://www.qt.io/licensing/
**
** Created 7/3/2019.
**
** 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 "qmldesignerusagetimesource.h"
#include <QtCore/QFileInfo>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/imode.h>
namespace UsageStatistic {
namespace Internal {
static QString currentModeName()
{
if (auto modeManager = Core::ModeManager::instance()) {
if (auto mode = modeManager->currentMode()) {
return mode->displayName().toLower();
}
}
return {};
}
QmlDesignerUsageTimeSource::QmlDesignerUsageTimeSource()
: TimeUsageSourceBase(QStringLiteral("qmlDesignerUsageTime"))
{
if (auto modeManager = Core::ModeManager::instance()) {
m_connections <<
connect(modeManager, &Core::ModeManager::currentModeChanged,
[this](auto &&modeId){
updateTrackingState(QString::fromUtf8(modeId.name().toLower())); });
}
if (auto editorManager = Core::EditorManager::instance()) {
m_connections <<
connect(editorManager, &Core::EditorManager::currentEditorChanged,
[this](){ updateTrackingState(currentModeName()); });
}
}
QmlDesignerUsageTimeSource::~QmlDesignerUsageTimeSource()
{
// Connections shouldn't outlive this object, because 'this' is captured
for (auto &&connection : m_connections)
disconnect(connection);
}
QString QmlDesignerUsageTimeSource::name() const
{
return tr("QmlDesigner usage time");
}
QString QmlDesignerUsageTimeSource::description() const
{
return tr("How long a user spent editing QML files in designer mode");
}
static bool isDesignMode(const QString &modeName)
{
static const QString designModeName = QStringLiteral("design");
return modeName == designModeName;
}
static bool editingQmlFile()
{
static const QSet<QString> validExtentions = {"qml", "qml.ui"};
static const QString validMimeType = "qml";
if (auto document = Core::EditorManager::currentDocument()) {
QString mimeType = document->mimeType().toLower();
QString extension = document->filePath().toFileInfo().completeSuffix().toLower();
return validExtentions.contains(extension) || mimeType.contains(validMimeType);
}
return false;
}
void QmlDesignerUsageTimeSource::updateTrackingState(const QString &modeName)
{
if (isDesignMode(modeName) && editingQmlFile() && !isTimeTrackingActive()) {
emit start();
} else {
emit stop();
}
}
} // namespace Internal
} // namespace UsageStatistic
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company
** Contact: https://www.qt.io/licensing/
**
** Created 7/3/2019.
**
** 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 "timeusagesourcebase.h"
namespace UsageStatistic {
namespace Internal {
class QmlDesignerUsageTimeSource : public TimeUsageSourceBase
{
public:
QmlDesignerUsageTimeSource();
~QmlDesignerUsageTimeSource() override;
public: // AbstractDataSource interface
QString name() const override;
QString description() const override;
private: // Methods
void updateTrackingState(const QString &modeName);
private: // Data
QVector<QMetaObject::Connection> m_connections;
};
} // namespace Internal
} // namespace UsageStatistic
......@@ -18,7 +18,8 @@ SOURCES += \
datasources/timeusagesourcebase.cpp \
datasources/modeusagetimesource.cpp \
datasources/examplesdatasource.cpp \
datasources/kitsource.cpp
datasources/kitsource.cpp \
datasources/qmldesignerusagetimesource.cpp
HEADERS += \
usagestatisticplugin.h \
......@@ -31,7 +32,8 @@ HEADERS += \
datasources/timeusagesourcebase.h \
datasources/modeusagetimesource.h \
datasources/examplesdatasource.h \
datasources/kitsource.h
datasources/kitsource.h \
datasources/qmldesignerusagetimesource.h
# Qt Creator linking
......
......@@ -33,6 +33,7 @@
#include "datasources/modeusagetimesource.h"
#include "datasources/examplesdatasource.h"
#include "datasources/kitsource.h"
#include "datasources/qmldesignerusagetimesource.h"
namespace UsageStatistic {
namespace Internal {
......@@ -87,6 +88,7 @@ static void addQtCreatorDataSources(KUserFeedback::Provider &provider)
provider.addDataSource(new ModeUsageTimeSource);
provider.addDataSource(new ExamplesDataSource);
provider.addDataSource(new KitSource);
provider.addDataSource(new QmlDesignerUsageTimeSource);
}
bool UsageStatisticPlugin::delayedInitialize()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment