2
0
forked from Ivasoft/DSView

Code refactoring 20

This commit is contained in:
dreamsourcelabTAI
2022-09-20 17:49:32 +08:00
parent 7376115bf5
commit cec8dade5e
18 changed files with 1185 additions and 1058 deletions

View File

@@ -891,9 +891,9 @@ void TriggerDock::lineEdit_highlight(QLineEdit *dst) {
}
void TriggerDock::try_commit_trigger()
{
int i;
AppConfig &app = AppConfig::Instance();
{
AppConfig &app = AppConfig::Instance();
int num = 0;
int mode = _session->get_device()->get_work_mode();
bool bInstant = _session->is_instant();
@@ -904,7 +904,7 @@ void TriggerDock::try_commit_trigger()
return;
}
if (this->commit_trigger() == false)
if (commit_trigger() == false)
{
/* simple trigger check trigger_enable */
for(auto &s : _session->get_signals())
@@ -913,11 +913,11 @@ void TriggerDock::try_commit_trigger()
view::LogicSignal *logicSig = NULL;
if ((logicSig = dynamic_cast<view::LogicSignal*>(s))) {
if (logicSig->commit_trig())
i++;
num++;
}
}
if (app._appOptions.warnofMultiTrig && i > 1) {
if (app._appOptions.warnofMultiTrig && num > 1) {
dialogs::DSMessageBox msg(this);
msg.mBox()->setText(tr("Trigger"));
msg.mBox()->setInformativeText(tr("Trigger setted on multiple channels! "

View File

@@ -273,8 +273,22 @@ namespace pv
connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int)));
_logo_bar->set_mainform_callback(this);
_session->set_default_device();
// Try load from file.
QString ldFileName(AppControl::Instance()->_open_file_name.c_str());
if (ldFileName != ""){
if (QFile::exists(ldFileName)){
dsv_info("auto load file:%s", ldFileName.toUtf8().data());
on_load_file(ldFileName);
}
else{
dsv_err("file is not exists:%s", ldFileName.toUtf8().data());
MsgBox::Show(tr("Open file error!"), ldFileName, NULL);
}
}
else{
_session->set_default_device();
}
}
void MainWindow::retranslateUi()
@@ -322,10 +336,7 @@ namespace pv
on_load_session(ses_name);
}
}
_trig_bar->restore_status();
//load specified file name from application startup param
@@ -402,7 +413,7 @@ namespace pv
break;
case SigSession::Test_data_err:
_session->stop_capture();
_sampling_bar->set_sampling(false);
_sampling_bar->update_view_status();
title = tr("Data Error");
error_pattern = _session->get_error_pattern();
@@ -1329,6 +1340,20 @@ namespace pv
_session->broadcast_msg(msg);
}
void MainWindow::reset_all_view()
{
_sampling_bar->reload();
_view->status_clear();
_view->reload();
_view->set_device();
_trigger_widget->init();
_trigger_widget->device_updated();
_trig_bar->reload();
_trig_bar->restore_status();
_dso_trigger_widget->init();
_measure_widget->reload();
}
void MainWindow::OnMessage(int msg)
{
switch (msg)
@@ -1343,12 +1368,16 @@ namespace pv
break;
case DSV_MSG_START_COLLECT_WORK:
_sampling_bar->set_sampling(false);
_sampling_bar->update_view_status();
_file_bar->update_view_status();
_trig_bar->update_view_status();
break;
case DSV_MSG_END_COLLECT_WORK:
_session->device_event_object()->device_updated();
_sampling_bar->set_sampling(true);
_sampling_bar->update_view_status();
_file_bar->update_view_status();
_trig_bar->update_view_status();
break;
case DSV_MSG_NEW_USB_DEVICE:
@@ -1360,17 +1389,9 @@ namespace pv
_msg->close();
_msg = NULL;
}
_sampling_bar->update_device_list();
_view->reload();
_view->set_device();
_trig_bar->reload();
_sampling_bar->reload();
_view->status_clear();
_trigger_widget->init();
_dso_trigger_widget->init();
_measure_widget->reload();
_trigger_widget->device_updated();
reset_all_view();
break;
case DSV_MSG_CURRENT_DEVICE_CHANGE_PREV:
@@ -1390,7 +1411,8 @@ namespace pv
break;
case DSV_MSG_DEVICE_MODE_CHANGED:
_view->mode_changed();
_view->mode_changed();
reset_all_view();
break;
case DSV_MSG_CURRENT_DEVICE_DETACHED:

View File

@@ -143,6 +143,7 @@ public:
private:
void check_usb_device_speed();
void reset_all_view();
private:
//ISessionCallback

View File

@@ -368,7 +368,8 @@ void SigSession::capture_init()
_trigger_ch = 0;
_hw_replied = false;
if (_device_agent.get_work_mode() != LOGIC)
int work_mode = _device_agent.get_work_mode();
if (work_mode == DSO || work_mode == ANALOG)
_feed_timer.Start(FeedInterval);
else
_feed_timer.Stop();
@@ -591,7 +592,8 @@ void SigSession::check_update()
_data_updated = false;
_noData_cnt = 0;
data_auto_unlock();
} else {
}
else {
if (++_noData_cnt >= (WaitShowTime/FeedInterval))
nodata_timeout();
}
@@ -1105,6 +1107,8 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
assert(packet);
ds_lock_guard lock(_data_mutex);
// dsv_info("%s", "Receive data.");
if (_data_lock && packet->type != SR_DF_END)
return;
@@ -1156,9 +1160,8 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
break;
}
case SR_DF_END:
{
if (!_logic_data->snapshot()->empty())
{
{
if (!_logic_data->snapshot()->empty()){
for (auto &g : _group_traces)
{
assert(g);
@@ -1505,6 +1508,7 @@ void SigSession::nodata_timeout()
void SigSession::feed_timeout()
{
data_unlock();
if (!_data_updated) {
if (++_noData_cnt >= (WaitShowTime/FeedInterval))
nodata_timeout();
@@ -1555,7 +1559,7 @@ void SigSession::set_repeat_intvl(double interval)
}
bool SigSession::repeat_check()
{
{
if (!_is_working) {
return false;
}
@@ -1819,14 +1823,28 @@ void SigSession::Close()
void SigSession::on_device_lib_event(int event)
{
if (_callback == NULL){
dsv_info("%s", "The callback is null, so the device event was ignored.");
return;
}
switch (event)
{
case DS_EV_DEVICE_RUNNING:
_device_status = ST_RUNNING;
receive_data(0);
break;
case DS_EV_DEVICE_STOPPED:
_device_status = ST_STOPPED;
// Confirm that SR_DF_END was received
if (!_logic_data->snapshot()->last_ended()
|| !_dso_data->snapshot()->last_ended()
|| !_analog_data->snapshot()->last_ended())
{
dsv_err("%s", "Error!The data is not completed.");
assert(false);
}
break;
case DS_EV_COLLECT_TASK_START:
@@ -1967,5 +1985,10 @@ void SigSession::on_device_lib_event(int event)
}
void SigSession::on_work_mode_changed()
{
init_signals();
}
} // namespace pv

View File

@@ -296,6 +296,7 @@ public:
struct ds_device_info* get_device_list(int &out_count, int &actived_index);
void add_msg_listener(IMessageListener *ln);
void broadcast_msg(int msg);
void on_work_mode_changed();
private:
bool exec_capture();
@@ -329,7 +330,7 @@ private:
void repeat_update();
void container_init();
void init_signals();
//IMessageListener
void OnMessage(int msg);

View File

@@ -36,7 +36,6 @@ namespace toolbars {
FileBar::FileBar(SigSession *session, QWidget *parent) :
QToolBar("File Bar", parent),
_enable(true),
_session(session),
_file_button(this)
{
@@ -232,14 +231,11 @@ void FileBar::on_actionCapture_triggered()
QTimer::singleShot(100, this, SIGNAL(sig_screenShot()));
}
void FileBar::enable_toggle(bool enable)
void FileBar::update_view_status()
{
_file_button.setDisabled(!enable);
}
void FileBar::set_settings_en(bool enable)
{
_menu_session->setDisabled(!enable);
bool bEnable = _session->is_working() == false;
_file_button.setEnabled(bEnable);
_menu_session->setEnabled(bEnable);
}
} // namespace toolbars

View File

@@ -42,14 +42,12 @@ class FileBar : public QToolBar
public:
explicit FileBar(SigSession *session, QWidget *parent = 0);
void enable_toggle(bool enable);
void set_settings_en(bool enable);
void update_view_status();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
void reStyle();
signals:
void sig_load_file(QString);
@@ -67,18 +65,14 @@ private slots:
void on_actionCapture_triggered();
private:
bool _enable;
SigSession* _session;
QToolButton _file_button;
QMenu *_menu;
QMenu *_menu_session; //when the hardware device is connected,it will be enable
QMenu *_menu;
QMenu *_menu_session; //when the hardware device is connected,it will be enable
QAction *_action_load;
QAction *_action_store;
QAction *_action_default;
QAction *_action_open;
QAction *_action_save;
QAction *_action_export;

File diff suppressed because it is too large Load Diff

View File

@@ -76,23 +76,18 @@ namespace pv
public:
SamplingBar(SigSession *session, QWidget *parent);
void enable_toggle(bool enable);
void enable_instant(bool enable);
SamplingBar(SigSession *session, QWidget *parent);
double hori_knob(int dir);
double commit_hori_res();
double get_hori_res();
void set_sample_rate(uint64_t sample_rate);
void update_device_list();
void reload();
void set_sampling(bool sampling);
void reload();
void update_view_status();
void config_device();
private:
void enable_run_stop(bool enable);
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
@@ -103,6 +98,7 @@ namespace pv
void update_sample_count_selector_value();
void commit_settings();
void setting_adj();
void enable_toggle(bool enable);
private slots:
void on_mode();
@@ -116,32 +112,33 @@ namespace pv
private:
SigSession *_session;
QToolButton _device_type;
DsComboBox _device_selector;
QToolButton _configure_button;
DsComboBox _sample_count;
DsComboBox _sample_rate;
SigSession *_session;
DsComboBox _device_selector;
DsComboBox _sample_count;
DsComboBox _sample_rate;
bool _updating_sample_rate;
bool _updating_sample_count;
bool _updating_device_list;
QToolButton _device_type;
QToolButton _configure_button;
QToolButton _run_stop_button;
QToolButton _instant_button;
QToolButton _mode_button;
QAction *_run_stop_action;
QAction *_instant_action;
QAction *_mode_action;
QToolButton _mode_button;
QMenu *_mode_menu;
QAction *_action_repeat;
QAction *_action_single;
DeviceAgent *_device_agent;
ds_device_handle _last_device_handle;
bool _is_run_as_instant;
};
} // namespace toolbars

View File

@@ -241,21 +241,6 @@ void TrigBar::search_clicked()
AppConfig::Instance().SaveFrame();
}
void TrigBar::enable_toggle(bool enable)
{
_trig_button.setDisabled(!enable);
_protocol_button.setDisabled(!enable);
_measure_button.setDisabled(!enable);
_search_button.setDisabled(!enable);
_function_button.setDisabled(!enable);
_setting_button.setDisabled(!enable);
}
void TrigBar::enable_protocol(bool enable)
{
_protocol_button.setDisabled(!enable);
}
void TrigBar::close_all()
{
if (_trig_button.isChecked()) {
@@ -310,8 +295,8 @@ void TrigBar::reload()
_action_dispalyOptions->setVisible(false);
}
enable_toggle(true);
update();
update_view_status();
update();
}
void TrigBar::on_actionFft_triggered()
@@ -384,7 +369,7 @@ void TrigBar::restore_status()
AppConfig &app = AppConfig::Instance();
int mode = _session->get_device()->get_work_mode();
if (mode == LOGIC)
if (mode == LOGIC)
return &app._frameOptions._logicDock;
else if (mode == DSO)
return &app._frameOptions._dsoDock;
@@ -392,5 +377,17 @@ void TrigBar::restore_status()
return &app._frameOptions._analogDock;
}
void TrigBar::update_view_status()
{
bool bEnable = _session->is_working() == false;
_trig_button.setEnabled(bEnable);
_protocol_button.setEnabled(bEnable);
_measure_button.setEnabled(bEnable);
_search_button.setEnabled(bEnable);
_function_button.setEnabled(bEnable);
_setting_button.setEnabled(bEnable);
}
} // namespace toolbars
} // namespace pv

View File

@@ -46,16 +46,15 @@ class TrigBar : public QToolBar
public:
explicit TrigBar(SigSession *session, QWidget *parent = 0);
void enable_toggle(bool enable);
void enable_protocol(bool enable);
void close_all();
void reload();
void update_view_status();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
DockOptions* getDockOptions();
DockOptions* getDockOptions();
signals:
void sig_setTheme(QString style);

View File

@@ -197,12 +197,14 @@ void DevMode::on_mode_change()
{
if ((*i).first == action) {
if (_device_agent->get_work_mode() != (*i).second->mode) {
_session->stop_capture();
_session->set_repeat_mode(false);
_session->stop_capture();
_session->session_save();
_device_agent->set_config(NULL, NULL,
SR_CONF_DEVICE_MODE,
g_variant_new_int16((*i).second->mode));
_session->on_work_mode_changed();
auto *mode_name = get_mode_name((*i).second->mode);
QString icon_fname = iconPath + "/" + QString::fromLocal8Bit(mode_name->_logo);

View File

@@ -42,9 +42,9 @@ const int LogicSignal::StateRound = 5;
LogicSignal::LogicSignal(data::Logic *data,
sr_channel *probe) :
Signal(probe),
_data(data),
_trig(NONTRIG)
_data(data)
{
_trig = NONTRIG;
}
LogicSignal::LogicSignal(view::LogicSignal *s,
@@ -96,7 +96,8 @@ bool LogicSignal::commit_trig()
if (_trig == NONTRIG) {
ds_trigger_probe_set(_index_list.front(), 'X', 'X');
return false;
} else {
}
else {
ds_trigger_set_en(true);
if (_trig == POSTRIG)
ds_trigger_probe_set(_index_list.front(), 'R', 'X');

View File

@@ -479,8 +479,6 @@ void View::repeat_unshow()
void View::frame_began()
{
// if (_device_agent->get_work_mode() == LOGIC)
// _viewbottom->set_trig_time(_session->get_session_time());
_search_hit = false;
_search_pos = 0;
set_search_pos(_search_pos, _search_hit);
@@ -866,6 +864,7 @@ void View::resizeEvent(QResizeEvent*)
update_margins();
update_scroll();
signals_changed();
if (_device_agent->get_work_mode() == DSO)
_scale = _session->cur_view_time() / get_view_width();

View File

@@ -44,6 +44,7 @@
#include "../config/appconfig.h"
#include "../dsvdef.h"
#include "../appcontrol.h"
#include "../log.h"
using namespace std;
@@ -89,6 +90,7 @@ Viewport::Viewport(View &parent, View_type type) :
transfer_started = false;
timer_cnt = 0;
_clickX = 0;
_sample_received = 0;
// drag inertial
_drag_strength = 0;
@@ -1196,7 +1198,8 @@ void Viewport::set_receive_len(quint64 length)
if (length == 0) {
_sample_received = 0;
start_trigger_timer(333);
} else {
}
else {
stop_trigger_timer();
if (_sample_received + length > _view.session().cur_samplelimits())
_sample_received = _view.session().cur_samplelimits();