X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdata%2Fdecodesignal.cpp;h=98275bad4b5f3fb17c84830ad916f5d3906ae533;hp=77784de07f84dcdce9431ef03fc634de56aed02e;hb=2cc024608cd20a78ad6765adfa0d50792e150c23;hpb=88a2597864920ecdbe66cf0cd4b8172bdabb2263 diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 77784de0..98275bad 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -86,6 +86,9 @@ void DecodeSignal::stack_decoder(const srd_decoder *decoder, bool restart_decode const shared_ptr dec = make_shared(decoder, stack_.size()); stack_.push_back(dec); + connect(dec.get(), SIGNAL(annotation_visibility_changed()), + this, SLOT(on_annotation_visibility_changed())); + // Include the newly created decode channels in the channel lists update_channel_list(); @@ -105,11 +108,12 @@ void DecodeSignal::remove_decoder(int index) assert(index < (int)stack_.size()); // Find the decoder in the stack - auto iter = stack_.begin(); - for (int i = 0; i < index; i++, iter++) - assert(iter != stack_.end()); + auto iter = stack_.begin() + index; + assert(iter != stack_.end()); + + shared_ptr dec = *iter; - decoder_removed(iter->get()); + decoder_removed(dec.get()); // Delete the element stack_.erase(iter); @@ -358,7 +362,7 @@ void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int in begin_decode(); } -double DecodeSignal::samplerate() const +double DecodeSignal::get_samplerate() const { double result = 0; @@ -698,7 +702,7 @@ void DecodeSignal::save_settings(QSettings &settings) const i = 0; for (const AnnotationClass* ann_class : decoder->ann_classes()) { settings.beginGroup("ann_class" + QString::number(i)); - settings.setValue("visible", ann_class->visible); + settings.setValue("visible", ann_class->visible()); settings.endGroup(); i++; } @@ -752,6 +756,9 @@ void DecodeSignal::restore_settings(QSettings &settings) if (QString::fromUtf8(dec->id) == id) { shared_ptr decoder = make_shared(dec, stack_.size()); + connect(decoder.get(), SIGNAL(annotation_visibility_changed()), + this, SLOT(on_annotation_visibility_changed())); + stack_.push_back(decoder); decoder->set_visible(settings.value("visible", true).toBool()); @@ -782,7 +789,7 @@ void DecodeSignal::restore_settings(QSettings &settings) i = 0; for (AnnotationClass* ann_class : decoder->ann_classes()) { settings.beginGroup("ann_class" + QString::number(i)); - ann_class->visible = settings.value("visible", true).toBool(); + ann_class->set_visible(settings.value("visible", true).toBool()); settings.endGroup(); i++; } @@ -815,7 +822,7 @@ void DecodeSignal::restore_settings(QSettings &settings) QString assigned_signal_name = settings.value("assigned_signal_name").toString(); for (const shared_ptr& signal : signalbases) - if (signal->name() == assigned_signal_name) + if ((signal->name() == assigned_signal_name) && (signal->type() != SignalBase::DecodeChannel)) channel->assigned_signal = signal.get(); channel->initial_pin_state = settings.value("initial_pin_state").toInt(); @@ -1456,10 +1463,39 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa // Add the annotation to the row const Annotation* ann = row_data.emplace_annotation(pdata); - // Add the annotation to the global annotation list + // We insert the annotation into the global annotation list in a way so that + // the annotation list is sorted by start sample and length. Otherwise, we'd + // have to sort the model, which is expensive deque& all_annotations = ds->segments_[ds->current_segment_id_].all_annotations; - all_annotations.emplace_back(ann); + + if (all_annotations.empty()) { + all_annotations.emplace_back(ann); + } else { + const uint64_t new_ann_len = (pdata->end_sample - pdata->start_sample); + bool ann_has_earlier_start = (pdata->start_sample < all_annotations.back()->start_sample()); + bool ann_is_longer = (new_ann_len > + (all_annotations.back()->end_sample() - all_annotations.back()->start_sample())); + + if (ann_has_earlier_start && ann_is_longer) { + bool ann_has_same_start; + auto it = all_annotations.end(); + + do { + it--; + ann_has_earlier_start = (pdata->start_sample < (*it)->start_sample()); + ann_has_same_start = (pdata->start_sample == (*it)->start_sample()); + ann_is_longer = (new_ann_len > (*it)->length()); + } while ((ann_has_earlier_start || (ann_has_same_start && ann_is_longer)) && (it != all_annotations.begin())); + + // Allow inserting at the front + if (it != all_annotations.begin()) + it++; + + all_annotations.emplace(it, ann); + } else + all_annotations.emplace_back(ann); + } // When emplace_annotation() inserts instead of appends an annotation, // the pointers in all_annotations that follow the inserted annotation and @@ -1562,5 +1598,10 @@ void DecodeSignal::on_data_received() logic_mux_cond_.notify_one(); } +void DecodeSignal::on_annotation_visibility_changed() +{ + annotation_visibility_changed(); +} + } // namespace data } // namespace pv