2
0
forked from Ivasoft/DSView

fix: the probe apply but user click cancel at the decoder options

This commit is contained in:
dreamsourcelabTAI
2024-04-11 21:09:24 +08:00
parent eca91797af
commit d90048ed90
7 changed files with 110 additions and 37 deletions

View File

@@ -23,6 +23,7 @@
#include <libsigrokdecode.h>
#include "decoder.h"
#include <assert.h>
#include "../../log.h"
namespace pv {
@@ -85,13 +86,67 @@ bool Decoder::commit()
_decode_end = _decode_end_back;
_setted = false;
return true;
} else {
}
else {
return false;
}
}
int Decoder::first_probe_index()
{
auto it = _probes.begin();
if (it != _probes.end()){
return (*it).second;
}
return -1;
}
bool Decoder::is_binded_probe(const srd_channel *const pdch)
{
assert(pdch);
auto it = _probes.find(pdch);
return it != _probes.end();
}
int Decoder::binded_probe_index(const srd_channel *const pdch)
{
assert(pdch);
auto it = _probes.find(pdch);
if (it != _probes.end()){
return (*it).second;
}
return -1;
}
std::vector<const srd_channel*> Decoder::binded_probe_list()
{
std::vector<const srd_channel*> lst;
for (auto it = _probes.begin(); it != _probes.end(); ++it){
lst.push_back((*it).first);
}
return lst;
}
bool Decoder::have_required_probes()
{
dsv_info("decoder:%p", this);
for (GSList *l = _decoder->channels; l; l = l->next) {
const srd_channel *const pdch = (const srd_channel*)l->data;
dsv_info("base decoder:%p", (void*)pdch);
}
for (auto it = _probes.begin(); it != _probes.end(); ++it){
const srd_channel *const pdch = (const srd_channel*)(*it).first;
dsv_info("got decoder:%p", (void*)pdch);
}
for (GSList *l = _decoder->channels; l; l = l->next) {
const srd_channel *const pdch = (const srd_channel*)l->data;
assert(pdch);

View File

@@ -28,7 +28,7 @@
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <glib.h>
struct srd_decoder;
@@ -58,13 +58,21 @@ public:
}
inline void show(bool show = true){
_shown = show;
_shown = show;
}
inline std::map<const srd_channel*, int>& channels(){
return _probes;
inline bool have_probes(){
return _probes.size() > 0;
}
int first_probe_index();
bool is_binded_probe(const srd_channel *const pdch);
int binded_probe_index(const srd_channel *const pdch);
std::vector<const srd_channel*> binded_probe_list();
void set_probes(std::map<const srd_channel*, int> probes);
inline std::map<std::string, GVariant*>& options(){

View File

@@ -449,9 +449,9 @@ void DecoderStack::do_decode_work()
// This works because we are currently assuming all
// LogicSignals have the same data/snapshot
for (auto dec : _stack) {
if (!dec->channels().empty()) {
if (dec->have_probes()) {
for(auto s : _session->get_signals()) {
if(s->get_index() == (*dec->channels().begin()).second && s->signal_type() == SR_CHANNEL_LOGIC)
if(s->get_index() == dec->first_probe_index() && s->signal_type() == SR_CHANNEL_LOGIC)
{
_snapshot = ((pv::view::LogicSignal*)s)->data();
if (_snapshot != NULL)

View File

@@ -292,29 +292,31 @@ DsComboBox* DecoderOptionsDlg::create_probe_selector(
const auto &sigs = AppControl::Instance()->GetSession()->get_signals();
data::decode::Decoder *_dec = const_cast<data::decode::Decoder*>(dec);
auto probe_iter = _dec->channels().find(pdch);
data::decode::Decoder *decoder = const_cast<data::decode::Decoder*>(dec);
DsComboBox *selector = new DsComboBox(parent);
selector->addItem("-", QVariant::fromValue(-1));
if (probe_iter == _dec->channels().end())
selector->setCurrentIndex(0);
int dex = 0;
const int binded_index = decoder->binded_probe_index(pdch);
for(auto s : sigs)
{
dex++;
if (s->signal_type() == SR_CHANNEL_LOGIC && s->enabled()){
selector->addItem(s->get_name(),QVariant::fromValue(s->get_index()));
if (probe_iter != _dec->channels().end()) {
if ((*probe_iter).second == s->get_index())
selector->setCurrentIndex(dex + 1);
if (binded_index == s->get_index()){
selector->setCurrentIndex(dex);
}
}
++dex;
}
}
if (binded_index == -1){
selector->setCurrentIndex(0);
}
return selector;
}
@@ -433,8 +435,6 @@ void DecoderOptionsDlg::create_decoder_form(
const ProbeSelector s = {combo, dec, pdch};
_probe_selectors.push_back(s);
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int)));
}
// Add the optional channels
@@ -463,8 +463,6 @@ void DecoderOptionsDlg::create_decoder_form(
const ProbeSelector s = {combo, dec, pdch};
_probe_selectors.push_back(s);
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int)));
}
// Add the options
@@ -491,11 +489,6 @@ void DecoderOptionsDlg::commit_probes()
}
}
void DecoderOptionsDlg::on_probe_selected(int)
{
commit_probes();
}
void DecoderOptionsDlg::commit_decoder_probes(data::decode::Decoder *dec)
{
assert(dec);
@@ -549,5 +542,10 @@ void DecoderOptionsDlg::on_trans_pramas()
this->reject();
}
void DecoderOptionsDlg::apply_setting()
{
commit_probes();
}
}//dialogs
}//pv

