diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index 381b078f..f28ad8c2 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -73,6 +73,7 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) : _p_label = new QLabel(_widget); _f_label = new QLabel(_widget); _d_label = new QLabel(_widget); + QGridLayout *mouse_layout = new QGridLayout(); mouse_layout->setVerticalSpacing(5); mouse_layout->setHorizontalSpacing(5); @@ -196,17 +197,19 @@ void MeasureDock::reStyle() _dist_add_btn->setIcon(QIcon(iconPath+"/add.svg")); _edge_add_btn->setIcon(QIcon(iconPath+"/add.svg")); - for (auto it = _dist_row_list.begin(); it != _dist_row_list.end(); it++) + auto mode_rows = get_mode_rows(); + + for (auto it = mode_rows->_dist_row_list.begin(); it != mode_rows->_dist_row_list.end(); it++) { (*it).del_bt->setIcon(QIcon(iconPath+"/del.svg")); } - for (auto it = _edge_row_list.begin(); it != _edge_row_list.end(); it++) + for (auto it = mode_rows->_edge_row_list.begin(); it != mode_rows->_edge_row_list.end(); it++) { (*it).del_bt->setIcon(QIcon(iconPath+"/del.svg")); } - for (auto it = _opt_row_list.begin(); it != _opt_row_list.end(); it++) + for (auto it = mode_rows->_opt_row_list.begin(); it != mode_rows->_opt_row_list.end(); it++) { (*it).del_bt->setIcon(QIcon(iconPath+"/del.svg")); } @@ -214,11 +217,6 @@ void MeasureDock::reStyle() update_dist(); } -void MeasureDock::refresh() -{ - -} - void MeasureDock::reload() { if (_session->get_device()->get_work_mode() == LOGIC) @@ -228,13 +226,9 @@ void MeasureDock::reload() _bSetting = true; - for (auto &o : _edge_row_list){ - update_probe_selector(o.box); - - if (o.channelIndex < o.box->count()){ - o.box->setCurrentIndex(o.channelIndex); - } - } + build_dist_pannel(); + build_edge_pannel(); + build_cursor_pannel(); _bSetting = false; @@ -273,7 +267,9 @@ void MeasureDock::build_dist_pannel() cal_lb.setFont(font); int bt_w = cal_lb.fontMetrics().horizontalAdvance("22") + 8; - for (auto &o : _dist_row_list) + auto mode_rows = get_mode_rows(); + + for (auto &o : mode_rows->_dist_row_list) { QWidget *row_widget = new QWidget(_widget); row_widget->setContentsMargins(0,0,0,0); @@ -342,7 +338,9 @@ void MeasureDock::build_dist_pannel() void MeasureDock::add_dist_measure() { - if (_dist_row_list.size() < Max_Measure_Limits) + auto mode_rows = get_mode_rows(); + + if (mode_rows->_dist_row_list.size() < Max_Measure_Limits) { cursor_row_info inf; inf.cursor1 = -1; @@ -354,7 +352,7 @@ void MeasureDock::add_dist_measure() inf.r_label = NULL; inf.channelIndex = 0; - _dist_row_list.push_back(inf); + mode_rows->_dist_row_list.push_back(inf); build_dist_pannel(); @@ -365,12 +363,14 @@ void MeasureDock::add_dist_measure() void MeasureDock::del_dist_measure() { auto src = dynamic_cast(sender()); - assert(src); + assert(src); - for (auto it =_dist_row_list.begin(); it != _dist_row_list.end(); it++) + auto mode_rows = get_mode_rows(); + + for (auto it = mode_rows->_dist_row_list.begin(); it != mode_rows->_dist_row_list.end(); it++) { if ((*it).del_bt == src){ - _dist_row_list.erase(it); + mode_rows->_dist_row_list.erase(it); build_dist_pannel(); break; } @@ -400,7 +400,9 @@ void MeasureDock::build_edge_pannel() cal_lb.setFont(font); int bt_w = cal_lb.fontMetrics().horizontalAdvance("22") + 8; - for (auto &o : _edge_row_list) + auto mode_rows = get_mode_rows(); + + for (auto &o : mode_rows->_edge_row_list) { QWidget *row_widget = new QWidget(_widget); row_widget->setContentsMargins(0,0,0,0); @@ -485,8 +487,10 @@ void MeasureDock::build_edge_pannel() void MeasureDock::on_edge_channel_selected() { QComboBox *box = dynamic_cast(sender()); - if (box != NULL && !_bSetting){ - for (auto &o : _edge_row_list) + auto mode_rows = get_mode_rows(); + + if (box != NULL && !_bSetting){ + for (auto &o : mode_rows->_edge_row_list) { if (o.box == box){ o.channelIndex = box->currentIndex(); @@ -500,7 +504,9 @@ void MeasureDock::on_edge_channel_selected() void MeasureDock::add_edge_measure() { - if (_edge_row_list.size() < Max_Measure_Limits) + auto mode_rows = get_mode_rows(); + + if (mode_rows->_edge_row_list.size() < Max_Measure_Limits) { cursor_row_info inf; inf.cursor1 = -1; @@ -512,7 +518,7 @@ void MeasureDock::add_edge_measure() inf.r_label = NULL; inf.channelIndex = 0; - _edge_row_list.push_back(inf); + mode_rows->_edge_row_list.push_back(inf); build_edge_pannel(); adjusLabelSize(); @@ -523,11 +529,12 @@ void MeasureDock::del_edge_measure() { QToolButton* src = dynamic_cast(sender()); assert(src); + auto mode_rows = get_mode_rows(); - for (auto it =_edge_row_list.begin(); it != _edge_row_list.end(); it++) + for (auto it =mode_rows->_edge_row_list.begin(); it != mode_rows->_edge_row_list.end(); it++) { if ((*it).del_bt == src){ - _edge_row_list.erase(it); + mode_rows->_edge_row_list.erase(it); build_edge_pannel(); break; } @@ -582,10 +589,11 @@ void MeasureDock::set_sel_cursor() QPushButton *sel_cursor_bt = qobject_cast(sender()); int type = 0; cursor_row_info *inf = NULL; + auto mode_rows = get_mode_rows(); if (type == 0) { - for (auto &o : _dist_row_list){ + for (auto &o : mode_rows->_dist_row_list){ if (o.start_bt == _sel_btn || o.end_bt == _sel_btn){ inf = &o; type = 1; @@ -596,7 +604,7 @@ void MeasureDock::set_sel_cursor() if (type == 0) { - for (auto &o : _edge_row_list){ + for (auto &o : mode_rows->_edge_row_list){ if (o.start_bt == _sel_btn || o.end_bt == _sel_btn){ inf = &o; type = 2; @@ -631,8 +639,13 @@ void MeasureDock::update_dist() QColor bkColor = AppConfig::Instance().GetStyleColor(); - for (auto &inf : _dist_row_list) - { + auto mode_rows = get_mode_rows(); + + for (auto &inf : mode_rows->_dist_row_list) + { + if (inf.start_bt == NULL) + break; + if (inf.cursor1 != -1) { if (inf.cursor1 > (int)cursor_list.size()) { inf.start_bt->setText(""); @@ -667,9 +680,13 @@ void MeasureDock::update_dist() void MeasureDock::update_edge() { auto &cursor_list = _view.get_cursorList(); + auto mode_rows = get_mode_rows(); - for (auto &inf : _edge_row_list) + for (auto &inf : mode_rows->_edge_row_list) { + if (inf.start_bt == NULL) + break; + if (inf.cursor1 != -1) { if (inf.cursor1 > (int)cursor_list.size()) { inf.start_bt->setText(""); @@ -716,11 +733,32 @@ void MeasureDock::update_edge() } } +void MeasureDock::update_cursor_info() +{ + auto &cursor_list = _view.get_cursorList(); + auto mode_rows = get_mode_rows(); + + int num_cursors = cursor_list.size(); + int num_rows = mode_rows->_opt_row_list.size(); + + if (num_rows == 0){ + return; + } + + assert(num_cursors == num_rows); + + for(int i = 0; i < num_cursors; i++) + { + if (mode_rows->_opt_row_list[i].info_label != NULL){ + QString cur_pos = _view.get_cm_time(i) + "/" + + QString::number(_view.get_cursor_samples(i)); + mode_rows->_opt_row_list[i].info_label->setText(cur_pos); + } + } +} + void MeasureDock::set_cursor_btn_color(QPushButton *btn) { - //#302F2F - // QColor bkColor = AppConfig::Instance().IsDarkStyle() ? QColor("#383838") : QColor("#FFFFFF"); - QColor bkColor = AppConfig::Instance().GetStyleColor(); bool isCursor = false; const unsigned int start = btn->text().toInt(&isCursor); @@ -767,30 +805,17 @@ void MeasureDock::adjusLabelSize() void MeasureDock::cursor_moving() { if (_view.cursors_shown()) { - auto &cursor_list = _view.get_cursorList(); - - if (cursor_list.size() != _opt_row_list.size()){ - assert(false); - } - - int index = 0; - - for(auto i = cursor_list.begin(); i != cursor_list.end(); i++) { - QString _cur_text = _view.get_cm_time(index) + "/" - + QString::number(_view.get_cursor_samples(index)); - _opt_row_list[index].info_label->setText(_cur_text); - index++; - } + update_cursor_info(); } update_dist(); } void MeasureDock::reCalc() -{ - cursor_update(); +{ update_dist(); update_edge(); + update_cursor_info(); adjusLabelSize(); } @@ -801,8 +826,9 @@ void MeasureDock::goto_cursor() assert(src); int index = 0; + auto mode_rows = get_mode_rows(); - for (auto it = _opt_row_list.begin(); it != _opt_row_list.end(); it++) + for (auto it = mode_rows->_opt_row_list.begin(); it != mode_rows->_opt_row_list.end(); it++) { if ( (*it).goto_bt == src){ _view.set_cursor_middle(index); @@ -814,18 +840,24 @@ void MeasureDock::goto_cursor() void MeasureDock::cursor_update() { - using namespace pv::data; - - for(auto it = _opt_row_list.begin(); it != _opt_row_list.end(); it++) - { - (*it).del_bt->deleteLater(); - (*it).goto_bt->deleteLater(); - (*it).info_label->deleteLater(); - } - _opt_row_list.clear(); - update_dist(); update_edge(); + build_cursor_pannel(); +} + +void MeasureDock::build_cursor_pannel() +{ + auto mode_rows = get_mode_rows(); + + for (auto &row : mode_rows->_opt_row_list) + { + if (row.del_bt != NULL){ + row.del_bt->deleteLater(); + row.goto_bt->deleteLater(); + row.info_label->deleteLater(); + } + } + mode_rows->_opt_row_list.clear(); QFont font = this->font(); font.setPointSizeF(AppConfig::Instance().appOptions.fontSize); @@ -839,6 +871,10 @@ void MeasureDock::cursor_update() QString iconPath = GetIconPath(); auto &cursor_list = _view.get_cursorList(); + if (cursor_list.size() == 0){ + return; + } + for(auto it = cursor_list.begin(); it != cursor_list.end(); it++) { XToolButton *del_btn = new XToolButton(_widget); del_btn->setIcon(QIcon(iconPath+"/del.svg")); @@ -861,7 +897,7 @@ void MeasureDock::cursor_update() connect(cursor_pushButton, SIGNAL(clicked()), this, SLOT(goto_cursor())); cursor_opt_info inf = {del_btn, cursor_pushButton, curpos_label, (*it)}; - _opt_row_list.push_back(inf); + mode_rows->_opt_row_list.push_back(inf); index++; cursor_dex++; @@ -877,8 +913,9 @@ void MeasureDock::del_cursor() Cursor* cursor = NULL; auto &cursor_list = _view.get_cursorList(); + auto mode_rows = get_mode_rows(); - for (auto it = _opt_row_list.begin(); it != _opt_row_list.end(); it++) + for (auto it = mode_rows->_opt_row_list.begin(); it != mode_rows->_opt_row_list.end(); it++) { if ((*it).del_bt == src){ cursor = (*it).cursor; @@ -954,5 +991,63 @@ void MeasureDock::adjust_form_size(QWidget *wid) } } +row_list_item* MeasureDock::get_mode_rows() +{ + int mode = _session->get_device()->get_work_mode(); + int dex = 0; + + if (mode == LOGIC){ + dex = 0; + } + else if (mode == DSO){ + dex = 1; + } + else if (mode == ANALOG){ + dex = 2; + } + + for (int i=0; i_dist_row_list){ + o.del_bt = NULL; + o.start_bt = NULL; + o.end_bt = NULL; + o.r_label = NULL; + o.box = NULL; + } + + for(auto &o : rows->_edge_row_list){ + o.del_bt = NULL; + o.start_bt = NULL; + o.end_bt = NULL; + o.r_label = NULL; + o.box = NULL; + } + + for (auto &row : rows->_opt_row_list) + { + if (row.del_bt != NULL){ + row.del_bt->deleteLater(); + row.goto_bt->deleteLater(); + row.info_label->deleteLater(); + row.del_bt = NULL; + row.goto_bt = NULL; + row.info_label = NULL; + } + } + rows->_opt_row_list.clear(); + } + + _mode_rows[dex]._mode_type = mode; + + return &_mode_rows[dex]; +} + } // namespace dock } // namespace pv diff --git a/DSView/pv/dock/measuredock.h b/DSView/pv/dock/measuredock.h index c885ee27..3dd1693f 100644 --- a/DSView/pv/dock/measuredock.h +++ b/DSView/pv/dock/measuredock.h @@ -75,6 +75,16 @@ struct cursor_opt_info view::Cursor *cursor; }; +struct row_list_item +{ + std::vector _dist_row_list; + std::vector _edge_row_list; + std::vector _opt_row_list; + int _mode_type; +}; + +#define MODE_ROWS_LENGTH 3 + class MeasureDock : public QScrollArea, public IUiWindow { Q_OBJECT @@ -99,12 +109,14 @@ private: void build_dist_pannel(); void build_edge_pannel(); + void build_cursor_pannel(); private: QComboBox* create_probe_selector(QWidget *parent); void update_probe_selector(QComboBox *selector); void adjusLabelSize(); void adjust_form_size(QWidget *wid); + row_list_item* get_mode_rows(); private slots: void goto_cursor(); @@ -114,6 +126,7 @@ private slots: void del_edge_measure(); void update_dist(); void update_edge(); + void update_cursor_info(); void set_cursor_btn_color(QPushButton *btn); void set_cursor_btn_color(QPushButton *btn, QColor cursorColor, QColor bkColor, bool isCursor); @@ -127,7 +140,6 @@ public slots: void cursor_moving(); void reCalc(); void measure_updated(); - void refresh(); private: SigSession *_session; @@ -151,11 +163,10 @@ private: QWidget *_dist_pannel; QWidget *_edge_pannel; - QGridLayout *_cursor_layout; - QGroupBox *_cursor_groupBox; - std::vector _dist_row_list; - std::vector _edge_row_list; - std::vector _opt_row_list; + QGridLayout *_cursor_layout; + QGroupBox *_cursor_groupBox; + + row_list_item _mode_rows[MODE_ROWS_LENGTH]; QLabel *_channel_label; QLabel *_edge_label; diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 2ddc4845..6473d880 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -1460,7 +1460,7 @@ namespace pv void MainWindow::on_cur_snap_samplerate_changed() { - _measure_widget->cursor_update(); + _measure_widget->reCalc(); } /*------------------on event end-------*/ @@ -1794,161 +1794,170 @@ namespace pv { switch (msg) { - case DSV_MSG_DEVICE_LIST_UPDATED: - _sampling_bar->update_device_list(); - break; - - case DSV_MSG_START_COLLECT_WORK_PREV: - if (_device_agent->get_work_mode() == LOGIC) - _trigger_widget->try_commit_trigger(); - else if (_device_agent->get_work_mode() == DSO) - _dso_trigger_widget->check_setting(); - - _view->capture_init(); - _view->on_state_changed(false); - break; - - case DSV_MSG_START_COLLECT_WORK: - update_toolbar_view_status(); - _view->on_state_changed(false); - _protocol_widget->update_view_status(); - break; - - case DSV_MSG_COLLECT_END: - prgRate(0); - _view->repeat_unshow(); - _view->on_state_changed(true); - _protocol_widget->update_view_status(); - break; - - case DSV_MSG_END_COLLECT_WORK: - update_toolbar_view_status(); - break; - - case DSV_MSG_CURRENT_DEVICE_CHANGE_PREV: - if (_msg != NULL){ - _msg->close(); - _msg = NULL; + case DSV_MSG_DEVICE_LIST_UPDATED: + { + _sampling_bar->update_device_list(); + break; } - _view->hide_calibration(); - - _protocol_widget->del_all_protocol(); - _view->reload(); - break; - - case DSV_MSG_CURRENT_DEVICE_CHANGED: - { - reset_all_view(); - load_device_config(); - update_title_bar_text(); - _sampling_bar->update_device_list(); - - _logo_bar->dsl_connected(_session->get_device()->is_hardware()); - update_toolbar_view_status(); - _session->device_event_object()->device_updated(); - - if (_device_agent->is_hardware()) + case DSV_MSG_START_COLLECT_WORK_PREV: { - _session->on_load_config_end(); - } - - if (_device_agent->get_work_mode() == LOGIC && _device_agent->is_file() == false) - _view->auto_set_max_scale(); + if (_device_agent->get_work_mode() == LOGIC) + _trigger_widget->try_commit_trigger(); + else if (_device_agent->get_work_mode() == DSO) + _dso_trigger_widget->check_setting(); - if (_device_agent->is_file()) + _view->capture_init(); + _view->on_state_changed(false); + break; + } + case DSV_MSG_START_COLLECT_WORK: { - check_config_file_version(); - - bool bDoneDecoder = false; - bool bLoadSuccess = false; - QJsonDocument doc = get_config_json_from_data_file(_device_agent->path(), bLoadSuccess); - - if (bLoadSuccess){ - load_config_from_json(doc, bDoneDecoder); + update_toolbar_view_status(); + _view->on_state_changed(false); + _protocol_widget->update_view_status(); + break; + } + case DSV_MSG_COLLECT_END: + { + prgRate(0); + _view->repeat_unshow(); + _view->on_state_changed(true); + _protocol_widget->update_view_status(); + break; + } + case DSV_MSG_END_COLLECT_WORK: + { + update_toolbar_view_status(); + break; + } + case DSV_MSG_CURRENT_DEVICE_CHANGE_PREV: + { + if (_msg != NULL){ + _msg->close(); + _msg = NULL; } + _view->hide_calibration(); - if (!bDoneDecoder && _device_agent->get_work_mode() == LOGIC) - { - QJsonArray deArray = get_decoder_json_from_data_file(_device_agent->path(), bLoadSuccess); + _protocol_widget->del_all_protocol(); + _view->reload(); + break; + } + case DSV_MSG_CURRENT_DEVICE_CHANGED: + { + reset_all_view(); + load_device_config(); + update_title_bar_text(); + _sampling_bar->update_device_list(); + + _logo_bar->dsl_connected(_session->get_device()->is_hardware()); + update_toolbar_view_status(); + _session->device_event_object()->device_updated(); + + if (_device_agent->is_hardware()) + { + _session->on_load_config_end(); + } + + if (_device_agent->get_work_mode() == LOGIC && _device_agent->is_file() == false) + _view->auto_set_max_scale(); + + if (_device_agent->is_file()) + { + check_config_file_version(); + + bool bDoneDecoder = false; + bool bLoadSuccess = false; + QJsonDocument doc = get_config_json_from_data_file(_device_agent->path(), bLoadSuccess); if (bLoadSuccess){ - StoreSession ss(_session); - ss.load_decoders(_protocol_widget, deArray); - } + load_config_from_json(doc, bDoneDecoder); + } + + if (!bDoneDecoder && _device_agent->get_work_mode() == LOGIC) + { + QJsonArray deArray = get_decoder_json_from_data_file(_device_agent->path(), bLoadSuccess); + + if (bLoadSuccess){ + StoreSession ss(_session); + ss.load_decoders(_protocol_widget, deArray); + } + } + + _view->update_all_trace_postion(); + QTimer::singleShot(100, this, [this](){ + _session->start_capture(true); + }); + } + else if (_device_agent->is_demo()) + { + if(_device_agent->get_work_mode() == LOGIC) + { + _pattern_mode = _device_agent->get_demo_operation_mode(); + _protocol_widget->del_all_protocol(); + _view->auto_set_max_scale(); + + if(_pattern_mode != "random"){ + load_demo_decoder_config(_pattern_mode); + } + } + } + + calc_min_height(); + + if (_device_agent->is_hardware() && _device_agent->is_new_device()){ + check_usb_device_speed(); } - _view->update_all_trace_postion(); - QTimer::singleShot(100, this, [this](){ - _session->start_capture(true); - }); + break; } - else if (_device_agent->is_demo()) + case DSV_MSG_DEVICE_OPTIONS_UPDATED: { - if(_device_agent->get_work_mode() == LOGIC) + _trigger_widget->device_updated(); + _measure_widget->reload(); + _view->check_calibration(); + break; + } + case DSV_MSG_DEVICE_DURATION_UPDATED: + { + _trigger_widget->device_updated(); + _view->timebase_changed(); + break; + } + case DSV_MSG_DEVICE_MODE_CHANGED: + { + _view->mode_changed(); + reset_all_view(); + load_device_config(); + update_title_bar_text(); + _view->hide_calibration(); + + update_toolbar_view_status(); + _sampling_bar->update_sample_rate_list(); + + if (_device_agent->is_hardware()) + _session->on_load_config_end(); + + if (_device_agent->get_work_mode() == LOGIC) + _view->auto_set_max_scale(); + + if(_device_agent->is_demo()) { _pattern_mode = _device_agent->get_demo_operation_mode(); _protocol_widget->del_all_protocol(); - _view->auto_set_max_scale(); - if(_pattern_mode != "random"){ - load_demo_decoder_config(_pattern_mode); + if(_device_agent->get_work_mode() == LOGIC) + { + if(_pattern_mode != "random"){ + _device_agent->update(); + load_demo_decoder_config(_pattern_mode); + } } } + + calc_min_height(); + break; } - - calc_min_height(); - - if (_device_agent->is_hardware() && _device_agent->is_new_device()){ - check_usb_device_speed(); - } - } - break; - - case DSV_MSG_DEVICE_OPTIONS_UPDATED: - _trigger_widget->device_updated(); - _measure_widget->reload(); - _view->check_calibration(); - break; - - case DSV_MSG_DEVICE_DURATION_UPDATED: - _trigger_widget->device_updated(); - _view->timebase_changed(); - break; - - case DSV_MSG_DEVICE_MODE_CHANGED: - _view->mode_changed(); - reset_all_view(); - load_device_config(); - update_title_bar_text(); - _view->hide_calibration(); - - update_toolbar_view_status(); - _sampling_bar->update_sample_rate_list(); - - if (_device_agent->is_hardware()) - _session->on_load_config_end(); - - if (_device_agent->get_work_mode() == LOGIC) - _view->auto_set_max_scale(); - - if(_device_agent->is_demo()) - { - _pattern_mode = _device_agent->get_demo_operation_mode(); - _protocol_widget->del_all_protocol(); - - if(_device_agent->get_work_mode() == LOGIC) - { - if(_pattern_mode != "random"){ - _device_agent->update(); - load_demo_decoder_config(_pattern_mode); - } - } - } - - calc_min_height(); - break; - - case DSV_MSG_NEW_USB_DEVICE: + case DSV_MSG_NEW_USB_DEVICE: { if (_msg != NULL){ _msg->close(); @@ -2006,114 +2015,125 @@ namespace pv _session->set_default_device(); } - } - break; - case DSV_MSG_CURRENT_DEVICE_DETACHED: - if (_msg != NULL){ - _msg->close(); - _msg = NULL; + break; } - - // Save current config, and switch to the last device. - _session->device_event_object()->device_updated(); - save_config(); - _view->hide_calibration(); - - if (_session->is_saving()){ - dsv_info("Device detached:Waitting for store the data. and will switch to new device."); - _is_auto_switch_device = true; - return; - } - - if (confirm_to_store_data()){ - _is_auto_switch_device = true; - on_save(); - } - else{ - _session->set_default_device(); - } - break; - - case DSV_MSG_SAVE_COMPLETE: - _session->clear_store_confirm_flag(); - - if (_is_auto_switch_device) + case DSV_MSG_CURRENT_DEVICE_DETACHED: { - _is_auto_switch_device = false; - _session->set_default_device(); - } - else - { - ds_device_handle devh = _sampling_bar->get_next_device_handle(); - if (devh != NULL_HANDLE) - { - dsv_info("Auto switch to the selected device."); - _session->set_device(devh); + if (_msg != NULL){ + _msg->close(); + _msg = NULL; } - } - break; - case DSV_MSG_CLEAR_DECODE_DATA: - if (_device_agent->get_work_mode() == LOGIC) - _protocol_widget->reset_view(); - break; - - case DSV_MSG_STORE_CONF_PREV: - if (_device_agent->is_hardware() && _session->have_hardware_data() == false){ - _sampling_bar->commit_settings(); - } - break; + // Save current config, and switch to the last device. + _session->device_event_object()->device_updated(); + save_config(); + _view->hide_calibration(); - case DSV_MSG_BEGIN_DEVICE_OPTIONS: - case DSV_MSG_COLLECT_MODE_CHANGED: - if(_device_agent->is_demo()){ - _pattern_mode = _device_agent->get_demo_operation_mode(); - } - if (msg == DSV_MSG_COLLECT_MODE_CHANGED){ - _trigger_widget->device_updated(); - _view->update(); - } - break; + if (_session->is_saving()){ + dsv_info("Device detached:Waitting for store the data. and will switch to new device."); + _is_auto_switch_device = true; + return; + } - case DSV_MSG_END_DEVICE_OPTIONS: - case DSV_MSG_DEMO_OPERATION_MODE_CHNAGED: - if(_device_agent->is_demo() &&_device_agent->get_work_mode() == LOGIC){ - QString pattern_mode = _device_agent->get_demo_operation_mode(); - - if(pattern_mode != _pattern_mode) + if (confirm_to_store_data()){ + _is_auto_switch_device = true; + on_save(); + } + else{ + _session->set_default_device(); + } + break; + } + case DSV_MSG_SAVE_COMPLETE: + { + _session->clear_store_confirm_flag(); + + if (_is_auto_switch_device) { - _pattern_mode = pattern_mode; - - _device_agent->update(); - _session->clear_view_data(); - _session->init_signals(); - update_toolbar_view_status(); - _sampling_bar->update_sample_rate_list(); - _protocol_widget->del_all_protocol(); - - if(_pattern_mode != "random"){ - _session->set_collect_mode(COLLECT_SINGLE); - load_demo_decoder_config(_pattern_mode); - - if (msg == DSV_MSG_END_DEVICE_OPTIONS) - _session->start_capture(false); // Auto load data. + _is_auto_switch_device = false; + _session->set_default_device(); + } + else + { + ds_device_handle devh = _sampling_bar->get_next_device_handle(); + if (devh != NULL_HANDLE) + { + dsv_info("Auto switch to the selected device."); + _session->set_device(devh); } - } + } + break; } - calc_min_height(); - break; + case DSV_MSG_CLEAR_DECODE_DATA: + { + if (_device_agent->get_work_mode() == LOGIC) + _protocol_widget->reset_view(); + break; + } + case DSV_MSG_STORE_CONF_PREV: + { + if (_device_agent->is_hardware() && _session->have_hardware_data() == false){ + _sampling_bar->commit_settings(); + } + break; + } + case DSV_MSG_BEGIN_DEVICE_OPTIONS: + case DSV_MSG_COLLECT_MODE_CHANGED: + { + if(_device_agent->is_demo()){ + _pattern_mode = _device_agent->get_demo_operation_mode(); + } + if (msg == DSV_MSG_COLLECT_MODE_CHANGED){ + _trigger_widget->device_updated(); + _view->update(); + } + break; + } + case DSV_MSG_END_DEVICE_OPTIONS: + case DSV_MSG_DEMO_OPERATION_MODE_CHNAGED: + { + if(_device_agent->is_demo() &&_device_agent->get_work_mode() == LOGIC){ + QString pattern_mode = _device_agent->get_demo_operation_mode(); + + if(pattern_mode != _pattern_mode) + { + _pattern_mode = pattern_mode; - case DSV_MSG_APP_OPTIONS_CHANGED: - update_title_bar_text(); - break; + _device_agent->update(); + _session->clear_view_data(); + _session->init_signals(); + update_toolbar_view_status(); + _sampling_bar->update_sample_rate_list(); + _protocol_widget->del_all_protocol(); + + if(_pattern_mode != "random"){ + _session->set_collect_mode(COLLECT_SINGLE); + load_demo_decoder_config(_pattern_mode); - case DSV_MSG_FONT_OPTIONS_CHANGED: - UiManager::Instance()->Update(UI_UPDATE_ACTION_FONT); - break; - case DSV_MSG_DATA_POOL_CHANGED: - _view->check_measure(); - break; + if (msg == DSV_MSG_END_DEVICE_OPTIONS) + _session->start_capture(false); // Auto load data. + } + } + } + calc_min_height(); + break; + } + case DSV_MSG_APP_OPTIONS_CHANGED: + { + update_title_bar_text(); + break; + } + case DSV_MSG_FONT_OPTIONS_CHANGED: + { + UiManager::Instance()->Update(UI_UPDATE_ACTION_FONT); + break; + } + case DSV_MSG_DATA_POOL_CHANGED: + { + _view->check_measure(); + break; + } } }