[Kst] branches/work/kst/portto4/kst/src/libkst
George Staikos
staikos at kde.org
Wed May 30 08:54:04 CEST 2007
SVN commit 669724 by staikos:
more checks and cleanup, and add a copy constructor to indicate where Kst will
crash due to shallow copy of pointers. This is really nasty and took hours to
track down. It may also affect trunk, but I don't know of any place doing this
particular thing in trunk.
M +13 -9 kstobjectcollection.h
--- branches/work/kst/portto4/kst/src/libkst/kstobjectcollection.h #669723:669724
@@ -75,6 +75,7 @@
class KstObjectCollection {
public:
KstObjectCollection();
+ KstObjectCollection(const KstObjectCollection& copy) { qDebug() << "CRASH! Deep copy required."; }
~KstObjectCollection();
typedef typename KstObjectList<KstSharedPtr<T> >::const_iterator const_iterator;
@@ -193,11 +194,11 @@
template <class T>
KstObjectTreeNode<T> *KstObjectTreeNode<T>::child(const QString& tag) const {
- if (_children.contains(tag)) {
- return _children[tag];
- } else {
- return NULL;
+ typename QMap<QString, KstObjectTreeNode<T> *>::ConstIterator i = _children.find(tag);
+ if (i != _children.end()) {
+ return *i;
}
+ return 0;
}
@@ -245,12 +246,15 @@
nextNode->_parent = currNode;
currNode->_children[*i] = nextNode;
if (index) {
- QList<KstObjectTreeNode<T> *> *l;
- if (!(l = index->take(*i))) {
+ QList<KstObjectTreeNode<T> *> *l = 0;
+ typename KstObjectNameIndex<T>::Iterator it = index->find(*i);
+ if (it == index->end()) {
l = new QList<KstObjectTreeNode<T> *>;
+ index->insert(*i, l);
+ } else {
+ l = *it;
}
l->append(nextNode);
- index->insert(*i, l);
}
}
currNode = nextNode;
@@ -756,7 +760,8 @@
// recursion helper
template <class T>
void KstObjectCollection<T>::relatedNodesHelper(T *o, KstObjectTreeNode<T> *n, QHash<int, KstObjectTreeNode<T>* >& nodes) {
-
+ Q_ASSERT(o);
+ Q_ASSERT(n);
if (n->object() && n->object() != o && !nodes.contains((long)n)) {
#if NAMEDEBUG > 2
qDebug() << "Found related node to" << o->tag().tagString() << ":" << n->object()->tag().tagString();
@@ -795,7 +800,6 @@
for (QStringList::ConstIterator i = ft.begin(); i != ft.end(); ++i) {
typename KstObjectNameIndex<T>::ConstIterator ni = _index.find(*i);
- qDebug() << "Iterate" << *i;
if (ni != _index.end()) {
QList<KstObjectTreeNode<T> *> *nodeList = *ni;
for (typename QList<KstObjectTreeNode<T> *>::ConstIterator i2 = nodeList->begin(); i2 != nodeList->end(); ++i2) {
More information about the Kst
mailing list