2
0
forked from Ivasoft/DSView

update: show the right cursor index on decoder dialog

This commit is contained in:
dreamsourcelabTAI
2022-04-25 17:55:39 +08:00
parent 956b4140be
commit c413d01c68
8 changed files with 154 additions and 62 deletions

View File

@@ -29,6 +29,7 @@
#include <QGridLayout>
#include <QFormLayout>
#include <QScrollArea>
#include <QVariant>
#include "../data/decoderstack.h"
#include "../prop/binding/decoderoptions.h"
@@ -52,8 +53,6 @@ namespace dialogs {
DecoderOptionsDlg::DecoderOptionsDlg(QWidget *parent)
:DSDialog(parent)
{
_start_index = 0;
_end_index = 0;
}
DecoderOptionsDlg::~DecoderOptionsDlg()
@@ -118,28 +117,46 @@ void DecoderOptionsDlg::load_options(view::DecodeTrace *trace)
_start_comboBox->setMinimumContentsLength(7);
_end_comboBox->setMinimumContentsLength(7);
// Add cursor list
auto view = _trace->get_view();
if (view) {
int index = 1;
for(auto i = view->get_cursorList().begin();
i != view->get_cursorList().end(); i++) {
QString curCursor = tr("Cursor ")+QString::number(index);
_start_comboBox->addItem(curCursor);
_end_comboBox->addItem(curCursor);
index++;
int dex1 = 0;
int dex2 = 0;
if (view)
{
int num = 1;
for (auto c : view->get_cursorList()){
QString curCursor = tr("Cursor") + QString::number(num);
_start_comboBox->addItem(curCursor, QVariant(c->get_key()));
_end_comboBox->addItem(curCursor, QVariant(c->get_key()));
if (c->get_key() == _cursor1)
dex1 = num;
if (c->get_key() == _cursor2)
dex2 = num;
num++;
}
}
// invalid cursor index
if (_start_index >= _start_comboBox->count())
_start_index = 0;
if (_end_index >= _end_comboBox->count())
_end_index = 0;
_start_comboBox->setCurrentIndex(_start_index);
_end_comboBox->setCurrentIndex(_end_index);
if (dex1 == 0)
_cursor1 = "";
if (dex2 == 0)
_cursor2 = "";
on_region_set(0); // set default sample range
if (dex1 > dex2 && false){
int tmp = dex1;
dex1 = dex2;
dex2 = tmp;
QString tmp_s = _cursor1;
_cursor1 = _cursor2;
_cursor1 = tmp_s;
}
_start_comboBox->setCurrentIndex(dex1);
_end_comboBox->setCurrentIndex(dex2);
update_decode_range(); // set default sample range
form->addRow(_start_comboBox, new QLabel(
tr("Decode start cursor from")));
@@ -198,9 +215,7 @@ void DecoderOptionsDlg::load_decoder_forms(QWidget *container)
if (dex > 1){
QWidget *l = new QWidget();
l->setMinimumHeight(1);
l->setMaximumHeight(1);
// l->setStyleSheet("background-color:#4b5cc4");
//container->layout()->addWidget(l);
l->setMaximumHeight(1);
}
QWidget *panel = new QWidget(container);
@@ -251,7 +266,11 @@ DsComboBox* DecoderOptionsDlg::create_probe_selector(
void DecoderOptionsDlg::on_region_set(int index)
{
(void)index;
update_decode_range();
}
void DecoderOptionsDlg::update_decode_range()
{
const uint64_t last_samples = AppControl::Instance()->GetSession()->cur_samplelimits() - 1;
const int index1 = _start_comboBox->currentIndex();
const int index2 = _end_comboBox->currentIndex();
@@ -261,13 +280,34 @@ void DecoderOptionsDlg::on_region_set(int index)
if (index1 == 0) {
decode_start = 0;
_cursor1 = "";
} else {
decode_start = view->get_cursor_samples(index1-1);
_cursor1 = _start_comboBox->itemData(index1).toString();
int cusrsor_index = view->get_cursor_index_by_key(_cursor1);
if (cusrsor_index != -1){
decode_start = view->get_cursor_samples(cusrsor_index);
}
else{
decode_start = 0;
_cursor1 = "";
}
}
if (index2 == 0) {
decode_end = last_samples;
_cursor2 = "";
} else {
decode_end = view->get_cursor_samples(index2-1);
_cursor2 = _end_comboBox->itemData(index2).toString();
int cusrsor_index = view->get_cursor_index_by_key(_cursor2);
if (cusrsor_index != -1){
decode_end = view->get_cursor_samples(cusrsor_index);
}
else{
decode_end = last_samples;
_cursor2 = "";
}
}
if (decode_start > last_samples)
@@ -280,8 +320,6 @@ void DecoderOptionsDlg::on_region_set(int index)
decode_start = decode_end;
decode_end = tmp;
}
_start_index = index1;
_end_index = index2;
for(auto &dec : _trace->decoder()->stack()) {
dec->set_decode_region(decode_start, decode_end);
@@ -390,28 +428,16 @@ void DecoderOptionsDlg::commit_decoder_probes(data::decode::Decoder *dec)
dec->set_probes(probe_map);
}
void DecoderOptionsDlg::set_sample_range(int start, int end)
{
_start_index = start;
_end_index = end;
}
void DecoderOptionsDlg::get_sample_range(int &start, int &end)
{
start = _start_index;
end = _end_index;
}
void DecoderOptionsDlg::on_accept()
{
if (_start_index > 0 && _start_index == _end_index){
if (_cursor1 != "" && _cursor1 == _cursor2){
MsgBox::Show("error", "Invalid cursor index for sample range!");
return;
}
this->accept();
}
}
}//dialogs
}//pv

View File

@@ -24,7 +24,8 @@
#include <QObject>
#include <QWidget>
#include <list>
#include <vector>
#include <QString>
class QGridLayout;
class DsComboBox;
@@ -71,8 +72,18 @@ public:
DecoderOptionsDlg(QWidget *parent);
~DecoderOptionsDlg();
void set_sample_range(int start, int end);
void get_sample_range(int &start, int &end);
inline void set_cursor_range(QString cursor1, QString cursor2)
{
_cursor1 = cursor1;
_cursor2 = cursor2;
}
inline void get_cursor_range(QString &cursor1, QString &cursor2)
{
cursor1 = _cursor1;
cursor2 = _cursor2;
}
void load_options(view::DecodeTrace *trace);
private:
@@ -85,7 +96,8 @@ private:
QWidget *parent, QFormLayout *form);
void commit_probes();
void commit_decoder_probes(data::decode::Decoder *dec);
void commit_decoder_probes(data::decode::Decoder *dec);
void update_decode_range();
private slots:
void on_probe_selected(int);
@@ -93,13 +105,13 @@ private slots:
void on_accept();
private:
std::list<prop::binding::DecoderOptions*> _bindings;
std::vector<prop::binding::DecoderOptions*> _bindings;
DsComboBox *_start_comboBox;
DsComboBox *_end_comboBox;
view::DecodeTrace *_trace;
int _start_index;
int _end_index;
std::list<ProbeSelector> _probe_selectors;
QString _cursor1;
QString _cursor2;
std::vector<ProbeSelector> _probe_selectors;
};
}//dialogs

