Simplify the auxiliary functions used within RegularArea<>, patch by André Wöbbeking.

Make the return value of RegularArea::geometry a simple list instead of a pointer, as suggested by André.

CCMAIL: Woebbeking@kde.org

svn path=/trunk/playground/graphics/okular/; revision=616994
remotes/origin/KDE/4.0
Pino Toscano 20 years ago
parent c248956942
commit bbb55280d5
  1. 115
      core/area.h
  2. 15
      ui/pageviewannotator.cpp

@ -275,65 +275,45 @@ struct HighlightRect : public NormalizedRect
/** @internal */ /** @internal */
template <typename T> template <typename T>
class okularPtrUtils void doDelete( T& t )
{ {
public: (void)t;
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;
}
};
/** @internal */ /** @internal */
template <typename T> template <typename T>
class okularPtrUtils<T*> T* givePtr( T& t )
{ {
public: return &t;
static void doDelete( T* t ) }
{
delete t;
}
static T* givePtr( T* t ) /** @internal */
{ template <typename T>
return t; T& deref( T& t )
} {
return t;
}
static const T* givePtr( const T* t ) /** @internal */
{ template <typename T>
return t; static void doDelete( T* t )
} {
delete t;
}
static T& deref( T* t ) /** @internal */
{ template <typename T>
return *t; static T* givePtr( T* t )
} {
return t;
}
static const T& deref( const T* t ) /** @internal */
{ template <typename T>
return *t; static T& deref( T* t )
} {
}; return *t;
}
/** /**
* @short A regular area of NormalizedShape which normalizes a Shape * @short A regular area of NormalizedShape which normalizes a Shape
@ -357,7 +337,7 @@ template <class NormalizedShape, class Shape> class RegularArea : public QList<
void appendShape( const NormalizedShape& shape ); void appendShape( const NormalizedShape& shape );
void simplify (); void simplify ();
bool isNull() const; bool isNull() const;
QList<Shape>* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; QList<Shape> geometry( int xScale, int yScale, int dx=0,int dy=0 ) const;
}; };
template <class NormalizedShape, class Shape> template <class NormalizedShape, class Shape>
@ -365,7 +345,7 @@ RegularArea<NormalizedShape, Shape>::~RegularArea<NormalizedShape, Shape>()
{ {
int size = this->count(); int size = this->count();
for ( int i = 0; i < size; ++i ) for ( int i = 0; i < size; ++i )
okularPtrUtils<NormalizedShape>::doDelete( (*this)[i] ); doDelete( (*this)[i] );
} }
template <class NormalizedShape, class Shape> template <class NormalizedShape, class Shape>
@ -377,12 +357,12 @@ void RegularArea<NormalizedShape, Shape>::simplify()
int end = this->count() - 1, x = 0; int end = this->count() - 1, x = 0;
for ( int i = 0; i < end; ++i ) for ( int i = 0; i < end; ++i )
{ {
if ( okularPtrUtils<NormalizedShape>::givePtr( (*this)[x] )->intersects( okularPtrUtils<NormalizedShape>::deref( (*this)[i+1] ) ) ) if ( givePtr( (*this)[x] )->intersects( deref( (*this)[i+1] ) ) )
{ {
okularPtrUtils<NormalizedShape>::deref((*this)[x]) |= okularPtrUtils<NormalizedShape>::deref((*this)[i+1]); deref((*this)[x]) |= deref((*this)[i+1]);
NormalizedShape& tobedeleted = (*this)[i+1]; NormalizedShape& tobedeleted = (*this)[i+1];
this->removeAt( i + 1 ); this->removeAt( i + 1 );
okularPtrUtils<NormalizedShape>::doDelete( tobedeleted ); doDelete( tobedeleted );
--end; --end;
--i; --i;
} }
@ -406,7 +386,7 @@ bool RegularArea<NormalizedShape, Shape>::isNull() const
return false; return false;
foreach ( const NormalizedShape& ns, *this ) foreach ( const NormalizedShape& ns, *this )
if ( !(okularPtrUtils<NormalizedShape>::givePtr(ns)->isNull()) ) if ( !givePtr(ns)->isNull() )
return false; return false;
return true; return true;
@ -422,7 +402,7 @@ bool RegularArea<NormalizedShape, Shape>::intersects( const NormalizedShape& rec
return false; return false;
foreach ( const NormalizedShape& ns, *this ) foreach ( const NormalizedShape& ns, *this )
if ( !okularPtrUtils<NormalizedShape>::givePtr(ns)->isNull() && okularPtrUtils<NormalizedShape>::givePtr(ns)->intersects( rect ) ) if ( !givePtr(ns)->isNull() && givePtr(ns)->intersects( rect ) )
return true; return true;
return false; return false;
@ -476,10 +456,10 @@ void RegularArea<NormalizedShape, Shape>::appendShape( const NormalizedShape& sh
{ {
// if the new shape intersects with the last shape in the list, then // if the new shape intersects with the last shape in the list, then
// merge it with that and delete the shape // merge it with that and delete the shape
if ( okularPtrUtils<NormalizedShape>::givePtr((*this)[size - 1])->intersects( shape ) ) if ( givePtr((*this)[size - 1])->intersects( shape ) )
{ {
okularPtrUtils<NormalizedShape>::deref((*this)[size - 1]) |= okularPtrUtils<NormalizedShape>::deref( shape ); deref((*this)[size - 1]) |= deref( shape );
okularPtrUtils<NormalizedShape>::doDelete( const_cast<NormalizedShape&>( shape ) ); doDelete( const_cast<NormalizedShape&>( shape ) );
} }
else else
this->append( shape ); this->append( shape );
@ -516,21 +496,18 @@ bool RegularArea<NormalizedShape, Shape>::contains( const NormalizedShape& shape
} }
template <class NormalizedShape, class Shape> template <class NormalizedShape, class Shape>
QList<Shape> * RegularArea<NormalizedShape, Shape>::geometry( int xScale, int yScale, int dx, int dy ) const QList<Shape> RegularArea<NormalizedShape, Shape>::geometry( int xScale, int yScale, int dx, int dy ) const
{ {
if ( !this ) if ( !this || this->isEmpty() )
return false; return QList<Shape>();
if ( this->isEmpty() )
return 0;
QList<Shape>* ret = new QList<Shape>; QList<Shape> ret;
Shape t; Shape t;
foreach( const NormalizedShape& ns, *this ) foreach( const NormalizedShape& ns, *this )
{ {
t = okularPtrUtils<NormalizedShape>::givePtr(ns)->geometry( xScale, yScale ); t = givePtr(ns)->geometry( xScale, yScale );
t.translate( dx, dy ); t.translate( dx, dy );
ret->append( t ); ret.append( t );
} }
return ret; return ret;

@ -436,17 +436,14 @@ class TextSelectorEngine : public AnnotatorEngine
QPoint start( (int)( lastPoint.x * item()->width() ), (int)( lastPoint.y * item()->height() ) ); QPoint start( (int)( lastPoint.x * item()->width() ), (int)( lastPoint.y * item()->height() ) );
QPoint end( (int)( nX * item()->width() ), (int)( nY * item()->height() ) ); QPoint end( (int)( nX * item()->width() ), (int)( nY * item()->height() ) );
Okular::RegularAreaRect * newselection = m_pageView->textSelectionForItem( item(), start, end ); Okular::RegularAreaRect * newselection = m_pageView->textSelectionForItem( item(), start, end );
QList<QRect> * geom = newselection->geometry( (int)xScale, (int)yScale ); QList<QRect> geom = newselection->geometry( (int)xScale, (int)yScale );
QRect newrect; QRect newrect;
if ( geom ) foreach( const QRect& r, geom )
{ {
foreach( QRect r, *geom ) if ( newrect.isNull() )
{ newrect = r;
if ( newrect.isNull() ) else
newrect = r; newrect |= r;
else
newrect |= r;
}
} }
rect |= newrect; rect |= newrect;
delete selection; delete selection;

Loading…
Cancel
Save