modelinglib: Remove foreach usage part 2

Change-Id: Ia898cc019a0534a97d20a3dc48e69c6617773766
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-12-20 13:23:39 +01:00
parent e1ae96647d
commit d2f1ac542f
17 changed files with 93 additions and 77 deletions

View File

@@ -24,8 +24,8 @@ public:
}; };
ConfigController::ConfigController(QObject *parent) ConfigController::ConfigController(QObject *parent)
: QObject(parent), : QObject(parent)
d(new ConfigControllerPrivate) , d(new ConfigControllerPrivate)
{ {
} }
@@ -68,7 +68,7 @@ void ConfigController::readStereotypeDefinitions(const QString &path)
// TODO add error handling // TODO add error handling
return; return;
} }
foreach (const QString &fileName, fileNames) { for (const QString &fileName : std::as_const(fileNames)) {
QFile file(QFileInfo(dir, fileName).absoluteFilePath()); QFile file(QFileInfo(dir, fileName).absoluteFilePath());
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
QString text = QString::fromUtf8(file.readAll()); QString text = QString::fromUtf8(file.readAll());

View File

@@ -18,7 +18,7 @@ public:
bool isEmpty() const { return m_elements.empty(); } bool isEmpty() const { return m_elements.empty(); }
int size() const { return m_elements.size(); } int size() const { return m_elements.size(); }
const QList<T *> elements() const { return m_elements; } QList<T *> elements() const { return m_elements; }
void setElements(const QList<T *> &elements) { m_elements = elements; } void setElements(const QList<T *> &elements) { m_elements = elements; }
void clear() { m_elements.clear(); } void clear() { m_elements.clear(); }
void append(T *element) { m_elements.append(element); } void append(T *element) { m_elements.append(element); }

View File

@@ -36,7 +36,7 @@ public:
~Selection(); ~Selection();
bool isEmpty() const { return m_indices.isEmpty(); } bool isEmpty() const { return m_indices.isEmpty(); }
const QList<Index> indices() const { return m_indices; } QList<Index> indices() const { return m_indices; }
void setIndices(const QList<Index> &indices); void setIndices(const QList<Index> &indices);
void clear(); void clear();

View File

@@ -65,7 +65,7 @@ public:
void setModelController(ModelController *modelController); void setModelController(ModelController *modelController);
UndoController *undoController() const { return m_undoController; } UndoController *undoController() const { return m_undoController; }
void setUndoController(UndoController *undoController); void setUndoController(UndoController *undoController);
const QList<MDiagram *> allDiagrams() const { return m_allDiagrams; } QList<MDiagram *> allDiagrams() const { return m_allDiagrams; }
private: private:
MDiagram *findDiagram(const Uid &diagramKey) const; MDiagram *findDiagram(const Uid &diagramKey) const;

View File

@@ -707,7 +707,8 @@ void ObjectItem::updateRelationStarter()
const QList<Toolbar> toolbars = stereotypeController->findToolbars(elementType); const QList<Toolbar> toolbars = stereotypeController->findToolbars(elementType);
if (!toolbars.isEmpty()) { if (!toolbars.isEmpty()) {
for (const Toolbar &toolbar : toolbars) { for (const Toolbar &toolbar : toolbars) {
for (const Toolbar::Tool &tool : toolbar.tools()) { const QList<Toolbar::Tool> tools = toolbar.tools();
for (const Toolbar::Tool &tool : tools) {
CustomRelation customRelation = CustomRelation customRelation =
stereotypeController->findCustomRelation(tool.m_elementType); stereotypeController->findCustomRelation(tool.m_elementType);
if (!customRelation.isNull()) if (!customRelation.isNull())

View File

@@ -121,21 +121,20 @@ bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line,
{ {
QMT_ASSERT(placement, return false); QMT_ASSERT(placement, return false);
QList<Candidate> candidates; const QList<Candidate> candidates{
candidates << Candidate(QVector2D(rect.topRight() - rect.topLeft()), QPointF(0.0, 0.0), SideTop) {QVector2D(rect.topRight() - rect.topLeft()), QPointF(0.0, 0.0), SideTop},
<< Candidate(QVector2D(rect.topLeft() - rect.topRight()), rect.topRight() - rect.topLeft(), SideTop) {QVector2D(rect.topLeft() - rect.topRight()), rect.topRight() - rect.topLeft(), SideTop},
<< Candidate(QVector2D(rect.bottomLeft() - rect.topLeft()), QPointF(0.0, 0.0), SideLeft) {QVector2D(rect.bottomLeft() - rect.topLeft()), QPointF(0.0, 0.0), SideLeft},
<< Candidate(QVector2D(rect.topLeft() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideLeft) {QVector2D(rect.topLeft() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideLeft},
<< Candidate(QVector2D(rect.bottomRight() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideBottom) {QVector2D(rect.bottomRight() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideBottom},
<< Candidate(QVector2D(rect.bottomLeft() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideBottom) {QVector2D(rect.bottomLeft() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideBottom},
<< Candidate(QVector2D(rect.bottomRight() - rect.topRight()), rect.topRight() - rect.topLeft(), SideRight) {QVector2D(rect.bottomRight() - rect.topRight()), rect.topRight() - rect.topLeft(), SideRight},
<< Candidate(QVector2D(rect.topRight() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideRight); {QVector2D(rect.topRight() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideRight}};
QVector<QVector2D> rectEdgeVectors; const QVector<QVector2D> rectEdgeVectors{{QVector2D(rect.topLeft() - rect.topLeft())},
rectEdgeVectors << QVector2D(rect.topLeft() - rect.topLeft()) {QVector2D(rect.topRight() - rect.topLeft())},
<< QVector2D(rect.topRight() - rect.topLeft()) {QVector2D(rect.bottomLeft() - rect.topLeft())},
<< QVector2D(rect.bottomLeft() - rect.topLeft()) {QVector2D(rect.bottomRight() - rect.topLeft())}};
<< QVector2D(rect.bottomRight() -rect.topLeft());
QVector2D directionVector(line.p2() - line.p1()); QVector2D directionVector(line.p2() - line.p1());
directionVector.normalize(); directionVector.normalize();
@@ -155,7 +154,7 @@ bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line,
Side side = SideUnspecified; Side side = SideUnspecified;
int bestSign = 0; int bestSign = 0;
foreach (const Candidate &candidate, candidates) { for (const Candidate &candidate : candidates) {
// solve equation a * directionVector + candidate.first = b * intersectionVector to find smallest a // solve equation a * directionVector + candidate.first = b * intersectionVector to find smallest a
double r = directionVector.x() * intersectionVector.y() - directionVector.y() * intersectionVector.x(); double r = directionVector.x() * intersectionVector.y() - directionVector.y() * intersectionVector.x();
if (r <= -1e-5 || r >= 1e-5) { if (r <= -1e-5 || r >= 1e-5) {
@@ -166,7 +165,7 @@ bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line,
bool ok = true; bool ok = true;
int sign = 0; int sign = 0;
QVector2D rectOriginVector = directionVector * a - QVector2D(candidate.second); QVector2D rectOriginVector = directionVector * a - QVector2D(candidate.second);
foreach (const QVector2D &rectEdgeVector, rectEdgeVectors) { for (const QVector2D &rectEdgeVector : rectEdgeVectors) {
QVector2D edgeVector = rectOriginVector + rectEdgeVector; QVector2D edgeVector = rectOriginVector + rectEdgeVector;
double aa = QVector2D::dotProduct(outsideVector, edgeVector); double aa = QVector2D::dotProduct(outsideVector, edgeVector);
if (aa < 0.0) { if (aa < 0.0) {

View File

@@ -47,7 +47,7 @@ void MObject::setName(const QString &name)
void MObject::setChildren(const Handles<MObject> &children) void MObject::setChildren(const Handles<MObject> &children)
{ {
m_children = children; m_children = children;
foreach (const Handle<MObject> &handle, children) { for (const Handle<MObject> &handle : children) {
if (handle.hasTarget()) if (handle.hasTarget())
handle.target()->setOwner(this); handle.target()->setOwner(this);
} }
@@ -116,7 +116,7 @@ void MObject::decontrolChild(MObject *child)
void MObject::setRelations(const Handles<MRelation> &relations) void MObject::setRelations(const Handles<MRelation> &relations)
{ {
m_relations = relations; m_relations = relations;
foreach (const Handle<MRelation> &handle, relations) { for (const Handle<MRelation> &handle : relations) {
if (handle.hasTarget()) if (handle.hasTarget())
handle.target()->setOwner(this); handle.target()->setOwner(this);
} }

View File

@@ -64,7 +64,7 @@ void MCloneVisitor::visitMDiagram(const MDiagram *diagram)
QMT_CHECK(m_cloned); QMT_CHECK(m_cloned);
auto cloned = dynamic_cast<MDiagram *>(m_cloned); auto cloned = dynamic_cast<MDiagram *>(m_cloned);
QMT_ASSERT(cloned, return); QMT_ASSERT(cloned, return);
foreach (const DElement *element, diagram->diagramElements()) { for (const DElement *element : diagram->diagramElements()) {
DCloneDeepVisitor visitor; DCloneDeepVisitor visitor;
element->accept(&visitor); element->accept(&visitor);
DElement *clonedElement = visitor.cloned(); DElement *clonedElement = visitor.cloned();
@@ -187,7 +187,7 @@ void MCloneDeepVisitor::visitMDiagram(const MDiagram *diagram)
QMT_CHECK(m_cloned); QMT_CHECK(m_cloned);
auto cloned = dynamic_cast<MDiagram *>(m_cloned); auto cloned = dynamic_cast<MDiagram *>(m_cloned);
QMT_ASSERT(cloned, return); QMT_ASSERT(cloned, return);
foreach (const DElement *element, diagram->diagramElements()) { for (const DElement *element : diagram->diagramElements()) {
DCloneDeepVisitor visitor; DCloneDeepVisitor visitor;
element->accept(&visitor); element->accept(&visitor);
DElement *clonedElement = visitor.cloned(); DElement *clonedElement = visitor.cloned();

View File

@@ -184,7 +184,7 @@ public:
~AddElementsCommand() override ~AddElementsCommand() override
{ {
foreach (const Clone &clone, m_clonedElements) for (const Clone &clone : std::as_const(m_clonedElements))
delete clone.m_clonedElement; delete clone.m_clonedElement;
} }
@@ -314,7 +314,7 @@ public:
~RemoveElementsCommand() override ~RemoveElementsCommand() override
{ {
foreach (const Clone &clone, m_clonedElements) for (const Clone &clone : std::as_const(m_clonedElements))
delete clone.m_clonedElement; delete clone.m_clonedElement;
} }
@@ -722,8 +722,8 @@ void ModelController::finishUpdateObject(MObject *object, bool cancelled)
if (!m_isResettingModel) { if (!m_isResettingModel) {
emit endUpdateObject(row, parent); emit endUpdateObject(row, parent);
if (!cancelled) { if (!cancelled) {
QList<MRelation *> relations = findRelationsOfObject(object); const QList<MRelation *> relations = findRelationsOfObject(object);
foreach (MRelation *relation, relations) for (MRelation *relation : relations)
emit relationEndChanged(relation, object); emit relationEndChanged(relation, object);
if (auto package = dynamic_cast<MPackage *>(object)) { if (auto package = dynamic_cast<MPackage *>(object)) {
if (m_oldPackageName != package->name()) if (m_oldPackageName != package->name())
@@ -892,7 +892,8 @@ MContainer ModelController::copyElements(const MSelection &modelSelection)
{ {
MReferences simplifiedSelection = simplify(modelSelection); MReferences simplifiedSelection = simplify(modelSelection);
MContainer copiedElements; MContainer copiedElements;
foreach (MElement *element, simplifiedSelection.elements()) { const QList<MElement *> elements = simplifiedSelection.elements();
for (MElement *element : elements) {
MCloneDeepVisitor visitor; MCloneDeepVisitor visitor;
element->accept(&visitor); element->accept(&visitor);
MElement *clonedElement = visitor.cloned(); MElement *clonedElement = visitor.cloned();
@@ -906,7 +907,8 @@ void ModelController::pasteElements(MObject *owner, const MReferences &modelCont
// clone all elements and renew their keys // clone all elements and renew their keys
QHash<Uid, Uid> renewedKeys; QHash<Uid, Uid> renewedKeys;
QList<MElement *> clonedElements; QList<MElement *> clonedElements;
foreach (MElement *element, modelContainer.elements()) { const QList<MElement *> elements = modelContainer.elements();
for (MElement *element : elements) {
if (option == PasteAlwaysWithNewKeys || option == PasteAlwaysAndKeepKeys || !findElement(element->uid())) { if (option == PasteAlwaysWithNewKeys || option == PasteAlwaysAndKeepKeys || !findElement(element->uid())) {
MCloneDeepVisitor visitor; MCloneDeepVisitor visitor;
element->accept(&visitor); element->accept(&visitor);
@@ -917,13 +919,13 @@ void ModelController::pasteElements(MObject *owner, const MReferences &modelCont
} }
} }
// fix all keys referencing between pasting elements // fix all keys referencing between pasting elements
foreach (MElement *clonedElement, clonedElements) for (MElement *clonedElement : std::as_const(clonedElements))
updateRelationKeys(clonedElement, renewedKeys); updateRelationKeys(clonedElement, renewedKeys);
if (m_undoController) if (m_undoController)
m_undoController->beginMergeSequence(tr("Paste")); m_undoController->beginMergeSequence(tr("Paste"));
// insert all elements // insert all elements
bool added = false; bool added = false;
foreach (MElement *clonedElement, clonedElements) { for (MElement *clonedElement : std::as_const(clonedElements)) {
if (auto object = dynamic_cast<MObject *>(clonedElement)) { if (auto object = dynamic_cast<MObject *>(clonedElement)) {
MObject *objectOwner = owner; MObject *objectOwner = owner;
if (!dynamic_cast<MPackage*>(owner)) if (!dynamic_cast<MPackage*>(owner))
@@ -974,7 +976,8 @@ void ModelController::deleteElements(const MSelection &modelSelection, const QSt
if (m_undoController) if (m_undoController)
m_undoController->beginMergeSequence(commandLabel); m_undoController->beginMergeSequence(commandLabel);
bool removed = false; bool removed = false;
foreach (MElement *element, simplifiedSelection.elements()) { const QList<MElement *> elements = simplifiedSelection.elements();
for (MElement *element : elements) {
// element may have been deleted indirectly by predecessor element in loop // element may have been deleted indirectly by predecessor element in loop
if ((element = findElement(element->uid()))) { if ((element = findElement(element->uid()))) {
if (auto object = dynamic_cast<MObject *>(element)) { if (auto object = dynamic_cast<MObject *>(element)) {
@@ -1018,7 +1021,8 @@ void ModelController::deleteElements(const MSelection &modelSelection, const QSt
void ModelController::removeRelatedRelations(MObject *object) void ModelController::removeRelatedRelations(MObject *object)
{ {
foreach (MRelation *relation, m_objectRelationsMap.values(object->uid())) const QList<MRelation *> relations = m_objectRelationsMap.values(object->uid());
for (MRelation *relation : relations)
removeRelation(relation); removeRelation(relation);
QMT_CHECK(m_objectRelationsMap.values(object->uid()).isEmpty()); QMT_CHECK(m_objectRelationsMap.values(object->uid()).isEmpty());
} }
@@ -1126,7 +1130,8 @@ MReferences ModelController::simplify(const MSelection &modelSelection)
{ {
// PERFORM improve performance by using a set of Uid build from modelSelection // PERFORM improve performance by using a set of Uid build from modelSelection
MReferences references; MReferences references;
foreach (const MSelection::Index &index, modelSelection.indices()) { const QList<MSelection::Index> indices = modelSelection.indices();
for (const MSelection::Index &index : indices) {
MElement *element = findElement(index.elementKey()); MElement *element = findElement(index.elementKey());
QMT_ASSERT(element, return MReferences()); QMT_ASSERT(element, return MReferences());
// if any (grand-)parent of element is in modelSelection then ignore element // if any (grand-)parent of element is in modelSelection then ignore element
@@ -1134,8 +1139,8 @@ MReferences ModelController::simplify(const MSelection &modelSelection)
MObject *owner = element->owner(); MObject *owner = element->owner();
while (owner) { while (owner) {
Uid ownerKey = owner->uid(); Uid ownerKey = owner->uid();
foreach (const MSelection::Index &index, modelSelection.indices()) { for (const MSelection::Index &otherIndex : indices) {
if (index.elementKey() == ownerKey) { if (otherIndex.elementKey() == ownerKey) {
ignore = true; ignore = true;
break; break;
} }
@@ -1162,13 +1167,13 @@ void ModelController::verifyModelIntegrity() const
verifyModelIntegrity(m_rootPackage, &objectsMap, &relationsMap, &objectRelationsMap); verifyModelIntegrity(m_rootPackage, &objectsMap, &relationsMap, &objectRelationsMap);
QMT_ASSERT(objectsMap.size() == m_objectsMap.size(), return); QMT_ASSERT(objectsMap.size() == m_objectsMap.size(), return);
foreach (const MObject *object, m_objectsMap) { for (const MObject *object : m_objectsMap) {
QMT_ASSERT(object, return); QMT_ASSERT(object, return);
QMT_ASSERT(m_objectsMap.contains(object->uid()), return); QMT_ASSERT(m_objectsMap.contains(object->uid()), return);
QMT_ASSERT(objectsMap.contains(object->uid()), return); QMT_ASSERT(objectsMap.contains(object->uid()), return);
} }
QMT_ASSERT(relationsMap.size() == m_relationsMap.size(), return); QMT_ASSERT(relationsMap.size() == m_relationsMap.size(), return);
foreach (const MRelation *relation, m_relationsMap) { for (const MRelation *relation : m_relationsMap) {
QMT_ASSERT(relation, return); QMT_ASSERT(relation, return);
QMT_ASSERT(m_relationsMap.contains(relation->uid()), return); QMT_ASSERT(m_relationsMap.contains(relation->uid()), return);
QMT_ASSERT(relationsMap.contains(relation->uid()), return); QMT_ASSERT(relationsMap.contains(relation->uid()), return);

View File

@@ -14,8 +14,8 @@ StereotypesController::StereotypesController(QObject *parent) :
bool StereotypesController::isParsable(const QString &stereotypes) bool StereotypesController::isParsable(const QString &stereotypes)
{ {
QStringList list = stereotypes.split(QLatin1Char(',')); const QStringList list = stereotypes.split(QLatin1Char(','));
foreach (const QString &part, list) { for (const QString &part : list) {
QString stereotype = part.trimmed(); QString stereotype = part.trimmed();
if (stereotype.length() == 0) if (stereotype.length() == 0)
return false; return false;
@@ -27,7 +27,7 @@ QString StereotypesController::toString(const QList<QString> &stereotypes)
{ {
QString s; QString s;
bool first = true; bool first = true;
foreach (const QString &stereotype, stereotypes) { for (const QString &stereotype : stereotypes) {
if (!first) if (!first)
s += ", "; s += ", ";
s += stereotype; s += stereotype;
@@ -39,8 +39,8 @@ QString StereotypesController::toString(const QList<QString> &stereotypes)
QList<QString> StereotypesController::fromString(const QString &stereotypes) QList<QString> StereotypesController::fromString(const QString &stereotypes)
{ {
QList<QString> result; QList<QString> result;
QStringList list = stereotypes.split(QLatin1Char(',')); const QStringList list = stereotypes.split(QLatin1Char(','));
foreach (const QString &part, list) { for (const QString &part : list) {
QString stereotype = part.trimmed(); QString stereotype = part.trimmed();
if (stereotype.length() > 0) if (stereotype.length() > 0)
result.append(stereotype); result.append(stereotype);

View File

@@ -36,7 +36,8 @@ void TreeModelManager::setModelTreeView(ModelTreeViewInterface *modelTreeView)
bool TreeModelManager::isRootPackageSelected() const bool TreeModelManager::isRootPackageSelected() const
{ {
foreach (const QModelIndex &index, m_modelTreeView->selectedSourceModelIndexes()) { const QList<QModelIndex> indices = m_modelTreeView->selectedSourceModelIndexes();
for (const QModelIndex &index : indices) {
auto object = dynamic_cast<MObject *>(m_treeModel->element(index)); auto object = dynamic_cast<MObject *>(m_treeModel->element(index));
if (object && !object->owner()) if (object && !object->owner())
return true; return true;
@@ -75,7 +76,8 @@ MPackage *TreeModelManager::selectedPackage() const
MSelection TreeModelManager::selectedObjects() const MSelection TreeModelManager::selectedObjects() const
{ {
MSelection modelSelection; MSelection modelSelection;
foreach (const QModelIndex &index, m_modelTreeView->selectedSourceModelIndexes()) { const QList<QModelIndex> indices = m_modelTreeView->selectedSourceModelIndexes();
for (const QModelIndex &index : indices) {
MElement *element = m_treeModel->element(index); MElement *element = m_treeModel->element(index);
if (auto object = dynamic_cast<MObject *>(element)) if (auto object = dynamic_cast<MObject *>(element))
modelSelection.append(object->uid(), m_treeModel->modelController()->ownerKey(object)); modelSelection.append(object->uid(), m_treeModel->modelController()->ownerKey(object));

View File

@@ -242,7 +242,7 @@ QString ClassMembersEdit::Cursor::preparse(const QString &text)
bool inCComment = false; bool inCComment = false;
bool inCppComment = false; bool inCppComment = false;
int braces = 0; int braces = 0;
foreach (QChar c, text) { for (QChar c : text) {
if (!inCComment && !inCppComment && lastChar == QLatin1Char('/') && c == QLatin1Char('/')) { if (!inCComment && !inCppComment && lastChar == QLatin1Char('/') && c == QLatin1Char('/')) {
inCppComment = true; inCppComment = true;
lastChar = QLatin1Char(' '); lastChar = QLatin1Char(' ');
@@ -345,7 +345,7 @@ QString ClassMembersEdit::build(const QList<MClassMember> &members)
QString currentGroup; QString currentGroup;
QString text; QString text;
foreach (const MClassMember &member, members) { for (const MClassMember &member : members) {
bool addNewline = false; bool addNewline = false;
bool addSpace = false; bool addSpace = false;
if (member.visibility() != currentVisibility) { if (member.visibility() != currentVisibility) {

View File

@@ -51,7 +51,8 @@ QList<QModelIndex> ModelTreeView::selectedSourceModelIndexes() const
{ {
QList<QModelIndex> indexes; QList<QModelIndex> indexes;
if (selectionModel()) { if (selectionModel()) {
foreach (const QModelIndex &index, selectionModel()->selection().indexes()) const QModelIndexList indexList = selectionModel()->selection().indexes();
for (const QModelIndex &index : indexList)
indexes.append(m_sortedTreeModel->mapToSource(index)); indexes.append(m_sortedTreeModel->mapToSource(index));
} }
return indexes; return indexes;
@@ -101,16 +102,15 @@ void ModelTreeView::startDrag(Qt::DropActions supportedActions)
indexes = selectedSourceModelIndexes(); indexes = selectedSourceModelIndexes();
else if (currentSourceModelIndex().isValid()) else if (currentSourceModelIndex().isValid())
indexes.append(currentSourceModelIndex()); indexes.append(currentSourceModelIndex());
if (!indexes.isEmpty()) {
foreach (const QModelIndex &index, indexes) { for (const QModelIndex &index : std::as_const(indexes)) {
MElement *element = treeModel->element(index); MElement *element = treeModel->element(index);
if (element) { if (element) {
dataStream << element->uid().toString(); dataStream << element->uid().toString();
if (dragIcon.isNull()) { if (dragIcon.isNull()) {
QIcon icon = treeModel->icon(index); QIcon icon = treeModel->icon(index);
if (!icon.isNull()) if (!icon.isNull())
dragIcon = icon; dragIcon = icon;
}
} }
} }
} }

View File

@@ -15,7 +15,7 @@ template<class T>
QList<T *> cloneAll(const QList<T *> &rhs) QList<T *> cloneAll(const QList<T *> &rhs)
{ {
QList<T *> result; QList<T *> result;
foreach (T *t, rhs) for (T *t : rhs)
result.append(t ? t->clone() : nullptr); result.append(t ? t->clone() : nullptr);
return result; return result;
} }
@@ -157,7 +157,7 @@ void IconShape::closePath()
void IconShape::visitShapes(ShapeConstVisitor *visitor) const void IconShape::visitShapes(ShapeConstVisitor *visitor) const
{ {
foreach (IShape *p, d->m_shapes) for (IShape *p : d->m_shapes)
p->accept(visitor); p->accept(visitor);
} }

View File

@@ -96,7 +96,8 @@ void ShapePaintVisitor::visitArc(const ArcShape *shapeArc)
void ShapePaintVisitor::visitPath(const PathShape *shapePath) void ShapePaintVisitor::visitPath(const PathShape *shapePath)
{ {
QPainterPath path; QPainterPath path;
foreach (const PathShape::Element &element, shapePath->elements()) { const QList<PathShape::Element> elements = shapePath->elements();
for (const PathShape::Element &element : elements) {
switch (element.m_elementType) { switch (element.m_elementType) {
case PathShape::TypeNone: case PathShape::TypeNone:
// nothing to do // nothing to do
@@ -206,7 +207,8 @@ void ShapeSizeVisitor::visitArc(const ArcShape *shapeArc)
void ShapeSizeVisitor::visitPath(const PathShape *shapePath) void ShapeSizeVisitor::visitPath(const PathShape *shapePath)
{ {
QPainterPath path; QPainterPath path;
foreach (const PathShape::Element &element, shapePath->elements()) { const QList<PathShape::Element> elements = shapePath->elements();
for (const PathShape::Element &element : elements) {
switch (element.m_elementType) { switch (element.m_elementType) {
case PathShape::TypeNone: case PathShape::TypeNone:
// nothing to do // nothing to do

View File

@@ -163,7 +163,8 @@ void DiagramSceneController::deleteFromDiagram(const DSelection &dselection, MDi
if (!dselection.isEmpty()) { if (!dselection.isEmpty()) {
MSelection mselection; MSelection mselection;
DSelection remainingDselection; DSelection remainingDselection;
foreach (const DSelection::Index &index, dselection.indices()) { const QList<DSelection::Index> indices = dselection.indices();
for (const DSelection::Index &index : indices) {
DElement *delement = m_diagramController->findElement(index.elementKey(), diagram); DElement *delement = m_diagramController->findElement(index.elementKey(), diagram);
QMT_ASSERT(delement, return); QMT_ASSERT(delement, return);
if (delement->modelUid().isValid()) { if (delement->modelUid().isValid()) {
@@ -421,7 +422,8 @@ void DiagramSceneController::dropNewModelElement(MObject *modelObject, MPackage
void DiagramSceneController::addRelatedElements(const DSelection &selection, MDiagram *diagram) void DiagramSceneController::addRelatedElements(const DSelection &selection, MDiagram *diagram)
{ {
m_diagramController->undoController()->beginMergeSequence(tr("Add Related Element")); m_diagramController->undoController()->beginMergeSequence(tr("Add Related Element"));
foreach (const DSelection::Index &index, selection.indices()) { const QList<DSelection::Index> indices = selection.indices();
for (const DSelection::Index &index : indices) {
DElement *delement = m_diagramController->findElement(index.elementKey(), diagram); DElement *delement = m_diagramController->findElement(index.elementKey(), diagram);
QMT_ASSERT(delement, return); QMT_ASSERT(delement, return);
DObject *dobject = dynamic_cast<DObject *>(delement); DObject *dobject = dynamic_cast<DObject *>(delement);
@@ -747,7 +749,8 @@ void DiagramSceneController::alignVBorderDistance(const DSelection &selection, M
void DiagramSceneController::alignPosition(DObject *object, const DSelection &selection, void DiagramSceneController::alignPosition(DObject *object, const DSelection &selection,
QPointF (*aligner)(DObject *, DObject *), MDiagram *diagram) QPointF (*aligner)(DObject *, DObject *), MDiagram *diagram)
{ {
foreach (const DSelection::Index &index, selection.indices()) { const QList<DSelection::Index> indices = selection.indices();
for (const DSelection::Index &index : indices) {
DElement *element = m_diagramController->findElement(index.elementKey(), diagram); DElement *element = m_diagramController->findElement(index.elementKey(), diagram);
if (auto selectedObject = dynamic_cast<DObject *>(element)) { if (auto selectedObject = dynamic_cast<DObject *>(element)) {
if (selectedObject != object) { if (selectedObject != object) {
@@ -774,7 +777,8 @@ void DiagramSceneController::alignSize(DObject *object, const DSelection &select
size.setHeight(minimumSize.height()); size.setHeight(minimumSize.height());
else else
size.setHeight(object->rect().height()); size.setHeight(object->rect().height());
foreach (const DSelection::Index &index, selection.indices()) { const QList<DSelection::Index> indices = selection.indices();
for (const DSelection::Index &index : indices) {
DElement *element = m_diagramController->findElement(index.elementKey(), diagram); DElement *element = m_diagramController->findElement(index.elementKey(), diagram);
if (auto selectedObject = dynamic_cast<DObject *>(element)) { if (auto selectedObject = dynamic_cast<DObject *>(element)) {
QRectF newRect = aligner(selectedObject, size); QRectF newRect = aligner(selectedObject, size);
@@ -800,7 +804,8 @@ void DiagramSceneController::alignOnRaster(DElement *element, MDiagram *diagram)
QList<DObject *> DiagramSceneController::collectObjects(const DSelection &selection, MDiagram *diagram) QList<DObject *> DiagramSceneController::collectObjects(const DSelection &selection, MDiagram *diagram)
{ {
QList<DObject *> list; QList<DObject *> list;
foreach (const DSelection::Index &index, selection.indices()) { const QList<DSelection::Index> indices = selection.indices();
for (const DSelection::Index &index : indices) {
DObject *object = m_diagramController->findElement<DObject>(index.elementKey(), diagram); DObject *object = m_diagramController->findElement<DObject>(index.elementKey(), diagram);
if (object) if (object)
list.append(object); list.append(object);
@@ -839,7 +844,7 @@ DObject *DiagramSceneController::addObject(MObject *modelObject, const QPointF &
alignOnRaster(diagramObject, diagram); alignOnRaster(diagramObject, diagram);
// add all relations between any other element on diagram and new element // add all relations between any other element on diagram and new element
foreach (DElement *delement, diagram->diagramElements()) { for (DElement *delement : diagram->diagramElements()) {
if (delement != diagramObject) { if (delement != diagramObject) {
auto dobject = dynamic_cast<DObject *>(delement); auto dobject = dynamic_cast<DObject *>(delement);
if (dobject) { if (dobject) {
@@ -925,7 +930,7 @@ DRelation *DiagramSceneController::addRelation(MRelation *modelRelation, const Q
relationPoints.append(DRelation::IntermediatePoint(i2)); relationPoints.append(DRelation::IntermediatePoint(i2));
relationPoints.append(DRelation::IntermediatePoint(i3)); relationPoints.append(DRelation::IntermediatePoint(i3));
} else { } else {
foreach (const QPointF &intermediatePoint, intermediatePoints) for (const QPointF &intermediatePoint : intermediatePoints)
relationPoints.append(DRelation::IntermediatePoint(intermediatePoint)); relationPoints.append(DRelation::IntermediatePoint(intermediatePoint));
} }
diagramRelation->setIntermediatePoints(relationPoints); diagramRelation->setIntermediatePoints(relationPoints);
@@ -957,7 +962,8 @@ bool DiagramSceneController::relocateRelationEnd(DRelation *relation, DObject *t
if (currentTargetMObject == modelRelation->owner()) if (currentTargetMObject == modelRelation->owner())
m_modelController->moveRelation(targetMObject, modelRelation); m_modelController->moveRelation(targetMObject, modelRelation);
// remove relation on all diagrams where the new targe element does not exist // remove relation on all diagrams where the new targe element does not exist
foreach (MDiagram *diagram, m_diagramController->allDiagrams()) { const QList<MDiagram *> diagrams = m_diagramController->allDiagrams();
for (MDiagram *diagram : diagrams) {
if (DElement *diagramRelation = m_diagramController->findDelegate(modelRelation, diagram)) { if (DElement *diagramRelation = m_diagramController->findDelegate(modelRelation, diagram)) {
if (!m_diagramController->findDelegate(targetMObject, diagram)) { if (!m_diagramController->findDelegate(targetMObject, diagram)) {
m_diagramController->removeElement(diagramRelation, diagram); m_diagramController->removeElement(diagramRelation, diagram);

View File

@@ -834,9 +834,10 @@ QXmlInArchive::XmlTag QXmlInArchive::readTag()
while (!m_stream.atEnd()) { while (!m_stream.atEnd()) {
switch (m_stream.readNext()) { switch (m_stream.readNext()) {
case QXmlStreamReader::StartElement: case QXmlStreamReader::StartElement: {
xmlTag.m_tagName = m_stream.name().toString(); xmlTag.m_tagName = m_stream.name().toString();
foreach (const QXmlStreamAttribute &attribute, m_stream.attributes()) { const QXmlStreamAttributes attrList = m_stream.attributes();
for (const QXmlStreamAttribute &attribute : attrList) {
if (attribute.name() == QLatin1String("id")) { if (attribute.name() == QLatin1String("id")) {
bool ok = false; bool ok = false;
int id = attribute.value().toString().toInt(&ok); int id = attribute.value().toString().toInt(&ok);
@@ -848,8 +849,8 @@ QXmlInArchive::XmlTag QXmlInArchive::readTag()
attribute.value().toString()); attribute.value().toString());
} }
} }
return xmlTag; return xmlTag;
}
case QXmlStreamReader::EndElement: case QXmlStreamReader::EndElement:
xmlTag.m_tagName = m_stream.name().toString(); xmlTag.m_tagName = m_stream.name().toString();
xmlTag.m_isEndTag = true; xmlTag.m_isEndTag = true;