]> sigrok.org Git - pulseview.git/commitdiff
Make annotation export customizable
authorSoeren Apel <redacted>
Sun, 5 Aug 2018 20:15:07 +0000 (22:15 +0200)
committerUwe Hermann <redacted>
Tue, 21 Aug 2018 10:02:38 +0000 (12:02 +0200)
pv/data/decode/row.cpp
pv/data/decode/row.hpp
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/decodetrace.cpp

index 5b1b25ee8ec56043f736b2d82938d9d1ea1ef0fd..8195f3e2d00f023c0cdfb91f4b0464c8065d5eab 100644 (file)
@@ -61,6 +61,13 @@ const QString Row::title() const
        return QString();
 }
 
+const QString Row::class_name() const
+{
+       if (row_ && row_->desc)
+               return QString::fromUtf8(row_->desc);
+       return QString();
+}
+
 int Row::index() const
 {
        return index_;
index 2411d4f61afaa2344660429fc2b76348f034a269..34bb2373e844babd768335d4d8a335a227696b0c 100644 (file)
@@ -43,6 +43,7 @@ public:
        const srd_decoder_annotation_row* row() const;
 
        const QString title() const;
+       const QString class_name() const;
        int index() const;
 
        bool operator<(const Row &other) const;
index 4c0715a8b936ae67a61abf2faf08c716c0f3de2c..97f47d7685d5b2a88e0f495d9f723f3aa226b9d4 100644 (file)
@@ -268,9 +268,10 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
        return form;
 }
 
-QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
+QWidget *Settings::get_decoder_settings_form(QWidget *parent)
 {
 #ifdef ENABLE_DECODE
+       GlobalSettings settings;
        QCheckBox *cb;
 
        QWidget *form = new QWidget(parent);
@@ -287,6 +288,20 @@ QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
                SLOT(on_dec_initialStateConfigurable_changed(int)));
        decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
 
+       // Annotation export settings
+       ann_export_format_ = new QLineEdit();
+       ann_export_format_->setText(
+               settings.value(GlobalSettings::Key_Dec_ExportFormat).toString());
+       connect(ann_export_format_, SIGNAL(textChanged(const QString&)),
+               this, SLOT(on_dec_exportFormat_changed(const QString&)));
+       decoder_layout->addRow(tr("Annotation export format"), ann_export_format_);
+       QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %c: row name; %q: use quotes for ann text"));
+       description_1->setAlignment(Qt::AlignRight);
+       decoder_layout->addRow(description_1);
+       QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts"));
+       description_2->setAlignment(Qt::AlignRight);
+       decoder_layout->addRow(description_2);
+
        return form;
 #else
        (void)parent;
@@ -629,12 +644,20 @@ void Settings::on_view_defaultLogicHeight_changed(int value)
        settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
 }
 
+#ifdef ENABLE_DECODE
 void Settings::on_dec_initialStateConfigurable_changed(int state)
 {
        GlobalSettings settings;
        settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
 }
 
