Commit 52f52dd9 authored by Jan Möbius's avatar Jan Möbius
Browse files

Tobias: Speedup datacontrol

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15168 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 417b16fb
...@@ -42,8 +42,7 @@ ...@@ -42,8 +42,7 @@
#include "TreeItem.hh" #include "TreeItem.hh"
/// Acceleration map QMap<int,TreeItem*> TreeItem::kTreeMap_;
static QMap<int,TreeItem*> treeMap_;
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
...@@ -54,18 +53,19 @@ TreeItem::TreeItem(int _id, QString _name, DataType _type, TreeItem* _parent) : ...@@ -54,18 +53,19 @@ TreeItem::TreeItem(int _id, QString _name, DataType _type, TreeItem* _parent) :
source_(false), source_(false),
visible_(true), visible_(true),
name_(_name), name_(_name),
parentItem_(_parent) parentItem_(_parent),
row_(0)
{ {
// Remember ourself ;-) // Remember ourself ;-)
treeMap_[_id] = this; kTreeMap_[_id] = this;
} }
TreeItem::~TreeItem() { TreeItem::~TreeItem() {
// Remove itself from map // Remove itself from map
QMap<int,TreeItem*>::iterator iter = treeMap_.find( id() ); QMap<int,TreeItem*>::iterator iter = kTreeMap_.find( id() );
if( iter != treeMap_.end() ) { if( iter != kTreeMap_.end() ) {
treeMap_.erase(iter); kTreeMap_.erase(iter);
} else { } else {
std::cerr << "Map accelerator destructor in DataControl: Currently removing object that is not in the map!" << std::endl; std::cerr << "Map accelerator destructor in DataControl: Currently removing object that is not in the map!" << std::endl;
} }
...@@ -191,8 +191,8 @@ TreeItem* TreeItem::next() { ...@@ -191,8 +191,8 @@ TreeItem* TreeItem::next() {
while ( parentPointer ) { while ( parentPointer ) {
// If there is an unvisited child of the parent, return this one // If there is an unvisited child of the parent, return this one
const int position = (thisPointer->row() + 1); int position = thisPointer->row() + 1;
if ( parentPointer->childCount() > position ) { if ( parentPointer->childCount() > position ) {
return parentPointer->childItems_[ position ]; return parentPointer->childItems_[ position ];
} }
...@@ -228,10 +228,7 @@ int TreeItem::level() { ...@@ -228,10 +228,7 @@ int TreeItem::level() {
int TreeItem::row() const int TreeItem::row() const
{ {
if (parentItem_) return row_;
return parentItem_->childItems_.indexOf(const_cast<TreeItem*>(this));
return 0;
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
...@@ -251,8 +248,9 @@ void TreeItem::setParent(TreeItem* _parent) { ...@@ -251,8 +248,9 @@ void TreeItem::setParent(TreeItem* _parent) {
void TreeItem::appendChild(TreeItem *item) void TreeItem::appendChild(TreeItem *item)
{ {
treeMap_[item->id()] = item; kTreeMap_[item->id()] = item;
childItems_.append(item); childItems_.append(item);
item->row_ = childItems_.size() - 1;
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
...@@ -278,10 +276,10 @@ TreeItem* TreeItem::childExists(int _objectId) { ...@@ -278,10 +276,10 @@ TreeItem* TreeItem::childExists(int _objectId) {
return this; return this;
// Check the map, for the item // Check the map, for the item
QMap<int,TreeItem*>::const_iterator iter = treeMap_.find(_objectId); QMap<int,TreeItem*>::const_iterator iter = kTreeMap_.find(_objectId);
// Not found -> return 0 // Not found -> return 0
if( iter == treeMap_.end() ) { if( iter == kTreeMap_.end() ) {
return 0; return 0;
} }
...@@ -310,21 +308,18 @@ TreeItem* TreeItem::childExists(int _objectId) { ...@@ -310,21 +308,18 @@ TreeItem* TreeItem::childExists(int _objectId) {
void TreeItem::removeChild( TreeItem* _item ) { void TreeItem::removeChild( TreeItem* _item ) {
bool found = false; int idx = (_item != 0) ? _item->row_ : -1;
QList<TreeItem*>::iterator i;
for (i = childItems_.begin(); i != childItems_.end(); ++i) {
if ( *i == _item ) {
found = true;
break;
}
}
if ( !found ) { if ( (idx < 0) || (idx >= childItems_.size()) || (childItems_[idx] != _item) ) {
std::cerr << "TreeItem: Illegal remove request" << std::endl; std::cerr << "TreeItem: Illegal remove request" << std::endl;
return; return;
} }
childItems_.erase(i); childItems_.removeAt(idx);
for ( ; idx < childItems_.size(); ++idx ) {
--(childItems_[idx]->row_);
}
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
......
...@@ -110,12 +110,18 @@ class TreeItem { ...@@ -110,12 +110,18 @@ class TreeItem {
int level(); int level();
private: private:
/// Parent item or 0 if rootnode /// Parent item or 0 if root node
TreeItem *parentItem_; TreeItem *parentItem_;
/// Index of this node in parent's childen
int row_;
/// Children of this node /// Children of this node
QList<TreeItem*> childItems_; QList<TreeItem*> childItems_;
/// Acceleration map
static QMap<int,TreeItem*> kTreeMap_;
public: public:
//=========================================================================== //===========================================================================
/** @name Tree : Parent nodes /** @name Tree : Parent nodes
...@@ -125,7 +131,7 @@ class TreeItem { ...@@ -125,7 +131,7 @@ class TreeItem {
/// get the row of this item from the parent /// get the row of this item from the parent
int row() const; int row() const;
/// Get the parent item ( 0 if rootitem ) /// Get the parent item ( 0 if root item )
TreeItem *parent(); TreeItem *parent();
/// Set the parent pointer /// Set the parent pointer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment