330 lines
9.5 KiB
C++
Executable File
330 lines
9.5 KiB
C++
Executable File
|
|
|
|
#pragma once
|
|
|
|
#include "logger.h"
|
|
|
|
#include <LtsUtils/LtsUtilsCore/data_modification_enum.h>
|
|
#include <LtsSession/lts_session.h>
|
|
|
|
#include <ProjectDataManagement/pdm_enums.hpp>
|
|
|
|
#include <QtCore/QHash>
|
|
#include <QtCore/QMap>
|
|
#include <QtCore/QObject>
|
|
|
|
#include "attribute_value_lookup.h"
|
|
|
|
namespace LtsSession
|
|
{
|
|
class LtsSession;
|
|
}
|
|
namespace LtsTimelineClassic
|
|
{
|
|
class Event;
|
|
}
|
|
namespace LtsWidgets
|
|
{
|
|
class LtsDateTimeEdit;
|
|
}
|
|
|
|
|
|
namespace Timeline
|
|
{
|
|
constexpr int markerTypeId = 999999;
|
|
|
|
class DetailData : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
enum class RequestResult
|
|
{
|
|
Error = 0,
|
|
Okay = 1,
|
|
InvalidAttributeType,
|
|
NoValueTranslationForAttribute,
|
|
NoUiTypeForAttribute,
|
|
InvalidAttributeTypeJson,
|
|
JsonCorrupted
|
|
};
|
|
|
|
struct GetDetailDataForAttributeResult
|
|
{
|
|
QString attributeType;
|
|
QString attributeValue;
|
|
|
|
QString attributeTypeId;
|
|
int attributeValueId = 0;
|
|
RequestResult requestResult = RequestResult::Error;
|
|
};
|
|
|
|
using GetDetailDataResultList = QVector<GetDetailDataForAttributeResult>;
|
|
|
|
enum AttributeUITypes
|
|
{
|
|
ATTRIBUTE_UI_TYPE_TIME_RANGE_WIDGET = 0,
|
|
ATTRIBUTE_UI_TYPE_DEFAULT_RANGE_WIDGET,
|
|
ATTRIBUTE_UI_TYPE_AREA_RANGE_WIDGET,
|
|
ATTRIBUTE_UI_TYPE_COMBO_BOX,
|
|
ATTRIBUTE_UI_TYPE_CHECKBOX,
|
|
ATTRIBUTE_UI_TYPE_RAD_RANGE_WIDGET
|
|
};
|
|
|
|
enum UIParameterType
|
|
{
|
|
UI_PARAM_TYPE_N1,
|
|
UI_PARAM_TYPE_N2,
|
|
UI_PARAM_TYPE_O1,
|
|
UI_PARAM_TYPE_O2,
|
|
UI_PARAM_TYPE_RAD,
|
|
|
|
UI_PARAM_TYPE_MIN,
|
|
UI_PARAM_TYPE_MAX,
|
|
UI_PARAM_TYPE_PREFIX,
|
|
UI_PARAM_TYPE_SUFFIX
|
|
};
|
|
|
|
enum InterpreterTypes
|
|
{
|
|
INTERPRETER_TYPE_NONE = 0,
|
|
|
|
INTERPRETER_TYPE_RANGE,
|
|
INTERPRETER_TYPE_AREA,
|
|
INTERPRETER_TYPE_ID_COMPARE,
|
|
INTERPRETER_TYPE_STR_COMPARE,
|
|
INTERPRETER_TYPE_POSITION,
|
|
INTERPRETER_TYPE_TIME,
|
|
INTERPRETER_TYPE_DURATION,
|
|
INTERPRETER_TYPE_RAD
|
|
};
|
|
|
|
|
|
explicit DetailData(LtsSession::LtsSession *session, QObject *parent = nullptr);
|
|
|
|
void populate();
|
|
GetDetailDataResultList getDetailData(const LtsTimelineClassic::Event *event);
|
|
GetDetailDataForAttributeResult getDetailDataForAttribute(const LtsTimelineClassic::Event *event, const QString &attributeType);
|
|
void createRetrieveCurrentTimeCallback(LtsWidgets::LtsDateTimeEdit *dateTimeEdit);
|
|
LtsSession::LtsSession *session() { return m_session; }
|
|
|
|
|
|
private:
|
|
|
|
|
|
void addRedirectedAttributeType(const QString &newAttributeTypeId, const QString &attributeText, const QString &redirectToAttributeTypeId);
|
|
void addAttributeType(const QString &attributeTypeId, const QString &attributeText, const int uiTypeId = ATTRIBUTE_UI_TYPE_COMBO_BOX, const int interpreterTypeId = INTERPRETER_TYPE_ID_COMPARE);
|
|
|
|
void addAttributeTypeWithYesAndNo(const QString &attributeTypeId, const QString &attributeText)
|
|
{
|
|
addAttributeType(attributeTypeId, attributeText, ATTRIBUTE_UI_TYPE_CHECKBOX);
|
|
attributeValueLookup.addValueToAttributeValueMap(attributeTypeId, 0, tr("No"));
|
|
attributeValueLookup.addValueToAttributeValueMap(attributeTypeId, 1, tr("Yes"));
|
|
}
|
|
|
|
template <typename AttributeEnumType>
|
|
void addAttributeValue(const QString &attributeTypeId, const AttributeEnumType &attributeEnum)
|
|
{
|
|
|
|
attributeValueLookup.addValueToAttributeValueMap(attributeTypeId, (int)attributeEnum, toString(attributeEnum));
|
|
}
|
|
|
|
void addEventType(int eventTypeId, const QString &eventTypeString);
|
|
void addEventType(const ProjectDataManagement::EventType &eventType);
|
|
|
|
GetDetailDataForAttributeResult getDetailDataForAttribute(const QString &attributeType, const QJsonValue &attributeValueJson);
|
|
|
|
LtsSession::LtsSession *m_session;
|
|
bool __already_populated__;
|
|
public:
|
|
|
|
class LookupBase
|
|
{
|
|
public:
|
|
explicit LookupBase(const QString &lookupClassName);
|
|
|
|
protected:
|
|
NGL::INGLLogger &m_logger;
|
|
QString m_lookupClassName;
|
|
};
|
|
|
|
|
|
class EventTypeLookup : public LookupBase
|
|
{
|
|
public:
|
|
using EventTypeMap = QMap<int , QString >;
|
|
|
|
EventTypeLookup();
|
|
|
|
void addEventType(const int key, const QString &value);
|
|
int getEventType(const QString &eventText) const;
|
|
QString getEventText(const int eventType) const;
|
|
QStringList getEventTexts() const;
|
|
bool isEventExists(const int eventType) const;
|
|
|
|
private:
|
|
EventTypeMap m_eventTypeMap;
|
|
};
|
|
EventTypeLookup eventTypeLookup;
|
|
|
|
|
|
class AttributeTypeLookup : public LookupBase
|
|
{
|
|
public:
|
|
using AttributeTypeLookupMap = QMap<QString , QString >;
|
|
using AttributeTypeList = QList<QString>;
|
|
using AttributeTextList = QStringList;
|
|
|
|
AttributeTypeLookup();
|
|
|
|
void addAttributeText(const QString &attributeType, const QString &attributeText);
|
|
QString getAttributeType(const QString &attributeText) const;
|
|
AttributeTypeList getAttributeTypes() const;
|
|
QString getAttributeText(const QString &attributeType, const QString &defaultReturnValue = QString()) const;
|
|
AttributeTextList getAttributeTexts() const;
|
|
|
|
private:
|
|
AttributeTypeLookupMap m_attributeTypeLookupMap;
|
|
};
|
|
AttributeTypeLookup attributeTypeLookup;
|
|
|
|
|
|
class AttributeEventLookup : public LookupBase
|
|
{
|
|
public:
|
|
using AttributeEventLookupMap = QMap<int , QList<QString> >;
|
|
using AttributeList = QList<QString>;
|
|
|
|
AttributeEventLookup();
|
|
|
|
void addAttributesToEvent(const int eventType, const AttributeList &attributeTypeList);
|
|
void addAttributesToEvent(const ProjectDataManagement::EventType &eventType, const AttributeList &attributeTypeList);
|
|
bool isAttributeInEvent(const int eventType, const QString &attributeType);
|
|
AttributeList getEventsAttributeList(const int eventType) const;
|
|
|
|
private:
|
|
AttributeEventLookupMap m_attributeEventLookupMap;
|
|
};
|
|
AttributeEventLookup attributeEventLookup;
|
|
|
|
|
|
class AttributeParameterLookup : public LookupBase
|
|
{
|
|
public:
|
|
using ParameterMap = QMap<int, QVariant>;
|
|
using AttributeParameterMap = QHash<QString, ParameterMap>;
|
|
|
|
AttributeParameterLookup();
|
|
|
|
void addParameter(const QString &attributeType, const ParameterMap ¶meterMap);
|
|
ParameterMap getParameterMap(const QString &attributeType) const;
|
|
QVariant getParameterValue(const QString &attributeType, const int parameterType) const;
|
|
|
|
private:
|
|
AttributeParameterMap m_attributeParameterMap;
|
|
};
|
|
AttributeParameterLookup attributeParameterLookup;
|
|
|
|
|
|
class AttributeUITypeLookup : public LookupBase
|
|
{
|
|
public:
|
|
using AttributeUITypeLookupMap = QHash<QString, int>;
|
|
|
|
AttributeUITypeLookup();
|
|
|
|
void addUITypeToAttribute(const QString &attributeType, const int uiType);
|
|
int getUIType(const QString &attributeType) const;
|
|
|
|
private:
|
|
AttributeUITypeLookupMap m_attributeUITypeLookupMap;
|
|
};
|
|
AttributeUITypeLookup attributeUITypeLookup;
|
|
|
|
|
|
class AttributeInterpreterLookup : public LookupBase
|
|
{
|
|
public:
|
|
using AttributeInterpreterLookupMap = QHash<QString, int>;
|
|
|
|
AttributeInterpreterLookup();
|
|
|
|
void addInterpreterTypeToAttribute(const QString &attributeType, const int interpreterType);
|
|
int getInterpreterType(const QString &attributeType) const;
|
|
|
|
private:
|
|
AttributeInterpreterLookupMap m_attributeInterpreterLookupMap;
|
|
};
|
|
AttributeInterpreterLookup attributeInterpreterLookup;
|
|
|
|
|
|
class AttributeValueLookup : public LookupBase
|
|
{
|
|
public:
|
|
AttributeValueLookup();
|
|
|
|
void addValueToAttributeValueMap(const QString &attributeType, const int valueKey, const QString &valueValue );
|
|
void removeValueFromAttributeValueMap(const QString &attributeType, const int valueKey);
|
|
void addValuesToAttributeValueMap(const QString &attributeType, const AttributeValueMap &avm);
|
|
void clear();
|
|
|
|
AttributeValueMap getAttributeValueMap(const QString &attributeType) const;
|
|
QString getValueStringFromValueId(const QString &attributeType, const int attributeValueId, const QString &defaultValue = QString()) const;
|
|
|
|
private:
|
|
AtributeValueLookupMap m_attributeTypeValueMap;
|
|
};
|
|
AttributeValueLookup attributeValueLookup;
|
|
|
|
class AttributeValueLookupDtc : public LookupBase
|
|
{
|
|
public:
|
|
AttributeValueLookupDtc() : LookupBase(QStringLiteral("AttributeValueLookupDtc")) {}
|
|
~AttributeValueLookupDtc() { qDeleteAll(m_provider); }
|
|
|
|
|
|
void addHandlerForDtc(const QString &attributeType, AttributeValueLookupProvider *provider)
|
|
{
|
|
auto &p = m_provider[attributeType];
|
|
delete p;
|
|
p = provider;
|
|
}
|
|
AttributeValueMap getAttributeValueMap(int eventType, const QString &attributeType) const
|
|
{
|
|
const auto provider = m_provider.value(attributeType);
|
|
if (!provider)
|
|
return {};
|
|
return provider->getAttributeValueMap(eventType);
|
|
}
|
|
QString getValueStringFromValueId(const QString &attributeType, int attributeValueId) const
|
|
{
|
|
const auto provider = m_provider.value(attributeType);
|
|
if (!provider)
|
|
return {};
|
|
return provider->getValueStringFromValueId(attributeValueId);
|
|
}
|
|
private:
|
|
QHash<QString, AttributeValueLookupProvider*> m_provider;
|
|
};
|
|
AttributeValueLookupDtc m_attributeValueLookupDtc;
|
|
AttributeValueMap operatorsForEventType(int eventType) const;
|
|
QString operatorNameFromId(int id) const;
|
|
|
|
class AttributeRedirectionLookup : public LookupBase
|
|
{
|
|
public:
|
|
using AttributeRedirectionMap = QHash<QString, QString>;
|
|
|
|
explicit AttributeRedirectionLookup();
|
|
|
|
void addRedirection(const QString &attributeType, const QString &redirectTo);
|
|
QString getRedirection(const QString &attributeType) const;
|
|
|
|
private:
|
|
AttributeRedirectionMap m_attributeRedirectionMap;
|
|
};
|
|
AttributeRedirectionLookup attributeRedirectionLookup;
|
|
};
|
|
|
|
}
|