From a2dcb8e24ab35441bc6b81071ebc9be89abac1f6 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Thu, 11 Apr 2024 16:51:59 +0800 Subject: [PATCH] Do not load the device until the window is ready --- DSView/pv/mainwindow.cpp | 33 +++++++++++++++++++-------------- DSView/pv/mainwindow.h | 5 ++++- DSView/pv/view/view.cpp | 6 ++++++ DSView/pv/view/view.h | 2 ++ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index bc98095b..2ddc4845 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -296,11 +296,9 @@ namespace pv connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int))); _delay_prop_msg_timer.SetCallback(std::bind(&MainWindow::on_delay_prop_msg, this)); - + _logo_bar->set_mainform_callback(this); - bool bLoadFile = false; - // Try load from file. QString ldFileName(AppControl::Instance()->_open_file_name.c_str()); if (ldFileName != "") @@ -311,12 +309,6 @@ namespace pv { dsv_info("Auto load file:%s", file_name.c_str()); tmp_file = ldFileName; - bLoadFile = true; - - QTimer::singleShot(100, this, [this](){ - on_load_file(tmp_file); - tmp_file = ""; - }); } else { @@ -325,14 +317,27 @@ namespace pv } } - if (!bLoadFile){ - QTimer::singleShot(100, this, [this](){ - _session->set_default_device(); - }); + // Load the device after the view is ready. + connect(&_load_device_timer, SIGNAL(timeout()), this, SLOT(on_load_device_first())); + _load_device_timer.start(100); + } + + void MainWindow::on_load_device_first() + { + if (_view->view_is_ready()) + { + if (tmp_file != ""){ + on_load_file(tmp_file); + tmp_file = ""; + } + else{ + _session->set_default_device(); + } + + _load_device_timer.stop(); } } - //* void MainWindow::retranslateUi() { _trigger_dock->setWindowTitle(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_TRIGGER_DOCK_TITLE), "Trigger Setting...")); diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index d4b02145..116ee7b2 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -32,6 +32,7 @@ #include "eventobject.h" #include #include +#include #include "dstimer.h" class QAction; @@ -123,6 +124,7 @@ private slots: void on_cur_snap_samplerate_changed(); void on_trigger_message(int msg); void on_delay_prop_msg(); + void on_load_device_first(); signals: void prgRate(int progress); @@ -241,7 +243,8 @@ private: QString _title_ext_string; int _key_value; - bool _key_vaild; + bool _key_vaild; + QTimer _load_device_timer; }; } // namespace pv diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 5f0644ab..74a141c7 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -1516,5 +1516,11 @@ void View::UpdateFont() update_font(); } +bool View::view_is_ready() +{ + int w = get_view_width(); + return w > 0; +} + } // namespace view } // namespace pv diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 90ff4791..73043272 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -333,6 +333,8 @@ public: void UpdateTheme() override; void UpdateFont() override; + bool view_is_ready(); + signals: void hover_point_changed(); void cursor_update();