Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files) - Formatted LtsAppDescriptor module files - Formatted LtsAppManager/AppChooser files - Applied clang-format to all DTC and enum headers across modules - Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/) Cosmetic changes only, no functional modifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
848 files changed
+28247
-38962
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace AreaEffectSimulation
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace AreaEffectSimulation
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace AreaEffectSimulation
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace AssetManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace AssetManagement
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace AssetManagement
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace AssetManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace AudioVideoManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace AudioVideoManagement
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace AudioVideoManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace Buildings
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace Buildings
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace Buildings
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace Buildings
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace CentralEffectSimulation
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace CentralEffectSimulation
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace CodificationManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace CodificationManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace ComponentMonitor
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace ComponentMonitor
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace Core
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace Core
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace Core
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace Core
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace Core
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace Core
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace Core
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace Core
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace DDS
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace DDS
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace EffectShowClient
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace EffectShowClient
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace EffectShowManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace EffectShowManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace Evaluations
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace Evaluations
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace ExerciseEventManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace ExerciseEventManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace ExerciseManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace ExerciseManagement
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace ExerciseManagement
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace ExerciseManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace FileManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace FileManagement
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace FileManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace GuezIedManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace GuezIedManagement
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace GuezNasat
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace GuezNasat
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||
|
||||
@@ -6,7 +7,7 @@ namespace InfrastructureManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
} // namespace Interface
|
||||
} // namespace InfrastructureManagement
|
||||
@@ -1,24 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||
enum class SymbolAppearance : int {
|
||||
Solid = 0,
|
||||
Dashed = 1,
|
||||
Dotted = 2
|
||||
};
|
||||
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||
|
||||
enum class SymbolVisibility : int {
|
||||
Visible = 0,
|
||||
Hidden = 1
|
||||
};
|
||||
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||
|
||||
struct UnitSymbolPosition {
|
||||
struct UnitSymbolPosition
|
||||
{
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
}
|
||||
} // namespace InfrastructureManagement
|
||||
Executable → Regular
+54
-77
@@ -1,10 +1,11 @@
|
||||
|
||||
|
||||
|
||||
#include "CppTopicGeneratorGrantlee.h"
|
||||
|
||||
#include "StructBuilder.h"
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QCryptographicHash>
|
||||
#include <grantlee/context.h>
|
||||
|
||||
#ifdef RTI_HEADER_AVAILABLE
|
||||
@@ -13,11 +14,9 @@
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
CppTopicGeneratorGrantlee::CppTopicGeneratorGrantlee()
|
||||
: GeneratorGrantleeBase("CodeGen.CppTopicGeneratorGrantlee")
|
||||
{}
|
||||
CppTopicGeneratorGrantlee::CppTopicGeneratorGrantlee() : GeneratorGrantleeBase("CodeGen.CppTopicGeneratorGrantlee") {}
|
||||
|
||||
bool CppTopicGeneratorGrantlee::init(const XmlReader *reader, StructBuilder *structBuilder)
|
||||
bool CppTopicGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
|
||||
{
|
||||
m_reader = reader;
|
||||
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
||||
@@ -28,15 +27,13 @@ bool CppTopicGeneratorGrantlee::init(const XmlReader *reader, StructBuilder *str
|
||||
return initDataTopics() && initFunctionTopics() && initIdlStructs();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CppTopicGeneratorGrantlee::initDataTopics()
|
||||
{
|
||||
DataTopicsWrapper *dataTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
||||
DataTopicsWrapper* dataTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
||||
const auto dataTopics = m_reader->getIdlStructInformation();
|
||||
QVector<IdlData> keyColumns;
|
||||
QVector<IdlData> trColumns;
|
||||
for (const CodeGen::TopicTypeInformation &tti : dataTopics)
|
||||
for (const CodeGen::TopicTypeInformation& tti : dataTopics)
|
||||
{
|
||||
if (!tti.isDataObject)
|
||||
continue;
|
||||
@@ -49,7 +46,7 @@ bool CppTopicGeneratorGrantlee::initDataTopics()
|
||||
ERROR_LOG(m_logger) << "could not find informations for struct " << tti.name;
|
||||
continue;
|
||||
}
|
||||
DataTopicWrapper *dtw = dataTopicsWrapper->addDataTopic(ctti);
|
||||
DataTopicWrapper* dtw = dataTopicsWrapper->addDataTopic(ctti);
|
||||
getSpecialColumns(ctti, keyColumns, trColumns);
|
||||
if (keyColumns.size() == 1)
|
||||
dtw->setKeyColumnData(keyColumns.first());
|
||||
@@ -69,9 +66,9 @@ bool CppTopicGeneratorGrantlee::initDataTopics()
|
||||
m_ctx->insert(QStringLiteral("dataTopics"), dataTopicsWrapper);
|
||||
|
||||
QSet<QString> exportedSubTopics;
|
||||
DataTopicsWrapper *subTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
||||
DataTopicsWrapper* subTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
||||
const QVector<QSharedPointer<DataTypeInfo>> serializeTopics = m_structBuilder->getSerializeFromToJsonTopics();
|
||||
for (const QSharedPointer<DataTypeInfo> &dti : serializeTopics)
|
||||
for (const QSharedPointer<DataTypeInfo>& dti : serializeTopics)
|
||||
{
|
||||
if (exportedSubTopics.contains(dti->idlType()))
|
||||
continue;
|
||||
@@ -90,29 +87,27 @@ bool CppTopicGeneratorGrantlee::initDataTopics()
|
||||
continue;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "Adding substruct topic " << ctti.name;
|
||||
DataTopicWrapper *dtw = subTopicsWrapper->addDataTopic(ctti);
|
||||
DataTopicWrapper* dtw = subTopicsWrapper->addDataTopic(ctti);
|
||||
dtw->setRecordTableInformation(cti);
|
||||
exportedSubTopics += dti->idlType();
|
||||
}
|
||||
}
|
||||
m_ctx->insert(QStringLiteral("serializeTopics"), subTopicsWrapper);
|
||||
|
||||
QVector<MemberInformationListWrapper *> jsonTopics;
|
||||
QVector<MemberInformationListWrapper*> jsonTopics;
|
||||
const QMap<QString, QVector<MemberInformation>> jsonExport = m_structBuilder->jsonStructureInformation();
|
||||
for (auto it = jsonExport.begin(); it != jsonExport.end(); ++it)
|
||||
{
|
||||
MemberInformationListWrapper *mil = new MemberInformationListWrapper(it.key(), it.value(), this);
|
||||
MemberInformationListWrapper* mil = new MemberInformationListWrapper(it.key(), it.value(), this);
|
||||
jsonTopics += mil;
|
||||
|
||||
}
|
||||
m_ctx->insert(QStringLiteral("jsonTopics"), QVariant::fromValue(jsonTopics));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInformation &tti,
|
||||
QVector<IdlData> &keyColumns,
|
||||
QVector<IdlData> &trColumns) const
|
||||
bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInformation& tti, QVector<IdlData>& keyColumns,
|
||||
QVector<IdlData>& trColumns) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Get special columns for " << tti.name << " - base is " << tti.baseValueType;
|
||||
if (!tti.isValid())
|
||||
@@ -120,7 +115,7 @@ bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInforma
|
||||
ERROR_LOG(m_logger) << "tti is not valid ...";
|
||||
return false;
|
||||
}
|
||||
for (const IdlData &ci : tti.members)
|
||||
for (const IdlData& ci : tti.members)
|
||||
{
|
||||
if (ci.isKey)
|
||||
keyColumns += ci;
|
||||
@@ -132,14 +127,12 @@ bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInforma
|
||||
return getSpecialColumns(topicTypeInformationByDerivedTopic(tti), keyColumns, trColumns);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CppTopicGeneratorGrantlee::initFunctionTopics()
|
||||
{
|
||||
|
||||
const QVector<FunctionTopic> functionTopics = m_reader->getFunctionTopics();
|
||||
FunctionTopicsWrapper *functionTopicsWrapper(new FunctionTopicsWrapper(QStringLiteral("functionTopics"), this));
|
||||
for (const FunctionTopic &ft : functionTopics)
|
||||
FunctionTopicsWrapper* functionTopicsWrapper(new FunctionTopicsWrapper(QStringLiteral("functionTopics"), this));
|
||||
for (const FunctionTopic& ft : functionTopics)
|
||||
{
|
||||
if (!handleStruct(ft, functionTopicsWrapper))
|
||||
return false;
|
||||
@@ -149,44 +142,43 @@ bool CppTopicGeneratorGrantlee::initFunctionTopics()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CppTopicGeneratorGrantlee::handleStruct(const FunctionTopic &ft,
|
||||
FunctionTopicsWrapper *functionTopicsWrapper)
|
||||
bool CppTopicGeneratorGrantlee::handleStruct(const FunctionTopic& ft, FunctionTopicsWrapper* functionTopicsWrapper)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "handling FunctionTopic: " << ft.name;
|
||||
|
||||
const CompleteTopicTypeInformation siRequest = m_structBuilder->topicTypeInformationByStructType(ft.requestTopicType);
|
||||
const CompleteTopicTypeInformation siRequest =
|
||||
m_structBuilder->topicTypeInformationByStructType(ft.requestTopicType);
|
||||
if (!siRequest.isValid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about request topic "
|
||||
<< ft.requestTopicName;
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about request topic " << ft.requestTopicName;
|
||||
return false;
|
||||
}
|
||||
|
||||
const CompleteTopicTypeInformation siReply = m_structBuilder->topicTypeInformationByStructType(ft.replyTopicType);
|
||||
if (!siReply.isValid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about reply topic "
|
||||
<< ft.replyTopicType;
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about reply topic " << ft.replyTopicType;
|
||||
return false;
|
||||
}
|
||||
|
||||
FunctionTopicWrapper *ftw = functionTopicsWrapper->addFunctionTopic(ft, siRequest, siReply);
|
||||
const QByteArray hash = QCryptographicHash::hash(ft.requestTopicName.toUtf8(), QCryptographicHash::Sha3_512).toHex().left(16);
|
||||
FunctionTopicWrapper* ftw = functionTopicsWrapper->addFunctionTopic(ft, siRequest, siReply);
|
||||
const QByteArray hash =
|
||||
QCryptographicHash::hash(ft.requestTopicName.toUtf8(), QCryptographicHash::Sha3_512).toHex().left(16);
|
||||
ftw->setReplyHandlerHash(QStringLiteral("0x") + QString::fromLatin1(hash) + QStringLiteral("LL"));
|
||||
if (!addRequesterRequestParams(ft.name, siRequest, ftw) ||
|
||||
!addRequesterReplyParams(ft.name, siReply, ftw))
|
||||
if (!addRequesterRequestParams(ft.name, siRequest, ftw) || !addRequesterReplyParams(ft.name, siReply, ftw))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CppTopicGeneratorGrantlee::addRequesterRequestParams(const QString &request_name,
|
||||
const CompleteTopicTypeInformation &request,
|
||||
FunctionTopicWrapper *ftw)
|
||||
bool CppTopicGeneratorGrantlee::addRequesterRequestParams(const QString& request_name,
|
||||
const CompleteTopicTypeInformation& request,
|
||||
FunctionTopicWrapper* ftw)
|
||||
{
|
||||
if (request.hasBaseValue())
|
||||
{
|
||||
const CompleteTopicTypeInformation siBase = m_structBuilder->topicTypeInformationByStructType(request.baseValueType);
|
||||
const CompleteTopicTypeInformation siBase =
|
||||
m_structBuilder->topicTypeInformationByStructType(request.baseValueType);
|
||||
if (!siBase.isValid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about base request topic "
|
||||
@@ -202,17 +194,17 @@ bool CppTopicGeneratorGrantlee::addRequesterRequestParams(const QString &request
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CppTopicGeneratorGrantlee::addRequesterReplyParams(const QString &request_name,
|
||||
const CompleteTopicTypeInformation &reply,
|
||||
FunctionTopicWrapper *ftw)
|
||||
bool CppTopicGeneratorGrantlee::addRequesterReplyParams(const QString& request_name,
|
||||
const CompleteTopicTypeInformation& reply,
|
||||
FunctionTopicWrapper* ftw)
|
||||
{
|
||||
if (reply.hasBaseValue())
|
||||
{
|
||||
const CompleteTopicTypeInformation siBase = m_structBuilder->topicTypeInformationByStructType(reply.baseValueType);
|
||||
const CompleteTopicTypeInformation siBase =
|
||||
m_structBuilder->topicTypeInformationByStructType(reply.baseValueType);
|
||||
if (!siBase.isValid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about base reply topic "
|
||||
<< reply.baseValueType;
|
||||
WARNING_LOG(m_logger) << "Could not get topic informations about base reply topic " << reply.baseValueType;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -224,11 +216,8 @@ bool CppTopicGeneratorGrantlee::addRequesterReplyParams(const QString &request_n
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformation &csi,
|
||||
QSet<QString> &idlStructNames,
|
||||
QVector<IdlStructWrapper *> &idlStructs)
|
||||
bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformation& csi, QSet<QString>& idlStructNames,
|
||||
QVector<IdlStructWrapper*>& idlStructs)
|
||||
{
|
||||
if (!csi.isValid())
|
||||
return true;
|
||||
@@ -236,12 +225,10 @@ bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformati
|
||||
if (idlStructNames.contains(csi.name))
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
|
||||
if (csi.hasBaseValue())
|
||||
{
|
||||
const CompleteTopicTypeInformation ctti = m_structBuilder->topicTypeInformationByStructType(csi.baseValueType, false);
|
||||
const CompleteTopicTypeInformation ctti =
|
||||
m_structBuilder->topicTypeInformationByStructType(csi.baseValueType, false);
|
||||
if (ctti.isValid())
|
||||
{
|
||||
#ifdef RTI_HEADER_AVAILABLE
|
||||
@@ -266,20 +253,17 @@ bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformati
|
||||
const int idx = csi.baseValueType.indexOf(QLatin1String("::"));
|
||||
if (idx < 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "idlStruct '" << csi.baseValueType
|
||||
<< "' not found in idl-file";
|
||||
ERROR_LOG(m_logger) << "idlStruct '" << csi.baseValueType << "' not found in idl-file";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (const IdlData &idlData : csi.members)
|
||||
for (const IdlData& idlData : csi.members)
|
||||
{
|
||||
QString idlType;
|
||||
DEBUG_LOG(m_logger) << "member: " << idlData.type << " - " << idlData.name
|
||||
<< " " << idlData.dataTypeInfo->isStructure()
|
||||
<< " " << idlData.dataTypeInfo->isSequence();
|
||||
DEBUG_LOG(m_logger) << "member: " << idlData.type << " - " << idlData.name << " "
|
||||
<< idlData.dataTypeInfo->isStructure() << " " << idlData.dataTypeInfo->isSequence();
|
||||
if (idlData.dataTypeInfo->isStructure())
|
||||
idlType = idlData.dataTypeInfo->idlType();
|
||||
else if (idlData.dataTypeInfo->isSequence())
|
||||
@@ -289,18 +273,14 @@ bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformati
|
||||
}
|
||||
if (idlType.isEmpty())
|
||||
continue;
|
||||
if (!handleIdlStruct(m_structBuilder->topicTypeInformationByStructType(idlType,
|
||||
false),
|
||||
idlStructNames,
|
||||
if (!handleIdlStruct(m_structBuilder->topicTypeInformationByStructType(idlType, false), idlStructNames,
|
||||
idlStructs))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << "Current structName: " << csi.name;
|
||||
idlStructs += new IdlStructWrapper(csi, this);
|
||||
|
||||
|
||||
idlStructNames.insert(csi.name);
|
||||
|
||||
return true;
|
||||
@@ -312,9 +292,9 @@ bool CppTopicGeneratorGrantlee::initIdlStructs()
|
||||
const QVector<CompleteTopicTypeInformation> csiData = m_structBuilder->topicTypeInformations();
|
||||
|
||||
QSet<QString> idlStructNames;
|
||||
QVector<IdlStructWrapper *> idlStructs;
|
||||
QVector<IdlStructWrapper*> idlStructs;
|
||||
idlStructs.reserve(csiData.size());
|
||||
for (const CompleteTopicTypeInformation &csi : csiData)
|
||||
for (const CompleteTopicTypeInformation& csi : csiData)
|
||||
{
|
||||
if (!handleIdlStruct(csi, idlStructNames, idlStructs))
|
||||
return false;
|
||||
@@ -323,27 +303,24 @@ bool CppTopicGeneratorGrantlee::initIdlStructs()
|
||||
m_ctx->insert(QStringLiteral("idl_structs"), QVariant::fromValue(idlStructs));
|
||||
|
||||
const QVector<EnumInformation> enumerations = m_structBuilder->enumInformations();
|
||||
QVector<IdlEnumWrapper *> idlEnumerations;
|
||||
QVector<IdlEnumWrapper*> idlEnumerations;
|
||||
idlEnumerations.reserve(enumerations.size());
|
||||
for (const EnumInformation &ei : enumerations)
|
||||
for (const EnumInformation& ei : enumerations)
|
||||
idlEnumerations += new IdlEnumWrapper(ei, this);
|
||||
m_ctx->insert(QStringLiteral("idl_enums"), QVariant::fromValue(idlEnumerations));
|
||||
|
||||
|
||||
exportUsedServices(m_reader);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CompleteTopicTypeInformation CppTopicGeneratorGrantlee::topicTypeInformationByDerivedTopic(const CompleteTopicTypeInformation &tti) const
|
||||
CompleteTopicTypeInformation
|
||||
CppTopicGeneratorGrantlee::topicTypeInformationByDerivedTopic(const CompleteTopicTypeInformation& tti) const
|
||||
{
|
||||
if (tti.baseValueType.isEmpty())
|
||||
return CompleteTopicTypeInformation();
|
||||
QString baseValueType = tti.baseValueType;
|
||||
|
||||
|
||||
if (tti.name.contains(QLatin1String("::")) &&
|
||||
!tti.baseValueType.contains(QLatin1String("::")))
|
||||
if (tti.name.contains(QLatin1String("::")) && !tti.baseValueType.contains(QLatin1String("::")))
|
||||
{
|
||||
const QStringList sl = tti.name.split(QStringLiteral("::"));
|
||||
baseValueType = sl.at(0) + QLatin1String("::") + tti.baseValueType;
|
||||
|
||||
Executable → Regular
+18
-24
@@ -1,11 +1,11 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "GeneratorGrantleeBase.h"
|
||||
#include "StructBuilder.h"
|
||||
#include "GrantleeWrappers.h"
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
@@ -13,35 +13,29 @@ namespace CodeGen
|
||||
class CppTopicGeneratorGrantlee final : public GeneratorGrantleeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
explicit CppTopicGeneratorGrantlee();
|
||||
|
||||
bool init(const XmlReader *reader, StructBuilder *structBuilder) override;
|
||||
|
||||
private:
|
||||
bool init(const XmlReader* reader, StructBuilder* structBuilder) override;
|
||||
|
||||
private:
|
||||
bool initDataTopics();
|
||||
bool getSpecialColumns(const CompleteTopicTypeInformation &tti,
|
||||
QVector<IdlData> &keyColumns,
|
||||
QVector<IdlData> &trColumns) const;
|
||||
bool getSpecialColumns(const CompleteTopicTypeInformation& tti, QVector<IdlData>& keyColumns,
|
||||
QVector<IdlData>& trColumns) const;
|
||||
|
||||
bool initFunctionTopics();
|
||||
bool handleStruct(const FunctionTopic &ft,
|
||||
FunctionTopicsWrapper *functionTopicsWrapper);
|
||||
bool addRequesterRequestParams(const QString &request_name,
|
||||
const CompleteTopicTypeInformation &request,
|
||||
FunctionTopicWrapper *ftw);
|
||||
bool addRequesterReplyParams(const QString &request_name,
|
||||
const CompleteTopicTypeInformation &reply,
|
||||
FunctionTopicWrapper *ftw);
|
||||
bool handleStruct(const FunctionTopic& ft, FunctionTopicsWrapper* functionTopicsWrapper);
|
||||
bool addRequesterRequestParams(const QString& request_name, const CompleteTopicTypeInformation& request,
|
||||
FunctionTopicWrapper* ftw);
|
||||
bool addRequesterReplyParams(const QString& request_name, const CompleteTopicTypeInformation& reply,
|
||||
FunctionTopicWrapper* ftw);
|
||||
|
||||
bool handleIdlStruct(const CompleteTopicTypeInformation &csi,
|
||||
QSet<QString> &idlStructNames,
|
||||
QVector<IdlStructWrapper *> &idlStructs);
|
||||
bool handleIdlStruct(const CompleteTopicTypeInformation& csi, QSet<QString>& idlStructNames,
|
||||
QVector<IdlStructWrapper*>& idlStructs);
|
||||
bool initIdlStructs();
|
||||
|
||||
CompleteTopicTypeInformation topicTypeInformationByDerivedTopic(const CompleteTopicTypeInformation &tti) const;
|
||||
CompleteTopicTypeInformation topicTypeInformationByDerivedTopic(const CompleteTopicTypeInformation& tti) const;
|
||||
|
||||
const XmlReader *m_reader = nullptr;
|
||||
const XmlReader* m_reader = nullptr;
|
||||
};
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+8
-11
@@ -1,36 +1,33 @@
|
||||
|
||||
|
||||
|
||||
#include "DaoGeneratorGrantlee.h"
|
||||
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <grantlee/context.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
DaoGeneratorGrantlee::DaoGeneratorGrantlee()
|
||||
: GeneratorGrantleeBase("CodeGen.DaoGeneratorGrantlee")
|
||||
{}
|
||||
DaoGeneratorGrantlee::DaoGeneratorGrantlee() : GeneratorGrantleeBase("CodeGen.DaoGeneratorGrantlee") {}
|
||||
|
||||
bool DaoGeneratorGrantlee::init(const XmlReader *reader,
|
||||
StructBuilder *structBuilder)
|
||||
bool DaoGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
|
||||
{
|
||||
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
||||
return false;
|
||||
|
||||
|
||||
if (reader->isServiceExerciseIndependent())
|
||||
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
|
||||
|
||||
bool bHasDbNotifications = false;
|
||||
QVector<DbStructWrapper *> vlServiceStructs;
|
||||
QVector<DbStructWrapper *> vlStaticDataStructs;
|
||||
QVector<DbStructWrapper*> vlServiceStructs;
|
||||
QVector<DbStructWrapper*> vlStaticDataStructs;
|
||||
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
|
||||
vlServiceStructs.reserve(csiData.size());
|
||||
vlStaticDataStructs.reserve(csiData.size());
|
||||
for (const CompleteStructInformation &csi : csiData)
|
||||
for (const CompleteStructInformation& csi : csiData)
|
||||
{
|
||||
DbStructWrapper *dbStructWrapper(new DbStructWrapper(csi, this));
|
||||
DbStructWrapper* dbStructWrapper(new DbStructWrapper(csi, this));
|
||||
|
||||
if (csi.hasStaticContent)
|
||||
vlStaticDataStructs += dbStructWrapper;
|
||||
|
||||
Executable → Regular
+6
-7
@@ -1,11 +1,11 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "GeneratorGrantleeBase.h"
|
||||
#include "StructBuilder.h"
|
||||
#include "GrantleeWrappers.h"
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
@@ -13,13 +13,12 @@ struct CompleteStructInformation;
|
||||
class StructBuilder;
|
||||
class XmlReader;
|
||||
|
||||
|
||||
class DaoGeneratorGrantlee final : public GeneratorGrantleeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
explicit DaoGeneratorGrantlee();
|
||||
|
||||
bool init(const XmlReader *reader, StructBuilder *structBuilder) override;
|
||||
bool init(const XmlReader* reader, StructBuilder* structBuilder) override;
|
||||
};
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+12
-12
@@ -1,37 +1,36 @@
|
||||
|
||||
|
||||
|
||||
#include "DatabaseGeneratorGrantlee.h"
|
||||
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <grantlee/context.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
DatabaseGeneratorGrantlee::DatabaseGeneratorGrantlee(bool targetIsServer)
|
||||
: GeneratorGrantleeBase("CodeGen.CppStructGeneratorGrantlee")
|
||||
, m_targetIsServer(targetIsServer)
|
||||
{}
|
||||
: GeneratorGrantleeBase("CodeGen.CppStructGeneratorGrantlee"), m_targetIsServer(targetIsServer)
|
||||
{
|
||||
}
|
||||
|
||||
bool DatabaseGeneratorGrantlee::init(const XmlReader *reader,
|
||||
StructBuilder *structBuilder)
|
||||
bool DatabaseGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
|
||||
{
|
||||
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
||||
return false;
|
||||
|
||||
|
||||
if (reader->isServiceExerciseIndependent())
|
||||
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
|
||||
|
||||
bool bHasDbNotifications = false;
|
||||
QVector<DbStructWrapper *> vlServiceStructs;
|
||||
QVector<DbStructWrapper *> vlStaticDataStructs;
|
||||
QVector<DbStructWrapper*> vlServiceStructs;
|
||||
QVector<DbStructWrapper*> vlStaticDataStructs;
|
||||
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
|
||||
vlServiceStructs.reserve(csiData.size());
|
||||
vlStaticDataStructs.reserve(csiData.size());
|
||||
for (const CompleteStructInformation &csi : csiData)
|
||||
for (const CompleteStructInformation& csi : csiData)
|
||||
{
|
||||
DbStructWrapper *dbStructWrapper(new DbStructWrapper(csi, this));
|
||||
DbStructWrapper* dbStructWrapper(new DbStructWrapper(csi, this));
|
||||
|
||||
if (csi.hasStaticContent)
|
||||
vlStaticDataStructs += dbStructWrapper;
|
||||
@@ -51,7 +50,8 @@ bool DatabaseGeneratorGrantlee::init(const XmlReader *reader,
|
||||
if (bHasDbNotifications)
|
||||
m_ctx->insert(QStringLiteral("has_db_notifications"), QLatin1String("1"));
|
||||
|
||||
m_ctx->insert(QStringLiteral("library_target"), m_targetIsServer ? QStringLiteral("SERVER") : QStringLiteral("COMMON"));
|
||||
m_ctx->insert(QStringLiteral("library_target"),
|
||||
m_targetIsServer ? QStringLiteral("SERVER") : QStringLiteral("COMMON"));
|
||||
|
||||
exportUsedServices(reader);
|
||||
|
||||
|
||||
Executable → Regular
+8
-8
@@ -1,11 +1,11 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "GeneratorGrantleeBase.h"
|
||||
#include "StructBuilder.h"
|
||||
#include "GrantleeWrappers.h"
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
@@ -13,15 +13,15 @@ struct CompleteStructInformation;
|
||||
class StructBuilder;
|
||||
class XmlReader;
|
||||
|
||||
|
||||
class DatabaseGeneratorGrantlee final : public GeneratorGrantleeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
explicit DatabaseGeneratorGrantlee(bool targetIsServer);
|
||||
|
||||
bool init(const XmlReader *reader, StructBuilder *structBuilder) override;
|
||||
private:
|
||||
bool init(const XmlReader* reader, StructBuilder* structBuilder) override;
|
||||
|
||||
private:
|
||||
bool m_targetIsServer;
|
||||
};
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+26
-28
@@ -1,9 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#include "GeneratorGrantleeBase.h"
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include "GrantleeWrappers.h"
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
@@ -11,11 +12,13 @@
|
||||
#include <grantlee/engine.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
GeneratorGrantleeBase::GeneratorGrantleeBase(const char *loggerName) : m_engine(new Grantlee::Engine)
|
||||
, m_ctx(new Grantlee::Context)
|
||||
, m_structBuilder(nullptr)
|
||||
.getNGLLogger(loggerName)),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||
{
|
||||
}
|
||||
|
||||
GeneratorGrantleeBase::~GeneratorGrantleeBase()
|
||||
@@ -24,7 +27,7 @@ GeneratorGrantleeBase::~GeneratorGrantleeBase()
|
||||
delete m_ctx;
|
||||
}
|
||||
|
||||
bool GeneratorGrantleeBase::initInternal(const XmlReader *reader, StructBuilder *structBuilder)
|
||||
bool GeneratorGrantleeBase::initInternal(const XmlReader* reader, StructBuilder* structBuilder)
|
||||
{
|
||||
m_structBuilder = structBuilder;
|
||||
|
||||
@@ -34,7 +37,8 @@ bool GeneratorGrantleeBase::initInternal(const XmlReader *reader, StructBuilder
|
||||
m_ctx->insert(QStringLiteral("namespace_abbr"), reader->getServiceAbbr().toLower());
|
||||
m_ctx->insert(QStringLiteral("namespace_abbr_upper"), reader->getServiceAbbr().toUpper());
|
||||
if (reader->getServiceNamespace() == QLatin1String("Core"))
|
||||
m_ctx->insert(QStringLiteral("include_prefix"), QStringLiteral("DDS/%1").arg(reader->getServiceNamespace()));
|
||||
m_ctx->insert(QStringLiteral("include_prefix"),
|
||||
QStringLiteral("DDS/%1").arg(reader->getServiceNamespace()));
|
||||
else
|
||||
m_ctx->insert(QStringLiteral("include_prefix"), reader->getServiceNamespace());
|
||||
m_ctx->insert(QStringLiteral("custom_record_replay"), reader->hasCustomRecordReplayPlugin());
|
||||
@@ -42,13 +46,12 @@ bool GeneratorGrantleeBase::initInternal(const XmlReader *reader, StructBuilder
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorGrantleeBase::setTemplate(const QString &templateName, const QString &tmpl)
|
||||
bool GeneratorGrantleeBase::setTemplate(const QString& templateName, const QString& tmpl)
|
||||
{
|
||||
m_template = m_engine->newTemplate(tmpl, QStringLiteral("myTemplate"));
|
||||
if (m_template->error())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Error parsing template '" << templateName
|
||||
<< "': " << m_template->errorString();
|
||||
WARNING_LOG(m_logger) << "Error parsing template '" << templateName << "': " << m_template->errorString();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -67,9 +70,7 @@ QString GeneratorGrantleeBase::errorString() const
|
||||
return m_template->errorString();
|
||||
}
|
||||
|
||||
|
||||
bool GeneratorGrantleeBase::generateData(const QString &templateName,
|
||||
const QString &outDirectory)
|
||||
bool GeneratorGrantleeBase::generateData(const QString& templateName, const QString& outDirectory)
|
||||
{
|
||||
QString content;
|
||||
if (!readFile(templateName, content))
|
||||
@@ -83,12 +84,11 @@ bool GeneratorGrantleeBase::generateData(const QString &templateName,
|
||||
if (!getFilenameFromData(content, outFilename))
|
||||
return false;
|
||||
|
||||
|
||||
QFile f(outDirectory + QLatin1Char('/') + outFilename);
|
||||
if (!f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: "
|
||||
<< f.errorString() << "(" << f.error() << ")";
|
||||
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: " << f.errorString() << "("
|
||||
<< f.error() << ")";
|
||||
return false;
|
||||
}
|
||||
const QByteArray outData = content.toUtf8();
|
||||
@@ -99,13 +99,12 @@ bool GeneratorGrantleeBase::generateData(const QString &templateName,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorGrantleeBase::readFile(const QString &filename, QString &data) const
|
||||
bool GeneratorGrantleeBase::readFile(const QString& filename, QString& data) const
|
||||
{
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODevice::ReadOnly))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error opening file " << filename
|
||||
<< " - error: " << f.errorString();
|
||||
ERROR_LOG(m_logger) << "Error opening file " << filename << " - error: " << f.errorString();
|
||||
return false;
|
||||
}
|
||||
data = QString::fromUtf8(f.readAll());
|
||||
@@ -113,15 +112,14 @@ bool GeneratorGrantleeBase::readFile(const QString &filename, QString &data) con
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorGrantleeBase::getFilenameFromData(const QString &dataToParse, QString &filename) const
|
||||
bool GeneratorGrantleeBase::getFilenameFromData(const QString& dataToParse, QString& filename) const
|
||||
{
|
||||
|
||||
const QString filenameMarker(QStringLiteral("// filename:"));
|
||||
int idx = dataToParse.indexOf(filenameMarker);
|
||||
if (idx < 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not find marker '" << filenameMarker
|
||||
<< "' in data!";
|
||||
ERROR_LOG(m_logger) << "Could not find marker '" << filenameMarker << "' in data!";
|
||||
return false;
|
||||
}
|
||||
idx += filenameMarker.length() + 1;
|
||||
@@ -136,19 +134,19 @@ bool GeneratorGrantleeBase::getFilenameFromData(const QString &dataToParse, QStr
|
||||
return true;
|
||||
}
|
||||
|
||||
void GeneratorGrantleeBase::addCustomFunctions(const QVector<CustomServiceFunctionInformation> &customFunctions)
|
||||
void GeneratorGrantleeBase::addCustomFunctions(const QVector<CustomServiceFunctionInformation>& customFunctions)
|
||||
{
|
||||
|
||||
QVariantList vlCustomDbFunctions;
|
||||
QVariantList vlCustomDtcFunctions;
|
||||
vlCustomDbFunctions.reserve(customFunctions.size());
|
||||
vlCustomDtcFunctions.reserve(customFunctions.size());
|
||||
for (const CustomServiceFunctionInformation &csfi : customFunctions)
|
||||
for (const CustomServiceFunctionInformation& csfi : customFunctions)
|
||||
{
|
||||
const QString signature(csfi.returnValue + QLatin1Char(' ') +
|
||||
csfi.methodName + QLatin1Char('(') + csfi.signature + QLatin1Char(')') +
|
||||
const QString signature(csfi.returnValue + QLatin1Char(' ') + csfi.methodName + QLatin1Char('(') +
|
||||
csfi.signature + QLatin1Char(')') +
|
||||
(csfi.isConst ? QStringLiteral(" const") : QString()));
|
||||
CustomFunctionWrapper *customFunctionWrapper(new CustomFunctionWrapper(signature, this));
|
||||
CustomFunctionWrapper* customFunctionWrapper(new CustomFunctionWrapper(signature, this));
|
||||
switch (csfi.type)
|
||||
{
|
||||
case CustomServiceFunctionInformation::Type::Db:
|
||||
@@ -170,16 +168,16 @@ void GeneratorGrantleeBase::addCustomFunctions(const QVector<CustomServiceFuncti
|
||||
m_ctx->insert(QStringLiteral("custom_db_procs"), vlCustomDbFunctions);
|
||||
}
|
||||
|
||||
void GeneratorGrantleeBase::exportUsedServices(const XmlReader *reader)
|
||||
void GeneratorGrantleeBase::exportUsedServices(const XmlReader* reader)
|
||||
{
|
||||
IdlServicesWrapper *idlServicesWrapper(new IdlServicesWrapper(QString(), this));
|
||||
IdlServicesWrapper* idlServicesWrapper(new IdlServicesWrapper(QString(), this));
|
||||
const QMap<QString, bool> usedServices = reader->usedServices();
|
||||
for (auto it = usedServices.begin(); it != usedServices.end(); ++it)
|
||||
{
|
||||
|
||||
if (!it.value())
|
||||
continue;
|
||||
const QString &svc = it.key();
|
||||
const QString& svc = it.key();
|
||||
const QString fullPath = reader->idlFileForService(svc);
|
||||
const int idx = fullPath.lastIndexOf(QLatin1Char('.'));
|
||||
if (idx < 0)
|
||||
|
||||
Executable → Regular
+22
-20
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
|
||||
@@ -17,7 +18,8 @@ class Context;
|
||||
class Engine;
|
||||
class TemplateImpl;
|
||||
using Template = QSharedPointer<TemplateImpl>;
|
||||
}
|
||||
} // namespace Grantlee
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
class StructBuilder;
|
||||
@@ -25,29 +27,29 @@ class StructBuilder;
|
||||
class GeneratorGrantleeBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
virtual ~GeneratorGrantleeBase();
|
||||
virtual bool init(const XmlReader *reader, StructBuilder *structBuilder) = 0;
|
||||
bool setTemplate(const QString &templateName, const QString &tmpl);
|
||||
virtual bool init(const XmlReader* reader, StructBuilder* structBuilder) = 0;
|
||||
bool setTemplate(const QString& templateName, const QString& tmpl);
|
||||
QString render() const;
|
||||
QString errorString() const;
|
||||
bool generateData(const QString &templateName,
|
||||
const QString &outDirectory);
|
||||
bool generateData(const QString& templateName, const QString& outDirectory);
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
explicit GeneratorGrantleeBase(const char *loggerName);
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
explicit GeneratorGrantleeBase(const char* loggerName);
|
||||
|
||||
bool initInternal(const XmlReader *reader, StructBuilder *structBuilder);
|
||||
bool readFile(const QString &filename, QString &data) const;
|
||||
bool getFilenameFromData(const QString &dataToParse, QString &filename) const;
|
||||
void addCustomFunctions(const QVector<CustomServiceFunctionInformation> &customFunctions);
|
||||
void exportUsedServices(const XmlReader *reader);
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
Grantlee::Engine *m_engine;
|
||||
Grantlee::Context *m_ctx;
|
||||
bool initInternal(const XmlReader* reader, StructBuilder* structBuilder);
|
||||
bool readFile(const QString& filename, QString& data) const;
|
||||
bool getFilenameFromData(const QString& dataToParse, QString& filename) const;
|
||||
void addCustomFunctions(const QVector<CustomServiceFunctionInformation>& customFunctions);
|
||||
void exportUsedServices(const XmlReader* reader);
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
Grantlee::Engine* m_engine;
|
||||
Grantlee::Context* m_ctx;
|
||||
Grantlee::Template m_template;
|
||||
StructBuilder *m_structBuilder;
|
||||
StructBuilder* m_structBuilder;
|
||||
};
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+47
-94
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#include "GrantleeWrappers.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <utility>
|
||||
|
||||
@@ -32,8 +32,8 @@ QString IdlStructWrapper::extensibility2String(int /*extensiblity*/)
|
||||
|
||||
QString DataTopicWrapper::typeFq() const
|
||||
{
|
||||
const QString &t = type();
|
||||
const QString &s = serviceName();
|
||||
const QString& t = type();
|
||||
const QString& s = serviceName();
|
||||
if (s.isEmpty())
|
||||
return t;
|
||||
if (t.startsWith(s))
|
||||
@@ -48,77 +48,50 @@ QString MemberInformationWrapper::ddsToQVariant() const
|
||||
|
||||
QString MemberInformationWrapper::qVariantToDds() const
|
||||
{
|
||||
const QString ddsType = isOptional() ?
|
||||
(QStringLiteral("dds::core::optional<") + cppDdsType() + QLatin1Char('>')) :
|
||||
(cppDdsType());
|
||||
const QString ddsType =
|
||||
isOptional() ? (QStringLiteral("dds::core::optional<") + cppDdsType() + QLatin1Char('>')) : (cppDdsType());
|
||||
|
||||
return QStringLiteral("data.") + cppMemberName() +
|
||||
QStringLiteral("() = fromQVariant<") + ddsType + QStringLiteral(">(q.value(i++))");
|
||||
return QStringLiteral("data.") + cppMemberName() + QStringLiteral("() = fromQVariant<") + ddsType +
|
||||
QStringLiteral(">(q.value(i++))");
|
||||
}
|
||||
|
||||
QString MemberInformationWrapper::ddsToJsonElement() const
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (cppMemberName().isEmpty())
|
||||
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
|
||||
|
||||
const QString memberAccess = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
|
||||
if (!isOptional())
|
||||
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") +
|
||||
cppToJsonPre() + QStringLiteral("element.") + memberAccess + cppToJsonPost();
|
||||
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
|
||||
QStringLiteral("element.") + memberAccess + cppToJsonPost();
|
||||
|
||||
const QString optionalAccess = isCppStruct() ? cppMemberName() + QStringLiteral(".is_set()") : cppMemberName() + QStringLiteral("().is_set()");
|
||||
const QString optionalAccess =
|
||||
isCppStruct() ? cppMemberName() + QStringLiteral(".is_set()") : cppMemberName() + QStringLiteral("().is_set()");
|
||||
const QString getValue = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
|
||||
return QStringLiteral("if (element.") + optionalAccess + QStringLiteral(") ") +
|
||||
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") +
|
||||
cppToJsonPre() + QStringLiteral("element.") + getValue + cppToJsonPost();
|
||||
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
|
||||
QStringLiteral("element.") + getValue + cppToJsonPost();
|
||||
}
|
||||
|
||||
QString MemberInformationWrapper::jsonElementToDds() const
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (cppMemberName().isEmpty())
|
||||
return QStringLiteral("element = ") +
|
||||
cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") + cppType() + QStringLiteral("\"))") + cppFromJsonPost();
|
||||
return QStringLiteral("element = ") + cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") +
|
||||
cppType() + QStringLiteral("\"))") + cppFromJsonPost();
|
||||
|
||||
QString ret(QStringLiteral("const QJsonValue val(objElement.value(QStringLiteral(\"") + cppMemberName() + QStringLiteral("\"))); "));
|
||||
QString ret(QStringLiteral("const QJsonValue val(objElement.value(QStringLiteral(\"") + cppMemberName() +
|
||||
QStringLiteral("\"))); "));
|
||||
if (isOptional())
|
||||
ret += QStringLiteral("if (!val.isNull()) ");
|
||||
|
||||
if (isCppStruct())
|
||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") +
|
||||
cppFromJsonPre2() + QStringLiteral("val") + cppFromJsonPost();
|
||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") + cppFromJsonPre2() +
|
||||
QStringLiteral("val") + cppFromJsonPost();
|
||||
else
|
||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral("(") +
|
||||
cppFromJsonPre2() + QStringLiteral("val") + cppFromJsonPost() + QStringLiteral(")");
|
||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral("(") + cppFromJsonPre2() +
|
||||
QStringLiteral("val") + cppFromJsonPost() + QStringLiteral(")");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -126,56 +99,39 @@ QString MemberInformationWrapper::jsonElementToDds() const
|
||||
QString MemberInformationWrapper::dbToJsonElement() const
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (cppMemberName().isEmpty())
|
||||
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
|
||||
|
||||
if (isOptional() || cppType() == QStringLiteral("QDateTime"))
|
||||
{
|
||||
QString ret = QStringLiteral("if (") + ((cppType() == QStringLiteral("QDateTime")) ? QString() : QStringLiteral("!")) +
|
||||
QString ret = QStringLiteral("if (") +
|
||||
((cppType() == QStringLiteral("QDateTime")) ? QString() : QStringLiteral("!")) +
|
||||
QStringLiteral("element.") + cppMemberName() +
|
||||
((cppType() == QStringLiteral("QDateTime")) ? QStringLiteral(".isValid()) ") : QStringLiteral(".isNull()) ")) +
|
||||
((cppType() == QStringLiteral("QDateTime")) ? QStringLiteral(".isValid()) ")
|
||||
: QStringLiteral(".isNull()) ")) +
|
||||
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ");
|
||||
if (isOptional())
|
||||
return ret += cppFromQvPre2() + QStringLiteral("element.") + cppMemberName() + cppFromQvPost();
|
||||
}
|
||||
|
||||
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") +
|
||||
cppToJsonPre() + QStringLiteral("element.") + cppMemberName() + cppToJsonPost();
|
||||
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
|
||||
QStringLiteral("element.") + cppMemberName() + cppToJsonPost();
|
||||
}
|
||||
|
||||
QString MemberInformationWrapper::jsonElementToDb() const
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (cppMemberName().isEmpty())
|
||||
return QStringLiteral("element = ") +
|
||||
cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") + cppType() + QStringLiteral("\"))") + cppFromJsonPost();
|
||||
return QStringLiteral("element = ") + cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") +
|
||||
cppType() + QStringLiteral("\"))") + cppFromJsonPost();
|
||||
|
||||
QString ret(QStringLiteral("const QJsonValue val(objElement.value(QStringLiteral(\"") + cppMemberName() + QStringLiteral("\"))); "));
|
||||
QString ret(QStringLiteral("const QJsonValue val(objElement.value(QStringLiteral(\"") + cppMemberName() +
|
||||
QStringLiteral("\"))); "));
|
||||
if (isOptional())
|
||||
ret += QStringLiteral("if (!val.isUndefined()) ");
|
||||
|
||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") +
|
||||
cppFromJsonPre2() + QStringLiteral("val") + cppFromJsonPost();
|
||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") + cppFromJsonPre2() +
|
||||
QStringLiteral("val") + cppFromJsonPost();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -184,18 +140,18 @@ QVariantList DbStructWrapper::insertStructures()
|
||||
{
|
||||
|
||||
QStringList tableNames;
|
||||
QMap<QString, QVector<MemberInformationWrapper *>> structures;
|
||||
QMap<QString, MemberInformationWrapper *> primaryKeys;
|
||||
QMap<QString, MemberInformationWrapper *> fkComplexTableKeys;
|
||||
QMap<QString, QVector<MemberInformationWrapper*>> structures;
|
||||
QMap<QString, MemberInformationWrapper*> primaryKeys;
|
||||
QMap<QString, MemberInformationWrapper*> fkComplexTableKeys;
|
||||
|
||||
tableNames.reserve(5);
|
||||
for (const QVariant &v : std::as_const(m_member))
|
||||
for (const QVariant& v : std::as_const(m_member))
|
||||
{
|
||||
MemberInformationWrapper *mi = v.value<MemberInformationWrapper *>();
|
||||
const QString &tableName = mi->info().db.table;
|
||||
MemberInformationWrapper* mi = v.value<MemberInformationWrapper*>();
|
||||
const QString& tableName = mi->info().db.table;
|
||||
if (mi->info().db.usedForInsert)
|
||||
{
|
||||
auto &tnStructure = structures[tableName];
|
||||
auto& tnStructure = structures[tableName];
|
||||
tnStructure.append(mi);
|
||||
if (!tableNames.contains(tableName))
|
||||
tableNames.push_back(tableName);
|
||||
@@ -211,27 +167,24 @@ QVariantList DbStructWrapper::insertStructures()
|
||||
fkComplexTableKeys[mi->info().db.table] = mi;
|
||||
}
|
||||
|
||||
|
||||
QVariantList vl;
|
||||
vl.reserve(tableNames.size());
|
||||
for (int i = 0; i < tableNames.size(); ++i)
|
||||
{
|
||||
const QString &tn = tableNames.at(i);
|
||||
MemberInformationWrapper *serialMember = fkComplexTableKeys.value(tn);
|
||||
MemberInformationWrapper *baseId = nullptr;
|
||||
MemberInformationWrapper *primaryKey = primaryKeys.value(tn);
|
||||
const QString& tn = tableNames.at(i);
|
||||
MemberInformationWrapper* serialMember = fkComplexTableKeys.value(tn);
|
||||
MemberInformationWrapper* baseId = nullptr;
|
||||
MemberInformationWrapper* primaryKey = primaryKeys.value(tn);
|
||||
if (i == 0 && tableNames.size() > 1)
|
||||
baseId = primaryKeys.value(tn);
|
||||
|
||||
|
||||
|
||||
if (tableNames.size() == 1)
|
||||
{
|
||||
baseId = nullptr;
|
||||
|
||||
if (!primaryKey)
|
||||
{
|
||||
NGL::INGLLogger &logger = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("DbStructWrapper");
|
||||
NGL::INGLLogger& logger = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("DbStructWrapper");
|
||||
WARNING_LOG(logger) << "Table " << tn << " has no primary key!";
|
||||
}
|
||||
else
|
||||
@@ -241,8 +194,8 @@ QVariantList DbStructWrapper::insertStructures()
|
||||
}
|
||||
}
|
||||
|
||||
const QVector<MemberInformationWrapper *> members = structures.value(tn);
|
||||
TableWrapper *tw = new TableWrapper(tn, members, serialMember, baseId, primaryKey, this);
|
||||
const QVector<MemberInformationWrapper*> members = structures.value(tn);
|
||||
TableWrapper* tw = new TableWrapper(tn, members, serialMember, baseId, primaryKey, this);
|
||||
vl += QVariant::fromValue(tw);
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+513
-237
File diff suppressed because it is too large.
Load diff
Executable → Regular
+142
-192
@@ -1,37 +1,31 @@
|
||||
|
||||
|
||||
|
||||
#include "SqlGenerator.h"
|
||||
|
||||
#include "StructBuilder.h"
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QStringList>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QStringList>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
|
||||
static QString getExerciseSchemaName(int exerciseId)
|
||||
{
|
||||
return QStringLiteral("ex_") + QString::number(exerciseId);
|
||||
}
|
||||
|
||||
SqlGenerator::SqlGenerator(XmlReader *xmlReader, StructBuilder *structBuilder) : m_xmlReader(xmlReader)
|
||||
, m_structBuilder(structBuilder)
|
||||
, m_createdByXmlFile(false)
|
||||
, m_isValid(true)
|
||||
, m_exerciseId(0),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
|
||||
SqlGenerator::SqlGenerator(XmlReader* xmlReader, StructBuilder* structBuilder)
|
||||
: m_xmlReader(xmlReader), m_structBuilder(structBuilder), m_createdByXmlFile(false), m_isValid(true),
|
||||
m_exerciseId(0), m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||
{
|
||||
}
|
||||
|
||||
SqlGenerator::SqlGenerator(const QString &xmlFile)
|
||||
: m_xmlReader(new XmlReader)
|
||||
, m_structBuilder(new StructBuilder(m_xmlReader))
|
||||
, m_createdByXmlFile(true)
|
||||
, m_isValid(false)
|
||||
, m_exerciseId(0)
|
||||
SqlGenerator::SqlGenerator(const QString& xmlFile)
|
||||
: m_xmlReader(new XmlReader), m_structBuilder(new StructBuilder(m_xmlReader)), m_createdByXmlFile(true),
|
||||
m_isValid(false), m_exerciseId(0)
|
||||
{
|
||||
m_isValid = m_xmlReader->readServiceFile(xmlFile, QString()) && m_structBuilder->buildStructures();
|
||||
}
|
||||
@@ -45,10 +39,10 @@ SqlGenerator::~SqlGenerator()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SqlGenerator::generateData(int exerciseId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Generating SQL data for service " << getServiceAbbr() << " in exercise " << exerciseId << ", this: " << this;
|
||||
DEBUG_LOG(m_logger) << "Generating SQL data for service " << getServiceAbbr() << " in exercise " << exerciseId
|
||||
<< ", this: " << this;
|
||||
|
||||
m_exerciseId = exerciseId;
|
||||
m_sqlGlobal = SqlStatements();
|
||||
@@ -69,10 +63,10 @@ bool SqlGenerator::generateData(int exerciseId)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlGenerator::createStatementsForTable(const QString &tableName, const QString &tableNameOut)
|
||||
bool SqlGenerator::createStatementsForTable(const QString& tableName, const QString& tableNameOut)
|
||||
{
|
||||
const QMap<QString, CompleteTableInformation> tables = m_structBuilder->getDbTables();
|
||||
for (const CompleteTableInformation &cti : tables)
|
||||
for (const CompleteTableInformation& cti : tables)
|
||||
{
|
||||
if (cti.name != tableName)
|
||||
continue;
|
||||
@@ -86,7 +80,7 @@ bool SqlGenerator::createStatementsForTable(const QString &tableName, const QStr
|
||||
bool SqlGenerator::handleTables()
|
||||
{
|
||||
const QMap<QString, CompleteTableInformation> tables = m_structBuilder->getDbTables();
|
||||
for (const CompleteTableInformation &cti : tables)
|
||||
for (const CompleteTableInformation& cti : tables)
|
||||
{
|
||||
if (!handleTable(cti))
|
||||
return false;
|
||||
@@ -107,7 +101,7 @@ bool SqlGenerator::handleTables()
|
||||
ci.name = QStringLiteral("IDX_sample_time");
|
||||
ci.affectedColumns = QStringList({QStringLiteral("sample_time")});
|
||||
ci.type = ConstraintInformation::Type::index;
|
||||
for (const CompleteTableInformation &cti : recTables)
|
||||
for (const CompleteTableInformation& cti : recTables)
|
||||
{
|
||||
CompleteTableInformation ctiTmp(cti);
|
||||
ctiTmp.columns.push_back(miColumnIsValid);
|
||||
@@ -122,7 +116,7 @@ bool SqlGenerator::handleTables()
|
||||
bool SqlGenerator::handleViews()
|
||||
{
|
||||
const QMap<QString, ViewInformation> views = m_structBuilder->getDbViews();
|
||||
for (const ViewInformation &vi : views)
|
||||
for (const ViewInformation& vi : views)
|
||||
{
|
||||
if (!handleView(vi))
|
||||
return false;
|
||||
@@ -131,7 +125,7 @@ bool SqlGenerator::handleViews()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlGenerator::handleView(const ViewInformation &vi)
|
||||
bool SqlGenerator::handleView(const ViewInformation& vi)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Handle view " << vi.name;
|
||||
|
||||
@@ -150,27 +144,25 @@ bool SqlGenerator::handleView(const ViewInformation &vi)
|
||||
if (!csi.primaryTable.isNull())
|
||||
{
|
||||
QStringList fromTables;
|
||||
fromTables += vi.baseSchema+QLatin1Char('.')+vi.baseTable;
|
||||
fromTables += vi.baseSchema + QLatin1Char('.') + vi.baseTable;
|
||||
|
||||
QStringList whereConditions;
|
||||
if (vi.filter.contains(QLatin1String("exercise_id")))
|
||||
whereConditions += QLatin1String("exercise_id=")+QString::number(m_exerciseId);
|
||||
whereConditions += QLatin1String("exercise_id=") + QString::number(m_exerciseId);
|
||||
|
||||
QStringList fqColumnNames;
|
||||
|
||||
|
||||
for (const MemberInformation &mi : csi.member)
|
||||
for (const MemberInformation& mi : csi.member)
|
||||
{
|
||||
if (mi.db.usedForView)
|
||||
fqColumnNames += mi.db.table + QLatin1Char('.') + mi.db.columnName + QLatin1String(" AS ") + mi.db.getColumnNameView();
|
||||
fqColumnNames += mi.db.table + QLatin1Char('.') + mi.db.columnName + QLatin1String(" AS ") +
|
||||
mi.db.getColumnNameView();
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "fqColumnNames = " << fqColumnNames.join(QStringLiteral(", "));
|
||||
|
||||
|
||||
if (!whereConditions.isEmpty())
|
||||
addToCreateViews(createViewStmt.arg(csi.viewName,
|
||||
fqColumnNames.join(QStringLiteral(", ")),
|
||||
addToCreateViews(createViewStmt.arg(csi.viewName, fqColumnNames.join(QStringLiteral(", ")),
|
||||
fromTables.join(QStringLiteral(", ")),
|
||||
whereConditions.join(QStringLiteral(" AND\n"))),
|
||||
vi.exerciseDependency);
|
||||
@@ -179,10 +171,9 @@ bool SqlGenerator::handleView(const ViewInformation &vi)
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
||||
bool SqlGenerator::handleTable(const CompleteTableInformation& cti)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Handle table " << cti.name;
|
||||
|
||||
@@ -202,20 +193,14 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
||||
|
||||
if ((cti.exerciseDependency & Global) == Global)
|
||||
{
|
||||
addToCreateTables(createTableStmt.arg(cti.name,
|
||||
getTableColumnCreateStatements(cti.name,
|
||||
cti.columns,
|
||||
&tableComments,
|
||||
Global)),
|
||||
addToCreateTables(createTableStmt.arg(
|
||||
cti.name, getTableColumnCreateStatements(cti.name, cti.columns, &tableComments, Global)),
|
||||
Global);
|
||||
}
|
||||
if ((cti.exerciseDependency & Exercise) == Exercise)
|
||||
{
|
||||
addToCreateTables(createTableStmt.arg(cti.name,
|
||||
getTableColumnCreateStatements(cti.name,
|
||||
cti.columns,
|
||||
&tableComments,
|
||||
Exercise)),
|
||||
addToCreateTables(createTableStmt.arg(cti.name, getTableColumnCreateStatements(cti.name, cti.columns,
|
||||
&tableComments, Exercise)),
|
||||
Exercise);
|
||||
}
|
||||
addToTables(cti.name, cti.exerciseDependency);
|
||||
@@ -237,29 +222,29 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
||||
QStringList whereConditions;
|
||||
fromTables += cti.name;
|
||||
|
||||
|
||||
for (const MemberInformation &mi : csi.member)
|
||||
for (const MemberInformation& mi : csi.member)
|
||||
{
|
||||
if (mi.db.usedForView)
|
||||
fqColumnNames += mi.db.table + QLatin1Char('.') + mi.db.columnName + QLatin1String(" AS ") + mi.db.getColumnNameView();
|
||||
fqColumnNames += mi.db.table + QLatin1Char('.') + mi.db.columnName + QLatin1String(" AS ") +
|
||||
mi.db.getColumnNameView();
|
||||
if (mi.cpp.isReadOnly && mi.db.isForeignKey)
|
||||
{
|
||||
|
||||
|
||||
|
||||
for (const QSharedPointer<TableInformation> &tiPtr : csi.tables)
|
||||
for (const QSharedPointer<TableInformation>& tiPtr : csi.tables)
|
||||
{
|
||||
if (tiPtr->name == mi.db.table)
|
||||
{
|
||||
const QSharedPointer<ForeignKeyInformation> fki = tiPtr->fkInformationForColumn(mi.db.table, mi.db.columnName);
|
||||
const QSharedPointer<ForeignKeyInformation> fki =
|
||||
tiPtr->fkInformationForColumn(mi.db.table, mi.db.columnName);
|
||||
if (!fki.isNull())
|
||||
{
|
||||
|
||||
if (!fromTables.contains(fki->destination.tableName))
|
||||
{
|
||||
whereConditions += fki->destination.tableName + QLatin1Char('.') + fki->destination.columnName +
|
||||
QLatin1String(" = ") +
|
||||
fki->source.tableName + QLatin1Char('.') + fki->source.columnName;
|
||||
whereConditions += fki->destination.tableName + QLatin1Char('.') +
|
||||
fki->destination.columnName + QLatin1String(" = ") +
|
||||
fki->source.tableName + QLatin1Char('.') +
|
||||
fki->source.columnName;
|
||||
fromTables += fki->destination.tableName;
|
||||
}
|
||||
}
|
||||
@@ -270,8 +255,7 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
||||
}
|
||||
if (!whereConditions.isEmpty())
|
||||
{
|
||||
addToCreateViews(createViewStmt.arg(csi.viewName,
|
||||
fqColumnNames.join(QStringLiteral(", ")),
|
||||
addToCreateViews(createViewStmt.arg(csi.viewName, fqColumnNames.join(QStringLiteral(", ")),
|
||||
fromTables.join(QStringLiteral(", ")),
|
||||
whereConditions.join(QStringLiteral(" AND\n"))),
|
||||
cti.exerciseDependency);
|
||||
@@ -290,19 +274,16 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
||||
const QVector<MemberInformation> &columns,
|
||||
QStringList *tableComments,
|
||||
ExerciseDependency ed)
|
||||
QString SqlGenerator::getTableColumnCreateStatements(const QString& tableName,
|
||||
const QVector<MemberInformation>& columns,
|
||||
QStringList* tableComments, ExerciseDependency ed)
|
||||
{
|
||||
Q_ASSERT(ed == Global || ed == Exercise);
|
||||
|
||||
const QString commentColumnStmt(QStringLiteral("COMMENT ON COLUMN %1 IS '%2';"));
|
||||
|
||||
|
||||
int maxLength = 1;
|
||||
for (const MemberInformation &mi : columns)
|
||||
for (const MemberInformation& mi : columns)
|
||||
maxLength = std::max(maxLength, static_cast<int>(mi.db.columnName.length()));
|
||||
maxLength += 1;
|
||||
|
||||
@@ -311,8 +292,8 @@ QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
||||
retCols += QString();
|
||||
for (int i = 0; i < columns.size(); ++i)
|
||||
{
|
||||
const MemberInformation &mi = columns.at(i);
|
||||
const FullQualifiedColumnInformation &ci = mi.db;
|
||||
const MemberInformation& mi = columns.at(i);
|
||||
const FullQualifiedColumnInformation& ci = mi.db;
|
||||
const QString spaces(maxLength - ci.columnName.length(), QLatin1Char(' '));
|
||||
QString column = ci.columnName + spaces + ci.datatype;
|
||||
if (ci.hasSequence)
|
||||
@@ -325,8 +306,7 @@ QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
||||
else
|
||||
schema = getExerciseSchemaName(m_exerciseId);
|
||||
|
||||
column += QLatin1String(" DEFAULT nextval(( '") +
|
||||
schema + QLatin1Char('.') + seqDescr +
|
||||
column += QLatin1String(" DEFAULT nextval(( '") + schema + QLatin1Char('.') + seqDescr +
|
||||
QLatin1String("'::text)::regclass)");
|
||||
}
|
||||
if (!ci.canBeNull)
|
||||
@@ -351,36 +331,33 @@ QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
||||
return retCols.join(QStringLiteral("\n "));
|
||||
}
|
||||
|
||||
QString SqlGenerator::generateSequence(const QString &tableName,
|
||||
const FullQualifiedColumnInformation &ci,
|
||||
QString SqlGenerator::generateSequence(const QString& tableName, const FullQualifiedColumnInformation& ci,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
const QString sequenceName = tableName + QLatin1Char('_') + ci.columnName + QLatin1String("_seq");
|
||||
|
||||
|
||||
|
||||
const QString createSequenceStmt(QLatin1String("CREATE SEQUENCE IF NOT EXISTS %1 INCREMENT %2 START %3 MINVALUE %4;"));
|
||||
const QString createSequenceStmt(
|
||||
QLatin1String("CREATE SEQUENCE IF NOT EXISTS %1 INCREMENT %2 START %3 MINVALUE %4;"));
|
||||
|
||||
const int minValue = ci.sequenceStart < 1 ? ci.sequenceStart : 1;
|
||||
|
||||
addToCreateSequences(createSequenceStmt.arg(sequenceName).arg(ci.sequenceIncrement).arg(ci.sequenceStart).arg(minValue), ed);
|
||||
addToCreateSequences(
|
||||
createSequenceStmt.arg(sequenceName).arg(ci.sequenceIncrement).arg(ci.sequenceStart).arg(minValue), ed);
|
||||
addToSequences(sequenceName, ed);
|
||||
|
||||
return sequenceName;
|
||||
}
|
||||
|
||||
void SqlGenerator::generatePrimaryKey(const QString &tableName,
|
||||
const FullQualifiedColumnInformation &ci,
|
||||
void SqlGenerator::generatePrimaryKey(const QString& tableName, const FullQualifiedColumnInformation& ci,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
QString pkName = QLatin1String("PK_") + tableName + QLatin1Char('_') + ci.columnName;
|
||||
|
||||
if (pkName.size() > 63) pkName.resize(63);
|
||||
if (pkName.size() > 63)
|
||||
pkName.resize(63);
|
||||
|
||||
addToPks(pkName, ed);
|
||||
|
||||
|
||||
|
||||
const QString pkConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 ADD CONSTRAINT %2 PRIMARY KEY (%3);"));
|
||||
addToCreatePks(pkConstraint.arg(tableName, pkName, ci.columnName), ed);
|
||||
|
||||
@@ -388,24 +365,21 @@ void SqlGenerator::generatePrimaryKey(const QString &tableName,
|
||||
addToDropConstraints(pkDropConstraint.arg(tableName, pkName), ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation> > &foreignKeys,
|
||||
void SqlGenerator::generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation>>& foreignKeys,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
for (const QSharedPointer<ForeignKeyInformation> &fk : foreignKeys)
|
||||
for (const QSharedPointer<ForeignKeyInformation>& fk : foreignKeys)
|
||||
generateForeignKey(fk, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::generateForeignKey(const QSharedPointer<ForeignKeyInformation> &foreignKey,
|
||||
ExerciseDependency ed)
|
||||
void SqlGenerator::generateForeignKey(const QSharedPointer<ForeignKeyInformation>& foreignKey, ExerciseDependency ed)
|
||||
{
|
||||
QString fkName = QLatin1String("FK_") + foreignKey->source.tableName +
|
||||
QLatin1Char('_') + foreignKey->source.columnName +
|
||||
QLatin1Char('_') + foreignKey->destination.tableName +
|
||||
QString fkName = QLatin1String("FK_") + foreignKey->source.tableName + QLatin1Char('_') +
|
||||
foreignKey->source.columnName + QLatin1Char('_') + foreignKey->destination.tableName +
|
||||
QLatin1Char('_') + foreignKey->destination.columnName;
|
||||
|
||||
|
||||
|
||||
if (fkName.size() > 63) fkName = foreignKey->name;
|
||||
if (fkName.size() > 63)
|
||||
fkName = foreignKey->name;
|
||||
|
||||
addToFks(fkName, ed);
|
||||
|
||||
@@ -431,71 +405,68 @@ void SqlGenerator::generateForeignKey(const QSharedPointer<ForeignKeyInformation
|
||||
|
||||
fkConstraint += QLatin1Char(';');
|
||||
|
||||
|
||||
|
||||
QString destination;
|
||||
if (!foreignKey->destination.schema.isEmpty())
|
||||
{
|
||||
const QString &extSchema = foreignKey->destination.schema;
|
||||
const QString& extSchema = foreignKey->destination.schema;
|
||||
destination = extSchema + QLatin1Char('.') + foreignKey->destination.tableName;
|
||||
}
|
||||
else
|
||||
destination = foreignKey->destination.tableName;
|
||||
|
||||
const QString &extSvcAbbr = foreignKey->destination.serviceAbbr;
|
||||
const QString& extSvcAbbr = foreignKey->destination.serviceAbbr;
|
||||
|
||||
if (!extSvcAbbr.isEmpty() && !m_referencedSevices.contains(extSvcAbbr))
|
||||
m_referencedSevices += extSvcAbbr;
|
||||
|
||||
addToCreateFks(fkConstraint.arg(foreignKey->source.tableName, fkName, foreignKey->source.columnName,
|
||||
destination, foreignKey->destination.columnName), ed);
|
||||
addToCreateFks(fkConstraint.arg(foreignKey->source.tableName, fkName, foreignKey->source.columnName, destination,
|
||||
foreignKey->destination.columnName),
|
||||
ed);
|
||||
|
||||
const QString fkDropConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 DROP CONSTRAINT IF EXISTS %2 CASCADE;"));
|
||||
addToDropConstraints(fkDropConstraint.arg(foreignKey->source.tableName, fkName), ed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SqlGenerator::generateConstraints(const QString &tableName,
|
||||
const QVector<ConstraintInformation> &constraints,
|
||||
void SqlGenerator::generateConstraints(const QString& tableName, const QVector<ConstraintInformation>& constraints,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
for (const ConstraintInformation &constraint : constraints)
|
||||
for (const ConstraintInformation& constraint : constraints)
|
||||
generateConstraint(tableName, constraint, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::generateConstraint(const QString &tableName,
|
||||
const ConstraintInformation &constraint,
|
||||
void SqlGenerator::generateConstraint(const QString& tableName, const ConstraintInformation& constraint,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
const QString dropConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 DROP CONSTRAINT IF EXISTS %2 CASCADE;"));
|
||||
switch (constraint.type)
|
||||
{
|
||||
case ConstraintInformation::Type::index:
|
||||
{
|
||||
case ConstraintInformation::Type::index: {
|
||||
QString constraintName = QLatin1String("IDX_") + tableName + QLatin1Char('_') +
|
||||
constraint.affectedColumns.join(QStringLiteral("_"));
|
||||
|
||||
if (constraintName.size() > 63) constraintName.resize(63);
|
||||
if (constraintName.size() > 63)
|
||||
constraintName.resize(63);
|
||||
|
||||
const QString index(QStringLiteral("CREATE INDEX %1 ON %2 (%3);"));
|
||||
|
||||
addToCreateConstraints(index.arg(constraintName, tableName, constraint.affectedColumns.join(QStringLiteral(", "))), ed);
|
||||
addToCreateConstraints(
|
||||
index.arg(constraintName, tableName, constraint.affectedColumns.join(QStringLiteral(", "))), ed);
|
||||
addToConstraints(constraintName, ed);
|
||||
|
||||
addToDropConstraints(dropConstraint.arg(tableName, constraintName), ed);
|
||||
|
||||
break;
|
||||
}
|
||||
case ConstraintInformation::Type::unique:
|
||||
{
|
||||
case ConstraintInformation::Type::unique: {
|
||||
QString constraintName = QLatin1String("UQ_") + tableName + QLatin1Char('_') +
|
||||
constraint.affectedColumns.join(QStringLiteral("_"));
|
||||
|
||||
if (constraintName.size() > 63) constraintName.resize(63);
|
||||
if (constraintName.size() > 63)
|
||||
constraintName.resize(63);
|
||||
const QString unique(QStringLiteral("ALTER TABLE %1 ADD CONSTRAINT %2 UNIQUE (%3);"));
|
||||
|
||||
addToCreateConstraints(unique.arg(tableName, constraintName, constraint.affectedColumns.join(QStringLiteral(", "))), ed);
|
||||
addToCreateConstraints(
|
||||
unique.arg(tableName, constraintName, constraint.affectedColumns.join(QStringLiteral(", "))), ed);
|
||||
addToConstraints(constraintName, ed);
|
||||
|
||||
addToDropConstraints(dropConstraint.arg(tableName, constraintName), ed);
|
||||
@@ -510,7 +481,7 @@ void SqlGenerator::generateConstraint(const QString &tableName,
|
||||
bool SqlGenerator::handleEnumerations()
|
||||
{
|
||||
const QVector<EnumInformation> enumerations = m_xmlReader->getEnumerations();
|
||||
for (const EnumInformation &ei : enumerations)
|
||||
for (const EnumInformation& ei : enumerations)
|
||||
{
|
||||
if (!handleEnumeration(ei))
|
||||
return false;
|
||||
@@ -518,7 +489,7 @@ bool SqlGenerator::handleEnumerations()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlGenerator::handleEnumeration(const EnumInformation &ei)
|
||||
bool SqlGenerator::handleEnumeration(const EnumInformation& ei)
|
||||
{
|
||||
const QStringList sql = handleEnumeration(ei, QString());
|
||||
if (m_sqlItemsGlobal.tables.contains(ei.tableName))
|
||||
@@ -529,7 +500,7 @@ bool SqlGenerator::handleEnumeration(const EnumInformation &ei)
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList SqlGenerator::handleEnumeration(const EnumInformation &ei, const QString &dbSchema) const
|
||||
QStringList SqlGenerator::handleEnumeration(const EnumInformation& ei, const QString& dbSchema) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Handle enumeration " << ei.enumName;
|
||||
|
||||
@@ -543,26 +514,24 @@ QStringList SqlGenerator::handleEnumeration(const EnumInformation &ei, const QSt
|
||||
const QString columnNames(QStringLiteral("id, name"));
|
||||
const QString tablename = dbSchema.isEmpty() ? ei.tableName : dbSchema + QLatin1Char('.') + ei.tableName;
|
||||
|
||||
|
||||
QStringList enumerationValues;
|
||||
for (const EnumKeyValuePair &evp : ei.values)
|
||||
for (const EnumKeyValuePair& evp : ei.values)
|
||||
{
|
||||
const QString values(QString::number(evp.value) + QLatin1String(", '") +
|
||||
fixupComment(evp.key) + QLatin1Char('\''));
|
||||
const QString values(QString::number(evp.value) + QLatin1String(", '") + fixupComment(evp.key) +
|
||||
QLatin1Char('\''));
|
||||
enumerationValues += insertEnum.arg(tablename, columnNames, values);
|
||||
}
|
||||
|
||||
return enumerationValues;
|
||||
}
|
||||
|
||||
bool SqlGenerator::generateDbNotifications(const QString &tableName,
|
||||
const QVector<DbNotifcationInformation> ¬ifications,
|
||||
bool SqlGenerator::generateDbNotifications(const QString& tableName,
|
||||
const QVector<DbNotifcationInformation>& notifications,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
for (const DbNotifcationInformation ¬ification : notifications)
|
||||
for (const DbNotifcationInformation& notification : notifications)
|
||||
{
|
||||
if (notification.paramNames.isEmpty() ||
|
||||
notification.paramNames.size() > 1)
|
||||
if (notification.paramNames.isEmpty() || notification.paramNames.size() > 1)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Can not handle more than one parameter";
|
||||
continue;
|
||||
@@ -574,8 +543,7 @@ bool SqlGenerator::generateDbNotifications(const QString &tableName,
|
||||
return true;
|
||||
}
|
||||
|
||||
void SqlGenerator::generateDbNotification(const DbNotifcationInformation ¬ification,
|
||||
ExerciseDependency ed)
|
||||
void SqlGenerator::generateDbNotification(const DbNotifcationInformation& notification, ExerciseDependency ed)
|
||||
{
|
||||
const QString func(QStringLiteral("CREATE OR REPLACE FUNCTION public.%1()\n"
|
||||
"RETURNS TRIGGER AS $$\n"
|
||||
@@ -603,8 +571,7 @@ void SqlGenerator::generateDbNotification(const DbNotifcationInformation ¬ifi
|
||||
addToDbFunctions(func.arg(triggerFuncName, notification.methodName, notification.paramNames.first()), ed);
|
||||
}
|
||||
|
||||
bool SqlGenerator::generateDbNotificationTrigger(const QString &tableName,
|
||||
const DbNotifcationInformation ¬ification,
|
||||
bool SqlGenerator::generateDbNotificationTrigger(const QString& tableName, const DbNotifcationInformation& notification,
|
||||
ExerciseDependency ed)
|
||||
{
|
||||
|
||||
@@ -643,7 +610,8 @@ bool SqlGenerator::generateDbNotificationTrigger(const QString &tableName,
|
||||
triggerNameShortcut = QStringLiteral("ad");
|
||||
break;
|
||||
}
|
||||
const QString triggerName(QLatin1String("trg_") + triggerNameShortcut + QLatin1Char('_') + notification.methodName);
|
||||
const QString triggerName(QLatin1String("trg_") + triggerNameShortcut + QLatin1Char('_') +
|
||||
notification.methodName);
|
||||
const QString triggerFuncName(getNotificationFunctionName(notification));
|
||||
addToDbFunctionTrigger(drop.arg(triggerName, tableName), ed);
|
||||
addToDbFunctionTrigger(func.arg(triggerName, when, tableName, triggerFuncName), ed);
|
||||
@@ -651,13 +619,12 @@ bool SqlGenerator::generateDbNotificationTrigger(const QString &tableName,
|
||||
return true;
|
||||
}
|
||||
|
||||
QString SqlGenerator::getNotificationFunctionName(const DbNotifcationInformation ¬ification) const
|
||||
QString SqlGenerator::getNotificationFunctionName(const DbNotifcationInformation& notification) const
|
||||
{
|
||||
return getServiceAbbr() + QLatin1Char('_') + notification.methodName;
|
||||
}
|
||||
|
||||
|
||||
QString SqlGenerator::fixupComment(const QString &comment)
|
||||
QString SqlGenerator::fixupComment(const QString& comment)
|
||||
{
|
||||
|
||||
QString ret = comment;
|
||||
@@ -666,21 +633,19 @@ QString SqlGenerator::fixupComment(const QString &comment)
|
||||
return ret;
|
||||
}
|
||||
|
||||
QStringList SqlGenerator::getDbSettings(const QString &dbSchema) const
|
||||
QStringList SqlGenerator::getDbSettings(const QString& dbSchema) const
|
||||
{
|
||||
QStringList data;
|
||||
|
||||
|
||||
QString dbUser(QStringLiteral("ets_"));
|
||||
if (m_exerciseId > 0)
|
||||
dbUser += QStringLiteral("ex_00");
|
||||
else
|
||||
dbUser += m_xmlReader->getServiceAbbr().toLower();
|
||||
|
||||
|
||||
data.append(QLatin1String("ALTER DEFAULT PRIVILEGES IN SCHEMA ") + dbSchema + QLatin1Char('\n') +
|
||||
QLatin1String(" GRANT SELECT,INSERT,UPDATE,DELETE,TRUNCATE ON TABLES TO ") + dbUser + QLatin1Char(';'));
|
||||
|
||||
QLatin1String(" GRANT SELECT,INSERT,UPDATE,DELETE,TRUNCATE ON TABLES TO ") + dbUser +
|
||||
QLatin1Char(';'));
|
||||
|
||||
data.append(QLatin1String("ALTER DEFAULT PRIVILEGES IN SCHEMA ") + dbSchema + QLatin1Char('\n') +
|
||||
QLatin1String(" GRANT SELECT, REFERENCES ON TABLES TO ets_ro;"));
|
||||
@@ -691,85 +656,79 @@ QStringList SqlGenerator::getDbSettings(const QString &dbSchema) const
|
||||
data.append(QLatin1String("ALTER DEFAULT PRIVILEGES IN SCHEMA ") + dbSchema + QLatin1Char('\n') +
|
||||
QLatin1String(" GRANT ALL ON SEQUENCES TO ") + dbUser + QLatin1Char(';'));
|
||||
|
||||
|
||||
data.append(QLatin1String("SET SEARCH_PATH TO ") + dbSchema + QLatin1String(", PUBLIC;"));
|
||||
|
||||
QStringList deps;
|
||||
deps.reserve(m_referencedSevices.size());
|
||||
for(const QString &svc : m_referencedSevices)
|
||||
for (const QString& svc : m_referencedSevices)
|
||||
deps += QStringLiteral("-- DEPENDS: ") + svc;
|
||||
|
||||
return deps + data;
|
||||
}
|
||||
|
||||
QStringList SqlGenerator::getAllSqlStmts(const QString &dbSchema, ExerciseDependency ed) const
|
||||
QStringList SqlGenerator::getAllSqlStmts(const QString& dbSchema, ExerciseDependency ed) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Creating statements for service " << getServiceAbbr() << " in exercise " << m_exerciseId << ", this: " << this;
|
||||
DEBUG_LOG(m_logger) << "Creating statements for service " << getServiceAbbr() << " in exercise " << m_exerciseId
|
||||
<< ", this: " << this;
|
||||
|
||||
QStringList data;
|
||||
|
||||
const SqlStatements &sql = getStatements(ed);
|
||||
const SqlStatements& sql = getStatements(ed);
|
||||
if (sql.isEmpty())
|
||||
return data;
|
||||
|
||||
if (!dbSchema.isEmpty())
|
||||
data << getDbSettings(dbSchema);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- Drop tables/views/sequences/constraints"));
|
||||
data.append(sql.dropViews);
|
||||
data.append(sql.dropConstraints);
|
||||
data.append(sql.dropTables);
|
||||
data.append(sql.dropSequences);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- Create tables"));
|
||||
data.append(sql.createTables);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- Create sequence(s)"));
|
||||
data.append(sql.createSequences);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- Create primary keys"));
|
||||
data.append(sql.createPrimaryKeys);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- Create foreign keys"));
|
||||
data.append(sql.createForeignKeys);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- Create views"));
|
||||
data.append(sql.createViews);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(
|
||||
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(QStringLiteral("\n-- Inserts for static data i.e. enums\n"));
|
||||
data.append(sql.enumerationValues);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(
|
||||
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(QStringLiteral("\n-- Notify functions for callbacks (signals in db interface)\n"));
|
||||
data.append(sql.dbFunctions);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(
|
||||
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(QStringLiteral("\n-- Notify function trigger for callbacks (signals in db interface)\n"));
|
||||
data.append(sql.dbFunctionTrigger);
|
||||
|
||||
|
||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(
|
||||
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||
data.append(QStringLiteral("\n-- Indexes \n"));
|
||||
data.append(sql.createConstraints);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
QStringList SqlGenerator::getEnumerationInsertValues(const QString &table, const QString &dbSchema) const
|
||||
QStringList SqlGenerator::getEnumerationInsertValues(const QString& table, const QString& dbSchema) const
|
||||
{
|
||||
const QVector<EnumInformation> enumerations = m_xmlReader->getEnumerations();
|
||||
|
||||
for (const EnumInformation &ei : enumerations)
|
||||
for (const EnumInformation& ei : enumerations)
|
||||
{
|
||||
if (ei.tableName == table)
|
||||
return handleEnumeration(ei, dbSchema);
|
||||
@@ -777,44 +736,36 @@ QStringList SqlGenerator::getEnumerationInsertValues(const QString &table, const
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
bool SqlGenerator::writeSqlToFile(const QString &dbSchema, const QString &sqlFile, ExerciseDependency ed) const
|
||||
bool SqlGenerator::writeSqlToFile(const QString& dbSchema, const QString& sqlFile, ExerciseDependency ed) const
|
||||
{
|
||||
return writeFile(sqlFile, getAllSqlStmts(dbSchema, ed).join(QLatin1Char('\n')));
|
||||
}
|
||||
|
||||
bool SqlGenerator::writeSql(const QString &filePath, ExerciseDependency ed)
|
||||
bool SqlGenerator::writeSql(const QString& filePath, ExerciseDependency ed)
|
||||
{
|
||||
Q_ASSERT(ed == Global || ed == Exercise);
|
||||
|
||||
|
||||
QString sqlFile = filePath + getServiceAbbr();
|
||||
if (ed == ExerciseDependency::Exercise)
|
||||
sqlFile += QLatin1Char('_') + getExerciseSchemaName(m_exerciseId);
|
||||
sqlFile += QLatin1String(".sql");
|
||||
|
||||
const SqlStatements &sql = getStatements(ed);
|
||||
const SqlStatements& sql = getStatements(ed);
|
||||
if (sql.isEmpty())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Sql file is emtpy: " << sqlFile;
|
||||
return writeFile(sqlFile, QString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
const QString dbSchema = (ed == ExerciseDependency::Exercise ?
|
||||
getExerciseSchemaName(m_exerciseId) :
|
||||
getServiceAbbr());
|
||||
const QString dbSchema =
|
||||
(ed == ExerciseDependency::Exercise ? getExerciseSchemaName(m_exerciseId) : getServiceAbbr());
|
||||
|
||||
INFO_LOG(m_logger) << "Creating sql-stmt for schema (" << dbSchema << ")";
|
||||
return writeSqlToFile(dbSchema, sqlFile, ed);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
static void addInternal(QStringList &global,
|
||||
QStringList &exercise,
|
||||
const T &stmt,
|
||||
ExerciseDependency ed)
|
||||
template <typename T>
|
||||
static void addInternal(QStringList& global, QStringList& exercise, const T& stmt, ExerciseDependency ed)
|
||||
{
|
||||
switch (ed)
|
||||
{
|
||||
@@ -833,103 +784,102 @@ static void addInternal(QStringList &global,
|
||||
}
|
||||
}
|
||||
|
||||
void SqlGenerator::addToDropSequences(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToDropSequences(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.dropSequences, m_sqlExercise.dropSequences, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToDropTables(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToDropTables(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.dropTables, m_sqlExercise.dropTables, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToDropViews(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToDropViews(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.dropViews, m_sqlExercise.dropViews, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreateConstraints(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreateConstraints(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createConstraints, m_sqlExercise.createConstraints, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToDropConstraints(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToDropConstraints(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.dropConstraints, m_sqlExercise.dropConstraints, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreateFks(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreateFks(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createForeignKeys, m_sqlExercise.createForeignKeys, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreatePks(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreatePks(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createPrimaryKeys, m_sqlExercise.createPrimaryKeys, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreateSequences(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreateSequences(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createSequences, m_sqlExercise.createSequences, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreateTables(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreateTables(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createTables, m_sqlExercise.createTables, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreateTables(const QStringList &stmts, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreateTables(const QStringList& stmts, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createTables, m_sqlExercise.createTables, stmts, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToCreateViews(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToCreateViews(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.createViews, m_sqlExercise.createViews, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToDbFunctions(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToDbFunctions(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.dbFunctions, m_sqlExercise.dbFunctions, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToDbFunctionTrigger(const QString &stmt, ExerciseDependency ed)
|
||||
void SqlGenerator::addToDbFunctionTrigger(const QString& stmt, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlGlobal.dbFunctionTrigger, m_sqlExercise.dbFunctionTrigger, stmt, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToConstraints(const QString &name, ExerciseDependency ed)
|
||||
void SqlGenerator::addToConstraints(const QString& name, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlItemsGlobal.constraints, m_sqlItemsExercise.constraints, name, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToFks(const QString &name, ExerciseDependency ed)
|
||||
void SqlGenerator::addToFks(const QString& name, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlItemsGlobal.foreignKeys, m_sqlItemsExercise.foreignKeys, name, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToPks(const QString &name, ExerciseDependency ed)
|
||||
void SqlGenerator::addToPks(const QString& name, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlItemsGlobal.primaryKeys, m_sqlItemsExercise.primaryKeys, name, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToSequences(const QString &name, ExerciseDependency ed)
|
||||
void SqlGenerator::addToSequences(const QString& name, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlItemsGlobal.sequences, m_sqlItemsExercise.sequences, name, ed);
|
||||
}
|
||||
|
||||
void SqlGenerator::addToTables(const QString &name, ExerciseDependency ed)
|
||||
void SqlGenerator::addToTables(const QString& name, ExerciseDependency ed)
|
||||
{
|
||||
addInternal(m_sqlItemsGlobal.tables, m_sqlItemsExercise.tables, name, ed);
|
||||
}
|
||||
|
||||
bool SqlGenerator::writeFile(const QString &fn, const QString &content) const
|
||||
bool SqlGenerator::writeFile(const QString& fn, const QString& content) const
|
||||
{
|
||||
QFile f(fn);
|
||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: "
|
||||
<< f.errorString();
|
||||
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: " << f.errorString();
|
||||
return false;
|
||||
}
|
||||
f.write(content.toUtf8());
|
||||
|
||||
Executable → Regular
+86
-62
@@ -2,11 +2,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QStringList>
|
||||
#include <QSharedPointer>
|
||||
#include "StructBuilder.h"
|
||||
#include "codegen_base_export.h"
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QStringList>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
@@ -23,7 +24,7 @@ class XmlReader;
|
||||
|
||||
class CODEGEN_BASE_EXPORT SqlGenerator final
|
||||
{
|
||||
public:
|
||||
public:
|
||||
struct SqlStatements
|
||||
{
|
||||
QStringList dropViews;
|
||||
@@ -57,19 +58,22 @@ public:
|
||||
QStringList constraints;
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
Q_DISABLE_COPY(SqlGenerator)
|
||||
|
||||
explicit SqlGenerator(XmlReader *xmlReader, StructBuilder *structBuilder);
|
||||
explicit SqlGenerator(const QString &xmlFile);
|
||||
explicit SqlGenerator(XmlReader* xmlReader, StructBuilder* structBuilder);
|
||||
explicit SqlGenerator(const QString& xmlFile);
|
||||
|
||||
~SqlGenerator();
|
||||
|
||||
bool isValid() const { return m_isValid; }
|
||||
bool isValid() const
|
||||
{
|
||||
return m_isValid;
|
||||
}
|
||||
|
||||
bool generateData(int exerciseId);
|
||||
|
||||
bool createStatementsForTable(const QString &tableName, const QString &tableNameOut);
|
||||
bool createStatementsForTable(const QString& tableName, const QString& tableNameOut);
|
||||
|
||||
SqlStatements getStatements(ExerciseDependency ed) const
|
||||
{
|
||||
@@ -81,83 +85,103 @@ public:
|
||||
return (ed == ExerciseDependency::Exercise ? m_sqlItemsExercise : m_sqlItemsGlobal);
|
||||
}
|
||||
|
||||
QStringList getEnumerationInsertValues(const QString &table, const QString &dbSchema) const;
|
||||
QStringList getEnumerationInsertValues(const QString& table, const QString& dbSchema) const;
|
||||
|
||||
QStringList getReferencedServices() const
|
||||
{
|
||||
return m_referencedSevices;
|
||||
}
|
||||
|
||||
QStringList getDbSettings(const QString &dbSchema) const;
|
||||
QStringList getDbSettings(const QString& dbSchema) const;
|
||||
|
||||
bool writeSql(const QString& filePath, ExerciseDependency ed);
|
||||
|
||||
bool writeSql(const QString &filePath, ExerciseDependency ed);
|
||||
bool writeSqlToFile(const QString& dbSchema, const QString& sqlFile, ExerciseDependency ed) const;
|
||||
|
||||
bool writeSqlToFile(const QString &dbSchema, const QString &sqlFile, ExerciseDependency ed) const;
|
||||
QString getServiceAbbr() const
|
||||
{
|
||||
return m_xmlReader->getServiceAbbr();
|
||||
}
|
||||
|
||||
bool isServiceExerciseIndependent() const
|
||||
{
|
||||
return m_xmlReader->isServiceExerciseIndependent();
|
||||
}
|
||||
|
||||
QString getServiceAbbr() const { return m_xmlReader->getServiceAbbr(); }
|
||||
bool isServiceExerciseIndependent() const { return m_xmlReader->isServiceExerciseIndependent(); }
|
||||
bool isServiceGlobal() const { return (m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::Global || m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::GlobalAndExercise); }
|
||||
CodeGen::ExerciseDependency getExerciseDependency() const { return m_xmlReader->defaultExerciseDependency();}
|
||||
QStringList getGroupNames() const { return m_xmlReader->getGroupNames(); }
|
||||
bool isServiceGlobal() const
|
||||
{
|
||||
return (m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::Global ||
|
||||
m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::GlobalAndExercise);
|
||||
}
|
||||
|
||||
QStringList getAllSqlStmts(const QString &dbSchema, ExerciseDependency ed) const;
|
||||
CodeGen::ExerciseDependency getExerciseDependency() const
|
||||
{
|
||||
return m_xmlReader->defaultExerciseDependency();
|
||||
}
|
||||
|
||||
QStringList getGroupNames() const
|
||||
{
|
||||
return m_xmlReader->getGroupNames();
|
||||
}
|
||||
|
||||
protected:
|
||||
QStringList getAllSqlStmts(const QString& dbSchema, ExerciseDependency ed) const;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
private:
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
|
||||
private:
|
||||
bool handleTables();
|
||||
bool handleViews();
|
||||
bool handleTable(const CompleteTableInformation &cti);
|
||||
bool handleView(const ViewInformation &vi);
|
||||
QString getTableColumnCreateStatements(const QString &tableName,
|
||||
const QVector<MemberInformation> &columns,
|
||||
QStringList *tableComments, ExerciseDependency ed);
|
||||
QString generateSequence(const QString &tableName, const FullQualifiedColumnInformation &ci, ExerciseDependency ed);
|
||||
void generatePrimaryKey(const QString &tableName, const FullQualifiedColumnInformation &ci, ExerciseDependency ed);
|
||||
void generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation> > &foreignKeys, ExerciseDependency ed);
|
||||
void generateForeignKey(const QSharedPointer<ForeignKeyInformation> &foreignKey, ExerciseDependency ed);
|
||||
void generateConstraints(const QString &tableName, const QVector<ConstraintInformation> &constraints, ExerciseDependency ed);
|
||||
void generateConstraint(const QString &tableName, const ConstraintInformation &constraint, ExerciseDependency ed);
|
||||
bool handleTable(const CompleteTableInformation& cti);
|
||||
bool handleView(const ViewInformation& vi);
|
||||
QString getTableColumnCreateStatements(const QString& tableName, const QVector<MemberInformation>& columns,
|
||||
QStringList* tableComments, ExerciseDependency ed);
|
||||
QString generateSequence(const QString& tableName, const FullQualifiedColumnInformation& ci, ExerciseDependency ed);
|
||||
void generatePrimaryKey(const QString& tableName, const FullQualifiedColumnInformation& ci, ExerciseDependency ed);
|
||||
void generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation>>& foreignKeys, ExerciseDependency ed);
|
||||
void generateForeignKey(const QSharedPointer<ForeignKeyInformation>& foreignKey, ExerciseDependency ed);
|
||||
void generateConstraints(const QString& tableName, const QVector<ConstraintInformation>& constraints,
|
||||
ExerciseDependency ed);
|
||||
void generateConstraint(const QString& tableName, const ConstraintInformation& constraint, ExerciseDependency ed);
|
||||
bool handleEnumerations();
|
||||
bool handleEnumeration(const EnumInformation &ei);
|
||||
QStringList handleEnumeration(const EnumInformation &ei, const QString &dbSchema) const;
|
||||
bool generateDbNotifications(const QString &tableName, const QVector<DbNotifcationInformation> ¬ifications, ExerciseDependency ed);
|
||||
void generateDbNotification(const DbNotifcationInformation ¬ification, ExerciseDependency ed);
|
||||
bool generateDbNotificationTrigger(const QString &tableName, const DbNotifcationInformation ¬ification, ExerciseDependency ed);
|
||||
QString getNotificationFunctionName(const DbNotifcationInformation ¬ification) const;
|
||||
static QString fixupComment(const QString &comment);
|
||||
bool handleEnumeration(const EnumInformation& ei);
|
||||
QStringList handleEnumeration(const EnumInformation& ei, const QString& dbSchema) const;
|
||||
bool generateDbNotifications(const QString& tableName, const QVector<DbNotifcationInformation>& notifications,
|
||||
ExerciseDependency ed);
|
||||
void generateDbNotification(const DbNotifcationInformation& notification, ExerciseDependency ed);
|
||||
bool generateDbNotificationTrigger(const QString& tableName, const DbNotifcationInformation& notification,
|
||||
ExerciseDependency ed);
|
||||
QString getNotificationFunctionName(const DbNotifcationInformation& notification) const;
|
||||
static QString fixupComment(const QString& comment);
|
||||
|
||||
private:
|
||||
XmlReader *m_xmlReader;
|
||||
StructBuilder *m_structBuilder;
|
||||
private:
|
||||
XmlReader* m_xmlReader;
|
||||
StructBuilder* m_structBuilder;
|
||||
bool m_createdByXmlFile;
|
||||
|
||||
void addToDropSequences(const QString &stmt, ExerciseDependency ed);
|
||||
void addToDropTables(const QString &stmt, ExerciseDependency ed);
|
||||
void addToDropViews(const QString &stmt, ExerciseDependency ed);
|
||||
void addToDropConstraints(const QString &stmt, ExerciseDependency ed);
|
||||
void addToDropSequences(const QString& stmt, ExerciseDependency ed);
|
||||
void addToDropTables(const QString& stmt, ExerciseDependency ed);
|
||||
void addToDropViews(const QString& stmt, ExerciseDependency ed);
|
||||
void addToDropConstraints(const QString& stmt, ExerciseDependency ed);
|
||||
|
||||
void addToCreateConstraints(const QString &stmt, ExerciseDependency ed);
|
||||
void addToCreateFks(const QString &stmt, ExerciseDependency ed);
|
||||
void addToCreatePks(const QString &stmt, ExerciseDependency ed);
|
||||
void addToCreateSequences(const QString &stmt, ExerciseDependency ed);
|
||||
void addToCreateTables(const QString &stmt, ExerciseDependency ed);
|
||||
void addToCreateTables(const QStringList &stmts, ExerciseDependency ed);
|
||||
void addToCreateViews(const QString &stmt, ExerciseDependency ed);
|
||||
void addToCreateConstraints(const QString& stmt, ExerciseDependency ed);
|
||||
void addToCreateFks(const QString& stmt, ExerciseDependency ed);
|
||||
void addToCreatePks(const QString& stmt, ExerciseDependency ed);
|
||||
void addToCreateSequences(const QString& stmt, ExerciseDependency ed);
|
||||
void addToCreateTables(const QString& stmt, ExerciseDependency ed);
|
||||
void addToCreateTables(const QStringList& stmts, ExerciseDependency ed);
|
||||
void addToCreateViews(const QString& stmt, ExerciseDependency ed);
|
||||
|
||||
void addToDbFunctions(const QString &stmt, ExerciseDependency ed);
|
||||
void addToDbFunctionTrigger(const QString &stmt, ExerciseDependency ed);
|
||||
void addToDbFunctions(const QString& stmt, ExerciseDependency ed);
|
||||
void addToDbFunctionTrigger(const QString& stmt, ExerciseDependency ed);
|
||||
|
||||
void addToConstraints(const QString &name, ExerciseDependency ed);
|
||||
void addToFks(const QString &name, ExerciseDependency ed);
|
||||
void addToPks(const QString &name, ExerciseDependency ed);
|
||||
void addToSequences(const QString &name, ExerciseDependency ed);
|
||||
void addToTables(const QString &name, ExerciseDependency ed);
|
||||
void addToConstraints(const QString& name, ExerciseDependency ed);
|
||||
void addToFks(const QString& name, ExerciseDependency ed);
|
||||
void addToPks(const QString& name, ExerciseDependency ed);
|
||||
void addToSequences(const QString& name, ExerciseDependency ed);
|
||||
void addToTables(const QString& name, ExerciseDependency ed);
|
||||
|
||||
bool writeFile(const QString &fn, const QString &content) const;
|
||||
bool writeFile(const QString& fn, const QString& content) const;
|
||||
|
||||
SqlStatements m_sqlGlobal;
|
||||
SqlStatements m_sqlExercise;
|
||||
@@ -171,4 +195,4 @@ private:
|
||||
int m_exerciseId;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+203
-273
File diff suppressed because it is too large.
Load diff
Executable → Regular
+161
-117
@@ -2,10 +2,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include "XmlReader.h"
|
||||
#include "codegen_base_export.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
@@ -23,9 +24,7 @@ struct EaData
|
||||
|
||||
QString toString() const
|
||||
{
|
||||
return table +
|
||||
QLatin1Char(';') + column +
|
||||
QLatin1Char(';') + type;
|
||||
return table + QLatin1Char(';') + column + QLatin1Char(';') + type;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -36,52 +35,81 @@ struct FullQualifiedColumnInformation : public ColumnInformation
|
||||
bool usedForView = false;
|
||||
QString columnNameView;
|
||||
|
||||
QString getColumnNameView() const { return columnNameView.isEmpty() ? columnName : columnNameView; }
|
||||
QString getColumnNameView() const
|
||||
{
|
||||
return columnNameView.isEmpty() ? columnName : columnNameView;
|
||||
}
|
||||
|
||||
FullQualifiedColumnInformation() = default;
|
||||
FullQualifiedColumnInformation(const ColumnInformation &ci, const QString &tableName)
|
||||
: ColumnInformation(ci)
|
||||
, table(tableName)
|
||||
{}
|
||||
|
||||
FullQualifiedColumnInformation(const ColumnInformation& ci, const QString& tableName)
|
||||
: ColumnInformation(ci), table(tableName)
|
||||
{
|
||||
}
|
||||
|
||||
QString toString() const
|
||||
{
|
||||
return table +
|
||||
QLatin1Char(';') + columnName +
|
||||
QLatin1Char(';') + datatype +
|
||||
return table + QLatin1Char(';') + columnName + QLatin1Char(';') + datatype +
|
||||
|
||||
QLatin1Char(';') + (isPrimaryKey ? QLatin1String("true") : QLatin1String("false")) +
|
||||
QLatin1Char(';') + (isForeignKey ? QLatin1String("true") : QLatin1String("false")) +
|
||||
QLatin1Char(';') + (usedForInsert ? QLatin1String("true") : QLatin1String("false")) +
|
||||
QLatin1Char(';') + (usedForView ? QLatin1String("true") : QLatin1String("false"));
|
||||
QLatin1Char(';') + (isPrimaryKey ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||
(isForeignKey ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||
(usedForInsert ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||
(usedForView ? QLatin1String("true") : QLatin1String("false"));
|
||||
}
|
||||
};
|
||||
|
||||
class DataTypeInfo
|
||||
{
|
||||
public:
|
||||
DataTypeInfo(const QString &name, bool isPod)
|
||||
: m_name(name)
|
||||
, m_isPod(isPod)
|
||||
{}
|
||||
public:
|
||||
DataTypeInfo(const QString& name, bool isPod) : m_name(name), m_isPod(isPod) {}
|
||||
|
||||
virtual ~DataTypeInfo() = default;
|
||||
virtual QString name() const { return m_name; }
|
||||
|
||||
virtual QString name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
virtual QString idlType() const = 0;
|
||||
virtual QString ddsType() const = 0;
|
||||
virtual QString sqlType() const = 0;
|
||||
virtual QString cppType() const = 0;
|
||||
virtual QString cppTypeConstRef() const { return isPod() ? cppType() : QLatin1String("const ") + cppType() + QLatin1String(" &"); }
|
||||
virtual bool isPod() const { return m_isPod; }
|
||||
virtual bool isSequence() const { return false; }
|
||||
virtual bool isStructure() const { return false; }
|
||||
virtual QVector<QSharedPointer<DataTypeInfo>> member() const { return QVector<QSharedPointer<DataTypeInfo>>(); }
|
||||
virtual QSharedPointer<DataTypeInfo> innerDataType() const { return QSharedPointer<DataTypeInfo>(); }
|
||||
|
||||
static QSharedPointer<DataTypeInfo> fromIdlDataType(const QString &name,
|
||||
const QString &idlType,
|
||||
StructBuilder *structBuilder,
|
||||
const QString &svcName = QString());
|
||||
protected:
|
||||
virtual QString cppTypeConstRef() const
|
||||
{
|
||||
return isPod() ? cppType() : QLatin1String("const ") + cppType() + QLatin1String(" &");
|
||||
}
|
||||
|
||||
virtual bool isPod() const
|
||||
{
|
||||
return m_isPod;
|
||||
}
|
||||
|
||||
virtual bool isSequence() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool isStructure() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual QVector<QSharedPointer<DataTypeInfo>> member() const
|
||||
{
|
||||
return QVector<QSharedPointer<DataTypeInfo>>();
|
||||
}
|
||||
|
||||
virtual QSharedPointer<DataTypeInfo> innerDataType() const
|
||||
{
|
||||
return QSharedPointer<DataTypeInfo>();
|
||||
}
|
||||
|
||||
static QSharedPointer<DataTypeInfo> fromIdlDataType(const QString& name, const QString& idlType,
|
||||
StructBuilder* structBuilder,
|
||||
const QString& svcName = QString());
|
||||
|
||||
protected:
|
||||
const QString m_name;
|
||||
const bool m_isPod;
|
||||
};
|
||||
@@ -91,22 +119,18 @@ struct IdlData : public IdlColumnInformation
|
||||
QSharedPointer<DataTypeInfo> dataTypeInfo;
|
||||
|
||||
IdlData() = default;
|
||||
explicit IdlData(const IdlColumnInformation &ci)
|
||||
: IdlColumnInformation(ci)
|
||||
{}
|
||||
|
||||
explicit IdlData(const IdlColumnInformation& ci) : IdlColumnInformation(ci) {}
|
||||
|
||||
QString toString() const
|
||||
{
|
||||
return name +
|
||||
QLatin1Char(';') + type +
|
||||
return name + QLatin1Char(';') + type +
|
||||
|
||||
QLatin1Char(';') + (isKey ? QLatin1String("true") : QLatin1String("false")) +
|
||||
QLatin1Char(';') + (isOptional ? QLatin1String("true") : QLatin1String("false"));
|
||||
QLatin1Char(';') + (isKey ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||
(isOptional ? QLatin1String("true") : QLatin1String("false"));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct CppData
|
||||
{
|
||||
QString structName;
|
||||
@@ -131,16 +155,11 @@ struct CppData
|
||||
|
||||
QString toString() const
|
||||
{
|
||||
return structName +
|
||||
QLatin1Char(';') + memberName +
|
||||
QLatin1Char(';') + (usedForCppStruct ? QLatin1String("true") : QLatin1String("false")) +
|
||||
QLatin1Char(';') + (isReadOnly ? QLatin1String("true") : QLatin1String("false")) +
|
||||
QLatin1Char(';') + type +
|
||||
QLatin1Char(';') + toVariantPre +
|
||||
QLatin1Char(';') + toVariantPost +
|
||||
QLatin1Char(';') + fromVariantPre1 +
|
||||
QLatin1Char(';') + fromVariantPre2 +
|
||||
QLatin1Char(';') + fromVariantPost;
|
||||
return structName + QLatin1Char(';') + memberName + QLatin1Char(';') +
|
||||
(usedForCppStruct ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||
(isReadOnly ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') + type +
|
||||
QLatin1Char(';') + toVariantPre + QLatin1Char(';') + toVariantPost + QLatin1Char(';') + fromVariantPre1 +
|
||||
QLatin1Char(';') + fromVariantPre2 + QLatin1Char(';') + fromVariantPost;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -155,10 +174,9 @@ struct MemberInformation
|
||||
|
||||
QString toString() const
|
||||
{
|
||||
return ea.toString() + QLatin1Char(';') +
|
||||
db.toString() + QLatin1Char(';') +
|
||||
cpp.toString();
|
||||
return ea.toString() + QLatin1Char(';') + db.toString() + QLatin1Char(';') + cpp.toString();
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return ea.column.isEmpty();
|
||||
@@ -169,7 +187,7 @@ struct CompleteStructInformation
|
||||
{
|
||||
QString structName;
|
||||
QString viewName;
|
||||
QSet<QSharedPointer<TableInformation> > tables;
|
||||
QSet<QSharedPointer<TableInformation>> tables;
|
||||
QSharedPointer<TableInformation> primaryTable;
|
||||
QVector<MemberInformation> member;
|
||||
QVector<DbNotifcationInformation> dbNotifications;
|
||||
@@ -188,23 +206,32 @@ struct CompleteTopicTypeInformation final : public TopicTypeInformationBase
|
||||
QVector<IdlData> members;
|
||||
|
||||
CompleteTopicTypeInformation() = default;
|
||||
explicit CompleteTopicTypeInformation(const TopicTypeInformationBase &s)
|
||||
: TopicTypeInformationBase(s)
|
||||
{}
|
||||
|
||||
bool hasBaseValue() const { return !baseValueType.isEmpty(); }
|
||||
bool isValid() const { return TopicTypeInformationBase::isValid() && !members.isEmpty(); }
|
||||
explicit CompleteTopicTypeInformation(const TopicTypeInformationBase& s) : TopicTypeInformationBase(s) {}
|
||||
|
||||
bool hasBaseValue() const
|
||||
{
|
||||
return !baseValueType.isEmpty();
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return TopicTypeInformationBase::isValid() && !members.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CompleteTableInformation : public TableInformation
|
||||
{
|
||||
QVector<MemberInformation> columns;
|
||||
explicit CompleteTableInformation(const TableInformation &o)
|
||||
: TableInformation(o)
|
||||
{}
|
||||
|
||||
explicit CompleteTableInformation(const TableInformation& o) : TableInformation(o) {}
|
||||
|
||||
CompleteTableInformation() = default;
|
||||
bool isEmpty() const { return columns.isEmpty(); }
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return columns.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
class CODEGEN_BASE_EXPORT StructBuilder
|
||||
@@ -214,43 +241,57 @@ class CODEGEN_BASE_EXPORT StructBuilder
|
||||
QSharedPointer<TableInformation> table;
|
||||
|
||||
ColumnInformationEx() = default;
|
||||
ColumnInformationEx(const ColumnInformation &o,
|
||||
const QSharedPointer<TableInformation> &ti)
|
||||
: ColumnInformation(o)
|
||||
, table(ti)
|
||||
{}
|
||||
|
||||
ColumnInformationEx(const ColumnInformation& o, const QSharedPointer<TableInformation>& ti)
|
||||
: ColumnInformation(o), table(ti)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
struct ServiceTypeStruct
|
||||
{
|
||||
QString service;
|
||||
QString type;
|
||||
bool bIsSequence = false;
|
||||
bool isExternalType() const { return !service.isEmpty(); }
|
||||
bool isSequence() const { return bIsSequence; }
|
||||
QString fqType() const { return service + QStringLiteral("::") + type; }
|
||||
|
||||
bool isExternalType() const
|
||||
{
|
||||
return !service.isEmpty();
|
||||
}
|
||||
|
||||
bool isSequence() const
|
||||
{
|
||||
return bIsSequence;
|
||||
}
|
||||
|
||||
QString fqType() const
|
||||
{
|
||||
return service + QStringLiteral("::") + type;
|
||||
}
|
||||
};
|
||||
|
||||
explicit StructBuilder(XmlReader *xmlReader);
|
||||
explicit StructBuilder(XmlReader* xmlReader);
|
||||
~StructBuilder() = default;
|
||||
|
||||
bool buildStructures();
|
||||
|
||||
QVector<CompleteStructInformation> structInformations() const
|
||||
{
|
||||
return m_structInfos;
|
||||
}
|
||||
|
||||
QVector<CompleteTopicTypeInformation> topicTypeInformations() const
|
||||
{
|
||||
return m_topicTypeInfos;
|
||||
}
|
||||
|
||||
CompleteStructInformation structInformationByTableName(const QString &tableName) const;
|
||||
CompleteStructInformation structInformationByTableName(const QString& tableName) const;
|
||||
|
||||
EnumInformation enumInformationByType(const QString &type, bool checkExternals = true, bool verbose = true);
|
||||
EnumInformation enumInformationByType(const QString& type, bool checkExternals = true, bool verbose = true);
|
||||
|
||||
CompleteTopicTypeInformation topicTypeInformationByStructType(const QString &type, bool checkExternals = true);
|
||||
CompleteTopicTypeInformation externalTopicTypeByStructType(const ServiceTypeStruct &sts);
|
||||
CompleteTopicTypeInformation topicTypeInformationByStructType(const QString& type, bool checkExternals = true);
|
||||
CompleteTopicTypeInformation externalTopicTypeByStructType(const ServiceTypeStruct& sts);
|
||||
|
||||
QVector<EnumInformation> enumInformations() const
|
||||
{
|
||||
@@ -277,49 +318,52 @@ public:
|
||||
return m_needPgArrayInclude;
|
||||
}
|
||||
|
||||
CompleteTableInformation completeTableInformation(const CompleteTopicTypeInformation &ctti);
|
||||
CompleteTableInformation getRecordingTopicTable(const QString &structName);
|
||||
CompleteTableInformation completeTableInformation(const CompleteTopicTypeInformation& ctti);
|
||||
CompleteTableInformation getRecordingTopicTable(const QString& structName);
|
||||
QMap<QString, CompleteTableInformation> getRecordingTopicTables();
|
||||
QVector<QSharedPointer<DataTypeInfo> > getSerializeFromToJsonTopics() const;
|
||||
bool fixupQVariantConversions(MemberInformation &mi) const;
|
||||
QVector<QSharedPointer<DataTypeInfo>> getSerializeFromToJsonTopics() const;
|
||||
bool fixupQVariantConversions(MemberInformation& mi) const;
|
||||
|
||||
Q_REQUIRED_RESULT static QString firstCharLowercase(const QString &txt);
|
||||
Q_REQUIRED_RESULT static QString camelCaseString(const QString &in, bool bFirstUppercase = false);
|
||||
Q_REQUIRED_RESULT static QString camelCaseToUnderline(const QString &in);
|
||||
Q_REQUIRED_RESULT static QString firstCharLowercase(const QString& txt);
|
||||
Q_REQUIRED_RESULT static QString camelCaseString(const QString& in, bool bFirstUppercase = false);
|
||||
Q_REQUIRED_RESULT static QString camelCaseToUnderline(const QString& in);
|
||||
|
||||
bool buildJSonStructureInformationFromIdlData(const CompleteTopicTypeInformation &ctti);
|
||||
QMap<QString, QVector<MemberInformation>> jsonStructureInformation() const { return m_jsonStructureInformation; }
|
||||
bool buildJSonStructureInformationFromIdlData(const CompleteTopicTypeInformation& ctti);
|
||||
|
||||
private:
|
||||
bool handleEnum(const EnumInformation &ei);
|
||||
bool handleTable(const ServiceStructInformation &ssi);
|
||||
bool handleIdlStructInfo(const TopicTypeInformation &tti,
|
||||
QVector<CompleteTopicTypeInformation> &destination,
|
||||
const QString &svcName = QString());
|
||||
bool loadExternalTopicType(const ServiceTypeStruct &sts);
|
||||
QMap<QString, QVector<MemberInformation>> jsonStructureInformation() const
|
||||
{
|
||||
return m_jsonStructureInformation;
|
||||
}
|
||||
|
||||
bool getColumnsFromTable(const QString &tableName,
|
||||
QVector<ColumnInformationEx> &columns,
|
||||
QVector<QString> &tableNames) const;
|
||||
private:
|
||||
bool handleEnum(const EnumInformation& ei);
|
||||
bool handleTable(const ServiceStructInformation& ssi);
|
||||
bool handleIdlStructInfo(const TopicTypeInformation& tti, QVector<CompleteTopicTypeInformation>& destination,
|
||||
const QString& svcName = QString());
|
||||
bool loadExternalTopicType(const ServiceTypeStruct& sts);
|
||||
|
||||
bool fixupCustomDbDatatypes(MemberInformation &memberInfo, QVector<MemberInformation> &members);
|
||||
bool fixupDatatypePoint2d(MemberInformation &memberInfo, QVector<MemberInformation> &members);
|
||||
bool fixupDatatypePoint3d(MemberInformation &memberInfo, QVector<MemberInformation> &members);
|
||||
bool fixupDatatypeIntegerArray(MemberInformation &memberInfo);
|
||||
bool getColumnsFromTable(const QString& tableName, QVector<ColumnInformationEx>& columns,
|
||||
QVector<QString>& tableNames) const;
|
||||
|
||||
QVector<MemberInformation> buildDbTableInformationFromIdlData(const CompleteTopicTypeInformation &ctti,
|
||||
const QString &tableName,
|
||||
const QString &columnNamePrefix,
|
||||
const QString &cppStructure);
|
||||
void addToSerializeFromToJsonTopics(const QSharedPointer<DataTypeInfo> &toAdd);
|
||||
CompleteTableInformation getRecordingTopicTable(const CompleteTopicTypeInformation &ctti,
|
||||
const MemberInformation &miPrimaryKey);
|
||||
bool fixupCustomDbDatatypes(MemberInformation& memberInfo, QVector<MemberInformation>& members);
|
||||
bool fixupDatatypePoint2d(MemberInformation& memberInfo, QVector<MemberInformation>& members);
|
||||
bool fixupDatatypePoint3d(MemberInformation& memberInfo, QVector<MemberInformation>& members);
|
||||
bool fixupDatatypeIntegerArray(MemberInformation& memberInfo);
|
||||
|
||||
QVector<MemberInformation> buildDbTableInformationFromIdlData(const CompleteTopicTypeInformation& ctti,
|
||||
const QString& tableName,
|
||||
const QString& columnNamePrefix,
|
||||
const QString& cppStructure);
|
||||
void addToSerializeFromToJsonTopics(const QSharedPointer<DataTypeInfo>& toAdd);
|
||||
CompleteTableInformation getRecordingTopicTable(const CompleteTopicTypeInformation& ctti,
|
||||
const MemberInformation& miPrimaryKey);
|
||||
MemberInformation getRecordPrimaryKey() const;
|
||||
|
||||
ServiceTypeStruct extractServiceAndTypeFromTypename(const QString &type);
|
||||
ServiceTypeStruct extractServiceAndTypeFromTypename(const QString& type);
|
||||
|
||||
void addToSqlTableInformation(const MemberInformation &mi);
|
||||
private:
|
||||
void addToSqlTableInformation(const MemberInformation& mi);
|
||||
|
||||
private:
|
||||
QVector<CompleteStructInformation> m_structInfos;
|
||||
QVector<CompleteTopicTypeInformation> m_topicTypeInfos;
|
||||
mutable QVector<CompleteTopicTypeInformation> m_externalTopicTypes;
|
||||
@@ -334,8 +378,8 @@ private:
|
||||
bool m_needPoint3d;
|
||||
bool m_needPgArrayInclude;
|
||||
|
||||
XmlReader *m_xmlReader;
|
||||
NGL::INGLLogger &m_logger;
|
||||
NGL::INGLLogger &m_loggerCSV;
|
||||
XmlReader* m_xmlReader;
|
||||
NGL::INGLLogger& m_logger;
|
||||
NGL::INGLLogger& m_loggerCSV;
|
||||
};
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+96
-132
@@ -1,41 +1,36 @@
|
||||
|
||||
|
||||
#include "XmlReader.h"
|
||||
#include <utility>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <QFile>
|
||||
#include <QDomDocument>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
#include <ngltools/ngltools_filesystem.h>
|
||||
#include <utility>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
|
||||
class XmlReaderException : public std::exception
|
||||
{
|
||||
public:
|
||||
explicit XmlReaderException(const QString &msg) noexcept
|
||||
: m_msg(msg.toUtf8())
|
||||
{}
|
||||
public:
|
||||
explicit XmlReaderException(const QString& msg) noexcept : m_msg(msg.toUtf8()) {}
|
||||
|
||||
~XmlReaderException() = default;
|
||||
|
||||
virtual const char *what() const noexcept
|
||||
virtual const char* what() const noexcept
|
||||
{
|
||||
return m_msg.data();
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
const QByteArray m_msg;
|
||||
};
|
||||
|
||||
XmlReader::XmlReader() : m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
|
||||
|
||||
bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
const QString &idlServiceInfoFile,
|
||||
const XmlReader *parent)
|
||||
bool XmlReader::readServiceFile(const QString& svcFile, const QString& idlServiceInfoFile, const XmlReader* parent)
|
||||
{
|
||||
m_externalXmlInformations.clear();
|
||||
m_idlFiles.clear();
|
||||
@@ -61,7 +56,6 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
m_prio = 0;
|
||||
m_svcDevMode = false;
|
||||
|
||||
|
||||
if (parent)
|
||||
{
|
||||
m_idlFiles = parent->m_idlFiles;
|
||||
@@ -70,11 +64,8 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
m_externalXmlInformations = parent->m_externalXmlInformations;
|
||||
}
|
||||
|
||||
|
||||
|
||||
loadIdlInfofile(idlServiceInfoFile);
|
||||
|
||||
|
||||
QFile f(svcFile);
|
||||
if (!f.exists())
|
||||
{
|
||||
@@ -83,35 +74,27 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
}
|
||||
if (!f.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_errorString = QLatin1String("Can not open service file '") + svcFile +
|
||||
QLatin1String("' for reading: ") + f.errorString();
|
||||
m_errorString =
|
||||
QLatin1String("Can not open service file '") + svcFile + QLatin1String("' for reading: ") + f.errorString();
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
return false;
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "SvcFile: " << svcFile;
|
||||
|
||||
|
||||
QString errMsg;
|
||||
int errLine = 0;
|
||||
int errColumn = 0;
|
||||
QDomDocument doc;
|
||||
if (!doc.setContent(&f, &errMsg, &errLine, &errColumn))
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing service file '") + svcFile + QLatin1String("': ") +
|
||||
errMsg + QLatin1String(" at ") + QString::number(errLine) +
|
||||
QLatin1Char(':') + QString::number(errColumn);
|
||||
m_errorString = QLatin1String("Error parsing service file '") + svcFile + QLatin1String("': ") + errMsg +
|
||||
QLatin1String(" at ") + QString::number(errLine) + QLatin1Char(':') +
|
||||
QString::number(errColumn);
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QDomElement domRoot = doc.documentElement();
|
||||
if (!domRoot.hasAttribute(QStringLiteral("namespace")))
|
||||
{
|
||||
@@ -126,8 +109,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
m_customRecordReplay = getAttributeBool(domRoot, QStringLiteral("customRecordReplay"), true, false);
|
||||
|
||||
QString devModeStr = getAttribute(domRoot, QStringLiteral("devMode"), true);
|
||||
m_svcDevMode = devModeStr == QStringLiteral("1") ||
|
||||
devModeStr == QStringLiteral("true");
|
||||
m_svcDevMode = devModeStr == QStringLiteral("1") || devModeStr == QStringLiteral("true");
|
||||
INFO_LOG(m_logger) << "devMode: " << m_svcDevMode;
|
||||
|
||||
const QString groupNamesString = getAttribute(domRoot, QStringLiteral("groups"), true);
|
||||
@@ -141,21 +123,19 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
|
||||
m_exerciseDependency = string2ExerciseDependency(getAttribute(domRoot, QStringLiteral("exerciseDependency"), true));
|
||||
|
||||
|
||||
|
||||
if (m_groupNames.contains(QStringLiteral("Core")) ||
|
||||
m_groupNames.contains(QStringLiteral("Master")))
|
||||
if (m_groupNames.contains(QStringLiteral("Core")) || m_groupNames.contains(QStringLiteral("Master")))
|
||||
{
|
||||
if (m_exerciseDependency != ExerciseDependency::Global &&
|
||||
m_exerciseDependency != ExerciseDependency::GlobalAndExercise)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Service " << getServiceNamespace()
|
||||
WARNING_LOG(m_logger)
|
||||
<< "Service " << getServiceNamespace()
|
||||
<< " is not marked as exercise independent but should be started in group Core/Master";
|
||||
}
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "exerciseDependency: " << (int)m_exerciseDependency;
|
||||
if ( domRoot.hasAttribute(QStringLiteral("prio")))
|
||||
if (domRoot.hasAttribute(QStringLiteral("prio")))
|
||||
{
|
||||
m_prio = getAttribute(domRoot, QStringLiteral("prio"), 0).toInt();
|
||||
}
|
||||
@@ -163,7 +143,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseDBSserviceStructs(domRoot.firstChildElement(QStringLiteral("dbServiceStructs")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing dbServiceStructs: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -174,7 +154,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseDBTables(domRoot.firstChildElement(QStringLiteral("tables")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing dbtables: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -185,7 +165,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseDBViews(domRoot.firstChildElement(QStringLiteral("views")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing dbviews: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -196,7 +176,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseEnumerations(domRoot.firstChildElement(QStringLiteral("enumerations")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing enumerations: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -207,7 +187,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseCustomDtcFunctions(domRoot.firstChildElement(QStringLiteral("customDtcFunctions")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing custom dtc functions: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -218,7 +198,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseTopicTypes(domRoot.firstChildElement(QStringLiteral("topicTypes")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing idl strucs: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -229,7 +209,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
{
|
||||
parseFunctionTopics(domRoot.firstChildElement(QStringLiteral("functionTopics")));
|
||||
}
|
||||
catch (const XmlReaderException &ex)
|
||||
catch (const XmlReaderException& ex)
|
||||
{
|
||||
m_errorString = QLatin1String("Error parsing function topics: ") + QLatin1String(ex.what());
|
||||
ERROR_LOG(m_logger) << m_errorString;
|
||||
@@ -239,23 +219,20 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
||||
return true;
|
||||
}
|
||||
|
||||
QString XmlReader::getAttribute(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional)
|
||||
QString XmlReader::getAttribute(const QDomElement& element, const QString& attributeName, bool bOptional)
|
||||
{
|
||||
if (!element.hasAttribute(attributeName))
|
||||
{
|
||||
if (bOptional)
|
||||
return QString();
|
||||
throw XmlReaderException(QLatin1String("Element ") + element.tagName() +
|
||||
QLatin1String(" has no attribute ") + attributeName);
|
||||
throw XmlReaderException(QLatin1String("Element ") + element.tagName() + QLatin1String(" has no attribute ") +
|
||||
attributeName);
|
||||
}
|
||||
return element.attribute(attributeName);
|
||||
}
|
||||
|
||||
bool XmlReader::getAttributeBool(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional, bool defaultValue)
|
||||
bool XmlReader::getAttributeBool(const QDomElement& element, const QString& attributeName, bool bOptional,
|
||||
bool defaultValue)
|
||||
{
|
||||
QString str = getAttribute(element, attributeName, bOptional);
|
||||
if (str.isEmpty())
|
||||
@@ -267,9 +244,8 @@ bool XmlReader::getAttributeBool(const QDomElement &element,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int XmlReader::getAttributeInt(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional, int defaultValue)
|
||||
int XmlReader::getAttributeInt(const QDomElement& element, const QString& attributeName, bool bOptional,
|
||||
int defaultValue)
|
||||
{
|
||||
QString str = getAttribute(element, attributeName, bOptional);
|
||||
if (str.isEmpty())
|
||||
@@ -279,19 +255,18 @@ int XmlReader::getAttributeInt(const QDomElement &element,
|
||||
if (!bOk)
|
||||
{
|
||||
|
||||
ret = str.toUInt(&bOk,16);
|
||||
if(!bOk)
|
||||
ret = str.toUInt(&bOk, 16);
|
||||
if (!bOk)
|
||||
throw XmlReaderException(QLatin1String("Can not parse int value: ") + str);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void XmlReader::parseDBSserviceStructs(const QDomElement &rootElement)
|
||||
void XmlReader::parseDBSserviceStructs(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
|
||||
|
||||
QDomElement domDbStruct = rootElement.firstChildElement(QStringLiteral("serviceStruct"));
|
||||
while (!domDbStruct.isNull())
|
||||
{
|
||||
@@ -320,7 +295,6 @@ void XmlReader::parseDBSserviceStructs(const QDomElement &rootElement)
|
||||
}
|
||||
std::sort(m_structsToGenerate.begin(), m_structsToGenerate.end());
|
||||
|
||||
|
||||
domDbStruct = rootElement.firstChildElement(QStringLiteral("table"));
|
||||
while (!domDbStruct.isNull())
|
||||
{
|
||||
@@ -333,7 +307,7 @@ void XmlReader::parseDBSserviceStructs(const QDomElement &rootElement)
|
||||
INFO_LOG(m_logger) << "Read " << m_structsToGenerate.size() << " database service struct(s)";
|
||||
}
|
||||
|
||||
void XmlReader::parseDBTables(const QDomElement &rootElement)
|
||||
void XmlReader::parseDBTables(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
@@ -345,7 +319,8 @@ void XmlReader::parseDBTables(const QDomElement &rootElement)
|
||||
ti->name = getAttribute(domDbTable, QStringLiteral("name"));
|
||||
ti->structName = QLatin1String("t_") + ti->name;
|
||||
ti->comment = getAttribute(domDbTable, QStringLiteral("comment"), true);
|
||||
ti->exerciseDependency = string2ExerciseDependency(getAttribute(domDbTable, QStringLiteral("exerciseDependency"), true));
|
||||
ti->exerciseDependency =
|
||||
string2ExerciseDependency(getAttribute(domDbTable, QStringLiteral("exerciseDependency"), true));
|
||||
|
||||
QDomElement domColumn = domDbTable.firstChildElement(QStringLiteral("column"));
|
||||
while (!domColumn.isNull())
|
||||
@@ -375,7 +350,7 @@ void XmlReader::parseDBTables(const QDomElement &rootElement)
|
||||
INFO_LOG(m_logger) << "Read " << m_tables.size() << " database table(s)";
|
||||
}
|
||||
|
||||
void XmlReader::parseDBViews(const QDomElement &rootElement)
|
||||
void XmlReader::parseDBViews(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
@@ -390,11 +365,11 @@ void XmlReader::parseDBViews(const QDomElement &rootElement)
|
||||
vi->baseTable = getAttribute(domDbView, QStringLiteral("base"));
|
||||
vi->comment = getAttribute(domDbView, QStringLiteral("comment"), true);
|
||||
vi->filter = getAttribute(domDbView, QStringLiteral("filter"));
|
||||
vi->exerciseDependency = string2ExerciseDependency(getAttribute(domDbView, QStringLiteral("exerciseDependency"), true));
|
||||
vi->exerciseDependency =
|
||||
string2ExerciseDependency(getAttribute(domDbView, QStringLiteral("exerciseDependency"), true));
|
||||
|
||||
DEBUG_LOG(m_logger) << "Base table = " << vi->baseTable;
|
||||
|
||||
|
||||
m_views.insert(vi->name, vi);
|
||||
|
||||
domDbView = domDbView.nextSiblingElement(domDbView.tagName());
|
||||
@@ -403,7 +378,7 @@ void XmlReader::parseDBViews(const QDomElement &rootElement)
|
||||
INFO_LOG(m_logger) << "Read " << m_views.size() << " database view(s)";
|
||||
}
|
||||
|
||||
void XmlReader::parseEnumerations(const QDomElement &rootElement)
|
||||
void XmlReader::parseEnumerations(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
@@ -434,7 +409,7 @@ void XmlReader::parseEnumerations(const QDomElement &rootElement)
|
||||
INFO_LOG(m_logger) << "Read " << m_enumerations.size() << " enumeration(s)";
|
||||
}
|
||||
|
||||
void XmlReader::parseCustomDtcFunctions(const QDomElement &rootElement)
|
||||
void XmlReader::parseCustomDtcFunctions(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
@@ -454,14 +429,11 @@ void XmlReader::parseCustomDtcFunctions(const QDomElement &rootElement)
|
||||
INFO_LOG(m_logger) << "Read " << m_enumerations.size() << " customDtcFunction(s)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void XmlReader::parseTopicTypes(const QDomElement &rootElement)
|
||||
void XmlReader::parseTopicTypes(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
|
||||
|
||||
QDomElement domIdlStruct = rootElement.firstChildElement(QStringLiteral("topicType"));
|
||||
while (!domIdlStruct.isNull())
|
||||
{
|
||||
@@ -469,7 +441,6 @@ void XmlReader::parseTopicTypes(const QDomElement &rootElement)
|
||||
isi.name = getAttribute(domIdlStruct, QStringLiteral("name"));
|
||||
isi.baseValueType = getAttribute(domIdlStruct, QStringLiteral("baseValueType"), true);
|
||||
|
||||
|
||||
const QStringList sl = isi.baseValueType.split(QStringLiteral("::"));
|
||||
if (sl.size() == 2)
|
||||
loadExternalTopicType(sl.at(0), sl.at(1));
|
||||
@@ -477,9 +448,12 @@ void XmlReader::parseTopicTypes(const QDomElement &rootElement)
|
||||
const QString tmp = getAttribute(domIdlStruct, QStringLiteral("extensibility"), true);
|
||||
|
||||
#ifdef RTI_HEADER_AVAILABLE
|
||||
if (tmp.compare(QLatin1String("FINAL"), Qt::CaseInsensitive) == 0) isi.extensibility = dds::core::xtypes::ExtensibilityKind::FINAL;
|
||||
if (tmp.compare(QLatin1String("MUTABLE"), Qt::CaseInsensitive) == 0) isi.extensibility = dds::core::xtypes::ExtensibilityKind::MUTABLE;
|
||||
if (tmp.compare(QLatin1String("EXTENSIBLE"), Qt::CaseInsensitive) == 0) isi.extensibility = dds::core::xtypes::ExtensibilityKind::EXTENSIBLE;
|
||||
if (tmp.compare(QLatin1String("FINAL"), Qt::CaseInsensitive) == 0)
|
||||
isi.extensibility = dds::core::xtypes::ExtensibilityKind::FINAL;
|
||||
if (tmp.compare(QLatin1String("MUTABLE"), Qt::CaseInsensitive) == 0)
|
||||
isi.extensibility = dds::core::xtypes::ExtensibilityKind::MUTABLE;
|
||||
if (tmp.compare(QLatin1String("EXTENSIBLE"), Qt::CaseInsensitive) == 0)
|
||||
isi.extensibility = dds::core::xtypes::ExtensibilityKind::EXTENSIBLE;
|
||||
#else
|
||||
// RTI not available - skip extensibility parsing
|
||||
Q_UNUSED(tmp)
|
||||
@@ -502,22 +476,19 @@ void XmlReader::parseTopicTypes(const QDomElement &rootElement)
|
||||
domColumn = domColumn.nextSiblingElement(domColumn.tagName());
|
||||
}
|
||||
|
||||
|
||||
m_idlStructsToGenerate.insert(isi.name, isi);
|
||||
|
||||
domIdlStruct = domIdlStruct.nextSiblingElement(domIdlStruct.tagName());
|
||||
}
|
||||
|
||||
|
||||
INFO_LOG(m_logger) << "Read " << m_idlStructsToGenerate.size() << " idl struct(s)";
|
||||
}
|
||||
|
||||
void XmlReader::parseFunctionTopics(const QDomElement &rootElement)
|
||||
void XmlReader::parseFunctionTopics(const QDomElement& rootElement)
|
||||
{
|
||||
if (rootElement.isNull())
|
||||
return;
|
||||
|
||||
|
||||
QDomElement domFunctionTopic = rootElement.firstChildElement(QStringLiteral("functionTopic"));
|
||||
while (!domFunctionTopic.isNull())
|
||||
{
|
||||
@@ -534,7 +505,7 @@ void XmlReader::parseFunctionTopics(const QDomElement &rootElement)
|
||||
domFunctionTopic = domFunctionTopic.nextSiblingElement(domFunctionTopic.tagName());
|
||||
}
|
||||
|
||||
for (const FunctionTopic &ft : std::as_const(m_functionTopics))
|
||||
for (const FunctionTopic& ft : std::as_const(m_functionTopics))
|
||||
{
|
||||
const QStringList sl1 = ft.requestTopicType.split(QStringLiteral("::"));
|
||||
if (sl1.size() == 2)
|
||||
@@ -545,7 +516,7 @@ void XmlReader::parseFunctionTopics(const QDomElement &rootElement)
|
||||
}
|
||||
}
|
||||
|
||||
ColumnInformation XmlReader::parseTableColumn(const QDomElement &column, const QString &tableName) const
|
||||
ColumnInformation XmlReader::parseTableColumn(const QDomElement& column, const QString& tableName) const
|
||||
{
|
||||
ColumnInformation ci;
|
||||
|
||||
@@ -565,13 +536,13 @@ ColumnInformation XmlReader::parseTableColumn(const QDomElement &column, const Q
|
||||
}
|
||||
|
||||
if (ci.columnName.toLower() != ci.columnName)
|
||||
WARNING_LOG(m_logger) << "Column " << ci.columnName << " in Table "
|
||||
<< tableName << " has has upper-case chars which is not allowed!";
|
||||
WARNING_LOG(m_logger) << "Column " << ci.columnName << " in Table " << tableName
|
||||
<< " has has upper-case chars which is not allowed!";
|
||||
|
||||
return ci;
|
||||
}
|
||||
|
||||
IdlColumnInformation XmlReader::parseIdlStructColumn(const QDomElement &column) const
|
||||
IdlColumnInformation XmlReader::parseIdlStructColumn(const QDomElement& column) const
|
||||
{
|
||||
IdlColumnInformation ci;
|
||||
|
||||
@@ -585,7 +556,7 @@ IdlColumnInformation XmlReader::parseIdlStructColumn(const QDomElement &column)
|
||||
return ci;
|
||||
}
|
||||
|
||||
QSharedPointer<ForeignKeyInformation> XmlReader::parseForeignKey(const QDomElement &foreignKey) const
|
||||
QSharedPointer<ForeignKeyInformation> XmlReader::parseForeignKey(const QDomElement& foreignKey) const
|
||||
{
|
||||
QSharedPointer<ForeignKeyInformation> fk(new ForeignKeyInformation);
|
||||
|
||||
@@ -611,8 +582,8 @@ QSharedPointer<ForeignKeyInformation> XmlReader::parseForeignKey(const QDomEleme
|
||||
return fk;
|
||||
}
|
||||
|
||||
ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString &foreignKeyName,
|
||||
const QDomElement &endpoint) const
|
||||
ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString& foreignKeyName,
|
||||
const QDomElement& endpoint) const
|
||||
{
|
||||
if (endpoint.isNull())
|
||||
throw XmlReaderException(QLatin1String("No endpoint for foreign key ") + foreignKeyName);
|
||||
@@ -620,7 +591,7 @@ ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString
|
||||
ForeignKeyInformation::Endpoint fkEndpoint;
|
||||
|
||||
fkEndpoint.service = getAttribute(endpoint, QStringLiteral("service"), true);
|
||||
fkEndpoint.serviceAbbr= getAttribute(endpoint, QStringLiteral("serviceAbbr"), true);
|
||||
fkEndpoint.serviceAbbr = getAttribute(endpoint, QStringLiteral("serviceAbbr"), true);
|
||||
fkEndpoint.schema = getAttribute(endpoint, QStringLiteral("schema"), true);
|
||||
fkEndpoint.tableName = getAttribute(endpoint, QStringLiteral("table"));
|
||||
fkEndpoint.columnName = getAttribute(endpoint, QStringLiteral("column"));
|
||||
@@ -628,7 +599,7 @@ ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString
|
||||
return fkEndpoint;
|
||||
}
|
||||
|
||||
ConstraintInformation XmlReader::parseConstraint(const QDomElement &constraint) const
|
||||
ConstraintInformation XmlReader::parseConstraint(const QDomElement& constraint) const
|
||||
{
|
||||
ConstraintInformation ret;
|
||||
|
||||
@@ -650,7 +621,7 @@ ConstraintInformation XmlReader::parseConstraint(const QDomElement &constraint)
|
||||
return ret;
|
||||
}
|
||||
|
||||
CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElement &customFunc,
|
||||
CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElement& customFunc,
|
||||
CustomServiceFunctionInformation::Type funcType) const
|
||||
{
|
||||
CustomServiceFunctionInformation ret;
|
||||
@@ -673,7 +644,6 @@ CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElemen
|
||||
paramName.append(QLatin1String(" = ") + paramDefault);
|
||||
paramHelper[pos] = qMakePair(paramName, paramType);
|
||||
domParam = domParam.nextSiblingElement(domParam.tagName());
|
||||
|
||||
}
|
||||
ret.paramNames.reserve(paramHelper.size());
|
||||
ret.paramTypes.reserve(paramHelper.size());
|
||||
@@ -693,44 +663,45 @@ CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElemen
|
||||
return ret;
|
||||
}
|
||||
|
||||
DbNotifcationInformation XmlReader::parseDbNotification(const QDomElement &customFunc) const
|
||||
DbNotifcationInformation XmlReader::parseDbNotification(const QDomElement& customFunc) const
|
||||
{
|
||||
DbNotifcationInformation ret(parseCustomFunction(customFunc, CustomServiceFunctionInformation::Type::DbNotify));
|
||||
|
||||
const QString attribute(getAttribute(customFunc, QStringLiteral("notificationTypes")).toLower());
|
||||
const QStringList nfTypes = attribute.split(QLatin1Char(','));
|
||||
static const QMap<QString, DbNotifcationInformation::NotificationType> s_nfTypeMap =
|
||||
{
|
||||
{ QLatin1String("beforeinsert"), DbNotifcationInformation::NotificationType::BeforeInsert },
|
||||
{ QLatin1String("afterinsert"), DbNotifcationInformation::NotificationType::AfterInsert },
|
||||
{ QLatin1String("beforeupdate"), DbNotifcationInformation::NotificationType::BeforeUpdate },
|
||||
{ QLatin1String("afterupdate"), DbNotifcationInformation::NotificationType::AfterUpdate },
|
||||
{ QLatin1String("beforedelete"), DbNotifcationInformation::NotificationType::BeforeDelete },
|
||||
{ QLatin1String("afterdelete"), DbNotifcationInformation::NotificationType::AfterDelete }
|
||||
};
|
||||
for (const QString &nfType : nfTypes)
|
||||
static const QMap<QString, DbNotifcationInformation::NotificationType> s_nfTypeMap = {
|
||||
{QLatin1String("beforeinsert"), DbNotifcationInformation::NotificationType::BeforeInsert},
|
||||
{QLatin1String("afterinsert"), DbNotifcationInformation::NotificationType::AfterInsert},
|
||||
{QLatin1String("beforeupdate"), DbNotifcationInformation::NotificationType::BeforeUpdate},
|
||||
{QLatin1String("afterupdate"), DbNotifcationInformation::NotificationType::AfterUpdate},
|
||||
{QLatin1String("beforedelete"), DbNotifcationInformation::NotificationType::BeforeDelete},
|
||||
{QLatin1String("afterdelete"), DbNotifcationInformation::NotificationType::AfterDelete}};
|
||||
for (const QString& nfType : nfTypes)
|
||||
{
|
||||
const auto it = s_nfTypeMap.find(nfType);
|
||||
if (it == s_nfTypeMap.end())
|
||||
throw XmlReaderException(QStringLiteral("Can not find notification type %2 in type map for function %1").arg(ret.methodName, nfType));
|
||||
throw XmlReaderException(QStringLiteral("Can not find notification type %2 in type map for function %1")
|
||||
.arg(ret.methodName, nfType));
|
||||
ret.notificationType += it.value();
|
||||
}
|
||||
if (ret.notificationType.isEmpty())
|
||||
throw XmlReaderException(QStringLiteral("Notification function '%1' without a valid notification type").arg(ret.methodName));
|
||||
throw XmlReaderException(
|
||||
QStringLiteral("Notification function '%1' without a valid notification type").arg(ret.methodName));
|
||||
if (ret.paramTypes.size() != 1)
|
||||
throw XmlReaderException(QStringLiteral("Notification function '%1' must have exactly one parameter").arg(ret.methodName));
|
||||
throw XmlReaderException(
|
||||
QStringLiteral("Notification function '%1' must have exactly one parameter").arg(ret.methodName));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
TopicTypeInformation XmlReader::loadExternalTopicType(const QString &externalServiceName, const QString &topicTypeName)
|
||||
TopicTypeInformation XmlReader::loadExternalTopicType(const QString& externalServiceName, const QString& topicTypeName)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "externalServiceName: " << externalServiceName << ", topicTypeName: " << topicTypeName;
|
||||
|
||||
if (!loadExternalService(externalServiceName))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not find service " << externalServiceName
|
||||
<< " referenced by external topic " << topicTypeName;
|
||||
WARNING_LOG(m_logger) << "Could not find service " << externalServiceName << " referenced by external topic "
|
||||
<< topicTypeName;
|
||||
return TopicTypeInformation();
|
||||
}
|
||||
auto extXmlReader = m_externalXmlInformations.value(externalServiceName);
|
||||
@@ -748,13 +719,13 @@ TopicTypeInformation XmlReader::loadExternalTopicType(const QString &externalSer
|
||||
m_usedServices[externalServiceName] = true;
|
||||
return tti;
|
||||
}
|
||||
WARNING_LOG(m_logger) << "Could not find topic " << topicTypeName
|
||||
<< " in external service definition for service "
|
||||
WARNING_LOG(m_logger) << "Could not find topic " << topicTypeName << " in external service definition for service "
|
||||
<< externalServiceName;
|
||||
return TopicTypeInformation();
|
||||
}
|
||||
|
||||
EnumInformation XmlReader::getExternalEnumeration(const QString &externalServiceName, const QString &enumName, bool verbose)
|
||||
EnumInformation XmlReader::getExternalEnumeration(const QString& externalServiceName, const QString& enumName,
|
||||
bool verbose)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "externalServiceName: " << externalServiceName << ", topicTypeName: " << enumName;
|
||||
|
||||
@@ -772,7 +743,7 @@ EnumInformation XmlReader::getExternalEnumeration(const QString &externalService
|
||||
}
|
||||
|
||||
const QVector<EnumInformation> enums = extXmlReader->getEnumerations();
|
||||
for (const EnumInformation &ei : enums)
|
||||
for (const EnumInformation& ei : enums)
|
||||
{
|
||||
if (ei.enumName == enumName)
|
||||
{
|
||||
@@ -782,15 +753,13 @@ EnumInformation XmlReader::getExternalEnumeration(const QString &externalService
|
||||
}
|
||||
if (verbose)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not find enumeration " << enumName
|
||||
<< " in external service definition for '"
|
||||
WARNING_LOG(m_logger) << "Could not find enumeration " << enumName << " in external service definition for '"
|
||||
<< externalServiceName << "'";
|
||||
}
|
||||
return EnumInformation();
|
||||
}
|
||||
|
||||
|
||||
bool XmlReader::loadExternalService(const QString &serviceName)
|
||||
bool XmlReader::loadExternalService(const QString& serviceName)
|
||||
{
|
||||
if (serviceName == getServiceNamespace())
|
||||
return false;
|
||||
@@ -801,7 +770,7 @@ bool XmlReader::loadExternalService(const QString &serviceName)
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
const QVector<QString> dirs = NGL::directories(NGL::FileType::ConfigFile);
|
||||
for (const QString &dirname : dirs)
|
||||
for (const QString& dirname : dirs)
|
||||
{
|
||||
QDirIterator dirIt(dirname + QStringLiteral("/xml"), QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
|
||||
while (dirIt.hasNext())
|
||||
@@ -824,8 +793,7 @@ bool XmlReader::loadExternalService(const QString &serviceName)
|
||||
auto extXmlReader = QSharedPointer<XmlReader>(new XmlReader);
|
||||
if (!extXmlReader->readServiceFile(fileName, QString(), this))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Error reading service file " << fileName
|
||||
<< " for service " << serviceName;
|
||||
WARNING_LOG(m_logger) << "Error reading service file " << fileName << " for service " << serviceName;
|
||||
return false;
|
||||
}
|
||||
m_externalXmlInformations[serviceName] = extXmlReader;
|
||||
@@ -834,7 +802,7 @@ bool XmlReader::loadExternalService(const QString &serviceName)
|
||||
return true;
|
||||
}
|
||||
|
||||
void XmlReader::loadIdlInfofile(const QString &idlServiceInfoFile)
|
||||
void XmlReader::loadIdlInfofile(const QString& idlServiceInfoFile)
|
||||
{
|
||||
if (idlServiceInfoFile.isEmpty())
|
||||
return;
|
||||
@@ -845,7 +813,7 @@ void XmlReader::loadIdlInfofile(const QString &idlServiceInfoFile)
|
||||
return;
|
||||
}
|
||||
const QList<QByteArray> files = f.readAll().split('\n');
|
||||
for (const QByteArray &filePath : files)
|
||||
for (const QByteArray& filePath : files)
|
||||
{
|
||||
|
||||
if (filePath.startsWith("--") || filePath.trimmed().isEmpty())
|
||||
@@ -871,38 +839,35 @@ void XmlReader::loadIdlInfofile(const QString &idlServiceInfoFile)
|
||||
}
|
||||
}
|
||||
|
||||
QString XmlReader::getIdlFileForService(const QMap<QString, QString> &data,
|
||||
const QString &serviceName) const
|
||||
QString XmlReader::getIdlFileForService(const QMap<QString, QString>& data, const QString& serviceName) const
|
||||
{
|
||||
const QString serviceAbbr = serviceNameAbbreviation(serviceName);
|
||||
return data.value(serviceAbbr);
|
||||
}
|
||||
|
||||
|
||||
QString XmlReader::serviceNameAbbreviation(const QString &serviceName) const
|
||||
QString XmlReader::serviceNameAbbreviation(const QString& serviceName) const
|
||||
{
|
||||
return m_fullServiceName2Abbreviation.value(serviceName);
|
||||
}
|
||||
|
||||
void XmlReader::getServiceNameInfoFromFilePath(const QStringList &parts)
|
||||
void XmlReader::getServiceNameInfoFromFilePath(const QStringList& parts)
|
||||
{
|
||||
if (parts.size() < 2)
|
||||
return;
|
||||
|
||||
|
||||
const QString abbreviation = parts.last().split(QLatin1Char('.')).first().split(QLatin1Char('_')).first();
|
||||
const QString serviceName = parts.at(parts.size() - 2);
|
||||
DEBUG_LOG(m_logger) << "serviceName: " << serviceName << " = " << abbreviation;
|
||||
m_fullServiceName2Abbreviation[serviceName] = abbreviation;
|
||||
}
|
||||
|
||||
ExerciseDependency XmlReader::string2ExerciseDependency(const QString &str)
|
||||
ExerciseDependency XmlReader::string2ExerciseDependency(const QString& str)
|
||||
{
|
||||
if (str.isEmpty())
|
||||
return ExerciseDependency::Undefined;
|
||||
const QStringList sd = str.toLower().split(QLatin1Char(','));
|
||||
int ret = ExerciseDependency::Undefined;
|
||||
for (const QString &s : sd)
|
||||
for (const QString& s : sd)
|
||||
{
|
||||
if (s == QLatin1String("global"))
|
||||
ret |= ExerciseDependency::Global;
|
||||
@@ -914,7 +879,7 @@ ExerciseDependency XmlReader::string2ExerciseDependency(const QString &str)
|
||||
return static_cast<ExerciseDependency>(ret);
|
||||
}
|
||||
|
||||
QString XmlReader::serviceNamespaceFromFile(const QString &fn)
|
||||
QString XmlReader::serviceNamespaceFromFile(const QString& fn)
|
||||
{
|
||||
QFile f(fn);
|
||||
if (!f.open(QIODevice::ReadOnly))
|
||||
@@ -928,4 +893,3 @@ QString XmlReader::serviceNamespaceFromFile(const QString &fn)
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
Executable → Regular
+137
-117
@@ -31,13 +31,7 @@ class QDomElement;
|
||||
namespace CodeGen
|
||||
{
|
||||
|
||||
enum ExerciseDependency
|
||||
{
|
||||
Undefined = 0,
|
||||
Global = 0x1,
|
||||
Exercise = 0x2,
|
||||
GlobalAndExercise = 0x3
|
||||
};
|
||||
enum ExerciseDependency { Undefined = 0, Global = 0x1, Exercise = 0x2, GlobalAndExercise = 0x3 };
|
||||
|
||||
struct EnumKeyValuePair
|
||||
{
|
||||
@@ -52,7 +46,10 @@ struct EnumInformation
|
||||
QString serviceName;
|
||||
QVector<EnumKeyValuePair> values;
|
||||
|
||||
bool isValid() const { return !enumName.isEmpty(); }
|
||||
bool isValid() const
|
||||
{
|
||||
return !enumName.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
struct ColumnInformation
|
||||
@@ -82,7 +79,6 @@ struct IdlColumnInformation
|
||||
bool isTranslatable = false;
|
||||
};
|
||||
|
||||
|
||||
struct ForeignKeyInformation
|
||||
{
|
||||
struct Endpoint
|
||||
@@ -97,8 +93,7 @@ struct ForeignKeyInformation
|
||||
QString name;
|
||||
Endpoint source;
|
||||
Endpoint destination;
|
||||
enum class OnDeleteAction
|
||||
{
|
||||
enum class OnDeleteAction {
|
||||
NoAction,
|
||||
Cascade,
|
||||
Restrict,
|
||||
@@ -115,40 +110,23 @@ struct CustomServiceFunctionInformation
|
||||
bool isConst = false;
|
||||
QVector<QString> paramTypes;
|
||||
QVector<QString> paramNames;
|
||||
enum class Type
|
||||
{
|
||||
Db,
|
||||
DbNotify,
|
||||
Dtc
|
||||
} type = Type::Db;
|
||||
enum class Type { Db, DbNotify, Dtc } type = Type::Db;
|
||||
};
|
||||
|
||||
struct DbNotifcationInformation : public CustomServiceFunctionInformation
|
||||
{
|
||||
DbNotifcationInformation() = default;
|
||||
explicit DbNotifcationInformation(const CustomServiceFunctionInformation &d)
|
||||
: CustomServiceFunctionInformation(d)
|
||||
{}
|
||||
enum class NotificationType
|
||||
|
||||
explicit DbNotifcationInformation(const CustomServiceFunctionInformation& d) : CustomServiceFunctionInformation(d)
|
||||
{
|
||||
BeforeInsert,
|
||||
AfterInsert,
|
||||
BeforeUpdate,
|
||||
AfterUpdate,
|
||||
BeforeDelete,
|
||||
AfterDelete
|
||||
};
|
||||
}
|
||||
enum class NotificationType { BeforeInsert, AfterInsert, BeforeUpdate, AfterUpdate, BeforeDelete, AfterDelete };
|
||||
QVector<NotificationType> notificationType;
|
||||
};
|
||||
|
||||
struct ConstraintInformation
|
||||
{
|
||||
enum struct Type
|
||||
{
|
||||
unknown = 0x00,
|
||||
unique = 0x01,
|
||||
index = 0x02
|
||||
} type = Type::unknown;
|
||||
enum struct Type { unknown = 0x00, unique = 0x01, index = 0x02 } type = Type::unknown;
|
||||
QString name;
|
||||
QStringList affectedColumns;
|
||||
};
|
||||
@@ -159,17 +137,16 @@ struct TableInformation
|
||||
QString structName;
|
||||
QString comment;
|
||||
QVector<ColumnInformation> plainColumns;
|
||||
QVector<QSharedPointer<ForeignKeyInformation> > foreignKeys;
|
||||
QVector<QSharedPointer<ForeignKeyInformation>> foreignKeys;
|
||||
QVector<ConstraintInformation> constraints;
|
||||
ExerciseDependency exerciseDependency = ExerciseDependency::Undefined;
|
||||
|
||||
QSharedPointer<ForeignKeyInformation> fkInformationForColumn(const QString &tableName,
|
||||
const QString &columnName) const
|
||||
QSharedPointer<ForeignKeyInformation> fkInformationForColumn(const QString& tableName,
|
||||
const QString& columnName) const
|
||||
{
|
||||
for (const QSharedPointer<ForeignKeyInformation> &fki : foreignKeys)
|
||||
for (const QSharedPointer<ForeignKeyInformation>& fki : foreignKeys)
|
||||
{
|
||||
if (fki->source.columnName == columnName &&
|
||||
fki->source.tableName == tableName)
|
||||
if (fki->source.columnName == columnName && fki->source.tableName == tableName)
|
||||
return fki;
|
||||
}
|
||||
return QSharedPointer<ForeignKeyInformation>();
|
||||
@@ -193,7 +170,7 @@ struct ServiceStructInformation
|
||||
QString primaryTable;
|
||||
bool hasStaticContent = false;
|
||||
|
||||
bool operator<(const ServiceStructInformation &o) const
|
||||
bool operator<(const ServiceStructInformation& o) const
|
||||
{
|
||||
if (hasStaticContent != o.hasStaticContent)
|
||||
return hasStaticContent < o.hasStaticContent;
|
||||
@@ -201,6 +178,7 @@ struct ServiceStructInformation
|
||||
return name < o.name;
|
||||
return primaryTable < o.primaryTable;
|
||||
}
|
||||
|
||||
QVector<DbNotifcationInformation> dbNotifications;
|
||||
};
|
||||
|
||||
@@ -227,9 +205,12 @@ struct TopicTypeInformationBase
|
||||
int extensibility = 0; // Placeholder when RTI DDS is not available
|
||||
#endif
|
||||
|
||||
virtual bool isValid() const { return !name.isEmpty(); }
|
||||
virtual bool isValid() const
|
||||
{
|
||||
return !name.isEmpty();
|
||||
}
|
||||
|
||||
bool operator<(const TopicTypeInformationBase &o) const
|
||||
bool operator<(const TopicTypeInformationBase& o) const
|
||||
{
|
||||
if (name != o.name)
|
||||
return name < o.name;
|
||||
@@ -252,39 +233,84 @@ struct FunctionTopic
|
||||
bool routeInReplay = false;
|
||||
};
|
||||
|
||||
|
||||
class CODEGEN_BASE_EXPORT XmlReader final
|
||||
{
|
||||
public:
|
||||
public:
|
||||
XmlReader();
|
||||
|
||||
bool readServiceFile(const QString &svcFile,
|
||||
const QString &idlServiceInfoFile = QString(),
|
||||
const XmlReader *parent = nullptr);
|
||||
bool readServiceFile(const QString& svcFile, const QString& idlServiceInfoFile = QString(),
|
||||
const XmlReader* parent = nullptr);
|
||||
|
||||
QString errorString() const
|
||||
{
|
||||
return m_errorString;
|
||||
}
|
||||
|
||||
QString getServiceNamespace() const { return m_svcNamespace; }
|
||||
QString getServiceAbbr() const { return m_svcAbbr; }
|
||||
QStringList getGroupNames() const { return m_groupNames; }
|
||||
int getPrio() const { return m_prio;}
|
||||
QStringList getProcNames() const { return m_svcProcNames; }
|
||||
bool hasCustomRecordReplayPlugin() const { return m_customRecordReplay; }
|
||||
bool getDevMode() const { return m_svcDevMode; }
|
||||
QString getServiceNamespace() const
|
||||
{
|
||||
return m_svcNamespace;
|
||||
}
|
||||
|
||||
bool isServiceExerciseIndependent() const { return m_exerciseDependency == ExerciseDependency::Global; }
|
||||
ExerciseDependency defaultExerciseDependency() const { return m_exerciseDependency; }
|
||||
QString getServiceAbbr() const
|
||||
{
|
||||
return m_svcAbbr;
|
||||
}
|
||||
|
||||
QMap<QString, QVector<QString> > getDbClass2TableMapping() const { return m_dbClassTables; }
|
||||
QStringList getGroupNames() const
|
||||
{
|
||||
return m_groupNames;
|
||||
}
|
||||
|
||||
int getPrio() const
|
||||
{
|
||||
return m_prio;
|
||||
}
|
||||
|
||||
QMap<QString, QString> getStruct2BaseClassRelations() const { return m_struct2BaseClass; }
|
||||
QVector<ServiceStructInformation> getStructToGenerate() const { return m_structsToGenerate; }
|
||||
QStringList getProcNames() const
|
||||
{
|
||||
return m_svcProcNames;
|
||||
}
|
||||
|
||||
bool hasCustomRecordReplayPlugin() const
|
||||
{
|
||||
return m_customRecordReplay;
|
||||
}
|
||||
|
||||
bool getDevMode() const
|
||||
{
|
||||
return m_svcDevMode;
|
||||
}
|
||||
|
||||
bool isServiceExerciseIndependent() const
|
||||
{
|
||||
return m_exerciseDependency == ExerciseDependency::Global;
|
||||
}
|
||||
|
||||
ExerciseDependency defaultExerciseDependency() const
|
||||
{
|
||||
return m_exerciseDependency;
|
||||
}
|
||||
|
||||
QMap<QString, QVector<QString>> getDbClass2TableMapping() const
|
||||
{
|
||||
return m_dbClassTables;
|
||||
}
|
||||
|
||||
QMap<QString, QString> getStruct2BaseClassRelations() const
|
||||
{
|
||||
return m_struct2BaseClass;
|
||||
}
|
||||
|
||||
QVector<ServiceStructInformation> getStructToGenerate() const
|
||||
{
|
||||
return m_structsToGenerate;
|
||||
}
|
||||
|
||||
QMap<QString, TopicTypeInformation> getIdlStructInformation() const
|
||||
{
|
||||
return m_idlStructsToGenerate;
|
||||
}
|
||||
|
||||
QMap<QString, TopicTypeInformation > getIdlStructInformation() const { return m_idlStructsToGenerate; }
|
||||
QVector<TopicTypeInformation> getIdlStructToGenerate() const
|
||||
{
|
||||
QVector<TopicTypeInformation> res;
|
||||
@@ -298,24 +324,27 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QSharedPointer<TableInformation> > getTables() const
|
||||
QMap<QString, QSharedPointer<TableInformation>> getTables() const
|
||||
{
|
||||
return m_tables;
|
||||
}
|
||||
QMap<QString, QSharedPointer<ViewInformation> > getViews() const
|
||||
|
||||
QMap<QString, QSharedPointer<ViewInformation>> getViews() const
|
||||
{
|
||||
return m_views;
|
||||
}
|
||||
QSharedPointer<TableInformation> getTable(const QString &table) const
|
||||
|
||||
QSharedPointer<TableInformation> getTable(const QString& table) const
|
||||
{
|
||||
return m_tables.value(table);
|
||||
}
|
||||
|
||||
QVector<EnumInformation> getEnumerations() const
|
||||
{
|
||||
return m_enumerations;
|
||||
}
|
||||
QVector<IdlColumnInformation> getIdlColumns(const QString &structName) const
|
||||
|
||||
QVector<IdlColumnInformation> getIdlColumns(const QString& structName) const
|
||||
{
|
||||
return m_idlStructsToGenerate.value(structName).columns;
|
||||
}
|
||||
@@ -324,17 +353,18 @@ public:
|
||||
{
|
||||
return m_functionTopics;
|
||||
}
|
||||
|
||||
QVector<TopicTypeInformation> getExternalTopicTypes() const
|
||||
{
|
||||
return m_externalTopicTypes;
|
||||
}
|
||||
|
||||
QString idlFileForService(const QString &serviceName) const
|
||||
QString idlFileForService(const QString& serviceName) const
|
||||
{
|
||||
return getIdlFileForService(m_idlFiles, serviceName);
|
||||
}
|
||||
|
||||
QString xmlFileForService(const QString &serviceName) const
|
||||
QString xmlFileForService(const QString& serviceName) const
|
||||
{
|
||||
return getIdlFileForService(m_xmlFiles, serviceName);
|
||||
}
|
||||
@@ -349,51 +379,46 @@ public:
|
||||
return m_customFunctions;
|
||||
}
|
||||
|
||||
TopicTypeInformation loadExternalTopicType(const QString& externalServiceName, const QString& topicTypeName);
|
||||
EnumInformation getExternalEnumeration(const QString& externalServiceName, const QString& enumName, bool verbose);
|
||||
|
||||
TopicTypeInformation loadExternalTopicType(const QString &externalServiceName, const QString &topicTypeName);
|
||||
EnumInformation getExternalEnumeration(const QString &externalServiceName, const QString &enumName, bool verbose);
|
||||
static ExerciseDependency string2ExerciseDependency(const QString& str);
|
||||
|
||||
static ExerciseDependency string2ExerciseDependency(const QString &str);
|
||||
XmlReader(const XmlReader&) = delete;
|
||||
XmlReader& operator=(const XmlReader&) = delete;
|
||||
|
||||
XmlReader(const XmlReader &) = delete;
|
||||
XmlReader &operator=(const XmlReader &) = delete;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void parseDBSserviceStructs(const QDomElement& rootElement);
|
||||
void parseDBTables(const QDomElement& rootElement);
|
||||
void parseDBViews(const QDomElement& rootElement);
|
||||
void parseEnumerations(const QDomElement& rootElement);
|
||||
void parseTopicTypes(const QDomElement& rootElement);
|
||||
void parseFunctionTopics(const QDomElement& rootElement);
|
||||
void parseCustomDtcFunctions(const QDomElement& rootElement);
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void parseDBSserviceStructs(const QDomElement &rootElement);
|
||||
void parseDBTables(const QDomElement &rootElement);
|
||||
void parseDBViews(const QDomElement &rootElement);
|
||||
void parseEnumerations(const QDomElement &rootElement);
|
||||
void parseTopicTypes(const QDomElement &rootElement);
|
||||
void parseFunctionTopics(const QDomElement &rootElement);
|
||||
void parseCustomDtcFunctions(const QDomElement &rootElement);
|
||||
static QString getAttribute(const QDomElement& element, const QString& attributeName, bool bOptional = false);
|
||||
static bool getAttributeBool(const QDomElement& element, const QString& attributeName, bool bOptional,
|
||||
bool defaultValue);
|
||||
static int getAttributeInt(const QDomElement& element, const QString& attributeName, bool bOptional = false,
|
||||
int defaultValue = 0);
|
||||
|
||||
static QString getAttribute(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional = false);
|
||||
static bool getAttributeBool(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional, bool defaultValue);
|
||||
static int getAttributeInt(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional = false, int defaultValue = 0);
|
||||
|
||||
ColumnInformation parseTableColumn(const QDomElement &column, const QString &tableName) const;
|
||||
IdlColumnInformation parseIdlStructColumn(const QDomElement &column) const;
|
||||
|
||||
QSharedPointer<ForeignKeyInformation> parseForeignKey(const QDomElement &foreignKey) const;
|
||||
ForeignKeyInformation::Endpoint parseForeignKeyEndpoint(const QString &foreignKeyName,
|
||||
const QDomElement &endpoint) const;
|
||||
ConstraintInformation parseConstraint(const QDomElement &constraint) const;
|
||||
CustomServiceFunctionInformation parseCustomFunction(const QDomElement &customFunc, CustomServiceFunctionInformation::Type funcType) const;
|
||||
DbNotifcationInformation parseDbNotification(const QDomElement &customFunc) const;
|
||||
bool loadExternalService(const QString &serviceName);
|
||||
void loadIdlInfofile(const QString &idlServiceInfoFile);
|
||||
QString getIdlFileForService(const QMap<QString, QString> &data, const QString &serviceName) const;
|
||||
QString serviceNameAbbreviation(const QString &serviceName) const;
|
||||
void getServiceNameInfoFromFilePath(const QStringList &parts);
|
||||
static QString serviceNamespaceFromFile(const QString &fn);
|
||||
ColumnInformation parseTableColumn(const QDomElement& column, const QString& tableName) const;
|
||||
IdlColumnInformation parseIdlStructColumn(const QDomElement& column) const;
|
||||
|
||||
QSharedPointer<ForeignKeyInformation> parseForeignKey(const QDomElement& foreignKey) const;
|
||||
ForeignKeyInformation::Endpoint parseForeignKeyEndpoint(const QString& foreignKeyName,
|
||||
const QDomElement& endpoint) const;
|
||||
ConstraintInformation parseConstraint(const QDomElement& constraint) const;
|
||||
CustomServiceFunctionInformation parseCustomFunction(const QDomElement& customFunc,
|
||||
CustomServiceFunctionInformation::Type funcType) const;
|
||||
DbNotifcationInformation parseDbNotification(const QDomElement& customFunc) const;
|
||||
bool loadExternalService(const QString& serviceName);
|
||||
void loadIdlInfofile(const QString& idlServiceInfoFile);
|
||||
QString getIdlFileForService(const QMap<QString, QString>& data, const QString& serviceName) const;
|
||||
QString serviceNameAbbreviation(const QString& serviceName) const;
|
||||
void getServiceNameInfoFromFilePath(const QStringList& parts);
|
||||
static QString serviceNamespaceFromFile(const QString& fn);
|
||||
|
||||
QString m_svcNamespace;
|
||||
|
||||
@@ -403,12 +428,9 @@ private:
|
||||
|
||||
bool m_customRecordReplay;
|
||||
|
||||
|
||||
ExerciseDependency m_exerciseDependency{ExerciseDependency::Exercise};
|
||||
|
||||
|
||||
QMap<QString, QVector<QString> > m_dbClassTables;
|
||||
|
||||
QMap<QString, QVector<QString>> m_dbClassTables;
|
||||
|
||||
QMap<QString, QString> m_struct2BaseClass;
|
||||
QVector<ServiceStructInformation> m_structsToGenerate;
|
||||
@@ -419,14 +441,12 @@ private:
|
||||
QVector<TopicTypeInformation> m_externalTopicTypes;
|
||||
QVector<CustomServiceFunctionInformation> m_customFunctions;
|
||||
|
||||
|
||||
QMap<QString, QSharedPointer<TableInformation> > m_tables;
|
||||
QMap<QString, QSharedPointer<ViewInformation> > m_views;
|
||||
QMap<QString, QSharedPointer<TableInformation>> m_tables;
|
||||
QMap<QString, QSharedPointer<ViewInformation>> m_views;
|
||||
QVector<EnumInformation> m_enumerations;
|
||||
QString m_errorString;
|
||||
|
||||
|
||||
QMap<QString, QSharedPointer<XmlReader> > m_externalXmlInformations;
|
||||
QMap<QString, QSharedPointer<XmlReader>> m_externalXmlInformations;
|
||||
QMap<QString, QString> m_idlFiles;
|
||||
QMap<QString, QString> m_xmlFiles;
|
||||
QMap<QString, bool> m_usedServices;
|
||||
@@ -436,4 +456,4 @@ private:
|
||||
int m_prio;
|
||||
bool m_svcDevMode{false};
|
||||
};
|
||||
}
|
||||
} // namespace CodeGen
|
||||
Executable → Regular
+9
-9
@@ -5,13 +5,13 @@
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef CODEGEN_BASE_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define CODEGEN_BASE_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_CODEGEN_BASE_LIB)
|
||||
# define CODEGEN_BASE_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define CODEGEN_BASE_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define CODEGEN_BASE_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_CODEGEN_BASE_LIB)
|
||||
#define CODEGEN_BASE_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define CODEGEN_BASE_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+43
-48
@@ -1,48 +1,37 @@
|
||||
|
||||
|
||||
|
||||
#include "StructBuilder.h"
|
||||
#include "XmlReader.h"
|
||||
#include "CppTopicGeneratorGrantlee.h"
|
||||
#include "DaoGeneratorGrantlee.h"
|
||||
#include "DatabaseGeneratorGrantlee.h"
|
||||
#include "CppTopicGeneratorGrantlee.h"
|
||||
#include "SqlGenerator.h"
|
||||
#include "StructBuilder.h"
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <QDir>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QDir>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser(LtsCommandLineParser::LtsCommandLineParser::None)
|
||||
public:
|
||||
CmdLineParser() : LtsCommandLineParser(LtsCommandLineParser::LtsCommandLineParser::None)
|
||||
{
|
||||
addOption({ QStringList() << QStringLiteral("s") << QStringLiteral("servicefile"),
|
||||
QStringLiteral("full path to the service xml-file"),
|
||||
QStringLiteral("service xml-file"),
|
||||
QStringLiteral("/home")
|
||||
});
|
||||
addOption({QStringList() << QStringLiteral("s") << QStringLiteral("servicefile"),
|
||||
QStringLiteral("full path to the service xml-file"), QStringLiteral("service xml-file"),
|
||||
QStringLiteral("/home")});
|
||||
|
||||
addOption({ QStringList() << QStringLiteral("a") << QStringLiteral("action"),
|
||||
QStringLiteral("the action to execute"),
|
||||
QStringLiteral("DATABASE|DATABASE_SERVER|IDL|DDS_TOPICS"),
|
||||
QStringLiteral("/0")
|
||||
});
|
||||
addOption({QStringList() << QStringLiteral("a") << QStringLiteral("action"),
|
||||
QStringLiteral("the action to execute"), QStringLiteral("DATABASE|DATABASE_SERVER|IDL|DDS_TOPICS"),
|
||||
QStringLiteral("/0")});
|
||||
|
||||
addOption({ QStringList() << QStringLiteral("o") << QStringLiteral("outdir"),
|
||||
addOption({QStringList() << QStringLiteral("o") << QStringLiteral("outdir"),
|
||||
QStringLiteral("the output directory where to put the generated files"),
|
||||
QStringLiteral("output directory"),
|
||||
QStringLiteral("/home")
|
||||
});
|
||||
QStringLiteral("output directory"), QStringLiteral("/home")});
|
||||
|
||||
addOption({ QStringList() << QStringLiteral("i") << QStringLiteral("idlinfo"),
|
||||
addOption({QStringList() << QStringLiteral("i") << QStringLiteral("idlinfo"),
|
||||
QStringLiteral("the info file with all available idl service files"),
|
||||
QStringLiteral("info file for idl"),
|
||||
QStringLiteral("/0")
|
||||
});
|
||||
QStringLiteral("info file for idl"), QStringLiteral("/0")});
|
||||
}
|
||||
|
||||
bool init()
|
||||
@@ -58,18 +47,33 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
QString serviceFile() const { return value(QStringLiteral("s")); }
|
||||
QString action() const { return value(QStringLiteral("a")); }
|
||||
QString outDir() const { return value(QStringLiteral("o")); }
|
||||
QString idlInfoFile() const { return value(QStringLiteral("i")); }
|
||||
QString serviceFile() const
|
||||
{
|
||||
return value(QStringLiteral("s"));
|
||||
}
|
||||
|
||||
QString action() const
|
||||
{
|
||||
return value(QStringLiteral("a"));
|
||||
}
|
||||
|
||||
QString outDir() const
|
||||
{
|
||||
return value(QStringLiteral("o"));
|
||||
}
|
||||
|
||||
QString idlInfoFile() const
|
||||
{
|
||||
return value(QStringLiteral("i"));
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("CodeGen", "codegen_log4cxx.props", true );
|
||||
app.createLogger("CodeGen", "codegen_log4cxx.props", true);
|
||||
|
||||
NGL::INGLLogger &m_logger = app.baseLogger();
|
||||
NGL::INGLLogger& m_logger = app.baseLogger();
|
||||
|
||||
CmdLineParser options;
|
||||
if (!options.init())
|
||||
@@ -81,8 +85,7 @@ int main(int argc, char **argv)
|
||||
DEBUG_LOG(m_logger) << "IdlInfoFile: " << options.idlInfoFile();
|
||||
if (!reader->readServiceFile(options.serviceFile(), options.idlInfoFile()))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error parsing service file '" << options.serviceFile()
|
||||
<< ": " << reader->errorString();
|
||||
ERROR_LOG(m_logger) << "Error parsing service file '" << options.serviceFile() << ": " << reader->errorString();
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -90,8 +93,7 @@ int main(int argc, char **argv)
|
||||
DEBUG_LOG(m_logger) << "Directory: " << options.outDir();
|
||||
if (!dir.exists() && !dir.mkpath(options.outDir()))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Directory '" << options.outDir()
|
||||
<< "' does not exist and can not be created!";
|
||||
ERROR_LOG(m_logger) << "Directory '" << options.outDir() << "' does not exist and can not be created!";
|
||||
return 3;
|
||||
}
|
||||
|
||||
@@ -104,7 +106,6 @@ int main(int argc, char **argv)
|
||||
|
||||
const QString action = options.action().toLower();
|
||||
|
||||
|
||||
QScopedPointer<CodeGen::GeneratorGrantleeBase> generator;
|
||||
if (action == QStringLiteral("dao"))
|
||||
generator.reset(new CodeGen::DaoGeneratorGrantlee);
|
||||
@@ -120,7 +121,6 @@ int main(int argc, char **argv)
|
||||
if (!sql.generateData(35))
|
||||
return 8;
|
||||
|
||||
|
||||
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
|
||||
@@ -130,14 +130,12 @@ int main(int argc, char **argv)
|
||||
if (!sql.generateData(42))
|
||||
return 8;
|
||||
|
||||
|
||||
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
sql.generateData(0);
|
||||
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Global))
|
||||
{
|
||||
@@ -158,11 +156,8 @@ int main(int argc, char **argv)
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const auto posArgs = options.positionalArguments();
|
||||
for (const QString &file : posArgs)
|
||||
for (const QString& file : posArgs)
|
||||
{
|
||||
|
||||
if (!generator->generateData(file, dir.absolutePath()))
|
||||
|
||||
Executable → Regular
+27
-37
@@ -1,44 +1,32 @@
|
||||
|
||||
|
||||
|
||||
#include "main_grantlee_gui.h"
|
||||
#include "ui_main_grantlee_gui.h"
|
||||
#include "StructBuilder.h"
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include "CppTopicGeneratorGrantlee.h"
|
||||
#include "DatabaseGeneratorGrantlee.h"
|
||||
#include "StructBuilder.h"
|
||||
#include "XmlReader.h"
|
||||
#include "ui_main_grantlee_gui.h"
|
||||
|
||||
#include <nglapplication/nglapplication.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <grantlee/engine.h>
|
||||
#include <nglapplication/nglapplication.h>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, m_xmlReader(nullptr)
|
||||
, m_structBuilder(nullptr)
|
||||
, m_generator(new CodeGen::CppTopicGeneratorGrantlee)
|
||||
, m_engine(new Grantlee::Engine)
|
||||
, m_ui(new Ui_MainGrantleeGui)
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent), m_xmlReader(nullptr), m_structBuilder(nullptr),
|
||||
m_generator(new CodeGen::CppTopicGeneratorGrantlee), m_engine(new Grantlee::Engine), m_ui(new Ui_MainGrantleeGui)
|
||||
{
|
||||
m_idlServiceInfoFile = QStringLiteral("/home/chehrlic/TDS/TDS-build-product-clang/service_idl_files.txt");
|
||||
m_ui->setupUi(this);
|
||||
connect(m_ui->actionExit, &QAction::triggered,
|
||||
this, &MainWindow::close);
|
||||
connect(m_ui->actionSelect_Data_Source, &QAction::triggered,
|
||||
this, &MainWindow::onSelectDataSource);
|
||||
connect(m_ui->actionOpen_Template, &QAction::triggered,
|
||||
this, &MainWindow::onOpenTemplate);
|
||||
connect(m_ui->actionSave_Template, &QAction::triggered,
|
||||
this, &MainWindow::onSaveTemplate);
|
||||
connect(m_ui->pbRefresh, &QPushButton::clicked,
|
||||
this, &MainWindow::onRefreshOutput);
|
||||
connect(m_ui->actionDatabaseGenerator, &QAction::triggered,
|
||||
this, &MainWindow::onGeneratorDb);
|
||||
connect(m_ui->actionDDS_Generator, &QAction::triggered,
|
||||
this, &MainWindow::onGeneratorDds);
|
||||
connect(m_ui->actionExit, &QAction::triggered, this, &MainWindow::close);
|
||||
connect(m_ui->actionSelect_Data_Source, &QAction::triggered, this, &MainWindow::onSelectDataSource);
|
||||
connect(m_ui->actionOpen_Template, &QAction::triggered, this, &MainWindow::onOpenTemplate);
|
||||
connect(m_ui->actionSave_Template, &QAction::triggered, this, &MainWindow::onSaveTemplate);
|
||||
connect(m_ui->pbRefresh, &QPushButton::clicked, this, &MainWindow::onRefreshOutput);
|
||||
connect(m_ui->actionDatabaseGenerator, &QAction::triggered, this, &MainWindow::onGeneratorDb);
|
||||
connect(m_ui->actionDDS_Generator, &QAction::triggered, this, &MainWindow::onGeneratorDds);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -54,14 +42,16 @@ static QLatin1String s_startDir("/home/chehrlic/TDS/TDS-source-product/Lts/");
|
||||
|
||||
void MainWindow::onSelectDataSource()
|
||||
{
|
||||
const QString dataSource = QFileDialog::getOpenFileName(this, tr("Select data source"), s_startDir, tr("Service Files (*.xml)"));
|
||||
const QString dataSource =
|
||||
QFileDialog::getOpenFileName(this, tr("Select data source"), s_startDir, tr("Service Files (*.xml)"));
|
||||
if (dataSource.isEmpty())
|
||||
return;
|
||||
delete m_xmlReader;
|
||||
m_xmlReader = new CodeGen::XmlReader;
|
||||
if (!m_xmlReader->readServiceFile(dataSource, m_idlServiceInfoFile))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Invalid data source"), tr("The selected data source is not valid: %1").arg(m_xmlReader->errorString()));
|
||||
QMessageBox::warning(this, tr("Invalid data source"),
|
||||
tr("The selected data source is not valid: %1").arg(m_xmlReader->errorString()));
|
||||
return;
|
||||
}
|
||||
delete m_structBuilder;
|
||||
@@ -78,7 +68,8 @@ void MainWindow::onSelectDataSource()
|
||||
|
||||
void MainWindow::onOpenTemplate()
|
||||
{
|
||||
const QString templateFile = QFileDialog::getOpenFileName(this, tr("Select data source"), s_startDir, tr("Templates (*.grantlee)"));
|
||||
const QString templateFile =
|
||||
QFileDialog::getOpenFileName(this, tr("Select data source"), s_startDir, tr("Templates (*.grantlee)"));
|
||||
if (templateFile.isEmpty())
|
||||
return;
|
||||
QFile f(templateFile);
|
||||
@@ -102,7 +93,8 @@ void MainWindow::onSaveTemplate()
|
||||
}
|
||||
f.write(m_ui->teInput->toPlainText().toUtf8());
|
||||
f.close();
|
||||
QMessageBox::information(this, tr("Saving template file"), tr("Successfully saved template to %1").arg(m_templateFile));
|
||||
QMessageBox::information(this, tr("Saving template file"),
|
||||
tr("Successfully saved template to %1").arg(m_templateFile));
|
||||
}
|
||||
|
||||
void MainWindow::onRefreshOutput()
|
||||
@@ -118,7 +110,7 @@ void MainWindow::onRefreshOutput()
|
||||
|
||||
void MainWindow::onGeneratorDb()
|
||||
{
|
||||
if (dynamic_cast<CodeGen::DatabaseGeneratorGrantlee *>(m_generator))
|
||||
if (dynamic_cast<CodeGen::DatabaseGeneratorGrantlee*>(m_generator))
|
||||
return;
|
||||
delete m_generator;
|
||||
m_generator = new CodeGen::DatabaseGeneratorGrantlee(false);
|
||||
@@ -128,7 +120,7 @@ void MainWindow::onGeneratorDb()
|
||||
|
||||
void MainWindow::onGeneratorDds()
|
||||
{
|
||||
if (dynamic_cast<CodeGen::CppTopicGeneratorGrantlee *>(m_generator))
|
||||
if (dynamic_cast<CodeGen::CppTopicGeneratorGrantlee*>(m_generator))
|
||||
return;
|
||||
delete m_generator;
|
||||
m_generator = new CodeGen::CppTopicGeneratorGrantlee;
|
||||
@@ -136,13 +128,12 @@ void MainWindow::onGeneratorDds()
|
||||
m_generator->init(m_xmlReader, m_structBuilder);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
NGLApplication app(argc, argv);
|
||||
app.createLogger("CodeGen", "codegen_log4cxx.props");
|
||||
|
||||
NGL::INGLLogger &m_logger = app.baseLogger();
|
||||
NGL::INGLLogger& m_logger = app.baseLogger();
|
||||
STARTUP_LOG(m_logger);
|
||||
|
||||
int iRet = 0;
|
||||
@@ -155,4 +146,3 @@ int main(int argc, char **argv)
|
||||
SHUTDOWN_LOG(m_logger);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
Executable → Regular
+14
-12
@@ -1,40 +1,42 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QObject>
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
class XmlReader;
|
||||
class StructBuilder;
|
||||
class GeneratorGrantleeBase;
|
||||
}
|
||||
} // namespace CodeGen
|
||||
|
||||
namespace Grantlee
|
||||
{
|
||||
class Engine;
|
||||
}
|
||||
class Ui_MainGrantleeGui;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void onSelectDataSource();
|
||||
void onOpenTemplate();
|
||||
void onSaveTemplate();
|
||||
void onRefreshOutput();
|
||||
void onGeneratorDb();
|
||||
void onGeneratorDds();
|
||||
private:
|
||||
CodeGen::XmlReader *m_xmlReader;
|
||||
CodeGen::StructBuilder *m_structBuilder;
|
||||
CodeGen::GeneratorGrantleeBase *m_generator;
|
||||
Grantlee::Engine *m_engine;
|
||||
|
||||
private:
|
||||
CodeGen::XmlReader* m_xmlReader;
|
||||
CodeGen::StructBuilder* m_structBuilder;
|
||||
CodeGen::GeneratorGrantleeBase* m_generator;
|
||||
Grantlee::Engine* m_engine;
|
||||
QString m_idlServiceInfoFile;
|
||||
QString m_templateFile;
|
||||
Ui_MainGrantleeGui *m_ui;
|
||||
Ui_MainGrantleeGui* m_ui;
|
||||
};
|
||||
@@ -1,16 +1,16 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QDir>
|
||||
#include <grantlee/engine.h>
|
||||
#include <grantlee/templateloader.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QString templatesDir = QDir::currentPath();
|
||||
if (argc > 1) {
|
||||
if (argc > 1)
|
||||
{
|
||||
templatesDir = QString::fromLocal8Bit(argv[1]);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ int main(int argc, char **argv)
|
||||
|
||||
QDir d(templatesDir);
|
||||
QStringList files = d.entryList(QStringList() << QStringLiteral("*.grantlee"), QDir::Files);
|
||||
if (files.isEmpty()) {
|
||||
if (files.isEmpty())
|
||||
{
|
||||
qDebug() << "No .grantlee templates found in" << templatesDir;
|
||||
// Treat absence as successful parse (nothing to check) to avoid failing
|
||||
// when directory is empty in different setups.
|
||||
@@ -29,21 +30,27 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
for (const QString &f : files) {
|
||||
for (const QString& f : files)
|
||||
{
|
||||
Grantlee::Template t;
|
||||
try {
|
||||
try
|
||||
{
|
||||
t = engine.loadByName(f);
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
qDebug() << "Exception while loading" << f;
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
if (!t) {
|
||||
if (!t)
|
||||
{
|
||||
qDebug() << "Failed to load template" << f;
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
if (t->error() != Grantlee::NoError) {
|
||||
if (t->error() != Grantlee::NoError)
|
||||
{
|
||||
qDebug() << "Parse error in" << f << ":" << t->errorString();
|
||||
ok = false;
|
||||
continue;
|
||||
@@ -51,7 +58,8 @@ int main(int argc, char **argv)
|
||||
// Render with empty context to ensure rendering path also works.
|
||||
Grantlee::Context ctx;
|
||||
QString out = t->render(&ctx);
|
||||
if (out.isNull()) {
|
||||
if (out.isNull())
|
||||
{
|
||||
qDebug() << "Rendering produced null for" << f;
|
||||
ok = false;
|
||||
continue;
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
#include "mocks/MockCoordTrans.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(CoordTransGTest, ForwardInverseRoundtrip) {
|
||||
auto p = MockCoordTrans::forward(1.2345, 2.3456);
|
||||
EXPECT_NEAR(p.first, 1.2345 * 111000.0, 1e-6);
|
||||
EXPECT_NEAR(p.second, 2.3456 * 111000.0, 1e-6);
|
||||
|
||||
auto inv = MockCoordTrans::inverse(p.first, p.second);
|
||||
EXPECT_NEAR(inv.first, 1.2345, 1e-9);
|
||||
EXPECT_NEAR(inv.second, 2.3456, 1e-9);
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include "mocks/MockCoordTrans.h"
|
||||
|
||||
class CoordTransSmoke : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testForward() {
|
||||
auto p = MockCoordTrans::forward(10.0, 20.0);
|
||||
QVERIFY(qFuzzyCompare(p.first, 10.0 * 111000.0));
|
||||
QVERIFY(qFuzzyCompare(p.second, 20.0 * 111000.0));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(CoordTransSmoke)
|
||||
#include "coordTransTests_smoke.moc"
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <utility>
|
||||
|
||||
// Minimal realistic mock for coordinate transforms used during migration.
|
||||
// Forward conversion returns approximate meters using lat/lon*111000.
|
||||
class MockCoordTrans {
|
||||
public:
|
||||
// approximate forward: (lat, lon) -> (x_m, y_m)
|
||||
static std::pair<double,double> forward(double lat_deg, double lon_deg) {
|
||||
return {lat_deg * 111000.0, lon_deg * 111000.0};
|
||||
}
|
||||
// approximate inverse
|
||||
static std::pair<double,double> inverse(double x_m, double y_m) {
|
||||
return {x_m / 111000.0, y_m / 111000.0};
|
||||
}
|
||||
};
|
||||
Executable → Regular
+16
-37
@@ -1,18 +1,15 @@
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <utility>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDirIterator>
|
||||
#include <QFile>
|
||||
#include <QFileInfoList>
|
||||
#include <QDirIterator>
|
||||
#include <QTextStream>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
|
||||
#include <QTextStream>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
@@ -31,7 +28,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -40,16 +38,16 @@ int main(int argc, char *argv[])
|
||||
QStringList lastErrors;
|
||||
QStringList dummy1;
|
||||
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())
|
||||
{
|
||||
printf("LtsAppDescriptorChecker: apps.json at %s invalid:\n%s\n", appsJsonFilePath.toStdString().c_str(), lastErrors.join(QStringLiteral("\r\n\r\n")).toStdString().c_str());
|
||||
printf("LtsAppDescriptorChecker: apps.json at %s invalid:\n%s\n", appsJsonFilePath.toStdString().c_str(),
|
||||
lastErrors.join(QStringLiteral("\r\n\r\n")).toStdString().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QFileInfoList guiPluginFiles;
|
||||
QDirIterator it(QStringLiteral("%1/../../Plugins/").arg(currentSrcDir), QDirIterator::Subdirectories);
|
||||
|
||||
@@ -67,14 +65,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
QStringList filenames;
|
||||
filenames.reserve(guiPluginFiles.size());
|
||||
for (const QFileInfo &fi : std::as_const(guiPluginFiles))
|
||||
for (const QFileInfo& fi : std::as_const(guiPluginFiles))
|
||||
{
|
||||
filenames += fi.absoluteFilePath();
|
||||
}
|
||||
|
||||
|
||||
QStringList guiPluginIIDs;
|
||||
for (const QFileInfo &fi : std::as_const(guiPluginFiles))
|
||||
for (const QFileInfo& fi : std::as_const(guiPluginFiles))
|
||||
{
|
||||
QFile f2(fi.absoluteFilePath());
|
||||
|
||||
@@ -102,38 +99,20 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return !ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+33
-42
@@ -1,29 +1,24 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_app_descriptor.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QCoreApplication>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonValue>
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace LtsAppDescriptor
|
||||
{
|
||||
static void addOptionToPlugin(PluginInfo &pluginInfo, const PluginInfo::Flag &flag)
|
||||
static void addOptionToPlugin(PluginInfo& pluginInfo, const PluginInfo::Flag& 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)
|
||||
{
|
||||
@@ -39,10 +34,9 @@ static void addOptionToPlugin(QVector<PluginInfo> &pluginInfos, const PluginInfo
|
||||
pluginInfos.append(pi);
|
||||
}
|
||||
|
||||
|
||||
static bool addOptionsToPlugin(AppDescription &appDesc, const QString &optionIdentifier, const QStringList &ignoredPlugins,
|
||||
const QJsonObject &optionsObject, const PluginInfo::Flag flag, QStringList &lastErrors,
|
||||
bool atLeastOnePluginNeeded)
|
||||
static bool addOptionsToPlugin(AppDescription& appDesc, const QString& optionIdentifier,
|
||||
const QStringList& ignoredPlugins, const QJsonObject& optionsObject,
|
||||
const PluginInfo::Flag flag, QStringList& lastErrors, bool atLeastOnePluginNeeded)
|
||||
{
|
||||
bool hasPlugins = false;
|
||||
auto optionsObjectIt = optionsObject.constFind(optionIdentifier);
|
||||
@@ -50,7 +44,7 @@ static bool addOptionsToPlugin(AppDescription &appDesc, const QString &optionIde
|
||||
{
|
||||
const QJsonArray plugins((*optionsObjectIt).toObject()[QStringLiteral("Plugins")].toArray());
|
||||
|
||||
for (const auto &pluginElem : plugins)
|
||||
for (const auto& pluginElem : plugins)
|
||||
{
|
||||
const QString pluginName = pluginElem.toString();
|
||||
if (!ignoredPlugins.contains(pluginName))
|
||||
@@ -63,14 +57,14 @@ static bool addOptionsToPlugin(AppDescription &appDesc, const QString &optionIde
|
||||
|
||||
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 true;
|
||||
}
|
||||
|
||||
|
||||
App LtsAppDescriptor::appFromInteger(int i)
|
||||
{
|
||||
switch (i)
|
||||
@@ -102,13 +96,11 @@ App LtsAppDescriptor::appFromInteger(int i)
|
||||
return App::Login;
|
||||
}
|
||||
|
||||
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray &jsonDocument,
|
||||
QStringList &lastErrors,
|
||||
const QStringList &ignoredPlugins,
|
||||
QString &loginPluginIid)
|
||||
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray& jsonDocument, QStringList& lastErrors,
|
||||
const QStringList& ignoredPlugins,
|
||||
QString& loginPluginIid)
|
||||
{
|
||||
|
||||
|
||||
AppDescriptionVector appDescriptions;
|
||||
|
||||
QJsonParseError parseError;
|
||||
@@ -117,7 +109,6 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
||||
if (parseError.error != QJsonParseError::NoError)
|
||||
{
|
||||
|
||||
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
QChar x = QLatin1Char('\n');
|
||||
@@ -138,8 +129,10 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -154,14 +147,11 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
||||
return appDescriptions;
|
||||
}
|
||||
|
||||
|
||||
for (const auto &appElem : appArray)
|
||||
for (const auto& appElem : appArray)
|
||||
{
|
||||
AppDescription appDesc;
|
||||
const QJsonObject appObject = appElem.toObject();
|
||||
|
||||
|
||||
|
||||
appDesc.id = appFromInteger(appObject.value(QStringLiteral("Id")).toInt(-1));
|
||||
if (appDesc.id == App::Login)
|
||||
{
|
||||
@@ -176,7 +166,9 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -185,31 +177,30 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
||||
const QJsonValue valueVisible = appObject.value(QStringLiteral("Visible"));
|
||||
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;
|
||||
}
|
||||
appDesc.visible = valueVisible.toBool(true);
|
||||
|
||||
const QJsonArray array(appObject.value(QStringLiteral("ACLs")).toArray());
|
||||
for (const QJsonValue &value : array)
|
||||
for (const QJsonValue& value : array)
|
||||
appDesc.requiredAcls.append(value.toInt());
|
||||
|
||||
|
||||
|
||||
const QJsonObject optionsObject(appObject.value(QStringLiteral("Options")).toObject());
|
||||
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject, PluginInfo::Flag::PAYLOAD, lastErrors, false);
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Actions"), ignoredPlugins, optionsObject, PluginInfo::Flag::ACTIONS, lastErrors, true );
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Main"), ignoredPlugins, optionsObject, PluginInfo::Flag::MAIN, lastErrors, false);
|
||||
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject,
|
||||
PluginInfo::Flag::PAYLOAD, 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return appDescriptions;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsAppDescriptor
|
||||
Executable → Regular
+23
-24
@@ -1,29 +1,26 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QVector>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
#ifndef LTSAPPDESCRIPTOR_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LTSAPPDESCRIPTOR_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
|
||||
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define LTSAPPDESCRIPTOR_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
|
||||
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace LtsAppDescriptor
|
||||
{
|
||||
|
||||
enum class App
|
||||
{
|
||||
enum class App {
|
||||
Login = -1,
|
||||
Situation = 0,
|
||||
ResourceManager = 1,
|
||||
@@ -49,15 +46,13 @@ enum class App
|
||||
|
||||
struct PluginInfo
|
||||
{
|
||||
enum class PluginType
|
||||
{
|
||||
enum class PluginType {
|
||||
UNKNOWN,
|
||||
DATA,
|
||||
GUI,
|
||||
};
|
||||
|
||||
enum class Flag
|
||||
{
|
||||
enum class Flag {
|
||||
UNKNOWN = 1 << 0,
|
||||
ACTIONS = 1 << 1,
|
||||
MAIN = 1 << 2,
|
||||
@@ -80,17 +75,21 @@ struct AppDescription
|
||||
QVector<int> requiredAcls;
|
||||
QVector<PluginInfo> pluginInfos;
|
||||
|
||||
bool isValid() const { return !appName.isEmpty(); }
|
||||
bool isValid() const
|
||||
{
|
||||
return !appName.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
typedef QVector<AppDescription> AppDescriptionVector;
|
||||
|
||||
|
||||
namespace LtsAppDescriptor
|
||||
{
|
||||
LTSAPPDESCRIPTOR_EXPORT App appFromInteger(int i);
|
||||
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray &jsonDocument, QStringList &lastErrors,
|
||||
const QStringList &ignoredPlugins, QString &loginPluginIid);
|
||||
}
|
||||
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray& jsonDocument,
|
||||
QStringList& lastErrors,
|
||||
const QStringList& ignoredPlugins,
|
||||
QString& loginPluginIid);
|
||||
} // namespace LtsAppDescriptor
|
||||
|
||||
}
|
||||
} // namespace LtsAppDescriptor
|
||||
Executable → Regular
+90
-111
@@ -1,18 +1,16 @@
|
||||
#include "lts_app_descriptor_editor.h"
|
||||
|
||||
#include "ui_lts_app_descriptor_editor.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QStringListModel>
|
||||
#include <QFileDialog>
|
||||
#include <QJsonDocument>
|
||||
#include <QMessageBox>
|
||||
#include <QStringListModel>
|
||||
#include <QTimer>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
LtsAppDescriptorEditor::LtsAppDescriptorEditor(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui_LtsAppDescriptionEditor)
|
||||
LtsAppDescriptorEditor::LtsAppDescriptorEditor(QWidget* parent) : QWidget(parent), m_ui(new Ui_LtsAppDescriptionEditor)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_vector = LtsAppDescriptor::AppDescriptionVector();
|
||||
@@ -50,10 +48,10 @@ LtsAppDescriptorEditor::~LtsAppDescriptorEditor()
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void LtsAppDescriptorEditor::getAppDescriptionVector()
|
||||
{
|
||||
m_fileName = QFileDialog::getOpenFileName(this, tr("Open JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"),
|
||||
m_fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("Open JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"),
|
||||
tr("JSON File (*.json)"));
|
||||
if (m_fileName.isEmpty())
|
||||
return;
|
||||
@@ -70,7 +68,7 @@ void LtsAppDescriptorEditor::getAppDescriptionVector()
|
||||
updateAppModel();
|
||||
}
|
||||
|
||||
void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
||||
void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex& index)
|
||||
{
|
||||
m_ui->gbPlugins->setEnabled(true);
|
||||
m_ui->pbDeleteApp->setEnabled(true);
|
||||
@@ -79,40 +77,40 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
||||
m_appIndex = index;
|
||||
|
||||
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;
|
||||
QString type;
|
||||
if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::DATA)
|
||||
type = QLatin1String("data");
|
||||
else if(pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
||||
else if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
||||
type = QLatin1String("gui");
|
||||
else
|
||||
type = QLatin1String("unknown");
|
||||
|
||||
if(type == QLatin1String("data"))
|
||||
pluginList << QString(type + QLatin1String(": ") +reqPlugin.iid);
|
||||
if (type == QLatin1String("data"))
|
||||
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid);
|
||||
else
|
||||
{
|
||||
QString strFlags;
|
||||
QFlags<LtsAppDescriptor::PluginInfo::Flag> flags = reqPlugin.flags;
|
||||
|
||||
bool actionsFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::ACTIONS);
|
||||
if(actionsFlag)
|
||||
if (actionsFlag)
|
||||
strFlags.append(QLatin1String("actions "));
|
||||
bool mainFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::MAIN);
|
||||
if(mainFlag)
|
||||
if (mainFlag)
|
||||
strFlags.append(QLatin1String("main "));
|
||||
bool payloadFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::PAYLOAD);
|
||||
if(payloadFlag)
|
||||
if (payloadFlag)
|
||||
strFlags.append(QLatin1String("payload "));
|
||||
bool optionalFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::OPTION);
|
||||
if(optionalFlag)
|
||||
if (optionalFlag)
|
||||
strFlags.append(QLatin1String("optional "));
|
||||
|
||||
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid + QLatin1String(" [ ") + strFlags + QLatin1String("]"));
|
||||
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid + QLatin1String(" [ ") + strFlags +
|
||||
QLatin1String("]"));
|
||||
}
|
||||
|
||||
}
|
||||
updatePluginModel(pluginList);
|
||||
|
||||
@@ -120,7 +118,7 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
||||
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_ui->pbDeletePlugin->setEnabled(true);
|
||||
@@ -135,13 +133,13 @@ void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex &index)
|
||||
QString type;
|
||||
if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::DATA)
|
||||
type = QLatin1String("data");
|
||||
else if(pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
||||
else if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
||||
type = QLatin1String("gui");
|
||||
else
|
||||
type = QLatin1String("unknown");
|
||||
m_ui->lePluginType->setText(type);
|
||||
|
||||
if(type == QLatin1String("gui"))
|
||||
if (type == QLatin1String("gui"))
|
||||
{
|
||||
m_ui->chbActions->setEnabled(true);
|
||||
m_ui->chbMain->setEnabled(true);
|
||||
@@ -168,16 +166,16 @@ void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex &index)
|
||||
|
||||
void LtsAppDescriptorEditor::pluginTypeChanged()
|
||||
{
|
||||
if(m_ui->lePluginType->text().isEmpty())
|
||||
if (m_ui->lePluginType->text().isEmpty())
|
||||
return;
|
||||
|
||||
if(m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||
{
|
||||
m_ui->chbActions->setEnabled(true);
|
||||
m_ui->chbMain->setEnabled(true);
|
||||
m_ui->chbPayload->setEnabled(true);
|
||||
}
|
||||
else if(m_ui->lePluginType->text() == QLatin1String("data"))
|
||||
else if (m_ui->lePluginType->text() == QLatin1String("data"))
|
||||
{
|
||||
m_ui->chbActions->setChecked(false);
|
||||
m_ui->chbActions->setEnabled(false);
|
||||
@@ -188,8 +186,7 @@ void LtsAppDescriptorEditor::pluginTypeChanged()
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Information,
|
||||
tr("Error"),
|
||||
QMessageBox msgBox(QMessageBox::Information, tr("Error"),
|
||||
tr("Plugin Type must either be \"gui\" or \"data\"."));
|
||||
msgBox.exec();
|
||||
m_ui->lePluginType->setText(QString());
|
||||
@@ -200,25 +197,22 @@ void LtsAppDescriptorEditor::onAppAddClicked()
|
||||
{
|
||||
m_changed = true;
|
||||
|
||||
if(m_ui->leAppName->text().isEmpty())
|
||||
if (m_ui->leAppName->text().isEmpty())
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Critical,
|
||||
tr("Error"),
|
||||
tr("The App needs to have a name."));
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The App needs to have a name."));
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList appList;
|
||||
Q_FOREACH(const LtsAppDescriptor::AppDescription &appDesc, m_vector)
|
||||
Q_FOREACH (const LtsAppDescriptor::AppDescription& appDesc, m_vector)
|
||||
{
|
||||
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"),
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
|
||||
tr("There already exists an app named \"%1\".").arg(m_ui->leAppName->text()));
|
||||
msgBox.exec();
|
||||
return;
|
||||
@@ -230,83 +224,74 @@ void LtsAppDescriptorEditor::onAppAddClicked()
|
||||
m_vector.append(newApp);
|
||||
|
||||
updateAppModel();
|
||||
|
||||
}
|
||||
|
||||
void LtsAppDescriptorEditor::onPluginAddClicked()
|
||||
{
|
||||
m_changed = true;
|
||||
|
||||
if(m_ui->lePluginType->text().isEmpty())
|
||||
if (m_ui->lePluginType->text().isEmpty())
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Critical,
|
||||
tr("Error"),
|
||||
tr("The Plugin needs to contain a type."));
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to contain a type."));
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
if(m_ui->lePluginName->text().isEmpty())
|
||||
if (m_ui->lePluginName->text().isEmpty())
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Critical,
|
||||
tr("Error"),
|
||||
tr("The Plugin needs to have a name."));
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to have a name."));
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(pluginList.contains(m_ui->lePluginName->text(),Qt::CaseInsensitive))
|
||||
if (pluginList.contains(m_ui->lePluginName->text(), Qt::CaseInsensitive))
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Critical,
|
||||
tr("Error"),
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
|
||||
tr("There already exists an plugin named \"%1\".").arg(m_ui->lePluginName->text()));
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LtsAppDescriptor::PluginInfo newPlugin;
|
||||
|
||||
newPlugin.iid = m_ui->lePluginName->text();
|
||||
|
||||
if(m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||
newPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
||||
else if(m_ui->lePluginType->text() == QLatin1String("data"))
|
||||
else if (m_ui->lePluginType->text() == QLatin1String("data"))
|
||||
newPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
else
|
||||
newPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
||||
|
||||
if(m_ui->chbActions->isChecked())
|
||||
if (m_ui->chbActions->isChecked())
|
||||
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
||||
if(m_ui->chbMain->isChecked())
|
||||
if (m_ui->chbMain->isChecked())
|
||||
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
||||
if(m_ui->chbPayload->isChecked())
|
||||
if (m_ui->chbPayload->isChecked())
|
||||
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
||||
|
||||
m_vector[m_appIndex.row()].requiredPlugins.append(newPlugin);
|
||||
|
||||
onAppsClicked(m_appIndex);
|
||||
onNewpluginClicked();
|
||||
|
||||
}
|
||||
|
||||
void LtsAppDescriptorEditor::onAppDeleteClicked()
|
||||
{
|
||||
m_changed = true;
|
||||
|
||||
if(!m_appIndex.isValid()) return;
|
||||
if (!m_appIndex.isValid())
|
||||
return;
|
||||
|
||||
QMessageBox msgBox(tr("Warning"),
|
||||
tr("The App \n\"%1\" \nwill be removed. Continue?").arg(m_appIndex.data().toString()),
|
||||
QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No | QMessageBox::Escape,
|
||||
QMessageBox::NoButton);
|
||||
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||
|
||||
if (msgBox.exec() == QMessageBox::No)
|
||||
return;
|
||||
@@ -314,21 +299,19 @@ void LtsAppDescriptorEditor::onAppDeleteClicked()
|
||||
m_vector.remove(m_appIndex.row());
|
||||
|
||||
updateAppModel();
|
||||
|
||||
}
|
||||
|
||||
void LtsAppDescriptorEditor::onPluginDeletedClicked()
|
||||
{
|
||||
m_changed = true;
|
||||
|
||||
if(!m_pluginIndex.isValid()) return;
|
||||
if (!m_pluginIndex.isValid())
|
||||
return;
|
||||
|
||||
QMessageBox msgBox(tr("Warning"),
|
||||
tr("The Plugin \n\"%1\" \nwill be removed. Continue?").arg(m_pluginIndex.data().toString()),
|
||||
QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No | QMessageBox::Escape,
|
||||
QMessageBox::NoButton);
|
||||
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||
|
||||
if (msgBox.exec() == QMessageBox::No)
|
||||
return;
|
||||
@@ -352,40 +335,43 @@ void LtsAppDescriptorEditor::onUpdateClicked()
|
||||
{
|
||||
m_changed = true;
|
||||
|
||||
if(m_ui->lePluginType->text().isEmpty())
|
||||
if (m_ui->lePluginType->text().isEmpty())
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Critical,
|
||||
tr("Error"),
|
||||
tr("The Plugin needs to contain a type."));
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to contain a type."));
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
if(m_ui->lePluginName->text().isEmpty())
|
||||
if (m_ui->lePluginName->text().isEmpty())
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Critical,
|
||||
tr("Error"),
|
||||
tr("The Plugin needs to have a name."));
|
||||
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to have a name."));
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].iid = m_ui->lePluginName->text();
|
||||
|
||||
if(m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
||||
else if(m_ui->lePluginType->text() == QLatin1String("data"))
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||
LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
||||
else if (m_ui->lePluginType->text() == QLatin1String("data"))
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||
LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
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())
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
||||
if(m_ui->chbMain->isChecked())
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
||||
if(m_ui->chbPayload->isChecked())
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
||||
if (m_ui->chbActions->isChecked())
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||
LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
||||
if (m_ui->chbMain->isChecked())
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||
LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
||||
if (m_ui->chbPayload->isChecked())
|
||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||
LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
||||
|
||||
onAppsClicked(m_appIndex);
|
||||
onNewpluginClicked();
|
||||
@@ -405,8 +391,8 @@ void LtsAppDescriptorEditor::onNewpluginClicked()
|
||||
m_ui->pbNewPlugin->setEnabled(false);
|
||||
m_ui->pbDeletePlugin->setEnabled(false);
|
||||
|
||||
if(m_pluginIndex.isValid())
|
||||
m_ui->lvPlugins->selectionModel()->select(m_pluginIndex,QItemSelectionModel::Deselect);
|
||||
if (m_pluginIndex.isValid())
|
||||
m_ui->lvPlugins->selectionModel()->select(m_pluginIndex, QItemSelectionModel::Deselect);
|
||||
m_pluginIndex = QModelIndex();
|
||||
}
|
||||
|
||||
@@ -429,8 +415,8 @@ void LtsAppDescriptorEditor::onNewAppClicked()
|
||||
m_ui->chbPayload->setChecked(false);
|
||||
m_ui->pbNewApp->setEnabled(false);
|
||||
|
||||
if(m_appIndex.isValid())
|
||||
m_ui->lvApps->selectionModel()->select(m_appIndex,QItemSelectionModel::Deselect);
|
||||
if (m_appIndex.isValid())
|
||||
m_ui->lvApps->selectionModel()->select(m_appIndex, QItemSelectionModel::Deselect);
|
||||
m_appIndex = QModelIndex();
|
||||
}
|
||||
|
||||
@@ -438,24 +424,24 @@ void LtsAppDescriptorEditor::updateAppModel()
|
||||
{
|
||||
onNewAppClicked();
|
||||
QStringList appList;
|
||||
Q_FOREACH(const LtsAppDescriptor::AppDescription &appDesc, m_vector)
|
||||
Q_FOREACH (const LtsAppDescriptor::AppDescription& appDesc, m_vector)
|
||||
{
|
||||
appList << appDesc.appName;
|
||||
}
|
||||
|
||||
if (!m_ui->lvApps->model())
|
||||
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)
|
||||
return;
|
||||
m->setStringList(appList);
|
||||
}
|
||||
|
||||
void LtsAppDescriptorEditor::updatePluginModel(const QStringList &list)
|
||||
void LtsAppDescriptorEditor::updatePluginModel(const QStringList& list)
|
||||
{
|
||||
if (!m_ui->lvPlugins->model())
|
||||
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)
|
||||
return;
|
||||
m->setStringList(list);
|
||||
@@ -463,14 +449,11 @@ void LtsAppDescriptorEditor::updatePluginModel(const QStringList &list)
|
||||
|
||||
void LtsAppDescriptorEditor::checkSave()
|
||||
{
|
||||
if(m_changed)
|
||||
if (m_changed)
|
||||
{
|
||||
QMessageBox msgBox(tr("Warning"),
|
||||
tr("The Data has been modified.\nDo you want to save your changes?"),
|
||||
QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No | QMessageBox::Escape,
|
||||
QMessageBox::NoButton);
|
||||
QMessageBox msgBox(tr("Warning"), tr("The Data has been modified.\nDo you want to save your changes?"),
|
||||
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||
|
||||
if (msgBox.exec() == QMessageBox::Yes)
|
||||
onSaveAsClicked();
|
||||
@@ -479,9 +462,10 @@ void LtsAppDescriptorEditor::checkSave()
|
||||
|
||||
void LtsAppDescriptorEditor::onSaveAsClicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save JSON"), QLatin1Literal("/shd/CTC/TOOLS/TDS/TDS-source/Lts/Projects/Legatus/resources/"),
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
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;
|
||||
|
||||
QByteArray jsonByteArray;
|
||||
@@ -494,9 +478,7 @@ void LtsAppDescriptorEditor::onSaveAsClicked()
|
||||
|
||||
m_changed = false;
|
||||
|
||||
QMessageBox msgBox(QMessageBox::Information,
|
||||
tr("Success"),
|
||||
tr("Your file has been saved."));
|
||||
QMessageBox msgBox(QMessageBox::Information, tr("Success"), tr("Your file has been saved."));
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
@@ -511,9 +493,7 @@ void LtsAppDescriptorEditor::onSaveClicked()
|
||||
|
||||
m_changed = false;
|
||||
|
||||
QMessageBox msgBox(QMessageBox::Information,
|
||||
tr("Success"),
|
||||
tr("Your file has been saved."));
|
||||
QMessageBox msgBox(QMessageBox::Information, tr("Success"), tr("Your file has been saved."));
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
@@ -540,7 +520,6 @@ void LtsAppDescriptorEditor::onNewClicked()
|
||||
|
||||
updateAppModel();
|
||||
updatePluginModel(QStringList());
|
||||
|
||||
}
|
||||
|
||||
void LtsAppDescriptorEditor::enableNewPlugin()
|
||||
|
||||
Executable → Regular
+22
-24
@@ -1,36 +1,34 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "lts_app_descriptor.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QObject>
|
||||
#include <QtWidgets/QWidget>
|
||||
|
||||
#ifndef LTSAPPDESCRIPTOREDITOR_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LTSAPPDESCRIPTOREDITOR_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_LTSAPPDESCRIPTOREDITOR_LIB)
|
||||
# define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define LTSAPPDESCRIPTOREDITOR_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_LTSAPPDESCRIPTOREDITOR_LIB)
|
||||
#define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class Ui_LtsAppDescriptionEditor;
|
||||
|
||||
|
||||
class LTSAPPDESCRIPTOREDITOR_EXPORT LtsAppDescriptorEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsAppDescriptorEditor(QWidget *parent = 0);
|
||||
public:
|
||||
explicit LtsAppDescriptorEditor(QWidget* parent = 0);
|
||||
~LtsAppDescriptorEditor();
|
||||
|
||||
private:
|
||||
Ui_LtsAppDescriptionEditor *m_ui;
|
||||
private:
|
||||
Ui_LtsAppDescriptionEditor* m_ui;
|
||||
LtsAppDescriptor::AppDescriptionVector m_vector;
|
||||
QModelIndex m_appIndex;
|
||||
QModelIndex m_pluginIndex;
|
||||
@@ -42,12 +40,12 @@ private:
|
||||
void getAppDescriptionVector();
|
||||
void setupMainWindow();
|
||||
void updateAppModel();
|
||||
void updatePluginModel(const QStringList &list);
|
||||
void updatePluginModel(const QStringList& list);
|
||||
void checkSave();
|
||||
|
||||
private slots:
|
||||
void onAppsClicked(const QModelIndex &index);
|
||||
void onPluginsClicked(const QModelIndex &index);
|
||||
private slots:
|
||||
void onAppsClicked(const QModelIndex& index);
|
||||
void onPluginsClicked(const QModelIndex& index);
|
||||
void pluginTypeChanged();
|
||||
void onAppAddClicked();
|
||||
void onPluginAddClicked();
|
||||
@@ -58,7 +56,7 @@ private slots:
|
||||
void onNewAppClicked();
|
||||
void enableNewPlugin();
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void onSaveClicked();
|
||||
void onSaveAsClicked();
|
||||
void onOpenClicked();
|
||||
|
||||
Executable → Regular
+10
-11
@@ -1,46 +1,45 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_app_descriptor_editor.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QMenuBar>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QMainWindow *mainWindow = new QMainWindow();
|
||||
QMenu *fileMenu = mainWindow->menuBar()->addMenu(QObject::tr("&File"));
|
||||
QMainWindow* mainWindow = new QMainWindow();
|
||||
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->setStatusTip(QObject::tr("Open an existing file"));
|
||||
fileMenu->addAction(openAct);
|
||||
|
||||
QAction *newAct = new QAction(QObject::tr("&New"), mainWindow);
|
||||
QAction* newAct = new QAction(QObject::tr("&New"), mainWindow);
|
||||
newAct->setShortcuts(QKeySequence::New);
|
||||
newAct->setStatusTip(QObject::tr("Create a new App"));
|
||||
fileMenu->addAction(newAct);
|
||||
|
||||
QAction *saveAct = new QAction(QObject::tr("&Save"), mainWindow);
|
||||
QAction* saveAct = new QAction(QObject::tr("&Save"), mainWindow);
|
||||
saveAct->setShortcuts(QKeySequence::Save);
|
||||
saveAct->setStatusTip(QObject::tr("Save modified file"));
|
||||
fileMenu->addAction(saveAct);
|
||||
|
||||
QAction *saveAsAct = new QAction(QObject::tr("&SaveAs"), mainWindow);
|
||||
QAction* saveAsAct = new QAction(QObject::tr("&SaveAs"), mainWindow);
|
||||
saveAsAct->setShortcuts(QKeySequence::SaveAs);
|
||||
saveAsAct->setStatusTip(QObject::tr("Save modified file as"));
|
||||
fileMenu->addAction(saveAsAct);
|
||||
|
||||
QAction *quitAct = new QAction(QObject::tr("&Quit"), mainWindow);
|
||||
QAction* quitAct = new QAction(QObject::tr("&Quit"), mainWindow);
|
||||
quitAct->setShortcuts(QKeySequence::Quit);
|
||||
quitAct->setStatusTip(QObject::tr("Quit the Application"));
|
||||
fileMenu->addAction(quitAct);
|
||||
|
||||
|
||||
LtsAppDescriptorEditor *editor = new LtsAppDescriptorEditor(mainWindow);
|
||||
LtsAppDescriptorEditor* editor = new LtsAppDescriptorEditor(mainWindow);
|
||||
mainWindow->setCentralWidget(editor);
|
||||
QObject::connect(openAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onOpenClicked);
|
||||
QObject::connect(newAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onNewClicked);
|
||||
|
||||
Executable → Regular
+5
-8
@@ -1,17 +1,14 @@
|
||||
|
||||
|
||||
|
||||
#include "app.h"
|
||||
#include "ui_app.h"
|
||||
#include "AppChooser/app_chooser_model.h"
|
||||
|
||||
#include "AppChooser/app_chooser_model.h"
|
||||
#include "ui_app.h"
|
||||
|
||||
namespace LtsAppManager
|
||||
{
|
||||
|
||||
CustomViewApp::CustomViewApp(QWidget *parent)
|
||||
: AbstractDisplayWidget(parent)
|
||||
, m_ui(new Ui::CustomViewApp)
|
||||
CustomViewApp::CustomViewApp(QWidget* parent) : AbstractDisplayWidget(parent), m_ui(new Ui::CustomViewApp)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->image->setMenuEnabled(false);
|
||||
@@ -22,7 +19,7 @@ CustomViewApp::~CustomViewApp()
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
bool CustomViewApp::init(const QModelIndex &idx)
|
||||
bool CustomViewApp::init(const QModelIndex& idx)
|
||||
{
|
||||
if (!idx.isValid())
|
||||
return false;
|
||||
@@ -32,4 +29,4 @@ bool CustomViewApp::init(const QModelIndex &idx)
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+5
-8
@@ -2,10 +2,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <Viewer/LtsDataView/abstract_display_widget.h>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CustomViewApp;
|
||||
@@ -18,14 +16,13 @@ class CustomViewApp final : public LtsDataView::AbstractDisplayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomViewApp(QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit CustomViewApp(QWidget* parent = nullptr);
|
||||
~CustomViewApp();
|
||||
bool init(const QModelIndex &idx) override;
|
||||
bool init(const QModelIndex& idx) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui::CustomViewApp* m_ui;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+13
-26
@@ -1,38 +1,30 @@
|
||||
|
||||
|
||||
#include "AppChooser/app_chooser.h"
|
||||
#include "ui_app_chooser.h"
|
||||
|
||||
#include "AppChooser/CustomViews/app.h"
|
||||
#include "AppChooser/app_chooser_model.h"
|
||||
#include "lts_app_manager.h"
|
||||
#include "AppChooser/CustomViews/app.h"
|
||||
#include "ui_app_chooser.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsAppManager
|
||||
{
|
||||
|
||||
AppChooser::AppChooser()
|
||||
: QWidget(nullptr)
|
||||
, m_ui(new Ui::AppChooser)
|
||||
, m_model()
|
||||
, m_madeSelection(false)
|
||||
AppChooser::AppChooser() : QWidget(nullptr), m_ui(new Ui::AppChooser), m_model(), m_madeSelection(false)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalDoubleClicked,
|
||||
this, &AppChooser::slotAppSelected);
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalEnterPressed,
|
||||
this, &AppChooser::slotAppSelected);
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalSelectionChanged,
|
||||
this, &AppChooser::enaDisa);
|
||||
connect(m_ui->pbQuit, &QPushButton::clicked,
|
||||
this, &QWidget::close);
|
||||
connect(m_ui->pbSelect, &QPushButton::clicked,
|
||||
this, &AppChooser::slotAppSelected);
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalDoubleClicked, this,
|
||||
&AppChooser::slotAppSelected);
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalEnterPressed, this,
|
||||
&AppChooser::slotAppSelected);
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalSelectionChanged, this, &AppChooser::enaDisa);
|
||||
connect(m_ui->pbQuit, &QPushButton::clicked, this, &QWidget::close);
|
||||
connect(m_ui->pbSelect, &QPushButton::clicked, this, &AppChooser::slotAppSelected);
|
||||
|
||||
m_model = new AppChooserModel(this);
|
||||
m_model->initModel(LtsAppManager::getInstance()->getAvailableApps());
|
||||
@@ -43,14 +35,12 @@ AppChooser::AppChooser()
|
||||
m_ui->widget->hideColumn(AppChooserModel::Columns::Visible);
|
||||
}
|
||||
|
||||
|
||||
AppChooser::~AppChooser()
|
||||
{
|
||||
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
void AppChooser::slotQuit()
|
||||
{
|
||||
if (m_alreadyCloseEmitted)
|
||||
@@ -59,14 +49,12 @@ void AppChooser::slotQuit()
|
||||
emit signalLogout();
|
||||
}
|
||||
|
||||
|
||||
void AppChooser::closeEvent(QCloseEvent *)
|
||||
void AppChooser::closeEvent(QCloseEvent*)
|
||||
{
|
||||
if (!m_madeSelection)
|
||||
slotQuit();
|
||||
}
|
||||
|
||||
|
||||
void AppChooser::slotAppSelected()
|
||||
{
|
||||
const QModelIndex idx = m_ui->widget->currentIndex();
|
||||
@@ -81,7 +69,6 @@ void AppChooser::slotAppSelected()
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void AppChooser::enaDisa()
|
||||
{
|
||||
const QModelIndexList selectedRows = m_ui->widget->selectedRows();
|
||||
@@ -90,4 +77,4 @@ void AppChooser::enaDisa()
|
||||
m_ui->pbSelect->setEnabled(cntSelectedRows == 1);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+12
-15
@@ -1,16 +1,14 @@
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QWidget>
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AppChooser;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsAppManager
|
||||
{
|
||||
|
||||
@@ -20,29 +18,28 @@ class AppChooser : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
AppChooser();
|
||||
~AppChooser();
|
||||
|
||||
private:
|
||||
Ui::AppChooser *m_ui;
|
||||
AppChooserModel *m_model;
|
||||
private:
|
||||
Ui::AppChooser* m_ui;
|
||||
AppChooserModel* m_model;
|
||||
bool m_madeSelection;
|
||||
bool m_alreadyCloseEmitted { false };
|
||||
bool m_alreadyCloseEmitted{false};
|
||||
|
||||
void enaDisa();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
protected:
|
||||
void closeEvent(QCloseEvent*);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void signalAppSelected(LtsAppDescriptor::App appId);
|
||||
void signalLogout();
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void slotAppSelected();
|
||||
void slotQuit();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+7
-9
@@ -4,17 +4,16 @@
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
|
||||
|
||||
namespace LtsAppManager
|
||||
{
|
||||
|
||||
AppChooserModel::AppChooserModel(QObject *parent)
|
||||
AppChooserModel::AppChooserModel(QObject* parent)
|
||||
: LtsWidgets::LtsAbstractTableModel<LtsAppDescriptor::AppDescription>({tr("Name")}, parent)
|
||||
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool AppChooserModel::initModel(const LtsAppDescriptor::AppDescriptionVector &availableApps)
|
||||
bool AppChooserModel::initModel(const LtsAppDescriptor::AppDescriptionVector& availableApps)
|
||||
{
|
||||
for (auto i = availableApps.constBegin(); i != availableApps.constEnd(); ++i)
|
||||
{
|
||||
@@ -29,13 +28,12 @@ bool AppChooserModel::initModel(const LtsAppDescriptor::AppDescriptionVector &av
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QVariant AppChooserModel::data(const QModelIndex &index, int role) const
|
||||
QVariant AppChooserModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole || !indexIsValid(index))
|
||||
return QVariant();
|
||||
|
||||
const LtsAppDescriptor::AppDescription &ad = m_vecData.at(index.row());
|
||||
const LtsAppDescriptor::AppDescription& ad = m_vecData.at(index.row());
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
@@ -47,4 +45,4 @@ QVariant AppChooserModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+7
-12
@@ -1,12 +1,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <LtsWidgets/lts_abstract_table_model.h>
|
||||
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsAppManager
|
||||
{
|
||||
@@ -14,17 +10,16 @@ class AppChooserModel final : public LtsWidgets::LtsAbstractTableModel<LtsAppDes
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Columns
|
||||
{
|
||||
public:
|
||||
enum Columns {
|
||||
Name = 0,
|
||||
Visible,
|
||||
};
|
||||
|
||||
explicit AppChooserModel(QObject *parent = nullptr);
|
||||
explicit AppChooserModel(QObject* parent = nullptr);
|
||||
|
||||
bool initModel(const LtsAppDescriptor::AppDescriptionVector &availableApps);
|
||||
bool initModel(const LtsAppDescriptor::AppDescriptionVector& availableApps);
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override final;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override final;
|
||||
};
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+188
-377
File diff suppressed because it is too large.
Load diff
Executable → Regular
+60
-47
@@ -1,27 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <memory>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifndef LTSAPPMANAGER_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LTSAPPMANAGER_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_LTSAPPMANAGER_LIB)
|
||||
# define LTSAPPMANAGER_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LTSAPPMANAGER_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define LTSAPPMANAGER_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_LTSAPPMANAGER_LIB)
|
||||
#define LTSAPPMANAGER_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define LTSAPPMANAGER_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace LtsPluginManager
|
||||
{
|
||||
@@ -37,7 +35,7 @@ namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
struct DdsConnectionParams;
|
||||
}
|
||||
} // namespace LtsSession
|
||||
|
||||
namespace DeveloperTools
|
||||
{
|
||||
@@ -46,7 +44,6 @@ class DevDialog;
|
||||
|
||||
class QTcpSocket;
|
||||
|
||||
|
||||
namespace LtsAppManager
|
||||
{
|
||||
|
||||
@@ -54,70 +51,86 @@ class LTSAPPMANAGER_EXPORT LtsAppManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
static LtsAppManager* getInstance();
|
||||
|
||||
void showLogin();
|
||||
|
||||
LtsPluginManager::LtsPluginManager* createApp(LtsAppDescriptor::App appId,
|
||||
const LtsSession::DdsConnectionParams& connParams,
|
||||
const QString& workspaceId = QString(), bool hidden = false,
|
||||
bool force = false);
|
||||
bool startAppOrLetUserChoose(LtsAppDescriptor::App appId, const LtsSession::DdsConnectionParams& connParams,
|
||||
bool force = false);
|
||||
|
||||
void setLoginPluginIid(const QString& loginPluginIid)
|
||||
{
|
||||
m_loginPluginIid = loginPluginIid;
|
||||
}
|
||||
|
||||
LtsPluginManager::LtsPluginManager *createApp(LtsAppDescriptor::App appId, const LtsSession::DdsConnectionParams &connParams,
|
||||
const QString &workspaceId = QString(), bool hidden = false, bool force = false);
|
||||
bool startAppOrLetUserChoose(LtsAppDescriptor::App appId, const LtsSession::DdsConnectionParams &connParams, bool force = false);
|
||||
void setLoginPluginIid(const QString &loginPluginIid) { m_loginPluginIid = loginPluginIid; }
|
||||
void setMainApp(LtsAppDescriptor::App appId = LtsAppDescriptor::App::Login);
|
||||
QVector<LtsPluginManager::LtsPluginManager *> getAppList() const { return m_appList ;}
|
||||
LtsAppDescriptor::AppDescriptionVector getAvailableApps() const { return m_availableApps; }
|
||||
void setAvailableApps(const LtsAppDescriptor::AppDescriptionVector &availableApps);
|
||||
bool hasRightForApp(const LtsAppDescriptor::AppDescription &appDescription) const;
|
||||
|
||||
QVector<LtsPluginManager::LtsPluginManager*> getAppList() const
|
||||
{
|
||||
return m_appList;
|
||||
}
|
||||
|
||||
LtsAppDescriptor::AppDescriptionVector getAvailableApps() const
|
||||
{
|
||||
return m_availableApps;
|
||||
}
|
||||
|
||||
void setAvailableApps(const LtsAppDescriptor::AppDescriptionVector& availableApps);
|
||||
bool hasRightForApp(const LtsAppDescriptor::AppDescription& appDescription) const;
|
||||
LtsAppDescriptor::AppDescription getApp(LtsAppDescriptor::App appId) const;
|
||||
bool hasApp(LtsAppDescriptor::App appId) const;
|
||||
int getNumberOfSituationMapInstances() const;
|
||||
void debugSendMessage(const QString &msg);
|
||||
void debugSendMessage(const QString& msg);
|
||||
|
||||
bool otherSessionsResponsibility(LtsSession::LtsSession* thisSession,
|
||||
const QVector<LtsAppDescriptor::App>& requiredAppTypes,
|
||||
const QVector<IDL::PartitionType>& requiredPartitionTypes,
|
||||
const QString& menuGroup, const QString& identifier, LtsWidgets::LayoutArea area);
|
||||
|
||||
|
||||
bool otherSessionsResponsibility(LtsSession::LtsSession *thisSession, const QVector<LtsAppDescriptor::App> &requiredAppTypes,
|
||||
const QVector<IDL::PartitionType> &requiredPartitionTypes, const QString &menuGroup,
|
||||
const QString &identifier, LtsWidgets::LayoutArea area);
|
||||
|
||||
private:
|
||||
private:
|
||||
friend struct LtsAppManagerHandler;
|
||||
friend class DeveloperTools::DevDialog;
|
||||
|
||||
LtsAppManager();
|
||||
~LtsAppManager();
|
||||
|
||||
bool startAppOrLetUserChoose(const LtsAppDescriptor::AppDescription &appDescription, const LtsSession::DdsConnectionParams &connParams, bool force = false);
|
||||
LtsPluginManager::LtsPluginManager *createApp(const LtsAppDescriptor::AppDescription &appDescription,
|
||||
const LtsSession::DdsConnectionParams &connParams,
|
||||
const QString &workspaceId = QString(),
|
||||
bool hidden = false, bool force = false);
|
||||
bool startAppOrLetUserChoose(const LtsAppDescriptor::AppDescription& appDescription,
|
||||
const LtsSession::DdsConnectionParams& connParams, bool force = false);
|
||||
LtsPluginManager::LtsPluginManager* createApp(const LtsAppDescriptor::AppDescription& appDescription,
|
||||
const LtsSession::DdsConnectionParams& connParams,
|
||||
const QString& workspaceId = QString(), bool hidden = false,
|
||||
bool force = false);
|
||||
void saveState();
|
||||
|
||||
LtsAppDescriptor::AppDescriptionVector m_availableApps;
|
||||
QVector<LtsPluginManager::LtsPluginManager *> m_appList;
|
||||
LtsLogin::LtsLogin *m_login;
|
||||
QVector<LtsPluginManager::LtsPluginManager*> m_appList;
|
||||
LtsLogin::LtsLogin* m_login;
|
||||
LtsAppDescriptor::AppDescription m_app;
|
||||
QString m_loginPluginIid;
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void slotLogout();
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void slotQuit();
|
||||
void slotSoftQuit();
|
||||
void slotShowLogin();
|
||||
void slotAppDestroyed();
|
||||
void slotStartDebugServer();
|
||||
void hideAllOtherBLWs(QObject *_caller);
|
||||
void taskSwitch(QObject *_caller);
|
||||
void hideAllOtherBLWs(QObject* _caller);
|
||||
void taskSwitch(QObject* _caller);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void signalLoginDone();
|
||||
void signalLogoffDone();
|
||||
void signalShowLogin();
|
||||
void signalInitializationFinished();
|
||||
void signalCommand(QTcpSocket *client, const QStringList argList);
|
||||
void signalCommand(QTcpSocket* client, const QStringList argList);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsAppManager
|
||||
Executable → Regular
+19
-22
@@ -1,32 +1,30 @@
|
||||
|
||||
|
||||
|
||||
#include "LtsCommandLineParser.h"
|
||||
#include <ngltools/ngltools_filesystem.h>
|
||||
#include <QNetworkInterface>
|
||||
|
||||
#include <QFlags>
|
||||
#include <QNetworkInterface>
|
||||
#include <QSettings>
|
||||
#include <QUrl>
|
||||
#include <ngltools/ngltools_filesystem.h>
|
||||
|
||||
namespace LtsCommandLineParser
|
||||
{
|
||||
static constexpr int s_maxDomainId = 232;
|
||||
|
||||
LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions opts)
|
||||
: QCommandLineParser()
|
||||
, m_enabledOptions(opts)
|
||||
: QCommandLineParser(), m_enabledOptions(opts)
|
||||
{
|
||||
if (NGL::isAppInBuildBasePath() || m_enabledOptions.testFlag(CreateDomainIdFromIp))
|
||||
{
|
||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
||||
for (const QHostAddress &address : addresses)
|
||||
for (const QHostAddress& address : addresses)
|
||||
{
|
||||
if (address.isLoopback() || address.isNull())
|
||||
continue;
|
||||
if (address.protocol() != QAbstractSocket::IPv4Protocol)
|
||||
continue;
|
||||
|
||||
|
||||
m_generatedDomainId = (address.toIPv4Address() & 0x000000ff) % 232;
|
||||
if (m_generatedDomainId == 0)
|
||||
m_generatedDomainId = s_maxDomainId;
|
||||
@@ -38,22 +36,19 @@ LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions op
|
||||
addOption({{QStringLiteral("e"), QStringLiteral("exerciseid")},
|
||||
QStringLiteral("Default: -1 (invalid, get from lts-cc.conf)"),
|
||||
QStringLiteral("exerciseId"),
|
||||
QStringLiteral("-1")
|
||||
});
|
||||
QStringLiteral("-1")});
|
||||
if (m_enabledOptions.testFlag(DomainId))
|
||||
addOption({{QStringLiteral("d"), QStringLiteral("domainid")},
|
||||
QStringLiteral("Default: ") + QString::number(m_generatedDomainId),
|
||||
QStringLiteral("domainId"),
|
||||
QString::number(m_generatedDomainId)
|
||||
});
|
||||
QString::number(m_generatedDomainId)});
|
||||
if (m_enabledOptions.testFlag(CustomConfigFile))
|
||||
{
|
||||
const QString cf(NGL::findProjectConfigFile());
|
||||
addOption({{QStringLiteral("i"), QStringLiteral("ini")},
|
||||
QStringLiteral("Default: ") + cf,
|
||||
QStringLiteral("filename"),
|
||||
cf
|
||||
});
|
||||
cf});
|
||||
}
|
||||
if (m_enabledOptions.testFlag(TcpConnectionUrl))
|
||||
{
|
||||
@@ -61,8 +56,7 @@ LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions op
|
||||
addOption({{QStringLiteral("t"), QStringLiteral("tcpurl")},
|
||||
QStringLiteral("Default: ") + defaultTcpUrl,
|
||||
QStringLiteral("hostname:port"),
|
||||
defaultTcpUrl
|
||||
});
|
||||
defaultTcpUrl});
|
||||
}
|
||||
addHelpOption();
|
||||
|
||||
@@ -76,9 +70,15 @@ int LtsCommandLineParser::domainId() const
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
fprintf(stdout, "\n\nAttention: using a default domain id != 0 because executable is run inside builddir - default domainid is %d\n\n", m_generatedDomainId);
|
||||
fprintf(stdout,
|
||||
"\n\nAttention: using a default domain id != 0 because executable is run inside builddir - default "
|
||||
"domainid is %d\n\n",
|
||||
m_generatedDomainId);
|
||||
#else
|
||||
fprintf(stdout, "\n\n\e[31mAttention: using a default domain id != 0 because executable is run inside builddir - default domainid is %d\e[0m\n\n", m_generatedDomainId);
|
||||
fprintf(stdout,
|
||||
"\n\n\e[31mAttention: using a default domain id != 0 because executable is run inside builddir - "
|
||||
"default domainid is %d\e[0m\n\n",
|
||||
m_generatedDomainId);
|
||||
#endif
|
||||
return m_generatedDomainId;
|
||||
}
|
||||
@@ -115,8 +115,7 @@ QUrl LtsCommandLineParser::tcpConnectionUrl() const
|
||||
|
||||
str.replace(QLatin1String("tcpv4_lan"), QLatin1String("tcpv4lan"));
|
||||
QUrl url = QUrl::fromUserInput(str);
|
||||
if (url.scheme() == QLatin1String("http") ||
|
||||
url.scheme() == QLatin1String("file"))
|
||||
if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("file"))
|
||||
url.setScheme(QStringLiteral("tcpv4lan"));
|
||||
return url;
|
||||
}
|
||||
@@ -161,7 +160,6 @@ void LtsCommandLineParser::showHelp(int exitCode)
|
||||
if (!m_additionalHelpStr.isEmpty())
|
||||
fprintf(stdout, "%s", qPrintable(m_additionalHelpStr));
|
||||
|
||||
|
||||
QCommandLineParser::showHelp(exitCode);
|
||||
}
|
||||
|
||||
@@ -179,5 +177,4 @@ bool LtsCommandLineParser::exerciseIdProvided() const
|
||||
return isSet(QStringLiteral("e"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsCommandLineParser
|
||||
Executable → Regular
+25
-12
@@ -1,19 +1,19 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include "ltscommandlineparser_export.h"
|
||||
|
||||
#include <QCommandLineParser>
|
||||
|
||||
class QUrl;
|
||||
|
||||
namespace LtsCommandLineParser
|
||||
{
|
||||
class LTSCOMMANDLINEPARSER_EXPORT LtsCommandLineParser : public QCommandLineParser
|
||||
{
|
||||
public:
|
||||
enum ProvideCommandLineParameterOptions
|
||||
{
|
||||
public:
|
||||
enum ProvideCommandLineParameterOptions {
|
||||
None = 0x0000,
|
||||
CreateDomainIdFromIp = 0x0001,
|
||||
DomainId = 0x0002,
|
||||
@@ -23,12 +23,22 @@ public:
|
||||
NoVersion = 0x0020
|
||||
};
|
||||
|
||||
explicit LtsCommandLineParser(ProvideCommandLineParameterOptions opts = ProvideCommandLineParameterOptions(CreateDomainIdFromIp|DomainId|ExerciseId|CustomConfigFile));
|
||||
explicit LtsCommandLineParser(ProvideCommandLineParameterOptions opts = ProvideCommandLineParameterOptions(
|
||||
CreateDomainIdFromIp | DomainId | ExerciseId | CustomConfigFile));
|
||||
virtual ~LtsCommandLineParser() = default;
|
||||
int domainId() const;
|
||||
void setDomainId(int id);
|
||||
int exerciseId() const { return m_exerciseId; }
|
||||
QString iniFile() const { return m_iniFile; }
|
||||
|
||||
int exerciseId() const
|
||||
{
|
||||
return m_exerciseId;
|
||||
}
|
||||
|
||||
QString iniFile() const
|
||||
{
|
||||
return m_iniFile;
|
||||
}
|
||||
|
||||
bool iniFileSet() const;
|
||||
bool useTcpConnection() const;
|
||||
QUrl tcpConnectionUrl() const;
|
||||
@@ -38,12 +48,15 @@ public:
|
||||
bool domainIdProvided() const;
|
||||
bool exerciseIdProvided() const;
|
||||
|
||||
void setUnitModuleTestMode(bool onOff) { m_unitModuleTestMode = onOff; }
|
||||
void setUnitModuleTestMode(bool onOff)
|
||||
{
|
||||
m_unitModuleTestMode = onOff;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
QString m_additionalHelpStr;
|
||||
|
||||
private:
|
||||
private:
|
||||
QFlags<ProvideCommandLineParameterOptions> m_enabledOptions;
|
||||
int m_exerciseId{0};
|
||||
int m_domainId{0};
|
||||
@@ -53,4 +66,4 @@ private:
|
||||
QString m_iniFile;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsCommandLineParser
|
||||
Executable → Regular
+4
-7
@@ -1,12 +1,11 @@
|
||||
|
||||
|
||||
|
||||
#include <GeographicLib/UTMUPS.hpp>
|
||||
#include <GeographicLib/MGRS.hpp>
|
||||
#include <GeographicLib/UTMUPS.hpp>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 3 || argc > 5)
|
||||
{
|
||||
@@ -59,9 +58,7 @@ int main(int argc, char **argv)
|
||||
part3 = mgrs.substr(5, prec);
|
||||
part4 = mgrs.substr(5 + prec, prec);
|
||||
}
|
||||
fprintf(stdout, "%13.10f, %13.10f = %s %s %s %s (UTM: %d %.2f, %.2f %c)\n",
|
||||
lon, lat,
|
||||
part1.c_str(), part2.c_str(), part3.c_str(), part4.c_str(),
|
||||
zone, x, y, northp ? 'N' : 'S');
|
||||
fprintf(stdout, "%13.10f, %13.10f = %s %s %s %s (UTM: %d %.2f, %.2f %c)\n", lon, lat, part1.c_str(), part2.c_str(),
|
||||
part3.c_str(), part4.c_str(), zone, x, y, northp ? 'N' : 'S');
|
||||
return 0;
|
||||
}
|
||||
Executable → Regular
+84
-83
@@ -1,19 +1,16 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_coord_trans.h"
|
||||
#include <utility>
|
||||
|
||||
#include <GeographicLib/Geocentric.hpp>
|
||||
#include <GeographicLib/UTMUPS.hpp>
|
||||
#include <GeographicLib/MGRS.hpp>
|
||||
#include <GeographicLib/UTMUPS.hpp>
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
#include <iomanip>
|
||||
#include <utility>
|
||||
|
||||
namespace LtsCoordTrans
|
||||
{
|
||||
@@ -27,16 +24,14 @@ static long s_conversion_counter_WGS84_Reverse = 0;
|
||||
static long s_conversion_counter_UTMUPS_Forward = 0;
|
||||
static long s_conversion_counter_UTMUPS_Reverse = 0;
|
||||
|
||||
|
||||
inline void incrementCounter(long &counterRef)
|
||||
inline void incrementCounter(long& counterRef)
|
||||
{
|
||||
#ifdef LTS_DEBUG
|
||||
++counterRef;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline std::string cleanupMgrsString(const QString &in)
|
||||
static inline std::string cleanupMgrsString(const QString& in)
|
||||
{
|
||||
const QByteArray ba(in.toLatin1());
|
||||
std::string ret;
|
||||
@@ -62,7 +57,7 @@ QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
||||
GeographicLib::MGRS::Forward(zone, northp, x, y, prec, mgrs);
|
||||
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());
|
||||
mgrs.clear();
|
||||
@@ -72,14 +67,13 @@ QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
||||
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)
|
||||
{
|
||||
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
|
||||
@@ -89,7 +83,7 @@ QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
||||
|
||||
QPointF UtmCoordinate::toPoint() const
|
||||
{
|
||||
return {x,y};
|
||||
return {x, y};
|
||||
}
|
||||
|
||||
QPointF UtmCoordinate::geographic(double offsetX, double offsetY) const
|
||||
@@ -100,20 +94,21 @@ QPointF UtmCoordinate::geographic(double offsetX, double offsetY) const
|
||||
GeographicLib::UTMUPS::Reverse(zone, northp, x + offsetX, y + offsetY, ret.ry(), ret.rx());
|
||||
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();
|
||||
}
|
||||
return ret * deg2rad();
|
||||
}
|
||||
|
||||
QPointF UtmCoordinate::geographic(const QPointF &offset) const
|
||||
QPointF UtmCoordinate::geographic(const QPointF& offset) const
|
||||
{
|
||||
return geographic(offset.x(), offset.y());
|
||||
}
|
||||
|
||||
QPointF UtmCoordinate::relativeTo(const UtmCoordinate &other) const
|
||||
QPointF UtmCoordinate::relativeTo(const UtmCoordinate& other) const
|
||||
{
|
||||
if (zone == other.zone)
|
||||
return QPointF(x - other.x, y - other.y);
|
||||
@@ -135,7 +130,7 @@ UtmCoordinate UtmCoordinate::fromGeographic(double lon, double lat, int setZone)
|
||||
GeographicLib::UTMUPS::Forward(lat, lon, ret.zone, ret.northp, ret.x, ret.y, setZone);
|
||||
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());
|
||||
ret = UtmCoordinate();
|
||||
@@ -143,12 +138,12 @@ UtmCoordinate UtmCoordinate::fromGeographic(double lon, double lat, int setZone)
|
||||
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);
|
||||
}
|
||||
|
||||
UtmCoordinate UtmCoordinate::fromMgrs(const QString &mgrs)
|
||||
UtmCoordinate UtmCoordinate::fromMgrs(const QString& mgrs)
|
||||
{
|
||||
UtmCoordinate utm;
|
||||
try
|
||||
@@ -157,9 +152,8 @@ UtmCoordinate UtmCoordinate::fromMgrs(const QString &mgrs)
|
||||
|
||||
GeographicLib::MGRS::Reverse(cleanupMgrsString(mgrs), utm.zone, utm.northp, utm.x, utm.y, prec, true);
|
||||
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());
|
||||
utm = UtmCoordinate();
|
||||
@@ -172,37 +166,34 @@ QString mgrsFromGeographic(double lon, double lat, int prec, bool 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();
|
||||
}
|
||||
|
||||
QVector<UtmCoordinate> &staticDefaultSquaresHelper()
|
||||
QVector<UtmCoordinate>& staticDefaultSquaresHelper()
|
||||
{
|
||||
static QVector<UtmCoordinate> s_defaultMgrsSquares;
|
||||
return s_defaultMgrsSquares;
|
||||
}
|
||||
UtmCoordinate &staticPreferedMgrsSquareHelper()
|
||||
|
||||
UtmCoordinate& staticPreferedMgrsSquareHelper()
|
||||
{
|
||||
static UtmCoordinate s_preferedMgrsSquare;
|
||||
return s_preferedMgrsSquare;
|
||||
}
|
||||
QVector<UtmCoordinate> &staticMgrsSquaresWithOffsetsHelper()
|
||||
|
||||
QVector<UtmCoordinate>& staticMgrsSquaresWithOffsetsHelper()
|
||||
{
|
||||
static QVector<UtmCoordinate> 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;
|
||||
rect_LatLon_radiant.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LtsCoordTrans::UtmCoordinate basePoint;
|
||||
{
|
||||
|
||||
@@ -210,7 +201,6 @@ QRectF addMarginToArea(const QRectF &rect_LatLon_radiant, const QSize &marginMet
|
||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(centerRad.x(), centerRad.y(), -1);
|
||||
mgrs += QStringLiteral("00000000000000");
|
||||
|
||||
|
||||
basePoint = LtsCoordTrans::UtmCoordinate::fromMgrs(mgrs);
|
||||
}
|
||||
|
||||
@@ -227,8 +217,8 @@ QRectF addMarginToArea(const QRectF &rect_LatLon_radiant, const QSize &marginMet
|
||||
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);
|
||||
|
||||
@@ -241,20 +231,17 @@ QVector<UtmCoordinate> getMgrsSquares(const QRectF &rect, bool setAsDefaultSquar
|
||||
if (setAsSquareWithMargin)
|
||||
staticMgrsSquaresWithOffsetsHelper() = ret;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF& rect)
|
||||
{
|
||||
QVector<UtmCoordinate> ret;
|
||||
QVector<QString> tmpMgrsSquares;
|
||||
|
||||
|
||||
double lonMin, lonMax, latMin, latMmax;
|
||||
rect.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
||||
|
||||
|
||||
bool withInSingleUtmSquare = true;
|
||||
{
|
||||
const UtmCoordinate upperRight(UtmCoordinate::fromGeographic(lonMax, latMmax));
|
||||
@@ -262,10 +249,6 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
||||
withInSingleUtmSquare = upperRight.zone == lowerLeft.zone;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LtsCoordTrans::UtmCoordinate basePoint;
|
||||
{
|
||||
|
||||
@@ -273,7 +256,6 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(centerRad.x(), centerRad.y(), -1);
|
||||
mgrs += QStringLiteral("00000000000000");
|
||||
|
||||
|
||||
basePoint = LtsCoordTrans::UtmCoordinate::fromMgrs(mgrs);
|
||||
}
|
||||
|
||||
@@ -283,8 +265,6 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
||||
const double maxX(upperRight.x - lowerLeft.x);
|
||||
const double maxY(upperRight.y - lowerLeft.y);
|
||||
|
||||
|
||||
|
||||
const int increment = withInSingleUtmSquare ? 10000 : 1000;
|
||||
for (double x = 0; x <= maxX + increment; x += increment)
|
||||
{
|
||||
@@ -306,28 +286,26 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
||||
return ret;
|
||||
}
|
||||
|
||||
QStringList getMgrsSurroundingSquares(const QRectF &geoRect, const QSize &offsetMeter)
|
||||
QStringList getMgrsSurroundingSquares(const QRectF& geoRect, const QSize& offsetMeter)
|
||||
{
|
||||
|
||||
const QVector<UtmCoordinate> mainUtms = getMgrsSquaresInternal(geoRect);
|
||||
QStringList mainSquares;
|
||||
mainSquares.reserve(mainUtms.count());
|
||||
for (const auto &utm : mainUtms)
|
||||
for (const auto& utm : mainUtms)
|
||||
mainSquares.append(utm.mgrs(0));
|
||||
|
||||
|
||||
const QRectF rectWithOffset = addMarginToArea(geoRect,offsetMeter);
|
||||
const QRectF rectWithOffset = addMarginToArea(geoRect, offsetMeter);
|
||||
|
||||
QVector<UtmCoordinate> mainUtmsWithOffset = getMgrsSquaresInternal(rectWithOffset);
|
||||
QStringList mainSquaresWithOffset;
|
||||
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));
|
||||
|
||||
|
||||
QStringList surroundingSquares;
|
||||
surroundingSquares.reserve(mainSquaresWithOffset.count());
|
||||
for (const auto & mgrs0 : mainSquaresWithOffset)
|
||||
for (const auto& mgrs0 : mainSquaresWithOffset)
|
||||
{
|
||||
if (!mainSquares.contains(mgrs0))
|
||||
surroundingSquares.append(mgrs0);
|
||||
@@ -341,12 +319,11 @@ QVector<UtmCoordinate> defaultMgrsSquareWithOffsets()
|
||||
return staticMgrsSquaresWithOffsetsHelper();
|
||||
}
|
||||
|
||||
|
||||
void setDefaultMgrsSquares(const QVector<QString> &squares)
|
||||
void setDefaultMgrsSquares(const QVector<QString>& squares)
|
||||
{
|
||||
QVector<UtmCoordinate> coords;
|
||||
coords.reserve(squares.size());
|
||||
for (const QString &s : squares)
|
||||
for (const QString& s : squares)
|
||||
coords += UtmCoordinate::fromMgrs(s + QStringLiteral("00000000000000"));
|
||||
staticDefaultSquaresHelper() = coords;
|
||||
}
|
||||
@@ -361,8 +338,7 @@ UtmCoordinate preferedMgrsSquare()
|
||||
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();
|
||||
@@ -383,11 +359,9 @@ bool lonLatAltToGeocentric(double lon, double lat, double altitude, double &xOut
|
||||
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
|
||||
{
|
||||
GeographicLib::Geocentric::WGS84().Reverse(x, y, z, lat, lon, altitude);
|
||||
@@ -406,41 +380,68 @@ bool geocentric2LonLatAlt(double x, double y, double z,
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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
|
||||
stream << "UtmCoordinate(" << std::setprecision(8) << coord.x << "#" << std::setprecision(8) << coord.y
|
||||
<< " zone=" << coord.zone << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
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_Reverse - fromMgrs : %ld\n" , s_conversion_counter_MGRS_Reverse);
|
||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Forward - lonLatAltToGeocentric : %ld\n" , 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);
|
||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Forward : - mgrs : %ld\n",
|
||||
s_conversion_counter_MGRS_Forward);
|
||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Reverse - fromMgrs : %ld\n",
|
||||
s_conversion_counter_MGRS_Reverse);
|
||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Forward - lonLatAltToGeocentric : %ld\n",
|
||||
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() { return s_conversion_counter_MGRS_Forward; }
|
||||
long getConversionCounter_MGRS_Reverse() { return s_conversion_counter_MGRS_Reverse; }
|
||||
long getConversionCounter_WGS84_Forward() { return s_conversion_counter_WGS84_Forward; }
|
||||
long getConversionCounter_WGS84_Reverse() { return s_conversion_counter_WGS84_Reverse; }
|
||||
long getConversionCounter_UTMUPS_Forward() { return s_conversion_counter_UTMUPS_Forward; }
|
||||
long getConversionCounter_UTMUPS_Reverse() { return s_conversion_counter_UTMUPS_Reverse; }
|
||||
|
||||
long getConversionCounter_MGRS_Forward()
|
||||
{
|
||||
return s_conversion_counter_MGRS_Forward;
|
||||
}
|
||||
|
||||
long getConversionCounter_MGRS_Reverse()
|
||||
{
|
||||
return s_conversion_counter_MGRS_Reverse;
|
||||
}
|
||||
|
||||
long getConversionCounter_WGS84_Forward()
|
||||
{
|
||||
return s_conversion_counter_WGS84_Forward;
|
||||
}
|
||||
|
||||
long getConversionCounter_WGS84_Reverse()
|
||||
{
|
||||
return s_conversion_counter_WGS84_Reverse;
|
||||
}
|
||||
|
||||
long getConversionCounter_UTMUPS_Forward()
|
||||
{
|
||||
return s_conversion_counter_UTMUPS_Forward;
|
||||
}
|
||||
|
||||
long getConversionCounter_UTMUPS_Reverse()
|
||||
{
|
||||
return s_conversion_counter_UTMUPS_Reverse;
|
||||
}
|
||||
|
||||
} // namespace LtsCoordTrans
|
||||
Executable → Regular
+51
-111
@@ -1,13 +1,11 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ltscoordtrans_export.h>
|
||||
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <QVector>
|
||||
#include <cmath>
|
||||
#include <ltscoordtrans_export.h>
|
||||
#include <string>
|
||||
class QPointF;
|
||||
class QRectF;
|
||||
class QSize;
|
||||
@@ -16,12 +14,20 @@ class QString;
|
||||
namespace LtsCoordTrans
|
||||
{
|
||||
|
||||
inline Q_CONSTEXPR double pi()
|
||||
{
|
||||
return M_PI;
|
||||
}
|
||||
|
||||
inline Q_CONSTEXPR double deg2rad()
|
||||
{
|
||||
return pi() / 180.;
|
||||
}
|
||||
|
||||
|
||||
inline Q_CONSTEXPR double pi() { return M_PI; }
|
||||
inline Q_CONSTEXPR double deg2rad() { return pi() / 180.; }
|
||||
inline Q_CONSTEXPR double rad2deg() { return 1. / deg2rad(); }
|
||||
inline Q_CONSTEXPR double rad2deg()
|
||||
{
|
||||
return 1. / deg2rad();
|
||||
}
|
||||
|
||||
struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
||||
{
|
||||
@@ -31,101 +37,60 @@ struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
||||
double y = 0.;
|
||||
|
||||
UtmCoordinate() = default;
|
||||
UtmCoordinate(int zone_, double x_, double y_, bool northp_ = true)
|
||||
: zone(zone_)
|
||||
, northp(northp_)
|
||||
, x(x_)
|
||||
, y(y_)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
bool isValid() const { return zone > 0 && zone <= 60; }
|
||||
|
||||
UtmCoordinate(int zone_, double x_, double y_, bool northp_ = true) : zone(zone_), northp(northp_), x(x_), y(y_) {}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return zone > 0 && zone <= 60;
|
||||
}
|
||||
|
||||
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
||||
|
||||
QPointF toPoint() 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(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 QPointF geographicFromMgrs(const QString& mgrs);
|
||||
|
||||
LTSCOORDTRANS_EXPORT QRectF addMarginToArea(const QRectF& rect_LatLon_radiant, const QSize& marginMeter);
|
||||
|
||||
LTSCOORDTRANS_EXPORT QPointF geographicFromMgrs(const QString &mgrs);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect);
|
||||
|
||||
|
||||
|
||||
QStringList getMgrsSurroundingSquares(const QRectF &geoRect, const QSize &offsetMeter);
|
||||
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> getMgrsSquares(const QRectF& rect, bool setAsDefaultSquares,
|
||||
bool setAsPreferedSquare,
|
||||
bool setAsSquareWithMargin = false);
|
||||
|
||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF& rect);
|
||||
|
||||
QStringList getMgrsSurroundingSquares(const QRectF& geoRect, const QSize& offsetMeter);
|
||||
|
||||
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 UtmCoordinate preferedMgrsSquare();
|
||||
|
||||
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 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);
|
||||
|
||||
|
||||
|
||||
|
||||
inline double squareDistance(const UtmCoordinate &p1, const UtmCoordinate &p2)
|
||||
inline double squareDistance(const UtmCoordinate& p1, const UtmCoordinate& p2)
|
||||
{
|
||||
if (p1.zone != p2.zone)
|
||||
{
|
||||
@@ -135,11 +100,7 @@ inline double squareDistance(const UtmCoordinate &p1, const UtmCoordinate &p2)
|
||||
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)
|
||||
{
|
||||
@@ -148,17 +109,13 @@ inline double squareDistance(const double lon1, const double lat1, const double
|
||||
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));
|
||||
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)
|
||||
{
|
||||
@@ -168,23 +125,18 @@ inline double distance(const UtmCoordinate &p1, const UtmCoordinate &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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
LTSCOORDTRANS_EXPORT void dumpConversionCounter();
|
||||
|
||||
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Forward();
|
||||
@@ -194,28 +146,19 @@ LTSCOORDTRANS_EXPORT long getConversionCounter_WGS84_Reverse();
|
||||
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Forward();
|
||||
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
|
||||
{
|
||||
using BaseClass = LtsCoordTrans::UtmCoordinate;
|
||||
|
||||
public:
|
||||
public:
|
||||
UtmCoordinate3D()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
explicit UtmCoordinate3D(const LtsCoordTrans::UtmCoordinate &utm2d, double _zValue = std::nan(""))
|
||||
:BaseClass()
|
||||
explicit UtmCoordinate3D(const LtsCoordTrans::UtmCoordinate& utm2d, double _zValue = std::nan("")) : BaseClass()
|
||||
{
|
||||
zone = utm2d.zone;
|
||||
northp = utm2d.northp;
|
||||
@@ -229,21 +172,18 @@ public:
|
||||
zone = -1;
|
||||
northp = true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
x = 0.;
|
||||
y = 0.;
|
||||
zValue = std::nan("");
|
||||
}
|
||||
|
||||
double z() const { return zValue; }
|
||||
double z() const
|
||||
{
|
||||
return zValue;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
double zValue{std::nan("")};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsCoordTrans
|
||||
Executable → Regular
+105
-175
@@ -1,12 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_coord_trans_unit_test.h"
|
||||
#include <utility>
|
||||
|
||||
#include "lts_coord_trans.h"
|
||||
|
||||
#include <GeographicLib/Math.hpp>
|
||||
#include <QTest>
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
#include <utility>
|
||||
|
||||
QTEST_MAIN(coordtrans_test)
|
||||
|
||||
@@ -15,14 +16,11 @@ void coordtrans_test::initTestCase()
|
||||
qDebug("sizeof(UtmCoordinate) = %lu", sizeof(LtsCoordTrans::UtmCoordinate));
|
||||
}
|
||||
|
||||
void coordtrans_test::cleanupTestCase()
|
||||
{}
|
||||
void coordtrans_test::cleanupTestCase() {}
|
||||
|
||||
void coordtrans_test::testFromGeographic()
|
||||
{
|
||||
|
||||
|
||||
|
||||
LtsCoordTrans::UtmCoordinate utm;
|
||||
QPointF lonlat;
|
||||
|
||||
@@ -44,8 +42,6 @@ void coordtrans_test::testFromGeographic()
|
||||
utm = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
||||
QCOMPARE(utm.mgrs(5), QStringLiteral("40R BM 85000 85000"));
|
||||
|
||||
|
||||
|
||||
utm = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("40R BM 00000 00000"));
|
||||
QCOMPARE(utm.mgrs(0), QStringLiteral("40Q BM"));
|
||||
}
|
||||
@@ -70,9 +66,7 @@ void coordtrans_test::testRelativeMetricalOffet_data()
|
||||
QTest::addColumn<QPoint>("offset");
|
||||
QTest::addColumn<QString>("correctMgrs");
|
||||
|
||||
|
||||
QTest::newRow("set 1") << QPoint( 5, 5) << QStringLiteral("32U PD 99995 99995");
|
||||
|
||||
QTest::newRow("set 1") << QPoint(5, 5) << QStringLiteral("32U PD 99995 99995");
|
||||
|
||||
QTest::newRow("set 2") << QPoint(100, 100) << QStringLiteral("32U QE 00090 00090");
|
||||
QTest::newRow("set 3") << QPoint(500, 500) << QStringLiteral("32U QE 00490 00490");
|
||||
@@ -83,7 +77,8 @@ void coordtrans_test::testRelativeMetricalOffet()
|
||||
QFETCH(QPoint, offset);
|
||||
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();
|
||||
|
||||
{
|
||||
@@ -96,36 +91,27 @@ void coordtrans_test::testRelativeMetricalOffet()
|
||||
QCOMPARE(utmRaw.mgrs(), correctMgrs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
const LtsCoordTrans::UtmCoordinate utmSimple(utmRef.zone,
|
||||
utmRef.x + offset.x(),
|
||||
utmRef.y + offset.y());
|
||||
const LtsCoordTrans::UtmCoordinate utmSimple(utmRef.zone, utmRef.x + offset.x(), utmRef.y + offset.y());
|
||||
|
||||
qDebug() << "offset = " << offset << " - utmSimple = " << utmSimple.mgrs();
|
||||
QCOMPARE(utmSimple.mgrs(), correctMgrs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
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 bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||
|
||||
|
||||
|
||||
QRectF rect (topLeft, bottomRight);
|
||||
QRectF rect(topLeft, bottomRight);
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
void coordtrans_test::testAddMarginToArea()
|
||||
{
|
||||
|
||||
@@ -134,36 +120,43 @@ void coordtrans_test::testAddMarginToArea()
|
||||
QRectF area = createArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000);
|
||||
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(5000, 20000));
|
||||
|
||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft() << " - degree:" << area.topLeft()*LtsCoordTrans::rad2deg();
|
||||
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft() << " - degree:" << area1Increased.topLeft()*LtsCoordTrans::rad2deg();
|
||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft()
|
||||
<< " - 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() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight() << " - degree:" << area1Increased.bottomRight()*LtsCoordTrans::rad2deg();
|
||||
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight()
|
||||
<< " - degree:" << area.bottomRight() * LtsCoordTrans::rad2deg();
|
||||
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight()
|
||||
<< " - degree:" << area1Increased.bottomRight() * LtsCoordTrans::rad2deg();
|
||||
|
||||
QVERIFY2( area1Increased.topLeft().x() < area.topLeft().x(), "addMarginToArea topLeft X failed");
|
||||
QVERIFY2( area1Increased.topLeft().y() < area.topLeft().y(), "addMarginToArea topLeft Y failed");
|
||||
QVERIFY2(area1Increased.topLeft().x() < area.topLeft().x(), "addMarginToArea topLeft X failed");
|
||||
QVERIFY2(area1Increased.topLeft().y() < area.topLeft().y(), "addMarginToArea topLeft Y failed");
|
||||
|
||||
QVERIFY2( area1Increased.bottomRight().x() > area.bottomRight().x(), "addMarginToArea bottomRight X failed");
|
||||
QVERIFY2( area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y failed");
|
||||
QVERIFY2(area1Increased.bottomRight().x() > area.bottomRight().x(), "addMarginToArea bottomRight X failed");
|
||||
QVERIFY2(area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y failed");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
qDebug() << "Luxemburg";
|
||||
QRectF area = createArea(QStringLiteral("32U LA 0000000000"), 100, 100, 5000, 5000);
|
||||
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(50000, 20000));
|
||||
|
||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft() << " - degree:" << area.topLeft()*LtsCoordTrans::rad2deg();
|
||||
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft() << " - degree:" << area1Increased.topLeft()*LtsCoordTrans::rad2deg();
|
||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft()
|
||||
<< " - 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() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight() << " - degree:" << area1Increased.bottomRight()*LtsCoordTrans::rad2deg();
|
||||
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight()
|
||||
<< " - degree:" << area.bottomRight() * LtsCoordTrans::rad2deg();
|
||||
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight()
|
||||
<< " - degree:" << area1Increased.bottomRight() * LtsCoordTrans::rad2deg();
|
||||
|
||||
QVERIFY2( area1Increased.topLeft().x() < area.topLeft().x(), "addMarginToArea topLeft X failed");
|
||||
QVERIFY2( area1Increased.topLeft().y() < area.topLeft().y(), "addMarginToArea topLeft Y failed");
|
||||
QVERIFY2(area1Increased.topLeft().x() < area.topLeft().x(), "addMarginToArea topLeft X failed");
|
||||
QVERIFY2(area1Increased.topLeft().y() < area.topLeft().y(), "addMarginToArea topLeft Y failed");
|
||||
|
||||
QVERIFY2( area1Increased.bottomRight().x() > area.bottomRight().x(), "addMarginToArea bottomRight X failed");
|
||||
QVERIFY2( area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y failed");
|
||||
QVERIFY2(area1Increased.bottomRight().x() > area.bottomRight().x(), "addMarginToArea bottomRight X failed");
|
||||
QVERIFY2(area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,23 +167,24 @@ void coordtrans_test::testIncreaseRect()
|
||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(lonlat.x(), lonlat.y(), 9);
|
||||
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 topLeftUtm2;
|
||||
|
||||
|
||||
{
|
||||
QPointF topLeftGeo = centerPoint.geographic(-1111, 2222);
|
||||
QPointF bottomRightGeo = centerPoint.geographic( 3000, -4000);
|
||||
QPointF bottomRightGeo = centerPoint.geographic(3000, -4000);
|
||||
|
||||
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() << "bottomRightUtm: " << bottomRightUtm.x << " - " << qSetRealNumberPrecision(15) << bottomRightUtm.y;
|
||||
qDebug() << "bottomRightUtm: " << bottomRightUtm.x << " - " << qSetRealNumberPrecision(15)
|
||||
<< bottomRightUtm.y;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
topLeftUtm2.x = centerPoint.x - 1111;
|
||||
topLeftUtm2.y = centerPoint.y + 2222;
|
||||
@@ -200,7 +194,8 @@ void coordtrans_test::testIncreaseRect()
|
||||
bottomRightUtm2.y = centerPoint.y - 4000;
|
||||
|
||||
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");
|
||||
@@ -218,10 +213,11 @@ void coordtrans_test::testIncreaseRect2()
|
||||
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 bottomRightGeo = centerPoint.geographic( 3000, -2000);
|
||||
QPointF bottomRightGeo = centerPoint.geographic(3000, -2000);
|
||||
myRect = QRectF(topLeftGeo, bottomRightGeo).normalized();
|
||||
|
||||
qDebug() << "myRect : " << myRect;
|
||||
@@ -229,39 +225,34 @@ void coordtrans_test::testIncreaseRect2()
|
||||
qDebug() << "myRect height : " << myRect.height();
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
const QPointF centerGeo = myRect.center();
|
||||
const LtsCoordTrans::UtmCoordinate centerUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(centerGeo);
|
||||
|
||||
QPointF topLeftGeo = centerUtm.geographic(-6000, 4000);
|
||||
QPointF bottomRightGeo = centerUtm.geographic( 6000, -4000);
|
||||
QPointF bottomRightGeo = centerUtm.geographic(6000, -4000);
|
||||
|
||||
myRectIncreased = QRectF(topLeftGeo, bottomRightGeo).normalized();
|
||||
|
||||
qDebug() << "myRectIncreased : " << myRectIncreased;
|
||||
qDebug() << "myRectIncreased center: " << myRectIncreased.center();
|
||||
qDebug() << "myRectIncreased height: " << myRectIncreased.height();
|
||||
|
||||
}
|
||||
|
||||
|
||||
QVERIFY2( (int)(myRectIncreased.center().x()*10000) == (int)(myRect.center().x()*10000), "testIncreaseRect2 centerX failed");
|
||||
QVERIFY2( (int)(myRectIncreased.center().y()*10000) == (int)(myRect.center().y()*10000), "testIncreaseRect2 centerY failed");
|
||||
QVERIFY2((int)(myRectIncreased.center().x() * 10000) == (int)(myRect.center().x() * 10000),
|
||||
"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.height() > myRect.height(), "testIncreaseRect2 height failed");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void coordtrans_test::testGeographicFromMgrs()
|
||||
{
|
||||
|
||||
QString mgrs(QStringLiteral("32UPD7654398765"));
|
||||
|
||||
|
||||
QPointF geographic = LtsCoordTrans::geographicFromMgrs(mgrs);
|
||||
QCOMPARE(geographic, QPointF(11.6436815550, 53.2088411454) * LtsCoordTrans::deg2rad());
|
||||
}
|
||||
@@ -269,163 +260,105 @@ void coordtrans_test::testGeographicFromMgrs()
|
||||
void coordtrans_test::testMgrsSquares()
|
||||
{
|
||||
|
||||
checkArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000,
|
||||
{QStringLiteral("32U PC"), QStringLiteral("32U PD")});
|
||||
checkArea(QStringLiteral("32U MD 0000000000"), 50000, 10000, 30000, 30000,
|
||||
{QStringLiteral("32U MC"), QStringLiteral("32U MD")});
|
||||
checkArea(QStringLiteral("32U MD 0000000000"), 89999, 89999, 21000, 21000,
|
||||
{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("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, 96760, 30000, 30000,
|
||||
{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("32U PD 0000000000"), 50000, 10000, 30000, 30000, { QStringLiteral("32U PC"),
|
||||
QStringLiteral("32U PD")
|
||||
});
|
||||
checkArea(QStringLiteral("32U MD 0000000000"), 50000, 10000, 30000, 30000, { QStringLiteral("32U MC"),
|
||||
QStringLiteral("32U MD")
|
||||
});
|
||||
checkArea(QStringLiteral("32U MD 0000000000"), 89999, 89999, 21000, 21000, { 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("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, 96760, 30000, 30000, { 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("32U LA 0000000000"), 10000, 10000, 5000, 5000, { QStringLiteral("32U LA"),
|
||||
});
|
||||
|
||||
|
||||
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 60000, 60000, { QStringLiteral("31U GQ"),
|
||||
QStringLiteral("31U GR"),
|
||||
QStringLiteral("32U KA"),
|
||||
QStringLiteral("32U KV"),
|
||||
checkArea(QStringLiteral("32U LA 0000000000"), 10000, 10000, 5000, 5000,
|
||||
{
|
||||
QStringLiteral("32U LA"),
|
||||
QStringLiteral("32U LV")
|
||||
});
|
||||
|
||||
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100,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"), 100, 100, 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"), 100, 100,200000,200000, { 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")
|
||||
});
|
||||
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 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"), 100, 100, 200000, 200000,
|
||||
{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);
|
||||
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 bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||
|
||||
|
||||
|
||||
const auto squares = LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), false, false);
|
||||
|
||||
QStringList src;
|
||||
src.reserve(squares.size());
|
||||
for (const auto &utm : squares)
|
||||
for (const auto& utm : squares)
|
||||
src += utm.mgrs(0);
|
||||
src.sort();
|
||||
|
||||
|
||||
return squares;
|
||||
}
|
||||
|
||||
void coordtrans_test::testMgrsSquaresWithSurrounding()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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");
|
||||
|
||||
|
||||
|
||||
|
||||
int biggerSize = initialSize + (1*110000);
|
||||
QVector<LtsCoordTrans::UtmCoordinate> squares9 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, biggerSize, biggerSize);
|
||||
int biggerSize = initialSize + (1 * 110000);
|
||||
QVector<LtsCoordTrans::UtmCoordinate> squares9 =
|
||||
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, biggerSize, biggerSize);
|
||||
|
||||
QVERIFY2(squares9.size() == 9, "checkAreaGetMgrsSquares biggerSize failed");
|
||||
|
||||
int muchBiggerSize = initialSize + (3*110000);
|
||||
QVector<LtsCoordTrans::UtmCoordinate> square33 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, muchBiggerSize, muchBiggerSize);
|
||||
int muchBiggerSize = initialSize + (3 * 110000);
|
||||
QVector<LtsCoordTrans::UtmCoordinate> square33 =
|
||||
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, muchBiggerSize, muchBiggerSize);
|
||||
|
||||
QVERIFY2(square33.size() == 33, "checkAreaGetMgrsSquares muchBiggerSize failed");
|
||||
|
||||
|
||||
QStringList string1;
|
||||
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));
|
||||
|
||||
QStringList string9;
|
||||
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));
|
||||
|
||||
QStringList string33;
|
||||
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));
|
||||
|
||||
{
|
||||
QStringList surroundingStrings;
|
||||
surroundingStrings.reserve(squares9.size());
|
||||
for (const QString &str : std::as_const(string9))
|
||||
for (const QString& str : std::as_const(string9))
|
||||
if (!string1.contains(str))
|
||||
surroundingStrings.append(str);
|
||||
|
||||
@@ -435,22 +368,21 @@ void coordtrans_test::testMgrsSquaresWithSurrounding()
|
||||
{
|
||||
QStringList surroundingStrings;
|
||||
surroundingStrings.reserve(string33.size());
|
||||
for (const QString &str : std::as_const(string33))
|
||||
for (const QString& str : std::as_const(string33))
|
||||
if (!string1.contains(str))
|
||||
surroundingStrings.append(str);
|
||||
|
||||
QVERIFY2(surroundingStrings.size() == 32, "checkAreaGetMgrsSquares squaresDiff failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
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 bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||
qDebug() << "TopLeft: " << topLeft * LtsCoordTrans::rad2deg();
|
||||
@@ -460,11 +392,9 @@ void coordtrans_test::checkArea(const QString &base,
|
||||
|
||||
QStringList src;
|
||||
src.reserve(squares.size());
|
||||
for (const auto &utm : squares)
|
||||
for (const auto& utm : squares)
|
||||
src += utm.mgrs(0);
|
||||
src.sort();
|
||||
qDebug() << "src: '" << src << "' expected: '" << coords << "'";
|
||||
QCOMPARE(src, coords);
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+3
-6
@@ -8,7 +8,7 @@
|
||||
class coordtrans_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
void testFromGeographic();
|
||||
@@ -26,9 +26,6 @@ private Q_SLOTS:
|
||||
|
||||
void testMgrsSquaresWithSurrounding();
|
||||
|
||||
private:
|
||||
void checkArea(const QString &base,
|
||||
int xCenter, int yCenter, int width, int height,
|
||||
const QStringList &coords);
|
||||
|
||||
private:
|
||||
void checkArea(const QString& base, int xCenter, int yCenter, int width, int height, const QStringList& coords);
|
||||
};
|
||||
Executable → Regular
+12
-21
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_coord_widget.h"
|
||||
|
||||
#include "lts_coord_widget_p.h"
|
||||
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
@@ -10,15 +10,13 @@
|
||||
namespace LtsCoordWidget
|
||||
{
|
||||
|
||||
LtsCoordWidget::LtsCoordWidget(DisplayType dt, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_displayType(dt)
|
||||
LtsCoordWidget::LtsCoordWidget(DisplayType dt, QWidget* parent) : QWidget(parent), m_displayType(dt)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
rebuildUi();
|
||||
}
|
||||
|
||||
void LtsCoordWidget::setCoordinate(const QPointF &geoCoord, bool bUseAsDefaultValue)
|
||||
void LtsCoordWidget::setCoordinate(const QPointF& geoCoord, bool bUseAsDefaultValue)
|
||||
{
|
||||
if (m_coordinate != geoCoord)
|
||||
emit coordinateChanged(geoCoord);
|
||||
@@ -46,7 +44,6 @@ QPointF LtsCoordWidget::coordinate() const
|
||||
return m_inputWidgetHandler->coordinate();
|
||||
}
|
||||
|
||||
|
||||
LtsCoordWidget::DisplayType LtsCoordWidget::displayType() const
|
||||
{
|
||||
return m_displayType;
|
||||
@@ -108,27 +105,22 @@ void LtsCoordWidget::setWithSurroundingMgrsSquares(bool bEnable)
|
||||
m_inputWidgetHandler->setWithSurroundingSquare(bEnable);
|
||||
}
|
||||
|
||||
void LtsCoordWidget::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords)
|
||||
void LtsCoordWidget::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords)
|
||||
{
|
||||
if (m_inputWidgetHandler)
|
||||
m_inputWidgetHandler->setMgrsSquares(geoCoords);
|
||||
}
|
||||
|
||||
|
||||
bool LtsCoordWidget::event(QEvent *event)
|
||||
bool LtsCoordWidget::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::ToolTip)
|
||||
updateToolTip();
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
|
||||
void LtsCoordWidget::rebuildUi()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if (m_inputWidgetHandler)
|
||||
{
|
||||
m_inputWidgetHandler->cleanup();
|
||||
@@ -157,12 +149,12 @@ void LtsCoordWidget::rebuildUi()
|
||||
|
||||
m_inputWidgetHandler->setSquaresEditable(m_bMgrsSquareEditable);
|
||||
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
||||
connect(m_inputWidgetHandler->resetButton(), &QToolButton::clicked,
|
||||
this, &LtsCoordWidget::onResetToDefaultCoordinate);
|
||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::coordinateChanged,
|
||||
this, &LtsCoordWidget::coordinateChanged);
|
||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::invalidCoordinate,
|
||||
this, &LtsCoordWidget::invalidCoordinate);
|
||||
connect(m_inputWidgetHandler->resetButton(), &QToolButton::clicked, this,
|
||||
&LtsCoordWidget::onResetToDefaultCoordinate);
|
||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::coordinateChanged, this,
|
||||
&LtsCoordWidget::coordinateChanged);
|
||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::invalidCoordinate, this,
|
||||
&LtsCoordWidget::invalidCoordinate);
|
||||
if (!m_defaultCoordinate.isNull())
|
||||
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
||||
}
|
||||
@@ -183,7 +175,6 @@ void LtsCoordWidget::updateToolTip()
|
||||
setToolTip(tt);
|
||||
}
|
||||
|
||||
|
||||
void LtsCoordWidget::onResetToDefaultCoordinate()
|
||||
{
|
||||
if (!m_inputWidgetHandler)
|
||||
@@ -193,4 +184,4 @@ void LtsCoordWidget::onResetToDefaultCoordinate()
|
||||
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsCoordWidget
|
||||
Executable → Regular
+29
-54
@@ -1,15 +1,12 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_coord_widget_p.h"
|
||||
#include <utility>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace LtsCoordWidget
|
||||
{
|
||||
|
||||
|
||||
|
||||
void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
||||
{
|
||||
const QPointF coord(coordinate());
|
||||
@@ -21,13 +18,8 @@ void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
||||
emit coordinateChanged(coord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MgrsEdit::MgrsEdit(int precision, QWidget *widget)
|
||||
: LtsCoordInputWidgetHandler(widget)
|
||||
, m_precision(precision)
|
||||
, m_ui(new Ui::Mgrs)
|
||||
MgrsEdit::MgrsEdit(int precision, QWidget* widget)
|
||||
: LtsCoordInputWidgetHandler(widget), m_precision(precision), m_ui(new Ui::Mgrs)
|
||||
{
|
||||
m_ui->setupUi(widget);
|
||||
|
||||
@@ -40,12 +32,10 @@ MgrsEdit::MgrsEdit(int precision, QWidget *widget)
|
||||
m_ui->leNorth->setValidator(new QIntValidator(0, upperLimit, m_ui->leNorth));
|
||||
setDefaultMgrsSquares();
|
||||
|
||||
connect(m_ui->cbxZone, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &MgrsEdit::onCoordinateDataChanged);
|
||||
connect(m_ui->leEast, &QLineEdit::editingFinished,
|
||||
this, &MgrsEdit::onCoordinateDataChanged);
|
||||
connect(m_ui->leNorth, &QLineEdit::editingFinished,
|
||||
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->leNorth, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
||||
}
|
||||
|
||||
MgrsEdit::~MgrsEdit()
|
||||
@@ -56,11 +46,11 @@ MgrsEdit::~MgrsEdit()
|
||||
bool MgrsEdit::isValid()
|
||||
{
|
||||
|
||||
const QString &east = m_ui->leEast->text();
|
||||
const QString& east = m_ui->leEast->text();
|
||||
if (east.size() != m_precision)
|
||||
return false;
|
||||
|
||||
const QString &north = m_ui->leNorth->text();
|
||||
const QString& north = m_ui->leNorth->text();
|
||||
if (north.size() != m_precision)
|
||||
return false;
|
||||
|
||||
@@ -73,7 +63,7 @@ bool MgrsEdit::isValid()
|
||||
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);
|
||||
if (mgrsString.isEmpty())
|
||||
@@ -86,7 +76,6 @@ void MgrsEdit::setCoordinate(const QPointF &geoCoord)
|
||||
m_ui->leEast->setText(QString());
|
||||
m_ui->leNorth->setText(QString());
|
||||
|
||||
|
||||
const QString mgrsSquare = mgrsString.left(3) + QLatin1Char(' ') + mgrsString.mid(3, 2);
|
||||
QString east = mgrsString.mid(5, m_precision);
|
||||
QString north = mgrsString.mid(5 + m_precision, m_precision);
|
||||
@@ -101,7 +90,7 @@ void MgrsEdit::setCoordinate(const QPointF &geoCoord)
|
||||
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();
|
||||
if (ret.isEmpty())
|
||||
@@ -123,7 +112,7 @@ QPointF MgrsEdit::coordinate() const
|
||||
return LtsCoordTrans::geographicFromMgrs(mgrsString);
|
||||
}
|
||||
|
||||
QToolButton *MgrsEdit::resetButton()
|
||||
QToolButton* MgrsEdit::resetButton()
|
||||
{
|
||||
return m_ui->tbReset;
|
||||
}
|
||||
@@ -131,7 +120,6 @@ QToolButton *MgrsEdit::resetButton()
|
||||
void MgrsEdit::cleanup()
|
||||
{
|
||||
|
||||
|
||||
delete m_ui->horizontalLayout;
|
||||
delete m_ui->cbxZone;
|
||||
delete m_ui->leEast;
|
||||
@@ -162,7 +150,7 @@ static QStringList defaultMgrsSquares()
|
||||
const QVector<LtsCoordTrans::UtmCoordinate> squares(LtsCoordTrans::defaultMgrsSquares());
|
||||
QStringList sl;
|
||||
sl.reserve(squares.size());
|
||||
for (const LtsCoordTrans::UtmCoordinate &c : squares)
|
||||
for (const LtsCoordTrans::UtmCoordinate& c : squares)
|
||||
sl += c.mgrs(0);
|
||||
std::sort(sl.begin(), sl.end());
|
||||
return sl;
|
||||
@@ -174,14 +162,13 @@ static QString preferedMgrsSquare()
|
||||
return c.mgrs(0);
|
||||
}
|
||||
|
||||
|
||||
void MgrsEdit::setDefaultMgrsSquares()
|
||||
{
|
||||
m_ui->cbxZone->addItems(defaultMgrsSquares());
|
||||
m_ui->cbxZone->setCurrentIndex(m_ui->cbxZone->findText(preferedMgrsSquare()));
|
||||
}
|
||||
|
||||
void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
||||
void MgrsEdit::addMgrsSquare(const QString& newMgrsSquare)
|
||||
{
|
||||
QStringList sl = defaultMgrsSquares();
|
||||
sl += newMgrsSquare;
|
||||
@@ -189,7 +176,7 @@ void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
||||
{
|
||||
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))
|
||||
sl.append(sq);
|
||||
}
|
||||
@@ -198,17 +185,17 @@ void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
||||
m_ui->cbxZone->addItems(sl);
|
||||
}
|
||||
|
||||
QStringList MgrsEdit::utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate> &coords)
|
||||
QStringList MgrsEdit::utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate>& coords)
|
||||
{
|
||||
QStringList list;
|
||||
list.reserve(coords.count());
|
||||
for (const auto &utm : coords)
|
||||
for (const auto& utm : coords)
|
||||
list.append(utm.mgrs(0));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords)
|
||||
void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords)
|
||||
{
|
||||
QStringList sl = utmCoordsToList(geoCoords);
|
||||
if (sl.isEmpty())
|
||||
@@ -219,16 +206,11 @@ void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCo
|
||||
m_ui->cbxZone->addItems(sl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Wgs84Edit::Wgs84Edit(QWidget *widget)
|
||||
: LtsCoordInputWidgetHandler(widget)
|
||||
, m_ui(new Ui::Wgs84)
|
||||
Wgs84Edit::Wgs84Edit(QWidget* widget) : LtsCoordInputWidgetHandler(widget), m_ui(new Ui::Wgs84)
|
||||
{
|
||||
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);
|
||||
m_ui->leLon->setValidator(v);
|
||||
|
||||
@@ -236,10 +218,8 @@ Wgs84Edit::Wgs84Edit(QWidget *widget)
|
||||
v->setNotation(QDoubleValidator::StandardNotation);
|
||||
m_ui->leLat->setValidator(v);
|
||||
|
||||
connect(m_ui->leLon, &QLineEdit::editingFinished,
|
||||
this, &Wgs84Edit::onCoordinateDataChanged);
|
||||
connect(m_ui->leLat, &QLineEdit::editingFinished,
|
||||
this, &Wgs84Edit::onCoordinateDataChanged);
|
||||
connect(m_ui->leLon, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
||||
connect(m_ui->leLat, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
||||
}
|
||||
|
||||
Wgs84Edit::~Wgs84Edit()
|
||||
@@ -253,7 +233,7 @@ bool Wgs84Edit::isValid()
|
||||
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 QLocale l;
|
||||
@@ -266,7 +246,6 @@ QPointF Wgs84Edit::coordinate() const
|
||||
QPointF ret;
|
||||
const QLocale l;
|
||||
|
||||
|
||||
const QString lonStr = m_ui->leLon->text().remove(l.groupSeparator());
|
||||
const QString latStr = m_ui->leLat->text().remove(l.groupSeparator());
|
||||
if (lonStr.isEmpty() || latStr.isEmpty())
|
||||
@@ -278,7 +257,7 @@ QPointF Wgs84Edit::coordinate() const
|
||||
return ret * LtsCoordTrans::deg2rad();
|
||||
}
|
||||
|
||||
QToolButton *Wgs84Edit::resetButton()
|
||||
QToolButton* Wgs84Edit::resetButton()
|
||||
{
|
||||
return m_ui->tbReset;
|
||||
}
|
||||
@@ -286,7 +265,6 @@ QToolButton *Wgs84Edit::resetButton()
|
||||
void Wgs84Edit::cleanup()
|
||||
{
|
||||
|
||||
|
||||
delete m_ui->horizontalLayout;
|
||||
delete m_ui->leLon;
|
||||
delete m_ui->leLat;
|
||||
@@ -301,14 +279,12 @@ void Wgs84Edit::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)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
if (ret != QValidator::Acceptable)
|
||||
@@ -322,5 +298,4 @@ QValidator::State DoubleValidator::validate(QString &input, int &pos) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace LtsCoordWidget
|
||||
Executable → Regular
+53
-40
@@ -2,93 +2,106 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include "ui_lts_coord_widget_mgrs.h"
|
||||
#include "ui_lts_coord_widget_wgs84.h"
|
||||
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <QComboBox>
|
||||
#include <QObject>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
namespace LtsCoordWidget
|
||||
{
|
||||
class LtsCoordInputWidgetHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsCoordInputWidgetHandler(QObject *parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
public:
|
||||
explicit LtsCoordInputWidgetHandler(QObject* parent) : QObject(parent) {}
|
||||
|
||||
virtual bool isValid() = 0;
|
||||
virtual void setCoordinate(const QPointF &geoCoord) = 0;
|
||||
virtual void setCoordinate(const QPointF& geoCoord) = 0;
|
||||
virtual QPointF coordinate() const = 0;
|
||||
virtual QToolButton *resetButton() = 0;
|
||||
virtual QToolButton* resetButton() = 0;
|
||||
virtual void cleanup() = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void setSquaresEditable(bool bEditable) = 0;
|
||||
virtual void setWithSurroundingSquare(bool bEnabled) = 0;
|
||||
virtual void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) = 0;
|
||||
protected Q_SLOTS:
|
||||
virtual void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) = 0;
|
||||
protected Q_SLOTS:
|
||||
void onCoordinateDataChanged();
|
||||
Q_SIGNALS:
|
||||
void coordinateChanged(const QPointF &newGeoCoord);
|
||||
Q_SIGNALS:
|
||||
void coordinateChanged(const QPointF& newGeoCoord);
|
||||
void invalidCoordinate();
|
||||
};
|
||||
|
||||
class MgrsEdit final : public LtsCoordInputWidgetHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MgrsEdit(int precision, QWidget *widget);
|
||||
public:
|
||||
explicit MgrsEdit(int precision, QWidget* widget);
|
||||
~MgrsEdit();
|
||||
|
||||
bool isValid() override;
|
||||
void setCoordinate(const QPointF &geoCoord) override;
|
||||
void setCoordinate(const QPointF& geoCoord) override;
|
||||
QPointF coordinate() const override;
|
||||
QToolButton *resetButton() override;
|
||||
QToolButton* resetButton() override;
|
||||
void cleanup() override;
|
||||
void clear() override;
|
||||
void setSquaresEditable(bool bEditable) override;
|
||||
void setWithSurroundingSquare(bool bEnabled) override;
|
||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) override;
|
||||
private:
|
||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) override;
|
||||
|
||||
private:
|
||||
void setDefaultMgrsSquares();
|
||||
void addMgrsSquare(const QString &newMgrsSquare);
|
||||
QStringList utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate> &coords);
|
||||
private:
|
||||
void addMgrsSquare(const QString& newMgrsSquare);
|
||||
QStringList utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate>& coords);
|
||||
|
||||
private:
|
||||
int m_precision;
|
||||
bool m_withMgrsSquareOffset=false;
|
||||
Ui::Mgrs *m_ui;
|
||||
bool m_withMgrsSquareOffset = false;
|
||||
Ui::Mgrs* m_ui;
|
||||
};
|
||||
|
||||
class Wgs84Edit final : public LtsCoordInputWidgetHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Wgs84Edit(QWidget *widget);
|
||||
public:
|
||||
explicit Wgs84Edit(QWidget* widget);
|
||||
~Wgs84Edit();
|
||||
|
||||
bool isValid() override;
|
||||
void setCoordinate(const QPointF &geoCoord) override;
|
||||
void setCoordinate(const QPointF& geoCoord) override;
|
||||
QPointF coordinate() const override;
|
||||
QToolButton *resetButton() override;
|
||||
QToolButton* resetButton() override;
|
||||
void cleanup() override;
|
||||
void clear() override;
|
||||
void setSquaresEditable(bool bEditable) override { Q_UNUSED(bEditable); }
|
||||
void setWithSurroundingSquare(bool bEnabled) override { Q_UNUSED(bEnabled); }
|
||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) override { Q_UNUSED(geoCoords); }
|
||||
private:
|
||||
Ui::Wgs84 *m_ui;
|
||||
|
||||
void setSquaresEditable(bool bEditable) override
|
||||
{
|
||||
Q_UNUSED(bEditable);
|
||||
}
|
||||
|
||||
void setWithSurroundingSquare(bool bEnabled) override
|
||||
{
|
||||
Q_UNUSED(bEnabled);
|
||||
}
|
||||
|
||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) override
|
||||
{
|
||||
Q_UNUSED(geoCoords);
|
||||
}
|
||||
|
||||
private:
|
||||
Ui::Wgs84* m_ui;
|
||||
};
|
||||
|
||||
class DoubleValidator final : public QDoubleValidator
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
|
||||
public:
|
||||
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
|
||||
Executable → Regular
+41
-50
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include "lts_coord_widget.h"
|
||||
|
||||
static void updateLabel(const QPointF &coord, QLabel *lbl, int prec)
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <QApplication>
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
static void updateLabel(const QPointF& coord, QLabel* lbl, int prec)
|
||||
{
|
||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(coord.x(), coord.y(), prec);
|
||||
QString str = QStringLiteral("mgrs: %1, lon: %2, lat: %3")
|
||||
@@ -19,7 +19,7 @@ static void updateLabel(const QPointF &coord, QLabel *lbl, int prec)
|
||||
lbl->setText(str);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
@@ -28,83 +28,74 @@ int main(int argc, char **argv)
|
||||
QPointF bottomRight(base.geographic(-50000, 50000));
|
||||
LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), true, true);
|
||||
|
||||
QDialog *dialog(new QDialog);
|
||||
QVBoxLayout *lay(new QVBoxLayout(dialog));
|
||||
|
||||
QDialog* dialog(new QDialog);
|
||||
QVBoxLayout* lay(new QVBoxLayout(dialog));
|
||||
|
||||
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->setCoordinate(defCoord, true);
|
||||
lay->addWidget(wMgrs5);
|
||||
QLabel *lbl5(new QLabel(dialog));
|
||||
QLabel* lbl5(new QLabel(dialog));
|
||||
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->setCoordinate(defCoord, true);
|
||||
lay->addWidget(wMgrs7);
|
||||
QLabel *lbl7(new QLabel(dialog));
|
||||
QLabel* lbl7(new QLabel(dialog));
|
||||
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->setCoordinate(defCoord, true);
|
||||
lay->addWidget(w84);
|
||||
QLabel *lbl84(new QLabel(dialog));
|
||||
QLabel* lbl84(new QLabel(dialog));
|
||||
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);
|
||||
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->setCoordinate(defCoord, true);
|
||||
hLay->addWidget(wChange);
|
||||
QPushButton *pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
||||
QPushButton* pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
||||
hLay->addWidget(pbReset);
|
||||
QObject::connect(pbReset, &QPushButton::clicked,
|
||||
wChange, [wChange]() { wChange->setWithResetButton(!wChange->withResetButton());});
|
||||
QPushButton *pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
||||
QObject::connect(pbReset, &QPushButton::clicked, wChange,
|
||||
[wChange]() { wChange->setWithResetButton(!wChange->withResetButton()); });
|
||||
QPushButton* pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
||||
hLay->addWidget(pbNext);
|
||||
QObject::connect(pbNext, &QPushButton::clicked,
|
||||
wChange, [wChange]()
|
||||
{
|
||||
QObject::connect(pbNext, &QPushButton::clicked, wChange, [wChange]() {
|
||||
LtsCoordWidget::LtsCoordWidget::DisplayType dt = wChange->displayType();
|
||||
switch (dt)
|
||||
{
|
||||
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5:
|
||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7; break;
|
||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7;
|
||||
break;
|
||||
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7:
|
||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84; break;
|
||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84;
|
||||
break;
|
||||
case LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84:
|
||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5; break;
|
||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
wChange->setDisplayType(dt);
|
||||
});
|
||||
|
||||
|
||||
QPushButton *pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
||||
QPushButton* pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
||||
lay->addWidget(pb);
|
||||
QObject::connect(pb, &QPushButton::clicked, qApp, QCoreApplication::quit);
|
||||
|
||||
|
||||
Executable → Regular
+4
-5
@@ -1,11 +1,10 @@
|
||||
|
||||
|
||||
|
||||
#include <GeographicLib/UTMUPS.hpp>
|
||||
#include <GeographicLib/MGRS.hpp>
|
||||
#include <GeographicLib/UTMUPS.hpp>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
@@ -39,7 +38,7 @@ int main(int argc, char **argv)
|
||||
part2 = mgrs.substr(3, 2);
|
||||
part3 = mgrs.substr(5, prec);
|
||||
part4 = mgrs.substr(5 + prec, prec);
|
||||
fprintf(stdout, "%s %s %s %s = %13.10f, %13.10f ( %13.10f, %13.10f )\n",
|
||||
part1.c_str(), part2.c_str(), part3.c_str(), part4.c_str(), lonDeg, latDeg, lonDeg / 180. * M_PI, latDeg / 180. * M_PI);
|
||||
fprintf(stdout, "%s %s %s %s = %13.10f, %13.10f ( %13.10f, %13.10f )\n", part1.c_str(), part2.c_str(),
|
||||
part3.c_str(), part4.c_str(), lonDeg, latDeg, lonDeg / 180. * M_PI, latDeg / 180. * M_PI);
|
||||
return 0;
|
||||
}
|
||||
Executable → Regular
+222
-325
File diff suppressed because it is too large.
Load diff
Executable → Regular
+8
-33
@@ -1,44 +1,28 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <LtsElevation/lts_elevation_manager.h>
|
||||
|
||||
#include <ElevationMap/elevation_map_manager.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
#include <LtsElevation/lts_elevation_manager.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QObject>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
using LOGGER_T = NGL::INGLLogger&;
|
||||
|
||||
|
||||
|
||||
|
||||
class UnitTestCoordinate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
UnitTestCoordinate();
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void initTestCase();
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
|
||||
void test_NaN();
|
||||
|
||||
void test_coordinate_simple1();
|
||||
@@ -68,18 +52,9 @@ private Q_SLOTS:
|
||||
|
||||
void test_coordinate_avoid_copy();
|
||||
|
||||
|
||||
|
||||
void test_container_references();
|
||||
void test_coordVector();
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
};
|
||||
Executable → Regular
+9
-30
@@ -1,31 +1,28 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "lts_coord_vector.h"
|
||||
|
||||
namespace LtsCoordTrans
|
||||
{
|
||||
|
||||
LtsCoordVector::LtsCoordVector(const std::vector<Core::GeoPosition> &geo_coordinates)
|
||||
LtsCoordVector::LtsCoordVector(const std::vector<Core::GeoPosition>& geo_coordinates)
|
||||
: m_geo_coordinates(geo_coordinates)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const std::vector<UtmCoordinate> &LtsCoordVector::toStdUtmCoord(int zone) const
|
||||
const std::vector<UtmCoordinate>& LtsCoordVector::toStdUtmCoord(int zone) const
|
||||
{
|
||||
convertGeoToStdUtm(zone);
|
||||
return m_utmMapStd[zone];
|
||||
}
|
||||
|
||||
const QVector<UtmCoordinate> &LtsCoordVector::toQVectorUtmCoord(int zone) const
|
||||
const QVector<UtmCoordinate>& LtsCoordVector::toQVectorUtmCoord(int zone) const
|
||||
{
|
||||
convertGeoToQVectorUtm(zone);
|
||||
return m_utmMapQVector[zone];
|
||||
}
|
||||
|
||||
const QVector<QPointF> &LtsCoordVector::toQVectorQPointF(int zone) const
|
||||
const QVector<QPointF>& LtsCoordVector::toQVectorQPointF(int zone) const
|
||||
{
|
||||
convertGeoToQVectorQPointF(zone);
|
||||
return m_utmMapQVectorQPointF[zone];
|
||||
@@ -45,16 +42,12 @@ void LtsCoordVector::convertGeoToQVectorUtm(int zone) const
|
||||
if (it != m_utmMapQVector.end())
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
convertGeoToStdUtm(zone);
|
||||
QVector<LtsCoordTrans::UtmCoordinate> &utmVectorRef = m_utmMapQVector[zone];
|
||||
QVector<LtsCoordTrans::UtmCoordinate>& utmVectorRef = m_utmMapQVector[zone];
|
||||
utmVectorRef.clear();
|
||||
utmVectorRef.reserve(m_geo_coordinates.size());
|
||||
|
||||
for (const auto &utmCoord : m_utmMapStd[zone])
|
||||
for (const auto& utmCoord : m_utmMapStd[zone])
|
||||
utmVectorRef.push_back(utmCoord);
|
||||
}
|
||||
|
||||
@@ -65,26 +58,12 @@ void LtsCoordVector::convertGeoToQVectorQPointF(int zone) const
|
||||
return;
|
||||
|
||||
convertGeoToStdUtm(zone);
|
||||
QVector<QPointF> &QVectorQPointFRef = m_utmMapQVectorQPointF[zone];
|
||||
QVector<QPointF>& QVectorQPointFRef = m_utmMapQVectorQPointF[zone];
|
||||
QVectorQPointFRef.clear();
|
||||
QVectorQPointFRef.reserve(m_geo_coordinates.size());
|
||||
|
||||
for (const auto &utmCoord : m_utmMapStd[zone])
|
||||
for (const auto& utmCoord : m_utmMapStd[zone])
|
||||
QVectorQPointFRef.push_back(QPointF(utmCoord.x, utmCoord.y));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace LtsCoordTrans
|
||||
Executable → Regular
+21
-41
@@ -1,82 +1,62 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltscoordinate_export.h"
|
||||
#include <utility>
|
||||
|
||||
#include <Core/core.hpp>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <QDebug>
|
||||
#include <QPointF>
|
||||
#include <QVector>
|
||||
#include <QDebug>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace LtsCoordTrans
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSCOORDINATE_EXPORT LtsCoordVector
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit LtsCoordVector(const std::vector<Core::GeoPosition>& geo_coordinates);
|
||||
|
||||
int size() const
|
||||
{
|
||||
return m_geo_coordinates.size();
|
||||
}
|
||||
|
||||
const std::vector<Core::GeoPosition>& geoPosition() const
|
||||
{
|
||||
return m_geo_coordinates;
|
||||
}
|
||||
|
||||
explicit LtsCoordVector(const std::vector<Core::GeoPosition> &geo_coordinates);
|
||||
const std::vector<LtsCoordTrans::UtmCoordinate>& toStdUtmCoord(int zone) const;
|
||||
const QVector<LtsCoordTrans::UtmCoordinate>& toQVectorUtmCoord(int zone) const;
|
||||
const QVector<QPointF>& toQVectorQPointF(int zone) const;
|
||||
|
||||
|
||||
|
||||
int size() const { return m_geo_coordinates.size() ; }
|
||||
const std::vector<Core::GeoPosition> &geoPosition() const { return m_geo_coordinates; }
|
||||
|
||||
|
||||
|
||||
|
||||
const std::vector<LtsCoordTrans::UtmCoordinate> &toStdUtmCoord(int zone) const;
|
||||
const QVector<LtsCoordTrans::UtmCoordinate> &toQVectorUtmCoord(int zone) const;
|
||||
const QVector<QPointF> &toQVectorQPointF(int zone) const;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void convertGeoToStdUtm(int zone) const;
|
||||
void convertGeoToQVectorUtm(int zone) const;
|
||||
void convertGeoToQVectorQPointF(int zone) const;
|
||||
|
||||
template<typename T>
|
||||
void convertGeoToUtmInternal(int zone, T &utmVectorRef) const
|
||||
template <typename T> void convertGeoToUtmInternal(int zone, T& utmVectorRef) const
|
||||
{
|
||||
|
||||
utmVectorRef.clear();
|
||||
utmVectorRef.reserve(m_geo_coordinates.size());
|
||||
|
||||
for (const auto &geoCoord : std::as_const(m_geo_coordinates))
|
||||
for (const auto& geoCoord : std::as_const(m_geo_coordinates))
|
||||
utmVectorRef.push_back(LtsCoordTrans::UtmCoordinate::fromGeographic(geoCoord.lon(), geoCoord.lat(), zone));
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::vector<Core::GeoPosition> m_geo_coordinates;
|
||||
|
||||
|
||||
|
||||
|
||||
mutable std::unordered_map<int, std::vector<LtsCoordTrans::UtmCoordinate>> m_utmMapStd;
|
||||
mutable std::unordered_map<int, QVector<LtsCoordTrans::UtmCoordinate>> m_utmMapQVector;
|
||||
mutable std::unordered_map<int, QVector<QPointF>> m_utmMapQVectorQPointF;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace LtsCoordTrans
|
||||
Executable → Regular
+16
-52
@@ -1,8 +1,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "lts_coordinate.h"
|
||||
|
||||
#include <QLineF>
|
||||
|
||||
namespace LtsCoordTrans
|
||||
@@ -10,13 +9,9 @@ namespace LtsCoordTrans
|
||||
|
||||
static long s_conversion_counter = 0;
|
||||
|
||||
|
||||
std::function<double(double, double, double, bool*)> LtsCoordinate::m_getElevationCB;
|
||||
|
||||
|
||||
|
||||
|
||||
void LtsCoordinate::setElevationCallback(const elevationCbFunc &elevationCB)
|
||||
void LtsCoordinate::setElevationCallback(const elevationCbFunc& elevationCB)
|
||||
{
|
||||
m_getElevationCB = elevationCB;
|
||||
}
|
||||
@@ -26,11 +21,9 @@ bool LtsCoordinate::hasElevationCallback()
|
||||
return m_getElevationCB != nullptr;
|
||||
}
|
||||
|
||||
double LtsCoordinate::elevationAt(double defaultElevation, bool *bIsCovered) const
|
||||
double LtsCoordinate::elevationAt(double defaultElevation, bool* bIsCovered) const
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (!bIsCovered)
|
||||
if (!std::isnan(m_elevation))
|
||||
return m_elevation;
|
||||
@@ -44,7 +37,7 @@ void LtsCoordinate::setZValueAccordingElevation(double defaultElevation)
|
||||
m_geo.z(elevationAt(defaultElevation));
|
||||
}
|
||||
|
||||
double LtsCoordinate::elevationAt(const LtsCoordinate &coordinate, double defaultElevation, bool *bIsCovered)
|
||||
double LtsCoordinate::elevationAt(const LtsCoordinate& coordinate, double defaultElevation, bool* bIsCovered)
|
||||
{
|
||||
return coordinate.elevationAt(defaultElevation, bIsCovered);
|
||||
}
|
||||
@@ -52,47 +45,23 @@ double LtsCoordinate::elevationAt(const LtsCoordinate &coordinate, double defaul
|
||||
void LtsCoordinate::replaceZValueByElevationIfValue(double zValueToBeReplaced, double defaultElevation)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ((std::isnan(zValueToBeReplaced) && std::isnan(m_geo.z())) ||
|
||||
qFuzzyCompare(m_geo.z(), zValueToBeReplaced))
|
||||
if ((std::isnan(zValueToBeReplaced) && std::isnan(m_geo.z())) || qFuzzyCompare(m_geo.z(), zValueToBeReplaced))
|
||||
setZValueAccordingElevation(defaultElevation);
|
||||
}
|
||||
|
||||
double LtsCoordinate::angleDegreeUtm2D(const LtsCoordinate &coord1, const LtsCoordinate &coord2)
|
||||
double LtsCoordinate::angleDegreeUtm2D(const LtsCoordinate& coord1, const LtsCoordinate& coord2)
|
||||
{
|
||||
const LtsCoordTrans::UtmCoordinate &utm1 = coord1.utmCoordinate();
|
||||
const LtsCoordTrans::UtmCoordinate &utm2 = coord2.utmCoordinateDiffZone(utm1.zone);
|
||||
const LtsCoordTrans::UtmCoordinate& utm1 = coord1.utmCoordinate();
|
||||
const LtsCoordTrans::UtmCoordinate& utm2 = coord2.utmCoordinateDiffZone(utm1.zone);
|
||||
|
||||
const QPointF& offsetUtm = utm2.toPoint() - utm1.toPoint();
|
||||
QLineF poly(QPointF(), offsetUtm);
|
||||
const double angle = poly.angle();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return fmod(angle+90.0, 360);
|
||||
return fmod(angle + 90.0, 360);
|
||||
}
|
||||
|
||||
const UtmCoordinate &LtsCoordinate::utmCoordinateInternal(int zone) const
|
||||
const UtmCoordinate& LtsCoordinate::utmCoordinateInternal(int zone) const
|
||||
{
|
||||
if (zone == -1)
|
||||
{
|
||||
@@ -138,7 +107,6 @@ QString LtsCoordinate::mgrsWithZ(int prec, bool withSpaces) const
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
QString LtsCoordinate::toString(bool fullAndExpensive) const
|
||||
{
|
||||
if (fullAndExpensive)
|
||||
@@ -147,12 +115,11 @@ QString LtsCoordinate::toString(bool fullAndExpensive) const
|
||||
elevationAt();
|
||||
}
|
||||
std::ostringstream stream;
|
||||
stream << "LtsCoordinate(m_geo=" << m_geo
|
||||
<< ", m_utm2D.x " << m_utm2D.x << ", m_utm2D.y " << m_utm2D.y << ", m_utm2D.zone " << m_utm2D.zone;
|
||||
stream << "LtsCoordinate(m_geo=" << m_geo << ", m_utm2D.x " << m_utm2D.x << ", m_utm2D.y " << m_utm2D.y
|
||||
<< ", m_utm2D.zone " << m_utm2D.zone;
|
||||
if (!qFuzzyIsNull(m_utm2D.x) || !qFuzzyIsNull(m_utm2D.y))
|
||||
stream << ", m_utm2D.mgrs '" << m_utm2D.mgrs().toUtf8().constData() << "'";
|
||||
stream << ", elevation " << std::fixed << std::setprecision(3) << m_elevation
|
||||
<< ")";
|
||||
stream << ", elevation " << std::fixed << std::setprecision(3) << m_elevation << ")";
|
||||
return QString::fromStdString(stream.str());
|
||||
}
|
||||
|
||||
@@ -160,19 +127,16 @@ void LtsCoordinate::resetConversionCounter()
|
||||
{
|
||||
s_conversion_counter = 0;
|
||||
}
|
||||
|
||||
long LtsCoordinate::getConversionCounter()
|
||||
{
|
||||
return s_conversion_counter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const LtsCoordinate &value)
|
||||
std::ostream& operator<<(std::ostream& stream, const LtsCoordinate& value)
|
||||
{
|
||||
stream << value.toString().toStdString();
|
||||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace LtsCoordTrans
|
||||
Executable → Regular
+128
-199
@@ -1,22 +1,18 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltscoordinate_export.h"
|
||||
#include <utility>
|
||||
|
||||
#include <Core/core.hpp>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <LtsUtils/LtsUtilsCore/qpoint3d.h>
|
||||
|
||||
#include <QPointF>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QPointF>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <type_traits>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace LtsCoordTrans
|
||||
{
|
||||
@@ -24,206 +20,176 @@ namespace LtsCoordTrans
|
||||
using UtmCoordinate2D = LtsCoordTrans::UtmCoordinate;
|
||||
using QPoint3D = LtsUtils::QPoint3D;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSCOORDINATE_EXPORT LtsCoordinate
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
explicit LtsCoordinate(double lon = 0, double lat = 0, double z = std::nan(""))
|
||||
: m_geo(Core::GeoPosition(lon, lat, z))
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
explicit LtsCoordinate(const QPointF &lonLat, double z = std::nan(""))
|
||||
explicit LtsCoordinate(const QPointF& lonLat, double z = std::nan(""))
|
||||
: m_geo(Core::GeoPosition(lonLat.x(), lonLat.y(), z))
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
explicit LtsCoordinate(const Core::GeoPosition &geoPos)
|
||||
: m_geo(geoPos)
|
||||
{}
|
||||
explicit LtsCoordinate(const Core::GeoPosition& geoPos) : m_geo(geoPos) {}
|
||||
|
||||
explicit LtsCoordinate(const Core::GeoPosition2D &geoPos2D)
|
||||
: m_geo(geoPos2D.lon(), geoPos2D.lat(), std::nan(""))
|
||||
{}
|
||||
explicit LtsCoordinate(const Core::GeoPosition2D& geoPos2D) : m_geo(geoPos2D.lon(), geoPos2D.lat(), std::nan("")) {}
|
||||
|
||||
|
||||
|
||||
LtsCoordinate(const LtsCoordTrans::UtmCoordinate &utm2D, double zValue) = delete;
|
||||
LtsCoordinate(const LtsCoordTrans::UtmCoordinate& utm2D, double zValue) = delete;
|
||||
|
||||
static LtsCoordinate fromGeoPosition(double lon, double lat, double z = std::nan(""))
|
||||
{
|
||||
return LtsCoordinate(lon, lat, z);
|
||||
}
|
||||
|
||||
|
||||
static LtsCoordinate fromUtmCoordinate(const LtsCoordTrans::UtmCoordinate &utm2D, double zValue)
|
||||
static LtsCoordinate fromUtmCoordinate(const LtsCoordTrans::UtmCoordinate& utm2D, double zValue)
|
||||
{
|
||||
Q_ASSERT_X(utm2D.zone > 0, "LtsCoordinate", "zone has to be set");
|
||||
|
||||
|
||||
|
||||
const QPointF &geoPnt = utm2D.geographic();
|
||||
const QPointF& geoPnt = utm2D.geographic();
|
||||
|
||||
return LtsCoordinate(geoPnt.x(), geoPnt.y(), zValue);
|
||||
}
|
||||
|
||||
static LtsCoordinate fromUtm(const QPointF &utm2d, int zone, double zValue)
|
||||
static LtsCoordinate fromUtm(const QPointF& utm2d, int zone, double zValue)
|
||||
{
|
||||
const LtsCoordTrans::UtmCoordinate utmCoord(zone, utm2d.x(), utm2d.y());
|
||||
const QPointF &geoPnt = utmCoord.geographic();
|
||||
const QPointF& geoPnt = utmCoord.geographic();
|
||||
return LtsCoordinate(geoPnt.x(), geoPnt.y(), zValue);
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return hasGeo() || hasUtm();
|
||||
}
|
||||
|
||||
bool hasGeo() const
|
||||
{
|
||||
return !(valueIsNullOrNan(m_geo.lon()) || valueIsNullOrNan(m_geo.lat()));
|
||||
}
|
||||
|
||||
bool hasUtm() const
|
||||
{
|
||||
return m_utm2D.isValid();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool isValid() const { return hasGeo() || hasUtm(); }
|
||||
bool hasGeo() const { return !(valueIsNullOrNan(m_geo.lon()) ||
|
||||
valueIsNullOrNan(m_geo.lat())); }
|
||||
bool hasUtm() const { return m_utm2D.isValid(); }
|
||||
|
||||
static bool valueIsNullOrNan(double value) { return qFuzzyIsNull(value) || std::isnan(value); }
|
||||
static bool valueIsNullOrNan(double value)
|
||||
{
|
||||
return qFuzzyIsNull(value) || std::isnan(value);
|
||||
}
|
||||
|
||||
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
||||
QString mgrsWithZ(int prec = 5, bool withSpaces = true) const;
|
||||
|
||||
QString toString(bool fullAndExpensive = false) const;
|
||||
|
||||
|
||||
|
||||
static void resetConversionCounter();
|
||||
static long getConversionCounter();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const Core::GeoPosition &geoPosition() const
|
||||
{
|
||||
return m_geo;
|
||||
}
|
||||
const Core::GeoPosition2D &geoPosition2D() const
|
||||
const Core::GeoPosition& geoPosition() const
|
||||
{
|
||||
return m_geo;
|
||||
}
|
||||
|
||||
const LtsCoordTrans::UtmCoordinate &utmCoordinate() const
|
||||
const Core::GeoPosition2D& geoPosition2D() const
|
||||
{
|
||||
return m_geo;
|
||||
}
|
||||
|
||||
const LtsCoordTrans::UtmCoordinate& utmCoordinate() const
|
||||
{
|
||||
if (!hasUtm())
|
||||
convertGeoToUtm();
|
||||
return m_utm2D;
|
||||
}
|
||||
|
||||
double& rz()
|
||||
{
|
||||
return m_geo.z();
|
||||
}
|
||||
|
||||
double &rz() { return m_geo.z(); }
|
||||
double z() const { return m_geo.z(); }
|
||||
void setZ(double value) { m_geo.z(value); }
|
||||
double z() const
|
||||
{
|
||||
return m_geo.z();
|
||||
}
|
||||
|
||||
void setZ(double value)
|
||||
{
|
||||
m_geo.z(value);
|
||||
}
|
||||
|
||||
LtsCoordTrans::UtmCoordinate utmCoordinateDiffZone(int zone) const
|
||||
{
|
||||
|
||||
|
||||
m_utm2D_differentZone = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon(), m_geo.lat(), zone);
|
||||
return m_utm2D_differentZone;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
T toUtm(int zone = -1) const
|
||||
template <typename T> T toUtm(int zone = -1) const
|
||||
{
|
||||
T obj;
|
||||
helperToUtm(obj, zone);
|
||||
return obj;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
QPointF toUtmPointF() const { return toUtm<QPointF>(); }
|
||||
QPoint3D toUtmPoint3D() const { return toUtm<QPoint3D>(); }
|
||||
QPointF toUtmPointF() const
|
||||
{
|
||||
return toUtm<QPointF>();
|
||||
}
|
||||
|
||||
QPointF toGeoPointF() const { return QPointF (m_geo.lon(), m_geo.lat()); }
|
||||
QPoint3D toGeoPoint3D() const { return QPoint3D(m_geo.lon(), m_geo.lat(), m_geo.z() ); }
|
||||
QPoint3D toUtmPoint3D() const
|
||||
{
|
||||
return toUtm<QPoint3D>();
|
||||
}
|
||||
|
||||
QPointF toGeoPointF() const
|
||||
{
|
||||
return QPointF(m_geo.lon(), m_geo.lat());
|
||||
}
|
||||
|
||||
QPoint3D toGeoPoint3D() const
|
||||
{
|
||||
return QPoint3D(m_geo.lon(), m_geo.lat(), m_geo.z());
|
||||
}
|
||||
|
||||
UtmCoordinate3D toUtmCoordinate3D() const
|
||||
{
|
||||
return UtmCoordinate3D(utmCoordinate(), m_geo.z());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using elevationCbFunc = std::function<double(double, double, double, bool*)>;
|
||||
|
||||
|
||||
|
||||
|
||||
static void setElevationCallback(const elevationCbFunc &elevationCB);
|
||||
static void setElevationCallback(const elevationCbFunc& elevationCB);
|
||||
static bool hasElevationCallback();
|
||||
|
||||
|
||||
|
||||
|
||||
double elevationAt(double defaultElevation = 0.0, bool *bIsCovered = nullptr) const;
|
||||
double elevationAt(double defaultElevation = 0.0, bool* bIsCovered = nullptr) const;
|
||||
void setZValueAccordingElevation(double defaultElevation = 0.0);
|
||||
|
||||
static double elevationAt(const LtsCoordinate &coordinate, double defaultElevation = 0.0, bool *bIsCovered = nullptr);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static double elevationAt(const LtsCoordinate& coordinate, double defaultElevation = 0.0,
|
||||
bool* bIsCovered = nullptr);
|
||||
|
||||
void replaceZValueByElevationIfValue(double zValueToBeReplaced = std::nan(""), double defaultElevation = 0.0);
|
||||
|
||||
double heightOverElevation() const
|
||||
{
|
||||
return m_geo.z() - elevationAt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double heightOverElevation() const { return m_geo.z() - elevationAt(); }
|
||||
|
||||
|
||||
double distanceUtm2D(const LtsCoordinate &other) const
|
||||
double distanceUtm2D(const LtsCoordinate& other) const
|
||||
{
|
||||
|
||||
|
||||
const LtsCoordTrans::UtmCoordinate &thisUtm2D = utmCoordinate();
|
||||
const LtsCoordTrans::UtmCoordinate &otherUtm2D = other.utmCoordinateDiffZone(m_utm2D.zone);
|
||||
const LtsCoordTrans::UtmCoordinate& thisUtm2D = utmCoordinate();
|
||||
const LtsCoordTrans::UtmCoordinate& otherUtm2D = other.utmCoordinateDiffZone(m_utm2D.zone);
|
||||
return LtsCoordTrans::distance(thisUtm2D, otherUtm2D);
|
||||
}
|
||||
|
||||
double distanceUtm3D(const LtsCoordinate &other) const
|
||||
double distanceUtm3D(const LtsCoordinate& other) const
|
||||
{
|
||||
|
||||
|
||||
const QPoint3D &thisUtm3D = toUtm<QPoint3D>();
|
||||
const QPoint3D &otherUtm3D = other.toUtm<QPoint3D>(m_utm2D.zone);
|
||||
const QPoint3D& thisUtm3D = toUtm<QPoint3D>();
|
||||
const QPoint3D& otherUtm3D = other.toUtm<QPoint3D>(m_utm2D.zone);
|
||||
const double dist3D = (thisUtm3D - otherUtm3D).length();
|
||||
|
||||
Q_ASSERT_X(!std::isnan(dist3D), "LtsCoordinate", "ERROR, distance3D is NaN");
|
||||
@@ -231,48 +197,58 @@ public:
|
||||
return dist3D;
|
||||
}
|
||||
|
||||
static double angleDegreeUtm2D(const LtsCoordinate& coord1, const LtsCoordinate& coord2);
|
||||
|
||||
protected:
|
||||
void clearGeo() const
|
||||
{
|
||||
clearGeoLonLat();
|
||||
m_geo.z(std::nan(""));
|
||||
}
|
||||
|
||||
void clearGeoLonLat() const
|
||||
{
|
||||
m_geo.lon(0);
|
||||
m_geo.lat(0);
|
||||
}
|
||||
|
||||
void clearUtm() const
|
||||
{
|
||||
m_utm2D = m_utm2D_differentZone = UtmCoordinate2D();
|
||||
}
|
||||
|
||||
void clearElevation() const
|
||||
{
|
||||
m_elevation = std::nan("");
|
||||
}
|
||||
|
||||
void clear() const
|
||||
{
|
||||
clearGeo();
|
||||
clearUtm();
|
||||
clearElevation();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static double angleDegreeUtm2D(const LtsCoordinate &coord1, const LtsCoordinate &coord2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void clearGeo() const { clearGeoLonLat(); m_geo.z(std::nan("")); }
|
||||
void clearGeoLonLat() const { m_geo.lon(0); m_geo.lat(0); }
|
||||
void clearUtm() const { m_utm2D = m_utm2D_differentZone = UtmCoordinate2D(); }
|
||||
void clearElevation() const { m_elevation = std::nan(""); }
|
||||
void clear() const { clearGeo(); clearUtm(); clearElevation(); }
|
||||
|
||||
const LtsCoordTrans::UtmCoordinate &utmCoordinateInternal(int zone = -1) const;
|
||||
const LtsCoordTrans::UtmCoordinate& utmCoordinateInternal(int zone = -1) const;
|
||||
void convertGeoToUtm() const;
|
||||
|
||||
protected:
|
||||
|
||||
void helperToUtm(QPointF &pntRef, int zone = -1) const
|
||||
protected:
|
||||
void helperToUtm(QPointF& pntRef, int zone = -1) const
|
||||
{
|
||||
const auto &utmTemp = utmCoordinateInternal(zone);
|
||||
const auto& utmTemp = utmCoordinateInternal(zone);
|
||||
pntRef.rx() = utmTemp.x;
|
||||
pntRef.ry() = utmTemp.y;
|
||||
}
|
||||
void helperToUtm(QPoint3D &pntRef, int zone = -1) const
|
||||
|
||||
void helperToUtm(QPoint3D& pntRef, int zone = -1) const
|
||||
{
|
||||
const auto &utmTemp = utmCoordinateInternal(zone);
|
||||
const auto& utmTemp = utmCoordinateInternal(zone);
|
||||
pntRef.rx() = utmTemp.x;
|
||||
pntRef.ry() = utmTemp.y;
|
||||
pntRef.rz() = m_geo.z();
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
mutable Core::GeoPosition m_geo;
|
||||
mutable UtmCoordinate2D m_utm2D;
|
||||
mutable UtmCoordinate2D m_utm2D_differentZone;
|
||||
@@ -281,88 +257,41 @@ protected:
|
||||
static elevationCbFunc m_getElevationCB;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSCOORDINATE_EXPORT LtsCoordinateNoImplicitCopy : public LtsCoordinate
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using BaseClass = LtsCoordinate;
|
||||
|
||||
|
||||
|
||||
LtsCoordinateNoImplicitCopy() = default;
|
||||
explicit LtsCoordinateNoImplicitCopy (const LtsCoordinateNoImplicitCopy &) = default;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
explicit LtsCoordinateNoImplicitCopy(const LtsCoordinateNoImplicitCopy&) = default;
|
||||
|
||||
~LtsCoordinateNoImplicitCopy() = default;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
explicit LtsCoordinateNoImplicitCopy(const QPointF &lonLat, double z = std::nan(""))
|
||||
explicit LtsCoordinateNoImplicitCopy(const QPointF& lonLat, double z = std::nan(""))
|
||||
: BaseClass(Core::GeoPosition(lonLat.x(), lonLat.y(), z))
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition &geoPos)
|
||||
: BaseClass(geoPos)
|
||||
{}
|
||||
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition& geoPos) : BaseClass(geoPos) {}
|
||||
|
||||
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition2D &geoPos2D)
|
||||
: BaseClass(geoPos2D)
|
||||
{}
|
||||
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition2D& geoPos2D) : BaseClass(geoPos2D) {}
|
||||
|
||||
|
||||
|
||||
|
||||
void updateGeoPosition(const Core::GeoPosition &geoPos) const
|
||||
void updateGeoPosition(const Core::GeoPosition& geoPos) const
|
||||
{
|
||||
clear();
|
||||
m_geo = geoPos;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T_OUT, typename T_IN>
|
||||
T_OUT convert(const T_IN& contIn)
|
||||
template <typename T_OUT, typename T_IN> T_OUT convert(const T_IN& contIn)
|
||||
{
|
||||
T_OUT out;
|
||||
out.reserve(contIn.size());
|
||||
for (const Core::GeoPosition &posGeo : std::as_const(contIn))
|
||||
for (const Core::GeoPosition& posGeo : std::as_const(contIn))
|
||||
out.push_back(LtsCoordinate(posGeo));
|
||||
return out;
|
||||
}
|
||||
|
||||
LTSCOORDINATE_EXPORT std::ostream& operator<<(std::ostream& stream, const LtsCoordinate& value);
|
||||
|
||||
|
||||
LTSCOORDINATE_EXPORT std::ostream &operator<< (std::ostream &stream,
|
||||
const LtsCoordinate &value);
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace LtsCoordTrans
|
||||
Executable → Regular
+31
-63
@@ -1,15 +1,12 @@
|
||||
|
||||
|
||||
|
||||
#include "elevation_unit_test.h"
|
||||
|
||||
#include <ElevationMap/elevation_map_manager.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
Q_DECLARE_METATYPE(LtsUtils::QPoint3D);
|
||||
Q_DECLARE_METATYPE(LtsElevation::LineOfSight);
|
||||
@@ -17,38 +14,27 @@ Q_DECLARE_METATYPE(LtsElevation::LineOfSight);
|
||||
#include <iostream>
|
||||
|
||||
static const int s_id{4711};
|
||||
static LtsElevation::LtsElevationManager *s_eleMgr{nullptr};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static LtsElevation::LtsElevationManager* s_eleMgr{nullptr};
|
||||
|
||||
class MyLtsElevationManagerBootstrap : public LtsElevation::LtsElevationManager
|
||||
{
|
||||
using BaseClass = LtsElevation::LtsElevationManager;
|
||||
|
||||
public:
|
||||
static LtsElevationManager *createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine)
|
||||
public:
|
||||
static LtsElevationManager* createInstanceUnitTest(int id, const QStringList& filePaths_rough_to_fine)
|
||||
{
|
||||
return BaseClass::createInstanceUnitTest(id, filePaths_rough_to_fine);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
UnitTestElevation::UnitTestElevation()
|
||||
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTestElevation"))
|
||||
{}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
void UnitTestElevation::initTestCase()
|
||||
{
|
||||
|
||||
|
||||
QString filePath(QStringLiteral("/usr/share/arcgis/resources/elevation/Altmark_dt1.tif"));
|
||||
|
||||
s_eleMgr = MyLtsElevationManagerBootstrap::createInstanceUnitTest(s_id, {filePath});
|
||||
@@ -56,7 +42,6 @@ void UnitTestElevation::initTestCase()
|
||||
const bool bIsValid = s_eleMgr->isValid();
|
||||
std::cerr << "myBootstrapMgr->isValid() 1 = " << bIsValid << std::endl;
|
||||
|
||||
|
||||
{
|
||||
s_eleMgr->waitForInitialization();
|
||||
const bool bIsValid = s_eleMgr->isValid();
|
||||
@@ -66,25 +51,21 @@ void UnitTestElevation::initTestCase()
|
||||
|
||||
void UnitTestElevation::init()
|
||||
{
|
||||
QVERIFY2(s_eleMgr , "static LtsElevationManager does not exist");
|
||||
QVERIFY2(s_eleMgr, "static LtsElevationManager does not exist");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void UnitTestElevation::test_elevation_data()
|
||||
{
|
||||
QTest::addColumn<QPointF>("lonLat");
|
||||
QTest::addColumn<double>("elevationRef");
|
||||
|
||||
QTest::newRow("elevation 1 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 10000")).geographic() << 75.0;
|
||||
QTest::newRow("elevation 2 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 72000 13000")).geographic() << 80.0;
|
||||
|
||||
QTest::newRow("elevation 1 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 10000")).geographic() << 75.0;
|
||||
QTest::newRow("elevation 2 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 72000 13000")).geographic() << 80.0;
|
||||
|
||||
|
||||
|
||||
|
||||
QTest::newRow("elevation 3 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 76925 18625")).geographic() << 92.0;
|
||||
QTest::newRow("elevation 3 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 76925 18625")).geographic() << 92.0;
|
||||
}
|
||||
|
||||
void UnitTestElevation::test_elevation()
|
||||
@@ -99,8 +80,8 @@ void UnitTestElevation::test_elevation()
|
||||
|
||||
void UnitTestElevation::test_elevation_isCovered()
|
||||
{
|
||||
const QPointF &lonLat1 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 10000")).geographic();
|
||||
const QPointF &lonLat2 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 60000 10000")).geographic();
|
||||
const QPointF& lonLat1 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 10000")).geographic();
|
||||
const QPointF& lonLat2 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 60000 10000")).geographic();
|
||||
|
||||
const double defaultElevationValue = -123;
|
||||
{
|
||||
@@ -117,7 +98,7 @@ void UnitTestElevation::test_elevation_isCovered()
|
||||
|
||||
void UnitTestElevation::test_elevation_defaultValue()
|
||||
{
|
||||
const QPointF &lonLat = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 10000")).geographic();
|
||||
const QPointF& lonLat = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 10000")).geographic();
|
||||
|
||||
double elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y());
|
||||
QVERIFY2(qFuzzyCompare(elevation, std::numeric_limits<double>::min()), " error on defaultValue");
|
||||
@@ -135,9 +116,6 @@ void UnitTestElevation::test_elevation_defaultValue()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void UnitTestElevation::test_lineOfSightCalculation_data()
|
||||
{
|
||||
QTest::addColumn<QPointF>("startGeo2D");
|
||||
@@ -146,35 +124,35 @@ void UnitTestElevation::test_lineOfSightCalculation_data()
|
||||
QTest::addColumn<double>("endObjH");
|
||||
QTest::addColumn<LtsElevation::LineOfSight>("expectedResult");
|
||||
|
||||
|
||||
|
||||
|
||||
QTest::newRow("losDataset 1 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 10000")).geographic() << 1.0
|
||||
QTest::newRow("losDataset 1 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 10000")).geographic() << 1.0
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 60000")).geographic() << 1.0
|
||||
<< LtsElevation::LineOfSight::LOS_ERROR;
|
||||
|
||||
|
||||
QTest::newRow("losDataset 2 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0
|
||||
QTest::newRow("losDataset 2 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0
|
||||
<< LtsElevation::LineOfSight::LOS_INVISIBLE;
|
||||
|
||||
|
||||
QTest::newRow("losDataset 3 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 20.0
|
||||
QTest::newRow("losDataset 3 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 20.0
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 20.0
|
||||
<< LtsElevation::LineOfSight::LOS_VISIBLE;
|
||||
|
||||
|
||||
QTest::newRow("losDataset 4 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << -1.0
|
||||
QTest::newRow("losDataset 4 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << -1.0
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0
|
||||
<< LtsElevation::LineOfSight::LOS_ERROR;
|
||||
QTest::newRow("losDataset 5 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0
|
||||
QTest::newRow("losDataset 5 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << -1.0
|
||||
<< LtsElevation::LineOfSight::LOS_ERROR;
|
||||
QTest::newRow("losDataset 6 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 0.0
|
||||
QTest::newRow("losDataset 6 ")
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 0.0
|
||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 0.0
|
||||
<< LtsElevation::LineOfSight::LOS_INVISIBLE;
|
||||
|
||||
}
|
||||
|
||||
void UnitTestElevation::test_lineOfSightCalculation()
|
||||
{
|
||||
QFETCH(QPointF, startGeo2D);
|
||||
@@ -195,21 +173,14 @@ void UnitTestElevation::test_lineOfSightCalculation()
|
||||
NOTICE_LOG(m_logger) << "los = " << los;
|
||||
|
||||
{
|
||||
LtsElevation::LineOfSight los2 = s_eleMgr->lineOfSightCalculation(startGeo2D, startObjH,
|
||||
endGeo2D, endObjH);
|
||||
LtsElevation::LineOfSight los2 = s_eleMgr->lineOfSightCalculation(startGeo2D, startObjH, endGeo2D, endObjH);
|
||||
QVERIFY2(los == los2, " got different lineOfSightCalculation result");
|
||||
}
|
||||
|
||||
|
||||
|
||||
QVERIFY2(los == expectedResult, " got lineOfSightCalculation result");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTestElevation", "log4cxxElevationUnitTest.props");
|
||||
@@ -218,7 +189,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
int ret = QTest::qExec(&tc, argc, argv);
|
||||
|
||||
|
||||
if (s_eleMgr)
|
||||
{
|
||||
s_eleMgr->cleanupAll();
|
||||
@@ -226,5 +196,3 @@ int main(int argc, char *argv[])
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+8
-31
@@ -1,45 +1,29 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <LtsElevation/lts_elevation_manager.h>
|
||||
|
||||
#include <ElevationMap/elevation_map_manager.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
#include <LtsElevation/lts_elevation_manager.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QObject>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
using LOGGER_T = NGL::INGLLogger&;
|
||||
|
||||
|
||||
|
||||
|
||||
class UnitTestElevation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
UnitTestElevation();
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void initTestCase();
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
|
||||
|
||||
void test_elevation_data();
|
||||
void test_elevation();
|
||||
|
||||
@@ -49,13 +33,6 @@ private Q_SLOTS:
|
||||
void test_lineOfSightCalculation_data();
|
||||
void test_lineOfSightCalculation();
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
};
|
||||
Executable → Regular
+4
-6
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
@@ -8,7 +7,7 @@
|
||||
namespace LtsElevation
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
LOGGER_T getLogger(const char* name)
|
||||
{
|
||||
static const char ns[] = "Lts.Elevation.";
|
||||
std::string loggerName;
|
||||
@@ -19,14 +18,13 @@ LOGGER_T getLogger(const char *name)
|
||||
|
||||
try
|
||||
{
|
||||
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());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsElevation
|
||||
Executable → Regular
+5
-6
@@ -1,18 +1,17 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
typedef NGL::INGLLogger &LOGGER_T;
|
||||
typedef NGL::INGLLogger& LOGGER_T;
|
||||
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
LOGGER_T getLogger(const char* name);
|
||||
|
||||
inline LOGGER_T getLogger(const QString& loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
} // namespace LtsElevation
|
||||
Executable → Regular
+79
-117
@@ -1,37 +1,37 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_elevation_manager.h"
|
||||
#include <utility>
|
||||
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
||||
|
||||
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
||||
|
||||
#include <Viewer/SituationMap/ElevationMap/elevation_map_manager.h>
|
||||
#include <Viewer/SituationMap/Common/resource_path.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QHash>
|
||||
#include <QSharedPointer>
|
||||
#include <QUrl>
|
||||
#include <Viewer/SituationMap/Common/resource_path.h>
|
||||
#include <Viewer/SituationMap/ElevationMap/elevation_map_manager.h>
|
||||
#include <utility>
|
||||
|
||||
|
||||
|
||||
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_UNDEFINED == (int)LtsElevation::LineOfSight::LOS_UNDEFINED, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_ERROR == (int)LtsElevation::LineOfSight::LOS_ERROR, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_VISIBLE == (int)LtsElevation::LineOfSight::LOS_VISIBLE, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_INVISIBLE == (int)LtsElevation::LineOfSight::LOS_INVISIBLE, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_UNDEFINED ==
|
||||
(int)LtsElevation::LineOfSight::LOS_UNDEFINED,
|
||||
"LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_ERROR ==
|
||||
(int)LtsElevation::LineOfSight::LOS_ERROR,
|
||||
"LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_VISIBLE ==
|
||||
(int)LtsElevation::LineOfSight::LOS_VISIBLE,
|
||||
"LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_INVISIBLE ==
|
||||
(int)LtsElevation::LineOfSight::LOS_INVISIBLE,
|
||||
"LineOfSight mismatch");
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
class LtsElevationManager;
|
||||
|
||||
|
||||
|
||||
using LtsElevatioMgrMapTrainingAreaId = QMap<int, LTS_ELEVATION_MANAGER_TYPE>;
|
||||
|
||||
|
||||
static LtsElevatioMgrMapTrainingAreaId <sElevatioMgrMapTrainingAreaId()
|
||||
static LtsElevatioMgrMapTrainingAreaId& ltsElevatioMgrMapTrainingAreaId()
|
||||
{
|
||||
static LtsElevatioMgrMapTrainingAreaId s_ltsElevatioMgrMapTrainingAreaId;
|
||||
return s_ltsElevatioMgrMapTrainingAreaId;
|
||||
@@ -43,7 +43,7 @@ static void cleanupLtsElevatioMgrMapTrainingAreaId()
|
||||
ltsElevatioMgrMapTrainingAreaId().clear();
|
||||
}
|
||||
|
||||
LtsElevatioMgrMapTrainingAreaId &getLtsElevationMgrMapTrainingAreaId()
|
||||
LtsElevatioMgrMapTrainingAreaId& getLtsElevationMgrMapTrainingAreaId()
|
||||
{
|
||||
if (ltsElevatioMgrMapTrainingAreaId().isEmpty())
|
||||
qAddPostRoutine(cleanupLtsElevatioMgrMapTrainingAreaId);
|
||||
@@ -53,31 +53,24 @@ LtsElevatioMgrMapTrainingAreaId &getLtsElevationMgrMapTrainingAreaId()
|
||||
|
||||
static long s_counter{0};
|
||||
|
||||
|
||||
|
||||
|
||||
class LtsElevationManager::Private
|
||||
{
|
||||
public:
|
||||
public:
|
||||
Private() = default;
|
||||
|
||||
~Private()
|
||||
{
|
||||
delete m_elevationManager;
|
||||
}
|
||||
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
||||
|
||||
QStringList m_filePaths_rough_to_fine;
|
||||
SituationMap::ElevationMapManager *m_elevationManager{nullptr};
|
||||
SituationMap::ElevationMapManager* m_elevationManager{nullptr};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LtsElevationManager::LtsElevationManager()
|
||||
: QObject(nullptr)
|
||||
, d(new Private)
|
||||
LtsElevationManager::LtsElevationManager() : QObject(nullptr), d(new Private)
|
||||
{
|
||||
++s_counter;
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START, s_counter=" << s_counter << " this=" << this;
|
||||
@@ -92,9 +85,9 @@ LtsElevationManager::~LtsElevationManager()
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END, s_counter=" << s_counter << " this=" << this;
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstance(int exerciseId,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
||||
LTS_ELEVATION_MANAGER_TYPE
|
||||
LtsElevationManager::createInstance(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
TRACE_LOG(logger) << Q_FUNC_INFO << " START, exerciseId=" << exerciseId;
|
||||
@@ -107,59 +100,43 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstance(int exerciseId,
|
||||
|
||||
int trainingAreaId = -1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static QHash<int,int> s_exIdToTaIdStore;
|
||||
static QHash<int, int> s_exIdToTaIdStore;
|
||||
|
||||
const auto exTaIt = s_exIdToTaIdStore.find(exerciseId);
|
||||
if (exTaIt != s_exIdToTaIdStore.end())
|
||||
{
|
||||
|
||||
|
||||
trainingAreaId = *exTaIt;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!exmDtc || !asmDtc)
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for exerciseId=" << exerciseId
|
||||
<< ", asmDtc=" << asmDtc
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for exerciseId=" << exerciseId << ", asmDtc=" << asmDtc
|
||||
<< ", exmDtc=" << exmDtc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, exmDtc);
|
||||
if (trainingAreaId <= 0)
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
s_exIdToTaIdStore[exerciseId] = trainingAreaId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE temp = createInstanceForTrainingAreaId(trainingAreaId, asmDtc);
|
||||
if (!temp)
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error on createInstanceForTrainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
temp->initDDS(exmDtc, asmDtc);
|
||||
|
||||
TRACE_LOG(logger) << Q_FUNC_INFO << " END, exerciseId=" << exerciseId;
|
||||
@@ -171,8 +148,9 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::getInstance(int exerciseId)
|
||||
return LtsElevationManager::createInstance(exerciseId);
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(int trainingAreaId,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
||||
LTS_ELEVATION_MANAGER_TYPE
|
||||
LtsElevationManager::createInstanceForTrainingAreaId(int trainingAreaId,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
TRACE_LOG(logger) << Q_FUNC_INFO << " START, trainingAreaId=" << trainingAreaId;
|
||||
@@ -183,31 +161,26 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
LtsElevatioMgrMapTrainingAreaId &map = getLtsElevationMgrMapTrainingAreaId();
|
||||
LtsElevatioMgrMapTrainingAreaId& map = getLtsElevationMgrMapTrainingAreaId();
|
||||
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(trainingAreaId);
|
||||
|
||||
|
||||
if (it != map.end())
|
||||
{
|
||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
||||
return it.value();
|
||||
}
|
||||
|
||||
|
||||
if (!asmDtc)
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for trainingAreaId=" << trainingAreaId
|
||||
<< ", asmDtc=" << asmDtc;
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for trainingAreaId=" << trainingAreaId << ", asmDtc=" << asmDtc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
||||
|
||||
|
||||
temp->initDDS(nullptr, asmDtc);
|
||||
|
||||
const QStringList &filenames = temp->getFilenamesForTrainingArea(trainingAreaId);
|
||||
const QStringList& filenames = temp->getFilenamesForTrainingArea(trainingAreaId);
|
||||
if (filenames.isEmpty())
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no filenames for trainingAreaId=" << trainingAreaId;
|
||||
@@ -215,7 +188,6 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool bInitFilenames = temp->init(filenames);
|
||||
if (!bInitFilenames)
|
||||
{
|
||||
@@ -232,27 +204,22 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(
|
||||
return map[trainingAreaId];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine)
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceUnitTest(int id,
|
||||
const QStringList& filePaths_rough_to_fine)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
|
||||
LtsElevatioMgrMapTrainingAreaId &map = getLtsElevationMgrMapTrainingAreaId();
|
||||
LtsElevatioMgrMapTrainingAreaId& map = getLtsElevationMgrMapTrainingAreaId();
|
||||
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(id);
|
||||
|
||||
|
||||
if (it != map.end())
|
||||
{
|
||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
||||
return it.value();
|
||||
}
|
||||
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
||||
|
||||
|
||||
bool bInitFilenames = temp->init(filePaths_rough_to_fine);
|
||||
if (!bInitFilenames)
|
||||
{
|
||||
@@ -267,12 +234,8 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceUnitTest(int id, c
|
||||
|
||||
TRACE_LOG(logger) << Q_FUNC_INFO << " END, trainingAreaId=" << id;
|
||||
return map[id];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LtsElevationManager::cleanupAll()
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
@@ -281,7 +244,8 @@ void LtsElevationManager::cleanupAll()
|
||||
TRACE_LOG(logger) << Q_FUNC_INFO << " END";
|
||||
}
|
||||
|
||||
void LtsElevationManager::initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc, const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
||||
void LtsElevationManager::initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc)
|
||||
{
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START";
|
||||
|
||||
@@ -307,19 +271,18 @@ QStringList LtsElevationManager::getFilenamesForExercise(int exerciseId)
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
int trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, d->m_exmDtc);
|
||||
if (trainingAreaId <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||
return {};
|
||||
}
|
||||
|
||||
QStringList filePaths_rough_to_fine = getFilenamesForTrainingArea(trainingAreaId);
|
||||
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END, filePaths_rough_to_fine=" << filePaths_rough_to_fine.join(QStringLiteral(";"));
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO
|
||||
<< " END, filePaths_rough_to_fine=" << filePaths_rough_to_fine.join(QStringLiteral(";"));
|
||||
return filePaths_rough_to_fine;
|
||||
}
|
||||
|
||||
@@ -334,21 +297,20 @@ QStringList LtsElevationManager::getFilenamesForTrainingArea(int trainingAreaId)
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
QStringList filePaths_rough_to_fine;
|
||||
{
|
||||
d->m_asmDtc->waitForHistoricalDataTrainingArea(1000);
|
||||
const AssetManagement::TrainingArea &ta = d->m_asmDtc->trainingArea(trainingAreaId);
|
||||
const AssetManagement::TrainingArea& ta = d->m_asmDtc->trainingArea(trainingAreaId);
|
||||
if (ta.id() != trainingAreaId)
|
||||
{
|
||||
ERROR_LOG(m_logger) << Q_FUNC_INFO << " Error on s_asmDtc->trainingArea"
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return {};
|
||||
}
|
||||
const std::vector<AssetManagement::MapDescription> &mdVec = ta.elevation();
|
||||
const std::vector<AssetManagement::MapDescription>& mdVec = ta.elevation();
|
||||
filePaths_rough_to_fine.reserve(mdVec.size());
|
||||
|
||||
for (const AssetManagement::MapDescription &md : std::as_const(mdVec))
|
||||
for (const AssetManagement::MapDescription& md : std::as_const(mdVec))
|
||||
{
|
||||
|
||||
QUrl url(QString::fromStdString(md.url()));
|
||||
@@ -359,11 +321,12 @@ QStringList LtsElevationManager::getFilenamesForTrainingArea(int trainingAreaId)
|
||||
filePaths_rough_to_fine.append(filePathAbs);
|
||||
}
|
||||
}
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END, filePaths_rough_to_fine=" << filePaths_rough_to_fine.join(QStringLiteral(";"));
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO
|
||||
<< " END, filePaths_rough_to_fine=" << filePaths_rough_to_fine.join(QStringLiteral(";"));
|
||||
return filePaths_rough_to_fine;
|
||||
}
|
||||
|
||||
bool LtsElevationManager::init(const QStringList &filePaths_rough_to_fine)
|
||||
bool LtsElevationManager::init(const QStringList& filePaths_rough_to_fine)
|
||||
{
|
||||
delete d->m_elevationManager;
|
||||
|
||||
@@ -384,7 +347,8 @@ bool LtsElevationManager::init(const QStringList &filePaths_rough_to_fine)
|
||||
return true;
|
||||
}
|
||||
|
||||
int LtsElevationManager::exerciseIdToTrainingAreaId(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc)
|
||||
int LtsElevationManager::exerciseIdToTrainingAreaId(int exerciseId,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
|
||||
@@ -395,12 +359,11 @@ int LtsElevationManager::exerciseIdToTrainingAreaId(int exerciseId, const std::s
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
int trainingAreaId = -1;
|
||||
{
|
||||
exmDtc->waitForHistoricalDataExercise(1000);
|
||||
|
||||
const ExerciseManagement::Exercise &exm = exmDtc->exercise(exerciseId);
|
||||
const ExerciseManagement::Exercise& exm = exmDtc->exercise(exerciseId);
|
||||
if (exm.id() != exerciseId)
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error on m_exmDtc->exercise"
|
||||
@@ -412,8 +375,7 @@ int LtsElevationManager::exerciseIdToTrainingAreaId(int exerciseId, const std::s
|
||||
if (trainingAreaId <= 0)
|
||||
{
|
||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -434,17 +396,19 @@ bool LtsElevationManager::isValid() const
|
||||
return d->m_elevationManager->isValid();
|
||||
}
|
||||
|
||||
double LtsElevationManager::elevation(double lon_rad, double lat_rad, double defaultValue, bool *bIsCovered) const
|
||||
double LtsElevationManager::elevation(double lon_rad, double lat_rad, double defaultValue, bool* bIsCovered) const
|
||||
{
|
||||
if (!d->m_elevationManager)
|
||||
return defaultValue;
|
||||
return d->m_elevationManager->elevation(lon_rad, lat_rad, defaultValue, bIsCovered);
|
||||
}
|
||||
|
||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D &startPointGeo_absZ,
|
||||
const LtsUtils::QPoint3D &endPointGeo_absZ)
|
||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D& startPointGeo_absZ,
|
||||
const LtsUtils::QPoint3D& endPointGeo_absZ)
|
||||
{
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START" << ", startPointGeo_absZ = " << startPointGeo_absZ << ", endPointGeo_absZ = " << endPointGeo_absZ;
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START"
|
||||
<< ", startPointGeo_absZ = " << startPointGeo_absZ
|
||||
<< ", endPointGeo_absZ = " << endPointGeo_absZ;
|
||||
|
||||
if (!isValid())
|
||||
{
|
||||
@@ -452,39 +416,37 @@ LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D
|
||||
return LineOfSight::LOS_ERROR;
|
||||
}
|
||||
|
||||
|
||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult = d->m_elevationManager->lineOfSightCalculation(startPointGeo_absZ,endPointGeo_absZ);
|
||||
|
||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult =
|
||||
d->m_elevationManager->lineOfSightCalculation(startPointGeo_absZ, endPointGeo_absZ);
|
||||
|
||||
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
||||
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END" << ", startPointGeo = " << startPointGeo_absZ << ", endPointGeo = " << endPointGeo_absZ
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END"
|
||||
<< ", startPointGeo = " << startPointGeo_absZ << ", endPointGeo = " << endPointGeo_absZ
|
||||
<< " -> LineOfSight " << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const QPointF &startPointGeo, double startHat, const QPointF &endPointGeo, double endHat)
|
||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const QPointF& startPointGeo, double startHat,
|
||||
const QPointF& endPointGeo, double endHat)
|
||||
{
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START"
|
||||
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat;
|
||||
|
||||
|
||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult = d->m_elevationManager->lineOfSightCalculation(startPointGeo, startHat,
|
||||
endPointGeo, endHat);
|
||||
|
||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult =
|
||||
d->m_elevationManager->lineOfSightCalculation(startPointGeo, startHat, endPointGeo, endHat);
|
||||
|
||||
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
||||
|
||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END"
|
||||
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat
|
||||
<< " -> LineOfSight " << static_cast<int>(eleMapMgrResult);
|
||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat << " -> LineOfSight "
|
||||
<< static_cast<int>(eleMapMgrResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
const QString toString(const LineOfSight &value)
|
||||
const QString toString(const LineOfSight& value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
@@ -501,10 +463,10 @@ const QString toString(const LineOfSight &value)
|
||||
return QStringLiteral("LineOfSightERROR");
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const LineOfSight value)
|
||||
std::ostream& operator<<(std::ostream& stream, const LineOfSight value)
|
||||
{
|
||||
stream << toString(value).toStdString();
|
||||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsElevation
|
||||
Executable → Regular
+31
-62
@@ -1,23 +1,17 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "logger.h"
|
||||
#include "ltselevation_export.h"
|
||||
|
||||
#include <LtsUtilsCore/qpoint3d.h>
|
||||
|
||||
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QStringList>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <memory>
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
@@ -30,7 +24,7 @@ namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
} // namespace ExerciseManagement
|
||||
|
||||
namespace AssetManagement
|
||||
{
|
||||
@@ -38,92 +32,67 @@ namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AssetManagement
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
|
||||
enum class LineOfSight { LOS_UNDEFINED,
|
||||
LOS_ERROR,
|
||||
LOS_VISIBLE,
|
||||
LOS_INVISIBLE };
|
||||
enum class LineOfSight { LOS_UNDEFINED, LOS_ERROR, LOS_VISIBLE, LOS_INVISIBLE };
|
||||
|
||||
class LtsElevationManager;
|
||||
using LTS_ELEVATION_MANAGER_TYPE = QPointer<LtsElevationManager>;
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSELEVATION_EXPORT LtsElevationManager : public QObject
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstance(int exerciseId,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc = {},
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc = {});
|
||||
public:
|
||||
static LTS_ELEVATION_MANAGER_TYPE
|
||||
createInstance(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc = {},
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc = {});
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE getInstance(int exerciseId);
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceForTrainingAreaId(int trainingAreaId,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc = nullptr);
|
||||
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE
|
||||
createInstanceForTrainingAreaId(int trainingAreaId,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc = nullptr);
|
||||
|
||||
static void cleanupAll();
|
||||
virtual ~LtsElevationManager();
|
||||
|
||||
|
||||
bool waitForInitialization();
|
||||
bool isValid() const;
|
||||
|
||||
double elevation(double lon_rad, double lat_rad, double defaultValue = std::numeric_limits<double>::min(), bool *bIsCovered = nullptr) const;
|
||||
double elevation(double lon_rad, double lat_rad, double defaultValue = std::numeric_limits<double>::min(),
|
||||
bool* bIsCovered = nullptr) const;
|
||||
|
||||
LineOfSight lineOfSightCalculation(const LtsUtils::QPoint3D &startPointGeo_absZ,
|
||||
const LtsUtils::QPoint3D &endPointGeo_absZ);
|
||||
LineOfSight lineOfSightCalculation(const LtsUtils::QPoint3D& startPointGeo_absZ,
|
||||
const LtsUtils::QPoint3D& endPointGeo_absZ);
|
||||
|
||||
LineOfSight lineOfSightCalculation(const QPointF &startPointGeo, double startHat,
|
||||
const QPointF &endPointGeo, double endHat);
|
||||
LineOfSight lineOfSightCalculation(const QPointF& startPointGeo, double startHat, const QPointF& endPointGeo,
|
||||
double endHat);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
explicit LtsElevationManager();
|
||||
|
||||
|
||||
|
||||
void initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc);
|
||||
bool init(const QStringList &filePaths_rough_to_fine);
|
||||
static int exerciseIdToTrainingAreaId(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc);
|
||||
|
||||
void initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc);
|
||||
bool init(const QStringList& filePaths_rough_to_fine);
|
||||
static int exerciseIdToTrainingAreaId(int exerciseId,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc);
|
||||
|
||||
QStringList getFilenamesForExercise(int exerciseId);
|
||||
QStringList getFilenamesForTrainingArea(int trainingAreaId);
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceUnitTest(int id, const QStringList& filePaths_rough_to_fine);
|
||||
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
private:
|
||||
class Private;
|
||||
|
||||
Private *d;
|
||||
Private* d;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
LTSELEVATION_EXPORT const QString toString(const LtsElevation::LineOfSight &value);
|
||||
LTSELEVATION_EXPORT const QString toString(const LtsElevation::LineOfSight& value);
|
||||
|
||||
LTSELEVATION_EXPORT std::ostream &operator<< (std::ostream &stream,
|
||||
const LtsElevation::LineOfSight value);
|
||||
LTSELEVATION_EXPORT std::ostream& operator<<(std::ostream& stream, const LtsElevation::LineOfSight value);
|
||||
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsElevation
|
||||
Executable → Regular
+40
-87
@@ -1,25 +1,26 @@
|
||||
|
||||
|
||||
|
||||
#include "aes_crypt.h"
|
||||
#include <QtCore/QByteArray>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
namespace LtsLicence
|
||||
{
|
||||
struct AesCryptPrivate
|
||||
{
|
||||
AesCryptPrivate()
|
||||
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR))
|
||||
, logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
||||
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR)),
|
||||
logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
||||
{
|
||||
qsrand(time(nullptr));
|
||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||
ERR_load_crypto_strings();
|
||||
#endif
|
||||
}
|
||||
|
||||
~AesCryptPrivate()
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||
@@ -28,11 +29,11 @@ struct AesCryptPrivate
|
||||
}
|
||||
|
||||
QString passPhrase;
|
||||
NGL::INGLLogger &logger;
|
||||
NGL::INGLLogger& logger;
|
||||
};
|
||||
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
||||
|
||||
void setPassPhrase(const QString &passPhrase)
|
||||
void setPassPhrase(const QString& passPhrase)
|
||||
{
|
||||
s_Private->passPhrase = passPhrase;
|
||||
}
|
||||
@@ -42,9 +43,7 @@ QString 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)
|
||||
*bOk = false;
|
||||
@@ -54,72 +53,53 @@ QByteArray decryptData(const QByteArray &dataToDecrypt,
|
||||
int outSize2 = 0;
|
||||
unsigned char key[32];
|
||||
|
||||
|
||||
const QByteArray baPassword = pw.toUtf8();
|
||||
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);
|
||||
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);
|
||||
if (i != 32)
|
||||
{
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits" ;
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
ret = EVP_DecryptInit_ex(ctx,
|
||||
EVP_aes_256_cbc(),
|
||||
nullptr,
|
||||
key,
|
||||
salt);
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
ret = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptInit_ex failed" ;
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptInit_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
|
||||
QByteArray bufDecrypted;
|
||||
bufDecrypted.resize(bufEncrypted.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(bufEncrypted.data());
|
||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufDecrypted.data());
|
||||
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(bufEncrypted.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)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptUpdate failed" ;
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptUpdate failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
ret = EVP_DecryptFinal_ex(ctx,
|
||||
dataOut + outSize1,
|
||||
&outSize2);
|
||||
ret = EVP_DecryptFinal_ex(ctx, dataOut + outSize1, &outSize2);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptFinal_ex failed" ;
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptFinal_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
@@ -132,10 +112,7 @@ QByteArray decryptData(const QByteArray &dataToDecrypt,
|
||||
return bufDecrypted;
|
||||
}
|
||||
|
||||
|
||||
QByteArray encryptData(const QByteArray &dataToEncrypt,
|
||||
const QString &pw,
|
||||
bool *bOk)
|
||||
QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw, bool* bOk)
|
||||
{
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
@@ -146,77 +123,53 @@ QByteArray encryptData(const QByteArray &dataToEncrypt,
|
||||
unsigned char key[32];
|
||||
QByteArray bufEncrypted;
|
||||
|
||||
|
||||
const QByteArray baPassword = pw.toUtf8();
|
||||
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);
|
||||
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);
|
||||
if (i != 32)
|
||||
{
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits" ;
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
|
||||
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
|
||||
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
|
||||
baSalt[i] = qrand();
|
||||
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();
|
||||
ret = EVP_EncryptInit_ex(ctx,
|
||||
EVP_aes_256_cbc(),
|
||||
nullptr,
|
||||
key,
|
||||
salt);
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
ret = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptInit_ex failed" ;
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptInit_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
|
||||
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char *>(salt), EVP_MAX_IV_LENGTH);
|
||||
bufEncrypted.resize(bufEncrypted.size() +
|
||||
dataToEncrypt.size() +
|
||||
EVP_CIPHER_CTX_block_size(ctx));
|
||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(dataToEncrypt.data());
|
||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufEncrypted.data());
|
||||
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char*>(salt), EVP_MAX_IV_LENGTH);
|
||||
bufEncrypted.resize(bufEncrypted.size() + dataToEncrypt.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(dataToEncrypt.data());
|
||||
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufEncrypted.data());
|
||||
dataOut += baSalt.size();
|
||||
ret = EVP_EncryptUpdate(ctx,
|
||||
dataOut,
|
||||
&outSize1,
|
||||
dataIn,
|
||||
dataToEncrypt.size());
|
||||
ret = EVP_EncryptUpdate(ctx, dataOut, &outSize1, dataIn, dataToEncrypt.size());
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptUpdate failed" ;
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptUpdate failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
|
||||
ret = EVP_EncryptFinal_ex(ctx,
|
||||
dataOut + outSize1,
|
||||
&outSize2);
|
||||
ret = EVP_EncryptFinal_ex(ctx, dataOut + outSize1, &outSize2);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptFinal_ex failed" ;
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptFinal_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
@@ -229,4 +182,4 @@ QByteArray encryptData(const QByteArray &dataToEncrypt,
|
||||
return bufEncrypted;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsLicence
|
||||
Executable → Regular
+8
-10
@@ -1,22 +1,20 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include "ltslicence_export.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace LtsLicence
|
||||
{
|
||||
|
||||
LTSLICENCE_EXPORT void setPassPhrase(const QString &passPhrase);
|
||||
LTSLICENCE_EXPORT void setPassPhrase(const 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
|
||||
Executable → Regular
+6
-7
@@ -1,13 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "aes_crypt_test.h"
|
||||
|
||||
#include "aes_crypt.h"
|
||||
#include "aes_crypt_test.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
QTEST_MAIN(aes_crypt_test)
|
||||
|
||||
@@ -30,7 +30,6 @@ void aes_crypt_test::truePassTest()
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
QCOMPARE(dec, content);
|
||||
|
||||
|
||||
const QByteArray bigContent(12345, '1');
|
||||
const QByteArray bigEnc = LtsLicence::encryptData(bigContent, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
|
||||
Executable → Regular
+1
-3
@@ -1,15 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class aes_crypt_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void truePassTest();
|
||||
void falsePassTest();
|
||||
|
||||
Executable → Regular
+17
-40
@@ -1,21 +1,21 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "lts_licence.h"
|
||||
#include <QDomDocument>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QDomDocument>
|
||||
#include <QObject>
|
||||
|
||||
namespace LtsLicence
|
||||
{
|
||||
static bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec);
|
||||
static NGL::INGLLogger &getLogger()
|
||||
static bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec);
|
||||
|
||||
static NGL::INGLLogger& getLogger()
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
||||
}
|
||||
|
||||
QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
||||
QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
||||
{
|
||||
QVector<Licence> licenceVec;
|
||||
|
||||
@@ -26,8 +26,8 @@ QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
||||
|
||||
if (!xmlDoc.setContent(unencryptedXmlData, &errorMsg, &errorLine, &errorColumn))
|
||||
{
|
||||
ERROR_LOG(getLogger()) << "Error reading xml data, " << "error in line " << errorLine
|
||||
<< ", column " << errorColumn
|
||||
ERROR_LOG(getLogger()) << "Error reading xml data, "
|
||||
<< "error in line " << errorLine << ", column " << errorColumn
|
||||
<< ", message: " << errorMsg;
|
||||
return licenceVec;
|
||||
}
|
||||
@@ -49,13 +49,12 @@ QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
||||
return licenceVec;
|
||||
}
|
||||
|
||||
|
||||
QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
||||
QByteArray writeUnencryptedLicences(const QVector<Licence>& licences)
|
||||
{
|
||||
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);
|
||||
|
||||
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
|
||||
@@ -66,35 +65,29 @@ QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
||||
QDomElement lic = xmlDoc.createElement(QLatin1String("licence"));
|
||||
root.appendChild(lic);
|
||||
|
||||
|
||||
QDomElement element = xmlDoc.createElement(QLatin1String("name"));
|
||||
QDomText text = xmlDoc.createTextNode(licences[i].name);
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("ignoreMaxCount"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreMaxCount));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("ignoreExpiration"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreExpiration));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("maxCount"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].maxCount));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
|
||||
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
||||
const QString qs = licences[i].expiration.toString(format);
|
||||
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("expiration"));
|
||||
text = xmlDoc.createTextNode(qs);
|
||||
element.appendChild(text);
|
||||
@@ -104,60 +97,46 @@ QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
||||
return xmlDoc.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec)
|
||||
bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec)
|
||||
{
|
||||
Licence licence;
|
||||
|
||||
|
||||
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
|
||||
licence.name = tag.text();
|
||||
|
||||
|
||||
tag = licenceElement.firstChildElement(QLatin1String("ignoreMaxCount"));
|
||||
licence.ignoreMaxCount = tag.text().toInt();
|
||||
|
||||
|
||||
tag = licenceElement.firstChildElement(QLatin1String("ignoreExpiration"));
|
||||
licence.ignoreExpiration = tag.text().toInt();
|
||||
|
||||
|
||||
tag = licenceElement.firstChildElement(QLatin1String("maxCount"));
|
||||
licence.maxCount = tag.text().toInt();
|
||||
|
||||
|
||||
tag = licenceElement.firstChildElement(QLatin1String("expiration"));
|
||||
|
||||
const QString qs(tag.text());
|
||||
|
||||
|
||||
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
||||
const QDateTime qdt = QDateTime::fromString(qs, format);
|
||||
|
||||
if (!qdt.isValid())
|
||||
{
|
||||
ERROR_LOG(getLogger()) << "Invalid expiration format! " << qs
|
||||
<< " used format: " << format
|
||||
;
|
||||
ERROR_LOG(getLogger()) << "Invalid expiration format! " << qs << " used format: " << format;
|
||||
return false;
|
||||
}
|
||||
|
||||
licence.expiration = qdt;
|
||||
INFO_LOG(getLogger()) << "Read licence for:'" << licence.name << "'"
|
||||
<< " IgnoreMaxCount: " << licence.ignoreMaxCount
|
||||
<< " IgnoreExpiration: " << licence.ignoreExpiration
|
||||
<< " MaxCount: " << licence.maxCount
|
||||
<< " Expiration: " << licence.expiration.date().toString()
|
||||
<< " " << licence.expiration.time().toString()
|
||||
<< " RefCount: " << licence.licenceRefCount
|
||||
;
|
||||
<< " IgnoreExpiration: " << licence.ignoreExpiration << " MaxCount: " << licence.maxCount
|
||||
<< " Expiration: " << licence.expiration.date().toString() << " "
|
||||
<< licence.expiration.time().toString() << " RefCount: " << licence.licenceRefCount;
|
||||
|
||||
licenceVec.append(licence);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString Licence::toString() const
|
||||
{
|
||||
return QObject::tr("Name: %1, Count: %2, ExpireDate: %3, Expires: %4, UseMaxCount: %5")
|
||||
@@ -168,6 +147,4 @@ QString Licence::toString() const
|
||||
.arg(ignoreMaxCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
} // namespace LtsLicence
|
||||
Executable → Regular
+5
-9
@@ -1,12 +1,12 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltslicence_export.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace LtsLicence
|
||||
{
|
||||
@@ -23,11 +23,7 @@ struct LTSLICENCE_EXPORT Licence
|
||||
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
|
||||
Executable → Regular
+13
-15
@@ -1,25 +1,22 @@
|
||||
|
||||
|
||||
|
||||
#include "logout_info_dialog.h"
|
||||
|
||||
#include "ui_logout_info_dialog.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
namespace LtsLogin
|
||||
{
|
||||
|
||||
LogoutInformationDialog::LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget *parent)
|
||||
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
||||
, m_ui(new Ui::LogoutInformationDialog)
|
||||
, m_timer(new QTimer(this))
|
||||
, m_timeOut(timeOut)
|
||||
, m_secsLeft(timeOut)
|
||||
LogoutInformationDialog::LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction,
|
||||
QWidget* parent)
|
||||
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal), m_ui(new Ui::LogoutInformationDialog),
|
||||
m_timer(new QTimer(this)), m_timeOut(timeOut), m_secsLeft(timeOut)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
QString actionText;
|
||||
switch(shutdownAction.underlying())
|
||||
switch (shutdownAction.underlying())
|
||||
{
|
||||
case AssetManagement::ShutdownAction::NoAction:
|
||||
case AssetManagement::ShutdownAction::Logout:
|
||||
@@ -35,8 +32,10 @@ LogoutInformationDialog::LogoutInformationDialog(int timeOut, AssetManagement::S
|
||||
|
||||
setText(tr("A %1 was triggered by a remote workstation.").arg(actionText));
|
||||
|
||||
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Ok), &QPushButton::clicked, this, &LogoutInformationDialog::acceptClicked);
|
||||
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &LogoutInformationDialog::closeClicked);
|
||||
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Ok), &QPushButton::clicked, this,
|
||||
&LogoutInformationDialog::acceptClicked);
|
||||
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this,
|
||||
&LogoutInformationDialog::closeClicked);
|
||||
connect(m_timer, &QTimer::timeout, this, &LogoutInformationDialog::onTimerTimeout);
|
||||
|
||||
m_timer->setInterval(1000);
|
||||
@@ -47,7 +46,7 @@ LogoutInformationDialog::~LogoutInformationDialog()
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void LogoutInformationDialog::setText(const QString &text)
|
||||
void LogoutInformationDialog::setText(const QString& text)
|
||||
{
|
||||
m_ui->lblLogoutText->setText(text);
|
||||
}
|
||||
@@ -75,7 +74,6 @@ void LogoutInformationDialog::closeClicked()
|
||||
{
|
||||
m_timer->stop();
|
||||
reject();
|
||||
|
||||
}
|
||||
|
||||
void LogoutInformationDialog::setCloseButtonText(int secsLeft)
|
||||
@@ -83,7 +81,7 @@ void LogoutInformationDialog::setCloseButtonText(int secsLeft)
|
||||
m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close)->setText(tr("Abort [%1]").arg(secsLeft));
|
||||
}
|
||||
|
||||
void LogoutInformationDialog::showEvent(QShowEvent *event)
|
||||
void LogoutInformationDialog::showEvent(QShowEvent* event)
|
||||
{
|
||||
m_secsLeft = m_timeOut;
|
||||
setCloseButtonText(m_secsLeft);
|
||||
@@ -91,4 +89,4 @@ void LogoutInformationDialog::showEvent(QShowEvent *event)
|
||||
LtsWidgets::LtsFramelessDialog::showEvent(event);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsLogin
|
||||
Executable → Regular
+16
-16
@@ -1,15 +1,16 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <LtsWidgets/lts_frameless_dialog.h>
|
||||
#include <AssetManagement/asm.hpp>
|
||||
#include <LtsWidgets/lts_frameless_dialog.h>
|
||||
#include <QObject>
|
||||
|
||||
class QTimer;
|
||||
|
||||
namespace Ui { class LogoutInformationDialog; }
|
||||
namespace Ui
|
||||
{
|
||||
class LogoutInformationDialog;
|
||||
}
|
||||
|
||||
namespace LtsLogin
|
||||
{
|
||||
@@ -18,27 +19,26 @@ class LogoutInformationDialog : public LtsWidgets::LtsFramelessDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget *parent = nullptr);
|
||||
public:
|
||||
LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget* parent = nullptr);
|
||||
~LogoutInformationDialog();
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void onTimerTimeout();
|
||||
void acceptClicked();
|
||||
void closeClicked();
|
||||
|
||||
private:
|
||||
void setText(const QString &text);
|
||||
private:
|
||||
void setText(const QString& text);
|
||||
void setCloseButtonText(int secsLeft);
|
||||
|
||||
Ui::LogoutInformationDialog *m_ui;
|
||||
QTimer *m_timer;
|
||||
Ui::LogoutInformationDialog* m_ui;
|
||||
QTimer* m_timer;
|
||||
int m_timeOut;
|
||||
int m_secsLeft;
|
||||
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override final;
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override final;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsLogin
|
||||
Executable → Regular
+33
-63
@@ -1,34 +1,31 @@
|
||||
|
||||
|
||||
#include "lts_login.h"
|
||||
|
||||
#include "logout_info_dialog.h"
|
||||
|
||||
#include <LtsPluginManager/lts_plugin_manager.h>
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <LtsSession/lts_session_manager.h>
|
||||
#include <LtsPluginManager/lts_plugin_manager.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsWidgets/lts_wait_dialog.h>
|
||||
#include <LtsSession/lts_session_manager.h>
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
|
||||
#include <LtsWidgets/lts_wait_dialog.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
namespace LtsLogin
|
||||
{
|
||||
const int logoutShutdownTimeout = 2 * 60;
|
||||
|
||||
LtsLogin::LtsLogin()
|
||||
: m_loginApp(nullptr)
|
||||
, m_shutdownAction(AssetManagement::ShutdownAction::NoAction)
|
||||
, m_isInLogoutDialog(false)
|
||||
{}
|
||||
|
||||
: m_loginApp(nullptr), m_shutdownAction(AssetManagement::ShutdownAction::NoAction), m_isInLogoutDialog(false)
|
||||
{
|
||||
}
|
||||
|
||||
LtsLogin::~LtsLogin()
|
||||
{
|
||||
@@ -36,7 +33,6 @@ LtsLogin::~LtsLogin()
|
||||
m_loginApp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::login()
|
||||
{
|
||||
LtsAppDescriptor::PluginInfo opmDataPlugin;
|
||||
@@ -87,15 +83,10 @@ void LtsLogin::login()
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished, this, [this]() {
|
||||
disconnect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished, this, nullptr);
|
||||
|
||||
|
||||
connect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
||||
this, [this]()
|
||||
{
|
||||
disconnect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
||||
this, nullptr);
|
||||
|
||||
LtsSession::LtsSession *session = getAdminSession();
|
||||
LtsSession::LtsSession* session = getAdminSession();
|
||||
|
||||
if (!session)
|
||||
{
|
||||
@@ -107,26 +98,24 @@ void LtsLogin::login()
|
||||
if (session->isInitializationDone())
|
||||
QMetaObject::invokeMethod(this, &LtsLogin::slotLoginDone);
|
||||
else
|
||||
connect(session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
||||
this, &LtsLogin::slotLoginDone, Qt::UniqueConnection);
|
||||
connect(session, &LtsSession::LtsSession::signalDoneInitializingSession, this, &LtsLogin::slotLoginDone,
|
||||
Qt::UniqueConnection);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::slotLoginDone()
|
||||
{
|
||||
LtsSession::LtsSession *session = getAdminSession();
|
||||
LtsSession::LtsSession* session = getAdminSession();
|
||||
|
||||
if (session != nullptr)
|
||||
{
|
||||
disconnect(session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
||||
this, &LtsLogin::slotLoginDone);
|
||||
disconnect(session, &LtsSession::LtsSession::signalDoneInitializingSession, this, &LtsLogin::slotLoginDone);
|
||||
|
||||
if (session->getDtc<AssetManagement::DataInterface>(m_asmDtc))
|
||||
{
|
||||
m_asmDtc->enableWorkstationLogout();
|
||||
connect(m_asmDtc.get(), &AssetManagement::Interface::Dtc::workstationLogoutChanged,
|
||||
this, &LtsLogin::slotLogoutShutdown);
|
||||
connect(m_asmDtc.get(), &AssetManagement::Interface::Dtc::workstationLogoutChanged, this,
|
||||
&LtsLogin::slotLogoutShutdown);
|
||||
}
|
||||
else
|
||||
qWarning() << "LtsLogin: no asm dtc, no remote logout/shutdown!";
|
||||
@@ -141,29 +130,21 @@ void LtsLogin::slotLoginDone()
|
||||
emit signalLoginDone();
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::showLogoutInformationDialog(AssetManagement::ShutdownAction action)
|
||||
{
|
||||
LogoutInformationDialog *lid = new LogoutInformationDialog(logoutShutdownTimeout, action, nullptr);
|
||||
connect(lid, &LogoutInformationDialog::accepted,
|
||||
this, [this, action]()
|
||||
{
|
||||
LogoutInformationDialog* lid = new LogoutInformationDialog(logoutShutdownTimeout, action, nullptr);
|
||||
connect(lid, &LogoutInformationDialog::accepted, this, [this, action]() {
|
||||
m_shutdownAction = action;
|
||||
m_isInLogoutDialog = false;
|
||||
emit signalLogout();
|
||||
});
|
||||
|
||||
connect(lid, &LogoutInformationDialog::rejected,
|
||||
this, [this]()
|
||||
{
|
||||
m_isInLogoutDialog = false;
|
||||
});
|
||||
connect(lid, &LogoutInformationDialog::rejected, this, [this]() { m_isInLogoutDialog = false; });
|
||||
|
||||
lid->show();
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout &data, DataModification modType)
|
||||
void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout& data, DataModification modType)
|
||||
{
|
||||
if (m_isInLogoutDialog)
|
||||
return;
|
||||
@@ -175,7 +156,8 @@ void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout &data
|
||||
m_asmDtc->enableAsset();
|
||||
for (int id : data.ids())
|
||||
{
|
||||
if (QString::fromStdString(m_asmDtc->asset(id).name()).compare(LtsSession::LtsSession::workstationName(), Qt::CaseInsensitive) == 0)
|
||||
if (QString::fromStdString(m_asmDtc->asset(id).name())
|
||||
.compare(LtsSession::LtsSession::workstationName(), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
m_isInLogoutDialog = true;
|
||||
showLogoutInformationDialog(data.shutdownAction());
|
||||
@@ -184,13 +166,11 @@ void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout &data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LtsSession::LtsSession *LtsLogin::getAdminSession()
|
||||
LtsSession::LtsSession* LtsLogin::getAdminSession()
|
||||
{
|
||||
return m_loginApp->m_sessionManager->getSession(IDL::PartitionType::Global, 0);
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::logoff()
|
||||
{
|
||||
if (m_loginApp == nullptr)
|
||||
@@ -199,9 +179,7 @@ void LtsLogin::logoff()
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LtsSession::LtsSession *datSession = getAdminSession();
|
||||
LtsSession::LtsSession* datSession = getAdminSession();
|
||||
|
||||
if (!datSession)
|
||||
{
|
||||
@@ -215,32 +193,27 @@ void LtsLogin::logoff()
|
||||
LtsSessionData::LtsSessionData::getInstance()->clear();
|
||||
|
||||
std::shared_ptr<OperatorManagement::Interface::Ftc> opmFtc;
|
||||
if (operatorId == -1 ||
|
||||
!datSession->getFtc<OperatorManagement::DataInterface>(opmFtc)
|
||||
)
|
||||
if (operatorId == -1 || !datSession->getFtc<OperatorManagement::DataInterface>(opmFtc))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
LtsUtils::OperatorSettings *os = LtsUtils::OperatorSettings::getInstance();
|
||||
LtsUtils::OperatorSettings* os = LtsUtils::OperatorSettings::getInstance();
|
||||
|
||||
const QByteArray settings = os->exportSettings();
|
||||
|
||||
|
||||
const auto vec(LtsUtils::convert<std::vector<uint8_t>>(settings));
|
||||
os->clear();
|
||||
opmFtc->operatorGetSetSettingsRequest(OperatorManagement::OperatorGetSetSettingsRequest(operatorId, vec));
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
catch (const std::runtime_error& err)
|
||||
{
|
||||
qCritical() << "Saving operator settings failed!" << err.what();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<SituationReplayManagement::ForeignDataInterface> srmIfc;
|
||||
if (datSession->getForeignDataInterface<SituationReplayManagement::DataInterface>(srmIfc))
|
||||
{
|
||||
@@ -248,7 +221,7 @@ void LtsLogin::logoff()
|
||||
{
|
||||
srmIfc->removeReplayPartitionsWorkstation(workstationId);
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
catch (const std::runtime_error& err)
|
||||
{
|
||||
qCritical() << "Removing reply partitions from this workstation failed!" << err.what();
|
||||
}
|
||||
@@ -257,23 +230,20 @@ void LtsLogin::logoff()
|
||||
{
|
||||
srmIfc->removeReplayPartitionsOperator(operatorId);
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
catch (const std::runtime_error& err)
|
||||
{
|
||||
qCritical() << "Removing reply partitions from this operator failed!" << err.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
opmFtc->operatorLogoutRequest(OperatorManagement::OperatorLogoutRequest(operatorId));
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
catch (const std::runtime_error& err)
|
||||
{
|
||||
qCritical() << "Logout failed!" << err.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
m_loginApp->deleteLater();
|
||||
@@ -309,4 +279,4 @@ void LtsLogin::logoff()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsLogin
|
||||
Executable → Regular
+18
-16
@@ -1,27 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#include <ltslogin_export.h>
|
||||
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
||||
#include <Plugins/OperatorManagement/opm_data_plugin_interface.h>
|
||||
#include <Plugins/SituationReplayManagement/srm_data_plugin_interface.h>
|
||||
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <ltslogin_export.h>
|
||||
|
||||
namespace LtsPluginManager
|
||||
{
|
||||
class LtsPluginManager;
|
||||
}
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
class RequestHelper;
|
||||
}
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
}
|
||||
|
||||
namespace DeveloperTools
|
||||
{
|
||||
class DevDialog;
|
||||
@@ -34,36 +33,39 @@ class LTSLOGIN_EXPORT LtsLogin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
LtsLogin();
|
||||
~LtsLogin();
|
||||
|
||||
void login();
|
||||
void logoff();
|
||||
void setLoginPlugin(const QString &loginPluginIid) { m_loginPluginIid = loginPluginIid; }
|
||||
|
||||
private:
|
||||
void setLoginPlugin(const QString& loginPluginIid)
|
||||
{
|
||||
m_loginPluginIid = loginPluginIid;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class DeveloperTools::DevDialog;
|
||||
|
||||
LtsSession::LtsSession *getAdminSession();
|
||||
LtsSession::LtsSession* getAdminSession();
|
||||
void showLogoutInformationDialog(AssetManagement::ShutdownAction action);
|
||||
|
||||
LtsPluginManager::LtsPluginManager *m_loginApp;
|
||||
LtsPluginManager::LtsPluginManager* m_loginApp;
|
||||
AssetManagement::ShutdownAction m_shutdownAction;
|
||||
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
||||
QString m_loginPluginIid;
|
||||
bool m_isInLogoutDialog;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void slotLoginDone();
|
||||
void slotLogoutShutdown(const AssetManagement::WorkstationLogout &data, DataModification modType);
|
||||
void slotLogoutShutdown(const AssetManagement::WorkstationLogout& data, DataModification modType);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void signalLogout();
|
||||
void signalStopBlock();
|
||||
void signalLoginDone();
|
||||
void signalLogoffDone();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsLogin
|
||||
Loaded 100 of 848 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user