/** * @RDE_HEADER@ * Model to handle datail data for the different event types * $Id$ * $HeadURL$ * $Author$ * * Created by Mike Wille, SLSE, 2017-09-04 */ #pragma once #include "logger.h" #include #include #include // needed for this header #include #include #include #include "attribute_value_lookup.h" namespace LtsSession { class LtsSession; } namespace LtsTimelineClassic { class Event; } namespace LtsWidgets { class LtsDateTimeEdit; } namespace Timeline { constexpr int markerTypeId = 999999; // HACK: there is no marker type class DetailData : public QObject { Q_OBJECT public: enum class RequestResult { Error = 0, Okay = 1, InvalidAttributeType, NoValueTranslationForAttribute, NoUiTypeForAttribute, InvalidAttributeTypeJson, JsonCorrupted }; struct GetDetailDataForAttributeResult { QString attributeType; // translated! "Friendly Fire" instead of the key "FriendlyFire" QString attributeValue; // also translated! "No" instead of the key "0" QString attributeTypeId; // "FriendlyFire" instead of the translated version "Friendly Fire" int attributeValueId = 0; RequestResult requestResult = RequestResult::Error; }; using GetDetailDataResultList = QVector; enum AttributeUITypes // attribute ui types { ATTRIBUTE_UI_TYPE_TIME_RANGE_WIDGET = 0, ATTRIBUTE_UI_TYPE_DEFAULT_RANGE_WIDGET, ATTRIBUTE_UI_TYPE_AREA_RANGE_WIDGET, ATTRIBUTE_UI_TYPE_COMBO_BOX, // most attributes use this 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, // ERROR VALUE //INTERPRETER_TYPE_TOINT, INTERPRETER_TYPE_RANGE, INTERPRETER_TYPE_AREA, // for filter interpreter INTERPRETER_TYPE_ID_COMPARE, // or key compare INTERPRETER_TYPE_STR_COMPARE, // or value compare [deprecated - do not use] INTERPRETER_TYPE_POSITION, // for event info windows line edits ! INTERPRETER_TYPE_TIME, // for event info windows line edits ! INTERPRETER_TYPE_DURATION, // for event info windows line edits ! 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: /** * @brief addRedirectedAttributeType just like "addAttributeType", but automatically redirects to "redirectionAttributeTypeId" (note that redirected attributes do not need to have ui types or interpreter types) * @param attributeTypeId * @param attributeText * @param redirectionAttributeTypeId */ 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 void addAttributeValue(const QString &attributeTypeId, const AttributeEnumType &attributeEnum) { //qWarning() << "<<<" << attributeTypeId << ":" << (int)attributeEnum << "=>" << toString(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__; // do not allow secondary population, this would take to much time to develop atm NGL::INGLLogger &m_logger; public: class LookupBase { public: explicit LookupBase(const QString &lookupClassName); protected: QString m_lookupClassName; NGL::INGLLogger &m_logger; }; class EventTypeLookup : public LookupBase { public: using EventTypeMap = QMap; // example: 3, 'Hit' EventTypeLookup(); void addEventType(const int key, const QString &value); int getEventType(const QString &eventText) const; QString getEventText(const int eventType) const; QStringList getEventTexts() const; // all texts bool isEventExists(const int eventType) const; private: EventTypeMap m_eventTypeMap; }; EventTypeLookup eventTypeLookup; class AttributeTypeLookup : public LookupBase { public: using AttributeTypeLookupMap = QMap; using AttributeTypeList = QList; 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 /* attributeTypeId List */>; using AttributeList = QList; 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; // get all attribute types from the event private: AttributeEventLookupMap m_attributeEventLookupMap; }; AttributeEventLookup attributeEventLookup; class AttributeParameterLookup : public LookupBase // as ui type is fixed for attribute type, it is perfectly okay to request parameters (min, max, etc.) by attribute type { public: using ParameterMap = QMap; // Parameter Type => Parameter String using AttributeParameterMap = QHash; AttributeParameterLookup(); void addParameter(const QString &attributeType, const ParameterMap ¶meterMap); // add a parameter map to the lookup 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; 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; 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); // add a VALUE (consisting of id & string) to the map coresponding to the attribute type void clear(); // clears map for updating map and sets to uninitialized AttributeValueMap getAttributeValueMap(const QString &attributeType) const; QString getValueStringFromValueId(const QString &attributeType, const int attributeValueId, const QString &defaultValue = QString()) const; private: AtributeValueLookupMap m_attributeTypeValueMap; // contains a map for each attribute type, that contain a map for their keys & values }; AttributeValueLookup attributeValueLookup; class AttributeValueLookupDtc : public LookupBase { public: AttributeValueLookupDtc() : LookupBase(QStringLiteral("AttributeValueLookupDtc")) {} ~AttributeValueLookupDtc() { qDeleteAll(m_provider); } // takes ownership on 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 m_provider; }; AttributeValueLookupDtc m_attributeValueLookupDtc; AttributeValueMap operatorsForEventType(int eventType) const; QString operatorNameFromId(int id) const; class AttributeRedirectionLookup : public LookupBase { public: using AttributeRedirectionMap = QHash; explicit AttributeRedirectionLookup(); void addRedirection(const QString &attributeType, const QString &redirectTo); QString getRedirection(const QString &attributeType) const; // returns redirection, or if no redirection for attribute type, then returns original attribute type private: AttributeRedirectionMap m_attributeRedirectionMap; }; AttributeRedirectionLookup attributeRedirectionLookup; }; } // namespace Timeline