Refactoring. Use C++11 range-based loop.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-04-02 20:38:56 +03:00
parent 4eaf556342
commit 3252130f36
18 changed files with 99 additions and 103 deletions

View File

@ -3207,18 +3207,18 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv)
}
}
for(int i=0; i < measurements.size(); ++i)
for(auto im : qAsConst(measurements))
{
m->AddEmpty(measurements.at(i).name, measurements.at(i).value);
m->AddEmpty(im.name, im.value);
if (not measurements.at(i).fullName.isEmpty())
if (not im.fullName.isEmpty())
{
m->SetMFullName(measurements.at(i).name, measurements.at(i).fullName);
m->SetMFullName(im.name, im.fullName);
}
if (not measurements.at(i).description.isEmpty())
if (not im.description.isEmpty())
{
m->SetMDescription(measurements.at(i).name, measurements.at(i).description);
m->SetMDescription(im.name, im.description);
}
}
@ -3317,21 +3317,21 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv)
}
}
for(int i=0; i < measurements.size(); ++i)
for(auto mm : qAsConst(measurements))
{
m->AddEmpty(measurements.at(i).name);
m->SetMBaseValue(measurements.at(i).name, measurements.at(i).base);
m->SetMSizeIncrease(measurements.at(i).name, measurements.at(i).sizeIncrease);
m->SetMHeightIncrease(measurements.at(i).name, measurements.at(i).heightIncrease);
m->AddEmpty(mm.name);
m->SetMBaseValue(mm.name, mm.base);
m->SetMSizeIncrease(mm.name, mm.sizeIncrease);
m->SetMHeightIncrease(mm.name, mm.heightIncrease);
if (not measurements.at(i).fullName.isEmpty())
if (not mm.fullName.isEmpty())
{
m->SetMFullName(measurements.at(i).name, measurements.at(i).fullName);
m->SetMFullName(mm.name, mm.fullName);
}
if (not measurements.at(i).description.isEmpty())
if (not mm.description.isEmpty())
{
m->SetMDescription(measurements.at(i).name, measurements.at(i).description);
m->SetMDescription(mm.name, mm.description);
}
}

View File

@ -585,15 +585,14 @@ bool DialogIncrements::IncrementUsed(const QString &name) const
{
const QVector<VFormulaField> expressions = doc->ListExpressions();
for(int i = 0; i < expressions.size(); ++i)
for(auto field : expressions)
{
if (expressions.at(i).expression.indexOf(name) != -1)
if (field.expression.indexOf(name) != -1)
{
// Eval formula
try
{
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i).expression, false,
false));
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(field.expression, false, false));
// Tokens (variables, measurements)
if (cal->GetTokens().values().contains(name))

View File

