diff --git a/DSView/pv/dialogs/decoderoptionsdlg.cpp b/DSView/pv/dialogs/decoderoptionsdlg.cpp index 31977bcc..a55599a0 100644 --- a/DSView/pv/dialogs/decoderoptionsdlg.cpp +++ b/DSView/pv/dialogs/decoderoptionsdlg.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #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 diff --git a/DSView/pv/dialogs/decoderoptionsdlg.h b/DSView/pv/dialogs/decoderoptionsdlg.h index c32f6d6e..485cfdd2 100644 --- a/DSView/pv/dialogs/decoderoptionsdlg.h +++ b/DSView/pv/dialogs/decoderoptionsdlg.h @@ -24,7 +24,8 @@ #include #include -#include +#include +#include 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 _bindings; + std::vector _bindings; DsComboBox *_start_comboBox; DsComboBox *_end_comboBox; view::DecodeTrace *_trace; - int _start_index; - int _end_index; - std::list _probe_selectors; + QString _cursor1; + QString _cursor2; + std::vector _probe_selectors; }; }//dialogs diff --git a/DSView/pv/view/cursor.cpp b/DSView/pv/view/cursor.cpp index 1d2e5268..1cf8f18f 100755 --- a/DSView/pv/view/cursor.cpp +++ b/DSView/pv/view/cursor.cpp @@ -34,6 +34,8 @@ #include #include +#include +#include #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 diff --git a/DSView/pv/view/cursor.h b/DSView/pv/view/cursor.h index 6e8292fc..029b5489 100755 --- a/DSView/pv/view/cursor.h +++ b/DSView/pv/view/cursor.h @@ -27,6 +27,7 @@ #include "timemarker.h" #include +#include 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 diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 6120e1c2..2bc71176 100755 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -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; diff --git a/DSView/pv/view/decodetrace.h b/DSView/pv/view/decodetrace.h index 8980c689..b8b09ce2 100755 --- a/DSView/pv/view/decodetrace.h +++ b/DSView/pv/view/decodetrace.h @@ -29,6 +29,7 @@ #include #include #include +#include #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; diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 3328fb5d..f33a6d16 100755 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -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 diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 213d3436..9526fd9e 100755 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -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();