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.
remotes/origin/work/fhek/foreground_background_text
snooxx 💤 4 years ago committed by Albert Astals Cid
parent 0197a78fb5
commit 9432565ede
  1. 16
      part/bookmarklist.cpp
  2. 6
      part/bookmarklist.h
  3. 7
      part/part.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<Okular::Page *> &pages, int setupFl
}
}
void BookmarkList::setAddBookmarkAction(QAction *addBookmarkAction)
{
m_showAllToolButton->setDefaultAction(addBookmarkAction);
}
void BookmarkList::slotShowAllBookmarks(bool showAll)
{
rebuildTree(showAll);

@ -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<Okular::Page *> &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

@ -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"));

Loading…
Cancel
Save