1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 13:33:50 +03:00

protect from nullptr crashes

This commit is contained in:
Michail Vourlakos 2022-05-22 17:24:40 +03:00
parent 02d3c37f93
commit 18b47b607f

View File

@ -75,6 +75,10 @@ QPoint ContextMenuLayerQuickItem::popUpRelevantToParent(const QRect &parentItem,
{
QPoint resultPoint;
if (!m_latteView) {
return resultPoint;
}
if (m_latteView->location() == Plasma::Types::TopEdge) {
resultPoint.setX(parentItem.left());
resultPoint.setY(parentItem.bottom());
@ -96,6 +100,10 @@ QPoint ContextMenuLayerQuickItem::popUpRelevantToGlobalPoint(const QRect &parent
{
QPoint resultPoint;
if (!m_latteView) {
return resultPoint;
}
if (m_latteView->location() == Plasma::Types::TopEdge) {
resultPoint.setX(popUpRect.x());
resultPoint.setY(popUpRect.y() + 1);
@ -151,7 +159,7 @@ void ContextMenuLayerQuickItem::mousePressEvent(QMouseEvent *event)
{
//qDebug() << "Step -1 ...";
if (!event || !m_latteView->containment()) {
if (!event || !m_latteView || !m_latteView->containment()) {
return;
}
@ -367,6 +375,10 @@ void ContextMenuLayerQuickItem::mousePressEvent(QMouseEvent *event)
//! update the appletContainsPos method from Panel view
void ContextMenuLayerQuickItem::updateAppletContainsMethod()
{
if (!m_latteView) {
return;
}
for (QQuickItem *item : m_latteView->contentItem()->childItems()) {
if (auto *metaObject = item->metaObject()) {
// not using QMetaObject::invokeMethod to avoid warnings when calling
@ -388,7 +400,7 @@ void ContextMenuLayerQuickItem::updateAppletContainsMethod()
void ContextMenuLayerQuickItem::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event)
{
if (!m_latteView->containment()) {
if (!m_latteView || !m_latteView->containment()) {
return;
}
@ -475,7 +487,7 @@ void ContextMenuLayerQuickItem::addAppletActions(QMenu *desktopMenu, Plasma::App
void ContextMenuLayerQuickItem::addContainmentActions(QMenu *desktopMenu, QEvent *event)
{
if (!m_latteView->containment()) {
if (!m_latteView || !m_latteView->containment()) {
return;
}
@ -525,13 +537,17 @@ void ContextMenuLayerQuickItem::addContainmentActions(QMenu *desktopMenu, QEvent
Plasma::Containment *ContextMenuLayerQuickItem::containmentById(uint id)
{
if (!m_latteView) {
return nullptr;
}
for (const auto containment : m_latteView->corona()->containments()) {
if (id == containment->id()) {
return containment;
}
}
return 0;
return nullptr;
}
}