From f79a231de29a4ccb3121ff4a008f83f7e97c203e Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Wed, 10 Apr 2024 21:00:37 +0800 Subject: [PATCH] fix: Popup a message when there is no data to export --- DSView/pv/data/decoderstack.cpp | 3 +++ DSView/pv/data/decoderstack.h | 5 +++++ DSView/pv/dialogs/protocolexp.cpp | 10 +++++++++- DSView/pv/sigsession.cpp | 11 +++++++++++ DSView/pv/sigsession.h | 2 ++ lang/cn/msg.json | 4 ++++ lang/en/msg.json | 4 ++++ 7 files changed, 38 insertions(+), 1 deletion(-) diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 623f5d8f..3449ddb8 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -69,6 +69,7 @@ DecoderStack::DecoderStack(pv::SigSession *session, _snapshot = NULL; _progress = 0; _is_decoding = false; + _result_count = 0; _stack.push_back(new decode::Decoder(dec)); @@ -375,6 +376,7 @@ void DecoderStack::init() _error_message = QString(); _no_memory = false; _snapshot = NULL; + _result_count = 0; for (auto i = _rows.begin();i != _rows.end(); i++) { (*i).second->clear(); @@ -802,6 +804,7 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *self) d->_no_memory = true; return; } + d->_result_count++; // Find the row assert(pdata->pdo); diff --git a/DSView/pv/data/decoderstack.h b/DSView/pv/data/decoderstack.h index 9b8de2f0..c681eba4 100644 --- a/DSView/pv/data/decoderstack.h +++ b/DSView/pv/data/decoderstack.h @@ -183,6 +183,10 @@ public: bool check_required_probes(); + inline uint64_t get_result_count(){ + return _result_count; + } + private: void decode_data(const uint64_t decode_start, const uint64_t decode_end, srd_session *const session); void execute_decode_stack(); @@ -218,6 +222,7 @@ private: bool _is_capture_end; int _progress; bool _is_decoding; + uint64_t _result_count; friend class DecoderStackTest::TwoDecoderStack; }; diff --git a/DSView/pv/dialogs/protocolexp.cpp b/DSView/pv/dialogs/protocolexp.cpp index 3f09b781..7b712c5f 100644 --- a/DSView/pv/dialogs/protocolexp.cpp +++ b/DSView/pv/dialogs/protocolexp.cpp @@ -43,6 +43,7 @@ #include "../utility/path.h" #include "../log.h" #include "../ui/langresource.h" +#include "../ui/msgbox.h" #define EXPORT_DEC_ROW_COUNT_MAX 20 @@ -108,7 +109,14 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession *session) : } void ProtocolExp::accept() -{ +{ + if (_session->have_decoded_result() == false) + { + QString errMsg = L_S(STR_PAGE_MSG, S_ID(IDS_MSG_NO_DECODED_RESULT), "No data to export"); + MsgBox::Show(errMsg); + return; + } + QDialog::accept(); if (_row_sel_list.empty()){ diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 53d9f951..85c35a41 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -2556,4 +2556,15 @@ namespace pv } } + bool SigSession::have_decoded_result() + { + for (auto trace : _decode_traces){ + if (trace->decoder()->get_result_count() > 0){ + return true; + } + } + + return false; + } + } // namespace pv diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index abfcae69..612c650c 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -449,6 +449,8 @@ public: void update_lang_text(); + bool have_decoded_result(); + private: void set_cur_samplelimits(uint64_t samplelimits); void set_cur_snap_samplerate(uint64_t samplerate); diff --git a/lang/cn/msg.json b/lang/cn/msg.json index dcb0ab25..598f3b44 100644 --- a/lang/cn/msg.json +++ b/lang/cn/msg.json @@ -385,5 +385,9 @@ { "id": "IDS_MSG_DATA_RANGE_HAVE_NO_DATA", "text": "数据范围内无数据!" + }, + { + "id": "IDS_MSG_NO_DECODED_RESULT", + "text": "无可导出的数据!" } ] diff --git a/lang/en/msg.json b/lang/en/msg.json index 28ea8fd7..83f92942 100644 --- a/lang/en/msg.json +++ b/lang/en/msg.json @@ -386,5 +386,9 @@ { "id": "IDS_MSG_DATA_RANGE_HAVE_NO_DATA", "text": "No data in the data range!" + }, + { + "id": "IDS_MSG_NO_DECODED_RESULT", + "text": "No data to export!" } ]