From bbb55280d50b2ab743fd04484a2035ed4f1d0726 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 27 Dec 2006 17:10:06 +0000 Subject: [PATCH] =?UTF-8?q?Simplify=20the=20auxiliary=20functions=20used?= =?UTF-8?q?=20within=20RegularArea<>,=20patch=20by=20Andr=C3=A9=20W=C3=B6b?= =?UTF-8?q?beking.=20Make=20the=20return=20value=20of=20RegularArea::geome?= =?UTF-8?q?try=20a=20simple=20list=20instead=20of=20a=20pointer,=20as=20su?= =?UTF-8?q?ggested=20by=20Andr=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CCMAIL: Woebbeking@kde.org svn path=/trunk/playground/graphics/okular/; revision=616994 --- core/area.h | 115 ++++++++++++++++----------------------- ui/pageviewannotator.cpp | 15 ++--- 2 files changed, 52 insertions(+), 78 deletions(-) diff --git a/core/area.h b/core/area.h index d46a6dd9a..ad12c7218 100644 --- a/core/area.h +++ b/core/area.h @@ -275,65 +275,45 @@ struct HighlightRect : public NormalizedRect /** @internal */ template -class okularPtrUtils +void doDelete( T& t ) { -public: - static void doDelete( T& t ) - { - (void)t; - } - - static T* givePtr( T& t ) - { - return &t; - } - - static const T* givePtr( const T& t ) - { - return &t; - } - - static T& deref( T& t ) - { - return t; - } - - static const T& deref( const T& t ) - { - return t; - } -}; + (void)t; +} /** @internal */ template -class okularPtrUtils +T* givePtr( T& t ) { -public: - static void doDelete( T* t ) - { - delete t; - } + return &t; +} - static T* givePtr( T* t ) - { - return t; - } +/** @internal */ +template +T& deref( T& t ) +{ + return t; +} - static const T* givePtr( const T* t ) - { - return t; - } +/** @internal */ +template +static void doDelete( T* t ) +{ + delete t; +} - static T& deref( T* t ) - { - return *t; - } +/** @internal */ +template +static T* givePtr( T* t ) +{ + return t; +} - static const T& deref( const T* t ) - { - return *t; - } -}; +/** @internal */ +template +static T& deref( T* t ) +{ + return *t; +} /** * @short A regular area of NormalizedShape which normalizes a Shape @@ -357,7 +337,7 @@ template class RegularArea : public QList< void appendShape( const NormalizedShape& shape ); void simplify (); bool isNull() const; - QList* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; + QList geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; }; template @@ -365,7 +345,7 @@ RegularArea::~RegularArea() { int size = this->count(); for ( int i = 0; i < size; ++i ) - okularPtrUtils::doDelete( (*this)[i] ); + doDelete( (*this)[i] ); } template @@ -377,12 +357,12 @@ void RegularArea::simplify() int end = this->count() - 1, x = 0; for ( int i = 0; i < end; ++i ) { - if ( okularPtrUtils::givePtr( (*this)[x] )->intersects( okularPtrUtils::deref( (*this)[i+1] ) ) ) + if ( givePtr( (*this)[x] )->intersects( deref( (*this)[i+1] ) ) ) { - okularPtrUtils::deref((*this)[x]) |= okularPtrUtils::deref((*this)[i+1]); + deref((*this)[x]) |= deref((*this)[i+1]); NormalizedShape& tobedeleted = (*this)[i+1]; this->removeAt( i + 1 ); - okularPtrUtils::doDelete( tobedeleted ); + doDelete( tobedeleted ); --end; --i; } @@ -406,7 +386,7 @@ bool RegularArea::isNull() const return false; foreach ( const NormalizedShape& ns, *this ) - if ( !(okularPtrUtils::givePtr(ns)->isNull()) ) + if ( !givePtr(ns)->isNull() ) return false; return true; @@ -422,7 +402,7 @@ bool RegularArea::intersects( const NormalizedShape& rec return false; foreach ( const NormalizedShape& ns, *this ) - if ( !okularPtrUtils::givePtr(ns)->isNull() && okularPtrUtils::givePtr(ns)->intersects( rect ) ) + if ( !givePtr(ns)->isNull() && givePtr(ns)->intersects( rect ) ) return true; return false; @@ -476,10 +456,10 @@ void RegularArea::appendShape( const NormalizedShape& sh { // if the new shape intersects with the last shape in the list, then // merge it with that and delete the shape - if ( okularPtrUtils::givePtr((*this)[size - 1])->intersects( shape ) ) + if ( givePtr((*this)[size - 1])->intersects( shape ) ) { - okularPtrUtils::deref((*this)[size - 1]) |= okularPtrUtils::deref( shape ); - okularPtrUtils::doDelete( const_cast( shape ) ); + deref((*this)[size - 1]) |= deref( shape ); + doDelete( const_cast( shape ) ); } else this->append( shape ); @@ -516,21 +496,18 @@ bool RegularArea::contains( const NormalizedShape& shape } template -QList * RegularArea::geometry( int xScale, int yScale, int dx, int dy ) const +QList RegularArea::geometry( int xScale, int yScale, int dx, int dy ) const { - if ( !this ) - return false; - - if ( this->isEmpty() ) - return 0; + if ( !this || this->isEmpty() ) + return QList(); - QList* ret = new QList; + QList ret; Shape t; foreach( const NormalizedShape& ns, *this ) { - t = okularPtrUtils::givePtr(ns)->geometry( xScale, yScale ); + t = givePtr(ns)->geometry( xScale, yScale ); t.translate( dx, dy ); - ret->append( t ); + ret.append( t ); } return ret; diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 1f42046bd..e134441ac 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -436,17 +436,14 @@ class TextSelectorEngine : public AnnotatorEngine QPoint start( (int)( lastPoint.x * item()->width() ), (int)( lastPoint.y * item()->height() ) ); QPoint end( (int)( nX * item()->width() ), (int)( nY * item()->height() ) ); Okular::RegularAreaRect * newselection = m_pageView->textSelectionForItem( item(), start, end ); - QList * geom = newselection->geometry( (int)xScale, (int)yScale ); + QList geom = newselection->geometry( (int)xScale, (int)yScale ); QRect newrect; - if ( geom ) + foreach( const QRect& r, geom ) { - foreach( QRect r, *geom ) - { - if ( newrect.isNull() ) - newrect = r; - else - newrect |= r; - } + if ( newrect.isNull() ) + newrect = r; + else + newrect |= r; } rect |= newrect; delete selection;