From 0a41305160452988b457f6b8fae6cb4ba99a1d67 Mon Sep 17 00:00:00 2001 From: Simone Gaiarin Date: Fri, 23 Apr 2021 10:06:27 +0200 Subject: [PATCH] Fix old quick annotations not deleted after reparse Also refactored the code to populate the quick annotations in order to re-add only the quick annotions and not config actions --- part/annotationactionhandler.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/part/annotationactionhandler.cpp b/part/annotationactionhandler.cpp index 95558d226..1a4752d35 100644 --- a/part/annotationactionhandler.cpp +++ b/part/annotationactionhandler.cpp @@ -63,7 +63,6 @@ public: , aHideToolBar(nullptr) , aShowToolBar(nullptr) , aToolBarVisibility(nullptr) - , aQuickToolsSeparator(nullptr) , aCustomStamp(nullptr) , aCustomWidth(nullptr) , aCustomOpacity(nullptr) @@ -130,7 +129,6 @@ public: QAction *aHideToolBar; QAction *aShowToolBar; KToggleAction *aToolBarVisibility; - QAction *aQuickToolsSeparator; QAction *aCustomStamp; QAction *aCustomWidth; @@ -357,15 +355,14 @@ void AnnotationActionHandlerPrivate::populateQuickAnnotations() q->deselectAllAnnotationActions(); } - KActionCollection *ac = qobject_cast(q->parent()->parent())->actionCollection(); - QAction *aConfigAnnotation = ac->action(QStringLiteral("options_configure_annotations")); const QList quickToolActions = aQuickTools->menu()->actions(); for (QAction *action : quickToolActions) { - aQuickTools->removeAction(action); - if (isQuickToolAction(action)) { + if (action->isCheckable()) { + aQuickTools->removeAction(action); delete action; } } + QAction *aSeparator = aQuickTools->menu()->actions().first(); textQuickTools.clear(); int favToolId = 1; @@ -379,7 +376,7 @@ void AnnotationActionHandlerPrivate::populateQuickAnnotations() } QIcon toolIcon = QIcon(PageViewAnnotator::makeToolPixmap(favToolElement)); QAction *annFav = new KToggleAction(toolIcon, itemText, q); - aQuickTools->addAction(annFav); + aQuickTools->insertAction(aSeparator, annFav); agTools->addAction(annFav); quickTools.append(annFav); if (shortcutNumber != numberKeys.end()) @@ -396,15 +393,6 @@ void AnnotationActionHandlerPrivate::populateQuickAnnotations() } favToolElement = annotator->quickTool(++favToolId); } - if (aQuickToolsSeparator) { - aQuickTools->addAction(aQuickToolsSeparator); - } - if (aShowToolBar) { - aQuickTools->addAction(aShowToolBar); - } - if (aConfigAnnotation) { - aQuickTools->addAction(aConfigAnnotation); - } // set the default action if (quickTools.isEmpty()) { @@ -668,8 +656,14 @@ AnnotationActionHandler::AnnotationActionHandler(PageViewAnnotator *parent, KAct d->aQuickTools->setDefaultAction(action); } }); - d->aQuickToolsSeparator = new QAction(this); - d->aQuickToolsSeparator->setSeparator(true); + QAction *aQuickToolsSeparator = new QAction(this); + aQuickToolsSeparator->setSeparator(true); + d->aQuickTools->addAction(aQuickToolsSeparator); + d->aQuickTools->addAction(d->aShowToolBar); + QAction *aConfigAnnotation = ac->action(QStringLiteral("options_configure_annotations")); + if (aConfigAnnotation) { + d->aQuickTools->addAction(aConfigAnnotation); + } d->populateQuickAnnotations(); // Add to quick annotation action