properly delete the regular areas of a RegularArea<> when it stores pointers to areas. no more memory leaks for RegularArea<>, yay!

svn path=/trunk/playground/graphics/okular/; revision=616069
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent 8d8ae89b1d
commit 0fa0609e1f
  1. 34
      core/area.h
  2. 8
      core/page.cpp

@ -272,6 +272,29 @@ struct HighlightRect : public NormalizedRect
QColor color;
};
/** @internal */
template <typename T>
class okularDeleter
{
public:
static void doDelete( T& t )
{
(void)t;
}
};
/** @internal */
template <typename T>
class okularDeleter<T*>
{
public:
static void doDelete( T* t )
{
delete t;
}
};
/**
* @short A regular area of NormalizedShape which normalizes a Shape
*
@ -286,6 +309,7 @@ struct HighlightRect : public NormalizedRect
template <class NormalizedShape, class Shape> class RegularArea : public QList<NormalizedShape>
{
public:
~RegularArea();
bool contains( double x, double y ) const;
bool contains( const NormalizedShape& shape ) const;
bool intersects (const RegularArea<NormalizedShape,Shape> * area) const;
@ -296,6 +320,14 @@ template <class NormalizedShape, class Shape> class RegularArea : public QList<
QList<Shape>* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const;
};
template <class NormalizedShape, class Shape>
RegularArea<NormalizedShape, Shape>::~RegularArea<NormalizedShape, Shape>()
{
int size = this->count();
for ( int i = 0; i < size; ++i )
okularDeleter<NormalizedShape>::doDelete( (*this)[i] );
}
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::simplify()
{
@ -308,7 +340,9 @@ void RegularArea<NormalizedShape, Shape>::simplify()
if ( (*this)[x]->intersects( (*this)[i+1] ) )
{
*((*this)[x]) |= *((*this)[i+1]);
NormalizedShape tobedeleted = (*this)[i+1];
this->removeAt( i + 1 );
okularDeleter<NormalizedShape>::doDelete( tobedeleted );
--end;
--i;
}

@ -582,12 +582,8 @@ void Page::deleteHighlights( int s_id )
void Page::deleteTextSelections()
{
if (m_textSelections)
{
qDeleteAll(*m_textSelections);
delete m_textSelections;
m_textSelections = 0;
}
delete m_textSelections;
m_textSelections = 0;
}
void Page::deleteSourceReferences()

Loading…
Cancel
Save