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
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace AreaEffectSimulation
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace AreaEffectSimulation
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace AreaEffectSimulation
|
namespace AreaEffectSimulation
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace AreaEffectSimulation
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace AssetManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace AssetManagement
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace AssetManagement
|
namespace AssetManagement
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace AssetManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace AudioVideoManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace AudioVideoManagement
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace AudioVideoManagement
|
namespace AudioVideoManagement
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace AudioVideoManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace Buildings
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace Buildings
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace Buildings
|
namespace Buildings
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace Buildings
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace CentralEffectSimulation
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace CentralEffectSimulation
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace CodificationManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace CodificationManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace ComponentMonitor
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace ComponentMonitor
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace Core
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace Core
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace Core
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace Core
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace Core
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace Core
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace DDS
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace DDS
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace EffectShowClient
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace EffectShowClient
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace EffectShowManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace EffectShowManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace Evaluations
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace Evaluations
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace ExerciseEventManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace ExerciseEventManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace ExerciseManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace ExerciseManagement
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace ExerciseManagement
|
namespace ExerciseManagement
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace ExerciseManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace FileManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace FileManagement
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace FileManagement
|
namespace FileManagement
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace FileManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace GuezIedManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace GuezIedManagement
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace GuezNasat
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace GuezNasat
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Forward-Declarations
|
// Für die Migration erstellen wir minimale Forward-Declarations
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ namespace InfrastructureManagement
|
|||||||
{
|
{
|
||||||
namespace Interface
|
namespace Interface
|
||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
class Ftc;
|
class Ftc;
|
||||||
}
|
} // namespace Interface
|
||||||
}
|
} // namespace InfrastructureManagement
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
// STUB-HEADER: Diese Datei wird normalerweise von ddsdtc generiert
|
||||||
// Für die Migration erstellen wir minimale Typ-Definitionen
|
// Für die Migration erstellen wir minimale Typ-Definitionen
|
||||||
|
|
||||||
namespace InfrastructureManagement
|
namespace InfrastructureManagement
|
||||||
{
|
{
|
||||||
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
// Placeholder enums - werden durch echte DDS-Typen ersetzt
|
||||||
enum class SymbolAppearance : int {
|
enum class SymbolAppearance : int { Solid = 0, Dashed = 1, Dotted = 2 };
|
||||||
Solid = 0,
|
|
||||||
Dashed = 1,
|
|
||||||
Dotted = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SymbolVisibility : int {
|
enum class SymbolVisibility : int { Visible = 0, Hidden = 1 };
|
||||||
Visible = 0,
|
|
||||||
Hidden = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UnitSymbolPosition {
|
struct UnitSymbolPosition
|
||||||
|
{
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace InfrastructureManagement
|
||||||
Executable → Regular
+54
-77
@@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "CppTopicGeneratorGrantlee.h"
|
#include "CppTopicGeneratorGrantlee.h"
|
||||||
|
|
||||||
#include "StructBuilder.h"
|
#include "StructBuilder.h"
|
||||||
#include <QCryptographicHash>
|
|
||||||
#include <NGLLogger/INGLLogger.h>
|
#include <NGLLogger/INGLLogger.h>
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <grantlee/context.h>
|
#include <grantlee/context.h>
|
||||||
|
|
||||||
#ifdef RTI_HEADER_AVAILABLE
|
#ifdef RTI_HEADER_AVAILABLE
|
||||||
@@ -13,11 +14,9 @@
|
|||||||
|
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
CppTopicGeneratorGrantlee::CppTopicGeneratorGrantlee()
|
CppTopicGeneratorGrantlee::CppTopicGeneratorGrantlee() : GeneratorGrantleeBase("CodeGen.CppTopicGeneratorGrantlee") {}
|
||||||
: GeneratorGrantleeBase("CodeGen.CppTopicGeneratorGrantlee")
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::init(const XmlReader *reader, StructBuilder *structBuilder)
|
bool CppTopicGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
|
||||||
{
|
{
|
||||||
m_reader = reader;
|
m_reader = reader;
|
||||||
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
||||||
@@ -28,15 +27,13 @@ bool CppTopicGeneratorGrantlee::init(const XmlReader *reader, StructBuilder *str
|
|||||||
return initDataTopics() && initFunctionTopics() && initIdlStructs();
|
return initDataTopics() && initFunctionTopics() && initIdlStructs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::initDataTopics()
|
bool CppTopicGeneratorGrantlee::initDataTopics()
|
||||||
{
|
{
|
||||||
DataTopicsWrapper *dataTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
DataTopicsWrapper* dataTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
||||||
const auto dataTopics = m_reader->getIdlStructInformation();
|
const auto dataTopics = m_reader->getIdlStructInformation();
|
||||||
QVector<IdlData> keyColumns;
|
QVector<IdlData> keyColumns;
|
||||||
QVector<IdlData> trColumns;
|
QVector<IdlData> trColumns;
|
||||||
for (const CodeGen::TopicTypeInformation &tti : dataTopics)
|
for (const CodeGen::TopicTypeInformation& tti : dataTopics)
|
||||||
{
|
{
|
||||||
if (!tti.isDataObject)
|
if (!tti.isDataObject)
|
||||||
continue;
|
continue;
|
||||||
@@ -49,7 +46,7 @@ bool CppTopicGeneratorGrantlee::initDataTopics()
|
|||||||
ERROR_LOG(m_logger) << "could not find informations for struct " << tti.name;
|
ERROR_LOG(m_logger) << "could not find informations for struct " << tti.name;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DataTopicWrapper *dtw = dataTopicsWrapper->addDataTopic(ctti);
|
DataTopicWrapper* dtw = dataTopicsWrapper->addDataTopic(ctti);
|
||||||
getSpecialColumns(ctti, keyColumns, trColumns);
|
getSpecialColumns(ctti, keyColumns, trColumns);
|
||||||
if (keyColumns.size() == 1)
|
if (keyColumns.size() == 1)
|
||||||
dtw->setKeyColumnData(keyColumns.first());
|
dtw->setKeyColumnData(keyColumns.first());
|
||||||
@@ -69,9 +66,9 @@ bool CppTopicGeneratorGrantlee::initDataTopics()
|
|||||||
m_ctx->insert(QStringLiteral("dataTopics"), dataTopicsWrapper);
|
m_ctx->insert(QStringLiteral("dataTopics"), dataTopicsWrapper);
|
||||||
|
|
||||||
QSet<QString> exportedSubTopics;
|
QSet<QString> exportedSubTopics;
|
||||||
DataTopicsWrapper *subTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
DataTopicsWrapper* subTopicsWrapper = new DataTopicsWrapper(QString(), this);
|
||||||
const QVector<QSharedPointer<DataTypeInfo>> serializeTopics = m_structBuilder->getSerializeFromToJsonTopics();
|
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()))
|
if (exportedSubTopics.contains(dti->idlType()))
|
||||||
continue;
|
continue;
|
||||||
@@ -90,29 +87,27 @@ bool CppTopicGeneratorGrantlee::initDataTopics()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DEBUG_LOG(m_logger) << "Adding substruct topic " << ctti.name;
|
DEBUG_LOG(m_logger) << "Adding substruct topic " << ctti.name;
|
||||||
DataTopicWrapper *dtw = subTopicsWrapper->addDataTopic(ctti);
|
DataTopicWrapper* dtw = subTopicsWrapper->addDataTopic(ctti);
|
||||||
dtw->setRecordTableInformation(cti);
|
dtw->setRecordTableInformation(cti);
|
||||||
exportedSubTopics += dti->idlType();
|
exportedSubTopics += dti->idlType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_ctx->insert(QStringLiteral("serializeTopics"), subTopicsWrapper);
|
m_ctx->insert(QStringLiteral("serializeTopics"), subTopicsWrapper);
|
||||||
|
|
||||||
QVector<MemberInformationListWrapper *> jsonTopics;
|
QVector<MemberInformationListWrapper*> jsonTopics;
|
||||||
const QMap<QString, QVector<MemberInformation>> jsonExport = m_structBuilder->jsonStructureInformation();
|
const QMap<QString, QVector<MemberInformation>> jsonExport = m_structBuilder->jsonStructureInformation();
|
||||||
for (auto it = jsonExport.begin(); it != jsonExport.end(); ++it)
|
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;
|
jsonTopics += mil;
|
||||||
|
|
||||||
}
|
}
|
||||||
m_ctx->insert(QStringLiteral("jsonTopics"), QVariant::fromValue(jsonTopics));
|
m_ctx->insert(QStringLiteral("jsonTopics"), QVariant::fromValue(jsonTopics));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInformation &tti,
|
bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInformation& tti, QVector<IdlData>& keyColumns,
|
||||||
QVector<IdlData> &keyColumns,
|
QVector<IdlData>& trColumns) const
|
||||||
QVector<IdlData> &trColumns) const
|
|
||||||
{
|
{
|
||||||
DEBUG_LOG(m_logger) << "Get special columns for " << tti.name << " - base is " << tti.baseValueType;
|
DEBUG_LOG(m_logger) << "Get special columns for " << tti.name << " - base is " << tti.baseValueType;
|
||||||
if (!tti.isValid())
|
if (!tti.isValid())
|
||||||
@@ -120,7 +115,7 @@ bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInforma
|
|||||||
ERROR_LOG(m_logger) << "tti is not valid ...";
|
ERROR_LOG(m_logger) << "tti is not valid ...";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (const IdlData &ci : tti.members)
|
for (const IdlData& ci : tti.members)
|
||||||
{
|
{
|
||||||
if (ci.isKey)
|
if (ci.isKey)
|
||||||
keyColumns += ci;
|
keyColumns += ci;
|
||||||
@@ -132,14 +127,12 @@ bool CppTopicGeneratorGrantlee::getSpecialColumns(const CompleteTopicTypeInforma
|
|||||||
return getSpecialColumns(topicTypeInformationByDerivedTopic(tti), keyColumns, trColumns);
|
return getSpecialColumns(topicTypeInformationByDerivedTopic(tti), keyColumns, trColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::initFunctionTopics()
|
bool CppTopicGeneratorGrantlee::initFunctionTopics()
|
||||||
{
|
{
|
||||||
|
|
||||||
const QVector<FunctionTopic> functionTopics = m_reader->getFunctionTopics();
|
const QVector<FunctionTopic> functionTopics = m_reader->getFunctionTopics();
|
||||||
FunctionTopicsWrapper *functionTopicsWrapper(new FunctionTopicsWrapper(QStringLiteral("functionTopics"), this));
|
FunctionTopicsWrapper* functionTopicsWrapper(new FunctionTopicsWrapper(QStringLiteral("functionTopics"), this));
|
||||||
for (const FunctionTopic &ft : functionTopics)
|
for (const FunctionTopic& ft : functionTopics)
|
||||||
{
|
{
|
||||||
if (!handleStruct(ft, functionTopicsWrapper))
|
if (!handleStruct(ft, functionTopicsWrapper))
|
||||||
return false;
|
return false;
|
||||||
@@ -149,44 +142,43 @@ bool CppTopicGeneratorGrantlee::initFunctionTopics()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::handleStruct(const FunctionTopic &ft,
|
bool CppTopicGeneratorGrantlee::handleStruct(const FunctionTopic& ft, FunctionTopicsWrapper* functionTopicsWrapper)
|
||||||
FunctionTopicsWrapper *functionTopicsWrapper)
|
|
||||||
{
|
{
|
||||||
DEBUG_LOG(m_logger) << "handling FunctionTopic: " << ft.name;
|
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())
|
if (!siRequest.isValid())
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Could not get topic informations about request topic "
|
WARNING_LOG(m_logger) << "Could not get topic informations about request topic " << ft.requestTopicName;
|
||||||
<< ft.requestTopicName;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CompleteTopicTypeInformation siReply = m_structBuilder->topicTypeInformationByStructType(ft.replyTopicType);
|
const CompleteTopicTypeInformation siReply = m_structBuilder->topicTypeInformationByStructType(ft.replyTopicType);
|
||||||
if (!siReply.isValid())
|
if (!siReply.isValid())
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Could not get topic informations about reply topic "
|
WARNING_LOG(m_logger) << "Could not get topic informations about reply topic " << ft.replyTopicType;
|
||||||
<< ft.replyTopicType;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionTopicWrapper *ftw = functionTopicsWrapper->addFunctionTopic(ft, siRequest, siReply);
|
FunctionTopicWrapper* ftw = functionTopicsWrapper->addFunctionTopic(ft, siRequest, siReply);
|
||||||
const QByteArray hash = QCryptographicHash::hash(ft.requestTopicName.toUtf8(), QCryptographicHash::Sha3_512).toHex().left(16);
|
const QByteArray hash =
|
||||||
|
QCryptographicHash::hash(ft.requestTopicName.toUtf8(), QCryptographicHash::Sha3_512).toHex().left(16);
|
||||||
ftw->setReplyHandlerHash(QStringLiteral("0x") + QString::fromLatin1(hash) + QStringLiteral("LL"));
|
ftw->setReplyHandlerHash(QStringLiteral("0x") + QString::fromLatin1(hash) + QStringLiteral("LL"));
|
||||||
if (!addRequesterRequestParams(ft.name, siRequest, ftw) ||
|
if (!addRequesterRequestParams(ft.name, siRequest, ftw) || !addRequesterReplyParams(ft.name, siReply, ftw))
|
||||||
!addRequesterReplyParams(ft.name, siReply, ftw))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::addRequesterRequestParams(const QString &request_name,
|
bool CppTopicGeneratorGrantlee::addRequesterRequestParams(const QString& request_name,
|
||||||
const CompleteTopicTypeInformation &request,
|
const CompleteTopicTypeInformation& request,
|
||||||
FunctionTopicWrapper *ftw)
|
FunctionTopicWrapper* ftw)
|
||||||
{
|
{
|
||||||
if (request.hasBaseValue())
|
if (request.hasBaseValue())
|
||||||
{
|
{
|
||||||
const CompleteTopicTypeInformation siBase = m_structBuilder->topicTypeInformationByStructType(request.baseValueType);
|
const CompleteTopicTypeInformation siBase =
|
||||||
|
m_structBuilder->topicTypeInformationByStructType(request.baseValueType);
|
||||||
if (!siBase.isValid())
|
if (!siBase.isValid())
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Could not get topic informations about base request topic "
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppTopicGeneratorGrantlee::addRequesterReplyParams(const QString &request_name,
|
bool CppTopicGeneratorGrantlee::addRequesterReplyParams(const QString& request_name,
|
||||||
const CompleteTopicTypeInformation &reply,
|
const CompleteTopicTypeInformation& reply,
|
||||||
FunctionTopicWrapper *ftw)
|
FunctionTopicWrapper* ftw)
|
||||||
{
|
{
|
||||||
if (reply.hasBaseValue())
|
if (reply.hasBaseValue())
|
||||||
{
|
{
|
||||||
const CompleteTopicTypeInformation siBase = m_structBuilder->topicTypeInformationByStructType(reply.baseValueType);
|
const CompleteTopicTypeInformation siBase =
|
||||||
|
m_structBuilder->topicTypeInformationByStructType(reply.baseValueType);
|
||||||
if (!siBase.isValid())
|
if (!siBase.isValid())
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Could not get topic informations about base reply topic "
|
WARNING_LOG(m_logger) << "Could not get topic informations about base reply topic " << reply.baseValueType;
|
||||||
<< reply.baseValueType;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,11 +216,8 @@ bool CppTopicGeneratorGrantlee::addRequesterReplyParams(const QString &request_n
|
|||||||
return true;
|
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())
|
if (!csi.isValid())
|
||||||
return true;
|
return true;
|
||||||
@@ -236,12 +225,10 @@ bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformati
|
|||||||
if (idlStructNames.contains(csi.name))
|
if (idlStructNames.contains(csi.name))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (csi.hasBaseValue())
|
if (csi.hasBaseValue())
|
||||||
{
|
{
|
||||||
const CompleteTopicTypeInformation ctti = m_structBuilder->topicTypeInformationByStructType(csi.baseValueType, false);
|
const CompleteTopicTypeInformation ctti =
|
||||||
|
m_structBuilder->topicTypeInformationByStructType(csi.baseValueType, false);
|
||||||
if (ctti.isValid())
|
if (ctti.isValid())
|
||||||
{
|
{
|
||||||
#ifdef RTI_HEADER_AVAILABLE
|
#ifdef RTI_HEADER_AVAILABLE
|
||||||
@@ -266,20 +253,17 @@ bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformati
|
|||||||
const int idx = csi.baseValueType.indexOf(QLatin1String("::"));
|
const int idx = csi.baseValueType.indexOf(QLatin1String("::"));
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "idlStruct '" << csi.baseValueType
|
ERROR_LOG(m_logger) << "idlStruct '" << csi.baseValueType << "' not found in idl-file";
|
||||||
<< "' not found in idl-file";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const IdlData& idlData : csi.members)
|
||||||
for (const IdlData &idlData : csi.members)
|
|
||||||
{
|
{
|
||||||
QString idlType;
|
QString idlType;
|
||||||
DEBUG_LOG(m_logger) << "member: " << idlData.type << " - " << idlData.name
|
DEBUG_LOG(m_logger) << "member: " << idlData.type << " - " << idlData.name << " "
|
||||||
<< " " << idlData.dataTypeInfo->isStructure()
|
<< idlData.dataTypeInfo->isStructure() << " " << idlData.dataTypeInfo->isSequence();
|
||||||
<< " " << idlData.dataTypeInfo->isSequence();
|
|
||||||
if (idlData.dataTypeInfo->isStructure())
|
if (idlData.dataTypeInfo->isStructure())
|
||||||
idlType = idlData.dataTypeInfo->idlType();
|
idlType = idlData.dataTypeInfo->idlType();
|
||||||
else if (idlData.dataTypeInfo->isSequence())
|
else if (idlData.dataTypeInfo->isSequence())
|
||||||
@@ -289,18 +273,14 @@ bool CppTopicGeneratorGrantlee::handleIdlStruct(const CompleteTopicTypeInformati
|
|||||||
}
|
}
|
||||||
if (idlType.isEmpty())
|
if (idlType.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (!handleIdlStruct(m_structBuilder->topicTypeInformationByStructType(idlType,
|
if (!handleIdlStruct(m_structBuilder->topicTypeInformationByStructType(idlType, false), idlStructNames,
|
||||||
false),
|
|
||||||
idlStructNames,
|
|
||||||
idlStructs))
|
idlStructs))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DEBUG_LOG(m_logger) << "Current structName: " << csi.name;
|
DEBUG_LOG(m_logger) << "Current structName: " << csi.name;
|
||||||
idlStructs += new IdlStructWrapper(csi, this);
|
idlStructs += new IdlStructWrapper(csi, this);
|
||||||
|
|
||||||
|
|
||||||
idlStructNames.insert(csi.name);
|
idlStructNames.insert(csi.name);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -312,9 +292,9 @@ bool CppTopicGeneratorGrantlee::initIdlStructs()
|
|||||||
const QVector<CompleteTopicTypeInformation> csiData = m_structBuilder->topicTypeInformations();
|
const QVector<CompleteTopicTypeInformation> csiData = m_structBuilder->topicTypeInformations();
|
||||||
|
|
||||||
QSet<QString> idlStructNames;
|
QSet<QString> idlStructNames;
|
||||||
QVector<IdlStructWrapper *> idlStructs;
|
QVector<IdlStructWrapper*> idlStructs;
|
||||||
idlStructs.reserve(csiData.size());
|
idlStructs.reserve(csiData.size());
|
||||||
for (const CompleteTopicTypeInformation &csi : csiData)
|
for (const CompleteTopicTypeInformation& csi : csiData)
|
||||||
{
|
{
|
||||||
if (!handleIdlStruct(csi, idlStructNames, idlStructs))
|
if (!handleIdlStruct(csi, idlStructNames, idlStructs))
|
||||||
return false;
|
return false;
|
||||||
@@ -323,27 +303,24 @@ bool CppTopicGeneratorGrantlee::initIdlStructs()
|
|||||||
m_ctx->insert(QStringLiteral("idl_structs"), QVariant::fromValue(idlStructs));
|
m_ctx->insert(QStringLiteral("idl_structs"), QVariant::fromValue(idlStructs));
|
||||||
|
|
||||||
const QVector<EnumInformation> enumerations = m_structBuilder->enumInformations();
|
const QVector<EnumInformation> enumerations = m_structBuilder->enumInformations();
|
||||||
QVector<IdlEnumWrapper *> idlEnumerations;
|
QVector<IdlEnumWrapper*> idlEnumerations;
|
||||||
idlEnumerations.reserve(enumerations.size());
|
idlEnumerations.reserve(enumerations.size());
|
||||||
for (const EnumInformation &ei : enumerations)
|
for (const EnumInformation& ei : enumerations)
|
||||||
idlEnumerations += new IdlEnumWrapper(ei, this);
|
idlEnumerations += new IdlEnumWrapper(ei, this);
|
||||||
m_ctx->insert(QStringLiteral("idl_enums"), QVariant::fromValue(idlEnumerations));
|
m_ctx->insert(QStringLiteral("idl_enums"), QVariant::fromValue(idlEnumerations));
|
||||||
|
|
||||||
|
|
||||||
exportUsedServices(m_reader);
|
exportUsedServices(m_reader);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompleteTopicTypeInformation
|
||||||
CompleteTopicTypeInformation CppTopicGeneratorGrantlee::topicTypeInformationByDerivedTopic(const CompleteTopicTypeInformation &tti) const
|
CppTopicGeneratorGrantlee::topicTypeInformationByDerivedTopic(const CompleteTopicTypeInformation& tti) const
|
||||||
{
|
{
|
||||||
if (tti.baseValueType.isEmpty())
|
if (tti.baseValueType.isEmpty())
|
||||||
return CompleteTopicTypeInformation();
|
return CompleteTopicTypeInformation();
|
||||||
QString baseValueType = tti.baseValueType;
|
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("::"));
|
const QStringList sl = tti.name.split(QStringLiteral("::"));
|
||||||
baseValueType = sl.at(0) + QLatin1String("::") + tti.baseValueType;
|
baseValueType = sl.at(0) + QLatin1String("::") + tti.baseValueType;
|
||||||
|
|||||||
Executable → Regular
+18
-24
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "GeneratorGrantleeBase.h"
|
#include "GeneratorGrantleeBase.h"
|
||||||
#include "StructBuilder.h"
|
|
||||||
#include "GrantleeWrappers.h"
|
#include "GrantleeWrappers.h"
|
||||||
|
#include "StructBuilder.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace CodeGen
|
namespace CodeGen
|
||||||
{
|
{
|
||||||
@@ -13,35 +13,29 @@ namespace CodeGen
|
|||||||
class CppTopicGeneratorGrantlee final : public GeneratorGrantleeBase
|
class CppTopicGeneratorGrantlee final : public GeneratorGrantleeBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CppTopicGeneratorGrantlee();
|
explicit CppTopicGeneratorGrantlee();
|
||||||
|
|
||||||
bool init(const XmlReader *reader, StructBuilder *structBuilder) override;
|
bool init(const XmlReader* reader, StructBuilder* structBuilder) override;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
bool initDataTopics();
|
bool initDataTopics();
|
||||||
bool getSpecialColumns(const CompleteTopicTypeInformation &tti,
|
bool getSpecialColumns(const CompleteTopicTypeInformation& tti, QVector<IdlData>& keyColumns,
|
||||||
QVector<IdlData> &keyColumns,
|
QVector<IdlData>& trColumns) const;
|
||||||
QVector<IdlData> &trColumns) const;
|
|
||||||
|
|
||||||
bool initFunctionTopics();
|
bool initFunctionTopics();
|
||||||
bool handleStruct(const FunctionTopic &ft,
|
bool handleStruct(const FunctionTopic& ft, FunctionTopicsWrapper* functionTopicsWrapper);
|
||||||
FunctionTopicsWrapper *functionTopicsWrapper);
|
bool addRequesterRequestParams(const QString& request_name, const CompleteTopicTypeInformation& request,
|
||||||
bool addRequesterRequestParams(const QString &request_name,
|
FunctionTopicWrapper* ftw);
|
||||||
const CompleteTopicTypeInformation &request,
|
bool addRequesterReplyParams(const QString& request_name, const CompleteTopicTypeInformation& reply,
|
||||||
FunctionTopicWrapper *ftw);
|
FunctionTopicWrapper* ftw);
|
||||||
bool addRequesterReplyParams(const QString &request_name,
|
|
||||||
const CompleteTopicTypeInformation &reply,
|
|
||||||
FunctionTopicWrapper *ftw);
|
|
||||||
|
|
||||||
bool handleIdlStruct(const CompleteTopicTypeInformation &csi,
|
bool handleIdlStruct(const CompleteTopicTypeInformation& csi, QSet<QString>& idlStructNames,
|
||||||
QSet<QString> &idlStructNames,
|
QVector<IdlStructWrapper*>& idlStructs);
|
||||||
QVector<IdlStructWrapper *> &idlStructs);
|
|
||||||
bool initIdlStructs();
|
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 "DaoGeneratorGrantlee.h"
|
||||||
|
|
||||||
#include "StructBuilder.h"
|
#include "StructBuilder.h"
|
||||||
|
|
||||||
#include <NGLLogger/INGLLogger.h>
|
#include <NGLLogger/INGLLogger.h>
|
||||||
#include <grantlee/context.h>
|
#include <grantlee/context.h>
|
||||||
|
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
DaoGeneratorGrantlee::DaoGeneratorGrantlee()
|
DaoGeneratorGrantlee::DaoGeneratorGrantlee() : GeneratorGrantleeBase("CodeGen.DaoGeneratorGrantlee") {}
|
||||||
: GeneratorGrantleeBase("CodeGen.DaoGeneratorGrantlee")
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool DaoGeneratorGrantlee::init(const XmlReader *reader,
|
bool DaoGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
|
||||||
StructBuilder *structBuilder)
|
|
||||||
{
|
{
|
||||||
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (reader->isServiceExerciseIndependent())
|
if (reader->isServiceExerciseIndependent())
|
||||||
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
|
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
|
||||||
|
|
||||||
bool bHasDbNotifications = false;
|
bool bHasDbNotifications = false;
|
||||||
QVector<DbStructWrapper *> vlServiceStructs;
|
QVector<DbStructWrapper*> vlServiceStructs;
|
||||||
QVector<DbStructWrapper *> vlStaticDataStructs;
|
QVector<DbStructWrapper*> vlStaticDataStructs;
|
||||||
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
|
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
|
||||||
vlServiceStructs.reserve(csiData.size());
|
vlServiceStructs.reserve(csiData.size());
|
||||||
vlStaticDataStructs.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)
|
if (csi.hasStaticContent)
|
||||||
vlStaticDataStructs += dbStructWrapper;
|
vlStaticDataStructs += dbStructWrapper;
|
||||||
|
|||||||
Executable → Regular
+6
-7
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "GeneratorGrantleeBase.h"
|
#include "GeneratorGrantleeBase.h"
|
||||||
#include "StructBuilder.h"
|
|
||||||
#include "GrantleeWrappers.h"
|
#include "GrantleeWrappers.h"
|
||||||
|
#include "StructBuilder.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace CodeGen
|
namespace CodeGen
|
||||||
{
|
{
|
||||||
@@ -13,13 +13,12 @@ struct CompleteStructInformation;
|
|||||||
class StructBuilder;
|
class StructBuilder;
|
||||||
class XmlReader;
|
class XmlReader;
|
||||||
|
|
||||||
|
|
||||||
class DaoGeneratorGrantlee final : public GeneratorGrantleeBase
|
class DaoGeneratorGrantlee final : public GeneratorGrantleeBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DaoGeneratorGrantlee();
|
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 "DatabaseGeneratorGrantlee.h"
|
||||||
|
|
||||||
#include "StructBuilder.h"
|
#include "StructBuilder.h"
|
||||||
|
|
||||||
#include <NGLLogger/INGLLogger.h>
|
#include <NGLLogger/INGLLogger.h>
|
||||||
#include <grantlee/context.h>
|
#include <grantlee/context.h>
|
||||||
|
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
DatabaseGeneratorGrantlee::DatabaseGeneratorGrantlee(bool targetIsServer)
|
DatabaseGeneratorGrantlee::DatabaseGeneratorGrantlee(bool targetIsServer)
|
||||||
: GeneratorGrantleeBase("CodeGen.CppStructGeneratorGrantlee")
|
: GeneratorGrantleeBase("CodeGen.CppStructGeneratorGrantlee"), m_targetIsServer(targetIsServer)
|
||||||
, m_targetIsServer(targetIsServer)
|
{
|
||||||
{}
|
}
|
||||||
|
|
||||||
bool DatabaseGeneratorGrantlee::init(const XmlReader *reader,
|
bool DatabaseGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
|
||||||
StructBuilder *structBuilder)
|
|
||||||
{
|
{
|
||||||
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (reader->isServiceExerciseIndependent())
|
if (reader->isServiceExerciseIndependent())
|
||||||
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
|
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
|
||||||
|
|
||||||
bool bHasDbNotifications = false;
|
bool bHasDbNotifications = false;
|
||||||
QVector<DbStructWrapper *> vlServiceStructs;
|
QVector<DbStructWrapper*> vlServiceStructs;
|
||||||
QVector<DbStructWrapper *> vlStaticDataStructs;
|
QVector<DbStructWrapper*> vlStaticDataStructs;
|
||||||
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
|
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
|
||||||
vlServiceStructs.reserve(csiData.size());
|
vlServiceStructs.reserve(csiData.size());
|
||||||
vlStaticDataStructs.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)
|
if (csi.hasStaticContent)
|
||||||
vlStaticDataStructs += dbStructWrapper;
|
vlStaticDataStructs += dbStructWrapper;
|
||||||
@@ -51,7 +50,8 @@ bool DatabaseGeneratorGrantlee::init(const XmlReader *reader,
|
|||||||
if (bHasDbNotifications)
|
if (bHasDbNotifications)
|
||||||
m_ctx->insert(QStringLiteral("has_db_notifications"), QLatin1String("1"));
|
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);
|
exportUsedServices(reader);
|
||||||
|
|
||||||
|
|||||||
Executable → Regular
+8
-8
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "GeneratorGrantleeBase.h"
|
#include "GeneratorGrantleeBase.h"
|
||||||
#include "StructBuilder.h"
|
|
||||||
#include "GrantleeWrappers.h"
|
#include "GrantleeWrappers.h"
|
||||||
|
#include "StructBuilder.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace CodeGen
|
namespace CodeGen
|
||||||
{
|
{
|
||||||
@@ -13,15 +13,15 @@ struct CompleteStructInformation;
|
|||||||
class StructBuilder;
|
class StructBuilder;
|
||||||
class XmlReader;
|
class XmlReader;
|
||||||
|
|
||||||
|
|
||||||
class DatabaseGeneratorGrantlee final : public GeneratorGrantleeBase
|
class DatabaseGeneratorGrantlee final : public GeneratorGrantleeBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DatabaseGeneratorGrantlee(bool targetIsServer);
|
explicit DatabaseGeneratorGrantlee(bool targetIsServer);
|
||||||
|
|
||||||
bool init(const XmlReader *reader, StructBuilder *structBuilder) override;
|
bool init(const XmlReader* reader, StructBuilder* structBuilder) override;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
bool m_targetIsServer;
|
bool m_targetIsServer;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CodeGen
|
||||||
Executable → Regular
+26
-28
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "GeneratorGrantleeBase.h"
|
#include "GeneratorGrantleeBase.h"
|
||||||
#include "XmlReader.h"
|
|
||||||
#include "GrantleeWrappers.h"
|
#include "GrantleeWrappers.h"
|
||||||
|
#include "XmlReader.h"
|
||||||
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
@@ -11,11 +12,13 @@
|
|||||||
#include <grantlee/engine.h>
|
#include <grantlee/engine.h>
|
||||||
|
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
GeneratorGrantleeBase::GeneratorGrantleeBase(const char *loggerName) : m_engine(new Grantlee::Engine)
|
GeneratorGrantleeBase::GeneratorGrantleeBase(const char *loggerName) : m_engine(new Grantlee::Engine)
|
||||||
, m_ctx(new Grantlee::Context)
|
, m_ctx(new Grantlee::Context)
|
||||||
, m_structBuilder(nullptr)
|
, m_structBuilder(nullptr)
|
||||||
.getNGLLogger(loggerName)),
|
.getNGLLogger(loggerName)),
|
||||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
|
m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratorGrantleeBase::~GeneratorGrantleeBase()
|
GeneratorGrantleeBase::~GeneratorGrantleeBase()
|
||||||
@@ -24,7 +27,7 @@ GeneratorGrantleeBase::~GeneratorGrantleeBase()
|
|||||||
delete m_ctx;
|
delete m_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorGrantleeBase::initInternal(const XmlReader *reader, StructBuilder *structBuilder)
|
bool GeneratorGrantleeBase::initInternal(const XmlReader* reader, StructBuilder* structBuilder)
|
||||||
{
|
{
|
||||||
m_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"), reader->getServiceAbbr().toLower());
|
||||||
m_ctx->insert(QStringLiteral("namespace_abbr_upper"), reader->getServiceAbbr().toUpper());
|
m_ctx->insert(QStringLiteral("namespace_abbr_upper"), reader->getServiceAbbr().toUpper());
|
||||||
if (reader->getServiceNamespace() == QLatin1String("Core"))
|
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
|
else
|
||||||
m_ctx->insert(QStringLiteral("include_prefix"), reader->getServiceNamespace());
|
m_ctx->insert(QStringLiteral("include_prefix"), reader->getServiceNamespace());
|
||||||
m_ctx->insert(QStringLiteral("custom_record_replay"), reader->hasCustomRecordReplayPlugin());
|
m_ctx->insert(QStringLiteral("custom_record_replay"), reader->hasCustomRecordReplayPlugin());
|
||||||
@@ -42,13 +46,12 @@ bool GeneratorGrantleeBase::initInternal(const XmlReader *reader, StructBuilder
|
|||||||
return true;
|
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"));
|
m_template = m_engine->newTemplate(tmpl, QStringLiteral("myTemplate"));
|
||||||
if (m_template->error())
|
if (m_template->error())
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Error parsing template '" << templateName
|
WARNING_LOG(m_logger) << "Error parsing template '" << templateName << "': " << m_template->errorString();
|
||||||
<< "': " << m_template->errorString();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -67,9 +70,7 @@ QString GeneratorGrantleeBase::errorString() const
|
|||||||
return m_template->errorString();
|
return m_template->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GeneratorGrantleeBase::generateData(const QString& templateName, const QString& outDirectory)
|
||||||
bool GeneratorGrantleeBase::generateData(const QString &templateName,
|
|
||||||
const QString &outDirectory)
|
|
||||||
{
|
{
|
||||||
QString content;
|
QString content;
|
||||||
if (!readFile(templateName, content))
|
if (!readFile(templateName, content))
|
||||||
@@ -83,12 +84,11 @@ bool GeneratorGrantleeBase::generateData(const QString &templateName,
|
|||||||
if (!getFilenameFromData(content, outFilename))
|
if (!getFilenameFromData(content, outFilename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
QFile f(outDirectory + QLatin1Char('/') + outFilename);
|
QFile f(outDirectory + QLatin1Char('/') + outFilename);
|
||||||
if (!f.open(QIODevice::WriteOnly))
|
if (!f.open(QIODevice::WriteOnly))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: "
|
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: " << f.errorString() << "("
|
||||||
<< f.errorString() << "(" << f.error() << ")";
|
<< f.error() << ")";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const QByteArray outData = content.toUtf8();
|
const QByteArray outData = content.toUtf8();
|
||||||
@@ -99,13 +99,12 @@ bool GeneratorGrantleeBase::generateData(const QString &templateName,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorGrantleeBase::readFile(const QString &filename, QString &data) const
|
bool GeneratorGrantleeBase::readFile(const QString& filename, QString& data) const
|
||||||
{
|
{
|
||||||
QFile f(filename);
|
QFile f(filename);
|
||||||
if (!f.open(QIODevice::ReadOnly))
|
if (!f.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Error opening file " << filename
|
ERROR_LOG(m_logger) << "Error opening file " << filename << " - error: " << f.errorString();
|
||||||
<< " - error: " << f.errorString();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
data = QString::fromUtf8(f.readAll());
|
data = QString::fromUtf8(f.readAll());
|
||||||
@@ -113,15 +112,14 @@ bool GeneratorGrantleeBase::readFile(const QString &filename, QString &data) con
|
|||||||
return true;
|
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:"));
|
const QString filenameMarker(QStringLiteral("// filename:"));
|
||||||
int idx = dataToParse.indexOf(filenameMarker);
|
int idx = dataToParse.indexOf(filenameMarker);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Could not find marker '" << filenameMarker
|
ERROR_LOG(m_logger) << "Could not find marker '" << filenameMarker << "' in data!";
|
||||||
<< "' in data!";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
idx += filenameMarker.length() + 1;
|
idx += filenameMarker.length() + 1;
|
||||||
@@ -136,19 +134,19 @@ bool GeneratorGrantleeBase::getFilenameFromData(const QString &dataToParse, QStr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneratorGrantleeBase::addCustomFunctions(const QVector<CustomServiceFunctionInformation> &customFunctions)
|
void GeneratorGrantleeBase::addCustomFunctions(const QVector<CustomServiceFunctionInformation>& customFunctions)
|
||||||
{
|
{
|
||||||
|
|
||||||
QVariantList vlCustomDbFunctions;
|
QVariantList vlCustomDbFunctions;
|
||||||
QVariantList vlCustomDtcFunctions;
|
QVariantList vlCustomDtcFunctions;
|
||||||
vlCustomDbFunctions.reserve(customFunctions.size());
|
vlCustomDbFunctions.reserve(customFunctions.size());
|
||||||
vlCustomDtcFunctions.reserve(customFunctions.size());
|
vlCustomDtcFunctions.reserve(customFunctions.size());
|
||||||
for (const CustomServiceFunctionInformation &csfi : customFunctions)
|
for (const CustomServiceFunctionInformation& csfi : customFunctions)
|
||||||
{
|
{
|
||||||
const QString signature(csfi.returnValue + QLatin1Char(' ') +
|
const QString signature(csfi.returnValue + QLatin1Char(' ') + csfi.methodName + QLatin1Char('(') +
|
||||||
csfi.methodName + QLatin1Char('(') + csfi.signature + QLatin1Char(')') +
|
csfi.signature + QLatin1Char(')') +
|
||||||
(csfi.isConst ? QStringLiteral(" const") : QString()));
|
(csfi.isConst ? QStringLiteral(" const") : QString()));
|
||||||
CustomFunctionWrapper *customFunctionWrapper(new CustomFunctionWrapper(signature, this));
|
CustomFunctionWrapper* customFunctionWrapper(new CustomFunctionWrapper(signature, this));
|
||||||
switch (csfi.type)
|
switch (csfi.type)
|
||||||
{
|
{
|
||||||
case CustomServiceFunctionInformation::Type::Db:
|
case CustomServiceFunctionInformation::Type::Db:
|
||||||
@@ -170,16 +168,16 @@ void GeneratorGrantleeBase::addCustomFunctions(const QVector<CustomServiceFuncti
|
|||||||
m_ctx->insert(QStringLiteral("custom_db_procs"), vlCustomDbFunctions);
|
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();
|
const QMap<QString, bool> usedServices = reader->usedServices();
|
||||||
for (auto it = usedServices.begin(); it != usedServices.end(); ++it)
|
for (auto it = usedServices.begin(); it != usedServices.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!it.value())
|
if (!it.value())
|
||||||
continue;
|
continue;
|
||||||
const QString &svc = it.key();
|
const QString& svc = it.key();
|
||||||
const QString fullPath = reader->idlFileForService(svc);
|
const QString fullPath = reader->idlFileForService(svc);
|
||||||
const int idx = fullPath.lastIndexOf(QLatin1Char('.'));
|
const int idx = fullPath.lastIndexOf(QLatin1Char('.'));
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
|
|||||||
Executable → Regular
+22
-20
@@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "XmlReader.h"
|
#include "XmlReader.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
@@ -17,7 +18,8 @@ class Context;
|
|||||||
class Engine;
|
class Engine;
|
||||||
class TemplateImpl;
|
class TemplateImpl;
|
||||||
using Template = QSharedPointer<TemplateImpl>;
|
using Template = QSharedPointer<TemplateImpl>;
|
||||||
}
|
} // namespace Grantlee
|
||||||
|
|
||||||
namespace CodeGen
|
namespace CodeGen
|
||||||
{
|
{
|
||||||
class StructBuilder;
|
class StructBuilder;
|
||||||
@@ -25,29 +27,29 @@ class StructBuilder;
|
|||||||
class GeneratorGrantleeBase : public QObject
|
class GeneratorGrantleeBase : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
virtual ~GeneratorGrantleeBase();
|
virtual ~GeneratorGrantleeBase();
|
||||||
virtual bool init(const XmlReader *reader, StructBuilder *structBuilder) = 0;
|
virtual bool init(const XmlReader* reader, StructBuilder* structBuilder) = 0;
|
||||||
bool setTemplate(const QString &templateName, const QString &tmpl);
|
bool setTemplate(const QString& templateName, const QString& tmpl);
|
||||||
QString render() const;
|
QString render() const;
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
bool generateData(const QString &templateName,
|
bool generateData(const QString& templateName, const QString& outDirectory);
|
||||||
const QString &outDirectory);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NGL::INGLLogger &m_logger;
|
NGL::INGLLogger& m_logger;
|
||||||
explicit GeneratorGrantleeBase(const char *loggerName);
|
explicit GeneratorGrantleeBase(const char* loggerName);
|
||||||
|
|
||||||
bool initInternal(const XmlReader *reader, StructBuilder *structBuilder);
|
bool initInternal(const XmlReader* reader, StructBuilder* structBuilder);
|
||||||
bool readFile(const QString &filename, QString &data) const;
|
bool readFile(const QString& filename, QString& data) const;
|
||||||
bool getFilenameFromData(const QString &dataToParse, QString &filename) const;
|
bool getFilenameFromData(const QString& dataToParse, QString& filename) const;
|
||||||
void addCustomFunctions(const QVector<CustomServiceFunctionInformation> &customFunctions);
|
void addCustomFunctions(const QVector<CustomServiceFunctionInformation>& customFunctions);
|
||||||
void exportUsedServices(const XmlReader *reader);
|
void exportUsedServices(const XmlReader* reader);
|
||||||
protected:
|
|
||||||
NGL::INGLLogger &m_logger;
|
protected:
|
||||||
Grantlee::Engine *m_engine;
|
NGL::INGLLogger& m_logger;
|
||||||
Grantlee::Context *m_ctx;
|
Grantlee::Engine* m_engine;
|
||||||
|
Grantlee::Context* m_ctx;
|
||||||
Grantlee::Template m_template;
|
Grantlee::Template m_template;
|
||||||
StructBuilder *m_structBuilder;
|
StructBuilder* m_structBuilder;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CodeGen
|
||||||
Executable → Regular
+47
-94
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "GrantleeWrappers.h"
|
#include "GrantleeWrappers.h"
|
||||||
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ QString IdlStructWrapper::extensibility2String(int /*extensiblity*/)
|
|||||||
|
|
||||||
QString DataTopicWrapper::typeFq() const
|
QString DataTopicWrapper::typeFq() const
|
||||||
{
|
{
|
||||||
const QString &t = type();
|
const QString& t = type();
|
||||||
const QString &s = serviceName();
|
const QString& s = serviceName();
|
||||||
if (s.isEmpty())
|
if (s.isEmpty())
|
||||||
return t;
|
return t;
|
||||||
if (t.startsWith(s))
|
if (t.startsWith(s))
|
||||||
@@ -48,77 +48,50 @@ QString MemberInformationWrapper::ddsToQVariant() const
|
|||||||
|
|
||||||
QString MemberInformationWrapper::qVariantToDds() const
|
QString MemberInformationWrapper::qVariantToDds() const
|
||||||
{
|
{
|
||||||
const QString ddsType = isOptional() ?
|
const QString ddsType =
|
||||||
(QStringLiteral("dds::core::optional<") + cppDdsType() + QLatin1Char('>')) :
|
isOptional() ? (QStringLiteral("dds::core::optional<") + cppDdsType() + QLatin1Char('>')) : (cppDdsType());
|
||||||
(cppDdsType());
|
|
||||||
|
|
||||||
return QStringLiteral("data.") + cppMemberName() +
|
return QStringLiteral("data.") + cppMemberName() + QStringLiteral("() = fromQVariant<") + ddsType +
|
||||||
QStringLiteral("() = fromQVariant<") + ddsType + QStringLiteral(">(q.value(i++))");
|
QStringLiteral(">(q.value(i++))");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MemberInformationWrapper::ddsToJsonElement() const
|
QString MemberInformationWrapper::ddsToJsonElement() const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cppMemberName().isEmpty())
|
if (cppMemberName().isEmpty())
|
||||||
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
|
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
|
||||||
|
|
||||||
const QString memberAccess = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
|
const QString memberAccess = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
|
||||||
if (!isOptional())
|
if (!isOptional())
|
||||||
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") +
|
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
|
||||||
cppToJsonPre() + QStringLiteral("element.") + memberAccess + cppToJsonPost();
|
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("()");
|
const QString getValue = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
|
||||||
return QStringLiteral("if (element.") + optionalAccess + QStringLiteral(") ") +
|
return QStringLiteral("if (element.") + optionalAccess + QStringLiteral(") ") +
|
||||||
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") +
|
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
|
||||||
cppToJsonPre() + QStringLiteral("element.") + getValue + cppToJsonPost();
|
QStringLiteral("element.") + getValue + cppToJsonPost();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MemberInformationWrapper::jsonElementToDds() const
|
QString MemberInformationWrapper::jsonElementToDds() const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cppMemberName().isEmpty())
|
if (cppMemberName().isEmpty())
|
||||||
return QStringLiteral("element = ") +
|
return QStringLiteral("element = ") + cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") +
|
||||||
cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") + cppType() + QStringLiteral("\"))") + cppFromJsonPost();
|
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())
|
if (isOptional())
|
||||||
ret += QStringLiteral("if (!val.isNull()) ");
|
ret += QStringLiteral("if (!val.isNull()) ");
|
||||||
|
|
||||||
if (isCppStruct())
|
if (isCppStruct())
|
||||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") +
|
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") + cppFromJsonPre2() +
|
||||||
cppFromJsonPre2() + QStringLiteral("val") + cppFromJsonPost();
|
QStringLiteral("val") + cppFromJsonPost();
|
||||||
else
|
else
|
||||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral("(") +
|
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral("(") + cppFromJsonPre2() +
|
||||||
cppFromJsonPre2() + QStringLiteral("val") + cppFromJsonPost() + QStringLiteral(")");
|
QStringLiteral("val") + cppFromJsonPost() + QStringLiteral(")");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -126,56 +99,39 @@ QString MemberInformationWrapper::jsonElementToDds() const
|
|||||||
QString MemberInformationWrapper::dbToJsonElement() const
|
QString MemberInformationWrapper::dbToJsonElement() const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cppMemberName().isEmpty())
|
if (cppMemberName().isEmpty())
|
||||||
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
|
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
|
||||||
|
|
||||||
if (isOptional() || cppType() == QStringLiteral("QDateTime"))
|
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() +
|
QStringLiteral("element.") + cppMemberName() +
|
||||||
((cppType() == QStringLiteral("QDateTime")) ? QStringLiteral(".isValid()) ") : QStringLiteral(".isNull()) ")) +
|
((cppType() == QStringLiteral("QDateTime")) ? QStringLiteral(".isValid()) ")
|
||||||
|
: QStringLiteral(".isNull()) ")) +
|
||||||
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ");
|
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ");
|
||||||
if (isOptional())
|
if (isOptional())
|
||||||
return ret += cppFromQvPre2() + QStringLiteral("element.") + cppMemberName() + cppFromQvPost();
|
return ret += cppFromQvPre2() + QStringLiteral("element.") + cppMemberName() + cppFromQvPost();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") +
|
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
|
||||||
cppToJsonPre() + QStringLiteral("element.") + cppMemberName() + cppToJsonPost();
|
QStringLiteral("element.") + cppMemberName() + cppToJsonPost();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MemberInformationWrapper::jsonElementToDb() const
|
QString MemberInformationWrapper::jsonElementToDb() const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cppMemberName().isEmpty())
|
if (cppMemberName().isEmpty())
|
||||||
return QStringLiteral("element = ") +
|
return QStringLiteral("element = ") + cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") +
|
||||||
cppFromQvPre2() + QStringLiteral("objElement.value(QStringLiteral(\"") + cppType() + QStringLiteral("\"))") + cppFromJsonPost();
|
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())
|
if (isOptional())
|
||||||
ret += QStringLiteral("if (!val.isUndefined()) ");
|
ret += QStringLiteral("if (!val.isUndefined()) ");
|
||||||
|
|
||||||
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") +
|
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") + cppFromJsonPre2() +
|
||||||
cppFromJsonPre2() + QStringLiteral("val") + cppFromJsonPost();
|
QStringLiteral("val") + cppFromJsonPost();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -184,18 +140,18 @@ QVariantList DbStructWrapper::insertStructures()
|
|||||||
{
|
{
|
||||||
|
|
||||||
QStringList tableNames;
|
QStringList tableNames;
|
||||||
QMap<QString, QVector<MemberInformationWrapper *>> structures;
|
QMap<QString, QVector<MemberInformationWrapper*>> structures;
|
||||||
QMap<QString, MemberInformationWrapper *> primaryKeys;
|
QMap<QString, MemberInformationWrapper*> primaryKeys;
|
||||||
QMap<QString, MemberInformationWrapper *> fkComplexTableKeys;
|
QMap<QString, MemberInformationWrapper*> fkComplexTableKeys;
|
||||||
|
|
||||||
tableNames.reserve(5);
|
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 *>();
|
MemberInformationWrapper* mi = v.value<MemberInformationWrapper*>();
|
||||||
const QString &tableName = mi->info().db.table;
|
const QString& tableName = mi->info().db.table;
|
||||||
if (mi->info().db.usedForInsert)
|
if (mi->info().db.usedForInsert)
|
||||||
{
|
{
|
||||||
auto &tnStructure = structures[tableName];
|
auto& tnStructure = structures[tableName];
|
||||||
tnStructure.append(mi);
|
tnStructure.append(mi);
|
||||||
if (!tableNames.contains(tableName))
|
if (!tableNames.contains(tableName))
|
||||||
tableNames.push_back(tableName);
|
tableNames.push_back(tableName);
|
||||||
@@ -211,27 +167,24 @@ QVariantList DbStructWrapper::insertStructures()
|
|||||||
fkComplexTableKeys[mi->info().db.table] = mi;
|
fkComplexTableKeys[mi->info().db.table] = mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantList vl;
|
QVariantList vl;
|
||||||
vl.reserve(tableNames.size());
|
vl.reserve(tableNames.size());
|
||||||
for (int i = 0; i < tableNames.size(); ++i)
|
for (int i = 0; i < tableNames.size(); ++i)
|
||||||
{
|
{
|
||||||
const QString &tn = tableNames.at(i);
|
const QString& tn = tableNames.at(i);
|
||||||
MemberInformationWrapper *serialMember = fkComplexTableKeys.value(tn);
|
MemberInformationWrapper* serialMember = fkComplexTableKeys.value(tn);
|
||||||
MemberInformationWrapper *baseId = nullptr;
|
MemberInformationWrapper* baseId = nullptr;
|
||||||
MemberInformationWrapper *primaryKey = primaryKeys.value(tn);
|
MemberInformationWrapper* primaryKey = primaryKeys.value(tn);
|
||||||
if (i == 0 && tableNames.size() > 1)
|
if (i == 0 && tableNames.size() > 1)
|
||||||
baseId = primaryKeys.value(tn);
|
baseId = primaryKeys.value(tn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (tableNames.size() == 1)
|
if (tableNames.size() == 1)
|
||||||
{
|
{
|
||||||
baseId = nullptr;
|
baseId = nullptr;
|
||||||
|
|
||||||
if (!primaryKey)
|
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!";
|
WARNING_LOG(logger) << "Table " << tn << " has no primary key!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -241,8 +194,8 @@ QVariantList DbStructWrapper::insertStructures()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<MemberInformationWrapper *> members = structures.value(tn);
|
const QVector<MemberInformationWrapper*> members = structures.value(tn);
|
||||||
TableWrapper *tw = new TableWrapper(tn, members, serialMember, baseId, primaryKey, this);
|
TableWrapper* tw = new TableWrapper(tn, members, serialMember, baseId, primaryKey, this);
|
||||||
vl += QVariant::fromValue(tw);
|
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 "SqlGenerator.h"
|
||||||
|
|
||||||
#include "StructBuilder.h"
|
#include "StructBuilder.h"
|
||||||
#include "XmlReader.h"
|
#include "XmlReader.h"
|
||||||
|
|
||||||
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
#include <QStringList>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
||||||
|
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
|
|
||||||
static QString getExerciseSchemaName(int exerciseId)
|
static QString getExerciseSchemaName(int exerciseId)
|
||||||
{
|
{
|
||||||
return QStringLiteral("ex_") + QString::number(exerciseId);
|
return QStringLiteral("ex_") + QString::number(exerciseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
SqlGenerator::SqlGenerator(XmlReader *xmlReader, StructBuilder *structBuilder) : m_xmlReader(xmlReader)
|
SqlGenerator::SqlGenerator(XmlReader* xmlReader, StructBuilder* structBuilder)
|
||||||
, m_structBuilder(structBuilder)
|
: m_xmlReader(xmlReader), m_structBuilder(structBuilder), m_createdByXmlFile(false), m_isValid(true),
|
||||||
, m_createdByXmlFile(false)
|
m_exerciseId(0), m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||||
, m_isValid(true)
|
{
|
||||||
, m_exerciseId(0),
|
}
|
||||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
|
|
||||||
|
|
||||||
SqlGenerator::SqlGenerator(const QString &xmlFile)
|
SqlGenerator::SqlGenerator(const QString& xmlFile)
|
||||||
: m_xmlReader(new XmlReader)
|
: m_xmlReader(new XmlReader), m_structBuilder(new StructBuilder(m_xmlReader)), m_createdByXmlFile(true),
|
||||||
, m_structBuilder(new StructBuilder(m_xmlReader))
|
m_isValid(false), m_exerciseId(0)
|
||||||
, m_createdByXmlFile(true)
|
|
||||||
, m_isValid(false)
|
|
||||||
, m_exerciseId(0)
|
|
||||||
{
|
{
|
||||||
m_isValid = m_xmlReader->readServiceFile(xmlFile, QString()) && m_structBuilder->buildStructures();
|
m_isValid = m_xmlReader->readServiceFile(xmlFile, QString()) && m_structBuilder->buildStructures();
|
||||||
}
|
}
|
||||||
@@ -45,10 +39,10 @@ SqlGenerator::~SqlGenerator()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SqlGenerator::generateData(int exerciseId)
|
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_exerciseId = exerciseId;
|
||||||
m_sqlGlobal = SqlStatements();
|
m_sqlGlobal = SqlStatements();
|
||||||
@@ -69,10 +63,10 @@ bool SqlGenerator::generateData(int exerciseId)
|
|||||||
return true;
|
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();
|
const QMap<QString, CompleteTableInformation> tables = m_structBuilder->getDbTables();
|
||||||
for (const CompleteTableInformation &cti : tables)
|
for (const CompleteTableInformation& cti : tables)
|
||||||
{
|
{
|
||||||
if (cti.name != tableName)
|
if (cti.name != tableName)
|
||||||
continue;
|
continue;
|
||||||
@@ -86,7 +80,7 @@ bool SqlGenerator::createStatementsForTable(const QString &tableName, const QStr
|
|||||||
bool SqlGenerator::handleTables()
|
bool SqlGenerator::handleTables()
|
||||||
{
|
{
|
||||||
const QMap<QString, CompleteTableInformation> tables = m_structBuilder->getDbTables();
|
const QMap<QString, CompleteTableInformation> tables = m_structBuilder->getDbTables();
|
||||||
for (const CompleteTableInformation &cti : tables)
|
for (const CompleteTableInformation& cti : tables)
|
||||||
{
|
{
|
||||||
if (!handleTable(cti))
|
if (!handleTable(cti))
|
||||||
return false;
|
return false;
|
||||||
@@ -107,7 +101,7 @@ bool SqlGenerator::handleTables()
|
|||||||
ci.name = QStringLiteral("IDX_sample_time");
|
ci.name = QStringLiteral("IDX_sample_time");
|
||||||
ci.affectedColumns = QStringList({QStringLiteral("sample_time")});
|
ci.affectedColumns = QStringList({QStringLiteral("sample_time")});
|
||||||
ci.type = ConstraintInformation::Type::index;
|
ci.type = ConstraintInformation::Type::index;
|
||||||
for (const CompleteTableInformation &cti : recTables)
|
for (const CompleteTableInformation& cti : recTables)
|
||||||
{
|
{
|
||||||
CompleteTableInformation ctiTmp(cti);
|
CompleteTableInformation ctiTmp(cti);
|
||||||
ctiTmp.columns.push_back(miColumnIsValid);
|
ctiTmp.columns.push_back(miColumnIsValid);
|
||||||
@@ -122,7 +116,7 @@ bool SqlGenerator::handleTables()
|
|||||||
bool SqlGenerator::handleViews()
|
bool SqlGenerator::handleViews()
|
||||||
{
|
{
|
||||||
const QMap<QString, ViewInformation> views = m_structBuilder->getDbViews();
|
const QMap<QString, ViewInformation> views = m_structBuilder->getDbViews();
|
||||||
for (const ViewInformation &vi : views)
|
for (const ViewInformation& vi : views)
|
||||||
{
|
{
|
||||||
if (!handleView(vi))
|
if (!handleView(vi))
|
||||||
return false;
|
return false;
|
||||||
@@ -131,7 +125,7 @@ bool SqlGenerator::handleViews()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SqlGenerator::handleView(const ViewInformation &vi)
|
bool SqlGenerator::handleView(const ViewInformation& vi)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(m_logger) << "Handle view " << vi.name;
|
DEBUG_LOG(m_logger) << "Handle view " << vi.name;
|
||||||
|
|
||||||
@@ -150,27 +144,25 @@ bool SqlGenerator::handleView(const ViewInformation &vi)
|
|||||||
if (!csi.primaryTable.isNull())
|
if (!csi.primaryTable.isNull())
|
||||||
{
|
{
|
||||||
QStringList fromTables;
|
QStringList fromTables;
|
||||||
fromTables += vi.baseSchema+QLatin1Char('.')+vi.baseTable;
|
fromTables += vi.baseSchema + QLatin1Char('.') + vi.baseTable;
|
||||||
|
|
||||||
QStringList whereConditions;
|
QStringList whereConditions;
|
||||||
if (vi.filter.contains(QLatin1String("exercise_id")))
|
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;
|
QStringList fqColumnNames;
|
||||||
|
|
||||||
|
for (const MemberInformation& mi : csi.member)
|
||||||
for (const MemberInformation &mi : csi.member)
|
|
||||||
{
|
{
|
||||||
if (mi.db.usedForView)
|
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(", "));
|
DEBUG_LOG(m_logger) << "fqColumnNames = " << fqColumnNames.join(QStringLiteral(", "));
|
||||||
|
|
||||||
|
|
||||||
if (!whereConditions.isEmpty())
|
if (!whereConditions.isEmpty())
|
||||||
addToCreateViews(createViewStmt.arg(csi.viewName,
|
addToCreateViews(createViewStmt.arg(csi.viewName, fqColumnNames.join(QStringLiteral(", ")),
|
||||||
fqColumnNames.join(QStringLiteral(", ")),
|
|
||||||
fromTables.join(QStringLiteral(", ")),
|
fromTables.join(QStringLiteral(", ")),
|
||||||
whereConditions.join(QStringLiteral(" AND\n"))),
|
whereConditions.join(QStringLiteral(" AND\n"))),
|
||||||
vi.exerciseDependency);
|
vi.exerciseDependency);
|
||||||
@@ -179,10 +171,9 @@ bool SqlGenerator::handleView(const ViewInformation &vi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
bool SqlGenerator::handleTable(const CompleteTableInformation& cti)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(m_logger) << "Handle table " << cti.name;
|
DEBUG_LOG(m_logger) << "Handle table " << cti.name;
|
||||||
|
|
||||||
@@ -202,20 +193,14 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
|||||||
|
|
||||||
if ((cti.exerciseDependency & Global) == Global)
|
if ((cti.exerciseDependency & Global) == Global)
|
||||||
{
|
{
|
||||||
addToCreateTables(createTableStmt.arg(cti.name,
|
addToCreateTables(createTableStmt.arg(
|
||||||
getTableColumnCreateStatements(cti.name,
|
cti.name, getTableColumnCreateStatements(cti.name, cti.columns, &tableComments, Global)),
|
||||||
cti.columns,
|
|
||||||
&tableComments,
|
|
||||||
Global)),
|
|
||||||
Global);
|
Global);
|
||||||
}
|
}
|
||||||
if ((cti.exerciseDependency & Exercise) == Exercise)
|
if ((cti.exerciseDependency & Exercise) == Exercise)
|
||||||
{
|
{
|
||||||
addToCreateTables(createTableStmt.arg(cti.name,
|
addToCreateTables(createTableStmt.arg(cti.name, getTableColumnCreateStatements(cti.name, cti.columns,
|
||||||
getTableColumnCreateStatements(cti.name,
|
&tableComments, Exercise)),
|
||||||
cti.columns,
|
|
||||||
&tableComments,
|
|
||||||
Exercise)),
|
|
||||||
Exercise);
|
Exercise);
|
||||||
}
|
}
|
||||||
addToTables(cti.name, cti.exerciseDependency);
|
addToTables(cti.name, cti.exerciseDependency);
|
||||||
@@ -237,29 +222,29 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
|||||||
QStringList whereConditions;
|
QStringList whereConditions;
|
||||||
fromTables += cti.name;
|
fromTables += cti.name;
|
||||||
|
|
||||||
|
for (const MemberInformation& mi : csi.member)
|
||||||
for (const MemberInformation &mi : csi.member)
|
|
||||||
{
|
{
|
||||||
if (mi.db.usedForView)
|
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)
|
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)
|
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 (!fki.isNull())
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!fromTables.contains(fki->destination.tableName))
|
if (!fromTables.contains(fki->destination.tableName))
|
||||||
{
|
{
|
||||||
whereConditions += fki->destination.tableName + QLatin1Char('.') + fki->destination.columnName +
|
whereConditions += fki->destination.tableName + QLatin1Char('.') +
|
||||||
QLatin1String(" = ") +
|
fki->destination.columnName + QLatin1String(" = ") +
|
||||||
fki->source.tableName + QLatin1Char('.') + fki->source.columnName;
|
fki->source.tableName + QLatin1Char('.') +
|
||||||
|
fki->source.columnName;
|
||||||
fromTables += fki->destination.tableName;
|
fromTables += fki->destination.tableName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,8 +255,7 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
|||||||
}
|
}
|
||||||
if (!whereConditions.isEmpty())
|
if (!whereConditions.isEmpty())
|
||||||
{
|
{
|
||||||
addToCreateViews(createViewStmt.arg(csi.viewName,
|
addToCreateViews(createViewStmt.arg(csi.viewName, fqColumnNames.join(QStringLiteral(", ")),
|
||||||
fqColumnNames.join(QStringLiteral(", ")),
|
|
||||||
fromTables.join(QStringLiteral(", ")),
|
fromTables.join(QStringLiteral(", ")),
|
||||||
whereConditions.join(QStringLiteral(" AND\n"))),
|
whereConditions.join(QStringLiteral(" AND\n"))),
|
||||||
cti.exerciseDependency);
|
cti.exerciseDependency);
|
||||||
@@ -290,19 +274,16 @@ bool SqlGenerator::handleTable(const CompleteTableInformation &cti)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SqlGenerator::getTableColumnCreateStatements(const QString& tableName,
|
||||||
QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
const QVector<MemberInformation>& columns,
|
||||||
const QVector<MemberInformation> &columns,
|
QStringList* tableComments, ExerciseDependency ed)
|
||||||
QStringList *tableComments,
|
|
||||||
ExerciseDependency ed)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(ed == Global || ed == Exercise);
|
Q_ASSERT(ed == Global || ed == Exercise);
|
||||||
|
|
||||||
const QString commentColumnStmt(QStringLiteral("COMMENT ON COLUMN %1 IS '%2';"));
|
const QString commentColumnStmt(QStringLiteral("COMMENT ON COLUMN %1 IS '%2';"));
|
||||||
|
|
||||||
|
|
||||||
int maxLength = 1;
|
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 = std::max(maxLength, static_cast<int>(mi.db.columnName.length()));
|
||||||
maxLength += 1;
|
maxLength += 1;
|
||||||
|
|
||||||
@@ -311,8 +292,8 @@ QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
|||||||
retCols += QString();
|
retCols += QString();
|
||||||
for (int i = 0; i < columns.size(); ++i)
|
for (int i = 0; i < columns.size(); ++i)
|
||||||
{
|
{
|
||||||
const MemberInformation &mi = columns.at(i);
|
const MemberInformation& mi = columns.at(i);
|
||||||
const FullQualifiedColumnInformation &ci = mi.db;
|
const FullQualifiedColumnInformation& ci = mi.db;
|
||||||
const QString spaces(maxLength - ci.columnName.length(), QLatin1Char(' '));
|
const QString spaces(maxLength - ci.columnName.length(), QLatin1Char(' '));
|
||||||
QString column = ci.columnName + spaces + ci.datatype;
|
QString column = ci.columnName + spaces + ci.datatype;
|
||||||
if (ci.hasSequence)
|
if (ci.hasSequence)
|
||||||
@@ -325,8 +306,7 @@ QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
|||||||
else
|
else
|
||||||
schema = getExerciseSchemaName(m_exerciseId);
|
schema = getExerciseSchemaName(m_exerciseId);
|
||||||
|
|
||||||
column += QLatin1String(" DEFAULT nextval(( '") +
|
column += QLatin1String(" DEFAULT nextval(( '") + schema + QLatin1Char('.') + seqDescr +
|
||||||
schema + QLatin1Char('.') + seqDescr +
|
|
||||||
QLatin1String("'::text)::regclass)");
|
QLatin1String("'::text)::regclass)");
|
||||||
}
|
}
|
||||||
if (!ci.canBeNull)
|
if (!ci.canBeNull)
|
||||||
@@ -351,36 +331,33 @@ QString SqlGenerator::getTableColumnCreateStatements(const QString &tableName,
|
|||||||
return retCols.join(QStringLiteral("\n "));
|
return retCols.join(QStringLiteral("\n "));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SqlGenerator::generateSequence(const QString &tableName,
|
QString SqlGenerator::generateSequence(const QString& tableName, const FullQualifiedColumnInformation& ci,
|
||||||
const FullQualifiedColumnInformation &ci,
|
|
||||||
ExerciseDependency ed)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
const QString sequenceName = tableName + QLatin1Char('_') + ci.columnName + QLatin1String("_seq");
|
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;
|
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);
|
addToSequences(sequenceName, ed);
|
||||||
|
|
||||||
return sequenceName;
|
return sequenceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlGenerator::generatePrimaryKey(const QString &tableName,
|
void SqlGenerator::generatePrimaryKey(const QString& tableName, const FullQualifiedColumnInformation& ci,
|
||||||
const FullQualifiedColumnInformation &ci,
|
|
||||||
ExerciseDependency ed)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
QString pkName = QLatin1String("PK_") + tableName + QLatin1Char('_') + ci.columnName;
|
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);
|
addToPks(pkName, ed);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const QString pkConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 ADD CONSTRAINT %2 PRIMARY KEY (%3);"));
|
const QString pkConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 ADD CONSTRAINT %2 PRIMARY KEY (%3);"));
|
||||||
addToCreatePks(pkConstraint.arg(tableName, pkName, ci.columnName), ed);
|
addToCreatePks(pkConstraint.arg(tableName, pkName, ci.columnName), ed);
|
||||||
|
|
||||||
@@ -388,24 +365,21 @@ void SqlGenerator::generatePrimaryKey(const QString &tableName,
|
|||||||
addToDropConstraints(pkDropConstraint.arg(tableName, pkName), ed);
|
addToDropConstraints(pkDropConstraint.arg(tableName, pkName), ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlGenerator::generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation> > &foreignKeys,
|
void SqlGenerator::generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation>>& foreignKeys,
|
||||||
ExerciseDependency ed)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
for (const QSharedPointer<ForeignKeyInformation> &fk : foreignKeys)
|
for (const QSharedPointer<ForeignKeyInformation>& fk : foreignKeys)
|
||||||
generateForeignKey(fk, ed);
|
generateForeignKey(fk, ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlGenerator::generateForeignKey(const QSharedPointer<ForeignKeyInformation> &foreignKey,
|
void SqlGenerator::generateForeignKey(const QSharedPointer<ForeignKeyInformation>& foreignKey, ExerciseDependency ed)
|
||||||
ExerciseDependency ed)
|
|
||||||
{
|
{
|
||||||
QString fkName = QLatin1String("FK_") + foreignKey->source.tableName +
|
QString fkName = QLatin1String("FK_") + foreignKey->source.tableName + QLatin1Char('_') +
|
||||||
QLatin1Char('_') + foreignKey->source.columnName +
|
foreignKey->source.columnName + QLatin1Char('_') + foreignKey->destination.tableName +
|
||||||
QLatin1Char('_') + foreignKey->destination.tableName +
|
|
||||||
QLatin1Char('_') + foreignKey->destination.columnName;
|
QLatin1Char('_') + foreignKey->destination.columnName;
|
||||||
|
|
||||||
|
if (fkName.size() > 63)
|
||||||
|
fkName = foreignKey->name;
|
||||||
if (fkName.size() > 63) fkName = foreignKey->name;
|
|
||||||
|
|
||||||
addToFks(fkName, ed);
|
addToFks(fkName, ed);
|
||||||
|
|
||||||
@@ -431,71 +405,68 @@ void SqlGenerator::generateForeignKey(const QSharedPointer<ForeignKeyInformation
|
|||||||
|
|
||||||
fkConstraint += QLatin1Char(';');
|
fkConstraint += QLatin1Char(';');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString destination;
|
QString destination;
|
||||||
if (!foreignKey->destination.schema.isEmpty())
|
if (!foreignKey->destination.schema.isEmpty())
|
||||||
{
|
{
|
||||||
const QString &extSchema = foreignKey->destination.schema;
|
const QString& extSchema = foreignKey->destination.schema;
|
||||||
destination = extSchema + QLatin1Char('.') + foreignKey->destination.tableName;
|
destination = extSchema + QLatin1Char('.') + foreignKey->destination.tableName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
destination = foreignKey->destination.tableName;
|
destination = foreignKey->destination.tableName;
|
||||||
|
|
||||||
const QString &extSvcAbbr = foreignKey->destination.serviceAbbr;
|
const QString& extSvcAbbr = foreignKey->destination.serviceAbbr;
|
||||||
|
|
||||||
if (!extSvcAbbr.isEmpty() && !m_referencedSevices.contains(extSvcAbbr))
|
if (!extSvcAbbr.isEmpty() && !m_referencedSevices.contains(extSvcAbbr))
|
||||||
m_referencedSevices += extSvcAbbr;
|
m_referencedSevices += extSvcAbbr;
|
||||||
|
|
||||||
addToCreateFks(fkConstraint.arg(foreignKey->source.tableName, fkName, foreignKey->source.columnName,
|
addToCreateFks(fkConstraint.arg(foreignKey->source.tableName, fkName, foreignKey->source.columnName, destination,
|
||||||
destination, foreignKey->destination.columnName), ed);
|
foreignKey->destination.columnName),
|
||||||
|
ed);
|
||||||
|
|
||||||
const QString fkDropConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 DROP CONSTRAINT IF EXISTS %2 CASCADE;"));
|
const QString fkDropConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 DROP CONSTRAINT IF EXISTS %2 CASCADE;"));
|
||||||
addToDropConstraints(fkDropConstraint.arg(foreignKey->source.tableName, fkName), ed);
|
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)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
for (const ConstraintInformation &constraint : constraints)
|
for (const ConstraintInformation& constraint : constraints)
|
||||||
generateConstraint(tableName, constraint, ed);
|
generateConstraint(tableName, constraint, ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlGenerator::generateConstraint(const QString &tableName,
|
void SqlGenerator::generateConstraint(const QString& tableName, const ConstraintInformation& constraint,
|
||||||
const ConstraintInformation &constraint,
|
|
||||||
ExerciseDependency ed)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
const QString dropConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 DROP CONSTRAINT IF EXISTS %2 CASCADE;"));
|
const QString dropConstraint(QStringLiteral("ALTER TABLE IF EXISTS %1 DROP CONSTRAINT IF EXISTS %2 CASCADE;"));
|
||||||
switch (constraint.type)
|
switch (constraint.type)
|
||||||
{
|
{
|
||||||
case ConstraintInformation::Type::index:
|
case ConstraintInformation::Type::index: {
|
||||||
{
|
|
||||||
QString constraintName = QLatin1String("IDX_") + tableName + QLatin1Char('_') +
|
QString constraintName = QLatin1String("IDX_") + tableName + QLatin1Char('_') +
|
||||||
constraint.affectedColumns.join(QStringLiteral("_"));
|
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);"));
|
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);
|
addToConstraints(constraintName, ed);
|
||||||
|
|
||||||
addToDropConstraints(dropConstraint.arg(tableName, constraintName), ed);
|
addToDropConstraints(dropConstraint.arg(tableName, constraintName), ed);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ConstraintInformation::Type::unique:
|
case ConstraintInformation::Type::unique: {
|
||||||
{
|
|
||||||
QString constraintName = QLatin1String("UQ_") + tableName + QLatin1Char('_') +
|
QString constraintName = QLatin1String("UQ_") + tableName + QLatin1Char('_') +
|
||||||
constraint.affectedColumns.join(QStringLiteral("_"));
|
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);"));
|
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);
|
addToConstraints(constraintName, ed);
|
||||||
|
|
||||||
addToDropConstraints(dropConstraint.arg(tableName, constraintName), ed);
|
addToDropConstraints(dropConstraint.arg(tableName, constraintName), ed);
|
||||||
@@ -510,7 +481,7 @@ void SqlGenerator::generateConstraint(const QString &tableName,
|
|||||||
bool SqlGenerator::handleEnumerations()
|
bool SqlGenerator::handleEnumerations()
|
||||||
{
|
{
|
||||||
const QVector<EnumInformation> enumerations = m_xmlReader->getEnumerations();
|
const QVector<EnumInformation> enumerations = m_xmlReader->getEnumerations();
|
||||||
for (const EnumInformation &ei : enumerations)
|
for (const EnumInformation& ei : enumerations)
|
||||||
{
|
{
|
||||||
if (!handleEnumeration(ei))
|
if (!handleEnumeration(ei))
|
||||||
return false;
|
return false;
|
||||||
@@ -518,7 +489,7 @@ bool SqlGenerator::handleEnumerations()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SqlGenerator::handleEnumeration(const EnumInformation &ei)
|
bool SqlGenerator::handleEnumeration(const EnumInformation& ei)
|
||||||
{
|
{
|
||||||
const QStringList sql = handleEnumeration(ei, QString());
|
const QStringList sql = handleEnumeration(ei, QString());
|
||||||
if (m_sqlItemsGlobal.tables.contains(ei.tableName))
|
if (m_sqlItemsGlobal.tables.contains(ei.tableName))
|
||||||
@@ -529,7 +500,7 @@ bool SqlGenerator::handleEnumeration(const EnumInformation &ei)
|
|||||||
return true;
|
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;
|
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 columnNames(QStringLiteral("id, name"));
|
||||||
const QString tablename = dbSchema.isEmpty() ? ei.tableName : dbSchema + QLatin1Char('.') + ei.tableName;
|
const QString tablename = dbSchema.isEmpty() ? ei.tableName : dbSchema + QLatin1Char('.') + ei.tableName;
|
||||||
|
|
||||||
|
|
||||||
QStringList enumerationValues;
|
QStringList enumerationValues;
|
||||||
for (const EnumKeyValuePair &evp : ei.values)
|
for (const EnumKeyValuePair& evp : ei.values)
|
||||||
{
|
{
|
||||||
const QString values(QString::number(evp.value) + QLatin1String(", '") +
|
const QString values(QString::number(evp.value) + QLatin1String(", '") + fixupComment(evp.key) +
|
||||||
fixupComment(evp.key) + QLatin1Char('\''));
|
QLatin1Char('\''));
|
||||||
enumerationValues += insertEnum.arg(tablename, columnNames, values);
|
enumerationValues += insertEnum.arg(tablename, columnNames, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
return enumerationValues;
|
return enumerationValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SqlGenerator::generateDbNotifications(const QString &tableName,
|
bool SqlGenerator::generateDbNotifications(const QString& tableName,
|
||||||
const QVector<DbNotifcationInformation> ¬ifications,
|
const QVector<DbNotifcationInformation>& notifications,
|
||||||
ExerciseDependency ed)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
for (const DbNotifcationInformation ¬ification : notifications)
|
for (const DbNotifcationInformation& notification : notifications)
|
||||||
{
|
{
|
||||||
if (notification.paramNames.isEmpty() ||
|
if (notification.paramNames.isEmpty() || notification.paramNames.size() > 1)
|
||||||
notification.paramNames.size() > 1)
|
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Can not handle more than one parameter";
|
ERROR_LOG(m_logger) << "Can not handle more than one parameter";
|
||||||
continue;
|
continue;
|
||||||
@@ -574,8 +543,7 @@ bool SqlGenerator::generateDbNotifications(const QString &tableName,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlGenerator::generateDbNotification(const DbNotifcationInformation ¬ification,
|
void SqlGenerator::generateDbNotification(const DbNotifcationInformation& notification, ExerciseDependency ed)
|
||||||
ExerciseDependency ed)
|
|
||||||
{
|
{
|
||||||
const QString func(QStringLiteral("CREATE OR REPLACE FUNCTION public.%1()\n"
|
const QString func(QStringLiteral("CREATE OR REPLACE FUNCTION public.%1()\n"
|
||||||
"RETURNS TRIGGER AS $$\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);
|
addToDbFunctions(func.arg(triggerFuncName, notification.methodName, notification.paramNames.first()), ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SqlGenerator::generateDbNotificationTrigger(const QString &tableName,
|
bool SqlGenerator::generateDbNotificationTrigger(const QString& tableName, const DbNotifcationInformation& notification,
|
||||||
const DbNotifcationInformation ¬ification,
|
|
||||||
ExerciseDependency ed)
|
ExerciseDependency ed)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -643,7 +610,8 @@ bool SqlGenerator::generateDbNotificationTrigger(const QString &tableName,
|
|||||||
triggerNameShortcut = QStringLiteral("ad");
|
triggerNameShortcut = QStringLiteral("ad");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const QString triggerName(QLatin1String("trg_") + triggerNameShortcut + QLatin1Char('_') + notification.methodName);
|
const QString triggerName(QLatin1String("trg_") + triggerNameShortcut + QLatin1Char('_') +
|
||||||
|
notification.methodName);
|
||||||
const QString triggerFuncName(getNotificationFunctionName(notification));
|
const QString triggerFuncName(getNotificationFunctionName(notification));
|
||||||
addToDbFunctionTrigger(drop.arg(triggerName, tableName), ed);
|
addToDbFunctionTrigger(drop.arg(triggerName, tableName), ed);
|
||||||
addToDbFunctionTrigger(func.arg(triggerName, when, tableName, triggerFuncName), ed);
|
addToDbFunctionTrigger(func.arg(triggerName, when, tableName, triggerFuncName), ed);
|
||||||
@@ -651,13 +619,12 @@ bool SqlGenerator::generateDbNotificationTrigger(const QString &tableName,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SqlGenerator::getNotificationFunctionName(const DbNotifcationInformation ¬ification) const
|
QString SqlGenerator::getNotificationFunctionName(const DbNotifcationInformation& notification) const
|
||||||
{
|
{
|
||||||
return getServiceAbbr() + QLatin1Char('_') + notification.methodName;
|
return getServiceAbbr() + QLatin1Char('_') + notification.methodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SqlGenerator::fixupComment(const QString& comment)
|
||||||
QString SqlGenerator::fixupComment(const QString &comment)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
QString ret = comment;
|
QString ret = comment;
|
||||||
@@ -666,21 +633,19 @@ QString SqlGenerator::fixupComment(const QString &comment)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SqlGenerator::getDbSettings(const QString &dbSchema) const
|
QStringList SqlGenerator::getDbSettings(const QString& dbSchema) const
|
||||||
{
|
{
|
||||||
QStringList data;
|
QStringList data;
|
||||||
|
|
||||||
|
|
||||||
QString dbUser(QStringLiteral("ets_"));
|
QString dbUser(QStringLiteral("ets_"));
|
||||||
if (m_exerciseId > 0)
|
if (m_exerciseId > 0)
|
||||||
dbUser += QStringLiteral("ex_00");
|
dbUser += QStringLiteral("ex_00");
|
||||||
else
|
else
|
||||||
dbUser += m_xmlReader->getServiceAbbr().toLower();
|
dbUser += m_xmlReader->getServiceAbbr().toLower();
|
||||||
|
|
||||||
|
|
||||||
data.append(QLatin1String("ALTER DEFAULT PRIVILEGES IN SCHEMA ") + dbSchema + QLatin1Char('\n') +
|
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') +
|
data.append(QLatin1String("ALTER DEFAULT PRIVILEGES IN SCHEMA ") + dbSchema + QLatin1Char('\n') +
|
||||||
QLatin1String(" GRANT SELECT, REFERENCES ON TABLES TO ets_ro;"));
|
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') +
|
data.append(QLatin1String("ALTER DEFAULT PRIVILEGES IN SCHEMA ") + dbSchema + QLatin1Char('\n') +
|
||||||
QLatin1String(" GRANT ALL ON SEQUENCES TO ") + dbUser + QLatin1Char(';'));
|
QLatin1String(" GRANT ALL ON SEQUENCES TO ") + dbUser + QLatin1Char(';'));
|
||||||
|
|
||||||
|
|
||||||
data.append(QLatin1String("SET SEARCH_PATH TO ") + dbSchema + QLatin1String(", PUBLIC;"));
|
data.append(QLatin1String("SET SEARCH_PATH TO ") + dbSchema + QLatin1String(", PUBLIC;"));
|
||||||
|
|
||||||
QStringList deps;
|
QStringList deps;
|
||||||
deps.reserve(m_referencedSevices.size());
|
deps.reserve(m_referencedSevices.size());
|
||||||
for(const QString &svc : m_referencedSevices)
|
for (const QString& svc : m_referencedSevices)
|
||||||
deps += QStringLiteral("-- DEPENDS: ") + svc;
|
deps += QStringLiteral("-- DEPENDS: ") + svc;
|
||||||
|
|
||||||
return deps + data;
|
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;
|
QStringList data;
|
||||||
|
|
||||||
const SqlStatements &sql = getStatements(ed);
|
const SqlStatements& sql = getStatements(ed);
|
||||||
if (sql.isEmpty())
|
if (sql.isEmpty())
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
if (!dbSchema.isEmpty())
|
if (!dbSchema.isEmpty())
|
||||||
data << getDbSettings(dbSchema);
|
data << getDbSettings(dbSchema);
|
||||||
|
|
||||||
|
|
||||||
data.append(QStringLiteral("\n-- Drop tables/views/sequences/constraints"));
|
data.append(QStringLiteral("\n-- Drop tables/views/sequences/constraints"));
|
||||||
data.append(sql.dropViews);
|
data.append(sql.dropViews);
|
||||||
data.append(sql.dropConstraints);
|
data.append(sql.dropConstraints);
|
||||||
data.append(sql.dropTables);
|
data.append(sql.dropTables);
|
||||||
data.append(sql.dropSequences);
|
data.append(sql.dropSequences);
|
||||||
|
|
||||||
|
|
||||||
data.append(QStringLiteral("\n-- Create tables"));
|
data.append(QStringLiteral("\n-- Create tables"));
|
||||||
data.append(sql.createTables);
|
data.append(sql.createTables);
|
||||||
|
|
||||||
|
|
||||||
data.append(QStringLiteral("\n-- Create sequence(s)"));
|
data.append(QStringLiteral("\n-- Create sequence(s)"));
|
||||||
data.append(sql.createSequences);
|
data.append(sql.createSequences);
|
||||||
|
|
||||||
|
|
||||||
data.append(QStringLiteral("\n-- Create primary keys"));
|
data.append(QStringLiteral("\n-- Create primary keys"));
|
||||||
data.append(sql.createPrimaryKeys);
|
data.append(sql.createPrimaryKeys);
|
||||||
|
|
||||||
|
|
||||||
data.append(QStringLiteral("\n-- Create foreign keys"));
|
data.append(QStringLiteral("\n-- Create foreign keys"));
|
||||||
data.append(sql.createForeignKeys);
|
data.append(sql.createForeignKeys);
|
||||||
|
|
||||||
|
|
||||||
data.append(QStringLiteral("\n-- Create views"));
|
data.append(QStringLiteral("\n-- Create views"));
|
||||||
data.append(sql.createViews);
|
data.append(sql.createViews);
|
||||||
|
|
||||||
|
data.append(
|
||||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||||
data.append(QStringLiteral("\n-- Inserts for static data i.e. enums\n"));
|
data.append(QStringLiteral("\n-- Inserts for static data i.e. enums\n"));
|
||||||
data.append(sql.enumerationValues);
|
data.append(sql.enumerationValues);
|
||||||
|
|
||||||
|
data.append(
|
||||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||||
data.append(QStringLiteral("\n-- Notify functions for callbacks (signals in db interface)\n"));
|
data.append(QStringLiteral("\n-- Notify functions for callbacks (signals in db interface)\n"));
|
||||||
data.append(sql.dbFunctions);
|
data.append(sql.dbFunctions);
|
||||||
|
|
||||||
|
data.append(
|
||||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||||
data.append(QStringLiteral("\n-- Notify function trigger for callbacks (signals in db interface)\n"));
|
data.append(QStringLiteral("\n-- Notify function trigger for callbacks (signals in db interface)\n"));
|
||||||
data.append(sql.dbFunctionTrigger);
|
data.append(sql.dbFunctionTrigger);
|
||||||
|
|
||||||
|
data.append(
|
||||||
data.append(QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
QStringLiteral("\n-- --------------------------------------------------------------------------------"));
|
||||||
data.append(QStringLiteral("\n-- Indexes \n"));
|
data.append(QStringLiteral("\n-- Indexes \n"));
|
||||||
data.append(sql.createConstraints);
|
data.append(sql.createConstraints);
|
||||||
|
|
||||||
return data;
|
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();
|
const QVector<EnumInformation> enumerations = m_xmlReader->getEnumerations();
|
||||||
|
|
||||||
for (const EnumInformation &ei : enumerations)
|
for (const EnumInformation& ei : enumerations)
|
||||||
{
|
{
|
||||||
if (ei.tableName == table)
|
if (ei.tableName == table)
|
||||||
return handleEnumeration(ei, dbSchema);
|
return handleEnumeration(ei, dbSchema);
|
||||||
@@ -777,44 +736,36 @@ QStringList SqlGenerator::getEnumerationInsertValues(const QString &table, const
|
|||||||
return QStringList();
|
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')));
|
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);
|
Q_ASSERT(ed == Global || ed == Exercise);
|
||||||
|
|
||||||
|
|
||||||
QString sqlFile = filePath + getServiceAbbr();
|
QString sqlFile = filePath + getServiceAbbr();
|
||||||
if (ed == ExerciseDependency::Exercise)
|
if (ed == ExerciseDependency::Exercise)
|
||||||
sqlFile += QLatin1Char('_') + getExerciseSchemaName(m_exerciseId);
|
sqlFile += QLatin1Char('_') + getExerciseSchemaName(m_exerciseId);
|
||||||
sqlFile += QLatin1String(".sql");
|
sqlFile += QLatin1String(".sql");
|
||||||
|
|
||||||
const SqlStatements &sql = getStatements(ed);
|
const SqlStatements& sql = getStatements(ed);
|
||||||
if (sql.isEmpty())
|
if (sql.isEmpty())
|
||||||
{
|
{
|
||||||
DEBUG_LOG(m_logger) << "Sql file is emtpy: " << sqlFile;
|
DEBUG_LOG(m_logger) << "Sql file is emtpy: " << sqlFile;
|
||||||
return writeFile(sqlFile, QString());
|
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 << ")";
|
INFO_LOG(m_logger) << "Creating sql-stmt for schema (" << dbSchema << ")";
|
||||||
return writeSqlToFile(dbSchema, sqlFile, ed);
|
return writeSqlToFile(dbSchema, sqlFile, ed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
template<typename T>
|
static void addInternal(QStringList& global, QStringList& exercise, const T& stmt, ExerciseDependency ed)
|
||||||
static void addInternal(QStringList &global,
|
|
||||||
QStringList &exercise,
|
|
||||||
const T &stmt,
|
|
||||||
ExerciseDependency ed)
|
|
||||||
{
|
{
|
||||||
switch (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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
QFile f(fn);
|
||||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: "
|
ERROR_LOG(m_logger) << "Error opening file '" << f.fileName() << "' for writing: " << f.errorString();
|
||||||
<< f.errorString();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
f.write(content.toUtf8());
|
f.write(content.toUtf8());
|
||||||
|
|||||||
Executable → Regular
+86
-62
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include "StructBuilder.h"
|
#include "StructBuilder.h"
|
||||||
#include "codegen_base_export.h"
|
#include "codegen_base_export.h"
|
||||||
|
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
namespace NGL
|
namespace NGL
|
||||||
{
|
{
|
||||||
class INGLLogger;
|
class INGLLogger;
|
||||||
@@ -23,7 +24,7 @@ class XmlReader;
|
|||||||
|
|
||||||
class CODEGEN_BASE_EXPORT SqlGenerator final
|
class CODEGEN_BASE_EXPORT SqlGenerator final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct SqlStatements
|
struct SqlStatements
|
||||||
{
|
{
|
||||||
QStringList dropViews;
|
QStringList dropViews;
|
||||||
@@ -57,19 +58,22 @@ public:
|
|||||||
QStringList constraints;
|
QStringList constraints;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_DISABLE_COPY(SqlGenerator)
|
Q_DISABLE_COPY(SqlGenerator)
|
||||||
|
|
||||||
explicit SqlGenerator(XmlReader *xmlReader, StructBuilder *structBuilder);
|
explicit SqlGenerator(XmlReader* xmlReader, StructBuilder* structBuilder);
|
||||||
explicit SqlGenerator(const QString &xmlFile);
|
explicit SqlGenerator(const QString& xmlFile);
|
||||||
|
|
||||||
~SqlGenerator();
|
~SqlGenerator();
|
||||||
|
|
||||||
bool isValid() const { return m_isValid; }
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return m_isValid;
|
||||||
|
}
|
||||||
|
|
||||||
bool generateData(int exerciseId);
|
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
|
SqlStatements getStatements(ExerciseDependency ed) const
|
||||||
{
|
{
|
||||||
@@ -81,83 +85,103 @@ public:
|
|||||||
return (ed == ExerciseDependency::Exercise ? m_sqlItemsExercise : m_sqlItemsGlobal);
|
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
|
QStringList getReferencedServices() const
|
||||||
{
|
{
|
||||||
return m_referencedSevices;
|
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 isServiceGlobal() const
|
||||||
bool isServiceExerciseIndependent() const { return m_xmlReader->isServiceExerciseIndependent(); }
|
{
|
||||||
bool isServiceGlobal() const { return (m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::Global || m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::GlobalAndExercise); }
|
return (m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::Global ||
|
||||||
CodeGen::ExerciseDependency getExerciseDependency() const { return m_xmlReader->defaultExerciseDependency();}
|
m_xmlReader->defaultExerciseDependency() == CodeGen::ExerciseDependency::GlobalAndExercise);
|
||||||
QStringList getGroupNames() const { return m_xmlReader->getGroupNames(); }
|
}
|
||||||
|
|
||||||
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;
|
protected:
|
||||||
private:
|
NGL::INGLLogger& m_logger;
|
||||||
|
|
||||||
|
private:
|
||||||
bool handleTables();
|
bool handleTables();
|
||||||
bool handleViews();
|
bool handleViews();
|
||||||
bool handleTable(const CompleteTableInformation &cti);
|
bool handleTable(const CompleteTableInformation& cti);
|
||||||
bool handleView(const ViewInformation &vi);
|
bool handleView(const ViewInformation& vi);
|
||||||
QString getTableColumnCreateStatements(const QString &tableName,
|
QString getTableColumnCreateStatements(const QString& tableName, const QVector<MemberInformation>& columns,
|
||||||
const QVector<MemberInformation> &columns,
|
QStringList* tableComments, ExerciseDependency ed);
|
||||||
QStringList *tableComments, ExerciseDependency ed);
|
QString generateSequence(const QString& tableName, const FullQualifiedColumnInformation& ci, ExerciseDependency ed);
|
||||||
QString generateSequence(const QString &tableName, const FullQualifiedColumnInformation &ci, ExerciseDependency ed);
|
void generatePrimaryKey(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 generateForeignKeys(const QVector<QSharedPointer<ForeignKeyInformation> > &foreignKeys, ExerciseDependency ed);
|
void generateForeignKey(const QSharedPointer<ForeignKeyInformation>& foreignKey, ExerciseDependency ed);
|
||||||
void generateForeignKey(const QSharedPointer<ForeignKeyInformation> &foreignKey, ExerciseDependency ed);
|
void generateConstraints(const QString& tableName, const QVector<ConstraintInformation>& constraints,
|
||||||
void generateConstraints(const QString &tableName, const QVector<ConstraintInformation> &constraints, ExerciseDependency ed);
|
ExerciseDependency ed);
|
||||||
void generateConstraint(const QString &tableName, const ConstraintInformation &constraint, ExerciseDependency ed);
|
void generateConstraint(const QString& tableName, const ConstraintInformation& constraint, ExerciseDependency ed);
|
||||||
bool handleEnumerations();
|
bool handleEnumerations();
|
||||||
bool handleEnumeration(const EnumInformation &ei);
|
bool handleEnumeration(const EnumInformation& ei);
|
||||||
QStringList handleEnumeration(const EnumInformation &ei, const QString &dbSchema) const;
|
QStringList handleEnumeration(const EnumInformation& ei, const QString& dbSchema) const;
|
||||||
bool generateDbNotifications(const QString &tableName, const QVector<DbNotifcationInformation> ¬ifications, ExerciseDependency ed);
|
bool generateDbNotifications(const QString& tableName, const QVector<DbNotifcationInformation>& notifications,
|
||||||
void generateDbNotification(const DbNotifcationInformation ¬ification, ExerciseDependency ed);
|
ExerciseDependency ed);
|
||||||
bool generateDbNotificationTrigger(const QString &tableName, const DbNotifcationInformation ¬ification, ExerciseDependency ed);
|
void generateDbNotification(const DbNotifcationInformation& notification, ExerciseDependency ed);
|
||||||
QString getNotificationFunctionName(const DbNotifcationInformation ¬ification) const;
|
bool generateDbNotificationTrigger(const QString& tableName, const DbNotifcationInformation& notification,
|
||||||
static QString fixupComment(const QString &comment);
|
ExerciseDependency ed);
|
||||||
|
QString getNotificationFunctionName(const DbNotifcationInformation& notification) const;
|
||||||
|
static QString fixupComment(const QString& comment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XmlReader *m_xmlReader;
|
XmlReader* m_xmlReader;
|
||||||
StructBuilder *m_structBuilder;
|
StructBuilder* m_structBuilder;
|
||||||
bool m_createdByXmlFile;
|
bool m_createdByXmlFile;
|
||||||
|
|
||||||
void addToDropSequences(const QString &stmt, ExerciseDependency ed);
|
void addToDropSequences(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToDropTables(const QString &stmt, ExerciseDependency ed);
|
void addToDropTables(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToDropViews(const QString &stmt, ExerciseDependency ed);
|
void addToDropViews(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToDropConstraints(const QString &stmt, ExerciseDependency ed);
|
void addToDropConstraints(const QString& stmt, ExerciseDependency ed);
|
||||||
|
|
||||||
void addToCreateConstraints(const QString &stmt, ExerciseDependency ed);
|
void addToCreateConstraints(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToCreateFks(const QString &stmt, ExerciseDependency ed);
|
void addToCreateFks(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToCreatePks(const QString &stmt, ExerciseDependency ed);
|
void addToCreatePks(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToCreateSequences(const QString &stmt, ExerciseDependency ed);
|
void addToCreateSequences(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToCreateTables(const QString &stmt, ExerciseDependency ed);
|
void addToCreateTables(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToCreateTables(const QStringList &stmts, ExerciseDependency ed);
|
void addToCreateTables(const QStringList& stmts, ExerciseDependency ed);
|
||||||
void addToCreateViews(const QString &stmt, ExerciseDependency ed);
|
void addToCreateViews(const QString& stmt, ExerciseDependency ed);
|
||||||
|
|
||||||
void addToDbFunctions(const QString &stmt, ExerciseDependency ed);
|
void addToDbFunctions(const QString& stmt, ExerciseDependency ed);
|
||||||
void addToDbFunctionTrigger(const QString &stmt, ExerciseDependency ed);
|
void addToDbFunctionTrigger(const QString& stmt, ExerciseDependency ed);
|
||||||
|
|
||||||
void addToConstraints(const QString &name, ExerciseDependency ed);
|
void addToConstraints(const QString& name, ExerciseDependency ed);
|
||||||
void addToFks(const QString &name, ExerciseDependency ed);
|
void addToFks(const QString& name, ExerciseDependency ed);
|
||||||
void addToPks(const QString &name, ExerciseDependency ed);
|
void addToPks(const QString& name, ExerciseDependency ed);
|
||||||
void addToSequences(const QString &name, ExerciseDependency ed);
|
void addToSequences(const QString& name, ExerciseDependency ed);
|
||||||
void addToTables(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_sqlGlobal;
|
||||||
SqlStatements m_sqlExercise;
|
SqlStatements m_sqlExercise;
|
||||||
@@ -171,4 +195,4 @@ private:
|
|||||||
int m_exerciseId;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <QtCore/QString>
|
|
||||||
#include "XmlReader.h"
|
#include "XmlReader.h"
|
||||||
#include "codegen_base_export.h"
|
#include "codegen_base_export.h"
|
||||||
|
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
namespace NGL
|
namespace NGL
|
||||||
{
|
{
|
||||||
class INGLLogger;
|
class INGLLogger;
|
||||||
@@ -23,9 +24,7 @@ struct EaData
|
|||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return table +
|
return table + QLatin1Char(';') + column + QLatin1Char(';') + type;
|
||||||
QLatin1Char(';') + column +
|
|
||||||
QLatin1Char(';') + type;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,52 +35,81 @@ struct FullQualifiedColumnInformation : public ColumnInformation
|
|||||||
bool usedForView = false;
|
bool usedForView = false;
|
||||||
QString columnNameView;
|
QString columnNameView;
|
||||||
|
|
||||||
QString getColumnNameView() const { return columnNameView.isEmpty() ? columnName : columnNameView; }
|
QString getColumnNameView() const
|
||||||
|
{
|
||||||
|
return columnNameView.isEmpty() ? columnName : columnNameView;
|
||||||
|
}
|
||||||
|
|
||||||
FullQualifiedColumnInformation() = default;
|
FullQualifiedColumnInformation() = default;
|
||||||
FullQualifiedColumnInformation(const ColumnInformation &ci, const QString &tableName)
|
|
||||||
: ColumnInformation(ci)
|
FullQualifiedColumnInformation(const ColumnInformation& ci, const QString& tableName)
|
||||||
, table(tableName)
|
: ColumnInformation(ci), table(tableName)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return table +
|
return table + QLatin1Char(';') + columnName + QLatin1Char(';') + datatype +
|
||||||
QLatin1Char(';') + columnName +
|
|
||||||
QLatin1Char(';') + datatype +
|
|
||||||
|
|
||||||
QLatin1Char(';') + (isPrimaryKey ? QLatin1String("true") : QLatin1String("false")) +
|
QLatin1Char(';') + (isPrimaryKey ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||||
QLatin1Char(';') + (isForeignKey ? QLatin1String("true") : QLatin1String("false")) +
|
(isForeignKey ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||||
QLatin1Char(';') + (usedForInsert ? QLatin1String("true") : QLatin1String("false")) +
|
(usedForInsert ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||||
QLatin1Char(';') + (usedForView ? QLatin1String("true") : QLatin1String("false"));
|
(usedForView ? QLatin1String("true") : QLatin1String("false"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DataTypeInfo
|
class DataTypeInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DataTypeInfo(const QString &name, bool isPod)
|
DataTypeInfo(const QString& name, bool isPod) : m_name(name), m_isPod(isPod) {}
|
||||||
: m_name(name)
|
|
||||||
, m_isPod(isPod)
|
|
||||||
{}
|
|
||||||
virtual ~DataTypeInfo() = default;
|
virtual ~DataTypeInfo() = default;
|
||||||
virtual QString name() const { return m_name; }
|
|
||||||
|
virtual QString name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
virtual QString idlType() const = 0;
|
virtual QString idlType() const = 0;
|
||||||
virtual QString ddsType() const = 0;
|
virtual QString ddsType() const = 0;
|
||||||
virtual QString sqlType() const = 0;
|
virtual QString sqlType() const = 0;
|
||||||
virtual QString cppType() 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,
|
virtual QString cppTypeConstRef() const
|
||||||
const QString &idlType,
|
{
|
||||||
StructBuilder *structBuilder,
|
return isPod() ? cppType() : QLatin1String("const ") + cppType() + QLatin1String(" &");
|
||||||
const QString &svcName = QString());
|
}
|
||||||
protected:
|
|
||||||
|
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 QString m_name;
|
||||||
const bool m_isPod;
|
const bool m_isPod;
|
||||||
};
|
};
|
||||||
@@ -91,22 +119,18 @@ struct IdlData : public IdlColumnInformation
|
|||||||
QSharedPointer<DataTypeInfo> dataTypeInfo;
|
QSharedPointer<DataTypeInfo> dataTypeInfo;
|
||||||
|
|
||||||
IdlData() = default;
|
IdlData() = default;
|
||||||
explicit IdlData(const IdlColumnInformation &ci)
|
|
||||||
: IdlColumnInformation(ci)
|
explicit IdlData(const IdlColumnInformation& ci) : IdlColumnInformation(ci) {}
|
||||||
{}
|
|
||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return name +
|
return name + QLatin1Char(';') + type +
|
||||||
QLatin1Char(';') + type +
|
|
||||||
|
|
||||||
QLatin1Char(';') + (isKey ? QLatin1String("true") : QLatin1String("false")) +
|
QLatin1Char(';') + (isKey ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||||
QLatin1Char(';') + (isOptional ? QLatin1String("true") : QLatin1String("false"));
|
(isOptional ? QLatin1String("true") : QLatin1String("false"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct CppData
|
struct CppData
|
||||||
{
|
{
|
||||||
QString structName;
|
QString structName;
|
||||||
@@ -131,16 +155,11 @@ struct CppData
|
|||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return structName +
|
return structName + QLatin1Char(';') + memberName + QLatin1Char(';') +
|
||||||
QLatin1Char(';') + memberName +
|
(usedForCppStruct ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') +
|
||||||
QLatin1Char(';') + (usedForCppStruct ? QLatin1String("true") : QLatin1String("false")) +
|
(isReadOnly ? QLatin1String("true") : QLatin1String("false")) + QLatin1Char(';') + type +
|
||||||
QLatin1Char(';') + (isReadOnly ? QLatin1String("true") : QLatin1String("false")) +
|
QLatin1Char(';') + toVariantPre + QLatin1Char(';') + toVariantPost + QLatin1Char(';') + fromVariantPre1 +
|
||||||
QLatin1Char(';') + type +
|
QLatin1Char(';') + fromVariantPre2 + QLatin1Char(';') + fromVariantPost;
|
||||||
QLatin1Char(';') + toVariantPre +
|
|
||||||
QLatin1Char(';') + toVariantPost +
|
|
||||||
QLatin1Char(';') + fromVariantPre1 +
|
|
||||||
QLatin1Char(';') + fromVariantPre2 +
|
|
||||||
QLatin1Char(';') + fromVariantPost;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -155,10 +174,9 @@ struct MemberInformation
|
|||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return ea.toString() + QLatin1Char(';') +
|
return ea.toString() + QLatin1Char(';') + db.toString() + QLatin1Char(';') + cpp.toString();
|
||||||
db.toString() + QLatin1Char(';') +
|
|
||||||
cpp.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEmpty() const
|
bool isEmpty() const
|
||||||
{
|
{
|
||||||
return ea.column.isEmpty();
|
return ea.column.isEmpty();
|
||||||
@@ -169,7 +187,7 @@ struct CompleteStructInformation
|
|||||||
{
|
{
|
||||||
QString structName;
|
QString structName;
|
||||||
QString viewName;
|
QString viewName;
|
||||||
QSet<QSharedPointer<TableInformation> > tables;
|
QSet<QSharedPointer<TableInformation>> tables;
|
||||||
QSharedPointer<TableInformation> primaryTable;
|
QSharedPointer<TableInformation> primaryTable;
|
||||||
QVector<MemberInformation> member;
|
QVector<MemberInformation> member;
|
||||||
QVector<DbNotifcationInformation> dbNotifications;
|
QVector<DbNotifcationInformation> dbNotifications;
|
||||||
@@ -188,23 +206,32 @@ struct CompleteTopicTypeInformation final : public TopicTypeInformationBase
|
|||||||
QVector<IdlData> members;
|
QVector<IdlData> members;
|
||||||
|
|
||||||
CompleteTopicTypeInformation() = default;
|
CompleteTopicTypeInformation() = default;
|
||||||
explicit CompleteTopicTypeInformation(const TopicTypeInformationBase &s)
|
|
||||||
: TopicTypeInformationBase(s)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool hasBaseValue() const { return !baseValueType.isEmpty(); }
|
explicit CompleteTopicTypeInformation(const TopicTypeInformationBase& s) : TopicTypeInformationBase(s) {}
|
||||||
bool isValid() const { return TopicTypeInformationBase::isValid() && !members.isEmpty(); }
|
|
||||||
|
bool hasBaseValue() const
|
||||||
|
{
|
||||||
|
return !baseValueType.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return TopicTypeInformationBase::isValid() && !members.isEmpty();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct CompleteTableInformation : public TableInformation
|
struct CompleteTableInformation : public TableInformation
|
||||||
{
|
{
|
||||||
QVector<MemberInformation> columns;
|
QVector<MemberInformation> columns;
|
||||||
explicit CompleteTableInformation(const TableInformation &o)
|
|
||||||
: TableInformation(o)
|
explicit CompleteTableInformation(const TableInformation& o) : TableInformation(o) {}
|
||||||
{}
|
|
||||||
CompleteTableInformation() = default;
|
CompleteTableInformation() = default;
|
||||||
bool isEmpty() const { return columns.isEmpty(); }
|
|
||||||
|
bool isEmpty() const
|
||||||
|
{
|
||||||
|
return columns.isEmpty();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CODEGEN_BASE_EXPORT StructBuilder
|
class CODEGEN_BASE_EXPORT StructBuilder
|
||||||
@@ -214,43 +241,57 @@ class CODEGEN_BASE_EXPORT StructBuilder
|
|||||||
QSharedPointer<TableInformation> table;
|
QSharedPointer<TableInformation> table;
|
||||||
|
|
||||||
ColumnInformationEx() = default;
|
ColumnInformationEx() = default;
|
||||||
ColumnInformationEx(const ColumnInformation &o,
|
|
||||||
const QSharedPointer<TableInformation> &ti)
|
ColumnInformationEx(const ColumnInformation& o, const QSharedPointer<TableInformation>& ti)
|
||||||
: ColumnInformation(o)
|
: ColumnInformation(o), table(ti)
|
||||||
, table(ti)
|
{
|
||||||
{}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct ServiceTypeStruct
|
struct ServiceTypeStruct
|
||||||
{
|
{
|
||||||
QString service;
|
QString service;
|
||||||
QString type;
|
QString type;
|
||||||
bool bIsSequence = false;
|
bool bIsSequence = false;
|
||||||
bool isExternalType() const { return !service.isEmpty(); }
|
|
||||||
bool isSequence() const { return bIsSequence; }
|
bool isExternalType() const
|
||||||
QString fqType() const { return service + QStringLiteral("::") + type; }
|
{
|
||||||
|
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;
|
~StructBuilder() = default;
|
||||||
|
|
||||||
bool buildStructures();
|
bool buildStructures();
|
||||||
|
|
||||||
QVector<CompleteStructInformation> structInformations() const
|
QVector<CompleteStructInformation> structInformations() const
|
||||||
{
|
{
|
||||||
return m_structInfos;
|
return m_structInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<CompleteTopicTypeInformation> topicTypeInformations() const
|
QVector<CompleteTopicTypeInformation> topicTypeInformations() const
|
||||||
{
|
{
|
||||||
return m_topicTypeInfos;
|
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 topicTypeInformationByStructType(const QString& type, bool checkExternals = true);
|
||||||
CompleteTopicTypeInformation externalTopicTypeByStructType(const ServiceTypeStruct &sts);
|
CompleteTopicTypeInformation externalTopicTypeByStructType(const ServiceTypeStruct& sts);
|
||||||
|
|
||||||
QVector<EnumInformation> enumInformations() const
|
QVector<EnumInformation> enumInformations() const
|
||||||
{
|
{
|
||||||
@@ -277,49 +318,52 @@ public:
|
|||||||
return m_needPgArrayInclude;
|
return m_needPgArrayInclude;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompleteTableInformation completeTableInformation(const CompleteTopicTypeInformation &ctti);
|
CompleteTableInformation completeTableInformation(const CompleteTopicTypeInformation& ctti);
|
||||||
CompleteTableInformation getRecordingTopicTable(const QString &structName);
|
CompleteTableInformation getRecordingTopicTable(const QString& structName);
|
||||||
QMap<QString, CompleteTableInformation> getRecordingTopicTables();
|
QMap<QString, CompleteTableInformation> getRecordingTopicTables();
|
||||||
QVector<QSharedPointer<DataTypeInfo> > getSerializeFromToJsonTopics() const;
|
QVector<QSharedPointer<DataTypeInfo>> getSerializeFromToJsonTopics() const;
|
||||||
bool fixupQVariantConversions(MemberInformation &mi) const;
|
bool fixupQVariantConversions(MemberInformation& mi) const;
|
||||||
|
|
||||||
Q_REQUIRED_RESULT static QString firstCharLowercase(const QString &txt);
|
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 camelCaseString(const QString& in, bool bFirstUppercase = false);
|
||||||
Q_REQUIRED_RESULT static QString camelCaseToUnderline(const QString &in);
|
Q_REQUIRED_RESULT static QString camelCaseToUnderline(const QString& in);
|
||||||
|
|
||||||
bool buildJSonStructureInformationFromIdlData(const CompleteTopicTypeInformation &ctti);
|
bool buildJSonStructureInformationFromIdlData(const CompleteTopicTypeInformation& ctti);
|
||||||
QMap<QString, QVector<MemberInformation>> jsonStructureInformation() const { return m_jsonStructureInformation; }
|
|
||||||
|
|
||||||
private:
|
QMap<QString, QVector<MemberInformation>> jsonStructureInformation() const
|
||||||
bool handleEnum(const EnumInformation &ei);
|
{
|
||||||
bool handleTable(const ServiceStructInformation &ssi);
|
return m_jsonStructureInformation;
|
||||||
bool handleIdlStructInfo(const TopicTypeInformation &tti,
|
}
|
||||||
QVector<CompleteTopicTypeInformation> &destination,
|
|
||||||
const QString &svcName = QString());
|
|
||||||
bool loadExternalTopicType(const ServiceTypeStruct &sts);
|
|
||||||
|
|
||||||
bool getColumnsFromTable(const QString &tableName,
|
private:
|
||||||
QVector<ColumnInformationEx> &columns,
|
bool handleEnum(const EnumInformation& ei);
|
||||||
QVector<QString> &tableNames) const;
|
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 getColumnsFromTable(const QString& tableName, QVector<ColumnInformationEx>& columns,
|
||||||
bool fixupDatatypePoint2d(MemberInformation &memberInfo, QVector<MemberInformation> &members);
|
QVector<QString>& tableNames) const;
|
||||||
bool fixupDatatypePoint3d(MemberInformation &memberInfo, QVector<MemberInformation> &members);
|
|
||||||
bool fixupDatatypeIntegerArray(MemberInformation &memberInfo);
|
|
||||||
|
|
||||||
QVector<MemberInformation> buildDbTableInformationFromIdlData(const CompleteTopicTypeInformation &ctti,
|
bool fixupCustomDbDatatypes(MemberInformation& memberInfo, QVector<MemberInformation>& members);
|
||||||
const QString &tableName,
|
bool fixupDatatypePoint2d(MemberInformation& memberInfo, QVector<MemberInformation>& members);
|
||||||
const QString &columnNamePrefix,
|
bool fixupDatatypePoint3d(MemberInformation& memberInfo, QVector<MemberInformation>& members);
|
||||||
const QString &cppStructure);
|
bool fixupDatatypeIntegerArray(MemberInformation& memberInfo);
|
||||||
void addToSerializeFromToJsonTopics(const QSharedPointer<DataTypeInfo> &toAdd);
|
|
||||||
CompleteTableInformation getRecordingTopicTable(const CompleteTopicTypeInformation &ctti,
|
QVector<MemberInformation> buildDbTableInformationFromIdlData(const CompleteTopicTypeInformation& ctti,
|
||||||
const MemberInformation &miPrimaryKey);
|
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;
|
MemberInformation getRecordPrimaryKey() const;
|
||||||
|
|
||||||
ServiceTypeStruct extractServiceAndTypeFromTypename(const QString &type);
|
ServiceTypeStruct extractServiceAndTypeFromTypename(const QString& type);
|
||||||
|
|
||||||
void addToSqlTableInformation(const MemberInformation &mi);
|
void addToSqlTableInformation(const MemberInformation& mi);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
QVector<CompleteStructInformation> m_structInfos;
|
QVector<CompleteStructInformation> m_structInfos;
|
||||||
QVector<CompleteTopicTypeInformation> m_topicTypeInfos;
|
QVector<CompleteTopicTypeInformation> m_topicTypeInfos;
|
||||||
mutable QVector<CompleteTopicTypeInformation> m_externalTopicTypes;
|
mutable QVector<CompleteTopicTypeInformation> m_externalTopicTypes;
|
||||||
@@ -334,8 +378,8 @@ private:
|
|||||||
bool m_needPoint3d;
|
bool m_needPoint3d;
|
||||||
bool m_needPgArrayInclude;
|
bool m_needPgArrayInclude;
|
||||||
|
|
||||||
XmlReader *m_xmlReader;
|
XmlReader* m_xmlReader;
|
||||||
NGL::INGLLogger &m_logger;
|
NGL::INGLLogger& m_logger;
|
||||||
NGL::INGLLogger &m_loggerCSV;
|
NGL::INGLLogger& m_loggerCSV;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CodeGen
|
||||||
Executable → Regular
+96
-132
@@ -1,41 +1,36 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "XmlReader.h"
|
#include "XmlReader.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
|
#include <QFile>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <ngltools/ngltools_filesystem.h>
|
#include <ngltools/ngltools_filesystem.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
|
|
||||||
class XmlReaderException : public std::exception
|
class XmlReaderException : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit XmlReaderException(const QString &msg) noexcept
|
explicit XmlReaderException(const QString& msg) noexcept : m_msg(msg.toUtf8()) {}
|
||||||
: m_msg(msg.toUtf8())
|
|
||||||
{}
|
|
||||||
|
|
||||||
~XmlReaderException() = default;
|
~XmlReaderException() = default;
|
||||||
|
|
||||||
virtual const char *what() const noexcept
|
virtual const char* what() const noexcept
|
||||||
{
|
{
|
||||||
return m_msg.data();
|
return m_msg.data();
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
private:
|
||||||
const QByteArray m_msg;
|
const QByteArray m_msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
XmlReader::XmlReader() : m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
|
XmlReader::XmlReader() : m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
|
||||||
|
|
||||||
bool XmlReader::readServiceFile(const QString &svcFile,
|
bool XmlReader::readServiceFile(const QString& svcFile, const QString& idlServiceInfoFile, const XmlReader* parent)
|
||||||
const QString &idlServiceInfoFile,
|
|
||||||
const XmlReader *parent)
|
|
||||||
{
|
{
|
||||||
m_externalXmlInformations.clear();
|
m_externalXmlInformations.clear();
|
||||||
m_idlFiles.clear();
|
m_idlFiles.clear();
|
||||||
@@ -61,7 +56,6 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
m_prio = 0;
|
m_prio = 0;
|
||||||
m_svcDevMode = false;
|
m_svcDevMode = false;
|
||||||
|
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
m_idlFiles = parent->m_idlFiles;
|
m_idlFiles = parent->m_idlFiles;
|
||||||
@@ -70,11 +64,8 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
m_externalXmlInformations = parent->m_externalXmlInformations;
|
m_externalXmlInformations = parent->m_externalXmlInformations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
loadIdlInfofile(idlServiceInfoFile);
|
loadIdlInfofile(idlServiceInfoFile);
|
||||||
|
|
||||||
|
|
||||||
QFile f(svcFile);
|
QFile f(svcFile);
|
||||||
if (!f.exists())
|
if (!f.exists())
|
||||||
{
|
{
|
||||||
@@ -83,35 +74,27 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
}
|
}
|
||||||
if (!f.open(QIODevice::ReadOnly))
|
if (!f.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Can not open service file '") + svcFile +
|
m_errorString =
|
||||||
QLatin1String("' for reading: ") + f.errorString();
|
QLatin1String("Can not open service file '") + svcFile + QLatin1String("' for reading: ") + f.errorString();
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO_LOG(m_logger) << "SvcFile: " << svcFile;
|
INFO_LOG(m_logger) << "SvcFile: " << svcFile;
|
||||||
|
|
||||||
|
|
||||||
QString errMsg;
|
QString errMsg;
|
||||||
int errLine = 0;
|
int errLine = 0;
|
||||||
int errColumn = 0;
|
int errColumn = 0;
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
if (!doc.setContent(&f, &errMsg, &errLine, &errColumn))
|
if (!doc.setContent(&f, &errMsg, &errLine, &errColumn))
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing service file '") + svcFile + QLatin1String("': ") +
|
m_errorString = QLatin1String("Error parsing service file '") + svcFile + QLatin1String("': ") + errMsg +
|
||||||
errMsg + QLatin1String(" at ") + QString::number(errLine) +
|
QLatin1String(" at ") + QString::number(errLine) + QLatin1Char(':') +
|
||||||
QLatin1Char(':') + QString::number(errColumn);
|
QString::number(errColumn);
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QDomElement domRoot = doc.documentElement();
|
QDomElement domRoot = doc.documentElement();
|
||||||
if (!domRoot.hasAttribute(QStringLiteral("namespace")))
|
if (!domRoot.hasAttribute(QStringLiteral("namespace")))
|
||||||
{
|
{
|
||||||
@@ -126,8 +109,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
m_customRecordReplay = getAttributeBool(domRoot, QStringLiteral("customRecordReplay"), true, false);
|
m_customRecordReplay = getAttributeBool(domRoot, QStringLiteral("customRecordReplay"), true, false);
|
||||||
|
|
||||||
QString devModeStr = getAttribute(domRoot, QStringLiteral("devMode"), true);
|
QString devModeStr = getAttribute(domRoot, QStringLiteral("devMode"), true);
|
||||||
m_svcDevMode = devModeStr == QStringLiteral("1") ||
|
m_svcDevMode = devModeStr == QStringLiteral("1") || devModeStr == QStringLiteral("true");
|
||||||
devModeStr == QStringLiteral("true");
|
|
||||||
INFO_LOG(m_logger) << "devMode: " << m_svcDevMode;
|
INFO_LOG(m_logger) << "devMode: " << m_svcDevMode;
|
||||||
|
|
||||||
const QString groupNamesString = getAttribute(domRoot, QStringLiteral("groups"), true);
|
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));
|
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 &&
|
if (m_exerciseDependency != ExerciseDependency::Global &&
|
||||||
m_exerciseDependency != ExerciseDependency::GlobalAndExercise)
|
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";
|
<< " is not marked as exercise independent but should be started in group Core/Master";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO_LOG(m_logger) << "exerciseDependency: " << (int)m_exerciseDependency;
|
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();
|
m_prio = getAttribute(domRoot, QStringLiteral("prio"), 0).toInt();
|
||||||
}
|
}
|
||||||
@@ -163,7 +143,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseDBSserviceStructs(domRoot.firstChildElement(QStringLiteral("dbServiceStructs")));
|
parseDBSserviceStructs(domRoot.firstChildElement(QStringLiteral("dbServiceStructs")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing dbServiceStructs: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing dbServiceStructs: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -174,7 +154,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseDBTables(domRoot.firstChildElement(QStringLiteral("tables")));
|
parseDBTables(domRoot.firstChildElement(QStringLiteral("tables")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing dbtables: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing dbtables: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -185,7 +165,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseDBViews(domRoot.firstChildElement(QStringLiteral("views")));
|
parseDBViews(domRoot.firstChildElement(QStringLiteral("views")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing dbviews: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing dbviews: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -196,7 +176,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseEnumerations(domRoot.firstChildElement(QStringLiteral("enumerations")));
|
parseEnumerations(domRoot.firstChildElement(QStringLiteral("enumerations")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing enumerations: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing enumerations: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -207,7 +187,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseCustomDtcFunctions(domRoot.firstChildElement(QStringLiteral("customDtcFunctions")));
|
parseCustomDtcFunctions(domRoot.firstChildElement(QStringLiteral("customDtcFunctions")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing custom dtc functions: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing custom dtc functions: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -218,7 +198,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseTopicTypes(domRoot.firstChildElement(QStringLiteral("topicTypes")));
|
parseTopicTypes(domRoot.firstChildElement(QStringLiteral("topicTypes")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing idl strucs: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing idl strucs: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -229,7 +209,7 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
{
|
{
|
||||||
parseFunctionTopics(domRoot.firstChildElement(QStringLiteral("functionTopics")));
|
parseFunctionTopics(domRoot.firstChildElement(QStringLiteral("functionTopics")));
|
||||||
}
|
}
|
||||||
catch (const XmlReaderException &ex)
|
catch (const XmlReaderException& ex)
|
||||||
{
|
{
|
||||||
m_errorString = QLatin1String("Error parsing function topics: ") + QLatin1String(ex.what());
|
m_errorString = QLatin1String("Error parsing function topics: ") + QLatin1String(ex.what());
|
||||||
ERROR_LOG(m_logger) << m_errorString;
|
ERROR_LOG(m_logger) << m_errorString;
|
||||||
@@ -239,23 +219,20 @@ bool XmlReader::readServiceFile(const QString &svcFile,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString XmlReader::getAttribute(const QDomElement &element,
|
QString XmlReader::getAttribute(const QDomElement& element, const QString& attributeName, bool bOptional)
|
||||||
const QString &attributeName,
|
|
||||||
bool bOptional)
|
|
||||||
{
|
{
|
||||||
if (!element.hasAttribute(attributeName))
|
if (!element.hasAttribute(attributeName))
|
||||||
{
|
{
|
||||||
if (bOptional)
|
if (bOptional)
|
||||||
return QString();
|
return QString();
|
||||||
throw XmlReaderException(QLatin1String("Element ") + element.tagName() +
|
throw XmlReaderException(QLatin1String("Element ") + element.tagName() + QLatin1String(" has no attribute ") +
|
||||||
QLatin1String(" has no attribute ") + attributeName);
|
attributeName);
|
||||||
}
|
}
|
||||||
return element.attribute(attributeName);
|
return element.attribute(attributeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlReader::getAttributeBool(const QDomElement &element,
|
bool XmlReader::getAttributeBool(const QDomElement& element, const QString& attributeName, bool bOptional,
|
||||||
const QString &attributeName,
|
bool defaultValue)
|
||||||
bool bOptional, bool defaultValue)
|
|
||||||
{
|
{
|
||||||
QString str = getAttribute(element, attributeName, bOptional);
|
QString str = getAttribute(element, attributeName, bOptional);
|
||||||
if (str.isEmpty())
|
if (str.isEmpty())
|
||||||
@@ -267,9 +244,8 @@ bool XmlReader::getAttributeBool(const QDomElement &element,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int XmlReader::getAttributeInt(const QDomElement &element,
|
int XmlReader::getAttributeInt(const QDomElement& element, const QString& attributeName, bool bOptional,
|
||||||
const QString &attributeName,
|
int defaultValue)
|
||||||
bool bOptional, int defaultValue)
|
|
||||||
{
|
{
|
||||||
QString str = getAttribute(element, attributeName, bOptional);
|
QString str = getAttribute(element, attributeName, bOptional);
|
||||||
if (str.isEmpty())
|
if (str.isEmpty())
|
||||||
@@ -279,19 +255,18 @@ int XmlReader::getAttributeInt(const QDomElement &element,
|
|||||||
if (!bOk)
|
if (!bOk)
|
||||||
{
|
{
|
||||||
|
|
||||||
ret = str.toUInt(&bOk,16);
|
ret = str.toUInt(&bOk, 16);
|
||||||
if(!bOk)
|
if (!bOk)
|
||||||
throw XmlReaderException(QLatin1String("Can not parse int value: ") + str);
|
throw XmlReaderException(QLatin1String("Can not parse int value: ") + str);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlReader::parseDBSserviceStructs(const QDomElement &rootElement)
|
void XmlReader::parseDBSserviceStructs(const QDomElement& rootElement)
|
||||||
{
|
{
|
||||||
if (rootElement.isNull())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
QDomElement domDbStruct = rootElement.firstChildElement(QStringLiteral("serviceStruct"));
|
QDomElement domDbStruct = rootElement.firstChildElement(QStringLiteral("serviceStruct"));
|
||||||
while (!domDbStruct.isNull())
|
while (!domDbStruct.isNull())
|
||||||
{
|
{
|
||||||
@@ -320,7 +295,6 @@ void XmlReader::parseDBSserviceStructs(const QDomElement &rootElement)
|
|||||||
}
|
}
|
||||||
std::sort(m_structsToGenerate.begin(), m_structsToGenerate.end());
|
std::sort(m_structsToGenerate.begin(), m_structsToGenerate.end());
|
||||||
|
|
||||||
|
|
||||||
domDbStruct = rootElement.firstChildElement(QStringLiteral("table"));
|
domDbStruct = rootElement.firstChildElement(QStringLiteral("table"));
|
||||||
while (!domDbStruct.isNull())
|
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)";
|
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())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
@@ -345,7 +319,8 @@ void XmlReader::parseDBTables(const QDomElement &rootElement)
|
|||||||
ti->name = getAttribute(domDbTable, QStringLiteral("name"));
|
ti->name = getAttribute(domDbTable, QStringLiteral("name"));
|
||||||
ti->structName = QLatin1String("t_") + ti->name;
|
ti->structName = QLatin1String("t_") + ti->name;
|
||||||
ti->comment = getAttribute(domDbTable, QStringLiteral("comment"), true);
|
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"));
|
QDomElement domColumn = domDbTable.firstChildElement(QStringLiteral("column"));
|
||||||
while (!domColumn.isNull())
|
while (!domColumn.isNull())
|
||||||
@@ -375,7 +350,7 @@ void XmlReader::parseDBTables(const QDomElement &rootElement)
|
|||||||
INFO_LOG(m_logger) << "Read " << m_tables.size() << " database table(s)";
|
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())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
@@ -390,11 +365,11 @@ void XmlReader::parseDBViews(const QDomElement &rootElement)
|
|||||||
vi->baseTable = getAttribute(domDbView, QStringLiteral("base"));
|
vi->baseTable = getAttribute(domDbView, QStringLiteral("base"));
|
||||||
vi->comment = getAttribute(domDbView, QStringLiteral("comment"), true);
|
vi->comment = getAttribute(domDbView, QStringLiteral("comment"), true);
|
||||||
vi->filter = getAttribute(domDbView, QStringLiteral("filter"));
|
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;
|
DEBUG_LOG(m_logger) << "Base table = " << vi->baseTable;
|
||||||
|
|
||||||
|
|
||||||
m_views.insert(vi->name, vi);
|
m_views.insert(vi->name, vi);
|
||||||
|
|
||||||
domDbView = domDbView.nextSiblingElement(domDbView.tagName());
|
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)";
|
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())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
@@ -434,7 +409,7 @@ void XmlReader::parseEnumerations(const QDomElement &rootElement)
|
|||||||
INFO_LOG(m_logger) << "Read " << m_enumerations.size() << " enumeration(s)";
|
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())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
@@ -454,14 +429,11 @@ void XmlReader::parseCustomDtcFunctions(const QDomElement &rootElement)
|
|||||||
INFO_LOG(m_logger) << "Read " << m_enumerations.size() << " customDtcFunction(s)";
|
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())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
QDomElement domIdlStruct = rootElement.firstChildElement(QStringLiteral("topicType"));
|
QDomElement domIdlStruct = rootElement.firstChildElement(QStringLiteral("topicType"));
|
||||||
while (!domIdlStruct.isNull())
|
while (!domIdlStruct.isNull())
|
||||||
{
|
{
|
||||||
@@ -469,7 +441,6 @@ void XmlReader::parseTopicTypes(const QDomElement &rootElement)
|
|||||||
isi.name = getAttribute(domIdlStruct, QStringLiteral("name"));
|
isi.name = getAttribute(domIdlStruct, QStringLiteral("name"));
|
||||||
isi.baseValueType = getAttribute(domIdlStruct, QStringLiteral("baseValueType"), true);
|
isi.baseValueType = getAttribute(domIdlStruct, QStringLiteral("baseValueType"), true);
|
||||||
|
|
||||||
|
|
||||||
const QStringList sl = isi.baseValueType.split(QStringLiteral("::"));
|
const QStringList sl = isi.baseValueType.split(QStringLiteral("::"));
|
||||||
if (sl.size() == 2)
|
if (sl.size() == 2)
|
||||||
loadExternalTopicType(sl.at(0), sl.at(1));
|
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);
|
const QString tmp = getAttribute(domIdlStruct, QStringLiteral("extensibility"), true);
|
||||||
|
|
||||||
#ifdef RTI_HEADER_AVAILABLE
|
#ifdef RTI_HEADER_AVAILABLE
|
||||||
if (tmp.compare(QLatin1String("FINAL"), Qt::CaseInsensitive) == 0) isi.extensibility = dds::core::xtypes::ExtensibilityKind::FINAL;
|
if (tmp.compare(QLatin1String("FINAL"), Qt::CaseInsensitive) == 0)
|
||||||
if (tmp.compare(QLatin1String("MUTABLE"), Qt::CaseInsensitive) == 0) isi.extensibility = dds::core::xtypes::ExtensibilityKind::MUTABLE;
|
isi.extensibility = dds::core::xtypes::ExtensibilityKind::FINAL;
|
||||||
if (tmp.compare(QLatin1String("EXTENSIBLE"), Qt::CaseInsensitive) == 0) isi.extensibility = dds::core::xtypes::ExtensibilityKind::EXTENSIBLE;
|
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
|
#else
|
||||||
// RTI not available - skip extensibility parsing
|
// RTI not available - skip extensibility parsing
|
||||||
Q_UNUSED(tmp)
|
Q_UNUSED(tmp)
|
||||||
@@ -502,22 +476,19 @@ void XmlReader::parseTopicTypes(const QDomElement &rootElement)
|
|||||||
domColumn = domColumn.nextSiblingElement(domColumn.tagName());
|
domColumn = domColumn.nextSiblingElement(domColumn.tagName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_idlStructsToGenerate.insert(isi.name, isi);
|
m_idlStructsToGenerate.insert(isi.name, isi);
|
||||||
|
|
||||||
domIdlStruct = domIdlStruct.nextSiblingElement(domIdlStruct.tagName());
|
domIdlStruct = domIdlStruct.nextSiblingElement(domIdlStruct.tagName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INFO_LOG(m_logger) << "Read " << m_idlStructsToGenerate.size() << " idl struct(s)";
|
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())
|
if (rootElement.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
QDomElement domFunctionTopic = rootElement.firstChildElement(QStringLiteral("functionTopic"));
|
QDomElement domFunctionTopic = rootElement.firstChildElement(QStringLiteral("functionTopic"));
|
||||||
while (!domFunctionTopic.isNull())
|
while (!domFunctionTopic.isNull())
|
||||||
{
|
{
|
||||||
@@ -534,7 +505,7 @@ void XmlReader::parseFunctionTopics(const QDomElement &rootElement)
|
|||||||
domFunctionTopic = domFunctionTopic.nextSiblingElement(domFunctionTopic.tagName());
|
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("::"));
|
const QStringList sl1 = ft.requestTopicType.split(QStringLiteral("::"));
|
||||||
if (sl1.size() == 2)
|
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;
|
ColumnInformation ci;
|
||||||
|
|
||||||
@@ -565,13 +536,13 @@ ColumnInformation XmlReader::parseTableColumn(const QDomElement &column, const Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ci.columnName.toLower() != ci.columnName)
|
if (ci.columnName.toLower() != ci.columnName)
|
||||||
WARNING_LOG(m_logger) << "Column " << ci.columnName << " in Table "
|
WARNING_LOG(m_logger) << "Column " << ci.columnName << " in Table " << tableName
|
||||||
<< tableName << " has has upper-case chars which is not allowed!";
|
<< " has has upper-case chars which is not allowed!";
|
||||||
|
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
IdlColumnInformation XmlReader::parseIdlStructColumn(const QDomElement &column) const
|
IdlColumnInformation XmlReader::parseIdlStructColumn(const QDomElement& column) const
|
||||||
{
|
{
|
||||||
IdlColumnInformation ci;
|
IdlColumnInformation ci;
|
||||||
|
|
||||||
@@ -585,7 +556,7 @@ IdlColumnInformation XmlReader::parseIdlStructColumn(const QDomElement &column)
|
|||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ForeignKeyInformation> XmlReader::parseForeignKey(const QDomElement &foreignKey) const
|
QSharedPointer<ForeignKeyInformation> XmlReader::parseForeignKey(const QDomElement& foreignKey) const
|
||||||
{
|
{
|
||||||
QSharedPointer<ForeignKeyInformation> fk(new ForeignKeyInformation);
|
QSharedPointer<ForeignKeyInformation> fk(new ForeignKeyInformation);
|
||||||
|
|
||||||
@@ -611,8 +582,8 @@ QSharedPointer<ForeignKeyInformation> XmlReader::parseForeignKey(const QDomEleme
|
|||||||
return fk;
|
return fk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString &foreignKeyName,
|
ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString& foreignKeyName,
|
||||||
const QDomElement &endpoint) const
|
const QDomElement& endpoint) const
|
||||||
{
|
{
|
||||||
if (endpoint.isNull())
|
if (endpoint.isNull())
|
||||||
throw XmlReaderException(QLatin1String("No endpoint for foreign key ") + foreignKeyName);
|
throw XmlReaderException(QLatin1String("No endpoint for foreign key ") + foreignKeyName);
|
||||||
@@ -620,7 +591,7 @@ ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString
|
|||||||
ForeignKeyInformation::Endpoint fkEndpoint;
|
ForeignKeyInformation::Endpoint fkEndpoint;
|
||||||
|
|
||||||
fkEndpoint.service = getAttribute(endpoint, QStringLiteral("service"), true);
|
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.schema = getAttribute(endpoint, QStringLiteral("schema"), true);
|
||||||
fkEndpoint.tableName = getAttribute(endpoint, QStringLiteral("table"));
|
fkEndpoint.tableName = getAttribute(endpoint, QStringLiteral("table"));
|
||||||
fkEndpoint.columnName = getAttribute(endpoint, QStringLiteral("column"));
|
fkEndpoint.columnName = getAttribute(endpoint, QStringLiteral("column"));
|
||||||
@@ -628,7 +599,7 @@ ForeignKeyInformation::Endpoint XmlReader::parseForeignKeyEndpoint(const QString
|
|||||||
return fkEndpoint;
|
return fkEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstraintInformation XmlReader::parseConstraint(const QDomElement &constraint) const
|
ConstraintInformation XmlReader::parseConstraint(const QDomElement& constraint) const
|
||||||
{
|
{
|
||||||
ConstraintInformation ret;
|
ConstraintInformation ret;
|
||||||
|
|
||||||
@@ -650,7 +621,7 @@ ConstraintInformation XmlReader::parseConstraint(const QDomElement &constraint)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElement &customFunc,
|
CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElement& customFunc,
|
||||||
CustomServiceFunctionInformation::Type funcType) const
|
CustomServiceFunctionInformation::Type funcType) const
|
||||||
{
|
{
|
||||||
CustomServiceFunctionInformation ret;
|
CustomServiceFunctionInformation ret;
|
||||||
@@ -673,7 +644,6 @@ CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElemen
|
|||||||
paramName.append(QLatin1String(" = ") + paramDefault);
|
paramName.append(QLatin1String(" = ") + paramDefault);
|
||||||
paramHelper[pos] = qMakePair(paramName, paramType);
|
paramHelper[pos] = qMakePair(paramName, paramType);
|
||||||
domParam = domParam.nextSiblingElement(domParam.tagName());
|
domParam = domParam.nextSiblingElement(domParam.tagName());
|
||||||
|
|
||||||
}
|
}
|
||||||
ret.paramNames.reserve(paramHelper.size());
|
ret.paramNames.reserve(paramHelper.size());
|
||||||
ret.paramTypes.reserve(paramHelper.size());
|
ret.paramTypes.reserve(paramHelper.size());
|
||||||
@@ -693,44 +663,45 @@ CustomServiceFunctionInformation XmlReader::parseCustomFunction(const QDomElemen
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
DbNotifcationInformation XmlReader::parseDbNotification(const QDomElement &customFunc) const
|
DbNotifcationInformation XmlReader::parseDbNotification(const QDomElement& customFunc) const
|
||||||
{
|
{
|
||||||
DbNotifcationInformation ret(parseCustomFunction(customFunc, CustomServiceFunctionInformation::Type::DbNotify));
|
DbNotifcationInformation ret(parseCustomFunction(customFunc, CustomServiceFunctionInformation::Type::DbNotify));
|
||||||
|
|
||||||
const QString attribute(getAttribute(customFunc, QStringLiteral("notificationTypes")).toLower());
|
const QString attribute(getAttribute(customFunc, QStringLiteral("notificationTypes")).toLower());
|
||||||
const QStringList nfTypes = attribute.split(QLatin1Char(','));
|
const QStringList nfTypes = attribute.split(QLatin1Char(','));
|
||||||
static const QMap<QString, DbNotifcationInformation::NotificationType> s_nfTypeMap =
|
static const QMap<QString, DbNotifcationInformation::NotificationType> s_nfTypeMap = {
|
||||||
{
|
{QLatin1String("beforeinsert"), DbNotifcationInformation::NotificationType::BeforeInsert},
|
||||||
{ QLatin1String("beforeinsert"), DbNotifcationInformation::NotificationType::BeforeInsert },
|
{QLatin1String("afterinsert"), DbNotifcationInformation::NotificationType::AfterInsert},
|
||||||
{ QLatin1String("afterinsert"), DbNotifcationInformation::NotificationType::AfterInsert },
|
{QLatin1String("beforeupdate"), DbNotifcationInformation::NotificationType::BeforeUpdate},
|
||||||
{ QLatin1String("beforeupdate"), DbNotifcationInformation::NotificationType::BeforeUpdate },
|
{QLatin1String("afterupdate"), DbNotifcationInformation::NotificationType::AfterUpdate},
|
||||||
{ QLatin1String("afterupdate"), DbNotifcationInformation::NotificationType::AfterUpdate },
|
{QLatin1String("beforedelete"), DbNotifcationInformation::NotificationType::BeforeDelete},
|
||||||
{ QLatin1String("beforedelete"), DbNotifcationInformation::NotificationType::BeforeDelete },
|
{QLatin1String("afterdelete"), DbNotifcationInformation::NotificationType::AfterDelete}};
|
||||||
{ QLatin1String("afterdelete"), DbNotifcationInformation::NotificationType::AfterDelete }
|
for (const QString& nfType : nfTypes)
|
||||||
};
|
|
||||||
for (const QString &nfType : nfTypes)
|
|
||||||
{
|
{
|
||||||
const auto it = s_nfTypeMap.find(nfType);
|
const auto it = s_nfTypeMap.find(nfType);
|
||||||
if (it == s_nfTypeMap.end())
|
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();
|
ret.notificationType += it.value();
|
||||||
}
|
}
|
||||||
if (ret.notificationType.isEmpty())
|
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)
|
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;
|
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;
|
DEBUG_LOG(m_logger) << "externalServiceName: " << externalServiceName << ", topicTypeName: " << topicTypeName;
|
||||||
|
|
||||||
if (!loadExternalService(externalServiceName))
|
if (!loadExternalService(externalServiceName))
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Could not find service " << externalServiceName
|
WARNING_LOG(m_logger) << "Could not find service " << externalServiceName << " referenced by external topic "
|
||||||
<< " referenced by external topic " << topicTypeName;
|
<< topicTypeName;
|
||||||
return TopicTypeInformation();
|
return TopicTypeInformation();
|
||||||
}
|
}
|
||||||
auto extXmlReader = m_externalXmlInformations.value(externalServiceName);
|
auto extXmlReader = m_externalXmlInformations.value(externalServiceName);
|
||||||
@@ -748,13 +719,13 @@ TopicTypeInformation XmlReader::loadExternalTopicType(const QString &externalSer
|
|||||||
m_usedServices[externalServiceName] = true;
|
m_usedServices[externalServiceName] = true;
|
||||||
return tti;
|
return tti;
|
||||||
}
|
}
|
||||||
WARNING_LOG(m_logger) << "Could not find topic " << topicTypeName
|
WARNING_LOG(m_logger) << "Could not find topic " << topicTypeName << " in external service definition for service "
|
||||||
<< " in external service definition for service "
|
|
||||||
<< externalServiceName;
|
<< externalServiceName;
|
||||||
return TopicTypeInformation();
|
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;
|
DEBUG_LOG(m_logger) << "externalServiceName: " << externalServiceName << ", topicTypeName: " << enumName;
|
||||||
|
|
||||||
@@ -772,7 +743,7 @@ EnumInformation XmlReader::getExternalEnumeration(const QString &externalService
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QVector<EnumInformation> enums = extXmlReader->getEnumerations();
|
const QVector<EnumInformation> enums = extXmlReader->getEnumerations();
|
||||||
for (const EnumInformation &ei : enums)
|
for (const EnumInformation& ei : enums)
|
||||||
{
|
{
|
||||||
if (ei.enumName == enumName)
|
if (ei.enumName == enumName)
|
||||||
{
|
{
|
||||||
@@ -782,15 +753,13 @@ EnumInformation XmlReader::getExternalEnumeration(const QString &externalService
|
|||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Could not find enumeration " << enumName
|
WARNING_LOG(m_logger) << "Could not find enumeration " << enumName << " in external service definition for '"
|
||||||
<< " in external service definition for '"
|
|
||||||
<< externalServiceName << "'";
|
<< externalServiceName << "'";
|
||||||
}
|
}
|
||||||
return EnumInformation();
|
return EnumInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool XmlReader::loadExternalService(const QString& serviceName)
|
||||||
bool XmlReader::loadExternalService(const QString &serviceName)
|
|
||||||
{
|
{
|
||||||
if (serviceName == getServiceNamespace())
|
if (serviceName == getServiceNamespace())
|
||||||
return false;
|
return false;
|
||||||
@@ -801,7 +770,7 @@ bool XmlReader::loadExternalService(const QString &serviceName)
|
|||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
{
|
{
|
||||||
const QVector<QString> dirs = NGL::directories(NGL::FileType::ConfigFile);
|
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);
|
QDirIterator dirIt(dirname + QStringLiteral("/xml"), QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
|
||||||
while (dirIt.hasNext())
|
while (dirIt.hasNext())
|
||||||
@@ -824,8 +793,7 @@ bool XmlReader::loadExternalService(const QString &serviceName)
|
|||||||
auto extXmlReader = QSharedPointer<XmlReader>(new XmlReader);
|
auto extXmlReader = QSharedPointer<XmlReader>(new XmlReader);
|
||||||
if (!extXmlReader->readServiceFile(fileName, QString(), this))
|
if (!extXmlReader->readServiceFile(fileName, QString(), this))
|
||||||
{
|
{
|
||||||
WARNING_LOG(m_logger) << "Error reading service file " << fileName
|
WARNING_LOG(m_logger) << "Error reading service file " << fileName << " for service " << serviceName;
|
||||||
<< " for service " << serviceName;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_externalXmlInformations[serviceName] = extXmlReader;
|
m_externalXmlInformations[serviceName] = extXmlReader;
|
||||||
@@ -834,7 +802,7 @@ bool XmlReader::loadExternalService(const QString &serviceName)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlReader::loadIdlInfofile(const QString &idlServiceInfoFile)
|
void XmlReader::loadIdlInfofile(const QString& idlServiceInfoFile)
|
||||||
{
|
{
|
||||||
if (idlServiceInfoFile.isEmpty())
|
if (idlServiceInfoFile.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -845,7 +813,7 @@ void XmlReader::loadIdlInfofile(const QString &idlServiceInfoFile)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QList<QByteArray> files = f.readAll().split('\n');
|
const QList<QByteArray> files = f.readAll().split('\n');
|
||||||
for (const QByteArray &filePath : files)
|
for (const QByteArray& filePath : files)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (filePath.startsWith("--") || filePath.trimmed().isEmpty())
|
if (filePath.startsWith("--") || filePath.trimmed().isEmpty())
|
||||||
@@ -871,38 +839,35 @@ void XmlReader::loadIdlInfofile(const QString &idlServiceInfoFile)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString XmlReader::getIdlFileForService(const QMap<QString, QString> &data,
|
QString XmlReader::getIdlFileForService(const QMap<QString, QString>& data, const QString& serviceName) const
|
||||||
const QString &serviceName) const
|
|
||||||
{
|
{
|
||||||
const QString serviceAbbr = serviceNameAbbreviation(serviceName);
|
const QString serviceAbbr = serviceNameAbbreviation(serviceName);
|
||||||
return data.value(serviceAbbr);
|
return data.value(serviceAbbr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString XmlReader::serviceNameAbbreviation(const QString& serviceName) const
|
||||||
QString XmlReader::serviceNameAbbreviation(const QString &serviceName) const
|
|
||||||
{
|
{
|
||||||
return m_fullServiceName2Abbreviation.value(serviceName);
|
return m_fullServiceName2Abbreviation.value(serviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlReader::getServiceNameInfoFromFilePath(const QStringList &parts)
|
void XmlReader::getServiceNameInfoFromFilePath(const QStringList& parts)
|
||||||
{
|
{
|
||||||
if (parts.size() < 2)
|
if (parts.size() < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
const QString abbreviation = parts.last().split(QLatin1Char('.')).first().split(QLatin1Char('_')).first();
|
const QString abbreviation = parts.last().split(QLatin1Char('.')).first().split(QLatin1Char('_')).first();
|
||||||
const QString serviceName = parts.at(parts.size() - 2);
|
const QString serviceName = parts.at(parts.size() - 2);
|
||||||
DEBUG_LOG(m_logger) << "serviceName: " << serviceName << " = " << abbreviation;
|
DEBUG_LOG(m_logger) << "serviceName: " << serviceName << " = " << abbreviation;
|
||||||
m_fullServiceName2Abbreviation[serviceName] = abbreviation;
|
m_fullServiceName2Abbreviation[serviceName] = abbreviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExerciseDependency XmlReader::string2ExerciseDependency(const QString &str)
|
ExerciseDependency XmlReader::string2ExerciseDependency(const QString& str)
|
||||||
{
|
{
|
||||||
if (str.isEmpty())
|
if (str.isEmpty())
|
||||||
return ExerciseDependency::Undefined;
|
return ExerciseDependency::Undefined;
|
||||||
const QStringList sd = str.toLower().split(QLatin1Char(','));
|
const QStringList sd = str.toLower().split(QLatin1Char(','));
|
||||||
int ret = ExerciseDependency::Undefined;
|
int ret = ExerciseDependency::Undefined;
|
||||||
for (const QString &s : sd)
|
for (const QString& s : sd)
|
||||||
{
|
{
|
||||||
if (s == QLatin1String("global"))
|
if (s == QLatin1String("global"))
|
||||||
ret |= ExerciseDependency::Global;
|
ret |= ExerciseDependency::Global;
|
||||||
@@ -914,7 +879,7 @@ ExerciseDependency XmlReader::string2ExerciseDependency(const QString &str)
|
|||||||
return static_cast<ExerciseDependency>(ret);
|
return static_cast<ExerciseDependency>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString XmlReader::serviceNamespaceFromFile(const QString &fn)
|
QString XmlReader::serviceNamespaceFromFile(const QString& fn)
|
||||||
{
|
{
|
||||||
QFile f(fn);
|
QFile f(fn);
|
||||||
if (!f.open(QIODevice::ReadOnly))
|
if (!f.open(QIODevice::ReadOnly))
|
||||||
@@ -928,4 +893,3 @@ QString XmlReader::serviceNamespaceFromFile(const QString &fn)
|
|||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Executable → Regular
+137
-117
@@ -31,13 +31,7 @@ class QDomElement;
|
|||||||
namespace CodeGen
|
namespace CodeGen
|
||||||
{
|
{
|
||||||
|
|
||||||
enum ExerciseDependency
|
enum ExerciseDependency { Undefined = 0, Global = 0x1, Exercise = 0x2, GlobalAndExercise = 0x3 };
|
||||||
{
|
|
||||||
Undefined = 0,
|
|
||||||
Global = 0x1,
|
|
||||||
Exercise = 0x2,
|
|
||||||
GlobalAndExercise = 0x3
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EnumKeyValuePair
|
struct EnumKeyValuePair
|
||||||
{
|
{
|
||||||
@@ -52,7 +46,10 @@ struct EnumInformation
|
|||||||
QString serviceName;
|
QString serviceName;
|
||||||
QVector<EnumKeyValuePair> values;
|
QVector<EnumKeyValuePair> values;
|
||||||
|
|
||||||
bool isValid() const { return !enumName.isEmpty(); }
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return !enumName.isEmpty();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColumnInformation
|
struct ColumnInformation
|
||||||
@@ -82,7 +79,6 @@ struct IdlColumnInformation
|
|||||||
bool isTranslatable = false;
|
bool isTranslatable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ForeignKeyInformation
|
struct ForeignKeyInformation
|
||||||
{
|
{
|
||||||
struct Endpoint
|
struct Endpoint
|
||||||
@@ -97,8 +93,7 @@ struct ForeignKeyInformation
|
|||||||
QString name;
|
QString name;
|
||||||
Endpoint source;
|
Endpoint source;
|
||||||
Endpoint destination;
|
Endpoint destination;
|
||||||
enum class OnDeleteAction
|
enum class OnDeleteAction {
|
||||||
{
|
|
||||||
NoAction,
|
NoAction,
|
||||||
Cascade,
|
Cascade,
|
||||||
Restrict,
|
Restrict,
|
||||||
@@ -115,40 +110,23 @@ struct CustomServiceFunctionInformation
|
|||||||
bool isConst = false;
|
bool isConst = false;
|
||||||
QVector<QString> paramTypes;
|
QVector<QString> paramTypes;
|
||||||
QVector<QString> paramNames;
|
QVector<QString> paramNames;
|
||||||
enum class Type
|
enum class Type { Db, DbNotify, Dtc } type = Type::Db;
|
||||||
{
|
|
||||||
Db,
|
|
||||||
DbNotify,
|
|
||||||
Dtc
|
|
||||||
} type = Type::Db;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DbNotifcationInformation : public CustomServiceFunctionInformation
|
struct DbNotifcationInformation : public CustomServiceFunctionInformation
|
||||||
{
|
{
|
||||||
DbNotifcationInformation() = default;
|
DbNotifcationInformation() = default;
|
||||||
explicit DbNotifcationInformation(const CustomServiceFunctionInformation &d)
|
|
||||||
: CustomServiceFunctionInformation(d)
|
explicit DbNotifcationInformation(const CustomServiceFunctionInformation& d) : CustomServiceFunctionInformation(d)
|
||||||
{}
|
|
||||||
enum class NotificationType
|
|
||||||
{
|
{
|
||||||
BeforeInsert,
|
}
|
||||||
AfterInsert,
|
enum class NotificationType { BeforeInsert, AfterInsert, BeforeUpdate, AfterUpdate, BeforeDelete, AfterDelete };
|
||||||
BeforeUpdate,
|
|
||||||
AfterUpdate,
|
|
||||||
BeforeDelete,
|
|
||||||
AfterDelete
|
|
||||||
};
|
|
||||||
QVector<NotificationType> notificationType;
|
QVector<NotificationType> notificationType;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConstraintInformation
|
struct ConstraintInformation
|
||||||
{
|
{
|
||||||
enum struct Type
|
enum struct Type { unknown = 0x00, unique = 0x01, index = 0x02 } type = Type::unknown;
|
||||||
{
|
|
||||||
unknown = 0x00,
|
|
||||||
unique = 0x01,
|
|
||||||
index = 0x02
|
|
||||||
} type = Type::unknown;
|
|
||||||
QString name;
|
QString name;
|
||||||
QStringList affectedColumns;
|
QStringList affectedColumns;
|
||||||
};
|
};
|
||||||
@@ -159,17 +137,16 @@ struct TableInformation
|
|||||||
QString structName;
|
QString structName;
|
||||||
QString comment;
|
QString comment;
|
||||||
QVector<ColumnInformation> plainColumns;
|
QVector<ColumnInformation> plainColumns;
|
||||||
QVector<QSharedPointer<ForeignKeyInformation> > foreignKeys;
|
QVector<QSharedPointer<ForeignKeyInformation>> foreignKeys;
|
||||||
QVector<ConstraintInformation> constraints;
|
QVector<ConstraintInformation> constraints;
|
||||||
ExerciseDependency exerciseDependency = ExerciseDependency::Undefined;
|
ExerciseDependency exerciseDependency = ExerciseDependency::Undefined;
|
||||||
|
|
||||||
QSharedPointer<ForeignKeyInformation> fkInformationForColumn(const QString &tableName,
|
QSharedPointer<ForeignKeyInformation> fkInformationForColumn(const QString& tableName,
|
||||||
const QString &columnName) const
|
const QString& columnName) const
|
||||||
{
|
{
|
||||||
for (const QSharedPointer<ForeignKeyInformation> &fki : foreignKeys)
|
for (const QSharedPointer<ForeignKeyInformation>& fki : foreignKeys)
|
||||||
{
|
{
|
||||||
if (fki->source.columnName == columnName &&
|
if (fki->source.columnName == columnName && fki->source.tableName == tableName)
|
||||||
fki->source.tableName == tableName)
|
|
||||||
return fki;
|
return fki;
|
||||||
}
|
}
|
||||||
return QSharedPointer<ForeignKeyInformation>();
|
return QSharedPointer<ForeignKeyInformation>();
|
||||||
@@ -193,7 +170,7 @@ struct ServiceStructInformation
|
|||||||
QString primaryTable;
|
QString primaryTable;
|
||||||
bool hasStaticContent = false;
|
bool hasStaticContent = false;
|
||||||
|
|
||||||
bool operator<(const ServiceStructInformation &o) const
|
bool operator<(const ServiceStructInformation& o) const
|
||||||
{
|
{
|
||||||
if (hasStaticContent != o.hasStaticContent)
|
if (hasStaticContent != o.hasStaticContent)
|
||||||
return hasStaticContent < o.hasStaticContent;
|
return hasStaticContent < o.hasStaticContent;
|
||||||
@@ -201,6 +178,7 @@ struct ServiceStructInformation
|
|||||||
return name < o.name;
|
return name < o.name;
|
||||||
return primaryTable < o.primaryTable;
|
return primaryTable < o.primaryTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<DbNotifcationInformation> dbNotifications;
|
QVector<DbNotifcationInformation> dbNotifications;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -227,9 +205,12 @@ struct TopicTypeInformationBase
|
|||||||
int extensibility = 0; // Placeholder when RTI DDS is not available
|
int extensibility = 0; // Placeholder when RTI DDS is not available
|
||||||
#endif
|
#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)
|
if (name != o.name)
|
||||||
return name < o.name;
|
return name < o.name;
|
||||||
@@ -252,39 +233,84 @@ struct FunctionTopic
|
|||||||
bool routeInReplay = false;
|
bool routeInReplay = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CODEGEN_BASE_EXPORT XmlReader final
|
class CODEGEN_BASE_EXPORT XmlReader final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XmlReader();
|
XmlReader();
|
||||||
|
|
||||||
bool readServiceFile(const QString &svcFile,
|
bool readServiceFile(const QString& svcFile, const QString& idlServiceInfoFile = QString(),
|
||||||
const QString &idlServiceInfoFile = QString(),
|
const XmlReader* parent = nullptr);
|
||||||
const XmlReader *parent = nullptr);
|
|
||||||
QString errorString() const
|
QString errorString() const
|
||||||
{
|
{
|
||||||
return m_errorString;
|
return m_errorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getServiceNamespace() const { return m_svcNamespace; }
|
QString getServiceNamespace() const
|
||||||
QString getServiceAbbr() const { return m_svcAbbr; }
|
{
|
||||||
QStringList getGroupNames() const { return m_groupNames; }
|
return m_svcNamespace;
|
||||||
int getPrio() const { return m_prio;}
|
}
|
||||||
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; }
|
QString getServiceAbbr() const
|
||||||
ExerciseDependency defaultExerciseDependency() const { return m_exerciseDependency; }
|
{
|
||||||
|
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; }
|
QStringList getProcNames() const
|
||||||
QVector<ServiceStructInformation> getStructToGenerate() const { return m_structsToGenerate; }
|
{
|
||||||
|
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> getIdlStructToGenerate() const
|
||||||
{
|
{
|
||||||
QVector<TopicTypeInformation> res;
|
QVector<TopicTypeInformation> res;
|
||||||
@@ -298,24 +324,27 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QSharedPointer<TableInformation>> getTables() const
|
||||||
QMap<QString, QSharedPointer<TableInformation> > getTables() const
|
|
||||||
{
|
{
|
||||||
return m_tables;
|
return m_tables;
|
||||||
}
|
}
|
||||||
QMap<QString, QSharedPointer<ViewInformation> > getViews() const
|
|
||||||
|
QMap<QString, QSharedPointer<ViewInformation>> getViews() const
|
||||||
{
|
{
|
||||||
return m_views;
|
return m_views;
|
||||||
}
|
}
|
||||||
QSharedPointer<TableInformation> getTable(const QString &table) const
|
|
||||||
|
QSharedPointer<TableInformation> getTable(const QString& table) const
|
||||||
{
|
{
|
||||||
return m_tables.value(table);
|
return m_tables.value(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<EnumInformation> getEnumerations() const
|
QVector<EnumInformation> getEnumerations() const
|
||||||
{
|
{
|
||||||
return m_enumerations;
|
return m_enumerations;
|
||||||
}
|
}
|
||||||
QVector<IdlColumnInformation> getIdlColumns(const QString &structName) const
|
|
||||||
|
QVector<IdlColumnInformation> getIdlColumns(const QString& structName) const
|
||||||
{
|
{
|
||||||
return m_idlStructsToGenerate.value(structName).columns;
|
return m_idlStructsToGenerate.value(structName).columns;
|
||||||
}
|
}
|
||||||
@@ -324,17 +353,18 @@ public:
|
|||||||
{
|
{
|
||||||
return m_functionTopics;
|
return m_functionTopics;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<TopicTypeInformation> getExternalTopicTypes() const
|
QVector<TopicTypeInformation> getExternalTopicTypes() const
|
||||||
{
|
{
|
||||||
return m_externalTopicTypes;
|
return m_externalTopicTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString idlFileForService(const QString &serviceName) const
|
QString idlFileForService(const QString& serviceName) const
|
||||||
{
|
{
|
||||||
return getIdlFileForService(m_idlFiles, serviceName);
|
return getIdlFileForService(m_idlFiles, serviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString xmlFileForService(const QString &serviceName) const
|
QString xmlFileForService(const QString& serviceName) const
|
||||||
{
|
{
|
||||||
return getIdlFileForService(m_xmlFiles, serviceName);
|
return getIdlFileForService(m_xmlFiles, serviceName);
|
||||||
}
|
}
|
||||||
@@ -349,51 +379,46 @@ public:
|
|||||||
return m_customFunctions;
|
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);
|
static ExerciseDependency string2ExerciseDependency(const QString& str);
|
||||||
EnumInformation getExternalEnumeration(const QString &externalServiceName, const QString &enumName, bool verbose);
|
|
||||||
|
|
||||||
static ExerciseDependency string2ExerciseDependency(const QString &str);
|
XmlReader(const XmlReader&) = delete;
|
||||||
|
XmlReader& operator=(const XmlReader&) = delete;
|
||||||
|
|
||||||
XmlReader(const XmlReader &) = delete;
|
private:
|
||||||
XmlReader &operator=(const XmlReader &) = delete;
|
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:
|
static QString getAttribute(const QDomElement& element, const QString& attributeName, bool bOptional = false);
|
||||||
NGL::INGLLogger &m_logger;
|
static bool getAttributeBool(const QDomElement& element, const QString& attributeName, bool bOptional,
|
||||||
void parseDBSserviceStructs(const QDomElement &rootElement);
|
bool defaultValue);
|
||||||
void parseDBTables(const QDomElement &rootElement);
|
static int getAttributeInt(const QDomElement& element, const QString& attributeName, bool bOptional = false,
|
||||||
void parseDBViews(const QDomElement &rootElement);
|
int defaultValue = 0);
|
||||||
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,
|
ColumnInformation parseTableColumn(const QDomElement& column, const QString& tableName) const;
|
||||||
const QString &attributeName,
|
IdlColumnInformation parseIdlStructColumn(const QDomElement& column) const;
|
||||||
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);
|
|
||||||
|
|
||||||
|
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;
|
QString m_svcNamespace;
|
||||||
|
|
||||||
@@ -403,12 +428,9 @@ private:
|
|||||||
|
|
||||||
bool m_customRecordReplay;
|
bool m_customRecordReplay;
|
||||||
|
|
||||||
|
|
||||||
ExerciseDependency m_exerciseDependency{ExerciseDependency::Exercise};
|
ExerciseDependency m_exerciseDependency{ExerciseDependency::Exercise};
|
||||||
|
|
||||||
|
QMap<QString, QVector<QString>> m_dbClassTables;
|
||||||
QMap<QString, QVector<QString> > m_dbClassTables;
|
|
||||||
|
|
||||||
|
|
||||||
QMap<QString, QString> m_struct2BaseClass;
|
QMap<QString, QString> m_struct2BaseClass;
|
||||||
QVector<ServiceStructInformation> m_structsToGenerate;
|
QVector<ServiceStructInformation> m_structsToGenerate;
|
||||||
@@ -419,14 +441,12 @@ private:
|
|||||||
QVector<TopicTypeInformation> m_externalTopicTypes;
|
QVector<TopicTypeInformation> m_externalTopicTypes;
|
||||||
QVector<CustomServiceFunctionInformation> m_customFunctions;
|
QVector<CustomServiceFunctionInformation> m_customFunctions;
|
||||||
|
|
||||||
|
QMap<QString, QSharedPointer<TableInformation>> m_tables;
|
||||||
QMap<QString, QSharedPointer<TableInformation> > m_tables;
|
QMap<QString, QSharedPointer<ViewInformation>> m_views;
|
||||||
QMap<QString, QSharedPointer<ViewInformation> > m_views;
|
|
||||||
QVector<EnumInformation> m_enumerations;
|
QVector<EnumInformation> m_enumerations;
|
||||||
QString m_errorString;
|
QString m_errorString;
|
||||||
|
|
||||||
|
QMap<QString, QSharedPointer<XmlReader>> m_externalXmlInformations;
|
||||||
QMap<QString, QSharedPointer<XmlReader> > m_externalXmlInformations;
|
|
||||||
QMap<QString, QString> m_idlFiles;
|
QMap<QString, QString> m_idlFiles;
|
||||||
QMap<QString, QString> m_xmlFiles;
|
QMap<QString, QString> m_xmlFiles;
|
||||||
QMap<QString, bool> m_usedServices;
|
QMap<QString, bool> m_usedServices;
|
||||||
@@ -436,4 +456,4 @@ private:
|
|||||||
int m_prio;
|
int m_prio;
|
||||||
bool m_svcDevMode{false};
|
bool m_svcDevMode{false};
|
||||||
};
|
};
|
||||||
}
|
} // namespace CodeGen
|
||||||
Executable → Regular
+9
-9
@@ -5,13 +5,13 @@
|
|||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
|
|
||||||
#ifndef CODEGEN_BASE_EXPORT
|
#ifndef CODEGEN_BASE_EXPORT
|
||||||
# ifdef BUILD_STATIC_LIBRARIES
|
#ifdef BUILD_STATIC_LIBRARIES
|
||||||
# define CODEGEN_BASE_EXPORT
|
#define CODEGEN_BASE_EXPORT
|
||||||
# else
|
#else
|
||||||
# if defined(MAKE_CODEGEN_BASE_LIB)
|
#if defined(MAKE_CODEGEN_BASE_LIB)
|
||||||
# define CODEGEN_BASE_EXPORT Q_DECL_EXPORT
|
#define CODEGEN_BASE_EXPORT Q_DECL_EXPORT
|
||||||
# else
|
#else
|
||||||
# define CODEGEN_BASE_EXPORT Q_DECL_IMPORT
|
#define CODEGEN_BASE_EXPORT Q_DECL_IMPORT
|
||||||
# endif
|
#endif
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
Executable → Regular
+43
-48
@@ -1,48 +1,37 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "CppTopicGeneratorGrantlee.h"
|
||||||
#include "StructBuilder.h"
|
|
||||||
#include "XmlReader.h"
|
|
||||||
#include "DaoGeneratorGrantlee.h"
|
#include "DaoGeneratorGrantlee.h"
|
||||||
#include "DatabaseGeneratorGrantlee.h"
|
#include "DatabaseGeneratorGrantlee.h"
|
||||||
#include "CppTopicGeneratorGrantlee.h"
|
|
||||||
#include "SqlGenerator.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 <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||||
|
#include <NGLLogger/INGLLogger.h>
|
||||||
|
#include <QDir>
|
||||||
|
#include <nglapplication/nglcoreapplication.h>
|
||||||
|
|
||||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CmdLineParser()
|
CmdLineParser() : LtsCommandLineParser(LtsCommandLineParser::LtsCommandLineParser::None)
|
||||||
: LtsCommandLineParser(LtsCommandLineParser::LtsCommandLineParser::None)
|
|
||||||
{
|
{
|
||||||
addOption({ QStringList() << QStringLiteral("s") << QStringLiteral("servicefile"),
|
addOption({QStringList() << QStringLiteral("s") << QStringLiteral("servicefile"),
|
||||||
QStringLiteral("full path to the service xml-file"),
|
QStringLiteral("full path to the service xml-file"), QStringLiteral("service xml-file"),
|
||||||
QStringLiteral("service xml-file"),
|
QStringLiteral("/home")});
|
||||||
QStringLiteral("/home")
|
|
||||||
});
|
|
||||||
|
|
||||||
addOption({ QStringList() << QStringLiteral("a") << QStringLiteral("action"),
|
addOption({QStringList() << QStringLiteral("a") << QStringLiteral("action"),
|
||||||
QStringLiteral("the action to execute"),
|
QStringLiteral("the action to execute"), QStringLiteral("DATABASE|DATABASE_SERVER|IDL|DDS_TOPICS"),
|
||||||
QStringLiteral("DATABASE|DATABASE_SERVER|IDL|DDS_TOPICS"),
|
QStringLiteral("/0")});
|
||||||
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("the output directory where to put the generated files"),
|
||||||
QStringLiteral("output directory"),
|
QStringLiteral("output directory"), QStringLiteral("/home")});
|
||||||
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("the info file with all available idl service files"),
|
||||||
QStringLiteral("info file for idl"),
|
QStringLiteral("info file for idl"), QStringLiteral("/0")});
|
||||||
QStringLiteral("/0")
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init()
|
bool init()
|
||||||
@@ -58,18 +47,33 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString serviceFile() const { return value(QStringLiteral("s")); }
|
QString serviceFile() const
|
||||||
QString action() const { return value(QStringLiteral("a")); }
|
{
|
||||||
QString outDir() const { return value(QStringLiteral("o")); }
|
return value(QStringLiteral("s"));
|
||||||
QString idlInfoFile() const { return value(QStringLiteral("i")); }
|
}
|
||||||
|
|
||||||
|
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);
|
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;
|
CmdLineParser options;
|
||||||
if (!options.init())
|
if (!options.init())
|
||||||
@@ -81,8 +85,7 @@ int main(int argc, char **argv)
|
|||||||
DEBUG_LOG(m_logger) << "IdlInfoFile: " << options.idlInfoFile();
|
DEBUG_LOG(m_logger) << "IdlInfoFile: " << options.idlInfoFile();
|
||||||
if (!reader->readServiceFile(options.serviceFile(), options.idlInfoFile()))
|
if (!reader->readServiceFile(options.serviceFile(), options.idlInfoFile()))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Error parsing service file '" << options.serviceFile()
|
ERROR_LOG(m_logger) << "Error parsing service file '" << options.serviceFile() << ": " << reader->errorString();
|
||||||
<< ": " << reader->errorString();
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +93,7 @@ int main(int argc, char **argv)
|
|||||||
DEBUG_LOG(m_logger) << "Directory: " << options.outDir();
|
DEBUG_LOG(m_logger) << "Directory: " << options.outDir();
|
||||||
if (!dir.exists() && !dir.mkpath(options.outDir()))
|
if (!dir.exists() && !dir.mkpath(options.outDir()))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Directory '" << options.outDir()
|
ERROR_LOG(m_logger) << "Directory '" << options.outDir() << "' does not exist and can not be created!";
|
||||||
<< "' does not exist and can not be created!";
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +106,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
const QString action = options.action().toLower();
|
const QString action = options.action().toLower();
|
||||||
|
|
||||||
|
|
||||||
QScopedPointer<CodeGen::GeneratorGrantleeBase> generator;
|
QScopedPointer<CodeGen::GeneratorGrantleeBase> generator;
|
||||||
if (action == QStringLiteral("dao"))
|
if (action == QStringLiteral("dao"))
|
||||||
generator.reset(new CodeGen::DaoGeneratorGrantlee);
|
generator.reset(new CodeGen::DaoGeneratorGrantlee);
|
||||||
@@ -120,7 +121,6 @@ int main(int argc, char **argv)
|
|||||||
if (!sql.generateData(35))
|
if (!sql.generateData(35))
|
||||||
return 8;
|
return 8;
|
||||||
|
|
||||||
|
|
||||||
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
|
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
|
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))
|
if (!sql.generateData(42))
|
||||||
return 8;
|
return 8;
|
||||||
|
|
||||||
|
|
||||||
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
|
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
|
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sql.generateData(0);
|
sql.generateData(0);
|
||||||
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Global))
|
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Global))
|
||||||
{
|
{
|
||||||
@@ -158,11 +156,8 @@ int main(int argc, char **argv)
|
|||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const auto posArgs = options.positionalArguments();
|
const auto posArgs = options.positionalArguments();
|
||||||
for (const QString &file : posArgs)
|
for (const QString& file : posArgs)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!generator->generateData(file, dir.absolutePath()))
|
if (!generator->generateData(file, dir.absolutePath()))
|
||||||
|
|||||||
Executable → Regular
+27
-37
@@ -1,44 +1,32 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "main_grantlee_gui.h"
|
#include "main_grantlee_gui.h"
|
||||||
#include "ui_main_grantlee_gui.h"
|
|
||||||
#include "StructBuilder.h"
|
|
||||||
#include "XmlReader.h"
|
|
||||||
#include "CppTopicGeneratorGrantlee.h"
|
#include "CppTopicGeneratorGrantlee.h"
|
||||||
#include "DatabaseGeneratorGrantlee.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 <NGLLogger/INGLLogger.h>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <grantlee/engine.h>
|
#include <grantlee/engine.h>
|
||||||
|
#include <nglapplication/nglapplication.h>
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget* parent)
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
: QMainWindow(parent), m_xmlReader(nullptr), m_structBuilder(nullptr),
|
||||||
: QMainWindow(parent)
|
m_generator(new CodeGen::CppTopicGeneratorGrantlee), m_engine(new Grantlee::Engine), m_ui(new Ui_MainGrantleeGui)
|
||||||
, 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_idlServiceInfoFile = QStringLiteral("/home/chehrlic/TDS/TDS-build-product-clang/service_idl_files.txt");
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
connect(m_ui->actionExit, &QAction::triggered,
|
connect(m_ui->actionExit, &QAction::triggered, this, &MainWindow::close);
|
||||||
this, &MainWindow::close);
|
connect(m_ui->actionSelect_Data_Source, &QAction::triggered, this, &MainWindow::onSelectDataSource);
|
||||||
connect(m_ui->actionSelect_Data_Source, &QAction::triggered,
|
connect(m_ui->actionOpen_Template, &QAction::triggered, this, &MainWindow::onOpenTemplate);
|
||||||
this, &MainWindow::onSelectDataSource);
|
connect(m_ui->actionSave_Template, &QAction::triggered, this, &MainWindow::onSaveTemplate);
|
||||||
connect(m_ui->actionOpen_Template, &QAction::triggered,
|
connect(m_ui->pbRefresh, &QPushButton::clicked, this, &MainWindow::onRefreshOutput);
|
||||||
this, &MainWindow::onOpenTemplate);
|
connect(m_ui->actionDatabaseGenerator, &QAction::triggered, this, &MainWindow::onGeneratorDb);
|
||||||
connect(m_ui->actionSave_Template, &QAction::triggered,
|
connect(m_ui->actionDDS_Generator, &QAction::triggered, this, &MainWindow::onGeneratorDds);
|
||||||
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()
|
MainWindow::~MainWindow()
|
||||||
@@ -54,14 +42,16 @@ static QLatin1String s_startDir("/home/chehrlic/TDS/TDS-source-product/Lts/");
|
|||||||
|
|
||||||
void MainWindow::onSelectDataSource()
|
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())
|
if (dataSource.isEmpty())
|
||||||
return;
|
return;
|
||||||
delete m_xmlReader;
|
delete m_xmlReader;
|
||||||
m_xmlReader = new CodeGen::XmlReader;
|
m_xmlReader = new CodeGen::XmlReader;
|
||||||
if (!m_xmlReader->readServiceFile(dataSource, m_idlServiceInfoFile))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
delete m_structBuilder;
|
delete m_structBuilder;
|
||||||
@@ -78,7 +68,8 @@ void MainWindow::onSelectDataSource()
|
|||||||
|
|
||||||
void MainWindow::onOpenTemplate()
|
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())
|
if (templateFile.isEmpty())
|
||||||
return;
|
return;
|
||||||
QFile f(templateFile);
|
QFile f(templateFile);
|
||||||
@@ -102,7 +93,8 @@ void MainWindow::onSaveTemplate()
|
|||||||
}
|
}
|
||||||
f.write(m_ui->teInput->toPlainText().toUtf8());
|
f.write(m_ui->teInput->toPlainText().toUtf8());
|
||||||
f.close();
|
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()
|
void MainWindow::onRefreshOutput()
|
||||||
@@ -118,7 +110,7 @@ void MainWindow::onRefreshOutput()
|
|||||||
|
|
||||||
void MainWindow::onGeneratorDb()
|
void MainWindow::onGeneratorDb()
|
||||||
{
|
{
|
||||||
if (dynamic_cast<CodeGen::DatabaseGeneratorGrantlee *>(m_generator))
|
if (dynamic_cast<CodeGen::DatabaseGeneratorGrantlee*>(m_generator))
|
||||||
return;
|
return;
|
||||||
delete m_generator;
|
delete m_generator;
|
||||||
m_generator = new CodeGen::DatabaseGeneratorGrantlee(false);
|
m_generator = new CodeGen::DatabaseGeneratorGrantlee(false);
|
||||||
@@ -128,7 +120,7 @@ void MainWindow::onGeneratorDb()
|
|||||||
|
|
||||||
void MainWindow::onGeneratorDds()
|
void MainWindow::onGeneratorDds()
|
||||||
{
|
{
|
||||||
if (dynamic_cast<CodeGen::CppTopicGeneratorGrantlee *>(m_generator))
|
if (dynamic_cast<CodeGen::CppTopicGeneratorGrantlee*>(m_generator))
|
||||||
return;
|
return;
|
||||||
delete m_generator;
|
delete m_generator;
|
||||||
m_generator = new CodeGen::CppTopicGeneratorGrantlee;
|
m_generator = new CodeGen::CppTopicGeneratorGrantlee;
|
||||||
@@ -136,13 +128,12 @@ void MainWindow::onGeneratorDds()
|
|||||||
m_generator->init(m_xmlReader, m_structBuilder);
|
m_generator->init(m_xmlReader, m_structBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
NGLApplication app(argc, argv);
|
NGLApplication app(argc, argv);
|
||||||
app.createLogger("CodeGen", "codegen_log4cxx.props");
|
app.createLogger("CodeGen", "codegen_log4cxx.props");
|
||||||
|
|
||||||
NGL::INGLLogger &m_logger = app.baseLogger();
|
NGL::INGLLogger& m_logger = app.baseLogger();
|
||||||
STARTUP_LOG(m_logger);
|
STARTUP_LOG(m_logger);
|
||||||
|
|
||||||
int iRet = 0;
|
int iRet = 0;
|
||||||
@@ -155,4 +146,3 @@ int main(int argc, char **argv)
|
|||||||
SHUTDOWN_LOG(m_logger);
|
SHUTDOWN_LOG(m_logger);
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Executable → Regular
+14
-12
@@ -1,40 +1,42 @@
|
|||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace CodeGen
|
namespace CodeGen
|
||||||
{
|
{
|
||||||
class XmlReader;
|
class XmlReader;
|
||||||
class StructBuilder;
|
class StructBuilder;
|
||||||
class GeneratorGrantleeBase;
|
class GeneratorGrantleeBase;
|
||||||
}
|
} // namespace CodeGen
|
||||||
|
|
||||||
namespace Grantlee
|
namespace Grantlee
|
||||||
{
|
{
|
||||||
class Engine;
|
class Engine;
|
||||||
}
|
}
|
||||||
class Ui_MainGrantleeGui;
|
class Ui_MainGrantleeGui;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget* parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onSelectDataSource();
|
void onSelectDataSource();
|
||||||
void onOpenTemplate();
|
void onOpenTemplate();
|
||||||
void onSaveTemplate();
|
void onSaveTemplate();
|
||||||
void onRefreshOutput();
|
void onRefreshOutput();
|
||||||
void onGeneratorDb();
|
void onGeneratorDb();
|
||||||
void onGeneratorDds();
|
void onGeneratorDds();
|
||||||
private:
|
|
||||||
CodeGen::XmlReader *m_xmlReader;
|
private:
|
||||||
CodeGen::StructBuilder *m_structBuilder;
|
CodeGen::XmlReader* m_xmlReader;
|
||||||
CodeGen::GeneratorGrantleeBase *m_generator;
|
CodeGen::StructBuilder* m_structBuilder;
|
||||||
Grantlee::Engine *m_engine;
|
CodeGen::GeneratorGrantleeBase* m_generator;
|
||||||
|
Grantlee::Engine* m_engine;
|
||||||
QString m_idlServiceInfoFile;
|
QString m_idlServiceInfoFile;
|
||||||
QString m_templateFile;
|
QString m_templateFile;
|
||||||
Ui_MainGrantleeGui *m_ui;
|
Ui_MainGrantleeGui* m_ui;
|
||||||
};
|
};
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <grantlee/engine.h>
|
#include <grantlee/engine.h>
|
||||||
#include <grantlee/templateloader.h>
|
#include <grantlee/templateloader.h>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
QString templatesDir = QDir::currentPath();
|
QString templatesDir = QDir::currentPath();
|
||||||
if (argc > 1) {
|
if (argc > 1)
|
||||||
|
{
|
||||||
templatesDir = QString::fromLocal8Bit(argv[1]);
|
templatesDir = QString::fromLocal8Bit(argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +21,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
QDir d(templatesDir);
|
QDir d(templatesDir);
|
||||||
QStringList files = d.entryList(QStringList() << QStringLiteral("*.grantlee"), QDir::Files);
|
QStringList files = d.entryList(QStringList() << QStringLiteral("*.grantlee"), QDir::Files);
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty())
|
||||||
|
{
|
||||||
qDebug() << "No .grantlee templates found in" << templatesDir;
|
qDebug() << "No .grantlee templates found in" << templatesDir;
|
||||||
// Treat absence as successful parse (nothing to check) to avoid failing
|
// Treat absence as successful parse (nothing to check) to avoid failing
|
||||||
// when directory is empty in different setups.
|
// when directory is empty in different setups.
|
||||||
@@ -29,21 +30,27 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for (const QString &f : files) {
|
for (const QString& f : files)
|
||||||
|
{
|
||||||
Grantlee::Template t;
|
Grantlee::Template t;
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
t = engine.loadByName(f);
|
t = engine.loadByName(f);
|
||||||
} catch (...) {
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
qDebug() << "Exception while loading" << f;
|
qDebug() << "Exception while loading" << f;
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!t) {
|
if (!t)
|
||||||
|
{
|
||||||
qDebug() << "Failed to load template" << f;
|
qDebug() << "Failed to load template" << f;
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (t->error() != Grantlee::NoError) {
|
if (t->error() != Grantlee::NoError)
|
||||||
|
{
|
||||||
qDebug() << "Parse error in" << f << ":" << t->errorString();
|
qDebug() << "Parse error in" << f << ":" << t->errorString();
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
@@ -51,7 +58,8 @@ int main(int argc, char **argv)
|
|||||||
// Render with empty context to ensure rendering path also works.
|
// Render with empty context to ensure rendering path also works.
|
||||||
Grantlee::Context ctx;
|
Grantlee::Context ctx;
|
||||||
QString out = t->render(&ctx);
|
QString out = t->render(&ctx);
|
||||||
if (out.isNull()) {
|
if (out.isNull())
|
||||||
|
{
|
||||||
qDebug() << "Rendering produced null for" << f;
|
qDebug() << "Rendering produced null for" << f;
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
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 <LtsAppDescriptor/lts_app_descriptor.h>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfoList>
|
#include <QFileInfoList>
|
||||||
#include <QDirIterator>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
|
#include <QTextStream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
@@ -31,7 +28,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!f.open(QFile::ReadOnly))
|
if (!f.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
printf("LtsAppDescriptorChecker: cannot open apps.json at %s: %s\n", appsJsonFilePath.toStdString().c_str(), f.errorString().toStdString().c_str());
|
printf("LtsAppDescriptorChecker: cannot open apps.json at %s: %s\n", appsJsonFilePath.toStdString().c_str(),
|
||||||
|
f.errorString().toStdString().c_str());
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,16 +38,16 @@ int main(int argc, char *argv[])
|
|||||||
QStringList lastErrors;
|
QStringList lastErrors;
|
||||||
QStringList dummy1;
|
QStringList dummy1;
|
||||||
QString dummy2;
|
QString dummy2;
|
||||||
LtsAppDescriptor::AppDescriptionVector adv = LtsAppDescriptor::LtsAppDescriptor::getAppDescriptionVector(f.readAll(), lastErrors, dummy1, dummy2);
|
LtsAppDescriptor::AppDescriptionVector adv =
|
||||||
|
LtsAppDescriptor::LtsAppDescriptor::getAppDescriptionVector(f.readAll(), lastErrors, dummy1, dummy2);
|
||||||
|
|
||||||
if (!lastErrors.isEmpty())
|
if (!lastErrors.isEmpty())
|
||||||
{
|
{
|
||||||
printf("LtsAppDescriptorChecker: apps.json at %s invalid:\n%s\n", 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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QFileInfoList guiPluginFiles;
|
QFileInfoList guiPluginFiles;
|
||||||
QDirIterator it(QStringLiteral("%1/../../Plugins/").arg(currentSrcDir), QDirIterator::Subdirectories);
|
QDirIterator it(QStringLiteral("%1/../../Plugins/").arg(currentSrcDir), QDirIterator::Subdirectories);
|
||||||
|
|
||||||
@@ -67,14 +65,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QStringList filenames;
|
QStringList filenames;
|
||||||
filenames.reserve(guiPluginFiles.size());
|
filenames.reserve(guiPluginFiles.size());
|
||||||
for (const QFileInfo &fi : std::as_const(guiPluginFiles))
|
for (const QFileInfo& fi : std::as_const(guiPluginFiles))
|
||||||
{
|
{
|
||||||
filenames += fi.absoluteFilePath();
|
filenames += fi.absoluteFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList guiPluginIIDs;
|
QStringList guiPluginIIDs;
|
||||||
for (const QFileInfo &fi : std::as_const(guiPluginFiles))
|
for (const QFileInfo& fi : std::as_const(guiPluginFiles))
|
||||||
{
|
{
|
||||||
QFile f2(fi.absoluteFilePath());
|
QFile f2(fi.absoluteFilePath());
|
||||||
|
|
||||||
@@ -102,38 +99,20 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
for (const LtsAppDescriptor::AppDescription &appdesc : std::as_const(adv))
|
for (const LtsAppDescriptor::AppDescription& appdesc : std::as_const(adv))
|
||||||
{
|
{
|
||||||
for (const LtsAppDescriptor::PluginInfo &pi : std::as_const(appdesc.pluginInfos))
|
for (const LtsAppDescriptor::PluginInfo& pi : std::as_const(appdesc.pluginInfos))
|
||||||
{
|
{
|
||||||
if (!guiPluginIIDs.contains(pi.iid))
|
if (!guiPluginIIDs.contains(pi.iid))
|
||||||
{
|
{
|
||||||
printf("LtsAppDescriptorChecker: apps.json at '%s' uses unknown IID '%s'\n", appsJsonFilePath.toStdString().c_str(), pi.iid.toStdString().c_str());
|
printf("LtsAppDescriptorChecker: apps.json at '%s' uses unknown IID '%s'\n",
|
||||||
|
appsJsonFilePath.toStdString().c_str(), pi.iid.toStdString().c_str());
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return !ok;
|
return !ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Executable → Regular
+33
-42
@@ -1,29 +1,24 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_app_descriptor.h"
|
#include "lts_app_descriptor.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QCoreApplication>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppDescriptor
|
namespace LtsAppDescriptor
|
||||||
{
|
{
|
||||||
static void addOptionToPlugin(PluginInfo &pluginInfo, const PluginInfo::Flag &flag)
|
static void addOptionToPlugin(PluginInfo& pluginInfo, const PluginInfo::Flag& flag)
|
||||||
{
|
{
|
||||||
pluginInfo.flags |= flag;
|
pluginInfo.flags |= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addOptionToPlugin(QVector<PluginInfo>& pluginInfos, const PluginInfo::Flag& flag, const QString& pluginName)
|
||||||
static void addOptionToPlugin(QVector<PluginInfo> &pluginInfos, const PluginInfo::Flag &flag, const QString &pluginName)
|
|
||||||
{
|
{
|
||||||
for (PluginInfo &pi : pluginInfos)
|
for (PluginInfo& pi : pluginInfos)
|
||||||
{
|
{
|
||||||
if (pi.iid == pluginName)
|
if (pi.iid == pluginName)
|
||||||
{
|
{
|
||||||
@@ -39,10 +34,9 @@ static void addOptionToPlugin(QVector<PluginInfo> &pluginInfos, const PluginInfo
|
|||||||
pluginInfos.append(pi);
|
pluginInfos.append(pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool addOptionsToPlugin(AppDescription& appDesc, const QString& optionIdentifier,
|
||||||
static bool addOptionsToPlugin(AppDescription &appDesc, const QString &optionIdentifier, const QStringList &ignoredPlugins,
|
const QStringList& ignoredPlugins, const QJsonObject& optionsObject,
|
||||||
const QJsonObject &optionsObject, const PluginInfo::Flag flag, QStringList &lastErrors,
|
const PluginInfo::Flag flag, QStringList& lastErrors, bool atLeastOnePluginNeeded)
|
||||||
bool atLeastOnePluginNeeded)
|
|
||||||
{
|
{
|
||||||
bool hasPlugins = false;
|
bool hasPlugins = false;
|
||||||
auto optionsObjectIt = optionsObject.constFind(optionIdentifier);
|
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());
|
const QJsonArray plugins((*optionsObjectIt).toObject()[QStringLiteral("Plugins")].toArray());
|
||||||
|
|
||||||
for (const auto &pluginElem : plugins)
|
for (const auto& pluginElem : plugins)
|
||||||
{
|
{
|
||||||
const QString pluginName = pluginElem.toString();
|
const QString pluginName = pluginElem.toString();
|
||||||
if (!ignoredPlugins.contains(pluginName))
|
if (!ignoredPlugins.contains(pluginName))
|
||||||
@@ -63,14 +57,14 @@ static bool addOptionsToPlugin(AppDescription &appDesc, const QString &optionIde
|
|||||||
|
|
||||||
if (atLeastOnePluginNeeded && !hasPlugins)
|
if (atLeastOnePluginNeeded && !hasPlugins)
|
||||||
{
|
{
|
||||||
lastErrors.append(QCoreApplication::tr("No plugins specified for '%1' option for app '%2'").arg(optionIdentifier, appDesc.appName));
|
lastErrors.append(QCoreApplication::tr("No plugins specified for '%1' option for app '%2'")
|
||||||
|
.arg(optionIdentifier, appDesc.appName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
App LtsAppDescriptor::appFromInteger(int i)
|
App LtsAppDescriptor::appFromInteger(int i)
|
||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
@@ -102,13 +96,11 @@ App LtsAppDescriptor::appFromInteger(int i)
|
|||||||
return App::Login;
|
return App::Login;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray &jsonDocument,
|
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray& jsonDocument, QStringList& lastErrors,
|
||||||
QStringList &lastErrors,
|
const QStringList& ignoredPlugins,
|
||||||
const QStringList &ignoredPlugins,
|
QString& loginPluginIid)
|
||||||
QString &loginPluginIid)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
AppDescriptionVector appDescriptions;
|
AppDescriptionVector appDescriptions;
|
||||||
|
|
||||||
QJsonParseError parseError;
|
QJsonParseError parseError;
|
||||||
@@ -117,7 +109,6 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
|||||||
if (parseError.error != QJsonParseError::NoError)
|
if (parseError.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int column = 0;
|
int column = 0;
|
||||||
QChar x = QLatin1Char('\n');
|
QChar x = QLatin1Char('\n');
|
||||||
@@ -138,8 +129,10 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastErrors.append(QCoreApplication::tr("JSON: %1<br>Row: %2, Column: %3")
|
||||||
lastErrors.append(QCoreApplication::tr("JSON: %1<br>Row: %2, Column: %3").arg(parseError.errorString()).arg(row+1).arg(column+1));
|
.arg(parseError.errorString())
|
||||||
|
.arg(row + 1)
|
||||||
|
.arg(column + 1));
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,14 +147,11 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
|||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& appElem : appArray)
|
||||||
for (const auto &appElem : appArray)
|
|
||||||
{
|
{
|
||||||
AppDescription appDesc;
|
AppDescription appDesc;
|
||||||
const QJsonObject appObject = appElem.toObject();
|
const QJsonObject appObject = appElem.toObject();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
appDesc.id = appFromInteger(appObject.value(QStringLiteral("Id")).toInt(-1));
|
appDesc.id = appFromInteger(appObject.value(QStringLiteral("Id")).toInt(-1));
|
||||||
if (appDesc.id == App::Login)
|
if (appDesc.id == App::Login)
|
||||||
{
|
{
|
||||||
@@ -176,7 +166,9 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
|||||||
{
|
{
|
||||||
if (valueActive.type() != QJsonValue::Type::Bool)
|
if (valueActive.type() != QJsonValue::Type::Bool)
|
||||||
{
|
{
|
||||||
lastErrors.append(QCoreApplication::tr("App '%1': value App.Active is not a bool (%2)").arg(appDesc.appName).arg((int)valueActive.type()));
|
lastErrors.append(QCoreApplication::tr("App '%1': value App.Active is not a bool (%2)")
|
||||||
|
.arg(appDesc.appName)
|
||||||
|
.arg((int)valueActive.type()));
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,31 +177,30 @@ AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray
|
|||||||
const QJsonValue valueVisible = appObject.value(QStringLiteral("Visible"));
|
const QJsonValue valueVisible = appObject.value(QStringLiteral("Visible"));
|
||||||
if (!valueVisible.isUndefined() && valueVisible.type() != QJsonValue::Type::Bool)
|
if (!valueVisible.isUndefined() && valueVisible.type() != QJsonValue::Type::Bool)
|
||||||
{
|
{
|
||||||
lastErrors.append(QCoreApplication::tr("App '%1': value App.Visible is not a bool (%2)").arg(appDesc.appName).arg((int)valueVisible.type()));
|
lastErrors.append(QCoreApplication::tr("App '%1': value App.Visible is not a bool (%2)")
|
||||||
|
.arg(appDesc.appName)
|
||||||
|
.arg((int)valueVisible.type()));
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
appDesc.visible = valueVisible.toBool(true);
|
appDesc.visible = valueVisible.toBool(true);
|
||||||
|
|
||||||
const QJsonArray array(appObject.value(QStringLiteral("ACLs")).toArray());
|
const QJsonArray array(appObject.value(QStringLiteral("ACLs")).toArray());
|
||||||
for (const QJsonValue &value : array)
|
for (const QJsonValue& value : array)
|
||||||
appDesc.requiredAcls.append(value.toInt());
|
appDesc.requiredAcls.append(value.toInt());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const QJsonObject optionsObject(appObject.value(QStringLiteral("Options")).toObject());
|
const QJsonObject optionsObject(appObject.value(QStringLiteral("Options")).toObject());
|
||||||
|
|
||||||
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject, PluginInfo::Flag::PAYLOAD, lastErrors, false);
|
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject,
|
||||||
addOptionsToPlugin(appDesc, QStringLiteral("Actions"), ignoredPlugins, optionsObject, PluginInfo::Flag::ACTIONS, lastErrors, true );
|
PluginInfo::Flag::PAYLOAD, lastErrors, false);
|
||||||
addOptionsToPlugin(appDesc, QStringLiteral("Main"), ignoredPlugins, optionsObject, PluginInfo::Flag::MAIN, lastErrors, false);
|
addOptionsToPlugin(appDesc, QStringLiteral("Actions"), ignoredPlugins, optionsObject, PluginInfo::Flag::ACTIONS,
|
||||||
|
lastErrors, true);
|
||||||
|
addOptionsToPlugin(appDesc, QStringLiteral("Main"), ignoredPlugins, optionsObject, PluginInfo::Flag::MAIN,
|
||||||
|
lastErrors, false);
|
||||||
|
|
||||||
appDescriptions.append(appDesc);
|
appDescriptions.append(appDesc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return appDescriptions;
|
return appDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsAppDescriptor
|
||||||
Executable → Regular
+23
-24
@@ -1,29 +1,26 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QVector>
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
#ifndef LTSAPPDESCRIPTOR_EXPORT
|
#ifndef LTSAPPDESCRIPTOR_EXPORT
|
||||||
# ifdef BUILD_STATIC_LIBRARIES
|
#ifdef BUILD_STATIC_LIBRARIES
|
||||||
# define LTSAPPDESCRIPTOR_EXPORT
|
#define LTSAPPDESCRIPTOR_EXPORT
|
||||||
# else
|
#else
|
||||||
# if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
|
#if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
|
||||||
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
|
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
|
||||||
# else
|
#else
|
||||||
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
|
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
|
||||||
# endif
|
#endif
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppDescriptor
|
namespace LtsAppDescriptor
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class App
|
enum class App {
|
||||||
{
|
|
||||||
Login = -1,
|
Login = -1,
|
||||||
Situation = 0,
|
Situation = 0,
|
||||||
ResourceManager = 1,
|
ResourceManager = 1,
|
||||||
@@ -49,15 +46,13 @@ enum class App
|
|||||||
|
|
||||||
struct PluginInfo
|
struct PluginInfo
|
||||||
{
|
{
|
||||||
enum class PluginType
|
enum class PluginType {
|
||||||
{
|
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
DATA,
|
DATA,
|
||||||
GUI,
|
GUI,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Flag
|
enum class Flag {
|
||||||
{
|
|
||||||
UNKNOWN = 1 << 0,
|
UNKNOWN = 1 << 0,
|
||||||
ACTIONS = 1 << 1,
|
ACTIONS = 1 << 1,
|
||||||
MAIN = 1 << 2,
|
MAIN = 1 << 2,
|
||||||
@@ -80,17 +75,21 @@ struct AppDescription
|
|||||||
QVector<int> requiredAcls;
|
QVector<int> requiredAcls;
|
||||||
QVector<PluginInfo> pluginInfos;
|
QVector<PluginInfo> pluginInfos;
|
||||||
|
|
||||||
bool isValid() const { return !appName.isEmpty(); }
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return !appName.isEmpty();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QVector<AppDescription> AppDescriptionVector;
|
typedef QVector<AppDescription> AppDescriptionVector;
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppDescriptor
|
namespace LtsAppDescriptor
|
||||||
{
|
{
|
||||||
LTSAPPDESCRIPTOR_EXPORT App appFromInteger(int i);
|
LTSAPPDESCRIPTOR_EXPORT App appFromInteger(int i);
|
||||||
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray &jsonDocument, QStringList &lastErrors,
|
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray& jsonDocument,
|
||||||
const QStringList &ignoredPlugins, QString &loginPluginIid);
|
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 "lts_app_descriptor_editor.h"
|
||||||
|
|
||||||
#include "ui_lts_app_descriptor_editor.h"
|
#include "ui_lts_app_descriptor_editor.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QStringListModel>
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QJsonDocument>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QStringListModel>
|
||||||
#include <QTimer>
|
#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_ui->setupUi(this);
|
||||||
m_vector = LtsAppDescriptor::AppDescriptionVector();
|
m_vector = LtsAppDescriptor::AppDescriptionVector();
|
||||||
@@ -50,10 +48,10 @@ LtsAppDescriptorEditor::~LtsAppDescriptorEditor()
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::getAppDescriptionVector()
|
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)"));
|
tr("JSON File (*.json)"));
|
||||||
if (m_fileName.isEmpty())
|
if (m_fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -70,7 +68,7 @@ void LtsAppDescriptorEditor::getAppDescriptionVector()
|
|||||||
updateAppModel();
|
updateAppModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
m_ui->gbPlugins->setEnabled(true);
|
m_ui->gbPlugins->setEnabled(true);
|
||||||
m_ui->pbDeleteApp->setEnabled(true);
|
m_ui->pbDeleteApp->setEnabled(true);
|
||||||
@@ -79,40 +77,40 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
|||||||
m_appIndex = index;
|
m_appIndex = index;
|
||||||
|
|
||||||
QStringList pluginList;
|
QStringList pluginList;
|
||||||
Q_FOREACH(const LtsAppDescriptor::PluginInfo &reqPlugin, m_vector.at(m_appIndex.row()).requiredPlugins)
|
Q_FOREACH (const LtsAppDescriptor::PluginInfo& reqPlugin, m_vector.at(m_appIndex.row()).requiredPlugins)
|
||||||
{
|
{
|
||||||
LtsAppDescriptor::PluginInfo::PluginType pluginType = reqPlugin.type;
|
LtsAppDescriptor::PluginInfo::PluginType pluginType = reqPlugin.type;
|
||||||
QString type;
|
QString type;
|
||||||
if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::DATA)
|
if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::DATA)
|
||||||
type = QLatin1String("data");
|
type = QLatin1String("data");
|
||||||
else if(pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
else if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
||||||
type = QLatin1String("gui");
|
type = QLatin1String("gui");
|
||||||
else
|
else
|
||||||
type = QLatin1String("unknown");
|
type = QLatin1String("unknown");
|
||||||
|
|
||||||
if(type == QLatin1String("data"))
|
if (type == QLatin1String("data"))
|
||||||
pluginList << QString(type + QLatin1String(": ") +reqPlugin.iid);
|
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString strFlags;
|
QString strFlags;
|
||||||
QFlags<LtsAppDescriptor::PluginInfo::Flag> flags = reqPlugin.flags;
|
QFlags<LtsAppDescriptor::PluginInfo::Flag> flags = reqPlugin.flags;
|
||||||
|
|
||||||
bool actionsFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::ACTIONS);
|
bool actionsFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::ACTIONS);
|
||||||
if(actionsFlag)
|
if (actionsFlag)
|
||||||
strFlags.append(QLatin1String("actions "));
|
strFlags.append(QLatin1String("actions "));
|
||||||
bool mainFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::MAIN);
|
bool mainFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::MAIN);
|
||||||
if(mainFlag)
|
if (mainFlag)
|
||||||
strFlags.append(QLatin1String("main "));
|
strFlags.append(QLatin1String("main "));
|
||||||
bool payloadFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::PAYLOAD);
|
bool payloadFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::PAYLOAD);
|
||||||
if(payloadFlag)
|
if (payloadFlag)
|
||||||
strFlags.append(QLatin1String("payload "));
|
strFlags.append(QLatin1String("payload "));
|
||||||
bool optionalFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::OPTION);
|
bool optionalFlag = flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::OPTION);
|
||||||
if(optionalFlag)
|
if (optionalFlag)
|
||||||
strFlags.append(QLatin1String("optional "));
|
strFlags.append(QLatin1String("optional "));
|
||||||
|
|
||||||
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid + QLatin1String(" [ ") + strFlags + QLatin1String("]"));
|
pluginList << QString(type + QLatin1String(": ") + reqPlugin.iid + QLatin1String(" [ ") + strFlags +
|
||||||
|
QLatin1String("]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
updatePluginModel(pluginList);
|
updatePluginModel(pluginList);
|
||||||
|
|
||||||
@@ -120,7 +118,7 @@ void LtsAppDescriptorEditor::onAppsClicked(const QModelIndex &index)
|
|||||||
m_ui->leAppName->setText(m_vector.at(m_appIndex.row()).appName);
|
m_ui->leAppName->setText(m_vector.at(m_appIndex.row()).appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex &index)
|
void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
m_pluginIndex = index;
|
m_pluginIndex = index;
|
||||||
m_ui->pbDeletePlugin->setEnabled(true);
|
m_ui->pbDeletePlugin->setEnabled(true);
|
||||||
@@ -135,13 +133,13 @@ void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex &index)
|
|||||||
QString type;
|
QString type;
|
||||||
if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::DATA)
|
if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::DATA)
|
||||||
type = QLatin1String("data");
|
type = QLatin1String("data");
|
||||||
else if(pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
else if (pluginType == LtsAppDescriptor::PluginInfo::PluginType::GUI)
|
||||||
type = QLatin1String("gui");
|
type = QLatin1String("gui");
|
||||||
else
|
else
|
||||||
type = QLatin1String("unknown");
|
type = QLatin1String("unknown");
|
||||||
m_ui->lePluginType->setText(type);
|
m_ui->lePluginType->setText(type);
|
||||||
|
|
||||||
if(type == QLatin1String("gui"))
|
if (type == QLatin1String("gui"))
|
||||||
{
|
{
|
||||||
m_ui->chbActions->setEnabled(true);
|
m_ui->chbActions->setEnabled(true);
|
||||||
m_ui->chbMain->setEnabled(true);
|
m_ui->chbMain->setEnabled(true);
|
||||||
@@ -168,16 +166,16 @@ void LtsAppDescriptorEditor::onPluginsClicked(const QModelIndex &index)
|
|||||||
|
|
||||||
void LtsAppDescriptorEditor::pluginTypeChanged()
|
void LtsAppDescriptorEditor::pluginTypeChanged()
|
||||||
{
|
{
|
||||||
if(m_ui->lePluginType->text().isEmpty())
|
if (m_ui->lePluginType->text().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(m_ui->lePluginType->text() == QLatin1String("gui"))
|
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||||
{
|
{
|
||||||
m_ui->chbActions->setEnabled(true);
|
m_ui->chbActions->setEnabled(true);
|
||||||
m_ui->chbMain->setEnabled(true);
|
m_ui->chbMain->setEnabled(true);
|
||||||
m_ui->chbPayload->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->setChecked(false);
|
||||||
m_ui->chbActions->setEnabled(false);
|
m_ui->chbActions->setEnabled(false);
|
||||||
@@ -188,8 +186,7 @@ void LtsAppDescriptorEditor::pluginTypeChanged()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Information,
|
QMessageBox msgBox(QMessageBox::Information, tr("Error"),
|
||||||
tr("Error"),
|
|
||||||
tr("Plugin Type must either be \"gui\" or \"data\"."));
|
tr("Plugin Type must either be \"gui\" or \"data\"."));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
m_ui->lePluginType->setText(QString());
|
m_ui->lePluginType->setText(QString());
|
||||||
@@ -200,25 +197,22 @@ void LtsAppDescriptorEditor::onAppAddClicked()
|
|||||||
{
|
{
|
||||||
m_changed = true;
|
m_changed = true;
|
||||||
|
|
||||||
if(m_ui->leAppName->text().isEmpty())
|
if (m_ui->leAppName->text().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The App needs to have a name."));
|
||||||
tr("Error"),
|
|
||||||
tr("The App needs to have a name."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList appList;
|
QStringList appList;
|
||||||
Q_FOREACH(const LtsAppDescriptor::AppDescription &appDesc, m_vector)
|
Q_FOREACH (const LtsAppDescriptor::AppDescription& appDesc, m_vector)
|
||||||
{
|
{
|
||||||
appList << appDesc.appName;
|
appList << appDesc.appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(appList.contains(m_ui->leAppName->text(),Qt::CaseInsensitive))
|
if (appList.contains(m_ui->leAppName->text(), Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
|
||||||
tr("Error"),
|
|
||||||
tr("There already exists an app named \"%1\".").arg(m_ui->leAppName->text()));
|
tr("There already exists an app named \"%1\".").arg(m_ui->leAppName->text()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
@@ -230,83 +224,74 @@ void LtsAppDescriptorEditor::onAppAddClicked()
|
|||||||
m_vector.append(newApp);
|
m_vector.append(newApp);
|
||||||
|
|
||||||
updateAppModel();
|
updateAppModel();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onPluginAddClicked()
|
void LtsAppDescriptorEditor::onPluginAddClicked()
|
||||||
{
|
{
|
||||||
m_changed = true;
|
m_changed = true;
|
||||||
|
|
||||||
if(m_ui->lePluginType->text().isEmpty())
|
if (m_ui->lePluginType->text().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to contain a type."));
|
||||||
tr("Error"),
|
|
||||||
tr("The Plugin needs to contain a type."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(m_ui->lePluginName->text().isEmpty())
|
if (m_ui->lePluginName->text().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to have a name."));
|
||||||
tr("Error"),
|
|
||||||
tr("The Plugin needs to have a name."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList pluginList;
|
QStringList pluginList;
|
||||||
Q_FOREACH(const LtsAppDescriptor::PluginInfo &pluginDesc, m_vector.at(m_appIndex.row()).requiredPlugins)
|
Q_FOREACH (const LtsAppDescriptor::PluginInfo& pluginDesc, m_vector.at(m_appIndex.row()).requiredPlugins)
|
||||||
{
|
{
|
||||||
pluginList << pluginDesc.iid;
|
pluginList << pluginDesc.iid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pluginList.contains(m_ui->lePluginName->text(),Qt::CaseInsensitive))
|
if (pluginList.contains(m_ui->lePluginName->text(), Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
|
||||||
tr("Error"),
|
|
||||||
tr("There already exists an plugin named \"%1\".").arg(m_ui->lePluginName->text()));
|
tr("There already exists an plugin named \"%1\".").arg(m_ui->lePluginName->text()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LtsAppDescriptor::PluginInfo newPlugin;
|
LtsAppDescriptor::PluginInfo newPlugin;
|
||||||
|
|
||||||
newPlugin.iid = m_ui->lePluginName->text();
|
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;
|
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;
|
newPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||||
else
|
else
|
||||||
newPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
newPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
||||||
|
|
||||||
if(m_ui->chbActions->isChecked())
|
if (m_ui->chbActions->isChecked())
|
||||||
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
||||||
if(m_ui->chbMain->isChecked())
|
if (m_ui->chbMain->isChecked())
|
||||||
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
||||||
if(m_ui->chbPayload->isChecked())
|
if (m_ui->chbPayload->isChecked())
|
||||||
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
newPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
||||||
|
|
||||||
m_vector[m_appIndex.row()].requiredPlugins.append(newPlugin);
|
m_vector[m_appIndex.row()].requiredPlugins.append(newPlugin);
|
||||||
|
|
||||||
onAppsClicked(m_appIndex);
|
onAppsClicked(m_appIndex);
|
||||||
onNewpluginClicked();
|
onNewpluginClicked();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onAppDeleteClicked()
|
void LtsAppDescriptorEditor::onAppDeleteClicked()
|
||||||
{
|
{
|
||||||
m_changed = true;
|
m_changed = true;
|
||||||
|
|
||||||
if(!m_appIndex.isValid()) return;
|
if (!m_appIndex.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
QMessageBox msgBox(tr("Warning"),
|
QMessageBox msgBox(tr("Warning"),
|
||||||
tr("The App \n\"%1\" \nwill be removed. Continue?").arg(m_appIndex.data().toString()),
|
tr("The App \n\"%1\" \nwill be removed. Continue?").arg(m_appIndex.data().toString()),
|
||||||
QMessageBox::Warning,
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||||
QMessageBox::Yes | QMessageBox::Default,
|
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||||
QMessageBox::No | QMessageBox::Escape,
|
|
||||||
QMessageBox::NoButton);
|
|
||||||
|
|
||||||
if (msgBox.exec() == QMessageBox::No)
|
if (msgBox.exec() == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
@@ -314,21 +299,19 @@ void LtsAppDescriptorEditor::onAppDeleteClicked()
|
|||||||
m_vector.remove(m_appIndex.row());
|
m_vector.remove(m_appIndex.row());
|
||||||
|
|
||||||
updateAppModel();
|
updateAppModel();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::onPluginDeletedClicked()
|
void LtsAppDescriptorEditor::onPluginDeletedClicked()
|
||||||
{
|
{
|
||||||
m_changed = true;
|
m_changed = true;
|
||||||
|
|
||||||
if(!m_pluginIndex.isValid()) return;
|
if (!m_pluginIndex.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
QMessageBox msgBox(tr("Warning"),
|
QMessageBox msgBox(tr("Warning"),
|
||||||
tr("The Plugin \n\"%1\" \nwill be removed. Continue?").arg(m_pluginIndex.data().toString()),
|
tr("The Plugin \n\"%1\" \nwill be removed. Continue?").arg(m_pluginIndex.data().toString()),
|
||||||
QMessageBox::Warning,
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||||
QMessageBox::Yes | QMessageBox::Default,
|
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||||
QMessageBox::No | QMessageBox::Escape,
|
|
||||||
QMessageBox::NoButton);
|
|
||||||
|
|
||||||
if (msgBox.exec() == QMessageBox::No)
|
if (msgBox.exec() == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
@@ -352,40 +335,43 @@ void LtsAppDescriptorEditor::onUpdateClicked()
|
|||||||
{
|
{
|
||||||
m_changed = true;
|
m_changed = true;
|
||||||
|
|
||||||
if(m_ui->lePluginType->text().isEmpty())
|
if (m_ui->lePluginType->text().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to contain a type."));
|
||||||
tr("Error"),
|
|
||||||
tr("The Plugin needs to contain a type."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(m_ui->lePluginName->text().isEmpty())
|
if (m_ui->lePluginName->text().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(QMessageBox::Critical,
|
QMessageBox msgBox(QMessageBox::Critical, tr("Error"), tr("The Plugin needs to have a name."));
|
||||||
tr("Error"),
|
|
||||||
tr("The Plugin needs to have a name."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].iid = m_ui->lePluginName->text();
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].iid = m_ui->lePluginName->text();
|
||||||
|
|
||||||
if(m_ui->lePluginType->text() == QLatin1String("gui"))
|
if (m_ui->lePluginType->text() == QLatin1String("gui"))
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||||
else if(m_ui->lePluginType->text() == QLatin1String("data"))
|
LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
else if (m_ui->lePluginType->text() == QLatin1String("data"))
|
||||||
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||||
|
LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||||
else
|
else
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type = LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].type =
|
||||||
|
LtsAppDescriptor::PluginInfo::PluginType::UNKNOWN;
|
||||||
|
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags = QFlags<LtsAppDescriptor::PluginInfo::Flag>();
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags =
|
||||||
|
QFlags<LtsAppDescriptor::PluginInfo::Flag>();
|
||||||
|
|
||||||
if(m_ui->chbActions->isChecked())
|
if (m_ui->chbActions->isChecked())
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||||
if(m_ui->chbMain->isChecked())
|
LtsAppDescriptor::PluginInfo::Flag::ACTIONS;
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::MAIN;
|
if (m_ui->chbMain->isChecked())
|
||||||
if(m_ui->chbPayload->isChecked())
|
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |=
|
||||||
m_vector[m_appIndex.row()].requiredPlugins[m_pluginIndex.row()].flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
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);
|
onAppsClicked(m_appIndex);
|
||||||
onNewpluginClicked();
|
onNewpluginClicked();
|
||||||
@@ -405,8 +391,8 @@ void LtsAppDescriptorEditor::onNewpluginClicked()
|
|||||||
m_ui->pbNewPlugin->setEnabled(false);
|
m_ui->pbNewPlugin->setEnabled(false);
|
||||||
m_ui->pbDeletePlugin->setEnabled(false);
|
m_ui->pbDeletePlugin->setEnabled(false);
|
||||||
|
|
||||||
if(m_pluginIndex.isValid())
|
if (m_pluginIndex.isValid())
|
||||||
m_ui->lvPlugins->selectionModel()->select(m_pluginIndex,QItemSelectionModel::Deselect);
|
m_ui->lvPlugins->selectionModel()->select(m_pluginIndex, QItemSelectionModel::Deselect);
|
||||||
m_pluginIndex = QModelIndex();
|
m_pluginIndex = QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,8 +415,8 @@ void LtsAppDescriptorEditor::onNewAppClicked()
|
|||||||
m_ui->chbPayload->setChecked(false);
|
m_ui->chbPayload->setChecked(false);
|
||||||
m_ui->pbNewApp->setEnabled(false);
|
m_ui->pbNewApp->setEnabled(false);
|
||||||
|
|
||||||
if(m_appIndex.isValid())
|
if (m_appIndex.isValid())
|
||||||
m_ui->lvApps->selectionModel()->select(m_appIndex,QItemSelectionModel::Deselect);
|
m_ui->lvApps->selectionModel()->select(m_appIndex, QItemSelectionModel::Deselect);
|
||||||
m_appIndex = QModelIndex();
|
m_appIndex = QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,24 +424,24 @@ void LtsAppDescriptorEditor::updateAppModel()
|
|||||||
{
|
{
|
||||||
onNewAppClicked();
|
onNewAppClicked();
|
||||||
QStringList appList;
|
QStringList appList;
|
||||||
Q_FOREACH(const LtsAppDescriptor::AppDescription &appDesc, m_vector)
|
Q_FOREACH (const LtsAppDescriptor::AppDescription& appDesc, m_vector)
|
||||||
{
|
{
|
||||||
appList << appDesc.appName;
|
appList << appDesc.appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_ui->lvApps->model())
|
if (!m_ui->lvApps->model())
|
||||||
m_ui->lvApps->setModel(new QStringListModel(this));
|
m_ui->lvApps->setModel(new QStringListModel(this));
|
||||||
QStringListModel *m = qobject_cast<QStringListModel*>(m_ui->lvApps->model());
|
QStringListModel* m = qobject_cast<QStringListModel*>(m_ui->lvApps->model());
|
||||||
if (!m)
|
if (!m)
|
||||||
return;
|
return;
|
||||||
m->setStringList(appList);
|
m->setStringList(appList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::updatePluginModel(const QStringList &list)
|
void LtsAppDescriptorEditor::updatePluginModel(const QStringList& list)
|
||||||
{
|
{
|
||||||
if (!m_ui->lvPlugins->model())
|
if (!m_ui->lvPlugins->model())
|
||||||
m_ui->lvPlugins->setModel(new QStringListModel(this));
|
m_ui->lvPlugins->setModel(new QStringListModel(this));
|
||||||
QStringListModel *m = qobject_cast<QStringListModel*>(m_ui->lvPlugins->model());
|
QStringListModel* m = qobject_cast<QStringListModel*>(m_ui->lvPlugins->model());
|
||||||
if (!m)
|
if (!m)
|
||||||
return;
|
return;
|
||||||
m->setStringList(list);
|
m->setStringList(list);
|
||||||
@@ -463,14 +449,11 @@ void LtsAppDescriptorEditor::updatePluginModel(const QStringList &list)
|
|||||||
|
|
||||||
void LtsAppDescriptorEditor::checkSave()
|
void LtsAppDescriptorEditor::checkSave()
|
||||||
{
|
{
|
||||||
if(m_changed)
|
if (m_changed)
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(tr("Warning"),
|
QMessageBox msgBox(tr("Warning"), tr("The Data has been modified.\nDo you want to save your changes?"),
|
||||||
tr("The Data has been modified.\nDo you want to save your changes?"),
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default,
|
||||||
QMessageBox::Warning,
|
QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton);
|
||||||
QMessageBox::Yes | QMessageBox::Default,
|
|
||||||
QMessageBox::No | QMessageBox::Escape,
|
|
||||||
QMessageBox::NoButton);
|
|
||||||
|
|
||||||
if (msgBox.exec() == QMessageBox::Yes)
|
if (msgBox.exec() == QMessageBox::Yes)
|
||||||
onSaveAsClicked();
|
onSaveAsClicked();
|
||||||
@@ -479,9 +462,10 @@ void LtsAppDescriptorEditor::checkSave()
|
|||||||
|
|
||||||
void LtsAppDescriptorEditor::onSaveAsClicked()
|
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)"));
|
tr("JSON File (*.json)"));
|
||||||
if(fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QByteArray jsonByteArray;
|
QByteArray jsonByteArray;
|
||||||
@@ -494,9 +478,7 @@ void LtsAppDescriptorEditor::onSaveAsClicked()
|
|||||||
|
|
||||||
m_changed = false;
|
m_changed = false;
|
||||||
|
|
||||||
QMessageBox msgBox(QMessageBox::Information,
|
QMessageBox msgBox(QMessageBox::Information, tr("Success"), tr("Your file has been saved."));
|
||||||
tr("Success"),
|
|
||||||
tr("Your file has been saved."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,9 +493,7 @@ void LtsAppDescriptorEditor::onSaveClicked()
|
|||||||
|
|
||||||
m_changed = false;
|
m_changed = false;
|
||||||
|
|
||||||
QMessageBox msgBox(QMessageBox::Information,
|
QMessageBox msgBox(QMessageBox::Information, tr("Success"), tr("Your file has been saved."));
|
||||||
tr("Success"),
|
|
||||||
tr("Your file has been saved."));
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,7 +520,6 @@ void LtsAppDescriptorEditor::onNewClicked()
|
|||||||
|
|
||||||
updateAppModel();
|
updateAppModel();
|
||||||
updatePluginModel(QStringList());
|
updatePluginModel(QStringList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsAppDescriptorEditor::enableNewPlugin()
|
void LtsAppDescriptorEditor::enableNewPlugin()
|
||||||
|
|||||||
Executable → Regular
+22
-24
@@ -1,36 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <QtWidgets/QWidget>
|
|
||||||
#include <QModelIndex>
|
|
||||||
|
|
||||||
#include "lts_app_descriptor.h"
|
#include "lts_app_descriptor.h"
|
||||||
|
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtWidgets/QWidget>
|
||||||
|
|
||||||
#ifndef LTSAPPDESCRIPTOREDITOR_EXPORT
|
#ifndef LTSAPPDESCRIPTOREDITOR_EXPORT
|
||||||
# ifdef BUILD_STATIC_LIBRARIES
|
#ifdef BUILD_STATIC_LIBRARIES
|
||||||
# define LTSAPPDESCRIPTOREDITOR_EXPORT
|
#define LTSAPPDESCRIPTOREDITOR_EXPORT
|
||||||
# else
|
#else
|
||||||
# if defined(MAKE_LTSAPPDESCRIPTOREDITOR_LIB)
|
#if defined(MAKE_LTSAPPDESCRIPTOREDITOR_LIB)
|
||||||
# define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_EXPORT
|
#define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_EXPORT
|
||||||
# else
|
#else
|
||||||
# define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_IMPORT
|
#define LTSAPPDESCRIPTOREDITOR_EXPORT Q_DECL_IMPORT
|
||||||
# endif
|
#endif
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Ui_LtsAppDescriptionEditor;
|
class Ui_LtsAppDescriptionEditor;
|
||||||
|
|
||||||
|
|
||||||
class LTSAPPDESCRIPTOREDITOR_EXPORT LtsAppDescriptorEditor : public QWidget
|
class LTSAPPDESCRIPTOREDITOR_EXPORT LtsAppDescriptorEditor : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LtsAppDescriptorEditor(QWidget *parent = 0);
|
explicit LtsAppDescriptorEditor(QWidget* parent = 0);
|
||||||
~LtsAppDescriptorEditor();
|
~LtsAppDescriptorEditor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_LtsAppDescriptionEditor *m_ui;
|
Ui_LtsAppDescriptionEditor* m_ui;
|
||||||
LtsAppDescriptor::AppDescriptionVector m_vector;
|
LtsAppDescriptor::AppDescriptionVector m_vector;
|
||||||
QModelIndex m_appIndex;
|
QModelIndex m_appIndex;
|
||||||
QModelIndex m_pluginIndex;
|
QModelIndex m_pluginIndex;
|
||||||
@@ -42,12 +40,12 @@ private:
|
|||||||
void getAppDescriptionVector();
|
void getAppDescriptionVector();
|
||||||
void setupMainWindow();
|
void setupMainWindow();
|
||||||
void updateAppModel();
|
void updateAppModel();
|
||||||
void updatePluginModel(const QStringList &list);
|
void updatePluginModel(const QStringList& list);
|
||||||
void checkSave();
|
void checkSave();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAppsClicked(const QModelIndex &index);
|
void onAppsClicked(const QModelIndex& index);
|
||||||
void onPluginsClicked(const QModelIndex &index);
|
void onPluginsClicked(const QModelIndex& index);
|
||||||
void pluginTypeChanged();
|
void pluginTypeChanged();
|
||||||
void onAppAddClicked();
|
void onAppAddClicked();
|
||||||
void onPluginAddClicked();
|
void onPluginAddClicked();
|
||||||
@@ -58,7 +56,7 @@ private slots:
|
|||||||
void onNewAppClicked();
|
void onNewAppClicked();
|
||||||
void enableNewPlugin();
|
void enableNewPlugin();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onSaveClicked();
|
void onSaveClicked();
|
||||||
void onSaveAsClicked();
|
void onSaveAsClicked();
|
||||||
void onOpenClicked();
|
void onOpenClicked();
|
||||||
|
|||||||
Executable → Regular
+10
-11
@@ -1,46 +1,45 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_app_descriptor_editor.h"
|
#include "lts_app_descriptor_editor.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
QMainWindow *mainWindow = new QMainWindow();
|
QMainWindow* mainWindow = new QMainWindow();
|
||||||
QMenu *fileMenu = mainWindow->menuBar()->addMenu(QObject::tr("&File"));
|
QMenu* fileMenu = mainWindow->menuBar()->addMenu(QObject::tr("&File"));
|
||||||
|
|
||||||
QAction *openAct = new QAction(QObject::tr("&Open"), mainWindow);
|
QAction* openAct = new QAction(QObject::tr("&Open"), mainWindow);
|
||||||
openAct->setShortcuts(QKeySequence::Open);
|
openAct->setShortcuts(QKeySequence::Open);
|
||||||
openAct->setStatusTip(QObject::tr("Open an existing file"));
|
openAct->setStatusTip(QObject::tr("Open an existing file"));
|
||||||
fileMenu->addAction(openAct);
|
fileMenu->addAction(openAct);
|
||||||
|
|
||||||
QAction *newAct = new QAction(QObject::tr("&New"), mainWindow);
|
QAction* newAct = new QAction(QObject::tr("&New"), mainWindow);
|
||||||
newAct->setShortcuts(QKeySequence::New);
|
newAct->setShortcuts(QKeySequence::New);
|
||||||
newAct->setStatusTip(QObject::tr("Create a new App"));
|
newAct->setStatusTip(QObject::tr("Create a new App"));
|
||||||
fileMenu->addAction(newAct);
|
fileMenu->addAction(newAct);
|
||||||
|
|
||||||
QAction *saveAct = new QAction(QObject::tr("&Save"), mainWindow);
|
QAction* saveAct = new QAction(QObject::tr("&Save"), mainWindow);
|
||||||
saveAct->setShortcuts(QKeySequence::Save);
|
saveAct->setShortcuts(QKeySequence::Save);
|
||||||
saveAct->setStatusTip(QObject::tr("Save modified file"));
|
saveAct->setStatusTip(QObject::tr("Save modified file"));
|
||||||
fileMenu->addAction(saveAct);
|
fileMenu->addAction(saveAct);
|
||||||
|
|
||||||
QAction *saveAsAct = new QAction(QObject::tr("&SaveAs"), mainWindow);
|
QAction* saveAsAct = new QAction(QObject::tr("&SaveAs"), mainWindow);
|
||||||
saveAsAct->setShortcuts(QKeySequence::SaveAs);
|
saveAsAct->setShortcuts(QKeySequence::SaveAs);
|
||||||
saveAsAct->setStatusTip(QObject::tr("Save modified file as"));
|
saveAsAct->setStatusTip(QObject::tr("Save modified file as"));
|
||||||
fileMenu->addAction(saveAsAct);
|
fileMenu->addAction(saveAsAct);
|
||||||
|
|
||||||
QAction *quitAct = new QAction(QObject::tr("&Quit"), mainWindow);
|
QAction* quitAct = new QAction(QObject::tr("&Quit"), mainWindow);
|
||||||
quitAct->setShortcuts(QKeySequence::Quit);
|
quitAct->setShortcuts(QKeySequence::Quit);
|
||||||
quitAct->setStatusTip(QObject::tr("Quit the Application"));
|
quitAct->setStatusTip(QObject::tr("Quit the Application"));
|
||||||
fileMenu->addAction(quitAct);
|
fileMenu->addAction(quitAct);
|
||||||
|
|
||||||
|
LtsAppDescriptorEditor* editor = new LtsAppDescriptorEditor(mainWindow);
|
||||||
LtsAppDescriptorEditor *editor = new LtsAppDescriptorEditor(mainWindow);
|
|
||||||
mainWindow->setCentralWidget(editor);
|
mainWindow->setCentralWidget(editor);
|
||||||
QObject::connect(openAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onOpenClicked);
|
QObject::connect(openAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onOpenClicked);
|
||||||
QObject::connect(newAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onNewClicked);
|
QObject::connect(newAct, &QAction::triggered, editor, &LtsAppDescriptorEditor::onNewClicked);
|
||||||
|
|||||||
Executable → Regular
+5
-8
@@ -1,17 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "app.h"
|
#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
|
namespace LtsAppManager
|
||||||
{
|
{
|
||||||
|
|
||||||
CustomViewApp::CustomViewApp(QWidget *parent)
|
CustomViewApp::CustomViewApp(QWidget* parent) : AbstractDisplayWidget(parent), m_ui(new Ui::CustomViewApp)
|
||||||
: AbstractDisplayWidget(parent)
|
|
||||||
, m_ui(new Ui::CustomViewApp)
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
m_ui->image->setMenuEnabled(false);
|
m_ui->image->setMenuEnabled(false);
|
||||||
@@ -22,7 +19,7 @@ CustomViewApp::~CustomViewApp()
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomViewApp::init(const QModelIndex &idx)
|
bool CustomViewApp::init(const QModelIndex& idx)
|
||||||
{
|
{
|
||||||
if (!idx.isValid())
|
if (!idx.isValid())
|
||||||
return false;
|
return false;
|
||||||
@@ -32,4 +29,4 @@ bool CustomViewApp::init(const QModelIndex &idx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsAppManager
|
||||||
Executable → Regular
+5
-8
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include <Viewer/LtsDataView/abstract_display_widget.h>
|
#include <Viewer/LtsDataView/abstract_display_widget.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class CustomViewApp;
|
class CustomViewApp;
|
||||||
@@ -18,14 +16,13 @@ class CustomViewApp final : public LtsDataView::AbstractDisplayWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CustomViewApp(QWidget *parent = nullptr);
|
explicit CustomViewApp(QWidget* parent = nullptr);
|
||||||
~CustomViewApp();
|
~CustomViewApp();
|
||||||
bool init(const QModelIndex &idx) override;
|
bool init(const QModelIndex& idx) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CustomViewApp* m_ui;
|
Ui::CustomViewApp* m_ui;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace LtsAppManager
|
||||||
Executable → Regular
+13
-26
@@ -1,38 +1,30 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "AppChooser/app_chooser.h"
|
#include "AppChooser/app_chooser.h"
|
||||||
#include "ui_app_chooser.h"
|
|
||||||
|
#include "AppChooser/CustomViews/app.h"
|
||||||
#include "AppChooser/app_chooser_model.h"
|
#include "AppChooser/app_chooser_model.h"
|
||||||
#include "lts_app_manager.h"
|
#include "lts_app_manager.h"
|
||||||
#include "AppChooser/CustomViews/app.h"
|
#include "ui_app_chooser.h"
|
||||||
|
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppManager
|
namespace LtsAppManager
|
||||||
{
|
{
|
||||||
|
|
||||||
AppChooser::AppChooser()
|
AppChooser::AppChooser() : QWidget(nullptr), m_ui(new Ui::AppChooser), m_model(), m_madeSelection(false)
|
||||||
: QWidget(nullptr)
|
|
||||||
, m_ui(new Ui::AppChooser)
|
|
||||||
, m_model()
|
|
||||||
, m_madeSelection(false)
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalDoubleClicked,
|
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalDoubleClicked, this,
|
||||||
this, &AppChooser::slotAppSelected);
|
&AppChooser::slotAppSelected);
|
||||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalEnterPressed,
|
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalEnterPressed, this,
|
||||||
this, &AppChooser::slotAppSelected);
|
&AppChooser::slotAppSelected);
|
||||||
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalSelectionChanged,
|
connect(m_ui->widget, &LtsDataView::LtsDataView::LtsDataView::signalSelectionChanged, this, &AppChooser::enaDisa);
|
||||||
this, &AppChooser::enaDisa);
|
connect(m_ui->pbQuit, &QPushButton::clicked, this, &QWidget::close);
|
||||||
connect(m_ui->pbQuit, &QPushButton::clicked,
|
connect(m_ui->pbSelect, &QPushButton::clicked, this, &AppChooser::slotAppSelected);
|
||||||
this, &QWidget::close);
|
|
||||||
connect(m_ui->pbSelect, &QPushButton::clicked,
|
|
||||||
this, &AppChooser::slotAppSelected);
|
|
||||||
|
|
||||||
m_model = new AppChooserModel(this);
|
m_model = new AppChooserModel(this);
|
||||||
m_model->initModel(LtsAppManager::getInstance()->getAvailableApps());
|
m_model->initModel(LtsAppManager::getInstance()->getAvailableApps());
|
||||||
@@ -43,14 +35,12 @@ AppChooser::AppChooser()
|
|||||||
m_ui->widget->hideColumn(AppChooserModel::Columns::Visible);
|
m_ui->widget->hideColumn(AppChooserModel::Columns::Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AppChooser::~AppChooser()
|
AppChooser::~AppChooser()
|
||||||
{
|
{
|
||||||
|
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AppChooser::slotQuit()
|
void AppChooser::slotQuit()
|
||||||
{
|
{
|
||||||
if (m_alreadyCloseEmitted)
|
if (m_alreadyCloseEmitted)
|
||||||
@@ -59,14 +49,12 @@ void AppChooser::slotQuit()
|
|||||||
emit signalLogout();
|
emit signalLogout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppChooser::closeEvent(QCloseEvent*)
|
||||||
void AppChooser::closeEvent(QCloseEvent *)
|
|
||||||
{
|
{
|
||||||
if (!m_madeSelection)
|
if (!m_madeSelection)
|
||||||
slotQuit();
|
slotQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AppChooser::slotAppSelected()
|
void AppChooser::slotAppSelected()
|
||||||
{
|
{
|
||||||
const QModelIndex idx = m_ui->widget->currentIndex();
|
const QModelIndex idx = m_ui->widget->currentIndex();
|
||||||
@@ -81,7 +69,6 @@ void AppChooser::slotAppSelected()
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AppChooser::enaDisa()
|
void AppChooser::enaDisa()
|
||||||
{
|
{
|
||||||
const QModelIndexList selectedRows = m_ui->widget->selectedRows();
|
const QModelIndexList selectedRows = m_ui->widget->selectedRows();
|
||||||
@@ -90,4 +77,4 @@ void AppChooser::enaDisa()
|
|||||||
m_ui->pbSelect->setEnabled(cntSelectedRows == 1);
|
m_ui->pbSelect->setEnabled(cntSelectedRows == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsAppManager
|
||||||
Executable → Regular
+12
-15
@@ -1,16 +1,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class AppChooser;
|
class AppChooser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppManager
|
namespace LtsAppManager
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -20,29 +18,28 @@ class AppChooser : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppChooser();
|
AppChooser();
|
||||||
~AppChooser();
|
~AppChooser();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AppChooser *m_ui;
|
Ui::AppChooser* m_ui;
|
||||||
AppChooserModel *m_model;
|
AppChooserModel* m_model;
|
||||||
bool m_madeSelection;
|
bool m_madeSelection;
|
||||||
bool m_alreadyCloseEmitted { false };
|
bool m_alreadyCloseEmitted{false};
|
||||||
|
|
||||||
void enaDisa();
|
void enaDisa();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent*);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalAppSelected(LtsAppDescriptor::App appId);
|
void signalAppSelected(LtsAppDescriptor::App appId);
|
||||||
void signalLogout();
|
void signalLogout();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotAppSelected();
|
void slotAppSelected();
|
||||||
void slotQuit();
|
void slotQuit();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace LtsAppManager
|
||||||
Executable → Regular
+7
-9
@@ -4,17 +4,16 @@
|
|||||||
|
|
||||||
#include <LtsSession/lts_session.h>
|
#include <LtsSession/lts_session.h>
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppManager
|
namespace LtsAppManager
|
||||||
{
|
{
|
||||||
|
|
||||||
AppChooserModel::AppChooserModel(QObject *parent)
|
AppChooserModel::AppChooserModel(QObject* parent)
|
||||||
: LtsWidgets::LtsAbstractTableModel<LtsAppDescriptor::AppDescription>({tr("Name")}, 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)
|
for (auto i = availableApps.constBegin(); i != availableApps.constEnd(); ++i)
|
||||||
{
|
{
|
||||||
@@ -29,13 +28,12 @@ bool AppChooserModel::initModel(const LtsAppDescriptor::AppDescriptionVector &av
|
|||||||
return true;
|
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))
|
if (role != Qt::DisplayRole || !indexIsValid(index))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const LtsAppDescriptor::AppDescription &ad = m_vecData.at(index.row());
|
const LtsAppDescriptor::AppDescription& ad = m_vecData.at(index.row());
|
||||||
|
|
||||||
switch (index.column())
|
switch (index.column())
|
||||||
{
|
{
|
||||||
@@ -47,4 +45,4 @@ QVariant AppChooserModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
} // namespace LtsAppManager
|
||||||
Executable → Regular
+7
-12
@@ -1,12 +1,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
|
|
||||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||||
#include <LtsWidgets/lts_abstract_table_model.h>
|
#include <LtsWidgets/lts_abstract_table_model.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppManager
|
namespace LtsAppManager
|
||||||
{
|
{
|
||||||
@@ -14,17 +10,16 @@ class AppChooserModel final : public LtsWidgets::LtsAbstractTableModel<LtsAppDes
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Columns
|
enum Columns {
|
||||||
{
|
|
||||||
Name = 0,
|
Name = 0,
|
||||||
Visible,
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
|
||||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||||
#include <LtsWidgets/lts_dialog.h>
|
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
|
||||||
#include <LtsSession/lts_session.h>
|
#include <LtsSession/lts_session.h>
|
||||||
#include <memory>
|
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||||
|
#include <LtsWidgets/lts_dialog.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#ifndef LTSAPPMANAGER_EXPORT
|
#ifndef LTSAPPMANAGER_EXPORT
|
||||||
# ifdef BUILD_STATIC_LIBRARIES
|
#ifdef BUILD_STATIC_LIBRARIES
|
||||||
# define LTSAPPMANAGER_EXPORT
|
#define LTSAPPMANAGER_EXPORT
|
||||||
# else
|
#else
|
||||||
# if defined(MAKE_LTSAPPMANAGER_LIB)
|
#if defined(MAKE_LTSAPPMANAGER_LIB)
|
||||||
# define LTSAPPMANAGER_EXPORT Q_DECL_EXPORT
|
#define LTSAPPMANAGER_EXPORT Q_DECL_EXPORT
|
||||||
# else
|
#else
|
||||||
# define LTSAPPMANAGER_EXPORT Q_DECL_IMPORT
|
#define LTSAPPMANAGER_EXPORT Q_DECL_IMPORT
|
||||||
# endif
|
#endif
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace LtsPluginManager
|
namespace LtsPluginManager
|
||||||
{
|
{
|
||||||
@@ -37,7 +35,7 @@ namespace LtsSession
|
|||||||
{
|
{
|
||||||
class LtsSession;
|
class LtsSession;
|
||||||
struct DdsConnectionParams;
|
struct DdsConnectionParams;
|
||||||
}
|
} // namespace LtsSession
|
||||||
|
|
||||||
namespace DeveloperTools
|
namespace DeveloperTools
|
||||||
{
|
{
|
||||||
@@ -46,7 +44,6 @@ class DevDialog;
|
|||||||
|
|
||||||
class QTcpSocket;
|
class QTcpSocket;
|
||||||
|
|
||||||
|
|
||||||
namespace LtsAppManager
|
namespace LtsAppManager
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -54,70 +51,86 @@ class LTSAPPMANAGER_EXPORT LtsAppManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static LtsAppManager* getInstance();
|
static LtsAppManager* getInstance();
|
||||||
|
|
||||||
void showLogin();
|
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);
|
void setMainApp(LtsAppDescriptor::App appId = LtsAppDescriptor::App::Login);
|
||||||
QVector<LtsPluginManager::LtsPluginManager *> getAppList() const { return m_appList ;}
|
|
||||||
LtsAppDescriptor::AppDescriptionVector getAvailableApps() const { return m_availableApps; }
|
QVector<LtsPluginManager::LtsPluginManager*> getAppList() const
|
||||||
void setAvailableApps(const LtsAppDescriptor::AppDescriptionVector &availableApps);
|
{
|
||||||
bool hasRightForApp(const LtsAppDescriptor::AppDescription &appDescription) 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;
|
LtsAppDescriptor::AppDescription getApp(LtsAppDescriptor::App appId) const;
|
||||||
bool hasApp(LtsAppDescriptor::App appId) const;
|
bool hasApp(LtsAppDescriptor::App appId) const;
|
||||||
int getNumberOfSituationMapInstances() 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);
|
||||||
|
|
||||||
|
private:
|
||||||
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:
|
|
||||||
friend struct LtsAppManagerHandler;
|
friend struct LtsAppManagerHandler;
|
||||||
friend class DeveloperTools::DevDialog;
|
friend class DeveloperTools::DevDialog;
|
||||||
|
|
||||||
LtsAppManager();
|
LtsAppManager();
|
||||||
~LtsAppManager();
|
~LtsAppManager();
|
||||||
|
|
||||||
bool startAppOrLetUserChoose(const LtsAppDescriptor::AppDescription &appDescription, const LtsSession::DdsConnectionParams &connParams, bool force = false);
|
bool startAppOrLetUserChoose(const LtsAppDescriptor::AppDescription& appDescription,
|
||||||
LtsPluginManager::LtsPluginManager *createApp(const LtsAppDescriptor::AppDescription &appDescription,
|
const LtsSession::DdsConnectionParams& connParams, bool force = false);
|
||||||
const LtsSession::DdsConnectionParams &connParams,
|
LtsPluginManager::LtsPluginManager* createApp(const LtsAppDescriptor::AppDescription& appDescription,
|
||||||
const QString &workspaceId = QString(),
|
const LtsSession::DdsConnectionParams& connParams,
|
||||||
bool hidden = false, bool force = false);
|
const QString& workspaceId = QString(), bool hidden = false,
|
||||||
|
bool force = false);
|
||||||
void saveState();
|
void saveState();
|
||||||
|
|
||||||
LtsAppDescriptor::AppDescriptionVector m_availableApps;
|
LtsAppDescriptor::AppDescriptionVector m_availableApps;
|
||||||
QVector<LtsPluginManager::LtsPluginManager *> m_appList;
|
QVector<LtsPluginManager::LtsPluginManager*> m_appList;
|
||||||
LtsLogin::LtsLogin *m_login;
|
LtsLogin::LtsLogin* m_login;
|
||||||
LtsAppDescriptor::AppDescription m_app;
|
LtsAppDescriptor::AppDescription m_app;
|
||||||
QString m_loginPluginIid;
|
QString m_loginPluginIid;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slotLogout();
|
void slotLogout();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotQuit();
|
void slotQuit();
|
||||||
void slotSoftQuit();
|
void slotSoftQuit();
|
||||||
void slotShowLogin();
|
void slotShowLogin();
|
||||||
void slotAppDestroyed();
|
void slotAppDestroyed();
|
||||||
void slotStartDebugServer();
|
void slotStartDebugServer();
|
||||||
void hideAllOtherBLWs(QObject *_caller);
|
void hideAllOtherBLWs(QObject* _caller);
|
||||||
void taskSwitch(QObject *_caller);
|
void taskSwitch(QObject* _caller);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalLoginDone();
|
void signalLoginDone();
|
||||||
void signalLogoffDone();
|
void signalLogoffDone();
|
||||||
void signalShowLogin();
|
void signalShowLogin();
|
||||||
void signalInitializationFinished();
|
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 "LtsCommandLineParser.h"
|
||||||
#include <ngltools/ngltools_filesystem.h>
|
|
||||||
#include <QNetworkInterface>
|
|
||||||
#include <QFlags>
|
#include <QFlags>
|
||||||
|
#include <QNetworkInterface>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <ngltools/ngltools_filesystem.h>
|
||||||
|
|
||||||
namespace LtsCommandLineParser
|
namespace LtsCommandLineParser
|
||||||
{
|
{
|
||||||
static constexpr int s_maxDomainId = 232;
|
static constexpr int s_maxDomainId = 232;
|
||||||
|
|
||||||
LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions opts)
|
LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions opts)
|
||||||
: QCommandLineParser()
|
: QCommandLineParser(), m_enabledOptions(opts)
|
||||||
, m_enabledOptions(opts)
|
|
||||||
{
|
{
|
||||||
if (NGL::isAppInBuildBasePath() || m_enabledOptions.testFlag(CreateDomainIdFromIp))
|
if (NGL::isAppInBuildBasePath() || m_enabledOptions.testFlag(CreateDomainIdFromIp))
|
||||||
{
|
{
|
||||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
||||||
for (const QHostAddress &address : addresses)
|
for (const QHostAddress& address : addresses)
|
||||||
{
|
{
|
||||||
if (address.isLoopback() || address.isNull())
|
if (address.isLoopback() || address.isNull())
|
||||||
continue;
|
continue;
|
||||||
if (address.protocol() != QAbstractSocket::IPv4Protocol)
|
if (address.protocol() != QAbstractSocket::IPv4Protocol)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
m_generatedDomainId = (address.toIPv4Address() & 0x000000ff) % 232;
|
m_generatedDomainId = (address.toIPv4Address() & 0x000000ff) % 232;
|
||||||
if (m_generatedDomainId == 0)
|
if (m_generatedDomainId == 0)
|
||||||
m_generatedDomainId = s_maxDomainId;
|
m_generatedDomainId = s_maxDomainId;
|
||||||
@@ -38,22 +36,19 @@ LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions op
|
|||||||
addOption({{QStringLiteral("e"), QStringLiteral("exerciseid")},
|
addOption({{QStringLiteral("e"), QStringLiteral("exerciseid")},
|
||||||
QStringLiteral("Default: -1 (invalid, get from lts-cc.conf)"),
|
QStringLiteral("Default: -1 (invalid, get from lts-cc.conf)"),
|
||||||
QStringLiteral("exerciseId"),
|
QStringLiteral("exerciseId"),
|
||||||
QStringLiteral("-1")
|
QStringLiteral("-1")});
|
||||||
});
|
|
||||||
if (m_enabledOptions.testFlag(DomainId))
|
if (m_enabledOptions.testFlag(DomainId))
|
||||||
addOption({{QStringLiteral("d"), QStringLiteral("domainid")},
|
addOption({{QStringLiteral("d"), QStringLiteral("domainid")},
|
||||||
QStringLiteral("Default: ") + QString::number(m_generatedDomainId),
|
QStringLiteral("Default: ") + QString::number(m_generatedDomainId),
|
||||||
QStringLiteral("domainId"),
|
QStringLiteral("domainId"),
|
||||||
QString::number(m_generatedDomainId)
|
QString::number(m_generatedDomainId)});
|
||||||
});
|
|
||||||
if (m_enabledOptions.testFlag(CustomConfigFile))
|
if (m_enabledOptions.testFlag(CustomConfigFile))
|
||||||
{
|
{
|
||||||
const QString cf(NGL::findProjectConfigFile());
|
const QString cf(NGL::findProjectConfigFile());
|
||||||
addOption({{QStringLiteral("i"), QStringLiteral("ini")},
|
addOption({{QStringLiteral("i"), QStringLiteral("ini")},
|
||||||
QStringLiteral("Default: ") + cf,
|
QStringLiteral("Default: ") + cf,
|
||||||
QStringLiteral("filename"),
|
QStringLiteral("filename"),
|
||||||
cf
|
cf});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (m_enabledOptions.testFlag(TcpConnectionUrl))
|
if (m_enabledOptions.testFlag(TcpConnectionUrl))
|
||||||
{
|
{
|
||||||
@@ -61,8 +56,7 @@ LtsCommandLineParser::LtsCommandLineParser(ProvideCommandLineParameterOptions op
|
|||||||
addOption({{QStringLiteral("t"), QStringLiteral("tcpurl")},
|
addOption({{QStringLiteral("t"), QStringLiteral("tcpurl")},
|
||||||
QStringLiteral("Default: ") + defaultTcpUrl,
|
QStringLiteral("Default: ") + defaultTcpUrl,
|
||||||
QStringLiteral("hostname:port"),
|
QStringLiteral("hostname:port"),
|
||||||
defaultTcpUrl
|
defaultTcpUrl});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
addHelpOption();
|
addHelpOption();
|
||||||
|
|
||||||
@@ -76,9 +70,15 @@ int LtsCommandLineParser::domainId() const
|
|||||||
{
|
{
|
||||||
#ifdef WIN32
|
#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
|
#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
|
#endif
|
||||||
return m_generatedDomainId;
|
return m_generatedDomainId;
|
||||||
}
|
}
|
||||||
@@ -115,8 +115,7 @@ QUrl LtsCommandLineParser::tcpConnectionUrl() const
|
|||||||
|
|
||||||
str.replace(QLatin1String("tcpv4_lan"), QLatin1String("tcpv4lan"));
|
str.replace(QLatin1String("tcpv4_lan"), QLatin1String("tcpv4lan"));
|
||||||
QUrl url = QUrl::fromUserInput(str);
|
QUrl url = QUrl::fromUserInput(str);
|
||||||
if (url.scheme() == QLatin1String("http") ||
|
if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("file"))
|
||||||
url.scheme() == QLatin1String("file"))
|
|
||||||
url.setScheme(QStringLiteral("tcpv4lan"));
|
url.setScheme(QStringLiteral("tcpv4lan"));
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -161,7 +160,6 @@ void LtsCommandLineParser::showHelp(int exitCode)
|
|||||||
if (!m_additionalHelpStr.isEmpty())
|
if (!m_additionalHelpStr.isEmpty())
|
||||||
fprintf(stdout, "%s", qPrintable(m_additionalHelpStr));
|
fprintf(stdout, "%s", qPrintable(m_additionalHelpStr));
|
||||||
|
|
||||||
|
|
||||||
QCommandLineParser::showHelp(exitCode);
|
QCommandLineParser::showHelp(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,5 +177,4 @@ bool LtsCommandLineParser::exerciseIdProvided() const
|
|||||||
return isSet(QStringLiteral("e"));
|
return isSet(QStringLiteral("e"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace LtsCommandLineParser
|
||||||
}
|
|
||||||
Executable → Regular
+25
-12
@@ -1,19 +1,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QCommandLineParser>
|
|
||||||
#include "ltscommandlineparser_export.h"
|
#include "ltscommandlineparser_export.h"
|
||||||
|
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
class QUrl;
|
class QUrl;
|
||||||
|
|
||||||
namespace LtsCommandLineParser
|
namespace LtsCommandLineParser
|
||||||
{
|
{
|
||||||
class LTSCOMMANDLINEPARSER_EXPORT LtsCommandLineParser : public QCommandLineParser
|
class LTSCOMMANDLINEPARSER_EXPORT LtsCommandLineParser : public QCommandLineParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ProvideCommandLineParameterOptions
|
enum ProvideCommandLineParameterOptions {
|
||||||
{
|
|
||||||
None = 0x0000,
|
None = 0x0000,
|
||||||
CreateDomainIdFromIp = 0x0001,
|
CreateDomainIdFromIp = 0x0001,
|
||||||
DomainId = 0x0002,
|
DomainId = 0x0002,
|
||||||
@@ -23,12 +23,22 @@ public:
|
|||||||
NoVersion = 0x0020
|
NoVersion = 0x0020
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit LtsCommandLineParser(ProvideCommandLineParameterOptions opts = ProvideCommandLineParameterOptions(CreateDomainIdFromIp|DomainId|ExerciseId|CustomConfigFile));
|
explicit LtsCommandLineParser(ProvideCommandLineParameterOptions opts = ProvideCommandLineParameterOptions(
|
||||||
|
CreateDomainIdFromIp | DomainId | ExerciseId | CustomConfigFile));
|
||||||
virtual ~LtsCommandLineParser() = default;
|
virtual ~LtsCommandLineParser() = default;
|
||||||
int domainId() const;
|
int domainId() const;
|
||||||
void setDomainId(int id);
|
void setDomainId(int id);
|
||||||
int exerciseId() const { return m_exerciseId; }
|
|
||||||
QString iniFile() const { return m_iniFile; }
|
int exerciseId() const
|
||||||
|
{
|
||||||
|
return m_exerciseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString iniFile() const
|
||||||
|
{
|
||||||
|
return m_iniFile;
|
||||||
|
}
|
||||||
|
|
||||||
bool iniFileSet() const;
|
bool iniFileSet() const;
|
||||||
bool useTcpConnection() const;
|
bool useTcpConnection() const;
|
||||||
QUrl tcpConnectionUrl() const;
|
QUrl tcpConnectionUrl() const;
|
||||||
@@ -38,12 +48,15 @@ public:
|
|||||||
bool domainIdProvided() const;
|
bool domainIdProvided() const;
|
||||||
bool exerciseIdProvided() const;
|
bool exerciseIdProvided() const;
|
||||||
|
|
||||||
void setUnitModuleTestMode(bool onOff) { m_unitModuleTestMode = onOff; }
|
void setUnitModuleTestMode(bool onOff)
|
||||||
|
{
|
||||||
|
m_unitModuleTestMode = onOff;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_additionalHelpStr;
|
QString m_additionalHelpStr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFlags<ProvideCommandLineParameterOptions> m_enabledOptions;
|
QFlags<ProvideCommandLineParameterOptions> m_enabledOptions;
|
||||||
int m_exerciseId{0};
|
int m_exerciseId{0};
|
||||||
int m_domainId{0};
|
int m_domainId{0};
|
||||||
@@ -53,4 +66,4 @@ private:
|
|||||||
QString m_iniFile;
|
QString m_iniFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace LtsCommandLineParser
|
||||||
Executable → Regular
+4
-7
@@ -1,12 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <GeographicLib/UTMUPS.hpp>
|
|
||||||
#include <GeographicLib/MGRS.hpp>
|
#include <GeographicLib/MGRS.hpp>
|
||||||
|
#include <GeographicLib/UTMUPS.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3 || argc > 5)
|
if (argc < 3 || argc > 5)
|
||||||
{
|
{
|
||||||
@@ -59,9 +58,7 @@ int main(int argc, char **argv)
|
|||||||
part3 = mgrs.substr(5, prec);
|
part3 = mgrs.substr(5, prec);
|
||||||
part4 = mgrs.substr(5 + prec, prec);
|
part4 = mgrs.substr(5 + prec, prec);
|
||||||
}
|
}
|
||||||
fprintf(stdout, "%13.10f, %13.10f = %s %s %s %s (UTM: %d %.2f, %.2f %c)\n",
|
fprintf(stdout, "%13.10f, %13.10f = %s %s %s %s (UTM: %d %.2f, %.2f %c)\n", lon, lat, part1.c_str(), part2.c_str(),
|
||||||
lon, lat,
|
part3.c_str(), part4.c_str(), zone, x, y, northp ? 'N' : 'S');
|
||||||
part1.c_str(), part2.c_str(), part3.c_str(), part4.c_str(),
|
|
||||||
zone, x, y, northp ? 'N' : 'S');
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Executable → Regular
+84
-83
@@ -1,19 +1,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_coord_trans.h"
|
#include "lts_coord_trans.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <GeographicLib/Geocentric.hpp>
|
#include <GeographicLib/Geocentric.hpp>
|
||||||
#include <GeographicLib/UTMUPS.hpp>
|
|
||||||
#include <GeographicLib/MGRS.hpp>
|
#include <GeographicLib/MGRS.hpp>
|
||||||
|
#include <GeographicLib/UTMUPS.hpp>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace LtsCoordTrans
|
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_Forward = 0;
|
||||||
static long s_conversion_counter_UTMUPS_Reverse = 0;
|
static long s_conversion_counter_UTMUPS_Reverse = 0;
|
||||||
|
|
||||||
|
inline void incrementCounter(long& counterRef)
|
||||||
inline void incrementCounter(long &counterRef)
|
|
||||||
{
|
{
|
||||||
#ifdef LTS_DEBUG
|
#ifdef LTS_DEBUG
|
||||||
++counterRef;
|
++counterRef;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline std::string cleanupMgrsString(const QString& in)
|
||||||
static inline std::string cleanupMgrsString(const QString &in)
|
|
||||||
{
|
{
|
||||||
const QByteArray ba(in.toLatin1());
|
const QByteArray ba(in.toLatin1());
|
||||||
std::string ret;
|
std::string ret;
|
||||||
@@ -62,7 +57,7 @@ QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
|||||||
GeographicLib::MGRS::Forward(zone, northp, x, y, prec, mgrs);
|
GeographicLib::MGRS::Forward(zone, northp, x, y, prec, mgrs);
|
||||||
incrementCounter(s_conversion_counter_MGRS_Forward);
|
incrementCounter(s_conversion_counter_MGRS_Forward);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while calculating mgrs from utm %d, %9.6f, %9.6f: %s\n", zone, x, y, e.what());
|
fprintf(stderr, "Error while calculating mgrs from utm %d, %9.6f, %9.6f: %s\n", zone, x, y, e.what());
|
||||||
mgrs.clear();
|
mgrs.clear();
|
||||||
@@ -72,14 +67,13 @@ QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
|||||||
if (withSpaces && mgrs.size() == static_cast<size_t>(5 + 2 * prec))
|
if (withSpaces && mgrs.size() == static_cast<size_t>(5 + 2 * prec))
|
||||||
{
|
{
|
||||||
|
|
||||||
const char *ptr = mgrs.c_str();
|
const char* ptr = mgrs.c_str();
|
||||||
|
|
||||||
ret = QString::fromLatin1(ptr, 3) + QLatin1Char(' ') +
|
ret = QString::fromLatin1(ptr, 3) + QLatin1Char(' ') + QString::fromLatin1(ptr + 3, 2);
|
||||||
QString::fromLatin1(ptr + 3, 2);
|
|
||||||
if (prec > 0)
|
if (prec > 0)
|
||||||
{
|
{
|
||||||
ret += QLatin1Char(' ') + QString::fromLatin1(ptr + 5, prec) +
|
ret += QLatin1Char(' ') + QString::fromLatin1(ptr + 5, prec) + QLatin1Char(' ') +
|
||||||
QLatin1Char(' ') + QString::fromLatin1(ptr + 5 + prec, prec);
|
QString::fromLatin1(ptr + 5 + prec, prec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -89,7 +83,7 @@ QString UtmCoordinate::mgrs(int prec, bool withSpaces) const
|
|||||||
|
|
||||||
QPointF UtmCoordinate::toPoint() const
|
QPointF UtmCoordinate::toPoint() const
|
||||||
{
|
{
|
||||||
return {x,y};
|
return {x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::geographic(double offsetX, double offsetY) const
|
QPointF UtmCoordinate::geographic(double offsetX, double offsetY) const
|
||||||
@@ -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());
|
GeographicLib::UTMUPS::Reverse(zone, northp, x + offsetX, y + offsetY, ret.ry(), ret.rx());
|
||||||
incrementCounter(s_conversion_counter_UTMUPS_Reverse);
|
incrementCounter(s_conversion_counter_UTMUPS_Reverse);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while calculating geographic from utm %d, %9.6f, %9.6f: %s\n", zone, x + offsetX, y + offsetY, e.what());
|
fprintf(stderr, "Error while calculating geographic from utm %d, %9.6f, %9.6f: %s\n", zone, x + offsetX,
|
||||||
|
y + offsetY, e.what());
|
||||||
ret = QPointF();
|
ret = QPointF();
|
||||||
}
|
}
|
||||||
return ret * deg2rad();
|
return ret * deg2rad();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::geographic(const QPointF &offset) const
|
QPointF UtmCoordinate::geographic(const QPointF& offset) const
|
||||||
{
|
{
|
||||||
return geographic(offset.x(), offset.y());
|
return geographic(offset.x(), offset.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF UtmCoordinate::relativeTo(const UtmCoordinate &other) const
|
QPointF UtmCoordinate::relativeTo(const UtmCoordinate& other) const
|
||||||
{
|
{
|
||||||
if (zone == other.zone)
|
if (zone == other.zone)
|
||||||
return QPointF(x - other.x, y - other.y);
|
return QPointF(x - other.x, y - other.y);
|
||||||
@@ -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);
|
GeographicLib::UTMUPS::Forward(lat, lon, ret.zone, ret.northp, ret.x, ret.y, setZone);
|
||||||
incrementCounter(s_conversion_counter_UTMUPS_Forward);
|
incrementCounter(s_conversion_counter_UTMUPS_Forward);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while calculating mgrs base point from %9.6f, %9.6f: %s\n", lat, lon, e.what());
|
fprintf(stderr, "Error while calculating mgrs base point from %9.6f, %9.6f: %s\n", lat, lon, e.what());
|
||||||
ret = UtmCoordinate();
|
ret = UtmCoordinate();
|
||||||
@@ -143,12 +138,12 @@ UtmCoordinate UtmCoordinate::fromGeographic(double lon, double lat, int setZone)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate UtmCoordinate::fromGeographic(const QPointF &lonLat, int setZone)
|
UtmCoordinate UtmCoordinate::fromGeographic(const QPointF& lonLat, int setZone)
|
||||||
{
|
{
|
||||||
return fromGeographic(lonLat.x(), lonLat.y(), setZone);
|
return fromGeographic(lonLat.x(), lonLat.y(), setZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
UtmCoordinate UtmCoordinate::fromMgrs(const QString &mgrs)
|
UtmCoordinate UtmCoordinate::fromMgrs(const QString& mgrs)
|
||||||
{
|
{
|
||||||
UtmCoordinate utm;
|
UtmCoordinate utm;
|
||||||
try
|
try
|
||||||
@@ -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);
|
GeographicLib::MGRS::Reverse(cleanupMgrsString(mgrs), utm.zone, utm.northp, utm.x, utm.y, prec, true);
|
||||||
incrementCounter(s_conversion_counter_MGRS_Reverse);
|
incrementCounter(s_conversion_counter_MGRS_Reverse);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error while converting mgrs coordinate %s to utm: %s\n", qPrintable(mgrs), e.what());
|
fprintf(stderr, "Error while converting mgrs coordinate %s to utm: %s\n", qPrintable(mgrs), e.what());
|
||||||
utm = UtmCoordinate();
|
utm = UtmCoordinate();
|
||||||
@@ -172,37 +166,34 @@ QString mgrsFromGeographic(double lon, double lat, int prec, bool withSpaces)
|
|||||||
return UtmCoordinate::fromGeographic(lon, lat, -1).mgrs(prec, withSpaces);
|
return UtmCoordinate::fromGeographic(lon, lat, -1).mgrs(prec, withSpaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF geographicFromMgrs(const QString &mgrs)
|
QPointF geographicFromMgrs(const QString& mgrs)
|
||||||
{
|
{
|
||||||
return UtmCoordinate::fromMgrs(mgrs).geographic();
|
return UtmCoordinate::fromMgrs(mgrs).geographic();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> &staticDefaultSquaresHelper()
|
QVector<UtmCoordinate>& staticDefaultSquaresHelper()
|
||||||
{
|
{
|
||||||
static QVector<UtmCoordinate> s_defaultMgrsSquares;
|
static QVector<UtmCoordinate> s_defaultMgrsSquares;
|
||||||
return s_defaultMgrsSquares;
|
return s_defaultMgrsSquares;
|
||||||
}
|
}
|
||||||
UtmCoordinate &staticPreferedMgrsSquareHelper()
|
|
||||||
|
UtmCoordinate& staticPreferedMgrsSquareHelper()
|
||||||
{
|
{
|
||||||
static UtmCoordinate s_preferedMgrsSquare;
|
static UtmCoordinate s_preferedMgrsSquare;
|
||||||
return s_preferedMgrsSquare;
|
return s_preferedMgrsSquare;
|
||||||
}
|
}
|
||||||
QVector<UtmCoordinate> &staticMgrsSquaresWithOffsetsHelper()
|
|
||||||
|
QVector<UtmCoordinate>& staticMgrsSquaresWithOffsetsHelper()
|
||||||
{
|
{
|
||||||
static QVector<UtmCoordinate> s_mgrsSquaresWithOffsets;
|
static QVector<UtmCoordinate> s_mgrsSquaresWithOffsets;
|
||||||
return s_mgrsSquaresWithOffsets;
|
return s_mgrsSquaresWithOffsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF addMarginToArea(const QRectF& rect_LatLon_radiant, const QSize& marginMeter)
|
||||||
QRectF addMarginToArea(const QRectF &rect_LatLon_radiant, const QSize &marginMeter)
|
|
||||||
{
|
{
|
||||||
double lonMin, lonMax, latMin, latMmax;
|
double lonMin, lonMax, latMin, latMmax;
|
||||||
rect_LatLon_radiant.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
rect_LatLon_radiant.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LtsCoordTrans::UtmCoordinate basePoint;
|
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);
|
QString mgrs = LtsCoordTrans::mgrsFromGeographic(centerRad.x(), centerRad.y(), -1);
|
||||||
mgrs += QStringLiteral("00000000000000");
|
mgrs += QStringLiteral("00000000000000");
|
||||||
|
|
||||||
|
|
||||||
basePoint = LtsCoordTrans::UtmCoordinate::fromMgrs(mgrs);
|
basePoint = LtsCoordTrans::UtmCoordinate::fromMgrs(mgrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,8 +217,8 @@ QRectF addMarginToArea(const QRectF &rect_LatLon_radiant, const QSize &marginMet
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<UtmCoordinate> getMgrsSquares(const QRectF& rect, bool setAsDefaultSquares, bool setAsPreferedSquare,
|
||||||
QVector<UtmCoordinate> getMgrsSquares(const QRectF &rect, bool setAsDefaultSquares, bool setAsPreferedSquare, bool setAsSquareWithMargin)
|
bool setAsSquareWithMargin)
|
||||||
{
|
{
|
||||||
QVector<UtmCoordinate> ret = getMgrsSquaresInternal(rect);
|
QVector<UtmCoordinate> ret = getMgrsSquaresInternal(rect);
|
||||||
|
|
||||||
@@ -241,20 +231,17 @@ QVector<UtmCoordinate> getMgrsSquares(const QRectF &rect, bool setAsDefaultSquar
|
|||||||
if (setAsSquareWithMargin)
|
if (setAsSquareWithMargin)
|
||||||
staticMgrsSquaresWithOffsetsHelper() = ret;
|
staticMgrsSquaresWithOffsetsHelper() = ret;
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF& rect)
|
||||||
{
|
{
|
||||||
QVector<UtmCoordinate> ret;
|
QVector<UtmCoordinate> ret;
|
||||||
QVector<QString> tmpMgrsSquares;
|
QVector<QString> tmpMgrsSquares;
|
||||||
|
|
||||||
|
|
||||||
double lonMin, lonMax, latMin, latMmax;
|
double lonMin, lonMax, latMin, latMmax;
|
||||||
rect.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
rect.normalized().getCoords(&lonMin, &latMin, &lonMax, &latMmax);
|
||||||
|
|
||||||
|
|
||||||
bool withInSingleUtmSquare = true;
|
bool withInSingleUtmSquare = true;
|
||||||
{
|
{
|
||||||
const UtmCoordinate upperRight(UtmCoordinate::fromGeographic(lonMax, latMmax));
|
const UtmCoordinate upperRight(UtmCoordinate::fromGeographic(lonMax, latMmax));
|
||||||
@@ -262,10 +249,6 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
|||||||
withInSingleUtmSquare = upperRight.zone == lowerLeft.zone;
|
withInSingleUtmSquare = upperRight.zone == lowerLeft.zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LtsCoordTrans::UtmCoordinate basePoint;
|
LtsCoordTrans::UtmCoordinate basePoint;
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -273,7 +256,6 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
|||||||
QString mgrs = LtsCoordTrans::mgrsFromGeographic(centerRad.x(), centerRad.y(), -1);
|
QString mgrs = LtsCoordTrans::mgrsFromGeographic(centerRad.x(), centerRad.y(), -1);
|
||||||
mgrs += QStringLiteral("00000000000000");
|
mgrs += QStringLiteral("00000000000000");
|
||||||
|
|
||||||
|
|
||||||
basePoint = LtsCoordTrans::UtmCoordinate::fromMgrs(mgrs);
|
basePoint = LtsCoordTrans::UtmCoordinate::fromMgrs(mgrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,8 +265,6 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
|||||||
const double maxX(upperRight.x - lowerLeft.x);
|
const double maxX(upperRight.x - lowerLeft.x);
|
||||||
const double maxY(upperRight.y - lowerLeft.y);
|
const double maxY(upperRight.y - lowerLeft.y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const int increment = withInSingleUtmSquare ? 10000 : 1000;
|
const int increment = withInSingleUtmSquare ? 10000 : 1000;
|
||||||
for (double x = 0; x <= maxX + increment; x += increment)
|
for (double x = 0; x <= maxX + increment; x += increment)
|
||||||
{
|
{
|
||||||
@@ -306,28 +286,26 @@ QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF &rect)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList getMgrsSurroundingSquares(const QRectF &geoRect, const QSize &offsetMeter)
|
QStringList getMgrsSurroundingSquares(const QRectF& geoRect, const QSize& offsetMeter)
|
||||||
{
|
{
|
||||||
|
|
||||||
const QVector<UtmCoordinate> mainUtms = getMgrsSquaresInternal(geoRect);
|
const QVector<UtmCoordinate> mainUtms = getMgrsSquaresInternal(geoRect);
|
||||||
QStringList mainSquares;
|
QStringList mainSquares;
|
||||||
mainSquares.reserve(mainUtms.count());
|
mainSquares.reserve(mainUtms.count());
|
||||||
for (const auto &utm : mainUtms)
|
for (const auto& utm : mainUtms)
|
||||||
mainSquares.append(utm.mgrs(0));
|
mainSquares.append(utm.mgrs(0));
|
||||||
|
|
||||||
|
const QRectF rectWithOffset = addMarginToArea(geoRect, offsetMeter);
|
||||||
const QRectF rectWithOffset = addMarginToArea(geoRect,offsetMeter);
|
|
||||||
|
|
||||||
QVector<UtmCoordinate> mainUtmsWithOffset = getMgrsSquaresInternal(rectWithOffset);
|
QVector<UtmCoordinate> mainUtmsWithOffset = getMgrsSquaresInternal(rectWithOffset);
|
||||||
QStringList mainSquaresWithOffset;
|
QStringList mainSquaresWithOffset;
|
||||||
mainSquaresWithOffset.reserve(mainUtmsWithOffset.count());
|
mainSquaresWithOffset.reserve(mainUtmsWithOffset.count());
|
||||||
for (const auto &utm : std::as_const(mainUtmsWithOffset))
|
for (const auto& utm : std::as_const(mainUtmsWithOffset))
|
||||||
mainSquaresWithOffset.append(utm.mgrs(0));
|
mainSquaresWithOffset.append(utm.mgrs(0));
|
||||||
|
|
||||||
|
|
||||||
QStringList surroundingSquares;
|
QStringList surroundingSquares;
|
||||||
surroundingSquares.reserve(mainSquaresWithOffset.count());
|
surroundingSquares.reserve(mainSquaresWithOffset.count());
|
||||||
for (const auto & mgrs0 : mainSquaresWithOffset)
|
for (const auto& mgrs0 : mainSquaresWithOffset)
|
||||||
{
|
{
|
||||||
if (!mainSquares.contains(mgrs0))
|
if (!mainSquares.contains(mgrs0))
|
||||||
surroundingSquares.append(mgrs0);
|
surroundingSquares.append(mgrs0);
|
||||||
@@ -341,12 +319,11 @@ QVector<UtmCoordinate> defaultMgrsSquareWithOffsets()
|
|||||||
return staticMgrsSquaresWithOffsetsHelper();
|
return staticMgrsSquaresWithOffsetsHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDefaultMgrsSquares(const QVector<QString>& squares)
|
||||||
void setDefaultMgrsSquares(const QVector<QString> &squares)
|
|
||||||
{
|
{
|
||||||
QVector<UtmCoordinate> coords;
|
QVector<UtmCoordinate> coords;
|
||||||
coords.reserve(squares.size());
|
coords.reserve(squares.size());
|
||||||
for (const QString &s : squares)
|
for (const QString& s : squares)
|
||||||
coords += UtmCoordinate::fromMgrs(s + QStringLiteral("00000000000000"));
|
coords += UtmCoordinate::fromMgrs(s + QStringLiteral("00000000000000"));
|
||||||
staticDefaultSquaresHelper() = coords;
|
staticDefaultSquaresHelper() = coords;
|
||||||
}
|
}
|
||||||
@@ -361,8 +338,7 @@ UtmCoordinate preferedMgrsSquare()
|
|||||||
return staticPreferedMgrsSquareHelper();
|
return staticPreferedMgrsSquareHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool lonLatAltToGeocentric(double lon, double lat, double altitude, double& xOut, double& yOut, double& zOut)
|
||||||
bool lonLatAltToGeocentric(double lon, double lat, double altitude, double &xOut, double &yOut, double &zOut)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
lon *= rad2deg();
|
lon *= rad2deg();
|
||||||
@@ -383,11 +359,9 @@ bool lonLatAltToGeocentric(double lon, double lat, double altitude, double &xOut
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool geocentric2LonLatAlt(double x, double y, double z,
|
bool geocentric2LonLatAlt(double x, double y, double z, double& lon, double& lat, double& altitude)
|
||||||
double &lon, double &lat, double &altitude)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GeographicLib::Geocentric::WGS84().Reverse(x, y, z, lat, lon, altitude);
|
GeographicLib::Geocentric::WGS84().Reverse(x, y, z, lat, lon, altitude);
|
||||||
@@ -406,41 +380,68 @@ bool geocentric2LonLatAlt(double x, double y, double z,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double distance(const QPointF &p1, const QPointF &p2)
|
double distance(const QPointF& p1, const QPointF& p2)
|
||||||
{
|
{
|
||||||
return distance(p1.x(), p1.y(), p2.x(), p2.y());
|
return distance(p1.x(), p1.y(), p2.x(), p2.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
double squareDistance(const QPointF &p1, const QPointF &p2)
|
double squareDistance(const QPointF& p1, const QPointF& p2)
|
||||||
{
|
{
|
||||||
return squareDistance(p1.x(), p1.y(), p2.x(), p2.y());
|
return squareDistance(p1.x(), p1.y(), p2.x(), p2.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<< (std::ostream &stream,
|
std::ostream& operator<<(std::ostream& stream, const UtmCoordinate& coord)
|
||||||
const UtmCoordinate &coord)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
stream << "UtmCoordinate(" << std::setprecision(8) << coord.x
|
stream << "UtmCoordinate(" << std::setprecision(8) << coord.x << "#" << std::setprecision(8) << coord.y
|
||||||
<< "#" << std::setprecision(8) << coord.y
|
|
||||||
<< " zone=" << coord.zone << ")";
|
<< " zone=" << coord.zone << ")";
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpConversionCounter()
|
void dumpConversionCounter()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Forward : - mgrs : %ld\n" , s_conversion_counter_MGRS_Forward);
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Forward : - mgrs : %ld\n",
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Reverse - fromMgrs : %ld\n" , s_conversion_counter_MGRS_Reverse);
|
s_conversion_counter_MGRS_Forward);
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Forward - lonLatAltToGeocentric : %ld\n" , s_conversion_counter_WGS84_Forward);
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_MGRS_Reverse - fromMgrs : %ld\n",
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Reverse - geocentric2LonLatAlt : %ld\n" , s_conversion_counter_WGS84_Reverse);
|
s_conversion_counter_MGRS_Reverse);
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Forward - fromGeographic : %ld\n" , s_conversion_counter_UTMUPS_Forward);
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Forward - lonLatAltToGeocentric : %ld\n",
|
||||||
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Reverse - geographic : %ld\n" , s_conversion_counter_UTMUPS_Reverse);
|
s_conversion_counter_WGS84_Forward);
|
||||||
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_WGS84_Reverse - geocentric2LonLatAlt : %ld\n",
|
||||||
|
s_conversion_counter_WGS84_Reverse);
|
||||||
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Forward - fromGeographic : %ld\n",
|
||||||
|
s_conversion_counter_UTMUPS_Forward);
|
||||||
|
fprintf(stderr, "LtsCoordTrans: s_conversion_counter_UTMUPS_Reverse - geographic : %ld\n",
|
||||||
|
s_conversion_counter_UTMUPS_Reverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
long getConversionCounter_MGRS_Forward() { return s_conversion_counter_MGRS_Forward; }
|
long getConversionCounter_MGRS_Forward()
|
||||||
long getConversionCounter_MGRS_Reverse() { return s_conversion_counter_MGRS_Reverse; }
|
{
|
||||||
long getConversionCounter_WGS84_Forward() { return s_conversion_counter_WGS84_Forward; }
|
return s_conversion_counter_MGRS_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_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
|
#pragma once
|
||||||
|
|
||||||
#include <ltscoordtrans_export.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <cmath>
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <cmath>
|
||||||
|
#include <ltscoordtrans_export.h>
|
||||||
|
#include <string>
|
||||||
class QPointF;
|
class QPointF;
|
||||||
class QRectF;
|
class QRectF;
|
||||||
class QSize;
|
class QSize;
|
||||||
@@ -16,12 +14,20 @@ class QString;
|
|||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans
|
||||||
{
|
{
|
||||||
|
|
||||||
|
inline Q_CONSTEXPR double pi()
|
||||||
|
{
|
||||||
|
return M_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Q_CONSTEXPR double deg2rad()
|
||||||
|
{
|
||||||
|
return pi() / 180.;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Q_CONSTEXPR double rad2deg()
|
||||||
inline Q_CONSTEXPR double pi() { return M_PI; }
|
{
|
||||||
inline Q_CONSTEXPR double deg2rad() { return pi() / 180.; }
|
return 1. / deg2rad();
|
||||||
inline Q_CONSTEXPR double rad2deg() { return 1. / deg2rad(); }
|
}
|
||||||
|
|
||||||
struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
||||||
{
|
{
|
||||||
@@ -31,101 +37,60 @@ struct LTSCOORDTRANS_EXPORT UtmCoordinate
|
|||||||
double y = 0.;
|
double y = 0.;
|
||||||
|
|
||||||
UtmCoordinate() = default;
|
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;
|
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
||||||
|
|
||||||
QPointF toPoint() const;
|
QPointF toPoint() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QPointF geographic(double offsetX = 0., double offsetY = 0.) const;
|
QPointF geographic(double offsetX = 0., double offsetY = 0.) const;
|
||||||
|
|
||||||
|
QPointF geographic(const QPointF& offset) const;
|
||||||
|
|
||||||
|
QPointF relativeTo(const UtmCoordinate& other) const;
|
||||||
QPointF geographic(const QPointF &offset) const;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QPointF relativeTo(const UtmCoordinate &other) const;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static UtmCoordinate fromGeographic(double lon, double lat, int setZone = -1);
|
static UtmCoordinate fromGeographic(double lon, double lat, int setZone = -1);
|
||||||
|
|
||||||
|
static UtmCoordinate fromGeographic(const QPointF& lonLat, int setZone = -1);
|
||||||
|
|
||||||
|
static UtmCoordinate fromMgrs(const QString& mgrs);
|
||||||
static UtmCoordinate fromGeographic(const QPointF &lonLat, int setZone = -1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static UtmCoordinate fromMgrs(const QString &mgrs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QString mgrsFromGeographic(double lon, double lat, int prec = 5, bool withSpaces = true);
|
LTSCOORDTRANS_EXPORT QString mgrsFromGeographic(double lon, double lat, int prec = 5, bool withSpaces = true);
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT QPointF geographicFromMgrs(const QString& mgrs);
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT QRectF addMarginToArea(const QRectF& rect_LatLon_radiant, const QSize& marginMeter);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QPointF geographicFromMgrs(const QString &mgrs);
|
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> getMgrsSquares(const QRectF& rect, bool setAsDefaultSquares,
|
||||||
|
bool setAsPreferedSquare,
|
||||||
|
bool setAsSquareWithMargin = false);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
QVector<UtmCoordinate> getMgrsSquaresInternal(const QRectF& rect);
|
||||||
|
|
||||||
|
QStringList getMgrsSurroundingSquares(const QRectF& geoRect, const QSize& offsetMeter);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquareWithOffsets();
|
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquareWithOffsets();
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT void setDefaultMgrsSquares(const QVector<QString>& squares);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT void setDefaultMgrsSquares(const QVector<QString> &squares);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquares();
|
LTSCOORDTRANS_EXPORT QVector<UtmCoordinate> defaultMgrsSquares();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT UtmCoordinate preferedMgrsSquare();
|
LTSCOORDTRANS_EXPORT UtmCoordinate preferedMgrsSquare();
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT bool lonLatAltToGeocentric(double lon, double lat, double altitude, double& xOut, double& yOut,
|
||||||
|
double& zOut);
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT bool 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);
|
inline double squareDistance(const UtmCoordinate& p1, const UtmCoordinate& p2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (p1.zone != p2.zone)
|
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);
|
return std::pow(p1.x - p2.x, 2) + std::pow(p1.y - p2.y, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT double squareDistance(const QPointF& p1, const QPointF& p2);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT double squareDistance(const QPointF &p1, const QPointF &p2);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline double squareDistance(const double lon1, const double lat1, const double lon2, const double lat2)
|
inline double squareDistance(const double lon1, const double lat1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
@@ -148,17 +109,13 @@ inline double squareDistance(const double lon1, const double lat1, const double
|
|||||||
return squareDistance(p1, p2);
|
return squareDistance(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline double squareDistance(const UtmCoordinate& p1, const double lon2, const double lat2)
|
||||||
|
|
||||||
inline double squareDistance(const UtmCoordinate &p1, const double lon2, const double lat2)
|
|
||||||
{
|
{
|
||||||
const auto p2(UtmCoordinate::fromGeographic(lon2, lat2, p1.zone));
|
const auto p2(UtmCoordinate::fromGeographic(lon2, lat2, p1.zone));
|
||||||
return squareDistance(p1, p2);
|
return squareDistance(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline double distance(const UtmCoordinate& p1, const UtmCoordinate& p2)
|
||||||
|
|
||||||
inline double distance(const UtmCoordinate &p1, const UtmCoordinate &p2)
|
|
||||||
{
|
{
|
||||||
if (p1.zone != p2.zone)
|
if (p1.zone != p2.zone)
|
||||||
{
|
{
|
||||||
@@ -168,23 +125,18 @@ inline double distance(const UtmCoordinate &p1, const UtmCoordinate &p2)
|
|||||||
return sqrt(squareDistance(p1, p2));
|
return sqrt(squareDistance(p1, p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT double distance(const QPointF& p1, const QPointF& p2);
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT double distance(const QPointF &p1, const QPointF &p2);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline double distance(const double lon1, const double lat1, const double lon2, const double lat2)
|
inline double distance(const double lon1, const double lat1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
return sqrt(squareDistance(lon1, lat1, lon2, lat2));
|
return sqrt(squareDistance(lon1, lat1, lon2, lat2));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double distance(const UtmCoordinate &p1, const double lon2, const double lat2)
|
inline double distance(const UtmCoordinate& p1, const double lon2, const double lat2)
|
||||||
{
|
{
|
||||||
return sqrt(squareDistance(p1, lon2, lat2));
|
return sqrt(squareDistance(p1, lon2, lat2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT void dumpConversionCounter();
|
LTSCOORDTRANS_EXPORT void dumpConversionCounter();
|
||||||
|
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Forward();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_MGRS_Forward();
|
||||||
@@ -194,28 +146,19 @@ LTSCOORDTRANS_EXPORT long getConversionCounter_WGS84_Reverse();
|
|||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Forward();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Forward();
|
||||||
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Reverse();
|
LTSCOORDTRANS_EXPORT long getConversionCounter_UTMUPS_Reverse();
|
||||||
|
|
||||||
|
LTSCOORDTRANS_EXPORT std::ostream& operator<<(std::ostream& stream, const UtmCoordinate& coord);
|
||||||
LTSCOORDTRANS_EXPORT std::ostream &operator<< (std::ostream &stream,
|
|
||||||
const UtmCoordinate &coord);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LTSCOORDTRANS_EXPORT UtmCoordinate3D : public LtsCoordTrans::UtmCoordinate
|
class LTSCOORDTRANS_EXPORT UtmCoordinate3D : public LtsCoordTrans::UtmCoordinate
|
||||||
{
|
{
|
||||||
using BaseClass = LtsCoordTrans::UtmCoordinate;
|
using BaseClass = LtsCoordTrans::UtmCoordinate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UtmCoordinate3D()
|
UtmCoordinate3D()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit UtmCoordinate3D(const LtsCoordTrans::UtmCoordinate &utm2d, double _zValue = std::nan(""))
|
explicit UtmCoordinate3D(const LtsCoordTrans::UtmCoordinate& utm2d, double _zValue = std::nan("")) : BaseClass()
|
||||||
:BaseClass()
|
|
||||||
{
|
{
|
||||||
zone = utm2d.zone;
|
zone = utm2d.zone;
|
||||||
northp = utm2d.northp;
|
northp = utm2d.northp;
|
||||||
@@ -229,21 +172,18 @@ public:
|
|||||||
zone = -1;
|
zone = -1;
|
||||||
northp = true;
|
northp = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
x = 0.;
|
x = 0.;
|
||||||
y = 0.;
|
y = 0.;
|
||||||
zValue = std::nan("");
|
zValue = std::nan("");
|
||||||
}
|
}
|
||||||
|
|
||||||
double z() const { return zValue; }
|
double z() const
|
||||||
|
{
|
||||||
|
return zValue;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double zValue{std::nan("")};
|
double zValue{std::nan("")};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace LtsCoordTrans
|
||||||
}
|
|
||||||
Executable → Regular
+105
-175
@@ -1,12 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_coord_trans_unit_test.h"
|
#include "lts_coord_trans_unit_test.h"
|
||||||
#include <utility>
|
|
||||||
#include "lts_coord_trans.h"
|
#include "lts_coord_trans.h"
|
||||||
|
|
||||||
#include <GeographicLib/Math.hpp>
|
#include <GeographicLib/Math.hpp>
|
||||||
#include <QTest>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QTest>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
QTEST_MAIN(coordtrans_test)
|
QTEST_MAIN(coordtrans_test)
|
||||||
|
|
||||||
@@ -15,14 +16,11 @@ void coordtrans_test::initTestCase()
|
|||||||
qDebug("sizeof(UtmCoordinate) = %lu", sizeof(LtsCoordTrans::UtmCoordinate));
|
qDebug("sizeof(UtmCoordinate) = %lu", sizeof(LtsCoordTrans::UtmCoordinate));
|
||||||
}
|
}
|
||||||
|
|
||||||
void coordtrans_test::cleanupTestCase()
|
void coordtrans_test::cleanupTestCase() {}
|
||||||
{}
|
|
||||||
|
|
||||||
void coordtrans_test::testFromGeographic()
|
void coordtrans_test::testFromGeographic()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LtsCoordTrans::UtmCoordinate utm;
|
LtsCoordTrans::UtmCoordinate utm;
|
||||||
QPointF lonlat;
|
QPointF lonlat;
|
||||||
|
|
||||||
@@ -44,8 +42,6 @@ void coordtrans_test::testFromGeographic()
|
|||||||
utm = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
utm = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
||||||
QCOMPARE(utm.mgrs(5), QStringLiteral("40R BM 85000 85000"));
|
QCOMPARE(utm.mgrs(5), QStringLiteral("40R BM 85000 85000"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
utm = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("40R BM 00000 00000"));
|
utm = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("40R BM 00000 00000"));
|
||||||
QCOMPARE(utm.mgrs(0), QStringLiteral("40Q BM"));
|
QCOMPARE(utm.mgrs(0), QStringLiteral("40Q BM"));
|
||||||
}
|
}
|
||||||
@@ -70,9 +66,7 @@ void coordtrans_test::testRelativeMetricalOffet_data()
|
|||||||
QTest::addColumn<QPoint>("offset");
|
QTest::addColumn<QPoint>("offset");
|
||||||
QTest::addColumn<QString>("correctMgrs");
|
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 2") << QPoint(100, 100) << QStringLiteral("32U QE 00090 00090");
|
||||||
QTest::newRow("set 3") << QPoint(500, 500) << QStringLiteral("32U QE 00490 00490");
|
QTest::newRow("set 3") << QPoint(500, 500) << QStringLiteral("32U QE 00490 00490");
|
||||||
@@ -83,7 +77,8 @@ void coordtrans_test::testRelativeMetricalOffet()
|
|||||||
QFETCH(QPoint, offset);
|
QFETCH(QPoint, offset);
|
||||||
QFETCH(QString, correctMgrs);
|
QFETCH(QString, correctMgrs);
|
||||||
|
|
||||||
const LtsCoordTrans::UtmCoordinate &utmRef = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 99990 99990"));
|
const LtsCoordTrans::UtmCoordinate& utmRef =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 99990 99990"));
|
||||||
qDebug() << "utmRef = " << utmRef.mgrs();
|
qDebug() << "utmRef = " << utmRef.mgrs();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -96,36 +91,27 @@ void coordtrans_test::testRelativeMetricalOffet()
|
|||||||
QCOMPARE(utmRaw.mgrs(), correctMgrs);
|
QCOMPARE(utmRaw.mgrs(), correctMgrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const LtsCoordTrans::UtmCoordinate utmSimple(utmRef.zone,
|
const LtsCoordTrans::UtmCoordinate utmSimple(utmRef.zone, utmRef.x + offset.x(), utmRef.y + offset.y());
|
||||||
utmRef.x + offset.x(),
|
|
||||||
utmRef.y + offset.y());
|
|
||||||
|
|
||||||
qDebug() << "offset = " << offset << " - utmSimple = " << utmSimple.mgrs();
|
qDebug() << "offset = " << offset << " - utmSimple = " << utmSimple.mgrs();
|
||||||
QCOMPARE(utmSimple.mgrs(), correctMgrs);
|
QCOMPARE(utmSimple.mgrs(), correctMgrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF createArea(const QString &base,
|
QRectF createArea(const QString& base, int xCenter, int yCenter, int width, int height)
|
||||||
int xCenter, int yCenter, int width, int height)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
||||||
LtsCoordTrans::UtmCoordinate utmBase(LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
LtsCoordTrans::UtmCoordinate utmBase(
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
||||||
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
||||||
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||||
|
|
||||||
|
QRectF rect(topLeft, bottomRight);
|
||||||
|
|
||||||
QRectF rect (topLeft, bottomRight);
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void coordtrans_test::testAddMarginToArea()
|
void coordtrans_test::testAddMarginToArea()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -134,36 +120,43 @@ void coordtrans_test::testAddMarginToArea()
|
|||||||
QRectF area = createArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000);
|
QRectF area = createArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000);
|
||||||
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(5000, 20000));
|
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(5000, 20000));
|
||||||
|
|
||||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft() << " - degree:" << area.topLeft()*LtsCoordTrans::rad2deg();
|
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft()
|
||||||
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft() << " - degree:" << area1Increased.topLeft()*LtsCoordTrans::rad2deg();
|
<< " - degree:" << area.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft()
|
||||||
|
<< " - degree:" << area1Increased.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
|
||||||
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight() << " - degree:" << area.bottomRight()*LtsCoordTrans::rad2deg();
|
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight()
|
||||||
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight() << " - degree:" << area1Increased.bottomRight()*LtsCoordTrans::rad2deg();
|
<< " - 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().x() < area.topLeft().x(), "addMarginToArea topLeft X failed");
|
||||||
QVERIFY2( area1Increased.topLeft().y() < area.topLeft().y(), "addMarginToArea topLeft Y 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().x() > area.bottomRight().x(), "addMarginToArea bottomRight X failed");
|
||||||
QVERIFY2( area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y failed");
|
QVERIFY2(area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
qDebug() << "Luxemburg";
|
qDebug() << "Luxemburg";
|
||||||
QRectF area = createArea(QStringLiteral("32U LA 0000000000"), 100, 100, 5000, 5000);
|
QRectF area = createArea(QStringLiteral("32U LA 0000000000"), 100, 100, 5000, 5000);
|
||||||
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(50000, 20000));
|
QRectF area1Increased = LtsCoordTrans::addMarginToArea(area, QSize(50000, 20000));
|
||||||
|
|
||||||
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft() << " - degree:" << area.topLeft()*LtsCoordTrans::rad2deg();
|
qDebug() << "topLeft : " << qSetRealNumberPrecision(15) << area.topLeft()
|
||||||
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft() << " - degree:" << area1Increased.topLeft()*LtsCoordTrans::rad2deg();
|
<< " - degree:" << area.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
qDebug() << "topLeftInc : " << qSetRealNumberPrecision(15) << area1Increased.topLeft()
|
||||||
|
<< " - degree:" << area1Increased.topLeft() * LtsCoordTrans::rad2deg();
|
||||||
|
|
||||||
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight() << " - degree:" << area.bottomRight()*LtsCoordTrans::rad2deg();
|
qDebug() << "bottomRight : " << qSetRealNumberPrecision(15) << area.bottomRight()
|
||||||
qDebug() << "bottomRightInc : " << qSetRealNumberPrecision(15) << area1Increased.bottomRight() << " - degree:" << area1Increased.bottomRight()*LtsCoordTrans::rad2deg();
|
<< " - 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().x() < area.topLeft().x(), "addMarginToArea topLeft X failed");
|
||||||
QVERIFY2( area1Increased.topLeft().y() < area.topLeft().y(), "addMarginToArea topLeft Y 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().x() > area.bottomRight().x(), "addMarginToArea bottomRight X failed");
|
||||||
QVERIFY2( area1Increased.bottomRight().y() > area.bottomRight().y(), "addMarginToArea bottomRight Y 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);
|
QString mgrs = LtsCoordTrans::mgrsFromGeographic(lonlat.x(), lonlat.y(), 9);
|
||||||
QCOMPARE(mgrs, QStringLiteral("32U MD 745000000 840000000"));
|
QCOMPARE(mgrs, QStringLiteral("32U MD 745000000 840000000"));
|
||||||
|
|
||||||
const LtsCoordTrans::UtmCoordinate centerPoint = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
const LtsCoordTrans::UtmCoordinate centerPoint =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
||||||
|
|
||||||
LtsCoordTrans::UtmCoordinate topLeftUtm;
|
LtsCoordTrans::UtmCoordinate topLeftUtm;
|
||||||
LtsCoordTrans::UtmCoordinate topLeftUtm2;
|
LtsCoordTrans::UtmCoordinate topLeftUtm2;
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
QPointF topLeftGeo = centerPoint.geographic(-1111, 2222);
|
QPointF topLeftGeo = centerPoint.geographic(-1111, 2222);
|
||||||
QPointF bottomRightGeo = centerPoint.geographic( 3000, -4000);
|
QPointF bottomRightGeo = centerPoint.geographic(3000, -4000);
|
||||||
|
|
||||||
topLeftUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(topLeftGeo);
|
topLeftUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(topLeftGeo);
|
||||||
const LtsCoordTrans::UtmCoordinate bottomRightUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(bottomRightGeo);
|
const LtsCoordTrans::UtmCoordinate bottomRightUtm =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(bottomRightGeo);
|
||||||
qDebug() << "topLeftUtm: " << topLeftUtm.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm.y;
|
qDebug() << "topLeftUtm: " << topLeftUtm.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm.y;
|
||||||
qDebug() << "bottomRightUtm: " << bottomRightUtm.x << " - " << qSetRealNumberPrecision(15) << bottomRightUtm.y;
|
qDebug() << "bottomRightUtm: " << bottomRightUtm.x << " - " << qSetRealNumberPrecision(15)
|
||||||
|
<< bottomRightUtm.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
topLeftUtm2.x = centerPoint.x - 1111;
|
topLeftUtm2.x = centerPoint.x - 1111;
|
||||||
topLeftUtm2.y = centerPoint.y + 2222;
|
topLeftUtm2.y = centerPoint.y + 2222;
|
||||||
@@ -200,7 +194,8 @@ void coordtrans_test::testIncreaseRect()
|
|||||||
bottomRightUtm2.y = centerPoint.y - 4000;
|
bottomRightUtm2.y = centerPoint.y - 4000;
|
||||||
|
|
||||||
qDebug() << "topLeftUtm2: " << topLeftUtm2.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm2.y;
|
qDebug() << "topLeftUtm2: " << topLeftUtm2.x << " - " << qSetRealNumberPrecision(15) << topLeftUtm2.y;
|
||||||
qDebug() << "bottomRightUtm2: " << bottomRightUtm2.x << " - " << qSetRealNumberPrecision(15) << bottomRightUtm2.y;
|
qDebug() << "bottomRightUtm2: " << bottomRightUtm2.x << " - " << qSetRealNumberPrecision(15)
|
||||||
|
<< bottomRightUtm2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY2(qFuzzyCompare(topLeftUtm.x, topLeftUtm2.x), "testIncreaseRect x failed");
|
QVERIFY2(qFuzzyCompare(topLeftUtm.x, topLeftUtm2.x), "testIncreaseRect x failed");
|
||||||
@@ -218,10 +213,11 @@ void coordtrans_test::testIncreaseRect2()
|
|||||||
QRectF myRectIncreased;
|
QRectF myRectIncreased;
|
||||||
|
|
||||||
{
|
{
|
||||||
const LtsCoordTrans::UtmCoordinate centerPoint = LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
const LtsCoordTrans::UtmCoordinate centerPoint =
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(lonlat.x(), lonlat.y());
|
||||||
|
|
||||||
QPointF topLeftGeo = centerPoint.geographic(-3000, 2000);
|
QPointF topLeftGeo = centerPoint.geographic(-3000, 2000);
|
||||||
QPointF bottomRightGeo = centerPoint.geographic( 3000, -2000);
|
QPointF bottomRightGeo = centerPoint.geographic(3000, -2000);
|
||||||
myRect = QRectF(topLeftGeo, bottomRightGeo).normalized();
|
myRect = QRectF(topLeftGeo, bottomRightGeo).normalized();
|
||||||
|
|
||||||
qDebug() << "myRect : " << myRect;
|
qDebug() << "myRect : " << myRect;
|
||||||
@@ -229,39 +225,34 @@ void coordtrans_test::testIncreaseRect2()
|
|||||||
qDebug() << "myRect height : " << myRect.height();
|
qDebug() << "myRect height : " << myRect.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const QPointF centerGeo = myRect.center();
|
const QPointF centerGeo = myRect.center();
|
||||||
const LtsCoordTrans::UtmCoordinate centerUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(centerGeo);
|
const LtsCoordTrans::UtmCoordinate centerUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(centerGeo);
|
||||||
|
|
||||||
QPointF topLeftGeo = centerUtm.geographic(-6000, 4000);
|
QPointF topLeftGeo = centerUtm.geographic(-6000, 4000);
|
||||||
QPointF bottomRightGeo = centerUtm.geographic( 6000, -4000);
|
QPointF bottomRightGeo = centerUtm.geographic(6000, -4000);
|
||||||
|
|
||||||
myRectIncreased = QRectF(topLeftGeo, bottomRightGeo).normalized();
|
myRectIncreased = QRectF(topLeftGeo, bottomRightGeo).normalized();
|
||||||
|
|
||||||
qDebug() << "myRectIncreased : " << myRectIncreased;
|
qDebug() << "myRectIncreased : " << myRectIncreased;
|
||||||
qDebug() << "myRectIncreased center: " << myRectIncreased.center();
|
qDebug() << "myRectIncreased center: " << myRectIncreased.center();
|
||||||
qDebug() << "myRectIncreased height: " << myRectIncreased.height();
|
qDebug() << "myRectIncreased height: " << myRectIncreased.height();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVERIFY2((int)(myRectIncreased.center().x() * 10000) == (int)(myRect.center().x() * 10000),
|
||||||
QVERIFY2( (int)(myRectIncreased.center().x()*10000) == (int)(myRect.center().x()*10000), "testIncreaseRect2 centerX failed");
|
"testIncreaseRect2 centerX failed");
|
||||||
QVERIFY2( (int)(myRectIncreased.center().y()*10000) == (int)(myRect.center().y()*10000), "testIncreaseRect2 centerY failed");
|
QVERIFY2((int)(myRectIncreased.center().y() * 10000) == (int)(myRect.center().y() * 10000),
|
||||||
|
"testIncreaseRect2 centerY failed");
|
||||||
|
|
||||||
QVERIFY2(myRectIncreased.width() > myRect.width(), "testIncreaseRect2 width failed");
|
QVERIFY2(myRectIncreased.width() > myRect.width(), "testIncreaseRect2 width failed");
|
||||||
QVERIFY2(myRectIncreased.height() > myRect.height(), "testIncreaseRect2 height failed");
|
QVERIFY2(myRectIncreased.height() > myRect.height(), "testIncreaseRect2 height failed");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void coordtrans_test::testGeographicFromMgrs()
|
void coordtrans_test::testGeographicFromMgrs()
|
||||||
{
|
{
|
||||||
|
|
||||||
QString mgrs(QStringLiteral("32UPD7654398765"));
|
QString mgrs(QStringLiteral("32UPD7654398765"));
|
||||||
|
|
||||||
|
|
||||||
QPointF geographic = LtsCoordTrans::geographicFromMgrs(mgrs);
|
QPointF geographic = LtsCoordTrans::geographicFromMgrs(mgrs);
|
||||||
QCOMPARE(geographic, QPointF(11.6436815550, 53.2088411454) * LtsCoordTrans::deg2rad());
|
QCOMPARE(geographic, QPointF(11.6436815550, 53.2088411454) * LtsCoordTrans::deg2rad());
|
||||||
}
|
}
|
||||||
@@ -269,163 +260,105 @@ void coordtrans_test::testGeographicFromMgrs()
|
|||||||
void coordtrans_test::testMgrsSquares()
|
void coordtrans_test::testMgrsSquares()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
checkArea(QStringLiteral("32U PD 0000000000"), 50000, 10000, 30000, 30000,
|
||||||
|
{QStringLiteral("32U PC"), QStringLiteral("32U PD")});
|
||||||
|
checkArea(QStringLiteral("32U 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,
|
||||||
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"),
|
|
||||||
QStringLiteral("32U LA"),
|
QStringLiteral("32U LA"),
|
||||||
QStringLiteral("32U LV")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100,150000,150000, { QStringLiteral("31U FQ"),
|
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 60000, 60000,
|
||||||
QStringLiteral("31U FR"),
|
{QStringLiteral("31U GQ"), QStringLiteral("31U GR"), QStringLiteral("32U KA"), QStringLiteral("32U KV"),
|
||||||
QStringLiteral("31U GQ"),
|
QStringLiteral("32U LA"), QStringLiteral("32U LV")});
|
||||||
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"),
|
checkArea(QStringLiteral("32U LA 0000000000"), 100, 100, 150000, 150000,
|
||||||
QStringLiteral("31U FQ"),
|
{QStringLiteral("31U FQ"), QStringLiteral("31U FR"), QStringLiteral("31U GQ"), QStringLiteral("31U GR"),
|
||||||
QStringLiteral("31U FR"),
|
QStringLiteral("32U KA"), QStringLiteral("32U KV"), QStringLiteral("32U LA"), QStringLiteral("32U LV")});
|
||||||
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, 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,
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> checkAreaGetMgrsSquares(const QString &base,
|
int height)
|
||||||
int xCenter, int yCenter, int width, int height)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
||||||
LtsCoordTrans::UtmCoordinate utmBase(LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
LtsCoordTrans::UtmCoordinate utmBase(
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
||||||
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
||||||
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const auto squares = LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), false, false);
|
const auto squares = LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), false, false);
|
||||||
|
|
||||||
QStringList src;
|
QStringList src;
|
||||||
src.reserve(squares.size());
|
src.reserve(squares.size());
|
||||||
for (const auto &utm : squares)
|
for (const auto& utm : squares)
|
||||||
src += utm.mgrs(0);
|
src += utm.mgrs(0);
|
||||||
src.sort();
|
src.sort();
|
||||||
|
|
||||||
|
|
||||||
return squares;
|
return squares;
|
||||||
}
|
}
|
||||||
|
|
||||||
void coordtrans_test::testMgrsSquaresWithSurrounding()
|
void coordtrans_test::testMgrsSquaresWithSurrounding()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int initialSize = 5000;
|
int initialSize = 5000;
|
||||||
|
|
||||||
|
QVector<LtsCoordTrans::UtmCoordinate> squares1 =
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> squares1 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, initialSize, initialSize);
|
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, initialSize, initialSize);
|
||||||
|
|
||||||
QVERIFY2(squares1.size() == 1, "checkAreaGetMgrsSquares failed");
|
QVERIFY2(squares1.size() == 1, "checkAreaGetMgrsSquares failed");
|
||||||
|
|
||||||
|
int biggerSize = initialSize + (1 * 110000);
|
||||||
|
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");
|
QVERIFY2(squares9.size() == 9, "checkAreaGetMgrsSquares biggerSize failed");
|
||||||
|
|
||||||
int muchBiggerSize = initialSize + (3*110000);
|
int muchBiggerSize = initialSize + (3 * 110000);
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> square33 = checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, muchBiggerSize, muchBiggerSize);
|
QVector<LtsCoordTrans::UtmCoordinate> square33 =
|
||||||
|
checkAreaGetMgrsSquares(QStringLiteral("32U NC 0000000000"), 50000, 50000, muchBiggerSize, muchBiggerSize);
|
||||||
|
|
||||||
QVERIFY2(square33.size() == 33, "checkAreaGetMgrsSquares muchBiggerSize failed");
|
QVERIFY2(square33.size() == 33, "checkAreaGetMgrsSquares muchBiggerSize failed");
|
||||||
|
|
||||||
|
|
||||||
QStringList string1;
|
QStringList string1;
|
||||||
string1.reserve(squares1.size());
|
string1.reserve(squares1.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &item : std::as_const(squares1))
|
for (const LtsCoordTrans::UtmCoordinate& item : std::as_const(squares1))
|
||||||
string1.append(item.mgrs(0));
|
string1.append(item.mgrs(0));
|
||||||
|
|
||||||
QStringList string9;
|
QStringList string9;
|
||||||
string9.reserve(squares9.size());
|
string9.reserve(squares9.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &item : std::as_const(squares9))
|
for (const LtsCoordTrans::UtmCoordinate& item : std::as_const(squares9))
|
||||||
string9.append(item.mgrs(0));
|
string9.append(item.mgrs(0));
|
||||||
|
|
||||||
QStringList string33;
|
QStringList string33;
|
||||||
string33.reserve(square33.size());
|
string33.reserve(square33.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &item : std::as_const(square33))
|
for (const LtsCoordTrans::UtmCoordinate& item : std::as_const(square33))
|
||||||
string33.append(item.mgrs(0));
|
string33.append(item.mgrs(0));
|
||||||
|
|
||||||
{
|
{
|
||||||
QStringList surroundingStrings;
|
QStringList surroundingStrings;
|
||||||
surroundingStrings.reserve(squares9.size());
|
surroundingStrings.reserve(squares9.size());
|
||||||
for (const QString &str : std::as_const(string9))
|
for (const QString& str : std::as_const(string9))
|
||||||
if (!string1.contains(str))
|
if (!string1.contains(str))
|
||||||
surroundingStrings.append(str);
|
surroundingStrings.append(str);
|
||||||
|
|
||||||
@@ -435,22 +368,21 @@ void coordtrans_test::testMgrsSquaresWithSurrounding()
|
|||||||
{
|
{
|
||||||
QStringList surroundingStrings;
|
QStringList surroundingStrings;
|
||||||
surroundingStrings.reserve(string33.size());
|
surroundingStrings.reserve(string33.size());
|
||||||
for (const QString &str : std::as_const(string33))
|
for (const QString& str : std::as_const(string33))
|
||||||
if (!string1.contains(str))
|
if (!string1.contains(str))
|
||||||
surroundingStrings.append(str);
|
surroundingStrings.append(str);
|
||||||
|
|
||||||
QVERIFY2(surroundingStrings.size() == 32, "checkAreaGetMgrsSquares squaresDiff failed");
|
QVERIFY2(surroundingStrings.size() == 32, "checkAreaGetMgrsSquares squaresDiff failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void coordtrans_test::checkArea(const QString &base,
|
void coordtrans_test::checkArea(const QString& base, int xCenter, int yCenter, int width, int height,
|
||||||
int xCenter, int yCenter, int width, int height,
|
const QStringList& coords)
|
||||||
const QStringList &coords)
|
|
||||||
{
|
{
|
||||||
qDebug() << "checkArea : base: " << base;
|
qDebug() << "checkArea : base: " << base;
|
||||||
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
QRectF areaRect = QRectF(xCenter - width / 2, yCenter - height / 2, width, height);
|
||||||
LtsCoordTrans::UtmCoordinate utmBase(LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
LtsCoordTrans::UtmCoordinate utmBase(
|
||||||
|
LtsCoordTrans::UtmCoordinate::fromGeographic(LtsCoordTrans::geographicFromMgrs(base)));
|
||||||
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
const QPointF topLeft(utmBase.geographic(areaRect.left(), areaRect.top()));
|
||||||
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
const QPointF bottomRight(utmBase.geographic(areaRect.right(), areaRect.bottom()));
|
||||||
qDebug() << "TopLeft: " << topLeft * LtsCoordTrans::rad2deg();
|
qDebug() << "TopLeft: " << topLeft * LtsCoordTrans::rad2deg();
|
||||||
@@ -460,11 +392,9 @@ void coordtrans_test::checkArea(const QString &base,
|
|||||||
|
|
||||||
QStringList src;
|
QStringList src;
|
||||||
src.reserve(squares.size());
|
src.reserve(squares.size());
|
||||||
for (const auto &utm : squares)
|
for (const auto& utm : squares)
|
||||||
src += utm.mgrs(0);
|
src += utm.mgrs(0);
|
||||||
src.sort();
|
src.sort();
|
||||||
qDebug() << "src: '" << src << "' expected: '" << coords << "'";
|
qDebug() << "src: '" << src << "' expected: '" << coords << "'";
|
||||||
QCOMPARE(src, coords);
|
QCOMPARE(src, coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Executable → Regular
+3
-6
@@ -8,7 +8,7 @@
|
|||||||
class coordtrans_test : public QObject
|
class coordtrans_test : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
void testFromGeographic();
|
void testFromGeographic();
|
||||||
@@ -26,9 +26,6 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
void testMgrsSquaresWithSurrounding();
|
void testMgrsSquaresWithSurrounding();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkArea(const QString &base,
|
void checkArea(const QString& base, int xCenter, int yCenter, int width, int height, const QStringList& coords);
|
||||||
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.h"
|
||||||
|
|
||||||
#include "lts_coord_widget_p.h"
|
#include "lts_coord_widget_p.h"
|
||||||
|
|
||||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||||
@@ -10,15 +10,13 @@
|
|||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsCoordWidget::LtsCoordWidget(DisplayType dt, QWidget *parent)
|
LtsCoordWidget::LtsCoordWidget(DisplayType dt, QWidget* parent) : QWidget(parent), m_displayType(dt)
|
||||||
: QWidget(parent)
|
|
||||||
, m_displayType(dt)
|
|
||||||
{
|
{
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
rebuildUi();
|
rebuildUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setCoordinate(const QPointF &geoCoord, bool bUseAsDefaultValue)
|
void LtsCoordWidget::setCoordinate(const QPointF& geoCoord, bool bUseAsDefaultValue)
|
||||||
{
|
{
|
||||||
if (m_coordinate != geoCoord)
|
if (m_coordinate != geoCoord)
|
||||||
emit coordinateChanged(geoCoord);
|
emit coordinateChanged(geoCoord);
|
||||||
@@ -46,7 +44,6 @@ QPointF LtsCoordWidget::coordinate() const
|
|||||||
return m_inputWidgetHandler->coordinate();
|
return m_inputWidgetHandler->coordinate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LtsCoordWidget::DisplayType LtsCoordWidget::displayType() const
|
LtsCoordWidget::DisplayType LtsCoordWidget::displayType() const
|
||||||
{
|
{
|
||||||
return m_displayType;
|
return m_displayType;
|
||||||
@@ -108,27 +105,22 @@ void LtsCoordWidget::setWithSurroundingMgrsSquares(bool bEnable)
|
|||||||
m_inputWidgetHandler->setWithSurroundingSquare(bEnable);
|
m_inputWidgetHandler->setWithSurroundingSquare(bEnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LtsCoordWidget::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords)
|
void LtsCoordWidget::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords)
|
||||||
{
|
{
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
m_inputWidgetHandler->setMgrsSquares(geoCoords);
|
m_inputWidgetHandler->setMgrsSquares(geoCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LtsCoordWidget::event(QEvent* event)
|
||||||
bool LtsCoordWidget::event(QEvent *event)
|
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::ToolTip)
|
if (event->type() == QEvent::ToolTip)
|
||||||
updateToolTip();
|
updateToolTip();
|
||||||
return QWidget::event(event);
|
return QWidget::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsCoordWidget::rebuildUi()
|
void LtsCoordWidget::rebuildUi()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (m_inputWidgetHandler)
|
if (m_inputWidgetHandler)
|
||||||
{
|
{
|
||||||
m_inputWidgetHandler->cleanup();
|
m_inputWidgetHandler->cleanup();
|
||||||
@@ -157,12 +149,12 @@ void LtsCoordWidget::rebuildUi()
|
|||||||
|
|
||||||
m_inputWidgetHandler->setSquaresEditable(m_bMgrsSquareEditable);
|
m_inputWidgetHandler->setSquaresEditable(m_bMgrsSquareEditable);
|
||||||
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
m_inputWidgetHandler->resetButton()->setVisible(m_bWithResetButton);
|
||||||
connect(m_inputWidgetHandler->resetButton(), &QToolButton::clicked,
|
connect(m_inputWidgetHandler->resetButton(), &QToolButton::clicked, this,
|
||||||
this, &LtsCoordWidget::onResetToDefaultCoordinate);
|
&LtsCoordWidget::onResetToDefaultCoordinate);
|
||||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::coordinateChanged,
|
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::coordinateChanged, this,
|
||||||
this, &LtsCoordWidget::coordinateChanged);
|
&LtsCoordWidget::coordinateChanged);
|
||||||
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::invalidCoordinate,
|
connect(m_inputWidgetHandler, &LtsCoordInputWidgetHandler::invalidCoordinate, this,
|
||||||
this, &LtsCoordWidget::invalidCoordinate);
|
&LtsCoordWidget::invalidCoordinate);
|
||||||
if (!m_defaultCoordinate.isNull())
|
if (!m_defaultCoordinate.isNull())
|
||||||
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
||||||
}
|
}
|
||||||
@@ -183,7 +175,6 @@ void LtsCoordWidget::updateToolTip()
|
|||||||
setToolTip(tt);
|
setToolTip(tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsCoordWidget::onResetToDefaultCoordinate()
|
void LtsCoordWidget::onResetToDefaultCoordinate()
|
||||||
{
|
{
|
||||||
if (!m_inputWidgetHandler)
|
if (!m_inputWidgetHandler)
|
||||||
@@ -193,4 +184,4 @@ void LtsCoordWidget::onResetToDefaultCoordinate()
|
|||||||
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
m_inputWidgetHandler->setCoordinate(m_defaultCoordinate);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsCoordWidget
|
||||||
Executable → Regular
+29
-54
@@ -1,15 +1,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_coord_widget_p.h"
|
#include "lts_coord_widget_p.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
||||||
{
|
{
|
||||||
const QPointF coord(coordinate());
|
const QPointF coord(coordinate());
|
||||||
@@ -21,13 +18,8 @@ void LtsCoordInputWidgetHandler::onCoordinateDataChanged()
|
|||||||
emit coordinateChanged(coord);
|
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);
|
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));
|
m_ui->leNorth->setValidator(new QIntValidator(0, upperLimit, m_ui->leNorth));
|
||||||
setDefaultMgrsSquares();
|
setDefaultMgrsSquares();
|
||||||
|
|
||||||
connect(m_ui->cbxZone, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
connect(m_ui->cbxZone, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||||
this, &MgrsEdit::onCoordinateDataChanged);
|
&MgrsEdit::onCoordinateDataChanged);
|
||||||
connect(m_ui->leEast, &QLineEdit::editingFinished,
|
connect(m_ui->leEast, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
||||||
this, &MgrsEdit::onCoordinateDataChanged);
|
connect(m_ui->leNorth, &QLineEdit::editingFinished, this, &MgrsEdit::onCoordinateDataChanged);
|
||||||
connect(m_ui->leNorth, &QLineEdit::editingFinished,
|
|
||||||
this, &MgrsEdit::onCoordinateDataChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MgrsEdit::~MgrsEdit()
|
MgrsEdit::~MgrsEdit()
|
||||||
@@ -56,11 +46,11 @@ MgrsEdit::~MgrsEdit()
|
|||||||
bool MgrsEdit::isValid()
|
bool MgrsEdit::isValid()
|
||||||
{
|
{
|
||||||
|
|
||||||
const QString &east = m_ui->leEast->text();
|
const QString& east = m_ui->leEast->text();
|
||||||
if (east.size() != m_precision)
|
if (east.size() != m_precision)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QString &north = m_ui->leNorth->text();
|
const QString& north = m_ui->leNorth->text();
|
||||||
if (north.size() != m_precision)
|
if (north.size() != m_precision)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -73,7 +63,7 @@ bool MgrsEdit::isValid()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setCoordinate(const QPointF &geoCoord)
|
void MgrsEdit::setCoordinate(const QPointF& geoCoord)
|
||||||
{
|
{
|
||||||
const QString mgrsString = LtsCoordTrans::mgrsFromGeographic(geoCoord.x(), geoCoord.y(), m_precision, false);
|
const QString mgrsString = LtsCoordTrans::mgrsFromGeographic(geoCoord.x(), geoCoord.y(), m_precision, false);
|
||||||
if (mgrsString.isEmpty())
|
if (mgrsString.isEmpty())
|
||||||
@@ -86,7 +76,6 @@ void MgrsEdit::setCoordinate(const QPointF &geoCoord)
|
|||||||
m_ui->leEast->setText(QString());
|
m_ui->leEast->setText(QString());
|
||||||
m_ui->leNorth->setText(QString());
|
m_ui->leNorth->setText(QString());
|
||||||
|
|
||||||
|
|
||||||
const QString mgrsSquare = mgrsString.left(3) + QLatin1Char(' ') + mgrsString.mid(3, 2);
|
const QString mgrsSquare = mgrsString.left(3) + QLatin1Char(' ') + mgrsString.mid(3, 2);
|
||||||
QString east = mgrsString.mid(5, m_precision);
|
QString east = mgrsString.mid(5, m_precision);
|
||||||
QString north = mgrsString.mid(5 + m_precision, 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);
|
m_ui->leNorth->setText(north);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QString getMgrsCoord(QLineEdit *le, int prec)
|
static inline QString getMgrsCoord(QLineEdit* le, int prec)
|
||||||
{
|
{
|
||||||
QString ret = le->text();
|
QString ret = le->text();
|
||||||
if (ret.isEmpty())
|
if (ret.isEmpty())
|
||||||
@@ -123,7 +112,7 @@ QPointF MgrsEdit::coordinate() const
|
|||||||
return LtsCoordTrans::geographicFromMgrs(mgrsString);
|
return LtsCoordTrans::geographicFromMgrs(mgrsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
QToolButton *MgrsEdit::resetButton()
|
QToolButton* MgrsEdit::resetButton()
|
||||||
{
|
{
|
||||||
return m_ui->tbReset;
|
return m_ui->tbReset;
|
||||||
}
|
}
|
||||||
@@ -131,7 +120,6 @@ QToolButton *MgrsEdit::resetButton()
|
|||||||
void MgrsEdit::cleanup()
|
void MgrsEdit::cleanup()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
delete m_ui->horizontalLayout;
|
delete m_ui->horizontalLayout;
|
||||||
delete m_ui->cbxZone;
|
delete m_ui->cbxZone;
|
||||||
delete m_ui->leEast;
|
delete m_ui->leEast;
|
||||||
@@ -162,7 +150,7 @@ static QStringList defaultMgrsSquares()
|
|||||||
const QVector<LtsCoordTrans::UtmCoordinate> squares(LtsCoordTrans::defaultMgrsSquares());
|
const QVector<LtsCoordTrans::UtmCoordinate> squares(LtsCoordTrans::defaultMgrsSquares());
|
||||||
QStringList sl;
|
QStringList sl;
|
||||||
sl.reserve(squares.size());
|
sl.reserve(squares.size());
|
||||||
for (const LtsCoordTrans::UtmCoordinate &c : squares)
|
for (const LtsCoordTrans::UtmCoordinate& c : squares)
|
||||||
sl += c.mgrs(0);
|
sl += c.mgrs(0);
|
||||||
std::sort(sl.begin(), sl.end());
|
std::sort(sl.begin(), sl.end());
|
||||||
return sl;
|
return sl;
|
||||||
@@ -174,14 +162,13 @@ static QString preferedMgrsSquare()
|
|||||||
return c.mgrs(0);
|
return c.mgrs(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MgrsEdit::setDefaultMgrsSquares()
|
void MgrsEdit::setDefaultMgrsSquares()
|
||||||
{
|
{
|
||||||
m_ui->cbxZone->addItems(defaultMgrsSquares());
|
m_ui->cbxZone->addItems(defaultMgrsSquares());
|
||||||
m_ui->cbxZone->setCurrentIndex(m_ui->cbxZone->findText(preferedMgrsSquare()));
|
m_ui->cbxZone->setCurrentIndex(m_ui->cbxZone->findText(preferedMgrsSquare()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
void MgrsEdit::addMgrsSquare(const QString& newMgrsSquare)
|
||||||
{
|
{
|
||||||
QStringList sl = defaultMgrsSquares();
|
QStringList sl = defaultMgrsSquares();
|
||||||
sl += newMgrsSquare;
|
sl += newMgrsSquare;
|
||||||
@@ -189,7 +176,7 @@ void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
|||||||
{
|
{
|
||||||
QStringList squares = utmCoordsToList(LtsCoordTrans::defaultMgrsSquareWithOffsets());
|
QStringList squares = utmCoordsToList(LtsCoordTrans::defaultMgrsSquareWithOffsets());
|
||||||
|
|
||||||
for (const auto &sq : std::as_const(squares))
|
for (const auto& sq : std::as_const(squares))
|
||||||
if (!sl.contains(sq))
|
if (!sl.contains(sq))
|
||||||
sl.append(sq);
|
sl.append(sq);
|
||||||
}
|
}
|
||||||
@@ -198,17 +185,17 @@ void MgrsEdit::addMgrsSquare(const QString &newMgrsSquare)
|
|||||||
m_ui->cbxZone->addItems(sl);
|
m_ui->cbxZone->addItems(sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MgrsEdit::utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate> &coords)
|
QStringList MgrsEdit::utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate>& coords)
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
list.reserve(coords.count());
|
list.reserve(coords.count());
|
||||||
for (const auto &utm : coords)
|
for (const auto& utm : coords)
|
||||||
list.append(utm.mgrs(0));
|
list.append(utm.mgrs(0));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords)
|
void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords)
|
||||||
{
|
{
|
||||||
QStringList sl = utmCoordsToList(geoCoords);
|
QStringList sl = utmCoordsToList(geoCoords);
|
||||||
if (sl.isEmpty())
|
if (sl.isEmpty())
|
||||||
@@ -219,16 +206,11 @@ void MgrsEdit::setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCo
|
|||||||
m_ui->cbxZone->addItems(sl);
|
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);
|
m_ui->setupUi(widget);
|
||||||
|
|
||||||
DoubleValidator *v = new DoubleValidator(-180, 180, 9, m_ui->leLon);
|
DoubleValidator* v = new DoubleValidator(-180, 180, 9, m_ui->leLon);
|
||||||
v->setNotation(QDoubleValidator::StandardNotation);
|
v->setNotation(QDoubleValidator::StandardNotation);
|
||||||
m_ui->leLon->setValidator(v);
|
m_ui->leLon->setValidator(v);
|
||||||
|
|
||||||
@@ -236,10 +218,8 @@ Wgs84Edit::Wgs84Edit(QWidget *widget)
|
|||||||
v->setNotation(QDoubleValidator::StandardNotation);
|
v->setNotation(QDoubleValidator::StandardNotation);
|
||||||
m_ui->leLat->setValidator(v);
|
m_ui->leLat->setValidator(v);
|
||||||
|
|
||||||
connect(m_ui->leLon, &QLineEdit::editingFinished,
|
connect(m_ui->leLon, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
||||||
this, &Wgs84Edit::onCoordinateDataChanged);
|
connect(m_ui->leLat, &QLineEdit::editingFinished, this, &Wgs84Edit::onCoordinateDataChanged);
|
||||||
connect(m_ui->leLat, &QLineEdit::editingFinished,
|
|
||||||
this, &Wgs84Edit::onCoordinateDataChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Wgs84Edit::~Wgs84Edit()
|
Wgs84Edit::~Wgs84Edit()
|
||||||
@@ -253,7 +233,7 @@ bool Wgs84Edit::isValid()
|
|||||||
return (!m_ui->leLon->text().isEmpty()) && (!m_ui->leLat->text().isEmpty());
|
return (!m_ui->leLon->text().isEmpty()) && (!m_ui->leLat->text().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wgs84Edit::setCoordinate(const QPointF &geoCoord)
|
void Wgs84Edit::setCoordinate(const QPointF& geoCoord)
|
||||||
{
|
{
|
||||||
const QPointF coord(geoCoord * LtsCoordTrans::rad2deg());
|
const QPointF coord(geoCoord * LtsCoordTrans::rad2deg());
|
||||||
const QLocale l;
|
const QLocale l;
|
||||||
@@ -266,7 +246,6 @@ QPointF Wgs84Edit::coordinate() const
|
|||||||
QPointF ret;
|
QPointF ret;
|
||||||
const QLocale l;
|
const QLocale l;
|
||||||
|
|
||||||
|
|
||||||
const QString lonStr = m_ui->leLon->text().remove(l.groupSeparator());
|
const QString lonStr = m_ui->leLon->text().remove(l.groupSeparator());
|
||||||
const QString latStr = m_ui->leLat->text().remove(l.groupSeparator());
|
const QString latStr = m_ui->leLat->text().remove(l.groupSeparator());
|
||||||
if (lonStr.isEmpty() || latStr.isEmpty())
|
if (lonStr.isEmpty() || latStr.isEmpty())
|
||||||
@@ -278,7 +257,7 @@ QPointF Wgs84Edit::coordinate() const
|
|||||||
return ret * LtsCoordTrans::deg2rad();
|
return ret * LtsCoordTrans::deg2rad();
|
||||||
}
|
}
|
||||||
|
|
||||||
QToolButton *Wgs84Edit::resetButton()
|
QToolButton* Wgs84Edit::resetButton()
|
||||||
{
|
{
|
||||||
return m_ui->tbReset;
|
return m_ui->tbReset;
|
||||||
}
|
}
|
||||||
@@ -286,7 +265,6 @@ QToolButton *Wgs84Edit::resetButton()
|
|||||||
void Wgs84Edit::cleanup()
|
void Wgs84Edit::cleanup()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
delete m_ui->horizontalLayout;
|
delete m_ui->horizontalLayout;
|
||||||
delete m_ui->leLon;
|
delete m_ui->leLon;
|
||||||
delete m_ui->leLat;
|
delete m_ui->leLat;
|
||||||
@@ -301,14 +279,12 @@ void Wgs84Edit::clear()
|
|||||||
m_ui->leLat->clear();
|
m_ui->leLat->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoubleValidator::DoubleValidator(double bottom, double top, int decimals, QObject* parent)
|
||||||
|
|
||||||
|
|
||||||
DoubleValidator::DoubleValidator(double bottom, double top, int decimals, QObject *parent)
|
|
||||||
: QDoubleValidator(bottom, top, decimals, parent)
|
: QDoubleValidator(bottom, top, decimals, parent)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QValidator::State DoubleValidator::validate(QString &input, int &pos) const
|
QValidator::State DoubleValidator::validate(QString& input, int& pos) const
|
||||||
{
|
{
|
||||||
const QValidator::State ret = QDoubleValidator::validate(input, pos);
|
const QValidator::State ret = QDoubleValidator::validate(input, pos);
|
||||||
if (ret != QValidator::Acceptable)
|
if (ret != QValidator::Acceptable)
|
||||||
@@ -322,5 +298,4 @@ QValidator::State DoubleValidator::validate(QString &input, int &pos) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsCoordWidget
|
||||||
|
|
||||||
Executable → Regular
+53
-40
@@ -2,93 +2,106 @@
|
|||||||
|
|
||||||
#pragma once
|
#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_mgrs.h"
|
||||||
#include "ui_lts_coord_widget_wgs84.h"
|
#include "ui_lts_coord_widget_wgs84.h"
|
||||||
|
|
||||||
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
namespace LtsCoordWidget
|
namespace LtsCoordWidget
|
||||||
{
|
{
|
||||||
class LtsCoordInputWidgetHandler : public QObject
|
class LtsCoordInputWidgetHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LtsCoordInputWidgetHandler(QObject *parent)
|
explicit LtsCoordInputWidgetHandler(QObject* parent) : QObject(parent) {}
|
||||||
: QObject(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
virtual bool isValid() = 0;
|
virtual bool isValid() = 0;
|
||||||
virtual void setCoordinate(const QPointF &geoCoord) = 0;
|
virtual void setCoordinate(const QPointF& geoCoord) = 0;
|
||||||
virtual QPointF coordinate() const = 0;
|
virtual QPointF coordinate() const = 0;
|
||||||
virtual QToolButton *resetButton() = 0;
|
virtual QToolButton* resetButton() = 0;
|
||||||
virtual void cleanup() = 0;
|
virtual void cleanup() = 0;
|
||||||
virtual void clear() = 0;
|
virtual void clear() = 0;
|
||||||
virtual void setSquaresEditable(bool bEditable) = 0;
|
virtual void setSquaresEditable(bool bEditable) = 0;
|
||||||
virtual void setWithSurroundingSquare(bool bEnabled) = 0;
|
virtual void setWithSurroundingSquare(bool bEnabled) = 0;
|
||||||
virtual void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) = 0;
|
virtual void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) = 0;
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void onCoordinateDataChanged();
|
void onCoordinateDataChanged();
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void coordinateChanged(const QPointF &newGeoCoord);
|
void coordinateChanged(const QPointF& newGeoCoord);
|
||||||
void invalidCoordinate();
|
void invalidCoordinate();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MgrsEdit final : public LtsCoordInputWidgetHandler
|
class MgrsEdit final : public LtsCoordInputWidgetHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit MgrsEdit(int precision, QWidget *widget);
|
explicit MgrsEdit(int precision, QWidget* widget);
|
||||||
~MgrsEdit();
|
~MgrsEdit();
|
||||||
|
|
||||||
bool isValid() override;
|
bool isValid() override;
|
||||||
void setCoordinate(const QPointF &geoCoord) override;
|
void setCoordinate(const QPointF& geoCoord) override;
|
||||||
QPointF coordinate() const override;
|
QPointF coordinate() const override;
|
||||||
QToolButton *resetButton() override;
|
QToolButton* resetButton() override;
|
||||||
void cleanup() override;
|
void cleanup() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void setSquaresEditable(bool bEditable) override;
|
void setSquaresEditable(bool bEditable) override;
|
||||||
void setWithSurroundingSquare(bool bEnabled) override;
|
void setWithSurroundingSquare(bool bEnabled) override;
|
||||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) override;
|
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate>& geoCoords) override;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
void setDefaultMgrsSquares();
|
void setDefaultMgrsSquares();
|
||||||
void addMgrsSquare(const QString &newMgrsSquare);
|
void addMgrsSquare(const QString& newMgrsSquare);
|
||||||
QStringList utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate> &coords);
|
QStringList utmCoordsToList(const QVector<LtsCoordTrans::UtmCoordinate>& coords);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
int m_precision;
|
int m_precision;
|
||||||
bool m_withMgrsSquareOffset=false;
|
bool m_withMgrsSquareOffset = false;
|
||||||
Ui::Mgrs *m_ui;
|
Ui::Mgrs* m_ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Wgs84Edit final : public LtsCoordInputWidgetHandler
|
class Wgs84Edit final : public LtsCoordInputWidgetHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Wgs84Edit(QWidget *widget);
|
explicit Wgs84Edit(QWidget* widget);
|
||||||
~Wgs84Edit();
|
~Wgs84Edit();
|
||||||
|
|
||||||
bool isValid() override;
|
bool isValid() override;
|
||||||
void setCoordinate(const QPointF &geoCoord) override;
|
void setCoordinate(const QPointF& geoCoord) override;
|
||||||
QPointF coordinate() const override;
|
QPointF coordinate() const override;
|
||||||
QToolButton *resetButton() override;
|
QToolButton* resetButton() override;
|
||||||
void cleanup() override;
|
void cleanup() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void setSquaresEditable(bool bEditable) override { Q_UNUSED(bEditable); }
|
|
||||||
void setWithSurroundingSquare(bool bEnabled) override { Q_UNUSED(bEnabled); }
|
void setSquaresEditable(bool bEditable) override
|
||||||
void setMgrsSquares(const QVector<LtsCoordTrans::UtmCoordinate> &geoCoords) override { Q_UNUSED(geoCoords); }
|
{
|
||||||
private:
|
Q_UNUSED(bEditable);
|
||||||
Ui::Wgs84 *m_ui;
|
}
|
||||||
|
|
||||||
|
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
|
class DoubleValidator final : public QDoubleValidator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
|
DoubleValidator(double bottom, double top, int decimals, QObject* parent = nullptr);
|
||||||
|
|
||||||
QValidator::State validate(QString &input, int &pos) const override;
|
QValidator::State validate(QString& input, int& pos) const override;
|
||||||
};
|
};
|
||||||
}
|
} // namespace LtsCoordWidget
|
||||||
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"
|
#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 mgrs = LtsCoordTrans::mgrsFromGeographic(coord.x(), coord.y(), prec);
|
||||||
QString str = QStringLiteral("mgrs: %1, lon: %2, lat: %3")
|
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);
|
lbl->setText(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
@@ -28,83 +28,74 @@ int main(int argc, char **argv)
|
|||||||
QPointF bottomRight(base.geographic(-50000, 50000));
|
QPointF bottomRight(base.geographic(-50000, 50000));
|
||||||
LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), true, true);
|
LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), true, true);
|
||||||
|
|
||||||
QDialog *dialog(new QDialog);
|
QDialog* dialog(new QDialog);
|
||||||
QVBoxLayout *lay(new QVBoxLayout(dialog));
|
QVBoxLayout* lay(new QVBoxLayout(dialog));
|
||||||
|
|
||||||
|
|
||||||
const QPointF defCoord(QPointF(53.0, 8.0) * LtsCoordTrans::deg2rad());
|
const QPointF defCoord(QPointF(53.0, 8.0) * LtsCoordTrans::deg2rad());
|
||||||
|
|
||||||
LtsCoordWidget::LtsCoordWidget *wMgrs5(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS, dialog));
|
LtsCoordWidget::LtsCoordWidget* wMgrs5(
|
||||||
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS, dialog));
|
||||||
wMgrs5->setWithResetButton(true);
|
wMgrs5->setWithResetButton(true);
|
||||||
wMgrs5->setCoordinate(defCoord, true);
|
wMgrs5->setCoordinate(defCoord, true);
|
||||||
lay->addWidget(wMgrs5);
|
lay->addWidget(wMgrs5);
|
||||||
QLabel *lbl5(new QLabel(dialog));
|
QLabel* lbl5(new QLabel(dialog));
|
||||||
lay->addWidget(lbl5);
|
lay->addWidget(lbl5);
|
||||||
QObject::connect(wMgrs5, &LtsCoordWidget::LtsCoordWidget::coordinateChanged,
|
QObject::connect(wMgrs5, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, lbl5,
|
||||||
lbl5, [lbl5](const QPointF & coord)
|
[lbl5](const QPointF& coord) { updateLabel(coord, lbl5, 5); });
|
||||||
{
|
|
||||||
updateLabel(coord, lbl5, 5);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
LtsCoordWidget::LtsCoordWidget* wMgrs7(
|
||||||
LtsCoordWidget::LtsCoordWidget *wMgrs7(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7, dialog));
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7, dialog));
|
||||||
wMgrs7->setWithResetButton(true);
|
wMgrs7->setWithResetButton(true);
|
||||||
wMgrs7->setCoordinate(defCoord, true);
|
wMgrs7->setCoordinate(defCoord, true);
|
||||||
lay->addWidget(wMgrs7);
|
lay->addWidget(wMgrs7);
|
||||||
QLabel *lbl7(new QLabel(dialog));
|
QLabel* lbl7(new QLabel(dialog));
|
||||||
lay->addWidget(lbl7);
|
lay->addWidget(lbl7);
|
||||||
QObject::connect(wMgrs7, &LtsCoordWidget::LtsCoordWidget::coordinateChanged,
|
QObject::connect(wMgrs7, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, wMgrs7,
|
||||||
wMgrs7, [lbl7](const QPointF & coord)
|
[lbl7](const QPointF& coord) { updateLabel(coord, lbl7, 7); });
|
||||||
{
|
|
||||||
updateLabel(coord, lbl7, 7);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
LtsCoordWidget::LtsCoordWidget* w84(
|
||||||
LtsCoordWidget::LtsCoordWidget *w84(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
||||||
w84->setWithResetButton(true);
|
w84->setWithResetButton(true);
|
||||||
w84->setCoordinate(defCoord, true);
|
w84->setCoordinate(defCoord, true);
|
||||||
lay->addWidget(w84);
|
lay->addWidget(w84);
|
||||||
QLabel *lbl84(new QLabel(dialog));
|
QLabel* lbl84(new QLabel(dialog));
|
||||||
lay->addWidget(lbl84);
|
lay->addWidget(lbl84);
|
||||||
QObject::connect(w84, &LtsCoordWidget::LtsCoordWidget::coordinateChanged,
|
QObject::connect(w84, &LtsCoordWidget::LtsCoordWidget::coordinateChanged, w84,
|
||||||
w84, [lbl84](const QPointF & coord)
|
[lbl84](const QPointF& coord) { updateLabel(coord, lbl84, 11); });
|
||||||
{
|
|
||||||
updateLabel(coord, lbl84, 11);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
QHBoxLayout* hLay = new QHBoxLayout;
|
||||||
QHBoxLayout *hLay = new QHBoxLayout;
|
|
||||||
lay->addLayout(hLay);
|
lay->addLayout(hLay);
|
||||||
LtsCoordWidget::LtsCoordWidget *wChange(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
LtsCoordWidget::LtsCoordWidget* wChange(
|
||||||
|
new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
||||||
wChange->setWithResetButton(true);
|
wChange->setWithResetButton(true);
|
||||||
wChange->setCoordinate(defCoord, true);
|
wChange->setCoordinate(defCoord, true);
|
||||||
hLay->addWidget(wChange);
|
hLay->addWidget(wChange);
|
||||||
QPushButton *pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
QPushButton* pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
||||||
hLay->addWidget(pbReset);
|
hLay->addWidget(pbReset);
|
||||||
QObject::connect(pbReset, &QPushButton::clicked,
|
QObject::connect(pbReset, &QPushButton::clicked, wChange,
|
||||||
wChange, [wChange]() { wChange->setWithResetButton(!wChange->withResetButton());});
|
[wChange]() { wChange->setWithResetButton(!wChange->withResetButton()); });
|
||||||
QPushButton *pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
QPushButton* pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
||||||
hLay->addWidget(pbNext);
|
hLay->addWidget(pbNext);
|
||||||
QObject::connect(pbNext, &QPushButton::clicked,
|
QObject::connect(pbNext, &QPushButton::clicked, wChange, [wChange]() {
|
||||||
wChange, [wChange]()
|
|
||||||
{
|
|
||||||
LtsCoordWidget::LtsCoordWidget::DisplayType dt = wChange->displayType();
|
LtsCoordWidget::LtsCoordWidget::DisplayType dt = wChange->displayType();
|
||||||
switch (dt)
|
switch (dt)
|
||||||
{
|
{
|
||||||
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5:
|
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5:
|
||||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7; break;
|
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7;
|
||||||
|
break;
|
||||||
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7:
|
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7:
|
||||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84; break;
|
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84;
|
||||||
|
break;
|
||||||
case LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84:
|
case LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84:
|
||||||
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5; break;
|
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wChange->setDisplayType(dt);
|
wChange->setDisplayType(dt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QPushButton* pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
||||||
QPushButton *pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
|
||||||
lay->addWidget(pb);
|
lay->addWidget(pb);
|
||||||
QObject::connect(pb, &QPushButton::clicked, qApp, QCoreApplication::quit);
|
QObject::connect(pb, &QPushButton::clicked, qApp, QCoreApplication::quit);
|
||||||
|
|
||||||
|
|||||||
Executable → Regular
+4
-5
@@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <GeographicLib/UTMUPS.hpp>
|
|
||||||
#include <GeographicLib/MGRS.hpp>
|
#include <GeographicLib/MGRS.hpp>
|
||||||
|
#include <GeographicLib/UTMUPS.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
@@ -39,7 +38,7 @@ int main(int argc, char **argv)
|
|||||||
part2 = mgrs.substr(3, 2);
|
part2 = mgrs.substr(3, 2);
|
||||||
part3 = mgrs.substr(5, prec);
|
part3 = mgrs.substr(5, prec);
|
||||||
part4 = mgrs.substr(5 + prec, prec);
|
part4 = mgrs.substr(5 + prec, prec);
|
||||||
fprintf(stdout, "%s %s %s %s = %13.10f, %13.10f ( %13.10f, %13.10f )\n",
|
fprintf(stdout, "%s %s %s %s = %13.10f, %13.10f ( %13.10f, %13.10f )\n", part1.c_str(), part2.c_str(),
|
||||||
part1.c_str(), part2.c_str(), part3.c_str(), part4.c_str(), lonDeg, latDeg, lonDeg / 180. * M_PI, latDeg / 180. * M_PI);
|
part3.c_str(), part4.c_str(), lonDeg, latDeg, lonDeg / 180. * M_PI, latDeg / 180. * M_PI);
|
||||||
return 0;
|
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
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <LtsElevation/lts_elevation_manager.h>
|
|
||||||
|
|
||||||
#include <ElevationMap/elevation_map_manager.h>
|
#include <ElevationMap/elevation_map_manager.h>
|
||||||
|
#include <LtsElevation/lts_elevation_manager.h>
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QtTest/QTest>
|
|
||||||
#include <NGLLogger/INGLLogger.h>
|
#include <NGLLogger/INGLLogger.h>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtTest/QTest>
|
||||||
|
|
||||||
using LOGGER_T = NGL::INGLLogger&;
|
using LOGGER_T = NGL::INGLLogger&;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UnitTestCoordinate : public QObject
|
class UnitTestCoordinate : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnitTestCoordinate();
|
UnitTestCoordinate();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
private Q_SLOTS:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_NaN();
|
void test_NaN();
|
||||||
|
|
||||||
void test_coordinate_simple1();
|
void test_coordinate_simple1();
|
||||||
@@ -68,18 +52,9 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
void test_coordinate_avoid_copy();
|
void test_coordinate_avoid_copy();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_container_references();
|
void test_container_references();
|
||||||
void test_coordVector();
|
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"
|
#include "lts_coord_vector.h"
|
||||||
|
|
||||||
namespace LtsCoordTrans
|
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)
|
: 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);
|
convertGeoToStdUtm(zone);
|
||||||
return m_utmMapStd[zone];
|
return m_utmMapStd[zone];
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<UtmCoordinate> &LtsCoordVector::toQVectorUtmCoord(int zone) const
|
const QVector<UtmCoordinate>& LtsCoordVector::toQVectorUtmCoord(int zone) const
|
||||||
{
|
{
|
||||||
convertGeoToQVectorUtm(zone);
|
convertGeoToQVectorUtm(zone);
|
||||||
return m_utmMapQVector[zone];
|
return m_utmMapQVector[zone];
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<QPointF> &LtsCoordVector::toQVectorQPointF(int zone) const
|
const QVector<QPointF>& LtsCoordVector::toQVectorQPointF(int zone) const
|
||||||
{
|
{
|
||||||
convertGeoToQVectorQPointF(zone);
|
convertGeoToQVectorQPointF(zone);
|
||||||
return m_utmMapQVectorQPointF[zone];
|
return m_utmMapQVectorQPointF[zone];
|
||||||
@@ -45,16 +42,12 @@ void LtsCoordVector::convertGeoToQVectorUtm(int zone) const
|
|||||||
if (it != m_utmMapQVector.end())
|
if (it != m_utmMapQVector.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
convertGeoToStdUtm(zone);
|
convertGeoToStdUtm(zone);
|
||||||
QVector<LtsCoordTrans::UtmCoordinate> &utmVectorRef = m_utmMapQVector[zone];
|
QVector<LtsCoordTrans::UtmCoordinate>& utmVectorRef = m_utmMapQVector[zone];
|
||||||
utmVectorRef.clear();
|
utmVectorRef.clear();
|
||||||
utmVectorRef.reserve(m_geo_coordinates.size());
|
utmVectorRef.reserve(m_geo_coordinates.size());
|
||||||
|
|
||||||
for (const auto &utmCoord : m_utmMapStd[zone])
|
for (const auto& utmCoord : m_utmMapStd[zone])
|
||||||
utmVectorRef.push_back(utmCoord);
|
utmVectorRef.push_back(utmCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,26 +58,12 @@ void LtsCoordVector::convertGeoToQVectorQPointF(int zone) const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
convertGeoToStdUtm(zone);
|
convertGeoToStdUtm(zone);
|
||||||
QVector<QPointF> &QVectorQPointFRef = m_utmMapQVectorQPointF[zone];
|
QVector<QPointF>& QVectorQPointFRef = m_utmMapQVectorQPointF[zone];
|
||||||
QVectorQPointFRef.clear();
|
QVectorQPointFRef.clear();
|
||||||
QVectorQPointFRef.reserve(m_geo_coordinates.size());
|
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));
|
QVectorQPointFRef.push_back(QPointF(utmCoord.x, utmCoord.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace LtsCoordTrans
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Executable → Regular
+21
-41
@@ -1,82 +1,62 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ltscoordinate_export.h"
|
#include "ltscoordinate_export.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <Core/core.hpp>
|
#include <Core/core.hpp>
|
||||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||||
|
#include <QDebug>
|
||||||
#include <unordered_map>
|
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LTSCOORDINATE_EXPORT LtsCoordVector
|
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;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
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:
|
|
||||||
void convertGeoToStdUtm(int zone) const;
|
void convertGeoToStdUtm(int zone) const;
|
||||||
void convertGeoToQVectorUtm(int zone) const;
|
void convertGeoToQVectorUtm(int zone) const;
|
||||||
void convertGeoToQVectorQPointF(int zone) const;
|
void convertGeoToQVectorQPointF(int zone) const;
|
||||||
|
|
||||||
template<typename T>
|
template <typename T> void convertGeoToUtmInternal(int zone, T& utmVectorRef) const
|
||||||
void convertGeoToUtmInternal(int zone, T &utmVectorRef) const
|
|
||||||
{
|
{
|
||||||
|
|
||||||
utmVectorRef.clear();
|
utmVectorRef.clear();
|
||||||
utmVectorRef.reserve(m_geo_coordinates.size());
|
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));
|
utmVectorRef.push_back(LtsCoordTrans::UtmCoordinate::fromGeographic(geoCoord.lon(), geoCoord.lat(), zone));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<Core::GeoPosition> m_geo_coordinates;
|
std::vector<Core::GeoPosition> m_geo_coordinates;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mutable std::unordered_map<int, std::vector<LtsCoordTrans::UtmCoordinate>> m_utmMapStd;
|
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<LtsCoordTrans::UtmCoordinate>> m_utmMapQVector;
|
||||||
mutable std::unordered_map<int, QVector<QPointF>> m_utmMapQVectorQPointF;
|
mutable std::unordered_map<int, QVector<QPointF>> m_utmMapQVectorQPointF;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace LtsCoordTrans
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Executable → Regular
+16
-52
@@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_coordinate.h"
|
#include "lts_coordinate.h"
|
||||||
|
|
||||||
#include <QLineF>
|
#include <QLineF>
|
||||||
|
|
||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans
|
||||||
@@ -10,13 +9,9 @@ namespace LtsCoordTrans
|
|||||||
|
|
||||||
static long s_conversion_counter = 0;
|
static long s_conversion_counter = 0;
|
||||||
|
|
||||||
|
|
||||||
std::function<double(double, double, double, bool*)> LtsCoordinate::m_getElevationCB;
|
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;
|
m_getElevationCB = elevationCB;
|
||||||
}
|
}
|
||||||
@@ -26,11 +21,9 @@ bool LtsCoordinate::hasElevationCallback()
|
|||||||
return m_getElevationCB != nullptr;
|
return m_getElevationCB != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
double LtsCoordinate::elevationAt(double defaultElevation, bool *bIsCovered) const
|
double LtsCoordinate::elevationAt(double defaultElevation, bool* bIsCovered) const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!bIsCovered)
|
if (!bIsCovered)
|
||||||
if (!std::isnan(m_elevation))
|
if (!std::isnan(m_elevation))
|
||||||
return m_elevation;
|
return m_elevation;
|
||||||
@@ -44,7 +37,7 @@ void LtsCoordinate::setZValueAccordingElevation(double defaultElevation)
|
|||||||
m_geo.z(elevationAt(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);
|
return coordinate.elevationAt(defaultElevation, bIsCovered);
|
||||||
}
|
}
|
||||||
@@ -52,47 +45,23 @@ double LtsCoordinate::elevationAt(const LtsCoordinate &coordinate, double defaul
|
|||||||
void LtsCoordinate::replaceZValueByElevationIfValue(double zValueToBeReplaced, double defaultElevation)
|
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);
|
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& utm1 = coord1.utmCoordinate();
|
||||||
const LtsCoordTrans::UtmCoordinate &utm2 = coord2.utmCoordinateDiffZone(utm1.zone);
|
const LtsCoordTrans::UtmCoordinate& utm2 = coord2.utmCoordinateDiffZone(utm1.zone);
|
||||||
|
|
||||||
const QPointF& offsetUtm = utm2.toPoint() - utm1.toPoint();
|
const QPointF& offsetUtm = utm2.toPoint() - utm1.toPoint();
|
||||||
QLineF poly(QPointF(), offsetUtm);
|
QLineF poly(QPointF(), offsetUtm);
|
||||||
const double angle = poly.angle();
|
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)
|
if (zone == -1)
|
||||||
{
|
{
|
||||||
@@ -138,7 +107,6 @@ QString LtsCoordinate::mgrsWithZ(int prec, bool withSpaces) const
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString LtsCoordinate::toString(bool fullAndExpensive) const
|
QString LtsCoordinate::toString(bool fullAndExpensive) const
|
||||||
{
|
{
|
||||||
if (fullAndExpensive)
|
if (fullAndExpensive)
|
||||||
@@ -147,12 +115,11 @@ QString LtsCoordinate::toString(bool fullAndExpensive) const
|
|||||||
elevationAt();
|
elevationAt();
|
||||||
}
|
}
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "LtsCoordinate(m_geo=" << m_geo
|
stream << "LtsCoordinate(m_geo=" << m_geo << ", m_utm2D.x " << m_utm2D.x << ", m_utm2D.y " << m_utm2D.y
|
||||||
<< ", m_utm2D.x " << m_utm2D.x << ", m_utm2D.y " << m_utm2D.y << ", m_utm2D.zone " << m_utm2D.zone;
|
<< ", m_utm2D.zone " << m_utm2D.zone;
|
||||||
if (!qFuzzyIsNull(m_utm2D.x) || !qFuzzyIsNull(m_utm2D.y))
|
if (!qFuzzyIsNull(m_utm2D.x) || !qFuzzyIsNull(m_utm2D.y))
|
||||||
stream << ", m_utm2D.mgrs '" << m_utm2D.mgrs().toUtf8().constData() << "'";
|
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());
|
return QString::fromStdString(stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,19 +127,16 @@ void LtsCoordinate::resetConversionCounter()
|
|||||||
{
|
{
|
||||||
s_conversion_counter = 0;
|
s_conversion_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long LtsCoordinate::getConversionCounter()
|
long LtsCoordinate::getConversionCounter()
|
||||||
{
|
{
|
||||||
return s_conversion_counter;
|
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();
|
stream << value.toString().toStdString();
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsCoordTrans
|
||||||
|
|
||||||
|
|
||||||
Executable → Regular
+128
-199
@@ -1,22 +1,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ltscoordinate_export.h"
|
#include "ltscoordinate_export.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <Core/core.hpp>
|
#include <Core/core.hpp>
|
||||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||||
#include <LtsUtils/LtsUtilsCore/qpoint3d.h>
|
#include <LtsUtils/LtsUtilsCore/qpoint3d.h>
|
||||||
|
|
||||||
#include <QPointF>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QPointF>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace LtsCoordTrans
|
namespace LtsCoordTrans
|
||||||
{
|
{
|
||||||
@@ -24,206 +20,176 @@ namespace LtsCoordTrans
|
|||||||
using UtmCoordinate2D = LtsCoordTrans::UtmCoordinate;
|
using UtmCoordinate2D = LtsCoordTrans::UtmCoordinate;
|
||||||
using QPoint3D = LtsUtils::QPoint3D;
|
using QPoint3D = LtsUtils::QPoint3D;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LTSCOORDINATE_EXPORT LtsCoordinate
|
class LTSCOORDINATE_EXPORT LtsCoordinate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
explicit LtsCoordinate(double lon = 0, double lat = 0, double z = std::nan(""))
|
explicit LtsCoordinate(double lon = 0, double lat = 0, double z = std::nan(""))
|
||||||
: m_geo(Core::GeoPosition(lon, lat, z))
|
: 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))
|
: m_geo(Core::GeoPosition(lonLat.x(), lonLat.y(), z))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit LtsCoordinate(const Core::GeoPosition &geoPos)
|
explicit LtsCoordinate(const Core::GeoPosition& geoPos) : m_geo(geoPos) {}
|
||||||
: m_geo(geoPos)
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit LtsCoordinate(const Core::GeoPosition2D &geoPos2D)
|
explicit LtsCoordinate(const Core::GeoPosition2D& geoPos2D) : m_geo(geoPos2D.lon(), geoPos2D.lat(), std::nan("")) {}
|
||||||
: 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(""))
|
static LtsCoordinate fromGeoPosition(double lon, double lat, double z = std::nan(""))
|
||||||
{
|
{
|
||||||
return LtsCoordinate(lon, lat, z);
|
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");
|
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);
|
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 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);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool valueIsNullOrNan(double value)
|
||||||
|
{
|
||||||
bool isValid() const { return hasGeo() || hasUtm(); }
|
return qFuzzyIsNull(value) || std::isnan(value);
|
||||||
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); }
|
|
||||||
|
|
||||||
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
QString mgrs(int prec = 5, bool withSpaces = true) const;
|
||||||
QString mgrsWithZ(int prec = 5, bool withSpaces = true) const;
|
QString mgrsWithZ(int prec = 5, bool withSpaces = true) const;
|
||||||
|
|
||||||
QString toString(bool fullAndExpensive = false) const;
|
QString toString(bool fullAndExpensive = false) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void resetConversionCounter();
|
static void resetConversionCounter();
|
||||||
static long getConversionCounter();
|
static long getConversionCounter();
|
||||||
|
|
||||||
|
const Core::GeoPosition& geoPosition() const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Core::GeoPosition &geoPosition() const
|
|
||||||
{
|
|
||||||
return m_geo;
|
|
||||||
}
|
|
||||||
const Core::GeoPosition2D &geoPosition2D() const
|
|
||||||
{
|
{
|
||||||
return m_geo;
|
return m_geo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LtsCoordTrans::UtmCoordinate &utmCoordinate() const
|
const Core::GeoPosition2D& geoPosition2D() const
|
||||||
|
{
|
||||||
|
return m_geo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LtsCoordTrans::UtmCoordinate& utmCoordinate() const
|
||||||
{
|
{
|
||||||
if (!hasUtm())
|
if (!hasUtm())
|
||||||
convertGeoToUtm();
|
convertGeoToUtm();
|
||||||
return m_utm2D;
|
return m_utm2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double& rz()
|
||||||
|
{
|
||||||
|
return m_geo.z();
|
||||||
|
}
|
||||||
|
|
||||||
double &rz() { return m_geo.z(); }
|
double z() const
|
||||||
double z() const { return m_geo.z(); }
|
{
|
||||||
void setZ(double value) { m_geo.z(value); }
|
return m_geo.z();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setZ(double value)
|
||||||
|
{
|
||||||
|
m_geo.z(value);
|
||||||
|
}
|
||||||
|
|
||||||
LtsCoordTrans::UtmCoordinate utmCoordinateDiffZone(int zone) const
|
LtsCoordTrans::UtmCoordinate utmCoordinateDiffZone(int zone) const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
m_utm2D_differentZone = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon(), m_geo.lat(), zone);
|
m_utm2D_differentZone = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon(), m_geo.lat(), zone);
|
||||||
return m_utm2D_differentZone;
|
return m_utm2D_differentZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> T toUtm(int zone = -1) const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T toUtm(int zone = -1) const
|
|
||||||
{
|
{
|
||||||
T obj;
|
T obj;
|
||||||
helperToUtm(obj, zone);
|
helperToUtm(obj, zone);
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF toUtmPointF() const { return toUtm<QPointF>(); }
|
QPointF toUtmPointF() const
|
||||||
QPoint3D toUtmPoint3D() const { return toUtm<QPoint3D>(); }
|
{
|
||||||
|
return toUtm<QPointF>();
|
||||||
|
}
|
||||||
|
|
||||||
QPointF toGeoPointF() const { return QPointF (m_geo.lon(), m_geo.lat()); }
|
QPoint3D toUtmPoint3D() const
|
||||||
QPoint3D toGeoPoint3D() const { return QPoint3D(m_geo.lon(), m_geo.lat(), m_geo.z() ); }
|
{
|
||||||
|
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
|
UtmCoordinate3D toUtmCoordinate3D() const
|
||||||
{
|
{
|
||||||
return UtmCoordinate3D(utmCoordinate(), m_geo.z());
|
return UtmCoordinate3D(utmCoordinate(), m_geo.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using elevationCbFunc = std::function<double(double, double, double, bool*)>;
|
using elevationCbFunc = std::function<double(double, double, double, bool*)>;
|
||||||
|
|
||||||
|
static void setElevationCallback(const elevationCbFunc& elevationCB);
|
||||||
|
|
||||||
|
|
||||||
static void setElevationCallback(const elevationCbFunc &elevationCB);
|
|
||||||
static bool hasElevationCallback();
|
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);
|
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);
|
void replaceZValueByElevationIfValue(double zValueToBeReplaced = std::nan(""), double defaultElevation = 0.0);
|
||||||
|
|
||||||
|
double heightOverElevation() const
|
||||||
|
{
|
||||||
|
return m_geo.z() - elevationAt();
|
||||||
|
}
|
||||||
|
|
||||||
|
double distanceUtm2D(const LtsCoordinate& other) const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double heightOverElevation() const { return m_geo.z() - elevationAt(); }
|
|
||||||
|
|
||||||
|
|
||||||
double distanceUtm2D(const LtsCoordinate &other) const
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const LtsCoordTrans::UtmCoordinate& thisUtm2D = utmCoordinate();
|
||||||
const LtsCoordTrans::UtmCoordinate &thisUtm2D = utmCoordinate();
|
const LtsCoordTrans::UtmCoordinate& otherUtm2D = other.utmCoordinateDiffZone(m_utm2D.zone);
|
||||||
const LtsCoordTrans::UtmCoordinate &otherUtm2D = other.utmCoordinateDiffZone(m_utm2D.zone);
|
|
||||||
return LtsCoordTrans::distance(thisUtm2D, otherUtm2D);
|
return LtsCoordTrans::distance(thisUtm2D, otherUtm2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
double distanceUtm3D(const LtsCoordinate &other) const
|
double distanceUtm3D(const LtsCoordinate& other) const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const QPoint3D& thisUtm3D = toUtm<QPoint3D>();
|
||||||
const QPoint3D &thisUtm3D = toUtm<QPoint3D>();
|
const QPoint3D& otherUtm3D = other.toUtm<QPoint3D>(m_utm2D.zone);
|
||||||
const QPoint3D &otherUtm3D = other.toUtm<QPoint3D>(m_utm2D.zone);
|
|
||||||
const double dist3D = (thisUtm3D - otherUtm3D).length();
|
const double dist3D = (thisUtm3D - otherUtm3D).length();
|
||||||
|
|
||||||
Q_ASSERT_X(!std::isnan(dist3D), "LtsCoordinate", "ERROR, distance3D is NaN");
|
Q_ASSERT_X(!std::isnan(dist3D), "LtsCoordinate", "ERROR, distance3D is NaN");
|
||||||
@@ -231,48 +197,58 @@ public:
|
|||||||
return dist3D;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
const LtsCoordTrans::UtmCoordinate& utmCoordinateInternal(int zone = -1) const;
|
||||||
|
|
||||||
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;
|
|
||||||
void convertGeoToUtm() const;
|
void convertGeoToUtm() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void helperToUtm(QPointF& pntRef, int zone = -1) const
|
||||||
void helperToUtm(QPointF &pntRef, int zone = -1) const
|
|
||||||
{
|
{
|
||||||
const auto &utmTemp = utmCoordinateInternal(zone);
|
const auto& utmTemp = utmCoordinateInternal(zone);
|
||||||
pntRef.rx() = utmTemp.x;
|
pntRef.rx() = utmTemp.x;
|
||||||
pntRef.ry() = utmTemp.y;
|
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.rx() = utmTemp.x;
|
||||||
pntRef.ry() = utmTemp.y;
|
pntRef.ry() = utmTemp.y;
|
||||||
pntRef.rz() = m_geo.z();
|
pntRef.rz() = m_geo.z();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable Core::GeoPosition m_geo;
|
mutable Core::GeoPosition m_geo;
|
||||||
mutable UtmCoordinate2D m_utm2D;
|
mutable UtmCoordinate2D m_utm2D;
|
||||||
mutable UtmCoordinate2D m_utm2D_differentZone;
|
mutable UtmCoordinate2D m_utm2D_differentZone;
|
||||||
@@ -281,88 +257,41 @@ protected:
|
|||||||
static elevationCbFunc m_getElevationCB;
|
static elevationCbFunc m_getElevationCB;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LTSCOORDINATE_EXPORT LtsCoordinateNoImplicitCopy : public LtsCoordinate
|
class LTSCOORDINATE_EXPORT LtsCoordinateNoImplicitCopy : public LtsCoordinate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using BaseClass = LtsCoordinate;
|
using BaseClass = LtsCoordinate;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LtsCoordinateNoImplicitCopy() = default;
|
LtsCoordinateNoImplicitCopy() = default;
|
||||||
explicit LtsCoordinateNoImplicitCopy (const LtsCoordinateNoImplicitCopy &) = default;
|
explicit LtsCoordinateNoImplicitCopy(const LtsCoordinateNoImplicitCopy&) = default;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
~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))
|
: BaseClass(Core::GeoPosition(lonLat.x(), lonLat.y(), z))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition &geoPos)
|
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition& geoPos) : BaseClass(geoPos) {}
|
||||||
: BaseClass(geoPos)
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition2D &geoPos2D)
|
explicit LtsCoordinateNoImplicitCopy(const Core::GeoPosition2D& geoPos2D) : BaseClass(geoPos2D) {}
|
||||||
: BaseClass(geoPos2D)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
void updateGeoPosition(const Core::GeoPosition& geoPos) const
|
||||||
|
|
||||||
|
|
||||||
void updateGeoPosition(const Core::GeoPosition &geoPos) const
|
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
m_geo = geoPos;
|
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;
|
T_OUT out;
|
||||||
out.reserve(contIn.size());
|
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));
|
out.push_back(LtsCoordinate(posGeo));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LTSCOORDINATE_EXPORT std::ostream& operator<<(std::ostream& stream, const LtsCoordinate& value);
|
||||||
|
|
||||||
|
} // namespace LtsCoordTrans
|
||||||
LTSCOORDINATE_EXPORT std::ostream &operator<< (std::ostream &stream,
|
|
||||||
const LtsCoordinate &value);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Executable → Regular
+31
-63
@@ -1,15 +1,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "elevation_unit_test.h"
|
#include "elevation_unit_test.h"
|
||||||
|
|
||||||
#include <ElevationMap/elevation_map_manager.h>
|
#include <ElevationMap/elevation_map_manager.h>
|
||||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||||
|
|
||||||
#include <nglapplication/nglcoreapplication.h>
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
#include <QtTest/QTest>
|
#include <QtTest/QTest>
|
||||||
|
#include <nglapplication/nglcoreapplication.h>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(LtsUtils::QPoint3D);
|
Q_DECLARE_METATYPE(LtsUtils::QPoint3D);
|
||||||
Q_DECLARE_METATYPE(LtsElevation::LineOfSight);
|
Q_DECLARE_METATYPE(LtsElevation::LineOfSight);
|
||||||
@@ -17,38 +14,27 @@ Q_DECLARE_METATYPE(LtsElevation::LineOfSight);
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
static const int s_id{4711};
|
static const int s_id{4711};
|
||||||
static LtsElevation::LtsElevationManager *s_eleMgr{nullptr};
|
static LtsElevation::LtsElevationManager* s_eleMgr{nullptr};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MyLtsElevationManagerBootstrap : public LtsElevation::LtsElevationManager
|
class MyLtsElevationManagerBootstrap : public LtsElevation::LtsElevationManager
|
||||||
{
|
{
|
||||||
using BaseClass = LtsElevation::LtsElevationManager;
|
using BaseClass = LtsElevation::LtsElevationManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static LtsElevationManager *createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine)
|
static LtsElevationManager* createInstanceUnitTest(int id, const QStringList& filePaths_rough_to_fine)
|
||||||
{
|
{
|
||||||
return BaseClass::createInstanceUnitTest(id, filePaths_rough_to_fine);
|
return BaseClass::createInstanceUnitTest(id, filePaths_rough_to_fine);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UnitTestElevation::UnitTestElevation()
|
UnitTestElevation::UnitTestElevation()
|
||||||
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTestElevation"))
|
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTestElevation"))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void UnitTestElevation::initTestCase()
|
void UnitTestElevation::initTestCase()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
QString filePath(QStringLiteral("/usr/share/arcgis/resources/elevation/Altmark_dt1.tif"));
|
QString filePath(QStringLiteral("/usr/share/arcgis/resources/elevation/Altmark_dt1.tif"));
|
||||||
|
|
||||||
s_eleMgr = MyLtsElevationManagerBootstrap::createInstanceUnitTest(s_id, {filePath});
|
s_eleMgr = MyLtsElevationManagerBootstrap::createInstanceUnitTest(s_id, {filePath});
|
||||||
@@ -56,7 +42,6 @@ void UnitTestElevation::initTestCase()
|
|||||||
const bool bIsValid = s_eleMgr->isValid();
|
const bool bIsValid = s_eleMgr->isValid();
|
||||||
std::cerr << "myBootstrapMgr->isValid() 1 = " << bIsValid << std::endl;
|
std::cerr << "myBootstrapMgr->isValid() 1 = " << bIsValid << std::endl;
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
s_eleMgr->waitForInitialization();
|
s_eleMgr->waitForInitialization();
|
||||||
const bool bIsValid = s_eleMgr->isValid();
|
const bool bIsValid = s_eleMgr->isValid();
|
||||||
@@ -66,25 +51,21 @@ void UnitTestElevation::initTestCase()
|
|||||||
|
|
||||||
void UnitTestElevation::init()
|
void UnitTestElevation::init()
|
||||||
{
|
{
|
||||||
QVERIFY2(s_eleMgr , "static LtsElevationManager does not exist");
|
QVERIFY2(s_eleMgr, "static LtsElevationManager does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UnitTestElevation::test_elevation_data()
|
void UnitTestElevation::test_elevation_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QPointF>("lonLat");
|
QTest::addColumn<QPointF>("lonLat");
|
||||||
QTest::addColumn<double>("elevationRef");
|
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 3 ")
|
||||||
QTest::newRow("elevation 2 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 72000 13000")).geographic() << 80.0;
|
<< 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()
|
void UnitTestElevation::test_elevation()
|
||||||
@@ -99,8 +80,8 @@ void UnitTestElevation::test_elevation()
|
|||||||
|
|
||||||
void UnitTestElevation::test_elevation_isCovered()
|
void UnitTestElevation::test_elevation_isCovered()
|
||||||
{
|
{
|
||||||
const QPointF &lonLat1 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 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 QPointF& lonLat2 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 60000 10000")).geographic();
|
||||||
|
|
||||||
const double defaultElevationValue = -123;
|
const double defaultElevationValue = -123;
|
||||||
{
|
{
|
||||||
@@ -117,7 +98,7 @@ void UnitTestElevation::test_elevation_isCovered()
|
|||||||
|
|
||||||
void UnitTestElevation::test_elevation_defaultValue()
|
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());
|
double elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y());
|
||||||
QVERIFY2(qFuzzyCompare(elevation, std::numeric_limits<double>::min()), " error on defaultValue");
|
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()
|
void UnitTestElevation::test_lineOfSightCalculation_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QPointF>("startGeo2D");
|
QTest::addColumn<QPointF>("startGeo2D");
|
||||||
@@ -146,35 +124,35 @@ void UnitTestElevation::test_lineOfSightCalculation_data()
|
|||||||
QTest::addColumn<double>("endObjH");
|
QTest::addColumn<double>("endObjH");
|
||||||
QTest::addColumn<LtsElevation::LineOfSight>("expectedResult");
|
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
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 60000")).geographic() << 1.0
|
||||||
<< LtsElevation::LineOfSight::LOS_ERROR;
|
<< LtsElevation::LineOfSight::LOS_ERROR;
|
||||||
|
|
||||||
|
QTest::newRow("losDataset 2 ")
|
||||||
QTest::newRow("losDataset 2 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0
|
||||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0
|
||||||
<< LtsElevation::LineOfSight::LOS_INVISIBLE;
|
<< LtsElevation::LineOfSight::LOS_INVISIBLE;
|
||||||
|
|
||||||
|
QTest::newRow("losDataset 3 ")
|
||||||
QTest::newRow("losDataset 3 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 20.0
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 20.0
|
||||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 20.0
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 20.0
|
||||||
<< LtsElevation::LineOfSight::LOS_VISIBLE;
|
<< LtsElevation::LineOfSight::LOS_VISIBLE;
|
||||||
|
|
||||||
|
QTest::newRow("losDataset 4 ")
|
||||||
QTest::newRow("losDataset 4 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << -1.0
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << -1.0
|
||||||
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0
|
||||||
<< LtsElevation::LineOfSight::LOS_ERROR;
|
<< 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
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << -1.0
|
||||||
<< LtsElevation::LineOfSight::LOS_ERROR;
|
<< 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
|
<< LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 0.0
|
||||||
<< LtsElevation::LineOfSight::LOS_INVISIBLE;
|
<< LtsElevation::LineOfSight::LOS_INVISIBLE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitTestElevation::test_lineOfSightCalculation()
|
void UnitTestElevation::test_lineOfSightCalculation()
|
||||||
{
|
{
|
||||||
QFETCH(QPointF, startGeo2D);
|
QFETCH(QPointF, startGeo2D);
|
||||||
@@ -195,21 +173,14 @@ void UnitTestElevation::test_lineOfSightCalculation()
|
|||||||
NOTICE_LOG(m_logger) << "los = " << los;
|
NOTICE_LOG(m_logger) << "los = " << los;
|
||||||
|
|
||||||
{
|
{
|
||||||
LtsElevation::LineOfSight los2 = s_eleMgr->lineOfSightCalculation(startGeo2D, startObjH,
|
LtsElevation::LineOfSight los2 = s_eleMgr->lineOfSightCalculation(startGeo2D, startObjH, endGeo2D, endObjH);
|
||||||
endGeo2D, endObjH);
|
|
||||||
QVERIFY2(los == los2, " got different lineOfSightCalculation result");
|
QVERIFY2(los == los2, " got different lineOfSightCalculation result");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QVERIFY2(los == expectedResult, " got lineOfSightCalculation result");
|
QVERIFY2(los == expectedResult, " got lineOfSightCalculation result");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
NGLCoreApplication app(argc, argv);
|
NGLCoreApplication app(argc, argv);
|
||||||
app.createLogger("UnitTestElevation", "log4cxxElevationUnitTest.props");
|
app.createLogger("UnitTestElevation", "log4cxxElevationUnitTest.props");
|
||||||
@@ -218,7 +189,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
int ret = QTest::qExec(&tc, argc, argv);
|
int ret = QTest::qExec(&tc, argc, argv);
|
||||||
|
|
||||||
|
|
||||||
if (s_eleMgr)
|
if (s_eleMgr)
|
||||||
{
|
{
|
||||||
s_eleMgr->cleanupAll();
|
s_eleMgr->cleanupAll();
|
||||||
@@ -226,5 +196,3 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Executable → Regular
+8
-31
@@ -1,45 +1,29 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <LtsElevation/lts_elevation_manager.h>
|
|
||||||
|
|
||||||
#include <ElevationMap/elevation_map_manager.h>
|
#include <ElevationMap/elevation_map_manager.h>
|
||||||
|
#include <LtsElevation/lts_elevation_manager.h>
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QtTest/QTest>
|
|
||||||
#include <NGLLogger/INGLLogger.h>
|
#include <NGLLogger/INGLLogger.h>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtTest/QTest>
|
||||||
|
|
||||||
using LOGGER_T = NGL::INGLLogger&;
|
using LOGGER_T = NGL::INGLLogger&;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UnitTestElevation : public QObject
|
class UnitTestElevation : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnitTestElevation();
|
UnitTestElevation();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
private Q_SLOTS:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_elevation_data();
|
void test_elevation_data();
|
||||||
void test_elevation();
|
void test_elevation();
|
||||||
|
|
||||||
@@ -49,13 +33,6 @@ private Q_SLOTS:
|
|||||||
void test_lineOfSightCalculation_data();
|
void test_lineOfSightCalculation_data();
|
||||||
void test_lineOfSightCalculation();
|
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 "logger.h"
|
||||||
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
@@ -8,7 +7,7 @@
|
|||||||
namespace LtsElevation
|
namespace LtsElevation
|
||||||
{
|
{
|
||||||
|
|
||||||
LOGGER_T getLogger(const char *name)
|
LOGGER_T getLogger(const char* name)
|
||||||
{
|
{
|
||||||
static const char ns[] = "Lts.Elevation.";
|
static const char ns[] = "Lts.Elevation.";
|
||||||
std::string loggerName;
|
std::string loggerName;
|
||||||
@@ -19,14 +18,13 @@ LOGGER_T getLogger(const char *name)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
||||||
getNGLLogger(loggerName);
|
|
||||||
}
|
}
|
||||||
catch (const std::exception &ex)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsElevation
|
||||||
Executable → Regular
+5
-6
@@ -1,18 +1,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <NGLLogger/INGLLogger.h>
|
#include <NGLLogger/INGLLogger.h>
|
||||||
|
|
||||||
namespace LtsElevation
|
namespace LtsElevation
|
||||||
{
|
{
|
||||||
typedef NGL::INGLLogger &LOGGER_T;
|
typedef NGL::INGLLogger& LOGGER_T;
|
||||||
|
|
||||||
LOGGER_T getLogger(const char *name);
|
LOGGER_T getLogger(const char* name);
|
||||||
inline LOGGER_T getLogger(const QString &loggerName)
|
|
||||||
|
inline LOGGER_T getLogger(const QString& loggerName)
|
||||||
{
|
{
|
||||||
return getLogger(loggerName.toUtf8().constData());
|
return getLogger(loggerName.toUtf8().constData());
|
||||||
}
|
}
|
||||||
}
|
} // namespace LtsElevation
|
||||||
Executable → Regular
+79
-117
@@ -1,37 +1,37 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_elevation_manager.h"
|
#include "lts_elevation_manager.h"
|
||||||
#include <utility>
|
|
||||||
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
|
||||||
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
||||||
|
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
||||||
#include <Viewer/SituationMap/ElevationMap/elevation_map_manager.h>
|
|
||||||
#include <Viewer/SituationMap/Common/resource_path.h>
|
|
||||||
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QUrl>
|
|
||||||
#include <QHash>
|
#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_UNDEFINED == (int)LtsElevation::LineOfSight::LOS_UNDEFINED, "LineOfSight mismatch");
|
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_ERROR ==
|
||||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_ERROR == (int)LtsElevation::LineOfSight::LOS_ERROR, "LineOfSight mismatch");
|
(int)LtsElevation::LineOfSight::LOS_ERROR,
|
||||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_VISIBLE == (int)LtsElevation::LineOfSight::LOS_VISIBLE, "LineOfSight mismatch");
|
"LineOfSight mismatch");
|
||||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_INVISIBLE == (int)LtsElevation::LineOfSight::LOS_INVISIBLE, "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
|
namespace LtsElevation
|
||||||
{
|
{
|
||||||
class LtsElevationManager;
|
class LtsElevationManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using LtsElevatioMgrMapTrainingAreaId = QMap<int, LTS_ELEVATION_MANAGER_TYPE>;
|
using LtsElevatioMgrMapTrainingAreaId = QMap<int, LTS_ELEVATION_MANAGER_TYPE>;
|
||||||
|
|
||||||
|
static LtsElevatioMgrMapTrainingAreaId& ltsElevatioMgrMapTrainingAreaId()
|
||||||
static LtsElevatioMgrMapTrainingAreaId <sElevatioMgrMapTrainingAreaId()
|
|
||||||
{
|
{
|
||||||
static LtsElevatioMgrMapTrainingAreaId s_ltsElevatioMgrMapTrainingAreaId;
|
static LtsElevatioMgrMapTrainingAreaId s_ltsElevatioMgrMapTrainingAreaId;
|
||||||
return s_ltsElevatioMgrMapTrainingAreaId;
|
return s_ltsElevatioMgrMapTrainingAreaId;
|
||||||
@@ -43,7 +43,7 @@ static void cleanupLtsElevatioMgrMapTrainingAreaId()
|
|||||||
ltsElevatioMgrMapTrainingAreaId().clear();
|
ltsElevatioMgrMapTrainingAreaId().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
LtsElevatioMgrMapTrainingAreaId &getLtsElevationMgrMapTrainingAreaId()
|
LtsElevatioMgrMapTrainingAreaId& getLtsElevationMgrMapTrainingAreaId()
|
||||||
{
|
{
|
||||||
if (ltsElevatioMgrMapTrainingAreaId().isEmpty())
|
if (ltsElevatioMgrMapTrainingAreaId().isEmpty())
|
||||||
qAddPostRoutine(cleanupLtsElevatioMgrMapTrainingAreaId);
|
qAddPostRoutine(cleanupLtsElevatioMgrMapTrainingAreaId);
|
||||||
@@ -53,31 +53,24 @@ LtsElevatioMgrMapTrainingAreaId &getLtsElevationMgrMapTrainingAreaId()
|
|||||||
|
|
||||||
static long s_counter{0};
|
static long s_counter{0};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LtsElevationManager::Private
|
class LtsElevationManager::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private() = default;
|
Private() = default;
|
||||||
|
|
||||||
~Private()
|
~Private()
|
||||||
{
|
{
|
||||||
delete m_elevationManager;
|
delete m_elevationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||||
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
||||||
|
|
||||||
QStringList m_filePaths_rough_to_fine;
|
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;
|
++s_counter;
|
||||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START, s_counter=" << s_counter << " this=" << this;
|
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;
|
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END, s_counter=" << s_counter << " this=" << this;
|
||||||
}
|
}
|
||||||
|
|
||||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstance(int exerciseId,
|
LTS_ELEVATION_MANAGER_TYPE
|
||||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
LtsElevationManager::createInstance(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc,
|
||||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc)
|
||||||
{
|
{
|
||||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||||
TRACE_LOG(logger) << Q_FUNC_INFO << " START, exerciseId=" << exerciseId;
|
TRACE_LOG(logger) << Q_FUNC_INFO << " START, exerciseId=" << exerciseId;
|
||||||
@@ -107,59 +100,43 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstance(int exerciseId,
|
|||||||
|
|
||||||
int trainingAreaId = -1;
|
int trainingAreaId = -1;
|
||||||
|
|
||||||
|
static QHash<int, int> s_exIdToTaIdStore;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static QHash<int,int> s_exIdToTaIdStore;
|
|
||||||
|
|
||||||
const auto exTaIt = s_exIdToTaIdStore.find(exerciseId);
|
const auto exTaIt = s_exIdToTaIdStore.find(exerciseId);
|
||||||
if (exTaIt != s_exIdToTaIdStore.end())
|
if (exTaIt != s_exIdToTaIdStore.end())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
trainingAreaId = *exTaIt;
|
trainingAreaId = *exTaIt;
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
if (!exmDtc || !asmDtc)
|
if (!exmDtc || !asmDtc)
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for exerciseId=" << exerciseId
|
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for exerciseId=" << exerciseId << ", asmDtc=" << asmDtc
|
||||||
<< ", asmDtc=" << asmDtc
|
|
||||||
<< ", exmDtc=" << exmDtc;
|
<< ", exmDtc=" << exmDtc;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, exmDtc);
|
trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, exmDtc);
|
||||||
if (trainingAreaId <= 0)
|
if (trainingAreaId <= 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
ERROR_LOG(logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
||||||
<< ", exerciseId=" << exerciseId
|
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||||
<< ", trainingAreaId=" << trainingAreaId;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
s_exIdToTaIdStore[exerciseId] = trainingAreaId;
|
s_exIdToTaIdStore[exerciseId] = trainingAreaId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LTS_ELEVATION_MANAGER_TYPE temp = createInstanceForTrainingAreaId(trainingAreaId, asmDtc);
|
LTS_ELEVATION_MANAGER_TYPE temp = createInstanceForTrainingAreaId(trainingAreaId, asmDtc);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error on createInstanceForTrainingAreaId"
|
ERROR_LOG(logger) << Q_FUNC_INFO << " Error on createInstanceForTrainingAreaId"
|
||||||
<< ", exerciseId=" << exerciseId
|
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||||
<< ", trainingAreaId=" << trainingAreaId;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
temp->initDDS(exmDtc, asmDtc);
|
temp->initDDS(exmDtc, asmDtc);
|
||||||
|
|
||||||
TRACE_LOG(logger) << Q_FUNC_INFO << " END, exerciseId=" << exerciseId;
|
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);
|
return LtsElevationManager::createInstance(exerciseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(int trainingAreaId,
|
LTS_ELEVATION_MANAGER_TYPE
|
||||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
LtsElevationManager::createInstanceForTrainingAreaId(int trainingAreaId,
|
||||||
|
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc)
|
||||||
{
|
{
|
||||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||||
TRACE_LOG(logger) << Q_FUNC_INFO << " START, trainingAreaId=" << trainingAreaId;
|
TRACE_LOG(logger) << Q_FUNC_INFO << " START, trainingAreaId=" << trainingAreaId;
|
||||||
@@ -183,31 +161,26 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LtsElevatioMgrMapTrainingAreaId& map = getLtsElevationMgrMapTrainingAreaId();
|
||||||
LtsElevatioMgrMapTrainingAreaId &map = getLtsElevationMgrMapTrainingAreaId();
|
|
||||||
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(trainingAreaId);
|
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(trainingAreaId);
|
||||||
|
|
||||||
|
|
||||||
if (it != map.end())
|
if (it != map.end())
|
||||||
{
|
{
|
||||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
||||||
return it.value();
|
return it.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!asmDtc)
|
if (!asmDtc)
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for trainingAreaId=" << trainingAreaId
|
ERROR_LOG(logger) << Q_FUNC_INFO << " no dtcs for trainingAreaId=" << trainingAreaId << ", asmDtc=" << asmDtc;
|
||||||
<< ", asmDtc=" << asmDtc;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
||||||
|
|
||||||
|
|
||||||
temp->initDDS(nullptr, asmDtc);
|
temp->initDDS(nullptr, asmDtc);
|
||||||
|
|
||||||
const QStringList &filenames = temp->getFilenamesForTrainingArea(trainingAreaId);
|
const QStringList& filenames = temp->getFilenamesForTrainingArea(trainingAreaId);
|
||||||
if (filenames.isEmpty())
|
if (filenames.isEmpty())
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " no filenames for trainingAreaId=" << trainingAreaId;
|
ERROR_LOG(logger) << Q_FUNC_INFO << " no filenames for trainingAreaId=" << trainingAreaId;
|
||||||
@@ -215,7 +188,6 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool bInitFilenames = temp->init(filenames);
|
bool bInitFilenames = temp->init(filenames);
|
||||||
if (!bInitFilenames)
|
if (!bInitFilenames)
|
||||||
{
|
{
|
||||||
@@ -232,27 +204,22 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(
|
|||||||
return map[trainingAreaId];
|
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");
|
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||||
|
|
||||||
LtsElevatioMgrMapTrainingAreaId &map = getLtsElevationMgrMapTrainingAreaId();
|
LtsElevatioMgrMapTrainingAreaId& map = getLtsElevationMgrMapTrainingAreaId();
|
||||||
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(id);
|
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(id);
|
||||||
|
|
||||||
|
|
||||||
if (it != map.end())
|
if (it != map.end())
|
||||||
{
|
{
|
||||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
||||||
return it.value();
|
return it.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
||||||
|
|
||||||
|
|
||||||
bool bInitFilenames = temp->init(filePaths_rough_to_fine);
|
bool bInitFilenames = temp->init(filePaths_rough_to_fine);
|
||||||
if (!bInitFilenames)
|
if (!bInitFilenames)
|
||||||
{
|
{
|
||||||
@@ -267,12 +234,8 @@ LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceUnitTest(int id, c
|
|||||||
|
|
||||||
TRACE_LOG(logger) << Q_FUNC_INFO << " END, trainingAreaId=" << id;
|
TRACE_LOG(logger) << Q_FUNC_INFO << " END, trainingAreaId=" << id;
|
||||||
return map[id];
|
return map[id];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsElevationManager::cleanupAll()
|
void LtsElevationManager::cleanupAll()
|
||||||
{
|
{
|
||||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||||
@@ -281,7 +244,8 @@ void LtsElevationManager::cleanupAll()
|
|||||||
TRACE_LOG(logger) << Q_FUNC_INFO << " END";
|
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";
|
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START";
|
||||||
|
|
||||||
@@ -307,19 +271,18 @@ QStringList LtsElevationManager::getFilenamesForExercise(int exerciseId)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, d->m_exmDtc);
|
int trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, d->m_exmDtc);
|
||||||
if (trainingAreaId <= 0)
|
if (trainingAreaId <= 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
ERROR_LOG(m_logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
||||||
<< ", exerciseId=" << exerciseId
|
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||||
<< ", trainingAreaId=" << trainingAreaId;
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList filePaths_rough_to_fine = getFilenamesForTrainingArea(trainingAreaId);
|
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;
|
return filePaths_rough_to_fine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,21 +297,20 @@ QStringList LtsElevationManager::getFilenamesForTrainingArea(int trainingAreaId)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList filePaths_rough_to_fine;
|
QStringList filePaths_rough_to_fine;
|
||||||
{
|
{
|
||||||
d->m_asmDtc->waitForHistoricalDataTrainingArea(1000);
|
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)
|
if (ta.id() != trainingAreaId)
|
||||||
{
|
{
|
||||||
ERROR_LOG(m_logger) << Q_FUNC_INFO << " Error on s_asmDtc->trainingArea"
|
ERROR_LOG(m_logger) << Q_FUNC_INFO << " Error on s_asmDtc->trainingArea"
|
||||||
<< ", trainingAreaId=" << trainingAreaId;
|
<< ", trainingAreaId=" << trainingAreaId;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const std::vector<AssetManagement::MapDescription> &mdVec = ta.elevation();
|
const std::vector<AssetManagement::MapDescription>& mdVec = ta.elevation();
|
||||||
filePaths_rough_to_fine.reserve(mdVec.size());
|
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()));
|
QUrl url(QString::fromStdString(md.url()));
|
||||||
@@ -359,11 +321,12 @@ QStringList LtsElevationManager::getFilenamesForTrainingArea(int trainingAreaId)
|
|||||||
filePaths_rough_to_fine.append(filePathAbs);
|
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;
|
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;
|
delete d->m_elevationManager;
|
||||||
|
|
||||||
@@ -384,7 +347,8 @@ bool LtsElevationManager::init(const QStringList &filePaths_rough_to_fine)
|
|||||||
return true;
|
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");
|
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||||
|
|
||||||
@@ -395,12 +359,11 @@ int LtsElevationManager::exerciseIdToTrainingAreaId(int exerciseId, const std::s
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int trainingAreaId = -1;
|
int trainingAreaId = -1;
|
||||||
{
|
{
|
||||||
exmDtc->waitForHistoricalDataExercise(1000);
|
exmDtc->waitForHistoricalDataExercise(1000);
|
||||||
|
|
||||||
const ExerciseManagement::Exercise &exm = exmDtc->exercise(exerciseId);
|
const ExerciseManagement::Exercise& exm = exmDtc->exercise(exerciseId);
|
||||||
if (exm.id() != exerciseId)
|
if (exm.id() != exerciseId)
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error on m_exmDtc->exercise"
|
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)
|
if (trainingAreaId <= 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
ERROR_LOG(logger) << Q_FUNC_INFO << " Error getting trainingAreaId"
|
||||||
<< ", exerciseId=" << exerciseId
|
<< ", exerciseId=" << exerciseId << ", trainingAreaId=" << trainingAreaId;
|
||||||
<< ", trainingAreaId=" << trainingAreaId;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -434,17 +396,19 @@ bool LtsElevationManager::isValid() const
|
|||||||
return d->m_elevationManager->isValid();
|
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)
|
if (!d->m_elevationManager)
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
return d->m_elevationManager->elevation(lon_rad, lat_rad, defaultValue, bIsCovered);
|
return d->m_elevationManager->elevation(lon_rad, lat_rad, defaultValue, bIsCovered);
|
||||||
}
|
}
|
||||||
|
|
||||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D &startPointGeo_absZ,
|
LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D& startPointGeo_absZ,
|
||||||
const LtsUtils::QPoint3D &endPointGeo_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())
|
if (!isValid())
|
||||||
{
|
{
|
||||||
@@ -452,39 +416,37 @@ LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D
|
|||||||
return LineOfSight::LOS_ERROR;
|
return LineOfSight::LOS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult =
|
||||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult = d->m_elevationManager->lineOfSightCalculation(startPointGeo_absZ,endPointGeo_absZ);
|
d->m_elevationManager->lineOfSightCalculation(startPointGeo_absZ, endPointGeo_absZ);
|
||||||
|
|
||||||
|
|
||||||
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
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;
|
<< " -> LineOfSight " << result;
|
||||||
return 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"
|
TRACE_LOG(m_logger) << Q_FUNC_INFO << " START"
|
||||||
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
||||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat;
|
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat;
|
||||||
|
|
||||||
|
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult =
|
||||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult = d->m_elevationManager->lineOfSightCalculation(startPointGeo, startHat,
|
d->m_elevationManager->lineOfSightCalculation(startPointGeo, startHat, endPointGeo, endHat);
|
||||||
endPointGeo, endHat);
|
|
||||||
|
|
||||||
|
|
||||||
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
||||||
|
|
||||||
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END"
|
TRACE_LOG(m_logger) << Q_FUNC_INFO << " END"
|
||||||
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
||||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat
|
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat << " -> LineOfSight "
|
||||||
<< " -> LineOfSight " << static_cast<int>(eleMapMgrResult);
|
<< static_cast<int>(eleMapMgrResult);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString toString(const LineOfSight& value)
|
||||||
const QString toString(const LineOfSight &value)
|
|
||||||
{
|
{
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
@@ -501,10 +463,10 @@ const QString toString(const LineOfSight &value)
|
|||||||
return QStringLiteral("LineOfSightERROR");
|
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();
|
stream << toString(value).toStdString();
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsElevation
|
||||||
Executable → Regular
+31
-62
@@ -1,23 +1,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "ltselevation_export.h"
|
#include "ltselevation_export.h"
|
||||||
|
|
||||||
#include <LtsUtilsCore/qpoint3d.h>
|
#include <LtsUtilsCore/qpoint3d.h>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
namespace LtsSession
|
namespace LtsSession
|
||||||
{
|
{
|
||||||
@@ -30,7 +24,7 @@ namespace Interface
|
|||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
}
|
}
|
||||||
}
|
} // namespace ExerciseManagement
|
||||||
|
|
||||||
namespace AssetManagement
|
namespace AssetManagement
|
||||||
{
|
{
|
||||||
@@ -38,92 +32,67 @@ namespace Interface
|
|||||||
{
|
{
|
||||||
class Dtc;
|
class Dtc;
|
||||||
}
|
}
|
||||||
}
|
} // namespace AssetManagement
|
||||||
|
|
||||||
|
|
||||||
namespace LtsElevation
|
namespace LtsElevation
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class LineOfSight { LOS_UNDEFINED,
|
enum class LineOfSight { LOS_UNDEFINED, LOS_ERROR, LOS_VISIBLE, LOS_INVISIBLE };
|
||||||
LOS_ERROR,
|
|
||||||
LOS_VISIBLE,
|
|
||||||
LOS_INVISIBLE };
|
|
||||||
|
|
||||||
class LtsElevationManager;
|
class LtsElevationManager;
|
||||||
using LTS_ELEVATION_MANAGER_TYPE = QPointer<LtsElevationManager>;
|
using LTS_ELEVATION_MANAGER_TYPE = QPointer<LtsElevationManager>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LTSELEVATION_EXPORT LtsElevationManager : public QObject
|
class LTSELEVATION_EXPORT LtsElevationManager : public QObject
|
||||||
{
|
{
|
||||||
public:
|
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 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 getInstance(int exerciseId);
|
||||||
|
|
||||||
|
static LTS_ELEVATION_MANAGER_TYPE
|
||||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceForTrainingAreaId(int trainingAreaId,
|
createInstanceForTrainingAreaId(int trainingAreaId,
|
||||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc = nullptr);
|
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc = nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void cleanupAll();
|
static void cleanupAll();
|
||||||
virtual ~LtsElevationManager();
|
virtual ~LtsElevationManager();
|
||||||
|
|
||||||
|
|
||||||
bool waitForInitialization();
|
bool waitForInitialization();
|
||||||
bool isValid() const;
|
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,
|
LineOfSight lineOfSightCalculation(const LtsUtils::QPoint3D& startPointGeo_absZ,
|
||||||
const LtsUtils::QPoint3D &endPointGeo_absZ);
|
const LtsUtils::QPoint3D& endPointGeo_absZ);
|
||||||
|
|
||||||
LineOfSight lineOfSightCalculation(const QPointF &startPointGeo, double startHat,
|
LineOfSight lineOfSightCalculation(const QPointF& startPointGeo, double startHat, const QPointF& endPointGeo,
|
||||||
const QPointF &endPointGeo, double endHat);
|
double endHat);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit LtsElevationManager();
|
explicit LtsElevationManager();
|
||||||
|
|
||||||
|
void initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc,
|
||||||
|
const std::shared_ptr<AssetManagement::Interface::Dtc>& asmDtc);
|
||||||
void initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
bool init(const QStringList& filePaths_rough_to_fine);
|
||||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc);
|
static int exerciseIdToTrainingAreaId(int exerciseId,
|
||||||
bool init(const QStringList &filePaths_rough_to_fine);
|
const std::shared_ptr<ExerciseManagement::Interface::Dtc>& exmDtc);
|
||||||
static int exerciseIdToTrainingAreaId(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc);
|
|
||||||
|
|
||||||
|
|
||||||
QStringList getFilenamesForExercise(int exerciseId);
|
QStringList getFilenamesForExercise(int exerciseId);
|
||||||
QStringList getFilenamesForTrainingArea(int trainingAreaId);
|
QStringList getFilenamesForTrainingArea(int trainingAreaId);
|
||||||
|
|
||||||
|
static LTS_ELEVATION_MANAGER_TYPE createInstanceUnitTest(int id, const QStringList& filePaths_rough_to_fine);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
class Private;
|
class Private;
|
||||||
|
|
||||||
Private *d;
|
Private* d;
|
||||||
LOGGER_T m_logger;
|
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,
|
LTSELEVATION_EXPORT std::ostream& operator<<(std::ostream& stream, const LtsElevation::LineOfSight value);
|
||||||
const LtsElevation::LineOfSight value);
|
|
||||||
|
|
||||||
|
} // namespace LtsElevation
|
||||||
|
|
||||||
}
|
|
||||||
Executable → Regular
+40
-87
@@ -1,25 +1,26 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "aes_crypt.h"
|
#include "aes_crypt.h"
|
||||||
#include <QtCore/QByteArray>
|
|
||||||
#include <openssl/evp.h>
|
|
||||||
#include <openssl/err.h>
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
#include <QtCore/QByteArray>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
|
||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
struct AesCryptPrivate
|
struct AesCryptPrivate
|
||||||
{
|
{
|
||||||
AesCryptPrivate()
|
AesCryptPrivate()
|
||||||
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR))
|
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR)),
|
||||||
, logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
||||||
{
|
{
|
||||||
qsrand(time(nullptr));
|
qsrand(time(nullptr));
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||||
ERR_load_crypto_strings();
|
ERR_load_crypto_strings();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~AesCryptPrivate()
|
~AesCryptPrivate()
|
||||||
{
|
{
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||||
@@ -28,11 +29,11 @@ struct AesCryptPrivate
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString passPhrase;
|
QString passPhrase;
|
||||||
NGL::INGLLogger &logger;
|
NGL::INGLLogger& logger;
|
||||||
};
|
};
|
||||||
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
||||||
|
|
||||||
void setPassPhrase(const QString &passPhrase)
|
void setPassPhrase(const QString& passPhrase)
|
||||||
{
|
{
|
||||||
s_Private->passPhrase = passPhrase;
|
s_Private->passPhrase = passPhrase;
|
||||||
}
|
}
|
||||||
@@ -42,9 +43,7 @@ QString passPhrase()
|
|||||||
return s_Private->passPhrase;
|
return s_Private->passPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray decryptData(const QByteArray &dataToDecrypt,
|
QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw, bool* bOk)
|
||||||
const QString &pw,
|
|
||||||
bool *bOk)
|
|
||||||
{
|
{
|
||||||
if (bOk)
|
if (bOk)
|
||||||
*bOk = false;
|
*bOk = false;
|
||||||
@@ -54,72 +53,53 @@ QByteArray decryptData(const QByteArray &dataToDecrypt,
|
|||||||
int outSize2 = 0;
|
int outSize2 = 0;
|
||||||
unsigned char key[32];
|
unsigned char key[32];
|
||||||
|
|
||||||
|
|
||||||
const QByteArray baPassword = pw.toUtf8();
|
const QByteArray baPassword = pw.toUtf8();
|
||||||
const unsigned char *dataPw = reinterpret_cast<const unsigned char *>(baPassword.data());
|
const unsigned char* dataPw = reinterpret_cast<const unsigned char*>(baPassword.data());
|
||||||
int i = EVP_BytesToKey(EVP_aes_256_cbc(),
|
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
||||||
EVP_sha1(),
|
|
||||||
nullptr,
|
|
||||||
dataPw,
|
|
||||||
baPassword.size(),
|
|
||||||
5,
|
|
||||||
key,
|
|
||||||
nullptr);
|
|
||||||
if (i != 32)
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
|
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
|
||||||
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
|
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
|
||||||
|
|
||||||
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
|
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
|
||||||
|
|
||||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||||
ret = EVP_DecryptInit_ex(ctx,
|
ret = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||||
EVP_aes_256_cbc(),
|
|
||||||
nullptr,
|
|
||||||
key,
|
|
||||||
salt);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QByteArray bufDecrypted;
|
QByteArray bufDecrypted;
|
||||||
bufDecrypted.resize(bufEncrypted.size() + EVP_CIPHER_CTX_block_size(ctx));
|
bufDecrypted.resize(bufEncrypted.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(bufEncrypted.data());
|
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(bufEncrypted.data());
|
||||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufDecrypted.data());
|
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufDecrypted.data());
|
||||||
|
|
||||||
ret = EVP_DecryptUpdate(ctx,
|
ret = EVP_DecryptUpdate(ctx, dataOut, &outSize1, dataIn, bufEncrypted.size());
|
||||||
dataOut,
|
|
||||||
&outSize1,
|
|
||||||
dataIn,
|
|
||||||
bufEncrypted.size());
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = EVP_DecryptFinal_ex(ctx,
|
ret = EVP_DecryptFinal_ex(ctx, dataOut + outSize1, &outSize2);
|
||||||
dataOut + outSize1,
|
|
||||||
&outSize2);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,10 +112,7 @@ QByteArray decryptData(const QByteArray &dataToDecrypt,
|
|||||||
return bufDecrypted;
|
return bufDecrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw, bool* bOk)
|
||||||
QByteArray encryptData(const QByteArray &dataToEncrypt,
|
|
||||||
const QString &pw,
|
|
||||||
bool *bOk)
|
|
||||||
{
|
{
|
||||||
if (bOk)
|
if (bOk)
|
||||||
*bOk = false;
|
*bOk = false;
|
||||||
@@ -146,77 +123,53 @@ QByteArray encryptData(const QByteArray &dataToEncrypt,
|
|||||||
unsigned char key[32];
|
unsigned char key[32];
|
||||||
QByteArray bufEncrypted;
|
QByteArray bufEncrypted;
|
||||||
|
|
||||||
|
|
||||||
const QByteArray baPassword = pw.toUtf8();
|
const QByteArray baPassword = pw.toUtf8();
|
||||||
const unsigned char *dataPw = reinterpret_cast<const unsigned char *>(baPassword.data());
|
const unsigned char* dataPw = reinterpret_cast<const unsigned char*>(baPassword.data());
|
||||||
int i = EVP_BytesToKey(EVP_aes_256_cbc(),
|
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
||||||
EVP_sha1(),
|
|
||||||
nullptr,
|
|
||||||
dataPw,
|
|
||||||
baPassword.size(),
|
|
||||||
5,
|
|
||||||
key,
|
|
||||||
nullptr);
|
|
||||||
if (i != 32)
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
|
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
|
||||||
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
|
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
|
||||||
baSalt[i] = qrand();
|
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();
|
||||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
ret = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||||
ret = EVP_EncryptInit_ex(ctx,
|
|
||||||
EVP_aes_256_cbc(),
|
|
||||||
nullptr,
|
|
||||||
key,
|
|
||||||
salt);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char*>(salt), EVP_MAX_IV_LENGTH);
|
||||||
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char *>(salt), EVP_MAX_IV_LENGTH);
|
bufEncrypted.resize(bufEncrypted.size() + dataToEncrypt.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||||
bufEncrypted.resize(bufEncrypted.size() +
|
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(dataToEncrypt.data());
|
||||||
dataToEncrypt.size() +
|
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufEncrypted.data());
|
||||||
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();
|
dataOut += baSalt.size();
|
||||||
ret = EVP_EncryptUpdate(ctx,
|
ret = EVP_EncryptUpdate(ctx, dataOut, &outSize1, dataIn, dataToEncrypt.size());
|
||||||
dataOut,
|
|
||||||
&outSize1,
|
|
||||||
dataIn,
|
|
||||||
dataToEncrypt.size());
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = EVP_EncryptFinal_ex(ctx, dataOut + outSize1, &outSize2);
|
||||||
ret = EVP_EncryptFinal_ex(ctx,
|
|
||||||
dataOut + outSize1,
|
|
||||||
&outSize2);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
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();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,4 +182,4 @@ QByteArray encryptData(const QByteArray &dataToEncrypt,
|
|||||||
return bufEncrypted;
|
return bufEncrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsLicence
|
||||||
Executable → Regular
+8
-10
@@ -1,22 +1,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QtCore/QString>
|
|
||||||
#include "ltslicence_export.h"
|
#include "ltslicence_export.h"
|
||||||
|
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
|
|
||||||
LTSLICENCE_EXPORT void setPassPhrase(const QString &passPhrase);
|
LTSLICENCE_EXPORT void setPassPhrase(const QString& passPhrase);
|
||||||
LTSLICENCE_EXPORT QString passPhrase();
|
LTSLICENCE_EXPORT QString passPhrase();
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QByteArray decryptData(const QByteArray &dataToDecrypt,
|
LTSLICENCE_EXPORT QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw = passPhrase(),
|
||||||
const QString &pw = passPhrase(),
|
bool* bOk = nullptr);
|
||||||
bool *bOk = nullptr);
|
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QByteArray encryptData(const QByteArray &dataToEncrypt,
|
LTSLICENCE_EXPORT QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw = passPhrase(),
|
||||||
const QString &pw = passPhrase(),
|
bool* bOk = nullptr);
|
||||||
bool *bOk = nullptr);
|
} // namespace LtsLicence
|
||||||
}
|
|
||||||
Executable → Regular
+6
-7
@@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "aes_crypt_test.h"
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
#include <QtTest/QTest>
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
||||||
#include <openssl/evp.h>
|
|
||||||
|
|
||||||
#include "aes_crypt.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)
|
QTEST_MAIN(aes_crypt_test)
|
||||||
|
|
||||||
@@ -30,7 +30,6 @@ void aes_crypt_test::truePassTest()
|
|||||||
QVERIFY2(bOk, "Error encrypting data...");
|
QVERIFY2(bOk, "Error encrypting data...");
|
||||||
QCOMPARE(dec, content);
|
QCOMPARE(dec, content);
|
||||||
|
|
||||||
|
|
||||||
const QByteArray bigContent(12345, '1');
|
const QByteArray bigContent(12345, '1');
|
||||||
const QByteArray bigEnc = LtsLicence::encryptData(bigContent, pw, &bOk);
|
const QByteArray bigEnc = LtsLicence::encryptData(bigContent, pw, &bOk);
|
||||||
QVERIFY2(bOk, "Error encrypting data...");
|
QVERIFY2(bOk, "Error encrypting data...");
|
||||||
|
|||||||
Executable → Regular
+1
-3
@@ -1,15 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
class aes_crypt_test : public QObject
|
class aes_crypt_test : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void truePassTest();
|
void truePassTest();
|
||||||
void falsePassTest();
|
void falsePassTest();
|
||||||
|
|||||||
Executable → Regular
+17
-40
@@ -1,21 +1,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "lts_licence.h"
|
#include "lts_licence.h"
|
||||||
#include <QDomDocument>
|
|
||||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||||
|
#include <QDomDocument>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
static bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec);
|
static bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec);
|
||||||
static NGL::INGLLogger &getLogger()
|
|
||||||
|
static NGL::INGLLogger& getLogger()
|
||||||
{
|
{
|
||||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
||||||
{
|
{
|
||||||
QVector<Licence> licenceVec;
|
QVector<Licence> licenceVec;
|
||||||
|
|
||||||
@@ -26,8 +26,8 @@ QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
|||||||
|
|
||||||
if (!xmlDoc.setContent(unencryptedXmlData, &errorMsg, &errorLine, &errorColumn))
|
if (!xmlDoc.setContent(unencryptedXmlData, &errorMsg, &errorLine, &errorColumn))
|
||||||
{
|
{
|
||||||
ERROR_LOG(getLogger()) << "Error reading xml data, " << "error in line " << errorLine
|
ERROR_LOG(getLogger()) << "Error reading xml data, "
|
||||||
<< ", column " << errorColumn
|
<< "error in line " << errorLine << ", column " << errorColumn
|
||||||
<< ", message: " << errorMsg;
|
<< ", message: " << errorMsg;
|
||||||
return licenceVec;
|
return licenceVec;
|
||||||
}
|
}
|
||||||
@@ -49,13 +49,12 @@ QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
|||||||
return licenceVec;
|
return licenceVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray writeUnencryptedLicences(const QVector<Licence>& licences)
|
||||||
QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
|
||||||
{
|
{
|
||||||
QDomDocument xmlDoc;
|
QDomDocument xmlDoc;
|
||||||
|
|
||||||
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(QLatin1String("xml"),
|
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(
|
||||||
QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
|
QLatin1String("xml"), QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
|
||||||
xmlDoc.appendChild(instr);
|
xmlDoc.appendChild(instr);
|
||||||
|
|
||||||
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
|
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
|
||||||
@@ -66,35 +65,29 @@ QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
|||||||
QDomElement lic = xmlDoc.createElement(QLatin1String("licence"));
|
QDomElement lic = xmlDoc.createElement(QLatin1String("licence"));
|
||||||
root.appendChild(lic);
|
root.appendChild(lic);
|
||||||
|
|
||||||
|
|
||||||
QDomElement element = xmlDoc.createElement(QLatin1String("name"));
|
QDomElement element = xmlDoc.createElement(QLatin1String("name"));
|
||||||
QDomText text = xmlDoc.createTextNode(licences[i].name);
|
QDomText text = xmlDoc.createTextNode(licences[i].name);
|
||||||
element.appendChild(text);
|
element.appendChild(text);
|
||||||
lic.appendChild(element);
|
lic.appendChild(element);
|
||||||
|
|
||||||
|
|
||||||
element = xmlDoc.createElement(QLatin1String("ignoreMaxCount"));
|
element = xmlDoc.createElement(QLatin1String("ignoreMaxCount"));
|
||||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreMaxCount));
|
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreMaxCount));
|
||||||
element.appendChild(text);
|
element.appendChild(text);
|
||||||
lic.appendChild(element);
|
lic.appendChild(element);
|
||||||
|
|
||||||
|
|
||||||
element = xmlDoc.createElement(QLatin1String("ignoreExpiration"));
|
element = xmlDoc.createElement(QLatin1String("ignoreExpiration"));
|
||||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreExpiration));
|
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreExpiration));
|
||||||
element.appendChild(text);
|
element.appendChild(text);
|
||||||
lic.appendChild(element);
|
lic.appendChild(element);
|
||||||
|
|
||||||
|
|
||||||
element = xmlDoc.createElement(QLatin1String("maxCount"));
|
element = xmlDoc.createElement(QLatin1String("maxCount"));
|
||||||
text = xmlDoc.createTextNode(QString::number(licences[i].maxCount));
|
text = xmlDoc.createTextNode(QString::number(licences[i].maxCount));
|
||||||
element.appendChild(text);
|
element.appendChild(text);
|
||||||
lic.appendChild(element);
|
lic.appendChild(element);
|
||||||
|
|
||||||
|
|
||||||
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
||||||
const QString qs = licences[i].expiration.toString(format);
|
const QString qs = licences[i].expiration.toString(format);
|
||||||
|
|
||||||
|
|
||||||
element = xmlDoc.createElement(QLatin1String("expiration"));
|
element = xmlDoc.createElement(QLatin1String("expiration"));
|
||||||
text = xmlDoc.createTextNode(qs);
|
text = xmlDoc.createTextNode(qs);
|
||||||
element.appendChild(text);
|
element.appendChild(text);
|
||||||
@@ -104,60 +97,46 @@ QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
|||||||
return xmlDoc.toByteArray();
|
return xmlDoc.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec)
|
||||||
bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec)
|
|
||||||
{
|
{
|
||||||
Licence licence;
|
Licence licence;
|
||||||
|
|
||||||
|
|
||||||
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
|
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
|
||||||
licence.name = tag.text();
|
licence.name = tag.text();
|
||||||
|
|
||||||
|
|
||||||
tag = licenceElement.firstChildElement(QLatin1String("ignoreMaxCount"));
|
tag = licenceElement.firstChildElement(QLatin1String("ignoreMaxCount"));
|
||||||
licence.ignoreMaxCount = tag.text().toInt();
|
licence.ignoreMaxCount = tag.text().toInt();
|
||||||
|
|
||||||
|
|
||||||
tag = licenceElement.firstChildElement(QLatin1String("ignoreExpiration"));
|
tag = licenceElement.firstChildElement(QLatin1String("ignoreExpiration"));
|
||||||
licence.ignoreExpiration = tag.text().toInt();
|
licence.ignoreExpiration = tag.text().toInt();
|
||||||
|
|
||||||
|
|
||||||
tag = licenceElement.firstChildElement(QLatin1String("maxCount"));
|
tag = licenceElement.firstChildElement(QLatin1String("maxCount"));
|
||||||
licence.maxCount = tag.text().toInt();
|
licence.maxCount = tag.text().toInt();
|
||||||
|
|
||||||
|
|
||||||
tag = licenceElement.firstChildElement(QLatin1String("expiration"));
|
tag = licenceElement.firstChildElement(QLatin1String("expiration"));
|
||||||
|
|
||||||
const QString qs(tag.text());
|
const QString qs(tag.text());
|
||||||
|
|
||||||
|
|
||||||
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
||||||
const QDateTime qdt = QDateTime::fromString(qs, format);
|
const QDateTime qdt = QDateTime::fromString(qs, format);
|
||||||
|
|
||||||
if (!qdt.isValid())
|
if (!qdt.isValid())
|
||||||
{
|
{
|
||||||
ERROR_LOG(getLogger()) << "Invalid expiration format! " << qs
|
ERROR_LOG(getLogger()) << "Invalid expiration format! " << qs << " used format: " << format;
|
||||||
<< " used format: " << format
|
|
||||||
;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
licence.expiration = qdt;
|
licence.expiration = qdt;
|
||||||
INFO_LOG(getLogger()) << "Read licence for:'" << licence.name << "'"
|
INFO_LOG(getLogger()) << "Read licence for:'" << licence.name << "'"
|
||||||
<< " IgnoreMaxCount: " << licence.ignoreMaxCount
|
<< " IgnoreMaxCount: " << licence.ignoreMaxCount
|
||||||
<< " IgnoreExpiration: " << licence.ignoreExpiration
|
<< " IgnoreExpiration: " << licence.ignoreExpiration << " MaxCount: " << licence.maxCount
|
||||||
<< " MaxCount: " << licence.maxCount
|
<< " Expiration: " << licence.expiration.date().toString() << " "
|
||||||
<< " Expiration: " << licence.expiration.date().toString()
|
<< licence.expiration.time().toString() << " RefCount: " << licence.licenceRefCount;
|
||||||
<< " " << licence.expiration.time().toString()
|
|
||||||
<< " RefCount: " << licence.licenceRefCount
|
|
||||||
;
|
|
||||||
|
|
||||||
licenceVec.append(licence);
|
licenceVec.append(licence);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString Licence::toString() const
|
QString Licence::toString() const
|
||||||
{
|
{
|
||||||
return QObject::tr("Name: %1, Count: %2, ExpireDate: %3, Expires: %4, UseMaxCount: %5")
|
return QObject::tr("Name: %1, Count: %2, ExpireDate: %3, Expires: %4, UseMaxCount: %5")
|
||||||
@@ -168,6 +147,4 @@ QString Licence::toString() const
|
|||||||
.arg(ignoreMaxCount);
|
.arg(ignoreMaxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace LtsLicence
|
||||||
|
|
||||||
}
|
|
||||||
Executable → Regular
+5
-9
@@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ltslicence_export.h"
|
#include "ltslicence_export.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QDateTime>
|
|
||||||
|
|
||||||
namespace LtsLicence
|
namespace LtsLicence
|
||||||
{
|
{
|
||||||
@@ -23,11 +23,7 @@ struct LTSLICENCE_EXPORT Licence
|
|||||||
QString toString() const;
|
QString toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LTSLICENCE_EXPORT QVector<Licence> readLicences(const QByteArray& unencryptedXmlData);
|
||||||
|
|
||||||
|
LTSLICENCE_EXPORT QByteArray writeUnencryptedLicences(const QVector<Licence>& licences);
|
||||||
LTSLICENCE_EXPORT QVector<Licence> readLicences(const QByteArray &unencryptedXmlData);
|
} // namespace LtsLicence
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LTSLICENCE_EXPORT QByteArray writeUnencryptedLicences(const QVector<Licence> &licences);
|
|
||||||
}
|
|
||||||
Executable → Regular
+13
-15
@@ -1,25 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "logout_info_dialog.h"
|
#include "logout_info_dialog.h"
|
||||||
|
|
||||||
#include "ui_logout_info_dialog.h"
|
#include "ui_logout_info_dialog.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
namespace LtsLogin
|
namespace LtsLogin
|
||||||
{
|
{
|
||||||
|
|
||||||
LogoutInformationDialog::LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget *parent)
|
LogoutInformationDialog::LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction,
|
||||||
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
QWidget* parent)
|
||||||
, m_ui(new Ui::LogoutInformationDialog)
|
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal), m_ui(new Ui::LogoutInformationDialog),
|
||||||
, m_timer(new QTimer(this))
|
m_timer(new QTimer(this)), m_timeOut(timeOut), m_secsLeft(timeOut)
|
||||||
, m_timeOut(timeOut)
|
|
||||||
, m_secsLeft(timeOut)
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
QString actionText;
|
QString actionText;
|
||||||
switch(shutdownAction.underlying())
|
switch (shutdownAction.underlying())
|
||||||
{
|
{
|
||||||
case AssetManagement::ShutdownAction::NoAction:
|
case AssetManagement::ShutdownAction::NoAction:
|
||||||
case AssetManagement::ShutdownAction::Logout:
|
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));
|
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::Ok), &QPushButton::clicked, this,
|
||||||
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &LogoutInformationDialog::closeClicked);
|
&LogoutInformationDialog::acceptClicked);
|
||||||
|
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this,
|
||||||
|
&LogoutInformationDialog::closeClicked);
|
||||||
connect(m_timer, &QTimer::timeout, this, &LogoutInformationDialog::onTimerTimeout);
|
connect(m_timer, &QTimer::timeout, this, &LogoutInformationDialog::onTimerTimeout);
|
||||||
|
|
||||||
m_timer->setInterval(1000);
|
m_timer->setInterval(1000);
|
||||||
@@ -47,7 +46,7 @@ LogoutInformationDialog::~LogoutInformationDialog()
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogoutInformationDialog::setText(const QString &text)
|
void LogoutInformationDialog::setText(const QString& text)
|
||||||
{
|
{
|
||||||
m_ui->lblLogoutText->setText(text);
|
m_ui->lblLogoutText->setText(text);
|
||||||
}
|
}
|
||||||
@@ -75,7 +74,6 @@ void LogoutInformationDialog::closeClicked()
|
|||||||
{
|
{
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
reject();
|
reject();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogoutInformationDialog::setCloseButtonText(int secsLeft)
|
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));
|
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;
|
m_secsLeft = m_timeOut;
|
||||||
setCloseButtonText(m_secsLeft);
|
setCloseButtonText(m_secsLeft);
|
||||||
@@ -91,4 +89,4 @@ void LogoutInformationDialog::showEvent(QShowEvent *event)
|
|||||||
LtsWidgets::LtsFramelessDialog::showEvent(event);
|
LtsWidgets::LtsFramelessDialog::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsLogin
|
||||||
Executable → Regular
+16
-16
@@ -1,15 +1,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <LtsWidgets/lts_frameless_dialog.h>
|
|
||||||
#include <AssetManagement/asm.hpp>
|
#include <AssetManagement/asm.hpp>
|
||||||
|
#include <LtsWidgets/lts_frameless_dialog.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
namespace Ui { class LogoutInformationDialog; }
|
namespace Ui
|
||||||
|
{
|
||||||
|
class LogoutInformationDialog;
|
||||||
|
}
|
||||||
|
|
||||||
namespace LtsLogin
|
namespace LtsLogin
|
||||||
{
|
{
|
||||||
@@ -18,27 +19,26 @@ class LogoutInformationDialog : public LtsWidgets::LtsFramelessDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget *parent = nullptr);
|
LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget* parent = nullptr);
|
||||||
~LogoutInformationDialog();
|
~LogoutInformationDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTimerTimeout();
|
void onTimerTimeout();
|
||||||
void acceptClicked();
|
void acceptClicked();
|
||||||
void closeClicked();
|
void closeClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setText(const QString &text);
|
void setText(const QString& text);
|
||||||
void setCloseButtonText(int secsLeft);
|
void setCloseButtonText(int secsLeft);
|
||||||
|
|
||||||
Ui::LogoutInformationDialog *m_ui;
|
Ui::LogoutInformationDialog* m_ui;
|
||||||
QTimer *m_timer;
|
QTimer* m_timer;
|
||||||
int m_timeOut;
|
int m_timeOut;
|
||||||
int m_secsLeft;
|
int m_secsLeft;
|
||||||
|
|
||||||
|
protected:
|
||||||
protected:
|
void showEvent(QShowEvent* event) override final;
|
||||||
void showEvent(QShowEvent *event) override final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace LtsLogin
|
||||||
Executable → Regular
+33
-63
@@ -1,34 +1,31 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "lts_login.h"
|
#include "lts_login.h"
|
||||||
|
|
||||||
#include "logout_info_dialog.h"
|
#include "logout_info_dialog.h"
|
||||||
|
|
||||||
#include <LtsPluginManager/lts_plugin_manager.h>
|
|
||||||
#include <LtsAppDescriptor/lts_app_descriptor.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.h>
|
||||||
#include <LtsSession/lts_session_data.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 <LtsUtilsCore/dds_vector.h>
|
||||||
#include <LtsUtilsSettings/settings.h>
|
#include <LtsUtilsSettings/settings.h>
|
||||||
|
#include <LtsWidgets/lts_wait_dialog.h>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QProcess>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
namespace LtsLogin
|
namespace LtsLogin
|
||||||
{
|
{
|
||||||
const int logoutShutdownTimeout = 2 * 60;
|
const int logoutShutdownTimeout = 2 * 60;
|
||||||
|
|
||||||
LtsLogin::LtsLogin()
|
LtsLogin::LtsLogin()
|
||||||
: m_loginApp(nullptr)
|
: m_loginApp(nullptr), m_shutdownAction(AssetManagement::ShutdownAction::NoAction), m_isInLogoutDialog(false)
|
||||||
, m_shutdownAction(AssetManagement::ShutdownAction::NoAction)
|
{
|
||||||
, m_isInLogoutDialog(false)
|
}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
LtsLogin::~LtsLogin()
|
LtsLogin::~LtsLogin()
|
||||||
{
|
{
|
||||||
@@ -36,7 +33,6 @@ LtsLogin::~LtsLogin()
|
|||||||
m_loginApp = nullptr;
|
m_loginApp = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsLogin::login()
|
void LtsLogin::login()
|
||||||
{
|
{
|
||||||
LtsAppDescriptor::PluginInfo opmDataPlugin;
|
LtsAppDescriptor::PluginInfo opmDataPlugin;
|
||||||
@@ -87,15 +83,10 @@ void LtsLogin::login()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished, this, [this]() {
|
||||||
|
disconnect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished, this, nullptr);
|
||||||
|
|
||||||
|
LtsSession::LtsSession* session = getAdminSession();
|
||||||
connect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
|
||||||
this, [this]()
|
|
||||||
{
|
|
||||||
disconnect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
|
||||||
this, nullptr);
|
|
||||||
|
|
||||||
LtsSession::LtsSession *session = getAdminSession();
|
|
||||||
|
|
||||||
if (!session)
|
if (!session)
|
||||||
{
|
{
|
||||||
@@ -107,26 +98,24 @@ void LtsLogin::login()
|
|||||||
if (session->isInitializationDone())
|
if (session->isInitializationDone())
|
||||||
QMetaObject::invokeMethod(this, &LtsLogin::slotLoginDone);
|
QMetaObject::invokeMethod(this, &LtsLogin::slotLoginDone);
|
||||||
else
|
else
|
||||||
connect(session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
connect(session, &LtsSession::LtsSession::signalDoneInitializingSession, this, &LtsLogin::slotLoginDone,
|
||||||
this, &LtsLogin::slotLoginDone, Qt::UniqueConnection);
|
Qt::UniqueConnection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsLogin::slotLoginDone()
|
void LtsLogin::slotLoginDone()
|
||||||
{
|
{
|
||||||
LtsSession::LtsSession *session = getAdminSession();
|
LtsSession::LtsSession* session = getAdminSession();
|
||||||
|
|
||||||
if (session != nullptr)
|
if (session != nullptr)
|
||||||
{
|
{
|
||||||
disconnect(session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
disconnect(session, &LtsSession::LtsSession::signalDoneInitializingSession, this, &LtsLogin::slotLoginDone);
|
||||||
this, &LtsLogin::slotLoginDone);
|
|
||||||
|
|
||||||
if (session->getDtc<AssetManagement::DataInterface>(m_asmDtc))
|
if (session->getDtc<AssetManagement::DataInterface>(m_asmDtc))
|
||||||
{
|
{
|
||||||
m_asmDtc->enableWorkstationLogout();
|
m_asmDtc->enableWorkstationLogout();
|
||||||
connect(m_asmDtc.get(), &AssetManagement::Interface::Dtc::workstationLogoutChanged,
|
connect(m_asmDtc.get(), &AssetManagement::Interface::Dtc::workstationLogoutChanged, this,
|
||||||
this, &LtsLogin::slotLogoutShutdown);
|
&LtsLogin::slotLogoutShutdown);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
qWarning() << "LtsLogin: no asm dtc, no remote logout/shutdown!";
|
qWarning() << "LtsLogin: no asm dtc, no remote logout/shutdown!";
|
||||||
@@ -141,29 +130,21 @@ void LtsLogin::slotLoginDone()
|
|||||||
emit signalLoginDone();
|
emit signalLoginDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsLogin::showLogoutInformationDialog(AssetManagement::ShutdownAction action)
|
void LtsLogin::showLogoutInformationDialog(AssetManagement::ShutdownAction action)
|
||||||
{
|
{
|
||||||
LogoutInformationDialog *lid = new LogoutInformationDialog(logoutShutdownTimeout, action, nullptr);
|
LogoutInformationDialog* lid = new LogoutInformationDialog(logoutShutdownTimeout, action, nullptr);
|
||||||
connect(lid, &LogoutInformationDialog::accepted,
|
connect(lid, &LogoutInformationDialog::accepted, this, [this, action]() {
|
||||||
this, [this, action]()
|
|
||||||
{
|
|
||||||
m_shutdownAction = action;
|
m_shutdownAction = action;
|
||||||
m_isInLogoutDialog = false;
|
m_isInLogoutDialog = false;
|
||||||
emit signalLogout();
|
emit signalLogout();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(lid, &LogoutInformationDialog::rejected,
|
connect(lid, &LogoutInformationDialog::rejected, this, [this]() { m_isInLogoutDialog = false; });
|
||||||
this, [this]()
|
|
||||||
{
|
|
||||||
m_isInLogoutDialog = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
lid->show();
|
lid->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout& data, DataModification modType)
|
||||||
void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout &data, DataModification modType)
|
|
||||||
{
|
{
|
||||||
if (m_isInLogoutDialog)
|
if (m_isInLogoutDialog)
|
||||||
return;
|
return;
|
||||||
@@ -175,7 +156,8 @@ void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout &data
|
|||||||
m_asmDtc->enableAsset();
|
m_asmDtc->enableAsset();
|
||||||
for (int id : data.ids())
|
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;
|
m_isInLogoutDialog = true;
|
||||||
showLogoutInformationDialog(data.shutdownAction());
|
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);
|
return m_loginApp->m_sessionManager->getSession(IDL::PartitionType::Global, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LtsLogin::logoff()
|
void LtsLogin::logoff()
|
||||||
{
|
{
|
||||||
if (m_loginApp == nullptr)
|
if (m_loginApp == nullptr)
|
||||||
@@ -199,9 +179,7 @@ void LtsLogin::logoff()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LtsSession::LtsSession* datSession = getAdminSession();
|
||||||
|
|
||||||
LtsSession::LtsSession *datSession = getAdminSession();
|
|
||||||
|
|
||||||
if (!datSession)
|
if (!datSession)
|
||||||
{
|
{
|
||||||
@@ -215,32 +193,27 @@ void LtsLogin::logoff()
|
|||||||
LtsSessionData::LtsSessionData::getInstance()->clear();
|
LtsSessionData::LtsSessionData::getInstance()->clear();
|
||||||
|
|
||||||
std::shared_ptr<OperatorManagement::Interface::Ftc> opmFtc;
|
std::shared_ptr<OperatorManagement::Interface::Ftc> opmFtc;
|
||||||
if (operatorId == -1 ||
|
if (operatorId == -1 || !datSession->getFtc<OperatorManagement::DataInterface>(opmFtc))
|
||||||
!datSession->getFtc<OperatorManagement::DataInterface>(opmFtc)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
LtsUtils::OperatorSettings *os = LtsUtils::OperatorSettings::getInstance();
|
LtsUtils::OperatorSettings* os = LtsUtils::OperatorSettings::getInstance();
|
||||||
|
|
||||||
const QByteArray settings = os->exportSettings();
|
const QByteArray settings = os->exportSettings();
|
||||||
|
|
||||||
|
|
||||||
const auto vec(LtsUtils::convert<std::vector<uint8_t>>(settings));
|
const auto vec(LtsUtils::convert<std::vector<uint8_t>>(settings));
|
||||||
os->clear();
|
os->clear();
|
||||||
opmFtc->operatorGetSetSettingsRequest(OperatorManagement::OperatorGetSetSettingsRequest(operatorId, vec));
|
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();
|
qCritical() << "Saving operator settings failed!" << err.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<SituationReplayManagement::ForeignDataInterface> srmIfc;
|
std::shared_ptr<SituationReplayManagement::ForeignDataInterface> srmIfc;
|
||||||
if (datSession->getForeignDataInterface<SituationReplayManagement::DataInterface>(srmIfc))
|
if (datSession->getForeignDataInterface<SituationReplayManagement::DataInterface>(srmIfc))
|
||||||
{
|
{
|
||||||
@@ -248,7 +221,7 @@ void LtsLogin::logoff()
|
|||||||
{
|
{
|
||||||
srmIfc->removeReplayPartitionsWorkstation(workstationId);
|
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();
|
qCritical() << "Removing reply partitions from this workstation failed!" << err.what();
|
||||||
}
|
}
|
||||||
@@ -257,23 +230,20 @@ void LtsLogin::logoff()
|
|||||||
{
|
{
|
||||||
srmIfc->removeReplayPartitionsOperator(operatorId);
|
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();
|
qCritical() << "Removing reply partitions from this operator failed!" << err.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
opmFtc->operatorLogoutRequest(OperatorManagement::OperatorLogoutRequest(operatorId));
|
opmFtc->operatorLogoutRequest(OperatorManagement::OperatorLogoutRequest(operatorId));
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &err)
|
catch (const std::runtime_error& err)
|
||||||
{
|
{
|
||||||
qCritical() << "Logout failed!" << err.what();
|
qCritical() << "Logout failed!" << err.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_loginApp->deleteLater();
|
m_loginApp->deleteLater();
|
||||||
@@ -309,4 +279,4 @@ void LtsLogin::logoff()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LtsLogin
|
||||||
Executable → Regular
+18
-16
@@ -1,27 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
||||||
|
|
||||||
#include <ltslogin_export.h>
|
|
||||||
#include <Plugins/OperatorManagement/opm_data_plugin_interface.h>
|
#include <Plugins/OperatorManagement/opm_data_plugin_interface.h>
|
||||||
#include <Plugins/SituationReplayManagement/srm_data_plugin_interface.h>
|
#include <Plugins/SituationReplayManagement/srm_data_plugin_interface.h>
|
||||||
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <ltslogin_export.h>
|
||||||
|
|
||||||
namespace LtsPluginManager
|
namespace LtsPluginManager
|
||||||
{
|
{
|
||||||
class LtsPluginManager;
|
class LtsPluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace LtsUtils
|
namespace LtsUtils
|
||||||
{
|
{
|
||||||
class RequestHelper;
|
class RequestHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace LtsSession
|
namespace LtsSession
|
||||||
{
|
{
|
||||||
class LtsSession;
|
class LtsSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace DeveloperTools
|
namespace DeveloperTools
|
||||||
{
|
{
|
||||||
class DevDialog;
|
class DevDialog;
|
||||||
@@ -34,36 +33,39 @@ class LTSLOGIN_EXPORT LtsLogin : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LtsLogin();
|
LtsLogin();
|
||||||
~LtsLogin();
|
~LtsLogin();
|
||||||
|
|
||||||
void login();
|
void login();
|
||||||
void logoff();
|
void logoff();
|
||||||
void setLoginPlugin(const QString &loginPluginIid) { m_loginPluginIid = loginPluginIid; }
|
|
||||||
|
|
||||||
private:
|
void setLoginPlugin(const QString& loginPluginIid)
|
||||||
|
{
|
||||||
|
m_loginPluginIid = loginPluginIid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
friend class DeveloperTools::DevDialog;
|
friend class DeveloperTools::DevDialog;
|
||||||
|
|
||||||
LtsSession::LtsSession *getAdminSession();
|
LtsSession::LtsSession* getAdminSession();
|
||||||
void showLogoutInformationDialog(AssetManagement::ShutdownAction action);
|
void showLogoutInformationDialog(AssetManagement::ShutdownAction action);
|
||||||
|
|
||||||
LtsPluginManager::LtsPluginManager *m_loginApp;
|
LtsPluginManager::LtsPluginManager* m_loginApp;
|
||||||
AssetManagement::ShutdownAction m_shutdownAction;
|
AssetManagement::ShutdownAction m_shutdownAction;
|
||||||
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
||||||
QString m_loginPluginIid;
|
QString m_loginPluginIid;
|
||||||
bool m_isInLogoutDialog;
|
bool m_isInLogoutDialog;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotLoginDone();
|
void slotLoginDone();
|
||||||
void slotLogoutShutdown(const AssetManagement::WorkstationLogout &data, DataModification modType);
|
void slotLogoutShutdown(const AssetManagement::WorkstationLogout& data, DataModification modType);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalLogout();
|
void signalLogout();
|
||||||
void signalStopBlock();
|
void signalStopBlock();
|
||||||
void signalLoginDone();
|
void signalLoginDone();
|
||||||
void signalLogoffDone();
|
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