Compare commits
81
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
156c2dfcdc | ||
|
|
09b6df8bc3 | ||
|
|
a62b729577 | ||
|
|
4bc64639e4 | ||
|
|
0f99d2c859 | ||
|
|
c12287471c | ||
|
|
7c1c22637e | ||
|
|
5183c9419c | ||
|
|
7fc6f66649 | ||
|
|
2b1c3dc241 | ||
|
|
42f9fbeebe | ||
|
|
c30bf7ac6b | ||
|
|
e4de02f27c | ||
|
|
5538ff7c6e | ||
|
|
751c990440 | ||
|
|
358aa5b47f | ||
|
|
5aefc953f8 | ||
|
|
b24051cd0d | ||
|
|
bed6f077e6 | ||
|
|
40b5a09489 | ||
|
|
e97806442f | ||
|
|
37dffeab46 | ||
|
|
e563800a85 | ||
|
|
2db87c4433 | ||
|
|
8716c392c6 | ||
|
|
b12ccbc9a3 | ||
|
|
b521638c03 | ||
|
|
9ac37ce6a7 | ||
|
|
fbcecd12df | ||
|
|
bbff0833ca | ||
|
|
d2139cd7e3 | ||
|
|
cfad8e695e | ||
|
|
65b997f993 | ||
|
|
16cf571caf | ||
|
|
8d511d935c | ||
|
|
68381278dd | ||
|
|
0c1f111d11 | ||
|
|
7a1c9d1c5f | ||
|
|
1123494db0 | ||
|
|
ac967a77d9 | ||
|
|
35c6f2d295 | ||
|
|
0f27a5bc14 | ||
|
|
456f37548e | ||
|
|
e40c9a2d40 | ||
|
|
1a4d372d6c | ||
|
|
c9d6dac20f | ||
|
|
597b4bb42d | ||
|
|
d3110cde5d | ||
|
|
87235db012 | ||
|
|
062bf8f96e | ||
|
|
f6de7a758b | ||
|
|
fda39f40ce | ||
|
|
c03a802b7a | ||
|
|
f617169a6f | ||
|
|
3c1bc0f341 | ||
|
|
0476030db2 | ||
|
|
72980bfdb7 | ||
|
|
bf14574451 | ||
|
|
3d31171f7b | ||
|
|
750168e9ba | ||
|
|
815e16368e | ||
|
|
b7bdc6e06a | ||
|
|
09b5e99729 | ||
|
|
13f0c3ffbc | ||
|
|
bdb93798e5 | ||
|
|
5823cf5dd9 | ||
|
|
03e5fa7160 | ||
|
|
5d6ac867cb | ||
|
|
33d611cf6f | ||
|
|
64408b347d | ||
|
|
3950641c72 | ||
|
|
3347ae842f | ||
|
|
94c028d95e | ||
|
|
372f695eec | ||
|
|
6dd243afa5 | ||
|
|
ffcb124dc0 | ||
|
|
e564da50ed | ||
|
|
56b589ee4f | ||
|
|
d8a7a5ed27 | ||
|
|
bc26b291f2 | ||
|
|
eb1d949edc |
No files matched your search
-18
@@ -9,21 +9,3 @@ fix_qt6_gui_deps.py
|
|||||||
fix_rti_conditionals.py
|
fix_rti_conditionals.py
|
||||||
fix_target_checks.py
|
fix_target_checks.py
|
||||||
build
|
build
|
||||||
__pycache__/
|
|
||||||
add_logger_bootstrap_include.py
|
|
||||||
aqtinstall.log
|
|
||||||
ces_fix.py
|
|
||||||
ces_pass2.py
|
|
||||||
fix_additem_enum.py
|
|
||||||
fix_broken_includes.py
|
|
||||||
fix_enum_as_int.py
|
|
||||||
fix_enums.py
|
|
||||||
fix_logger_init.py
|
|
||||||
fix_logger_remnant.py
|
|
||||||
fix_members.py
|
|
||||||
fix_mlogger.py
|
|
||||||
fix_pdm_combo.py
|
|
||||||
fix_sco.py
|
|
||||||
restore_underlying.py
|
|
||||||
../../restore_ppm_dtc.py
|
|
||||||
*.py
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
# export MIGRATE_PIPELINE_ROOT="/home/torsten/sandbox/qt6-migration-pipeline"
|
# export MIGRATE_PIPELINE_ROOT="/home/torsten/sandbox/qt6-migration-pipeline"
|
||||||
export MIGRATE_PIPELINE_ROOT="/home/nkana/repo/qt6-migration-pipeline"
|
export MIGRATE_PIPELINE_ROOT="/home/torsten/sandbox/qt6-migration-pipeline"
|
||||||
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=16000
|
|
||||||
export LANG=C.UTF-8
|
export LANG=C.UTF-8
|
||||||
export LC_ALL=C.UTF-8
|
export LC_ALL=C.UTF-8
|
||||||
@@ -14,4 +14,5 @@ build/
|
|||||||
build2/
|
build2/
|
||||||
.envrc
|
.envrc
|
||||||
build4
|
build4
|
||||||
coverage-out/
|
build4_*
|
||||||
|
deb_build_tmp
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
# Prebuilt build image for the release validation-scope branch
|
# Prebuilt build image for the Release 2 branch
|
||||||
# (Ubuntu 26.04 + Qt6 + all dependencies for the legatus release build).
|
# (Ubuntu 26.04 + Qt6 + all dependencies for the legatus release build).
|
||||||
#
|
#
|
||||||
# Built by new_docker_build.sh --build-prebuilt-image, which passes the
|
# Build with (the APT package list mirrors the in-container install list of
|
||||||
# package list and Qt settings as build args (see build_prebuilt_image()).
|
# new_docker_build_release2.sh):
|
||||||
|
# docker build --build-arg APT_PACKAGES="<space-separated packages>" -t <image> .
|
||||||
|
|
||||||
FROM ubuntu:26.04
|
FROM ubuntu:26.04
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Wrapper-Objects for Grantlee engine
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Hanna E. Rathje, SLSE, 2015-08-04
|
||||||
|
*/
|
||||||
|
|
||||||
#include "GrantleeWrappers.h"
|
#include "GrantleeWrappers.h"
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -1,13 +1,11 @@
|
|||||||
|
// Stub GTest smoke test for coordTrans
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(CoordTransSmokeTest, StubTest)
|
TEST(CoordTransSmokeTest, StubTest) {
|
||||||
{
|
|
||||||
EXPECT_TRUE(true);
|
EXPECT_TRUE(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
|
// Stub QtTest smoke test for coordTrans
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
class CoordTransSmokeTest : public QObject
|
class CoordTransSmokeTest : public QObject
|
||||||
@@ -6,7 +6,9 @@ class CoordTransSmokeTest : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void stubTest() { QVERIFY(true); }
|
void stubTest() {
|
||||||
|
QVERIFY(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(CoordTransSmokeTest)
|
QTEST_APPLESS_MAIN(CoordTransSmokeTest)
|
||||||
+5
-5
@@ -1,3 +1,5 @@
|
|||||||
|
// MockCoordTrans.h - Stub mock for CoordTrans functionality
|
||||||
|
// This is a placeholder to allow builds without full CoordTrans implementation
|
||||||
|
|
||||||
#ifndef MOCK_COORD_TRANS_H
|
#ifndef MOCK_COORD_TRANS_H
|
||||||
#define MOCK_COORD_TRANS_H
|
#define MOCK_COORD_TRANS_H
|
||||||
@@ -6,12 +8,10 @@
|
|||||||
#include <QtCore/QPointF>
|
#include <QtCore/QPointF>
|
||||||
|
|
||||||
// Minimal stub to satisfy linker requirements
|
// Minimal stub to satisfy linker requirements
|
||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans {
|
||||||
{
|
|
||||||
// Placeholder types
|
// Placeholder types
|
||||||
struct UtmCoordinate
|
struct UtmCoordinate {
|
||||||
{
|
static UtmCoordinate fromMgrs(const QString&) { return UtmCoordinate(); }
|
||||||
static UtmCoordinate fromMgrs(const QString &) { return UtmCoordinate(); }
|
|
||||||
QPointF geographic() const { return QPointF(); }
|
QPointF geographic() const { return QPointF(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
@@ -28,7 +28,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!f.open(QFile::ReadOnly))
|
if (!f.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
printf("LtsAppDescriptorChecker: cannot open apps.json at %s: %s\n", appsJsonFilePath.toStdString().c_str(), f.errorString().toStdString().c_str());
|
printf("LtsAppDescriptorChecker: cannot open apps.json at %s: %s\n", appsJsonFilePath.toStdString().c_str(),
|
||||||
|
f.errorString().toStdString().c_str());
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +38,12 @@ int main(int argc, char *argv[])
|
|||||||
QStringList lastErrors;
|
QStringList lastErrors;
|
||||||
QStringList dummy1;
|
QStringList dummy1;
|
||||||
QString dummy2;
|
QString dummy2;
|
||||||
LtsAppDescriptor::AppDescriptionVector adv = LtsAppDescriptor::LtsAppDescriptor::getAppDescriptionVector(f.readAll(), lastErrors, dummy1, dummy2);
|
LtsAppDescriptor::AppDescriptionVector adv =
|
||||||
|
LtsAppDescriptor::LtsAppDescriptor::getAppDescriptionVector(f.readAll(), lastErrors, dummy1, dummy2);
|
||||||
|
|
||||||
if (!lastErrors.isEmpty())
|
if (!lastErrors.isEmpty())
|
||||||
{
|
{
|
||||||
printf("LtsAppDescriptorChecker: apps.json at %s invalid:\n%s\n",
|
printf("LtsAppDescriptorChecker: apps.json at %s invalid:\n%s\n", appsJsonFilePath.toStdString().c_str(),
|
||||||
appsJsonFilePath.toStdString().c_str(),
|
|
||||||
lastErrors.join(QStringLiteral("\r\n\r\n")).toStdString().c_str());
|
lastErrors.join(QStringLiteral("\r\n\r\n")).toStdString().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -64,13 +65,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QStringList filenames;
|
QStringList filenames;
|
||||||
filenames.reserve(guiPluginFiles.size());
|
filenames.reserve(guiPluginFiles.size());
|
||||||
for (const QFileInfo &fi : std::as_const(guiPluginFiles))
|
for (const QFileInfo& fi : std::as_const(guiPluginFiles))
|
||||||
{
|
{
|
||||||
filenames += fi.absoluteFilePath();
|
filenames += fi.absoluteFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList guiPluginIIDs;
|
QStringList guiPluginIIDs;
|
||||||
for (const QFileInfo &fi : std::as_const(guiPluginFiles))
|
for (const QFileInfo& fi : std::as_const(guiPluginFiles))
|
||||||
{
|
{
|
||||||
QFile f2(fi.absoluteFilePath());
|
QFile f2(fi.absoluteFilePath());
|
||||||
|
|
||||||
@@ -100,13 +101,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
for (const LtsAppDescriptor::AppDescription &appdesc : std::as_const(adv))
|
for (const LtsAppDescriptor::AppDescription& appdesc : std::as_const(adv))
|
||||||
{
|
{
|
||||||
for (const LtsAppDescriptor::PluginInfo &pi : std::as_const(appdesc.pluginInfos))
|
for (const LtsAppDescriptor::PluginInfo& pi : std::as_const(appdesc.pluginInfos))
|
||||||
{
|
{
|
||||||
if (!guiPluginIIDs.contains(pi.iid))
|
if (!guiPluginIIDs.contains(pi.iid))
|
||||||
{
|
{
|
||||||
printf("LtsAppDescriptorChecker: apps.json at '%s' uses unknown IID '%s'\n", appsJsonFilePath.toStdString().c_str(), pi.iid.toStdString().c_str());
|
printf("LtsAppDescriptorChecker: apps.json at '%s' uses unknown IID '%s'\n",
|
||||||
|
appsJsonFilePath.toStdString().c_str(), pi.iid.toStdString().c_str());
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* App Descriptor - Class to modify App Descriptor JSON Documents
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Mike Wille, SLSE, 2016-10-24
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_app_descriptor.h"
|
#include "lts_app_descriptor.h"
|
||||||
|
|
||||||
@@ -11,14 +19,14 @@
|
|||||||
|
|
||||||
namespace LtsAppDescriptor
|
namespace LtsAppDescriptor
|
||||||
{
|
{
|
||||||
static void addOptionToPlugin(PluginInfo &pluginInfo, const PluginInfo::Flag &flag)
|
static void addOptionToPlugin(PluginInfo& pluginInfo, const PluginInfo::Flag& flag)
|
||||||
{
|
{
|
||||||
pluginInfo.flags |= flag;
|
pluginInfo.flags |= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addOptionToPlugin(QVector<PluginInfo> &pluginInfos, const PluginInfo::Flag &flag, const QString &pluginName)
|
static void addOptionToPlugin(QVector<PluginInfo>& pluginInfos, const PluginInfo::Flag& flag, const QString& pluginName)
|
||||||
{
|
{
|
||||||
for (PluginInfo &pi : pluginInfos)
|
for (PluginInfo& pi : pluginInfos)
|
||||||
{
|
{
|
||||||
if (pi.iid == pluginName)
|
if (pi.iid == pluginName)
|
||||||
{
|
{
|
||||||
@@ -32,23 +40,19 @@ namespace LtsAppDescriptor
|
|||||||
pi.type = PluginInfo::PluginType::GUI;
|
pi.type = PluginInfo::PluginType::GUI;
|
||||||
addOptionToPlugin(pi, flag);
|
addOptionToPlugin(pi, flag);
|
||||||
pluginInfos.append(pi);
|
pluginInfos.append(pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool addOptionsToPlugin(AppDescription &appDesc,
|
static bool addOptionsToPlugin(AppDescription& appDesc, const QString& optionIdentifier,
|
||||||
const QString &optionIdentifier,
|
const QStringList& ignoredPlugins, const QJsonObject& optionsObject,
|
||||||
const QStringList &ignoredPlugins,
|
const PluginInfo::Flag flag, QStringList& lastErrors, bool atLeastOnePluginNeeded)
|
||||||
const QJsonObject &optionsObject,
|
{
|
||||||
const PluginInfo::Flag flag,
|
|
||||||
QStringList &lastErrors,
|
|
||||||
bool atLeastOnePluginNeeded)
|
|
||||||
{
|
|
||||||
bool hasPlugins = false;
|
bool hasPlugins = false;
|
||||||
auto optionsObjectIt = optionsObject.constFind(optionIdentifier);
|
auto optionsObjectIt = optionsObject.constFind(optionIdentifier);
|
||||||
if (optionsObjectIt != optionsObject.constEnd())
|
if (optionsObjectIt != optionsObject.constEnd())
|
||||||
{
|
{
|
||||||
const QJsonArray plugins((*optionsObjectIt).toObject()[QStringLiteral("Plugins")].toArray());
|
const QJsonArray plugins((*optionsObjectIt).toObject()[QStringLiteral("Plugins")].toArray());
|
||||||
|
|
||||||
for (const auto &pluginElem : plugins)
|
for (const auto& pluginElem : plugins)
|
||||||
{
|
{
|
||||||
const QString pluginName = pluginElem.toString();
|
const QString pluginName = pluginElem.toString();
|
||||||
if (!ignoredPlugins.contains(pluginName))
|
if (!ignoredPlugins.contains(pluginName))
|
||||||
@@ -61,15 +65,16 @@ namespace LtsAppDescriptor
|
|||||||
|
|
||||||
if (atLeastOnePluginNeeded && !hasPlugins)
|
if (atLeastOnePluginNeeded && !hasPlugins)
|
||||||
{
|
{
|
||||||
lastErrors.append(QCoreApplication::tr("No plugins specified for '%1' option for app '%2'").arg(optionIdentifier, appDesc.appName));
|
lastErrors.append(QCoreApplication::tr("No plugins specified for '%1' option for app '%2'")
|
||||||
|
.arg(optionIdentifier, appDesc.appName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
App LtsAppDescriptor::appFromInteger(int i)
|
App LtsAppDescriptor::appFromInteger(int i)
|
||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case int(App::Login):
|
case int(App::Login):
|
||||||
@@ -97,13 +102,12 @@ namespace LtsAppDescriptor
|
|||||||
}
|
}
|
||||||
Q_ASSERT_X(false, "LtsAppDescriptor::appFromInteger", qPrintable(QStringLiteral("Unknown app id: %1").arg(i)));
|
Q_ASSERT_X(false, "LtsAppDescriptor::appFromInteger", qPrintable(QStringLiteral("Unknown app id: %1").arg(i)));
|
||||||
return App::Login;
|
return App::Login;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray &jsonDocument,
|
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray& jsonDocument, QStringList& lastErrors,
|
||||||
QStringList &lastErrors,
|
const QStringList& ignoredPlugins,
|
||||||
const QStringList &ignoredPlugins,
|
QString& loginPluginIid)
|
||||||
QString &loginPluginIid)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
AppDescriptionVector appDescriptions;
|
AppDescriptionVector appDescriptions;
|
||||||
|
|
||||||
@@ -133,7 +137,10 @@ namespace LtsAppDescriptor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastErrors.append(QCoreApplication::tr("JSON: %1<br>Row: %2, Column: %3").arg(parseError.errorString()).arg(row + 1).arg(column + 1));
|
lastErrors.append(QCoreApplication::tr("JSON: %1<br>Row: %2, Column: %3")
|
||||||
|
.arg(parseError.errorString())
|
||||||
|
.arg(row + 1)
|
||||||
|
.arg(column + 1));
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +155,7 @@ namespace LtsAppDescriptor
|
|||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &appElem : appArray)
|
for (const auto& appElem : appArray)
|
||||||
{
|
{
|
||||||
AppDescription appDesc;
|
AppDescription appDesc;
|
||||||
const QJsonObject appObject = appElem.toObject();
|
const QJsonObject appObject = appElem.toObject();
|
||||||
@@ -167,7 +174,9 @@ namespace LtsAppDescriptor
|
|||||||
{
|
{
|
||||||
if (valueActive.type() != QJsonValue::Type::Bool)
|
if (valueActive.type() != QJsonValue::Type::Bool)
|
||||||
{
|
{
|
||||||
lastErrors.append(QCoreApplication::tr("App '%1': value App.Active is not a bool (%2)").arg(appDesc.appName).arg((int)valueActive.type()));
|
lastErrors.append(QCoreApplication::tr("App '%1': value App.Active is not a bool (%2)")
|
||||||
|
.arg(appDesc.appName)
|
||||||
|
.arg((int)valueActive.type()));
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,25 +185,30 @@ namespace LtsAppDescriptor
|
|||||||
const QJsonValue valueVisible = appObject.value(QStringLiteral("Visible"));
|
const QJsonValue valueVisible = appObject.value(QStringLiteral("Visible"));
|
||||||
if (!valueVisible.isUndefined() && valueVisible.type() != QJsonValue::Type::Bool)
|
if (!valueVisible.isUndefined() && valueVisible.type() != QJsonValue::Type::Bool)
|
||||||
{
|
{
|
||||||
lastErrors.append(QCoreApplication::tr("App '%1': value App.Visible is not a bool (%2)").arg(appDesc.appName).arg((int)valueVisible.type()));
|
lastErrors.append(QCoreApplication::tr("App '%1': value App.Visible is not a bool (%2)")
|
||||||
|
.arg(appDesc.appName)
|
||||||
|
.arg((int)valueVisible.type()));
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
appDesc.visible = valueVisible.toBool(true);
|
appDesc.visible = valueVisible.toBool(true);
|
||||||
|
|
||||||
const QJsonArray array(appObject.value(QStringLiteral("ACLs")).toArray());
|
const QJsonArray array(appObject.value(QStringLiteral("ACLs")).toArray());
|
||||||
for (const QJsonValue &value : array)
|
for (const QJsonValue& value : array)
|
||||||
appDesc.requiredAcls.append(value.toInt());
|
appDesc.requiredAcls.append(value.toInt());
|
||||||
|
|
||||||
const QJsonObject optionsObject(appObject.value(QStringLiteral("Options")).toObject());
|
const QJsonObject optionsObject(appObject.value(QStringLiteral("Options")).toObject());
|
||||||
|
|
||||||
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject, PluginInfo::Flag::PAYLOAD, lastErrors, false);
|
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject,
|
||||||
addOptionsToPlugin(appDesc, QStringLiteral("Actions"), ignoredPlugins, optionsObject, PluginInfo::Flag::ACTIONS, lastErrors, true);
|
PluginInfo::Flag::PAYLOAD, lastErrors, false);
|
||||||
addOptionsToPlugin(appDesc, QStringLiteral("Main"), ignoredPlugins, optionsObject, PluginInfo::Flag::MAIN, lastErrors, false);
|
addOptionsToPlugin(appDesc, QStringLiteral("Actions"), ignoredPlugins, optionsObject, PluginInfo::Flag::ACTIONS,
|
||||||
|
lastErrors, true);
|
||||||
|
addOptionsToPlugin(appDesc, QStringLiteral("Main"), ignoredPlugins, optionsObject, PluginInfo::Flag::MAIN,
|
||||||
|
lastErrors, false);
|
||||||
|
|
||||||
appDescriptions.append(appDesc);
|
appDescriptions.append(appDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsAppDescriptor
|
} // namespace LtsAppDescriptor
|
||||||
@@ -14,23 +14,23 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#ifndef LTSAPPDESCRIPTOR_EXPORT
|
#ifndef LTSAPPDESCRIPTOR_EXPORT
|
||||||
#ifdef BUILD_STATIC_LIBRARIES
|
# ifdef BUILD_STATIC_LIBRARIES
|
||||||
#define LTSAPPDESCRIPTOR_EXPORT
|
# define LTSAPPDESCRIPTOR_EXPORT
|
||||||
#else
|
# else
|
||||||
#if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
|
# if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
|
||||||
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
|
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
# else
|
||||||
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
|
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
|
||||||
#endif
|
# endif
|
||||||
#endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppDescriptor
|
namespace LtsAppDescriptor
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class App
|
enum class App
|
||||||
{
|
{
|
||||||
Login = -1,
|
Login = -1,
|
||||||
Situation = 0,
|
Situation = 0,
|
||||||
ResourceManager = 1,
|
ResourceManager = 1,
|
||||||
@@ -52,10 +52,10 @@ namespace LtsAppDescriptor
|
|||||||
SilhouetteEditor = 18, // for L400P2
|
SilhouetteEditor = 18, // for L400P2
|
||||||
Shootback = 19, // for L400P2
|
Shootback = 19, // for L400P2
|
||||||
SAAs = 20, //Schnittstelle Adapter Adler
|
SAAs = 20, //Schnittstelle Adapter Adler
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PluginInfo
|
struct PluginInfo
|
||||||
{
|
{
|
||||||
enum class PluginType
|
enum class PluginType
|
||||||
{
|
{
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
@@ -77,10 +77,10 @@ namespace LtsAppDescriptor
|
|||||||
QString iid;
|
QString iid;
|
||||||
QFlags<Flag> flags;
|
QFlags<Flag> flags;
|
||||||
QStringList options;
|
QStringList options;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AppDescription
|
struct AppDescription
|
||||||
{
|
{
|
||||||
App id = App::Login;
|
App id = App::Login;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
@@ -89,18 +89,16 @@ namespace LtsAppDescriptor
|
|||||||
QVector<PluginInfo> pluginInfos;
|
QVector<PluginInfo> pluginInfos;
|
||||||
|
|
||||||
bool isValid() const { return !appName.isEmpty(); }
|
bool isValid() const { return !appName.isEmpty(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QVector<AppDescription> AppDescriptionVector;
|
typedef QVector<AppDescription> AppDescriptionVector;
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppDescriptor // TODO: make qobject class singleton - for tr
|
namespace LtsAppDescriptor // TODO: make qobject class singleton - for tr
|
||||||
{
|
{
|
||||||
LTSAPPDESCRIPTOR_EXPORT App appFromInteger(int i);
|
LTSAPPDESCRIPTOR_EXPORT App appFromInteger(int i);
|
||||||
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray &jsonDocument,
|
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray &jsonDocument, QStringList &lastErrors,
|
||||||
QStringList &lastErrors,
|
const QStringList &ignoredPlugins, QString &loginPluginIid);
|
||||||
const QStringList &ignoredPlugins,
|
}
|
||||||
QString &loginPluginIid);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace LtsAppDescriptor
|
} // namespace LtsAppDescriptor
|
||||||
+45
-41
@@ -13,9 +13,7 @@
|
|||||||
#include <QtWidgets/QLineEdit>
|
#include <QtWidgets/QLineEdit>
|
||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
|
|
||||||
LtsAppDescriptorEditor::LtsAppDescriptorEditor(QWidget *parent)
|
LtsAppDescriptorEditor::LtsAppDescriptorEditor(QWidget* parent) : QWidget(parent), m_ui(new Ui_LtsAppDescriptionEditor)
|
||||||
: QWidget(parent)
|
|
||||||
, m_ui(new Ui_LtsAppDescriptionEditor)
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
m_vector = LtsAppDescriptor::AppDescriptionVector();
|
m_vector = LtsAppDescriptor::AppDescriptionVector();
|
||||||
@@ -55,8 +53,9 @@ LtsAppDescriptorEditor::~LtsAppDescriptorEditor()
|
|||||||
|
|
||||||
void LtsAppDescriptorEditor::getAppDescriptionVector()
|
void LtsAppDescriptorEditor::getAppDescriptionVector()
|
||||||
{
|
{
|
||||||
m_fileName =
|
m_fileName = QFileDialog::getOpenFileName(
|
||||||
QFileDialog::getOpenFileName(this, tr("Open JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"), tr("JSON File (*.json)"));
|
this, tr("Open JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"),
|
||||||
|
tr("JSON File (*.json)"));
|
||||||
if (m_fileName.isEmpty())
|
if (m_fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -72,7 +71,7 @@ void LtsAppDescriptorEditor::getAppDescriptionVector()
|
|||||||
updateAppModel();
|
updateAppModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
m_ui->gbPlugins->setEnabled(true);
|
m_ui->gbPlugins->setEnabled(true);
|
||||||
m_ui->pbDeleteApp->setEnabled(true);
|
m_ui->pbDeleteApp->setEnabled(true);
|
||||||
@@ -81,7 +80,7 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
|||||||
m_appIndex = index;
|
m_appIndex = index;
|
||||||
|
|
||||||
QStringList pluginList;
|
QStringList pluginList;
|
||||||
Q_FOREACH (const LtsAppDescriptor::PluginInfo &reqPlugin, m_vector.at(m_appIndex.row()).requiredPlugins)
|
Q_FOREACH (const LtsAppDescriptor::PluginInfo& reqPlugin, m_vector.at(m_appIndex.row()).requiredPlugins)
|
||||||
{
|
{
|
||||||
LtsAppDescriptor::PluginInfo::PluginType pluginType = reqPlugin.type;
|
LtsAppDescriptor::PluginInfo::PluginType pluginType = reqPlugin.type;
|
||||||
QString type;
|
QString type;
|
||||||
@@ -112,7 +111,8 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
|||||||
if (optionalFlag)
|
if (optionalFlag)
|
||||||
strFlags.append(QLatin1String("optional "));
|
strFlags.append(QLatin1String("optional "));
|
||||||
|
|
||||||
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid + QLatin1String(" [ ") + strFlags + QLatin1String("]"));
|
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid + QLatin1String(" [ ") + strFlags +
|
||||||
|
QLatin1String("]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updatePluginModel(pluginList);
|
updatePluginModel(pluginList);
|
||||||
@@ -121,7 +121,7 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
|||||||
m_ui->leAppName->setText(m_vector.at(m_appIndex.row()).appName);
|
m_ui->leAppName->setText(m_vector.at(m_appIndex.row()).appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex &index)
|
void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
m_pluginIndex = index;
|
m_pluginIndex = index;
|
||||||
m_ui->pbDeletePlugin->setEnabled(true);
|
m_ui->pbDeletePlugin->setEnabled(true);
|
||||||
@@ -189,7 +189,8 @@ void LtsAppDescriptorEditor::pluginTypeChanged()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Information, tr("Error"), tr("Plugin Type must either be \"gui\" or \"data\"."));
|
QMessageBox msgBox(QMessageBox::Information, tr("Error"),
|
||||||
|
tr("Plugin Type must either be \"gui\" or \"data\"."));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
m_ui->lePluginType->setText(QString());
|
m_ui->lePluginType->setText(QString());
|
||||||
}
|
}
|
||||||
@@ -207,14 +208,15 @@ void LtsAppDescriptorEditor::onAppAddClicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList appList;
|
QStringList appList;
|
||||||
Q_FOREACH (const LtsAppDescriptor::AppDescription &appDesc, m_vector)
|
Q_FOREACH (const LtsAppDescriptor::AppDescription& appDesc, m_vector)
|
||||||
{
|
{
|
||||||
appList << appDesc.appName;
|
appList << appDesc.appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appList.contains(m_ui->leAppName->text(), Qt::CaseInsensitive))
|
if (appList.contains(m_ui->leAppName->text(), Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("There already exists an app named \"%1\".").arg(m_ui->leAppName->text()));
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
|
||||||
|
tr("There already exists an app named \"%1\".").arg(m_ui->leAppName->text()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -245,14 +247,15 @@ void LtsAppDescriptorEditor::onPluginAddClicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList pluginList;
|
QStringList pluginList;
|
||||||
Q_FOREACH (const LtsAppDescriptor::PluginInfo &pluginDesc, m_vector.at(m_appIndex.row()).requiredPlugins)
|
Q_FOREACH (const LtsAppDescriptor::PluginInfo& pluginDesc, m_vector.at(m_appIndex.row()).requiredPlugins)
|
||||||
{
|
{
|
||||||
pluginList << pluginDesc.iid;
|
pluginList << pluginDesc.iid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginList.contains(m_ui->lePluginName->text(), Qt::CaseInsensitive))
|
if (pluginList.contains(m_ui->lePluginName->text(), Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("There already exists an plugin named \"%1\".").arg(m_ui->lePluginName->text()));
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
|
||||||
|
tr("There already exists an plugin named \"%1\".").arg(m_ui->lePluginName->text()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -290,10 +293,8 @@ void LtsAppDescriptorEditor::onAppDeleteClicked()
|
|||||||
|
|
||||||
QMessageBox msgBox(tr("Warning"),
|
QMessageBox msgBox(tr("Warning"),
|
||||||
tr("The App \n\"%1\" \nwill be removed. Continue?").arg(m_appIndex.data().toString()),
|
tr("The App \n\"%1\" \nwill be removed. Continue?").arg(m_appIndex.data().toString()),
|
||||||
QMessageBox::Warning,
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||||
QMessageBox::Yes | QMessageBox::Default,
|
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||||
QMessageBox::No | QMessageBox::Escape,
|
|
||||||
QMessageBox::NoButton);
|
|
||||||
|
|
||||||
if (msgBox.exec() == QMessageBox::No)
|
if (msgBox.exec() == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
@@ -312,10 +313,8 @@ void LtsAppDescriptorEditor::onPluginDeletedClicked()
|
|||||||
|
|
||||||
QMessageBox msgBox(tr("Warning"),
|
QMessageBox msgBox(tr("Warning"),
|
||||||
tr("The Plugin \n\"%1\" \nwill be removed. Continue?").arg(m_pluginIndex.data().toString()),
|
tr("The Plugin \n\"%1\" \nwill be removed. Continue?").arg(m_pluginIndex.data().toString()),
|
||||||
QMessageBox::Warning,
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||||
QMessageBox::Yes | QMessageBox::Default,
|
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||||
QMessageBox::No | QMessageBox::Escape,
|
|
||||||
QMessageBox::NoButton);
|
|
||||||
|
|
||||||
if (msgBox.exec() == QMessageBox::No)
|
if (msgBox.exec() == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
@@ -355,20 +354,27 @@ void LtsAppDescriptorEditor::onUpdateClicked()
|
|||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].iid = m_ui->lePluginName->text();
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].iid = m_ui->lePluginName->text();
|
||||||
|
|
||||||
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||||
|
LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
||||||
else if (m_ui->lePluginType->text() == QLatin1String("data"))
|
else if (m_ui->lePluginType->text() == QLatin1String("data"))
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||||
|
LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||||
else
|
else
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||||
|
LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
||||||
|
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags = QFlags<LtsAppDescriptor::PluginInfo::Flag>();
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags =
|
||||||
|
QFlags<LtsAppDescriptor::PluginInfo::Flag>();
|
||||||
|
|
||||||
if (m_ui->chbActions->isChecked())
|
if (m_ui->chbActions->isChecked())
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||||
|
LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
||||||
if (m_ui->chbMain->isChecked())
|
if (m_ui->chbMain->isChecked())
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||||
|
LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
||||||
if (m_ui->chbPayload->isChecked())
|
if (m_ui->chbPayload->isChecked())
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||||
|
LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
||||||
|
|
||||||
onAppsClicked(m_appIndex);
|
onAppsClicked(m_appIndex);
|
||||||
onNewpluginClicked();
|
onNewpluginClicked();
|
||||||
@@ -421,24 +427,24 @@ void LtsAppDescriptorEditor::updateAppModel()
|
|||||||
{
|
{
|
||||||
onNewAppClicked();
|
onNewAppClicked();
|
||||||
QStringList appList;
|
QStringList appList;
|
||||||
Q_FOREACH (const LtsAppDescriptor::AppDescription &appDesc, m_vector)
|
Q_FOREACH (const LtsAppDescriptor::AppDescription& appDesc, m_vector)
|
||||||
{
|
{
|
||||||
appList << appDesc.appName;
|
appList << appDesc.appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_ui->lvApps->model())
|
if (!m_ui->lvApps->model())
|
||||||
m_ui->lvApps->setModel(new QStringListModel(this));
|
m_ui->lvApps->setModel(new QStringListModel(this));
|
||||||
QStringListModel *m = qobject_cast<QStringListModel *>(m_ui->lvApps->model());
|
QStringListModel* m = qobject_cast<QStringListModel*>(m_ui->lvApps->model());
|
||||||
if (!m)
|
if (!m)
|
||||||
return;
|
return;
|
||||||
m->setStringList(appList);
|
m->setStringList(appList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::updatePluginModel(const QStringList &list)
|
void LtsAppDescriptorEditor::updatePluginModel(const QStringList& list)
|
||||||
{
|
{
|
||||||
if (!m_ui->lvPlugins->model())
|
if (!m_ui->lvPlugins->model())
|
||||||
m_ui->lvPlugins->setModel(new QStringListModel(this));
|
m_ui->lvPlugins->setModel(new QStringListModel(this));
|
||||||
QStringListModel *m = qobject_cast<QStringListModel *>(m_ui->lvPlugins->model());
|
QStringListModel* m = qobject_cast<QStringListModel*>(m_ui->lvPlugins->model());
|
||||||
if (!m)
|
if (!m)
|
||||||
return;
|
return;
|
||||||
m->setStringList(list);
|
m->setStringList(list);
|
||||||
@@ -448,12 +454,9 @@ void LtsAppDescriptorEditor::checkSave()
|
|||||||
{
|
{
|
||||||
if (m_changed)
|
if (m_changed)
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(tr("Warning"),
|
QMessageBox msgBox(tr("Warning"), tr("The Data has been modified.\nDo you want to save your changes?"),
|
||||||
tr("The Data has been modified.\nDo you want to save your changes?"),
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||||
QMessageBox::Warning,
|
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||||
QMessageBox::Yes | QMessageBox::Default,
|
|
||||||
QMessageBox::No | QMessageBox::Escape,
|
|
||||||
QMessageBox::NoButton);
|
|
||||||
|
|
||||||
if (msgBox.exec() == QMessageBox::Yes)
|
if (msgBox.exec() == QMessageBox::Yes)
|
||||||
onSaveAsClicked();
|
onSaveAsClicked();
|
||||||
@@ -462,8 +465,9 @@ void LtsAppDescriptorEditor::checkSave()
|
|||||||
|
|
||||||
void LtsAppDescriptorEditor::onSaveAsClicked()
|
void LtsAppDescriptorEditor::onSaveAsClicked()
|
||||||
{
|
{
|
||||||
QString fileName =
|
QString fileName = QFileDialog::getSaveFileName(
|
||||||
QFileDialog::getSaveFileName(this, tr("Save JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"), tr("JSON File (*.json)"));
|
this, tr("Save JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"),
|
||||||
|
tr("JSON File (*.json)"));
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -23,12 +23,12 @@ class LTSAPPDESCRIPTOREDITOR_EXPORT LtsAppDescriptorEditor : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LtsAppDescriptorEditor(QWidget *parent = 0);
|
explicit LtsAppDescriptorEditor(QWidget* parent = 0);
|
||||||
~LtsAppDescriptorEditor();
|
~LtsAppDescriptorEditor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_LtsAppDescriptionEditor *m_ui;
|
Ui_LtsAppDescriptionEditor* m_ui;
|
||||||
LtsAppDescriptor::AppDescriptionVector m_vector;
|
LtsAppDescriptor::AppDescriptionVector m_vector;
|
||||||
QModelIndex m_appIndex;
|
QModelIndex m_appIndex;
|
||||||
QModelIndex m_pluginIndex;
|
QModelIndex m_pluginIndex;
|
||||||
@@ -40,12 +40,12 @@ private:
|
|||||||
void getAppDescriptionVector();
|
void getAppDescriptionVector();
|
||||||
void setupMainWindow();
|
void setupMainWindow();
|
||||||
void updateAppModel();
|
void updateAppModel();
|
||||||
void updatePluginModel(const QStringList &list);
|
void updatePluginModel(const QStringList& list);
|
||||||
void checkSave();
|
void checkSave();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAppsClicked(const QModelIndex &index);
|
void onAppsClicked(const QModelIndex& index);
|
||||||
void onPluginsClicked(const QModelIndex &index);
|
void onPluginsClicked(const QModelIndex& index);
|
||||||
void pluginTypeChanged();
|
void pluginTypeChanged();
|
||||||
void onAppAddClicked();
|
void onAppAddClicked();
|
||||||
void onPluginAddClicked();
|
void onPluginAddClicked();
|
||||||
@@ -56,7 +56,7 @@ private slots:
|
|||||||
void onNewAppClicked();
|
void onNewAppClicked();
|
||||||
void enableNewPlugin();
|
void enableNewPlugin();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onSaveClicked();
|
void onSaveClicked();
|
||||||
void onSaveAsClicked();
|
void onSaveAsClicked();
|
||||||
void onOpenClicked();
|
void onOpenClicked();
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* App Descriptor Editor
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Mike Wille, SLSE, 2016-10-24
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_app_descriptor_editor.h"
|
#include "lts_app_descriptor_editor.h"
|
||||||
|
|
||||||
@@ -7,39 +15,39 @@
|
|||||||
#include <QtWidgets/QMainWindow>
|
#include <QtWidgets/QMainWindow>
|
||||||
#include <QtWidgets/QMenuBar>
|
#include <QtWidgets/QMenuBar>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
QMainWindow *mainWindow = new QMainWindow();
|
QMainWindow* mainWindow = new QMainWindow();
|
||||||
QMenu *fileMenu = mainWindow->menuBar()->addMenu(QObject::tr("&File"));
|
QMenu* fileMenu = mainWindow->menuBar()->addMenu(QObject::tr("&File"));
|
||||||
|
|
||||||
QAction *openAct = new QAction(QObject::tr("&Open"), mainWindow);
|
QAction* openAct = new QAction(QObject::tr("&Open"), mainWindow);
|
||||||
openAct->setShortcuts(QKeySequence::Open);
|
openAct->setShortcuts(QKeySequence::Open);
|
||||||
openAct->setStatusTip(QObject::tr("Open an existing file"));
|
openAct->setStatusTip(QObject::tr("Open an existing file"));
|
||||||
fileMenu->addAction(openAct);
|
fileMenu->addAction(openAct);
|
||||||
|
|
||||||
QAction *newAct = new QAction(QObject::tr("&New"), mainWindow);
|
QAction* newAct = new QAction(QObject::tr("&New"), mainWindow);
|
||||||
newAct->setShortcuts(QKeySequence::New);
|
newAct->setShortcuts(QKeySequence::New);
|
||||||
newAct->setStatusTip(QObject::tr("Create a new App"));
|
newAct->setStatusTip(QObject::tr("Create a new App"));
|
||||||
fileMenu->addAction(newAct);
|
fileMenu->addAction(newAct);
|
||||||
|
|
||||||
QAction *saveAct = new QAction(QObject::tr("&Save"), mainWindow);
|
QAction* saveAct = new QAction(QObject::tr("&Save"), mainWindow);
|
||||||
saveAct->setShortcuts(QKeySequence::Save);
|
saveAct->setShortcuts(QKeySequence::Save);
|
||||||
saveAct->setStatusTip(QObject::tr("Save modified file"));
|
saveAct->setStatusTip(QObject::tr("Save modified file"));
|
||||||
fileMenu->addAction(saveAct);
|
fileMenu->addAction(saveAct);
|
||||||
|
|
||||||
QAction *saveAsAct = new QAction(QObject::tr("&SaveAs"), mainWindow);
|
QAction* saveAsAct = new QAction(QObject::tr("&SaveAs"), mainWindow);
|
||||||
saveAsAct->setShortcuts(QKeySequence::SaveAs);
|
saveAsAct->setShortcuts(QKeySequence::SaveAs);
|
||||||
saveAsAct->setStatusTip(QObject::tr("Save modified file as"));
|
saveAsAct->setStatusTip(QObject::tr("Save modified file as"));
|
||||||
fileMenu->addAction(saveAsAct);
|
fileMenu->addAction(saveAsAct);
|
||||||
|
|
||||||
QAction *quitAct = new QAction(QObject::tr("&Quit"), mainWindow);
|
QAction* quitAct = new QAction(QObject::tr("&Quit"), mainWindow);
|
||||||
quitAct->setShortcuts(QKeySequence::Quit);
|
quitAct->setShortcuts(QKeySequence::Quit);
|
||||||
quitAct->setStatusTip(QObject::tr("Quit the Application"));
|
quitAct->setStatusTip(QObject::tr("Quit the Application"));
|
||||||
fileMenu->addAction(quitAct);
|
fileMenu->addAction(quitAct);
|
||||||
|
|
||||||
LtsAppDescriptorEditor *editor = new LtsAppDescriptorEditor(mainWindow);
|
LtsAppDescriptorEditor* editor = new LtsAppDescriptorEditor(mainWindow);
|
||||||
mainWindow->setCentralWidget(editor);
|
mainWindow->setCentralWidget(editor);
|
||||||
QObject::connect(openAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onOpenClicked);
|
QObject::connect(openAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onOpenClicked);
|
||||||
QObject::connect(newAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onNewClicked);
|
QObject::connect(newAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onNewClicked);
|
||||||
|
|||||||
@@ -19,5 +19,3 @@ NGL_TARGET_LINK_LIBRARIES(LtsCommandLineParser
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
Qt6::Core
|
Qt6::Core
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(unit-test)
|
|
||||||
+47
-37
@@ -1,4 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#include "LtsCommandLineParser.h"
|
#include "LtsCommandLineParser.h"
|
||||||
|
|
||||||
@@ -10,16 +15,15 @@
|
|||||||
|
|
||||||
namespace LtsCommandLineParser
|
namespace LtsCommandLineParser
|
||||||
{
|
{
|
||||||
static constexpr int s_maxDomainId = 232;
|
static constexpr int s_maxDomainId = 232;
|
||||||
|
|
||||||
LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions opts)
|
LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions opts)
|
||||||
: QCommandLineParser()
|
: QCommandLineParser(), m_enabledOptions(opts)
|
||||||
, m_enabledOptions(opts)
|
{
|
||||||
{
|
|
||||||
if (NGL::isAppInBuildBasePath() || m_enabledOptions.testFlag(CreateDomainIdFromIp))
|
if (NGL::isAppInBuildBasePath() || m_enabledOptions.testFlag(CreateDomainIdFromIp))
|
||||||
{
|
{
|
||||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
||||||
for (const QHostAddress &address : addresses)
|
for (const QHostAddress& address : addresses)
|
||||||
{
|
{
|
||||||
if (address.isLoopback() || address.isNull())
|
if (address.isLoopback() || address.isNull())
|
||||||
continue;
|
continue;
|
||||||
@@ -46,21 +50,27 @@ namespace LtsCommandLineParser
|
|||||||
if (m_enabledOptions.testFlag(CustomConfigFile))
|
if (m_enabledOptions.testFlag(CustomConfigFile))
|
||||||
{
|
{
|
||||||
const QString cf(NGL::findProjectConfigFile());
|
const QString cf(NGL::findProjectConfigFile());
|
||||||
addOption({{QStringLiteral("i"), QStringLiteral("ini")}, QStringLiteral("Default: ") + cf, QStringLiteral("filename"), cf});
|
addOption({{QStringLiteral("i"), QStringLiteral("ini")},
|
||||||
|
QStringLiteral("Default: ") + cf,
|
||||||
|
QStringLiteral("filename"),
|
||||||
|
cf});
|
||||||
}
|
}
|
||||||
if (m_enabledOptions.testFlag(TcpConnectionUrl))
|
if (m_enabledOptions.testFlag(TcpConnectionUrl))
|
||||||
{
|
{
|
||||||
const QString defaultTcpUrl(QStringLiteral("EXCTDS01:7400"));
|
const QString defaultTcpUrl(QStringLiteral("EXCTDS01:7400"));
|
||||||
addOption({{QStringLiteral("t"), QStringLiteral("tcpurl")}, QStringLiteral("Default: ") + defaultTcpUrl, QStringLiteral("hostname:port"), defaultTcpUrl});
|
addOption({{QStringLiteral("t"), QStringLiteral("tcpurl")},
|
||||||
|
QStringLiteral("Default: ") + defaultTcpUrl,
|
||||||
|
QStringLiteral("hostname:port"),
|
||||||
|
defaultTcpUrl});
|
||||||
}
|
}
|
||||||
addHelpOption();
|
addHelpOption();
|
||||||
|
|
||||||
if (!m_enabledOptions.testFlag(NoVersion))
|
if (!m_enabledOptions.testFlag(NoVersion))
|
||||||
addVersionOption();
|
addVersionOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LtsCommandLineParser::domainId() const
|
int LtsCommandLineParser::domainId() const
|
||||||
{
|
{
|
||||||
if (m_domainId == 0 && m_generatedDomainId != 0 && !m_domainIdSetByFunction)
|
if (m_domainId == 0 && m_generatedDomainId != 0 && !m_domainIdSetByFunction)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -78,30 +88,30 @@ namespace LtsCommandLineParser
|
|||||||
return m_generatedDomainId;
|
return m_generatedDomainId;
|
||||||
}
|
}
|
||||||
return m_domainId;
|
return m_domainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCommandLineParser::setDomainId(int id)
|
void LtsCommandLineParser::setDomainId(int id)
|
||||||
{
|
{
|
||||||
m_domainIdSetByFunction = true;
|
m_domainIdSetByFunction = true;
|
||||||
m_domainId = id;
|
m_domainId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCommandLineParser::iniFileSet() const
|
bool LtsCommandLineParser::iniFileSet() const
|
||||||
{
|
{
|
||||||
if (!m_enabledOptions.testFlag(CustomConfigFile))
|
if (!m_enabledOptions.testFlag(CustomConfigFile))
|
||||||
return false;
|
return false;
|
||||||
return isSet(QStringLiteral("i"));
|
return isSet(QStringLiteral("i"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCommandLineParser::useTcpConnection() const
|
bool LtsCommandLineParser::useTcpConnection() const
|
||||||
{
|
{
|
||||||
if (!m_enabledOptions.testFlag(TcpConnectionUrl))
|
if (!m_enabledOptions.testFlag(TcpConnectionUrl))
|
||||||
return false;
|
return false;
|
||||||
return isSet(QStringLiteral("t"));
|
return isSet(QStringLiteral("t"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl LtsCommandLineParser::tcpConnectionUrl() const
|
QUrl LtsCommandLineParser::tcpConnectionUrl() const
|
||||||
{
|
{
|
||||||
if (!m_enabledOptions.testFlag(TcpConnectionUrl))
|
if (!m_enabledOptions.testFlag(TcpConnectionUrl))
|
||||||
return QUrl();
|
return QUrl();
|
||||||
if (!useTcpConnection())
|
if (!useTcpConnection())
|
||||||
@@ -113,10 +123,10 @@ namespace LtsCommandLineParser
|
|||||||
if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("file"))
|
if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("file"))
|
||||||
url.setScheme(QStringLiteral("tcpv4lan"));
|
url.setScheme(QStringLiteral("tcpv4lan"));
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCommandLineParser::init(bool bParseHelp)
|
bool LtsCommandLineParser::init(bool bParseHelp)
|
||||||
{
|
{
|
||||||
if (!parse(QCoreApplication::arguments()))
|
if (!parse(QCoreApplication::arguments()))
|
||||||
{
|
{
|
||||||
fprintf(stdout, "\nBad option: %s \n", qPrintable(errorText()));
|
fprintf(stdout, "\nBad option: %s \n", qPrintable(errorText()));
|
||||||
@@ -148,28 +158,28 @@ namespace LtsCommandLineParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCommandLineParser::showHelp(int exitCode)
|
void LtsCommandLineParser::showHelp(int exitCode)
|
||||||
{
|
{
|
||||||
if (!m_additionalHelpStr.isEmpty())
|
if (!m_additionalHelpStr.isEmpty())
|
||||||
fprintf(stdout, "%s", qPrintable(m_additionalHelpStr));
|
fprintf(stdout, "%s", qPrintable(m_additionalHelpStr));
|
||||||
|
|
||||||
QCommandLineParser::showHelp(exitCode);
|
QCommandLineParser::showHelp(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCommandLineParser::domainIdProvided() const
|
bool LtsCommandLineParser::domainIdProvided() const
|
||||||
{
|
{
|
||||||
if (!m_enabledOptions.testFlag(DomainId))
|
if (!m_enabledOptions.testFlag(DomainId))
|
||||||
return false;
|
return false;
|
||||||
return isSet(QStringLiteral("d"));
|
return isSet(QStringLiteral("d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCommandLineParser::exerciseIdProvided() const
|
bool LtsCommandLineParser::exerciseIdProvided() const
|
||||||
{
|
{
|
||||||
if (!m_enabledOptions.testFlag(ExerciseId))
|
if (!m_enabledOptions.testFlag(ExerciseId))
|
||||||
return false;
|
return false;
|
||||||
return isSet(QStringLiteral("e"));
|
return isSet(QStringLiteral("e"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsCommandLineParser
|
} // namespace LtsCommandLineParser
|
||||||
+24
-11
@@ -1,4 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -10,11 +15,10 @@ class QUrl;
|
|||||||
|
|
||||||
namespace LtsCommandLineParser
|
namespace LtsCommandLineParser
|
||||||
{
|
{
|
||||||
class LTSCOMMANDLINEPARSER_EXPORT LtsCommandLineParser : public QCommandLineParser
|
class LTSCOMMANDLINEPARSER_EXPORT LtsCommandLineParser : public QCommandLineParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ProvideCommandLineParameterOptions
|
enum ProvideCommandLineParameterOptions {
|
||||||
{
|
|
||||||
None = 0x0000,
|
None = 0x0000,
|
||||||
CreateDomainIdFromIp = 0x0001,
|
CreateDomainIdFromIp = 0x0001,
|
||||||
DomainId = 0x0002,
|
DomainId = 0x0002,
|
||||||
@@ -24,15 +28,21 @@ namespace LtsCommandLineParser
|
|||||||
NoVersion = 0x0020
|
NoVersion = 0x0020
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit LtsCommandLineParser(ProvideCommandLineParameterOptions opts = ProvideCommandLineParameterOptions(CreateDomainIdFromIp | DomainId | ExerciseId |
|
explicit LtsCommandLineParser(ProvideCommandLineParameterOptions opts = ProvideCommandLineParameterOptions(
|
||||||
CustomConfigFile));
|
CreateDomainIdFromIp | DomainId | ExerciseId | CustomConfigFile));
|
||||||
virtual ~LtsCommandLineParser() = default;
|
virtual ~LtsCommandLineParser() = default;
|
||||||
int domainId() const;
|
int domainId() const;
|
||||||
void setDomainId(int id);
|
void setDomainId(int id);
|
||||||
|
|
||||||
int exerciseId() const { return m_exerciseId; }
|
int exerciseId() const
|
||||||
|
{
|
||||||
|
return m_exerciseId;
|
||||||
|
}
|
||||||
|
|
||||||
QString iniFile() const { return m_iniFile; }
|
QString iniFile() const
|
||||||
|
{
|
||||||
|
return m_iniFile;
|
||||||
|
}
|
||||||
|
|
||||||
bool iniFileSet() const;
|
bool iniFileSet() const;
|
||||||
bool useTcpConnection() const;
|
bool useTcpConnection() const;
|
||||||
@@ -43,7 +53,10 @@ namespace LtsCommandLineParser
|
|||||||
bool domainIdProvided() const;
|
bool domainIdProvided() const;
|
||||||
bool exerciseIdProvided() const;
|
bool exerciseIdProvided() const;
|
||||||
|
|
||||||
void setUnitModuleTestMode(bool onOff) { m_unitModuleTestMode = onOff; }
|
void setUnitModuleTestMode(bool onOff)
|
||||||
|
{
|
||||||
|
m_unitModuleTestMode = onOff;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_additionalHelpStr;
|
QString m_additionalHelpStr;
|
||||||
@@ -56,6 +69,6 @@ namespace LtsCommandLineParser
|
|||||||
bool m_domainIdSetByFunction{false};
|
bool m_domainIdSetByFunction{false};
|
||||||
bool m_unitModuleTestMode{false};
|
bool m_unitModuleTestMode{false};
|
||||||
QString m_iniFile;
|
QString m_iniFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsCommandLineParser
|
} // namespace LtsCommandLineParser
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
#
|
|
||||||
# Unit tests for the LtsCommandLineParser module.
|
|
||||||
# One test executable per module, each registered with ctest.
|
|
||||||
#
|
|
||||||
if (NOT BUILD_TESTING)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# --- LtsCommandLineParser: option registration, parsing, domain id handling
|
|
||||||
if (TARGET LtsCommandLineParser)
|
|
||||||
# probe helper: runs init() with a real command line (QtTest's main cannot
|
|
||||||
# forward CLI options); used by iniFileProvidesDomainId
|
|
||||||
ADD_EXECUTABLE(commandlineparser_ini_probe commandlineparser_ini_probe.cpp)
|
|
||||||
TARGET_LINK_LIBRARIES(commandlineparser_ini_probe
|
|
||||||
LtsCommandLineParser
|
|
||||||
Qt6::Core
|
|
||||||
)
|
|
||||||
|
|
||||||
ADD_EXECUTABLE(commandlineparser_unit_test commandlineparser_unit_test.cpp)
|
|
||||||
ADD_DEPENDENCIES(commandlineparser_unit_test commandlineparser_ini_probe)
|
|
||||||
TARGET_COMPILE_DEFINITIONS(commandlineparser_unit_test PRIVATE
|
|
||||||
INI_PROBE_EXE="$<TARGET_FILE:commandlineparser_ini_probe>")
|
|
||||||
TARGET_LINK_LIBRARIES(commandlineparser_unit_test
|
|
||||||
LtsCommandLineParser
|
|
||||||
Qt6::Core
|
|
||||||
Qt6::Test
|
|
||||||
)
|
|
||||||
ADD_TEST(NAME commandlineparser_unit_test COMMAND $<TARGET_FILE:commandlineparser_unit_test>)
|
|
||||||
endif()
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
/**
|
|
||||||
* @RDE_HEADER@
|
|
||||||
* Helper probe for the LtsCommandLineParser unit test: runs init() with the
|
|
||||||
* real command line (QTest's main cannot forward CLI options) and reports
|
|
||||||
* the resulting domain id.
|
|
||||||
* $Id$
|
|
||||||
* $HeadURL$
|
|
||||||
* $Author$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
|
|
||||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
QCoreApplication app(argc, argv);
|
|
||||||
|
|
||||||
LtsCommandLineParser::LtsCommandLineParser parser;
|
|
||||||
parser.setUnitModuleTestMode(true);
|
|
||||||
if (!parser.init(false))
|
|
||||||
{
|
|
||||||
std::printf("INIT_FAIL\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::printf("DOMAINID=%d\n", parser.domainId());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
-173
@@ -1,173 +0,0 @@
|
|||||||
/**
|
|
||||||
* @RDE_HEADER@
|
|
||||||
* Unittest
|
|
||||||
* $Id$
|
|
||||||
* $HeadURL$
|
|
||||||
* $Author$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QtTest/QTest>
|
|
||||||
|
|
||||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
||||||
|
|
||||||
#include <QtCore/QDir>
|
|
||||||
#include <QtCore/QProcess>
|
|
||||||
#include <QtCore/QSettings>
|
|
||||||
#include <QtCore/QTemporaryDir>
|
|
||||||
#include <QtCore/QUrl>
|
|
||||||
|
|
||||||
class commandlineparser_unit_test : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void optionDefaults();
|
|
||||||
void parseWithOptions();
|
|
||||||
void tcpConnectionUrl();
|
|
||||||
void setDomainIdOverridesGenerated();
|
|
||||||
void domainIdFallbackRange();
|
|
||||||
void initCleanRun();
|
|
||||||
void iniFileProvidesDomainId();
|
|
||||||
void unknownOptionBehaviour();
|
|
||||||
};
|
|
||||||
|
|
||||||
using Lcp = LtsCommandLineParser::LtsCommandLineParser;
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::optionDefaults()
|
|
||||||
{
|
|
||||||
Lcp parser;
|
|
||||||
// nothing parsed yet
|
|
||||||
QVERIFY(!parser.domainIdProvided());
|
|
||||||
QVERIFY(!parser.exerciseIdProvided());
|
|
||||||
QVERIFY(!parser.iniFileSet());
|
|
||||||
QVERIFY(!parser.useTcpConnection());
|
|
||||||
QVERIFY(!parser.tcpConnectionUrl().isValid());
|
|
||||||
QCOMPARE(parser.exerciseId(), 0);
|
|
||||||
QCOMPARE(parser.iniFile(), QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::parseWithOptions()
|
|
||||||
{
|
|
||||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(
|
|
||||||
Lcp::DomainId | Lcp::ExerciseId | Lcp::CustomConfigFile | Lcp::TcpConnectionUrl));
|
|
||||||
const bool ok = parser.parse({
|
|
||||||
QStringLiteral("prog"),
|
|
||||||
QStringLiteral("-d"), QStringLiteral("42"),
|
|
||||||
QStringLiteral("-e"), QStringLiteral("7"),
|
|
||||||
QStringLiteral("-i"), QStringLiteral("/tmp/lts-cc.conf"),
|
|
||||||
QStringLiteral("-t"), QStringLiteral("tcpv4_lan://10.0.0.1:7400")
|
|
||||||
});
|
|
||||||
QVERIFY(ok);
|
|
||||||
QVERIFY(parser.domainIdProvided());
|
|
||||||
QVERIFY(parser.exerciseIdProvided());
|
|
||||||
QVERIFY(parser.iniFileSet());
|
|
||||||
QVERIFY(parser.useTcpConnection());
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::tcpConnectionUrl()
|
|
||||||
{
|
|
||||||
// the tcpv4_lan scheme is canonicalized to tcpv4lan
|
|
||||||
{
|
|
||||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(Lcp::TcpConnectionUrl));
|
|
||||||
QVERIFY(parser.parse({
|
|
||||||
QStringLiteral("prog"),
|
|
||||||
QStringLiteral("-t"), QStringLiteral("tcpv4_lan://10.0.0.1:7400")
|
|
||||||
}));
|
|
||||||
const QUrl url = parser.tcpConnectionUrl();
|
|
||||||
QCOMPARE(url.scheme(), QStringLiteral("tcpv4lan"));
|
|
||||||
QCOMPARE(url.host(), QStringLiteral("10.0.0.1"));
|
|
||||||
QCOMPARE(url.port(), 7400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// http/file input is rewritten to the tcpv4lan scheme
|
|
||||||
{
|
|
||||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(Lcp::TcpConnectionUrl));
|
|
||||||
QVERIFY(parser.parse({
|
|
||||||
QStringLiteral("prog"),
|
|
||||||
QStringLiteral("-t"), QStringLiteral("http://192.168.0.2:7500")
|
|
||||||
}));
|
|
||||||
QCOMPARE(parser.tcpConnectionUrl().scheme(), QStringLiteral("tcpv4lan"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// without the option enabled the URL is never returned
|
|
||||||
{
|
|
||||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(Lcp::DomainId));
|
|
||||||
const QUrl url = parser.tcpConnectionUrl();
|
|
||||||
QVERIFY(!url.isValid());
|
|
||||||
QVERIFY(!parser.useTcpConnection());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::setDomainIdOverridesGenerated()
|
|
||||||
{
|
|
||||||
Lcp parser;
|
|
||||||
parser.setDomainId(7);
|
|
||||||
// the function-set id is always returned, never the IP-generated fallback
|
|
||||||
QCOMPARE(parser.domainId(), 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::domainIdFallbackRange()
|
|
||||||
{
|
|
||||||
// without an explicit id the parser falls back to the id generated from
|
|
||||||
// the local IPv4 address (or 0 when none is found)
|
|
||||||
Lcp parser;
|
|
||||||
const int id = parser.domainId();
|
|
||||||
QVERIFY2(id >= 0 && id <= 232,
|
|
||||||
qPrintable(QStringLiteral("domainId() fallback out of range: %1").arg(id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::initCleanRun()
|
|
||||||
{
|
|
||||||
// init() parses the test executable's own argument list (program name
|
|
||||||
// only under ctest) and succeeds
|
|
||||||
Lcp parser;
|
|
||||||
QVERIFY(parser.init(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::iniFileProvidesDomainId()
|
|
||||||
{
|
|
||||||
// init() re-parses the application's own argument list and QCommandLineParser
|
|
||||||
// resets the option state on every parse, so -i can only reach it through the
|
|
||||||
// process argv. QtTest's main cannot forward CLI options, so the (non-QtTest)
|
|
||||||
// probe executable runs init() with a real command line instead.
|
|
||||||
// The ini file is created under the working directory (rather than the
|
|
||||||
// default /tmp) so the test is independent of /tmp's state.
|
|
||||||
QTemporaryDir tmp(QDir::current().absolutePath() + QStringLiteral("/lcp_ut_XXXXXX"));
|
|
||||||
QVERIFY(tmp.isValid());
|
|
||||||
const QString iniFile = tmp.path() + QStringLiteral("/lts-cc.conf");
|
|
||||||
{
|
|
||||||
QSettings s(iniFile, QSettings::IniFormat);
|
|
||||||
s.setValue(QStringLiteral("Global/DomainId"), 7);
|
|
||||||
s.sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
QProcess proc;
|
|
||||||
proc.start(QStringLiteral(INI_PROBE_EXE), { QStringLiteral("-i"), iniFile });
|
|
||||||
QVERIFY(proc.waitForFinished(10000));
|
|
||||||
const QByteArray out = proc.readAllStandardOutput();
|
|
||||||
// no -d given: the domain id is read from the ini file
|
|
||||||
QVERIFY2(out.contains(QByteArrayLiteral("DOMAINID=7")),
|
|
||||||
qPrintable(QString::fromUtf8(out)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandlineparser_unit_test::unknownOptionBehaviour()
|
|
||||||
{
|
|
||||||
// the version option is registered unless NoVersion is set
|
|
||||||
Lcp withVersion;
|
|
||||||
QVERIFY(withVersion.parse({ QStringLiteral("prog"), QStringLiteral("-v") }));
|
|
||||||
QVERIFY(withVersion.isSet(QStringLiteral("v")));
|
|
||||||
|
|
||||||
// with NoVersion, -v is not registered and parsing fails
|
|
||||||
Lcp strict(Lcp::NoVersion);
|
|
||||||
QVERIFY(!strict.parse({ QStringLiteral("prog"), QStringLiteral("-v") }));
|
|
||||||
|
|
||||||
// the help option is always registered
|
|
||||||
Lcp parser;
|
|
||||||
parser.setUnitModuleTestMode(true);
|
|
||||||
QVERIFY(parser.parse({ QStringLiteral("prog"), QStringLiteral("-h") }));
|
|
||||||
QVERIFY(parser.isSet(QStringLiteral("h")));
|
|
||||||
}
|
|
||||||
|
|
||||||
QTEST_MAIN(commandlineparser_unit_test)
|
|
||||||
|
|
||||||
#include "commandlineparser_unit_test.moc"
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3 || argc > 5)
|
if (argc < 3 || argc > 5)
|
||||||
{
|
{
|
||||||
@@ -58,17 +58,7 @@ int main(int argc, char **argv)
|
|||||||
part3 = mgrs.substr(5, prec);
|
part3 = mgrs.substr(5, prec);
|
||||||
part4 = mgrs.substr(5 + prec, prec);
|
part4 = mgrs.substr(5 + prec, prec);
|
||||||
}
|
}
|
||||||
fprintf(stdout,
|
fprintf(stdout, "%13.10f, %13.10f = %s %s %s %s (UTM: %d %.2f, %.2f %c)\n", lon, lat, part1.c_str(), part2.c_str(),
|
||||||
"%13.10f, %13.10f = %s %s %s %s (UTM: %d %.2f, %.2f %c)\n",
|
part3.c_str(), part4.c_str(), zone, x, y, northp ? 'N' : 'S');
|
||||||
lon,
|
|
||||||
lat,
|
|
||||||
part1.c_str(),
|
|
||||||
part2.c_str(),
|
|
||||||
part3.c_str(),
|
|
||||||
part4.c_str(),
|
|
||||||
zone,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
northp ? 'N' : 'S');
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Provide some coordinate translation functions on top of GeographicLib
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-08-31
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_coord_trans.h"
|
#include "lts_coord_trans.h"
|
||||||
|
|
||||||
@@ -15,24 +23,24 @@
|
|||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans
|
||||||
{
|
{
|
||||||
|
|
||||||
static long s_conversion_counter_MGRS_Forward = 0;
|
static long s_conversion_counter_MGRS_Forward = 0;
|
||||||
static long s_conversion_counter_MGRS_Reverse = 0;
|
static long s_conversion_counter_MGRS_Reverse = 0;
|
||||||
|
|
||||||
static long s_conversion_counter_WGS84_Forward = 0;
|
static long s_conversion_counter_WGS84_Forward = 0;
|
||||||
static long s_conversion_counter_WGS84_Reverse = 0;
|
static long s_conversion_counter_WGS84_Reverse = 0;
|
||||||
|
|
||||||
static long s_conversion_counter_UTMUPS_Forward = 0;
|
static long s_conversion_counter_UTMUPS_Forward = 0;
|
||||||
static long s_conversion_counter_UTMUPS_Reverse = 0;
|
static long s_conversion_counter_UTMUPS_Reverse = 0;
|
||||||
|
|
||||||
inline void incrementCounter(long &counterRef)
|
inline void incrementCounter(long& counterRef)
|
||||||
{
|
{
|
||||||
#ifdef LTS_DEBUG
|
#ifdef LTS_DEBUG
|
||||||
++counterRef;
|
++counterRef;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string cleanupMgrsString(const QString &in)
|
static inline std::string cleanupMgrsString(const QString& in)
|
||||||
{
|
{
|
||||||
const QByteArray ba(in.toLatin1());
|
const QByteArray ba(in.toLatin1());
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ret.reserve(ba.size());
|
ret.reserve(ba.size());
|
||||||
@@ -42,10 +50,10 @@ namespace LtsCoordTrans
|
|||||||
ret += c;
|
ret += c;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
||||||
{
|
{
|
||||||
if (prec < 0)
|
if (prec < 0)
|
||||||
prec = 0;
|
prec = 0;
|
||||||
if (prec > 11)
|
if (prec > 11)
|
||||||
@@ -57,7 +65,7 @@ namespace LtsCoordTrans
|
|||||||
GeographicLib::MGRS::Forward(zone, northp, x, y, prec, mgrs);
|
GeographicLib::MGRS::Forward(zone, northp, x, y, prec, mgrs);
|
||||||
incrementCounter(s_conversion_counter_MGRS_Forward);
|
incrementCounter(s_conversion_counter_MGRS_Forward);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while calculating mgrs from utm %d, %9.6f, %9.6f: %s\n", zone, x, y, e.what());
|
fprintf(stderr, "Error while calculating mgrs from utm %d, %9.6f, %9.6f: %s\n", zone, x, y, e.what());
|
||||||
mgrs.clear();
|
mgrs.clear();
|
||||||
@@ -67,56 +75,58 @@ namespace LtsCoordTrans
|
|||||||
if (withSpaces && mgrs.size() == static_cast<size_t>(5 + 2 * prec))
|
if (withSpaces && mgrs.size() == static_cast<size_t>(5 + 2 * prec))
|
||||||
{
|
{
|
||||||
|
|
||||||
const char *ptr = mgrs.c_str();
|
const char* ptr = mgrs.c_str();
|
||||||
|
|
||||||
ret = QString::fromLatin1(ptr, 3) + QLatin1Char(' ') + QString::fromLatin1(ptr + 3, 2);
|
ret = QString::fromLatin1(ptr, 3) + QLatin1Char(' ') + QString::fromLatin1(ptr + 3, 2);
|
||||||
if (prec > 0)
|
if (prec > 0)
|
||||||
{
|
{
|
||||||
ret += QLatin1Char(' ') + QString::fromLatin1(ptr + 5, prec) + QLatin1Char(' ') + QString::fromLatin1(ptr + 5 + prec, prec);
|
ret += QLatin1Char(' ') + QString::fromLatin1(ptr + 5, prec) + QLatin1Char(' ') +
|
||||||
|
QString::fromLatin1(ptr + 5 + prec, prec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = QString::fromLatin1(mgrs.c_str(), mgrs.size());
|
ret = QString::fromLatin1(mgrs.c_str(), mgrs.size());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::toPoint() const
|
QPointF UtmCoordinate::toPoint() const
|
||||||
{
|
{
|
||||||
return {x, y};
|
return {x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::geographic(double offsetX, double offsetY) const
|
QPointF UtmCoordinate::geographic(double offsetX, double offsetY) const
|
||||||
{
|
{
|
||||||
QPointF ret;
|
QPointF ret;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GeographicLib::UTMUPS::Reverse(zone, northp, x + offsetX, y + offsetY, ret.ry(), ret.rx());
|
GeographicLib::UTMUPS::Reverse(zone, northp, x + offsetX, y + offsetY, ret.ry(), ret.rx());
|
||||||
incrementCounter(s_conversion_counter_UTMUPS_Reverse);
|
incrementCounter(s_conversion_counter_UTMUPS_Reverse);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while calculating geographic from utm %d, %9.6f, %9.6f: %s\n", zone, x + offsetX, y + offsetY, e.what());
|
fprintf(stderr, "Error while calculating geographic from utm %d, %9.6f, %9.6f: %s\n", zone, x + offsetX,
|
||||||
|
y + offsetY, e.what());
|
||||||
ret = QPointF();
|
ret = QPointF();
|
||||||
}
|
}
|
||||||
return ret * deg2rad();
|
return ret * deg2rad();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::geographic(const QPointF &offset) const
|
QPointF UtmCoordinate::geographic(const QPointF& offset) const
|
||||||
{
|
{
|
||||||
return geographic(offset.x(), offset.y());
|
return geographic(offset.x(), offset.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::relativeTo(const UtmCoordinate &other) const
|
QPointF UtmCoordinate::relativeTo(const UtmCoordinate& other) const
|
||||||
{
|
{
|
||||||
if (zone == other.zone)
|
if (zone == other.zone)
|
||||||
return QPointF(x - other.x, y - other.y);
|
return QPointF(x - other.x, y - other.y);
|
||||||
|
|
||||||
UtmCoordinate otherInMyZone = fromGeographic(other.geographic(), zone);
|
UtmCoordinate otherInMyZone = fromGeographic(other.geographic(), zone);
|
||||||
return QPointF(x - otherInMyZone.x, y - otherInMyZone.y);
|
return QPointF(x - otherInMyZone.x, y - otherInMyZone.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate UtmCoordinate::fromGeographic(double lon, double lat, int setZone)
|
UtmCoordinate UtmCoordinate::fromGeographic(double lon, double lat, int setZone)
|
||||||
{
|
{
|
||||||
|
|
||||||
lon *= rad2deg();
|
lon *= rad2deg();
|
||||||
lat *= rad2deg();
|
lat *= rad2deg();
|
||||||
@@ -128,21 +138,21 @@ namespace LtsCoordTrans
|
|||||||
GeographicLib::UTMUPS::Forward(lat, lon, ret.zone, ret.northp, ret.x, ret.y, setZone);
|
GeographicLib::UTMUPS::Forward(lat, lon, ret.zone, ret.northp, ret.x, ret.y, setZone);
|
||||||
incrementCounter(s_conversion_counter_UTMUPS_Forward);
|
incrementCounter(s_conversion_counter_UTMUPS_Forward);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while calculating mgrs base point from %9.6f, %9.6f: %s\n", lat, lon, e.what());
|
fprintf(stderr, "Error while calculating mgrs base point from %9.6f, %9.6f: %s\n", lat, lon, e.what());
|
||||||
ret = UtmCoordinate();
|
ret = UtmCoordinate();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate UtmCoordinate::fromGeographic(const QPointF &lonLat, int setZone)
|
UtmCoordinate UtmCoordinate::fromGeographic(const QPointF& lonLat, int setZone)
|
||||||
{
|
{
|
||||||
return fromGeographic(lonLat.x(), lonLat.y(), setZone);
|
return fromGeographic(lonLat.x(), lonLat.y(), setZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate UtmCoordinate::fromMgrs(const QString &mgrs)
|
UtmCoordinate UtmCoordinate::fromMgrs(const QString& mgrs)
|
||||||
{
|
{
|
||||||
UtmCoordinate utm;
|
UtmCoordinate utm;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -151,44 +161,44 @@ namespace LtsCoordTrans
|
|||||||
GeographicLib::MGRS::Reverse(cleanupMgrsString(mgrs), utm.zone, utm.northp, utm.x, utm.y, prec, true);
|
GeographicLib::MGRS::Reverse(cleanupMgrsString(mgrs), utm.zone, utm.northp, utm.x, utm.y, prec, true);
|
||||||
incrementCounter(s_conversion_counter_MGRS_Reverse);
|
incrementCounter(s_conversion_counter_MGRS_Reverse);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while converting mgrs coordinate %s to utm: %s\n", qPrintable(mgrs), e.what());
|
fprintf(stderr, "Error while converting mgrs coordinate %s to utm: %s\n", qPrintable(mgrs), e.what());
|
||||||
utm = UtmCoordinate();
|
utm = UtmCoordinate();
|
||||||
}
|
}
|
||||||
return utm;
|
return utm;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mgrsFromGeographic(double lon, double lat, int prec, bool withSpaces)
|
QString mgrsFromGeographic(double lon, double lat, int prec, bool withSpaces)
|
||||||
{
|
{
|
||||||
return UtmCoordinate::fromGeographic(lon, lat, -1).mgrs(prec, withSpaces);
|
return UtmCoordinate::fromGeographic(lon, lat, -1).mgrs(prec, withSpaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF geographicFromMgrs(const QString &mgrs)
|
QPointF geographicFromMgrs(const QString& mgrs)
|
||||||
{
|
{
|
||||||
return UtmCoordinate::fromMgrs(mgrs).geographic();
|
return UtmCoordinate::fromMgrs(mgrs).geographic();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> &staticDefaultSquaresHelper()
|
QVector<UtmCoordinate>& staticDefaultSquaresHelper()
|
||||||
{
|
{
|
||||||
static QVector<UtmCoordinate> s_defaultMgrsSquares;
|
static QVector<UtmCoordinate> s_defaultMgrsSquares;
|
||||||
return s_defaultMgrsSquares;
|
return s_defaultMgrsSquares;
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate &staticPreferedMgrsSquareHelper()
|
UtmCoordinate& staticPreferedMgrsSquareHelper()
|
||||||
{
|
{
|
||||||
static UtmCoordinate s_preferedMgrsSquare;
|
static UtmCoordinate s_preferedMgrsSquare;
|
||||||
return s_preferedMgrsSquare;
|
return s_preferedMgrsSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> &staticMgrsSquaresWithOffsetsHelper()
|
QVector<UtmCoordinate>& staticMgrsSquaresWithOffsetsHelper()
|
||||||
{
|
{
|
||||||
static QVector<UtmCoordinate> s_mgrsSquaresWithOffsets;
|
static QVector<UtmCoordinate> s_mgrsSquaresWithOffsets;
|
||||||
return s_mgrsSquaresWithOffsets;
|
return s_mgrsSquaresWithOffsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF addMarginToArea(const QRectF &rect_LatLon_radiant, const QSize &marginMeter)
|
QRectF addMarginToArea(const QRectF& rect_LatLon_radiant, const QSize& marginMeter)
|
||||||
{
|
{
|
||||||
double lonMin, lonMax, latMin, latMmax;
|
double lonMin, lonMax, latMin, latMmax;
|
||||||
rect_LatLon_radiant.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
rect_LatLon_radiant.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
||||||
|
|
||||||
@@ -213,10 +223,11 @@ namespace LtsCoordTrans
|
|||||||
|
|
||||||
QRectF res = QRectF(topLeft, bottomRight);
|
QRectF res = QRectF(topLeft, bottomRight);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> getMgrsSquares(const QRectF &rect, bool setAsDefaultSquares, bool setAsPreferedSquare, bool setAsSquareWithMargin)
|
QVector<UtmCoordinate> getMgrsSquares(const QRectF& rect, bool setAsDefaultSquares, bool setAsPreferedSquare,
|
||||||
{
|
bool setAsSquareWithMargin)
|
||||||
|
{
|
||||||
QVector<UtmCoordinate> ret = getMgrsSquaresInternal(rect);
|
QVector<UtmCoordinate> ret = getMgrsSquaresInternal(rect);
|
||||||
|
|
||||||
if (setAsDefaultSquares)
|
if (setAsDefaultSquares)
|
||||||
@@ -229,10 +240,10 @@ namespace LtsCoordTrans
|
|||||||
staticMgrsSquaresWithOffsetsHelper() = ret;
|
staticMgrsSquaresWithOffsetsHelper() = ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF& rect)
|
||||||
{
|
{
|
||||||
QVector<UtmCoordinate> ret;
|
QVector<UtmCoordinate> ret;
|
||||||
QVector<QString> tmpMgrsSquares;
|
QVector<QString> tmpMgrsSquares;
|
||||||
|
|
||||||
@@ -281,15 +292,15 @@ namespace LtsCoordTrans
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList getMgrsSurroundingSquares(const QRectF &geoRect, const QSize &offsetMeter)
|
QStringList getMgrsSurroundingSquares(const QRectF& geoRect, const QSize& offsetMeter)
|
||||||
{
|
{
|
||||||
|
|
||||||
const QVector<UtmCoordinate> mainUtms = getMgrsSquaresInternal(geoRect);
|
const QVector<UtmCoordinate> mainUtms = getMgrsSquaresInternal(geoRect);
|
||||||
QStringList mainSquares;
|
QStringList mainSquares;
|
||||||
mainSquares.reserve(mainUtms.count());
|
mainSquares.reserve(mainUtms.count());
|
||||||
for (const auto &utm : mainUtms)
|
for (const auto& utm : mainUtms)
|
||||||
mainSquares.append(utm.mgrs(0));
|
mainSquares.append(utm.mgrs(0));
|
||||||
|
|
||||||
const QRectF rectWithOffset = addMarginToArea(geoRect, offsetMeter);
|
const QRectF rectWithOffset = addMarginToArea(geoRect, offsetMeter);
|
||||||
@@ -297,46 +308,46 @@ namespace LtsCoordTrans
|
|||||||
QVector<UtmCoordinate> mainUtmsWithOffset = getMgrsSquaresInternal(rectWithOffset);
|
QVector<UtmCoordinate> mainUtmsWithOffset = getMgrsSquaresInternal(rectWithOffset);
|
||||||
QStringList mainSquaresWithOffset;
|
QStringList mainSquaresWithOffset;
|
||||||
mainSquaresWithOffset.reserve(mainUtmsWithOffset.count());
|
mainSquaresWithOffset.reserve(mainUtmsWithOffset.count());
|
||||||
for (const auto &utm : std::as_const(mainUtmsWithOffset))
|
for (const auto& utm : std::as_const(mainUtmsWithOffset))
|
||||||
mainSquaresWithOffset.append(utm.mgrs(0));
|
mainSquaresWithOffset.append(utm.mgrs(0));
|
||||||
|
|
||||||
QStringList surroundingSquares;
|
QStringList surroundingSquares;
|
||||||
surroundingSquares.reserve(mainSquaresWithOffset.count());
|
surroundingSquares.reserve(mainSquaresWithOffset.count());
|
||||||
for (const auto &mgrs0 : mainSquaresWithOffset)
|
for (const auto& mgrs0 : mainSquaresWithOffset)
|
||||||
{
|
{
|
||||||
if (!mainSquares.contains(mgrs0))
|
if (!mainSquares.contains(mgrs0))
|
||||||
surroundingSquares.append(mgrs0);
|
surroundingSquares.append(mgrs0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return surroundingSquares;
|
return surroundingSquares;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> defaultMgrsSquareWithOffsets()
|
QVector<UtmCoordinate> defaultMgrsSquareWithOffsets()
|
||||||
{
|
{
|
||||||
return staticMgrsSquaresWithOffsetsHelper();
|
return staticMgrsSquaresWithOffsetsHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultMgrsSquares(const QVector<QString> &squares)
|
void setDefaultMgrsSquares(const QVector<QString>& squares)
|
||||||
{
|
{
|
||||||
QVector<UtmCoordinate> coords;
|
QVector<UtmCoordinate> coords;
|
||||||
coords.reserve(squares.size());
|
coords.reserve(squares.size());
|
||||||
for (const QString &s : squares)
|
for (const QString& s : squares)
|
||||||
coords += UtmCoordinate::fromMgrs(s + QStringLiteral("00000000000000"));
|
coords += UtmCoordinate::fromMgrs(s + QStringLiteral("00000000000000"));
|
||||||
staticDefaultSquaresHelper() = coords;
|
staticDefaultSquaresHelper() = coords;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> defaultMgrsSquares()
|
QVector<UtmCoordinate> defaultMgrsSquares()
|
||||||
{
|
{
|
||||||
return staticDefaultSquaresHelper();
|
return staticDefaultSquaresHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate preferedMgrsSquare()
|
UtmCoordinate preferedMgrsSquare()
|
||||||
{
|
{
|
||||||
return staticPreferedMgrsSquareHelper();
|
return staticPreferedMgrsSquareHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lonLatAltToGeocentric(double lon, double lat, double altitude, double &xOut, double &yOut, double &zOut)
|
bool lonLatAltToGeocentric(double lon, double lat, double altitude, double& xOut, double& yOut, double& zOut)
|
||||||
{
|
{
|
||||||
|
|
||||||
lon *= rad2deg();
|
lon *= rad2deg();
|
||||||
lat *= rad2deg();
|
lat *= rad2deg();
|
||||||
@@ -354,10 +365,10 @@ namespace LtsCoordTrans
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool geocentric2LonLatAlt(double x, double y, double z, double &lon, double &lat, double &altitude)
|
bool geocentric2LonLatAlt(double x, double y, double z, double& lon, double& lat, double& altitude)
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -375,63 +386,70 @@ namespace LtsCoordTrans
|
|||||||
lon *= deg2rad();
|
lon *= deg2rad();
|
||||||
lat *= deg2rad();
|
lat *= deg2rad();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double distance(const QPointF &p1, const QPointF &p2)
|
double distance(const QPointF& p1, const QPointF& p2)
|
||||||
{
|
{
|
||||||
return distance(p1.x(), p1.y(), p2.x(), p2.y());
|
return distance(p1.x(), p1.y(), p2.x(), p2.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
double squareDistance(const QPointF &p1, const QPointF &p2)
|
double squareDistance(const QPointF& p1, const QPointF& p2)
|
||||||
{
|
{
|
||||||
return squareDistance(p1.x(), p1.y(), p2.x(), p2.y());
|
return squareDistance(p1.x(), p1.y(), p2.x(), p2.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &stream, const UtmCoordinate &coord)
|
std::ostream& operator<<(std::ostream& stream, const UtmCoordinate& coord)
|
||||||
{
|
{
|
||||||
|
|
||||||
stream << "UtmCoordinate(" << std::setprecision(8) << coord.x << "#" << std::setprecision(8) << coord.y << " zone=" << coord.zone << ")";
|
stream << "UtmCoordinate(" << std::setprecision(8) << coord.x << "#" << std::setprecision(8) << coord.y
|
||||||
|
<< " zone=" << coord.zone << ")";
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpConversionCounter()
|
void dumpConversionCounter()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Forward : - mgrs : %ld\n", s_conversion_counter_MGRS_Forward);
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Forward : - mgrs : %ld\n",
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Reverse - fromMgrs : %ld\n", s_conversion_counter_MGRS_Reverse);
|
s_conversion_counter_MGRS_Forward);
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Forward - lonLatAltToGeocentric : %ld\n", s_conversion_counter_WGS84_Forward);
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Reverse - fromMgrs : %ld\n",
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Reverse - geocentric2LonLatAlt : %ld\n", s_conversion_counter_WGS84_Reverse);
|
s_conversion_counter_MGRS_Reverse);
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Forward - fromGeographic : %ld\n", s_conversion_counter_UTMUPS_Forward);
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Forward - lonLatAltToGeocentric : %ld\n",
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Reverse - geographic : %ld\n", s_conversion_counter_UTMUPS_Reverse);
|
s_conversion_counter_WGS84_Forward);
|
||||||
}
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Reverse - geocentric2LonLatAlt : %ld\n",
|
||||||
|
s_conversion_counter_WGS84_Reverse);
|
||||||
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Forward - fromGeographic : %ld\n",
|
||||||
|
s_conversion_counter_UTMUPS_Forward);
|
||||||
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Reverse - geographic : %ld\n",
|
||||||
|
s_conversion_counter_UTMUPS_Reverse);
|
||||||
|
}
|
||||||
|
|
||||||
long getConversionCounter_MGRS_Forward()
|
long getConversionCounter_MGRS_Forward()
|
||||||
{
|
{
|
||||||
return s_conversion_counter_MGRS_Forward;
|
return s_conversion_counter_MGRS_Forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getConversionCounter_MGRS_Reverse()
|
long getConversionCounter_MGRS_Reverse()
|
||||||
{
|
{
|
||||||
return s_conversion_counter_MGRS_Reverse;
|
return s_conversion_counter_MGRS_Reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getConversionCounter_WGS84_Forward()
|
long getConversionCounter_WGS84_Forward()
|
||||||
{
|
{
|
||||||
return s_conversion_counter_WGS84_Forward;
|
return s_conversion_counter_WGS84_Forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getConversionCounter_WGS84_Reverse()
|
long getConversionCounter_WGS84_Reverse()
|
||||||
{
|
{
|
||||||
return s_conversion_counter_WGS84_Reverse;
|
return s_conversion_counter_WGS84_Reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getConversionCounter_UTMUPS_Forward()
|
long getConversionCounter_UTMUPS_Forward()
|
||||||
{
|
{
|
||||||
return s_conversion_counter_UTMUPS_Forward;
|
return s_conversion_counter_UTMUPS_Forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getConversionCounter_UTMUPS_Reverse()
|
long getConversionCounter_UTMUPS_Reverse()
|
||||||
{
|
{
|
||||||
return s_conversion_counter_UTMUPS_Reverse;
|
return s_conversion_counter_UTMUPS_Reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsCoordTrans
|
} // namespace LtsCoordTrans
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Provide some coordinate translation functions on top of GeographicLib
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-08-31
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -14,23 +22,23 @@ class QString;
|
|||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans
|
||||||
{
|
{
|
||||||
|
|
||||||
inline Q_CONSTEXPR double pi()
|
inline Q_CONSTEXPR double pi()
|
||||||
{
|
{
|
||||||
return M_PI;
|
return M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Q_CONSTEXPR double deg2rad()
|
inline Q_CONSTEXPR double deg2rad()
|
||||||
{
|
{
|
||||||
return pi() / 180.;
|
return pi() / 180.;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Q_CONSTEXPR double rad2deg()
|
inline Q_CONSTEXPR double rad2deg()
|
||||||
{
|
{
|
||||||
return 1. / deg2rad();
|
return 1. / deg2rad();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
||||||
{
|
{
|
||||||
int zone = -1;
|
int zone = -1;
|
||||||
bool northp = true;
|
bool northp = true;
|
||||||
double x = 0.;
|
double x = 0.;
|
||||||
@@ -38,15 +46,12 @@ namespace LtsCoordTrans
|
|||||||
|
|
||||||
UtmCoordinate() = default;
|
UtmCoordinate() = default;
|
||||||
|
|
||||||
UtmCoordinate(int zone_, double x_, double y_, bool northp_ = true)
|
UtmCoordinate(int zone_, double x_, double y_, bool northp_ = true) : zone(zone_), northp(northp_), x(x_), y(y_) {}
|
||||||
: zone(zone_)
|
|
||||||
, northp(northp_)
|
|
||||||
, x(x_)
|
|
||||||
, y(y_)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValid() const { return zone > 0 && zone <= 60; }
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return zone > 0 && zone <= 60;
|
||||||
|
}
|
||||||
|
|
||||||
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
||||||
|
|
||||||
@@ -54,108 +59,114 @@ namespace LtsCoordTrans
|
|||||||
|
|
||||||
QPointF geographic(double offsetX = 0., double offsetY = 0.) const;
|
QPointF geographic(double offsetX = 0., double offsetY = 0.) const;
|
||||||
|
|
||||||
QPointF geographic(const QPointF &offset) const;
|
QPointF geographic(const QPointF& offset) const;
|
||||||
|
|
||||||
QPointF relativeTo(const UtmCoordinate &other) const;
|
QPointF relativeTo(const UtmCoordinate& other) const;
|
||||||
|
|
||||||
static UtmCoordinate fromGeographic(double lon, double lat, int setZone = -1);
|
static UtmCoordinate fromGeographic(double lon, double lat, int setZone = -1);
|
||||||
|
|
||||||
static UtmCoordinate fromGeographic(const QPointF &lonLat, int setZone = -1);
|
static UtmCoordinate fromGeographic(const QPointF& lonLat, int setZone = -1);
|
||||||
|
|
||||||
static UtmCoordinate fromMgrs(const QString &mgrs);
|
static UtmCoordinate fromMgrs(const QString& mgrs);
|
||||||
};
|
};
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QString mgrsFromGeographic(double lon, double lat, int prec = 5, bool withSpaces = true);
|
LTSCOORDTRANS_EXPORT QString mgrsFromGeographic(double lon, double lat, int prec = 5, bool withSpaces = true);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QPointF geographicFromMgrs(const QString &mgrs);
|
LTSCOORDTRANS_EXPORT QPointF geographicFromMgrs(const QString& mgrs);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QRectF addMarginToArea(const QRectF &rect_LatLon_radiant, const QSize &marginMeter);
|
LTSCOORDTRANS_EXPORT QRectF addMarginToArea(const QRectF& rect_LatLon_radiant, const QSize& marginMeter);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> getMgrsSquares(const QRectF &rect, bool setAsDefaultSquares, bool setAsPreferedSquare, bool setAsSquareWithMargin = false);
|
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> getMgrsSquares(const QRectF& rect, bool setAsDefaultSquares,
|
||||||
|
bool setAsPreferedSquare,
|
||||||
|
bool setAsSquareWithMargin = false);
|
||||||
|
|
||||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect);
|
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF& rect);
|
||||||
|
|
||||||
QStringList getMgrsSurroundingSquares(const QRectF &geoRect, const QSize &offsetMeter);
|
QStringList getMgrsSurroundingSquares(const QRectF& geoRect, const QSize& offsetMeter);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquareWithOffsets();
|
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquareWithOffsets();
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT void setDefaultMgrsSquares(const QVector<QString> &squares);
|
LTSCOORDTRANS_EXPORT void setDefaultMgrsSquares(const QVector<QString>& squares);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquares();
|
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquares();
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT UtmCoordinate preferedMgrsSquare();
|
LTSCOORDTRANS_EXPORT UtmCoordinate preferedMgrsSquare();
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT bool lonLatAltToGeocentric(double lon, double lat, double altitude, double &xOut, double &yOut, double &zOut);
|
LTSCOORDTRANS_EXPORT bool lonLatAltToGeocentric(double lon, double lat, double altitude, double& xOut, double& yOut,
|
||||||
|
double& zOut);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT bool geocentric2LonLatAlt(double x, double y, double z, double &lon, double &lat, double &altitude);
|
LTSCOORDTRANS_EXPORT bool geocentric2LonLatAlt(double x, double y, double z, double& lon, double& lat,
|
||||||
|
double& altitude);
|
||||||
|
|
||||||
inline double squareDistance(const UtmCoordinate &p1, const UtmCoordinate &p2)
|
inline double squareDistance(const UtmCoordinate& p1, const UtmCoordinate& p2)
|
||||||
{
|
{
|
||||||
if (p1.zone != p2.zone)
|
if (p1.zone != p2.zone)
|
||||||
{
|
{
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return std::nan("");
|
return std::nan("");
|
||||||
}
|
}
|
||||||
return std::pow(p1.x - p2.x, 2) + std::pow(p1.y - p2.y, 2);
|
return std::pow(p1.x - p2.x, 2) + std::pow(p1.y - p2.y, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT double squareDistance(const QPointF &p1, const QPointF &p2);
|
LTSCOORDTRANS_EXPORT double squareDistance(const QPointF& p1, const QPointF& p2);
|
||||||
|
|
||||||
inline double squareDistance(const double lon1, const double lat1, const double lon2, const double lat2)
|
inline double squareDistance(const double lon1, const double lat1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
const auto p1(UtmCoordinate::fromGeographic(lon1, lat1));
|
const auto p1(UtmCoordinate::fromGeographic(lon1, lat1));
|
||||||
const auto p2(UtmCoordinate::fromGeographic(lon2, lat2, p1.zone));
|
const auto p2(UtmCoordinate::fromGeographic(lon2, lat2, p1.zone));
|
||||||
return squareDistance(p1, p2);
|
return squareDistance(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double squareDistance(const UtmCoordinate &p1, const double lon2, const double lat2)
|
inline double squareDistance(const UtmCoordinate& p1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
const auto p2(UtmCoordinate::fromGeographic(lon2, lat2, p1.zone));
|
const auto p2(UtmCoordinate::fromGeographic(lon2, lat2, p1.zone));
|
||||||
return squareDistance(p1, p2);
|
return squareDistance(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double distance(const UtmCoordinate &p1, const UtmCoordinate &p2)
|
inline double distance(const UtmCoordinate& p1, const UtmCoordinate& p2)
|
||||||
{
|
{
|
||||||
if (p1.zone != p2.zone)
|
if (p1.zone != p2.zone)
|
||||||
{
|
{
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return std::nan("");
|
return std::nan("");
|
||||||
}
|
}
|
||||||
return sqrt(squareDistance(p1, p2));
|
return sqrt(squareDistance(p1, p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT double distance(const QPointF &p1, const QPointF &p2);
|
LTSCOORDTRANS_EXPORT double distance(const QPointF& p1, const QPointF& p2);
|
||||||
|
|
||||||
inline double distance(const double lon1, const double lat1, const double lon2, const double lat2)
|
inline double distance(const double lon1, const double lat1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
return sqrt(squareDistance(lon1, lat1, lon2, lat2));
|
return sqrt(squareDistance(lon1, lat1, lon2, lat2));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double distance(const UtmCoordinate &p1, const double lon2, const double lat2)
|
inline double distance(const UtmCoordinate& p1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
return sqrt(squareDistance(p1, lon2, lat2));
|
return sqrt(squareDistance(p1, lon2, lat2));
|
||||||
}
|
}
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT void dumpConversionCounter();
|
LTSCOORDTRANS_EXPORT void dumpConversionCounter();
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Forward();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Forward();
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Reverse();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Reverse();
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_WGS84_Forward();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_WGS84_Forward();
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_WGS84_Reverse();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_WGS84_Reverse();
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Forward();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Forward();
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Reverse();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Reverse();
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT std::ostream &operator<<(std::ostream &stream, const UtmCoordinate &coord);
|
LTSCOORDTRANS_EXPORT std::ostream& operator<<(std::ostream& stream, const UtmCoordinate& coord);
|
||||||
|
|
||||||
class LTSCOORDTRANS_EXPORT UtmCoordinate3D : public LtsCoordTrans::UtmCoordinate
|
class LTSCOORDTRANS_EXPORT UtmCoordinate3D : public LtsCoordTrans::UtmCoordinate
|
||||||
{
|
{
|
||||||
using BaseClass = LtsCoordTrans::UtmCoordinate;
|
using BaseClass = LtsCoordTrans::UtmCoordinate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UtmCoordinate3D() { reset(); }
|
UtmCoordinate3D()
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
explicit UtmCoordinate3D(const LtsCoordTrans::UtmCoordinate &utm2d, double _zValue = std::nan(""))
|
explicit UtmCoordinate3D(const LtsCoordTrans::UtmCoordinate& utm2d, double _zValue = std::nan("")) : BaseClass()
|
||||||
: BaseClass()
|
|
||||||
{
|
{
|
||||||
zone = utm2d.zone;
|
zone = utm2d.zone;
|
||||||
northp = utm2d.northp;
|
northp = utm2d.northp;
|
||||||
@@ -174,10 +185,13 @@ namespace LtsCoordTrans
|
|||||||
zValue = std::nan("");
|
zValue = std::nan("");
|
||||||
}
|
}
|
||||||
|
|
||||||
double z() const { return zValue; }
|
double z() const
|
||||||
|
{
|
||||||
|
return zValue;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double zValue{std::nan("")};
|
double zValue{std::nan("")};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsCoordTrans
|
} // namespace LtsCoordTrans
|
||||||
+76
-90
@@ -77,7 +77,8 @@ void coordtrans_test::testRelativeMetricalOffet()
|
|||||||
QFETCH(QPoint, offset);
|
QFETCH(QPoint, offset);
|
||||||
QFETCH(QString, correctMgrs);
|
QFETCH(QString, correctMgrs);
|
||||||
|
|
||||||
const LtsCoordTrans::UtmCoordinate &utmRef = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 99990 99990"));
|
const LtsCoordTrans::UtmCoordinate& utmRef =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 99990 99990"));
|
||||||
qDebug() << "utmRef = " << utmRef.mgrs();
|
qDebug() << "utmRef = " << utmRef.mgrs();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -98,11 +99,12 @@ void coordtrans_test::testRelativeMetricalOffet()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF createArea(const QString &base, int xCenter, int yCenter, int width, int height)
|
QRectF createArea(const QString& base, int xCenter, int yCenter, int width, int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
||||||
LtsCoordTrans::UtmCoordinate utmBase(LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
LtsCoordTrans::UtmCoordinate utmBase(
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
||||||
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
||||||
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||||
|
|
||||||
@@ -118,10 +120,13 @@ void coordtrans_test::testAddMarginToArea()
|
|||||||
QRectF area = createArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000);
|
QRectF area = createArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000);
|
||||||
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(5000, 20000));
|
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(5000, 20000));
|
||||||
|
|
||||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft() << " - degree:" << area.topLeft() * LtsCoordTrans::rad2deg();
|
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft()
|
||||||
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft() << " - degree:" << area1Increased.topLeft() * LtsCoordTrans::rad2deg();
|
<< " - degree:" << area.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft()
|
||||||
|
<< " - degree:" << area1Increased.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
|
||||||
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight() << " - degree:" << area.bottomRight() * LtsCoordTrans::rad2deg();
|
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight()
|
||||||
|
<< " - degree:" << area.bottomRight() * LtsCoordTrans::rad2deg();
|
||||||
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight()
|
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight()
|
||||||
<< " - degree:" << area1Increased.bottomRight() * LtsCoordTrans::rad2deg();
|
<< " - degree:" << area1Increased.bottomRight() * LtsCoordTrans::rad2deg();
|
||||||
|
|
||||||
@@ -137,10 +142,13 @@ void coordtrans_test::testAddMarginToArea()
|
|||||||
QRectF area = createArea(QStringLiteral("32U LA 0000000000"), 100, 100, 5000, 5000);
|
QRectF area = createArea(QStringLiteral("32U LA 0000000000"), 100, 100, 5000, 5000);
|
||||||
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(50000, 20000));
|
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(50000, 20000));
|
||||||
|
|
||||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft() << " - degree:" << area.topLeft() * LtsCoordTrans::rad2deg();
|
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft()
|
||||||
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft() << " - degree:" << area1Increased.topLeft() * LtsCoordTrans::rad2deg();
|
<< " - degree:" << area.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft()
|
||||||
|
<< " - degree:" << area1Increased.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
|
||||||
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight() << " - degree:" << area.bottomRight() * LtsCoordTrans::rad2deg();
|
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight()
|
||||||
|
<< " - degree:" << area.bottomRight() * LtsCoordTrans::rad2deg();
|
||||||
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight()
|
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight()
|
||||||
<< " - degree:" << area1Increased.bottomRight() * LtsCoordTrans::rad2deg();
|
<< " - degree:" << area1Increased.bottomRight() * LtsCoordTrans::rad2deg();
|
||||||
|
|
||||||
@@ -159,7 +167,8 @@ void coordtrans_test::testIncreaseRect()
|
|||||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(lonlat.x(), lonlat.y(), 9);
|
QString mgrs = LtsCoordTrans::mgrsFromGeographic(lonlat.x(), lonlat.y(), 9);
|
||||||
QCOMPARE(mgrs, QStringLiteral("32U MD 745000000 840000000"));
|
QCOMPARE(mgrs, QStringLiteral("32U MD 745000000 840000000"));
|
||||||
|
|
||||||
const LtsCoordTrans::UtmCoordinate centerPoint = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
const LtsCoordTrans::UtmCoordinate centerPoint =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
||||||
|
|
||||||
LtsCoordTrans::UtmCoordinate topLeftUtm;
|
LtsCoordTrans::UtmCoordinate topLeftUtm;
|
||||||
LtsCoordTrans::UtmCoordinate topLeftUtm2;
|
LtsCoordTrans::UtmCoordinate topLeftUtm2;
|
||||||
@@ -169,9 +178,11 @@ void coordtrans_test::testIncreaseRect()
|
|||||||
QPointF bottomRightGeo = centerPoint.geographic(3000, -4000);
|
QPointF bottomRightGeo = centerPoint.geographic(3000, -4000);
|
||||||
|
|
||||||
topLeftUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(topLeftGeo);
|
topLeftUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(topLeftGeo);
|
||||||
const LtsCoordTrans::UtmCoordinate bottomRightUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(bottomRightGeo);
|
const LtsCoordTrans::UtmCoordinate bottomRightUtm =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(bottomRightGeo);
|
||||||
qDebug() << "topLeftUtm: " << topLeftUtm.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm.y;
|
qDebug() << "topLeftUtm: " << topLeftUtm.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm.y;
|
||||||
qDebug() << "bottomRightUtm: " << bottomRightUtm.x << " - " << qSetRealNumberPrecision(15) << bottomRightUtm.y;
|
qDebug() << "bottomRightUtm: " << bottomRightUtm.x << " - " << qSetRealNumberPrecision(15)
|
||||||
|
<< bottomRightUtm.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -183,7 +194,8 @@ void coordtrans_test::testIncreaseRect()
|
|||||||
bottomRightUtm2.y = centerPoint.y - 4000;
|
bottomRightUtm2.y = centerPoint.y - 4000;
|
||||||
|
|
||||||
qDebug() << "topLeftUtm2: " << topLeftUtm2.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm2.y;
|
qDebug() << "topLeftUtm2: " << topLeftUtm2.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm2.y;
|
||||||
qDebug() << "bottomRightUtm2: " << bottomRightUtm2.x << " - " << qSetRealNumberPrecision(15) << bottomRightUtm2.y;
|
qDebug() << "bottomRightUtm2: " << bottomRightUtm2.x << " - " << qSetRealNumberPrecision(15)
|
||||||
|
<< bottomRightUtm2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY2(qFuzzyCompare(topLeftUtm.x, topLeftUtm2.x), "testIncreaseRect x failed");
|
QVERIFY2(qFuzzyCompare(topLeftUtm.x, topLeftUtm2.x), "testIncreaseRect x failed");
|
||||||
@@ -201,7 +213,8 @@ void coordtrans_test::testIncreaseRect2()
|
|||||||
QRectF myRectIncreased;
|
QRectF myRectIncreased;
|
||||||
|
|
||||||
{
|
{
|
||||||
const LtsCoordTrans::UtmCoordinate centerPoint = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
const LtsCoordTrans::UtmCoordinate centerPoint =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
||||||
|
|
||||||
QPointF topLeftGeo = centerPoint.geographic(-3000, 2000);
|
QPointF topLeftGeo = centerPoint.geographic(-3000, 2000);
|
||||||
QPointF bottomRightGeo = centerPoint.geographic(3000, -2000);
|
QPointF bottomRightGeo = centerPoint.geographic(3000, -2000);
|
||||||
@@ -226,8 +239,10 @@ void coordtrans_test::testIncreaseRect2()
|
|||||||
qDebug() << "myRectIncreased height: " << myRectIncreased.height();
|
qDebug() << "myRectIncreased height: " << myRectIncreased.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY2((int)(myRectIncreased.center().x() * 10000) == (int)(myRect.center().x() * 10000), "testIncreaseRect2 centerX failed");
|
QVERIFY2((int)(myRectIncreased.center().x() * 10000) == (int)(myRect.center().x() * 10000),
|
||||||
QVERIFY2((int)(myRectIncreased.center().y() * 10000) == (int)(myRect.center().y() * 10000), "testIncreaseRect2 centerY failed");
|
"testIncreaseRect2 centerX failed");
|
||||||
|
QVERIFY2((int)(myRectIncreased.center().y() * 10000) == (int)(myRect.center().y() * 10000),
|
||||||
|
"testIncreaseRect2 centerY failed");
|
||||||
|
|
||||||
QVERIFY2(myRectIncreased.width() > myRect.width(), "testIncreaseRect2 width failed");
|
QVERIFY2(myRectIncreased.width() > myRect.width(), "testIncreaseRect2 width failed");
|
||||||
QVERIFY2(myRectIncreased.height() > myRect.height(), "testIncreaseRect2 height failed");
|
QVERIFY2(myRectIncreased.height() > myRect.height(), "testIncreaseRect2 height failed");
|
||||||
@@ -245,84 +260,50 @@ void coordtrans_test::testGeographicFromMgrs()
|
|||||||
void coordtrans_test::testMgrsSquares()
|
void coordtrans_test::testMgrsSquares()
|
||||||
{
|
{
|
||||||
|
|
||||||
checkArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000, {QStringLiteral("32U PC"), QStringLiteral("32U PD")});
|
checkArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000,
|
||||||
checkArea(QStringLiteral("32U MD 0000000000"), 50000, 10000, 30000, 30000, {QStringLiteral("32U MC"), QStringLiteral("32U MD")});
|
{QStringLiteral("32U PC"), QStringLiteral("32U PD")});
|
||||||
checkArea(QStringLiteral("32U MD 0000000000"),
|
checkArea(QStringLiteral("32U MD 0000000000"), 50000, 10000, 30000, 30000,
|
||||||
89999,
|
{QStringLiteral("32U MC"), QStringLiteral("32U MD")});
|
||||||
89999,
|
checkArea(QStringLiteral("32U MD 0000000000"), 89999, 89999, 21000, 21000,
|
||||||
21000,
|
|
||||||
21000,
|
|
||||||
{QStringLiteral("32U MD"), QStringLiteral("32U ME"), QStringLiteral("32U ND"), QStringLiteral("32U NE")});
|
{QStringLiteral("32U MD"), QStringLiteral("32U ME"), QStringLiteral("32U ND"), QStringLiteral("32U NE")});
|
||||||
|
|
||||||
checkArea(QStringLiteral("39Q XG 0000000000"), 40000, 35000, 60000, 70000, {QStringLiteral("39Q XG"), QStringLiteral("39R XG")});
|
checkArea(QStringLiteral("39Q XG 0000000000"), 40000, 35000, 60000, 70000,
|
||||||
|
{QStringLiteral("39Q XG"), QStringLiteral("39R XG")});
|
||||||
checkArea(QStringLiteral("40R CP 0000000000"), 94000, 9000, 7000, 16000, {QStringLiteral("40R CP")});
|
checkArea(QStringLiteral("40R CP 0000000000"), 94000, 9000, 7000, 16000, {QStringLiteral("40R CP")});
|
||||||
checkArea(QStringLiteral("40R DN 0000000000"), 500, 95500, 12000, 7000, {QStringLiteral("40R CN"), QStringLiteral("40R DN")});
|
checkArea(QStringLiteral("40R DN 0000000000"), 500, 95500, 12000, 7000,
|
||||||
checkArea(QStringLiteral("40R DN 0000000000"),
|
{QStringLiteral("40R CN"), QStringLiteral("40R DN")});
|
||||||
500,
|
checkArea(QStringLiteral("40R DN 0000000000"), 500, 96760, 30000, 30000,
|
||||||
96760,
|
|
||||||
30000,
|
|
||||||
30000,
|
|
||||||
{QStringLiteral("40R CN"), QStringLiteral("40R CP"), QStringLiteral("40R DN"), QStringLiteral("40R DP")});
|
{QStringLiteral("40R CN"), QStringLiteral("40R CP"), QStringLiteral("40R DN"), QStringLiteral("40R DP")});
|
||||||
checkArea(QStringLiteral("40R BM 0000000000"), 59000, 59500, 46000, 40000, {QStringLiteral("40Q BM"), QStringLiteral("40R BM")});
|
checkArea(QStringLiteral("40R BM 0000000000"), 59000, 59500, 46000, 40000,
|
||||||
|
{QStringLiteral("40Q BM"), QStringLiteral("40R BM")});
|
||||||
|
|
||||||
checkArea(QStringLiteral("32U LA 0000000000"),
|
checkArea(QStringLiteral("32U LA 0000000000"), 10000, 10000, 5000, 5000,
|
||||||
10000,
|
|
||||||
10000,
|
|
||||||
5000,
|
|
||||||
5000,
|
|
||||||
{
|
{
|
||||||
QStringLiteral("32U LA"),
|
QStringLiteral("32U LA"),
|
||||||
});
|
});
|
||||||
|
|
||||||
checkArea(QStringLiteral("32U LA 0000000000"),
|
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 60000, 60000,
|
||||||
100,
|
{QStringLiteral("31U GQ"), QStringLiteral("31U GR"), QStringLiteral("32U KA"), QStringLiteral("32U KV"),
|
||||||
100,
|
QStringLiteral("32U LA"), QStringLiteral("32U LV")});
|
||||||
60000,
|
|
||||||
60000,
|
|
||||||
{QStringLiteral("31U GQ"), QStringLiteral("31U GR"), QStringLiteral("32U KA"), QStringLiteral("32U KV"), QStringLiteral("32U LA"), QStringLiteral("32U LV")});
|
|
||||||
|
|
||||||
checkArea(QStringLiteral("32U LA 0000000000"),
|
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 150000, 150000,
|
||||||
100,
|
{QStringLiteral("31U FQ"), QStringLiteral("31U FR"), QStringLiteral("31U GQ"), QStringLiteral("31U GR"),
|
||||||
100,
|
QStringLiteral("32U KA"), QStringLiteral("32U KV"), QStringLiteral("32U LA"), QStringLiteral("32U LV")});
|
||||||
150000,
|
|
||||||
150000,
|
|
||||||
{QStringLiteral("31U FQ"),
|
|
||||||
QStringLiteral("31U FR"),
|
|
||||||
QStringLiteral("31U GQ"),
|
|
||||||
QStringLiteral("31U GR"),
|
|
||||||
QStringLiteral("32U KA"),
|
|
||||||
QStringLiteral("32U KV"),
|
|
||||||
QStringLiteral("32U LA"),
|
|
||||||
QStringLiteral("32U LV")});
|
|
||||||
|
|
||||||
checkArea(QStringLiteral("32U LA 0000000000"),
|
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 200000, 200000,
|
||||||
100,
|
{QStringLiteral("31U FP"), QStringLiteral("31U FQ"), QStringLiteral("31U FR"), QStringLiteral("31U GP"),
|
||||||
100,
|
QStringLiteral("31U GQ"), QStringLiteral("31U GR"), QStringLiteral("31U GS"), QStringLiteral("32U KA"),
|
||||||
200000,
|
QStringLiteral("32U KB"), QStringLiteral("32U KV"), QStringLiteral("32U LA"), QStringLiteral("32U LB"),
|
||||||
200000,
|
QStringLiteral("32U LV"), QStringLiteral("32U MA"), QStringLiteral("32U MB"), QStringLiteral("32U MV")});
|
||||||
{QStringLiteral("31U FP"),
|
|
||||||
QStringLiteral("31U FQ"),
|
|
||||||
QStringLiteral("31U FR"),
|
|
||||||
QStringLiteral("31U GP"),
|
|
||||||
QStringLiteral("31U GQ"),
|
|
||||||
QStringLiteral("31U GR"),
|
|
||||||
QStringLiteral("31U GS"),
|
|
||||||
QStringLiteral("32U KA"),
|
|
||||||
QStringLiteral("32U KB"),
|
|
||||||
QStringLiteral("32U KV"),
|
|
||||||
QStringLiteral("32U LA"),
|
|
||||||
QStringLiteral("32U LB"),
|
|
||||||
QStringLiteral("32U LV"),
|
|
||||||
QStringLiteral("32U MA"),
|
|
||||||
QStringLiteral("32U MB"),
|
|
||||||
QStringLiteral("32U MV")});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> checkAreaGetMgrsSquares(const QString &base, int xCenter, int yCenter, int width, int height)
|
QVector<LtsCoordTrans::UtmCoordinate> checkAreaGetMgrsSquares(const QString& base, int xCenter, int yCenter, int width,
|
||||||
|
int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
||||||
LtsCoordTrans::UtmCoordinate utmBase(LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
LtsCoordTrans::UtmCoordinate utmBase(
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
||||||
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
||||||
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||||
|
|
||||||
@@ -330,7 +311,7 @@ QVector<LtsCoordTrans::UtmCoordinate> checkAreaGetMgrsSquares(const QString &bas
|
|||||||
|
|
||||||
QStringList src;
|
QStringList src;
|
||||||
src.reserve(squares.size());
|
src.reserve(squares.size());
|
||||||
for (const auto &utm : squares)
|
for (const auto& utm : squares)
|
||||||
src += utm.mgrs(0);
|
src += utm.mgrs(0);
|
||||||
src.sort();
|
src.sort();
|
||||||
|
|
||||||
@@ -342,39 +323,42 @@ void coordtrans_test::testMgrsSquaresWithSurrounding()
|
|||||||
|
|
||||||
int initialSize = 5000;
|
int initialSize = 5000;
|
||||||
|
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> squares1 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, initialSize, initialSize);
|
QVector<LtsCoordTrans::UtmCoordinate> squares1 =
|
||||||
|
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, initialSize, initialSize);
|
||||||
|
|
||||||
QVERIFY2(squares1.size() == 1, "checkAreaGetMgrsSquares failed");
|
QVERIFY2(squares1.size() == 1, "checkAreaGetMgrsSquares failed");
|
||||||
|
|
||||||
int biggerSize = initialSize + (1 * 110000);
|
int biggerSize = initialSize + (1 * 110000);
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> squares9 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, biggerSize, biggerSize);
|
QVector<LtsCoordTrans::UtmCoordinate> squares9 =
|
||||||
|
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, biggerSize, biggerSize);
|
||||||
|
|
||||||
QVERIFY2(squares9.size() == 9, "checkAreaGetMgrsSquares biggerSize failed");
|
QVERIFY2(squares9.size() == 9, "checkAreaGetMgrsSquares biggerSize failed");
|
||||||
|
|
||||||
int muchBiggerSize = initialSize + (3 * 110000);
|
int muchBiggerSize = initialSize + (3 * 110000);
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> square33 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, muchBiggerSize, muchBiggerSize);
|
QVector<LtsCoordTrans::UtmCoordinate> square33 =
|
||||||
|
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, muchBiggerSize, muchBiggerSize);
|
||||||
|
|
||||||
QVERIFY2(square33.size() == 33, "checkAreaGetMgrsSquares muchBiggerSize failed");
|
QVERIFY2(square33.size() == 33, "checkAreaGetMgrsSquares muchBiggerSize failed");
|
||||||
|
|
||||||
QStringList string1;
|
QStringList string1;
|
||||||
string1.reserve(squares1.size());
|
string1.reserve(squares1.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &item : std::as_const(squares1))
|
for (const LtsCoordTrans::UtmCoordinate& item : std::as_const(squares1))
|
||||||
string1.append(item.mgrs(0));
|
string1.append(item.mgrs(0));
|
||||||
|
|
||||||
QStringList string9;
|
QStringList string9;
|
||||||
string9.reserve(squares9.size());
|
string9.reserve(squares9.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &item : std::as_const(squares9))
|
for (const LtsCoordTrans::UtmCoordinate& item : std::as_const(squares9))
|
||||||
string9.append(item.mgrs(0));
|
string9.append(item.mgrs(0));
|
||||||
|
|
||||||
QStringList string33;
|
QStringList string33;
|
||||||
string33.reserve(square33.size());
|
string33.reserve(square33.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &item : std::as_const(square33))
|
for (const LtsCoordTrans::UtmCoordinate& item : std::as_const(square33))
|
||||||
string33.append(item.mgrs(0));
|
string33.append(item.mgrs(0));
|
||||||
|
|
||||||
{
|
{
|
||||||
QStringList surroundingStrings;
|
QStringList surroundingStrings;
|
||||||
surroundingStrings.reserve(squares9.size());
|
surroundingStrings.reserve(squares9.size());
|
||||||
for (const QString &str : std::as_const(string9))
|
for (const QString& str : std::as_const(string9))
|
||||||
if (!string1.contains(str))
|
if (!string1.contains(str))
|
||||||
surroundingStrings.append(str);
|
surroundingStrings.append(str);
|
||||||
|
|
||||||
@@ -384,7 +368,7 @@ void coordtrans_test::testMgrsSquaresWithSurrounding()
|
|||||||
{
|
{
|
||||||
QStringList surroundingStrings;
|
QStringList surroundingStrings;
|
||||||
surroundingStrings.reserve(string33.size());
|
surroundingStrings.reserve(string33.size());
|
||||||
for (const QString &str : std::as_const(string33))
|
for (const QString& str : std::as_const(string33))
|
||||||
if (!string1.contains(str))
|
if (!string1.contains(str))
|
||||||
surroundingStrings.append(str);
|
surroundingStrings.append(str);
|
||||||
|
|
||||||
@@ -392,11 +376,13 @@ void coordtrans_test::testMgrsSquaresWithSurrounding()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void coordtrans_test::checkArea(const QString &base, int xCenter, int yCenter, int width, int height, const QStringList &coords)
|
void coordtrans_test::checkArea(const QString& base, int xCenter, int yCenter, int width, int height,
|
||||||
|
const QStringList& coords)
|
||||||
{
|
{
|
||||||
qDebug() << "checkArea : base: " << base;
|
qDebug() << "checkArea : base: " << base;
|
||||||
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
||||||
LtsCoordTrans::UtmCoordinate utmBase(LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
LtsCoordTrans::UtmCoordinate utmBase(
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
||||||
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
||||||
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||||
qDebug() << "TopLeft: " << topLeft * LtsCoordTrans::rad2deg();
|
qDebug() << "TopLeft: " << topLeft * LtsCoordTrans::rad2deg();
|
||||||
@@ -406,7 +392,7 @@ void coordtrans_test::checkArea(const QString &base, int xCenter, int yCenter, i
|
|||||||
|
|
||||||
QStringList src;
|
QStringList src;
|
||||||
src.reserve(squares.size());
|
src.reserve(squares.size());
|
||||||
for (const auto &utm : squares)
|
for (const auto& utm : squares)
|
||||||
src += utm.mgrs(0);
|
src += utm.mgrs(0);
|
||||||
src.sort();
|
src.sort();
|
||||||
qDebug() << "src: '" << src << "' expected: '" << coords << "'";
|
qDebug() << "src: '" << src << "' expected: '" << coords << "'";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
class coordtrans_test : public QObject
|
class coordtrans_test : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
void testFromGeographic();
|
void testFromGeographic();
|
||||||
@@ -26,6 +26,6 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
void testMgrsSquaresWithSurrounding();
|
void testMgrsSquaresWithSurrounding();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkArea(const QString &base, int xCenter, int yCenter, int width, int height, const QStringList &coords);
|
void checkArea(const QString& base, int xCenter, int yCenter, int width, int height, const QStringList& coords);
|
||||||
};
|
};
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* An Input Widget for coordinates
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-09-08
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_coord_widget.h"
|
#include "lts_coord_widget.h"
|
||||||
|
|
||||||
@@ -10,118 +18,116 @@
|
|||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsCoordWidget::LtsCoordWidget(DisplayType dt, QWidget *parent)
|
LtsCoordWidget::LtsCoordWidget(DisplayType dt, QWidget* parent) : QWidget(parent), m_displayType(dt)
|
||||||
: QWidget(parent)
|
{
|
||||||
, m_displayType(dt)
|
|
||||||
{
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
rebuildUi();
|
rebuildUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setCoordinate(const QPointF &geoCoord, bool bUseAsDefaultValue)
|
void LtsCoordWidget::setCoordinate(const QPointF& geoCoord, bool bUseAsDefaultValue)
|
||||||
{
|
{
|
||||||
if (m_coordinate != geoCoord)
|
if (m_coordinate != geoCoord)
|
||||||
emit coordinateChanged(geoCoord);
|
emit coordinateChanged(geoCoord);
|
||||||
if (bUseAsDefaultValue)
|
if (bUseAsDefaultValue)
|
||||||
m_defaultCoordinate = geoCoord;
|
m_defaultCoordinate = geoCoord;
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->setCoordinate(geoCoord);
|
m_inputWidgetHandler->setCoordinate(geoCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::clear()
|
void LtsCoordWidget::clear()
|
||||||
{
|
{
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->clear();
|
m_inputWidgetHandler->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setCoordinate(double lon, double lat, bool bUseAsDefaultValue)
|
void LtsCoordWidget::setCoordinate(double lon, double lat, bool bUseAsDefaultValue)
|
||||||
{
|
{
|
||||||
setCoordinate(QPointF(lon, lat), bUseAsDefaultValue);
|
setCoordinate(QPointF(lon, lat), bUseAsDefaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF LtsCoordWidget::coordinate() const
|
QPointF LtsCoordWidget::coordinate() const
|
||||||
{
|
{
|
||||||
if (!m_inputWidgetHandler)
|
if (!m_inputWidgetHandler)
|
||||||
return QPointF();
|
return QPointF();
|
||||||
return m_inputWidgetHandler->coordinate();
|
return m_inputWidgetHandler->coordinate();
|
||||||
}
|
}
|
||||||
|
|
||||||
LtsCoordWidget::DisplayType LtsCoordWidget::displayType() const
|
LtsCoordWidget::DisplayType LtsCoordWidget::displayType() const
|
||||||
{
|
{
|
||||||
return m_displayType;
|
return m_displayType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setDisplayType(LtsCoordWidget::DisplayType dt)
|
void LtsCoordWidget::setDisplayType(LtsCoordWidget::DisplayType dt)
|
||||||
{
|
{
|
||||||
if (m_displayType == dt)
|
if (m_displayType == dt)
|
||||||
return;
|
return;
|
||||||
m_displayType = dt;
|
m_displayType = dt;
|
||||||
rebuildUi();
|
rebuildUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCoordWidget::withResetButton() const
|
bool LtsCoordWidget::withResetButton() const
|
||||||
{
|
{
|
||||||
return m_bWithResetButton;
|
return m_bWithResetButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setWithResetButton(bool bWith)
|
void LtsCoordWidget::setWithResetButton(bool bWith)
|
||||||
{
|
{
|
||||||
if (m_bWithResetButton == bWith)
|
if (m_bWithResetButton == bWith)
|
||||||
return;
|
return;
|
||||||
m_bWithResetButton = bWith;
|
m_bWithResetButton = bWith;
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCoordWidget::showToolTip() const
|
bool LtsCoordWidget::showToolTip() const
|
||||||
{
|
{
|
||||||
return m_bShowToolTip;
|
return m_bShowToolTip;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setShowToolTip(bool bShow)
|
void LtsCoordWidget::setShowToolTip(bool bShow)
|
||||||
{
|
{
|
||||||
if (m_bShowToolTip == bShow)
|
if (m_bShowToolTip == bShow)
|
||||||
return;
|
return;
|
||||||
m_bShowToolTip = bShow;
|
m_bShowToolTip = bShow;
|
||||||
|
|
||||||
updateToolTip();
|
updateToolTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCoordWidget::mgrsSquareEditable() const
|
bool LtsCoordWidget::mgrsSquareEditable() const
|
||||||
{
|
{
|
||||||
return m_bMgrsSquareEditable;
|
return m_bMgrsSquareEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setMgrsSquareEditable(bool bEditable)
|
void LtsCoordWidget::setMgrsSquareEditable(bool bEditable)
|
||||||
{
|
{
|
||||||
if (m_bMgrsSquareEditable == bEditable)
|
if (m_bMgrsSquareEditable == bEditable)
|
||||||
return;
|
return;
|
||||||
m_bMgrsSquareEditable = bEditable;
|
m_bMgrsSquareEditable = bEditable;
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->setSquaresEditable(bEditable);
|
m_inputWidgetHandler->setSquaresEditable(bEditable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setWithSurroundingMgrsSquares(bool bEnable)
|
void LtsCoordWidget::setWithSurroundingMgrsSquares(bool bEnable)
|
||||||
{
|
{
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->setWithSurroundingSquare(bEnable);
|
m_inputWidgetHandler->setWithSurroundingSquare(bEnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords)
|
void LtsCoordWidget::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords)
|
||||||
{
|
{
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->setMgrsSquares(geoCoords);
|
m_inputWidgetHandler->setMgrsSquares(geoCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LtsCoordWidget::event(QEvent *event)
|
bool LtsCoordWidget::event(QEvent* event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::ToolTip)
|
if (event->type() == QEvent::ToolTip)
|
||||||
updateToolTip();
|
updateToolTip();
|
||||||
return QWidget::event(event);
|
return QWidget::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::rebuildUi()
|
void LtsCoordWidget::rebuildUi()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
{
|
{
|
||||||
@@ -151,15 +157,18 @@ namespace LtsCoordWidget
|
|||||||
|
|
||||||
m_inputWidgetHandler->setSquaresEditable(m_bMgrsSquareEditable);
|
m_inputWidgetHandler->setSquaresEditable(m_bMgrsSquareEditable);
|
||||||
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
||||||
connect(m_inputWidgetHandler->resetButton(), &QToolButton::clicked, this, &LtsCoordWidget::onResetToDefaultCoordinate);
|
connect(m_inputWidgetHandler->resetButton(), &QToolButton::clicked, this,
|
||||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::coordinateChanged, this, &LtsCoordWidget::coordinateChanged);
|
&LtsCoordWidget::onResetToDefaultCoordinate);
|
||||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::invalidCoordinate, this, &LtsCoordWidget::invalidCoordinate);
|
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::coordinateChanged, this,
|
||||||
|
&LtsCoordWidget::coordinateChanged);
|
||||||
|
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::invalidCoordinate, this,
|
||||||
|
&LtsCoordWidget::invalidCoordinate);
|
||||||
if (!m_defaultCoordinate.isNull())
|
if (!m_defaultCoordinate.isNull())
|
||||||
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::updateToolTip()
|
void LtsCoordWidget::updateToolTip()
|
||||||
{
|
{
|
||||||
QString tt;
|
QString tt;
|
||||||
if (m_bShowToolTip)
|
if (m_bShowToolTip)
|
||||||
{
|
{
|
||||||
@@ -172,15 +181,15 @@ namespace LtsCoordWidget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setToolTip(tt);
|
setToolTip(tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::onResetToDefaultCoordinate()
|
void LtsCoordWidget::onResetToDefaultCoordinate()
|
||||||
{
|
{
|
||||||
if (!m_inputWidgetHandler)
|
if (!m_inputWidgetHandler)
|
||||||
return;
|
return;
|
||||||
if (m_defaultCoordinate.isNull())
|
if (m_defaultCoordinate.isNull())
|
||||||
m_inputWidgetHandler->clear();
|
m_inputWidgetHandler->clear();
|
||||||
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsCoordWidget
|
} // namespace LtsCoordWidget
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* An Input Widget for coordinates
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-09-08
|
||||||
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||||
#include <LtsCoordTrans/ltscoordwidget_export.h>
|
#include <LtsCoordTrans/ltscoordwidget_export.h>
|
||||||
@@ -10,53 +17,43 @@ class QToolButton;
|
|||||||
|
|
||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
class LtsCoordInputWidgetHandler;
|
class LtsCoordInputWidgetHandler;
|
||||||
|
|
||||||
class LTSCOORDWIDGET_EXPORT LtsCoordWidget : public QWidget
|
class LTSCOORDWIDGET_EXPORT LtsCoordWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum class DisplayType
|
enum class DisplayType { MGRS5, MGRS7, UTM, WGS84, MGRS = DisplayType::MGRS5 };
|
||||||
{
|
|
||||||
MGRS5,
|
|
||||||
MGRS7,
|
|
||||||
UTM,
|
|
||||||
WGS84,
|
|
||||||
MGRS = DisplayType::MGRS5
|
|
||||||
};
|
|
||||||
Q_ENUM(DisplayType)
|
Q_ENUM(DisplayType)
|
||||||
Q_PROPERTY(DisplayType displayType READ displayType WRITE setDisplayType)
|
Q_PROPERTY(DisplayType displayType READ displayType WRITE setDisplayType)
|
||||||
Q_PROPERTY(bool withResetButton READ withResetButton WRITE setWithResetButton)
|
Q_PROPERTY(bool withResetButton READ withResetButton WRITE setWithResetButton)
|
||||||
Q_PROPERTY(bool showToolTip READ showToolTip WRITE setShowToolTip)
|
Q_PROPERTY(bool showToolTip READ showToolTip WRITE setShowToolTip)
|
||||||
Q_PROPERTY(bool mgrsSquareEditable READ mgrsSquareEditable WRITE setMgrsSquareEditable)
|
Q_PROPERTY(bool mgrsSquareEditable READ mgrsSquareEditable WRITE setMgrsSquareEditable)
|
||||||
|
|
||||||
explicit LtsCoordWidget(QWidget *parent = nullptr)
|
explicit LtsCoordWidget(QWidget* parent = nullptr) : LtsCoordWidget(LtsCoordWidget::DisplayType::MGRS, parent) {}
|
||||||
: LtsCoordWidget(LtsCoordWidget::DisplayType::MGRS, parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit LtsCoordWidget(DisplayType dt, QWidget *parent = nullptr);
|
explicit LtsCoordWidget(DisplayType dt, QWidget* parent = nullptr);
|
||||||
|
|
||||||
QPointF coordinate() const;
|
QPointF coordinate() const;
|
||||||
DisplayType displayType() const;
|
DisplayType displayType() const;
|
||||||
bool withResetButton() const;
|
bool withResetButton() const;
|
||||||
bool showToolTip() const;
|
bool showToolTip() const;
|
||||||
bool mgrsSquareEditable() const;
|
bool mgrsSquareEditable() const;
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent* event) override;
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
|
||||||
void setCoordinate(const QPointF &geoCoord, bool bUseAsDefaultValue = true);
|
void setCoordinate(const QPointF& geoCoord, bool bUseAsDefaultValue = true);
|
||||||
void setCoordinate(double lon, double lat, bool bUseAsDefaultValue = true);
|
void setCoordinate(double lon, double lat, bool bUseAsDefaultValue = true);
|
||||||
void setDisplayType(LtsCoordWidget::DisplayType dt);
|
void setDisplayType(LtsCoordWidget::DisplayType dt);
|
||||||
void setWithResetButton(bool bWith);
|
void setWithResetButton(bool bWith);
|
||||||
void setShowToolTip(bool bShow);
|
void setShowToolTip(bool bShow);
|
||||||
void setMgrsSquareEditable(bool bEditable);
|
void setMgrsSquareEditable(bool bEditable);
|
||||||
void setWithSurroundingMgrsSquares(bool bEnable);
|
void setWithSurroundingMgrsSquares(bool bEnable);
|
||||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords);
|
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void coordinateChanged(const QPointF &newGeoCoord);
|
void coordinateChanged(const QPointF& newGeoCoord);
|
||||||
void invalidCoordinate();
|
void invalidCoordinate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -70,8 +67,8 @@ namespace LtsCoordWidget
|
|||||||
bool m_bShowToolTip = true;
|
bool m_bShowToolTip = true;
|
||||||
bool m_bMgrsSquareEditable = false;
|
bool m_bMgrsSquareEditable = false;
|
||||||
LtsCoordWidget::DisplayType m_displayType = LtsCoordWidget::DisplayType::MGRS;
|
LtsCoordWidget::DisplayType m_displayType = LtsCoordWidget::DisplayType::MGRS;
|
||||||
LtsCoordInputWidgetHandler *m_inputWidgetHandler = nullptr;
|
LtsCoordInputWidgetHandler* m_inputWidgetHandler = nullptr;
|
||||||
QPointF m_coordinate;
|
QPointF m_coordinate;
|
||||||
QPointF m_defaultCoordinate;
|
QPointF m_defaultCoordinate;
|
||||||
};
|
};
|
||||||
} // namespace LtsCoordWidget
|
} // namespace LtsCoordWidget
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* An Input Widget for coordinates
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-09-08
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_coord_widget_p.h"
|
#include "lts_coord_widget_p.h"
|
||||||
|
|
||||||
@@ -7,8 +15,8 @@
|
|||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
|
|
||||||
void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
||||||
{
|
{
|
||||||
const QPointF coord(coordinate());
|
const QPointF coord(coordinate());
|
||||||
if (coord.isNull())
|
if (coord.isNull())
|
||||||
{
|
{
|
||||||
@@ -16,13 +24,11 @@ namespace LtsCoordWidget
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit coordinateChanged(coord);
|
emit coordinateChanged(coord);
|
||||||
}
|
}
|
||||||
|
|
||||||
MgrsEdit::MgrsEdit(int precision, QWidget *widget)
|
MgrsEdit::MgrsEdit(int precision, QWidget* widget)
|
||||||
: LtsCoordInputWidgetHandler(widget)
|
: LtsCoordInputWidgetHandler(widget), m_precision(precision), m_ui(new Ui::Mgrs)
|
||||||
, m_precision(precision)
|
{
|
||||||
, m_ui(new Ui::Mgrs)
|
|
||||||
{
|
|
||||||
m_ui->setupUi(widget);
|
m_ui->setupUi(widget);
|
||||||
|
|
||||||
if (m_precision < 0)
|
if (m_precision < 0)
|
||||||
@@ -34,24 +40,25 @@ namespace LtsCoordWidget
|
|||||||
m_ui->leNorth->setValidator(new QIntValidator(0, upperLimit, m_ui->leNorth));
|
m_ui->leNorth->setValidator(new QIntValidator(0, upperLimit, m_ui->leNorth));
|
||||||
setDefaultMgrsSquares();
|
setDefaultMgrsSquares();
|
||||||
|
|
||||||
connect(m_ui->cbxZone, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MgrsEdit::onCoordinateDataChanged);
|
connect(m_ui->cbxZone, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||||
|
&MgrsEdit::onCoordinateDataChanged);
|
||||||
connect(m_ui->leEast, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
connect(m_ui->leEast, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
||||||
connect(m_ui->leNorth, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
connect(m_ui->leNorth, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
MgrsEdit::~MgrsEdit()
|
MgrsEdit::~MgrsEdit()
|
||||||
{
|
{
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MgrsEdit::isValid()
|
bool MgrsEdit::isValid()
|
||||||
{
|
{
|
||||||
|
|
||||||
const QString &east = m_ui->leEast->text();
|
const QString& east = m_ui->leEast->text();
|
||||||
if (east.size() != m_precision)
|
if (east.size() != m_precision)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QString &north = m_ui->leNorth->text();
|
const QString& north = m_ui->leNorth->text();
|
||||||
if (north.size() != m_precision)
|
if (north.size() != m_precision)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -62,10 +69,10 @@ namespace LtsCoordWidget
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setCoordinate(const QPointF &geoCoord)
|
void MgrsEdit::setCoordinate(const QPointF& geoCoord)
|
||||||
{
|
{
|
||||||
const QString mgrsString = LtsCoordTrans::mgrsFromGeographic(geoCoord.x(), geoCoord.y(), m_precision, false);
|
const QString mgrsString = LtsCoordTrans::mgrsFromGeographic(geoCoord.x(), geoCoord.y(), m_precision, false);
|
||||||
if (mgrsString.isEmpty())
|
if (mgrsString.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -89,10 +96,10 @@ namespace LtsCoordWidget
|
|||||||
m_ui->cbxZone->setCurrentIndex(idx);
|
m_ui->cbxZone->setCurrentIndex(idx);
|
||||||
m_ui->leEast->setText(east);
|
m_ui->leEast->setText(east);
|
||||||
m_ui->leNorth->setText(north);
|
m_ui->leNorth->setText(north);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QString getMgrsCoord(QLineEdit *le, int prec)
|
static inline QString getMgrsCoord(QLineEdit* le, int prec)
|
||||||
{
|
{
|
||||||
QString ret = le->text();
|
QString ret = le->text();
|
||||||
if (ret.isEmpty())
|
if (ret.isEmpty())
|
||||||
return ret;
|
return ret;
|
||||||
@@ -100,10 +107,10 @@ namespace LtsCoordWidget
|
|||||||
ret += QLatin1Char('0');
|
ret += QLatin1Char('0');
|
||||||
le->setText(ret);
|
le->setText(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF MgrsEdit::coordinate() const
|
QPointF MgrsEdit::coordinate() const
|
||||||
{
|
{
|
||||||
const QString east = getMgrsCoord(m_ui->leEast, m_precision);
|
const QString east = getMgrsCoord(m_ui->leEast, m_precision);
|
||||||
const QString north = getMgrsCoord(m_ui->leNorth, m_precision);
|
const QString north = getMgrsCoord(m_ui->leNorth, m_precision);
|
||||||
if (east.isEmpty() || north.isEmpty() || m_ui->cbxZone->currentIndex() < 0)
|
if (east.isEmpty() || north.isEmpty() || m_ui->cbxZone->currentIndex() < 0)
|
||||||
@@ -111,93 +118,93 @@ namespace LtsCoordWidget
|
|||||||
|
|
||||||
const QString mgrsString(m_ui->cbxZone->currentText() + east + north);
|
const QString mgrsString(m_ui->cbxZone->currentText() + east + north);
|
||||||
return LtsCoordTrans::geographicFromMgrs(mgrsString);
|
return LtsCoordTrans::geographicFromMgrs(mgrsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
QToolButton *MgrsEdit::resetButton()
|
QToolButton* MgrsEdit::resetButton()
|
||||||
{
|
{
|
||||||
return m_ui->tbReset;
|
return m_ui->tbReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::cleanup()
|
void MgrsEdit::cleanup()
|
||||||
{
|
{
|
||||||
|
|
||||||
delete m_ui->horizontalLayout;
|
delete m_ui->horizontalLayout;
|
||||||
delete m_ui->cbxZone;
|
delete m_ui->cbxZone;
|
||||||
delete m_ui->leEast;
|
delete m_ui->leEast;
|
||||||
delete m_ui->leNorth;
|
delete m_ui->leNorth;
|
||||||
delete m_ui->tbReset;
|
delete m_ui->tbReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::clear()
|
void MgrsEdit::clear()
|
||||||
{
|
{
|
||||||
m_ui->cbxZone->clear();
|
m_ui->cbxZone->clear();
|
||||||
m_ui->leEast->clear();
|
m_ui->leEast->clear();
|
||||||
m_ui->leNorth->clear();
|
m_ui->leNorth->clear();
|
||||||
setDefaultMgrsSquares();
|
setDefaultMgrsSquares();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setSquaresEditable(bool bEditable)
|
void MgrsEdit::setSquaresEditable(bool bEditable)
|
||||||
{
|
{
|
||||||
m_ui->cbxZone->setEditable(bEditable);
|
m_ui->cbxZone->setEditable(bEditable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setWithSurroundingSquare(bool bEnabled)
|
void MgrsEdit::setWithSurroundingSquare(bool bEnabled)
|
||||||
{
|
{
|
||||||
m_withMgrsSquareOffset = bEnabled;
|
m_withMgrsSquareOffset = bEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList defaultMgrsSquares()
|
static QStringList defaultMgrsSquares()
|
||||||
{
|
{
|
||||||
const QVector<LtsCoordTrans::UtmCoordinate> squares(LtsCoordTrans::defaultMgrsSquares());
|
const QVector<LtsCoordTrans::UtmCoordinate> squares(LtsCoordTrans::defaultMgrsSquares());
|
||||||
QStringList sl;
|
QStringList sl;
|
||||||
sl.reserve(squares.size());
|
sl.reserve(squares.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &c : squares)
|
for (const LtsCoordTrans::UtmCoordinate& c : squares)
|
||||||
sl += c.mgrs(0);
|
sl += c.mgrs(0);
|
||||||
std::sort(sl.begin(), sl.end());
|
std::sort(sl.begin(), sl.end());
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString preferedMgrsSquare()
|
static QString preferedMgrsSquare()
|
||||||
{
|
{
|
||||||
const LtsCoordTrans::UtmCoordinate c(LtsCoordTrans::preferedMgrsSquare());
|
const LtsCoordTrans::UtmCoordinate c(LtsCoordTrans::preferedMgrsSquare());
|
||||||
return c.mgrs(0);
|
return c.mgrs(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setDefaultMgrsSquares()
|
void MgrsEdit::setDefaultMgrsSquares()
|
||||||
{
|
{
|
||||||
m_ui->cbxZone->addItems(defaultMgrsSquares());
|
m_ui->cbxZone->addItems(defaultMgrsSquares());
|
||||||
m_ui->cbxZone->setCurrentIndex(m_ui->cbxZone->findText(preferedMgrsSquare()));
|
m_ui->cbxZone->setCurrentIndex(m_ui->cbxZone->findText(preferedMgrsSquare()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
void MgrsEdit::addMgrsSquare(const QString& newMgrsSquare)
|
||||||
{
|
{
|
||||||
QStringList sl = defaultMgrsSquares();
|
QStringList sl = defaultMgrsSquares();
|
||||||
sl += newMgrsSquare;
|
sl += newMgrsSquare;
|
||||||
if (m_withMgrsSquareOffset)
|
if (m_withMgrsSquareOffset)
|
||||||
{
|
{
|
||||||
QStringList squares = utmCoordsToList(LtsCoordTrans::defaultMgrsSquareWithOffsets());
|
QStringList squares = utmCoordsToList(LtsCoordTrans::defaultMgrsSquareWithOffsets());
|
||||||
|
|
||||||
for (const auto &sq : std::as_const(squares))
|
for (const auto& sq : std::as_const(squares))
|
||||||
if (!sl.contains(sq))
|
if (!sl.contains(sq))
|
||||||
sl.append(sq);
|
sl.append(sq);
|
||||||
}
|
}
|
||||||
std::sort(sl.begin(), sl.end());
|
std::sort(sl.begin(), sl.end());
|
||||||
m_ui->cbxZone->clear();
|
m_ui->cbxZone->clear();
|
||||||
m_ui->cbxZone->addItems(sl);
|
m_ui->cbxZone->addItems(sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MgrsEdit::utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate> &coords)
|
QStringList MgrsEdit::utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate>& coords)
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
list.reserve(coords.count());
|
list.reserve(coords.count());
|
||||||
for (const auto &utm : coords)
|
for (const auto& utm : coords)
|
||||||
list.append(utm.mgrs(0));
|
list.append(utm.mgrs(0));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords)
|
void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords)
|
||||||
{
|
{
|
||||||
QStringList sl = utmCoordsToList(geoCoords);
|
QStringList sl = utmCoordsToList(geoCoords);
|
||||||
if (sl.isEmpty())
|
if (sl.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -205,15 +212,13 @@ namespace LtsCoordWidget
|
|||||||
std::sort(sl.begin(), sl.end());
|
std::sort(sl.begin(), sl.end());
|
||||||
m_ui->cbxZone->clear();
|
m_ui->cbxZone->clear();
|
||||||
m_ui->cbxZone->addItems(sl);
|
m_ui->cbxZone->addItems(sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Wgs84Edit::Wgs84Edit(QWidget *widget)
|
Wgs84Edit::Wgs84Edit(QWidget* widget) : LtsCoordInputWidgetHandler(widget), m_ui(new Ui::Wgs84)
|
||||||
: LtsCoordInputWidgetHandler(widget)
|
{
|
||||||
, m_ui(new Ui::Wgs84)
|
|
||||||
{
|
|
||||||
m_ui->setupUi(widget);
|
m_ui->setupUi(widget);
|
||||||
|
|
||||||
DoubleValidator *v = new DoubleValidator(-180, 180, 9, m_ui->leLon);
|
DoubleValidator* v = new DoubleValidator(-180, 180, 9, m_ui->leLon);
|
||||||
v->setNotation(QDoubleValidator::StandardNotation);
|
v->setNotation(QDoubleValidator::StandardNotation);
|
||||||
m_ui->leLon->setValidator(v);
|
m_ui->leLon->setValidator(v);
|
||||||
|
|
||||||
@@ -223,29 +228,29 @@ namespace LtsCoordWidget
|
|||||||
|
|
||||||
connect(m_ui->leLon, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
connect(m_ui->leLon, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
||||||
connect(m_ui->leLat, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
connect(m_ui->leLat, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
Wgs84Edit::~Wgs84Edit()
|
Wgs84Edit::~Wgs84Edit()
|
||||||
{
|
{
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wgs84Edit::isValid()
|
bool Wgs84Edit::isValid()
|
||||||
{
|
{
|
||||||
|
|
||||||
return (!m_ui->leLon->text().isEmpty()) && (!m_ui->leLat->text().isEmpty());
|
return (!m_ui->leLon->text().isEmpty()) && (!m_ui->leLat->text().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wgs84Edit::setCoordinate(const QPointF &geoCoord)
|
void Wgs84Edit::setCoordinate(const QPointF& geoCoord)
|
||||||
{
|
{
|
||||||
const QPointF coord(geoCoord * LtsCoordTrans::rad2deg());
|
const QPointF coord(geoCoord * LtsCoordTrans::rad2deg());
|
||||||
const QLocale l;
|
const QLocale l;
|
||||||
m_ui->leLon->setText(l.toString(coord.x(), 'f', 9));
|
m_ui->leLon->setText(l.toString(coord.x(), 'f', 9));
|
||||||
m_ui->leLat->setText(l.toString(coord.y(), 'f', 9));
|
m_ui->leLat->setText(l.toString(coord.y(), 'f', 9));
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF Wgs84Edit::coordinate() const
|
QPointF Wgs84Edit::coordinate() const
|
||||||
{
|
{
|
||||||
QPointF ret;
|
QPointF ret;
|
||||||
const QLocale l;
|
const QLocale l;
|
||||||
|
|
||||||
@@ -258,15 +263,15 @@ namespace LtsCoordWidget
|
|||||||
ret.ry() = l.toDouble(latStr);
|
ret.ry() = l.toDouble(latStr);
|
||||||
|
|
||||||
return ret * LtsCoordTrans::deg2rad();
|
return ret * LtsCoordTrans::deg2rad();
|
||||||
}
|
}
|
||||||
|
|
||||||
QToolButton *Wgs84Edit::resetButton()
|
QToolButton* Wgs84Edit::resetButton()
|
||||||
{
|
{
|
||||||
return m_ui->tbReset;
|
return m_ui->tbReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wgs84Edit::cleanup()
|
void Wgs84Edit::cleanup()
|
||||||
{
|
{
|
||||||
|
|
||||||
delete m_ui->horizontalLayout;
|
delete m_ui->horizontalLayout;
|
||||||
delete m_ui->leLon;
|
delete m_ui->leLon;
|
||||||
@@ -274,21 +279,21 @@ namespace LtsCoordWidget
|
|||||||
delete m_ui->tbReset;
|
delete m_ui->tbReset;
|
||||||
delete m_ui->lblLon;
|
delete m_ui->lblLon;
|
||||||
delete m_ui->lblLat;
|
delete m_ui->lblLat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wgs84Edit::clear()
|
void Wgs84Edit::clear()
|
||||||
{
|
{
|
||||||
m_ui->leLon->clear();
|
m_ui->leLon->clear();
|
||||||
m_ui->leLat->clear();
|
m_ui->leLat->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
DoubleValidator::DoubleValidator(double bottom, double top, int decimals, QObject *parent)
|
DoubleValidator::DoubleValidator(double bottom, double top, int decimals, QObject* parent)
|
||||||
: QDoubleValidator(bottom, top, decimals, parent)
|
: QDoubleValidator(bottom, top, decimals, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QValidator::State DoubleValidator::validate(QString &input, int &pos) const
|
QValidator::State DoubleValidator::validate(QString& input, int& pos) const
|
||||||
{
|
{
|
||||||
const QValidator::State ret = QDoubleValidator::validate(input, pos);
|
const QValidator::State ret = QDoubleValidator::validate(input, pos);
|
||||||
if (ret != QValidator::Acceptable)
|
if (ret != QValidator::Acceptable)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -299,6 +304,6 @@ namespace LtsCoordWidget
|
|||||||
if (input.contains(gs))
|
if (input.contains(gs))
|
||||||
return QValidator::Invalid;
|
return QValidator::Invalid;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsCoordWidget
|
} // namespace LtsCoordWidget
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* An Input Widget for coordinates
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-09-08
|
||||||
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ui_lts_coord_widget_mgrs.h"
|
#include "ui_lts_coord_widget_mgrs.h"
|
||||||
@@ -13,89 +20,95 @@
|
|||||||
|
|
||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
class LtsCoordInputWidgetHandler : public QObject
|
class LtsCoordInputWidgetHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LtsCoordInputWidgetHandler(QObject *parent)
|
explicit LtsCoordInputWidgetHandler(QObject* parent) : QObject(parent) {}
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool isValid() = 0;
|
virtual bool isValid() = 0;
|
||||||
virtual void setCoordinate(const QPointF &geoCoord) = 0;
|
virtual void setCoordinate(const QPointF& geoCoord) = 0;
|
||||||
virtual QPointF coordinate() const = 0;
|
virtual QPointF coordinate() const = 0;
|
||||||
virtual QToolButton *resetButton() = 0;
|
virtual QToolButton* resetButton() = 0;
|
||||||
virtual void cleanup() = 0;
|
virtual void cleanup() = 0;
|
||||||
virtual void clear() = 0;
|
virtual void clear() = 0;
|
||||||
virtual void setSquaresEditable(bool bEditable) = 0;
|
virtual void setSquaresEditable(bool bEditable) = 0;
|
||||||
virtual void setWithSurroundingSquare(bool bEnabled) = 0;
|
virtual void setWithSurroundingSquare(bool bEnabled) = 0;
|
||||||
virtual void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) = 0;
|
virtual void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) = 0;
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void onCoordinateDataChanged();
|
void onCoordinateDataChanged();
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void coordinateChanged(const QPointF &newGeoCoord);
|
void coordinateChanged(const QPointF& newGeoCoord);
|
||||||
void invalidCoordinate();
|
void invalidCoordinate();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MgrsEdit final : public LtsCoordInputWidgetHandler
|
class MgrsEdit final : public LtsCoordInputWidgetHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit MgrsEdit(int precision, QWidget *widget);
|
explicit MgrsEdit(int precision, QWidget* widget);
|
||||||
~MgrsEdit();
|
~MgrsEdit();
|
||||||
|
|
||||||
bool isValid() override;
|
bool isValid() override;
|
||||||
void setCoordinate(const QPointF &geoCoord) override;
|
void setCoordinate(const QPointF& geoCoord) override;
|
||||||
QPointF coordinate() const override;
|
QPointF coordinate() const override;
|
||||||
QToolButton *resetButton() override;
|
QToolButton* resetButton() override;
|
||||||
void cleanup() override;
|
void cleanup() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void setSquaresEditable(bool bEditable) override;
|
void setSquaresEditable(bool bEditable) override;
|
||||||
void setWithSurroundingSquare(bool bEnabled) override;
|
void setWithSurroundingSquare(bool bEnabled) override;
|
||||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) override;
|
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDefaultMgrsSquares();
|
void setDefaultMgrsSquares();
|
||||||
void addMgrsSquare(const QString &newMgrsSquare);
|
void addMgrsSquare(const QString& newMgrsSquare);
|
||||||
QStringList utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate> &coords);
|
QStringList utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate>& coords);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_precision;
|
int m_precision;
|
||||||
bool m_withMgrsSquareOffset = false;
|
bool m_withMgrsSquareOffset = false;
|
||||||
Ui::Mgrs *m_ui;
|
Ui::Mgrs* m_ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Wgs84Edit final : public LtsCoordInputWidgetHandler
|
class Wgs84Edit final : public LtsCoordInputWidgetHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Wgs84Edit(QWidget *widget);
|
explicit Wgs84Edit(QWidget* widget);
|
||||||
~Wgs84Edit();
|
~Wgs84Edit();
|
||||||
|
|
||||||
bool isValid() override;
|
bool isValid() override;
|
||||||
void setCoordinate(const QPointF &geoCoord) override;
|
void setCoordinate(const QPointF& geoCoord) override;
|
||||||
QPointF coordinate() const override;
|
QPointF coordinate() const override;
|
||||||
QToolButton *resetButton() override;
|
QToolButton* resetButton() override;
|
||||||
void cleanup() override;
|
void cleanup() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
|
||||||
void setSquaresEditable(bool bEditable) override { Q_UNUSED(bEditable); }
|
void setSquaresEditable(bool bEditable) override
|
||||||
|
{
|
||||||
|
Q_UNUSED(bEditable);
|
||||||
|
}
|
||||||
|
|
||||||
void setWithSurroundingSquare(bool bEnabled) override { Q_UNUSED(bEnabled); }
|
void setWithSurroundingSquare(bool bEnabled) override
|
||||||
|
{
|
||||||
|
Q_UNUSED(bEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) override { Q_UNUSED(geoCoords); }
|
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) override
|
||||||
|
{
|
||||||
|
Q_UNUSED(geoCoords);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Wgs84 *m_ui;
|
Ui::Wgs84* m_ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DoubleValidator final : public QDoubleValidator
|
class DoubleValidator final : public QDoubleValidator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
|
DoubleValidator(double bottom, double top, int decimals, QObject* parent = nullptr);
|
||||||
|
|
||||||
QValidator::State validate(QString &input, int &pos) const override;
|
QValidator::State validate(QString& input, int& pos) const override;
|
||||||
};
|
};
|
||||||
} // namespace LtsCoordWidget
|
} // namespace LtsCoordWidget
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Small test app for ltscoordwidget
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-09-08
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_coord_widget.h"
|
#include "lts_coord_widget.h"
|
||||||
|
|
||||||
@@ -9,15 +17,17 @@
|
|||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
#include <QtWidgets/QVBoxLayout>
|
#include <QtWidgets/QVBoxLayout>
|
||||||
|
|
||||||
static void updateLabel(const QPointF &coord, QLabel *lbl, int prec)
|
static void updateLabel(const QPointF& coord, QLabel* lbl, int prec)
|
||||||
{
|
{
|
||||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(coord.x(), coord.y(), prec);
|
QString mgrs = LtsCoordTrans::mgrsFromGeographic(coord.x(), coord.y(), prec);
|
||||||
QString str =
|
QString str = QStringLiteral("mgrs: %1, lon: %2, lat: %3")
|
||||||
QStringLiteral("mgrs: %1, lon: %2, lat: %3").arg(mgrs).arg(coord.x() * LtsCoordTrans::rad2deg(), 0, 'f', 10).arg(coord.y() * LtsCoordTrans::rad2deg(), 0, 'f', 10);
|
.arg(mgrs)
|
||||||
|
.arg(coord.x() * LtsCoordTrans::rad2deg(), 0, 'f', 10)
|
||||||
|
.arg(coord.y() * LtsCoordTrans::rad2deg(), 0, 'f', 10);
|
||||||
lbl->setText(str);
|
lbl->setText(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
@@ -26,51 +36,55 @@ int main(int argc, char **argv)
|
|||||||
QPointF bottomRight(base.geographic(-50000, 50000));
|
QPointF bottomRight(base.geographic(-50000, 50000));
|
||||||
LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), true, true);
|
LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), true, true);
|
||||||
|
|
||||||
QDialog *dialog(new QDialog);
|
QDialog* dialog(new QDialog);
|
||||||
QVBoxLayout *lay(new QVBoxLayout(dialog));
|
QVBoxLayout* lay(new QVBoxLayout(dialog));
|
||||||
|
|
||||||
const QPointF defCoord(QPointF(53.0, 8.0) * LtsCoordTrans::deg2rad());
|
const QPointF defCoord(QPointF(53.0, 8.0) * LtsCoordTrans::deg2rad());
|
||||||
|
|
||||||
LtsCoordWidget::LtsCoordWidget *wMgrs5(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS, dialog));
|
LtsCoordWidget::LtsCoordWidget* wMgrs5(
|
||||||
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS, dialog));
|
||||||
wMgrs5->setWithResetButton(true);
|
wMgrs5->setWithResetButton(true);
|
||||||
wMgrs5->setCoordinate(defCoord, true);
|
wMgrs5->setCoordinate(defCoord, true);
|
||||||
lay->addWidget(wMgrs5);
|
lay->addWidget(wMgrs5);
|
||||||
QLabel *lbl5(new QLabel(dialog));
|
QLabel* lbl5(new QLabel(dialog));
|
||||||
lay->addWidget(lbl5);
|
lay->addWidget(lbl5);
|
||||||
QObject::connect(wMgrs5, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, lbl5, [lbl5](const QPointF &coord) { updateLabel(coord, lbl5, 5); });
|
QObject::connect(wMgrs5, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, lbl5,
|
||||||
|
[lbl5](const QPointF& coord) { updateLabel(coord, lbl5, 5); });
|
||||||
|
|
||||||
LtsCoordWidget::LtsCoordWidget *wMgrs7(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7, dialog));
|
LtsCoordWidget::LtsCoordWidget* wMgrs7(
|
||||||
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7, dialog));
|
||||||
wMgrs7->setWithResetButton(true);
|
wMgrs7->setWithResetButton(true);
|
||||||
wMgrs7->setCoordinate(defCoord, true);
|
wMgrs7->setCoordinate(defCoord, true);
|
||||||
lay->addWidget(wMgrs7);
|
lay->addWidget(wMgrs7);
|
||||||
QLabel *lbl7(new QLabel(dialog));
|
QLabel* lbl7(new QLabel(dialog));
|
||||||
lay->addWidget(lbl7);
|
lay->addWidget(lbl7);
|
||||||
QObject::connect(wMgrs7, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, wMgrs7, [lbl7](const QPointF &coord) { updateLabel(coord, lbl7, 7); });
|
QObject::connect(wMgrs7, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, wMgrs7,
|
||||||
|
[lbl7](const QPointF& coord) { updateLabel(coord, lbl7, 7); });
|
||||||
|
|
||||||
LtsCoordWidget::LtsCoordWidget *w84(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
LtsCoordWidget::LtsCoordWidget* w84(
|
||||||
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
||||||
w84->setWithResetButton(true);
|
w84->setWithResetButton(true);
|
||||||
w84->setCoordinate(defCoord, true);
|
w84->setCoordinate(defCoord, true);
|
||||||
lay->addWidget(w84);
|
lay->addWidget(w84);
|
||||||
QLabel *lbl84(new QLabel(dialog));
|
QLabel* lbl84(new QLabel(dialog));
|
||||||
lay->addWidget(lbl84);
|
lay->addWidget(lbl84);
|
||||||
QObject::connect(w84, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, w84, [lbl84](const QPointF &coord) { updateLabel(coord, lbl84, 11); });
|
QObject::connect(w84, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, w84,
|
||||||
|
[lbl84](const QPointF& coord) { updateLabel(coord, lbl84, 11); });
|
||||||
|
|
||||||
QHBoxLayout *hLay = new QHBoxLayout;
|
QHBoxLayout* hLay = new QHBoxLayout;
|
||||||
lay->addLayout(hLay);
|
lay->addLayout(hLay);
|
||||||
LtsCoordWidget::LtsCoordWidget *wChange(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
LtsCoordWidget::LtsCoordWidget* wChange(
|
||||||
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
||||||
wChange->setWithResetButton(true);
|
wChange->setWithResetButton(true);
|
||||||
wChange->setCoordinate(defCoord, true);
|
wChange->setCoordinate(defCoord, true);
|
||||||
hLay->addWidget(wChange);
|
hLay->addWidget(wChange);
|
||||||
QPushButton *pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
QPushButton* pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
||||||
hLay->addWidget(pbReset);
|
hLay->addWidget(pbReset);
|
||||||
QObject::connect(pbReset, &QPushButton::clicked, wChange, [wChange]() { wChange->setWithResetButton(!wChange->withResetButton()); });
|
QObject::connect(pbReset, &QPushButton::clicked, wChange,
|
||||||
QPushButton *pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
[wChange]() { wChange->setWithResetButton(!wChange->withResetButton()); });
|
||||||
|
QPushButton* pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
||||||
hLay->addWidget(pbNext);
|
hLay->addWidget(pbNext);
|
||||||
QObject::connect(pbNext,
|
QObject::connect(pbNext, &QPushButton::clicked, wChange, [wChange]() {
|
||||||
&QPushButton::clicked,
|
|
||||||
wChange,
|
|
||||||
[wChange]()
|
|
||||||
{
|
|
||||||
LtsCoordWidget::LtsCoordWidget::DisplayType dt = wChange->displayType();
|
LtsCoordWidget::LtsCoordWidget::DisplayType dt = wChange->displayType();
|
||||||
switch (dt)
|
switch (dt)
|
||||||
{
|
{
|
||||||
@@ -89,7 +103,7 @@ int main(int argc, char **argv)
|
|||||||
wChange->setDisplayType(dt);
|
wChange->setDisplayType(dt);
|
||||||
});
|
});
|
||||||
|
|
||||||
QPushButton *pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
QPushButton* pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
||||||
lay->addWidget(pb);
|
lay->addWidget(pb);
|
||||||
QObject::connect(pb, &QPushButton::clicked, qApp, QCoreApplication::quit);
|
QObject::connect(pb, &QPushButton::clicked, qApp, QCoreApplication::quit);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <GeographicLib/UTMUPS.hpp>
|
#include <GeographicLib/UTMUPS.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
@@ -38,15 +38,7 @@ int main(int argc, char **argv)
|
|||||||
part2 = mgrs.substr(3, 2);
|
part2 = mgrs.substr(3, 2);
|
||||||
part3 = mgrs.substr(5, prec);
|
part3 = mgrs.substr(5, prec);
|
||||||
part4 = mgrs.substr(5 + prec, prec);
|
part4 = mgrs.substr(5 + prec, prec);
|
||||||
fprintf(stdout,
|
fprintf(stdout, "%s %s %s %s = %13.10f, %13.10f ( %13.10f, %13.10f )\n", part1.c_str(), part2.c_str(),
|
||||||
"%s %s %s %s = %13.10f, %13.10f ( %13.10f, %13.10f )\n",
|
part3.c_str(), part4.c_str(), lonDeg, latDeg, lonDeg / 180. * M_PI, latDeg / 180. * M_PI);
|
||||||
part1.c_str(),
|
|
||||||
part2.c_str(),
|
|
||||||
part3.c_str(),
|
|
||||||
part4.c_str(),
|
|
||||||
lonDeg,
|
|
||||||
latDeg,
|
|
||||||
lonDeg / 180. * M_PI,
|
|
||||||
latDeg / 180. * M_PI);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Crypt/Decrypt functions (AES 256 CBC)
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#include "aes_crypt.h"
|
#include "aes_crypt.h"
|
||||||
|
|
||||||
@@ -10,11 +16,11 @@
|
|||||||
|
|
||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
struct AesCryptPrivate
|
struct AesCryptPrivate
|
||||||
{
|
{
|
||||||
AesCryptPrivate()
|
AesCryptPrivate()
|
||||||
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR))
|
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR)),
|
||||||
, logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
||||||
{
|
{
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||||
ERR_load_crypto_strings();
|
ERR_load_crypto_strings();
|
||||||
@@ -29,22 +35,22 @@ namespace LtsLicence
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString passPhrase;
|
QString passPhrase;
|
||||||
NGL::INGLLogger &logger;
|
NGL::INGLLogger& logger;
|
||||||
};
|
};
|
||||||
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
||||||
|
|
||||||
void setPassPhrase(const QString &passPhrase)
|
void setPassPhrase(const QString& passPhrase)
|
||||||
{
|
{
|
||||||
s_Private->passPhrase = passPhrase;
|
s_Private->passPhrase = passPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString passPhrase()
|
QString passPhrase()
|
||||||
{
|
{
|
||||||
return s_Private->passPhrase;
|
return s_Private->passPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray decryptData(const QByteArray &dataToDecrypt, const QString &pw, bool *bOk)
|
QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw, bool* bOk)
|
||||||
{
|
{
|
||||||
if (bOk)
|
if (bOk)
|
||||||
*bOk = false;
|
*bOk = false;
|
||||||
|
|
||||||
@@ -54,7 +60,7 @@ namespace LtsLicence
|
|||||||
unsigned char key[32];
|
unsigned char key[32];
|
||||||
|
|
||||||
const QByteArray baPassword = pw.toUtf8();
|
const QByteArray baPassword = pw.toUtf8();
|
||||||
const unsigned char *dataPw = reinterpret_cast<const unsigned char *>(baPassword.data());
|
const unsigned char* dataPw = reinterpret_cast<const unsigned char*>(baPassword.data());
|
||||||
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
||||||
if (i != 32)
|
if (i != 32)
|
||||||
{
|
{
|
||||||
@@ -63,11 +69,11 @@ namespace LtsLicence
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
|
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
|
||||||
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
|
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
|
||||||
|
|
||||||
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
|
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
|
||||||
|
|
||||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||||
ret = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
ret = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
@@ -80,8 +86,8 @@ namespace LtsLicence
|
|||||||
|
|
||||||
QByteArray bufDecrypted;
|
QByteArray bufDecrypted;
|
||||||
bufDecrypted.resize(bufEncrypted.size() + EVP_CIPHER_CTX_block_size(ctx));
|
bufDecrypted.resize(bufEncrypted.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(bufEncrypted.data());
|
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(bufEncrypted.data());
|
||||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufDecrypted.data());
|
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufDecrypted.data());
|
||||||
|
|
||||||
ret = EVP_DecryptUpdate(ctx, dataOut, &outSize1, dataIn, bufEncrypted.size());
|
ret = EVP_DecryptUpdate(ctx, dataOut, &outSize1, dataIn, bufEncrypted.size());
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@@ -110,10 +116,10 @@ namespace LtsLicence
|
|||||||
if (bOk)
|
if (bOk)
|
||||||
*bOk = true;
|
*bOk = true;
|
||||||
return bufDecrypted;
|
return bufDecrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray encryptData(const QByteArray &dataToEncrypt, const QString &pw, bool *bOk)
|
QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw, bool* bOk)
|
||||||
{
|
{
|
||||||
if (bOk)
|
if (bOk)
|
||||||
*bOk = false;
|
*bOk = false;
|
||||||
|
|
||||||
@@ -124,7 +130,7 @@ namespace LtsLicence
|
|||||||
QByteArray bufEncrypted;
|
QByteArray bufEncrypted;
|
||||||
|
|
||||||
const QByteArray baPassword = pw.toUtf8();
|
const QByteArray baPassword = pw.toUtf8();
|
||||||
const unsigned char *dataPw = reinterpret_cast<const unsigned char *>(baPassword.data());
|
const unsigned char* dataPw = reinterpret_cast<const unsigned char*>(baPassword.data());
|
||||||
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
||||||
if (i != 32)
|
if (i != 32)
|
||||||
{
|
{
|
||||||
@@ -135,9 +141,9 @@ namespace LtsLicence
|
|||||||
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
|
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
|
||||||
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
|
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
|
||||||
baSalt[i] = static_cast<char>(QRandomGenerator::global()->bounded(256));
|
baSalt[i] = static_cast<char>(QRandomGenerator::global()->bounded(256));
|
||||||
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
|
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
|
||||||
|
|
||||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||||
ret = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
ret = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
@@ -148,10 +154,10 @@ namespace LtsLicence
|
|||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char *>(salt), EVP_MAX_IV_LENGTH);
|
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char*>(salt), EVP_MAX_IV_LENGTH);
|
||||||
bufEncrypted.resize(bufEncrypted.size() + dataToEncrypt.size() + EVP_CIPHER_CTX_block_size(ctx));
|
bufEncrypted.resize(bufEncrypted.size() + dataToEncrypt.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(dataToEncrypt.data());
|
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(dataToEncrypt.data());
|
||||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufEncrypted.data());
|
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufEncrypted.data());
|
||||||
dataOut += baSalt.size();
|
dataOut += baSalt.size();
|
||||||
ret = EVP_EncryptUpdate(ctx, dataOut, &outSize1, dataIn, dataToEncrypt.size());
|
ret = EVP_EncryptUpdate(ctx, dataOut, &outSize1, dataIn, dataToEncrypt.size());
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@@ -180,6 +186,6 @@ namespace LtsLicence
|
|||||||
if (bOk)
|
if (bOk)
|
||||||
*bOk = true;
|
*bOk = true;
|
||||||
return bufEncrypted;
|
return bufEncrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsLicence
|
} // namespace LtsLicence
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Crypt/Decrypt functions (AES 256 CBC)
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -9,10 +15,12 @@
|
|||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
|
|
||||||
LTSLICENCE_EXPORT void setPassPhrase(const QString &passPhrase);
|
LTSLICENCE_EXPORT void setPassPhrase(const QString& passPhrase);
|
||||||
LTSLICENCE_EXPORT QString passPhrase();
|
LTSLICENCE_EXPORT QString passPhrase();
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QByteArray decryptData(const QByteArray &dataToDecrypt, const QString &pw = passPhrase(), bool *bOk = nullptr);
|
LTSLICENCE_EXPORT QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw = passPhrase(),
|
||||||
|
bool* bOk = nullptr);
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QByteArray encryptData(const QByteArray &dataToEncrypt, const QString &pw = passPhrase(), bool *bOk = nullptr);
|
LTSLICENCE_EXPORT QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw = passPhrase(),
|
||||||
|
bool* bOk = nullptr);
|
||||||
} // namespace LtsLicence
|
} // namespace LtsLicence
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Test for NCrypt
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#include "aes_crypt_test.h"
|
#include "aes_crypt_test.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Test for NCrypt
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
@@ -7,7 +13,7 @@
|
|||||||
class aes_crypt_test : public QObject
|
class aes_crypt_test : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void truePassTest();
|
void truePassTest();
|
||||||
void falsePassTest();
|
void falsePassTest();
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Licence Library
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by hjl, SLSE, 2016-06-01
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "lts_licence.h"
|
#include "lts_licence.h"
|
||||||
@@ -8,15 +16,15 @@
|
|||||||
|
|
||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
static bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec);
|
static bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec);
|
||||||
|
|
||||||
static NGL::INGLLogger &getLogger()
|
static NGL::INGLLogger& getLogger()
|
||||||
{
|
{
|
||||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
||||||
{
|
{
|
||||||
QVector<Licence> licenceVec;
|
QVector<Licence> licenceVec;
|
||||||
|
|
||||||
QDomDocument xmlDoc;
|
QDomDocument xmlDoc;
|
||||||
@@ -45,13 +53,14 @@ namespace LtsLicence
|
|||||||
licenceElement = licenceElement.nextSiblingElement(QLatin1String("licence"));
|
licenceElement = licenceElement.nextSiblingElement(QLatin1String("licence"));
|
||||||
}
|
}
|
||||||
return licenceVec;
|
return licenceVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
QByteArray writeUnencryptedLicences(const QVector<Licence>& licences)
|
||||||
{
|
{
|
||||||
QDomDocument xmlDoc;
|
QDomDocument xmlDoc;
|
||||||
|
|
||||||
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(QLatin1String("xml"), QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
|
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(
|
||||||
|
QLatin1String("xml"), QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
|
||||||
xmlDoc.appendChild(instr);
|
xmlDoc.appendChild(instr);
|
||||||
|
|
||||||
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
|
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
|
||||||
@@ -92,10 +101,10 @@ namespace LtsLicence
|
|||||||
}
|
}
|
||||||
INFO_LOG(getLogger()) << "Generated XML Data...\n" << xmlDoc.toByteArray();
|
INFO_LOG(getLogger()) << "Generated XML Data...\n" << xmlDoc.toByteArray();
|
||||||
return xmlDoc.toByteArray();
|
return xmlDoc.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec)
|
bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec)
|
||||||
{
|
{
|
||||||
Licence licence;
|
Licence licence;
|
||||||
|
|
||||||
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
|
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
|
||||||
@@ -125,22 +134,23 @@ namespace LtsLicence
|
|||||||
|
|
||||||
licence.expiration = qdt;
|
licence.expiration = qdt;
|
||||||
INFO_LOG(getLogger()) << "Read licence for:'" << licence.name << "'"
|
INFO_LOG(getLogger()) << "Read licence for:'" << licence.name << "'"
|
||||||
<< " IgnoreMaxCount: " << licence.ignoreMaxCount << " IgnoreExpiration: " << licence.ignoreExpiration << " MaxCount: " << licence.maxCount
|
<< " IgnoreMaxCount: " << licence.ignoreMaxCount
|
||||||
<< " Expiration: " << licence.expiration.date().toString() << " " << licence.expiration.time().toString()
|
<< " IgnoreExpiration: " << licence.ignoreExpiration << " MaxCount: " << licence.maxCount
|
||||||
<< " RefCount: " << licence.licenceRefCount;
|
<< " Expiration: " << licence.expiration.date().toString() << " "
|
||||||
|
<< licence.expiration.time().toString() << " RefCount: " << licence.licenceRefCount;
|
||||||
|
|
||||||
licenceVec.append(licence);
|
licenceVec.append(licence);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Licence::toString() const
|
QString Licence::toString() const
|
||||||
{
|
{
|
||||||
return QObject::tr("Name: %1, Count: %2, ExpireDate: %3, Expires: %4, UseMaxCount: %5")
|
return QObject::tr("Name: %1, Count: %2, ExpireDate: %3, Expires: %4, UseMaxCount: %5")
|
||||||
.arg(name)
|
.arg(name)
|
||||||
.arg(maxCount)
|
.arg(maxCount)
|
||||||
.arg(expiration.toString())
|
.arg(expiration.toString())
|
||||||
.arg(ignoreExpiration)
|
.arg(ignoreExpiration)
|
||||||
.arg(ignoreMaxCount);
|
.arg(ignoreMaxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsLicence
|
} // namespace LtsLicence
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Licence Library
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by hjl, SLSE, 2016-06-01
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -11,8 +18,8 @@
|
|||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
|
|
||||||
struct LTSLICENCE_EXPORT Licence
|
struct LTSLICENCE_EXPORT Licence
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
bool ignoreMaxCount = false;
|
bool ignoreMaxCount = false;
|
||||||
bool ignoreExpiration = false;
|
bool ignoreExpiration = false;
|
||||||
@@ -21,9 +28,9 @@ namespace LtsLicence
|
|||||||
int licenceRefCount = 0;
|
int licenceRefCount = 0;
|
||||||
|
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QVector<Licence> readLicences(const QByteArray &unencryptedXmlData);
|
LTSLICENCE_EXPORT QVector<Licence> readLicences(const QByteArray& unencryptedXmlData);
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QByteArray writeUnencryptedLicences(const QVector<Licence> &licences);
|
LTSLICENCE_EXPORT QByteArray writeUnencryptedLicences(const QVector<Licence>& licences);
|
||||||
} // namespace LtsLicence
|
} // namespace LtsLicence
|
||||||
@@ -9,58 +9,56 @@
|
|||||||
namespace LtsNotification
|
namespace LtsNotification
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsNotification::LtsNotification(LtsNotificationController *ctl)
|
LtsNotification::LtsNotification(LtsNotificationController* ctl) : QObject(), m_controller(ctl)
|
||||||
: QObject()
|
{
|
||||||
, m_controller(ctl)
|
|
||||||
{
|
|
||||||
connect(ctl, &LtsNotificationController::destroyed, this, &LtsNotification::slotCtlDestroyed);
|
connect(ctl, &LtsNotificationController::destroyed, this, &LtsNotification::slotCtlDestroyed);
|
||||||
}
|
}
|
||||||
|
|
||||||
LtsNotification::~LtsNotification()
|
LtsNotification::~LtsNotification()
|
||||||
{
|
{
|
||||||
delete m_controller;
|
delete m_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::setIcon(const QIcon &icon)
|
void LtsNotification::setIcon(const QIcon& icon)
|
||||||
{
|
{
|
||||||
m_controller->setIcon(icon);
|
m_controller->setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::setAction(const std::function<void(void)> &action)
|
void LtsNotification::setAction(const std::function<void(void)>& action)
|
||||||
{
|
{
|
||||||
m_controller->setAction(action);
|
m_controller->setAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::setToolTip(const QString &toolTip)
|
void LtsNotification::setToolTip(const QString& toolTip)
|
||||||
{
|
{
|
||||||
m_controller->setToolTip(toolTip);
|
m_controller->setToolTip(toolTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &LtsNotification::tooltip() const
|
const QString& LtsNotification::tooltip() const
|
||||||
{
|
{
|
||||||
return m_controller->tooltip();
|
return m_controller->tooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::setCount(const int count)
|
void LtsNotification::setCount(const int count)
|
||||||
{
|
{
|
||||||
m_controller->setCount(count);
|
m_controller->setCount(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::setEnabled(bool enable)
|
void LtsNotification::setEnabled(bool enable)
|
||||||
{
|
{
|
||||||
m_controller->setEnabled(enable);
|
m_controller->setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::setBackground(const int r, const int g, const int b)
|
void LtsNotification::setBackground(const int r, const int g, const int b)
|
||||||
{
|
{
|
||||||
m_controller->setBackground(r, g, b);
|
m_controller->setBackground(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotification::slotCtlDestroyed(QObject *obj)
|
void LtsNotification::slotCtlDestroyed(QObject* obj)
|
||||||
{
|
{
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
|
||||||
m_controller = nullptr;
|
m_controller = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsNotification
|
} // namespace LtsNotification
|
||||||
@@ -11,35 +11,35 @@
|
|||||||
|
|
||||||
namespace LtsSession
|
namespace LtsSession
|
||||||
{
|
{
|
||||||
class LtsSession;
|
class LtsSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace LtsNotification
|
namespace LtsNotification
|
||||||
{
|
{
|
||||||
class LtsNotificationController;
|
class LtsNotificationController;
|
||||||
|
|
||||||
class LTSNOTIFICATION_EXPORT LtsNotification : public QObject
|
class LTSNOTIFICATION_EXPORT LtsNotification : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LtsNotification(LtsNotificationController *ctl);
|
explicit LtsNotification(LtsNotificationController* ctl);
|
||||||
~LtsNotification();
|
~LtsNotification();
|
||||||
|
|
||||||
void setIcon(const QIcon &icon);
|
void setIcon(const QIcon& icon);
|
||||||
void setAction(const std::function<void(void)> &action);
|
void setAction(const std::function<void(void)>& action);
|
||||||
void setToolTip(const QString &toolTip);
|
void setToolTip(const QString& toolTip);
|
||||||
void setCount(const int count);
|
void setCount(const int count);
|
||||||
void setEnabled(bool enable);
|
void setEnabled(bool enable);
|
||||||
void setBackground(const int r, const int g, const int b);
|
void setBackground(const int r, const int g, const int b);
|
||||||
|
|
||||||
const QString &tooltip() const;
|
const QString& tooltip() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LtsNotificationController *m_controller;
|
LtsNotificationController* m_controller;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotCtlDestroyed(QObject *obj);
|
void slotCtlDestroyed(QObject* obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsNotification
|
} // namespace LtsNotification
|
||||||
+46
-51
@@ -13,36 +13,34 @@
|
|||||||
namespace LtsNotification
|
namespace LtsNotification
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsNotificationController::LtsNotificationController(const QString &identifier)
|
LtsNotificationController::LtsNotificationController(const QString& identifier)
|
||||||
: QObject()
|
: QObject(), m_count(0), m_identifier(QStringLiteral("LtsNotification%1").arg(identifier))
|
||||||
, m_count(0)
|
{
|
||||||
, m_identifier(QStringLiteral("LtsNotification%1").arg(identifier))
|
}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LtsNotificationController::~LtsNotificationController()
|
LtsNotificationController::~LtsNotificationController()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_notiList);
|
qDeleteAll(m_notiList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setIcon(const QIcon &icon)
|
void LtsNotificationController::setIcon(const QIcon& icon)
|
||||||
{
|
{
|
||||||
m_icon = icon;
|
m_icon = icon;
|
||||||
|
|
||||||
setAllIcons();
|
setAllIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setCount(const int count)
|
void LtsNotificationController::setCount(const int count)
|
||||||
{
|
{
|
||||||
m_count = count;
|
m_count = count;
|
||||||
|
|
||||||
setAllIcons();
|
setAllIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setBackground(const int r, const int g, const int b)
|
void LtsNotificationController::setBackground(const int r, const int g, const int b)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (QToolButton *tb : std::as_const(m_notiList))
|
for (QToolButton* tb : std::as_const(m_notiList))
|
||||||
{
|
{
|
||||||
|
|
||||||
QString stylesheet;
|
QString stylesheet;
|
||||||
@@ -50,55 +48,56 @@ namespace LtsNotification
|
|||||||
if (r == -1 && g == -1 && b == -1)
|
if (r == -1 && g == -1 && b == -1)
|
||||||
stylesheet = QStringLiteral("");
|
stylesheet = QStringLiteral("");
|
||||||
else
|
else
|
||||||
stylesheet = QStringLiteral("QToolButton {background-color: rgb(") + QString::number(r) + QStringLiteral(",") + QString::number(g) + QStringLiteral(",") +
|
stylesheet = QStringLiteral("QToolButton {background-color: rgb(") + QString::number(r) +
|
||||||
QString::number(b) + QStringLiteral(");}");
|
QStringLiteral(",") + QString::number(g) + QStringLiteral(",") + QString::number(b) +
|
||||||
|
QStringLiteral(");}");
|
||||||
|
|
||||||
tb->setStyleSheet(stylesheet);
|
tb->setStyleSheet(stylesheet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setEnabled(bool enable)
|
void LtsNotificationController::setEnabled(bool enable)
|
||||||
{
|
{
|
||||||
m_enable = enable;
|
m_enable = enable;
|
||||||
|
|
||||||
setAllIcons();
|
setAllIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setAction(const std::function<void(void)> &action)
|
void LtsNotificationController::setAction(const std::function<void(void)>& action)
|
||||||
{
|
{
|
||||||
m_action = action;
|
m_action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setToolTip(const QString &toolTip)
|
void LtsNotificationController::setToolTip(const QString& toolTip)
|
||||||
{
|
{
|
||||||
m_toolTip = toolTip;
|
m_toolTip = toolTip;
|
||||||
|
|
||||||
for (QToolButton *tb : std::as_const(m_notiList))
|
for (QToolButton* tb : std::as_const(m_notiList))
|
||||||
{
|
{
|
||||||
tb->setToolTip(toolTip);
|
tb->setToolTip(toolTip);
|
||||||
tb->setIconSize(QSize(30, 30));
|
tb->setIconSize(QSize(30, 30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::setAllIcons()
|
void LtsNotificationController::setAllIcons()
|
||||||
{
|
{
|
||||||
if (m_icon.isNull())
|
if (m_icon.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QIcon icon = modifyIcon(m_icon);
|
QIcon icon = modifyIcon(m_icon);
|
||||||
|
|
||||||
for (QToolButton *tb : std::as_const(m_notiList))
|
for (QToolButton* tb : std::as_const(m_notiList))
|
||||||
{
|
{
|
||||||
tb->setIcon(icon);
|
tb->setIcon(icon);
|
||||||
tb->setIconSize(QSize(30, 30));
|
tb->setIconSize(QSize(30, 30));
|
||||||
tb->setEnabled(m_enable);
|
tb->setEnabled(m_enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SIZE 40
|
#define SIZE 40
|
||||||
|
|
||||||
QIcon LtsNotificationController::modifyIcon(const QIcon &icon)
|
QIcon LtsNotificationController::modifyIcon(const QIcon& icon)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_count < 1)
|
if (m_count < 1)
|
||||||
return icon;
|
return icon;
|
||||||
@@ -122,11 +121,11 @@ namespace LtsNotification
|
|||||||
painter.restore();
|
painter.restore();
|
||||||
|
|
||||||
return iconImage;
|
return iconImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
QToolButton *LtsNotificationController::createWidget()
|
QToolButton* LtsNotificationController::createWidget()
|
||||||
{
|
{
|
||||||
QToolButton *b = new QToolButton();
|
QToolButton* b = new QToolButton();
|
||||||
b->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
b->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||||
b->setObjectName(m_identifier);
|
b->setObjectName(m_identifier);
|
||||||
|
|
||||||
@@ -134,11 +133,7 @@ namespace LtsNotification
|
|||||||
b->setMaximumSize(SIZE, SIZE);
|
b->setMaximumSize(SIZE, SIZE);
|
||||||
|
|
||||||
connect(b, &QToolButton::destroyed, this, &LtsNotificationController::slotNotiWidgetDestroyed);
|
connect(b, &QToolButton::destroyed, this, &LtsNotificationController::slotNotiWidgetDestroyed);
|
||||||
connect(b,
|
connect(b, &QToolButton::clicked, this, [this]() {
|
||||||
&QToolButton::clicked,
|
|
||||||
this,
|
|
||||||
[this]()
|
|
||||||
{
|
|
||||||
if (m_action)
|
if (m_action)
|
||||||
m_action();
|
m_action();
|
||||||
});
|
});
|
||||||
@@ -150,11 +145,11 @@ namespace LtsNotification
|
|||||||
|
|
||||||
m_notiList.append(b);
|
m_notiList.append(b);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsNotificationController::slotNotiWidgetDestroyed(QObject *obj)
|
void LtsNotificationController::slotNotiWidgetDestroyed(QObject* obj)
|
||||||
{
|
{
|
||||||
m_notiList.removeAll(static_cast<QToolButton *>(obj));
|
m_notiList.removeAll(static_cast<QToolButton*>(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsNotification
|
} // namespace LtsNotification
|
||||||
@@ -14,37 +14,43 @@ class QToolButton;
|
|||||||
|
|
||||||
namespace LtsSession
|
namespace LtsSession
|
||||||
{
|
{
|
||||||
class LtsSession;
|
class LtsSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace LtsNotification
|
namespace LtsNotification
|
||||||
{
|
{
|
||||||
class LtsNotificationWidget;
|
class LtsNotificationWidget;
|
||||||
|
|
||||||
class LTSNOTIFICATION_EXPORT LtsNotificationController : public QObject
|
class LTSNOTIFICATION_EXPORT LtsNotificationController : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LtsNotificationController(const QString &identifier);
|
explicit LtsNotificationController(const QString& identifier);
|
||||||
~LtsNotificationController();
|
~LtsNotificationController();
|
||||||
|
|
||||||
QToolButton *createWidget();
|
QToolButton* createWidget();
|
||||||
|
|
||||||
void setIcon(const QIcon &icon);
|
void setIcon(const QIcon& icon);
|
||||||
void setAction(const std::function<void(void)> &action);
|
void setAction(const std::function<void(void)>& action);
|
||||||
void setToolTip(const QString &toolTip);
|
void setToolTip(const QString& toolTip);
|
||||||
void setCount(const int count);
|
void setCount(const int count);
|
||||||
void setBackground(const int r, const int g, const int b);
|
void setBackground(const int r, const int g, const int b);
|
||||||
|
|
||||||
const QString &identifier() const { return m_identifier; }
|
const QString& identifier() const
|
||||||
|
{
|
||||||
|
return m_identifier;
|
||||||
|
}
|
||||||
|
|
||||||
const QString &tooltip() const { return m_toolTip; }
|
const QString& tooltip() const
|
||||||
|
{
|
||||||
|
return m_toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
void setEnabled(bool enable);
|
void setEnabled(bool enable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QToolButton *> m_notiList;
|
QList<QToolButton*> m_notiList;
|
||||||
|
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
std::function<void(void)> m_action;
|
std::function<void(void)> m_action;
|
||||||
@@ -54,10 +60,10 @@ namespace LtsNotification
|
|||||||
QString m_identifier;
|
QString m_identifier;
|
||||||
|
|
||||||
void setAllIcons();
|
void setAllIcons();
|
||||||
QIcon modifyIcon(const QIcon &icon);
|
QIcon modifyIcon(const QIcon& icon);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotNotiWidgetDestroyed(QObject *obj);
|
void slotNotiWidgetDestroyed(QObject* obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsNotification
|
} // namespace LtsNotification
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Building Config - logging facility
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
@@ -7,8 +13,8 @@
|
|||||||
namespace LtsSerialPortQuerry
|
namespace LtsSerialPortQuerry
|
||||||
{
|
{
|
||||||
|
|
||||||
LOGGER_T getLogger(const char *name)
|
LOGGER_T getLogger(const char* name)
|
||||||
{
|
{
|
||||||
static const char ns[] = "SPQ.";
|
static const char ns[] = "SPQ.";
|
||||||
std::string loggerName;
|
std::string loggerName;
|
||||||
const size_t len = strlen(name);
|
const size_t len = strlen(name);
|
||||||
@@ -20,11 +26,11 @@ namespace LtsSerialPortQuerry
|
|||||||
{
|
{
|
||||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
||||||
}
|
}
|
||||||
catch (const std::exception &ex)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsSerialPortQuerry
|
} // namespace LtsSerialPortQuerry
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Logging for XxxXxxXxx
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -6,12 +12,12 @@
|
|||||||
|
|
||||||
namespace LtsSerialPortQuerry
|
namespace LtsSerialPortQuerry
|
||||||
{
|
{
|
||||||
typedef NGL::INGLLogger &LOGGER_T;
|
typedef NGL::INGLLogger& LOGGER_T;
|
||||||
|
|
||||||
LOGGER_T getLogger(const char *name);
|
LOGGER_T getLogger(const char* name);
|
||||||
|
|
||||||
inline LOGGER_T getLogger(const QString &loggerName)
|
inline LOGGER_T getLogger(const QString& loggerName)
|
||||||
{
|
{
|
||||||
return getLogger(loggerName.toUtf8().constData());
|
return getLogger(loggerName.toUtf8().constData());
|
||||||
}
|
}
|
||||||
} // namespace LtsSerialPortQuerry
|
} // namespace LtsSerialPortQuerry
|
||||||
+10
-13
@@ -9,27 +9,24 @@
|
|||||||
|
|
||||||
namespace LtsSerialPortQuerry
|
namespace LtsSerialPortQuerry
|
||||||
{
|
{
|
||||||
class LTSSERIALPORTQUERRY_EXPORT LtsSerialPortQuerry : public QObject
|
class LTSSERIALPORTQUERRY_EXPORT LtsSerialPortQuerry : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LtsSerialPortQuerry(QObject *parent = nullptr);
|
explicit LtsSerialPortQuerry(QObject* parent = nullptr);
|
||||||
|
|
||||||
void setSerialPortSettings(const QSerialPort::BaudRate &baudRate,
|
void setSerialPortSettings(const QSerialPort::BaudRate& baudRate, const QSerialPort::OpenModeFlag& openModeFlag,
|
||||||
const QSerialPort::OpenModeFlag &openModeFlag,
|
const QSerialPort::DataBits& dataBits, const QSerialPort::FlowControl& flowControll,
|
||||||
const QSerialPort::DataBits &dataBits,
|
const QSerialPort::Parity& parity, const QSerialPort::StopBits& stopBits);
|
||||||
const QSerialPort::FlowControl &flowControll,
|
|
||||||
const QSerialPort::Parity &parity,
|
|
||||||
const QSerialPort::StopBits &stopBits);
|
|
||||||
void continueQuerry();
|
void continueQuerry();
|
||||||
void restartQuerry();
|
void restartQuerry();
|
||||||
QSerialPort *currentSerialPort();
|
QSerialPort* currentSerialPort();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectionEstablished();
|
void connectionEstablished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void querrySerialPort(const QSerialPortInfo &info);
|
void querrySerialPort(const QSerialPortInfo& info);
|
||||||
void closeAndDeleteCurrentPort();
|
void closeAndDeleteCurrentPort();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -44,7 +41,7 @@ namespace LtsSerialPortQuerry
|
|||||||
QSerialPort::FlowControl m_flowControll;
|
QSerialPort::FlowControl m_flowControll;
|
||||||
QSerialPort::Parity m_parity;
|
QSerialPort::Parity m_parity;
|
||||||
QSerialPort::StopBits m_stopBits;
|
QSerialPort::StopBits m_stopBits;
|
||||||
QSerialPort *m_currentSerialPort;
|
QSerialPort* m_currentSerialPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsSerialPortQuerry
|
} // namespace LtsSerialPortQuerry
|
||||||
+44
-51
@@ -5,37 +5,31 @@
|
|||||||
namespace LtsSerialPortQuerry
|
namespace LtsSerialPortQuerry
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsSerialPortQuerry::LtsSerialPortQuerry(QObject *parent)
|
LtsSerialPortQuerry::LtsSerialPortQuerry(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent), m_logger(getLogger("LtsSerialPortQuerry")), m_currentQuerry(0),
|
||||||
, m_logger(getLogger("LtsSerialPortQuerry"))
|
m_baudRate(QSerialPort::Baud115200), m_openModeFlag(QSerialPort::ReadWrite), m_dataBits(QSerialPort::Data8),
|
||||||
, m_currentQuerry(0)
|
m_flowControll(QSerialPort::NoFlowControl), m_parity(QSerialPort::NoParity), m_stopBits(QSerialPort::OneStop),
|
||||||
, m_baudRate(QSerialPort::Baud115200)
|
m_currentSerialPort(nullptr)
|
||||||
, m_openModeFlag(QSerialPort::ReadWrite)
|
{
|
||||||
, m_dataBits(QSerialPort::Data8)
|
}
|
||||||
, m_flowControll(QSerialPort::NoFlowControl)
|
|
||||||
, m_parity(QSerialPort::NoParity)
|
|
||||||
, m_stopBits(QSerialPort::OneStop)
|
|
||||||
, m_currentSerialPort(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void LtsSerialPortQuerry::setSerialPortSettings(const QSerialPort::BaudRate &baudRate,
|
void LtsSerialPortQuerry::setSerialPortSettings(const QSerialPort::BaudRate& baudRate,
|
||||||
const QIODevice::OpenModeFlag &openModeFlag,
|
const QIODevice::OpenModeFlag& openModeFlag,
|
||||||
const QSerialPort::DataBits &dataBits,
|
const QSerialPort::DataBits& dataBits,
|
||||||
const QSerialPort::FlowControl &flowControll,
|
const QSerialPort::FlowControl& flowControll,
|
||||||
const QSerialPort::Parity &parity,
|
const QSerialPort::Parity& parity,
|
||||||
const QSerialPort::StopBits &stopBits)
|
const QSerialPort::StopBits& stopBits)
|
||||||
{
|
{
|
||||||
m_baudRate = baudRate;
|
m_baudRate = baudRate;
|
||||||
m_openModeFlag = openModeFlag;
|
m_openModeFlag = openModeFlag;
|
||||||
m_dataBits = dataBits;
|
m_dataBits = dataBits;
|
||||||
m_flowControll = flowControll;
|
m_flowControll = flowControll;
|
||||||
m_parity = parity;
|
m_parity = parity;
|
||||||
m_stopBits = stopBits;
|
m_stopBits = stopBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsSerialPortQuerry::continueQuerry()
|
void LtsSerialPortQuerry::continueQuerry()
|
||||||
{
|
{
|
||||||
m_currentQuerry++;
|
m_currentQuerry++;
|
||||||
if (m_currentQuerry >= m_serialPortInfos.size())
|
if (m_currentQuerry >= m_serialPortInfos.size())
|
||||||
{
|
{
|
||||||
@@ -44,10 +38,10 @@ namespace LtsSerialPortQuerry
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
querrySerialPort(m_serialPortInfos.at(m_currentQuerry));
|
querrySerialPort(m_serialPortInfos.at(m_currentQuerry));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsSerialPortQuerry::restartQuerry()
|
void LtsSerialPortQuerry::restartQuerry()
|
||||||
{
|
{
|
||||||
DEBUG_LOG(m_logger) << "restart querry ";
|
DEBUG_LOG(m_logger) << "restart querry ";
|
||||||
m_serialPortInfos = QSerialPortInfo::availablePorts();
|
m_serialPortInfos = QSerialPortInfo::availablePorts();
|
||||||
m_currentQuerry = 0;
|
m_currentQuerry = 0;
|
||||||
@@ -55,15 +49,15 @@ namespace LtsSerialPortQuerry
|
|||||||
querrySerialPort(m_serialPortInfos.at(m_currentQuerry));
|
querrySerialPort(m_serialPortInfos.at(m_currentQuerry));
|
||||||
else
|
else
|
||||||
QTimer::singleShot(1000, this, &LtsSerialPortQuerry::restartQuerry);
|
QTimer::singleShot(1000, this, &LtsSerialPortQuerry::restartQuerry);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSerialPort *LtsSerialPortQuerry::currentSerialPort()
|
QSerialPort* LtsSerialPortQuerry::currentSerialPort()
|
||||||
{
|
{
|
||||||
return m_currentSerialPort;
|
return m_currentSerialPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsSerialPortQuerry::querrySerialPort(const QSerialPortInfo &info)
|
void LtsSerialPortQuerry::querrySerialPort(const QSerialPortInfo& info)
|
||||||
{
|
{
|
||||||
closeAndDeleteCurrentPort();
|
closeAndDeleteCurrentPort();
|
||||||
m_currentSerialPort = new QSerialPort(info, this);
|
m_currentSerialPort = new QSerialPort(info, this);
|
||||||
m_currentSerialPort->setBaudRate(m_baudRate);
|
m_currentSerialPort->setBaudRate(m_baudRate);
|
||||||
@@ -72,7 +66,8 @@ namespace LtsSerialPortQuerry
|
|||||||
m_currentSerialPort->setStopBits(m_stopBits);
|
m_currentSerialPort->setStopBits(m_stopBits);
|
||||||
m_currentSerialPort->setFlowControl(m_flowControll);
|
m_currentSerialPort->setFlowControl(m_flowControll);
|
||||||
|
|
||||||
DEBUG_LOG(m_logger) << "Try opening Comport:" << m_currentSerialPort->portName() << " index is: " << m_currentQuerry;
|
DEBUG_LOG(m_logger) << "Try opening Comport:" << m_currentSerialPort->portName()
|
||||||
|
<< " index is: " << m_currentQuerry;
|
||||||
|
|
||||||
if (!m_currentSerialPort->open(QSerialPort::ReadWrite))
|
if (!m_currentSerialPort->open(QSerialPort::ReadWrite))
|
||||||
{
|
{
|
||||||
@@ -83,14 +78,15 @@ namespace LtsSerialPortQuerry
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connect(m_currentSerialPort, &QSerialPort::errorOccurred, this, &LtsSerialPortQuerry::onSerialPortError, Qt::UniqueConnection);
|
connect(m_currentSerialPort, &QSerialPort::errorOccurred, this, &LtsSerialPortQuerry::onSerialPortError,
|
||||||
|
Qt::UniqueConnection);
|
||||||
DEBUG_LOG(m_logger) << "Oppened comport" << m_currentSerialPort->portName();
|
DEBUG_LOG(m_logger) << "Oppened comport" << m_currentSerialPort->portName();
|
||||||
emit connectionEstablished();
|
emit connectionEstablished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsSerialPortQuerry::closeAndDeleteCurrentPort()
|
void LtsSerialPortQuerry::closeAndDeleteCurrentPort()
|
||||||
{
|
{
|
||||||
if (m_currentSerialPort)
|
if (m_currentSerialPort)
|
||||||
{
|
{
|
||||||
m_currentSerialPort->disconnect();
|
m_currentSerialPort->disconnect();
|
||||||
@@ -100,22 +96,22 @@ namespace LtsSerialPortQuerry
|
|||||||
|
|
||||||
m_currentSerialPort = nullptr;
|
m_currentSerialPort = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsSerialPortQuerry::onSerialPortError(QSerialPort::SerialPortError serialPortError)
|
void LtsSerialPortQuerry::onSerialPortError(QSerialPort::SerialPortError serialPortError)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_currentSerialPort)
|
if (!m_currentSerialPort)
|
||||||
return;
|
return;
|
||||||
DEBUG_LOG(m_logger) << "Spontaneous error " << serialPortError << " doesn't have to be an error ...";
|
DEBUG_LOG(m_logger) << "Spontaneous error " << serialPortError << " doesn't have to be an error ...";
|
||||||
|
|
||||||
const QString errStr(QStringLiteral("QSerialPort::SerialPortError ") + QString::number(serialPortError) + QStringLiteral(" from serial port ") +
|
const QString errStr(QStringLiteral("QSerialPort::SerialPortError ") + QString::number(serialPortError) +
|
||||||
m_currentSerialPort->portName() + QStringLiteral(" error: ") + m_currentSerialPort->errorString());
|
QStringLiteral(" from serial port ") + m_currentSerialPort->portName() +
|
||||||
|
QStringLiteral(" error: ") + m_currentSerialPort->errorString());
|
||||||
|
|
||||||
switch (serialPortError)
|
switch (serialPortError)
|
||||||
{
|
{
|
||||||
case QSerialPort::SerialPortError::NoError:
|
case QSerialPort::SerialPortError::NoError: {
|
||||||
{
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -123,25 +119,22 @@ namespace LtsSerialPortQuerry
|
|||||||
case QSerialPort::SerialPortError::PermissionError:
|
case QSerialPort::SerialPortError::PermissionError:
|
||||||
case QSerialPort::SerialPortError::OpenError:
|
case QSerialPort::SerialPortError::OpenError:
|
||||||
case QSerialPort::SerialPortError::NotOpenError:
|
case QSerialPort::SerialPortError::NotOpenError:
|
||||||
case QSerialPort::SerialPortError::UnknownError:
|
case QSerialPort::SerialPortError::UnknownError: {
|
||||||
{
|
|
||||||
ERROR_LOG(m_logger) << "Closing port and try to reopen it. " << m_currentSerialPort->portName();
|
ERROR_LOG(m_logger) << "Closing port and try to reopen it. " << m_currentSerialPort->portName();
|
||||||
continueQuerry();
|
continueQuerry();
|
||||||
|
|
||||||
Q_FALLTHROUGH();
|
Q_FALLTHROUGH();
|
||||||
}
|
}
|
||||||
case QSerialPort::SerialPortError::UnsupportedOperationError:
|
case QSerialPort::SerialPortError::UnsupportedOperationError: {
|
||||||
{
|
|
||||||
ERROR_LOG(m_logger) << errStr;
|
ERROR_LOG(m_logger) << errStr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
ERROR_LOG(m_logger) << "Got an Error> " << errStr << "restarting";
|
ERROR_LOG(m_logger) << "Got an Error> " << errStr << "restarting";
|
||||||
continueQuerry();
|
continueQuerry();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace LtsSerialPortQuerry
|
} // namespace LtsSerialPortQuerry
|
||||||
+11
-14
@@ -9,21 +9,18 @@
|
|||||||
|
|
||||||
namespace LtsSerialPortQuerry
|
namespace LtsSerialPortQuerry
|
||||||
{
|
{
|
||||||
class LTSSERIALPORTQUERRY_EXPORT LtsSerialPortQuerry : public QObject
|
class LTSSERIALPORTQUERRY_EXPORT LtsSerialPortQuerry : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LtsSerialPortQuerry(QObject *parent = nullptr);
|
explicit LtsSerialPortQuerry(QObject* parent = nullptr);
|
||||||
|
|
||||||
void setSerialPortSettings(const QSerialPort::BaudRate &baudRate,
|
void setSerialPortSettings(const QSerialPort::BaudRate& baudRate, const QSerialPort::OpenModeFlag& openModeFlag,
|
||||||
const QSerialPort::OpenModeFlag &openModeFlag,
|
const QSerialPort::DataBits& dataBits, const QSerialPort::FlowControl& flowControll,
|
||||||
const QSerialPort::DataBits &dataBits,
|
const QSerialPort::Parity& parity, const QSerialPort::StopBits& stopBits);
|
||||||
const QSerialPort::FlowControl &flowControll,
|
|
||||||
const QSerialPort::Parity &parity,
|
|
||||||
const QSerialPort::StopBits &stopBits);
|
|
||||||
|
|
||||||
void restartQuerry();
|
void restartQuerry();
|
||||||
QSerialPort *currentSerialPort();
|
QSerialPort* currentSerialPort();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void continueQuerry();
|
void continueQuerry();
|
||||||
@@ -32,8 +29,8 @@ namespace LtsSerialPortQuerry
|
|||||||
void connectionEstablished();
|
void connectionEstablished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NGL::INGLLogger &m_logger;
|
NGL::INGLLogger& m_logger;
|
||||||
void querrySerialPort(const QSerialPortInfo &info);
|
void querrySerialPort(const QSerialPortInfo& info);
|
||||||
void closeAndDeleteCurrentPort();
|
void closeAndDeleteCurrentPort();
|
||||||
void onSerialPortError(QSerialPort::SerialPortError serialPortError);
|
void onSerialPortError(QSerialPort::SerialPortError serialPortError);
|
||||||
QList<QSerialPortInfo> m_serialPortInfos;
|
QList<QSerialPortInfo> m_serialPortInfos;
|
||||||
@@ -44,7 +41,7 @@ namespace LtsSerialPortQuerry
|
|||||||
QSerialPort::FlowControl m_flowControll;
|
QSerialPort::FlowControl m_flowControll;
|
||||||
QSerialPort::Parity m_parity;
|
QSerialPort::Parity m_parity;
|
||||||
QSerialPort::StopBits m_stopBits;
|
QSerialPort::StopBits m_stopBits;
|
||||||
QSerialPort *m_currentSerialPort;
|
QSerialPort* m_currentSerialPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsSerialPortQuerry
|
} // namespace LtsSerialPortQuerry
|
||||||
+52
-39
@@ -34,23 +34,25 @@ using namespace LtsUtils;
|
|||||||
|
|
||||||
namespace QTest
|
namespace QTest
|
||||||
{
|
{
|
||||||
template <> char *toString(const QVector<int> &vec)
|
template <> char* toString(const QVector<int>& vec)
|
||||||
{
|
{
|
||||||
QStringList sl;
|
QStringList sl;
|
||||||
sl.reserve(vec.size());
|
sl.reserve(vec.size());
|
||||||
for (int i : vec)
|
for (int i : vec)
|
||||||
sl += QString::number(i);
|
sl += QString::number(i);
|
||||||
return qstrdup(sl.join(QLatin1Char(',')).toLatin1().constData());
|
return qstrdup(sl.join(QLatin1Char(',')).toLatin1().constData());
|
||||||
}
|
}
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||||
template <typename T1, typename T2> inline bool qCompare(const T1 &t1, const T2 &t2, const char *actual, const char *expected, const char *file, int line)
|
template <typename T1, typename T2>
|
||||||
{
|
inline bool qCompare(const T1& t1, const T2& t2, const char* actual, const char* expected, const char* file, int line)
|
||||||
return compare_helper(t1 == t2, "Compared values are not the same", toString(t1), toString(t2), actual, expected, file, line);
|
{
|
||||||
}
|
return compare_helper(t1 == t2, "Compared values are not the same", toString(t1), toString(t2), actual, expected,
|
||||||
|
file, line);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} // namespace QTest
|
} // namespace QTest
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
LtsUtilsTest tc;
|
LtsUtilsTest tc;
|
||||||
@@ -63,9 +65,7 @@ void LtsUtilsTest::test_promise()
|
|||||||
|
|
||||||
results.append(1);
|
results.append(1);
|
||||||
|
|
||||||
LtsUtils::Promise p(
|
LtsUtils::Promise p([&results](LtsUtils::ResultFunction resolve, LtsUtils::ResultFunction) {
|
||||||
[&results](LtsUtils::ResultFunction resolve, LtsUtils::ResultFunction)
|
|
||||||
{
|
|
||||||
results.append(4);
|
results.append(4);
|
||||||
qDebug() << "LtsUtils Promise: Promise executed! Resolving now";
|
qDebug() << "LtsUtils Promise: Promise executed! Resolving now";
|
||||||
|
|
||||||
@@ -75,17 +75,13 @@ void LtsUtilsTest::test_promise()
|
|||||||
results.append(2);
|
results.append(2);
|
||||||
|
|
||||||
bool resolved = false;
|
bool resolved = false;
|
||||||
p.resolved(
|
p.resolved([&resolved, &results](const QVariant& value) {
|
||||||
[&resolved, &results](const QVariant &value)
|
|
||||||
{
|
|
||||||
results.append(5);
|
results.append(5);
|
||||||
qDebug() << "LtsUtils Promise: Promise was resolved with value" << value;
|
qDebug() << "LtsUtils Promise: Promise was resolved with value" << value;
|
||||||
resolved = true;
|
resolved = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
p.rejected(
|
p.rejected([](const QVariant& val) {
|
||||||
[](const QVariant &val)
|
|
||||||
{
|
|
||||||
qCritical() << "rejected with val" << val;
|
qCritical() << "rejected with val" << val;
|
||||||
QFAIL("Promise unexpectedly rejected");
|
QFAIL("Promise unexpectedly rejected");
|
||||||
});
|
});
|
||||||
@@ -264,7 +260,8 @@ void LtsUtilsTest::test_fromIntArray2D()
|
|||||||
{
|
{
|
||||||
qDebug("LtsUtils: test_fromIntArray2D");
|
qDebug("LtsUtils: test_fromIntArray2D");
|
||||||
|
|
||||||
QString str = LtsUtils::IntArray2D({{0, 2}, {1, 3}, {2, 999999999}, {3, -2147483647}, {4, 2147483647}, {5, 123456}}).toPgString();
|
QString str = LtsUtils::IntArray2D({{0, 2}, {1, 3}, {2, 999999999}, {3, -2147483647}, {4, 2147483647}, {5, 123456}})
|
||||||
|
.toPgString();
|
||||||
|
|
||||||
qDebug() << "LtsUtils: Result " << str;
|
qDebug() << "LtsUtils: Result " << str;
|
||||||
QCOMPARE(str, QLatin1String("{{0,2},{1,3},{2,999999999},{3,-2147483647},{4,2147483647},{5,123456}}"));
|
QCOMPARE(str, QLatin1String("{{0,2},{1,3},{2,999999999},{3,-2147483647},{4,2147483647},{5,123456}}"));
|
||||||
@@ -298,7 +295,9 @@ void LtsUtilsTest::test_fromBigintArray2D()
|
|||||||
{
|
{
|
||||||
qDebug("LtsUtils: test_fromBigintArray2D");
|
qDebug("LtsUtils: test_fromBigintArray2D");
|
||||||
|
|
||||||
QString str = LtsUtils::BigintArray2D({{0, -123456789}, {1, -2147483647}, {2, 999999999999}, {3, 123456789}, {4, 2147483647}}).toPgString();
|
QString str =
|
||||||
|
LtsUtils::BigintArray2D({{0, -123456789}, {1, -2147483647}, {2, 999999999999}, {3, 123456789}, {4, 2147483647}})
|
||||||
|
.toPgString();
|
||||||
|
|
||||||
qDebug() << "LtsUtils: Result " << str;
|
qDebug() << "LtsUtils: Result " << str;
|
||||||
QCOMPARE(str, QLatin1String("{{0,-123456789},{1,-2147483647},{2,999999999999},{3,123456789},{4,2147483647}}"));
|
QCOMPARE(str, QLatin1String("{{0,-123456789},{1,-2147483647},{2,999999999999},{3,123456789},{4,2147483647}}"));
|
||||||
@@ -337,10 +336,14 @@ void LtsUtilsTest::test_bitArray()
|
|||||||
qDebug("LtsUtils: test_bitArray");
|
qDebug("LtsUtils: test_bitArray");
|
||||||
|
|
||||||
{
|
{
|
||||||
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(8)).size() == 1, " wrong size of underlying data");
|
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(8)).size() == 1,
|
||||||
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(9)).size() == 2, " wrong size of underlying data");
|
" wrong size of underlying data");
|
||||||
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(16)).size() == 2, " wrong size of underlying data");
|
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(9)).size() == 2,
|
||||||
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(17)).size() == 3, " wrong size of underlying data");
|
" wrong size of underlying data");
|
||||||
|
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(16)).size() == 2,
|
||||||
|
" wrong size of underlying data");
|
||||||
|
QVERIFY2(LtsUtils::BitArray::convert<std::vector<uint8_t>>(QBitArray(17)).size() == 3,
|
||||||
|
" wrong size of underlying data");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -483,7 +486,7 @@ void LtsUtilsTest::test_convert()
|
|||||||
const auto resultQVec = LtsUtils::convert<QVector<std::vector<uint8_t>>>(resultVec);
|
const auto resultQVec = LtsUtils::convert<QVector<std::vector<uint8_t>>>(resultVec);
|
||||||
QCOMPARE(resultVec.size(), containerLen);
|
QCOMPARE(resultVec.size(), containerLen);
|
||||||
QCOMPARE(resultQVec.size(), containerLen);
|
QCOMPARE(resultQVec.size(), containerLen);
|
||||||
for (const auto &inner : resultQVec)
|
for (const auto& inner : resultQVec)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < containerLen; ++i)
|
for (int i = 0; i < containerLen; ++i)
|
||||||
QCOMPARE(inner.at(i), i + 1);
|
QCOMPARE(inner.at(i), i + 1);
|
||||||
@@ -499,7 +502,7 @@ class Emitter : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signal1();
|
void signal1();
|
||||||
void signal2(int i);
|
void signal2(int i);
|
||||||
};
|
};
|
||||||
@@ -508,11 +511,14 @@ class Spy : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void slot1() { ++m_slot1Count; }
|
void slot1()
|
||||||
|
{
|
||||||
|
++m_slot1Count;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int m_slot1Count{0};
|
int m_slot1Count{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -520,7 +526,8 @@ void LtsUtilsTest::test_connection()
|
|||||||
{
|
{
|
||||||
Emitter emitter;
|
Emitter emitter;
|
||||||
Spy spy;
|
Spy spy;
|
||||||
std::unique_ptr<LtsUtils::IConnection> conn(LtsUtils::createConnection(&emitter, &Emitter::signal1, &spy, &Spy::slot1));
|
std::unique_ptr<LtsUtils::IConnection> conn(
|
||||||
|
LtsUtils::createConnection(&emitter, &Emitter::signal1, &spy, &Spy::slot1));
|
||||||
emit emitter.signal1();
|
emit emitter.signal1();
|
||||||
QCOMPARE(spy.m_slot1Count, 0);
|
QCOMPARE(spy.m_slot1Count, 0);
|
||||||
|
|
||||||
@@ -537,7 +544,8 @@ void LtsUtilsTest::test_queuedConnection()
|
|||||||
{
|
{
|
||||||
Emitter emitter;
|
Emitter emitter;
|
||||||
Spy spy;
|
Spy spy;
|
||||||
std::unique_ptr<LtsUtils::IConnection> conn(LtsUtils::createConnection(&emitter, &Emitter::signal2, &spy, &Spy::slot1));
|
std::unique_ptr<LtsUtils::IConnection> conn(
|
||||||
|
LtsUtils::createConnection(&emitter, &Emitter::signal2, &spy, &Spy::slot1));
|
||||||
emit emitter.signal2(42);
|
emit emitter.signal2(42);
|
||||||
QCOMPARE(spy.m_slot1Count, 0);
|
QCOMPARE(spy.m_slot1Count, 0);
|
||||||
|
|
||||||
@@ -552,8 +560,10 @@ void LtsUtilsTest::test_signalSignalConnection()
|
|||||||
{
|
{
|
||||||
Emitter emitter;
|
Emitter emitter;
|
||||||
Spy spy;
|
Spy spy;
|
||||||
std::unique_ptr<LtsUtils::IConnection> signalSignalConn(LtsUtils::createConnection(&emitter, &Emitter::signal2, &emitter, &Emitter::signal1));
|
std::unique_ptr<LtsUtils::IConnection> signalSignalConn(
|
||||||
std::unique_ptr<LtsUtils::IConnection> signalSlotConn(LtsUtils::createConnection(&emitter, &Emitter::signal1, &spy, &Spy::slot1));
|
LtsUtils::createConnection(&emitter, &Emitter::signal2, &emitter, &Emitter::signal1));
|
||||||
|
std::unique_ptr<LtsUtils::IConnection> signalSlotConn(
|
||||||
|
LtsUtils::createConnection(&emitter, &Emitter::signal1, &spy, &Spy::slot1));
|
||||||
|
|
||||||
signalSignalConn->connect();
|
signalSignalConn->connect();
|
||||||
signalSlotConn->connect();
|
signalSlotConn->connect();
|
||||||
@@ -951,10 +961,12 @@ void LtsUtilsTest::test_byteStreamFromSfmMessage()
|
|||||||
msg.setId(16);
|
msg.setId(16);
|
||||||
msg.setRtr(true);
|
msg.setRtr(true);
|
||||||
const quint8 payloadArray[] = {0x11, 0x02, 0x03, 0x04, 0x50};
|
const quint8 payloadArray[] = {0x11, 0x02, 0x03, 0x04, 0x50};
|
||||||
msg.setPayload(QByteArray(reinterpret_cast<const char *>(payloadArray), sizeof(payloadArray)));
|
msg.setPayload(QByteArray(reinterpret_cast<const char*>(payloadArray), sizeof(payloadArray)));
|
||||||
|
|
||||||
const quint8 expectedResultArray[] = {0x02, 0x80, 0x00, 0x10, 0x05, 0x80, 0x91, 0x80, 0x82, 0x80, 0x83, 0x04, 0x50, 0x00, 0x03};
|
const quint8 expectedResultArray[] = {0x02, 0x80, 0x00, 0x10, 0x05, 0x80, 0x91, 0x80,
|
||||||
QByteArray expectedResult = QByteArray(reinterpret_cast<const char *>(expectedResultArray), sizeof(expectedResultArray));
|
0x82, 0x80, 0x83, 0x04, 0x50, 0x00, 0x03};
|
||||||
|
QByteArray expectedResult =
|
||||||
|
QByteArray(reinterpret_cast<const char*>(expectedResultArray), sizeof(expectedResultArray));
|
||||||
|
|
||||||
QByteArray byteMessage = byteStreamFromSfmMessage(msg);
|
QByteArray byteMessage = byteStreamFromSfmMessage(msg);
|
||||||
|
|
||||||
@@ -976,17 +988,18 @@ void LtsUtilsTest::test_byteStreamToSfmMessage()
|
|||||||
msgComplete.setRtr(true);
|
msgComplete.setRtr(true);
|
||||||
|
|
||||||
const quint8 payloadArray[] = {0x11, 0x02, 0x03, 0x04, 0x50, 0x00};
|
const quint8 payloadArray[] = {0x11, 0x02, 0x03, 0x04, 0x50, 0x00};
|
||||||
msgComplete.setPayload(QByteArray(reinterpret_cast<const char *>(payloadArray), sizeof(payloadArray)));
|
msgComplete.setPayload(QByteArray(reinterpret_cast<const char*>(payloadArray), sizeof(payloadArray)));
|
||||||
|
|
||||||
const quint8 dataArray[] = {0x02, 0x80, 0x00, 0x10, 0x06, 0x80, 0x91, 0x80, 0x82, 0x80, 0x83, 0x04, 0x50, 0x00, 0xFF, 0x03};
|
const quint8 dataArray[] = {0x02, 0x80, 0x00, 0x10, 0x06, 0x80, 0x91, 0x80,
|
||||||
QByteArray dataComplete = QByteArray(reinterpret_cast<const char *>(dataArray), sizeof(dataArray));
|
0x82, 0x80, 0x83, 0x04, 0x50, 0x00, 0xFF, 0x03};
|
||||||
|
QByteArray dataComplete = QByteArray(reinterpret_cast<const char*>(dataArray), sizeof(dataArray));
|
||||||
|
|
||||||
SfmMessage result;
|
SfmMessage result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = byteStreamToSfmMessage(dataComplete);
|
result = byteStreamToSfmMessage(dataComplete);
|
||||||
}
|
}
|
||||||
catch (const ConversionError &ex)
|
catch (const ConversionError& ex)
|
||||||
{
|
{
|
||||||
qDebug() << ex.what();
|
qDebug() << ex.what();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
class LtsUtilsTest : public QObject
|
class LtsUtilsTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
|
||||||
void test_toIntArray();
|
void test_toIntArray();
|
||||||
void test_fromIntArray();
|
void test_fromIntArray();
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Function which waits (QEventLoop) for a success signal or a cancelation signal, optionally with a timeout
|
||||||
|
* Useful for blocking on async things
|
||||||
|
* $Id: connection.h 45834 2019-03-01 12:56:15Z ehrlicher $
|
||||||
|
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/swp_2023_devel/Lts/Common/LtsUtils/LtsUtilsCore/connection.h $
|
||||||
|
* $Author: ehrlicher $
|
||||||
|
*
|
||||||
|
* Created by Mike Wille, ESZS, 2024-03-03
|
||||||
|
*/
|
||||||
|
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
@@ -7,25 +18,28 @@
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
template <typename Func> void addConnect(QEventLoop &x, bool &success, const typename QtPrivate::FunctionPointer<Func>::Object *sender, Func signal, bool isSuccess)
|
template <typename Func>
|
||||||
{
|
void addConnect(QEventLoop& x, bool& success, const typename QtPrivate::FunctionPointer<Func>::Object* sender,
|
||||||
|
Func signal, bool isSuccess)
|
||||||
|
{
|
||||||
if (isSuccess)
|
if (isSuccess)
|
||||||
{
|
{
|
||||||
QObject::connect(sender, signal, &x, [&success]() { success = true; });
|
QObject::connect(sender, signal, &x, [&success]() { success = true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(sender, signal, &x, &QEventLoop::quit, Qt::QueuedConnection);
|
QObject::connect(sender, signal, &x, &QEventLoop::quit, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Func, typename... Connect>
|
template <typename Func, typename... Connect>
|
||||||
void addConnect(QEventLoop &x, bool &success, const typename QtPrivate::FunctionPointer<Func>::Object *sender, Func signal, bool isSuccess, Connect... connects)
|
void addConnect(QEventLoop& x, bool& success, const typename QtPrivate::FunctionPointer<Func>::Object* sender,
|
||||||
{
|
Func signal, bool isSuccess, Connect... connects)
|
||||||
|
{
|
||||||
addConnect(x, success, sender, signal, isSuccess);
|
addConnect(x, success, sender, signal, isSuccess);
|
||||||
addConnect(x, success, connects...);
|
addConnect(x, success, connects...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Connect> void await(Connect... connects) noexcept(false)
|
template <typename... Connect> void await(Connect... connects) noexcept(false)
|
||||||
{
|
{
|
||||||
QEventLoop x;
|
QEventLoop x;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
@@ -38,10 +52,10 @@ namespace LtsUtils
|
|||||||
|
|
||||||
throw std::runtime_error("Failed.");
|
throw std::runtime_error("Failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Connect> void awaitTimeout(const int timeoutMs, Connect... connects) noexcept(false)
|
template <typename... Connect> void awaitTimeout(const int timeoutMs, Connect... connects) noexcept(false)
|
||||||
{
|
{
|
||||||
std::unique_ptr<QTimer> t(new QTimer);
|
std::unique_ptr<QTimer> t(new QTimer);
|
||||||
bool timeout = false;
|
bool timeout = false;
|
||||||
|
|
||||||
@@ -49,11 +63,7 @@ namespace LtsUtils
|
|||||||
{
|
{
|
||||||
t->setInterval(timeoutMs);
|
t->setInterval(timeoutMs);
|
||||||
t->setSingleShot(true);
|
t->setSingleShot(true);
|
||||||
QObject::connect(t.get(),
|
QObject::connect(t.get(), &QTimer::timeout, t.get(), [&timeout]() {
|
||||||
&QTimer::timeout,
|
|
||||||
t.get(),
|
|
||||||
[&timeout]()
|
|
||||||
{
|
|
||||||
fprintf(stderr, "awaitTimeout: timed out!\n");
|
fprintf(stderr, "awaitTimeout: timed out!\n");
|
||||||
timeout = true;
|
timeout = true;
|
||||||
});
|
});
|
||||||
@@ -67,15 +77,13 @@ namespace LtsUtils
|
|||||||
|
|
||||||
throw std::runtime_error("Timeout.");
|
throw std::runtime_error("Timeout.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Func1, typename Func2>
|
template <typename Func1, typename Func2>
|
||||||
void awaitWithCancelationSignal(const typename QtPrivate::FunctionPointer<Func1>::Object *sender1,
|
void awaitWithCancelationSignal(const typename QtPrivate::FunctionPointer<Func1>::Object* sender1, Func1 signal1,
|
||||||
Func1 signal1,
|
const typename QtPrivate::FunctionPointer<Func2>::Object* sender2, Func2 signal2,
|
||||||
const typename QtPrivate::FunctionPointer<Func2>::Object *sender2,
|
|
||||||
Func2 signal2,
|
|
||||||
const int timeoutMs = 0) noexcept(false)
|
const int timeoutMs = 0) noexcept(false)
|
||||||
{
|
{
|
||||||
if (timeoutMs > 0)
|
if (timeoutMs > 0)
|
||||||
{
|
{
|
||||||
awaitTimeout(timeoutMs, sender1, signal1, true, sender2, signal2, false);
|
awaitTimeout(timeoutMs, sender1, signal1, true, sender2, signal2, false);
|
||||||
@@ -83,5 +91,5 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
await(sender1, signal1, true, sender2, signal2, false);
|
await(sender1, signal1, true, sender2, signal2, false);
|
||||||
}
|
}
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* General Qt-connection
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Christian Fröbel, SLSE, 2017-07-24
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -11,36 +18,36 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class IConnection
|
class IConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IConnection() = default;
|
virtual ~IConnection() = default;
|
||||||
virtual void connect(Qt::ConnectionType = Qt::AutoConnection) = 0;
|
virtual void connect(Qt::ConnectionType = Qt::AutoConnection) = 0;
|
||||||
virtual void disconnect() = 0;
|
virtual void disconnect() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DummyConnection : public IConnection
|
class DummyConnection : public IConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void connect(Qt::ConnectionType = Qt::AutoConnection) override {}
|
void connect(Qt::ConnectionType = Qt::AutoConnection) override {}
|
||||||
|
|
||||||
void disconnect() override {}
|
void disconnect() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class T> struct ExtractClass;
|
template <class T> struct ExtractClass;
|
||||||
|
|
||||||
template <class T, class Member> struct ExtractClass<Member T::*>
|
template <class T, class Member> struct ExtractClass<Member T::*>
|
||||||
{
|
{
|
||||||
using type = T;
|
using type = T;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <class Signal, class Slot> class Connection : public IConnection
|
template <class Signal, class Slot> class Connection : public IConnection
|
||||||
{
|
{
|
||||||
static_assert(std::is_member_function_pointer_v<Signal>, "Must be a pointer to method");
|
static_assert(std::is_member_function_pointer_v<Signal>, "Must be a pointer to method");
|
||||||
static_assert(std::is_member_function_pointer_v<Slot>, "Must be a pointer to method");
|
static_assert(std::is_member_function_pointer_v<Slot>, "Must be a pointer to method");
|
||||||
|
|
||||||
@@ -51,11 +58,8 @@ namespace LtsUtils
|
|||||||
static_assert(std::is_base_of_v<QObject, Target>, "Must be derived from QObject");
|
static_assert(std::is_base_of_v<QObject, Target>, "Must be derived from QObject");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Connection(Emitter *emitter, Signal signal, Target *target, Slot slot)
|
Connection(Emitter* emitter, Signal signal, Target* target, Slot slot)
|
||||||
: m_emitter(emitter)
|
: m_emitter(emitter), m_signal(signal), m_target(target), m_slot(slot)
|
||||||
, m_signal(signal)
|
|
||||||
, m_target(target)
|
|
||||||
, m_slot(slot)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(emitter);
|
Q_ASSERT(emitter);
|
||||||
Q_ASSERT(signal);
|
Q_ASSERT(signal);
|
||||||
@@ -93,15 +97,13 @@ namespace LtsUtils
|
|||||||
QPointer<Target> m_target;
|
QPointer<Target> m_target;
|
||||||
Slot m_slot;
|
Slot m_slot;
|
||||||
QMetaObject::Connection m_conn;
|
QMetaObject::Connection m_conn;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Signal, class Slot>
|
template <class Signal, class Slot>
|
||||||
Connection<Signal, Slot> *createConnection(typename detail::ExtractClass<Signal>::type *emitter,
|
Connection<Signal, Slot>* createConnection(typename detail::ExtractClass<Signal>::type* emitter, Signal signal,
|
||||||
Signal signal,
|
typename detail::ExtractClass<Slot>::type* target, Slot slot)
|
||||||
typename detail::ExtractClass<Slot>::type *target,
|
{
|
||||||
Slot slot)
|
|
||||||
{
|
|
||||||
return new Connection<Signal, Slot>(emitter, signal, target, slot);
|
return new Connection<Signal, Slot>(emitter, signal, target, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+2
-7
@@ -4,14 +4,9 @@
|
|||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
enum class DataModification
|
enum class DataModification { eAdded, eModified, eRemoved };
|
||||||
{
|
|
||||||
eAdded,
|
|
||||||
eModified,
|
|
||||||
eRemoved
|
|
||||||
};
|
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &str, DataModification mod)
|
inline std::ostream& operator<<(std::ostream& str, DataModification mod)
|
||||||
{
|
{
|
||||||
switch (mod)
|
switch (mod)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,15 +9,15 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace BitArray
|
namespace BitArray
|
||||||
{
|
{
|
||||||
constexpr inline int bitNumber(int position)
|
constexpr inline int bitNumber(int position)
|
||||||
{
|
{
|
||||||
return 7 - (position % 8);
|
return 7 - (position % 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline bool testBit(const T &bitField, int position, bool *oob = nullptr)
|
template <typename T> inline bool testBit(const T& bitField, int position, bool* oob = nullptr)
|
||||||
{
|
{
|
||||||
const size_t byteNum = position / 8;
|
const size_t byteNum = position / 8;
|
||||||
if (byteNum >= bitField.size())
|
if (byteNum >= bitField.size())
|
||||||
{
|
{
|
||||||
@@ -30,10 +30,10 @@ namespace LtsUtils
|
|||||||
|
|
||||||
const typename T::value_type mask = 1 << bitNumber(position);
|
const typename T::value_type mask = 1 << bitNumber(position);
|
||||||
return ((bitField.at(byteNum) & mask) == mask);
|
return ((bitField.at(byteNum) & mask) == mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline bool setBit(T &bitField, int position, bool set = true)
|
template <typename T> inline bool setBit(T& bitField, int position, bool set = true)
|
||||||
{
|
{
|
||||||
const size_t byteNum = position / 8;
|
const size_t byteNum = position / 8;
|
||||||
if (byteNum >= bitField.size())
|
if (byteNum >= bitField.size())
|
||||||
return false;
|
return false;
|
||||||
@@ -45,16 +45,16 @@ namespace LtsUtils
|
|||||||
bitField[byteNum] &= ~mask;
|
bitField[byteNum] &= ~mask;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline bool clearBit(T &bitField, int position)
|
template <typename T> inline bool clearBit(T& bitField, int position)
|
||||||
{
|
{
|
||||||
return setBit(bitField, position, false);
|
return setBit(bitField, position, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SUPPORT_QBITARRAY
|
#ifdef SUPPORT_QBITARRAY
|
||||||
template <typename T> inline T convert(const QBitArray &bitArray)
|
template <typename T> inline T convert(const QBitArray& bitArray)
|
||||||
{
|
{
|
||||||
T ret;
|
T ret;
|
||||||
ret.resize((bitArray.size() + 7) / 8, 0);
|
ret.resize((bitArray.size() + 7) / 8, 0);
|
||||||
|
|
||||||
@@ -68,10 +68,10 @@ namespace LtsUtils
|
|||||||
ret[byteNum] &= ~mask;
|
ret[byteNum] &= ~mask;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline QBitArray convert(T &bitField, int realSize)
|
template <typename T> inline QBitArray convert(T& bitField, int realSize)
|
||||||
{
|
{
|
||||||
QBitArray ba(realSize);
|
QBitArray ba(realSize);
|
||||||
for (int32_t i = 0; i < realSize; ++i)
|
for (int32_t i = 0; i < realSize; ++i)
|
||||||
{
|
{
|
||||||
@@ -81,10 +81,10 @@ namespace LtsUtils
|
|||||||
ba[i] = bit;
|
ba[i] = bit;
|
||||||
}
|
}
|
||||||
return ba;
|
return ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace BitArray
|
} // namespace BitArray
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -8,30 +8,30 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T, typename S> inline void convert(const S &in, T &out)
|
template <typename T, typename S> inline void convert(const S& in, T& out)
|
||||||
{
|
{
|
||||||
static_assert(!std::is_same_v<S, T>, "Try to convert a type to the same type - is useless");
|
static_assert(!std::is_same_v<S, T>, "Try to convert a type to the same type - is useless");
|
||||||
out.reserve(static_cast<int>(in.size()));
|
out.reserve(static_cast<int>(in.size()));
|
||||||
std::copy(in.begin(), in.end(), std::back_inserter(out));
|
std::copy(in.begin(), in.end(), std::back_inserter(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename S> inline T convert(const S &in)
|
template <typename T, typename S> inline T convert(const S& in)
|
||||||
{
|
{
|
||||||
static_assert(!std::is_same_v<S, T>, "Try to convert a type to the same type - is useless");
|
static_assert(!std::is_same_v<S, T>, "Try to convert a type to the same type - is useless");
|
||||||
T out;
|
T out;
|
||||||
convert(in, out);
|
convert(in, out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline QByteArray toQByteArray(const T &in)
|
template <typename T> inline QByteArray toQByteArray(const T& in)
|
||||||
{
|
{
|
||||||
return convert<QByteArray>(in);
|
return convert<QByteArray>(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename V = typename T::value_type> bool isInVector(const T &vec, const V &valueToSearch)
|
template <typename T, typename V = typename T::value_type> bool isInVector(const T& vec, const V& valueToSearch)
|
||||||
{
|
{
|
||||||
const auto end = vec.end();
|
const auto end = vec.end();
|
||||||
return std::find(vec.begin(), end, valueToSearch) != end;
|
return std::find(vec.begin(), end, valueToSearch) != end;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+6
-6
@@ -14,11 +14,11 @@ class QImage;
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const std::vector<uint8_t> &data);
|
LTSUTILSCORE_EXPORT QPixmap getPixmap(const std::vector<uint8_t>& data);
|
||||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const QByteArray &data);
|
LTSUTILSCORE_EXPORT QPixmap getPixmap(const QByteArray& data);
|
||||||
LTSUTILSCORE_EXPORT QImage getImage(const std::vector<uint8_t> &data);
|
LTSUTILSCORE_EXPORT QImage getImage(const std::vector<uint8_t>& data);
|
||||||
LTSUTILSCORE_EXPORT QImage getImage(const QByteArray &data);
|
LTSUTILSCORE_EXPORT QImage getImage(const QByteArray& data);
|
||||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromPixmap(const QPixmap &pixmap, bool *bIsPng = nullptr);
|
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromPixmap(const QPixmap& pixmap, bool* bIsPng = nullptr);
|
||||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromImage(const QImage &image, bool *bIsPng = nullptr);
|
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromImage(const QImage& image, bool* bIsPng = nullptr);
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* JsonObject
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Christian Fröbel, SLSE, 2017-10-26
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -21,81 +28,95 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class JsonParseError : public std::runtime_error
|
class JsonParseError : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonParseError(const QJsonParseError &err)
|
JsonParseError(const QJsonParseError& err)
|
||||||
: std::runtime_error("json parse error: " + err.errorString().toStdString() + " - at offset " + std::to_string(err.offset))
|
: std::runtime_error("json parse error: " + err.errorString().toStdString() + " - at offset " +
|
||||||
|
std::to_string(err.offset))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonError : public std::runtime_error
|
class JsonError : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using std::runtime_error::runtime_error;
|
using std::runtime_error::runtime_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonKeyError : public JsonError
|
class JsonKeyError : public JsonError
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using JsonError::JsonError;
|
using JsonError::JsonError;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonRangeError : public JsonError
|
class JsonRangeError : public JsonError
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using JsonError::JsonError;
|
using JsonError::JsonError;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonTypeError : public JsonError
|
class JsonTypeError : public JsonError
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using JsonError::JsonError;
|
using JsonError::JsonError;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonObject
|
class JsonObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class Key;
|
class Key;
|
||||||
|
|
||||||
JsonObject() = default;
|
JsonObject() = default;
|
||||||
|
|
||||||
explicit JsonObject(const QJsonObject &json)
|
explicit JsonObject(const QJsonObject& json) : m_json(json), m_jsonIsSet(true) {}
|
||||||
: m_json(json)
|
|
||||||
, m_jsonIsSet(true)
|
explicit JsonObject(QJsonObject&& json) : m_json(std::move(json)), m_jsonIsSet(true) {}
|
||||||
|
|
||||||
|
static inline JsonObject fromJson(const char* json, int len = -1);
|
||||||
|
|
||||||
|
static inline JsonObject fromJson(const QByteArray& json)
|
||||||
{
|
{
|
||||||
|
return fromJson(json.data(), json.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit JsonObject(QJsonObject &&json)
|
static inline JsonObject fromJson(const std::string& json)
|
||||||
: m_json(std::move(json))
|
|
||||||
, m_jsonIsSet(true)
|
|
||||||
{
|
{
|
||||||
|
return fromJson(json.c_str(), json.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline JsonObject fromJson(const char *json, int len = -1);
|
static inline JsonObject fromJsonSafe(const char* json, int len = -1) noexcept(false);
|
||||||
|
|
||||||
static inline JsonObject fromJson(const QByteArray &json) { return fromJson(json.data(), json.size()); }
|
static inline JsonObject fromJsonSafe(const QByteArray& json) noexcept(false)
|
||||||
|
{
|
||||||
|
return fromJsonSafe(json.data(), json.size());
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonObject fromJson(const std::string &json) { return fromJson(json.c_str(), json.size()); }
|
static inline JsonObject fromJsonSafe(const std::string& json) noexcept(false)
|
||||||
|
{
|
||||||
|
return fromJsonSafe(json.c_str(), json.size());
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonObject fromJsonSafe(const char *json, int len = -1) noexcept(false);
|
template <class T> [[nodiscard]] bool contains(const Key& key) const;
|
||||||
|
|
||||||
static inline JsonObject fromJsonSafe(const QByteArray &json) noexcept(false) { return fromJsonSafe(json.data(), json.size()); }
|
[[nodiscard]] bool isNull(const Key& key) const
|
||||||
|
{
|
||||||
|
return contains<void>(key);
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonObject fromJsonSafe(const std::string &json) noexcept(false) { return fromJsonSafe(json.c_str(), json.size()); }
|
[[nodiscard]] bool isEmpty() const
|
||||||
|
{
|
||||||
|
return m_json.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
template <class T> [[nodiscard]] bool contains(const Key &key) const;
|
[[nodiscard]] bool isValid() const
|
||||||
|
{
|
||||||
|
return m_jsonIsSet;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool isNull(const Key &key) const { return contains<void>(key); }
|
template <class T> T value(const Key& key) const noexcept(false);
|
||||||
|
|
||||||
[[nodiscard]] bool isEmpty() const { return m_json.isEmpty(); }
|
template <class T> T valueOr(const Key& key, const T& defaultValue) const noexcept(false);
|
||||||
|
|
||||||
[[nodiscard]] bool isValid() const { return m_jsonIsSet; }
|
|
||||||
|
|
||||||
template <class T> T value(const Key &key) const noexcept(false);
|
|
||||||
|
|
||||||
template <class T> T valueOr(const Key &key, const T &defaultValue) const noexcept(false);
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] bool isMap() const;
|
template <class T> [[nodiscard]] bool isMap() const;
|
||||||
|
|
||||||
@@ -103,47 +124,56 @@ namespace LtsUtils
|
|||||||
|
|
||||||
template <class T> std::map<std::string, T> toStdMap() const;
|
template <class T> std::map<std::string, T> toStdMap() const;
|
||||||
|
|
||||||
bool operator==(const JsonObject &other) const { return m_json == other.m_json; }
|
bool operator==(const JsonObject& other) const
|
||||||
|
{
|
||||||
|
return m_json == other.m_json;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator!=(const JsonObject &other) const { return !(*this == other); }
|
bool operator!=(const JsonObject& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
class Key
|
class Key
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Key(QString s)
|
Key(QString s) : m_s(std::move(s)) {}
|
||||||
: m_s(std::move(s))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Key(const std::string &s)
|
Key(const std::string& s) : m_s(QString::fromStdString(s)) {}
|
||||||
: m_s(QString::fromStdString(s))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Key(const char *s)
|
Key(const char* s) : m_s(QString::fromUtf8(s)) {}
|
||||||
: m_s(QString::fromUtf8(s))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const QString &() const { return m_s; }
|
operator const QString&() const
|
||||||
|
{
|
||||||
|
return m_s;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_s;
|
const QString m_s;
|
||||||
};
|
};
|
||||||
|
|
||||||
operator const QJsonObject &() const { return m_json; }
|
operator const QJsonObject&() const
|
||||||
|
{
|
||||||
|
return m_json;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] const QJsonObject &object() const { return m_json; }
|
[[nodiscard]] const QJsonObject& object() const
|
||||||
|
{
|
||||||
|
return m_json;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] bool containsAny(const QString &key) const { return m_json.contains(key); }
|
[[nodiscard]] bool containsAny(const QString& key) const
|
||||||
|
{
|
||||||
|
return m_json.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject m_json;
|
QJsonObject m_json;
|
||||||
bool m_jsonIsSet = false;
|
bool m_jsonIsSet = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonObject JsonObject::fromJson(const char *json, int len)
|
JsonObject JsonObject::fromJson(const char* json, int len)
|
||||||
{
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen(json);
|
len = strlen(json);
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@@ -155,10 +185,10 @@ namespace LtsUtils
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
return JsonObject(doc.object());
|
return JsonObject(doc.object());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject JsonObject::fromJsonSafe(const char *json, int len) noexcept(false)
|
JsonObject JsonObject::fromJsonSafe(const char* json, int len) noexcept(false)
|
||||||
{
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen(json);
|
len = strlen(json);
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@@ -170,46 +200,62 @@ namespace LtsUtils
|
|||||||
throw JsonTypeError("JSON root is not an object");
|
throw JsonTypeError("JSON root is not an object");
|
||||||
|
|
||||||
return JsonObject(doc.object());
|
return JsonObject(doc.object());
|
||||||
}
|
}
|
||||||
|
|
||||||
class JsonArray
|
class JsonArray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonArray() = default;
|
JsonArray() = default;
|
||||||
|
|
||||||
explicit JsonArray(const QJsonArray &json)
|
explicit JsonArray(const QJsonArray& json) : m_json(json), m_jsonIsSet(true) {}
|
||||||
: m_json(json)
|
|
||||||
, m_jsonIsSet(true)
|
explicit JsonArray(QJsonArray&& json) : m_json(std::move(json)), m_jsonIsSet(true) {}
|
||||||
|
|
||||||
|
static inline JsonArray fromJson(const char* json, int len = -1);
|
||||||
|
|
||||||
|
static inline JsonArray fromJson(const QByteArray& json)
|
||||||
{
|
{
|
||||||
|
return fromJson(json.data(), json.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit JsonArray(QJsonArray &&json)
|
static inline JsonArray fromJson(const std::string& json)
|
||||||
: m_json(std::move(json))
|
|
||||||
, m_jsonIsSet(true)
|
|
||||||
{
|
{
|
||||||
|
return fromJson(json.c_str(), json.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline JsonArray fromJson(const char *json, int len = -1);
|
static inline JsonArray fromJsonSafe(const char* json, int len = -1) noexcept(false);
|
||||||
|
|
||||||
static inline JsonArray fromJson(const QByteArray &json) { return fromJson(json.data(), json.size()); }
|
static inline JsonArray fromJsonSafe(const QByteArray& json) noexcept(false)
|
||||||
|
{
|
||||||
|
return fromJson(json.data(), json.size());
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonArray fromJson(const std::string &json) { return fromJson(json.c_str(), json.size()); }
|
static inline JsonArray fromJsonSafe(const std::string& json) noexcept(false)
|
||||||
|
{
|
||||||
|
return fromJson(json.c_str(), json.size());
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonArray fromJsonSafe(const char *json, int len = -1) noexcept(false);
|
[[nodiscard]] int size() const
|
||||||
|
{
|
||||||
|
return m_json.size();
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonArray fromJsonSafe(const QByteArray &json) noexcept(false) { return fromJson(json.data(), json.size()); }
|
[[nodiscard]] bool isEmpty() const
|
||||||
|
{
|
||||||
|
return m_json.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
static inline JsonArray fromJsonSafe(const std::string &json) noexcept(false) { return fromJson(json.c_str(), json.size()); }
|
[[nodiscard]] bool isValid() const
|
||||||
|
{
|
||||||
[[nodiscard]] int size() const { return m_json.size(); }
|
return m_jsonIsSet;
|
||||||
|
}
|
||||||
[[nodiscard]] bool isEmpty() const { return m_json.isEmpty(); }
|
|
||||||
|
|
||||||
[[nodiscard]] bool isValid() const { return m_jsonIsSet; }
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] bool contains(int index) const noexcept(false);
|
template <class T> [[nodiscard]] bool contains(int index) const noexcept(false);
|
||||||
|
|
||||||
[[nodiscard]] bool isNull(int index) const noexcept(false) { return contains<void>(index); }
|
[[nodiscard]] bool isNull(int index) const noexcept(false)
|
||||||
|
{
|
||||||
|
return contains<void>(index);
|
||||||
|
}
|
||||||
|
|
||||||
template <class T> T at(int index) const noexcept(false);
|
template <class T> T at(int index) const noexcept(false);
|
||||||
|
|
||||||
@@ -219,19 +265,28 @@ namespace LtsUtils
|
|||||||
|
|
||||||
template <class T> std::vector<T> toStdVector() const;
|
template <class T> std::vector<T> toStdVector() const;
|
||||||
|
|
||||||
bool operator==(const JsonArray &other) const { return m_json == other.m_json; }
|
bool operator==(const JsonArray& other) const
|
||||||
|
{
|
||||||
|
return m_json == other.m_json;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator!=(const JsonArray &other) const { return !(*this == other); }
|
bool operator!=(const JsonArray& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
const QJsonArray &operator()() const { return m_json; }
|
const QJsonArray& operator()() const
|
||||||
|
{
|
||||||
|
return m_json;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QJsonArray m_json;
|
QJsonArray m_json;
|
||||||
bool m_jsonIsSet = false;
|
bool m_jsonIsSet = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonArray JsonArray::fromJson(const char *json, int len)
|
JsonArray JsonArray::fromJson(const char* json, int len)
|
||||||
{
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen(json);
|
len = strlen(json);
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@@ -243,10 +298,10 @@ namespace LtsUtils
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
return JsonArray(doc.array());
|
return JsonArray(doc.array());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray JsonArray::fromJsonSafe(const char *json, int len) noexcept(false)
|
JsonArray JsonArray::fromJsonSafe(const char* json, int len) noexcept(false)
|
||||||
{
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen(json);
|
len = strlen(json);
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@@ -258,34 +313,52 @@ namespace LtsUtils
|
|||||||
throw JsonTypeError("JSON root is not an array");
|
throw JsonTypeError("JSON root is not an array");
|
||||||
|
|
||||||
return JsonArray(doc.array());
|
return JsonArray(doc.array());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T> struct JsonValue;
|
||||||
|
|
||||||
|
template <class Int> struct JsonLimits
|
||||||
|
{
|
||||||
|
static constexpr Int lowest()
|
||||||
|
{
|
||||||
|
return std::numeric_limits<Int>::lowest();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> struct JsonValue;
|
static constexpr Int max()
|
||||||
|
|
||||||
template <class Int> struct JsonLimits
|
|
||||||
{
|
{
|
||||||
static constexpr Int lowest() { return std::numeric_limits<Int>::lowest(); }
|
return std::numeric_limits<Int>::max();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr Int max() { return std::numeric_limits<Int>::max(); }
|
template <> struct JsonLimits<int64_t>
|
||||||
};
|
{
|
||||||
|
static constexpr int64_t lowest()
|
||||||
template <> struct JsonLimits<int64_t>
|
|
||||||
{
|
{
|
||||||
static constexpr int64_t lowest() { return -(static_cast<int64_t>(1) << 53) + 1; }
|
return -(static_cast<int64_t>(1) << 53) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr int64_t max() { return (static_cast<int64_t>(1) << 53) - 1; }
|
static constexpr int64_t max()
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonLimits<uint64_t>
|
|
||||||
{
|
{
|
||||||
static constexpr uint64_t lowest() { return 0; }
|
return (static_cast<int64_t>(1) << 53) - 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr uint64_t max() { return JsonLimits<int64_t>::max(); }
|
template <> struct JsonLimits<uint64_t>
|
||||||
};
|
{
|
||||||
|
static constexpr uint64_t lowest()
|
||||||
template <class Int> struct JsonIntValue
|
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value)
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr uint64_t max()
|
||||||
|
{
|
||||||
|
return JsonLimits<int64_t>::max();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Int> struct JsonIntValue
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
if (!value.isDouble())
|
if (!value.isDouble())
|
||||||
return false;
|
return false;
|
||||||
@@ -300,127 +373,163 @@ namespace LtsUtils
|
|||||||
return val == wholeInt;
|
return val == wholeInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int value(const QJsonValue &value) noexcept(false)
|
static Int value(const QJsonValue& value) noexcept(false)
|
||||||
{
|
{
|
||||||
if (!matchesType(value))
|
if (!matchesType(value))
|
||||||
throw JsonTypeError("JSON value not of type Int");
|
throw JsonTypeError("JSON value not of type Int");
|
||||||
return static_cast<Int>(value.toDouble());
|
return static_cast<Int>(value.toDouble());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<int16_t> : JsonIntValue<int16_t>
|
template <> struct JsonValue<int16_t> : JsonIntValue<int16_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct JsonValue<uint16_t> : JsonIntValue<uint16_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct JsonValue<int32_t> : JsonIntValue<int32_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct JsonValue<uint32_t> : JsonIntValue<uint32_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct JsonValue<int64_t> : JsonIntValue<int64_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct JsonValue<uint64_t> : JsonIntValue<uint64_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct JsonValue<double>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
};
|
return value.isDouble();
|
||||||
|
}
|
||||||
|
|
||||||
template <> struct JsonValue<uint16_t> : JsonIntValue<uint16_t>
|
static double value(const QJsonValue& value) noexcept(false)
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<int32_t> : JsonIntValue<int32_t>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<uint32_t> : JsonIntValue<uint32_t>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<int64_t> : JsonIntValue<int64_t>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<uint64_t> : JsonIntValue<uint64_t>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<double>
|
|
||||||
{
|
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isDouble(); }
|
|
||||||
|
|
||||||
static double value(const QJsonValue &value) noexcept(false)
|
|
||||||
{
|
{
|
||||||
if (!matchesType(value))
|
if (!matchesType(value))
|
||||||
throw JsonTypeError("JSON value not of type Double");
|
throw JsonTypeError("JSON value not of type Double");
|
||||||
return value.toDouble();
|
return value.toDouble();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<bool>
|
template <> struct JsonValue<bool>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isBool(); }
|
return value.isBool();
|
||||||
|
}
|
||||||
|
|
||||||
static bool value(const QJsonValue &value) noexcept(false)
|
static bool value(const QJsonValue& value) noexcept(false)
|
||||||
{
|
{
|
||||||
if (!matchesType(value))
|
if (!matchesType(value))
|
||||||
throw JsonTypeError("JSON value not of type Bool");
|
throw JsonTypeError("JSON value not of type Bool");
|
||||||
return value.toBool();
|
return value.toBool();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<QString>
|
template <> struct JsonValue<QString>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isString(); }
|
return value.isString();
|
||||||
|
}
|
||||||
|
|
||||||
static QString value(const QJsonValue &value) noexcept(false)
|
static QString value(const QJsonValue& value) noexcept(false)
|
||||||
{
|
{
|
||||||
if (!matchesType(value))
|
if (!matchesType(value))
|
||||||
throw JsonTypeError("JSON value not of type String");
|
throw JsonTypeError("JSON value not of type String");
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<std::string>
|
template <> struct JsonValue<std::string>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isString(); }
|
return value.isString();
|
||||||
|
}
|
||||||
|
|
||||||
static std::string value(const QJsonValue &value) { return JsonValue<QString>::value(value).toStdString(); }
|
static std::string value(const QJsonValue& value)
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<QJsonObject>
|
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isObject(); }
|
return JsonValue<QString>::value(value).toStdString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static QJsonObject value(const QJsonValue &value) noexcept(false)
|
template <> struct JsonValue<QJsonObject>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
|
{
|
||||||
|
return value.isObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
static QJsonObject value(const QJsonValue& value) noexcept(false)
|
||||||
{
|
{
|
||||||
if (!matchesType(value))
|
if (!matchesType(value))
|
||||||
throw JsonTypeError("JSON value not of type Object");
|
throw JsonTypeError("JSON value not of type Object");
|
||||||
return value.toObject();
|
return value.toObject();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<JsonObject>
|
template <> struct JsonValue<JsonObject>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isObject(); }
|
return value.isObject();
|
||||||
|
}
|
||||||
|
|
||||||
static JsonObject value(const QJsonValue &value) { return JsonObject(JsonValue<QJsonObject>::value(value)); }
|
static JsonObject value(const QJsonValue& value)
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct JsonValue<void>
|
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isNull(); }
|
return JsonObject(JsonValue<QJsonObject>::value(value));
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<QJsonArray>
|
template <> struct JsonValue<void>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isArray(); }
|
return value.isNull();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static QJsonArray value(const QJsonValue &value) noexcept(false)
|
template <> struct JsonValue<QJsonArray>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
|
{
|
||||||
|
return value.isArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
static QJsonArray value(const QJsonValue& value) noexcept(false)
|
||||||
{
|
{
|
||||||
if (!matchesType(value))
|
if (!matchesType(value))
|
||||||
throw JsonTypeError("JSON value not of type Array");
|
throw JsonTypeError("JSON value not of type Array");
|
||||||
return value.toArray();
|
return value.toArray();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct JsonValue<JsonArray>
|
template <> struct JsonValue<JsonArray>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return value.isArray(); }
|
return value.isArray();
|
||||||
|
}
|
||||||
|
|
||||||
static JsonArray value(const QJsonValue &value) { return JsonArray(JsonValue<QJsonArray>::value(value)); }
|
static JsonArray value(const QJsonValue& value)
|
||||||
};
|
|
||||||
|
|
||||||
template <class T> struct JsonValue<QVector<T>>
|
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value)
|
return JsonArray(JsonValue<QJsonArray>::value(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> struct JsonValue<QVector<T>>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
if (!value.isArray())
|
if (!value.isArray())
|
||||||
return false;
|
return false;
|
||||||
@@ -429,27 +538,30 @@ namespace LtsUtils
|
|||||||
return array.isVector<T>();
|
return array.isVector<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVector<T> value(const QJsonValue &value)
|
static QVector<T> value(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
const JsonArray array(JsonValue<QJsonArray>::value(value));
|
const JsonArray array(JsonValue<QJsonArray>::value(value));
|
||||||
return array.toVector<T>();
|
return array.toVector<T>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> struct JsonValue<std::vector<T>>
|
template <class T> struct JsonValue<std::vector<T>>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return JsonValue<QVector<T>>::matchesType(value); }
|
return JsonValue<QVector<T>>::matchesType(value);
|
||||||
|
}
|
||||||
|
|
||||||
static std::vector<T> value(const QJsonValue &value)
|
static std::vector<T> value(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
const JsonArray array(JsonValue<QJsonArray>::value(value));
|
const JsonArray array(JsonValue<QJsonArray>::value(value));
|
||||||
return array.toStdVector<T>();
|
return array.toStdVector<T>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> struct JsonValue<QMap<QString, T>>
|
template <class T> struct JsonValue<QMap<QString, T>>
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value)
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
if (!value.isObject())
|
if (!value.isObject())
|
||||||
return false;
|
return false;
|
||||||
@@ -458,122 +570,126 @@ namespace LtsUtils
|
|||||||
return obj.isMap<T>();
|
return obj.isMap<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QMap<QString, T> value(const QJsonValue &value)
|
static QMap<QString, T> value(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
const JsonObject obj(JsonValue<QJsonObject>::value(value));
|
const JsonObject obj(JsonValue<QJsonObject>::value(value));
|
||||||
return obj.toMap<T>();
|
return obj.toMap<T>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> struct JsonValue<std::map<std::string, T>>
|
template <class T> struct JsonValue<std::map<std::string, T>>
|
||||||
|
{
|
||||||
|
static bool matchesType(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
static bool matchesType(const QJsonValue &value) { return JsonValue<QMap<QString, T>>::matchesType(value); }
|
return JsonValue<QMap<QString, T>>::matchesType(value);
|
||||||
|
}
|
||||||
|
|
||||||
static std::map<std::string, T> value(const QJsonValue &value)
|
static std::map<std::string, T> value(const QJsonValue& value)
|
||||||
{
|
{
|
||||||
const JsonObject obj(JsonValue<QJsonObject>::value(value));
|
const JsonObject obj(JsonValue<QJsonObject>::value(value));
|
||||||
return obj.toStdMap<T>();
|
return obj.toStdMap<T>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> bool JsonObject::contains(const Key &key) const
|
template <class T> bool JsonObject::contains(const Key& key) const
|
||||||
{
|
{
|
||||||
if (!m_json.contains(key))
|
if (!m_json.contains(key))
|
||||||
return false;
|
return false;
|
||||||
return JsonValue<T>::matchesType(m_json.value(key));
|
return JsonValue<T>::matchesType(m_json.value(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> T JsonObject::value(const Key &key) const noexcept(false)
|
template <class T> T JsonObject::value(const Key& key) const noexcept(false)
|
||||||
{
|
{
|
||||||
if (!containsAny(key))
|
if (!containsAny(key))
|
||||||
throw JsonKeyError("no element with key: " + static_cast<const QString &>(key).toStdString());
|
throw JsonKeyError("no element with key: " + static_cast<const QString&>(key).toStdString());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return JsonValue<T>::value(m_json.value(key));
|
return JsonValue<T>::value(m_json.value(key));
|
||||||
}
|
}
|
||||||
catch (const JsonTypeError &typeError)
|
catch (const JsonTypeError& typeError)
|
||||||
{
|
{
|
||||||
throw JsonTypeError(std::string(typeError.what()) + " - key: " + static_cast<const QString &>(key).toStdString());
|
throw JsonTypeError(std::string(typeError.what()) +
|
||||||
}
|
" - key: " + static_cast<const QString&>(key).toStdString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class T> T JsonObject::valueOr(const Key &key, const T &defaultValue) const
|
template <class T> T JsonObject::valueOr(const Key& key, const T& defaultValue) const
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return value<T>(key);
|
return value<T>(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (const JsonKeyError &)
|
catch (const JsonKeyError&)
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool JsonObject::isMap() const
|
template <class T> bool JsonObject::isMap() const
|
||||||
{
|
{
|
||||||
const QStringList keys = m_json.keys();
|
const QStringList keys = m_json.keys();
|
||||||
for (const auto &key : keys)
|
for (const auto& key : keys)
|
||||||
if (!JsonValue<T>::matchesType(m_json.value(key)))
|
if (!JsonValue<T>::matchesType(m_json.value(key)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> QMap<QString, T> JsonObject::toMap() const
|
template <class T> QMap<QString, T> JsonObject::toMap() const
|
||||||
{
|
{
|
||||||
QMap<QString, T> result;
|
QMap<QString, T> result;
|
||||||
for (auto current = m_json.begin(); current != m_json.end(); ++current)
|
for (auto current = m_json.begin(); current != m_json.end(); ++current)
|
||||||
result.insert(current.key(), JsonValue<T>::value(current.value()));
|
result.insert(current.key(), JsonValue<T>::value(current.value()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> std::map<std::string, T> JsonObject::toStdMap() const
|
template <class T> std::map<std::string, T> JsonObject::toStdMap() const
|
||||||
{
|
{
|
||||||
std::map<std::string, T> result;
|
std::map<std::string, T> result;
|
||||||
for (auto current = m_json.begin(); current != m_json.end(); ++current)
|
for (auto current = m_json.begin(); current != m_json.end(); ++current)
|
||||||
result.insert({current.key().toStdString(), JsonValue<T>::value(current.value())});
|
result.insert({current.key().toStdString(), JsonValue<T>::value(current.value())});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool JsonArray::contains(int index) const noexcept(false)
|
template <class T> bool JsonArray::contains(int index) const noexcept(false)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_json.size())
|
if (index < 0 || index >= m_json.size())
|
||||||
throw JsonRangeError("index out of range: " + std::to_string(index));
|
throw JsonRangeError("index out of range: " + std::to_string(index));
|
||||||
return JsonValue<T>::matchesType(m_json.at(index));
|
return JsonValue<T>::matchesType(m_json.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> T JsonArray::at(int index) const noexcept(false)
|
template <class T> T JsonArray::at(int index) const noexcept(false)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_json.size())
|
if (index < 0 || index >= m_json.size())
|
||||||
throw JsonRangeError("index out of range: " + std::to_string(index));
|
throw JsonRangeError("index out of range: " + std::to_string(index));
|
||||||
return JsonValue<T>::value(m_json.at(index));
|
return JsonValue<T>::value(m_json.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool JsonArray::isVector() const
|
template <class T> bool JsonArray::isVector() const
|
||||||
{
|
{
|
||||||
for (const QJsonValue &value : m_json)
|
for (const QJsonValue& value : m_json)
|
||||||
if (!JsonValue<T>::matchesType(value))
|
if (!JsonValue<T>::matchesType(value))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> QVector<T> JsonArray::toVector() const
|
template <class T> QVector<T> JsonArray::toVector() const
|
||||||
{
|
{
|
||||||
QVector<T> result;
|
QVector<T> result;
|
||||||
result.reserve(m_json.size());
|
result.reserve(m_json.size());
|
||||||
for (const QJsonValue &value : m_json)
|
for (const QJsonValue& value : m_json)
|
||||||
result.push_back(JsonValue<T>::value(value));
|
result.push_back(JsonValue<T>::value(value));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> std::vector<T> JsonArray::toStdVector() const
|
template <class T> std::vector<T> JsonArray::toStdVector() const
|
||||||
{
|
{
|
||||||
std::vector<T> result;
|
std::vector<T> result;
|
||||||
result.reserve(m_json.size());
|
result.reserve(m_json.size());
|
||||||
for (const QJsonValue &value : m_json)
|
for (const QJsonValue& value : m_json)
|
||||||
result.push_back(JsonValue<T>::value(value));
|
result.push_back(JsonValue<T>::value(value));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -3,12 +3,12 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsUtils::LtsPortRange fromQPoint(const QPoint &point)
|
LtsUtils::LtsPortRange fromQPoint(const QPoint& point)
|
||||||
{
|
{
|
||||||
if (point.x() < 1025 || point.y() > 65535 || point.x() > point.y())
|
if (point.x() < 1025 || point.y() > 65535 || point.x() > point.y())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return {static_cast<quint16>(point.x()), static_cast<quint16>(point.y())};
|
return {static_cast<quint16>(point.x()), static_cast<quint16>(point.y())};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
typedef QPair<quint16, quint16> LtsPortRange;
|
typedef QPair<quint16, quint16> LtsPortRange;
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT LtsPortRange fromQPoint(const QPoint &point);
|
LTSUTILSCORE_EXPORT LtsPortRange fromQPoint(const QPoint& point);
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+22
-10
@@ -1,4 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* A class that contains an identifier string and a dynmically translatable string. Useful for e.g. translating menu groups.
|
||||||
|
* Menu groups can be shared between plugins and multiple actions and are distinguished by the menu group identifier.
|
||||||
|
* Menu groups also need to be translatable as the Ui puts actions into group boxes, distinguished by a menu group.
|
||||||
|
* Menu groups are also used outside of the current Q_OBJECT context, so calling tr(..) would not work. translatedText(..)
|
||||||
|
* fixes this problem.
|
||||||
|
* $Id: $
|
||||||
|
* $HeadURL: $
|
||||||
|
* $Author: $
|
||||||
|
*
|
||||||
|
* Created by Mike Lennart Wille, SLTE, 2022-06-22
|
||||||
|
*/
|
||||||
|
|
||||||
#include "lts_translatable_identifier.h"
|
#include "lts_translatable_identifier.h"
|
||||||
|
|
||||||
@@ -6,17 +18,17 @@
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
LtsTranslatableIdentifier::LtsTranslatableIdentifier(const QString &identifier, const QObject *context, const char *translatableText)
|
LtsTranslatableIdentifier::LtsTranslatableIdentifier(const QString& identifier, const QObject* context,
|
||||||
: m_identifier(identifier)
|
const char* translatableText)
|
||||||
, m_translationContext(context->metaObject()->className())
|
: m_identifier(identifier), m_translationContext(context->metaObject()->className()),
|
||||||
, m_translatableText(translatableText)
|
m_translatableText(translatableText)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString LtsTranslatableIdentifier::translatedText(const char *disambiguation, int n) const
|
const QString LtsTranslatableIdentifier::translatedText(const char* disambiguation, int n) const
|
||||||
{
|
{
|
||||||
if (m_identifier.isEmpty() || m_translationContext == nullptr || m_translatableText == nullptr)
|
if (m_identifier.isEmpty() || m_translationContext == nullptr || m_translatableText == nullptr)
|
||||||
return {};
|
return {};
|
||||||
return QCoreApplication::translate(m_translationContext, m_translatableText, disambiguation, n);
|
return QCoreApplication::translate(m_translationContext, m_translatableText, disambiguation, n);
|
||||||
}
|
}
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+30
-14
@@ -1,5 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* A class that contains an identifier string and a dynmically translatable string. Useful for e.g. translating menu groups.
|
||||||
|
* Menu groups can be shared between plugins and multiple actions and are distinguished by the menu group identifier.
|
||||||
|
* Menu groups also need to be translatable as the Ui puts actions into group boxes, distinguished by a menu group.
|
||||||
|
* Menu groups are also used outside of the current Q_OBJECT context, so calling tr(..) would not work. translatedText(..)
|
||||||
|
* fixes this problem.
|
||||||
|
* $Id: $
|
||||||
|
* $HeadURL: $
|
||||||
|
* $Author: $
|
||||||
|
*
|
||||||
|
* Created by Mike Lennart Wille, SLTE, 2022-06-22
|
||||||
|
*/
|
||||||
|
|
||||||
#include "ltsutilscore_export.h"
|
#include "ltsutilscore_export.h"
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
@@ -7,27 +21,29 @@
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
class LTSUTILSCORE_EXPORT LtsTranslatableIdentifier
|
class LTSUTILSCORE_EXPORT LtsTranslatableIdentifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LtsTranslatableIdentifier()
|
LtsTranslatableIdentifier() : m_translationContext(nullptr), m_translatableText("") {}
|
||||||
: m_translationContext(nullptr)
|
|
||||||
, m_translatableText("")
|
LtsTranslatableIdentifier(const QString& identifier, const QObject* context, const char* translatableText);
|
||||||
|
|
||||||
|
const QString& identifier() const
|
||||||
{
|
{
|
||||||
|
return m_identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
LtsTranslatableIdentifier(const QString &identifier, const QObject *context, const char *translatableText);
|
const QString translatedText(const char* disambiguation = nullptr, int n = -1) const;
|
||||||
|
|
||||||
const QString &identifier() const { return m_identifier; }
|
const QString _context() const
|
||||||
|
{
|
||||||
const QString translatedText(const char *disambiguation = nullptr, int n = -1) const;
|
return QString::fromUtf8(m_translationContext);
|
||||||
|
}
|
||||||
const QString _context() const { return QString::fromUtf8(m_translationContext); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_identifier;
|
QString m_identifier;
|
||||||
const char *m_translationContext;
|
const char* m_translationContext;
|
||||||
|
|
||||||
const char *m_translatableText;
|
const char* m_translatableText;
|
||||||
};
|
};
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
inline bool isPositionTimeOutdated(qint64 curTime, qint64 posTime)
|
inline bool isPositionTimeOutdated(qint64 curTime, qint64 posTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
return curTime > posTime + 11 * 60 * 1000;
|
return curTime > posTime + 11 * 60 * 1000;
|
||||||
}
|
}
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -11,8 +11,8 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T> static inline QString convertToPgString(const std::vector<T> &data)
|
template <typename T> static inline QString convertToPgString(const std::vector<T>& data)
|
||||||
{
|
{
|
||||||
if (data.size() == 0)
|
if (data.size() == 0)
|
||||||
return QLatin1String("{}");
|
return QLatin1String("{}");
|
||||||
QString ret(QLatin1Char('{'));
|
QString ret(QLatin1Char('{'));
|
||||||
@@ -21,20 +21,22 @@ namespace LtsUtils
|
|||||||
ret.chop(1);
|
ret.chop(1);
|
||||||
ret += QLatin1Char('}');
|
ret += QLatin1Char('}');
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT QString IntArray::toPgString() const
|
template <> LTSUTILSCORE_EXPORT QString IntArray::toPgString() const
|
||||||
{
|
{
|
||||||
return convertToPgString(m_data);
|
return convertToPgString(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT QString BigintArray::toPgString() const
|
template <> LTSUTILSCORE_EXPORT QString BigintArray::toPgString() const
|
||||||
{
|
{
|
||||||
return convertToPgString(m_data);
|
return convertToPgString(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> static inline T convertFromPgString(const QString &str, const std::function<typename T::Type(QStringView val, bool *bOk)> &convertFunc)
|
template <typename T>
|
||||||
{
|
static inline T convertFromPgString(const QString& str,
|
||||||
|
const std::function<typename T::Type(QStringView val, bool* bOk)>& convertFunc)
|
||||||
|
{
|
||||||
typename T::ContainerType result;
|
typename T::ContainerType result;
|
||||||
|
|
||||||
int idxStart = str.indexOf(QLatin1Char('{'));
|
int idxStart = str.indexOf(QLatin1Char('{'));
|
||||||
@@ -51,7 +53,7 @@ namespace LtsUtils
|
|||||||
const QStringView strRef = QStringView(str).mid(idxStart + 1, idxEnd - idxStart - 1);
|
const QStringView strRef = QStringView(str).mid(idxStart + 1, idxEnd - idxStart - 1);
|
||||||
const QVector<QStringView> vec = strRef.split(QLatin1Char(','), Qt::SkipEmptyParts);
|
const QVector<QStringView> vec = strRef.split(QLatin1Char(','), Qt::SkipEmptyParts);
|
||||||
result.reserve(vec.size());
|
result.reserve(vec.size());
|
||||||
for (const QStringView &s : vec)
|
for (const QStringView& s : vec)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const typename T::Type i = convertFunc(s, &ok);
|
const typename T::Type i = convertFunc(s, &ok);
|
||||||
@@ -60,44 +62,48 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
return T(result);
|
return T(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT IntArray IntArray::fromPgString(const QString &str)
|
template <> LTSUTILSCORE_EXPORT IntArray IntArray::fromPgString(const QString& str)
|
||||||
{
|
{
|
||||||
return convertFromPgString<IntArray>(str, [](QStringView val, bool *bOk) { return val.toString().toInt(bOk); });
|
return convertFromPgString<IntArray>(str, [](QStringView val, bool* bOk) { return val.toString().toInt(bOk); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT BigintArray BigintArray::fromPgString(const QString &str)
|
template <> LTSUTILSCORE_EXPORT BigintArray BigintArray::fromPgString(const QString& str)
|
||||||
{
|
{
|
||||||
return convertFromPgString<BigintArray>(str, [](QStringView val, bool *bOk) { return val.toString().toLongLong(bOk); });
|
return convertFromPgString<BigintArray>(str,
|
||||||
}
|
[](QStringView val, bool* bOk) { return val.toString().toLongLong(bOk); });
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T> static inline QString convertToPgString(const std::map<T, T> &data)
|
template <typename T> static inline QString convertToPgString(const std::map<T, T>& data)
|
||||||
{
|
{
|
||||||
if (data.size() == 0)
|
if (data.size() == 0)
|
||||||
return QLatin1String("{}");
|
return QLatin1String("{}");
|
||||||
QString ret(QLatin1Char('{'));
|
QString ret(QLatin1Char('{'));
|
||||||
for (const auto &it : data)
|
for (const auto& it : data)
|
||||||
{
|
{
|
||||||
ret += QLatin1Char('{') + QString::number(it.first) + QLatin1Char(',') + QString::number(it.second) + QLatin1String("},");
|
ret += QLatin1Char('{') + QString::number(it.first) + QLatin1Char(',') + QString::number(it.second) +
|
||||||
|
QLatin1String("},");
|
||||||
}
|
}
|
||||||
ret.chop(1);
|
ret.chop(1);
|
||||||
ret += QLatin1Char('}');
|
ret += QLatin1Char('}');
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT QString IntArray2D::toPgString() const
|
template <> LTSUTILSCORE_EXPORT QString IntArray2D::toPgString() const
|
||||||
{
|
{
|
||||||
return convertToPgString<IntArray2D::Type>(m_data);
|
return convertToPgString<IntArray2D::Type>(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT QString BigintArray2D::toPgString() const
|
template <> LTSUTILSCORE_EXPORT QString BigintArray2D::toPgString() const
|
||||||
{
|
{
|
||||||
return convertToPgString<BigintArray2D::Type>(m_data);
|
return convertToPgString<BigintArray2D::Type>(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> static inline T convertFromPgString2D(const QString &str, const std::function<typename T::Type(QStringView val)> &convertFunc)
|
template <typename T>
|
||||||
{
|
static inline T convertFromPgString2D(const QString& str,
|
||||||
|
const std::function<typename T::Type(QStringView val)>& convertFunc)
|
||||||
|
{
|
||||||
typename T::ContainerType ret;
|
typename T::ContainerType ret;
|
||||||
int idxStart = str.indexOf(QLatin1Char('{'));
|
int idxStart = str.indexOf(QLatin1Char('{'));
|
||||||
int idxEnd = str.lastIndexOf(QLatin1Char('}'));
|
int idxEnd = str.lastIndexOf(QLatin1Char('}'));
|
||||||
@@ -130,16 +136,16 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
return T(ret);
|
return T(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT IntArray2D IntArray2D::fromPgString(const QString &str)
|
template <> LTSUTILSCORE_EXPORT IntArray2D IntArray2D::fromPgString(const QString& str)
|
||||||
{
|
{
|
||||||
return convertFromPgString2D<IntArray2D>(str, [](QStringView val) { return val.toString().toInt(); });
|
return convertFromPgString2D<IntArray2D>(str, [](QStringView val) { return val.toString().toInt(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> LTSUTILSCORE_EXPORT BigintArray2D BigintArray2D::fromPgString(const QString &str)
|
template <> LTSUTILSCORE_EXPORT BigintArray2D BigintArray2D::fromPgString(const QString& str)
|
||||||
{
|
{
|
||||||
return convertFromPgString2D<BigintArray2D>(str, [](QStringView val) { return val.toString().toLongLong(); });
|
return convertFromPgString2D<BigintArray2D>(str, [](QStringView val) { return val.toString().toLongLong(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -9,32 +9,32 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T, typename C> class PgArray
|
template <typename T, typename C> class PgArray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Type = T;
|
using Type = T;
|
||||||
using ContainerType = C;
|
using ContainerType = C;
|
||||||
|
|
||||||
PgArray() = default;
|
PgArray() = default;
|
||||||
|
|
||||||
Q_DECL_CONSTEXPR explicit PgArray(const C &data)
|
Q_DECL_CONSTEXPR explicit PgArray(const C& data) : m_data(data) {}
|
||||||
: m_data(data)
|
|
||||||
|
Q_DECL_CONSTEXPR C operator()() const
|
||||||
{
|
{
|
||||||
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECL_CONSTEXPR C operator()() const { return m_data; }
|
|
||||||
|
|
||||||
[[nodiscard]] QString toPgString() const;
|
[[nodiscard]] QString toPgString() const;
|
||||||
static PgArray fromPgString(const QString &str);
|
static PgArray fromPgString(const QString& str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
C m_data;
|
C m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
using IntArray = PgArray<int, std::vector<int>>;
|
using IntArray = PgArray<int, std::vector<int>>;
|
||||||
using BigintArray = PgArray<int64_t, std::vector<int64_t>>;
|
using BigintArray = PgArray<int64_t, std::vector<int64_t>>;
|
||||||
|
|
||||||
using IntArray2D = PgArray<int, std::map<int, int>>;
|
using IntArray2D = PgArray<int, std::map<int, int>>;
|
||||||
using BigintArray2D = PgArray<int64_t, std::map<int64_t, int64_t>>;
|
using BigintArray2D = PgArray<int64_t, std::map<int64_t, int64_t>>;
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -7,20 +7,16 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
Promise::Promise(const std::function<void(ResultFunction resolve, ResultFunction reject)> &function, QObject *parent)
|
Promise::Promise(const std::function<void(ResultFunction resolve, ResultFunction reject)>& function, QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent), m_functionAlreadySet(false), m_timeout(new QTimer(this)), m_resultSet(false), m_timeoutSet(false)
|
||||||
, m_functionAlreadySet(false)
|
{
|
||||||
, m_timeout(new QTimer(this))
|
|
||||||
, m_resultSet(false)
|
|
||||||
, m_timeoutSet(false)
|
|
||||||
{
|
|
||||||
m_timeout->setSingleShot(true);
|
m_timeout->setSingleShot(true);
|
||||||
connect(m_timeout, &QTimer::timeout, this, &Promise::slotTimeout);
|
connect(m_timeout, &QTimer::timeout, this, &Promise::slotTimeout);
|
||||||
setFunction(function);
|
setFunction(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Promise::setFunction(const std::function<void(ResultFunction resolve, ResultFunction reject)> &function)
|
void Promise::setFunction(const std::function<void(ResultFunction resolve, ResultFunction reject)>& function)
|
||||||
{
|
{
|
||||||
if (!function || m_functionAlreadySet)
|
if (!function || m_functionAlreadySet)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -29,54 +25,56 @@ namespace LtsUtils
|
|||||||
if (m_timeoutSet)
|
if (m_timeoutSet)
|
||||||
m_timeout->start();
|
m_timeout->start();
|
||||||
|
|
||||||
QTimer::singleShot(0, this, [this, function]() { function([this](const QVariant &value) { resolve(value); }, [this](const QVariant &value) { reject(value); }); });
|
QTimer::singleShot(0, this, [this, function]() {
|
||||||
}
|
function([this](const QVariant& value) { resolve(value); }, [this](const QVariant& value) { reject(value); });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Promise::setTimeout(int interval)
|
void Promise::setTimeout(int interval)
|
||||||
{
|
{
|
||||||
m_timeout->stop();
|
m_timeout->stop();
|
||||||
m_timeout->setInterval(interval);
|
m_timeout->setInterval(interval);
|
||||||
m_timeoutSet = (interval != 0);
|
m_timeoutSet = (interval != 0);
|
||||||
|
|
||||||
if (interval != 0 && m_functionAlreadySet)
|
if (interval != 0 && m_functionAlreadySet)
|
||||||
m_timeout->start();
|
m_timeout->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Promise::slotTimeout()
|
void Promise::slotTimeout()
|
||||||
{
|
{
|
||||||
reject(QStringLiteral("timeout"));
|
reject(QStringLiteral("timeout"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Promise::resolve(const QVariant &value)
|
void Promise::resolve(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (m_resultSet)
|
if (m_resultSet)
|
||||||
return;
|
return;
|
||||||
m_resultSet = true;
|
m_resultSet = true;
|
||||||
|
|
||||||
m_timeout->stop();
|
m_timeout->stop();
|
||||||
m_resolveFn(value);
|
m_resolveFn(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Promise::reject(const QVariant &value)
|
void Promise::reject(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (m_resultSet)
|
if (m_resultSet)
|
||||||
return;
|
return;
|
||||||
m_resultSet = true;
|
m_resultSet = true;
|
||||||
|
|
||||||
m_timeout->stop();
|
m_timeout->stop();
|
||||||
m_rejectFn(value);
|
m_rejectFn(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise &Promise::resolved(ResultFunction resolveFn)
|
Promise& Promise::resolved(ResultFunction resolveFn)
|
||||||
{
|
{
|
||||||
m_resolveFn = resolveFn;
|
m_resolveFn = resolveFn;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise &Promise::rejected(ResultFunction rejectFn)
|
Promise& Promise::rejected(ResultFunction rejectFn)
|
||||||
{
|
{
|
||||||
m_rejectFn = rejectFn;
|
m_rejectFn = rejectFn;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -10,38 +10,39 @@ class QTimer;
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
typedef std::function<void(const QVariant &value)> RawResultFunction;
|
typedef std::function<void(const QVariant& value)> RawResultFunction;
|
||||||
typedef const RawResultFunction &ResultFunction;
|
typedef const RawResultFunction& ResultFunction;
|
||||||
|
|
||||||
class LTSUTILSCORE_EXPORT Promise : public QObject
|
class LTSUTILSCORE_EXPORT Promise : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Promise(const std::function<void(ResultFunction resolve, ResultFunction reject)> &function, QObject *parent = nullptr);
|
Promise(const std::function<void(ResultFunction resolve, ResultFunction reject)>& function,
|
||||||
|
QObject* parent = nullptr);
|
||||||
|
|
||||||
void setFunction(const std::function<void(ResultFunction resolve, ResultFunction reject)> &function);
|
void setFunction(const std::function<void(ResultFunction resolve, ResultFunction reject)>& function);
|
||||||
|
|
||||||
void resolve(const QVariant &value = QVariant());
|
void resolve(const QVariant& value = QVariant());
|
||||||
|
|
||||||
void reject(const QVariant &value = QVariant());
|
void reject(const QVariant& value = QVariant());
|
||||||
|
|
||||||
void setTimeout(int interval);
|
void setTimeout(int interval);
|
||||||
|
|
||||||
Promise &resolved(ResultFunction resolveFn);
|
Promise& resolved(ResultFunction resolveFn);
|
||||||
|
|
||||||
Promise &rejected(ResultFunction rejectFn);
|
Promise& rejected(ResultFunction rejectFn);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RawResultFunction m_resolveFn;
|
RawResultFunction m_resolveFn;
|
||||||
RawResultFunction m_rejectFn;
|
RawResultFunction m_rejectFn;
|
||||||
bool m_functionAlreadySet;
|
bool m_functionAlreadySet;
|
||||||
QTimer *m_timeout;
|
QTimer* m_timeout;
|
||||||
bool m_resultSet;
|
bool m_resultSet;
|
||||||
bool m_timeoutSet;
|
bool m_timeoutSet;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotTimeout();
|
void slotTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+28
-50
@@ -9,30 +9,23 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
void PromiseExample1_Class::doSomethingAsync1()
|
void PromiseExample1_Class::doSomethingAsync1()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(200, this, [this]() { emit signalDone1(true); });
|
QTimer::singleShot(200, this, [this]() { emit signalDone1(true); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void PromiseExample1_Class::doSomethingAsync2()
|
void PromiseExample1_Class::doSomethingAsync2()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(450, this, [this]() { emit signalDone2(true, 1234); });
|
QTimer::singleShot(450, this, [this]() { emit signalDone2(true, 1234); });
|
||||||
}
|
}
|
||||||
|
|
||||||
PromiseExample1::PromiseExample1(QObject *parent)
|
PromiseExample1::PromiseExample1(QObject* parent) : QObject(parent), m_success(false)
|
||||||
: QObject(parent)
|
{
|
||||||
, m_success(false)
|
|
||||||
{
|
|
||||||
|
|
||||||
auto func = [this](ResultFunction resolve, ResultFunction reject)
|
auto func = [this](ResultFunction resolve, ResultFunction reject) {
|
||||||
{
|
PromiseExample1_Class* c = new PromiseExample1_Class(this);
|
||||||
PromiseExample1_Class *c = new PromiseExample1_Class(this);
|
|
||||||
|
|
||||||
connect(c,
|
connect(c, &PromiseExample1_Class::signalDone1, this, [this, c, resolve, reject](bool didThisWork) {
|
||||||
&PromiseExample1_Class::signalDone1,
|
|
||||||
this,
|
|
||||||
[this, c, resolve, reject](bool didThisWork)
|
|
||||||
{
|
|
||||||
if (!didThisWork)
|
if (!didThisWork)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -42,11 +35,8 @@ namespace LtsUtils
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
connect(c,
|
connect(c, &PromiseExample1_Class::signalDone2, this,
|
||||||
&PromiseExample1_Class::signalDone2,
|
[resolve, reject](bool didThisWork, int someNumberThatReturns) {
|
||||||
this,
|
|
||||||
[resolve, reject](bool didThisWork, int someNumberThatReturns)
|
|
||||||
{
|
|
||||||
if (didThisWork)
|
if (didThisWork)
|
||||||
resolve(someNumberThatReturns);
|
resolve(someNumberThatReturns);
|
||||||
else
|
else
|
||||||
@@ -59,22 +49,17 @@ namespace LtsUtils
|
|||||||
|
|
||||||
c->doSomethingAsync1();
|
c->doSomethingAsync1();
|
||||||
};
|
};
|
||||||
Promise *p = new Promise(func, this);
|
Promise* p = new Promise(func, this);
|
||||||
|
|
||||||
p->resolved(
|
p->resolved([this](const QVariant& value) {
|
||||||
[this](const QVariant &value)
|
|
||||||
{
|
|
||||||
qDebug() << "example1 promise succeeded! 'someNumberThatReturns' was" << value;
|
qDebug() << "example1 promise succeeded! 'someNumberThatReturns' was" << value;
|
||||||
|
|
||||||
m_success = true;
|
m_success = true;
|
||||||
})
|
}).rejected([](const QVariant& value) { qDebug() << "example1 promise failed.." << value; });
|
||||||
.rejected([](const QVariant &value) { qDebug() << "example1 promise failed.." << value; });
|
}
|
||||||
}
|
|
||||||
|
|
||||||
PromiseExample2::PromiseExample2(QObject *parent)
|
PromiseExample2::PromiseExample2(QObject* parent) : QObject(parent), m_success(false)
|
||||||
: QObject(parent)
|
{
|
||||||
, m_success(false)
|
|
||||||
{
|
|
||||||
|
|
||||||
Promise* p = new Promise(
|
Promise* p = new Promise(
|
||||||
[](ResultFunction, ResultFunction) {
|
[](ResultFunction, ResultFunction) {
|
||||||
@@ -84,32 +69,25 @@ namespace LtsUtils
|
|||||||
|
|
||||||
p->setTimeout(1000);
|
p->setTimeout(1000);
|
||||||
|
|
||||||
p->resolved([](const QVariant &) { QFAIL("This test case's promise should never resolve"); });
|
p->resolved([](const QVariant&) { QFAIL("This test case's promise should never resolve"); });
|
||||||
|
|
||||||
p->rejected(
|
p->rejected([this](const QVariant& val) {
|
||||||
[this](const QVariant &val)
|
|
||||||
{
|
|
||||||
QVERIFY2(val == QStringLiteral("timeout"), "Promise didn't reject with string \"timeout\"");
|
QVERIFY2(val == QStringLiteral("timeout"), "Promise didn't reject with string \"timeout\"");
|
||||||
qDebug() << "Promise rejected as expected";
|
qDebug() << "Promise rejected as expected";
|
||||||
m_success = true;
|
m_success = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
PromiseExample3::PromiseExample3(QObject *parent)
|
PromiseExample3::PromiseExample3(QObject* parent) : QObject(parent), m_success(true), m_alreadyRejected(false)
|
||||||
: QObject(parent)
|
{
|
||||||
, m_success(true)
|
|
||||||
, m_alreadyRejected(false)
|
|
||||||
{
|
|
||||||
|
|
||||||
Promise *p = new Promise([](ResultFunction, ResultFunction reject) { reject(QString()); }, this);
|
Promise* p = new Promise([](ResultFunction, ResultFunction reject) { reject(QString()); }, this);
|
||||||
|
|
||||||
p->setTimeout(1000);
|
p->setTimeout(1000);
|
||||||
|
|
||||||
p->resolved([](const QVariant &) { QFAIL("This test case's promise should never resolve"); });
|
p->resolved([](const QVariant&) { QFAIL("This test case's promise should never resolve"); });
|
||||||
|
|
||||||
p->rejected(
|
p->rejected([this](const QVariant& val) {
|
||||||
[this](const QVariant &val)
|
|
||||||
{
|
|
||||||
qDebug() << "rejected with val" << val;
|
qDebug() << "rejected with val" << val;
|
||||||
QVERIFY2(val == QString(), "Promise didn't reject with an expected empty string.");
|
QVERIFY2(val == QString(), "Promise didn't reject with an expected empty string.");
|
||||||
QVERIFY2(!m_alreadyRejected, "Promise rejected more than once");
|
QVERIFY2(!m_alreadyRejected, "Promise rejected more than once");
|
||||||
@@ -117,6 +95,6 @@ namespace LtsUtils
|
|||||||
m_alreadyRejected = true;
|
m_alreadyRejected = true;
|
||||||
qDebug() << "Promise rejected as expected";
|
qDebug() << "Promise rejected as expected";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+27
-18
@@ -5,8 +5,8 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class PromiseExample1_Class : public QObject
|
class PromiseExample1_Class : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
using QObject::QObject;
|
using QObject::QObject;
|
||||||
@@ -17,43 +17,52 @@ namespace LtsUtils
|
|||||||
signals:
|
signals:
|
||||||
void signalDone1(bool didThisWork);
|
void signalDone1(bool didThisWork);
|
||||||
void signalDone2(bool didThisWork, int someNumberThatReturns);
|
void signalDone2(bool didThisWork, int someNumberThatReturns);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PromiseExample1 : public QObject
|
class PromiseExample1 : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PromiseExample1(QObject *parent = nullptr);
|
explicit PromiseExample1(QObject* parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] bool isSuccess() const { return m_success; }
|
[[nodiscard]] bool isSuccess() const
|
||||||
|
{
|
||||||
|
return m_success;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_success;
|
bool m_success;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PromiseExample2 : public QObject
|
class PromiseExample2 : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PromiseExample2(QObject *parent = nullptr);
|
explicit PromiseExample2(QObject* parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] bool isSuccess() const { return m_success; }
|
[[nodiscard]] bool isSuccess() const
|
||||||
|
{
|
||||||
|
return m_success;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_success;
|
bool m_success;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PromiseExample3 : public QObject
|
class PromiseExample3 : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PromiseExample3(QObject *parent = nullptr);
|
explicit PromiseExample3(QObject* parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] bool isSuccess() const { return m_success; }
|
[[nodiscard]] bool isSuccess() const
|
||||||
|
{
|
||||||
|
return m_success;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_success;
|
bool m_success;
|
||||||
bool m_alreadyRejected;
|
bool m_alreadyRejected;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+63
-65
@@ -8,8 +8,8 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T> void inline set8Byte(const T in, QByteArray &out)
|
template <typename T> void inline set8Byte(const T in, QByteArray& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
out += (in & 0xFF00000000000000UL) >> 56;
|
out += (in & 0xFF00000000000000UL) >> 56;
|
||||||
out += (in & 0x00FF000000000000UL) >> 48;
|
out += (in & 0x00FF000000000000UL) >> 48;
|
||||||
@@ -19,22 +19,21 @@ namespace LtsUtils
|
|||||||
out += (in & 0x0000000000FF0000UL) >> 16;
|
out += (in & 0x0000000000FF0000UL) >> 16;
|
||||||
out += (in & 0x000000000000FF00UL) >> 8;
|
out += (in & 0x000000000000FF00UL) >> 8;
|
||||||
out += (in & 0x00000000000000FFUL);
|
out += (in & 0x00000000000000FFUL);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> void inline set8Byte(const double in, QByteArray &out)
|
template <> void inline set8Byte(const double in, QByteArray& out)
|
||||||
{
|
{
|
||||||
union hack
|
union hack {
|
||||||
{
|
|
||||||
double d;
|
double d;
|
||||||
int64_t i;
|
int64_t i;
|
||||||
} h;
|
} h;
|
||||||
|
|
||||||
h.d = in;
|
h.d = in;
|
||||||
set8Byte(h.i, out);
|
set8Byte(h.i, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get8Byte(const QByteArray &baData, size_t &pos, T &out)
|
template <typename T> bool inline get8Byte(const QByteArray& baData, size_t& pos, T& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
static_assert(sizeof(T) >= 8, "sizeof(out) is smaller than 8 bytes - will not fit");
|
static_assert(sizeof(T) >= 8, "sizeof(out) is smaller than 8 bytes - will not fit");
|
||||||
out = T();
|
out = T();
|
||||||
@@ -42,7 +41,7 @@ namespace LtsUtils
|
|||||||
if (size_t(baData.size()) < pos + 8)
|
if (size_t(baData.size()) < pos + 8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const char *data = baData.data() + pos;
|
const char* data = baData.data() + pos;
|
||||||
|
|
||||||
if (std::numeric_limits<T>::is_signed)
|
if (std::numeric_limits<T>::is_signed)
|
||||||
out |= static_cast<signed long long>(data[0]) << 56;
|
out |= static_cast<signed long long>(data[0]) << 56;
|
||||||
@@ -59,14 +58,13 @@ namespace LtsUtils
|
|||||||
pos += 8;
|
pos += 8;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> bool inline get8Byte(const QByteArray &baData, size_t &pos, double &out)
|
template <> bool inline get8Byte(const QByteArray& baData, size_t& pos, double& out)
|
||||||
{
|
{
|
||||||
out = 0.;
|
out = 0.;
|
||||||
|
|
||||||
union hack
|
union hack {
|
||||||
{
|
|
||||||
double d;
|
double d;
|
||||||
int64_t i;
|
int64_t i;
|
||||||
} h;
|
} h;
|
||||||
@@ -75,31 +73,31 @@ namespace LtsUtils
|
|||||||
return false;
|
return false;
|
||||||
out = h.d;
|
out = h.d;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get8Byte(const QByteArray &data, T &out)
|
template <typename T> bool inline get8Byte(const QByteArray& data, T& out)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
return get8Byte(data, pos, out);
|
return get8Byte(data, pos, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void inline set4Byte(const T in, QByteArray &out)
|
template <typename T> void inline set4Byte(const T in, QByteArray& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
out += (in & 0xFF000000) >> 24;
|
out += (in & 0xFF000000) >> 24;
|
||||||
out += (in & 0x00FF0000) >> 16;
|
out += (in & 0x00FF0000) >> 16;
|
||||||
out += (in & 0x0000FF00) >> 8;
|
out += (in & 0x0000FF00) >> 8;
|
||||||
out += (in & 0x000000FF);
|
out += (in & 0x000000FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> void inline set4Byte(const double in, QByteArray &out)
|
template <> void inline set4Byte(const double in, QByteArray& out)
|
||||||
{
|
{
|
||||||
int tmp = qRound(in);
|
int tmp = qRound(in);
|
||||||
return set4Byte(tmp, out);
|
return set4Byte(tmp, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get4Byte(const QByteArray &baData, size_t &pos, T &out)
|
template <typename T> bool inline get4Byte(const QByteArray& baData, size_t& pos, T& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
static_assert(sizeof(T) >= 4, "sizeof(out) is smaller than 4 bytes - will not fit");
|
static_assert(sizeof(T) >= 4, "sizeof(out) is smaller than 4 bytes - will not fit");
|
||||||
out = T();
|
out = T();
|
||||||
@@ -107,7 +105,7 @@ namespace LtsUtils
|
|||||||
if (size_t(baData.size()) < pos + 4)
|
if (size_t(baData.size()) < pos + 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const char *data = baData.data() + pos;
|
const char* data = baData.data() + pos;
|
||||||
|
|
||||||
if (std::numeric_limits<T>::is_signed)
|
if (std::numeric_limits<T>::is_signed)
|
||||||
out |= data[0] << 24;
|
out |= data[0] << 24;
|
||||||
@@ -120,34 +118,34 @@ namespace LtsUtils
|
|||||||
pos += 4;
|
pos += 4;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> bool inline get4Byte(const QByteArray &baData, size_t &pos, double &out)
|
template <> bool inline get4Byte(const QByteArray& baData, size_t& pos, double& out)
|
||||||
{
|
{
|
||||||
out = 0.;
|
out = 0.;
|
||||||
int tmp;
|
int tmp;
|
||||||
if (!get4Byte(baData, pos, tmp))
|
if (!get4Byte(baData, pos, tmp))
|
||||||
return false;
|
return false;
|
||||||
out = tmp;
|
out = tmp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get4Byte(const QByteArray &data, T &out)
|
template <typename T> bool inline get4Byte(const QByteArray& data, T& out)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
return get4Byte(data, pos, out);
|
return get4Byte(data, pos, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void inline set3Byte(const T in, QByteArray &out)
|
template <typename T> void inline set3Byte(const T in, QByteArray& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
out += (in & 0x00FF0000) >> 16;
|
out += (in & 0x00FF0000) >> 16;
|
||||||
out += (in & 0x0000FF00) >> 8;
|
out += (in & 0x0000FF00) >> 8;
|
||||||
out += (in & 0x000000FF);
|
out += (in & 0x000000FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get3Byte(const QByteArray &baData, size_t &pos, T &out)
|
template <typename T> bool inline get3Byte(const QByteArray& baData, size_t& pos, T& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
static_assert(sizeof(T) >= 3, "sizeof(out) is smaller than 3 bytes - will not fit");
|
static_assert(sizeof(T) >= 3, "sizeof(out) is smaller than 3 bytes - will not fit");
|
||||||
out = T();
|
out = T();
|
||||||
@@ -155,7 +153,7 @@ namespace LtsUtils
|
|||||||
if (size_t(baData.size()) < pos + 3)
|
if (size_t(baData.size()) < pos + 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const char *data = baData.data() + pos;
|
const char* data = baData.data() + pos;
|
||||||
|
|
||||||
if (std::numeric_limits<T>::is_signed)
|
if (std::numeric_limits<T>::is_signed)
|
||||||
out |= data[0] << 16;
|
out |= data[0] << 16;
|
||||||
@@ -167,23 +165,23 @@ namespace LtsUtils
|
|||||||
pos += 3;
|
pos += 3;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get3Byte(const QByteArray &data, T &out)
|
template <typename T> bool inline get3Byte(const QByteArray& data, T& out)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
return get3Byte(data, pos, out);
|
return get3Byte(data, pos, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void inline set2Byte(const T in, QByteArray &out)
|
template <typename T> void inline set2Byte(const T in, QByteArray& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
out += (in & 0x0000FF00) >> 8;
|
out += (in & 0x0000FF00) >> 8;
|
||||||
out += (in & 0x000000FF);
|
out += (in & 0x000000FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get2Byte(const QByteArray &baData, size_t &pos, T &out)
|
template <typename T> bool inline get2Byte(const QByteArray& baData, size_t& pos, T& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
static_assert(sizeof(T) >= 2, "sizeof(out) is smaller than 2 bytes - will not fit");
|
static_assert(sizeof(T) >= 2, "sizeof(out) is smaller than 2 bytes - will not fit");
|
||||||
out = T();
|
out = T();
|
||||||
@@ -191,7 +189,7 @@ namespace LtsUtils
|
|||||||
if (size_t(baData.size()) < pos + 2)
|
if (size_t(baData.size()) < pos + 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const char *data = baData.data() + pos;
|
const char* data = baData.data() + pos;
|
||||||
|
|
||||||
if (std::numeric_limits<T>::is_signed)
|
if (std::numeric_limits<T>::is_signed)
|
||||||
out |= data[0] << 8;
|
out |= data[0] << 8;
|
||||||
@@ -202,23 +200,23 @@ namespace LtsUtils
|
|||||||
pos += 2;
|
pos += 2;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get2Byte(const QByteArray &data, T &out)
|
template <typename T> bool inline get2Byte(const QByteArray& data, T& out)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
return get2Byte(data, pos, out);
|
return get2Byte(data, pos, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void inline set1Byte(const T in, QByteArray &out)
|
template <typename T> void inline set1Byte(const T in, QByteArray& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
unsigned char c = static_cast<unsigned char>(in);
|
unsigned char c = static_cast<unsigned char>(in);
|
||||||
out += c;
|
out += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get1Byte(const QByteArray &baData, size_t &pos, T &out)
|
template <typename T> bool inline get1Byte(const QByteArray& baData, size_t& pos, T& out)
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
static_assert(std::is_integral_v<T> || std::is_enum_v<T>, "Only integrals allowed for raw byte accessd");
|
||||||
out = T();
|
out = T();
|
||||||
|
|
||||||
@@ -233,11 +231,11 @@ namespace LtsUtils
|
|||||||
pos += 1;
|
pos += 1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool inline get1Byte(const QByteArray &data, T &out)
|
template <typename T> bool inline get1Byte(const QByteArray& data, T& out)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
return get1Byte(data, pos, out);
|
return get1Byte(data, pos, out);
|
||||||
}
|
}
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -5,54 +5,51 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
QPlane3D::QPlane3D(const QPoint3D &pos, const QPoint3D &vec1, const QPoint3D &vec2)
|
QPlane3D::QPlane3D(const QPoint3D& pos, const QPoint3D& vec1, const QPoint3D& vec2)
|
||||||
: m_pos(pos)
|
: m_pos(pos), m_vec1(vec1), m_vec2(vec2)
|
||||||
, m_vec1(vec1)
|
{
|
||||||
, m_vec2(vec2)
|
|
||||||
{
|
|
||||||
m_normal = QPoint3D::crossProduct(m_vec1, m_vec2);
|
m_normal = QPoint3D::crossProduct(m_vec1, m_vec2);
|
||||||
m_planeC = QPoint3D::dotProduct(m_pos, m_normal);
|
m_planeC = QPoint3D::dotProduct(m_pos, m_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint3D QPlane3D::intersection(const QPoint3D &point, const QPoint3D &direction) const
|
QPoint3D QPlane3D::intersection(const QPoint3D& point, const QPoint3D& direction) const
|
||||||
{
|
{
|
||||||
const double dotProduct = QPoint3D::dotProduct(direction, m_normal);
|
const double dotProduct = QPoint3D::dotProduct(direction, m_normal);
|
||||||
if (qFuzzyIsNull(dotProduct))
|
if (qFuzzyIsNull(dotProduct))
|
||||||
return inPlane(point) ? point : QPoint3D();
|
return inPlane(point) ? point : QPoint3D();
|
||||||
const double distance = distanceTo(point) / std::abs(dotProduct);
|
const double distance = distanceTo(point) / std::abs(dotProduct);
|
||||||
return point + distance * direction;
|
return point + distance * direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QPlane3D::intersects(const QPoint3D &direction) const
|
bool QPlane3D::intersects(const QPoint3D& direction) const
|
||||||
{
|
{
|
||||||
return !isParallel(direction);
|
return !isParallel(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QPlane3D::isParallel(const QPoint3D &direction) const
|
bool QPlane3D::isParallel(const QPoint3D& direction) const
|
||||||
{
|
{
|
||||||
return qFuzzyIsNull(QPoint3D::dotProduct(m_normal, direction));
|
return qFuzzyIsNull(QPoint3D::dotProduct(m_normal, direction));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QPlane3D::inPlane(const QPoint3D &point) const
|
bool QPlane3D::inPlane(const QPoint3D& point) const
|
||||||
{
|
{
|
||||||
if (point == m_pos)
|
if (point == m_pos)
|
||||||
return true;
|
return true;
|
||||||
return qFuzzyIsNull(QPoint3D::dotProduct(m_normal, point - m_pos));
|
return qFuzzyIsNull(QPoint3D::dotProduct(m_normal, point - m_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
double QPlane3D::distanceTo(const QPoint3D &point) const
|
double QPlane3D::distanceTo(const QPoint3D& point) const
|
||||||
{
|
{
|
||||||
return QPoint3D::dotProduct(point - m_pos, m_normal);
|
return QPoint3D::dotProduct(point - m_pos, m_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPolygon3D::QPolygon3D(const QVector<QPoint3D> &vertices)
|
QPolygon3D::QPolygon3D(const QVector<QPoint3D>& vertices)
|
||||||
: QPlane3D(vertices[0], vertices[1], vertices[2])
|
: QPlane3D(vertices[0], vertices[1], vertices[2]), m_vertices(vertices)
|
||||||
, m_vertices(vertices)
|
{
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool QPolygon3D::containsPoint(const QPoint3D &point) const
|
bool QPolygon3D::containsPoint(const QPoint3D& point) const
|
||||||
{
|
{
|
||||||
if (!inPlane(point))
|
if (!inPlane(point))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -64,13 +61,13 @@ namespace LtsUtils
|
|||||||
const int numberOfVertices = m_vertices.size();
|
const int numberOfVertices = m_vertices.size();
|
||||||
for (int i = 0; i < m_vertices.size(); ++i)
|
for (int i = 0; i < m_vertices.size(); ++i)
|
||||||
{
|
{
|
||||||
const QPoint3D &first = m_vertices[i % numberOfVertices] - point;
|
const QPoint3D& first = m_vertices[i % numberOfVertices] - point;
|
||||||
const QPoint3D &second = m_vertices[(i + 1) % numberOfVertices] - point;
|
const QPoint3D& second = m_vertices[(i + 1) % numberOfVertices] - point;
|
||||||
|
|
||||||
cosTheta = QPoint3D::dotProduct(first, second) / (first.length() * second.length());
|
cosTheta = QPoint3D::dotProduct(first, second) / (first.length() * second.length());
|
||||||
angleSum += acos(cosTheta);
|
angleSum += acos(cosTheta);
|
||||||
}
|
}
|
||||||
return qFuzzyIsNull(M_2_PI - angleSum);
|
return qFuzzyIsNull(M_2_PI - angleSum);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -11,27 +11,42 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class LTSUTILSCORE_EXPORT QPlane3D
|
class LTSUTILSCORE_EXPORT QPlane3D
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QPlane3D(const QPoint3D &pos, const QPoint3D &vec1, const QPoint3D &vec2);
|
QPlane3D(const QPoint3D& pos, const QPoint3D& vec1, const QPoint3D& vec2);
|
||||||
|
|
||||||
QPoint3D intersection(const QPoint3D &point, const QPoint3D &direction) const;
|
QPoint3D intersection(const QPoint3D& point, const QPoint3D& direction) const;
|
||||||
bool intersects(const QPoint3D &direction) const;
|
bool intersects(const QPoint3D& direction) const;
|
||||||
bool isParallel(const QPoint3D &direction) const;
|
bool isParallel(const QPoint3D& direction) const;
|
||||||
bool inPlane(const QPoint3D &point) const;
|
bool inPlane(const QPoint3D& point) const;
|
||||||
double distanceTo(const QPoint3D &point) const;
|
double distanceTo(const QPoint3D& point) const;
|
||||||
|
|
||||||
const QPoint3D &pos() const { return m_pos; }
|
const QPoint3D& pos() const
|
||||||
|
{
|
||||||
|
return m_pos;
|
||||||
|
}
|
||||||
|
|
||||||
const QPoint3D &vec1() const { return m_vec1; }
|
const QPoint3D& vec1() const
|
||||||
|
{
|
||||||
|
return m_vec1;
|
||||||
|
}
|
||||||
|
|
||||||
const QPoint3D &vec2() const { return m_vec2; }
|
const QPoint3D& vec2() const
|
||||||
|
{
|
||||||
|
return m_vec2;
|
||||||
|
}
|
||||||
|
|
||||||
const QPoint3D &normal() const { return m_normal; }
|
const QPoint3D& normal() const
|
||||||
|
{
|
||||||
|
return m_normal;
|
||||||
|
}
|
||||||
|
|
||||||
double planeC() const { return m_planeC; }
|
double planeC() const
|
||||||
|
{
|
||||||
|
return m_planeC;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QPoint3D m_pos;
|
QPoint3D m_pos;
|
||||||
@@ -39,20 +54,23 @@ namespace LtsUtils
|
|||||||
QPoint3D m_vec2;
|
QPoint3D m_vec2;
|
||||||
QPoint3D m_normal;
|
QPoint3D m_normal;
|
||||||
double m_planeC;
|
double m_planeC;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LTSUTILSCORE_EXPORT QPolygon3D : public QPlane3D
|
class LTSUTILSCORE_EXPORT QPolygon3D : public QPlane3D
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QPolygon3D(const QVector<QPoint3D> &vertices);
|
QPolygon3D(const QVector<QPoint3D>& vertices);
|
||||||
|
|
||||||
bool contains(const QPoint3D &point) const { return m_vertices.contains(point); }
|
bool contains(const QPoint3D& point) const
|
||||||
|
{
|
||||||
|
return m_vertices.contains(point);
|
||||||
|
}
|
||||||
|
|
||||||
bool containsPoint(const QPoint3D &point) const;
|
bool containsPoint(const QPoint3D& point) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<QPoint3D> m_vertices;
|
QVector<QPoint3D> m_vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -7,14 +7,14 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
QDataStream &operator<<(QDataStream &s, const QPoint3D &p)
|
QDataStream& operator<<(QDataStream& s, const QPoint3D& p)
|
||||||
{
|
{
|
||||||
s << p.x() << p.y() << p.z();
|
s << p.x() << p.y() << p.z();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream &operator>>(QDataStream &s, QPoint3D &p)
|
QDataStream& operator>>(QDataStream& s, QPoint3D& p)
|
||||||
{
|
{
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
s >> x;
|
s >> x;
|
||||||
p.rx() = x;
|
p.rx() = x;
|
||||||
@@ -23,6 +23,6 @@ namespace LtsUtils
|
|||||||
s >> z;
|
s >> z;
|
||||||
p.rz() = z;
|
p.rz() = z;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -13,24 +13,15 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class QPoint3D
|
class QPoint3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Axis
|
enum class Axis { X, Y, Z };
|
||||||
{
|
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
Z
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr QPoint3D() = default;
|
constexpr QPoint3D() = default;
|
||||||
constexpr QPoint3D(double xpos, double ypos, double zpos);
|
constexpr QPoint3D(double xpos, double ypos, double zpos);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> explicit QPoint3D(const T& data) : xp(data.offsetX()), yp(data.offsetY()), zp(data.offsetZ())
|
||||||
explicit QPoint3D(const T &data)
|
|
||||||
: xp(data.offsetX())
|
|
||||||
, yp(data.offsetY())
|
|
||||||
, zp(data.offsetZ())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,17 +34,26 @@ namespace LtsUtils
|
|||||||
constexpr inline void setY(double ypos);
|
constexpr inline void setY(double ypos);
|
||||||
constexpr inline void setZ(double zpos);
|
constexpr inline void setZ(double zpos);
|
||||||
|
|
||||||
constexpr inline double &rx();
|
constexpr inline double& rx();
|
||||||
constexpr inline double &ry();
|
constexpr inline double& ry();
|
||||||
constexpr inline double &rz();
|
constexpr inline double& rz();
|
||||||
|
|
||||||
constexpr inline QPointF toPointF() const;
|
constexpr inline QPointF toPointF() const;
|
||||||
|
|
||||||
static QPoint3D fromQPointF(const QPointF &p) { return QPoint3D(p.x(), p.y(), .0); }
|
static QPoint3D fromQPointF(const QPointF& p)
|
||||||
|
{
|
||||||
|
return QPoint3D(p.x(), p.y(), .0);
|
||||||
|
}
|
||||||
|
|
||||||
inline double lengthSquared() const { return (xp * xp) + (yp * yp) + (zp * zp); }
|
inline double lengthSquared() const
|
||||||
|
{
|
||||||
|
return (xp * xp) + (yp * yp) + (zp * zp);
|
||||||
|
}
|
||||||
|
|
||||||
inline double length() const { return std::sqrt(lengthSquared()); }
|
inline double length() const
|
||||||
|
{
|
||||||
|
return std::sqrt(lengthSquared());
|
||||||
|
}
|
||||||
|
|
||||||
inline void normalize()
|
inline void normalize()
|
||||||
{
|
{
|
||||||
@@ -79,30 +79,27 @@ namespace LtsUtils
|
|||||||
return QPoint3D(*this);
|
return QPoint3D(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void rotate(const double &phi, const Axis &axis)
|
inline void rotate(const double& phi, const Axis& axis)
|
||||||
{
|
{
|
||||||
const double sin = std::sin(phi);
|
const double sin = std::sin(phi);
|
||||||
const double cos = std::cos(phi);
|
const double cos = std::cos(phi);
|
||||||
switch (axis)
|
switch (axis)
|
||||||
{
|
{
|
||||||
case Axis::X:
|
case Axis::X: {
|
||||||
{
|
|
||||||
const double _yp = (cos * yp) - (sin * zp);
|
const double _yp = (cos * yp) - (sin * zp);
|
||||||
const double _zp = (sin * yp) + (cos * zp);
|
const double _zp = (sin * yp) + (cos * zp);
|
||||||
yp = _yp;
|
yp = _yp;
|
||||||
zp = _zp;
|
zp = _zp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Axis::Y:
|
case Axis::Y: {
|
||||||
{
|
|
||||||
const double _xp = (cos * xp) + (sin * zp);
|
const double _xp = (cos * xp) + (sin * zp);
|
||||||
const double _zp = (-sin * xp) + (cos * zp);
|
const double _zp = (-sin * xp) + (cos * zp);
|
||||||
xp = _xp;
|
xp = _xp;
|
||||||
zp = _zp;
|
zp = _zp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Axis::Z:
|
case Axis::Z: {
|
||||||
{
|
|
||||||
const double _xp = (cos * xp) - (sin * yp);
|
const double _xp = (cos * xp) - (sin * yp);
|
||||||
const double _yp = (sin * xp) + (cos * yp);
|
const double _yp = (sin * xp) + (cos * yp);
|
||||||
xp = _xp;
|
xp = _xp;
|
||||||
@@ -112,42 +109,63 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QPoint3D rotated(const double &phi, const Axis &axis) const
|
inline QPoint3D rotated(const double& phi, const Axis& axis) const
|
||||||
{
|
{
|
||||||
QPoint3D p(*this);
|
QPoint3D p(*this);
|
||||||
p.rotate(phi, axis);
|
p.rotate(phi, axis);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double distanceToLine(const QPoint3D &point, const QPoint3D &direction) const
|
inline double distanceToLine(const QPoint3D& point, const QPoint3D& direction) const
|
||||||
{
|
{
|
||||||
if (direction.isNull())
|
if (direction.isNull())
|
||||||
return (*this - point).length();
|
return (*this - point).length();
|
||||||
QPoint3D p = point + dotProduct(*this - point, direction) * direction;
|
QPoint3D p = point + dotProduct(*this - point, direction) * direction;
|
||||||
return (*this - p).length();
|
return (*this - p).length();
|
||||||
}
|
}
|
||||||
inline double distanceToPlane(const QPoint3D &plane, const QPoint3D &normal) const { return dotProduct(*this - plane, normal); }
|
inline double distanceToPlane(const QPoint3D& plane, const QPoint3D& normal) const
|
||||||
inline double distanceToPlane(const QPoint3D &plane1, const QPoint3D &plane2, const QPoint3D &plane3) const
|
{
|
||||||
|
return dotProduct(*this - plane, normal);
|
||||||
|
}
|
||||||
|
inline double distanceToPlane(const QPoint3D& plane1, const QPoint3D& plane2, const QPoint3D& plane3) const
|
||||||
{
|
{
|
||||||
QPoint3D n = normal(plane2 - plane1, plane3 - plane1);
|
QPoint3D n = normal(plane2 - plane1, plane3 - plane1);
|
||||||
return dotProduct(*this - plane1, n);
|
return dotProduct(*this - plane1, n);
|
||||||
}
|
}
|
||||||
inline double distanceToPoint(const QPoint3D &point) const { return (*this - point).length(); }
|
inline double distanceToPoint(const QPoint3D& point) const
|
||||||
|
{
|
||||||
|
return (*this - point).length();
|
||||||
|
}
|
||||||
|
|
||||||
friend constexpr inline bool operator==(const QPoint3D &p1, const QPoint3D &p2);
|
friend constexpr inline bool operator==(const QPoint3D& p1, const QPoint3D& p2);
|
||||||
friend constexpr inline bool operator!=(const QPoint3D &p1, const QPoint3D &p2);
|
friend constexpr inline bool operator!=(const QPoint3D& p1, const QPoint3D& p2);
|
||||||
|
|
||||||
friend constexpr inline QPoint3D operator+(const QPoint3D &p1, const QPoint3D &p2) { return QPoint3D(p1.xp + p2.xp, p1.yp + p2.yp, p1.zp + p2.zp); }
|
friend constexpr inline QPoint3D operator+(const QPoint3D& p1, const QPoint3D& p2)
|
||||||
|
{
|
||||||
|
return QPoint3D(p1.xp + p2.xp, p1.yp + p2.yp, p1.zp + p2.zp);
|
||||||
|
}
|
||||||
|
|
||||||
friend constexpr inline QPoint3D operator-(const QPoint3D &p1, const QPoint3D &p2) { return QPoint3D(p1.xp - p2.xp, p1.yp - p2.yp, p1.zp - p2.zp); }
|
friend constexpr inline QPoint3D operator-(const QPoint3D& p1, const QPoint3D& p2)
|
||||||
|
{
|
||||||
|
return QPoint3D(p1.xp - p2.xp, p1.yp - p2.yp, p1.zp - p2.zp);
|
||||||
|
}
|
||||||
|
|
||||||
friend constexpr inline QPoint3D operator*(const QPoint3D &p1, double factor) { return QPoint3D(p1.xp * factor, p1.yp * factor, p1.zp * factor); }
|
friend constexpr inline QPoint3D operator*(const QPoint3D& p1, double factor)
|
||||||
|
{
|
||||||
|
return QPoint3D(p1.xp * factor, p1.yp * factor, p1.zp * factor);
|
||||||
|
}
|
||||||
|
|
||||||
friend constexpr inline QPoint3D operator*(double factor, const QPoint3D &p1) { return QPoint3D(p1.xp * factor, p1.yp * factor, p1.zp * factor); }
|
friend constexpr inline QPoint3D operator*(double factor, const QPoint3D& p1)
|
||||||
|
{
|
||||||
|
return QPoint3D(p1.xp * factor, p1.yp * factor, p1.zp * factor);
|
||||||
|
}
|
||||||
|
|
||||||
friend constexpr inline QPoint3D operator/(const QPoint3D &p1, double factor) { return QPoint3D(p1.xp / factor, p1.yp / factor, p1.zp / factor); }
|
friend constexpr inline QPoint3D operator/(const QPoint3D& p1, double factor)
|
||||||
|
{
|
||||||
|
return QPoint3D(p1.xp / factor, p1.yp / factor, p1.zp / factor);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr inline QPoint3D &operator+=(const QPoint3D &o)
|
constexpr inline QPoint3D& operator+=(const QPoint3D& o)
|
||||||
{
|
{
|
||||||
xp += o.xp;
|
xp += o.xp;
|
||||||
yp += o.yp;
|
yp += o.yp;
|
||||||
@@ -155,7 +173,7 @@ namespace LtsUtils
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline QPoint3D &operator-=(const QPoint3D &o)
|
constexpr inline QPoint3D& operator-=(const QPoint3D& o)
|
||||||
{
|
{
|
||||||
xp -= o.xp;
|
xp -= o.xp;
|
||||||
yp -= o.yp;
|
yp -= o.yp;
|
||||||
@@ -163,7 +181,7 @@ namespace LtsUtils
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline QPoint3D &operator*=(double factor)
|
constexpr inline QPoint3D& operator*=(double factor)
|
||||||
{
|
{
|
||||||
xp *= factor;
|
xp *= factor;
|
||||||
yp *= factor;
|
yp *= factor;
|
||||||
@@ -171,7 +189,7 @@ namespace LtsUtils
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline QPoint3D &operator/=(double divisor)
|
constexpr inline QPoint3D& operator/=(double divisor)
|
||||||
{
|
{
|
||||||
xp /= divisor;
|
xp /= divisor;
|
||||||
yp /= divisor;
|
yp /= divisor;
|
||||||
@@ -179,18 +197,27 @@ namespace LtsUtils
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static inline double dotProduct(const QPoint3D &v1, const QPoint3D &v2) { return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp; }
|
constexpr static inline double dotProduct(const QPoint3D& v1, const QPoint3D& v2)
|
||||||
|
{
|
||||||
|
return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr static inline QPoint3D crossProduct(const QPoint3D &v1, const QPoint3D &v2)
|
constexpr static inline QPoint3D crossProduct(const QPoint3D& v1, const QPoint3D& v2)
|
||||||
{
|
{
|
||||||
return QPoint3D(v1.yp * v2.zp - v1.zp * v2.yp, v1.zp * v2.xp - v1.xp * v2.zp, v1.xp * v2.yp - v1.yp * v2.xp);
|
return QPoint3D(v1.yp * v2.zp - v1.zp * v2.yp, v1.zp * v2.xp - v1.xp * v2.zp, v1.xp * v2.yp - v1.yp * v2.xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QPoint3D normal(const QPoint3D &v1, const QPoint3D &v2) { return crossProduct(v1, v2).normalized(); }
|
static inline QPoint3D normal(const QPoint3D& v1, const QPoint3D& v2)
|
||||||
|
{
|
||||||
|
return crossProduct(v1, v2).normalized();
|
||||||
|
}
|
||||||
|
|
||||||
static inline QPoint3D normal(const QPoint3D &v1, const QPoint3D &v2, const QPoint3D &v3) { return crossProduct((v2 - v1), (v3 - v1)).normalized(); }
|
static inline QPoint3D normal(const QPoint3D& v1, const QPoint3D& v2, const QPoint3D& v3)
|
||||||
|
{
|
||||||
|
return crossProduct((v2 - v1), (v3 - v1)).normalized();
|
||||||
|
}
|
||||||
|
|
||||||
friend inline bool qFuzzyCompare(const QPoint3D &v1, const QPoint3D &v2)
|
friend inline bool qFuzzyCompare(const QPoint3D& v1, const QPoint3D& v2)
|
||||||
{
|
{
|
||||||
return ::qFuzzyCompare(v1.xp, v2.xp) && ::qFuzzyCompare(v1.yp, v2.yp) && ::qFuzzyCompare(v1.zp, v2.zp);
|
return ::qFuzzyCompare(v1.xp, v2.xp) && ::qFuzzyCompare(v1.yp, v2.yp) && ::qFuzzyCompare(v1.zp, v2.zp);
|
||||||
}
|
}
|
||||||
@@ -199,88 +226,83 @@ namespace LtsUtils
|
|||||||
double xp = 0;
|
double xp = 0;
|
||||||
double yp = 0;
|
double yp = 0;
|
||||||
double zp = 0;
|
double zp = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// QDataStream& operator<<(QDataStream& s, const QPoint3D& p);
|
// QDataStream& operator<<(QDataStream& s, const QPoint3D& p);
|
||||||
// QDataStream& operator>>(QDataStream& s, QPoint3D& p);
|
// QDataStream& operator>>(QDataStream& s, QPoint3D& p);
|
||||||
|
|
||||||
constexpr inline QPoint3D::QPoint3D(double xpos, double ypos, double zpos)
|
constexpr inline QPoint3D::QPoint3D(double xpos, double ypos, double zpos) : xp(xpos), yp(ypos), zp(zpos) {}
|
||||||
: xp(xpos)
|
|
||||||
, yp(ypos)
|
|
||||||
, zp(zpos)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool QPoint3D::isNull() const
|
inline bool QPoint3D::isNull() const
|
||||||
{
|
{
|
||||||
return qIsNull(xp) && qIsNull(yp) && qIsNull(zp);
|
return qIsNull(xp) && qIsNull(yp) && qIsNull(zp);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline double QPoint3D::x() const
|
constexpr inline double QPoint3D::x() const
|
||||||
{
|
{
|
||||||
return xp;
|
return xp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline double QPoint3D::y() const
|
constexpr inline double QPoint3D::y() const
|
||||||
{
|
{
|
||||||
return yp;
|
return yp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline double QPoint3D::z() const
|
constexpr inline double QPoint3D::z() const
|
||||||
{
|
{
|
||||||
return zp;
|
return zp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline void QPoint3D::setX(double xpos)
|
constexpr inline void QPoint3D::setX(double xpos)
|
||||||
{
|
{
|
||||||
xp = xpos;
|
xp = xpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline void QPoint3D::setY(double ypos)
|
constexpr inline void QPoint3D::setY(double ypos)
|
||||||
{
|
{
|
||||||
yp = ypos;
|
yp = ypos;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline void QPoint3D::setZ(double zpos)
|
constexpr inline void QPoint3D::setZ(double zpos)
|
||||||
{
|
{
|
||||||
zp = zpos;
|
zp = zpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline double &QPoint3D::rx()
|
constexpr inline double& QPoint3D::rx()
|
||||||
{
|
{
|
||||||
return xp;
|
return xp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline double &QPoint3D::ry()
|
constexpr inline double& QPoint3D::ry()
|
||||||
{
|
{
|
||||||
return yp;
|
return yp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline double &QPoint3D::rz()
|
constexpr inline double& QPoint3D::rz()
|
||||||
{
|
{
|
||||||
return zp;
|
return zp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline QPointF QPoint3D::toPointF() const
|
constexpr inline QPointF QPoint3D::toPointF() const
|
||||||
{
|
{
|
||||||
return QPointF(xp, yp);
|
return QPointF(xp, yp);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline bool operator==(const QPoint3D &p1, const QPoint3D &p2)
|
constexpr inline bool operator==(const QPoint3D& p1, const QPoint3D& p2)
|
||||||
{
|
{
|
||||||
return p1.xp == p2.xp && p1.yp == p2.yp && p1.zp == p2.zp;
|
return p1.xp == p2.xp && p1.yp == p2.yp && p1.zp == p2.zp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline bool operator!=(const QPoint3D &p1, const QPoint3D &p2)
|
constexpr inline bool operator!=(const QPoint3D& p1, const QPoint3D& p2)
|
||||||
{
|
{
|
||||||
return p1.xp != p2.xp || p1.yp != p2.yp || p1.zp != p2.zp;
|
return p1.xp != p2.xp || p1.yp != p2.yp || p1.zp != p2.zp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &stream, const QPoint3D &pos)
|
inline std::ostream& operator<<(std::ostream& stream, const QPoint3D& pos)
|
||||||
{
|
{
|
||||||
stream << "(" << pos.x() << "," << pos.y() << "," << pos.z() << ")";
|
stream << "(" << pos.x() << "," << pos.y() << "," << pos.z() << ")";
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
|
|
||||||
|
|||||||
+14
-8
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* ScopedConnection
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Christian Fröbel, SLSE, 2017-07-24
|
||||||
|
*/
|
||||||
|
|
||||||
#include "scoped_connection.h"
|
#include "scoped_connection.h"
|
||||||
|
|
||||||
@@ -7,16 +14,15 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
ScopedConnection::ScopedConnection(IConnection *connection, Qt::ConnectionType connType)
|
ScopedConnection::ScopedConnection(IConnection* connection, Qt::ConnectionType connType) : m_conn(connection)
|
||||||
: m_conn(connection)
|
{
|
||||||
{
|
|
||||||
Q_ASSERT(connection);
|
Q_ASSERT(connection);
|
||||||
m_conn->connect(connType);
|
m_conn->connect(connType);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedConnection::~ScopedConnection()
|
ScopedConnection::~ScopedConnection()
|
||||||
{
|
{
|
||||||
m_conn->disconnect();
|
m_conn->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+14
-7
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* ScopedConnection
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Christian Fröbel, SLSE, 2017-07-24
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -9,16 +16,16 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class IConnection;
|
class IConnection;
|
||||||
|
|
||||||
class LTSUTILSCORE_EXPORT ScopedConnection
|
class LTSUTILSCORE_EXPORT ScopedConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ScopedConnection(IConnection *connection, Qt::ConnectionType = Qt::AutoConnection);
|
explicit ScopedConnection(IConnection* connection, Qt::ConnectionType = Qt::AutoConnection);
|
||||||
~ScopedConnection();
|
~ScopedConnection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IConnection *m_conn;
|
IConnection* m_conn;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+58
-58
@@ -5,24 +5,24 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
static constexpr unsigned char XON = 0x11;
|
static constexpr unsigned char XON = 0x11;
|
||||||
static constexpr unsigned char XOFF = 0x13;
|
static constexpr unsigned char XOFF = 0x13;
|
||||||
static constexpr unsigned char STX = 0x02;
|
static constexpr unsigned char STX = 0x02;
|
||||||
static constexpr unsigned char ETX = 0x03;
|
static constexpr unsigned char ETX = 0x03;
|
||||||
static constexpr unsigned char SUBST = 0x80;
|
static constexpr unsigned char SUBST = 0x80;
|
||||||
|
|
||||||
static constexpr unsigned char SUB_XON = 0x91;
|
static constexpr unsigned char SUB_XON = 0x91;
|
||||||
static constexpr unsigned char SUB_XOFF = 0x93;
|
static constexpr unsigned char SUB_XOFF = 0x93;
|
||||||
static constexpr unsigned char SUB_STX = 0x82;
|
static constexpr unsigned char SUB_STX = 0x82;
|
||||||
static constexpr unsigned char SUB_ETX = 0x83;
|
static constexpr unsigned char SUB_ETX = 0x83;
|
||||||
static constexpr unsigned char SUB_SUBST = 0x00;
|
static constexpr unsigned char SUB_SUBST = 0x00;
|
||||||
|
|
||||||
static constexpr int HEADER_SIZE = 3;
|
static constexpr int HEADER_SIZE = 3;
|
||||||
static constexpr int CHECKSUM_SIZE = 1;
|
static constexpr int CHECKSUM_SIZE = 1;
|
||||||
static constexpr int MINIMUM_BYTE_SIZE = 1 + HEADER_SIZE + CHECKSUM_SIZE + 1;
|
static constexpr int MINIMUM_BYTE_SIZE = 1 + HEADER_SIZE + CHECKSUM_SIZE + 1;
|
||||||
|
|
||||||
static SfmMessage getSfmMessage(const QByteArray &p_data)
|
static SfmMessage getSfmMessage(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned short id = 0;
|
unsigned short id = 0;
|
||||||
id |= (((unsigned short)p_data[0]) & 0x7F) << 8;
|
id |= (((unsigned short)p_data[0]) & 0x7F) << 8;
|
||||||
@@ -34,10 +34,10 @@ namespace LtsUtils
|
|||||||
msg.setPayload(p_data.right(p_data.size() - HEADER_SIZE));
|
msg.setPayload(p_data.right(p_data.size() - HEADER_SIZE));
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray getHeader(const SfmMessage &p_msg)
|
static QByteArray getHeader(const SfmMessage& p_msg)
|
||||||
{
|
{
|
||||||
QByteArray header(2, Qt::Uninitialized);
|
QByteArray header(2, Qt::Uninitialized);
|
||||||
|
|
||||||
header[0] = ((p_msg.id() >> 8) & 0x7f) | (p_msg.rtr() << 7);
|
header[0] = ((p_msg.id() >> 8) & 0x7f) | (p_msg.rtr() << 7);
|
||||||
@@ -45,20 +45,20 @@ namespace LtsUtils
|
|||||||
header[1] = (p_msg.id() >> 0) & 0xff;
|
header[1] = (p_msg.id() >> 0) & 0xff;
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char getChecksum(const QByteArray &p_data)
|
static inline char getChecksum(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
char sum = 0;
|
char sum = 0;
|
||||||
|
|
||||||
for (const char c : p_data)
|
for (const char c : p_data)
|
||||||
sum += c;
|
sum += c;
|
||||||
|
|
||||||
return sum ^ 0xff;
|
return sum ^ 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray removeChecksum(const QByteArray &p_data)
|
static QByteArray removeChecksum(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
QByteArray withoutChecksum(p_data);
|
QByteArray withoutChecksum(p_data);
|
||||||
ConversionError error("Checksum error");
|
ConversionError error("Checksum error");
|
||||||
|
|
||||||
@@ -73,10 +73,10 @@ namespace LtsUtils
|
|||||||
throw error;
|
throw error;
|
||||||
|
|
||||||
return withoutChecksum;
|
return withoutChecksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray maskData(const QByteArray &p_data)
|
static QByteArray maskData(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
QByteArray maskData;
|
QByteArray maskData;
|
||||||
maskData.reserve(p_data.size() * 8 / 6);
|
maskData.reserve(p_data.size() * 8 / 6);
|
||||||
|
|
||||||
@@ -111,10 +111,10 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
return maskData;
|
return maskData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool mustBeMasked(const unsigned char byte)
|
static bool mustBeMasked(const unsigned char byte)
|
||||||
{
|
{
|
||||||
switch (byte)
|
switch (byte)
|
||||||
{
|
{
|
||||||
case XON:
|
case XON:
|
||||||
@@ -127,10 +127,10 @@ namespace LtsUtils
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lenMaskedData(const QByteArray &data)
|
int lenMaskedData(const QByteArray& data)
|
||||||
{
|
{
|
||||||
int ret = data.length();
|
int ret = data.length();
|
||||||
const unsigned char upperLen = ((data.length() & 0xff00) >> 8);
|
const unsigned char upperLen = ((data.length() & 0xff00) >> 8);
|
||||||
const unsigned char lowerLen = ((data.length() & 0x00ff) >> 0);
|
const unsigned char lowerLen = ((data.length() & 0x00ff) >> 0);
|
||||||
@@ -147,10 +147,10 @@ namespace LtsUtils
|
|||||||
++ret;
|
++ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray unmaskData(const QByteArray &p_data)
|
static QByteArray unmaskData(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
QByteArray unmaskData;
|
QByteArray unmaskData;
|
||||||
unmaskData.reserve(p_data.size());
|
unmaskData.reserve(p_data.size());
|
||||||
|
|
||||||
@@ -187,20 +187,20 @@ namespace LtsUtils
|
|||||||
unmaskData.append(byte);
|
unmaskData.append(byte);
|
||||||
}
|
}
|
||||||
return unmaskData;
|
return unmaskData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray addFrame(const QByteArray &p_data)
|
static QByteArray addFrame(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
QByteArray ret;
|
QByteArray ret;
|
||||||
ret.reserve(2 + p_data.size());
|
ret.reserve(2 + p_data.size());
|
||||||
ret.append(STX);
|
ret.append(STX);
|
||||||
ret.append(p_data);
|
ret.append(p_data);
|
||||||
ret.append(ETX);
|
ret.append(ETX);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray removeFrame(const QByteArray &p_data)
|
static QByteArray removeFrame(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (p_data[0] == STX && p_data[p_data.size() - 1] == ETX)
|
if (p_data[0] == STX && p_data[p_data.size() - 1] == ETX)
|
||||||
{
|
{
|
||||||
@@ -209,20 +209,20 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw ConversionError("Framing Error");
|
throw ConversionError("Framing Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkLength(const QByteArray &p_data)
|
static void checkLength(const QByteArray& p_data)
|
||||||
{
|
{
|
||||||
if (p_data.size() < HEADER_SIZE)
|
if (p_data.size() < HEADER_SIZE)
|
||||||
throw ConversionError("Telegram too short");
|
throw ConversionError("Telegram too short");
|
||||||
|
|
||||||
unsigned char length = p_data[HEADER_SIZE - 1];
|
unsigned char length = p_data[HEADER_SIZE - 1];
|
||||||
if (length != p_data.size() - HEADER_SIZE)
|
if (length != p_data.size() - HEADER_SIZE)
|
||||||
throw ConversionError("Telegram length does not match");
|
throw ConversionError("Telegram length does not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray byteStreamFromSfmMessage(const SfmMessage &message)
|
QByteArray byteStreamFromSfmMessage(const SfmMessage& message)
|
||||||
{
|
{
|
||||||
QByteArray byteData(getHeader(message));
|
QByteArray byteData(getHeader(message));
|
||||||
|
|
||||||
byteData.append(message.payload().size());
|
byteData.append(message.payload().size());
|
||||||
@@ -230,10 +230,10 @@ namespace LtsUtils
|
|||||||
byteData.append(getChecksum(byteData));
|
byteData.append(getChecksum(byteData));
|
||||||
|
|
||||||
return addFrame(maskData(byteData));
|
return addFrame(maskData(byteData));
|
||||||
}
|
}
|
||||||
|
|
||||||
SfmMessage byteStreamToSfmMessage(const QByteArray &datastream)
|
SfmMessage byteStreamToSfmMessage(const QByteArray& datastream)
|
||||||
{
|
{
|
||||||
if (datastream.size() < MINIMUM_BYTE_SIZE)
|
if (datastream.size() < MINIMUM_BYTE_SIZE)
|
||||||
throw ConversionError("Can't convert an QByteArray that hasn't the minimum size!");
|
throw ConversionError("Can't convert an QByteArray that hasn't the minimum size!");
|
||||||
|
|
||||||
@@ -247,10 +247,10 @@ namespace LtsUtils
|
|||||||
checkLength(checkMsg);
|
checkLength(checkMsg);
|
||||||
|
|
||||||
return getSfmMessage(checkMsg);
|
return getSfmMessage(checkMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray byteStreamFromEscMessage(const QByteArray &message)
|
QByteArray byteStreamFromEscMessage(const QByteArray& message)
|
||||||
{
|
{
|
||||||
QByteArray byteData = message;
|
QByteArray byteData = message;
|
||||||
if (message.size() == 1)
|
if (message.size() == 1)
|
||||||
{
|
{
|
||||||
@@ -264,10 +264,10 @@ namespace LtsUtils
|
|||||||
byteData = addFrame(byteData);
|
byteData = addFrame(byteData);
|
||||||
|
|
||||||
return byteData;
|
return byteData;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray byteStreamToEscMessage(const QByteArray &datastream)
|
QByteArray byteStreamToEscMessage(const QByteArray& datastream)
|
||||||
{
|
{
|
||||||
if (datastream.size() < 2)
|
if (datastream.size() < 2)
|
||||||
return QByteArray("ERROR");
|
return QByteArray("ERROR");
|
||||||
|
|
||||||
@@ -278,6 +278,6 @@ namespace LtsUtils
|
|||||||
|
|
||||||
checkMsg.chop(1);
|
checkMsg.chop(1);
|
||||||
return checkMsg;
|
return checkMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+39
-18
@@ -9,43 +9,64 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class LTSUTILSCORE_EXPORT SfmMessage
|
class LTSUTILSCORE_EXPORT SfmMessage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned int id() const { return m_id; }
|
unsigned int id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
void setId(unsigned int id) { m_id = id; }
|
void setId(unsigned int id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
bool rtr() const { return m_rtr; }
|
bool rtr() const
|
||||||
|
{
|
||||||
|
return m_rtr;
|
||||||
|
}
|
||||||
|
|
||||||
void setRtr(bool rtr) { m_rtr = rtr; }
|
void setRtr(bool rtr)
|
||||||
|
{
|
||||||
|
m_rtr = rtr;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray payload() const { return m_payload; }
|
QByteArray payload() const
|
||||||
|
{
|
||||||
|
return m_payload;
|
||||||
|
}
|
||||||
|
|
||||||
void setPayload(const QByteArray &payload) { m_payload = payload; }
|
void setPayload(const QByteArray& payload)
|
||||||
|
{
|
||||||
|
m_payload = payload;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const SfmMessage &msg) const { return (m_id == msg.id() && m_rtr == msg.rtr() && m_payload == msg.payload()); }
|
bool operator==(const SfmMessage& msg) const
|
||||||
|
{
|
||||||
|
return (m_id == msg.id() && m_rtr == msg.rtr() && m_payload == msg.payload());
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int m_id = 0;
|
unsigned int m_id = 0;
|
||||||
bool m_rtr = false;
|
bool m_rtr = false;
|
||||||
QByteArray m_payload;
|
QByteArray m_payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConversionError : public std::runtime_error
|
class ConversionError : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using std::runtime_error::runtime_error;
|
using std::runtime_error::runtime_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT QByteArray byteStreamFromSfmMessage(const SfmMessage &message);
|
LTSUTILSCORE_EXPORT QByteArray byteStreamFromSfmMessage(const SfmMessage& message);
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT SfmMessage byteStreamToSfmMessage(const QByteArray &datastream);
|
LTSUTILSCORE_EXPORT SfmMessage byteStreamToSfmMessage(const QByteArray& datastream);
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT QByteArray byteStreamFromEscMessage(const QByteArray &message);
|
LTSUTILSCORE_EXPORT QByteArray byteStreamFromEscMessage(const QByteArray& message);
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT QByteArray byteStreamToEscMessage(const QByteArray &datastream);
|
LTSUTILSCORE_EXPORT QByteArray byteStreamToEscMessage(const QByteArray& datastream);
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT int lenMaskedData(const QByteArray &data);
|
LTSUTILSCORE_EXPORT int lenMaskedData(const QByteArray& data);
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
inline bool lessThan(const QVariant &var1, const QVariant &var2)
|
inline bool lessThan(const QVariant& var1, const QVariant& var2)
|
||||||
{
|
{
|
||||||
if (var1.canConvert<QString>() && var2.canConvert<QString>())
|
if (var1.canConvert<QString>() && var2.canConvert<QString>())
|
||||||
{
|
{
|
||||||
QString str1(var1.toString());
|
QString str1(var1.toString());
|
||||||
@@ -32,6 +32,6 @@ namespace LtsUtils
|
|||||||
return var1.toDouble() < var2.toDouble();
|
return var1.toDouble() < var2.toDouble();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+6
@@ -45,6 +45,9 @@ if(QT6_GUI_AVAILABLE)
|
|||||||
Qt6::Svg
|
Qt6::Svg
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
TARGET_LINK_LIBRARIES(LtsUtilsGuiDds PUBLIC ddscore)
|
||||||
|
ENDIF(BUILD_RTI)
|
||||||
NGL_TARGET_COMPILE_DEFINITIONS(LtsUtilsGuiDds
|
NGL_TARGET_COMPILE_DEFINITIONS(LtsUtilsGuiDds
|
||||||
PUBLIC
|
PUBLIC
|
||||||
REQUEST_HELPER_WITH_GUI
|
REQUEST_HELPER_WITH_GUI
|
||||||
@@ -77,3 +80,6 @@ NGL_TARGET_LINK_LIBRARIES(LtsUtilsDds
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
Qt6::Core
|
Qt6::Core
|
||||||
)
|
)
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
TARGET_LINK_LIBRARIES(LtsUtilsDds PUBLIC ddscore)
|
||||||
|
ENDIF(BUILD_RTI)
|
||||||
+35
-35
@@ -13,8 +13,8 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
QIcon iconFromSvg(const QByteArray &svgData, QSize iconSize)
|
QIcon iconFromSvg(const QByteArray& svgData, QSize iconSize)
|
||||||
{
|
{
|
||||||
QSvgRenderer renderer(svgData);
|
QSvgRenderer renderer(svgData);
|
||||||
QPixmap p(iconSize);
|
QPixmap p(iconSize);
|
||||||
p.fill(Qt::transparent);
|
p.fill(Qt::transparent);
|
||||||
@@ -23,60 +23,60 @@ namespace LtsUtils
|
|||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
return {p};
|
return {p};
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon iconFromSvg(const QString &svgFilename, QSize iconSize)
|
QIcon iconFromSvg(const QString& svgFilename, QSize iconSize)
|
||||||
{
|
{
|
||||||
QFile f(svgFilename);
|
QFile f(svgFilename);
|
||||||
if (!f.open(QIODevice::ReadOnly))
|
if (!f.open(QIODevice::ReadOnly))
|
||||||
return {};
|
return {};
|
||||||
return iconFromSvg(f.readAll(), iconSize);
|
return iconFromSvg(f.readAll(), iconSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap pixmapFromIcon(const QIcon &icon, QSize iconSize)
|
QPixmap pixmapFromIcon(const QIcon& icon, QSize iconSize)
|
||||||
{
|
{
|
||||||
return icon.pixmap(iconSize).scaled(100, 100, Qt::AspectRatioMode::IgnoreAspectRatio);
|
return icon.pixmap(iconSize).scaled(100, 100, Qt::AspectRatioMode::IgnoreAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap pixmapFromSvg(const QString &svgFilename, QSize iconSize)
|
QPixmap pixmapFromSvg(const QString& svgFilename, QSize iconSize)
|
||||||
{
|
{
|
||||||
return pixmapFromIcon(iconFromSvg(svgFilename, iconSize), iconSize);
|
return pixmapFromIcon(iconFromSvg(svgFilename, iconSize), iconSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap getPixmap(const std::vector<uint8_t> &data)
|
QPixmap getPixmap(const std::vector<uint8_t>& data)
|
||||||
{
|
{
|
||||||
if (data.size() == 0)
|
if (data.size() == 0)
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
|
|
||||||
return getPixmap(QByteArray(reinterpret_cast<const char *>(&data.at(0)), data.size()));
|
return getPixmap(QByteArray(reinterpret_cast<const char*>(&data.at(0)), data.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap getPixmap(const QByteArray &data)
|
QPixmap getPixmap(const QByteArray& data)
|
||||||
{
|
{
|
||||||
return QPixmap::fromImage(QImage::fromData(data));
|
return QPixmap::fromImage(QImage::fromData(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage getImage(const std::vector<uint8_t> &data)
|
QImage getImage(const std::vector<uint8_t>& data)
|
||||||
{
|
{
|
||||||
if (data.size() == 0)
|
if (data.size() == 0)
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
return getImage(QByteArray(reinterpret_cast<const char *>(&data.at(0)), data.size()));
|
return getImage(QByteArray(reinterpret_cast<const char*>(&data.at(0)), data.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage getImage(const QByteArray &data)
|
QImage getImage(const QByteArray& data)
|
||||||
{
|
{
|
||||||
return QImage::fromData(data);
|
return QImage::fromData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void setIf(bool *boolPtr, bool val)
|
static inline void setIf(bool* boolPtr, bool val)
|
||||||
{
|
{
|
||||||
if (boolPtr)
|
if (boolPtr)
|
||||||
*boolPtr = val;
|
*boolPtr = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> fromPixmap(const QPixmap &pixmap, bool *bIsPng)
|
std::vector<uint8_t> fromPixmap(const QPixmap& pixmap, bool* bIsPng)
|
||||||
{
|
{
|
||||||
QBuffer buf;
|
QBuffer buf;
|
||||||
buf.open(QIODevice::WriteOnly);
|
buf.open(QIODevice::WriteOnly);
|
||||||
pixmap.save(&buf, "PNG");
|
pixmap.save(&buf, "PNG");
|
||||||
@@ -99,10 +99,10 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
return convert<std::vector<uint8_t>>(ba);
|
return convert<std::vector<uint8_t>>(ba);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> fromImage(const QImage &image, bool *bIsPng)
|
std::vector<uint8_t> fromImage(const QImage& image, bool* bIsPng)
|
||||||
{
|
{
|
||||||
QBuffer buf;
|
QBuffer buf;
|
||||||
buf.open(QIODevice::WriteOnly);
|
buf.open(QIODevice::WriteOnly);
|
||||||
image.save(&buf, "PNG");
|
image.save(&buf, "PNG");
|
||||||
@@ -124,6 +124,6 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
return convert<std::vector<uint8_t>>(ba);
|
return convert<std::vector<uint8_t>>(ba);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+10
-10
@@ -17,15 +17,15 @@ class QIcon;
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const std::vector<uint8_t> &data);
|
LTSUTILSCORE_EXPORT QPixmap getPixmap(const std::vector<uint8_t>& data);
|
||||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const QByteArray &data);
|
LTSUTILSCORE_EXPORT QPixmap getPixmap(const QByteArray& data);
|
||||||
LTSUTILSCORE_EXPORT QImage getImage(const std::vector<uint8_t> &data);
|
LTSUTILSCORE_EXPORT QImage getImage(const std::vector<uint8_t>& data);
|
||||||
LTSUTILSCORE_EXPORT QImage getImage(const QByteArray &data);
|
LTSUTILSCORE_EXPORT QImage getImage(const QByteArray& data);
|
||||||
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QByteArray &svgData, QSize iconSize = QSize(100, 100));
|
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QByteArray& svgData, QSize iconSize = QSize(100, 100));
|
||||||
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QString &svgFilename, QSize iconSize = QSize(100, 100));
|
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QString& svgFilename, QSize iconSize = QSize(100, 100));
|
||||||
LTSUTILSCORE_EXPORT QPixmap pixmapFromIcon(const QIcon &icon, QSize iconSize = QSize(100, 100));
|
LTSUTILSCORE_EXPORT QPixmap pixmapFromIcon(const QIcon& icon, QSize iconSize = QSize(100, 100));
|
||||||
LTSUTILSCORE_EXPORT QPixmap pixmapFromSvg(const QString &svgFilename, QSize iconSize = QSize(100, 100));
|
LTSUTILSCORE_EXPORT QPixmap pixmapFromSvg(const QString& svgFilename, QSize iconSize = QSize(100, 100));
|
||||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromPixmap(const QPixmap &pixmap, bool *bIsPng = nullptr);
|
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromPixmap(const QPixmap& pixmap, bool* bIsPng = nullptr);
|
||||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromImage(const QImage &image, bool *bIsPng = nullptr);
|
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromImage(const QImage& image, bool* bIsPng = nullptr);
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+59
-62
@@ -18,27 +18,20 @@
|
|||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
bool RequestHelper::s_debug = false;
|
bool RequestHelper::s_debug = false;
|
||||||
|
|
||||||
RequestHelper::RequestHelper(QObject *parent,
|
RequestHelper::RequestHelper(QObject* parent, bool quiet,
|
||||||
bool quiet,
|
|
||||||
|
|
||||||
const std::function<void(void)> &success,
|
const std::function<void(void)>& success, const std::function<void(void)>& failure)
|
||||||
const std::function<void(void)> &failure)
|
: QObject(parent), m_failed(false), m_repliedId(-1), m_quiet(quiet), m_blockingCall(true), m_successFn(success),
|
||||||
: QObject(parent)
|
m_failureFn(failure)
|
||||||
, m_failed(false)
|
{
|
||||||
, m_repliedId(-1)
|
|
||||||
, m_quiet(quiet)
|
|
||||||
, m_blockingCall(true)
|
|
||||||
, m_successFn(success)
|
|
||||||
, m_failureFn(failure)
|
|
||||||
{
|
|
||||||
connect(this, &RequestHelper::signalSuccess, this, m_successFn, Qt::QueuedConnection);
|
connect(this, &RequestHelper::signalSuccess, this, m_successFn, Qt::QueuedConnection);
|
||||||
connect(this, &RequestHelper::signalFailed, this, m_failureFn, Qt::QueuedConnection);
|
connect(this, &RequestHelper::signalFailed, this, m_failureFn, Qt::QueuedConnection);
|
||||||
|
|
||||||
if (s_debug)
|
if (s_debug)
|
||||||
{
|
{
|
||||||
QTimer *t = new QTimer(this);
|
QTimer* t = new QTimer(this);
|
||||||
t->setInterval(2000);
|
t->setInterval(2000);
|
||||||
t->setSingleShot(true);
|
t->setSingleShot(true);
|
||||||
connect(this, &RequestHelper::signalNextRequest, t, static_cast<void (QTimer::*)(void)>(&QTimer::start));
|
connect(this, &RequestHelper::signalNextRequest, t, static_cast<void (QTimer::*)(void)>(&QTimer::start));
|
||||||
@@ -50,27 +43,28 @@ namespace LtsUtils
|
|||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::addRequest(const std::function<int64_t()> &requestFunction, const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler)
|
void RequestHelper::addRequest(const std::function<int64_t()>& requestFunction,
|
||||||
{
|
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler)
|
||||||
|
{
|
||||||
m_requestFunctions.append(RequestFunctionContainer(requestFunction, baseReplyHandler));
|
m_requestFunctions.append(RequestFunctionContainer(requestFunction, baseReplyHandler));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestHelper::requestReply(const Core::FunctionReply &baseReply)
|
bool RequestHelper::requestReply(const Core::FunctionReply& baseReply)
|
||||||
{
|
{
|
||||||
// rtiddsgen 7.7 generates plain public members (no getters/setters)
|
// rtiddsgen 7.7 generates plain public members (no getters/setters)
|
||||||
const Core::FunctionReplyObject fro(baseReply.id, baseReply.errorString, baseReply.errorParams);
|
const Core::FunctionReplyObject fro(baseReply.id, baseReply.errorString, baseReply.errorParams);
|
||||||
return _requestReply(fro, &baseReply);
|
return _requestReply(fro, &baseReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestHelper::requestReply(const Core::FunctionReplyObject &replyObject)
|
bool RequestHelper::requestReply(const Core::FunctionReplyObject& replyObject)
|
||||||
{
|
{
|
||||||
return _requestReply(replyObject, nullptr);
|
return _requestReply(replyObject, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestHelper::_requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply)
|
bool RequestHelper::_requestReply(const Core::FunctionReplyObject& fro, const Core::FunctionReply* baseReply)
|
||||||
{
|
{
|
||||||
m_errorString = fro.translated();
|
m_errorString = fro.translated();
|
||||||
|
|
||||||
#ifdef REQUEST_HELPER_WITH_GUI
|
#ifdef REQUEST_HELPER_WITH_GUI
|
||||||
@@ -81,11 +75,13 @@ namespace LtsUtils
|
|||||||
{
|
{
|
||||||
if (m_blockingCall)
|
if (m_blockingCall)
|
||||||
{
|
{
|
||||||
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget *>(parent()), m_errorString, tr("Request failed"));
|
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget*>(parent()), m_errorString,
|
||||||
|
tr("Request failed"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget *>(parent()), m_errorString, tr("Request failed"));
|
new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget*>(parent()), m_errorString,
|
||||||
|
tr("Request failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +94,8 @@ namespace LtsUtils
|
|||||||
if (baseReply)
|
if (baseReply)
|
||||||
m_singleRequestCustomFunctionReply(*baseReply);
|
m_singleRequestCustomFunctionReply(*baseReply);
|
||||||
else
|
else
|
||||||
m_singleRequestCustomFunctionReply(Core::FunctionReply(fro.id(), fro.str(), fro.args(), fro.additionalInfo()));
|
m_singleRequestCustomFunctionReply(
|
||||||
|
Core::FunctionReply(fro.id(), fro.str(), fro.args(), fro.additionalInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fro.error())
|
if (fro.error())
|
||||||
@@ -109,24 +106,25 @@ namespace LtsUtils
|
|||||||
|
|
||||||
emit signalNextRequest();
|
emit signalNextRequest();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestHelper::startSingleRequest(const std::function<int64_t()> &requestFunction,
|
bool RequestHelper::startSingleRequest(
|
||||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler)
|
const std::function<int64_t()>& requestFunction,
|
||||||
{
|
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler)
|
||||||
|
{
|
||||||
addRequest(requestFunction, baseReplyHandler);
|
addRequest(requestFunction, baseReplyHandler);
|
||||||
return startRequests();
|
return startRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::failure()
|
void RequestHelper::failure()
|
||||||
{
|
{
|
||||||
m_failed = true;
|
m_failed = true;
|
||||||
emit signalFailed();
|
emit signalFailed();
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::done()
|
void RequestHelper::done()
|
||||||
{
|
{
|
||||||
#ifdef REQUEST_HELPER_WITH_GUI
|
#ifdef REQUEST_HELPER_WITH_GUI
|
||||||
if (!m_quiet)
|
if (!m_quiet)
|
||||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
|
||||||
@@ -142,10 +140,10 @@ namespace LtsUtils
|
|||||||
|
|
||||||
if (!m_blockingCall)
|
if (!m_blockingCall)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::slotNextRequest()
|
void RequestHelper::slotNextRequest()
|
||||||
{
|
{
|
||||||
if (m_requestFunctions.isEmpty())
|
if (m_requestFunctions.isEmpty())
|
||||||
{
|
{
|
||||||
if (!m_blockingCall)
|
if (!m_blockingCall)
|
||||||
@@ -168,14 +166,12 @@ namespace LtsUtils
|
|||||||
{
|
{
|
||||||
if (m_blockingCall)
|
if (m_blockingCall)
|
||||||
{
|
{
|
||||||
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget *>(parent()), tr("Request failed"));
|
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget*>(parent()), tr("Request failed"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connect(new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget *>(parent()), tr("Request failed")),
|
connect(new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget*>(parent()), tr("Request failed")),
|
||||||
&LtsWidgets::LtsMessageDialogNew::destroyed,
|
&LtsWidgets::LtsMessageDialogNew::destroyed, this, [this]() { failure(); });
|
||||||
this,
|
|
||||||
[this]() { failure(); });
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -183,28 +179,29 @@ namespace LtsUtils
|
|||||||
#endif
|
#endif
|
||||||
failure();
|
failure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::startSingleBackgroundRequest(const std::function<int64_t()> &requestFunction,
|
void RequestHelper::startSingleBackgroundRequest(
|
||||||
const std::function<void(const Core::FunctionReply &)> &baseReplyHandler)
|
const std::function<int64_t()>& requestFunction,
|
||||||
{
|
const std::function<void(const Core::FunctionReply&)>& baseReplyHandler)
|
||||||
|
{
|
||||||
m_blockingCall = false;
|
m_blockingCall = false;
|
||||||
startSingleRequest(requestFunction, baseReplyHandler);
|
startSingleRequest(requestFunction, baseReplyHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::startBackgroundRequests()
|
void RequestHelper::startBackgroundRequests()
|
||||||
{
|
{
|
||||||
m_blockingCall = false;
|
m_blockingCall = false;
|
||||||
startRequests();
|
startRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHelper::setCustomWaitMessage(const QString &customWaitMessage)
|
void RequestHelper::setCustomWaitMessage(const QString& customWaitMessage)
|
||||||
{
|
{
|
||||||
m_customWaitMessage = (customWaitMessage + QStringLiteral(" ..."));
|
m_customWaitMessage = (customWaitMessage + QStringLiteral(" ..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestHelper::startRequests()
|
bool RequestHelper::startRequests()
|
||||||
{
|
{
|
||||||
if (m_requestFunctions.isEmpty())
|
if (m_requestFunctions.isEmpty())
|
||||||
{
|
{
|
||||||
#ifdef LTS_DEBUG
|
#ifdef LTS_DEBUG
|
||||||
@@ -226,7 +223,7 @@ namespace LtsUtils
|
|||||||
|
|
||||||
if (s_debug)
|
if (s_debug)
|
||||||
{
|
{
|
||||||
QTimer *t = new QTimer(this);
|
QTimer* t = new QTimer(this);
|
||||||
t->setInterval(2000);
|
t->setInterval(2000);
|
||||||
connect(t, &QTimer::timeout, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection);
|
connect(t, &QTimer::timeout, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection);
|
||||||
connect(t, &QTimer::timeout, t, &QTimer::deleteLater);
|
connect(t, &QTimer::timeout, t, &QTimer::deleteLater);
|
||||||
@@ -245,6 +242,6 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (!m_failed);
|
return (!m_failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
+24
-23
@@ -27,41 +27,41 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T> dds::core::optional<T> toOptional(T inVal)
|
template<typename T>
|
||||||
{
|
dds::core::optional<T> toOptional(T inVal)
|
||||||
|
{
|
||||||
return inVal != T() ? dds::core::optional<T>(inVal) : dds::core::optional<T>();
|
return inVal != T() ? dds::core::optional<T>(inVal) : dds::core::optional<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> dds::core::optional<T> optional()
|
template<typename T>
|
||||||
{
|
dds::core::optional<T> optional()
|
||||||
|
{
|
||||||
return dds::core::optional<T>();
|
return dds::core::optional<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject // TODO: DOC !!!
|
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject // TODO: DOC !!!
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool s_debug;
|
static bool s_debug;
|
||||||
|
|
||||||
explicit RequestHelper(
|
explicit RequestHelper(QObject *parent = nullptr, bool quiet = false,
|
||||||
QObject *parent = nullptr,
|
|
||||||
bool quiet = false,
|
|
||||||
// for non-blocking
|
// for non-blocking
|
||||||
const std::function<void(void)> &success = []() {},
|
const std::function<void (void)> &success = [](){},
|
||||||
const std::function<void(void)> &failure = []() {});
|
const std::function<void (void)> &failure = [](){});
|
||||||
~RequestHelper() = default;
|
~RequestHelper() = default;
|
||||||
|
|
||||||
bool quiet() const { return m_quiet; }
|
bool quiet() const { return m_quiet; }
|
||||||
void setQuiet(bool quiet) { m_quiet = quiet; }
|
void setQuiet(bool quiet) { m_quiet = quiet; }
|
||||||
void addRequest(const std::function<int64_t()> &requestFunction, const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
|
void addRequest(const std::function<int64_t()> &requestFunction,
|
||||||
|
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
|
||||||
bool startRequests(); // blocks!
|
bool startRequests(); // blocks!
|
||||||
|
|
||||||
// do not throw a message if this method fails, as this method does this already // blocks!
|
// do not throw a message if this method fails, as this method does this already // blocks!
|
||||||
bool startSingleRequest(const std::function<int64_t(void)> &requestFunction,
|
bool startSingleRequest(const std::function<int64_t(void)> &requestFunction,
|
||||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler =
|
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr // for replies that return a custom FunctionReply, which has to be handled >>after successful execution<<
|
||||||
nullptr // for replies that return a custom FunctionReply, which has to be handled >>after successful execution<<
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// non-blocking !
|
// non-blocking !
|
||||||
@@ -109,7 +109,7 @@ namespace LtsUtils
|
|||||||
bool failed() const { return m_failed; }
|
bool failed() const { return m_failed; }
|
||||||
void failure();
|
void failure();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const Core::FunctionReply &)>>;
|
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const Core::FunctionReply &)>>;
|
||||||
|
|
||||||
QVector<RequestFunctionContainer> m_requestFunctions;
|
QVector<RequestFunctionContainer> m_requestFunctions;
|
||||||
@@ -118,22 +118,23 @@ namespace LtsUtils
|
|||||||
std::function<void(const Core::FunctionReply &)> m_singleRequestCustomFunctionReply;
|
std::function<void(const Core::FunctionReply &)> m_singleRequestCustomFunctionReply;
|
||||||
bool m_quiet;
|
bool m_quiet;
|
||||||
bool m_blockingCall;
|
bool m_blockingCall;
|
||||||
std::function<void(void)> m_successFn;
|
std::function<void (void)> m_successFn;
|
||||||
std::function<void(void)> m_failureFn;
|
std::function<void (void)> m_failureFn;
|
||||||
QString m_errorString;
|
QString m_errorString;
|
||||||
QString m_customWaitMessage;
|
QString m_customWaitMessage;
|
||||||
|
|
||||||
void done();
|
void done();
|
||||||
bool _requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply);
|
bool _requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalNextRequest();
|
void signalNextRequest();
|
||||||
void signalQuitLoop();
|
void signalQuitLoop();
|
||||||
void signalSuccess();
|
void signalSuccess();
|
||||||
void signalFailed();
|
void signalFailed();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotNextRequest();
|
void slotNextRequest();
|
||||||
};
|
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -16,17 +16,16 @@
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class SettingType
|
enum class SettingType {
|
||||||
{
|
|
||||||
String = 1,
|
String = 1,
|
||||||
StringList = 2,
|
StringList = 2,
|
||||||
Json = 3,
|
Json = 3,
|
||||||
FunctionKeys = 4,
|
FunctionKeys = 4,
|
||||||
Boolean = 5,
|
Boolean = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
QString typeToString(SettingType t)
|
QString typeToString(SettingType t)
|
||||||
{
|
{
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case SettingType::String:
|
case SettingType::String:
|
||||||
@@ -42,10 +41,10 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return QStringLiteral("Unknown SettingType (%1)").arg(int(t));
|
return QStringLiteral("Unknown SettingType (%1)").arg(int(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingType stringToType(const QString &s)
|
SettingType stringToType(const QString& s)
|
||||||
{
|
{
|
||||||
if (s == typeToString(SettingType::String))
|
if (s == typeToString(SettingType::String))
|
||||||
return SettingType::String;
|
return SettingType::String;
|
||||||
if (s == typeToString(SettingType::StringList))
|
if (s == typeToString(SettingType::StringList))
|
||||||
@@ -58,51 +57,51 @@ namespace LtsUtils
|
|||||||
return SettingType::Boolean;
|
return SettingType::Boolean;
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return SettingType::String;
|
return SettingType::String;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString craftKey(const QString &group, const QString &identifier)
|
static QString craftKey(const QString& group, const QString& identifier)
|
||||||
{
|
{
|
||||||
return group + QLatin1Char('.') + identifier;
|
return group + QLatin1Char('.') + identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static OperatorSettings *s_operatorSettings = nullptr;
|
static OperatorSettings* s_operatorSettings = nullptr;
|
||||||
|
|
||||||
static void cleanupOperatorSettings()
|
static void cleanupOperatorSettings()
|
||||||
{
|
{
|
||||||
delete s_operatorSettings;
|
delete s_operatorSettings;
|
||||||
s_operatorSettings = nullptr;
|
s_operatorSettings = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
OperatorSettings *OperatorSettings::getInstance()
|
OperatorSettings* OperatorSettings::getInstance()
|
||||||
{
|
{
|
||||||
if (!s_operatorSettings)
|
if (!s_operatorSettings)
|
||||||
{
|
{
|
||||||
s_operatorSettings = new OperatorSettings;
|
s_operatorSettings = new OperatorSettings;
|
||||||
qAddPostRoutine(&cleanupOperatorSettings);
|
qAddPostRoutine(&cleanupOperatorSettings);
|
||||||
}
|
}
|
||||||
return s_operatorSettings;
|
return s_operatorSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ProjectSettings *s_projectSettings = nullptr;
|
static ProjectSettings* s_projectSettings = nullptr;
|
||||||
|
|
||||||
static void cleanupProjectSettings()
|
static void cleanupProjectSettings()
|
||||||
{
|
{
|
||||||
delete s_projectSettings;
|
delete s_projectSettings;
|
||||||
s_projectSettings = nullptr;
|
s_projectSettings = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectSettings *ProjectSettings::getInstance()
|
ProjectSettings* ProjectSettings::getInstance()
|
||||||
{
|
{
|
||||||
if (!s_projectSettings)
|
if (!s_projectSettings)
|
||||||
{
|
{
|
||||||
s_projectSettings = new ProjectSettings;
|
s_projectSettings = new ProjectSettings;
|
||||||
qAddPostRoutine(&cleanupProjectSettings);
|
qAddPostRoutine(&cleanupProjectSettings);
|
||||||
}
|
}
|
||||||
return s_projectSettings;
|
return s_projectSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectSettings::initFromFile(const QString &filename)
|
bool ProjectSettings::initFromFile(const QString& filename)
|
||||||
{
|
{
|
||||||
QFile f(filename);
|
QFile f(filename);
|
||||||
if (!f.open(QIODevice::ReadOnly))
|
if (!f.open(QIODevice::ReadOnly))
|
||||||
return false;
|
return false;
|
||||||
@@ -117,12 +116,12 @@ namespace LtsUtils
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
QHash<QString, QVariant> newData;
|
QHash<QString, QVariant> newData;
|
||||||
const QStringList &groupKeys(psObj.keys());
|
const QStringList& groupKeys(psObj.keys());
|
||||||
for (const auto &gKey : groupKeys)
|
for (const auto& gKey : groupKeys)
|
||||||
{
|
{
|
||||||
const QJsonObject objGroup(psObj[gKey].toObject());
|
const QJsonObject objGroup(psObj[gKey].toObject());
|
||||||
const QStringList &itemKeys(objGroup.keys());
|
const QStringList& itemKeys(objGroup.keys());
|
||||||
for (const auto &key : itemKeys)
|
for (const auto& key : itemKeys)
|
||||||
{
|
{
|
||||||
const QJsonObject obj(objGroup[key].toObject());
|
const QJsonObject obj(objGroup[key].toObject());
|
||||||
const auto strType(obj[QStringLiteral("Type")].toString());
|
const auto strType(obj[QStringLiteral("Type")].toString());
|
||||||
@@ -134,12 +133,11 @@ namespace LtsUtils
|
|||||||
case SettingType::Json:
|
case SettingType::Json:
|
||||||
val = QJsonDocument(jVal.toObject()).toJson();
|
val = QJsonDocument(jVal.toObject()).toJson();
|
||||||
break;
|
break;
|
||||||
case SettingType::StringList:
|
case SettingType::StringList: {
|
||||||
{
|
|
||||||
const QJsonArray arr(jVal.toArray());
|
const QJsonArray arr(jVal.toArray());
|
||||||
QStringList sl;
|
QStringList sl;
|
||||||
sl.reserve(arr.size());
|
sl.reserve(arr.size());
|
||||||
for (const auto &ele : arr)
|
for (const auto& ele : arr)
|
||||||
sl.push_back(ele.toString());
|
sl.push_back(ele.toString());
|
||||||
val = sl;
|
val = sl;
|
||||||
break;
|
break;
|
||||||
@@ -159,17 +157,18 @@ namespace LtsUtils
|
|||||||
}
|
}
|
||||||
getInstance()->m_data = newData;
|
getInstance()->m_data = newData;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectSettings::isFunctionEnabled(const QString &group, const QString &function)
|
bool ProjectSettings::isFunctionEnabled(const QString& group, const QString& function)
|
||||||
{
|
{
|
||||||
const QStringList functionNames = getInstance()->value(QStringLiteral("Functionalities"), QStringLiteral("IdentifierList")).toStringList();
|
const QStringList functionNames =
|
||||||
|
getInstance()->value(QStringLiteral("Functionalities"), QStringLiteral("IdentifierList")).toStringList();
|
||||||
|
|
||||||
return functionNames.contains(group + QLatin1Char(':') + function);
|
return functionNames.contains(group + QLatin1Char(':') + function);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::init(const QByteArray &settings)
|
void Settings::init(const QByteArray& settings)
|
||||||
{
|
{
|
||||||
QByteArray uncompressed;
|
QByteArray uncompressed;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -184,10 +183,10 @@ namespace LtsUtils
|
|||||||
|
|
||||||
QDataStream stream(uncompressed);
|
QDataStream stream(uncompressed);
|
||||||
stream >> m_data;
|
stream >> m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray Settings::exportSettings() const
|
QByteArray Settings::exportSettings() const
|
||||||
{
|
{
|
||||||
if (m_data.isEmpty())
|
if (m_data.isEmpty())
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|
||||||
@@ -195,15 +194,15 @@ namespace LtsUtils
|
|||||||
QDataStream stream(&ba, QIODevice::WriteOnly);
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
||||||
stream << m_data;
|
stream << m_data;
|
||||||
return qCompress(ba);
|
return qCompress(ba);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::clear()
|
void Settings::clear()
|
||||||
{
|
{
|
||||||
m_data.clear();
|
m_data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::dump()
|
void Settings::dump()
|
||||||
{
|
{
|
||||||
qWarning() << "Settings::m_data: keys=" << m_data.keys();
|
qWarning() << "Settings::m_data: keys=" << m_data.keys();
|
||||||
QHashIterator<QString, QVariant> it(m_data);
|
QHashIterator<QString, QVariant> it(m_data);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -214,23 +213,23 @@ namespace LtsUtils
|
|||||||
<< " - key='" << it.key() << "' value -> '" << it.value() << "'";
|
<< " - key='" << it.key() << "' value -> '" << it.value() << "'";
|
||||||
}
|
}
|
||||||
qWarning() << "Settings::m_data: ------------------";
|
qWarning() << "Settings::m_data: ------------------";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::setValue(const QString &group, const QString &identifier, const QVariant &value)
|
void Settings::setValue(const QString& group, const QString& identifier, const QVariant& value)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_data.insert(craftKey(group, identifier), value);
|
m_data.insert(craftKey(group, identifier), value);
|
||||||
emit valueChanged(group, identifier, value);
|
emit valueChanged(group, identifier, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::removeValue(const QString &group, const QString &identifier)
|
void Settings::removeValue(const QString& group, const QString& identifier)
|
||||||
{
|
{
|
||||||
if (m_data.remove(craftKey(group, identifier)))
|
if (m_data.remove(craftKey(group, identifier)))
|
||||||
emit valueRemoved(group, identifier);
|
emit valueRemoved(group, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Settings::identifiers(const QString &group) const
|
QStringList Settings::identifiers(const QString& group) const
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for (auto it = m_data.begin(); it != m_data.end(); ++it)
|
for (auto it = m_data.begin(); it != m_data.end(); ++it)
|
||||||
{
|
{
|
||||||
@@ -239,11 +238,11 @@ namespace LtsUtils
|
|||||||
result.append(decrafted.at(0).mid(1));
|
result.append(decrafted.at(0).mid(1));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Settings::value(const QString &group, const QString &identifier, const QVariant &defaultValue) const
|
QVariant Settings::value(const QString& group, const QString& identifier, const QVariant& defaultValue) const
|
||||||
{
|
{
|
||||||
return m_data.value(craftKey(group, identifier), defaultValue);
|
return m_data.value(craftKey(group, identifier), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -12,22 +12,22 @@ class QJsonObject;
|
|||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
class LTSUTILSSETTINGS_EXPORT Settings : public QObject
|
class LTSUTILSSETTINGS_EXPORT Settings : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~Settings() = default;
|
~Settings() = default;
|
||||||
|
|
||||||
void setValue(const QString &group, const QString &identifier, const QVariant &value);
|
void setValue(const QString& group, const QString& identifier, const QVariant& value);
|
||||||
|
|
||||||
void removeValue(const QString &group, const QString &identifier);
|
void removeValue(const QString& group, const QString& identifier);
|
||||||
|
|
||||||
QVariant value(const QString &group, const QString &identifier, const QVariant &defaultValue = QVariant()) const;
|
QVariant value(const QString& group, const QString& identifier, const QVariant& defaultValue = QVariant()) const;
|
||||||
|
|
||||||
QStringList identifiers(const QString &group) const;
|
QStringList identifiers(const QString& group) const;
|
||||||
|
|
||||||
void init(const QByteArray &settings);
|
void init(const QByteArray& settings);
|
||||||
QByteArray exportSettings() const;
|
QByteArray exportSettings() const;
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
@@ -37,28 +37,28 @@ namespace LtsUtils
|
|||||||
Settings() = default;
|
Settings() = default;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void valueChanged(const QString &group, const QString &identifier, const QVariant &value);
|
void valueChanged(const QString& group, const QString& identifier, const QVariant& value);
|
||||||
void valueRemoved(const QString &group, const QString &identifier);
|
void valueRemoved(const QString& group, const QString& identifier);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<QString, QVariant> m_data;
|
QHash<QString, QVariant> m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LTSUTILSSETTINGS_EXPORT OperatorSettings : public Settings
|
class LTSUTILSSETTINGS_EXPORT OperatorSettings : public Settings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static OperatorSettings *getInstance();
|
static OperatorSettings* getInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
class LTSUTILSSETTINGS_EXPORT ProjectSettings : public Settings
|
class LTSUTILSSETTINGS_EXPORT ProjectSettings : public Settings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static ProjectSettings *getInstance();
|
static ProjectSettings* getInstance();
|
||||||
|
|
||||||
static bool initFromFile(const QString &filename);
|
static bool initFromFile(const QString& filename);
|
||||||
static bool isFunctionEnabled(const QString &group, const QString &function);
|
static bool isFunctionEnabled(const QString& group, const QString& function);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LtsUtils
|
} // namespace LtsUtils
|
||||||
@@ -180,11 +180,6 @@ NGL_INSTALL_TARGET(LtsWidgets)
|
|||||||
#
|
#
|
||||||
# Designer-Plugin
|
# Designer-Plugin
|
||||||
#
|
#
|
||||||
# Qt Designer development plugin (COMPONENT Devel), not part of the Release 2
|
|
||||||
# build closure: it links modules pruned from the tree (LtsDataView,
|
|
||||||
# LtsReportDisplay, LtsFileDialog, svcFlmCommon — prune commit 7fc6f6664), so
|
|
||||||
# it is only defined when those modules are present.
|
|
||||||
IF(EXISTS "${CMAKE_SOURCE_DIR}/Lts/Viewer/LtsDataView")
|
|
||||||
SET(ltswidgetsplugin_SRCS ltswidgetsplugin.cpp ltswidgetsplugin.json)
|
SET(ltswidgetsplugin_SRCS ltswidgetsplugin.cpp ltswidgetsplugin.json)
|
||||||
NGL_ADD_LIBRARY(WS ltswidgetsplugin MODULE ${ltswidgetsplugin_SRCS})
|
NGL_ADD_LIBRARY(WS ltswidgetsplugin MODULE ${ltswidgetsplugin_SRCS})
|
||||||
NGL_TARGET_LINK_LIBRARIES(ltswidgetsplugin LtsWidgets ltsCoordWidget LtsDataView LtsFileDialog LtsReportDisplay svcFlmCommon)
|
NGL_TARGET_LINK_LIBRARIES(ltswidgetsplugin LtsWidgets ltsCoordWidget LtsDataView LtsFileDialog LtsReportDisplay svcFlmCommon)
|
||||||
@@ -197,7 +192,6 @@ if(DEFINED QT6_INC_DIR AND EXISTS "${QT6_INC_DIR}/QtPrintSupport")
|
|||||||
endif()
|
endif()
|
||||||
NGL_SET_TARGET_PROPERTIES(ltswidgetsplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/designer)
|
NGL_SET_TARGET_PROPERTIES(ltswidgetsplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/designer)
|
||||||
NGL_INSTALL_TARGET(ltswidgetsplugin DESTINATION lib/designer COMPONENT Devel)
|
NGL_INSTALL_TARGET(ltswidgetsplugin DESTINATION lib/designer COMPONENT Devel)
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
IF(BUILD_TESTING)
|
IF(BUILD_TESTING)
|
||||||
# picture_editing_test
|
# picture_editing_test
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ TARGET_INCLUDE_DIRECTORIES(RecordReplayPlugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
|||||||
TARGET_LINK_LIBRARIES(RecordReplayPlugin PUBLIC Qt6::Core)
|
TARGET_LINK_LIBRARIES(RecordReplayPlugin PUBLIC Qt6::Core)
|
||||||
|
|
||||||
# Topic Replay Interface
|
# Topic Replay Interface
|
||||||
#
|
|
||||||
# Links TopicEditorBase, which was pruned from the tree (prune commit
|
|
||||||
# 7fc6f6664), so the target is only defined when the module is present.
|
|
||||||
IF(EXISTS "${CMAKE_SOURCE_DIR}/Lts/Common/TopicEditorBase")
|
|
||||||
ADD_LIBRARY(TopicReplayInterface SHARED
|
ADD_LIBRARY(TopicReplayInterface SHARED
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/topic_replay_interface.h
|
${CMAKE_CURRENT_SOURCE_DIR}/topic_replay_interface.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/topic_replay_interface.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/topic_replay_interface.cpp
|
||||||
@@ -60,7 +56,6 @@ TARGET_INCLUDE_DIRECTORIES(TopicReplayInterface PUBLIC
|
|||||||
${CMAKE_BINARY_DIR}/Lts/Common/TopicEditorBase # topiceditorbase_export.h
|
${CMAKE_BINARY_DIR}/Lts/Common/TopicEditorBase # topiceditorbase_export.h
|
||||||
)
|
)
|
||||||
TARGET_LINK_LIBRARIES(TopicReplayInterface PUBLIC Qt6::Core TopicEditorBase)
|
TARGET_LINK_LIBRARIES(TopicReplayInterface PUBLIC Qt6::Core TopicEditorBase)
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
# These interface base classes (e.g. DataPluginBase::Plugin) are Q_OBJECT classes. The top-level
|
# These interface base classes (e.g. DataPluginBase::Plugin) are Q_OBJECT classes. The top-level
|
||||||
# CMAKE_CXX_VISIBILITY_PRESET hidden compiles their Q_OBJECT meta symbols (staticMetaObject/vtable/
|
# CMAKE_CXX_VISIBILITY_PRESET hidden compiles their Q_OBJECT meta symbols (staticMetaObject/vtable/
|
||||||
@@ -75,15 +70,8 @@ set_target_properties(
|
|||||||
ProjectPluginInterface
|
ProjectPluginInterface
|
||||||
StylePluginInterface
|
StylePluginInterface
|
||||||
RecordReplayPlugin
|
RecordReplayPlugin
|
||||||
|
TopicReplayInterface
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
CXX_VISIBILITY_PRESET default
|
CXX_VISIBILITY_PRESET default
|
||||||
CXX_VISIBILITY_INLINES_HIDDEN OFF
|
CXX_VISIBILITY_INLINES_HIDDEN OFF
|
||||||
)
|
)
|
||||||
# TopicReplayInterface (pruned dependency, see above)
|
|
||||||
IF(TARGET TopicReplayInterface)
|
|
||||||
set_target_properties(TopicReplayInterface
|
|
||||||
PROPERTIES
|
|
||||||
CXX_VISIBILITY_PRESET default
|
|
||||||
CXX_VISIBILITY_INLINES_HIDDEN OFF
|
|
||||||
)
|
|
||||||
ENDIF()
|
|
||||||
+18
-11
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Interface for HMI plugins
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-02-29
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -8,25 +15,25 @@
|
|||||||
|
|
||||||
namespace NGL
|
namespace NGL
|
||||||
{
|
{
|
||||||
class INGLLogger;
|
class INGLLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace LtsSession
|
namespace LtsSession
|
||||||
{
|
{
|
||||||
class LtsSessionDataDds;
|
class LtsSessionDataDds;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace DataPluginBase
|
namespace DataPluginBase
|
||||||
{
|
{
|
||||||
|
|
||||||
class Interface
|
class Interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Interface() = default;
|
virtual ~Interface() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Plugin : public QObject
|
class Plugin : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -34,9 +41,9 @@ namespace DataPluginBase
|
|||||||
virtual ~Plugin() = default;
|
virtual ~Plugin() = default;
|
||||||
|
|
||||||
virtual QString pluginName() const = 0;
|
virtual QString pluginName() const = 0;
|
||||||
virtual std::shared_ptr<Interface> createDataInterface(LtsSession::LtsSessionDataDds *session) = 0;
|
virtual std::shared_ptr<Interface> createDataInterface(LtsSession::LtsSessionDataDds* session) = 0;
|
||||||
virtual bool availableInPartition(IDL::PartitionType partition) const = 0;
|
virtual bool availableInPartition(IDL::PartitionType partition) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace DataPluginBase
|
} // namespace DataPluginBase
|
||||||
|
|
||||||
|
|||||||
+13
-5
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Interface for Project Plugins (Resources)
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Mike Wille, SLSE, 2016-10-10
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -7,13 +15,13 @@
|
|||||||
namespace ProjectPlugin
|
namespace ProjectPlugin
|
||||||
{
|
{
|
||||||
|
|
||||||
class Plugin
|
class Plugin
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Plugin() = default;
|
virtual ~Plugin() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectPlugin
|
} // namespace ProjectPlugin
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Provide Record/Replay functionality for dds topics in a service
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Christian Ehrlicher, SLSE, 2016-07-07
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -10,15 +17,15 @@
|
|||||||
|
|
||||||
namespace DDSConnector
|
namespace DDSConnector
|
||||||
{
|
{
|
||||||
class DdsConnector;
|
class DdsConnector;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NSqlQuery;
|
class NSqlQuery;
|
||||||
|
|
||||||
namespace RecordReplay
|
namespace RecordReplay
|
||||||
{
|
{
|
||||||
class RecordReplayPlugin
|
class RecordReplayPlugin
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -26,21 +33,22 @@ namespace RecordReplay
|
|||||||
|
|
||||||
virtual QString pluginName() const = 0;
|
virtual QString pluginName() const = 0;
|
||||||
|
|
||||||
virtual bool initDtc(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector, int exerciseId) = 0;
|
virtual bool initDtc(const std::shared_ptr<DDSConnector::DdsConnector>& ddsConnector, int exerciseId) = 0;
|
||||||
|
|
||||||
virtual bool initDts(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector, int exerciseId, bool bCanHandleSchemas, NSqlQuery &query) = 0;
|
virtual bool initDts(const std::shared_ptr<DDSConnector::DdsConnector>& ddsConnector, int exerciseId,
|
||||||
|
bool bCanHandleSchemas, NSqlQuery& query) = 0;
|
||||||
|
|
||||||
virtual bool initCopy(int exerciseId, bool bCanHandleSchemasRead, bool bCanHandleSchemasWrite) = 0;
|
virtual bool initCopy(int exerciseId, bool bCanHandleSchemasRead, bool bCanHandleSchemasWrite) = 0;
|
||||||
|
|
||||||
virtual bool copyData(NSqlQuery &queryFrom, NSqlQuery &queryTo, qint64 fromTime, qint64 toTime) = 0;
|
virtual bool copyData(NSqlQuery& queryFrom, NSqlQuery& queryTo, qint64 fromTime, qint64 toTime) = 0;
|
||||||
|
|
||||||
virtual QString svcShortName() const = 0;
|
virtual QString svcShortName() const = 0;
|
||||||
|
|
||||||
virtual bool ddsTopicsToDatabase(NSqlQuery &query, QHash<QString, qint64> &minRecordSampleTimes) = 0;
|
virtual bool ddsTopicsToDatabase(NSqlQuery& query, QHash<QString, qint64>& minRecordSampleTimes) = 0;
|
||||||
|
|
||||||
virtual bool setReplayStartTime(NSqlQuery &query, qint64 startTime) = 0;
|
virtual bool setReplayStartTime(NSqlQuery& query, qint64 startTime) = 0;
|
||||||
|
|
||||||
virtual bool ddsTopicsFromDatabase(NSqlQuery &query, qint64 fromTime, qint64 toTime) = 0;
|
virtual bool ddsTopicsFromDatabase(NSqlQuery& query, qint64 fromTime, qint64 toTime) = 0;
|
||||||
|
|
||||||
virtual bool publishData(qint64 desiredTime) = 0;
|
virtual bool publishData(qint64 desiredTime) = 0;
|
||||||
|
|
||||||
@@ -58,24 +66,22 @@ namespace RecordReplay
|
|||||||
std::map<int64_t, int64_t> recIdArray;
|
std::map<int64_t, int64_t> recIdArray;
|
||||||
RecSnapshot() = default;
|
RecSnapshot() = default;
|
||||||
|
|
||||||
RecSnapshot(qint64 timeStamp_, const std::map<int64_t, int64_t> &recIdArray_)
|
RecSnapshot(qint64 timeStamp_, const std::map<int64_t, int64_t>& recIdArray_)
|
||||||
: timeStamp(timeStamp_)
|
: timeStamp(timeStamp_), recIdArray(recIdArray_)
|
||||||
, recIdArray(recIdArray_)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual std::map<QString, std::vector<RecSnapshot>> getSnapshotTimes(NSqlQuery &query,
|
virtual std::map<QString, std::vector<RecSnapshot>>
|
||||||
qint64 toTime,
|
getSnapshotTimes(NSqlQuery& query, qint64 toTime, qint64 interval,
|
||||||
qint64 interval,
|
const QHash<QString, qint64>& minRecordedSampleTimes) = 0;
|
||||||
const QHash<QString, qint64> &minRecordedSampleTimes) = 0;
|
|
||||||
|
|
||||||
virtual QVector<QString> getRecordTopicNames() const = 0;
|
virtual QVector<QString> getRecordTopicNames() const = 0;
|
||||||
|
|
||||||
virtual QVector<QString> getRecordTableNames() const = 0;
|
virtual QVector<QString> getRecordTableNames() const = 0;
|
||||||
|
|
||||||
virtual qint64 getMinimumSampleTime(NSqlQuery &q, const QString &topicName, qint64 defaultValue) const = 0;
|
virtual qint64 getMinimumSampleTime(NSqlQuery& q, const QString& topicName, qint64 defaultValue) const = 0;
|
||||||
};
|
};
|
||||||
} // namespace RecordReplay
|
} // namespace RecordReplay
|
||||||
|
|
||||||
Q_DECLARE_INTERFACE(RecordReplay::RecordReplayPlugin, "special:3:recordreplay")
|
Q_DECLARE_INTERFACE(RecordReplay::RecordReplayPlugin, "special:3:recordreplay")
|
||||||
+12
-4
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Interface for Style Plugins (Resources & Stylesheets)
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Mike Wille, SLSE, 2016-10-14
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -6,8 +14,8 @@
|
|||||||
|
|
||||||
namespace StylePlugin
|
namespace StylePlugin
|
||||||
{
|
{
|
||||||
class Plugin
|
class Plugin
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -15,7 +23,7 @@ namespace StylePlugin
|
|||||||
|
|
||||||
virtual void loadStyle(bool highDpi) = 0;
|
virtual void loadStyle(bool highDpi) = 0;
|
||||||
virtual void unloadStyle() = 0;
|
virtual void unloadStyle() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace StylePlugin
|
} // namespace StylePlugin
|
||||||
|
|
||||||
|
|||||||
+45
-19
@@ -1,4 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Interface for Script Editor Playback Controls
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*
|
||||||
|
* Created by Mike Wille, SLSE, 2017-04-19
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -10,17 +18,20 @@ class QWidget;
|
|||||||
|
|
||||||
namespace TopicEditorBase
|
namespace TopicEditorBase
|
||||||
{
|
{
|
||||||
class ExportNotifier;
|
class ExportNotifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace TopicReplay
|
namespace TopicReplay
|
||||||
{
|
{
|
||||||
|
|
||||||
class Interface
|
class Interface
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QJsonObject timeRange(qint64 start, qint64 end) { return {{QStringLiteral("start"), start}, {QStringLiteral("end"), end}}; }
|
static QJsonObject timeRange(qint64 start, qint64 end)
|
||||||
|
{
|
||||||
|
return {{QStringLiteral("start"), start}, {QStringLiteral("end"), end}};
|
||||||
|
}
|
||||||
|
|
||||||
struct SituationReplayTime
|
struct SituationReplayTime
|
||||||
{
|
{
|
||||||
@@ -60,9 +71,12 @@ namespace TopicReplay
|
|||||||
Interface() = default;
|
Interface() = default;
|
||||||
virtual ~Interface() = default;
|
virtual ~Interface() = default;
|
||||||
|
|
||||||
virtual QWidget *createWidget() { return nullptr; }
|
virtual QWidget* createWidget()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool playbackInit(const QJsonObject &attributes)
|
virtual bool playbackInit(const QJsonObject& attributes)
|
||||||
{
|
{
|
||||||
Q_UNUSED(attributes);
|
Q_UNUSED(attributes);
|
||||||
return true;
|
return true;
|
||||||
@@ -74,40 +88,52 @@ namespace TopicReplay
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool playbackPause() { return true; }
|
virtual bool playbackPause()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool playbackStop() { return true; }
|
virtual bool playbackStop()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void setExportPlaybackTimes(qint64 startTimeSec, qint64 durationSec, const QVector<SituationReplayTime> &sitReplayTimes)
|
virtual void setExportPlaybackTimes(qint64 startTimeSec, qint64 durationSec,
|
||||||
|
const QVector<SituationReplayTime>& sitReplayTimes)
|
||||||
{
|
{
|
||||||
Q_UNUSED(startTimeSec);
|
Q_UNUSED(startTimeSec);
|
||||||
Q_UNUSED(durationSec);
|
Q_UNUSED(durationSec);
|
||||||
Q_UNUSED(sitReplayTimes);
|
Q_UNUSED(sitReplayTimes);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool exportTopic(const QJsonObject &attributes, const QString &strFolderPath, TopicEditorBase::ExportNotifier *pExportNotifier) = 0;
|
virtual bool exportTopic(const QJsonObject& attributes, const QString& strFolderPath,
|
||||||
|
TopicEditorBase::ExportNotifier* pExportNotifier) = 0;
|
||||||
|
|
||||||
virtual QVector<TopicEditorBase::TopicData> additionalTrackEntries(const QJsonObject &attributes) const
|
virtual QVector<TopicEditorBase::TopicData> additionalTrackEntries(const QJsonObject& attributes) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(attributes);
|
Q_UNUSED(attributes);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual QVector<TopicEditorBase::TopicData> additionalTrackEntries(const QJsonObject &attributes, bool &keepOriginalTopic) const
|
virtual QVector<TopicEditorBase::TopicData> additionalTrackEntries(const QJsonObject& attributes,
|
||||||
|
bool& keepOriginalTopic) const
|
||||||
{
|
{
|
||||||
keepOriginalTopic = true;
|
keepOriginalTopic = true;
|
||||||
return additionalTrackEntries(attributes);
|
return additionalTrackEntries(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setBasePath(const QString &basePath) { Q_UNUSED(basePath); }
|
virtual void setBasePath(const QString& basePath)
|
||||||
};
|
|
||||||
|
|
||||||
class Factory
|
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(basePath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Factory
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Factory() = default;
|
virtual ~Factory() = default;
|
||||||
virtual Interface *createInterface(TopicEditorBase::TopicType topicType) = 0;
|
virtual Interface* createInterface(TopicEditorBase::TopicType topicType) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TopicReplay
|
} // namespace TopicReplay
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Project Defines
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef LTS_COMMON_PROJECTCONFIG_PROJECT_DEFINES_H
|
#ifndef LTS_COMMON_PROJECTCONFIG_PROJECT_DEFINES_H
|
||||||
#define LTS_COMMON_PROJECTCONFIG_PROJECT_DEFINES_H
|
#define LTS_COMMON_PROJECTCONFIG_PROJECT_DEFINES_H
|
||||||
@@ -10,17 +16,16 @@
|
|||||||
|
|
||||||
namespace IDL
|
namespace IDL
|
||||||
{
|
{
|
||||||
enum class PartitionType
|
enum class PartitionType {
|
||||||
{
|
|
||||||
Any,
|
Any,
|
||||||
Global,
|
Global,
|
||||||
Exercise,
|
Exercise,
|
||||||
AllExercises,
|
AllExercises,
|
||||||
Replay,
|
Replay,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::string toStdString(PartitionType pt)
|
inline std::string toStdString(PartitionType pt)
|
||||||
{
|
{
|
||||||
switch (pt)
|
switch (pt)
|
||||||
{
|
{
|
||||||
case PartitionType::Any:
|
case PartitionType::Any:
|
||||||
@@ -35,10 +40,10 @@ namespace IDL
|
|||||||
return "Replay";
|
return "Replay";
|
||||||
}
|
}
|
||||||
return std::string("invalid:") + std::to_string(static_cast<int>(pt));
|
return std::string("invalid:") + std::to_string(static_cast<int>(pt));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &o, PartitionType pt)
|
inline std::ostream& operator<<(std::ostream& o, PartitionType pt)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (pt)
|
switch (pt)
|
||||||
{
|
{
|
||||||
@@ -51,21 +56,21 @@ namespace IDL
|
|||||||
default:
|
default:
|
||||||
return o << std::to_string(static_cast<int>(pt));
|
return o << std::to_string(static_cast<int>(pt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string exercisePartition(int exerciseId)
|
inline std::string exercisePartition(int exerciseId)
|
||||||
{
|
{
|
||||||
if (exerciseId < 0)
|
if (exerciseId < 0)
|
||||||
return {"ex_*"};
|
return {"ex_*"};
|
||||||
return std::string("ex_") + std::to_string(exerciseId);
|
return std::string("ex_") + std::to_string(exerciseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string replayPartition(int partitionId)
|
inline std::string replayPartition(int partitionId)
|
||||||
{
|
{
|
||||||
if (partitionId < 0)
|
if (partitionId < 0)
|
||||||
return {"srp_*"};
|
return {"srp_*"};
|
||||||
return std::string("srp_") + std::to_string(partitionId);
|
return std::string("srp_") + std::to_string(partitionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace IDL
|
} // namespace IDL
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* * GenericDataWriter (including GenericDataWriterBase)
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,6 @@ NGL_ADD_LIBRARY2(AAR SV HLA WS ddsQoS SHARED ${SRCS})
|
|||||||
NGL_TARGET_INCLUDE_DIRECTORIES(ddsQoS
|
NGL_TARGET_INCLUDE_DIRECTORIES(ddsQoS
|
||||||
INTERFACE
|
INTERFACE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
||||||
# Consumers (the generated *_topic_type_plugin.cpp) include
|
|
||||||
# DDS_DefaultQos.h -> ddsqos_export.h; the export header is generated
|
|
||||||
# into the binary dir, so export it the same way ddsfts exports its
|
|
||||||
# ddsfts_export.h. Without this every <svc>TopicTypePlugin target fails
|
|
||||||
# to compile ("ddsqos_export.h: No such file or directory").
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
)
|
||||||
NGL_TARGET_LINK_LIBRARIES(ddsQoS
|
NGL_TARGET_LINK_LIBRARIES(ddsQoS
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* Online Help Viewer Dialog
|
||||||
|
* $Id$
|
||||||
|
* $HeadURL$
|
||||||
|
* $Author$
|
||||||
|
* Created by Astrid Müller, SGAS, 2018-04-10
|
||||||
|
*/
|
||||||
|
|
||||||
#include "online_help_viewer_dialog.h"
|
#include "online_help_viewer_dialog.h"
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
INCLUDE(MacroRTIDDSGen)
|
||||||
|
INCLUDE(MacroCodeGenIdl)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(Plugins)
|
ADD_SUBDIRECTORY(Plugins)
|
||||||
|
|
||||||
SET(xml_FILE tab_service.xml)
|
SET(xml_FILE tab_service.xml)
|
||||||
@@ -33,9 +36,6 @@ SET(SRCS_telegrams
|
|||||||
training_area_telegrams.h
|
training_area_telegrams.h
|
||||||
)
|
)
|
||||||
NGL_ADD_LIBRARY(AAR SV WS HLA tabTelegrams STATIC ${SRCS_telegrams})
|
NGL_ADD_LIBRARY(AAR SV WS HLA tabTelegrams STATIC ${SRCS_telegrams})
|
||||||
|
|
||||||
# tabTelegrams is a STATIC lib linked into shared/MODULE targets
|
|
||||||
SET_TARGET_PROPERTIES(tabTelegrams PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
||||||
NGL_TARGET_INCLUDE_DIRECTORIES(tabTelegrams
|
NGL_TARGET_INCLUDE_DIRECTORIES(tabTelegrams
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||||
@@ -70,17 +70,34 @@ SET(SRCS_common
|
|||||||
tab_export.h
|
tab_export.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# Stub files (no RTI code generation in the release scope)
|
IF(BUILD_RTI)
|
||||||
LIST(APPEND SRCS_common
|
# Generate tab_enums.idl / tab.idl
|
||||||
|
CODEGEN_IDL_SVC(SRCS_common ${xml_FILE})
|
||||||
|
# Generate tab_db_impl.cpp/.h, tab_db.h
|
||||||
|
CODEGEN_DATABASE(SRCS_common ${xml_FILE})
|
||||||
|
# Generate *.cpp/*.hpp from idl (only with BUILD_RTI)
|
||||||
|
RTIDDSGEN(SRCS_common tab_enums.idl)
|
||||||
|
# tab.idl includes pdm.idl, so add explicit dependency on pdm.idl generation
|
||||||
|
RTIDDSGEN(SRCS_common tab.idl DEPENDS ${CMAKE_BINARY_DIR}/Lts/Services/ProjectDataManagement/pdm.idl)
|
||||||
|
# Generate tab_dt[s,c]_types.h, tab_ft[s,c]_types.h
|
||||||
|
CODEGEN_TOPIC_TYPEDEFS(SRCS_common ${xml_FILE})
|
||||||
|
# generate tab_[d|f]tc.h
|
||||||
|
CODEGEN_CLIENT_TOPICS_IFC(SRCS_common ${xml_FILE})
|
||||||
|
ELSE()
|
||||||
|
# Stub files for BUILD_RTI=OFF - NO code generation
|
||||||
|
LIST(APPEND SRCS_common
|
||||||
stubs/tab_enums_stub.hpp
|
stubs/tab_enums_stub.hpp
|
||||||
stubs/tab_stub.hpp
|
stubs/tab_stub.hpp
|
||||||
stubs/tab_db_stub.hpp
|
stubs/tab_db_stub.hpp
|
||||||
stubs/tab_topic_type_plugin_stub.cpp
|
stubs/tab_topic_type_plugin_stub.cpp
|
||||||
)
|
)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
# Create target only if component flags allow
|
# Create target only if component flags allow
|
||||||
NGL_ADD_LIBRARY2(AAR SV WS HLA svcTabCommon SHARED ${SRCS_common})
|
NGL_ADD_LIBRARY2(AAR SV WS HLA svcTabCommon SHARED ${SRCS_common})
|
||||||
|
|
||||||
|
# Generate export header ALWAYS (needed for logger.h even if target not built)
|
||||||
|
# Use custom command to create minimal export header if target wasn't created
|
||||||
IF(NOT TARGET svcTabCommon)
|
IF(NOT TARGET svcTabCommon)
|
||||||
# Create a dummy static library just for export header generation
|
# Create a dummy static library just for export header generation
|
||||||
ADD_LIBRARY(svcTabCommon STATIC ${SRCS_common})
|
ADD_LIBRARY(svcTabCommon STATIC ${SRCS_common})
|
||||||
@@ -104,8 +121,211 @@ NGL_TARGET_LINK_LIBRARIES(svcTabCommon
|
|||||||
$<IF:$<TARGET_EXISTS:svcPdmCommon>,svcPdmCommon,>
|
$<IF:$<TARGET_EXISTS:svcPdmCommon>,svcPdmCommon,>
|
||||||
LtsUtilsCoreHeaderOnly
|
LtsUtilsCoreHeaderOnly
|
||||||
)
|
)
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
NGL_TARGET_LINK_LIBRARIES(svcTabCommon
|
||||||
|
PRIVATE
|
||||||
|
RTI::nddscpp2
|
||||||
|
PUBLIC
|
||||||
|
ddscore
|
||||||
|
)
|
||||||
|
ENDIF(BUILD_RTI)
|
||||||
NGL_INSTALL_TARGET(svcTabCommon)
|
NGL_INSTALL_TARGET(svcTabCommon)
|
||||||
|
|
||||||
|
#
|
||||||
|
# --- Library svcTabClient --------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
SET(SRCS_client
|
||||||
|
tab_export.h
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
# generate tab_[d|f]tc_impl.[cpp|h]
|
||||||
|
CODEGEN_CLIENT_TOPICS_IMPL(SRCS_client ${xml_FILE})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
NGL_ADD_LIBRARY2(AAR SV WS HLA svcTabClient SHARED ${SRCS_client})
|
||||||
|
# NGL_ADD_LIBRARY2 (unlike NGL_ADD_LIBRARY) does not define the
|
||||||
|
# MAKE_<SYMBOL>_LIB compile guard, but the generated tab_[d|f]tc_impl.h
|
||||||
|
# headers require MAKE_SVCTABCLIENT_LIB — same situation as
|
||||||
|
# svcCoreClient/ddscore, which define their guards explicitly.
|
||||||
|
TARGET_COMPILE_DEFINITIONS(svcTabClient PRIVATE MAKE_SVCTABCLIENT_LIB)
|
||||||
|
NGL_TARGET_INCLUDE_DIRECTORIES(svcTabClient
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
NGL_TARGET_LINK_LIBRARIES(svcTabClient
|
||||||
|
PRIVATE
|
||||||
|
RTI::nddscpp2
|
||||||
|
ddsconnector
|
||||||
|
PUBLIC
|
||||||
|
svcTabCommon
|
||||||
|
ddsftc
|
||||||
|
)
|
||||||
|
ENDIF(BUILD_RTI)
|
||||||
|
NGL_INSTALL_TARGET(svcTabClient)
|
||||||
|
|
||||||
|
#
|
||||||
|
# --- Library svcTabServer --------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
SET(SRCS_server
|
||||||
|
tx_mixin.cpp
|
||||||
|
tx_mixin.h
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
# generate tab_[d|f]ts.h, tab_[d|f]ts_impl.[cpp|h]
|
||||||
|
CODEGEN_SERVER_TOPICS(SRCS_server ${xml_FILE})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
NGL_ADD_LIBRARY2(AAR HLA SV svcTabServer SHARED ${SRCS_server}) # NGL_ADD_LIBRARY2 won't work here - no time for investigations
|
||||||
|
# Generated tab_[d|f]ts_impl.h require MAKE_SVCTABSERVER_LIB (see svcTabClient above).
|
||||||
|
TARGET_COMPILE_DEFINITIONS(svcTabServer PRIVATE MAKE_SVCTABSERVER_LIB)
|
||||||
|
if(BUILD_SV OR BUILD_HLA)
|
||||||
|
GENERATE_EXPORT_HEADER(svcTabServer) # FIXME: quick workaround
|
||||||
|
endif()
|
||||||
|
NGL_TARGET_INCLUDE_DIRECTORIES(svcTabServer
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||||
|
)
|
||||||
|
|
||||||
|
NGL_TARGET_LINK_LIBRARIES(svcTabServer
|
||||||
|
PUBLIC
|
||||||
|
svcTabCommon
|
||||||
|
ngldb
|
||||||
|
${_QT_CORE_TARGET}
|
||||||
|
$<IF:$<AND:$<BOOL:${QT6_GUI_AVAILABLE}>,$<TARGET_EXISTS:Qt6::Gui>>,Qt6::Gui,>
|
||||||
|
${_QT_NETWORK_TARGET}
|
||||||
|
)
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
NGL_TARGET_LINK_LIBRARIES(svcTabServer
|
||||||
|
PRIVATE
|
||||||
|
RTI::nddscpp2
|
||||||
|
ddsconnector
|
||||||
|
ddsfts
|
||||||
|
)
|
||||||
|
ENDIF(BUILD_RTI)
|
||||||
|
NGL_INSTALL_TARGET(svcTabServer)
|
||||||
|
|
||||||
|
#
|
||||||
|
# --- Topic Type Plugin --------------------------------------------------------------
|
||||||
|
#
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
CREATE_TOPIC_TYPE_PLUGIN(${xml_FILE})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
#
|
||||||
|
# --- RecordReplayPlugin --------------------------------------------------------------
|
||||||
|
#
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
CREATE_RECORD_REPLAY_PLUGIN_SHARED(${xml_FILE})
|
||||||
|
IF (TARGET tabRecordReplayPlugin)
|
||||||
|
TARGET_SOURCES(tabRecordReplayPlugin
|
||||||
|
PRIVATE
|
||||||
|
tab_record_replay_plugin_custom.cpp
|
||||||
|
tab_record_replay_plugin_custom.h
|
||||||
|
)
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
#
|
||||||
|
# --- Executable svcTrainingAreaBase (sTAB) -------------------------------------------------
|
||||||
|
#
|
||||||
|
SET(SRCS_exe
|
||||||
|
dds_handler.cpp
|
||||||
|
dds_handler.h
|
||||||
|
exm_handler.cpp
|
||||||
|
exm_handler.h
|
||||||
|
ism_handler.cpp
|
||||||
|
ism_handler.h
|
||||||
|
main.cpp
|
||||||
|
main_handler.cpp
|
||||||
|
main_handler.h
|
||||||
|
pdm_handler.cpp
|
||||||
|
pdm_handler.h
|
||||||
|
ppm_handler.cpp
|
||||||
|
ppm_handler.h
|
||||||
|
position_handler.cpp
|
||||||
|
position_handler.h
|
||||||
|
recv_from_dds_aes.cpp
|
||||||
|
recv_from_dds_aes.h
|
||||||
|
recv_from_dds_fts.cpp
|
||||||
|
recv_from_dds_fts.h
|
||||||
|
recv_from_tab.h
|
||||||
|
send_to_dds.cpp
|
||||||
|
send_to_dds.h
|
||||||
|
send_to_tab.h
|
||||||
|
settings.cpp
|
||||||
|
settings.h
|
||||||
|
tab_export.h
|
||||||
|
tab_plugin_interface.h
|
||||||
|
|
||||||
|
WebSocketInterface/data_manager.cpp
|
||||||
|
WebSocketInterface/data_manager.h
|
||||||
|
WebSocketInterface/json_keys.h
|
||||||
|
WebSocketInterface/websocket_interface_handler.cpp
|
||||||
|
WebSocketInterface/websocket_interface_handler.h
|
||||||
|
WebSocketInterface/Messages/client_message.cpp
|
||||||
|
WebSocketInterface/Messages/client_message.h
|
||||||
|
WebSocketInterface/Messages/reply_message.cpp
|
||||||
|
WebSocketInterface/Messages/reply_message.h
|
||||||
|
# tx_mixin.cpp
|
||||||
|
# tx_mixin.h
|
||||||
|
|
||||||
|
log4cxx_tab.props
|
||||||
|
${xml_FILE}
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(BUILD_RTI)
|
||||||
|
# Generate tab.sql, tab.xml
|
||||||
|
CODEGEN_SQL(SRCS_exe ${xml_FILE})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
NGL_ADD_SVC_ICON(SRCS_exe)
|
||||||
|
NGL_ADD_EXECUTABLE(AAR SV svcTrainingAreaBase ${SRCS_exe})
|
||||||
|
NGL_TARGET_LINK_LIBRARIES(svcTrainingAreaBase
|
||||||
|
Qt6::Core
|
||||||
|
Qt6::Network
|
||||||
|
LtsCoordTrans
|
||||||
|
LtsWebSocketServer
|
||||||
|
LtsCommandLineParser
|
||||||
|
LtsPluginLoader
|
||||||
|
LtsUtilsCoreHeaderOnly
|
||||||
|
LtsUtilsCore
|
||||||
|
svcTabCommon
|
||||||
|
svcTabServer
|
||||||
|
# main_handler.cpp includes the generated <TrainingAreaBase/tab_record_replay_plugin.h>
|
||||||
|
# and directly instantiates TrainingAreaBase::RecordReplayPluginCustom (whose methods
|
||||||
|
# live in the plugin .so). Linking the plugin target (rather than relying on a full
|
||||||
|
# `make all` having generated the header first) makes this a proper build dependency:
|
||||||
|
# the plugin's codegen runs before the exe compiles (so the generated header exists),
|
||||||
|
# the plugin's PUBLIC build-tree include dir is inherited (so the include resolves),
|
||||||
|
# and the plugin .so is linked (so the RecordReplayPluginCustom symbols resolve).
|
||||||
|
$<IF:$<TARGET_EXISTS:tabRecordReplayPlugin>,tabRecordReplayPlugin,>
|
||||||
|
svcNomClient
|
||||||
|
svcAesClient
|
||||||
|
svcOpmClient
|
||||||
|
svcCoreClient
|
||||||
|
svcAsmClient
|
||||||
|
svcExmClient
|
||||||
|
$<IF:$<TARGET_EXISTS:svcIsmClient>,svcIsmClient,>
|
||||||
|
svcPdmClient
|
||||||
|
svcPpmClient
|
||||||
|
$<IF:$<TARGET_EXISTS:ddsconnector>,ddsconnector,>
|
||||||
|
nglsettings
|
||||||
|
ProjectConfig
|
||||||
|
NGLLogger
|
||||||
|
nglcoreapplication
|
||||||
|
ngltools
|
||||||
|
tabTelegrams
|
||||||
|
)
|
||||||
|
NGL_INSTALL_TARGET(svcTrainingAreaBase)
|
||||||
|
NGL_INSTALL(AAR SV FILES log4cxx_tab.props DESTINATION bin)
|
||||||
|
NGL_ADD_TARGET_LINK(svcTrainingAreaBase sTAB)
|
||||||
|
|
||||||
# clientPluginInterface
|
# clientPluginInterface
|
||||||
ADD_LIBRARY(tabPluginInterface INTERFACE)
|
ADD_LIBRARY(tabPluginInterface INTERFACE)
|
||||||
TARGET_SOURCES(tabPluginInterface INTERFACE
|
TARGET_SOURCES(tabPluginInterface INTERFACE
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* AsmHandler for AdlerJson Plugin
|
||||||
|
* $Id: pdm_handler.cpp 62304 2024-03-21 08:17:45Z ewert_j $
|
||||||
|
* $HeadURL: svn://slssvn/TDS/branches/product/features/ufom/Lts/Proxies/TrainingAreaBase/Plugins/UFomHlaJson/pdm_handler.cpp $
|
||||||
|
* $Author: ewert_j $
|
||||||
|
* Created by Hanna E. Rathje, 2025-11-18
|
||||||
|
*/
|
||||||
|
|
||||||
#include "asm_handler.h"
|
#include "asm_handler.h"
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* FlmHandler for AdlerJson Plugin
|
||||||
|
* $Id: pdm_handler.cpp 62304 2024-03-21 08:17:45Z ewert_j $
|
||||||
|
* $HeadURL: svn://slssvn/TDS/branches/product/features/ufom/Lts/Proxies/TrainingAreaBase/Plugins/UFomHlaJson/pdm_handler.cpp $
|
||||||
|
* $Author: ewert_j $
|
||||||
|
* Created by Hanna E. Rathje, 2025-11-18
|
||||||
|
*/
|
||||||
|
|
||||||
#include "flm_handler.h"
|
#include "flm_handler.h"
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* JsonHandlerTx for AdlerJson Plugin
|
||||||
|
* $Id: hla_handler_tx.cpp 62899 2024-05-29 11:08:50Z ewert_j $
|
||||||
|
* $HeadURL: svn://slssvn/TDS/branches/product/features/ufom/Lts/Proxies/TrainingAreaBase/Plugins/AdlerJson/hla_handler_tx.cpp $
|
||||||
|
* $Author: ewert_j $
|
||||||
|
* Created by Julius Ewert, ESIM, 2024-03-20
|
||||||
|
*/
|
||||||
|
|
||||||
#include "json_handler_tx.h"
|
#include "json_handler_tx.h"
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* PdmHandler for AdlerJson Plugin
|
||||||
|
* $Id: pdm_handler.cpp 62304 2024-03-21 08:17:45Z ewert_j $
|
||||||
|
* $HeadURL: svn://slssvn/TDS/branches/product/features/ufom/Lts/Proxies/TrainingAreaBase/Plugins/AdlerJson/pdm_handler.cpp $
|
||||||
|
* $Author: ewert_j $
|
||||||
|
* Created by Julius Ewert, ESIM, 2024-03-20
|
||||||
|
*/
|
||||||
|
|
||||||
#include "pdm_handler.h"
|
#include "pdm_handler.h"
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @RDE_HEADER@
|
||||||
|
* PpmHandler for AdlerJson Plugin
|
||||||
|
* $Id: ppm_handler.cpp 62899 2024-05-29 11:08:50Z ewert_j $
|
||||||
|
* $HeadURL: svn://slssvn/TDS/branches/product/features/ufom/Lts/Proxies/TrainingAreaBase/Plugins/AdlerJson/ppm_handler.cpp $
|
||||||
|
* $Author: ewert_j $
|
||||||
|
* Created by Julius Ewert, ESIM, 2024-03-20
|
||||||
|
*/
|
||||||
|
|
||||||
#include "ppm_handler.h"
|
#include "ppm_handler.h"
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|||||||
Loaded 100 of 377 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user