Commit 901046fd authored by David Jarvie's avatar David Jarvie
Browse files

Fix crash when context menu is requested after toolbar has been edited

parent d0ebe192
Pipeline #70080 canceled with stage
KAlarm Change Log
=== Version 3.3.0 (KDE Applications 21.08) --- 9 July 2021 ===
* Add date selector option to filter alarms.
=== Version 3.3.0 (KDE Applications 21.08) --- 12 July 2021 ===
* Add date selector option to enable alarm list view to be filtered.
* Fix crash when context menu is requested after toolbar has been edited.
=== Version 3.2.2 (KDE Applications 21.04.2) --- 26 May 2021 ===
* In audio alarm edit dialogue, don't show file name in encoded format [KDE Bug 437676]
......
......@@ -147,7 +147,7 @@ MainWindow::MainWindow(bool restored)
QVBoxLayout* vlayout = new QVBoxLayout(mPanel);
vlayout->setContentsMargins(0, 0, 0, 0);
mResourceSelector = new ResourceSelector(mPanel);
mResourceSelector = new ResourceSelector(this, mPanel);
vlayout->addWidget(mResourceSelector);
mSplitter->setStretchFactor(0, 0); // don't resize resource selector when window is resized
mSplitter->setStretchFactor(1, 1);
......@@ -576,10 +576,8 @@ void MainWindow::initActions()
applyMainWindowSettings(KSharedConfig::openConfig()->group(WINDOW_NAME));
mContextMenu = static_cast<QMenu*>(factory()->container(QStringLiteral("listContext"), this));
mActionsMenu = static_cast<QMenu*>(factory()->container(QStringLiteral("actions"), this));
QMenu* resourceMenu = static_cast<QMenu*>(factory()->container(QStringLiteral("resourceContext"), this));
mResourceSelector->setContextMenu(resourceMenu);
mMenuError = (!mContextMenu || !mActionsMenu || !resourceMenu);
QMenu* actionsMenu = static_cast<QMenu*>(factory()->container(QStringLiteral("actions"), this));
mMenuError = (!mContextMenu || !actionsMenu || !resourceContextMenu());
connect(mActionUndo->menu(), &QMenu::aboutToShow, this, &MainWindow::slotInitUndoMenu);
connect(mActionUndo->menu(), &QMenu::triggered, this, &MainWindow::slotUndoItem);
connect(mActionRedo->menu(), &QMenu::aboutToShow, this, &MainWindow::slotInitRedoMenu);
......@@ -679,6 +677,18 @@ void MainWindow::clearSelection()
mListView->clearSelection();
}
/******************************************************************************
* Provide the context menu for the resource selector to use.
*/
QMenu* MainWindow::resourceContextMenu()
{
// Recreate the resource selector context menu if it has been deleted
// (which happens if the toolbar is edited).
if (!mResourceContextMenu)
mResourceContextMenu = static_cast<QMenu*>(factory()->container(QStringLiteral("resourceContext"), this));
return mResourceContextMenu;
}
/******************************************************************************
* Called when the New button is clicked to edit a new alarm to add to the list.
*/
......@@ -1541,8 +1551,11 @@ void MainWindow::slotSelection()
void MainWindow::slotContextMenuRequested(const QPoint& globalPos)
{
qCDebug(KALARM_LOG) << "MainWindow::slotContextMenuRequested";
if (mContextMenu)
mContextMenu->popup(globalPos);
// Recreate the context menu if it has been deleted (which happens if the
// toolbar is edited).
if (!mContextMenu)
mContextMenu = static_cast<QMenu*>(factory()->container(QStringLiteral("listContext"), this));
mContextMenu->popup(globalPos);
}
/******************************************************************************
......
......@@ -20,6 +20,7 @@
#include <QVector>
#include <QMap>
#include <QPointer>
class QDragEnterEvent;
class QHideEvent;
......@@ -54,6 +55,7 @@ public:
KAEvent selectedEvent() const;
void editAlarm(EditAlarmDlg*, const KAEvent&);
void clearSelection();
QMenu* resourceContextMenu();
bool eventFilter(QObject*, QEvent*) override;
static void refresh();
......@@ -173,8 +175,8 @@ private:
KToggleAction* mActionToggleTrayIcon;
KToggleAction* mActionShowArchived;
KToggleAction* mActionSpreadWindows;
QMenu* mActionsMenu;
QMenu* mContextMenu;
QPointer<QMenu> mContextMenu;
QPointer<QMenu> mResourceContextMenu;
QMap<QAction*, int> mUndoMenuIds; // items in the undo/redo menu, in order of appearance
int mResourcesWidth {-1}; // width of resource selector widget
bool mHiddenTrayParent {false}; // on session restoration, hide this window
......
......@@ -14,6 +14,7 @@
#include "functions.h"
#include "kalarmapp.h"
#include "mainwindow.h"
#include "preferences.h"
#include "resourcescalendar.h"
#include "resources/resourcedatamodelbase.h"
......@@ -43,8 +44,9 @@
using namespace KCalendarCore;
ResourceSelector::ResourceSelector(QWidget* parent)
ResourceSelector::ResourceSelector(MainWindow* parentWindow, QWidget* parent)
: QFrame(parent)
, mMainWindow(parentWindow)
{
QBoxLayout* topLayout = new QVBoxLayout(this);
......@@ -320,16 +322,12 @@ void ResourceSelector::initActions(KActionCollection* actions)
connect(mActionExport, &QAction::triggered, this, &ResourceSelector::exportCalendar);
}
void ResourceSelector::setContextMenu(QMenu* menu)
{
mContextMenu = menu;
}
/******************************************************************************
* Display the context menu for the selected calendar.
*/
void ResourceSelector::contextMenuRequested(const QPoint& viewportPos)
{
mContextMenu = mMainWindow->resourceContextMenu();
if (!mContextMenu)
return;
bool active = false;
......
/*
* resourceselector.h - alarm calendar resource selection widget
* Program: kalarm
* SPDX-FileCopyrightText: 2006-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2006-2021 David Jarvie <djarvie@kde.org>
* Based on KOrganizer's ResourceView class and KAddressBook's ResourceSelection class,
* SPDX-FileCopyrightText: 2003, 2004 Cornelius Schumacher <schumacher@kde.org>
* SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
......@@ -26,6 +26,7 @@ class KActionCollection;
class KToggleAction;
class QComboBox;
class QMenu;
class MainWindow;
class ResourceView;
......@@ -36,9 +37,8 @@ class ResourceSelector : public QFrame
{
Q_OBJECT
public:
explicit ResourceSelector(QWidget* parent = nullptr);
explicit ResourceSelector(MainWindow* parentWindow, QWidget* parent = nullptr);
void initActions(KActionCollection*);
void setContextMenu(QMenu*);
Q_SIGNALS:
void resized(const QSize& oldSize, const QSize& newSize);
......@@ -70,6 +70,7 @@ class ResourceSelector : public QFrame
CalEvent::Type currentResourceType() const;
Resource currentResource() const;
MainWindow* mMainWindow;
ResourceView* mListView;
QComboBox* mAlarmType;
QPushButton* mAddButton;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment