The step 2 of code refactoring for v2.0

This commit is contained in:
dreamsourcelabTAI
2023-07-25 14:32:17 +08:00
parent e49d63690c
commit e2e8c5280f
46 changed files with 264 additions and 82 deletions
+1 -1
View File
@@ -181,7 +181,7 @@ void AppControl::remove_font_form(IFontForm *form)
void AppControl::update_font_forms()
{
for (auto f : _font_forms){
f->update_font();
f->UpdateFont();
}
}
+1 -1
View File
@@ -429,7 +429,7 @@ void MainFrame::readSettings()
AppConfig &app = AppConfig::Instance();
if (app.frameOptions.language > 0){
_mainWindow->switchLanguage(app.frameOptions.language);
_mainWindow->SwitchLanguage(app.frameOptions.language);
}
int left = app.frameOptions.left;
+2 -2
View File
@@ -238,7 +238,7 @@ namespace appcore {
// defaut language
AppConfig &app = AppConfig::Instance();
switchLanguage(app.frameOptions.language);
SwitchLanguage(app.frameOptions.language);
switchTheme(app.frameOptions.style);
retranslateUi();
@@ -1356,7 +1356,7 @@ namespace appcore {
return false;
}
void MainWindow::switchLanguage(int language)
void MainWindow::SwitchLanguage(int language)
{
if (language == 0)
return;
+1 -1
View File
@@ -139,7 +139,7 @@ signals:
public:
//IMainForm
void switchLanguage(int language) override;
void SwitchLanguage(int language) override;
bool able_to_close();
private:
+2 -5
View File
@@ -29,18 +29,15 @@
#include "signaldata.h"
namespace dsv{
namespace appcore{
namespace appcore{
class SigSession;
}
}
using namespace dsv::appcore;
namespace dsv{
namespace view{
class DsoSignal;
class dslDial;
}
}
using namespace dsv::appcore;
using namespace dsv::view;
namespace dsv {
-1
View File
@@ -23,7 +23,6 @@
#define DECODE_ROW_H
#include <vector>
#include "annotation.h"
struct srd_decoder;
+1 -1
View File
@@ -206,7 +206,7 @@ void DecoderOptionsDlg::load_options_view()
confirm_button_box->addWidget(button_box, 0, Qt::AlignRight);
form->addRow(confirm_button_box);
this->update_font();
this->UpdateFont();
int real_content_width = _content_width;
int content_height = _contentHeight;
+3 -3
View File
@@ -398,7 +398,7 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout)
enable_all_probes->setMaximumWidth(bt_width);
disable_all_probes->setMaximumWidth(bt_width);
this->update_font();
this->UpdateFont();
contentHeight += enable_all_probes->sizeHint().height();
contentHeight += channel_line_height * row2 + 50;
@@ -734,7 +734,7 @@ void DeviceOptions::analog_probes(QGridLayout &layout)
layout.addWidget(tabWidget, 0, 0, 1, 1);
this->update_font();
this->UpdateFont();
_groupHeight2 = tabWidget->sizeHint().height() + 10;
_dynamic_panel->setFixedHeight(_groupHeight2);
@@ -836,7 +836,7 @@ void DeviceOptions::build_dynamic_panel()
int bb = 0;
void DeviceOptions::try_resize_scroll()
{
this->update_font();
this->UpdateFont();
// content area height
int contentHeight = _groupHeight1 + _groupHeight2 + 20; // +space
+4 -4
View File
@@ -129,7 +129,7 @@ int DSDialog::exec()
connect(_base_button, SIGNAL(accepted()), this, SLOT(accept()));
}
update_font();
UpdateFont();
return QDialog::exec();
}
@@ -175,20 +175,20 @@ void DSDialog::build_base(bool hasClose)
_main_layout->setContentsMargins(10,5,10,10);
}
void DSDialog::update_font()
void DSDialog::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
ui::set_form_font(this, font);
if (_titlebar != NULL){
_titlebar->update_font();
_titlebar->UpdateFont();
}
}
void DSDialog::show()
{
update_font();
UpdateFont();
QWidget::show();
}
+1 -1
View File
@@ -67,7 +67,7 @@ public:
void SetTitleSpace(int h);
//IFontForm
void update_font() override;
void UpdateFont() override;
void show();
+1 -1
View File
@@ -136,7 +136,7 @@ int DSMessageBox::exec()
ui::set_form_font(this, font);
if (_titlebar != NULL){
_titlebar->update_font();
_titlebar->UpdateFont();
}
return QDialog::exec();
+2 -2
View File
@@ -173,7 +173,7 @@ DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession *session) :
retranslateUi();
update_font();
UpdateFont();
}
DsoTriggerDock::~DsoTriggerDock()
@@ -488,7 +488,7 @@ void DsoTriggerDock::update_view()
connect(_margin_slider, SIGNAL(valueChanged(int)), this, SLOT(margin_changed(int)));
}
void DsoTriggerDock::update_font()
void DsoTriggerDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -63,7 +63,7 @@ private:
bool check_trig_channel();
//IFontForm
void update_font() override;
void UpdateFont() override;
signals:
void set_trig_pos(int percent);
+2 -2
View File
@@ -150,7 +150,7 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) :
connect(_fen_checkBox, SIGNAL(stateChanged(int)), &_view, SLOT(set_measure_en(int)));
connect(&_view, SIGNAL(measure_updated()), this, SLOT(measure_updated()));
update_font();
UpdateFont();
}
MeasureDock::~MeasureDock()
@@ -827,7 +827,7 @@ void MeasureDock::del_cursor()
_view.update();
}
void MeasureDock::update_font()
void MeasureDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -94,7 +94,7 @@ private:
void reStyle();
//IFontForm
void update_font() override;
void UpdateFont() override;
void build_dist_pannel();
void build_edge_pannel();
+3 -3
View File
@@ -226,7 +226,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
connect(_pro_search_button, SIGNAL(clicked()), this, SLOT(show_protocol_select()));
update_font();
UpdateFont();
}
ProtocolDock::~ProtocolDock()
@@ -1041,7 +1041,7 @@ bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const Decod
}
}
void ProtocolDock::update_font()
void ProtocolDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
@@ -1049,7 +1049,7 @@ bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const Decod
_table_view->setFont(font);
for(auto lay : _protocol_lay_items){
lay->update_font();
lay->UpdateFont();
}
font.setPointSizeF(font.pointSizeF() + 1);
+1 -1
View File
@@ -120,7 +120,7 @@ private:
void update_deocder_item_name(void *trace_handel, const char *name) override;
//IFontForm
void update_font() override;
void UpdateFont() override;
signals:
void protocol_updated();
+1 -1
View File
@@ -73,7 +73,7 @@ ProtocolItemLayer::ProtocolItemLayer(QWidget *parent, QString protocolName, IPro
connect(_set_button, SIGNAL(clicked()),this, SLOT(on_set_protocol()));
connect(_format_combox, SIGNAL(currentIndexChanged(int)),this, SLOT(on_format_select_changed(int)));
update_font();
UpdateFont();
}
ProtocolItemLayer::~ProtocolItemLayer(){
+1 -1
View File
@@ -71,7 +71,7 @@ public:
void set_label_name(QString name);
void update_font();
void UpdateFont();
private slots:
void on_set_protocol();
+2 -2
View File
@@ -85,7 +85,7 @@ SearchDock::SearchDock(QWidget *parent, View &view, SigSession *session) :
retranslateUi();
update_font();
UpdateFont();
connect(&_pre_button, SIGNAL(clicked()), this, SLOT(on_previous()));
connect(&_nxt_button, SIGNAL(clicked()),this, SLOT(on_next()));
@@ -254,7 +254,7 @@ void SearchDock::on_set()
}
}
void SearchDock::update_font()
void SearchDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -76,7 +76,7 @@ private:
void reStyle();
//IFontForm
void update_font() override;
void UpdateFont() override;
public slots:
void on_previous();
+2 -2
View File
@@ -134,7 +134,7 @@ TriggerDock::TriggerDock(QWidget *parent, SigSession *session) :
retranslateUi();
update_font();
UpdateFont();
}
TriggerDock::~TriggerDock()
@@ -1072,7 +1072,7 @@ void TriggerDock::on_serial_hex_changed()
_is_serial_val_setting = false;
}
void TriggerDock::update_font()
void TriggerDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -90,7 +90,7 @@ private:
bool commit_trigger();
//IFontForm
void update_font() override;
void UpdateFont() override;
private slots:
void simple_trigger();
-11
View File
@@ -59,11 +59,6 @@ public:
virtual void OnDlgResult(bool bYes)=0;
};
class IMainForm{
public:
virtual void switchLanguage(int language)=0;
};
#define DSV_MSG_START_COLLECT_WORK_PREV 5001
#define DSV_MSG_START_COLLECT_WORK 5002
@@ -108,10 +103,4 @@ public:
virtual void update_deocder_item_name(void *trace_handel, const char *name)=0;
};
class IFontForm
{
public:
virtual void update_font()=0;
};
#endif
+2 -2
View File
@@ -96,7 +96,7 @@ FileBar::FileBar(SigSession *session, QWidget *parent) :
connect(_action_export, SIGNAL(triggered()), this, SIGNAL(sig_export()));
connect(_action_capture, SIGNAL(triggered()), this, SLOT(on_actionCapture_triggered()));
update_font();
UpdateFont();
}
void FileBar::changeEvent(QEvent *event)
@@ -256,7 +256,7 @@ void FileBar::update_view_status()
_menu_session->setEnabled(bEnable && is_hardware);
}
void FileBar::update_font()
void FileBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -58,7 +58,7 @@ private:
void reStyle();
//IFontForm
void update_font() override;
void UpdateFont() override;
signals:
void sig_load_file(QString);
+4 -4
View File
@@ -124,7 +124,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
connect(_update, SIGNAL(triggered()), this, SLOT(on_action_update()));
connect(_log, SIGNAL(triggered()), this, SLOT(on_action_setting_log()));
update_font();
UpdateFont();
}
void LogoBar::changeEvent(QEvent *event)
@@ -188,7 +188,7 @@ void LogoBar::on_actionEn_triggered()
QIcon(":/icons/English.svg")));
assert(_mainForm);
_mainForm->switchLanguage(LAN_EN);
_mainForm->SwitchLanguage(LAN_EN);
}
void LogoBar::on_actionCn_triggered()
@@ -196,7 +196,7 @@ void LogoBar::on_actionCn_triggered()
_language->setIcon(QIcon::fromTheme("file",
QIcon(":/icons/Chinese.svg")));
assert(_mainForm);
_mainForm->switchLanguage(LAN_CN);
_mainForm->SwitchLanguage(LAN_CN);
}
void LogoBar::on_actionAbout_triggered()
@@ -348,7 +348,7 @@ void LogoBar::on_clear_log_file()
}
}
void LogoBar::update_font()
void LogoBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -65,7 +65,7 @@ private:
void reStyle();
//IFontForm
void update_font() override;
void UpdateFont() override;
signals:
//post event message to open user help document, MainWindow class receive it
+2 -2
View File
@@ -130,7 +130,7 @@ namespace dsv
_instant_action = addWidget(&_instant_button);
update_view_status();
update_font();
UpdateFont();
connect(&_device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(on_device_selected()));
connect(&_configure_button, SIGNAL(clicked()), this, SLOT(on_configure()));
@@ -1257,7 +1257,7 @@ namespace dsv
on_instant_stop();
}
void SamplingBar::update_font()
void SamplingBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -129,7 +129,7 @@ namespace toolbars{
bool action_instant_stop();
//IFontForm
void update_font() override;
void UpdateFont() override;
private slots:
void on_collect_mode();
+2 -2
View File
@@ -93,7 +93,7 @@ TitleBar::TitleBar(bool top, QWidget *parent, bool hasClose) :
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
update_font();
UpdateFont();
}
TitleBar::~TitleBar(){
@@ -238,7 +238,7 @@ void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
QWidget::mouseDoubleClickEvent(event);
}
void TitleBar::update_font()
void TitleBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -44,7 +44,7 @@ public:
QString title();
//IFontForm
void update_font() override;
void UpdateFont() override;
private:
void changeEvent(QEvent *event);
+2 -2
View File
@@ -123,7 +123,7 @@ TrigBar::TrigBar(SigSession *session, QWidget *parent) :
connect(_light_style, SIGNAL(triggered()), this, SLOT(on_actionLight_triggered()));
connect(_action_dispalyOptions, SIGNAL(triggered()), this, SLOT(on_display_setting()));
update_font();
UpdateFont();
}
//语言变化
@@ -371,7 +371,7 @@ void TrigBar::update_checked_status()
_search_button.setChecked(opt->searchDock);
}
void TrigBar::update_font()
void TrigBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -64,7 +64,7 @@ private:
void update_checked_status();
//IFontForm
void update_font() override;
void UpdateFont() override;
signals:
void sig_setTheme(QString style);
@@ -2,7 +2,7 @@
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
* Copyright (C) 2023 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,14 +19,17 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef STRING_IDS_H
#define STRING_IDS_H
#ifndef LANG_PAGE_IDS_H
#define LANG_PAGE_IDS_H
/**
* Language resource page code.
*/
#define STR_PAGE_MSG 1
#define STR_PAGE_TOOLBAR 2
#define STR_PAGE_DLG 3
#define STR_PAGE_DSL 100
#define STR_PAGE_DECODER 101
#define IDS_MSG_LOG_LEVEL
#endif
+84
View File
@@ -0,0 +1,84 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2023 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "langitemlist.h"
#include <assert.h>
#include "langresource.h"
LangItemList::LangItemList()
{
}
LangItemList::~LangItemList()
{
Clear();
}
void LangItemList::Clear()
{
for(auto it = m_items.begin(); it != m_items.end(); it++)
{
delete (*it).setter;
}
m_items.clear();
}
void LangItemList::AddItem(int page_id, const char *key_id, const char *defaultStr, ILangSetter *setter)
{
assert(key_id);
assert(defaultStr);
assert(setter);
LangItemInfo item = {page_id, key_id, defaultStr, setter};
m_items.push_back(item);
}
void LangItemList::RemoveItemBySetterHandle(void *setterHandle)
{
assert(setterHandle);
for(auto it = m_items.begin(); it != m_items.end(); it++)
{
if ((*it).setter->GetControlHandle() == setterHandle){
m_items.erase(it);
break;
}
}
}
void LangItemList::LoadAllText()
{
for(auto it = m_items.begin(); it != m_items.end(); it++)
{
int page_id = (*it).lang_page_id;
const char *key_id = (*it).key_id;
const char *def_str = (*it).default_str;
ILangSetter *setter = (*it).setter;
const char *str = LangResource::Instance()->get_lang_text(page_id, key_id, def_str);
if (str == NULL){
str = def_str;
}
setter->SetLangText(str);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2023 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LANG_ITEM_LIST_H
#define LANG_ITEM_LIST_H
#include <vector>
#include "uitypes.h"
#include "lang_page_ids.h"
struct LangItemInfo
{
int lang_page_id;
const char *key_id;
const char *default_str;
ILangSetter *setter;
};
class LangItemList
{
public:
LangItemList();
~LangItemList();
void Clear();
void AddItem(int page_id, const char *key_id, const char *defaultStr, ILangSetter *setter);
void RemoveItemBySetterHandle(void *setterHandle);
void LoadAllText();
private:
std::vector<LangItemInfo> m_items;
};
#endif
@@ -27,7 +27,7 @@
#include <QString>
#include <string>
#include <mutex>
#include "string_ids.h"
#include "lang_page_ids.h"
struct lang_key_item
{
+55
View File
@@ -0,0 +1,55 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2023 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef UICORE_UI_TYPES_H
#define UICORE_UI_TYPES_H
class ILangSetter
{
public:
virtual void SetLangText(const char *szText)=0;
virtual void* GetControlHandle()=0;
};
class ILangForm
{
public:
virtual void LoadLangText()=0;
};
class IFontForm
{
public:
virtual void UpdateFont()=0;
};
class IMainForm
{
public:
virtual void SwitchLanguage(int language)=0;
virtual void AddLangForm(ILangForm *form)=0;
virtual void RemoveLangForm(ILangForm *form)=0;
virtual void AddFontForm(IFontForm *form)=0;
virtual void RemoveFontForm(IFontForm *form)=0;
virtual void UpdateAllFontForm()=0;
};
#endif
+4 -4
View File
@@ -89,7 +89,7 @@ DevMode::DevMode(QWidget *parent, SigSession *session) :
layout->setStretch(1, 100);
setLayout(layout);
update_font();
UpdateFont();
connect(_close_button, SIGNAL(clicked()), this, SLOT(on_close()));
}
@@ -172,7 +172,7 @@ void DevMode::set_device()
_bFile = true;
}
update_font();
UpdateFont();
update();
}
@@ -231,7 +231,7 @@ void DevMode::on_mode_change()
}
}
update_font();
UpdateFont();
}
void DevMode::on_close()
@@ -279,7 +279,7 @@ const struct dev_mode_name* DevMode::get_mode_name(int mode)
assert(false);
}
void DevMode::update_font()
void DevMode::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -72,7 +72,7 @@ private:
const struct dev_mode_name* get_mode_name(int mode);
//IFontForm
void update_font() override;
void UpdateFont() override;
public slots:
void set_device();
+1 -1
View File
@@ -1339,7 +1339,7 @@ int View::get_body_height()
_time_viewport->update();
}
void View::update_font()
void View::UpdateFont()
{
headerWidth();
}
+1 -1
View File
@@ -320,7 +320,7 @@ public:
}
//IFontForm
void update_font() override;
void UpdateFont() override;
signals:
void hover_point_changed();
+2 -2
View File
@@ -106,7 +106,7 @@ Viewport::Viewport(View &parent, View_type type) :
_xAction = xAction;
setContextMenuPolicy(Qt::CustomContextMenu);
this->update_font();
this->UpdateFont();
connect(&_trigger_timer, SIGNAL(timeout()),this, SLOT(on_trigger_timer()));
connect(&_drag_timer, SIGNAL(timeout()),this, SLOT(on_drag_timer()));
@@ -2001,7 +2001,7 @@ void Viewport::add_cursor_x()
_view.show_xcursors(true);
}
void Viewport::update_font()
void Viewport::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
+1 -1
View File
@@ -116,7 +116,7 @@ public:
void update_lang();
//IFontForm
void update_font() override;
void UpdateFont() override;
protected:
bool event(QEvent *event) override;