Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions dock-network-plugin/dockcontentwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class DockContentWidget : public QWidget
m_mainLayout->setContentsMargins(margin);
}
void setMinHeight(int minHeight) { m_minHeight = minHeight; }

public Q_SLOTS:
void updateSize() {
auto h = Dock::DOCK_POPUP_WIDGET_MAX_HEIGHT - 20 - m_mainLayout->contentsMargins().top() - (m_netCheckBtn->isVisible() ? (m_netSetBtn->height() + m_netCheckBtn->height() + 10) : m_netSetBtn->height());
m_netView->setMaxHeight(h);
Expand All @@ -90,6 +92,24 @@ class DockContentWidget : public QWidget
return QWidget::eventFilter(watch, event);
}

void showEvent(QShowEvent *event) override
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider extracting the deferred sizing behavior into a shared helper to centralize logic and avoid string-based invokeMethod usage while preserving current show/hide behavior.

You can reduce the new complexity by centralizing the deferred sizing logic and avoiding the string-based invokeMethod while keeping behavior (immediate + deferred updates, min-height reset, resize) intact.

1. Centralize deferred sizing

Extract the queued sizing logic to a small helper, used from both showEvent and hideEvent. This removes duplication and makes the async behavior explicit:

private:
    bool m_deferredUpdateScheduled = false;

    void scheduleDeferredUpdateSize(bool doResize)
    {
        if (m_deferredUpdateScheduled)
            return;

        m_deferredUpdateScheduled = true;
        QMetaObject::invokeMethod(this, [this, doResize]() {
            m_deferredUpdateScheduled = false;
            updateSize();
            if (doResize)
                resize(size());
        }, Qt::QueuedConnection);
    }

2. Simplify showEvent and hideEvent with the helper

Reuse the helper so the control flow is easy to follow and you no longer need the string-based overload:

void showEvent(QShowEvent *event) override
{
    updateSize();                    // keep immediate update
    QWidget::showEvent(event);
    scheduleDeferredUpdateSize(true); // deferred update + resize
}

void hideEvent(QHideEvent *event) override
{
    QWidget::hideEvent(event);
    m_minHeight = -1;
    // 隐藏时更新尺寸为折叠状态,确保下次显示时初始尺寸正确
    scheduleDeferredUpdateSize(false); // deferred update only
}

This keeps all current behavior (immediate sizing on show, deferred re-sizes, min-height reset on hide) but removes duplicated lambdas, avoids string-based invokeMethod, and makes the deferred sizing semantics clear and centralized.

{
updateSize();
QWidget::showEvent(event);
QMetaObject::invokeMethod(this, [this]() {
updateSize();
resize(size());
}, Qt::QueuedConnection);
}

void hideEvent(QHideEvent *event) override
{
QWidget::hideEvent(event);
m_minHeight = -1;
// 隐藏时更新尺寸为折叠状态,确保下次显示时初始尺寸正确
QMetaObject::invokeMethod(this, "updateSize", Qt::QueuedConnection);
}
Comment on lines +107 to +111
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Mixed styles of QMetaObject::invokeMethod reduce type safety and consistency.

In showEvent you use the functor-based overload, but hideEvent uses the string-based one, which is less type-safe and more fragile during refactors. Please update hideEvent to the functor form as well, e.g. QMetaObject::invokeMethod(this, [this]{ updateSize(); }, Qt::QueuedConnection);.

Suggested change
QWidget::hideEvent(event);
m_minHeight = -1;
// 隐藏时更新尺寸为折叠状态,确保下次显示时初始尺寸正确
QMetaObject::invokeMethod(this, "updateSize", Qt::QueuedConnection);
}
QWidget::hideEvent(event);
m_minHeight = -1;
// 隐藏时更新尺寸为折叠状态,确保下次显示时初始尺寸正确
QMetaObject::invokeMethod(this, [this]() {
updateSize();
}, Qt::QueuedConnection);
}


private:
QVBoxLayout *m_mainLayout;
NetView *m_netView;
Expand Down
1 change: 1 addition & 0 deletions net-view/window/netview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ void NetView::showEvent(QShowEvent *event)
if (m_shouldUpdateExpand)
m_manager->exec(NetManager::ToggleExpand, "");
m_shouldUpdateExpand = false;
updateGeometries();
}

void NetView::hideEvent(QHideEvent *event)
Expand Down