[rkward-cvs] SF.net SVN: rkward: [2142] branches/KDE4_port/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Mon Oct 29 19:16:49 UTC 2007
Revision: 2142
http://rkward.svn.sourceforge.net/rkward/?rev=2142&view=rev
Author: tfry
Date: 2007-10-29 12:16:49 -0700 (Mon, 29 Oct 2007)
Log Message:
-----------
Children of RContainerObjects are now stored in a QList indexed by their (integer) position in the R backend
This is the first step in porting the RObjectListView to the Qt4 model/view architecture.
Modified Paths:
--------------
branches/KDE4_port/rkward/core/rcontainerobject.cpp
branches/KDE4_port/rkward/core/rcontainerobject.h
branches/KDE4_port/rkward/core/robject.cpp
branches/KDE4_port/rkward/core/robject.h
branches/KDE4_port/rkward/core/robjectlist.cpp
branches/KDE4_port/rkward/core/robjectlist.h
branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp
branches/KDE4_port/rkward/rkconsole.cpp
branches/KDE4_port/rkward/rkward.cpp
branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp
Modified: branches/KDE4_port/rkward/core/rcontainerobject.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rcontainerobject.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/core/rcontainerobject.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -40,8 +40,8 @@
RK_TRACE (OBJECTS);
// delete child objects. Note: the map itself is cleared/deleted automatically
- for (RObjectMap::iterator it = childmap.begin (); it != childmap.end (); ++it) {
- delete it.data ();
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ delete childmap[i];
}
}
@@ -59,13 +59,15 @@
delete child;
return 0;
} else {
+ int child_index = getIndexOf (child);
+ RK_ASSERT (child_index >= 0);
if (RKGlobals::tracker ()->removeObject (child, 0, true)) {
RData *child_name_data = new_data->getStructureVector ()[0];
RK_ASSERT (child_name_data->getDataType () == RData::StringVector);
RK_ASSERT (child_name_data->getDataLength () >= 1);
QString child_name = child_name_data->getStringVector ()[0];
-
- return (createChildFromStructure (new_data, child_name));
+
+ return (createChildFromStructure (new_data, child_name, child_index));
} else {
return child; // it was restored in it's old shape
}
@@ -94,10 +96,9 @@
return true;
}
-RObject *RContainerObject::createChildFromStructure (RData *child_data, const QString &child_name) {
+RObject *RContainerObject::createChildFromStructure (RData *child_data, const QString &child_name, int position) {
RK_TRACE (OBJECTS);
RK_ASSERT (child_data->getDataType () == RData::StructureVector);
- RK_ASSERT (childmap.find (child_name) == childmap.end ());
RK_ASSERT (child_data->getDataLength () >= 2); // need to see at least the type at this point
RData *type_data = child_data->getStructureVector ()[1];
@@ -125,7 +126,7 @@
RKGlobals::tracker ()->lockUpdates (false);
RK_ASSERT (child_object);
- if (child_object) childmap.insert (child_name, child_object);
+ if (child_object) childmap.insert (position, child_object);
if (child_object) RKGlobals::tracker ()->addObject (child_object, 0);
return child_object;
}
@@ -146,34 +147,43 @@
RK_ASSERT (child_name_data->getDataLength () >= 1);
QString child_name = child_name_data->getStringVector ()[0];
- RObject *child_object;
- RObjectMap::const_iterator it = childmap.find (child_name);
- if (it != childmap.end ()) {
- child_object = updateChildStructure (it.data (), child_data);
+ RObject *child_object = findChildByName (child_name);
+ if (child_object) {
+ child_object = updateChildStructure (child_object, child_data);
} else {
- child_object = createChildFromStructure (child_data, child_name);
+ child_object = createChildFromStructure (child_data, child_name, i);
}
- new_childmap.insert (child_name, child_object);
+ new_childmap.insert (i, child_object);
}
// now find out, which old ones are missing
- Q3ValueList<RObject*> removed_list;
- for (RObjectMap::const_iterator it = childmap.constBegin (); it != childmap.constEnd (); ++it) {
- QString child_string = it.key ();
+ QList<RObject*> removed_list;
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ RObject* old_child = childmap[i];
+ QString child_name = old_child->getShortName ();
- if (new_childmap.find (child_string) == new_childmap.end ()) {
- if (it.data ()->isPending ()) {
- new_childmap.insert (child_string, it.data ());
+ 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) {
+ if (old_child->isPending ()) {
+ new_childmap.append (old_child);
} else {
- removed_list.append (it.data ());
+ removed_list.append (old_child);
}
}
}
// finally delete the missing old ones
- for (Q3ValueList<RObject*>::iterator it = removed_list.begin (); it != removed_list.end (); ++it) {
- RK_DO (qDebug ("child no longer present: %s.", (*it)->getFullName ().toLatin1 ().data ()), OBJECTS, DL_DEBUG);
- RKGlobals::tracker ()->removeObject ((*it), 0, true);
+ 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);
}
childmap = new_childmap;
@@ -184,31 +194,40 @@
return childmap.size ();
}
+// KDE4: do we need this? Can't we return the RObjectMap?
RObject **RContainerObject::children () {
RK_TRACE (OBJECTS);
RObject **ret = new RObject *[childmap.size ()];
- int i = 0;
- for (RObjectMap::iterator it = childmap.begin (); it != childmap.end (); ++it) {
- ret[i++] = it.data ();
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ ret[i] = childmap[i];
}
return ret;
}
void RContainerObject::writeChildMetaData (RCommandChain *chain) {
RK_TRACE (OBJECTS);
- for (RObjectMap::iterator it = childmap.begin (); it != childmap.end (); ++it) {
- it.data ()->writeMetaData (chain);
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ childmap[i]->writeMetaData (chain);
}
}
-RObject *RContainerObject::findChild (const QString &name) {
+RObject *RContainerObject::findChildByName (const QString &name) const {
RK_TRACE (OBJECTS);
- RObjectMap::iterator it = childmap.find (name);
- RK_ASSERT (it != childmap.end ());
- return (it.data ());
+
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ RObject* obj = childmap[i];
+ if (obj->getShortName () == name) return (obj);
+ }
+ return 0;
}
+int RContainerObject::getIndexOf (RObject *child) const {
+ RK_TRACE (OBJECTS);
+
+ return childmap.indexOf (child);
+}
+
RObject *RContainerObject::findObject (const QString &name, bool is_canonified) {
RK_TRACE (OBJECTS);
@@ -219,16 +238,15 @@
QString current_level = canonified.section (QChar ('$'), 0, 0);
QString remainder = canonified.section (QChar ('$'), 1);
- RObjectMap::iterator it = childmap.find (current_level);
- if (it == childmap.end ()) return 0;
+ RObject* found = findChildByName (current_level);
+ if (!found) return 0;
- RObject *found = it.data ();
if (remainder.isEmpty ()) return found;
return (found->findObject (remainder, true));
}
-void RContainerObject::findObjectsMatching (const QString &partial_name, RObjectMap *current_list, bool name_is_canonified) {
+void RContainerObject::findObjectsMatching (const QString &partial_name, RObjectSearchMap *current_list, bool name_is_canonified) {
RK_TRACE (OBJECTS);
RK_ASSERT (current_list);
@@ -240,40 +258,31 @@
QString remainder = canonified.section (QChar ('$'), 1);
if (canonified.endsWith (QChar ('$'))) {
- RObjectMap::iterator it = childmap.find (current_level);
-
- if (it == childmap.end ()) return;
-
- RObject *found = it.data ();
- found->findObjectsMatching (QString (), current_list, true);
-
+ RObject* found = findChildByName (current_level);
+ if (found) found->findObjectsMatching (QString (), current_list, true);
return;
}
if (remainder.isEmpty ()) {
- for (RObjectMap::const_iterator it = childmap.constBegin (); it != childmap.constEnd (); ++it) {
- if (it.key ().startsWith (current_level)) {
- QString base_name = it.data ()->getBaseName ();
+ for (int i = 0; i < childmap.size (); ++i) {
+ RObject* child = childmap[i];
+ if (child->getShortName ().startsWith (current_level)) {
+ QString base_name = child->getBaseName ();
if (current_list->contains (base_name)) {
- current_list->insert (it.data ()->getFullName (), it.data ());
+ current_list->insert (child->getFullName (), child);
} else {
- current_list->insert (base_name, it.data ());
+ current_list->insert (base_name, child);
}
}
}
} else {
- RObjectMap::iterator it = childmap.find (current_level);
-
- if (it == childmap.end ()) return;
-
- RObject *found = it.data ();
- found->findObjectsMatching (remainder, current_list, true);
+ RObject* found = findChildByName (current_level);
+ if (found) found->findObjectsMatching (remainder, current_list, true);
}
}
-RObject *RContainerObject::createNewChild (const QString &name, RKEditor *creator, bool container, bool data_frame) {
+RObject *RContainerObject::createNewChild (const QString &name, int position, RKEditor *creator, bool container, bool data_frame) {
RK_TRACE (OBJECTS);
- RK_ASSERT (childmap.find (name) == childmap.end ());
RObject *ret;
if (container) {
@@ -285,9 +294,11 @@
} else {
ret = new RKVariable (this, name);
}
-
- childmap.insert (name, ret);
+ if ((position < 0) || (position > childmap.size ())) position = childmap.size ();
+
+ childmap.insert (position, ret);
+
RKGlobals::tracker ()->addObject (ret, creator);
return ret;
@@ -296,15 +307,11 @@
void RContainerObject::renameChild (RObject *object, const QString &new_name) {
RK_TRACE (OBJECTS);
- RObjectMap::iterator it = childmap.find (object->getShortName ());
- RK_ASSERT (it.data () == object);
-
+ RK_ASSERT (findChildByName (object->getShortName ()) == object);
+
RCommand *command = new RCommand (renameChildCommand (object, new_name), RCommand::App | RCommand::Sync);
RKGlobals::rInterface ()->issueCommand (command, 0);
-
- childmap.remove (it.key ());
- childmap.insert (new_name, object);
-
+
object->name = new_name;
}
@@ -316,13 +323,14 @@
RKGlobals::rInterface ()->issueCommand (command, 0);
}
- RObjectMap::iterator it = childmap.find (object->getShortName ());
- if (it == childmap.end ()) {
+ int i = getIndexOf (object);
+ if (i < 0) {
+ RK_ASSERT (false);
return;
}
- RK_ASSERT (it.data () == object);
+ RK_ASSERT (childmap[i] == object);
- childmap.remove (it);
+ childmap.removeAt (i);
delete object;
}
@@ -341,8 +349,8 @@
bool RContainerObject::isParentOf (RObject *object, bool recursive) {
RK_TRACE (OBJECTS);
- for (RObjectMap::iterator it = childmap.begin (); it != childmap.end (); ++it) {
- RObject *child = it.data ();
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ RObject *child = childmap[i];
if (child == object) {
return true;
} else if (recursive && child->isContainer ()) {
@@ -365,7 +373,7 @@
if (!unique) return ret;
QString postfix;
- while (childmap.contains (ret + postfix)) {
+ while (findChildByName (ret + postfix)) {
postfix.setNum (++i);
}
return (ret + postfix);
Modified: branches/KDE4_port/rkward/core/rcontainerobject.h
===================================================================
--- branches/KDE4_port/rkward/core/rcontainerobject.h 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/core/rcontainerobject.h 2007-10-29 19:16:49 UTC (rev 2142)
@@ -38,7 +38,7 @@
/** update the given child with the given data. Since the child may be mismatching, and may need to be recreated, returns a pointer to the child (old or new) */
RObject *updateChildStructure (RObject *child, RData *new_data, bool just_created=false);
- RObject *createChildFromStructure (RData *child_data, const QString &child_name);
+ RObject *createChildFromStructure (RData *child_data, const QString &child_name, int position);
/** reimplemented from RObject to also update children */
bool updateStructure (RData *new_data);
@@ -47,13 +47,15 @@
RObject **children ();
/** like findObject (), but does not recurse, i.e. only direct children */
- RObject *findChild (const QString &name);
+ RObject *findChildByName (const QString &name) const;
+ /** return the index of the given child, or -1 if there is no such child */
+ int getIndexOf (RObject *child) const;
bool isParentOf (RObject *object, bool recursive=false);
/** creates a new child. Right now only RKVariables (false, false), or data.frames (true, true), or unspecified containers (true, false) can be created.
API will likely change. The child is NOT created in the workspace. That's your resonsibility. All this function returns is a new RObject* of the given
type and with the name (if necessary) changed to a legal value. TODO: checking for and changing illegal names is not yet implemented */
- virtual RObject *createNewChild (const QString &name, RKEditor *creator=0, bool container=false, bool data_frame=false);
+ virtual RObject *createNewChild (const QString &name, int position=-1, RKEditor *creator=0, bool container=false, bool data_frame=false);
/** returns true, if there are no children in this container. Note: of course the object list may not be up to date! */
bool isEmpty () { return childmap.isEmpty (); };
@@ -65,7 +67,7 @@
virtual RObject *findObject (const QString &name, bool is_canonified=false);
/** reimplemented from RObject to actually search for matching objects */
- void findObjectsMatching (const QString &partial_name, RObjectMap *current_list, bool name_is_canonified=false);
+ void findObjectsMatching (const QString &partial_name, RObjectSearchMap *current_list, bool name_is_canonified=false);
protected:
void updateChildren (RData *new_children);
RObjectMap childmap;
Modified: branches/KDE4_port/rkward/core/robject.cpp
===================================================================
--- branches/KDE4_port/rkward/core/robject.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/core/robject.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -82,7 +82,7 @@
return 0;
}
-void RObject::findObjectsMatching (const QString &, RObjectMap *, bool) {
+void RObject::findObjectsMatching (const QString &, RObjectSearchMap *, bool) {
RK_TRACE (OBJECTS);
return;
}
Modified: branches/KDE4_port/rkward/core/robject.h
===================================================================
--- branches/KDE4_port/rkward/core/robject.h 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/core/robject.h 2007-10-29 19:16:49 UTC (rev 2142)
@@ -123,8 +123,9 @@
/** short hand for getDimension (0). Meaningful for one-dimensional objects */
int getLength () { return dimensions[0]; };
-/** A map of objects accessible by their short name. Used in RContainerObject. Defined here for technical reasons. */
- typedef QMap<QString, RObject*> RObjectMap;
+/** A map of objects accessible by index. Used in RContainerObject. Defined here for technical reasons. */
+ typedef QList<RObject*> RObjectMap;
+ typedef QMap<QString, RObject*> RObjectSearchMap;
/** A map of values to labels. This is used both in regular objects, in which it just represents a map of named values, if any. The more important use is in factors, where it represents the factor levels. Here, the key is always a string representation of a positive integer. */
typedef QMap<QString, QString> ValueLabels;
@@ -161,7 +162,7 @@
@param partial_name The partial name to look up
@param current_list A pointer to a valid (but probably initially empty) RObjectMap. Matches will be added to this list
@param name_is_canonified internal parameter. Set to true, if the name to match is already canonfied (else it will be canonified internally) */
- virtual void findObjectsMatching (const QString &partial_name, RObjectMap *current_list, bool name_is_canonified=false);
+ virtual void findObjectsMatching (const QString &partial_name, RObjectSearchMap *current_list, bool name_is_canonified=false);
/** If the object is being edited, returns that editor (in the future probably a list of editors). Else returns 0 */
RKEditor *objectOpened ();
Modified: branches/KDE4_port/rkward/core/robjectlist.cpp
===================================================================
--- branches/KDE4_port/rkward/core/robjectlist.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/core/robjectlist.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -53,9 +53,8 @@
type = RObject::Workspace;
update_chain = 0;
- toplevel_environments = new REnvironmentObject*[1];
- num_toplevel_environments = 1;
- toplevel_environments[0] = createTopLevelEnvironment (".GlobalEnv");
+ childmap.insert (0, createTopLevelEnvironment (".GlobalEnv"));
+ RKGlobals::tracker ()->addObject (childmap[0], 0);
}
RObjectList::~RObjectList () {
@@ -105,63 +104,48 @@
void RObjectList::updateEnvironments (QString *env_names, unsigned int env_count) {
RK_TRACE (OBJECTS);
- Q3ValueList<REnvironmentObject *> removelist;
+ RObjectMap newchildmap;
- // check which envs are removed
- // we could as well iterate over the childmap, but this is easier
- for (unsigned int i = 0; i < num_toplevel_environments; ++i) {
- bool found = false;
- for (unsigned int j = 0; j < env_count; ++j) {
- if (toplevel_environments[i]->getShortName () == env_names[j]) {
- found = true;
- break;
- }
- }
- if (!found) removelist.append (toplevel_environments[i]);
- }
-
- // remove the environments which are gone
- for (Q3ValueList<REnvironmentObject *>::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);
- }
-
- // find which items are new
+ // find which items are new, and copy the old ones
for (unsigned int i = 0; i < env_count; ++i) {
QString name = env_names[i];
- if (childmap.find (name) == childmap.end ()) {
- createTopLevelEnvironment (name);
- } else {
- RObject *obj = childmap[name];
+
+ RObject* obj = findChildByName (name);
+ if (obj) {
// for now, we only update the .GlobalEnv. All others we assume to be static
if (obj->isType (GlobalEnv)) {
obj->updateFromR (update_chain);
}
+ } else {
+ obj = createTopLevelEnvironment (name);
+ RKGlobals::tracker ()->addObject (obj, 0);
}
+ newchildmap.insert (i, obj);
}
- // set the new list of environments in the correct order
- delete [] toplevel_environments;
- toplevel_environments = new REnvironmentObject*[env_count];
- num_toplevel_environments = env_count;
- for (unsigned int i = 0; i < env_count; ++i) {
- RObject *obj = childmap[env_names[i]];
- RK_ASSERT (obj);
- RK_ASSERT (obj->isType (Environment));
+ // check which envs have been removed
+ QList<RObject *> removelist;
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ RObject *obj = childmap[i];
+ bool found = newchildmap.contains (obj);
+ if (!found) removelist.append (obj);
+ }
- toplevel_environments[i] = static_cast<REnvironmentObject *> (obj);
+ // 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;
}
REnvironmentObject *RObjectList::createTopLevelEnvironment (const QString &name) {
RK_TRACE (OBJECTS);
- RK_ASSERT (childmap.find (name) == childmap.end ());
- REnvironmentObject *envobj = new REnvironmentObject (this, name);
- childmap.insert (name, envobj);
- RKGlobals::tracker ()->addObject (envobj, 0);
+ REnvironmentObject *envobj = new REnvironmentObject (this, name);
envobj->updateFromR (update_chain);
-
return envobj;
}
@@ -176,27 +160,21 @@
QString env = canonified.section ("::", 0, 0);
QString remainder = canonified.section ("::", 1);
- RObject *found = 0;
- for (unsigned int i = 0; i < num_toplevel_environments; ++i) {
- if (toplevel_environments[i]->namespaceName () == env) {
- found = toplevel_environments[i];
- break;
- }
- }
+ RObject *found = findChildByNamespace (env);
if (!found) return 0;
return (found->findObject (remainder, true));
}
// no "::"-qualification given, do normal search in all environments, return first match
- for (unsigned int i = 0; i < num_toplevel_environments; ++i) {
- RObject *found = toplevel_environments[i]->findObject (canonified, true);
+ for (int i = 0; i < childmap.size (); ++i) {
+ RObject *found = childmap[i]->findObject (canonified, true);
if (found) return found;
}
return 0;
}
-void RObjectList::findObjectsMatching (const QString &partial_name, RObjectMap *current_list, bool name_is_canonified) {
+void RObjectList::findObjectsMatching (const QString &partial_name, RObjectSearchMap *current_list, bool name_is_canonified) {
RK_TRACE (OBJECTS);
RK_ASSERT (current_list);
@@ -208,31 +186,39 @@
QString env = canonified.section ("::", 0, 0);
QString remainder = canonified.section ("::", 1);
- RObject *found = 0;
- for (unsigned int i = 0; i < num_toplevel_environments; ++i) {
- if (toplevel_environments[i]->namespaceName () == env) {
- found = toplevel_environments[i];
- break;
- }
- }
+ RObject *found = findChildByNamespace (env);
if (!found) return;
found->findObjectsMatching (remainder, current_list, true);
return;
}
- // no "::"-qualification given, do normal search in all environments.
- for (unsigned int i = 0; i < num_toplevel_environments; ++i) {
- toplevel_environments[i]->findObjectsMatching (canonified, current_list, true);
+ // no namespace given. Search all environments for matches
+ for (int i = 0; i < childmap.size (); ++i) {
+ childmap[i]->findObjectsMatching (canonified, current_list, true);
}
}
-RObject *RObjectList::createNewChild (const QString &name, RKEditor *creator, bool container, bool data_frame) {
+REnvironmentObject* RObjectList::findChildByNamespace (const QString &namespacename) {
RK_TRACE (OBJECTS);
- return (getGlobalEnv ()->createNewChild (name, creator, container, data_frame));
+ for (int i = childmap.size () - 1; i >= 0; --i) {
+ RObject* child = childmap[i];
+ RK_ASSERT (child->isType (Environment));
+ REnvironmentObject* env = static_cast<REnvironmentObject *> (child);
+ if (env->namespaceName () == namespacename) {
+ return env;
+ }
+ }
+ return 0;
}
+RObject *RObjectList::createNewChild (const QString &name, int position, RKEditor *creator, bool container, bool data_frame) {
+ RK_TRACE (OBJECTS);
+
+ return (getGlobalEnv ()->createNewChild (name, position, creator, container, data_frame));
+}
+
QString RObjectList::validizeName (const QString &child_name, bool unique) {
RK_TRACE (OBJECTS);
@@ -269,17 +255,6 @@
RK_TRACE (OBJECTS);
if (removed_in_workspace) {
- // remove from list of toplevel environments
- REnvironmentObject **new_toplevel_envs = new REnvironmentObject*[num_toplevel_environments];
- unsigned int num_new_toplevel_envs = 0;
- for (unsigned int i=0; i < num_toplevel_environments; ++i) {
- if (toplevel_environments[i] != object) new_toplevel_envs[num_new_toplevel_envs++] = toplevel_environments[i];
- }
- RK_ASSERT ((num_toplevel_environments - 1) == num_new_toplevel_envs);
- delete [] toplevel_environments;
- toplevel_environments = new_toplevel_envs;
- num_toplevel_environments = num_new_toplevel_envs;
-
RContainerObject::removeChild (object, removed_in_workspace);
} else {
RK_ASSERT (false);
@@ -293,7 +268,8 @@
RObjectList *list = getObjectList ();
RK_ASSERT (list);
- REnvironmentObject *envobj = list->toplevel_environments[0];
+ RK_ASSERT (list->numChildren ());
+ REnvironmentObject *envobj = static_cast<REnvironmentObject*> (list->childmap[0]);
RK_ASSERT (envobj);
RK_ASSERT (envobj->isType (RObject::GlobalEnv));
Modified: branches/KDE4_port/rkward/core/robjectlist.h
===================================================================
--- branches/KDE4_port/rkward/core/robjectlist.h 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/core/robjectlist.h 2007-10-29 19:16:49 UTC (rev 2142)
@@ -56,16 +56,18 @@
RObject *findObject (const QString &name, bool canonified=false);
/** reimplemented from RContainerObject to search the environments in search order */
- void findObjectsMatching (const QString &partial_name, RObjectMap *current_list, bool name_is_canonified=false);
+ void findObjectsMatching (const QString &partial_name, RObjectSearchMap *current_list, bool name_is_canonified=false);
/** reimplemented from RContainerObject to create the child in the .GlobalEnv */
- RObject *createNewChild (const QString &name, RKEditor *creator=0, bool container=false, bool data_frame=false);
+ RObject *createNewChild (const QString &name, int position=-1, RKEditor *creator=0, bool container=false, bool data_frame=false);
/** reimplemented from RContainerObject to validize the name in .GlobalEnv */
QString validizeName (const QString &child_name, bool unique=true);
KUrl getWorkspaceURL () { return current_url; };
+ REnvironmentObject* findChildByNamespace (const QString &namespacename);
+
static RObjectList *getObjectList () { return object_list; };
static REnvironmentObject *getGlobalEnv ();
public slots:
@@ -94,9 +96,6 @@
RCommandChain *update_chain;
- REnvironmentObject **toplevel_environments;
- unsigned int num_toplevel_environments;
-
REnvironmentObject *createTopLevelEnvironment (const QString &name);
KUrl current_url;
Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -87,7 +87,7 @@
if (initialize_to_empty) {
for (int i=0; i < numTrueCols (); ++i) {
- RObject *obj = static_cast<RContainerObject *> (getObject ())->createNewChild (static_cast<RContainerObject *> (getObject ())->validizeName ("var"), this);
+ RObject *obj = static_cast<RContainerObject *> (getObject ())->createNewChild (static_cast<RContainerObject *> (getObject ())->validizeName ("var"), i, this);
if (obj->isVariable ()) {
static_cast<RKVariable*> (obj)->setLength (dataview->numTrueRows ());
setColObject (i, static_cast<RKVariable*> (obj));
@@ -99,6 +99,7 @@
pushTable (open_chain);
}
+ // KDE4 TODO: this is no longer needed, as objects can now be addressed by their position in the parent
// actually, given the object, we already know the child-names. We don't know their order, however, so we better fetch the name-row again.
object->markDataDirty ();
object->updateFromR (open_chain);
@@ -125,7 +126,7 @@
if (numTrueCols () <= col) {
insertNewColumn ();
}
- RKVariable *current_child = static_cast<RKVariable *> (static_cast <RContainerObject*> (getObject ())->findChild (command->getStringVector ()[col]));
+ RKVariable *current_child = static_cast<RKVariable *> (static_cast <RContainerObject*> (getObject ())->findChildByName (command->getStringVector ()[col]));
RK_ASSERT (current_child);
if (current_child->isVariable ()) {
if (!getColObject (col)) { // if we initialized the table to empty, the object may already exist in our map
@@ -186,9 +187,9 @@
void RKEditorDataFrame::columnAdded (int col) {
RK_TRACE (EDITOR);
- RObject *obj = static_cast<RContainerObject *> (getObject ())->createNewChild (static_cast<RContainerObject *> (getObject ())->validizeName (QString::null), this);
+ RObject *obj = static_cast<RContainerObject *> (getObject ())->createNewChild (static_cast<RContainerObject *> (getObject ())->validizeName (QString ()), col, this);
RK_ASSERT (obj->isVariable ());
- RKGlobals::rInterface ()->issueCommand (new RCommand (".rk.data.frame.insert.column (" + getObject ()->getFullName () + ", \"" + obj->getShortName () + "\", " + QString ().setNum (col+1) + ")", RCommand::App | RCommand::Sync));
+ RKGlobals::rInterface ()->issueCommand (new RCommand (".rk.data.frame.insert.column (" + getObject ()->getFullName () + ", \"" + obj->getShortName () + "\", " + QString::number (col+1) + ")", RCommand::App | RCommand::Sync));
static_cast<RKVariable*> (obj)->setLength (dataview->numTrueRows ());
obj->setCreatedInEditor (this);
Modified: branches/KDE4_port/rkward/rkconsole.cpp
===================================================================
--- branches/KDE4_port/rkward/rkconsole.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/rkconsole.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -404,8 +404,8 @@
if (!do_file_completion) {
if (!current_symbol.isEmpty ()) { // try object name completion first
- RObject::RObjectMap map;
- RObject::RObjectMap::const_iterator it;
+ RObject::RObjectSearchMap map;
+ RObject::RObjectSearchMap::const_iterator it;
RObjectList::getObjectList ()->findObjectsMatching (current_symbol, &map);
QStringList entries;
Modified: branches/KDE4_port/rkward/rkward.cpp
===================================================================
--- branches/KDE4_port/rkward/rkward.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/rkward.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -257,7 +257,7 @@
} else if (result->result == StartupDialog::ChoseFile) {
slotFileOpenWorkspace ();
} else if (result->result == StartupDialog::EmptyTable) {
- RObject *object = RObjectList::getObjectList ()->createNewChild (i18n ("my.data"), 0, true, true);
+ RObject *object = RObjectList::getObjectList ()->createNewChild (i18n ("my.data"), -1, 0, true, true);
// usually an explicit call to activateView should not be necessary. Somehow however, here, it is.
RKWorkplace::mainWorkplace ()->editObject (object, true);
}
@@ -526,7 +526,7 @@
if (ok) {
QString valid = RObjectList::getObjectList ()->validizeName (name);
if (valid != name) KMessageBox::sorry (this, i18n ("The name you specified was already in use or not valid. Renamed to %1", valid), i18n ("Invalid Name"));
- RObject *object = RObjectList::getObjectList ()->createNewChild (valid, 0, true, true);
+ RObject *object = RObjectList::getObjectList ()->createNewChild (valid, -1, 0, true, true);
RKWorkplace::mainWorkplace ()->editObject (object, true);
}
Modified: branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp 2007-10-29 14:16:54 UTC (rev 2141)
+++ branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp 2007-10-29 19:16:49 UTC (rev 2142)
@@ -506,12 +506,13 @@
if (current_symbol == symbol) return; // already up to date
- RObject::RObjectMap map;
+ RObject::RObjectSearchMap map;
RObjectList::getObjectList ()->findObjectsMatching (symbol, &map);
+//KDE4 TODO: clean up once the format of findObjectsMatching is solid
list.clear ();
// this is silly, but we need an int indexable storage, so we copy the map to a list
- for (RObject::RObjectMap::const_iterator it = map.constBegin (); it != map.constEnd (); ++it) {
+ for (RObject::RObjectSearchMap::const_iterator it = map.constBegin (); it != map.constEnd (); ++it) {
list.append (it.data ());
}
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