mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-18 10:32:53 +00:00
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
|
||||
${STATUSQ_QRC_COMPILED}
|
||||
src/plugin.cpp
|
||||
include/StatusQ/QClipboardProxy.h
|
||||
include/StatusQ/modelutilsinternal.h
|
||||
include/StatusQ/permissionutilsinternal.h
|
||||
include/StatusQ/rxvalidator.h
|
||||
include/StatusQ/statussyntaxhighlighter.h
|
||||
include/StatusQ/statuswindow.h
|
||||
include/StatusQ/stringutilsinternal.h
|
||||
src/QClipboardProxy.cpp
|
||||
src/modelutilsinternal.cpp
|
||||
src/permissionutilsinternal.cpp
|
||||
src/plugin.cpp
|
||||
src/rxvalidator.cpp
|
||||
src/statussyntaxhighlighter.cpp
|
||||
src/statuswindow.cpp
|
||||
src/stringutilsinternal.cpp
|
||||
)
|
||||
|
||||
set_target_properties(StatusQ PROPERTIES
|
||||
|
19
ui/StatusQ/include/StatusQ/stringutilsinternal.h
Normal file
19
ui/StatusQ/include/StatusQ/stringutilsinternal.h
Normal file
@ -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);
|
||||
};
|
11
ui/StatusQ/src/StatusQ/Core/Utils/StringUtils.qml
Normal file
11
ui/StatusQ/src/StatusQ/Core/Utils/StringUtils.qml
Normal file
@ -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 ModelUtils 0.1 ModelUtils.qml
|
||||
singleton OperatorsUtils 0.1 OperatorsUtils.qml
|
||||
singleton StringUtils 0.1 StringUtils.qml
|
||||
singleton Utils 0.1 Utils.qml
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "StatusQ/rxvalidator.h"
|
||||
#include "StatusQ/statussyntaxhighlighter.h"
|
||||
#include "StatusQ/statuswindow.h"
|
||||
#include "StatusQ/stringutilsinternal.h"
|
||||
|
||||
class StatusQPlugin : public QQmlExtensionPlugin {
|
||||
Q_OBJECT
|
||||
@ -26,6 +27,8 @@ public:
|
||||
|
||||
qmlRegisterSingletonType<ModelUtilsInternal>(
|
||||
"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 *) {
|
||||
return new PermissionUtilsInternal;
|
||||
|
@ -207,6 +207,7 @@
|
||||
<file>StatusQ/Core/Utils/ModelUtils.qml</file>
|
||||
<file>StatusQ/Core/Utils/ModelsComparator.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/StatusQrCodeScanner.qml</file>
|
||||
<file>StatusQ/Components/StatusOnlineBadge.qml</file>
|
||||
|
20
ui/StatusQ/src/stringutilsinternal.cpp
Normal file
20
ui/StatusQ/src/stringutilsinternal.cpp
Normal 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…
x
Reference in New Issue
Block a user