[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/libs/kofficecore
From: Thorsten Zachmann <t.zachmann () zagge ! de>
Date: 2007-03-14 6:33:56
Message-ID: 1173854036.592766.30183.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 642358 by zachmann:
o Fix memleak in destructor and clear method when the tree was not empty.
o updated the testupto test the clear method.
M +28 -2 KoRTree.h
M +34 -12 tests/rtreetestapp.cpp
M +2 -0 tests/rtreetestapp.h
--- trunk/koffice/libs/kofficecore/KoRTree.h #642357:642358
@@ -211,7 +211,7 @@
{
public:
NoneLeafNode( int capacity, int level, Node * parent );
- virtual ~NoneLeafNode() {}
+ virtual ~NoneLeafNode();
virtual void insert( const QRectF& bb, Node * data );
virtual void remove( int index );
@@ -244,7 +244,7 @@
static int dataIdCounter;
LeafNode( int capacity, int level, Node * parent );
- virtual ~LeafNode() {}
+ virtual ~LeafNode();
virtual void insert( const QRectF& bb, const T& data, int id );
virtual void remove( int index );
@@ -411,6 +411,8 @@
{
insertHelper( leaf->childBoundingBox(j), leaf->getData( j ), \
leaf->getDataId( j ) ); }
+ // clear is needed as the data items are not removed when insert into a \
new node + leaf->clear();
delete leaf;
}
else
@@ -420,6 +422,8 @@
{
insert( node->getNode( j ) );
}
+ // clear is needed as the data items are not removed when insert into a \
new node + node->clear();
delete node;
}
}
@@ -558,6 +562,8 @@
}
//qDebug() << " delete n1" << n1 << n1->nodeId();
+ // clear is needed as the data items are not removed
+ n1->clear();
delete n1;
return qMakePair( node, n2 );
}
@@ -715,6 +721,8 @@
if ( n )
{
Node * kid = n->getNode( 0 );
+ // clear is needed as the data items are not removed
+ m_root->clear();
delete m_root;
m_root = kid;
m_root->setParent( 0 );
@@ -808,9 +816,20 @@
: Node( capacity, level, parent )
, m_childs( capacity )
{
+ //qDebug() << "NoneLeafNode::NoneLeafNode()" << this;
}
template <typename T>
+KoRTree<T>::NoneLeafNode::~NoneLeafNode()
+{
+ //qDebug() << "NoneLeafNode::~NoneLeafNode()" << this;
+ for ( int i = 0; i < this->m_counter; ++i )
+ {
+ delete m_childs[i];
+ }
+}
+
+template <typename T>
void KoRTree<T>::NoneLeafNode::insert( const QRectF& bb, Node * data )
{
m_childs[this->m_counter] = data;
@@ -973,6 +992,13 @@
, m_data( capacity )
, m_dataIds( capacity )
{
+ //qDebug() << "LeafNode::LeafNode" << this;
+}
+
+template <typename T>
+KoRTree<T>::LeafNode::~LeafNode()
+{
+ //qDebug() << "LeafNode::~LeafNode" << this;
}
template <typename T>
--- trunk/koffice/libs/kofficecore/tests/rtreetestapp.cpp #642357:642358
@@ -50,7 +50,7 @@
{
m_tool = &m_createTool;
setBackgroundRole(QPalette::Base);
- m_file.open( QIODevice::WriteOnly );
+ m_file.open( QIODevice::WriteOnly | QIODevice::Unbuffered );
m_out.setDevice( &m_file );
}
@@ -61,7 +61,7 @@
void Canvas::insert( QRectF & rect )
{
- m_out << "i " << rect.left() << " " << rect.top() << " " << rect.width() << " " \
<< rect.height() << "\n"; + m_out << "i " << rect.left() << " " << rect.top() << " \
" << rect.width() << " " << rect.height() << endl; Data * data = new Data( rect );
m_rects.insert( data );
m_rtree.insert( rect, data );
@@ -83,7 +83,7 @@
void Canvas::remove( QRectF & rect )
{
- m_out << "r " << rect.left() << " " << rect.top() << " " << rect.width() << " " \
<< rect.height() << "\n"; + m_out << "r " << rect.left() << " " << rect.top() << " \
" << rect.width() << " " << rect.height() << endl; m_found = QList<Data *>();
QList<Data *> remove = m_rtree.intersects( rect );
foreach ( Data * data, remove )
@@ -95,6 +95,15 @@
update();
}
+void Canvas::clear()
+{
+ m_out << "c" << endl;
+ m_rtree.clear();
+ qDeleteAll( m_rects );
+ m_rects.clear();
+ update();
+}
+
void Canvas::replay()
{
if ( QCoreApplication::arguments().size() > 1 )
@@ -108,6 +117,7 @@
{
m_list.push_back( in.readLine() );
}
+ qDebug() << "commands:" << m_list.size();
m_listId = 0;
QTimer::singleShot( 1000, this, SLOT( replayStep() ) );
}
@@ -119,18 +129,25 @@
QString line = m_list.at( m_listId++ );
qDebug() << "Line:" << line;
QStringList values = line.split( " " );
- int left = values[1].toInt();
- int top = values[2].toInt();
- int right = values[3].toInt();
- int bottom = values[4].toInt();
- QRectF rect( left, top, right, bottom );
- if ( values[0] == "i" )
+ if ( values[0] == "c" )
{
- insert( rect );
+ clear();
}
- else if ( values[0] == "r" )
+ else
{
- remove( rect );
+ int left = values[1].toInt();
+ int top = values[2].toInt();
+ int right = values[3].toInt();
+ int bottom = values[4].toInt();
+ QRectF rect( left, top, right, bottom );
+ if ( values[0] == "i" )
+ {
+ insert( rect );
+ }
+ else if ( values[0] == "r" )
+ {
+ remove( rect );
+ }
}
update();
@@ -279,6 +296,10 @@
m_removeAct->setStatusTip(tr("Remove Object"));
connect(m_removeAct, SIGNAL(triggered()), m_canvas, SLOT( selectRemoveTool() ) \
);
+ m_clearAct = new QAction(tr("&Clear"), this);
+ m_clearAct->setStatusTip(tr("Clear Object"));
+ connect(m_clearAct, SIGNAL(triggered()), m_canvas, SLOT( clear() ) );
+
m_replayAct = new QAction(tr("&Replay"), this);
m_replayAct->setShortcut(QKeySequence(tr("Ctrl+R")));
m_replayAct->setStatusTip(tr("Replay"));
@@ -309,6 +330,7 @@
m_editMenu->addAction(m_insertAct);
m_editMenu->addAction(m_selectAct);
m_editMenu->addAction(m_removeAct);
+ m_editMenu->addAction(m_clearAct);
menuBar()->addSeparator();
--- trunk/koffice/libs/kofficecore/tests/rtreetestapp.h #642357:642358
@@ -73,6 +73,7 @@
void selectInsertTool();
void selectSelectTool();
void selectRemoveTool();
+ void clear();
void replay();
void debug();
@@ -134,6 +135,7 @@
QAction * m_insertAct;
QAction * m_selectAct;
QAction * m_removeAct;
+ QAction * m_clearAct;
QActionGroup *m_toolAct;
QAction * m_replayAct;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic