[rkward-cvs] SF.net SVN: rkward: [2143] branches/KDE4_port
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Mon Oct 29 21:35:22 UTC 2007
Revision: 2143
http://rkward.svn.sourceforge.net/rkward/?rev=2143&view=rev
Author: tfry
Date: 2007-10-29 14:35:21 -0700 (Mon, 29 Oct 2007)
Log Message:
-----------
Some more preparations for switching to an item model for the R object lists
Modified Paths:
--------------
branches/KDE4_port/TODO_KDE4
branches/KDE4_port/rkward/core/rcontainerobject.cpp
branches/KDE4_port/rkward/core/rcontainerobject.h
branches/KDE4_port/rkward/core/robjectlist.cpp
branches/KDE4_port/rkward/misc/rkspinbox.cpp
branches/KDE4_port/rkward/settings/rksettingsmoduledebug.cpp
Modified: branches/KDE4_port/TODO_KDE4
===================================================================
--- branches/KDE4_port/TODO_KDE4 2007-10-29 19:16:49 UTC (rev 2142)
+++ branches/KDE4_port/TODO_KDE4 2007-10-29 21:35:21 UTC (rev 2143)
@@ -28,6 +28,7 @@
- the whole idea of having a single mutex for everything is flawed. We should use several specialized ones
-* the 'X' icon for closing a tab (Ctl-W) is absent
-* when rkward freezes, terminating (window close -> Terminate) rkward does not kill rkward.bin
+ - do some profiling, whether the more expensive lookup in RContainerObject::findObjectByName() is a performance issue
rkcommandeditorwindow
- code completion
Modified: branches/KDE4_port/rkward/core/rcontainerobject.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rcontainerobject.cpp 2007-10-29 19:16:49 UTC (rev 2142)
+++ branches/KDE4_port/rkward/core/rcontainerobject.cpp 2007-10-29 21:35:21 UTC (rev 2143)
@@ -124,10 +124,13 @@
RKGlobals::tracker ()->lockUpdates (true); // object not yet added. prevent updates
child_object = updateChildStructure (child_object, child_data, true);
RKGlobals::tracker ()->lockUpdates (false);
- RK_ASSERT (child_object);
- if (child_object) childmap.insert (position, child_object);
- if (child_object) RKGlobals::tracker ()->addObject (child_object, 0);
+ if (!child_object) {
+ RK_ASSERT (false);
+ return 0;
+ }
+ childmap.insert (position, child_object);
+ RKGlobals::tracker ()->addObject (child_object, 0);
return child_object;
}
@@ -136,7 +139,7 @@
RK_ASSERT (new_children->getDataType () == RData::StructureVector);
unsigned int new_child_count = new_children->getDataLength ();
-// first find out, which children are now available, copy the old ones, create the new ones
+ // first find out, which children are now available, copy the old ones, create the new ones
RObjectMap new_childmap;
for (unsigned int i = 0; i < new_child_count; ++i) {
RData *child_data = new_children->getStructureVector ()[i];
@@ -156,37 +159,44 @@
new_childmap.insert (i, child_object);
}
-// now find out, which old ones are missing
- QList<RObject*> removed_list;
- for (int i = childmap.size () - 1; i >= 0; --i) {
+ // now find out, which old ones are missing or changed position
+ for (int i = 0; i < childmap.size (); ++i) { // do *not* cache the childmap.size ()! We may change it in the loop.
RObject* old_child = childmap[i];
- QString child_name = old_child->getShortName ();
- RObject* new_child = 0;
- for (int j = new_childmap.size () - 1; j >= 0; --j) {
- RObject* obj = new_childmap[j];
- if (obj->getShortName () == child_name) {
- new_child = obj;
- break;
- }
- }
- if (!new_child) {
+ int new_pos = new_childmap.indexOf (old_child);
+ if (new_pos < 0) {
if (old_child->isPending ()) {
- new_childmap.append (old_child);
+ new_childmap.insert (i, old_child);
} else {
- removed_list.append (old_child);
+ RK_DO (qDebug ("child no longer present: %s.", old_child->getFullName ().toLatin1 ().data ()), OBJECTS, DL_DEBUG);
+ if (RKGlobals::tracker ()->removeObject (old_child, 0, true)) --i;
+ else (new_childmap.insert (i, old_child));
}
+ } else {
+ if (i != new_pos) {
+ // this call is rather expensive, all in all, but fortunately called very rarely
+ moveChild (old_child, i, new_pos);
+ }
}
}
-// finally delete the missing old ones
- for (int i = removed_list.size () - 1; i >= 0; --i) {
- RObject* child = removed_list[i];
- RK_DO (qDebug ("child no longer present: %s.", child->getFullName ().toLatin1 ().data ()), OBJECTS, DL_DEBUG);
- RKGlobals::tracker ()->removeObject (child, 0, true);
- }
+ RK_DO (RK_ASSERT (childmap == new_childmap), OBJECTS, DL_DEBUG); // this is an expensive assert, hence wrapping it inside RK_DO
+}
- childmap = new_childmap;
+void RContainerObject::moveChild (RObject* child, int from_index, int to_index) {
+ RK_TRACE (OBJECTS);
+
+ RK_ASSERT (from_index != to_index);
+
+ RK_DO (qDebug ("Child position changed from %d to %d, %s", from_index, to_index, child->getFullName ().toLatin1 ().data ()), OBJECTS, DL_DEBUG);
+
+ RK_ASSERT (childmap[from_index] == child);
+ RK_ASSERT (from_index < childmap.size ());
+ childmap.removeAt (from_index);
+ RK_ASSERT (to_index <= childmap.size ());
+ childmap.insert (to_index, child);
+
+#warning TODO notify the modification tracker
}
int RContainerObject::numChildren () {
Modified: branches/KDE4_port/rkward/core/rcontainerobject.h
===================================================================
--- branches/KDE4_port/rkward/core/rcontainerobject.h 2007-10-29 19:16:49 UTC (rev 2142)
+++ branches/KDE4_port/rkward/core/rcontainerobject.h 2007-10-29 21:35:21 UTC (rev 2143)
@@ -68,6 +68,8 @@
/** reimplemented from RObject to actually search for matching objects */
void findObjectsMatching (const QString &partial_name, RObjectSearchMap *current_list, bool name_is_canonified=false);
+
+ void moveChild (RObject* child, int from_index, int to_index);
protected:
void updateChildren (RData *new_children);
RObjectMap childmap;
Modified: branches/KDE4_port/rkward/core/robjectlist.cpp
===================================================================
--- branches/KDE4_port/rkward/core/robjectlist.cpp 2007-10-29 19:16:49 UTC (rev 2142)
+++ branches/KDE4_port/rkward/core/robjectlist.cpp 2007-10-29 21:35:21 UTC (rev 2143)
@@ -118,27 +118,28 @@
}
} else {
obj = createTopLevelEnvironment (name);
+ childmap.insert (i, obj);
RKGlobals::tracker ()->addObject (obj, 0);
}
newchildmap.insert (i, obj);
}
- // check which envs have been removed
- QList<RObject *> removelist;
+ // check which envs have been removed or changed position
for (int i = childmap.size () - 1; i >= 0; --i) {
RObject *obj = childmap[i];
- bool found = newchildmap.contains (obj);
- if (!found) removelist.append (obj);
+ int new_pos = newchildmap.indexOf (obj);
+
+ if (new_pos < 0) { // environment is gone
+ RK_DO (qDebug ("removing toplevel environment %s from list", obj->getShortName ().toLatin1 ().data ()), OBJECTS, DL_INFO);
+ if (RKGlobals::tracker ()->removeObject (obj, 0, true)) --i;
+ else (newchildmap.insert (i, obj));
+ } else if (new_pos != i) {
+ // this call is rather expensive, all in all, but fortunately called very rarely
+ moveChild (obj, i, new_pos);
+ }
}
- // remove the environments which are gone
- for (QList<RObject *>::const_iterator it = removelist.constBegin (); it != removelist.constEnd (); ++it) {
- RK_DO (qDebug ("removing toplevel environment %s from list", (*it)->getShortName ().toLatin1 ().data ()), OBJECTS, DL_INFO);
- RKGlobals::tracker ()->removeObject (*it, 0, true);
- }
-
- // set the new list
- childmap = newchildmap;
+ RK_DO (RK_ASSERT (childmap == newchildmap), OBJECTS, DL_DEBUG); // this is an expensive assert, hence wrapping it inside RK_DO
}
REnvironmentObject *RObjectList::createTopLevelEnvironment (const QString &name) {
Modified: branches/KDE4_port/rkward/misc/rkspinbox.cpp
===================================================================
--- branches/KDE4_port/rkward/misc/rkspinbox.cpp 2007-10-29 19:16:49 UTC (rev 2142)
+++ branches/KDE4_port/rkward/misc/rkspinbox.cpp 2007-10-29 21:35:21 UTC (rev 2143)
@@ -33,6 +33,7 @@
mode = Integer;
real_value = 0;
int_value = 0;
+ default_precision = 0;
int_min = INT_MIN;
int_max = INT_MAX;
@@ -131,7 +132,7 @@
} else {
power = -default_precision;
}
- int step = (int) pow (10, power-1);
+ int step = (int) pow (10, power);
if (step < 1) step = 1;
int_value += change * step;
@@ -163,6 +164,7 @@
real_value = initial;
real_min = min;
real_max = max;
+ RK_ASSERT (real_min < real_max);
RKSpinBox::default_precision = default_precision;
setValue (0);
@@ -182,7 +184,9 @@
int_min = min;
int_max = max;
+ RK_ASSERT (int_min < int_max);
int_value = initial;
+ default_precision = 0;
mode = Integer;
Modified: branches/KDE4_port/rkward/settings/rksettingsmoduledebug.cpp
===================================================================
--- branches/KDE4_port/rkward/settings/rksettingsmoduledebug.cpp 2007-10-29 19:16:49 UTC (rev 2142)
+++ branches/KDE4_port/rkward/settings/rksettingsmoduledebug.cpp 2007-10-29 21:35:21 UTC (rev 2143)
@@ -44,7 +44,7 @@
label = new QLabel (i18n ("Debug level"), this);
debug_level_box = new RKSpinBox (this);
- debug_level_box->setIntMode (DL_FATAL, DL_TRACE, DL_FATAL - RK_Debug_Level);
+ debug_level_box->setIntMode (DL_TRACE, DL_FATAL, DL_FATAL - RK_Debug_Level);
connect (debug_level_box, SIGNAL (valueChanged(int)), this, SLOT (settingChanged(int)));
main_vbox->addWidget (label);
main_vbox->addWidget (debug_level_box);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list