From 948ea54026480cfbdad4a55a6cd19535c2c9b210 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 17 Jan 2012 23:01:26 +0100 Subject: [PATCH] Decided i don't want to use a QPair here, just use a struct with two fields --- ui/annotationpopup.cpp | 20 ++++++++++---------- ui/annotationpopup.h | 14 +++++++++++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp index 8124ec1fa..c98727ce9 100644 --- a/ui/annotationpopup.cpp +++ b/ui/annotationpopup.cpp @@ -26,7 +26,7 @@ AnnotationPopup::AnnotationPopup( Okular::Document *document, void AnnotationPopup::addAnnotation( Okular::Annotation* annotation, int pageNumber ) { - AnnotPagePair pair = qMakePair( annotation, pageNumber ); + AnnotPagePair pair( annotation, pageNumber ); if ( !mAnnotations.contains( pair ) ) mAnnotations.append( pair ); } @@ -52,16 +52,16 @@ void AnnotationPopup::exec( const QPoint &point ) deleteNote = menu.addAction( KIcon( "list-remove" ), i18n( "&Delete" ) ); deleteNote->setEnabled( mDocument->isAllowed( Okular::AllowNotes ) ); - if ( onlyOne && mAnnotations.first().first->flags() & Okular::Annotation::DenyDelete ) + if ( onlyOne && mAnnotations.first().annotation->flags() & Okular::Annotation::DenyDelete ) deleteNote->setEnabled( false ); showProperties = menu.addAction( KIcon( "configure" ), i18n( "&Properties" ) ); showProperties->setEnabled( onlyOne ); - if ( onlyOne && mAnnotations.first().first->subType() == Okular::Annotation::AFileAttachment ) + if ( onlyOne && mAnnotations.first().annotation->subType() == Okular::Annotation::AFileAttachment ) { menu.addSeparator(); - fileAttachAnnot = static_cast< Okular::FileAttachmentAnnotation * >( mAnnotations.first().first ); + fileAttachAnnot = static_cast< Okular::FileAttachmentAnnotation * >( mAnnotations.first().annotation ); const QString saveText = i18nc( "%1 is the name of the file to save", "&Save '%1'...", fileAttachAnnot->embeddedFile()->name() ); saveAttachment = menu.addAction( KIcon( "document-save" ), saveText ); } @@ -71,18 +71,18 @@ void AnnotationPopup::exec( const QPoint &point ) // check if the user really selected an action if ( choice ) { if ( choice == popoutWindow ) { - emit setAnnotationWindow( mAnnotations.first().first ); + emit setAnnotationWindow( mAnnotations.first().annotation ); } else if( choice == deleteNote ) { Q_FOREACH ( const AnnotPagePair& pair, mAnnotations ) { - if ( pair.second != -1 ) - mDocument->removePageAnnotation( pair.second, pair.first ); + if ( pair.pageNumber != -1 ) + mDocument->removePageAnnotation( pair.pageNumber, pair.annotation ); - emit removeAnnotationWindow( pair.first ); + emit removeAnnotationWindow( pair.annotation ); } } else if( choice == showProperties ) { - if ( mAnnotations.first().second != -1 ) { - AnnotsPropertiesDialog propdialog( mParent, mDocument, mAnnotations.first().second, mAnnotations.first().first ); + if ( mAnnotations.first().pageNumber != -1 ) { + AnnotsPropertiesDialog propdialog( mParent, mDocument, mAnnotations.first().pageNumber, mAnnotations.first().annotation ); propdialog.exec(); } } else if( choice == saveAttachment ) { diff --git a/ui/annotationpopup.h b/ui/annotationpopup.h index 5409f72d8..6b81f1798 100644 --- a/ui/annotationpopup.h +++ b/ui/annotationpopup.h @@ -38,7 +38,19 @@ class AnnotationPopup : public QObject private: QWidget *mParent; - typedef QPair< Okular::Annotation*, int > AnnotPagePair; + struct AnnotPagePair { + AnnotPagePair( Okular::Annotation *a, int pn ) : annotation( a ), pageNumber( pn ) + { } + + AnnotPagePair( const AnnotPagePair & pair ) : annotation( pair.annotation ), pageNumber( pair.pageNumber ) + { } + + bool operator==( const AnnotPagePair & pair ) const + { return annotation == pair.annotation && pageNumber == pair.pageNumber; } + + Okular::Annotation* annotation; + int pageNumber; + }; QList< AnnotPagePair > mAnnotations; Okular::Document *mDocument; };