From: Soeren Apel Date: Sun, 5 Aug 2018 20:15:07 +0000 (+0200) Subject: Make annotation export customizable X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1ed996b433f3391f54846784d76da4fe6b07500f;p=pulseview.git Make annotation export customizable --- diff --git a/pv/data/decode/row.cpp b/pv/data/decode/row.cpp index 5b1b25ee..8195f3e2 100644 --- a/pv/data/decode/row.cpp +++ b/pv/data/decode/row.cpp @@ -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_; diff --git a/pv/data/decode/row.hpp b/pv/data/decode/row.hpp index 2411d4f6..34bb2373 100644 --- a/pv/data/decode/row.hpp +++ b/pv/data/decode/row.hpp @@ -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; diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 4c0715a8..97f47d76 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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); diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index 40142056..a51bc97a 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -25,6 +25,7 @@ #include #include #include +#include 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_; }; diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index cd69591a..7c40cae5 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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); diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 40dc1b3c..b5cd24fd 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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; diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 300fd2ec..865c4926 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -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;