From 59cb022c78ed3a9f3483b93b43b0e42bdf80de8d Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Fri, 25 Feb 2022 11:16:44 +0800 Subject: [PATCH] update: protocol search key word was changed, list panel auto be show popup --- DSView/main.cpp | 2 +- DSView/pv/data/decoderstack.cpp | 11 ++-- DSView/pv/dock/protocoldock.cpp | 92 +++++++++++++++++++++++++++++---- DSView/pv/dock/protocoldock.h | 19 +++++++ DSView/pv/dstimer.cpp | 63 ++++++++++++++++------ DSView/pv/dstimer.h | 23 +++++++-- DSView/pv/sigsession.cpp | 2 +- DSView/pv/ui/dscombobox.cpp | 13 ++++- DSView/pv/ui/dscombobox.h | 16 ++++-- doc/decoder.txt | 1 + 10 files changed, 197 insertions(+), 45 deletions(-) diff --git a/DSView/main.cpp b/DSView/main.cpp index 6c13cf2b..2f1cbb53 100755 --- a/DSView/main.cpp +++ b/DSView/main.cpp @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) QApplication::setOrganizationName("DreamSourceLab"); QApplication::setOrganizationDomain("www.DreamSourceLab.com"); - qDebug()<<"\n----------------- version:"<di_list; d; d = d->next) { srd_decoder_inst *di = (srd_decoder_inst *)d->data; @@ -479,6 +480,8 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod } } + assert(logic_di); + uint64_t entry_cnt = 0; uint64_t i = decode_start; char *error = NULL; @@ -487,12 +490,8 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod qDebug()<<"decode data index have been end:"<m_bStop){ - break; - } - + while(i < decode_end && !_no_memory && !status->m_bStop) + { std::vector chunk; std::vector chunk_const; uint64_t chunk_end = decode_end; diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index 80d1fed0..63bffefb 100755 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -52,24 +52,55 @@ #include "../config/appconfig.h" #include "../data/decode/decoderstatus.h" +#define PROTOCOL_FIND_TITLE "Protocol search..." + using namespace std; + +//--------------------------class KeywordLineEdit + +KeywordLineEdit::KeywordLineEdit(QComboBox *comboBox) +:QLineEdit() +{ + assert(comboBox); + _comboBox = comboBox; +} + + + void KeywordLineEdit::focusInEvent(QFocusEvent *e) + { + QLineEdit::focusInEvent(e); + QString key(PROTOCOL_FIND_TITLE); + if (this->text() == key){ + this->setText(""); + } + } + +void KeywordLineEdit::focusOutEvent(QFocusEvent *e) + { + QLineEdit::focusOutEvent(e); + + if (this->text() == ""){ + this->setText(PROTOCOL_FIND_TITLE); + } + } + +//---------------------------------------------------------- namespace pv { namespace dock { ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *session) : QScrollArea(parent), - _session(session), - _view(view), - _cur_search_index(-1), - _search_edited(false), - _searching(false), - _add_silent(false) + _view(view) { + _session = session; + _cur_search_index = -1; + _search_edited = false; + _searching = false; + _add_silent = false; + _up_widget = new QWidget(this); - - QHBoxLayout *hori_layout = new QHBoxLayout(); - + _add_button = new QPushButton(_up_widget); _add_button->setFlat(true); _del_all_button = new QPushButton(_up_widget); @@ -78,6 +109,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio _protocol_combobox = new DsComboBox(_up_widget); _protocol_combobox->setEditable(true); + _protocol_combobox->setLineEdit(new KeywordLineEdit(_protocol_combobox)); _protocol_combobox->setCompleter(NULL); GSList *l = g_slist_sort(g_slist_copy((GSList*)srd_decoder_list()), decoder_name_cmp); @@ -120,6 +152,8 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio for (auto info : _decoderInfoList){ _protocol_combobox->addItem(QString::fromUtf8(info->Name), QVariant::fromValue(info->Index)); } + _protocol_combobox->setCurrentIndex(-1); + _protocol_combobox->lineEdit()->setText(PROTOCOL_FIND_TITLE); if (repeatNammes != ""){ QString err = "Any protocol have repeated id or name: "; @@ -127,12 +161,14 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio MsgBox::Show("error", err.toUtf8().data()); } + _up_layout = new QVBoxLayout(); + + QHBoxLayout *hori_layout = new QHBoxLayout(); hori_layout->addWidget(_add_button); hori_layout->addWidget(_del_all_button); hori_layout->addWidget(_protocol_combobox); hori_layout->addStretch(1); - - _up_layout = new QVBoxLayout(); + _up_layout->addLayout(hori_layout); _up_layout->addStretch(1); @@ -216,6 +252,12 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio retranslateUi(); + _key_find_timer.SetCallback(std::bind(&ProtocolDock::show_protocol_list_panel, this)); + //when porotocol list panel was showPopup statu, receive key press event + QWidget *popup1 = _protocol_combobox->findChild(); + QWidget *wid1 = popup1->findChild(); + wid1->installEventFilter(this); + connect(_dn_nav_button, SIGNAL(clicked()),this, SLOT(nav_table_view())); connect(_dn_save_button, SIGNAL(clicked()),this, SLOT(export_table_view())); connect(_dn_set_button, SIGNAL(clicked()),this, SLOT(set_model())); @@ -857,8 +899,25 @@ void ProtocolDock::on_decoder_name_edited(const QString &value) _protocol_combobox->setCurrentIndex(-1); _protocol_combobox->lineEdit()->setText(value); + + if (_key_find_timer.IsActived() == false){ + //check input keep time + _key_find_timer.Start(100); + } + else{ + _key_find_timer.ResetActiveTime(); + } } + void ProtocolDock::show_protocol_list_panel() + { + //press key end, to popup list panel + if (_key_find_timer.GetActiveTimeLong() >= 1000){ + _key_find_timer.Stop(); + _protocol_combobox->showPopup(); + } + } + bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const DecoderInfoItem *o2) { const char *s1 = o1->Name; @@ -891,6 +950,17 @@ bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const Decod return true; } +bool ProtocolDock::eventFilter(QObject *object, QEvent *event) +{ + if ( event->type() == QEvent::KeyPress ) + { + if (_protocol_combobox->IsPopup()){ + _protocol_combobox->hidePopup(); + } + } + return false; +} + //------------------------- diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index 0e017316..50a69b7d 100755 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,21 @@ struct DecoderInfoItem{ void *ObjectHandle; //srd_decoder* type }; +class KeywordLineEdit : public QLineEdit + { + Q_OBJECT + +public: + KeywordLineEdit(QComboBox *comboBox); + +protected: + void focusInEvent(QFocusEvent *e) override; + void focusOutEvent(QFocusEvent *e) override; + +private: + QComboBox *_comboBox; +}; + namespace pv { class SigSession; @@ -124,6 +140,8 @@ private: static int decoder_name_cmp(const void *a, const void *b); void resize_table_view(data::DecoderModel *decoder_model); static bool protocol_sort_callback(const DecoderInfoItem *o1, const DecoderInfoItem *o2); + void show_protocol_list_panel(); + bool eventFilter(QObject *object, QEvent *event); private: SigSession *_session; @@ -162,6 +180,7 @@ private: bool _searching; bool _add_silent; + DsTimer _key_find_timer; }; } // namespace dock diff --git a/DSView/pv/dstimer.cpp b/DSView/pv/dstimer.cpp index e3bbaad2..c788de65 100644 --- a/DSView/pv/dstimer.cpp +++ b/DSView/pv/dstimer.cpp @@ -2,14 +2,15 @@ #include "dstimer.h" #include + DsTimer::DsTimer(){ _binded = false; + _isActived = false; } - void DsTimer::on_timeout() - { +void DsTimer::on_timeout(){ _call(); //call back - } +} void DsTimer::TimeOut(int millsec, CALLBACL_FUNC f) { @@ -17,33 +18,61 @@ void DsTimer::TimeOut(int millsec, CALLBACL_FUNC f) QTimer::singleShot(millsec, this, SLOT(on_timeout())); } -void DsTimer::SetCallback(CALLBACL_FUNC f) - { - assert(!_binded); - _binded = true; + void DsTimer::Start(int millsec, CALLBACL_FUNC f) + { + if (_isActived) + return; - _call = f; - connect(&_timer, SIGNAL(timeout()), this, SLOT(on_timeout())); + _call = f; + + if (!_binded){ + _binded = true; + connect(&_timer, SIGNAL(timeout()), this, SLOT(on_timeout())); + } + + _timer.start(millsec); + _isActived = true; + _beginTime = high_resolution_clock::now(); } - void DsTimer::Start(int millsec, CALLBACL_FUNC f) +void DsTimer::SetCallback(CALLBACL_FUNC f) { - assert(!_binded); - _binded = true; + _call = f; - _call = f; - connect(&_timer, SIGNAL(timeout()), this, SLOT(on_timeout())); - _timer.start(millsec); + if(!_binded){ + _binded = true; + connect(&_timer, SIGNAL(timeout()), this, SLOT(on_timeout())); + } } void DsTimer::Start(int millsec) { - //check if connectb + //check if connect assert(_binded); + + if (_isActived) + return; + _timer.start(millsec); + _isActived = true; + _beginTime = high_resolution_clock::now(); } void DsTimer::Stop() { - _timer.stop(); + if (_isActived) + _timer.stop(); + _isActived = false; + } + + long long DsTimer::GetActiveTimeLong() + { + high_resolution_clock::time_point endTime = high_resolution_clock::now(); + milliseconds timeInterval = std::chrono::duration_cast(endTime - _beginTime); + return timeInterval.count(); + } + + void DsTimer::ResetActiveTime() + { + _beginTime = high_resolution_clock::now(); } diff --git a/DSView/pv/dstimer.h b/DSView/pv/dstimer.h index 87c35f41..a10f07b6 100644 --- a/DSView/pv/dstimer.h +++ b/DSView/pv/dstimer.h @@ -5,12 +5,17 @@ #include #include #include +#include + +using std::chrono::high_resolution_clock; +using std::chrono::milliseconds; typedef std::function CALLBACL_FUNC; -class DsTimer : public QObject + +class DsTimer : protected QObject { - Q_OBJECT + Q_OBJECT public: DsTimer(); @@ -25,13 +30,23 @@ public: void Stop(); + inline bool IsActived(){ + return _isActived; + } + + long long GetActiveTimeLong(); + + void ResetActiveTime(); + private slots: void on_timeout(); -private: - CALLBACL_FUNC _call; +private: QTimer _timer; bool _binded; + bool _isActived; + high_resolution_clock::time_point _beginTime; + CALLBACL_FUNC _call; }; #endif diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 59b6db30..8351ea2c 100755 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -1900,7 +1900,7 @@ void SigSession::set_stop_scale(float scale) } if (task->_delete_flag){ - qDebug()<<"desroy a decoder in task thread"; + qDebug()<<"destroy a decoder in task thread"; DESTROY_QT_LATER(task); std::this_thread::sleep_for(std::chrono::milliseconds(100)); diff --git a/DSView/pv/ui/dscombobox.cpp b/DSView/pv/ui/dscombobox.cpp index f405b6b9..008d8fde 100644 --- a/DSView/pv/ui/dscombobox.cpp +++ b/DSView/pv/ui/dscombobox.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2022 DreamSourceLab * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,11 +24,14 @@ #include "dscombobox.h" #include #include +#include + #include "../config/appconfig.h" DsComboBox::DsComboBox(QWidget *parent) : QComboBox(parent) { _contentWidth = 0; + _bPopup = false; QComboBox::setSizeAdjustPolicy(QComboBox::AdjustToContents); } @@ -51,6 +54,7 @@ DsComboBox::DsComboBox(QWidget *parent) : QComboBox(parent) void DsComboBox::showPopup() { QComboBox::showPopup(); + _bPopup = true; #ifdef Q_OS_DARWIN @@ -70,3 +74,10 @@ DsComboBox::DsComboBox(QWidget *parent) : QComboBox(parent) } #endif } + + void DsComboBox::hidePopup() + { + QComboBox::hidePopup(); + _bPopup = false; + } + diff --git a/DSView/pv/ui/dscombobox.h b/DSView/pv/ui/dscombobox.h index 00820d50..81da331c 100644 --- a/DSView/pv/ui/dscombobox.h +++ b/DSView/pv/ui/dscombobox.h @@ -4,7 +4,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2022 DreamSourceLab * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ #define DSCOMBOBOX_H #include +#include class DsComboBox : public QComboBox { @@ -35,11 +36,18 @@ public: void addItem(const QString &atext, const QVariant &userData = QVariant()); -protected: - void showPopup(); +public: + void showPopup() override; + + void hidePopup() override; + + inline bool IsPopup(){ + return _bPopup; + } private: - int _contentWidth; + int _contentWidth; + bool _bPopup; }; diff --git a/doc/decoder.txt b/doc/decoder.txt index 97dd181e..58980882 100644 --- a/doc/decoder.txt +++ b/doc/decoder.txt @@ -26,4 +26,5 @@ c can call's method of python: 5.printlog //print log to console, param type is string +decode函数返回任意值,则表示解析任务终止