View File

@@ -34,6 +34,8 @@
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <stdlib.h>
#include "../dsvdef.h"
@@ -55,6 +57,16 @@ Cursor::Cursor(View &view, QColor color, uint64_t index) :
TimeMarker(view, color, index),
_other(*this)
{
static bool bSpeed = false;
if (!bSpeed){
bSpeed = true;
srand(std::time(NULL));
}
// make a rand key
char buf[8+1];
make_rand_str(buf, 8);
_key = QString(buf);
}
QRect Cursor::get_label_rect(const QRect &rect, bool &visible, bool has_hoff)
@@ -168,5 +180,15 @@ void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
Ruler::format_real_time(_index, _view.session().cur_snap_samplerate())).size();
}
void Cursor::make_rand_str(char *buf, int len)
{
for (int i = 0; i < len; ++i)
{
buf[i] = 'a' + rand() % 26;
}
buf[len] = 0;
}
} // namespace view
} // namespace pv

View File

@@ -27,6 +27,7 @@
#include "timemarker.h"
#include <QSizeF>
#include <QString>
class QPainter;
@@ -81,13 +82,29 @@ public:
void paint_fix_label(QPainter &p, const QRect &rect,
unsigned int prefix, QChar label, QColor color, bool has_hoff);
public:
inline QString get_key(){
return _key;
}
inline void set_key(QString key){
_key = key;
}
inline uint64_t get_index()
{
return _index;
}
private:
void compute_text_size(QPainter &p, unsigned int prefix);
void make_rand_str(char *buf, int len);
private:
const Cursor &_other;
QSizeF _text_size;
QSizeF _text_size;
QString _key;
};
} // namespace view

