Skip to content

Conversation

@pppanghu77
Copy link

@pppanghu77 pppanghu77 commented Jun 17, 2025

Realize the saving and restoration of the window state, including maximizing the state and size. The relevant functions have been updated to ensure that the state is correctly saved when the window is maximized and the saved state is applied when restored.

Log: Add the functions of saving and restoring window status
Bug: https://pms.uniontech.com/bug-view-318459.html

Summary by Sourcery

Persist the main window’s size and maximization state across sessions using new saveConfigWinState and restoreConfigWinState methods

Bug Fixes:

  • Fix loss of window size and maximization status between sessions by persisting window state to settings

Enhancements:

  • Introduce saveConfigWinState and restoreConfigWinState to handle window state persistence
  • Replace direct resize calls with restoreConfigWinState during initialization and use saveConfigWinState on destruction
  • Add MAINWINDOW_STATE_NAME setting key to store the window’s state

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 17, 2025

Reviewer's Guide

This PR implements full window state persistence by introducing dedicated save/restore routines (including maximizing logic), updating lifecycle hooks to call them, and adding the corresponding configuration constant.

ER diagram for window state persistence settings

erDiagram
    SETTINGS {
        string MainWindowWidthName
        string MainWindowHeightName
        string MainWindowStateName
    }
    SETTINGS ||..|| MAINWINDOW : stores
Loading

Class diagram for updated MainWindow window state management

classDiagram
    class MainWindow {
        +void saveConfigWinSize(int w, int h)
        +void saveConfigWinState()
        +void restoreConfigWinState()
        -void saveConfigWinSize(int w, int h) (moved)
    }
    MainWindow --> QSettings : uses
Loading

File-Level Changes

Change Details Files
Implement window state save and restore logic
  • Add QTimer include for delayed maximize
  • Replace destructor saveConfigWinSize() call with saveConfigWinState()
  • Replace initial resize() call with restoreConfigWinState()
  • Define saveConfigWinState() to handle maximized and normal size saving
  • Define restoreConfigWinState() to apply saved size and delayed maximize
src/source/mainwindow.cpp
Update mainwindow.h to expose new state methods
  • Add declarations for saveConfigWinState() and restoreConfigWinState()
  • Retain existing saveConfigWinSize() declaration
  • Remove duplicate saveConfigWinSize() definition block
src/source/mainwindow.h
Add configuration key for window state
  • Define MAINWINDOW_STATE_NAME constant for saving state
src/source/common/uistruct.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Realize the saving and restoration of the window state, including maximizing the state and size. The relevant functions have been updated to ensure that the state is correctly saved when the window is maximized and the saved state is applied when restored.

Log: Add the functions of saving and restoring window status
Bug: https://pms.uniontech.com/bug-view-318459.html
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. MainWindow::saveConfigWinState函数中,对于最大化窗口,保存的尺寸是正常尺寸而不是最大化尺寸。这可能会导致用户在恢复窗口状态时,窗口尺寸不符合预期。建议保存最大化状态时也保存最大化尺寸。

  2. MainWindow::restoreConfigWinState函数中,使用QTimer::singleShot(0, this, [this]() { ... })延迟执行最大化操作,这是一个好的做法,可以确保窗口完全初始化后再最大化。但是,如果窗口初始化需要较长时间,可能会导致用户在窗口完全显示之前看到窗口尺寸不正确。

  3. MainWindow::restoreConfigWinState函数中,恢复窗口状态时先设置正常尺寸,然后再应用状态。这可能会导致窗口在恢复状态时出现闪烁。建议先应用状态,然后再设置尺寸。

  4. MainWindow::saveConfigWinState函数中,保存窗口状态时没有检查m_pSettings是否为空。如果m_pSettings为空,调用setValuesync可能会导致程序崩溃。建议在调用这些函数之前检查m_pSettings是否为空。

  5. MainWindow::restoreConfigWinState函数中,恢复窗口状态时使用了QTimer::singleShot(0, this, [this]() { ... })延迟执行。这可能会导致窗口在恢复状态时出现闪烁。建议使用QMetaObject::invokeMethod来延迟执行最大化操作,这样可以确保窗口在最大化之前已经完全初始化。

  6. MainWindow::restoreConfigWinState函数中,恢复窗口状态时先设置正常尺寸,然后再应用状态。这可能会导致窗口在恢复状态时出现闪烁。建议先应用状态,然后再设置尺寸。

  7. MainWindow::saveConfigWinState函数中,保存窗口状态时没有检查m_pSettings是否为空。如果m_pSettings为空,调用setValuesync可能会导致程序崩溃。建议在调用这些函数之前检查m_pSettings是否为空。

  8. MainWindow::restoreConfigWinState函数中,恢复窗口状态时使用了QTimer::singleShot(0, this, [this]() { ... })延迟执行。这可能会导致窗口在恢复状态时出现闪烁。建议使用QMetaObject::invokeMethod来延迟执行最大化操作,这样可以确保窗口在最大化之前已经完全初始化。

  9. MainWindow::restoreConfigWinState函数中,恢复窗口状态时先设置正常尺寸,然后再应用状态。这可能会导致窗口在恢复状态时出现闪烁。建议先应用状态,然后再设置尺寸。

  10. MainWindow::saveConfigWinState函数中,保存窗口状态时没有检查m_pSettings是否为空。如果m_pSettings为空,调用setValuesync可能会导致程序崩溃。建议在调用这些函数之前检查m_pSettings是否为空。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, pppanghu77

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pppanghu77
Copy link
Author

/merge

@deepin-bot deepin-bot bot merged commit 0c94529 into linuxdeepin:release/eagle Jun 17, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants