Skip to content

Commit

Permalink
added qml data formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jan 13, 2025
1 parent eccdf92 commit 569b07c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/framework/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/view/widgetstatestore.cpp
${CMAKE_CURRENT_LIST_DIR}/view/widgetstatestore.h
${CMAKE_CURRENT_LIST_DIR}/view/widgetutils.h
${CMAKE_CURRENT_LIST_DIR}/view/qmldataformatter.cpp
${CMAKE_CURRENT_LIST_DIR}/view/qmldataformatter.h

${CMAKE_CURRENT_LIST_DIR}/view/internal/errordetailsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/errordetailsmodel.h
Expand Down
6 changes: 6 additions & 0 deletions src/framework/ui/internal/uiengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ UiEngine::UiEngine(const modularity::ContextPtr& iocCtx)
m_interactiveProvider = std::make_shared<InteractiveProvider>(iocContext());
m_api = new QmlApi(this, iocContext());
m_tooltip = new QmlToolTip(this, iocContext());
m_dataFormatter = new QmlDataFormatter(this);

//! NOTE At the moment, UiTheme is also QProxyStyle
//! Inside the theme, QApplication::setStyle(this) is calling and the QStyleSheetStyle becomes as parent.
Expand Down Expand Up @@ -132,6 +133,11 @@ void UiEngine::quit()
m_engine = nullptr;
}

QmlDataFormatter* UiEngine::df() const
{
return m_dataFormatter;
}

QQuickItem* UiEngine::rootItem() const
{
return m_rootItem;
Expand Down
4 changes: 4 additions & 0 deletions src/framework/ui/internal/uiengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../view/qmltranslation.h"
#include "../view/interactiveprovider.h"
#include "../view/qmlapi.h"
#include "../view/qmldataformatter.h"

#include "languages/ilanguagesservice.h"

Expand All @@ -43,6 +44,7 @@ class UiEngine : public QObject, public IUiEngine, public Injectable

Q_PROPERTY(api::ThemeApi * theme READ theme NOTIFY themeChanged)
Q_PROPERTY(QmlToolTip * tooltip READ tooltip CONSTANT)
Q_PROPERTY(QmlDataFormatter * df READ df CONSTANT)

Q_PROPERTY(QQuickItem * rootItem READ rootItem WRITE setRootItem NOTIFY rootItemChanged)

Expand All @@ -62,6 +64,7 @@ class UiEngine : public QObject, public IUiEngine, public Injectable
QmlApi* api() const;
api::ThemeApi* theme() const;
QmlToolTip* tooltip() const;
QmlDataFormatter* df() const;
InteractiveProvider* interactiveProvider_property() const;
std::shared_ptr<InteractiveProvider> interactiveProvider() const;

Expand Down Expand Up @@ -104,6 +107,7 @@ public slots:
std::shared_ptr<InteractiveProvider> m_interactiveProvider = nullptr;
QmlApi* m_api = nullptr;
QmlToolTip* m_tooltip = nullptr;
QmlDataFormatter* m_dataFormatter = nullptr;
QQuickItem* m_rootItem = nullptr;
mutable int m_isEffectsAllowed = -1;
};
Expand Down
1 change: 1 addition & 0 deletions src/framework/ui/uimodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void UiModule::registerUiTypes()
qmlRegisterUncreatableType<ContainerType>("Muse.Ui", 1, 0, "ContainerType", "Cannot create a ContainerType");

qmlRegisterUncreatableType<NavigationEvent>("Muse.Ui", 1, 0, "NavigationEvent", "Cannot create a KeyNavigationEvent");
qmlRegisterType<QmlDataFormatter>("Muse.Ui", 1, 0, "QmlDataFormatter");
qmlRegisterType<NavigationSection>("Muse.Ui", 1, 0, "NavigationSection");
qmlRegisterType<NavigationPanel>("Muse.Ui", 1, 0, "NavigationPanel");
qmlRegisterType<NavigationPopupPanel>("Muse.Ui", 1, 0, "NavigationPopupPanel");
Expand Down
36 changes: 36 additions & 0 deletions src/framework/ui/view/qmldataformatter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2025 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 3 as
* published by the Free Software Foundation.
*
* 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, see <https://www.gnu.org/licenses/>.
*/
#include "qmldataformatter.h"

#include "global/dataformatter.h"

using namespace muse::ui;

QmlDataFormatter::QmlDataFormatter(QObject* parent)
: QObject{parent}
{
}

QString QmlDataFormatter::formatReal(double value, int decimals) const
{
return DataFormatter::formatReal(value, decimals);
}
35 changes: 35 additions & 0 deletions src/framework/ui/view/qmldataformatter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2025 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 3 as
* published by the Free Software Foundation.
*
* 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once

#include <QObject>

namespace muse::ui {
class QmlDataFormatter : public QObject
{
Q_OBJECT
public:
explicit QmlDataFormatter(QObject* parent = nullptr);

Q_INVOKABLE QString formatReal(double value, int decimals = 2) const;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TextInputField {
property real min: -10000.0
property int decimals: 2

currentText: parseFloat(root.currentValue.toFixed(root.decimals))
currentText: ui.df.formatReal(root.currentValue, root.decimals)

validator: DoubleInputValidator {
top: root.max
Expand Down

0 comments on commit 569b07c

Please sign in to comment.