]> sigrok.org Git - pulseview.git/blobdiff - pv/data/decodesignal.cpp
clang-tidy fixes
[pulseview.git] / pv / data / decodesignal.cpp
index d6eb924755b15452323c684cf2bdc285cd774a2c..f8e719992d59b2df7a1c22664e4772ad55088567 100644 (file)
 #include <pv/globalsettings.hpp>
 #include <pv/session.hpp>
 
-using std::forward_list;
 using std::lock_guard;
-using std::make_pair;
 using std::make_shared;
 using std::min;
 using std::out_of_range;
 using std::shared_ptr;
 using std::unique_lock;
-using pv::data::decode::Annotation;
 using pv::data::decode::AnnotationClass;
 using pv::data::decode::DecodeChannel;
-using pv::data::decode::Decoder;
-using pv::data::decode::Row;
 
 namespace pv {
 namespace data {
@@ -145,6 +140,8 @@ bool DecodeSignal::toggle_decoder_visibility(int index)
 
 void DecodeSignal::reset_decode(bool shutting_down)
 {
+       resume_decode();  // Make sure the decode thread isn't blocked by pausing
+
        if (stack_config_changed_ || shutting_down)
                stop_srd_session();
        else
@@ -162,8 +159,6 @@ void DecodeSignal::reset_decode(bool shutting_down)
                logic_mux_thread_.join();
        }
 
-       resume_decode();  // Make sure the decode thread isn't blocked by pausing
-
        current_segment_id_ = 0;
        segments_.clear();
 
@@ -474,17 +469,15 @@ uint64_t DecodeSignal::get_annotation_count(const Row* row, uint32_t segment_id)
        auto row_it = segment->annotation_rows.find(row);
 
        const RowData* rd;
-       if (row_it == segment->annotation_rows.end()) {
-               // FIXME Use the fallback row, but how?
-               assert(false);
+       if (row_it == segment->annotation_rows.end())
                return 0;
-       else
+       else
                rd = &(row_it->second);
 
        return rd->get_annotation_count();
 }
 
-void DecodeSignal::get_annotation_subset(vector<Annotation> &dest,
+void DecodeSignal::get_annotation_subset(deque<const Annotation*> &dest,
        const Row* row, uint32_t segment_id, uint64_t start_sample,
        uint64_t end_sample) const
 {
@@ -498,37 +491,19 @@ void DecodeSignal::get_annotation_subset(vector<Annotation> &dest,
        auto row_it = segment->annotation_rows.find(row);
 
        const RowData* rd;
-       if (row_it == segment->annotation_rows.end()) {
-               // FIXME Use the fallback row, but how?
-               assert(false);
+       if (row_it == segment->annotation_rows.end())
                return;
-       else
+       else
                rd = &(row_it->second);
 
        rd->get_annotation_subset(dest, start_sample, end_sample);
 }
 
-void DecodeSignal::get_annotation_subset(vector<Annotation> &dest,
+void DecodeSignal::get_annotation_subset(deque<const Annotation*> &dest,
        uint32_t segment_id, uint64_t start_sample, uint64_t end_sample) const
 {
-       // Use forward_lists for faster merging
-       forward_list<Annotation> *all_ann_list = new forward_list<Annotation>();
-
-       vector<const Row*> rows = get_rows();
-       for (const Row* row : rows) {
-               vector<Annotation> *ann_vector = new vector<Annotation>();
-               get_annotation_subset(*ann_vector, row, segment_id, start_sample, end_sample);
-
-               forward_list<Annotation> *ann_list =
-                       new forward_list<Annotation>(ann_vector->begin(), ann_vector->end());
-               delete ann_vector;
-
-               all_ann_list->merge(*ann_list);
-               delete ann_list;
-       }
-
-       move(all_ann_list->begin(), all_ann_list->end(), back_inserter(dest));
-       delete all_ann_list;
+       for (const Row* row : get_rows())
+               get_annotation_subset(dest, row, segment_id, start_sample, end_sample);
 }
 
 uint32_t DecodeSignal::get_binary_data_chunk_count(uint32_t segment_id,
@@ -697,6 +672,24 @@ void DecodeSignal::save_settings(QSettings &settings) const
                        i++;
                }
 
+               // Save row properties
+               i = 0;
+               for (const Row* row : decoder->get_rows()) {
+                       settings.beginGroup("row" + QString::number(i));
+                       settings.setValue("visible", row->visible());
+                       settings.endGroup();
+                       i++;
+               }
+
+               // Save class properties
+               i = 0;
+               for (const AnnotationClass* ann_class : decoder->ann_classes()) {
+                       settings.beginGroup("ann_class" + QString::number(i));
+                       settings.setValue("visible", ann_class->visible);
+                       settings.endGroup();
+                       i++;
+               }
+
                settings.endGroup();
        }
 
@@ -762,6 +755,25 @@ void DecodeSignal::restore_settings(QSettings &settings)
 
                                // Include the newly created decode channels in the channel lists
                                update_channel_list();
+
+                               // Restore row properties
+                               int i = 0;
+                               for (Row* row : decoder->get_rows()) {
+                                       settings.beginGroup("row" + QString::number(i));
+                                       row->set_visible(settings.value("visible", true).toBool());
+                                       settings.endGroup();
+                                       i++;
+                               }
+
+                               // Restore class properties
+                               i = 0;
+                               for (AnnotationClass* ann_class : decoder->ann_classes()) {
+                                       settings.beginGroup("ann_class" + QString::number(i));
+                                       ann_class->visible = settings.value("visible", true).toBool();
+                                       settings.endGroup();
+                                       i++;
+                               }
+
                                break;
                        }
                }
@@ -773,7 +785,7 @@ void DecodeSignal::restore_settings(QSettings &settings)
        // Restore channel mapping
        unsigned int channels = settings.value("channels").toInt();
 
-       const unordered_set< shared_ptr<data::SignalBase> > signalbases =
+       const vector< shared_ptr<data::SignalBase> > signalbases =
                session_.signalbases();
 
        for (unsigned int channel_id = 0; channel_id < channels; channel_id++) {
@@ -1370,7 +1382,7 @@ void DecodeSignal::create_decode_segment()
        segments_.emplace_back(DecodeSegment());
 
        // Add annotation classes
-       for (const shared_ptr<Decoder> dec : stack_)
+       for (const shared_ptr<Decoder>& dec : stack_)
                for (Row* row : dec->get_rows())
                        segments_.back().annotation_rows.emplace(row, RowData(row));