View File

@@ -91,6 +91,8 @@ public:
return _is_reload_form;
}
void apply_setting();
private:
void load_options_view();
@@ -107,7 +109,6 @@ private:
void update_decode_range();
private slots:
void on_probe_selected(int);
void on_region_set(int index);
void on_accept();
void on_trans_pramas();

View File

@@ -1224,9 +1224,11 @@ bool StoreSession::gen_decoders_json(QJsonArray &array)
const bool have_probes = (d->channels || d->opt_channels) != 0;
if (have_probes) {
for(auto it = dec->channels().begin();it != dec->channels().end(); it++) {
auto binded_probes = dec->binded_probe_list();
for(auto probe : binded_probes) {
QJsonObject ch_obj;
ch_obj[(*it).first->id] = QJsonValue::fromVariant((*it).second);
int binded_index = dec->binded_probe_index(probe);
ch_obj[probe->id] = QJsonValue::fromVariant(binded_index);
ch_array.push_back(ch_obj);
}
}

View File

@@ -373,18 +373,25 @@ void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a,
draw_range(a, p, fill, outline, text_color, h,
start, end, y, fore, back);
if ((a.type()/100 == 2) && (end - start > 20)) {
for(auto dec : _decoder_stack->stack()) {
for (auto& iter : dec->channels()) {
int type = dec->get_channel_type(iter.first);
if ((a.type()/100 == 2) && (end - start > 20))
{
for(auto dec : _decoder_stack->stack())
{
auto probes = dec->binded_probe_list();
for (auto probe : probes) {
int type = dec->get_channel_type(probe);
if ((type == SRD_CHANNEL_COMMON) ||
((type%100 != a.type()%100) && (type%100 != 0)))
continue;
((type%100 != a.type()%100) && (type%100 != 0))){
continue;
}
const double mark_end = a.end_sample() / samples_per_pixel - pixels_offset;
for(auto s : _session->get_signals()) {
if((s->get_index() == iter.second) && s->signal_type() == SR_CHANNEL_LOGIC) {
int binded_index = dec->binded_probe_index(probe);
if((s->get_index() == binded_index) && s->signal_type() == SR_CHANNEL_LOGIC) {
view::LogicSignal *logicSig = (view::LogicSignal*)s;
logicSig->paint_mark(p, start, mark_end, type/100);
break;
@@ -677,6 +684,8 @@ bool DecodeTrace::create_popup(bool isnew)
if (QDialog::Accepted == dlg_ret)
{
dlg.apply_setting();
for(auto dec : _decoder_stack->stack())
{
if (dec->commit() || _decoder_stack->options_changed()) {