QmlDesigner: Add custom int and double validator

Add custom/studio int and double validator in order to be able to set
a locale directly and not via using a name/string. Use a copy of the
system locale with omit group separator set.

Task-number: QDS-13536
Change-Id: I61c995b4d1f2575fcb53e327f35e4781cebc28ca
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Henning Gruendl
2024-09-10 17:28:38 +02:00
committed by Henning Gründl
parent 9e5b6bb1c9
commit 1717a386ba
7 changed files with 115 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
import QtQuick
import QtQuick.Templates as T
import StudioTheme 1.0 as StudioTheme
import StudioTheme as StudioTheme
import StudioQuickUtils
T.SpinBox {
@@ -100,7 +100,7 @@ T.SpinBox {
DoubleValidator {
id: doubleValidator
locale: control.locale.name
locale: control.locale
notation: DoubleValidator.StandardNotation
decimals: control.decimals
bottom: Math.min(control.realFrom, control.realTo)
@@ -109,7 +109,7 @@ T.SpinBox {
IntValidator {
id: intValidator
locale: control.locale.name
locale: control.locale
bottom: Math.round(Math.min(control.realFrom, control.realTo))
top: Math.round(Math.max(control.realFrom, control.realTo))
}

View File

@@ -3,7 +3,7 @@
import QtQuick
import QtQuick.Templates as T
import StudioTheme 1.0 as StudioTheme
import StudioTheme as StudioTheme
import StudioQuickUtils
T.SpinBox {
@@ -79,7 +79,7 @@ T.SpinBox {
DoubleValidator {
id: doubleValidator
locale: control.locale.name
locale: control.locale
notation: DoubleValidator.StandardNotation
decimals: control.decimals
bottom: Math.min(control.from, control.to) / control.factor
@@ -88,7 +88,7 @@ T.SpinBox {
IntValidator {
id: intValidator
locale: control.locale.name
locale: control.locale
bottom: Math.min(control.from, control.to)
top: Math.max(control.from, control.to)
}

View File

@@ -50,6 +50,7 @@ extend_qtc_plugin(QmlDesignerBase
studiostyle_p.cpp studiostyle_p.h
studioquickwidget.cpp studioquickwidget.h
studiosettingspage.cpp studiosettingspage.h
studiovalidator.cpp studiovalidator.h
)

View File

@@ -9,6 +9,7 @@
#include <designersettings.h>
#include <studioquickutils.h>
#include <studiovalidator.h>
#include <windowmanager.h>
#include <coreplugin/icore.h>
@@ -93,6 +94,8 @@ bool QmlDesignerBasePlugin::initialize(const QStringList &arguments, QString *)
WindowManager::registerDeclarativeType();
StudioQuickUtils::registerDeclarativeType();
StudioIntValidator::registerDeclarativeType();
StudioDoubleValidator::registerDeclarativeType();
d = std::make_unique<Data>();
if (Core::ICore::settings()->value("QML/Designer/StandAloneMode", false).toBool())

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2023 The Qt Company Ltd.
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "studioquickutils.h"
@@ -9,7 +9,7 @@ namespace QmlDesigner {
StudioQuickUtils::StudioQuickUtils()
{
m_locale = QLocale("DesignStudioLocale");
m_locale = QLocale(QLocale::system());
m_locale.setNumberOptions(QLocale::OmitGroupSeparator);
}

View File

@@ -0,0 +1,54 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "studiovalidator.h"
#include <coreplugin/icore.h>
namespace QmlDesigner {
StudioIntValidator::StudioIntValidator(QObject *parent)
: QIntValidator(parent)
{}
void StudioIntValidator::registerDeclarativeType()
{
qmlRegisterType<StudioIntValidator>("StudioQuickUtils", 1, 0, "IntValidator");
}
QLocale StudioIntValidator::locale() const
{
return QIntValidator::locale();
}
void StudioIntValidator::setLocale(const QLocale &locale)
{
if (QIntValidator::locale() != locale) {
QIntValidator::setLocale(locale);
emit localeChanged();
}
}
StudioDoubleValidator::StudioDoubleValidator(QObject *parent)
: QDoubleValidator(parent)
{}
void StudioDoubleValidator::registerDeclarativeType()
{
qmlRegisterType<StudioDoubleValidator>("StudioQuickUtils", 1, 0, "DoubleValidator");
}
QLocale StudioDoubleValidator::locale() const
{
return QDoubleValidator::locale();
}
void StudioDoubleValidator::setLocale(const QLocale &locale)
{
if (QDoubleValidator::locale() != locale) {
QDoubleValidator::setLocale(locale);
emit localeChanged();
}
}
} // namespace QmlDesigner

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "../qmldesignerbase_global.h"
#include <QtQml/qqml.h>
#include <QLocale>
#include <QValidator>
namespace QmlDesigner {
class QMLDESIGNERBASE_EXPORT StudioIntValidator : public QIntValidator
{
Q_OBJECT
Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL)
public:
StudioIntValidator(QObject *parent = nullptr);
static void registerDeclarativeType();
QLocale locale() const;
void setLocale(const QLocale &locale);
signals:
void localeChanged();
};
class QMLDESIGNERBASE_EXPORT StudioDoubleValidator : public QDoubleValidator
{
Q_OBJECT
Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL)
public:
StudioDoubleValidator(QObject *parent = nullptr);
static void registerDeclarativeType();
QLocale locale() const;
void setLocale(const QLocale &locale);
signals:
void localeChanged();
};
} // namespace QmlDesigner