feat(StatusQ/Utils): Add StringUtils to expose string-related C++ routines
So far methods like escapeHtml were available via backend, creating unnecessary dependency on backing in UI components.
This commit is contained in:
parent
02d16cb22f
commit
0cba5eccbd
|
@ -88,19 +88,21 @@ endif()
|
||||||
|
|
||||||
add_library(StatusQ SHARED
|
add_library(StatusQ SHARED
|
||||||
${STATUSQ_QRC_COMPILED}
|
${STATUSQ_QRC_COMPILED}
|
||||||
src/plugin.cpp
|
|
||||||
include/StatusQ/QClipboardProxy.h
|
include/StatusQ/QClipboardProxy.h
|
||||||
include/StatusQ/modelutilsinternal.h
|
include/StatusQ/modelutilsinternal.h
|
||||||
include/StatusQ/permissionutilsinternal.h
|
include/StatusQ/permissionutilsinternal.h
|
||||||
include/StatusQ/rxvalidator.h
|
include/StatusQ/rxvalidator.h
|
||||||
include/StatusQ/statussyntaxhighlighter.h
|
include/StatusQ/statussyntaxhighlighter.h
|
||||||
include/StatusQ/statuswindow.h
|
include/StatusQ/statuswindow.h
|
||||||
|
include/StatusQ/stringutilsinternal.h
|
||||||
src/QClipboardProxy.cpp
|
src/QClipboardProxy.cpp
|
||||||
src/modelutilsinternal.cpp
|
src/modelutilsinternal.cpp
|
||||||
src/permissionutilsinternal.cpp
|
src/permissionutilsinternal.cpp
|
||||||
|
src/plugin.cpp
|
||||||
src/rxvalidator.cpp
|
src/rxvalidator.cpp
|
||||||
src/statussyntaxhighlighter.cpp
|
src/statussyntaxhighlighter.cpp
|
||||||
src/statuswindow.cpp
|
src/statuswindow.cpp
|
||||||
|
src/stringutilsinternal.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(StatusQ PROPERTIES
|
set_target_properties(StatusQ PROPERTIES
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class QJSEngine;
|
||||||
|
class QQmlEngine;
|
||||||
|
|
||||||
|
class StringUtilsInternal : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit StringUtilsInternal(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
Q_INVOKABLE QString escapeHtml(const QString &unsafe) const;
|
||||||
|
|
||||||
|
static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);
|
||||||
|
};
|
|
@ -0,0 +1,11 @@
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import QtQuick 2.15
|
||||||
|
|
||||||
|
import StatusQ.Internal 0.1 as Internal
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
function escapeHtml(unsafe) {
|
||||||
|
return Internal.StringUtils.escapeHtml(unsafe)
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,4 +13,5 @@ singleton AmountsArithmetic 0.1 AmountsArithmetic.qml
|
||||||
singleton Emoji 0.1 Emoji.qml
|
singleton Emoji 0.1 Emoji.qml
|
||||||
singleton ModelUtils 0.1 ModelUtils.qml
|
singleton ModelUtils 0.1 ModelUtils.qml
|
||||||
singleton OperatorsUtils 0.1 OperatorsUtils.qml
|
singleton OperatorsUtils 0.1 OperatorsUtils.qml
|
||||||
|
singleton StringUtils 0.1 StringUtils.qml
|
||||||
singleton Utils 0.1 Utils.qml
|
singleton Utils 0.1 Utils.qml
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "StatusQ/rxvalidator.h"
|
#include "StatusQ/rxvalidator.h"
|
||||||
#include "StatusQ/statussyntaxhighlighter.h"
|
#include "StatusQ/statussyntaxhighlighter.h"
|
||||||
#include "StatusQ/statuswindow.h"
|
#include "StatusQ/statuswindow.h"
|
||||||
|
#include "StatusQ/stringutilsinternal.h"
|
||||||
|
|
||||||
class StatusQPlugin : public QQmlExtensionPlugin {
|
class StatusQPlugin : public QQmlExtensionPlugin {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -26,6 +27,8 @@ public:
|
||||||
|
|
||||||
qmlRegisterSingletonType<ModelUtilsInternal>(
|
qmlRegisterSingletonType<ModelUtilsInternal>(
|
||||||
"StatusQ.Internal", 0, 1, "ModelUtils", &ModelUtilsInternal::qmlInstance);
|
"StatusQ.Internal", 0, 1, "ModelUtils", &ModelUtilsInternal::qmlInstance);
|
||||||
|
qmlRegisterSingletonType<StringUtilsInternal>(
|
||||||
|
"StatusQ.Internal", 0, 1, "StringUtils", &StringUtilsInternal::qmlInstance);
|
||||||
|
|
||||||
qmlRegisterSingletonType<PermissionUtilsInternal>("StatusQ.Internal", 0, 1, "PermissionUtils", [](QQmlEngine *, QJSEngine *) {
|
qmlRegisterSingletonType<PermissionUtilsInternal>("StatusQ.Internal", 0, 1, "PermissionUtils", [](QQmlEngine *, QJSEngine *) {
|
||||||
return new PermissionUtilsInternal;
|
return new PermissionUtilsInternal;
|
||||||
|
|
|
@ -207,6 +207,7 @@
|
||||||
<file>StatusQ/Core/Utils/ModelUtils.qml</file>
|
<file>StatusQ/Core/Utils/ModelUtils.qml</file>
|
||||||
<file>StatusQ/Core/Utils/ModelsComparator.qml</file>
|
<file>StatusQ/Core/Utils/ModelsComparator.qml</file>
|
||||||
<file>StatusQ/Core/Utils/ModelChangeTracker.qml</file>
|
<file>StatusQ/Core/Utils/ModelChangeTracker.qml</file>
|
||||||
|
<file>StatusQ/Core/Utils/StringUtils.qml</file>
|
||||||
<file>StatusQ/Components/StatusPageIndicator.qml</file>
|
<file>StatusQ/Components/StatusPageIndicator.qml</file>
|
||||||
<file>StatusQ/Components/StatusQrCodeScanner.qml</file>
|
<file>StatusQ/Components/StatusQrCodeScanner.qml</file>
|
||||||
<file>StatusQ/Components/StatusOnlineBadge.qml</file>
|
<file>StatusQ/Components/StatusOnlineBadge.qml</file>
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "StatusQ/stringutilsinternal.h"
|
||||||
|
|
||||||
|
StringUtilsInternal::StringUtilsInternal(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString StringUtilsInternal::escapeHtml(const QString &unsafe) const
|
||||||
|
{
|
||||||
|
return unsafe.toHtmlEscaped();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject* StringUtilsInternal::qmlInstance(QQmlEngine *engine,
|
||||||
|
QJSEngine *scriptEngine)
|
||||||
|
{
|
||||||
|
Q_UNUSED(engine);
|
||||||
|
Q_UNUSED(scriptEngine);
|
||||||
|
|
||||||
|
return new StringUtilsInternal;
|
||||||
|
}
|
Loading…
Reference in New Issue