From 7e053bec6faecf30c4ba421ce9ce6e69b459ad14 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Sat, 11 May 2024 19:54:01 +0800 Subject: [PATCH] fix: the decoded data exporting dialog can't close in MAC os --- DSView/pv/dialogs/protocolexp.cpp | 67 +++++++++++++++++++------------ DSView/pv/dialogs/protocolexp.h | 12 ++++-- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/DSView/pv/dialogs/protocolexp.cpp b/DSView/pv/dialogs/protocolexp.cpp index 7b712c5f..e3f0cb9b 100644 --- a/DSView/pv/dialogs/protocolexp.cpp +++ b/DSView/pv/dialogs/protocolexp.cpp @@ -59,6 +59,8 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession *session) : Qt::Horizontal, this), _export_cancel(false) { + _bAbleClose = false; + _format_combobox = new DsComboBox(this); //tr _format_combobox->addItem("Comma-Separated Values (*.csv)"); @@ -102,27 +104,51 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession *session) : layout()->addLayout(_layout); setTitle(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_PROTOCOL_EXPORT), "Protocol Export")); - connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); - connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); - connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(&_button_box, SIGNAL(accepted()), this, SLOT(onAccept())); + connect(&_button_box, SIGNAL(rejected()), this, SLOT(onReject())); + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(onReject())); + + connect(&m_timer, &QTimer::timeout, this, &ProtocolExp::on_timeout); + m_timer.setInterval(200); } -void ProtocolExp::accept() -{ - if (_session->have_decoded_result() == false) +void ProtocolExp::on_timeout() +{ + if (_bAbleClose){ + closeSelf(); + } +} + +void ProtocolExp::onReject() +{ + using namespace Qt; + + QDialog::reject(); + this->deleteLater(); +} + +void ProtocolExp::cancel_export() +{ + _export_cancel = true; +} + +void ProtocolExp::closeSelf() +{ + close(); + this->deleteLater(); +} + +void ProtocolExp::onAccept() +{ + if (_session->have_decoded_result() == false + || _row_sel_list.empty()) { 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()){ - return; - } - + QList supportedFormats; for (int i = _format_combobox->count() - 1; i >= 0; i--) { @@ -170,6 +196,7 @@ void ProtocolExp::accept() QFuture future; future = QtConcurrent::run([&]{ save_proc(); + _bAbleClose = true; }); Qt::WindowFlags flags = Qt::CustomizeWindowHint; @@ -186,6 +213,8 @@ void ProtocolExp::accept() connect(this, SIGNAL(export_progress(int)), &dlg, SLOT(setValue(int))); connect(&dlg, SIGNAL(canceled()), this, SLOT(cancel_export())); + m_timer.start(); + this->hide(); watcher.setFuture(future); dlg.exec(); @@ -335,17 +364,5 @@ bool ProtocolExp::compare_ann_index(const data::decode::Annotation *a, return a->start_sample() < b->start_sample(); } -void ProtocolExp::reject() -{ - using namespace Qt; - - QDialog::reject(); -} - -void ProtocolExp::cancel_export() -{ - _export_cancel = true; -} - } // namespace dialogs } // namespace pv diff --git a/DSView/pv/dialogs/protocolexp.h b/DSView/pv/dialogs/protocolexp.h index f8afc844..7e8dd986 100644 --- a/DSView/pv/dialogs/protocolexp.h +++ b/DSView/pv/dialogs/protocolexp.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "../prop/binding/deviceoptions.h" #include "../toolbars/titlebar.h" @@ -64,18 +65,21 @@ private: public: ProtocolExp(QWidget *parent, SigSession *session); -protected: - void accept(); - void reject(); +protected: void save_proc(); static bool compare_ann_index(const data::decode::Annotation *a, const data::decode::Annotation *b); + void closeSelf(); + signals: void export_progress(int percent); private slots: void cancel_export(); + void onAccept(); + void onReject(); + void on_timeout(); private: SigSession *_session; @@ -90,6 +94,8 @@ private: bool _export_cancel; QString _fileName; + QTimer m_timer; + bool _bAbleClose; }; } // namespace dialogs