summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-11-03 10:16:42 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-11-03 14:04:23 +0000
commit84c76d2006631e3b79f22a81a9dc93638b7dc5e0 (patch)
treeac3b290a5c4f7ce5d9591ff6d5fd8186914a33f4 /src/shared
parentac6b24246a0097eb77baccb55f23efbe4a38979a (diff)
Qt Designer/Gradient editor: Remove use of Java-style iterators
Use range-based for or STL style iterators instead. Change-Id: I9bf403504448a50cd0bb2f5cc188bfa3ac7f6a8a Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/qtgradienteditor/qtgradientmanager.cpp8
-rw-r--r--src/shared/qtgradienteditor/qtgradientstopscontroller.cpp41
-rw-r--r--src/shared/qtgradienteditor/qtgradientstopsmodel.cpp40
-rw-r--r--src/shared/qtgradienteditor/qtgradientstopswidget.cpp49
-rw-r--r--src/shared/qtgradienteditor/qtgradientutils.cpp11
-rw-r--r--src/shared/qtgradienteditor/qtgradientview.cpp5
6 files changed, 51 insertions, 103 deletions
diff --git a/src/shared/qtgradienteditor/qtgradientmanager.cpp b/src/shared/qtgradienteditor/qtgradientmanager.cpp
index 8395ffd1a..2662221b5 100644
--- a/src/shared/qtgradienteditor/qtgradientmanager.cpp
+++ b/src/shared/qtgradienteditor/qtgradientmanager.cpp
@@ -123,11 +123,9 @@ void QtGradientManager::changeGradient(const QString &id, const QGradient &newGr
void QtGradientManager::clear()
{
- QMap<QString, QGradient> grads = gradients();
- QMapIterator<QString, QGradient> itGrad(grads);
- while (itGrad.hasNext()) {
- removeGradient(itGrad.next().key());
- }
+ const QMap<QString, QGradient> grads = gradients();
+ for (auto it = grads.cbegin(), end = grads.cend(); it != end; ++it)
+ removeGradient(it.key());
}
QT_END_NAMESPACE
diff --git a/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp b/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
index d5b8d10bc..289f88da2 100644
--- a/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
+++ b/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
@@ -402,10 +402,8 @@ void QtGradientStopsControllerPrivate::slotChangeColor(const QColor &color)
if (!stop)
return;
m_model->changeStop(stop, color);
- QList<QtGradientStop *> stops = m_model->selectedStops();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ const QList<QtGradientStop *> stops = m_model->selectedStops();
+ for (QtGradientStop *s : stops) {
if (s != stop)
m_model->changeStop(s, color);
}
@@ -417,10 +415,8 @@ void QtGradientStopsControllerPrivate::slotChangeHue(const QColor &color)
if (!stop)
return;
m_model->changeStop(stop, color);
- QList<QtGradientStop *> stops = m_model->selectedStops();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ const QList<QtGradientStop *> stops = m_model->selectedStops();
+ for (QtGradientStop *s : stops) {
if (s != stop) {
QColor c = s->color();
if (m_ui->hsvRadioButton->isChecked())
@@ -448,10 +444,8 @@ void QtGradientStopsControllerPrivate::slotChangeSaturation(const QColor &color)
if (!stop)
return;
m_model->changeStop(stop, color);
- QList<QtGradientStop *> stops = m_model->selectedStops();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ const QList<QtGradientStop *> stops = m_model->selectedStops();
+ for (QtGradientStop *s : stops) {
if (s != stop) {
QColor c = s->color();
if (m_ui->hsvRadioButton->isChecked()) {
@@ -483,10 +477,8 @@ void QtGradientStopsControllerPrivate::slotChangeValue(const QColor &color)
if (!stop)
return;
m_model->changeStop(stop, color);
- QList<QtGradientStop *> stops = m_model->selectedStops();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ const QList<QtGradientStop *> stops = m_model->selectedStops();
+ for (QtGradientStop *s : stops) {
if (s != stop) {
QColor c = s->color();
if (m_ui->hsvRadioButton->isChecked()) {
@@ -518,10 +510,8 @@ void QtGradientStopsControllerPrivate::slotChangeAlpha(const QColor &color)
if (!stop)
return;
m_model->changeStop(stop, color);
- QList<QtGradientStop *> stops = m_model->selectedStops();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ const QList<QtGradientStop *> stops = m_model->selectedStops();
+ for (QtGradientStop *s : stops) {
if (s != stop) {
QColor c = s->color();
if (m_ui->hsvRadioButton->isChecked()) {
@@ -673,10 +663,8 @@ QtGradientStopsController::~QtGradientStopsController()
void QtGradientStopsController::setGradientStops(const QGradientStops &stops)
{
d_ptr->m_model->clear();
- QVectorIterator<QPair<qreal, QColor> > it(stops);
QtGradientStop *first = 0;
- while (it.hasNext()) {
- QPair<qreal, QColor> pair = it.next();
+ for (const QPair<qreal, QColor> &pair : stops) {
QtGradientStop *stop = d_ptr->m_model->addStop(pair.first, pair.second);
if (!first)
first = stop;
@@ -688,12 +676,9 @@ void QtGradientStopsController::setGradientStops(const QGradientStops &stops)
QGradientStops QtGradientStopsController::gradientStops() const
{
QGradientStops stops;
- QList<QtGradientStop *> stopsList = d_ptr->m_model->stops().values();
- QListIterator<QtGradientStop *> itStop(stopsList);
- while (itStop.hasNext()) {
- QtGradientStop *stop = itStop.next();
+ const QList<QtGradientStop *> stopsList = d_ptr->m_model->stops().values();
+ for (const QtGradientStop *stop : stopsList)
stops << QPair<qreal, QColor>(stop->position(), stop->color());
- }
return stops;
}
diff --git a/src/shared/qtgradienteditor/qtgradientstopsmodel.cpp b/src/shared/qtgradienteditor/qtgradientstopsmodel.cpp
index 676cb719e..0dac9b867 100644
--- a/src/shared/qtgradienteditor/qtgradientstopsmodel.cpp
+++ b/src/shared/qtgradienteditor/qtgradientstopsmodel.cpp
@@ -330,11 +330,8 @@ QtGradientStopsModel *QtGradientStopsModel::clone() const
QtGradientStopsModel *model = new QtGradientStopsModel();
QMap<qreal, QtGradientStop *> stopsToClone = stops();
- QMapIterator<qreal, QtGradientStop *> it(stopsToClone);
- while (it.hasNext()) {
- it.next();
+ for (auto it = stopsToClone.cbegin(), end = stopsToClone.cend(); it != end; ++it)
model->addStop(it.key(), it.value()->color());
- }
// clone selection and current also
return model;
}
@@ -378,12 +375,9 @@ void QtGradientStopsModel::moveStops(double newPosition)
PositionStopMap stopList;
- QList<QtGradientStop *> selected = selectedStops();
- QListIterator<QtGradientStop *> it(selected);
- while (it.hasNext()) {
- QtGradientStop *stop = it.next();
+ const QList<QtGradientStop *> selected = selectedStops();
+ for (QtGradientStop *stop : selected)
stopList[stop->position()] = stop;
- }
stopList[current->position()] = current;
PositionStopMap::ConstIterator itStop = forward ? stopList.constBegin() : stopList.constEnd();
@@ -412,18 +406,16 @@ void QtGradientStopsModel::moveStops(double newPosition)
void QtGradientStopsModel::clear()
{
- QList<QtGradientStop *> stopsList = stops().values();
- QListIterator<QtGradientStop *> it(stopsList);
- while (it.hasNext())
- removeStop(it.next());
+ const QList<QtGradientStop *> stopsList = stops().values();
+ for (QtGradientStop *stop : stopsList)
+ removeStop(stop);
}
void QtGradientStopsModel::clearSelection()
{
- QList<QtGradientStop *> stopsList = selectedStops();
- QListIterator<QtGradientStop *> it(stopsList);
- while (it.hasNext())
- selectStop(it.next(), false);
+ const QList<QtGradientStop *> stopsList = selectedStops();
+ for (QtGradientStop *stop : stopsList)
+ selectStop(stop, false);
}
void QtGradientStopsModel::flipAll()
@@ -453,20 +445,16 @@ void QtGradientStopsModel::flipAll()
void QtGradientStopsModel::selectAll()
{
- QList<QtGradientStop *> stopsList = stops().values();
- QListIterator<QtGradientStop *> it(stopsList);
- while (it.hasNext())
- selectStop(it.next(), true);
+ const auto stopsMap = stops();
+ for (auto it = stopsMap.cbegin(), end = stopsMap.cend(); it != end; ++it)
+ selectStop(it.value(), true);
}
void QtGradientStopsModel::deleteStops()
{
- QList<QtGradientStop *> selected = selectedStops();
- QListIterator<QtGradientStop *> itSel(selected);
- while (itSel.hasNext()) {
- QtGradientStop *stop = itSel.next();
+ const QList<QtGradientStop *> selected = selectedStops();
+ for (QtGradientStop *stop : selected)
removeStop(stop);
- }
QtGradientStop *current = currentStop();
if (current)
removeStop(current);
diff --git a/src/shared/qtgradienteditor/qtgradientstopswidget.cpp b/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
index 5e1209ff2..4968aa2ba 100644
--- a/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
+++ b/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
@@ -135,10 +135,7 @@ double QtGradientStopsWidgetPrivate::toViewport(double x) const
QtGradientStop *QtGradientStopsWidgetPrivate::stopAt(const QPoint &viewportPos) const
{
double posY = m_handleSize / 2;
- QListIterator<QtGradientStop *> itStop(m_stops);
- while (itStop.hasNext()) {
- QtGradientStop *stop = itStop.next();
-
+ for (QtGradientStop *stop : m_stops) {
double posX = toViewport(stop->position());
double x = viewportPos.x() - posX;
@@ -154,10 +151,7 @@ QList<QtGradientStop *> QtGradientStopsWidgetPrivate::stopsAt(const QPoint &view
{
QList<QtGradientStop *> stops;
double posY = m_handleSize / 2;
- QListIterator<QtGradientStop *> itStop(m_stops);
- while (itStop.hasNext()) {
- QtGradientStop *stop = itStop.next();
-
+ for (QtGradientStop *stop : m_stops) {
double posX = toViewport(stop->position());
double x = viewportPos.x() - posX;
@@ -176,11 +170,9 @@ void QtGradientStopsWidgetPrivate::setupMove(QtGradientStop *stop, int x)
int viewportX = qRound(toViewport(stop->position()));
m_moveOffset = x - viewportX;
- QList<QtGradientStop *> stops = m_stops;
+ const QList<QtGradientStop *> stops = m_stops;
m_stops.clear();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ for (QtGradientStop *s : stops) {
if (m_model->isSelected(s) || s == stop) {
m_moveStops[s] = s->position() - stop->position();
m_stops.append(s);
@@ -188,9 +180,7 @@ void QtGradientStopsWidgetPrivate::setupMove(QtGradientStop *stop, int x)
m_moveOriginal[s->position()] = s->color();
}
}
- itStop.toFront();
- while (itStop.hasNext()) {
- QtGradientStop *s = itStop.next();
+ for (QtGradientStop *s : stops) {
if (!m_model->isSelected(s))
m_stops.append(s);
}
@@ -456,15 +446,13 @@ void QtGradientStopsWidget::setGradientStopsModel(QtGradientStopsModel *model)
connect(d_ptr->m_model, SIGNAL(currentStopChanged(QtGradientStop*)),
this, SLOT(slotCurrentStopChanged(QtGradientStop*)));
- QList<QtGradientStop *> stops = d_ptr->m_model->stops().values();
- QListIterator<QtGradientStop *> itStop(stops);
- while (itStop.hasNext())
- d_ptr->slotStopAdded(itStop.next());
+ const QtGradientStopsModel::PositionStopMap stopsMap = d_ptr->m_model->stops();
+ for (auto it = stopsMap.cbegin(), end = stopsMap.cend(); it != end; ++it)
+ d_ptr->slotStopAdded(it.value());
- QList<QtGradientStop *> selected = d_ptr->m_model->selectedStops();
- QListIterator<QtGradientStop *> itSelect(selected);
- while (itSelect.hasNext())
- d_ptr->slotStopSelected(itSelect.next(), true);
+ const QList<QtGradientStop *> selected = d_ptr->m_model->selectedStops();
+ for (QtGradientStop *stop : selected)
+ d_ptr->slotStopSelected(stop, true);
d_ptr->slotCurrentStopChanged(d_ptr->m_model->currentStop());
}
@@ -670,9 +658,7 @@ void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
double x1 = d_ptr->fromViewport(xv1);
double x2 = d_ptr->fromViewport(xv2);
- QListIterator<QtGradientStop *> itStop(d_ptr->m_stops);
- while (itStop.hasNext()) {
- QtGradientStop *stop = itStop.next();
+ for (QtGradientStop *stop : qAsConst(d_ptr->m_stops)) {
if ((stop->position() >= x1 && stop->position() <= x2) ||
beginList.contains(stop) || endList.contains(stop))
d_ptr->m_model->selectStop(stop, true);
@@ -801,9 +787,8 @@ void QtGradientStopsWidget::paintEvent(QPaintEvent *e)
if (h > 0) {
QLinearGradient lg(0, 0, w, 0);
QMap<qreal, QtGradientStop *> stops = model->stops();
- QMapIterator<qreal, QtGradientStop *> itStop(stops);
- while (itStop.hasNext()) {
- QtGradientStop *stop = itStop.next().value();
+ for (auto itStop = stops.cbegin(), send = stops.cend(); itStop != send; ++itStop) {
+ QtGradientStop *stop = itStop.value();
double pos = stop->position();
if (pos >= begin && pos <= end) {
double gradPos = (pos - begin) / width;
@@ -842,10 +827,8 @@ void QtGradientStopsWidget::paintEvent(QPaintEvent *e)
QPen pen;
p.setRenderHint(QPainter::Antialiasing);
- QListIterator<QtGradientStop *> itStop(d_ptr->m_stops);
- itStop.toBack();
- while (itStop.hasPrevious()) {
- QtGradientStop *stop = itStop.previous();
+ for (auto rit = d_ptr->m_stops.crbegin(), rend = d_ptr->m_stops.crend(); rit != rend; ++rit) {
+ QtGradientStop *stop = *rit;
double x = stop->position();
if (x >= begin - handleWidth / 2 && x <= end + handleWidth / 2) {
double viewX = x * w * (d_ptr->m_scaleFactor + max) / d_ptr->m_scaleFactor - viewBegin;
diff --git a/src/shared/qtgradienteditor/qtgradientutils.cpp b/src/shared/qtgradienteditor/qtgradientutils.cpp
index aa247b65d..6ae3999a8 100644
--- a/src/shared/qtgradienteditor/qtgradientutils.cpp
+++ b/src/shared/qtgradienteditor/qtgradientutils.cpp
@@ -146,10 +146,9 @@ static QDomElement saveGradient(QDomDocument &doc, const QGradient &gradient)
gradElem.setAttribute(QLatin1String("spread"), gradientSpreadToString(gradient.spread()));
gradElem.setAttribute(QLatin1String("coordinateMode"), gradientCoordinateModeToString(gradient.coordinateMode()));
- QGradientStops stops = gradient.stops();
- QVectorIterator<QGradientStop > it(stops);
- while (it.hasNext())
- gradElem.appendChild(saveGradientStop(doc, it.next()));
+ const QGradientStops stops = gradient.stops();
+ for (const QGradientStop &stop : stops)
+ gradElem.appendChild(saveGradientStop(doc, stop));
if (type == QGradient::LinearGradient) {
const QLinearGradient &g = *static_cast<const QLinearGradient *>(&gradient);
@@ -245,9 +244,7 @@ QString QtGradientUtils::saveState(const QtGradientManager *manager)
QDomElement rootElem = doc.createElement(QLatin1String("gradients"));
QMap<QString, QGradient> grads = manager->gradients();
- QMapIterator<QString, QGradient> itGrad(grads);
- while (itGrad.hasNext()) {
- itGrad.next();
+ for (auto itGrad = grads.cbegin(), end = grads.cend(); itGrad != end; ++itGrad) {
QDomElement idElem = doc.createElement(QLatin1String("gradient"));
idElem.setAttribute(QLatin1String("name"), itGrad.key());
QDomElement gradElem = saveGradient(doc, itGrad.value());
diff --git a/src/shared/qtgradienteditor/qtgradientview.cpp b/src/shared/qtgradienteditor/qtgradientview.cpp
index fa8515bd8..a0d4790e6 100644
--- a/src/shared/qtgradienteditor/qtgradientview.cpp
+++ b/src/shared/qtgradienteditor/qtgradientview.cpp
@@ -252,11 +252,8 @@ void QtGradientView::setGradientManager(QtGradientManager *manager)
return;
QMap<QString, QGradient> gradients = m_manager->gradients();
- QMapIterator<QString, QGradient> itGrad(gradients);
- while (itGrad.hasNext()) {
- itGrad.next();
+ for (auto itGrad = gradients.cbegin(), end = gradients.cend(); itGrad != end; ++itGrad)
slotGradientAdded(itGrad.key(), itGrad.value());
- }
connect(m_manager, SIGNAL(gradientAdded(QString,QGradient)),
this, SLOT(slotGradientAdded(QString,QGradient)));