summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2017-10-01 15:49:26 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2017-10-01 15:49:26 +0000
commite0957537cd0938313803c290a2f3922a3889e6f1 (patch)
tree7f158d00a7655ee91ac094f676f6b3bd624a78b7 /src/ui/dialog
parentMerge branch 'master' of gitlab.com:inkscape/inkscape (diff)
downloadinkscape-e0957537cd0938313803c290a2f3922a3889e6f1.tar.gz
inkscape-e0957537cd0938313803c290a2f3922a3889e6f1.zip
Removed all GSList occurences in .h files
Diffstat (limited to 'src/ui/dialog')
-rw-r--r--src/ui/dialog/spellcheck.cpp87
-rw-r--r--src/ui/dialog/spellcheck.h11
-rw-r--r--src/ui/dialog/symbols.cpp46
-rw-r--r--src/ui/dialog/symbols.h12
4 files changed, 62 insertions, 94 deletions
diff --git a/src/ui/dialog/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp
index 4f7657f4f..3318b5e6b 100644
--- a/src/ui/dialog/spellcheck.cpp
+++ b/src/ui/dialog/spellcheck.cpp
@@ -50,8 +50,6 @@ namespace Dialog {
SpellCheck::SpellCheck (void) :
UI::Widget::Panel ("", "/dialogs/spellcheck/", SP_VERB_DIALOG_SPELLCHECK),
- _rects(NULL),
- _seen_objects(NULL),
_text(NULL),
_layout(NULL),
_stops(0),
@@ -196,12 +194,11 @@ void SpellCheck::setTargetDesktop(SPDesktop *desktop)
void SpellCheck::clearRects()
{
- for (GSList *it = _rects; it; it = it->next) {
- sp_canvas_item_hide(SP_CANVAS_ITEM(it->data));
- sp_canvas_item_destroy(SP_CANVAS_ITEM(it->data));
+ for(auto t : _rects) {
+ sp_canvas_item_hide(t);
+ sp_canvas_item_destroy(t);
}
- g_slist_free(_rects);
- _rects = NULL;
+ _rects.clear();
}
void SpellCheck::disconnect()
@@ -214,47 +211,39 @@ void SpellCheck::disconnect()
}
}
-GSList *SpellCheck::allTextItems (SPObject *r, GSList *l, bool hidden, bool locked)
+void SpellCheck::allTextItems (SPObject *r, std::vector<SPItem *> &l, bool hidden, bool locked)
{
if (!desktop)
- return l; // no desktop to check
+ return; // no desktop to check
if (SP_IS_DEFS(r))
- return l; // we're not interested in items in defs
+ return; // we're not interested in items in defs
if (!strcmp(r->getRepr()->name(), "svg:metadata")) {
- return l; // we're not interested in metadata
+ return; // we're not interested in metadata
}
for (auto& child: r->children) {
if (SP_IS_ITEM (&child) && !child.cloned && !desktop->isLayer(SP_ITEM(&child))) {
if ((hidden || !desktop->itemIsHidden(SP_ITEM(&child))) && (locked || !SP_ITEM(&child)->isLocked())) {
if (SP_IS_TEXT(&child) || SP_IS_FLOWTEXT(&child))
- l = g_slist_prepend (l, &child);
+ l.push_back(static_cast<SPItem*>(&child));
}
}
- l = allTextItems (&child, l, hidden, locked);
+ allTextItems (&child, l, hidden, locked);
}
- return l;
+ return;
}
bool
SpellCheck::textIsValid (SPObject *root, SPItem *text)
{
- GSList *l = NULL;
- l = allTextItems (root, l, false, true);
- for (GSList *i = l; i; i = i->next) {
- SPItem *item = static_cast<SPItem *>(i->data);
- if (item == text) {
- g_slist_free (l);
- return true;
- }
- }
- g_slist_free (l);
- return false;
+ std::vector<SPItem*> l;
+ allTextItems (root, l, false, true);
+ return (std::find(l.begin(), l.end(), text) != l.end());
}
-gint SpellCheck::compareTextBboxes (gconstpointer a, gconstpointer b)
+bool SpellCheck::compareTextBboxes (gconstpointer a, gconstpointer b)//returns a<b
{
SPItem *i1 = SP_ITEM(a);
SPItem *i2 = SP_ITEM(b);
@@ -262,41 +251,28 @@ gint SpellCheck::compareTextBboxes (gconstpointer a, gconstpointer b)
Geom::OptRect bbox1 = i1->desktopVisualBounds();
Geom::OptRect bbox2 = i2->desktopVisualBounds();
if (!bbox1 || !bbox2) {
- return 0;
+ return false;
}
// vector between top left corners
Geom::Point diff = Geom::Point(bbox2->min()[Geom::X], bbox2->max()[Geom::Y]) -
Geom::Point(bbox1->min()[Geom::X], bbox1->max()[Geom::Y]);
- // sort top to bottom, left to right, but:
- // if i2 is higher only 0.2 or less times it is righter than i1, put i1 first
- if (diff[Geom::Y] > 0.2 * diff[Geom::X])
- return 1;
- else
- return -1;
-
- return 0;
+ return diff[Geom::Y] == 0 ? (diff[Geom::X] < 0) : (diff[Geom::Y] < 0);
}
// We regenerate and resort the list every time, because user could have changed it while the
// dialog was waiting
SPItem *SpellCheck::getText (SPObject *root)
{
- GSList *l = NULL;
- l = allTextItems (root, l, false, true);
- l = g_slist_sort(l, (GCompareFunc)SpellCheck::compareTextBboxes);
-
- for (GSList *i = l; i; i = i->next) {
- SPItem *item = static_cast<SPItem *>(i->data);
- if (!g_slist_find (_seen_objects, item)) {
- _seen_objects = g_slist_prepend(_seen_objects, item);
- g_slist_free(l);
+ std::vector<SPItem*> l;
+ allTextItems (root, l, false, true);
+ std::sort(l.begin(),l.end(),SpellCheck::compareTextBboxes);
+
+ for (auto item:l) {
+ if(_seen_objects.insert(item).second)
return item;
- }
}
-
- g_slist_free(l);
return NULL;
}
@@ -402,8 +378,7 @@ SpellCheck::init(SPDesktop *d)
_root = desktop->getDocument()->getRoot();
// empty the list of objects we've checked
- g_slist_free (_seen_objects);
- _seen_objects = NULL;
+ _seen_objects.clear();
// grab first text
nextText();
@@ -456,8 +431,7 @@ SpellCheck::finished ()
g_free(label);
}
- g_slist_free(_seen_objects);
- _seen_objects = NULL;
+ _seen_objects.clear();
desktop = NULL;
_root = NULL;
@@ -615,7 +589,7 @@ SpellCheck::nextWord()
curve->lineto(area.corner(0));
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(rect), curve);
sp_canvas_item_show(rect);
- _rects = g_slist_prepend(_rects, rect);
+ _rects.push_back(rect);
// scroll to make it all visible
Geom::Point const center = desktop->get_display_area().midpoint();
@@ -707,10 +681,10 @@ SpellCheck::nextWord()
void
SpellCheck::deleteLastRect ()
{
- if (_rects) {
- sp_canvas_item_hide(SP_CANVAS_ITEM(_rects->data));
- sp_canvas_item_destroy(SP_CANVAS_ITEM(_rects->data));
- _rects = _rects->next; // pop latest-prepended rect
+ if (!_rects.empty()) {
+ sp_canvas_item_hide(_rects.back());
+ sp_canvas_item_destroy(_rects.back());
+ _rects.pop_back(); // pop latest-prepended rect
}
}
@@ -861,7 +835,6 @@ SpellCheck::onStart ()
}
}
-
/*
Local Variables:
mode:c++
diff --git a/src/ui/dialog/spellcheck.h b/src/ui/dialog/spellcheck.h
index 834f23c24..e7563ad1e 100644
--- a/src/ui/dialog/spellcheck.h
+++ b/src/ui/dialog/spellcheck.h
@@ -16,6 +16,9 @@
# include <config.h>
#endif
+#include <vector>
+#include <set>
+
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/buttonbox.h>
@@ -68,7 +71,7 @@ private:
/**
* Returns a list of all the text items in the SPObject
*/
- GSList *allTextItems (SPObject *r, GSList *l, bool hidden, bool locked);
+ void allTextItems (SPObject *r, std::vector<SPItem *> &l, bool hidden, bool locked);
/**
* Is text inside the SPOject's tree
@@ -78,7 +81,7 @@ private:
/**
* Compare the visual bounds of 2 SPItems referred to by a and b
*/
- static gint compareTextBboxes (gconstpointer a, gconstpointer b);
+ static bool compareTextBboxes (gconstpointer a, gconstpointer b);
SPItem *getText (SPObject *root);
void nextText ();
@@ -165,12 +168,12 @@ private:
/**
* list of canvasitems (currently just rects) that mark misspelled things on canvas
*/
- GSList *_rects;
+ std::vector<SPCanvasItem *> _rects;
/**
* list of text objects we have already checked in this session
*/
- GSList *_seen_objects;
+ std::set<SPItem *> _seen_objects;
/**
* the object currently being checked
diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp
index b876fa98c..558b0b19e 100644
--- a/src/ui/dialog/symbols.cpp
+++ b/src/ui/dialog/symbols.cpp
@@ -617,52 +617,48 @@ void SymbolsDialog::get_symbols() {
}
}
-GSList* SymbolsDialog::symbols_in_doc_recursive (SPObject *r, GSList *l)
+void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vector<SPSymbol*> &l)
{
- g_return_val_if_fail(r != NULL, l);
+ if(!r) return;
// Stop multiple counting of same symbol
if ( dynamic_cast<SPUse *>(r) ) {
- return l;
+ return;
}
if ( dynamic_cast<SPSymbol *>(r) ) {
- l = g_slist_prepend (l, r);
+ l.push_back(dynamic_cast<SPSymbol *>(r));
}
for (auto& child: r->children) {
- l = symbols_in_doc_recursive( &child, l );
+ symbols_in_doc_recursive( &child, l );
}
-
- return l;
}
-GSList* SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument ) {
+std::vector<SPSymbol*> SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument )
+{
- GSList *l = NULL;
- l = symbols_in_doc_recursive (symbolDocument->getRoot(), l );
- l = g_slist_reverse( l );
+ std::vector<SPSymbol*> l;
+ symbols_in_doc_recursive (symbolDocument->getRoot(), l );
return l;
}
-GSList* SymbolsDialog::use_in_doc_recursive (SPObject *r, GSList *l)
+void SymbolsDialog::use_in_doc_recursive (SPObject *r, std::vector<SPUse*> &l)
{
if ( dynamic_cast<SPUse *>(r) ) {
- l = g_slist_prepend (l, r);
+ l.push_back(dynamic_cast<SPUse *>(r));
}
for (auto& child: r->children) {
- l = use_in_doc_recursive( &child, l );
+ use_in_doc_recursive( &child, l );
}
-
- return l;
}
-GSList* SymbolsDialog::use_in_doc( SPDocument* useDocument ) {
+std::vector<SPUse*> SymbolsDialog::use_in_doc( SPDocument* useDocument ) {
- GSList *l = NULL;
- l = use_in_doc_recursive (useDocument->getRoot(), l );
+ std::vector<SPUse*> l;
+ use_in_doc_recursive (useDocument->getRoot(), l);
return l;
}
@@ -671,10 +667,8 @@ GSList* SymbolsDialog::use_in_doc( SPDocument* useDocument ) {
gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* document) {
gchar const* style = 0;
- GSList* l = use_in_doc( document );
- for( ; l != NULL; l = l->next ) {
- SPObject *obj = reinterpret_cast<SPObject *>(l->data);
- SPUse *use = dynamic_cast<SPUse *>(obj);
+ std::vector<SPUse*> l = use_in_doc( document );
+ for( auto use:l ) {
if ( use ) {
gchar const *href = use->getRepr()->attribute("xlink:href");
if( href ) {
@@ -693,10 +687,8 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen
void SymbolsDialog::add_symbols( SPDocument* symbolDocument ) {
- GSList* l = symbols_in_doc( symbolDocument );
- for( ; l != NULL; l = l->next ) {
- SPObject *obj = reinterpret_cast<SPObject *>(l->data);
- SPSymbol *symbol = dynamic_cast<SPSymbol *>(obj);
+ std::vector<SPSymbol*> l = symbols_in_doc( symbolDocument );
+ for(auto symbol:l) {
if (symbol) {
add_symbol( symbol );
}
diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h
index 5dc1e3cad..747e5c6c9 100644
--- a/src/ui/dialog/symbols.h
+++ b/src/ui/dialog/symbols.h
@@ -14,10 +14,10 @@
#define INKSCAPE_UI_DIALOG_SYMBOLS_H
#include "display/drawing.h"
-
#include "ui/dialog/desktop-tracker.h"
-
#include "ui/widget/panel.h"
+#include "sp-symbol.h"
+#include "sp-use.h"
#include <vector>
@@ -85,10 +85,10 @@ private:
void add_symbol( SPObject* symbol_document );
SPDocument* symbols_preview_doc();
- GSList* symbols_in_doc_recursive(SPObject *r, GSList *l);
- GSList* symbols_in_doc( SPDocument* document );
- GSList* use_in_doc_recursive(SPObject *r, GSList *l);
- GSList* use_in_doc( SPDocument* document );
+ void symbols_in_doc_recursive(SPObject *r, std::vector<SPSymbol*> &l);
+ std::vector<SPSymbol*> symbols_in_doc( SPDocument* document );
+ void use_in_doc_recursive(SPObject *r, std::vector<SPUse*> &l);
+ std::vector<SPUse*> use_in_doc( SPDocument* document );
gchar const* style_from_use( gchar const* id, SPDocument* document);
Glib::RefPtr<Gdk::Pixbuf> draw_symbol(SPObject *symbol);