fix: Fixed the tooltip not following the area format#403
Merged
Conversation
Fixed the tooltip not following the area format Log: Fixed the tooltip not following the area format pms: BUG-342705
deepin pr auto review我来对这段代码进行审查分析:
具体改进建议: // 在 DatetimeWidget 类中添加成员变量
class DatetimeWidget : public QWidget {
private:
QLocale m_locale; // 添加成员变量
// ... 其他成员
};
// 在构造函数中初始化
DatetimeWidget::DatetimeWidget(QWidget *parent)
: QWidget(parent),
m_locale(QLocale::system()) // 初始化
{
// ... 其他初始化代码
}
// 修改 updateDateTimeString 函数
void DatetimeWidget::updateDateTimeString()
{
// 使用成员变量而不是临时对象
const QDateTime current = QDateTime::currentDateTime();
// 添加错误检查
if (!m_locale.isValid()) {
m_locale = QLocale::system();
}
if (position == Dock::Bottom || position == Dock::Top) {
QString timeFormat = m_regionFormat->getShortTimeFormat();
timeStr = m_locale.toString(current, timeFormat);
dateString = m_locale.toString(current.date(), m_regionFormat->getShortDateFormat());
// ... 其余代码
}
}
// 在 RegionFormat 中添加验证
void RegionFormat::setLocaleName(const QString &localeName) {
// 验证 localeName 格式
QLocale newLocale(localeName);
if (newLocale.isValid()) {
m_localeName = localeName;
// 更新其他相关设置
} else {
qWarning() << "Invalid locale name:" << localeName;
}
}这些改进可以提高代码的健壮性、性能和可维护性,同时确保了本地化处理的正确性。 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR updates datetime display to consistently use the configured locale/region formats for both date and time, and wires the locale name configuration key into the region format handling so the tooltip/date label follow the area settings. Sequence diagram for locale config update affecting datetime tooltipsequenceDiagram
actor User
participant DockSettingsUI
participant QSettings as Settings
participant RegionFormat
participant DatetimeWidget
User ->> DockSettingsUI: change region locale
DockSettingsUI ->> Settings: setValue localeName_key, newLocaleName
Settings -->> RegionFormat: keyChanged localeName_key
RegionFormat ->> RegionFormat: initConnect lambda handles key
RegionFormat ->> RegionFormat: setLocaleName(newLocaleName)
RegionFormat ->> DatetimeWidget: signal regionFormatChanged
DatetimeWidget ->> DatetimeWidget: updateDateTimeString()
DatetimeWidget ->> DatetimeWidget: locale.toString(current.date(), shortDateFormat)
DatetimeWidget ->> DatetimeWidget: locale.toString(current.time(), shortTimeFormat)
DatetimeWidget ->> DatetimeWidget: update labels and tooltip text
Class diagram for updated datetime locale handlingclassDiagram
class DatetimeWidget {
- RegionFormat* m_regionFormat
- QLabel* m_timeLabel
- QLabel* m_dateLabel
- QLocale locale
+ void updateDateTimeString()
}
class RegionFormat {
- QSettings* m_config
- QString shortTimeFormat
- QString longTimeFormat
- QString shortDateFormat
- QString localeName
+ void initConnect()
+ void setShortTimeFormat(QString format)
+ void setLongTimeFormat(QString format)
+ void setShortDateFormat(QString format)
+ void setLocaleName(QString name)
+ QString getShortTimeFormat()
+ QString getShortDateFormat()
}
class QLocale {
+ QString toString(QDateTime datetime, QString format)
+ QString toString(QDate date, QString format)
+ QString toString(QTime time, QString format)
}
class QDateTime {
+ QDate date()
+ QTime time()
}
class QSettings {
+ QVariant value(QString key)
+ void setValue(QString key, QVariant value)
}
DatetimeWidget --> RegionFormat : uses
DatetimeWidget --> QLocale : uses
DatetimeWidget --> QDateTime : uses
RegionFormat --> QSettings : reads_config_from
DatetimeWidget --> QLabel : updates_text_of
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
18202781743
approved these changes
Dec 23, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed the tooltip not following the area format
Log: Fixed the tooltip not following the area format
pms: BUG-342705
Summary by Sourcery
Ensure the dock datetime widget uses locale-aware formatting for date and time display and updates locale configuration handling.
Bug Fixes:
Enhancements: