From: Soeren Apel Date: Thu, 30 Jan 2020 19:39:20 +0000 (+0100) Subject: DecodeTrace: Add "%c" to the format string X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=761f8302350c52f2cf357f49e1084e7101c70497;p=pulseview.git DecodeTrace: Add "%c" to the format string --- diff --git a/pv/data/decode/annotation.cpp b/pv/data/decode/annotation.cpp index e32dcc9f..8ac8d5f9 100644 --- a/pv/data/decode/annotation.cpp +++ b/pv/data/decode/annotation.cpp @@ -25,6 +25,7 @@ extern "C" { #include #include +#include using std::vector; @@ -104,6 +105,14 @@ Annotation::Class Annotation::ann_class_id() const return ann_class_id_; } +const QString Annotation::ann_class_name() const +{ + const AnnotationClass* ann_class = + row_->decoder()->get_ann_class_by_id(ann_class_id_); + + return QString(ann_class->name); +} + const vector* Annotation::annotations() const { return annotations_; diff --git a/pv/data/decode/annotation.hpp b/pv/data/decode/annotation.hpp index 1bb9ad34..cfa5e5e9 100644 --- a/pv/data/decode/annotation.hpp +++ b/pv/data/decode/annotation.hpp @@ -48,7 +48,10 @@ public: uint64_t start_sample() const; uint64_t end_sample() const; + Class ann_class_id() const; + const QString ann_class_name() const; + const vector* annotations() const; const Row* row() const; diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index 0f12fec8..e6fe82d2 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -264,6 +264,14 @@ AnnotationClass* Decoder::get_ann_class_by_id(size_t id) return &(ann_classes_[id]); } +const AnnotationClass* Decoder::get_ann_class_by_id(size_t id) const +{ + if (id >= ann_classes_.size()) + return nullptr; + + return &(ann_classes_[id]); +} + uint32_t Decoder::get_binary_class_count() const { return bin_classes_.size(); diff --git a/pv/data/decode/decoder.hpp b/pv/data/decode/decoder.hpp index 545992f8..eb9a44bf 100644 --- a/pv/data/decode/decoder.hpp +++ b/pv/data/decode/decoder.hpp @@ -113,6 +113,7 @@ public: vector ann_classes() const; vector ann_classes(); AnnotationClass* get_ann_class_by_id(size_t id); + const AnnotationClass* get_ann_class_by_id(size_t id) const; uint32_t get_binary_class_count() const; const DecodeBinaryClassInfo* get_binary_class(uint32_t id) const; diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 1abbd85c..b648b4b3 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -415,10 +415,10 @@ QWidget *Settings::get_decoder_settings_form(QWidget *parent) 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; %r: row name; %q: use quotation marks")); + QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %r: row name; %c: class name")); description_1->setAlignment(Qt::AlignRight); decoder_layout->addRow(description_1); - QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts")); + QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts; %q: use quotation marks")); description_2->setAlignment(Qt::AlignRight); decoder_layout->addRow(description_2); diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index a91f5e03..3afb45ac 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -1191,30 +1191,54 @@ void DecodeTrace::export_annotations(deque& annotations) cons const QString quote = format.contains("%q") ? "\"" : ""; format = format.remove("%q"); + const bool has_sample_range = format.contains("%s"); + const bool has_row_name = format.contains("%r"); + const bool has_dec_name = format.contains("%d"); + const bool has_class_name = format.contains("%c"); + const bool has_first_ann_text = format.contains("%1"); + const bool has_all_ann_text = format.contains("%a"); + QFile file(file_name); if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { QTextStream out_stream(&file); for (const Annotation* ann : annotations) { - const QString sample_range = QString("%1-%2") \ - .arg(QString::number(ann->start_sample()), QString::number(ann->end_sample())); + QString out_text = format; - const QString row_name = quote + ann->row()->description() + quote; + if (has_sample_range) { + const QString sample_range = QString("%1-%2") \ + .arg(QString::number(ann->start_sample()), QString::number(ann->end_sample())); + out_text = out_text.replace("%s", sample_range); + } - QString all_ann_text; - for (const QString &s : *(ann->annotations())) - all_ann_text = all_ann_text + quote + s + quote + ","; - all_ann_text.chop(1); + if (has_dec_name) + out_text = out_text.replace("%d", + quote + QString::fromUtf8(ann->row()->decoder()->name()) + quote); - const QString first_ann_text = quote + ann->annotations()->front() + quote; + if (has_row_name) { + const QString row_name = quote + ann->row()->description() + quote; + out_text = out_text.replace("%r", row_name); + } + + if (has_class_name) { + const QString class_name = quote + ann->ann_class_name() + quote; + out_text = out_text.replace("%c", class_name); + } + + if (has_first_ann_text) { + const QString first_ann_text = quote + ann->annotations()->front() + quote; + out_text = out_text.replace("%1", first_ann_text); + } + + if (has_all_ann_text) { + QString all_ann_text; + for (const QString &s : *(ann->annotations())) + all_ann_text = all_ann_text + quote + s + quote + ","; + all_ann_text.chop(1); + + out_text = out_text.replace("%a", all_ann_text); + } - QString out_text = format; - out_text = out_text.replace("%s", sample_range); - out_text = out_text.replace("%d", - quote + QString::fromUtf8(ann->row()->decoder()->name()) + quote); - out_text = out_text.replace("%r", row_name); - out_text = out_text.replace("%1", first_ann_text); - out_text = out_text.replace("%a", all_ann_text); out_stream << out_text << '\n'; } diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 40ecc195..6159cdd9 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -1909,6 +1909,8 @@ void View::on_segment_changed(int segment) void View::on_settingViewTriggerIsZeroTime_changed(const QVariant new_value) { + (void)new_value; + if (!custom_zero_offset_set_) reset_zero_position(); }