# HG changeset patch # User Chris Cannam # Date 1480068489 0 # Node ID 114de081a42d894400dbdcf4945d578b4c7dc8a3 # Parent 4b0c968a581a44a9447b9c7120de262fe50069f8 Tidy up, with some convenient C++11isms diff -r 4b0c968a581a -r 114de081a42d data/model/Labeller.h --- a/data/model/Labeller.h Fri Nov 25 09:57:36 2016 +0000 +++ b/data/model/Labeller.h Fri Nov 25 10:08:09 2016 +0000 @@ -180,34 +180,26 @@ template Command *labelAll(SparseModel &model, MultiSelection *ms) { - typename SparseModel::PointList::iterator i; - typename SparseModel::PointList pl(model.getPoints()); - - typename SparseModel::EditCommand *command = - new typename SparseModel::EditCommand + auto points(model.getPoints()); + auto command = new typename SparseModel::EditCommand (&model, tr("Label Points")); PointType prevPoint(0); + bool havePrevPoint(false); - for (i = pl.begin(); i != pl.end(); ++i) { + for (auto p: points) { - bool inRange = true; if (ms) { - Selection s(ms->getContainingSelection(i->frame, false)); - if (s.isEmpty() || !s.contains(i->frame)) { - inRange = false; + Selection s(ms->getContainingSelection(p.frame, false)); + if (!s.contains(p.frame)) { + prevPoint = p; + havePrevPoint = true; + continue; } } - PointType p(*i); - - if (!inRange) { - prevPoint = p; - continue; - } - if (actingOnPrevPoint()) { - if (i != pl.begin()) { + if (havePrevPoint) { command->deletePoint(prevPoint); label(p, &prevPoint); command->addPoint(prevPoint); @@ -219,6 +211,7 @@ } prevPoint = p; + havePrevPoint = true; } return command->finish(); @@ -234,31 +227,24 @@ template Command *subdivide(SparseModel &model, MultiSelection *ms, int n) { - typename SparseModel::PointList::iterator i; - typename SparseModel::PointList pl(model.getPoints()); + auto points(model.getPoints()); + auto command = new typename SparseModel::EditCommand + (&model, tr("Subdivide Points")); - typename SparseModel::EditCommand *command = - new typename SparseModel::EditCommand - (&model, tr("Subdivide")); - - for (i = pl.begin(); i != pl.end(); ++i) { + for (auto i = points.begin(); i != points.end(); ++i) { auto j = i; // require a "next point" even if it's not in selection - if (++j == pl.end()) { + if (++j == points.end()) { break; } - bool inRange = true; if (ms) { Selection s(ms->getContainingSelection(i->frame, false)); - if (s.isEmpty() || !s.contains(i->frame)) { - inRange = false; + if (!s.contains(i->frame)) { + continue; } } - if (!inRange) { - continue; - } PointType p(*i); PointType nextP(*j); @@ -285,28 +271,21 @@ template Command *winnow(SparseModel &model, MultiSelection *ms, int n) { - typename SparseModel::PointList::iterator i; - typename SparseModel::PointList pl(model.getPoints()); - - typename SparseModel::EditCommand *command = - new typename SparseModel::EditCommand - (&model, tr("Subdivide")); + auto points(model.getPoints()); + auto command = new typename SparseModel::EditCommand + (&model, tr("Winnow Points")); int counter = 0; - for (i = pl.begin(); i != pl.end(); ++i) { + for (auto p: points) { - bool inRange = true; if (ms) { - Selection s(ms->getContainingSelection(i->frame, false)); - if (s.isEmpty() || !s.contains(i->frame)) { - inRange = false; + Selection s(ms->getContainingSelection(p.frame, false)); + if (!s.contains(p.frame)) { + counter = 0; + continue; } } - if (!inRange) { - counter = 0; - continue; - } ++counter; @@ -316,7 +295,7 @@ continue; } - command->deletePoint(*i); + command->deletePoint(p); } return command->finish();