diff --git a/kmplot/equationeditorwidget.cpp b/kmplot/equationeditorwidget.cpp --- a/kmplot/equationeditorwidget.cpp +++ b/kmplot/equationeditorwidget.cpp @@ -45,8 +45,8 @@ QFont buttonFont; buttonFont.setPointSizeF(font.pointSizeF() * 1.1); - QList buttons = findChildren(); - foreach (QToolButton* w, buttons) { + const QList buttons = findChildren(); + for (QToolButton* w : buttons) { KAcceleratorManager::setNoAccel(w); connect(w, &QToolButton::clicked, this, &EquationEditorWidget::characterButtonClicked); diff --git a/kmplot/equationhighlighter.cpp b/kmplot/equationhighlighter.cpp --- a/kmplot/equationhighlighter.cpp +++ b/kmplot/equationhighlighter.cpp @@ -69,15 +69,15 @@ QTextCharFormat other; - QStringList variables = m_parent->m_equation->variables(); - QStringList functions = XParser::self()->predefinedFunctions(true) + XParser::self()->userFunctions(); + const QStringList variables = m_parent->m_equation->variables(); + const QStringList functions = XParser::self()->predefinedFunctions(true) + XParser::self()->userFunctions(); for (int i = 0; i < text.length(); ++i) { QString remaining = text.right(text.length() - i); bool found = false; - foreach (const QString& var, variables) { + for (const QString& var : variables) { if (remaining.startsWith(var)) { setFormat(i, var.length(), variable); i += var.length() - 1; @@ -88,7 +88,7 @@ if (found) continue; - foreach (const QString& f, functions) { + for (const QString& f : functions) { if (remaining.startsWith(f)) { setFormat(i, f.length(), function); i += f.length() - 1; diff --git a/kmplot/function.cpp b/kmplot/function.cpp --- a/kmplot/function.cpp +++ b/kmplot/function.cpp @@ -386,12 +386,10 @@ int p1 = m_fstr.indexOf( '(' ); int p2 = m_fstr.indexOf( ')' ); - QStringList listSplit; - if ( (p1 != -1) && (p2 != -1) ) - listSplit = m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts ); + const QStringList listSplit = ( (p1 != -1) && (p2 != -1) ) ? m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts ) : QStringList(); // Variables shouldn't contain spaces! - foreach ( QString s, listSplit ) { //krazy:exclude=foreach + for ( QString s : listSplit ) { s = s.remove(' '); if ( !s.isEmpty() ) m_variables << s; @@ -619,7 +617,7 @@ Function::~Function() { - foreach ( Equation * e, eq ) + for ( Equation * e : qAsConst(eq) ) delete e; } @@ -831,7 +829,7 @@ for ( PMode p = Derivative0; p <= Integral; p = PMode(p+1) ) { - foreach ( Plot plot, list ) { //krazy:exclude=foreach + for ( Plot plot : qAsConst(list) ) { if ( !plotAppearance(p).visible ) continue; plot.plotMode = p; @@ -848,7 +846,7 @@ for ( int i = 0; i < eq[0]->differentialStates.size(); ++i ) { - foreach ( Plot plot, list ) { //krazy:exclude=foreach + for ( Plot plot : qAsConst(list) ) { plot.stateNumber = i; duplicated << plot; } @@ -860,7 +858,7 @@ if ( combinations & DifferentPMSignatures ) { int size = 0; - foreach ( Equation * equation, eq ) + for ( Equation * equation : qAsConst(eq) ) size += equation->pmCount(); unsigned max = unsigned( std::pow( 2.0, (double)size ) ); @@ -878,12 +876,12 @@ // Generate a plot for each signature in signatures QList< Plot > duplicated; - foreach ( const QVector &signature, signatures ) + for ( const QVector &signature : qAsConst(signatures) ) { int at = 0; QList< QVector > pmSignature; - foreach ( Equation * equation, eq ) + for ( Equation * equation : qAsConst(eq) ) { int pmCount = equation->pmCount(); QVector sig( pmCount ); @@ -894,7 +892,7 @@ pmSignature << sig; } - foreach ( Plot plot, list ) { //krazy:exclude=foreach + for ( Plot plot : qAsConst(list) ) { plot.pmSignature = pmSignature; duplicated << plot; } @@ -925,7 +923,7 @@ if ( m_dependencies.contains( function->id() ) ) return true; - foreach ( int functionId, m_dependencies ) + for ( int functionId : qAsConst(m_dependencies) ) { Function * f = XParser::self()->functionWithID( functionId ); diff --git a/kmplot/functioneditor.cpp b/kmplot/functioneditor.cpp --- a/kmplot/functioneditor.cpp +++ b/kmplot/functioneditor.cpp @@ -123,7 +123,7 @@ #define CONNECT_WIDGETS( name, signal ) \ { \ QList widgets = m_editor->findChildren(); \ - foreach ( name * w, widgets ) \ + for ( name * w : qAsConst(widgets) ) \ connect( w, SIGNAL(signal), this, SLOT(save()) ); \ } @@ -230,7 +230,7 @@ // Now, any IDs left in currentIDs are of functions that have been deleted - foreach ( FunctionListItem * item, currentFunctionItems ) + for ( FunctionListItem * item : qAsConst(currentFunctionItems) ) { if ( m_functionID == item->function() ) m_functionID = -1; @@ -726,7 +726,7 @@ if ( !f || !functionListItem ) return; - foreach ( Equation * eq, f->eq ) + for ( Equation * eq : qAsConst(f->eq) ) eq->differentialStates.resetToInitial(); //save all settings in the function now when we know no errors have appeared @@ -769,7 +769,7 @@ KmPlotIO io; - foreach ( QListWidgetItem * item, items ) + for ( QListWidgetItem * item : qAsConst(items) ) { int f = static_cast(item)->function(); diff --git a/kmplot/functiontools.cpp b/kmplot/functiontools.cpp --- a/kmplot/functiontools.cpp +++ b/kmplot/functiontools.cpp @@ -106,21 +106,21 @@ m_widget->list->clear(); m_equations.clear(); - foreach ( Function * function, XParser::self()->m_ufkt ) + for ( Function * function : qAsConst(XParser::self()->m_ufkt) ) { if ( function->type() != Function::Cartesian && function->type() != Function::Differential ) continue; QList plots = function->plots(); for ( int i = 0; i < function->eq.size(); ++i ) { - foreach ( const Plot &plot, plots ) + for ( const Plot &plot : qAsConst(plots) ) m_equations << EquationPair( plot, i ); } } - foreach ( const EquationPair &eq, m_equations ) + for ( const EquationPair &eq : qAsConst(m_equations) ) { Equation * equation = eq.first.function()->eq[ eq.second ]; QListWidgetItem * item = new QListWidgetItem( equation->fstr(), m_widget->list ); diff --git a/kmplot/initialconditionseditor.cpp b/kmplot/initialconditionseditor.cpp --- a/kmplot/initialconditionseditor.cpp +++ b/kmplot/initialconditionseditor.cpp @@ -320,14 +320,14 @@ void InitialConditionsEditor::remove() { - QModelIndexList selected = view->selectionModel()->selectedIndexes(); + const QModelIndexList selected = view->selectionModel()->selectedIndexes(); QMap< int, void * > sorted; - foreach ( const QModelIndex &index, selected ) + for ( const QModelIndex &index : selected ) sorted.insert( -index.row(), 0l ); - QList indexes = sorted.keys(); + const QList indexes = sorted.keys(); - foreach ( int row, indexes ) + for ( int row : indexes ) m_model->removeRows( -row, 1, QModelIndex() ); emit dataChanged(); diff --git a/kmplot/kgradientdialog.cpp b/kmplot/kgradientdialog.cpp --- a/kmplot/kgradientdialog.cpp +++ b/kmplot/kgradientdialog.cpp @@ -132,8 +132,8 @@ //BEGIN draw arrows painter.setRenderHint( QPainter::Antialiasing, true ); - QGradientStops stops = m_gradient.stops(); - foreach ( const QGradientStop &stop, stops ) + const QGradientStops stops = m_gradient.stops(); + for ( const QGradientStop &stop : stops ) drawArrow( & painter, stop ); //END draw arrows } diff --git a/kmplot/kmplot.cpp b/kmplot/kmplot.cpp --- a/kmplot/kmplot.cpp +++ b/kmplot/kmplot.cpp @@ -106,8 +106,9 @@ setAutoSaveSettings(); { bool exit = false; - bool first = true; - foreach(const QString& arg, parser.positionalArguments()) + bool first = true; + const auto arguments = parser.positionalArguments(); + for (const QString& arg : arguments) { QUrl url = urlFromArg(arg); if (first) diff --git a/kmplot/kmplotio.cpp b/kmplot/kmplotio.cpp --- a/kmplot/kmplotio.cpp +++ b/kmplot/kmplotio.cpp @@ -111,7 +111,7 @@ root.appendChild( tag ); - foreach ( Function *f, XParser::self()->m_ufkt ) + for ( Function *f : qAsConst(XParser::self()->m_ufkt) ) addFunction( doc, root, f ); addConstants( doc, root ); @@ -214,7 +214,7 @@ tag.setAttribute( "use-parameter-list", function->m_parameters.useList ); QStringList str_parameters; - foreach ( const Value &k, function->m_parameters.list ) + for ( const Value &k : qAsConst(function->m_parameters.list) ) str_parameters << k.expression(); if( !str_parameters.isEmpty() ) @@ -241,7 +241,7 @@ bool first = true; QString ys; - foreach ( const Value &y, state->y0 ) + for ( const Value &y : qAsConst(state->y0) ) { if ( !first ) ys += ';'; @@ -609,7 +609,7 @@ QDomElement e = node.toElement(); QString x = e.attribute( "x" ); - QStringList y = e.attribute( "y" ).split( ';' ); + const QStringList y = e.attribute( "y" ).split( ';' ); DifferentialState * state = equation->differentialStates.add(); if ( state->y0.size() != y.size() ) @@ -621,7 +621,7 @@ state->x0.updateExpression( x ); int at = 0; - foreach ( const QString &f, y ) + for ( const QString &f : y ) state->y0[at++] = f; } node = node.nextSibling(); @@ -834,19 +834,19 @@ QString KmPlotIO::gradientToString( const QGradientStops & stops ) { QString string; - foreach ( const QGradientStop &stop, stops ) + for ( const QGradientStop &stop : qAsConst(stops) ) string += QString( "%1;%2," ).arg( stop.first ).arg( stop.second.name() ); return string; } // static QGradientStops KmPlotIO::stringToGradient( const QString & string ) { - QStringList stopStrings = string.split( ',', QString::SkipEmptyParts ); + const QStringList stopStrings = string.split( ',', QString::SkipEmptyParts ); QGradientStops stops; - foreach ( const QString &stopString, stopStrings ) + for ( const QString &stopString : stopStrings ) { QString pos = stopString.section( ';', 0, 0 ); QString color = stopString.section( ';', 1, 1 ); diff --git a/kmplot/kparametereditor.cpp b/kmplot/kparametereditor.cpp --- a/kmplot/kparametereditor.cpp +++ b/kmplot/kparametereditor.cpp @@ -79,7 +79,7 @@ connect(m_mainWidget->value, &EquationEdit::upPressed, this, &KParameterEditor::prev); connect(m_mainWidget->value, &EquationEdit::downPressed, this, &KParameterEditor::next); - foreach ( const Value &v, *m_parameter ) + for ( const Value &v : qAsConst(*m_parameter) ) m_mainWidget->list->addItem( v.expression() ); connect(m_mainWidget->cmdNew, &QPushButton::clicked, this, &KParameterEditor::cmdNew_clicked); diff --git a/kmplot/maindlg.cpp b/kmplot/maindlg.cpp --- a/kmplot/maindlg.cpp +++ b/kmplot/maindlg.cpp @@ -555,7 +555,7 @@ { QString filters; QMimeDatabase mimeDatabase; - foreach (const QByteArray &mimeType, QImageWriter::supportedMimeTypes()) { + for (const QByteArray &mimeType : QImageWriter::supportedMimeTypes()) { const QString filter = mimeDatabase.mimeTypeForName(QLatin1String(mimeType)).filterString(); if (!filter.isEmpty()) { if (mimeType == QByteArrayLiteral("image/png")) { diff --git a/kmplot/parameterswidget.cpp b/kmplot/parameterswidget.cpp --- a/kmplot/parameterswidget.cpp +++ b/kmplot/parameterswidget.cpp @@ -84,7 +84,7 @@ return; } - foreach ( EquationEdit * edit, m_equationEdits ) + for ( EquationEdit * edit : qAsConst(m_equationEdits) ) { if ( edit->equation()->usesParameter() || !edit->equation()->looksLikeFunction() ) continue; diff --git a/kmplot/parser.cpp b/kmplot/parser.cpp --- a/kmplot/parser.cpp +++ b/kmplot/parser.cpp @@ -162,7 +162,7 @@ Parser::~Parser() { - foreach ( Function * function, m_ufkt ) + for ( Function * function : qAsConst(m_ufkt) ) delete function; delete m_ownEquation; delete m_constants; @@ -192,9 +192,9 @@ { QStringList names; - foreach ( Function * f, m_ufkt ) + for ( Function * f : qAsConst(m_ufkt) ) { - foreach ( Equation * eq, f->eq ) + for ( Equation * eq : qAsConst(f->eq) ) { if ( !eq->name().isEmpty() ) names << eq->name(); @@ -208,9 +208,9 @@ void Parser::reparseAllFunctions() { - foreach ( Function * f, m_ufkt ) + for ( Function * f : m_ufkt ) { - foreach ( Equation * eq, f->eq ) + for ( Equation * eq : f->eq ) initEquation( eq ); } } @@ -669,12 +669,12 @@ while ( ! newFunctions.isEmpty() ) { - QList currentFunctions = newFunctions; + const QList currentFunctions = newFunctions; newFunctions.clear(); - foreach ( Function *f, currentFunctions ) + for ( Function *f : currentFunctions ) { - foreach ( Function *other, m_ufkt ) + for ( Function *other : qAsConst(m_ufkt) ) { if ( (other==f) || toRemove.contains(other) ) continue; @@ -700,7 +700,7 @@ return false; } - foreach ( Function *f, toRemove ) + for ( Function *f : qAsConst(toRemove) ) { uint id = f->id(); m_ufkt.remove( id ); @@ -988,16 +988,16 @@ bool Parser::tryVariable() { - QStringList variables = m_currentEquation->variables(); + const QStringList variables = m_currentEquation->variables(); // Sort the parameters by size, so that when identifying parameters, want to // match e.g. "ab" before "a" typedef QMultiMap ISMap; ISMap sorted; - foreach ( const QString &var, variables ) + for ( const QString &var : variables ) sorted.insert( -var.length(), var ); - foreach ( const QString &var, sorted ) + for ( const QString &var : qAsConst(sorted) ) { if ( match( var ) ) { @@ -1013,7 +1013,7 @@ bool Parser::tryUserFunction() { - foreach ( Function * it, m_ufkt ) + for ( Function * it : qAsConst(m_ufkt) ) { for ( int i = 0; i < it->eq.size(); ++i ) { @@ -1198,9 +1198,9 @@ int Parser::fnameToID(const QString &name) { - foreach ( Function * it, m_ufkt ) + for ( Function * it : qAsConst(m_ufkt) ) { - foreach ( Equation * eq, it->eq ) + for ( Equation * eq : qAsConst(it->eq) ) { if ( eq->looksLikeFunction() && (name == eq->name()) ) return it->id(); @@ -1589,18 +1589,18 @@ //BEGIN build up strings QMap< LengthOrderedString, StringType > strings; - QStringList predefinedFunctions = XParser::self()->predefinedFunctions( true ); - foreach ( const QString &f, predefinedFunctions ) + const QStringList predefinedFunctions = XParser::self()->predefinedFunctions( true ); + for ( const QString &f : predefinedFunctions ) strings[f] = FunctionString; - foreach ( Function * it, m_parser->m_ufkt ) + for ( Function * it : qAsConst(m_parser->m_ufkt) ) { - foreach ( Equation * eq, it->eq ) + for ( Equation * eq : qAsConst(it->eq) ) strings[eq->name()] = FunctionString; } - QStringList constantNames = m_parser->constants()->names(); - foreach ( const QString &name, constantNames ) + const QStringList constantNames = m_parser->constants()->names(); + for ( const QString &name : constantNames ) strings[name] = ConstantString; strings[QStringLiteral("pi")] = ConstantString; //END build up strings diff --git a/kmplot/view.cpp b/kmplot/view.cpp --- a/kmplot/view.cpp +++ b/kmplot/view.cpp @@ -402,7 +402,7 @@ painter.setRenderHint( QPainter::Antialiasing, m_zoomMode != Translating ); double at = -1; - foreach ( Function * function, XParser::self()->m_ufkt ) + for ( Function * function : qAsConst(XParser::self()->m_ufkt) ) { at += 1; @@ -1261,7 +1261,7 @@ assert( circular.function() ); const QList< Plot > plots = function->plots(); - foreach ( const Plot &plot, plots ) + for ( const Plot &plot : plots ) { bool setAliased = false; if ( plot.parameter.type() == Parameter::Animated ) @@ -1286,7 +1286,7 @@ function->m_implicitMode = Function::FixedY; QList roots = findRoots( plot, m_xmin, m_xmax, RoughRoot ); - foreach ( double x, roots ) + for ( double x : qAsConst(roots) ) { #ifdef DEBUG_IMPLICIT painter->setPen( QPen( Qt::red, painter->pen().width() ) ); @@ -1302,7 +1302,7 @@ function->m_implicitMode = Function::FixedX; roots = findRoots( plot, m_ymin, m_ymax, RoughRoot ); - foreach ( double y, roots ) + for ( double y : qAsConst(roots) ) { #ifdef DEBUG_IMPLICIT painter->setPen( QPen( Qt::blue, painter->pen().width() ) ); @@ -1315,11 +1315,11 @@ FuzzyPointMap singularSorted; FuzzyPoint::dx = (m_xmax-m_xmin) * SegmentMin * 0.1 / m_clipRect.width(); FuzzyPoint::dy = (m_ymax-m_ymin) * SegmentMin * 0.1 / m_clipRect.height(); - foreach ( const QPointF &point, singular ) + for ( const QPointF &point : qAsConst(singular) ) singularSorted.insert( point, point ); singular = singularSorted.values(); - foreach ( const QPointF &point, singular ) + for ( const QPointF &point : qAsConst(singular) ) { // radius of circle around singular point double epsilon = qMin( FuzzyPoint::dx, FuzzyPoint::dy ); @@ -1345,7 +1345,7 @@ qDebug() << "Found " << roots.size() << " roots.\n"; #endif - foreach ( double t, roots ) + for ( double t : qAsConst(roots) ) { #ifdef DEBUG_IMPLICIT painter->setPen( QPen( Qt::green, painter->pen().width() ) ); @@ -1655,13 +1655,13 @@ (function->eq[0]->order() == 1) && function->plotAppearance( Function::Derivative0 ).showTangentField ) { - QList plots = function->plots( Function::PlotCombinations(Function::AllCombinations) & ~Function::DifferentInitialStates ); - foreach ( const Plot &plot, plots ) + const QList plots = function->plots( Function::PlotCombinations(Function::AllCombinations) & ~Function::DifferentInitialStates ); + for ( const Plot &plot : plots ) drawTangentField( plot, painter ); } - QList plots = function->plots(); - foreach ( const Plot &plot, plots ) + const QList plots = function->plots(); + for ( const Plot &plot : plots ) drawPlot( plot, painter ); } @@ -2028,20 +2028,20 @@ // Used for determining where to draw the next label indicating the plot name int plotNameAt = 0; - foreach ( Function * function, XParser::self()->m_ufkt ) + for ( Function * function : qAsConst(XParser::self()->m_ufkt) ) { if ( m_stopCalculating ) break; - foreach ( const Plot &plot, function->plots() ) + for ( const Plot &plot : function->plots() ) { plot.updateFunction(); // Draw extrema points? if ( (function->type() == Function::Cartesian) && function->plotAppearance( plot.plotMode ).showExtrema ) { - QList stationaryPoints = findStationaryPoints( plot ); - foreach ( const QPointF &realValue, stationaryPoints ) + const QList stationaryPoints = findStationaryPoints( plot ); + for ( const QPointF &realValue : stationaryPoints ) { painter->setPen( QPen( Qt::black, millimetersToPixels( 1.5, painter->device() ) ) ); painter->drawPoint( toPixel( realValue ) ); @@ -2397,7 +2397,7 @@ text += "

" + i18n("Functions:") + "
    "; - foreach ( Function * function, XParser::self()->m_ufkt ) + for ( Function * function : qAsConst(XParser::self()->m_ufkt) ) text += "
  • " + function->name().replace( '\n', "
    " ) + "
  • "; text += "
"; @@ -2415,11 +2415,11 @@ Plot plot2 = plot; plot2.differentiate(); - QList< double > roots = findRoots( plot2, getXmin( plot.function() ), getXmax( plot.function() ), RoughRoot ); + const QList< double > roots = findRoots( plot2, getXmin( plot.function() ), getXmax( plot.function() ), RoughRoot ); plot.updateFunction(); QList< QPointF > stationaryPoints; - foreach ( double x, roots ) + for ( double x : roots ) { QPointF real = realValue( plot, x, false ); if ( real.y() >= m_ymin && real.y() <= m_ymax ) @@ -3090,10 +3090,10 @@ double best_distance = 1e30; // a nice large number QPointF best_cspos; - foreach ( Function * function, XParser::self()->m_ufkt ) + for ( Function * function : qAsConst(XParser::self()->m_ufkt) ) { const QList< Plot > plots = function->plots(); - foreach ( const Plot &plot, plots ) + for ( const Plot &plot : plots ) { plot.updateFunction(); @@ -3757,7 +3757,7 @@ double best = (type == Maximum) ? -HUGE_VAL : +HUGE_VAL; QPointF bestPoint; - foreach ( double root, roots ) + for ( double root : qAsConst(roots) ) { QPointF rv = realValue( plot, root, false ); if ( (type == Maximum && rv.y() > best) || (type == Minimum && rv.y() < best) ) @@ -3958,7 +3958,7 @@ void View::updateSliders() { bool needSliderWindow = false; - foreach ( Function * it, XParser::self()->m_ufkt ) + for ( Function * it : qAsConst(XParser::self()->m_ufkt) ) { if ( it->m_parameters.useSlider && !it->allPlotsAreHidden() ) { diff --git a/kmplot/xparser.cpp b/kmplot/xparser.cpp --- a/kmplot/xparser.cpp +++ b/kmplot/xparser.cpp @@ -211,14 +211,14 @@ bool ok = true; name[pos] = lastChar; - foreach ( Function * it, m_ufkt ) + for ( Function * it : qAsConst(m_ufkt) ) { if ( int(it->id()) == id ) continue; - foreach ( Equation * eq, it->eq ) + for ( Equation * eq : qAsConst(it->eq) ) { - foreach ( const QString& pattern, neededPatterns) { + for ( const QString& pattern : neededPatterns) { if ( eq->name() == pattern.arg(name) ) ok = false; } @@ -255,12 +255,12 @@ } QString const fname = str.left(p1); - foreach ( Function * it, m_ufkt ) + for ( Function * it : qAsConst(m_ufkt) ) { if ( int(it->id()) == id ) continue; - foreach ( Equation * eq, it->eq ) + for ( Equation * eq : qAsConst(it->eq) ) { if ( eq->name() != fname ) continue; @@ -648,7 +648,7 @@ return QStringList(); Function *item = m_ufkt[id]; QStringList str_parameter; - foreach ( const Value &it, item->m_parameters.list ) + for ( const Value &it : qAsConst(item->m_parameters.list) ) str_parameter << it.expression(); return str_parameter; } @@ -659,7 +659,7 @@ Function *tmp_ufkt = m_ufkt[id]; //check if the parameter already exists - foreach ( const Value &it, tmp_ufkt->m_parameters.list ) + for ( const Value &it : qAsConst(tmp_ufkt->m_parameters.list) ) { if ( it.expression() == new_parameter ) return false;