diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-01-02 09:41:30 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-01-02 09:41:30 +0000 |
| commit | 169dff19d4da8d76e69b8e896aa25b0013639c03 (patch) | |
| tree | a0c070fa95188b5cde708ac285e6a2db9df4a83f /src/ui/tool | |
| parent | Avoid creating a new document before opening an old document. (diff) | |
| download | inkscape-169dff19d4da8d76e69b8e896aa25b0013639c03.tar.gz inkscape-169dff19d4da8d76e69b8e896aa25b0013639c03.zip | |
modernize loops
Diffstat (limited to 'src/ui/tool')
| -rw-r--r-- | src/ui/tool/control-point-selection.cpp | 88 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.cpp | 71 | ||||
| -rw-r--r-- | src/ui/tool/node.cpp | 10 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 137 | ||||
| -rw-r--r-- | src/ui/tool/transform-handle-set.cpp | 14 |
5 files changed, 156 insertions, 164 deletions
diff --git a/src/ui/tool/control-point-selection.cpp b/src/ui/tool/control-point-selection.cpp index 915ed2a78..fc069e5bf 100644 --- a/src/ui/tool/control-point-selection.cpp +++ b/src/ui/tool/control-point-selection.cpp @@ -136,8 +136,8 @@ void ControlPointSelection::clear() /** Select all points that this selection can contain. */ void ControlPointSelection::selectAll() { - for (set_type::iterator i = _all_points.begin(); i != _all_points.end(); ++i) { - insert(*i, false); + for (auto _all_point : _all_points) { + insert(_all_point, false); } std::vector<SelectableControlPoint *> out(_all_points.begin(), _all_points.end()); if (!out.empty()) @@ -147,10 +147,10 @@ void ControlPointSelection::selectAll() void ControlPointSelection::selectArea(Geom::Rect const &r) { std::vector<SelectableControlPoint *> out; - for (set_type::iterator i = _all_points.begin(); i != _all_points.end(); ++i) { - if (r.contains(**i)) { - insert(*i, false); - out.push_back(*i); + for (auto _all_point : _all_points) { + if (r.contains(*_all_point)) { + insert(_all_point, false); + out.push_back(_all_point); } } if (!out.empty()) @@ -160,14 +160,14 @@ void ControlPointSelection::selectArea(Geom::Rect const &r) void ControlPointSelection::invertSelection() { std::vector<SelectableControlPoint *> in, out; - for (set_type::iterator i = _all_points.begin(); i != _all_points.end(); ++i) { - if ((*i)->selected()) { - in.push_back(*i); - erase(*i); + for (auto _all_point : _all_points) { + if (_all_point->selected()) { + in.push_back(_all_point); + erase(_all_point); } else { - out.push_back(*i); - insert(*i, false); + out.push_back(_all_point); + insert(_all_point, false); } } if (!in.empty()) @@ -181,21 +181,21 @@ void ControlPointSelection::spatialGrow(SelectableControlPoint *origin, int dir) Geom::Point p = origin->position(); double best_dist = grow ? HUGE_VAL : 0; SelectableControlPoint *match = nullptr; - for (set_type::iterator i = _all_points.begin(); i != _all_points.end(); ++i) { - bool selected = (*i)->selected(); + for (auto _all_point : _all_points) { + bool selected = _all_point->selected(); if (grow && !selected) { - double dist = Geom::distance((*i)->position(), p); + double dist = Geom::distance(_all_point->position(), p); if (dist < best_dist) { best_dist = dist; - match = *i; + match = _all_point; } } if (!grow && selected) { - double dist = Geom::distance((*i)->position(), p); + double dist = Geom::distance(_all_point->position(), p); // use >= to also deselect the origin node when it's the last one selected if (dist >= best_dist) { best_dist = dist; - match = *i; + match = _all_point; } } } @@ -209,8 +209,7 @@ void ControlPointSelection::spatialGrow(SelectableControlPoint *origin, int dir) /** Transform all selected control points by the given affine transformation. */ void ControlPointSelection::transform(Geom::Affine const &m) { - for (iterator i = _points.begin(); i != _points.end(); ++i) { - SelectableControlPoint *cur = *i; + for (auto cur : _points) { cur->transform(m); } _updateBounds(); @@ -230,8 +229,8 @@ void ControlPointSelection::align(Geom::Dim2 axis) Geom::OptInterval bound; - for (iterator i = _points.begin(); i != _points.end(); ++i) { - bound.unionWith(Geom::OptInterval((*i)->position()[d])); + for (auto _point : _points) { + bound.unionWith(Geom::OptInterval(_point->position()[d])); } if (!bound) { return; } @@ -257,10 +256,10 @@ void ControlPointSelection::align(Geom::Dim2 axis) return; } - for (iterator i = _points.begin(); i != _points.end(); ++i) { - Geom::Point pos = (*i)->position(); + for (auto _point : _points) { + Geom::Point pos = _point->position(); pos[d] = new_coord; - (*i)->move(pos); + _point->move(pos); } } @@ -276,9 +275,9 @@ void ControlPointSelection::distribute(Geom::Dim2 d) Geom::OptInterval bound; // first we insert all points into a multimap keyed by the aligned coord to sort them // simultaneously we compute the extent of selection - for (iterator i = _points.begin(); i != _points.end(); ++i) { - Geom::Point pos = (*i)->position(); - sm.insert(std::make_pair(pos[d], (*i))); + for (auto _point : _points) { + Geom::Point pos = _point->position(); + sm.insert(std::make_pair(pos[d], _point)); bound.unionWith(Geom::OptInterval(pos[d])); } @@ -345,13 +344,13 @@ void ControlPointSelection::_pointGrabbed(SelectableControlPoint *point) double maxdist = 0; Geom::Affine m; m.setIdentity(); - for (iterator i = _points.begin(); i != _points.end(); ++i) { - _original_positions.insert(std::make_pair(*i, (*i)->position())); - _last_trans.insert(std::make_pair(*i, m)); - double dist = Geom::distance(*_grabbed_point, **i); + for (auto _point : _points) { + _original_positions.insert(std::make_pair(_point, _point->position())); + _last_trans.insert(std::make_pair(_point, m)); + double dist = Geom::distance(*_grabbed_point, *_point); if (dist > maxdist) { maxdist = dist; - _farthest_point = *i; + _farthest_point = _point; } } } @@ -362,8 +361,7 @@ void ControlPointSelection::_pointDragged(Geom::Point &new_pos, GdkEventMotion * double fdist = Geom::distance(_original_positions[_grabbed_point], _original_positions[_farthest_point]); if (held_only_alt(*event) && fdist > 0) { // Sculpting - for (iterator i = _points.begin(); i != _points.end(); ++i) { - SelectableControlPoint *cur = (*i); + for (auto cur : _points) { Geom::Affine trans; trans.setIdentity(); double dist = Geom::distance(_original_positions[cur], _original_positions[_grabbed_point]); @@ -410,8 +408,7 @@ void ControlPointSelection::_pointDragged(Geom::Point &new_pos, GdkEventMotion * } } else { Geom::Point delta = new_pos - _grabbed_point->position(); - for (iterator i = _points.begin(); i != _points.end(); ++i) { - SelectableControlPoint *cur = (*i); + for (auto cur : _points) { cur->move(_original_positions[cur] + abs_delta); } _handles->rotationCenter().move(_handles->rotationCenter().position() + delta); @@ -461,8 +458,7 @@ void ControlPointSelection::_updateBounds() { _rot_radius = boost::none; _bounds = Geom::OptRect(); - for (iterator i = _points.begin(); i != _points.end(); ++i) { - SelectableControlPoint *cur = (*i); + for (auto cur : _points) { Geom::Point p = cur->position(); if (!_bounds) { _bounds = Geom::Rect(p, p); @@ -719,8 +715,8 @@ bool ControlPointSelection::event(Inkscape::UI::Tools::ToolBase * /*event_contex void ControlPointSelection::getOriginalPoints(std::vector<Inkscape::SnapCandidatePoint> &pts) { pts.clear(); - for (iterator i = _points.begin(); i != _points.end(); ++i) { - pts.emplace_back(_original_positions[*i], SNAPSOURCE_NODE_HANDLE); + for (auto _point : _points) { + pts.emplace_back(_original_positions[_point], SNAPSOURCE_NODE_HANDLE); } } @@ -728,9 +724,9 @@ void ControlPointSelection::getUnselectedPoints(std::vector<Inkscape::SnapCandid { pts.clear(); ControlPointSelection::Set &nodes = this->allPoints(); - for (ControlPointSelection::Set::iterator i = nodes.begin(); i != nodes.end(); ++i) { - if (!(*i)->selected()) { - Node *n = static_cast<Node*>(*i); + for (auto node : nodes) { + if (!node->selected()) { + Node *n = static_cast<Node*>(node); pts.push_back(n->snapCandidatePoint()); } } @@ -739,8 +735,8 @@ void ControlPointSelection::getUnselectedPoints(std::vector<Inkscape::SnapCandid void ControlPointSelection::setOriginalPoints() { _original_positions.clear(); - for (iterator i = _points.begin(); i != _points.end(); ++i) { - _original_positions.insert(std::make_pair(*i, (*i)->position())); + for (auto _point : _points) { + _original_positions.insert(std::make_pair(_point, _point->position())); } } diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index b107ab359..08114ac03 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -58,8 +58,8 @@ void find_join_iterators(ControlPointSelection &sel, IterPairList &pairs) IterSet join_iters; // find all endnodes in selection - for (ControlPointSelection::iterator i = sel.begin(); i != sel.end(); ++i) { - Node *node = dynamic_cast<Node*>(*i); + for (auto i : sel) { + Node *node = dynamic_cast<Node*>(i); if (!node) continue; NodeList::iterator iter = NodeList::get_iterator(node); if (!iter.next() || !iter.prev()) join_iters.insert(iter); @@ -181,8 +181,7 @@ void MultiPathManipulator::setItems(std::set<ShapeRecord> const &s) } // add newly selected items - for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) { - ShapeRecord const &r = *i; + for (const auto & r : shapes) { if (!SP_IS_PATH(r.item) && !IS_LIVEPATHEFFECT(r.item)) continue; std::shared_ptr<PathManipulator> newpm(new PathManipulator(*this, (SPPath*) r.item, r.edit_transform, _getOutlineColor(r.role, r.item), r.lpe_key)); @@ -297,8 +296,8 @@ void MultiPathManipulator::setNodeType(NodeType type) // When all selected nodes are already cusp, retract their handles bool retract_handles = (type == NODE_CUSP); - for (ControlPointSelection::iterator i = _selection.begin(); i != _selection.end(); ++i) { - Node *node = dynamic_cast<Node*>(*i); + for (auto i : _selection) { + Node *node = dynamic_cast<Node*>(i); if (node) { retract_handles &= (node->type() == NODE_CUSP); node->setType(type); @@ -306,8 +305,8 @@ void MultiPathManipulator::setNodeType(NodeType type) } if (retract_handles) { - for (ControlPointSelection::iterator i = _selection.begin(); i != _selection.end(); ++i) { - Node *node = dynamic_cast<Node*>(*i); + for (auto i : _selection) { + Node *node = dynamic_cast<Node*>(i); if (node) { node->front()->retract(); node->back()->retract(); @@ -371,37 +370,37 @@ void MultiPathManipulator::joinNodes() } find_join_iterators(_selection, joins); - for (IterPairList::iterator i = joins.begin(); i != joins.end(); ++i) { - bool same_path = prepare_join(*i); - NodeList &sp_first = NodeList::get(i->first); - NodeList &sp_second = NodeList::get(i->second); - i->first->setType(NODE_CUSP, false); + for (auto & join : joins) { + bool same_path = prepare_join(join); + NodeList &sp_first = NodeList::get(join.first); + NodeList &sp_second = NodeList::get(join.second); + join.first->setType(NODE_CUSP, false); Geom::Point joined_pos, pos_handle_front, pos_handle_back; - pos_handle_front = *i->second->front(); - pos_handle_back = *i->first->back(); + pos_handle_front = *join.second->front(); + pos_handle_back = *join.first->back(); // When we encounter the mouseover node, we unset the iterator - it will be invalidated - if (i->first == preserve_pos) { - joined_pos = *i->first; + if (join.first == preserve_pos) { + joined_pos = *join.first; preserve_pos = NodeList::iterator(); - } else if (i->second == preserve_pos) { - joined_pos = *i->second; + } else if (join.second == preserve_pos) { + joined_pos = *join.second; preserve_pos = NodeList::iterator(); } else { - joined_pos = Geom::middle_point(*i->first, *i->second); + joined_pos = Geom::middle_point(*join.first, *join.second); } // if the handles aren't degenerate, don't move them - i->first->move(joined_pos); - Node *joined_node = i->first.ptr(); - if (!i->second->front()->isDegenerate()) { + join.first->move(joined_pos); + Node *joined_node = join.first.ptr(); + if (!join.second->front()->isDegenerate()) { joined_node->front()->setPosition(pos_handle_front); } - if (!i->first->back()->isDegenerate()) { + if (!join.first->back()->isDegenerate()) { joined_node->back()->setPosition(pos_handle_back); } - sp_second.erase(i->second); + sp_second.erase(join.second); if (same_path) { sp_first.setClosed(true); @@ -409,7 +408,7 @@ void MultiPathManipulator::joinNodes() sp_first.splice(sp_first.end(), sp_second); sp_second.kill(); } - _selection.insert(i->first.ptr()); + _selection.insert(join.first.ptr()); } if (joins.empty()) { @@ -441,12 +440,12 @@ void MultiPathManipulator::joinSegments() IterPairList joins; find_join_iterators(_selection, joins); - for (IterPairList::iterator i = joins.begin(); i != joins.end(); ++i) { - bool same_path = prepare_join(*i); - NodeList &sp_first = NodeList::get(i->first); - NodeList &sp_second = NodeList::get(i->second); - i->first->setType(NODE_CUSP, false); - i->second->setType(NODE_CUSP, false); + for (auto & join : joins) { + bool same_path = prepare_join(join); + NodeList &sp_first = NodeList::get(join.first); + NodeList &sp_second = NodeList::get(join.second); + join.first->setType(NODE_CUSP, false); + join.second->setType(NODE_CUSP, false); if (same_path) { sp_first.setClosed(true); } else { @@ -510,9 +509,9 @@ void MultiPathManipulator::move(Geom::Point const &delta) void MultiPathManipulator::showOutline(bool show) { - for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) { + for (auto & i : _mmap) { // always show outlines for clipping paths and masks - i->second->showOutline(show || i->first.role != SHAPE_ROLE_NORMAL); + i.second->showOutline(show || i.first.role != SHAPE_ROLE_NORMAL); } _show_outline = show; } @@ -759,8 +758,8 @@ bool MultiPathManipulator::event(Inkscape::UI::Tools::ToolBase *event_context, G break; case GDK_MOTION_NOTIFY: combine_motion_events(_desktop->canvas, event->motion, 0); - for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) { - if (i->second->event(event_context, event)) return true; + for (auto & i : _mmap) { + if (i.second->event(event_context, event)) return true; } break; default: break; diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 4321963b9..78c359609 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -381,8 +381,8 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) //if the snap adjustment is activated and it is not bspline if (snap && !_pm()._isBSpline()) { ControlPointSelection::Set &nodes = _parent->_selection.allPoints(); - for (ControlPointSelection::Set::iterator i = nodes.begin(); i != nodes.end(); ++i) { - Node *n = static_cast<Node*>(*i); + for (auto node : nodes) { + Node *n = static_cast<Node*>(node); unselected.push_back(n->snapCandidatePoint()); } sm.setupIgnoreSelection(_desktop, true, &unselected); @@ -1225,9 +1225,9 @@ void Node::dragged(Geom::Point &new_pos, GdkEventMotion *event) // Build the list of unselected nodes. typedef ControlPointSelection::Set Set; Set &nodes = _selection.allPoints(); - for (Set::iterator i = nodes.begin(); i != nodes.end(); ++i) { - if (!(*i)->selected()) { - Node *n = static_cast<Node*>(*i); + for (auto node : nodes) { + if (!node->selected()) { + Node *n = static_cast<Node*>(node); Inkscape::SnapCandidatePoint p(n->position(), n->_snapSourceType(), n->_snapTargetType()); unselected.push_back(p); } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index a2390f3a9..83c177297 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -220,8 +220,8 @@ void PathManipulator::clear() /** Select all nodes in subpaths that have something selected. */ void PathManipulator::selectSubpaths() { - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - NodeList::iterator sp_start = (*i)->begin(), sp_end = (*i)->end(); + for (auto & _subpath : _subpaths) { + NodeList::iterator sp_start = _subpath->begin(), sp_end = _subpath->end(); for (NodeList::iterator j = sp_start; j != sp_end; ++j) { if (j->selected()) { // if at least one of the nodes from this subpath is selected, @@ -237,11 +237,11 @@ void PathManipulator::selectSubpaths() /** Invert selection in the selected subpaths. */ void PathManipulator::invertSelectionInSubpaths() { - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { if (j->selected()) { // found selected node - invert selection in this subpath - for (NodeList::iterator k = (*i)->begin(); k != (*i)->end(); ++k) { + for (NodeList::iterator k = _subpath->begin(); k != _subpath->end(); ++k) { if (k->selected()) _selection.erase(k.ptr()); else _selection.insert(k.ptr()); } @@ -257,8 +257,8 @@ void PathManipulator::insertNodes() { if (_num_selected < 2) return; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { NodeList::iterator k = j.next(); if (k && j->selected() && k->selected()) { j = subdivideSegment(j, 0.5); @@ -312,11 +312,11 @@ void PathManipulator::insertNodeAtExtremum(ExtremumType extremum) double sign = (extremum == EXTR_MIN_X || extremum == EXTR_MIN_Y) ? -1. : 1.; Geom::Dim2 dim = (extremum == EXTR_MIN_X || extremum == EXTR_MAX_X) ? Geom::X : Geom::Y; - for (SubpathList::iterator subp = _subpaths.begin(); subp != _subpaths.end(); ++subp) { + for (auto & _subpath : _subpaths) { Geom::Coord extrvalue = - Geom::infinity(); std::vector< std::pair<NodeList::iterator, double> > extremum_vector; - for (NodeList::iterator first = (*subp)->begin(); first != (*subp)->end(); ++first) { + for (NodeList::iterator first = _subpath->begin(); first != _subpath->end(); ++first) { NodeList::iterator second = first.next(); if (second && first->selected() && second->selected()) { add_or_replace_if_extremum(extremum_vector, extrvalue, sign * first->position()[dim], first, 0.); @@ -331,19 +331,19 @@ void PathManipulator::insertNodeAtExtremum(ExtremumType extremum) // and determine extremum Geom::Bezier deriv1d = derivative(temp1d); std::vector<double> rs = deriv1d.roots(); - for (std::vector<double>::iterator it = rs.begin(); it != rs.end(); ++it) { - add_or_replace_if_extremum(extremum_vector, extrvalue, sign * temp1d.valueAt(*it), first, *it); + for (double & r : rs) { + add_or_replace_if_extremum(extremum_vector, extrvalue, sign * temp1d.valueAt(r), first, r); } } } } - for (unsigned i = 0; i < extremum_vector.size(); ++i) { + for (auto & i : extremum_vector) { // don't insert node at the start or end of a segment, i.e. round values for extr_t - double t = extremum_vector[i].second; + double t = i.second; if ( !Geom::are_near(t - std::floor(t+0.5),0.) ) // std::floor(t+0.5) is another way of writing round(t) { - _selection.insert( subdivideSegment(extremum_vector[i].first, t).ptr() ); + _selection.insert( subdivideSegment(i.first, t).ptr() ); } } } @@ -356,8 +356,8 @@ void PathManipulator::duplicateNodes() { if (_num_selected == 0) return; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { if (j->selected()) { NodeList::iterator k = j.next(); Node *n = new Node(_multi_path_manipulator._path_data.node_data, *j); @@ -372,7 +372,7 @@ void PathManipulator::duplicateNodes() n->front()->setPosition(*j->front()); j->front()->retract(); j->setType(NODE_CUSP, false); - (*i)->insert(k, n); + _subpath->insert(k, n); if (k) { // We need to manually call the selection change callback to refresh @@ -399,11 +399,10 @@ void PathManipulator::weldNodes(NodeList::iterator preserve_pos) hideDragPoint(); bool pos_valid = preserve_pos; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - SubpathPtr sp = *i; + for (auto sp : _subpaths) { unsigned num_selected = 0, num_unselected = 0; - for (NodeList::iterator j = sp->begin(); j != sp->end(); ++j) { - if (j->selected()) ++num_selected; + for (auto & j : *sp) { + if (j.selected()) ++num_selected; else ++num_unselected; } if (num_selected < 2) continue; @@ -474,11 +473,10 @@ void PathManipulator::weldSegments() if (_num_selected < 2) return; hideDragPoint(); - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - SubpathPtr sp = *i; + for (auto sp : _subpaths) { unsigned num_selected = 0, num_unselected = 0; - for (NodeList::iterator j = sp->begin(); j != sp->end(); ++j) { - if (j->selected()) ++num_selected; + for (auto & j : *sp) { + if (j.selected()) ++num_selected; else ++num_unselected; } @@ -588,8 +586,8 @@ void PathManipulator::deleteNodes(bool keep_shape) // If there are less than 2 unselected nodes in an open subpath or no unselected nodes // in a closed one, delete entire subpath. unsigned num_unselected = 0, num_selected = 0; - for (NodeList::iterator j = sp->begin(); j != sp->end(); ++j) { - if (j->selected()) ++num_selected; + for (auto & j : *sp) { + if (j.selected()) ++num_selected; else ++num_unselected; } if (num_selected == 0) { @@ -709,8 +707,8 @@ void PathManipulator::deleteSegments() SubpathPtr sp = *i; bool has_unselected = false; unsigned num_selected = 0; - for (NodeList::iterator j = sp->begin(); j != sp->end(); ++j) { - if (j->selected()) { + for (auto & j : *sp) { + if (j.selected()) { ++num_selected; } else { has_unselected = true; @@ -779,16 +777,16 @@ void PathManipulator::deleteSegments() * will be reversed. Otherwise all subpaths will be reversed. */ void PathManipulator::reverseSubpaths(bool selected_only) { - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { + for (auto & _subpath : _subpaths) { if (selected_only) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { if (j->selected()) { - (*i)->reverse(); + _subpath->reverse(); break; // continue with the next subpath } } } else { - (*i)->reverse(); + _subpath->reverse(); } } } @@ -797,8 +795,8 @@ void PathManipulator::reverseSubpaths(bool selected_only) void PathManipulator::setSegmentType(SegmentType type) { if (_num_selected == 0) return; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { NodeList::iterator k = j.next(); if (!(k && j->selected() && k->selected())) continue; switch (type) { @@ -908,8 +906,8 @@ void PathManipulator::showHandles(bool show) { if (show == _show_handles) return; if (show) { - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { if (!j->selected()) continue; j->showHandles(true); if (j.prev()) j.prev()->showHandles(true); @@ -917,8 +915,8 @@ void PathManipulator::showHandles(bool show) } } } else { - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { j->showHandles(false); } } @@ -953,8 +951,8 @@ void PathManipulator::setLiveObjects(bool set) void PathManipulator::updateHandles() { - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { j->updateHandles(); } } @@ -964,8 +962,8 @@ void PathManipulator::setControlsTransform(Geom::Affine const &tnew) { Geom::Affine delta = _i2d_transform.inverse() * _edit_transform.inverse() * tnew * _i2d_transform; _edit_transform = tnew; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { j->transform(delta); } } @@ -1068,8 +1066,8 @@ NodeList::iterator PathManipulator::extremeNode(NodeList::iterator origin, bool double extr_dist = closest ? HUGE_VAL : -HUGE_VAL; if (_num_selected == 0 && !search_unselected) return match; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { if(j->selected()) { if (!search_selected) continue; } else { @@ -1098,8 +1096,8 @@ void PathManipulator::_externalChange(unsigned type) // ugly: stored offsets of selected nodes in a vector // vector<bool> should be specialized so that it takes only 1 bit per value std::vector<bool> selpos; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { selpos.push_back(j->selected()); } } @@ -1107,8 +1105,8 @@ void PathManipulator::_externalChange(unsigned type) _createControlPointsFromGeometry(); - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { if (curpos >= size) goto end_restore; if (selpos[curpos]) _selection.insert(j.ptr()); ++curpos; @@ -1123,8 +1121,8 @@ void PathManipulator::_externalChange(unsigned type) _i2d_transform = _path->i2dt_affine(); _d2i_transform = _i2d_transform.inverse(); i2d_change *= _i2d_transform; - for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { j->transform(i2d_change); } } @@ -1160,22 +1158,22 @@ void PathManipulator::_createControlPointsFromGeometry() pathv *= (_edit_transform * _i2d_transform); // in this loop, we know that there are no zero-segment subpaths - for (Geom::PathVector::iterator pit = pathv.begin(); pit != pathv.end(); ++pit) { + for (auto & pit : pathv) { // prepare new subpath SubpathPtr subpath(new NodeList(_subpaths)); _subpaths.push_back(subpath); - Node *previous_node = new Node(_multi_path_manipulator._path_data.node_data, pit->initialPoint()); + Node *previous_node = new Node(_multi_path_manipulator._path_data.node_data, pit.initialPoint()); subpath->push_back(previous_node); - bool closed = pit->closed(); + bool closed = pit.closed(); - for (Geom::Path::iterator cit = pit->begin(); cit != pit->end(); ++cit) { + for (Geom::Path::iterator cit = pit.begin(); cit != pit.end(); ++cit) { Geom::Point pos = cit->finalPoint(); Node *current_node; // if the closing segment is degenerate and the path is closed, we need to move // the handle of the first node instead of creating a new one - if (closed && cit == --(pit->end())) { + if (closed && cit == --(pit.end())) { current_node = subpath->begin().get_pointer(); } else { /* regardless of segment type, create a new node at the end @@ -1197,7 +1195,7 @@ void PathManipulator::_createControlPointsFromGeometry() previous_node = current_node; } // If the path is closed, make the list cyclic - if (pit->closed()) subpath->setClosed(true); + if (pit.closed()) subpath->setClosed(true); } // we need to set the nodetypes after all the handles are in place, @@ -1224,14 +1222,14 @@ void PathManipulator::_createControlPointsFromGeometry() nodetype_string.append(nodetype_len - nodetype_string.size(), 'b'); } std::string::iterator tsi = nodetype_string.begin(); - for (std::list<SubpathPtr>::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { j->setType(Node::parse_nodetype(*tsi++), false); } - if ((*i)->closed()) { + if (_subpath->closed()) { // STUPIDITY ALERT: it seems we need to use the duplicate type symbol instead of // the first one to remain backward compatible. - (*i)->begin()->setType(Node::parse_nodetype(*tsi++), false); + _subpath->begin()->setType(Node::parse_nodetype(*tsi++), false); } } } @@ -1419,12 +1417,12 @@ std::string PathManipulator::_createTypeString() { // precondition: no single-node subpaths std::stringstream tstr; - for (std::list<SubpathPtr>::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { tstr << j->type(); } // nodestring format peculiarity: first node is counted twice for closed paths - if ((*i)->closed()) tstr << (*i)->begin()->type(); + if (_subpath->closed()) tstr << _subpath->begin()->type(); } return tstr.str(); } @@ -1448,8 +1446,7 @@ void PathManipulator::_updateOutline() // of little 'harpoons' that show the direction of the subpaths. auto rot_scale_w2d = Geom::Rotate(210.0 / 180.0 * M_PI) * Geom::Scale(10.0) * _desktop->w2d(); Geom::PathVector arrows; - for (Geom::PathVector::iterator i = pv.begin(); i != pv.end(); ++i) { - Geom::Path &path = *i; + for (auto & path : pv) { for (Geom::Path::iterator j = path.begin(); j != path.end_default(); ++j) { Geom::Point at = j->pointAt(0.5); Geom::Point ut = j->unitTangentAt(0.5); @@ -1600,8 +1597,8 @@ bool PathManipulator::_handleClicked(Handle *h, GdkEventButton *event) } void PathManipulator::_selectionChangedM(std::vector<SelectableControlPoint *> pvec, bool selected) { - for (size_t n = 0, e = pvec.size(); n < e; ++n) { - _selectionChanged(pvec[n], selected); + for (auto & n : pvec) { + _selectionChanged(n, selected); } } @@ -1650,8 +1647,8 @@ void PathManipulator::_selectionChanged(SelectableControlPoint *p, bool selected void PathManipulator::_removeNodesFromSelection() { // remove this manipulator's nodes from selection - for (std::list<SubpathPtr>::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { - for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + for (auto & _subpath : _subpaths) { + for (NodeList::iterator j = _subpath->begin(); j != _subpath->end(); ++j) { _selection.erase(j.get_pointer()); } } diff --git a/src/ui/tool/transform-handle-set.cpp b/src/ui/tool/transform-handle-set.cpp index 781675a99..c1d6692bc 100644 --- a/src/ui/tool/transform-handle-set.cpp +++ b/src/ui/tool/transform-handle-set.cpp @@ -154,8 +154,8 @@ bool TransformHandle::grabbed(GdkEventMotion *) _all_snap_sources_sorted = _snap_points; // Calculate and store the distance to the reference point for each snap candidate point - for(std::vector<Inkscape::SnapCandidatePoint>::iterator i = _all_snap_sources_sorted.begin(); i != _all_snap_sources_sorted.end(); ++i) { - (*i).setDistance(Geom::L2((*i).getPoint() - _origin)); + for(auto & i : _all_snap_sources_sorted) { + i.setDistance(Geom::L2(i.getPoint() - _origin)); } // Sort them ascending, using the distance calculated above as the single criteria @@ -724,8 +724,8 @@ TransformHandleSet::TransformHandleSet(SPDesktop *d, SPCanvasGroup *th_group) TransformHandleSet::~TransformHandleSet() { - for (unsigned i = 0; i < 17; ++i) { - delete _handles[i]; + for (auto & _handle : _handles) { + delete _handle; } } @@ -844,9 +844,9 @@ void TransformHandleSet::_updateVisibility(bool v) _center->setVisible(show_rotate /*&& bp[Geom::X] > handle_size[Geom::X] && bp[Geom::Y] > handle_size[Geom::Y]*/); } else { - for (unsigned i = 0; i < 17; ++i) { - if (_handles[i] != _active) - _handles[i]->setVisible(false); + for (auto & _handle : _handles) { + if (_handle != _active) + _handle->setVisible(false); } } |
