From ba026566469453cc1758a4ec668dc569f10ab6f0 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 25 Oct 2017 14:59:17 +0200 Subject: [PATCH] Make m_annowindows a set instead of a hash Will make it for easier maintainance when we need to reuse the windows and annotation pointers change --- ui/annotwindow.cpp | 5 +++++ ui/annotwindow.h | 2 ++ ui/pageview.cpp | 35 +++++++++++++---------------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/ui/annotwindow.cpp b/ui/annotwindow.cpp index 4cca403b8..011f70cf6 100644 --- a/ui/annotwindow.cpp +++ b/ui/annotwindow.cpp @@ -241,6 +241,11 @@ AnnotWindow::~AnnotWindow() delete m_latexRenderer; } +Okular::Annotation * AnnotWindow::annotation() const +{ + return m_annot; +} + void AnnotWindow::reloadInfo() { const QColor newcolor = m_annot->style().color().isValid() ? m_annot->style().color() : Qt::yellow; diff --git a/ui/annotwindow.h b/ui/annotwindow.h index d34c3ea20..5c403f1fc 100644 --- a/ui/annotwindow.h +++ b/ui/annotwindow.h @@ -36,6 +36,8 @@ class AnnotWindow : public QFrame void reloadInfo(); + Okular::Annotation * annotation() const; + private: MovableTitle * m_title; KTextEdit *textEdit; diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 0593380cc..8b98c36b2 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -172,7 +172,7 @@ public: // annotations PageViewAnnotator * annotator; //text annotation dialogs list - QHash< Okular::Annotation *, AnnotWindow * > m_annowindows; + QSet< AnnotWindow * > m_annowindows; // other stuff QTimer * delayResizeEventTimer; bool dirtyLayout; @@ -451,7 +451,7 @@ PageView::~PageView() // We need to assign it to a different list otherwise slotAnnotationWindowDestroyed // will bite us and clear d->m_annowindows - QHash< Okular::Annotation *, AnnotWindow * > annowindows = d->m_annowindows; + QSet< AnnotWindow * > annowindows = d->m_annowindows; d->m_annowindows.clear(); qDeleteAll( annowindows ); @@ -756,10 +756,13 @@ void PageView::openAnnotationWindow( Okular::Annotation * annotation, int pageNu // find the annot window AnnotWindow* existWindow = nullptr; - QHash< Okular::Annotation *, AnnotWindow * >::ConstIterator it = d->m_annowindows.constFind( annotation ); - if ( it != d->m_annowindows.constEnd() ) + foreach(AnnotWindow *aw, d->m_annowindows) { - existWindow = *it; + if ( aw->annotation() == annotation ) + { + existWindow = aw; + break; + } } if ( existWindow == nullptr ) @@ -767,7 +770,7 @@ void PageView::openAnnotationWindow( Okular::Annotation * annotation, int pageNu existWindow = new AnnotWindow( this, annotation, d->document, pageNumber ); connect(existWindow, &QObject::destroyed, this, &PageView::slotAnnotationWindowDestroyed); - d->m_annowindows.insert( annotation, existWindow ); + d->m_annowindows << existWindow; } existWindow->show(); @@ -775,19 +778,7 @@ void PageView::openAnnotationWindow( Okular::Annotation * annotation, int pageNu void PageView::slotAnnotationWindowDestroyed( QObject * window ) { - QHash< Okular::Annotation*, AnnotWindow * >::Iterator it = d->m_annowindows.begin(); - QHash< Okular::Annotation*, AnnotWindow * >::Iterator itEnd = d->m_annowindows.end(); - while ( it != itEnd ) - { - if ( it.value() == window ) - { - it = d->m_annowindows.erase( it ); - } - else - { - ++it; - } - } + d->m_annowindows.remove( static_cast( window ) ); } void PageView::displayMessage( const QString & message, const QString & details, PageViewMessage::Icon icon, int duration ) @@ -1087,7 +1078,7 @@ void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, int setup // We need to assign it to a different list otherwise slotAnnotationWindowDestroyed // will bite us and clear d->m_annowindows - QHash< Okular::Annotation *, AnnotWindow * > annowindows = d->m_annowindows; + QSet< AnnotWindow * > annowindows = d->m_annowindows; d->m_annowindows.clear(); qDeleteAll( annowindows ); @@ -1330,10 +1321,10 @@ void PageView::notifyPageChanged( int pageNumber, int changedFlags ) { const QLinkedList< Okular::Annotation * > annots = d->document->page( pageNumber )->annotations(); const QLinkedList< Okular::Annotation * >::ConstIterator annItEnd = annots.end(); - QHash< Okular::Annotation*, AnnotWindow * >::Iterator it = d->m_annowindows.begin(); + QSet< AnnotWindow * >::Iterator it = d->m_annowindows.begin(); for ( ; it != d->m_annowindows.end(); ) { - QLinkedList< Okular::Annotation * >::ConstIterator annIt = qFind( annots, it.key() ); + QLinkedList< Okular::Annotation * >::ConstIterator annIt = qFind( annots, (*it)->annotation() ); if ( annIt != annItEnd ) { (*it)->reloadInfo();