code formatting (for "global" and "telemetry" modules)

This commit is contained in:
Howard-C 2019-12-21 14:01:34 +08:00
parent 675053f957
commit 691df1539d
18 changed files with 240 additions and 56 deletions

View file

@ -23,16 +23,19 @@
#include <QString>
#include <QtQml/qqml.h>
class AbstractModuleSetup
{
public:
//---------------------------------------------------------
// AbstractModuleSetup
//---------------------------------------------------------
class AbstractModuleSetup {
public:
void setup() {
registerExports();
registerResources();
registerQmlTypes();
}
protected:
protected:
virtual QString moduleName() = 0;
virtual void registerExports() {}

View file

@ -1,3 +1,22 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2019 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#include "modulessetup.h"
#include "config.h"
@ -5,6 +24,10 @@
#include "telemetrysetup.h"
#endif
//---------------------------------------------------------
// ModulesSetup
//---------------------------------------------------------
ModulesSetup::ModulesSetup()
{
#ifdef BUILD_TELEMETRY_MODULE
@ -12,9 +35,12 @@ ModulesSetup::ModulesSetup()
#endif
}
//---------------------------------------------------------
// setup
//---------------------------------------------------------
void ModulesSetup::setup()
{
for (AbstractModuleSetup* moduleSetup : m_modulesSetupList) {
for (AbstractModuleSetup* moduleSetup : m_modulesSetupList)
moduleSetup->setup();
}
}

View file

@ -1,12 +1,34 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2019 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef MODULESSETUP_H
#define MODULESSETUP_H
#include <QList>
#include "interfaces/abstractmodulesetup.h"
class ModulesSetup
{
public:
//---------------------------------------------------------
// ModulesSetup
//---------------------------------------------------------
class ModulesSetup {
public:
static ModulesSetup* instance() {
static ModulesSetup s;
return &s;
@ -14,12 +36,12 @@ public:
void setup();
private:
private:
Q_DISABLE_COPY(ModulesSetup)
ModulesSetup();
QList<AbstractModuleSetup*> m_modulesSetupList;
};
};
#endif // MODULESSETUP_H

View file

@ -29,11 +29,13 @@
INTERFACE_NAME* ALIAS() { return ServiceInjector<INTERFACE_NAME>::getService(); } \
void set##ALIAS(INTERFACE_NAME* impl) { ServiceInjector<INTERFACE_NAME>::setService(impl); } \
template <typename I>
class ServiceInjector
{
public:
//---------------------------------------------------------
// ServiceInjector
//---------------------------------------------------------
template <typename I>
class ServiceInjector {
public:
ServiceInjector() {
ServicesResolver::IServiceFactory* srvFactory = ServicesResolver::resolveServiceFactory<I>();
@ -44,8 +46,8 @@ public:
void setService(I* service) { m_service = QSharedPointer<I>(service); }
private:
private:
QSharedPointer<I> m_service;
};
};
#endif // SERVICEINJECTOR_H

View file

@ -30,29 +30,38 @@
return id; \
} \
//---------------------------------------------------------
// ServicesResolver
//---------------------------------------------------------
class ServicesResolver {
public:
public:
//---------------------------------------------------
// IServiceFactory
//---------------------------------------------------
struct IServiceFactory {
virtual void* getInstance() = 0;
};
virtual void* getInstance() = 0;
};
//---------------------------------------------------
// FunctorBasedFactory
//---------------------------------------------------
template <typename T>
struct FunctorBasedFactory : public IServiceFactory
{
struct FunctorBasedFactory : public IServiceFactory {
using F = T*(*)();
FunctorBasedFactory(F f) : IServiceFactory() {
getInstanceFunc = f;
}
void* getInstance() override {
return getInstanceFunc();
}
private:
F getInstanceFunc;
};
};
template <typename I, typename T>
static inline void registerService(T*(*f)()) {
@ -71,13 +80,12 @@ public:
return srvHash()->value(interfaceId);
}
private:
private:
static inline QHash<QUuid, IServiceFactory*> *srvHash() {
static QHash<QUuid, IServiceFactory*> serviceHash = QHash<QUuid, IServiceFactory*>();
return &serviceHash;
}
};
};
#endif // SERVICESRESOLVER_H

View file

@ -7050,6 +7050,10 @@ bool MuseScore::saveMp3(Score* score, QIODevice* device, bool& wasCanceled)
#ifdef BUILD_TELEMETRY_MODULE
//---------------------------------------------------------
// tryToRequestTelemetryPermission
//---------------------------------------------------------
void tryToRequestTelemetryPermission()
{
QString accessRequestedAtVersion = preferences.getString(PREF_APP_STARTUP_TELEMETRY_ACCESS_REQUESTED);
@ -7064,12 +7068,16 @@ void tryToRequestTelemetryPermission()
}
#endif
//---------------------------------------------------------
// updateUiStyleAndTheme
//---------------------------------------------------------
void MuseScore::updateUiStyleAndTheme()
{
// set UI Theme
QApplication::setStyle(QStyleFactory::create("Fusion"));
QString wd = QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).arg(QCoreApplication::applicationName());
QString wd = QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).arg(QCoreApplication::applicationName());
// set UI Color Palette
QPalette p(QApplication::palette());
QString jsonPaletteFilename = preferences.isThemeDark() ? "palette_dark_fusion.json" : "palette_light_fusion.json";;
@ -7111,12 +7119,13 @@ void MuseScore::updateUiStyleAndTheme()
css.replace("$buttonHighlightDisabledOn", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_DARK_ON).name().toLatin1());
css.replace("$buttonHighlightEnabledOff", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_DARK_OFF).name().toLatin1());
css.replace("$buttonHighlightEnabledOn", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_DARK_ON).name().toLatin1());
} else {
}
else {
css.replace("$buttonHighlightDisabledOff", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_LIGHT_OFF).name().toLatin1());
css.replace("$buttonHighlightDisabledOn", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_LIGHT_ON).name().toLatin1());
css.replace("$buttonHighlightEnabledOff", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_LIGHT_OFF).name().toLatin1());
css.replace("$buttonHighlightEnabledOn", Ms::preferences.getColor(PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_LIGHT_ON).name().toLatin1());
}
}
qApp->setStyleSheet(css);
@ -7129,6 +7138,10 @@ void MuseScore::updateUiStyleAndTheme()
Shortcut::refreshIcons();
}
//---------------------------------------------------------
// initApplication
//---------------------------------------------------------
MuseScoreApplication* MuseScoreApplication::initApplication(int& argc, char** argv)
{
QFile f(":/revision.h");
@ -7167,6 +7180,10 @@ MuseScoreApplication* MuseScoreApplication::initApplication(int& argc, char** ar
return app;
}
//---------------------------------------------------------
// parseCommandLineArguments
//---------------------------------------------------------
MuseScoreApplication::CommandLineParseResult MuseScoreApplication::parseCommandLineArguments(MuseScoreApplication* app)
{
QCommandLineParser parser;
@ -7508,6 +7525,10 @@ int runApplication(int& argc, char** av)
return qApp->exec();
}
//---------------------------------------------------------
// init
//---------------------------------------------------------
void MuseScore::init(QStringList& argv)
{
mscoreGlobalShare = getSharePath();

View file

@ -4374,6 +4374,10 @@ void Shortcut::resetToDefault()
dirty = true;
}
//---------------------------------------------------------
// getShortcutByKeySequence
//---------------------------------------------------------
Shortcut* Shortcut::getShortcutByKeySequence(const QKeySequence &keySequence)
{
for (Shortcut* shortcut : _shortcuts.values()) {
@ -4440,6 +4444,10 @@ QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::Seque
return s;
}
//---------------------------------------------------------
// keySeqFromString
//---------------------------------------------------------
QKeySequence Shortcut::keySeqFromString(const QString& str, QKeySequence::SequenceFormat fmt)
{
int code[KEYSEQ_SIZE], i;

View file

@ -27,11 +27,18 @@
#include <QToolButton>
#include "shortcut.h"
//---------------------------------------------------------
// ActionEventObserver
//---------------------------------------------------------
ActionEventObserver::ActionEventObserver(QObject *parent) : QObject(parent)
{
}
//---------------------------------------------------------
// extractActionData
//---------------------------------------------------------
QPair<QString, QString> ActionEventObserver::extractActionData(QObject* watched)
{
QPair<QString, QString> result;
@ -64,9 +71,12 @@ QPair<QString, QString> ActionEventObserver::extractActionData(QObject* watched)
result.second = actionKey;
return result;
}
//---------------------------------------------------------
// eventFilter
//---------------------------------------------------------
bool ActionEventObserver::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonRelease) {

View file

@ -27,13 +27,16 @@
#include "interfaces/itelemetryservice.h"
class ActionEventObserver : public QObject, public ServiceInjector<ITelemetryService>
{
//---------------------------------------------------------
// ActionEventObserver
//---------------------------------------------------------
class ActionEventObserver : public QObject, public ServiceInjector<ITelemetryService> {
Q_OBJECT
INJECT(ITelemetryService, telemetryService)
public:
public:
static ActionEventObserver* instance()
{
static ActionEventObserver s;
@ -42,11 +45,11 @@ public:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
private:
Q_DISABLE_COPY(ActionEventObserver)
explicit ActionEventObserver(QObject* parent = nullptr);
QPair<QString, QString> extractActionData(QObject *watched);
};
};
#endif // MENUBAR_H

View file

@ -25,9 +25,12 @@
#include <QVariantMap>
#include "servicesresolver.h"
class ITelemetryService
{
public:
//---------------------------------------------------------
// ITelemetryService
//---------------------------------------------------------
class ITelemetryService {
public:
INTERFACE_ID
virtual ~ITelemetryService() = default;

View file

@ -22,21 +22,37 @@
#include <QDesktopServices>
#include <QUrl>
//---------------------------------------------------------
// TelemetryPermissionModel
//---------------------------------------------------------
TelemetryPermissionModel::TelemetryPermissionModel(QObject *parent) : QObject(parent)
{
m_settings.setValue(PREF_APP_STARTUP_TELEMETRY_ACCESS_REQUESTED, true);
}
//---------------------------------------------------------
// accept
//---------------------------------------------------------
void TelemetryPermissionModel::accept()
{
m_settings.setValue(PREF_APP_TELEMETRY_ALLOWED, true);
}
//---------------------------------------------------------
// reject
//---------------------------------------------------------
void TelemetryPermissionModel::reject()
{
m_settings.setValue(PREF_APP_TELEMETRY_ALLOWED, false);
}
//---------------------------------------------------------
// openLink
//---------------------------------------------------------
void TelemetryPermissionModel::openLink(const QString &link)
{
QDesktopServices::openUrl(QUrl(link));

View file

@ -24,18 +24,21 @@
#include <QSettings>
#include <QString>
class TelemetryPermissionModel : public QObject
{
Q_OBJECT
//---------------------------------------------------------
// TelemetryPermissionModel
//---------------------------------------------------------
public:
class TelemetryPermissionModel : public QObject {
Q_OBJECT
public:
explicit TelemetryPermissionModel(QObject *parent = nullptr);
Q_INVOKABLE void accept();
Q_INVOKABLE void reject();
Q_INVOKABLE void openLink(const QString &link);
private:
private:
QSettings m_settings;
};

View file

@ -22,10 +22,18 @@
#include "telemetryservice.h"
#include "config.h"
//---------------------------------------------------------
// TelemetryService
//---------------------------------------------------------
TelemetryService::TelemetryService()
{
}
//---------------------------------------------------------
// sendEvent
//---------------------------------------------------------
void TelemetryService::sendEvent(const QString &category, const QString &action, const QString &label, const QVariant &value, const QVariantMap &customValues)
{
if (!isTelemetryAllowed() || category.isEmpty() || action.isEmpty())
@ -34,6 +42,10 @@ void TelemetryService::sendEvent(const QString &category, const QString &action,
GAnalytics::instance(TELEMETRY_TRACK_ID)->sendEvent(category, action, label, value, customValues);
}
//---------------------------------------------------------
// sendException
//---------------------------------------------------------
void TelemetryService::sendException(const QString &exceptionDescription, bool exceptionFatal, const QVariantMap &customValues)
{
if (!isTelemetryAllowed())
@ -42,6 +54,10 @@ void TelemetryService::sendException(const QString &exceptionDescription, bool e
GAnalytics::instance(TELEMETRY_TRACK_ID)->sendException(exceptionDescription, exceptionFatal, customValues);
}
//---------------------------------------------------------
// startSession
//---------------------------------------------------------
void TelemetryService::startSession()
{
if (!isTelemetryAllowed())
@ -50,6 +66,10 @@ void TelemetryService::startSession()
GAnalytics::instance(TELEMETRY_TRACK_ID)->startSession();
}
//---------------------------------------------------------
// endSession
//---------------------------------------------------------
void TelemetryService::endSession()
{
if (!isTelemetryAllowed())
@ -58,6 +78,10 @@ void TelemetryService::endSession()
GAnalytics::instance(TELEMETRY_TRACK_ID)->endSession();
}
//---------------------------------------------------------
// isTelemetryAllowed
//---------------------------------------------------------
bool TelemetryService::isTelemetryAllowed() const
{
#ifdef MSCORE_UNSTABLE

View file

@ -24,8 +24,12 @@
#include <QSettings>
//---------------------------------------------------------
// TelemetryService
//---------------------------------------------------------
class TelemetryService : public ITelemetryService {
public:
public:
TelemetryService();
void sendEvent(const QString &category, const QString &action, const QString &label, const QVariant &value, const QVariantMap &customValues) override;
@ -33,7 +37,7 @@ public:
void startSession() override;
void endSession() override;
private:
private:
bool isTelemetryAllowed() const;
QSettings m_settings;

View file

@ -26,10 +26,18 @@
#include "models/telemetrypermissionmodel.h"
//---------------------------------------------------------
// TelemetrySetup
//---------------------------------------------------------
TelemetrySetup::TelemetrySetup()
{
}
//---------------------------------------------------------
// registerExports
//---------------------------------------------------------
void TelemetrySetup::registerExports()
{
ServicesResolver::registerService<ITelemetryService, TelemetryService>([]() -> TelemetryService* {
@ -37,16 +45,28 @@ void TelemetrySetup::registerExports()
});
}
//---------------------------------------------------------
// moduleName
//---------------------------------------------------------
QString TelemetrySetup::moduleName()
{
return QStringLiteral("telemetry");
}
//---------------------------------------------------------
// registerResources
//---------------------------------------------------------
void TelemetrySetup::registerResources()
{
Q_INIT_RESOURCE(telemetry_resources);
}
//---------------------------------------------------------
// registerQmlTypes
//---------------------------------------------------------
void TelemetrySetup::registerQmlTypes()
{
qmlRegisterType<TelemetryPermissionModel>("MuseScore.Telemetry", 3, 3, "TelemetryPermissionModel");

View file

@ -22,12 +22,15 @@
#include "interfaces/abstractmodulesetup.h"
class TelemetrySetup : public AbstractModuleSetup
{
public:
//---------------------------------------------------------
// TelemetrySetup
//---------------------------------------------------------
class TelemetrySetup : public AbstractModuleSetup {
public:
TelemetrySetup();
protected:
protected:
void registerExports() override;
QString moduleName() override;

View file

@ -21,6 +21,10 @@
#include <QQuickItem>
//---------------------------------------------------------
// TelemetryPermissionDialog
//---------------------------------------------------------
TelemetryPermissionDialog::TelemetryPermissionDialog(QWidget* parentWidget) : QQuickView()
{
setMinimumWidth(500);

View file

@ -24,10 +24,14 @@
#include <QQmlEngine>
#include <QWidget>
class TelemetryPermissionDialog : public QQuickView
{
//---------------------------------------------------------
// TelemetryPermissionDialog
//---------------------------------------------------------
class TelemetryPermissionDialog : public QQuickView {
Q_OBJECT
public:
public:
explicit TelemetryPermissionDialog(QWidget* parentWidget = nullptr);
};