diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -29,6 +29,7 @@ // system includes #include +#include #include // local includes @@ -47,7 +48,7 @@ { public: PickPointEngine( const QDomElement & engineElement ) - : AnnotatorEngine( engineElement ), clicked( false ), pixmap( nullptr ), + : AnnotatorEngine( engineElement ), clicked( false ), xscale( 1.0 ), yscale( 1.0 ) { // parse engine specific attributes @@ -64,12 +65,7 @@ // create engine objects if ( !hoverIconName.simplified().isEmpty() ) - pixmap = new QPixmap( GuiUtils::loadStamp( hoverIconName, QSize( size, size ) ) ); - } - - ~PickPointEngine() override - { - delete pixmap; + pixmap = std::unique_ptr( new QPixmap( GuiUtils::loadStamp( hoverIconName, QSize( size, size ) ) ) ); } QRect event( EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * page ) override @@ -305,7 +301,7 @@ Okular::NormalizedRect rect; Okular::NormalizedPoint startpoint; Okular::NormalizedPoint point; - QPixmap * pixmap; + std::unique_ptr pixmap; QString hoverIconName, iconName; int size; double xscale,yscale; @@ -490,17 +486,11 @@ { public: TextSelectorEngine( const QDomElement & engineElement, PageView * pageView ) - : AnnotatorEngine( engineElement ), m_pageView( pageView ), - selection( nullptr ) + : AnnotatorEngine( engineElement ), m_pageView( pageView ) { // parse engine specific attributes } - ~TextSelectorEngine() override - { - delete selection; - } - QRect event( EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/ ) override { // only proceed if pressing left button @@ -521,9 +511,8 @@ { const QPoint start( (int)( lastPoint.x * item()->uncroppedWidth() ), (int)( lastPoint.y * item()->uncroppedHeight() ) ); const QPoint end( (int)( nX * item()->uncroppedWidth() ), (int)( nY * item()->uncroppedHeight() ) ); - delete selection; - selection = nullptr; - Okular::RegularAreaRect * newselection = m_pageView->textSelectionForItem( item(), start, end ); + selection.reset(); + std::unique_ptr newselection( m_pageView->textSelectionForItem( item(), start, end ) ); if ( newselection && !newselection->isEmpty() ) { const QList geom = newselection->geometry( (int)xScale, (int)yScale ); @@ -536,11 +525,7 @@ newrect |= r; } rect |= newrect; - selection = newselection; - } - else - { - delete newselection; + selection = std::move(newselection); } } } @@ -621,8 +606,7 @@ ann = ha; } - delete selection; - selection = nullptr; + selection.reset(); // safety check if ( !ann ) @@ -647,7 +631,7 @@ // data PageView * m_pageView; // TODO: support more pages - Okular::RegularAreaRect * selection; + std::unique_ptr selection; Okular::NormalizedPoint lastPoint; QRect rect; };