diff --git a/plotjuggler_app/nlohmann_parsers.h b/plotjuggler_app/nlohmann_parsers.h index 57f55fb71..dc4c34f94 100644 --- a/plotjuggler_app/nlohmann_parsers.h +++ b/plotjuggler_app/nlohmann_parsers.h @@ -10,6 +10,7 @@ #include "nlohmann/json.hpp" #include "PlotJuggler/messageparser_base.h" #include +#include using namespace PJ; @@ -110,14 +111,18 @@ class QCheckBoxClose : public QGroupBox class NlohmannParserCreator : public ParserFactoryPlugin { public: - NlohmannParserCreator() + NlohmannParserCreator(const char* encoding) { + _encoding = encoding; _checkbox_use_timestamp = new QCheckBoxClose("use field as timestamp if available"); + loadSettings(); } template MessageParserPtr createParserImpl(const std::string& topic_name, PlotDataMapRef& data) { + saveSettings(); + std::string timestamp_name = _checkbox_use_timestamp->lineedit->text().toStdString(); return std::make_shared( topic_name, data, _checkbox_use_timestamp->isChecked(), timestamp_name); @@ -125,16 +130,48 @@ class NlohmannParserCreator : public ParserFactoryPlugin virtual QWidget* optionsWidget() { + loadSettings(); + return _checkbox_use_timestamp; } + const char* encoding() const override + { + return _encoding; + } + + virtual void loadSettings() + { + QSettings settings; + QString prefix = QString("NlohmannParser.") + QString(encoding()); + bool checked = settings.value(prefix + ".timestampEnabled", false).toBool(); + QString field = settings.value(prefix + ".timestampFieldName", "").toString(); + + _checkbox_use_timestamp->setChecked(checked); + _checkbox_use_timestamp->lineedit->setText(field); + } + + virtual void saveSettings() + { + QSettings settings; + QString prefix = QString("NlohmannParser.") + QString(encoding()); + settings.setValue(prefix + ".timestampEnabled", _checkbox_use_timestamp->isChecked()); + settings.setValue(prefix + ".timestampFieldName", + _checkbox_use_timestamp->lineedit->text()); + } + protected: QCheckBoxClose* _checkbox_use_timestamp; + const char* _encoding; }; class JSON_ParserFactory : public NlohmannParserCreator { public: + JSON_ParserFactory() : NlohmannParserCreator("json") + { + } + MessageParserPtr createParser(const std::string& topic_name, const std::string& /*type_name*/, const std::string& /*schema*/, @@ -146,15 +183,15 @@ class JSON_ParserFactory : public NlohmannParserCreator { return "JSON_ParserFactory"; } - const char* encoding() const override - { - return "json"; - } }; class CBOR_ParserFactory : public NlohmannParserCreator { public: + CBOR_ParserFactory() : NlohmannParserCreator("cbor") + { + } + MessageParserPtr createParser(const std::string& topic_name, const std::string&, const std::string&, PlotDataMapRef& data) override { @@ -164,15 +201,15 @@ class CBOR_ParserFactory : public NlohmannParserCreator { return "CBOR_ParserFactory"; } - const char* encoding() const override - { - return "cbor"; - } }; class BSON_ParserFactory : public NlohmannParserCreator { public: + BSON_ParserFactory() : NlohmannParserCreator("bson") + { + } + MessageParserPtr createParser(const std::string& topic_name, const std::string&, const std::string&, PlotDataMapRef& data) override { @@ -182,15 +219,15 @@ class BSON_ParserFactory : public NlohmannParserCreator { return "BSON_ParserFactory"; } - const char* encoding() const override - { - return "bson"; - } }; class MessagePack_ParserFactory : public NlohmannParserCreator { public: + MessagePack_ParserFactory() : NlohmannParserCreator("msgpack") + { + } + MessageParserPtr createParser(const std::string& topic_name, const std::string&, const std::string&, PlotDataMapRef& data) override { @@ -200,10 +237,6 @@ class MessagePack_ParserFactory : public NlohmannParserCreator { return "MessagePack_ParserFactory"; } - const char* encoding() const override - { - return "msgpack"; - } }; #endif // NLOHMANN_PARSERS_H