summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2015-12-08 22:18:50 +0000
committerMarc Jeanmougin <marcjeanmougin@free.fr>2015-12-08 22:18:50 +0000
commitcfd295134c9804bf98fba835361000a891c2fa56 (patch)
tree753674a4d61212a956ef5969dd88be1635da638c /src
parentcppification: GSList replaced by vectors (connectors) (diff)
downloadinkscape-cfd295134c9804bf98fba835361000a891c2fa56.tar.gz
inkscape-cfd295134c9804bf98fba835361000a891c2fa56.zip
cppification: GSList replaced by vectors (undo/redo)
(bzr r14504.1.14)
Diffstat (limited to 'src')
-rw-r--r--src/desktop-style.h1
-rw-r--r--src/document-private.h6
-rw-r--r--src/document-undo.cpp70
-rw-r--r--src/document.cpp25
-rw-r--r--src/document.h2
5 files changed, 41 insertions, 63 deletions
diff --git a/src/desktop-style.h b/src/desktop-style.h
index b9199b615..bf05adadf 100644
--- a/src/desktop-style.h
+++ b/src/desktop-style.h
@@ -19,7 +19,6 @@ class SPDesktop;
class SPObject;
class SPItem;
class SPStyle;
-typedef struct _GSList GSList;
namespace Inkscape {
namespace XML {
class Node;
diff --git a/src/document-private.h b/src/document-private.h
index a4a2abd77..55c844ecc 100644
--- a/src/document-private.h
+++ b/src/document-private.h
@@ -53,9 +53,7 @@ struct SPDocumentPrivate {
IDChangedSignalMap id_changed_signals;
/* Resources */
- /* It is GHashTable of GSLists */
std::map<std::string, std::set<SPObject *> > resources;
- //GHashTable *resources;
ResourcesChangedSignalMap resources_changed_signals;
sigc::signal<void> destroySignal;
@@ -70,8 +68,8 @@ struct SPDocumentPrivate {
bool sensitive; /* If we save actions to undo stack */
Inkscape::XML::Event * partial; /* partial undo log when interrupted */
int history_size;
- GSList * undo; /* Undo stack of reprs */
- GSList * redo; /* Redo stack of reprs */
+ std::vector<Inkscape::Event *> undo; /* Undo stack of reprs */
+ std::vector<Inkscape::Event *> redo; /* Redo stack of reprs */
/* Undo listener */
Inkscape::CompositeUndoStackObserver undoStackObservers;
diff --git a/src/document-undo.cpp b/src/document-undo.cpp
index 59e060cd5..eb0ac7707 100644
--- a/src/document-undo.cpp
+++ b/src/document-undo.cpp
@@ -162,12 +162,12 @@ void Inkscape::DocumentUndo::maybeDone(SPDocument *doc, const gchar *key, const
return;
}
- if (key && !doc->actionkey.empty() && (doc->actionkey == key) && doc->priv->undo) {
- ((Inkscape::Event *)doc->priv->undo->data)->event =
- sp_repr_coalesce_log (((Inkscape::Event *)doc->priv->undo->data)->event, log);
+ if (key && !doc->actionkey.empty() && (doc->actionkey == key) && !doc->priv->undo.empty()) {
+ (doc->priv->undo.back())->event =
+ sp_repr_coalesce_log ((doc->priv->undo.back())->event, log);
} else {
Inkscape::Event *event = new Inkscape::Event(log, event_type, event_description);
- doc->priv->undo = g_slist_prepend (doc->priv->undo, event);
+ doc->priv->undo.push_back(event);
doc->priv->history_size++;
doc->priv->undoStackObservers.notifyUndoCommitEvent(event);
}
@@ -211,7 +211,7 @@ static void finish_incomplete_transaction(SPDocument &doc) {
priv.partial = sp_repr_coalesce_log(priv.partial, log);
sp_repr_debug_print_log(priv.partial);
Inkscape::Event *event = new Inkscape::Event(priv.partial);
- priv.undo = g_slist_prepend(priv.undo, event);
+ priv.undo.push_back(event);
priv.undoStackObservers.notifyUndoCommitEvent(event);
priv.partial = NULL;
}
@@ -227,8 +227,8 @@ static void perform_document_update(SPDocument &doc) {
sp_repr_debug_print_log(update_log);
//Coalesce the update changes with the last action performed by user
- Inkscape::Event* undo_stack_top = (Inkscape::Event *)doc.priv->undo->data;
- if (undo_stack_top) {
+ if (!doc.priv->undo.empty()) {
+ Inkscape::Event* undo_stack_top = doc.priv->undo.back();
undo_stack_top->event = sp_repr_coalesce_log(undo_stack_top->event, update_log);
} else {
sp_repr_free_log(update_log);
@@ -256,13 +256,13 @@ gboolean Inkscape::DocumentUndo::undo(SPDocument *doc)
finish_incomplete_transaction(*doc);
- if (doc->priv->undo) {
- Inkscape::Event *log=(Inkscape::Event *)doc->priv->undo->data;
- doc->priv->undo = g_slist_remove (doc->priv->undo, log);
+ if (! doc->priv->undo.empty()) {
+ Inkscape::Event *log = doc->priv->undo.back();
+ doc->priv->undo.pop_back();
sp_repr_undo_log (log->event);
perform_document_update(*doc);
- doc->priv->redo = g_slist_prepend (doc->priv->redo, log);
+ doc->priv->redo.push_back(log);
doc->setModifiedSinceSave();
doc->priv->undoStackObservers.notifyUndoEvent(log);
@@ -303,11 +303,11 @@ gboolean Inkscape::DocumentUndo::redo(SPDocument *doc)
finish_incomplete_transaction(*doc);
- if (doc->priv->redo) {
- Inkscape::Event *log=(Inkscape::Event *)doc->priv->redo->data;
- doc->priv->redo = g_slist_remove (doc->priv->redo, log);
+ if (! doc->priv->redo.empty()) {
+ Inkscape::Event *log = doc->priv->redo.back();
+ doc->priv->redo.pop_back();
sp_repr_replay_log (log->event);
- doc->priv->undo = g_slist_prepend (doc->priv->undo, log);
+ doc->priv->undo.push_back(log);
doc->setModifiedSinceSave();
doc->priv->undoStackObservers.notifyRedoEvent(log);
@@ -330,37 +330,29 @@ gboolean Inkscape::DocumentUndo::redo(SPDocument *doc)
void Inkscape::DocumentUndo::clearUndo(SPDocument *doc)
{
- if (doc->priv->undo)
- doc->priv->undoStackObservers.notifyClearUndoEvent();
-
- while (doc->priv->undo) {
- GSList *current;
-
- current = doc->priv->undo;
- doc->priv->undo = current->next;
- doc->priv->history_size--;
-
- delete ((Inkscape::Event *) current->data);
- g_slist_free_1 (current);
- }
+ if (! doc->priv->undo.empty())
+ doc->priv->undoStackObservers.notifyClearUndoEvent();
+ while (! doc->priv->undo.empty()) {
+ Inkscape::Event *e = doc->priv->undo.back();
+ doc->priv->undo.pop_back();
+ delete e;
+ doc->priv->history_size--;
+ }
}
void Inkscape::DocumentUndo::clearRedo(SPDocument *doc)
{
- if (doc->priv->redo)
+ if (!doc->priv->redo.empty())
doc->priv->undoStackObservers.notifyClearRedoEvent();
- while (doc->priv->redo) {
- GSList *current;
-
- current = doc->priv->redo;
- doc->priv->redo = current->next;
- doc->priv->history_size--;
-
- delete ((Inkscape::Event *) current->data);
- g_slist_free_1 (current);
- }
+ while (! doc->priv->redo.empty()) {
+ Inkscape::Event *e = doc->priv->redo.back();
+ doc->priv->redo.pop_back();
+ delete e;
+ doc->priv->history_size--;
+ }
}
+
/*
Local Variables:
mode:c++
diff --git a/src/document.cpp b/src/document.cpp
index fcbe5a809..05e165965 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -81,7 +81,7 @@ using Inkscape::Util::unit_table;
static gint sp_document_idle_handler(gpointer data);
static gint sp_document_rerouting_handler(gpointer data);
-gboolean sp_document_resource_list_free(gpointer key, gpointer value, gpointer data);
+//gboolean sp_document_resource_list_free(gpointer key, gpointer value, gpointer data);
static gint doc_count = 0;
static gint doc_mem_count = 0;
@@ -105,7 +105,6 @@ SPDocument::SPDocument() :
rerouting_handler_id(0),
profileManager(NULL), // deferred until after other initialization
router(new Avoid::Router(Avoid::PolyLineRouting|Avoid::OrthogonalRouting)),
- _collection_queue(NULL),
oldSignalsConnected(false),
current_persp3d(NULL),
current_persp3d_impl(NULL),
@@ -122,8 +121,6 @@ SPDocument::SPDocument() :
p->sensitive = false;
p->partial = NULL;
p->history_size = 0;
- p->undo = NULL;
- p->redo = NULL;
p->seeking = false;
priv = p;
@@ -283,19 +280,18 @@ void SPDocument::queueForOrphanCollection(SPObject *object) {
g_return_if_fail(object->document == this);
sp_object_ref(object, NULL);
- _collection_queue = g_slist_prepend(_collection_queue, object);
+ _collection_queue.push_back(object);
}
void SPDocument::collectOrphans() {
- while (_collection_queue) {
- GSList *objects=_collection_queue;
- _collection_queue = NULL;
- for ( GSList *iter=objects ; iter ; iter = iter->next ) {
- SPObject *object=reinterpret_cast<SPObject *>(iter->data);
+ while (!_collection_queue.empty()) {
+ std::vector<SPObject *> objects(_collection_queue);
+ _collection_queue.clear();
+ for (std::vector<SPObject *>::const_iterator iter = objects.begin(); iter != objects.end(); ++iter) {
+ SPObject *object = *iter;
object->collectOrphan();
sp_object_unref(object, NULL);
}
- g_slist_free(objects);
}
}
@@ -1588,13 +1584,6 @@ sigc::connection SPDocument::connectResourcesChanged(gchar const *key,
/* Helpers */
-gboolean
-sp_document_resource_list_free(gpointer /*key*/, gpointer value, gpointer /*data*/)
-{
- g_slist_free((GSList *) value);
- return TRUE;
-}
-
static unsigned int count_objects_recursive(SPObject *obj, unsigned int count)
{
count++; // obj itself
diff --git a/src/document.h b/src/document.h
index c7d3abf90..cf8ebc3cb 100644
--- a/src/document.h
+++ b/src/document.h
@@ -122,7 +122,7 @@ public:
// Instance of the connector router
Avoid::Router *router;
- GSList *_collection_queue;
+ std::vector<SPObject *> _collection_queue;
bool oldSignalsConnected;