View File

@@ -130,12 +130,8 @@ DecodeTrace::DecodeTrace(pv::SigSession *session,
_pub_input_layer = NULL;
_progress = 0;
_decode_start = 0;
_decode_end = INT64_MAX;
_end_index = 0;
_start_index = 0;
_decoder_stack = decoder_stack;
_session = session;
_delete_flag = false;
@@ -657,15 +653,18 @@ QRectF DecodeTrace::get_rect(DecodeSetRegions type, int y, int right)
void DecodeTrace::frame_ended()
{
const uint64_t last_samples = _session->cur_samplelimits() - 1;
if (_decode_start > last_samples) {
_decode_start = 0;
_start_index = 0;
_decode_cursor1 = "";
}
if (_end_index ==0 ||
if (_decode_cursor2 == "" ||
_decode_end > last_samples) {
_decode_end = last_samples;
_end_index = 0;
_decode_cursor2 = "";
}
for(auto &dec : _decoder_stack->stack()) {
dec->set_decode_region(_decode_start, _decode_end);
dec->commit();
@@ -683,7 +682,7 @@ bool DecodeTrace::create_popup(bool isnew)
int ret = false; //setting have changed flag
QWidget *top = AppControl::Instance()->GetTopWindow();
dialogs::DecoderOptionsDlg dlg(top);
dlg.set_sample_range(_start_index, _end_index);
dlg.set_cursor_range(_decode_cursor1, _decode_cursor2);
dlg.load_options(this);
if (QDialog::Accepted == dlg.exec())
@@ -698,7 +697,7 @@ bool DecodeTrace::create_popup(bool isnew)
}
}
dlg.get_sample_range(_start_index, _end_index);
dlg.get_cursor_range(_decode_cursor1, _decode_cursor2);
}
return ret;

View File

@@ -29,6 +29,7 @@
#include <QSignalMapper>
#include <QFormLayout>
#include <QWidget>
#include <QString>
#include "trace.h"
#include "../prop/binding/decoderoptions.h"
@@ -191,8 +192,9 @@ private:
uint64_t _decode_start;
uint64_t _decode_end;
int _start_index;
int _end_index;
QString _decode_cursor1; // the cursor key name, sample start index
QString _decode_cursor2;
QFormLayout *_pub_input_layer;
int _progress;

View File

@@ -1321,5 +1321,17 @@ void View::set_receive_len(uint64_t len)
_fft_viewport->set_receive_len(len);
}
int View::get_cursor_index_by_key(QString key)
{
int dex = 0;
for (auto c : _cursorList){
if (c->get_key() == key){
return dex;
}
++dex;
}
return -1;
}
} // namespace view
} // namespace pv

View File

@@ -239,6 +239,8 @@ public:
double index2pixel(uint64_t index, bool has_hoff = true);
uint64_t pixel2index(double pixel);
int get_cursor_index_by_key(QString key);
signals:
void hover_point_changed();