[rkward-cvs] SF.net SVN: rkward: [2145] branches/KDE4_port/rkward/core
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Mon Oct 29 23:27:48 UTC 2007
Revision: 2145
http://rkward.svn.sourceforge.net/rkward/?rev=2145&view=rev
Author: tfry
Date: 2007-10-29 16:27:48 -0700 (Mon, 29 Oct 2007)
Log Message:
-----------
All object additions/removals should now run through the RKModificationTracker.
This is part of the work to port RObjectListView to the model/view architecture
Modified Paths:
--------------
branches/KDE4_port/rkward/core/rcontainerobject.cpp
branches/KDE4_port/rkward/core/rcontainerobject.h
branches/KDE4_port/rkward/core/renvironmentobject.cpp
branches/KDE4_port/rkward/core/renvironmentobject.h
branches/KDE4_port/rkward/core/rkmodificationtracker.cpp
branches/KDE4_port/rkward/core/rkmodificationtracker.h
branches/KDE4_port/rkward/core/robjectlist.cpp
branches/KDE4_port/rkward/core/robjectlist.h
Modified: branches/KDE4_port/rkward/core/rcontainerobject.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rcontainerobject.cpp 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/rcontainerobject.cpp 2007-10-29 23:27:48 UTC (rev 2145)
@@ -127,8 +127,7 @@
RK_ASSERT (false);
return 0;
}
- childmap.insert (position, child_object);
- RKGlobals::tracker ()->addObject (child_object, 0);
+ RKGlobals::tracker ()->addObject (child_object, this, position);
return child_object;
}
@@ -190,11 +189,9 @@
RK_ASSERT (childmap[from_index] == child);
RK_ASSERT (from_index < childmap.size ());
- childmap.removeAt (from_index);
+ RKGlobals::tracker ()->internalRemoveObject (child, true, false);
RK_ASSERT (to_index <= childmap.size ());
- childmap.insert (to_index, child);
-
-#warning TODO notify the modification tracker
+ RKGlobals::tracker ()->addObject (child, this, to_index);
}
int RContainerObject::numChildren () const {
@@ -314,9 +311,7 @@
if ((position < 0) || (position > childmap.size ())) position = childmap.size ();
- childmap.insert (position, ret);
-
- RKGlobals::tracker ()->addObject (ret, creator);
+ RKGlobals::tracker ()->addObject (ret, this, position, creator);
return ret;
}
@@ -332,22 +327,42 @@
object->name = new_name;
}
-void RContainerObject::removeChild (RObject *object, bool removed_in_workspace) {
+void RContainerObject::insertChild (RObject* child, int position) {
RK_TRACE (OBJECTS);
- if (!removed_in_workspace) {
- RCommand *command = new RCommand (removeChildCommand (object), RCommand::App | RCommand::Sync | RCommand::ObjectListUpdate);
- RKGlobals::rInterface ()->issueCommand (command, 0);
- }
+ RK_ASSERT (child->getContainer () == this);
+ if ((position < 0) || (position > childmap.size ())) position = childmap.size ();
+ childmap.insert (position, child);
+}
+void RContainerObject::removeChildNoDelete (RObject *object) {
+ RK_TRACE (OBJECTS);
+
int i = getIndexOf (object);
if (i < 0) {
RK_ASSERT (false);
return;
}
- RK_ASSERT (childmap[i] == object);
+ childmap.removeAt (i);
+}
- childmap.removeAt (i);
+void RContainerObject::removeChild (RObject *object, bool removed_in_workspace) {
+ RK_TRACE (OBJECTS);
+
+ if (!removed_in_workspace) {
+ if (isType (Environment) && (!isType (GlobalEnv))) {
+ RK_ASSERT (false);
+ return;
+ } else if (isType (Workspace)) {
+ RK_ASSERT (false);
+ return;
+ }
+
+ RCommand *command = new RCommand (removeChildCommand (object), RCommand::App | RCommand::Sync | RCommand::ObjectListUpdate);
+ RKGlobals::rInterface ()->issueCommand (command, 0);
+ }
+
+ removeChildNoDelete (object);
delete object;
}
Modified: branches/KDE4_port/rkward/core/rcontainerobject.h
===================================================================
--- branches/KDE4_port/rkward/core/rcontainerobject.h 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/rcontainerobject.h 2007-10-29 23:27:48 UTC (rev 2145)
@@ -79,9 +79,12 @@
friend class RObjectList;
friend class RObject;
virtual void renameChild (RObject *object, const QString &new_name);
- virtual void removeChild (RObject *object, bool removed_in_workspace);
+ void removeChild (RObject *object, bool removed_in_workspace);
virtual QString removeChildCommand (RObject *object) const;
virtual QString renameChildCommand (RObject *object, const QString &new_name) const;
+friend class RKModificationTracker;
+ void insertChild (RObject* child, int position);
+ void removeChildNoDelete (RObject* child);
};
#endif
Modified: branches/KDE4_port/rkward/core/renvironmentobject.cpp
===================================================================
--- branches/KDE4_port/rkward/core/renvironmentobject.cpp 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/renvironmentobject.cpp 2007-10-29 23:27:48 UTC (rev 2145)
@@ -132,16 +132,6 @@
}
}
-void REnvironmentObject::removeChild (RObject *object, bool removed_in_workspace) {
- RK_TRACE (OBJECTS);
-
- if ((type & GlobalEnv) || removed_in_workspace) {
- RContainerObject::removeChild (object, removed_in_workspace);
- } else {
- RK_ASSERT (false);
- }
-}
-
QString REnvironmentObject::renameChildCommand (RObject *object, const QString &new_name) const {
RK_TRACE (OBJECTS);
Modified: branches/KDE4_port/rkward/core/renvironmentobject.h
===================================================================
--- branches/KDE4_port/rkward/core/renvironmentobject.h 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/renvironmentobject.h 2007-10-29 23:27:48 UTC (rev 2145)
@@ -44,8 +44,6 @@
bool updateStructure (RData *new_data);
/** reimplemented from RContainerObject to raise an assert if this is not the isGlobalEnv (). Otherwise calls "remove (objectname)" instead of objectname <- NULL" */
void renameChild (RObject *object, const QString &new_name);
-/** reimplemented from RContainerObject to raise an assert if this is not the isGlobalEnv (). Otherwise calls "remove (objectname)" instead of objectname <- NULL" */
- void removeChild (RObject *object, bool removed_in_workspace);
/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
QString removeChildCommand (RObject *object) const;
/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
Modified: branches/KDE4_port/rkward/core/rkmodificationtracker.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rkmodificationtracker.cpp 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/rkmodificationtracker.cpp 2007-10-29 23:27:48 UTC (rev 2145)
@@ -64,7 +64,19 @@
}
}
}
-
+
+ internalRemoveObject (object, removed_in_workspace, true);
+
+ return true;
+}
+
+void RKModificationTracker::internalRemoveObject (RObject *object, bool removed_in_workspace, bool delete_obj) {
+ RK_TRACE (OBJECTS);
+
+// TODO: allow more than one editor per object
+// WARNING: This does not work, if a sub-object is being edited!
+ RKEditor *ed = object->objectOpened ();
+
if (ed) ed->removeObject (object); // READ: delete ed
/* What's this? A child of a removed complex object may be edited somewhere, but not the whole object. In this case, the editor has no chance of restoring the object, but it still needs to be closed. We search all editors for the removed object */
if (object->isContainer ()) {
@@ -79,9 +91,9 @@
}
if (updates_locked <= 0) emit (objectRemoved (object));
- object->remove (removed_in_workspace);
- return true;
+ if (delete_obj) object->remove (removed_in_workspace);
+ else object->getContainer ()->removeChildNoDelete (object);
}
void RKModificationTracker::renameObject (RObject *object, const QString &new_name) {
@@ -97,8 +109,11 @@
if (updates_locked <= 0) emit (objectPropertiesChanged (object));
}
-void RKModificationTracker::addObject (RObject *object, RKEditor *editor) {
+void RKModificationTracker::addObject (RObject *object, RContainerObject* parent, int position, RKEditor *editor) {
RK_TRACE (OBJECTS);
+
+ parent->insertChild (object, position);
+
// TODO: allow more than one editor per object
RKEditor *ed = 0;
if (object->getContainer ()) ed = object->getContainer ()->objectOpened ();
Modified: branches/KDE4_port/rkward/core/rkmodificationtracker.h
===================================================================
--- branches/KDE4_port/rkward/core/rkmodificationtracker.h 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/rkmodificationtracker.h 2007-10-29 23:27:48 UTC (rev 2145)
@@ -42,7 +42,7 @@
/** essentially like the above function, but requests a renaming of the object. Will also take care of finding out, whether the name is valid and promting for a different name otherwise. */
void renameObject (RObject *object, const QString &new_name);
/** essentially like the above function(s). All objects editing a parent of the new objects are notified of the addition. */
- void addObject (RObject *object, RKEditor *editor=0);
+ void addObject (RObject *object, RContainerObject* parent, int position, RKEditor *editor=0);
/** the object's meta data was modified. Tells all editors and lists containing the object to update accordingly. */
void objectMetaChanged (RObject *object);
/** the object's data was modified. Tells all editors and lists containing the object to update accordingly. The ChangeSet given tells which parts of the data have to be updated. The ChangeSet will get deleted by the RKModificationTracker, when done. */
@@ -58,6 +58,10 @@
void objectAdded (RObject *object);
private:
int updates_locked;
+
+friend class RContainerObject;
+/** uncondiontally remove the given object. Do *not* call this except from RContainerObject::moveChild() or internally from removeObject(). Call removeObject(), instead. */
+ void internalRemoveObject (RObject *object, bool removed_in_workspace, bool delete_obj);
};
#endif
Modified: branches/KDE4_port/rkward/core/robjectlist.cpp
===================================================================
--- branches/KDE4_port/rkward/core/robjectlist.cpp 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/robjectlist.cpp 2007-10-29 23:27:48 UTC (rev 2145)
@@ -53,8 +53,7 @@
type = RObject::Workspace;
update_chain = 0;
- childmap.insert (0, createTopLevelEnvironment (".GlobalEnv"));
- RKGlobals::tracker ()->addObject (childmap[0], 0);
+ RKGlobals::tracker ()->addObject (createTopLevelEnvironment (".GlobalEnv"), this, 0);
}
RObjectList::~RObjectList () {
@@ -118,8 +117,7 @@
}
} else {
obj = createTopLevelEnvironment (name);
- childmap.insert (i, obj);
- RKGlobals::tracker ()->addObject (obj, 0);
+ RKGlobals::tracker ()->addObject (obj, this, i);
}
newchildmap.insert (i, obj);
}
@@ -252,16 +250,6 @@
return ("remove (" + object->getFullName () + ')');
}
-void RObjectList::removeChild (RObject *object, bool removed_in_workspace) {
- RK_TRACE (OBJECTS);
-
- if (removed_in_workspace) {
- RContainerObject::removeChild (object, removed_in_workspace);
- } else {
- RK_ASSERT (false);
- }
-}
-
//static
REnvironmentObject *RObjectList::getGlobalEnv () {
RK_TRACE (OBJECTS);
Modified: branches/KDE4_port/rkward/core/robjectlist.h
===================================================================
--- branches/KDE4_port/rkward/core/robjectlist.h 2007-10-29 22:36:19 UTC (rev 2144)
+++ branches/KDE4_port/rkward/core/robjectlist.h 2007-10-29 23:27:48 UTC (rev 2145)
@@ -80,7 +80,6 @@
protected:
/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
QString removeChildCommand (RObject *object) const;
- void removeChild (RObject *object, bool removed_in_workspace);
/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
QString renameChildCommand (RObject *object, const QString &new_name) const;
/// reimplemented from RContainerObject to emit a change signal
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