From 47125dc1ee8649cf998e567de8feaa67996c8077 Mon Sep 17 00:00:00 2001 From: dreamsource-tai Date: Fri, 26 Jul 2024 11:32:46 +0800 Subject: [PATCH] Resolve the issue of UI garbled formatting in certain regions. --- CMakeLists.txt | 2 ++ DSView/pv/dialogs/deviceoptions.cpp | 2 -- DSView/pv/dialogs/interval.cpp | 5 ++- DSView/pv/dialogs/interval.h | 3 +- DSView/pv/dialogs/protocolexp.cpp | 5 ++- DSView/pv/dock/dsotriggerdock.h | 1 - DSView/pv/dock/keywordlineedit.cpp | 1 + DSView/pv/dock/keywordlineedit.h | 1 - DSView/pv/dock/measuredock.h | 1 - DSView/pv/dock/searchdock.h | 1 - DSView/pv/dock/triggerdock.h | 1 - DSView/pv/mainwindow.cpp | 4 ++- DSView/pv/prop/double.cpp | 9 +++-- DSView/pv/prop/int.cpp | 8 ++--- DSView/pv/prop/string.cpp | 7 ++-- DSView/pv/storesession.cpp | 13 ++++--- DSView/pv/ui/xspinbox.cpp | 56 +++++++++++++++++++++++++++++ DSView/pv/ui/xspinbox.h | 43 ++++++++++++++++++++++ DSView/pv/utility/formatting.cpp | 49 +++++++++++++++++++++++++ DSView/pv/utility/formatting.h | 36 +++++++++++++++++++ DSView/pv/view/viewstatus.cpp | 7 ++-- 21 files changed, 219 insertions(+), 36 deletions(-) create mode 100644 DSView/pv/ui/xspinbox.cpp create mode 100644 DSView/pv/ui/xspinbox.h create mode 100644 DSView/pv/utility/formatting.cpp create mode 100644 DSView/pv/utility/formatting.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b8cf57d..ab660383 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,6 +351,8 @@ set(DSView_SOURCES DSView/pv/ui/xtoolbutton.cpp DSView/pv/ui/uimanager.cpp DSView/pv/ui/popupdlglist.cpp + DSView/pv/ui/xspinbox.cpp + DSView/pv/utility/formatting.cpp ) set(DSView_HEADERS diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index 53d843e6..7d4ae1c4 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -23,8 +23,6 @@ #include "deviceoptions.h" #include -#include -#include #include #include #include diff --git a/DSView/pv/dialogs/interval.cpp b/DSView/pv/dialogs/interval.cpp index f9bdec2d..d4fa7749 100644 --- a/DSView/pv/dialogs/interval.cpp +++ b/DSView/pv/dialogs/interval.cpp @@ -20,10 +20,9 @@ */ #include "interval.h" - #include - #include "../ui/langresource.h" +#include "../ui/xspinbox.h" namespace pv { namespace dialogs { @@ -41,7 +40,7 @@ Interval::Interval(QWidget *parent) : setMinimumWidth(300); _interval_label = new QLabel(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_INTERVAL_S), "Interval(s): "), this); - _interval_spinBox = new QDoubleSpinBox(this); + _interval_spinBox = new XDoubleSpinBox(this); _interval_spinBox->setRange(0.1, 10); _interval_spinBox->setDecimals(1); _interval_spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons); diff --git a/DSView/pv/dialogs/interval.h b/DSView/pv/dialogs/interval.h index 825c0330..05fb7bca 100644 --- a/DSView/pv/dialogs/interval.h +++ b/DSView/pv/dialogs/interval.h @@ -24,7 +24,6 @@ #define DSVIEW_PV_INTERVAL_H #include -#include #include #include @@ -32,6 +31,8 @@ #include "../toolbars/titlebar.h" #include "dsdialog.h" +class QDoubleSpinBox; + namespace pv { namespace dialogs { diff --git a/DSView/pv/dialogs/protocolexp.cpp b/DSView/pv/dialogs/protocolexp.cpp index e3f0cb9b..f65d8e31 100644 --- a/DSView/pv/dialogs/protocolexp.cpp +++ b/DSView/pv/dialogs/protocolexp.cpp @@ -44,6 +44,7 @@ #include "../log.h" #include "../ui/langresource.h" #include "../ui/msgbox.h" + #include "../utility/formatting.h" #define EXPORT_DEC_ROW_COUNT_MAX 20 @@ -166,7 +167,9 @@ void ProtocolExp::onAccept() AppConfig &app = AppConfig::Instance(); QString default_filter = _format_combobox->currentText(); QString default_name = app.userHistory.protocolExportPath + "/" + "decoder-"; - default_name += _session->get_session_time().toString("-yyMMdd-hhmmss"); + + QString dateTimeString = Formatting::DateTimeToString(_session->get_session_time(), TimeStrigFormatType::TIME_STR_FORMAT_SHORT2); + default_name += "-" + dateTimeString; QString file_name = QFileDialog::getSaveFileName( this, diff --git a/DSView/pv/dock/dsotriggerdock.h b/DSView/pv/dock/dsotriggerdock.h index 77c3323d..2ef8a253 100644 --- a/DSView/pv/dock/dsotriggerdock.h +++ b/DSView/pv/dock/dsotriggerdock.h @@ -24,7 +24,6 @@ #include #include -#include #include #include #include diff --git a/DSView/pv/dock/keywordlineedit.cpp b/DSView/pv/dock/keywordlineedit.cpp index aef003ec..2c2e4722 100644 --- a/DSView/pv/dock/keywordlineedit.cpp +++ b/DSView/pv/dock/keywordlineedit.cpp @@ -22,6 +22,7 @@ #include "keywordlineedit.h" #include #include +#include #include "../config/appconfig.h" #include "../ui/langresource.h" #include "../log.h" diff --git a/DSView/pv/dock/keywordlineedit.h b/DSView/pv/dock/keywordlineedit.h index 93b50cb8..414073cc 100644 --- a/DSView/pv/dock/keywordlineedit.h +++ b/DSView/pv/dock/keywordlineedit.h @@ -27,7 +27,6 @@ #include #include #include -#include #include class IKeywordActive{ diff --git a/DSView/pv/dock/measuredock.h b/DSView/pv/dock/measuredock.h index 6a4821ce..4e19a2ae 100644 --- a/DSView/pv/dock/measuredock.h +++ b/DSView/pv/dock/measuredock.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/DSView/pv/dock/searchdock.h b/DSView/pv/dock/searchdock.h index ff71acf9..08e1fb40 100644 --- a/DSView/pv/dock/searchdock.h +++ b/DSView/pv/dock/searchdock.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include diff --git a/DSView/pv/dock/triggerdock.h b/DSView/pv/dock/triggerdock.h index 4248c312..c1e16bd7 100644 --- a/DSView/pv/dock/triggerdock.h +++ b/DSView/pv/dock/triggerdock.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 5ba86a0c..74dc348b 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -43,6 +43,7 @@ #include #include #include +#include "utility/formatting.h" //include with qt5 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -525,7 +526,8 @@ namespace pv void MainWindow::on_screenShot() { AppConfig &app = AppConfig::Instance(); - QString default_name = app.userHistory.screenShotPath + "/" + APP_NAME + QDateTime::currentDateTime().toString("-yyMMdd-hhmmss"); + QString dateTimeString = Formatting::DateTimeToString(QDateTime::currentDateTime(), TimeStrigFormatType::TIME_STR_FORMAT_SHORT2); + QString default_name = app.userHistory.screenShotPath + "/" + APP_NAME + "-" + dateTimeString; int x = parentWidget()->pos().x(); int y = parentWidget()->pos().y(); diff --git a/DSView/pv/prop/double.cpp b/DSView/pv/prop/double.cpp index b5c7c3d7..2672f87b 100644 --- a/DSView/pv/prop/double.cpp +++ b/DSView/pv/prop/double.cpp @@ -20,11 +20,10 @@ */ -#include - -#include - #include "double.h" +#include +#include "../ui/xspinbox.h" + using namespace std; using namespace boost; @@ -57,7 +56,7 @@ QWidget* Double::get_widget(QWidget *parent, bool auto_commit) if (_spin_box) return _spin_box; - _spin_box = new QDoubleSpinBox(parent); + _spin_box = new XDoubleSpinBox(parent); _spin_box->setDecimals(_decimals); _spin_box->setSuffix(_suffix); if (_range) diff --git a/DSView/pv/prop/int.cpp b/DSView/pv/prop/int.cpp index 3648193d..c6e9f60c 100644 --- a/DSView/pv/prop/int.cpp +++ b/DSView/pv/prop/int.cpp @@ -20,13 +20,11 @@ */ +#include "int.h" #include #include #include - -#include - -#include "int.h" +#include "../ui/xspinbox.h" using boost::optional; using namespace std; @@ -82,7 +80,7 @@ QWidget* Int::get_widget(QWidget *parent, bool auto_commit) if (!_value) return NULL; - _spin_box = new QSpinBox(parent); + _spin_box = new XSpinBox(parent); _spin_box->setSuffix(_suffix); const GVariantType *const type = g_variant_get_type(_value); diff --git a/DSView/pv/prop/string.cpp b/DSView/pv/prop/string.cpp index 04648e68..79c0b255 100644 --- a/DSView/pv/prop/string.cpp +++ b/DSView/pv/prop/string.cpp @@ -19,12 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - -#include -#include - #include "string.h" +#include +#include namespace pv { namespace prop { diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index f7cfe38e..bad85ce6 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -60,8 +60,8 @@ #include "utility/encoding.h" #include "utility/path.h" #include "log.h" - #include "ui/langresource.h" + #include "utility/formatting.h" #define DEOCDER_CONFIG_VERSION 2 @@ -922,8 +922,8 @@ void StoreSession::export_exec(data::Snapshot *snapshot) } } - QString sessionTime = _session->get_session_time().toString("yyyy-MM-dd HH:mm:ss"); - strcpy(output.time_string, sessionTime.toStdString().c_str()); + QString dateTimeString = Formatting::DateTimeToString(_session->get_session_time(), TimeStrigFormatType::TIME_STR_FORMAT_ALL); + strcpy(output.time_string, dateTimeString.toStdString().c_str()); QFile file(_file_name); file.open(QIODevice::WriteOnly | QIODevice::Text); @@ -1649,7 +1649,8 @@ QString StoreSession::MakeSaveFile(bool bDlg) } } - default_name += _session->get_session_time().toString("-yyMMdd-hhmmss"); + QString dateTimeString = Formatting::DateTimeToString(_session->get_session_time(), TimeStrigFormatType::TIME_STR_FORMAT_SHORT2); + default_name += "-" + dateTimeString; // Show the dialog if (bDlg) @@ -1707,7 +1708,9 @@ QString StoreSession::MakeExportFile(bool bDlg) break; } } - default_name += _session->get_session_time().toString("-yyMMdd-hhmmss"); + + QString dateTimeString = Formatting::DateTimeToString(_session->get_session_time(), TimeStrigFormatType::TIME_STR_FORMAT_SHORT2); + default_name += "-" + dateTimeString; //ext name QList supportedFormats = getSuportedExportFormats(); diff --git a/DSView/pv/ui/xspinbox.cpp b/DSView/pv/ui/xspinbox.cpp new file mode 100644 index 00000000..fd9ef540 --- /dev/null +++ b/DSView/pv/ui/xspinbox.cpp @@ -0,0 +1,56 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2024 DreamSourceLab + * + * 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 "xspinbox.h" + +XSpinBox::XSpinBox(QWidget *parent) + : QSpinBox(parent) +{ + +} + +XSpinBox::~XSpinBox() +{ + +} + +QString XSpinBox::textFromValue(int val) const +{ + return QString::number(val); +} + +//-------------------XDoubleSpinBox +XDoubleSpinBox::XDoubleSpinBox(QWidget *parent) + : QDoubleSpinBox(parent) +{ + +} + +XDoubleSpinBox::~XDoubleSpinBox() +{ + +} + +QString XDoubleSpinBox::textFromValue(double val) const +{ + int digit = decimals(); + return QString::number(val, 'f', digit); +} \ No newline at end of file diff --git a/DSView/pv/ui/xspinbox.h b/DSView/pv/ui/xspinbox.h new file mode 100644 index 00000000..42aeeca5 --- /dev/null +++ b/DSView/pv/ui/xspinbox.h @@ -0,0 +1,43 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2024 DreamSourceLab + * + * 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 +#include + +class XSpinBox : public QSpinBox +{ +public: + XSpinBox(QWidget *parent); + ~XSpinBox(); + +protected: + QString textFromValue(int val) const override; +}; + +class XDoubleSpinBox : public QDoubleSpinBox +{ +public: + XDoubleSpinBox(QWidget *parent); + ~XDoubleSpinBox(); + +protected: + QString textFromValue(double val) const override; +}; \ No newline at end of file diff --git a/DSView/pv/utility/formatting.cpp b/DSView/pv/utility/formatting.cpp new file mode 100644 index 00000000..b4efe03b --- /dev/null +++ b/DSView/pv/utility/formatting.cpp @@ -0,0 +1,49 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2024 DreamSourceLab + * + * 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 "formatting.h" +#include +#include +#include + +QString Formatting::DateTimeToString(QDateTime tm, TimeStrigFormatType format) +{ + int year = tm.date().year(); + int month = tm.date().month(); + int day = tm.date().day(); + int hour = tm.time().hour(); + int minute = tm.time().minute(); + int second = tm.time().second(); + + char buffer[20]; + + switch (format) + { + case TimeStrigFormatType::TIME_STR_FORMAT_SHORT2: //"yyMMdd-hhmmss" + sprintf(buffer, "%02d%02d%02d-%02d%02d%02d", year%100, month, day, hour, minute, second); + break; + default: //yyyy-MM-dd hh:mm:ss + sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); + break; + } + + return QString(buffer); +} \ No newline at end of file diff --git a/DSView/pv/utility/formatting.h b/DSView/pv/utility/formatting.h new file mode 100644 index 00000000..f936c4cc --- /dev/null +++ b/DSView/pv/utility/formatting.h @@ -0,0 +1,36 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2024 DreamSourceLab + * + * 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 + */ + +class QDateTime; +class QString; + +enum TimeStrigFormatType +{ + TIME_STR_FORMAT_ALL = 0, //"yyyy-MM-dd hh:mm:ss" + TIME_STR_FORMAT_SHORT2, //"yyMMdd-hhmmss" +}; + + +class Formatting +{ +public: + static QString DateTimeToString(QDateTime tm, TimeStrigFormatType format); +}; \ No newline at end of file diff --git a/DSView/pv/view/viewstatus.cpp b/DSView/pv/view/viewstatus.cpp index feff7362..3796b351 100644 --- a/DSView/pv/view/viewstatus.cpp +++ b/DSView/pv/view/viewstatus.cpp @@ -40,6 +40,7 @@ #include "../config/appconfig.h" #include "../appcontrol.h" #include "../ui/fn.h" +#include "../utility/formatting.h" using namespace std; @@ -188,9 +189,9 @@ void ViewStatus::repeat_unshow() } void ViewStatus::set_trig_time(QDateTime time) -{ - _trig_time = L_S(STR_PAGE_DLG, S_ID(IDS_DLG_TRIGGER_TIME), "Trigger Time: ") + time.toString("yyyy-MM-dd hh:mm:ss"); - // assert(0); +{ + QString dateTimeString = Formatting::DateTimeToString(time, TimeStrigFormatType::TIME_STR_FORMAT_ALL); + _trig_time = L_S(STR_PAGE_DLG, S_ID(IDS_DLG_TRIGGER_TIME), "Trigger Time: ") + dateTimeString; } void ViewStatus::set_rle_depth(uint64_t depth)