Decided i don't want to use a QPair here, just use a struct with two fields

This commit is contained in:
Albert Astals Cid 2012-01-17 23:01:26 +01:00
parent 7884c879a7
commit 948ea54026
2 changed files with 23 additions and 11 deletions

View file

@ -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 ) {

View file

@ -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;
};