Replaced raw PopupMenu pointer with unique_qptr in FlatLabel.

This commit is contained in:
23rd 2021-04-10 21:49:57 +03:00
parent 8c381e6bd4
commit 92fe8b138b
2 changed files with 4 additions and 17 deletions

View file

@ -614,11 +614,6 @@ void FlatLabel::touchEvent(QTouchEvent *e) {
}
void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) {
if (_contextMenu) {
_contextMenu->deleteLater();
_contextMenu = nullptr;
}
if (e->reason() == QContextMenuEvent::Mouse) {
_lastMousePos = e->globalPos();
} else {
@ -635,7 +630,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
const auto fullSelection = _selectable
&& _text.isFullSelection(_selection);
_contextMenu = new PopupMenu(this);
_contextMenu = base::make_unique_q<PopupMenu>(this);
if (fullSelection && !_contextCopyText.isEmpty()) {
_contextMenu->addAction(
@ -662,11 +657,9 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
}
}
if (_contextMenu->actions().empty()) {
delete _contextMenu;
if (_contextMenu->empty()) {
_contextMenu = nullptr;
} else {
connect(_contextMenu, SIGNAL(destroyed(QObject*)), this, SLOT(onContextMenuDestroy(QObject*)));
_contextMenu->popup(e->globalPos());
e->accept();
}
@ -688,12 +681,6 @@ void FlatLabel::onTouchSelect() {
dragActionStart(_touchPos, Qt::LeftButton);
}
void FlatLabel::onContextMenuDestroy(QObject *obj) {
if (obj == _contextMenu) {
_contextMenu = nullptr;
}
}
void FlatLabel::onExecuteDrag() {
if (_dragAction != Dragging) return;

View file

@ -6,6 +6,7 @@
//
#pragma once
#include "base/unique_qptr.h"
#include "ui/rp_widget.h"
#include "ui/wrap/padding_wrap.h"
#include "ui/text/text.h"
@ -171,7 +172,6 @@ private Q_SLOTS:
void onCopyContextText();
void onTouchSelect();
void onContextMenuDestroy(QObject *obj);
void onExecuteDrag();
@ -229,7 +229,7 @@ private:
QPoint _trippleClickPoint;
QTimer _trippleClickTimer;
PopupMenu *_contextMenu = nullptr;
base::unique_qptr<PopupMenu> _contextMenu;
QString _contextCopyText;
ClickHandlerFilter _clickHandlerFilter;