+void Settings::on_dec_exportFormat_changed(const QString &text)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text);
+}
+#endif
+
 void Settings::on_log_logLevel_changed(int value)
 {
        logging.set_log_level(value);
index 40142056487c8fcc509437d76d1c9629b2986589..a51bc97a93de5f8ddc5d8248d6ecda6b03866d56 100644 (file)
@@ -25,6 +25,7 @@
 #include <QListWidget>
 #include <QPlainTextEdit>
 #include <QStackedWidget>
+#include <QLineEdit>
 
 namespace pv {
 
@@ -46,7 +47,7 @@ public:
        QPlainTextEdit *create_log_view() const;
 
        QWidget *get_view_settings_form(QWidget *parent) const;
-       QWidget *get_decoder_settings_form(QWidget *parent) const;
+       QWidget *get_decoder_settings_form(QWidget *parent);
        QWidget *get_about_page(QWidget *parent) const;
        QWidget *get_logging_page(QWidget *parent) const;
 
@@ -66,7 +67,10 @@ private Q_SLOTS:
        void on_view_conversionThresholdDispMode_changed(int state);
        void on_view_defaultDivHeight_changed(int value);
        void on_view_defaultLogicHeight_changed(int value);
+#ifdef ENABLE_DECODE
        void on_dec_initialStateConfigurable_changed(int state);
+       void on_dec_exportFormat_changed(const QString &text);
+#endif
        void on_log_logLevel_changed(int value);
        void on_log_bufferSize_changed(int value);
        void on_log_saveToFile_clicked(bool checked);
@@ -77,6 +81,10 @@ private:
        PageListWidget *page_list;
        QStackedWidget *pages;
 
+#ifdef ENABLE_DECODE
+       QLineEdit *ann_export_format_;
+#endif
+
        QPlainTextEdit *log_view_;
 };
 
index cd69591a8cbae45f6808a3cf2338197ef3ceb4fb..7c40cae5b5157087c99e27cb7fb99bf2d887ab1c 100644 (file)
@@ -42,6 +42,7 @@ const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight
 const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight";
 const QString GlobalSettings::Key_View_ShowHoverMarker = "View_ShowHoverMarker";
 const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
+const QString GlobalSettings::Key_Dec_ExportFormat = "Dec_ExportFormat";
 const QString GlobalSettings::Key_Log_BufferSize = "Log_BufferSize";
 const QString GlobalSettings::Key_Log_NotifyOfStacktrace = "Log_NotifyOfStacktrace";
 
@@ -77,6 +78,9 @@ void GlobalSettings::set_defaults_where_needed()
                setValue(Key_View_DefaultLogicHeight,
                2 * QFontMetrics(QApplication::font()).height());
 
+       if (!contains(Key_Dec_ExportFormat))
+               setValue(Key_Dec_ExportFormat, "%s %d: %c: %1");
+
        // Default to 500 lines of backlog
        if (!contains(Key_Log_BufferSize))
                setValue(Key_Log_BufferSize, 500);
index 40dc1b3c5e94d0cda96e8078a7f166f45609b254..b5cd24fd5ad809a3fcb769fa503523229864726b 100644 (file)
@@ -58,6 +58,7 @@ public:
        static const QString Key_View_DefaultLogicHeight;
        static const QString Key_View_ShowHoverMarker;
        static const QString Key_Dec_InitialStateConfigurable;
+       static const QString Key_Dec_ExportFormat;
        static const QString Key_Log_BufferSize;
        static const QString Key_Log_NotifyOfStacktrace;
 
index 300fd2ecddbb5759f908f64f0a3255944a746939..865c492604fea09e0647defbb6bd5fb95f123d5c 100644 (file)
@@ -1041,8 +1041,8 @@ void DecodeTrace::on_export_row_from_here()
        if (annotations.empty())
                return;
 
-       QSettings settings;
-       const QString dir = settings.value(SettingSaveDirectory).toString();
+       GlobalSettings settings;
+       const QString dir = settings.value("MainWindow/SaveDirectory").toString();
 
        const QString file_name = QFileDialog::getSaveFileName(
                owner_->view(), tr("Export annotations"), dir, tr("Text Files (*.txt);;All Files (*)"));
@@ -1050,12 +1050,33 @@ void DecodeTrace::on_export_row_from_here()
        if (file_name.isEmpty())
                return;
 
+       const QString format = settings.value(GlobalSettings::Key_Dec_ExportFormat).toString();
+       const QString quote = format.contains("%q") ? "\"" : "";
+       const QString class_name = selected_row_->class_name();
+
        QFile file(file_name);
        if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
                QTextStream out_stream(&file);
 
-               for (Annotation &ann : annotations)
-                       out_stream << ann.annotations().front() << '\n';
+               for (Annotation &ann : annotations) {
+                       const QString sample_range = QString("%1-%2").arg(ann.start_sample()).arg(
+                               ann.end_sample());
+
+                       QString all_ann_text;
+                       for (const QString &s : ann.annotations())
+                               all_ann_text = all_ann_text + quote + s + quote + ",";
+                       all_ann_text.chop(1);
+
+                       const QString first_ann_text = quote + ann.annotations().front() + quote;
+
+                       QString out_text = format;
+                       out_text = out_text.replace("%s", sample_range);
+                       out_text = out_text.replace("%d", decode_signal_->name());
+                       out_text = out_text.replace("%c", class_name);
+                       out_text = out_text.replace("%1", first_ann_text);
+                       out_text = out_text.replace("%a", all_ann_text);
+                       out_stream << out_text << '\n';
+               }
 
                if (out_stream.status() == QTextStream::Ok)
                        return;