]> sigrok.org Git - pulseview.git/commitdiff
DecodeTrace: Add "%c" to the format string
authorSoeren Apel <redacted>
Thu, 30 Jan 2020 19:39:20 +0000 (20:39 +0100)
committerSoeren Apel <redacted>
Thu, 30 Jan 2020 19:39:20 +0000 (20:39 +0100)
pv/data/decode/annotation.cpp
pv/data/decode/annotation.hpp
pv/data/decode/decoder.cpp
pv/data/decode/decoder.hpp
pv/dialogs/settings.cpp
pv/views/trace/decodetrace.cpp
pv/views/trace/view.cpp

index e32dcc9fdc7f0b529dde1b90666b21abbe64e69e..8ac8d5f9e4970e193771cffe107c414da73f077a 100644 (file)
@@ -25,6 +25,7 @@ extern "C" {
 #include <vector>
 
 #include <pv/data/decode/annotation.hpp>
+#include <pv/data/decode/decoder.hpp>
 
 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<QString>* Annotation::annotations() const
 {
        return annotations_;
index 1bb9ad34c046a215321d6e276b3ddea6bb453106..cfa5e5e982e54746f79cac80c15062af7cd3f66b 100644 (file)
@@ -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<QString>* annotations() const;
        const Row* row() const;
 
index 0f12fec8bd753024c53c859f4a44427bfb7a5f81..e6fe82d22a092d7e663a06e813ab52a4aac908da 100644 (file)
@@ -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();
index 545992f8a24a379b2381c93739432656aa45bcc7..eb9a44bf6c1a8841cba632bc1bf3b5aa8d517c91 100644 (file)
@@ -113,6 +113,7 @@ public:
        vector<const AnnotationClass*> ann_classes() const;
        vector<AnnotationClass*> 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;
index 1abbd85c03e28d775e571bad73b99ede8da488c1..b648b4b3f942b71d1e0a5fccd4e9c6de888eba09 100644 (file)
@@ -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);
 
index a91f5e03985504a585e0f5dfe08f1c78ce47d7c2..3afb45ac931cad9d82c74c953ca22a420c08a43a 100644 (file)
@@ -1191,30 +1191,54 @@ void DecodeTrace::export_annotations(deque<const Annotation*>& 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';
                }
 
index 40ecc195cea44e9cd5d204b525c2386c8c618baa..6159cdd997053b921dedb6158860796e0195cac1 100644 (file)
@@ -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();
 }