@ -746,9 +746,9 @@ void DialogLayoutSettings::InitPrinter()
QStringList printerNames;
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
const QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
for(int i = 0; i < printers.size(); ++i)
for(auto printer : printers)
{
const QString name = printers.at(i).printerName();
const QString name = printer.printerName();
if (not name.isEmpty())
{
printerNames.append(name);

View File

@ -44,11 +44,11 @@ QStringList PrepareKnowMaterials(const QStringList &patternMaterials, bool remem
if (rememberPM)
{
for(int i=0; i < patternMaterials.size(); ++i)
for(auto &patternMaterial : patternMaterials)
{
if (not patternMaterials.at(i).isEmpty() && not knownMaterials.contains(patternMaterials.at(i)))
if (not patternMaterial.isEmpty() && not knownMaterials.contains(patternMaterial))
{
knownMaterials.append(patternMaterials.at(i));
knownMaterials.append(patternMaterial);
}
}
}

View File

@ -292,26 +292,26 @@ QString NameRegExp()
QString decimalPoints;
QString groupSeparators;
for(int i = 0; i < allLocales.size(); ++i)
for(auto &locale : allLocales)
{
if (not positiveSigns.contains(allLocales.at(i).positiveSign()))
if (not positiveSigns.contains(locale.positiveSign()))
{
positiveSigns.append(allLocales.at(i).positiveSign());
positiveSigns.append(locale.positiveSign());
}
if (not negativeSigns.contains(allLocales.at(i).negativeSign()))
if (not negativeSigns.contains(locale.negativeSign()))
{
negativeSigns.append(allLocales.at(i).negativeSign());
negativeSigns.append(locale.negativeSign());
}
if (not decimalPoints.contains(allLocales.at(i).decimalPoint()))
if (not decimalPoints.contains(locale.decimalPoint()))
{
decimalPoints.append(allLocales.at(i).decimalPoint());
decimalPoints.append(locale.decimalPoint());
}
if (not groupSeparators.contains(allLocales.at(i).groupSeparator()))
if (not groupSeparators.contains(locale.groupSeparator()))
{
groupSeparators.append(allLocales.at(i).groupSeparator());
groupSeparators.append(locale.groupSeparator());
}
}

View File

@ -622,10 +622,8 @@ bool VDxfEngine::ExportToAAMA(const QVector<VLayoutPiece> &details)
ExportAAMAGlobalText(input, details);
for(int i = 0; i < details.size(); ++i)
for(auto &detail : details)
{
const VLayoutPiece &detail = details.at(i);
dx_ifaceBlock *detailBlock = new dx_ifaceBlock();
QString blockName = detail.GetName();
@ -736,11 +734,10 @@ void VDxfEngine::ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece
{
if (detail.IsSeamAllowance())
{
QVector<QLineF> passmarks = detail.GetPassmarks();
for(int i = 0; i < passmarks.size(); ++i)
const QVector<QLineF> passmarks = detail.GetPassmarks();
for(auto passmark : passmarks)
{
DRW_Entity *e = AAMALine(passmarks.at(i), "4");
if (e)
if (DRW_Entity *e = AAMALine(passmark, "4"))
{
detailBlock->ent.push_back(e);
}

View File

@ -83,9 +83,9 @@ VCubicBezierPath VCubicBezierPath::Rotate(const QPointF &originPoint, qreal degr
{
const QVector<VPointF> points = GetCubicPath();
VCubicBezierPath curve;
for(int i=0; i < points.size(); ++i)
for(auto &point : points)
{
curve.append(points.at(i).Rotate(originPoint, degrees));
curve.append(point.Rotate(originPoint, degrees));
}
curve.setName(name() + prefix);
curve.SetColor(GetColor());
@ -99,9 +99,9 @@ VCubicBezierPath VCubicBezierPath::Flip(const QLineF &axis, const QString &prefi
{
const QVector<VPointF> points = GetCubicPath();
VCubicBezierPath curve;
for(int i=0; i < points.size(); ++i)
for(auto &point : points)
{
curve.append(points.at(i).Flip(axis));
curve.append(point.Flip(axis));
}
curve.setName(name() + prefix);
curve.SetColor(GetColor());
@ -115,9 +115,9 @@ VCubicBezierPath VCubicBezierPath::Move(qreal length, qreal angle, const QString
{
const QVector<VPointF> points = GetCubicPath();
VCubicBezierPath curve;
for(int i=0; i < points.size(); ++i)
for(auto &point : points)
{
curve.append(points.at(i).Move(length, angle));
curve.append(point.Move(length, angle));
}
curve.setName(name() + prefix);
curve.SetColor(GetColor());

View File

@ -305,9 +305,9 @@ QVector<QPointF> CorrectPosition(const QRectF &parentBoundingRect, QVector<QPoin
QVector<VSAPoint> PrepareAllowance(const QVector<QPointF> &points)
{
QVector<VSAPoint> allowancePoints;
for(int i = 0; i < points.size(); ++i)
for(auto point : points)
{
allowancePoints.append(VSAPoint(points.at(i)));
allowancePoints.append(VSAPoint(point));
}
return allowancePoints;
}
@ -348,9 +348,10 @@ QStringList PieceLabelText(const QVector<QPointF> &labelShape, const VTextManage
QVector<VLayoutPlaceLabel> ConvertPlaceLabels(const VPiece &piece, const VContainer *pattern)
{
QVector<VLayoutPlaceLabel> labels;
for(int i=0; i < piece.GetPlaceLabels().size(); ++i)
const QVector<quint32> placeLabels = piece.GetPlaceLabels();
for(auto placeLabel : placeLabels)
{
const auto label = pattern->GeometricObject<VPlaceLabelItem>(piece.GetPlaceLabels().at(i));
const auto label = pattern->GeometricObject<VPlaceLabelItem>(placeLabel);
VLayoutPlaceLabel layoutLabel;
layoutLabel.shape = label->LabelShape();
layoutLabel.center = label->toQPointF();

View File

@ -591,11 +591,11 @@ void VContainer::ClearUniqueIncrementNames()
const QList<QString> list = uniqueNames.toList();
ClearUniqueNames();
for(int i = 0; i < list.size(); ++i)
for(auto &name : list)
{
if (not list.at(i).startsWith('#'))
if (not name.startsWith('#'))
{
uniqueNames.insert(list.at(i));
uniqueNames.insert(name);
}
}
}

View File

@ -448,11 +448,11 @@ QVector<QLineF> VPiece::PassmarksLines(const VContainer *data, const QVector<QPo
QVector<PlaceLabelImg> VPiece::PlaceLabelPoints(const VContainer *data) const
{
QVector<PlaceLabelImg> points;
for(int i=0; i < d->m_placeLabels.size(); ++i)
for(auto placeLabel : d->m_placeLabels)
{
try
{
const auto label = data->GeometricObject<VPlaceLabelItem>(d->m_placeLabels.at(i));
const auto label = data->GeometricObject<VPlaceLabelItem>(placeLabel);
points.append(label->LabelShape());
}
catch (const VExceptionBadId &e)

View File

@ -995,9 +995,9 @@ QVector<VSAPoint> VPiecePath::CurveSeamAllowanceSegment(const VContainer *data,
qreal w2 = end.GetSABefore();
if (w1 < 0 && w2 < 0)
{// no local widths
for(int i = 0; i < points.size(); ++i)
for(auto point : points)
{
VSAPoint p(points.at(i));
VSAPoint p(point);
if (i == 0)
{ // first point
p.SetSAAfter(begin.GetSAAfter());
@ -1036,9 +1036,9 @@ QVector<VSAPoint> VPiecePath::CurveSeamAllowanceSegment(const VContainer *data,
qreal length = 0; // how much we handle
for(int i = 1; i < points.size(); ++i)
for(auto point : points)
{
p = VSAPoint(points.at(i));
p = VSAPoint(point);
if (i == points.size() - 1)
{// last point

View File

@ -411,12 +411,12 @@ void VAbstractTool::ToolCreation(const Source &typeCreation)
//---------------------------------------------------------------------------------------------------------------------
VToolRecord VAbstractTool::GetRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
{
QVector<VToolRecord> *history = doc->getHistory();
for(int i = 0; i < history->size(); ++i)
const QVector<VToolRecord> *history = doc->getHistory();
for(auto &record : *history)
{
if (history->at(i).getId() == id && history->at(i).getTypeTool() == toolType)
if (record.getId() == id && record.getTypeTool() == toolType)
{
return history->at(i);
return record;
}
}
return VToolRecord();

View File

@ -1240,9 +1240,9 @@ void VToolSeamAllowance::keyReleaseEvent(QKeyEvent *event)
{
qApp->getUndoStack()->beginMacro(tr("multi deletion"));
for(int i=0; i < toolList.size(); ++i)
for(auto tool : toolList)
{
toolList.at(i)->RemoveWithConfirm(false);
tool->RemoveWithConfirm(false);
}
}
DeleteToolWithConfirm(false);
@ -1892,9 +1892,9 @@ QList<VToolSeamAllowance *> VToolSeamAllowance::SelectedTools() const
if (not list.isEmpty())
{
for(int i=0; i < list.size(); ++i)
for(auto item : list)
{
VToolSeamAllowance *tool = qgraphicsitem_cast<VToolSeamAllowance *>(list.at(i));
VToolSeamAllowance *tool = qgraphicsitem_cast<VToolSeamAllowance *>(item);
if (tool != nullptr && tool->getId() != m_id)
{
tools.append(tool);
@ -2011,9 +2011,8 @@ QVector<CustomSARecord> VToolSeamAllowance::DuplicateCustomSARecords(const QVect
const QMap<quint32, quint32> &replacements)
{
QVector<CustomSARecord> newRecords;
for(int i=0; i < records.size(); ++i)
for(auto record : records)
{
CustomSARecord record = records.at(i);
record.path = DuplicatePiecePath(record.path, initData);
record.startPoint = replacements.value(record.startPoint, NULL_ID);
record.endPoint = replacements.value(record.endPoint, NULL_ID);
@ -2027,9 +2026,9 @@ QVector<quint32> VToolSeamAllowance::DuplicateInternalPaths(const QVector<quint3
const VToolSeamAllowanceInitData &initData)
{
QVector<quint32> newPaths;
for(int i=0; i < iPaths.size(); ++i)
for(auto iPath : iPaths)
{
newPaths.append(DuplicatePiecePath(iPaths.at(i), initData));
newPaths.append(DuplicatePiecePath(iPath, initData));
}
return newPaths;
}
@ -2039,11 +2038,11 @@ QVector<quint32> VToolSeamAllowance::DuplicatePins(const QVector<quint32> &pins,
const VToolSeamAllowanceInitData &initData)
{
QVector<quint32> newPins;
for(int i=0; i < pins.size(); ++i)
for(auto p : pins)
{
QSharedPointer<VPointF> pin = initData.data->GeometricObject<VPointF>(pins.at(i));
QSharedPointer<VPointF> pin = initData.data->GeometricObject<VPointF>(p);
VAbstractNode *tool = qobject_cast<VAbstractNode *>(VAbstractPattern::getTool(pins.at(i)));
VAbstractNode *tool = qobject_cast<VAbstractNode *>(VAbstractPattern::getTool(p));
SCASSERT(tool != nullptr)
VToolPinInitData initNodeData;
@ -2068,10 +2067,10 @@ QVector<quint32> VToolSeamAllowance::DuplicatePlaceLabels(const QVector<quint32>
const VToolSeamAllowanceInitData &initData)
{
QVector<quint32> newPlaceLabels;
for(int i=0; i < placeLabels.size(); ++i)
for(auto placeLabel : placeLabels)
{
QSharedPointer<VPlaceLabelItem> label = initData.data->GeometricObject<VPlaceLabelItem>(placeLabels.at(i));
VAbstractNode *tool = qobject_cast<VAbstractNode *>(VAbstractPattern::getTool(placeLabels.at(i)));
QSharedPointer<VPlaceLabelItem> label = initData.data->GeometricObject<VPlaceLabelItem>(placeLabel);
VAbstractNode *tool = qobject_cast<VAbstractNode *>(VAbstractPattern::getTool(placeLabel));
SCASSERT(tool != nullptr)
VToolPlaceLabelInitData initNodeData;

View File

@ -1161,9 +1161,9 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32>
quint32 pRotate, qreal angle)
{
QVector<quint32> nodeChildren;
for(int i=0; i < d.GetCustomSARecords().size(); ++i)
const QVector<CustomSARecord> records = d.GetCustomSARecords();
for(auto record : records)
{
CustomSARecord record = d.GetCustomSARecords().at(i);
const VPiecePath path = initData.data->GetPiecePath(record.path);
VPiecePath newPath = path;
newPath.Clear();//Clear nodes
@ -1220,9 +1220,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector
qreal dy, quint32 pRotate, qreal angle)
{
QVector<quint32> nodeChildren;
for(int i=0; i < d.GetInternalPaths().size(); ++i)
const QVector<quint32> internalPaths = d.GetInternalPaths();
for(auto iPath : internalPaths)
{
const VPiecePath path = initData.data->GetPiecePath(d.GetInternalPaths().at(i));
const VPiecePath path = initData.data->GetPiecePath(iPath);
VPiecePath newPath = path;
newPath.Clear();//Clear nodes
@ -1280,9 +1281,10 @@ void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector<quint32>
quint32 pRotate, qreal angle)
{
QVector<quint32> nodeChildren;
for(int i=0; i < d.GetPins().size(); ++i)
const QVector<quint32> pins = d.GetPins();
for(auto pin : pins)
{
const quint32 id = AddPin(d.GetPins().at(i), initData, children, drawName, dx, dy, pRotate, angle);
const quint32 id = AddPin(pin, initData, children, drawName, dx, dy, pRotate, angle);
newDetail.GetPins().append(id);
}
children += nodeChildren;
@ -1294,10 +1296,10 @@ void CreateUnitedDetailPlaceLabels(VPiece &newDetail, const VPiece &d, QVector<q
qreal dy, quint32 pRotate, qreal angle)
{
QVector<quint32> nodeChildren;
for(int i=0; i < d.GetPlaceLabels().size(); ++i)
const QVector<quint32> placeLabels = d.GetPlaceLabels();
for(auto placeLabel : placeLabels)
{
const quint32 id = AddPlaceLabel(d.GetPlaceLabels().at(i), initData, children, drawName, dx, dy, pRotate,
angle);
const quint32 id = AddPlaceLabel(placeLabel, initData, children, drawName, dx, dy, pRotate, angle);
newDetail.GetPlaceLabels().append(id);
}
children += nodeChildren;
@ -1645,9 +1647,9 @@ void VToolUnionDetails::incrementReferens()
if (_referens == 1)
{
const QVector<quint32> objects = GetReferenceObjects();
for(int i = 0; i < objects.size(); ++i)
for(auto object : objects)
{
doc->IncrementReferens(objects.at(i));
doc->IncrementReferens(object);
}
QDomElement domElement = doc->elementById(m_id, getTagName());
@ -1665,9 +1667,9 @@ void VToolUnionDetails::decrementReferens()
if (_referens == 0)
{
const QVector<quint32> objects = GetReferenceObjects();
for(int i = 0; i < objects.size(); ++i)
for(auto object : objects)
{
doc->DecrementReferens(objects.at(i));
doc->DecrementReferens(object);
}
QDomElement domElement = doc->elementById(m_id, getTagName());

View File

@ -49,14 +49,14 @@ void TST_NameRegExp::TestNameRegExp_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(int i = 0; i < allLocales.size(); ++i)
for(auto &locale : allLocales)
{
INIT_LOCALE_VARIABLES(allLocales.at(i));
INIT_LOCALE_VARIABLES(locale);
Q_UNUSED(positiveSign)
Q_UNUSED(expUpper)
Q_UNUSED(expLower)
const QString localeName = allLocales.at(i).name();
const QString localeName = locale.name();
QString tag = localeName+QLatin1String(". First character can't be ")+sign0;
QTest::newRow(qUtf8Printable(tag)) << sign0+QLatin1String("a") << false;

View File

@ -84,9 +84,8 @@ void TST_QmuTokenParser::TokenFromUser_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(int i = 0; i < allLocales.size(); ++i)
for(auto &locale : allLocales)
{
const QLocale locale = allLocales.at(i);
PrepareVal(1000.5, locale);
PrepareVal(-1000.5, locale);
}

View File

@ -50,9 +50,8 @@ void TST_ReadVal::TestReadVal_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(int i = 0; i < allLocales.size(); ++i)
for(auto &locale : allLocales)
{
const QLocale locale = allLocales.at(i);
PrepareVal(1., locale);
PrepareVal(1.0, locale);
PrepareVal(-1.0, locale);

View File

@ -58,10 +58,10 @@ void TST_VTranslateVars::TestFormulaFromUser_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(int i = 0; i < allLocales.size(); ++i)
for(auto &locale : allLocales)
{
PrepareValFromUser(1000.5, allLocales.at(i));
PrepareValFromUser(-1000.5, allLocales.at(i));
PrepareValFromUser(1000.5, locale);
PrepareValFromUser(-1000.5, locale);
}
}
@ -88,10 +88,10 @@ void TST_VTranslateVars::TestFormulaToUser_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(int i = 0; i < allLocales.size(); ++i)
for(auto &locale : allLocales)
{
PrepareValToUser(1000.5, allLocales.at(i));
PrepareValToUser(-1000.5, allLocales.at(i));
PrepareValToUser(1000.5, locale);
PrepareValToUser(-1000.5, locale);
}
}