Improved the text selection by using and ad-hoc function that takes care of adding or merging a new shape to the area, so the simply() at the end is no more needed.

This gives another speedup when using the text selection.
(And, rename okularDeleter to okularPtrUtils.)

svn path=/trunk/playground/graphics/okular/; revision=616089
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent 0fa0609e1f
commit 7d275a6390
  1. 46
      core/area.h
  2. 5
      core/textpage.cpp

@ -275,24 +275,34 @@ struct HighlightRect : public NormalizedRect
/** @internal */
template <typename T>
class okularDeleter
class okularPtrUtils
{
public:
static void doDelete( T& t )
{
(void)t;
}
static T* givePtr( T& t )
{
return &t;
}
};
/** @internal */
template <typename T>
class okularDeleter<T*>
class okularPtrUtils<T*>
{
public:
static void doDelete( T* t )
{
delete t;
}
static T* givePtr( T* t )
{
return t;
}
};
/**
@ -315,6 +325,7 @@ template <class NormalizedShape, class Shape> class RegularArea : public QList<
bool intersects (const RegularArea<NormalizedShape,Shape> * area) const;
bool intersects (const NormalizedShape& shape) const;
void appendArea (const RegularArea<NormalizedShape,Shape> *area);
void appendShape( const NormalizedShape& shape );
void simplify ();
bool isNull() const;
QList<Shape>* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const;
@ -325,7 +336,7 @@ RegularArea<NormalizedShape, Shape>::~RegularArea<NormalizedShape, Shape>()
{
int size = this->count();
for ( int i = 0; i < size; ++i )
okularDeleter<NormalizedShape>::doDelete( (*this)[i] );
okularPtrUtils<NormalizedShape>::doDelete( (*this)[i] );
}
template <class NormalizedShape, class Shape>
@ -342,7 +353,7 @@ void RegularArea<NormalizedShape, Shape>::simplify()
*((*this)[x]) |= *((*this)[i+1]);
NormalizedShape tobedeleted = (*this)[i+1];
this->removeAt( i + 1 );
okularDeleter<NormalizedShape>::doDelete( tobedeleted );
okularPtrUtils<NormalizedShape>::doDelete( tobedeleted );
--end;
--i;
}
@ -420,6 +431,33 @@ void RegularArea<NormalizedShape, Shape>::appendArea( const RegularArea<Normaliz
}
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::appendShape( const NormalizedShape& shape )
{
if ( !this )
return;
int size = this->count();
// if the list is empty, adds the shape normally
if ( size == 0 )
{
this->append( shape );
}
else
{
// if the new shape intersects with the last shape in the list, then
// merge it with that and delete the shape
if ( (*this)[size - 1]->intersects( shape ) )
{
*((*this)[size - 1]) |= *okularPtrUtils<NormalizedShape>::givePtr( shape );
okularPtrUtils<NormalizedShape>::doDelete( shape );
}
else
this->append( shape );
}
}
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::contains( double x, double y ) const
{

@ -215,7 +215,7 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const
{
tmp=d->m_words[it]->area();
if (tmp->intersects(&first))
ret->append(tmp);
ret->appendShape(tmp);
}
}
else*/
@ -234,13 +234,12 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const
{
tmp=d->m_words[it]->transformedArea();
if (tmp->intersects(&first) || tmp->intersects(&second) || tmp->intersects(&third))
ret->append(new NormalizedRect(*tmp));
ret->appendShape(new NormalizedRect(*tmp));
}
// }
}
ret->simplify();
return ret;
}

Loading…
Cancel
Save