diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2015-12-09 15:49:59 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2015-12-09 15:49:59 +0000 |
| commit | 50ab3a3c4215474d437f9adcc4b725bed26767d7 (patch) | |
| tree | 0241555b1dc6efe9f35db7696c7e440e8a56bada /src/ui/tools | |
| parent | Remove unused var in header file (diff) | |
| parent | update to trunk (diff) | |
| download | inkscape-50ab3a3c4215474d437f9adcc4b725bed26767d7.tar.gz inkscape-50ab3a3c4215474d437f9adcc4b725bed26767d7.zip | |
Merge glib_hunt: cppification and removal of many glib GList/GSList/GHashTable
(bzr r14520)
Diffstat (limited to 'src/ui/tools')
| -rw-r--r-- | src/ui/tools/gradient-tool.cpp | 38 | ||||
| -rw-r--r-- | src/ui/tools/mesh-tool.cpp | 32 | ||||
| -rw-r--r-- | src/ui/tools/select-tool.cpp | 94 | ||||
| -rw-r--r-- | src/ui/tools/select-tool.h | 8 | ||||
| -rw-r--r-- | src/ui/tools/tool-base.cpp | 2 |
5 files changed, 76 insertions, 98 deletions
diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index bcb0b12b7..9d8101cc4 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -225,13 +225,13 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi std::vector<Geom::Point> coords; // for all selected draggers - for (GList *i = drag->selected; i != NULL; i = i->next) { - GrDragger *dragger = (GrDragger *) i->data; + for (std::set<GrDragger *>::const_iterator i = drag->selected.begin(); i != drag->selected.end() ; ++i ) { + GrDragger *dragger = *i; // remember the coord of the dragger to reselect it later coords.push_back(dragger->point); // for all draggables of dragger - for (GSList const* j = dragger->draggables; j != NULL; j = j->next) { - GrDraggable *d = (GrDraggable *) j->data; + for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end(); ++j) { + GrDraggable *d = *j; // find the gradient SPGradient *gradient = getGradient(d->item, d->fill_or_stroke); @@ -315,9 +315,9 @@ sp_gradient_context_add_stops_between_selected_stops (GradientTool *rc) if (g_slist_length(these_stops) == 0 && drag->numSelected() == 1) { // if a single stop is selected, add between that stop and the next one - GrDragger *dragger = (GrDragger *) drag->selected->data; - for (GSList const* j = dragger->draggables; j != NULL; j = j->next) { - GrDraggable *d = (GrDraggable *) j->data; + GrDragger *dragger = *(drag->selected.begin()); + for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end(); ++j) { + GrDraggable *d = *j; if (d->point_type == POINT_RG_FOCUS) { /* * There are 2 draggables at the center (start) of a radial gradient @@ -482,9 +482,9 @@ bool GradientTool::root_handler(GdkEvent* event) { bool over_line = false; SPCtrlLine *line = NULL; - if (drag->lines) { - for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) { - line = (SPCtrlLine*) l->data; + if (!drag->lines.empty()) { + for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() && (!over_line); ++l) { + line = *l; over_line |= sp_gradient_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); } } @@ -588,9 +588,9 @@ bool GradientTool::root_handler(GdkEvent* event) { bool over_line = false; - if (drag->lines) { - for (GSList *l = drag->lines; l != NULL; l = l->next) { - over_line |= sp_gradient_context_is_over_line (this, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y)); + if (!drag->lines.empty()) { + for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end(); ++l) { + over_line |= sp_gradient_context_is_over_line (this, (SPItem*) (*l), Geom::Point(event->motion.x, event->motion.y)); } } @@ -613,12 +613,10 @@ bool GradientTool::root_handler(GdkEvent* event) { bool over_line = false; SPCtrlLine *line = NULL; - if (drag->lines) { - for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) { - line = (SPCtrlLine*) l->data; + if (!drag->lines.empty()) { + for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() && (!over_line); ++l) { + line = *l; over_line = sp_gradient_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); - if (over_line) - break; } } @@ -663,7 +661,7 @@ bool GradientTool::root_handler(GdkEvent* event) { } } else { // click in an empty space; do the same as Esc - if (drag->selected) { + if (!drag->selected.empty()) { drag->deselectAll(); } else { selection->clear(); @@ -719,7 +717,7 @@ bool GradientTool::root_handler(GdkEvent* event) { break; case GDK_KEY_Escape: - if (drag->selected) { + if (!drag->selected.empty()) { drag->deselectAll(); } else { Inkscape::SelectionHelper::selectNone(desktop); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 56ba08789..7db4e09d8 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -332,11 +332,11 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) // Get list of selected draggers for each mesh. // For all selected draggers - for (GList *i = drag->selected; i != NULL; i = i->next) { - GrDragger *dragger = (GrDragger *) i->data; + for (std::set<GrDragger *>::const_iterator i = drag->selected.begin(); i != drag->selected.end(); ++i) { + GrDragger *dragger = *i; // For all draggables of dragger - for (GSList const* j = dragger->draggables; j != NULL; j = j->next) { - GrDraggable *d = (GrDraggable *) j->data; + for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end() ; ++j) { + GrDraggable *d = *j; // Only mesh corners if( d->point_type != POINT_MG_CORNER ) continue; @@ -457,9 +457,9 @@ bool MeshTool::root_handler(GdkEvent* event) { bool over_line = false; SPCtrlCurve *line = NULL; - if (drag->lines) { - for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) { - line = (SPCtrlCurve*) l->data; + if (! drag->lines.empty()) { + for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() && (!over_line); l++) { + line = (SPCtrlCurve*) (*l); over_line |= sp_mesh_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); } } @@ -593,9 +593,9 @@ bool MeshTool::root_handler(GdkEvent* event) { // Change cursor shape if over line bool over_line = false; - if (drag->lines) { - for (GSList *l = drag->lines; l != NULL; l = l->next) { - over_line |= sp_mesh_context_is_over_line (this, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y)); + if (!drag->lines.empty()) { + for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() ; l++) { + over_line |= sp_mesh_context_is_over_line (this, (SPItem*)(*l), Geom::Point(event->motion.x, event->motion.y)); } } @@ -624,9 +624,9 @@ bool MeshTool::root_handler(GdkEvent* event) { bool over_line = false; SPCtrlLine *line = NULL; - if (drag->lines) { - for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) { - line = (SPCtrlLine*) l->data; + if (!drag->lines.empty()) { + for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() && (!over_line); l++) { + line = (SPCtrlLine*)(*l); over_line = sp_mesh_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); if (over_line) { @@ -678,7 +678,7 @@ bool MeshTool::root_handler(GdkEvent* event) { } } else { // click in an empty space; do the same as Esc - if (drag->selected) { + if (!drag->selected.empty()) { drag->deselectAll(); } else { selection->clear(); @@ -724,7 +724,7 @@ bool MeshTool::root_handler(GdkEvent* event) { break; case GDK_KEY_Escape: - if (drag->selected) { + if (!drag->selected.empty()) { drag->deselectAll(); } else { selection->clear(); @@ -841,7 +841,7 @@ bool MeshTool::root_handler(GdkEvent* event) { case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - if ( drag->selected ) { + if ( !drag->selected.empty() ) { std::cout << "Deleting mesh stops not implemented yet" << std::endl; ret = TRUE; } diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index f06b03d91..2b85216d2 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -89,10 +89,6 @@ SelectTool::SelectTool() , button_press_shift(false) , button_press_ctrl(false) , button_press_alt(false) - , cycling_items(NULL) - , cycling_items_cmp(NULL) - , cycling_items_selected_before(NULL) - , cycling_cur_item(NULL) , cycling_wrap(true) , item(NULL) , grabbed(NULL) @@ -390,16 +386,16 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed) { - if (!this->cycling_cur_item) { + if (this->cycling_cur_item == this->cycling_items.end()) { return; } Inkscape::DrawingItem *arenaitem; - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(cycling_cur_item->data)); + SPItem *item = *cycling_cur_item; g_assert(item != NULL); // Deactivate current item - if (!g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) { + if (std::find(cycling_items_selected_before.begin(), cycling_items_selected_before.end(), item) == cycling_items_selected_before.end() && selection->includes(item)) { selection->remove(item); } @@ -407,20 +403,20 @@ void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *sele arenaitem->setOpacity(0.3); // Find next item and activate it - GList *next; + std::vector<SPItem *>::iterator next = this->cycling_cur_item; if (scroll_event->direction == GDK_SCROLL_UP) { - next = this->cycling_cur_item->next; - if (next == NULL && this->cycling_wrap) - next = this->cycling_items; + next++; + if (next == this->cycling_items.end() && this->cycling_wrap) + next = this->cycling_items.begin(); } else { - next = this->cycling_cur_item->prev; - if (next == NULL && this->cycling_wrap) - next = g_list_last(this->cycling_items); + if(next == this->cycling_items.begin()) + next = this->cycling_items.end(); + next--; } - if (next) { + if (next!=this->cycling_items.end()) { this->cycling_cur_item = next; - item = dynamic_cast<SPItem *>(static_cast<SPObject *>(this->cycling_cur_item->data)); + item = *next; g_assert(item != NULL); } @@ -435,8 +431,8 @@ void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *sele } void SelectTool::sp_select_context_reset_opacities() { - for (GList *l = this->cycling_items; l != NULL; l = g_list_next(l)) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data)); + for (std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l ) { + SPItem *item = *l; if (item) { Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey); arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(item->style->opacity.value)); @@ -445,14 +441,10 @@ void SelectTool::sp_select_context_reset_opacities() { } } - g_list_free(this->cycling_items); - g_list_free(this->cycling_items_selected_before); - g_list_free(this->cycling_items_cmp); - - this->cycling_items = NULL; - this->cycling_items_selected_before = NULL; - this->cycling_cur_item = NULL; - this->cycling_items_cmp = NULL; + this->cycling_items.clear(); + this->cycling_items_selected_before.clear(); + this->cycling_cur_item = this->cycling_items.end(); + this->cycling_items_cmp.clear(); } bool SelectTool::root_handler(GdkEvent* event) { @@ -819,70 +811,57 @@ bool SelectTool::root_handler(GdkEvent* event) { SPItem *item = desktop->getItemAtPoint(p, true, NULL); // Save pointer to current cycle-item so that we can find it again later, in the freshly built list - SPItem *tmp_cur_item = this->cycling_cur_item ? dynamic_cast<SPItem *>(static_cast<SPObject *>(this->cycling_cur_item->data)) : NULL; - g_list_free(this->cycling_items); - this->cycling_items = NULL; - this->cycling_cur_item = NULL; - + SPItem *tmp_cur_item = this->cycling_cur_item!=this->cycling_items.end() ? (*(this->cycling_cur_item)) : NULL; + this->cycling_items.clear(); + this->cycling_cur_item = this->cycling_items.end(); while(item != NULL) { - this->cycling_items = g_list_append(this->cycling_items, item); + this->cycling_items.push_back(item); item = desktop->getItemAtPoint(p, true, item); } /* Compare current item list with item list during previous scroll ... */ - GList *l1, *l2; - bool item_lists_differ = false; - - // Note that we can do an 'or' comparison in the loop because it is safe to call g_list_next with a NULL pointer. - for (l1 = this->cycling_items, l2 = this->cycling_items_cmp; l1 != NULL || l2 != NULL; l1 = g_list_next(l1), l2 = g_list_next(l2)) { - if ((l1 !=NULL && l2 == NULL) || (l1 == NULL && l2 != NULL) || (l1->data != l2->data)) { - item_lists_differ = true; - break; - } - } + bool item_lists_differ = this->cycling_items != this->cycling_items_cmp; /* If list of items under mouse pointer hasn't changed ... */ if (!item_lists_differ) { // ... find current item in the freshly built list and continue cycling ... // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead - this->cycling_cur_item = g_list_find(this->cycling_items, tmp_cur_item); - g_assert(this->cycling_cur_item != NULL || this->cycling_items == NULL); + this->cycling_cur_item = std::find(this->cycling_items.begin(), this->cycling_items.end(), tmp_cur_item); + g_assert(this->cycling_cur_item != this->cycling_items.end() || this->cycling_items.empty()); } else { // ... otherwise reset opacities for outdated items ... Inkscape::DrawingItem *arenaitem; - for(GList *l = this->cycling_items_cmp; l != NULL; l = l->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data)); + for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) { + SPItem *item = *l; if (item) { arenaitem = item->get_arenaitem(desktop->dkey); arenaitem->setOpacity(1.0); //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) - if (!g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) { + if (std::find(this->cycling_items_selected_before.begin(),this->cycling_items_selected_before.end(), item)==this->cycling_items_selected_before.end() && selection->includes(item)) { selection->remove(item); } } } // ... clear the lists ... - g_list_free(this->cycling_items_cmp); - g_list_free(this->cycling_items_selected_before); - this->cycling_items_cmp = NULL; - this->cycling_items_selected_before = NULL; - this->cycling_cur_item = NULL; + this->cycling_items_cmp.clear(); + this->cycling_items_selected_before.clear(); + this->cycling_cur_item = this->cycling_items.end(); // ... and rebuild them with the new items. - this->cycling_items_cmp = g_list_copy(this->cycling_items); + this->cycling_items_cmp = (this->cycling_items); - for(GList *l = this->cycling_items; l != NULL; l = l->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data)); + for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) { + SPItem *item =*l; if (item) { arenaitem = item->get_arenaitem(desktop->dkey); arenaitem->setOpacity(0.3); if (selection->includes(item)) { // already selected items are stored separately, too - this->cycling_items_selected_before = g_list_append(this->cycling_items_selected_before, item); + this->cycling_items_selected_before.push_back(item); } } else { g_assert_not_reached(); @@ -890,7 +869,8 @@ bool SelectTool::root_handler(GdkEvent* event) { } // set the current item to the bottommost one so that the cycling step below re-starts at the top - this->cycling_cur_item = g_list_last(this->cycling_items); + this->cycling_cur_item = this->cycling_items.end(); + this->cycling_cur_item--; } this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h index 5af99a56a..af183b1ca 100644 --- a/src/ui/tools/select-tool.h +++ b/src/ui/tools/select-tool.h @@ -40,10 +40,10 @@ public: bool button_press_ctrl; bool button_press_alt; - GList *cycling_items; - GList *cycling_items_cmp; - GList *cycling_items_selected_before; - GList *cycling_cur_item; + std::vector<SPItem *> cycling_items; + std::vector<SPItem *> cycling_items_cmp; + std::vector<SPItem *> cycling_items_selected_before; + std::vector<SPItem *>::iterator cycling_cur_item; bool cycling_wrap; SPItem *item; diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index bf7b61b61..abac2c091 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -924,7 +924,7 @@ void ToolBase::enableGrDrag(bool enable) { */ bool ToolBase::deleteSelectedDrag(bool just_one) { - if (_grdrag && _grdrag->selected) { + if (_grdrag && !_grdrag->selected.empty()) { _grdrag->deleteSelected(just_one); return TRUE; } |
