From 9432565ede1599baf9484e66a2f1a335f338cfef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?snooxx=20=F0=9F=92=A4?= Date: Wed, 2 Feb 2022 23:58:48 +0000 Subject: [PATCH] Fix broken page MiniBar The `MiniBar` normally used to display page numbers and to provide navigation buttons regressed since 01557c16c4 to only show an empty non-functional button called "Page Number", along with multiple warnings: `QObject::connect(MiniBar, QAction): invalid nullptr parameter` This is caused by moving `setupViewerActions()` to a place where `m_miniBar` is not initialized yet, even though it has a runtime `connect`-dependency on it. By moving `setupViewerActions()` back, the `MiniBar` starts working again. Now the `m_addBookmark` action, which is created in that function, is not available anymore to be passed to the constructor of `BookmarkList`. To avoid moving the setup of the latter away from the rest of the sidebar code, only assigning the action to the bookmark button contained in the `BookmarkList` is deferred to `setupViewerActions()`. As requested, any accidental future `nullptr`-access will be handled by crashing, even in Release builds, by omitting any checks. BUG: 450347 Test Plan: Page numbers show up again in toolbar, no more `connect` warnings. --- part/bookmarklist.cpp | 16 ++++++++++------ part/bookmarklist.h | 6 +++++- part/part.cpp | 7 ++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/part/bookmarklist.cpp b/part/bookmarklist.cpp index b85be8617..00cbe4ed1 100644 --- a/part/bookmarklist.cpp +++ b/part/bookmarklist.cpp @@ -117,7 +117,7 @@ public: } }; -BookmarkList::BookmarkList(Okular::Document *document, QAction *addBookmarkAction, QWidget *parent) +BookmarkList::BookmarkList(Okular::Document *document, QWidget *parent) : QWidget(parent) , m_document(document) , m_currentDocumentItem(nullptr) @@ -161,11 +161,10 @@ BookmarkList::BookmarkList(Okular::Document *document, QAction *addBookmarkActio rebuildTree(m_showForAllDocumentsCheckbox->isChecked()); - QToolButton *showAllToolButton = new QToolButton(this); - showAllToolButton->setDefaultAction(addBookmarkAction); - showAllToolButton->setAutoRaise(true); - showAllToolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - mainlay->addWidget(showAllToolButton); + m_showAllToolButton = new QToolButton(this); + m_showAllToolButton->setAutoRaise(true); + m_showAllToolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + mainlay->addWidget(m_showAllToolButton); } BookmarkList::~BookmarkList() @@ -198,6 +197,11 @@ void BookmarkList::notifySetup(const QVector &pages, int setupFl } } +void BookmarkList::setAddBookmarkAction(QAction *addBookmarkAction) +{ + m_showAllToolButton->setDefaultAction(addBookmarkAction); +} + void BookmarkList::slotShowAllBookmarks(bool showAll) { rebuildTree(showAll); diff --git a/part/bookmarklist.h b/part/bookmarklist.h index a4a7bc0d7..5a11bb193 100644 --- a/part/bookmarklist.h +++ b/part/bookmarklist.h @@ -13,6 +13,7 @@ class QAction; class QCheckBox; +class QToolButton; class QTreeWidget; class QTreeWidgetItem; class KTreeWidgetSearchLine; @@ -30,12 +31,14 @@ class BookmarkList : public QWidget, public Okular::DocumentObserver Q_OBJECT public: - explicit BookmarkList(Okular::Document *document, QAction *addBookmarkAction, QWidget *parent = nullptr); + explicit BookmarkList(Okular::Document *document, QWidget *parent = nullptr); ~BookmarkList() override; // inherited from DocumentObserver void notifySetup(const QVector &pages, int setupFlags) override; + void setAddBookmarkAction(QAction *addBookmarkAction); + private Q_SLOTS: void slotShowAllBookmarks(bool); void slotExecuted(QTreeWidgetItem *item); @@ -56,6 +59,7 @@ private: KTreeWidgetSearchLine *m_searchLine; QCheckBox *m_showForAllDocumentsCheckbox; QTreeWidgetItem *m_currentDocumentItem; + QToolButton *m_showAllToolButton; }; #endif diff --git a/part/part.cpp b/part/part.cpp index 5f56b567a..c2b55b6d8 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -377,8 +377,6 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) // sLabel->setBuddy( m_searchWidget ); // m_searchToolBar->setStretchableWidget( m_searchWidget ); - setupViewerActions(); - // [left toolbox optional item: Table of Contents] | [] m_toc = new TOC(nullptr, m_document); connect(m_toc.data(), &TOC::hasTOC, this, &Part::enableTOC); @@ -406,7 +404,7 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) m_sidebar->addItem(m_reviewsWidget, QIcon::fromTheme(QStringLiteral("draw-freehand")), i18n("Annotations")); // [left toolbox: Bookmarks] | [] - m_bookmarkList = new BookmarkList(m_document, m_addBookmark, nullptr); + m_bookmarkList = new BookmarkList(m_document, nullptr); m_sidebar->addItem(m_bookmarkList, QIcon::fromTheme(QStringLiteral("bookmarks")), i18n("Bookmarks")); // [left toolbox optional item: Signature Panel] | [] @@ -538,6 +536,8 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) connect(m_document->bookmarkManager(), &BookmarkManager::saved, this, &Part::slotRebuildBookmarkMenu); + setupViewerActions(); + if (m_embedMode != ViewerWidgetMode) { setupActions(); } else { @@ -711,6 +711,7 @@ void Part::setupViewerActions() m_addBookmark = KStandardAction::addBookmark(this, SLOT(slotAddBookmark()), ac); m_addBookmarkText = m_addBookmark->text(); m_addBookmarkIcon = m_addBookmark->icon(); + m_bookmarkList->setAddBookmarkAction(m_addBookmark); m_renameBookmark = ac->addAction(QStringLiteral("rename_bookmark")); m_renameBookmark->setText(i18n("Rename Bookmark"));