Skip to content
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

fix: fix crash when closing folder list widget #2535

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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
31 changes: 23 additions & 8 deletions src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#include <QStyle>
#include <QStyleOptionViewItem>
#include <QPainter>
#include <QMouseEvent>

Check warning on line 21 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 21 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMenu>

Check warning on line 22 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMenu> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 22 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QMenu> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 23 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 23 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QEventLoop>

Check warning on line 24 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QEventLoop> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 24 in src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QEventLoop> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DWIDGET_USE_NAMESPACE
using namespace dfmplugin_titlebar;
Expand Down Expand Up @@ -51,6 +52,10 @@

UrlPushButtonPrivate::~UrlPushButtonPrivate()
{
if (folderListWidget) {
folderListWidget->hide();
folderListWidget->deleteLater();
}
}

void UrlPushButtonPrivate::initConnect()
Expand Down Expand Up @@ -194,24 +199,40 @@
fmWarning("Parent is not a CrumbBar !!!");
return;
}

// 如果已经显示则隐藏
if (folderListWidget && folderListWidget->isVisible()) {
folderListWidget->hide();
return;
}

if (crumbDatas.isEmpty())
return;

// 保存 crumbBar 的弱引用
QPointer<CrumbBar> weakCrumbBar(crumbBar);
crumbBar->setPopupVisible(true);

const bool leftToRight = (q->layoutDirection() == Qt::LeftToRight);
const int popupX = (leftToRight && !stacked) ? (q->width() - arrowWidth() - kBorderWidth) : 0;
const QPoint popupPos = q->parentWidget()->mapToGlobal(q->geometry().bottomLeft() + QPoint(popupX, 0));

if (!folderListWidget) {
folderListWidget = new FolderListWidget(q);
connect(folderListWidget, &FolderListWidget::urlButtonActivated, q, &UrlPushButton::urlButtonActivated);
connect(folderListWidget, &FolderListWidget::hidden, this, [this, weakCrumbBar]() {
if (weakCrumbBar) {
weakCrumbBar->setPopupVisible(false);
}
if (hoverFlag) {
hoverFlag = false;
q->update();
}
});
}
QList<CrumbData> childDatas;

if (!stacked) {
// 堆叠时显示堆叠目录
// 非堆叠时显示子目录
requestCompleteByUrl(crumbDatas.last().url);
} else {
folderListWidget->setFolderList(crumbDatas, stacked);
Expand All @@ -221,12 +242,6 @@
QEventLoop eventLoop;
connect(folderListWidget, &FolderListWidget::hidden, &eventLoop, &QEventLoop::quit);
(void)eventLoop.exec(QEventLoop::DialogExec);

crumbBar->setPopupVisible(false);
if (hoverFlag) {
hoverFlag = false;
q->update();
}
}

void UrlPushButtonPrivate::onCompletionFound(const QStringList &stringList)
Expand Down
Loading