-
Notifications
You must be signed in to change notification settings - Fork 40
pick develop/eagle to master #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff9504b
39cf79a
ff48efe
260b077
68fa715
1da90f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| , m_CurrentResolution("") | ||
| , m_SerialNumber("") | ||
| , m_ProductionWeek("") | ||
| , m_RefreshRate("") | ||
| , m_Width(0) | ||
| , m_Height(0) | ||
| , m_IsTomlSet(false) | ||
|
|
@@ -338,9 +339,13 @@ | |
| qCDebug(appLog) << "Getting monitor overview information"; | ||
| QString ov; | ||
|
|
||
| ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize); | ||
| if (Common::specialComType == 6) { | ||
| ov = QString("(%1)").arg(m_ScreenSize); | ||
| } else { | ||
| ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize); | ||
| } | ||
| qCDebug(appLog) << "Monitor overview:" << ov; | ||
|
|
||
| return ov; | ||
| } | ||
|
|
||
|
|
@@ -354,7 +359,8 @@ | |
| { | ||
| qCDebug(appLog) << "Loading base device info for monitor"; | ||
| // 添加基本信息 | ||
| addBaseDeviceInfo("Name", m_Name); | ||
| if (Common::specialComType != 6) | ||
| addBaseDeviceInfo("Name", m_Name); | ||
| addBaseDeviceInfo("Vendor", m_Vendor); | ||
| addBaseDeviceInfo("Type", m_Model); | ||
| addBaseDeviceInfo("Display Input", m_DisplayInput); | ||
|
|
@@ -369,6 +375,14 @@ | |
| if (m_CurrentResolution != "@Hz") { | ||
| addOtherDeviceInfo("Current Resolution", m_CurrentResolution); | ||
| addOtherDeviceInfo("Display Ratio", m_AspectRatio); | ||
| if (Common::specialComType == 4) { | ||
| if (m_CurrentResolution.contains("@")) { | ||
| QStringList refreshList = m_CurrentResolution.split('@', QT_SKIP_EMPTY_PARTS); | ||
| if (refreshList.size() == 2) { | ||
| m_RefreshRate = refreshList.at(1).trimmed(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| addOtherDeviceInfo("Primary Monitor", m_MainScreen); | ||
| addOtherDeviceInfo("Size", m_ScreenSize); | ||
|
|
@@ -427,12 +441,19 @@ | |
| int pos = rateMatch.capturedStart(); | ||
| if (pos > 0 && curRate.size() > pos && !Common::boardVendorType().isEmpty()) { | ||
| qCDebug(appLog) << "Adjusting rate for board vendor type"; | ||
| curRate = QString::number(ceil(curRate.left(pos).toDouble())) + curRate.right(curRate.size() - pos); | ||
| if (Common::specialComType == 1) { | ||
| curRate = QString::number(ceil(curRate.left(pos).toDouble())) + ".00" + curRate.right(curRate.size() - pos); | ||
| } else { | ||
| curRate = QString::number(ceil(curRate.left(pos).toDouble())) + curRate.right(curRate.size() - pos); | ||
| } | ||
| } | ||
| if (Common::specialComType == 1 || Common::specialComType == 6) { | ||
| m_RefreshRate = QString("%1").arg(curRate); | ||
|
Comment on lines
+450
to
+451
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): m_RefreshRate may retain stale values when no rate is detected
|
||
| } | ||
| if (Common::specialComType == 5) { | ||
| if (Common::specialComType == 5 || Common::specialComType == 6) { | ||
| m_CurrentResolution = QString("%1").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)); | ||
| } else { | ||
| m_CurrentResolution = QString("%1@%2").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).arg(curRate); | ||
| m_CurrentResolution = QString("%1 @%2").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).arg(curRate); | ||
| } | ||
| } else { | ||
| qCDebug(appLog) << "Rate is empty, setting current resolution without rate"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring the new monitor-handling logic to remove redundant assignments, replace magic specialComType numbers with named enums, and centralize resolution/refresh-rate formatting into small helpers.
You can keep all the new behavior but significantly reduce complexity and duplication with a few small refactors.
1. Simplify
getOverviewInfoThe current logic reassigns
ovunnecessarily and repeats the same format string:You can remove the redundant assignment and use a conditional expression (or a tiny helper) instead:
2. Replace magic
specialComTypenumbers with named valuesYou already have several magic numbers (1, 4, 5, 6). You can centralize their meaning without changing behavior by introducing an enum (or
enum class) and using it where you branch:Then update conditions locally for clarity:
This keeps all branching exactly as-is but makes the intent much clearer and reduces cognitive load.
3. Localize resolution/refresh-rate formatting
Right now, resolution and refresh rate formatting is scattered:
setMainInfoFromXrandr:specialComType == 1: tweakcurRatestring with a".00"inserted.specialComType == 1 || 6: setm_RefreshRate.specialComType == 5 || 6: setm_CurrentResolutionwithout@."Size @Rate"format with a space.loadOtherDeviceInfo:specialComType == 4: parsem_CurrentResolutionto extract refresh rate.You can centralize this into compact helpers that preserve behavior but remove duplication and condition scattering.
3.1 Extract a
formatCurRatehelperThis removes the duplicated
curRateexpression with/without".00":Use it in
setMainInfoFromXrandr:Behavior is unchanged; logic is easier to follow and the
curRateformatting is in one place.3.2 Extract refresh-rate parsing from
m_CurrentResolutionThe parsing for
specialComType == 4can also be centralized to avoid repeating rules elsewhere:Then
loadOtherDeviceInfobecomes:This centralizes the
@parsing logic; if otherspecialComTypevalues later need similar parsing, it’s now reusable.All of the above keeps your feature behavior intact, but: