aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/modelinglib
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2022-12-20 13:23:39 +0100
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2023-01-03 14:45:31 +0000
commitd2f1ac542f077ca3518a611f3246d5731d678231 (patch)
treee83a2f777a242cc5509136b2da57de5c18eadf89 /src/libs/modelinglib
parente1ae96647d60a262244fbfb8dd43485361d55e74 (diff)
modelinglib: Remove foreach usage part 2
Change-Id: Ia898cc019a0534a97d20a3dc48e69c6617773766 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/libs/modelinglib')
-rw-r--r--src/libs/modelinglib/qmt/config/configcontroller.cpp6
-rw-r--r--src/libs/modelinglib/qmt/controller/references.h2
-rw-r--r--src/libs/modelinglib/qmt/controller/selection.h2
-rw-r--r--src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.h2
-rw-r--r--src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp3
-rw-r--r--src/libs/modelinglib/qmt/infrastructure/geometryutilities.cpp33
-rw-r--r--src/libs/modelinglib/qmt/model/mobject.cpp4
-rw-r--r--src/libs/modelinglib/qmt/model_controller/mclonevisitor.cpp4
-rw-r--r--src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp35
-rw-r--r--src/libs/modelinglib/qmt/model_ui/stereotypescontroller.cpp10
-rw-r--r--src/libs/modelinglib/qmt/model_ui/treemodelmanager.cpp6
-rw-r--r--src/libs/modelinglib/qmt/model_widgets_ui/classmembersedit.cpp4
-rw-r--r--src/libs/modelinglib/qmt/model_widgets_ui/modeltreeview.cpp22
-rw-r--r--src/libs/modelinglib/qmt/stereotype/iconshape.cpp4
-rw-r--r--src/libs/modelinglib/qmt/stereotype/shapepaintvisitor.cpp6
-rw-r--r--src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp22
-rw-r--r--src/libs/modelinglib/qtserialization/inc/qark/qxmlinarchive.h7
17 files changed, 94 insertions, 78 deletions
diff --git a/src/libs/modelinglib/qmt/config/configcontroller.cpp b/src/libs/modelinglib/qmt/config/configcontroller.cpp
index 2f8ec8fcea..feb0d4e385 100644
--- a/src/libs/modelinglib/qmt/config/configcontroller.cpp
+++ b/src/libs/modelinglib/qmt/config/configcontroller.cpp
@@ -24,8 +24,8 @@ public:
};
ConfigController::ConfigController(QObject *parent)
- : QObject(parent),
- d(new ConfigControllerPrivate)
+ : QObject(parent)
+ , d(new ConfigControllerPrivate)
{
}
@@ -68,7 +68,7 @@ void ConfigController::readStereotypeDefinitions(const QString &path)
// TODO add error handling
return;
}
- foreach (const QString &fileName, fileNames) {
+ for (const QString &fileName : std::as_const(fileNames)) {
QFile file(QFileInfo(dir, fileName).absoluteFilePath());
if (file.open(QIODevice::ReadOnly)) {
QString text = QString::fromUtf8(file.readAll());
diff --git a/src/libs/modelinglib/qmt/controller/references.h b/src/libs/modelinglib/qmt/controller/references.h
index daf479fd89..4f43127590 100644
--- a/src/libs/modelinglib/qmt/controller/references.h
+++ b/src/libs/modelinglib/qmt/controller/references.h
@@ -18,7 +18,7 @@ public:
bool isEmpty() const { return m_elements.empty(); }
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 clear() { m_elements.clear(); }
void append(T *element) { m_elements.append(element); }
diff --git a/src/libs/modelinglib/qmt/controller/selection.h b/src/libs/modelinglib/qmt/controller/selection.h
index 16b88882c1..d14cb95bf8 100644
--- a/src/libs/modelinglib/qmt/controller/selection.h
+++ b/src/libs/modelinglib/qmt/controller/selection.h
@@ -36,7 +36,7 @@ public:
~Selection();
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 clear();
diff --git a/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.h b/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.h
index d2625abed9..dc4054ffde 100644
--- a/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.h
+++ b/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.h
@@ -65,7 +65,7 @@ public:
void setModelController(ModelController *modelController);
UndoController *undoController() const { return m_undoController; }
void setUndoController(UndoController *undoController);
- const QList<MDiagram *> allDiagrams() const { return m_allDiagrams; }
+ QList<MDiagram *> allDiagrams() const { return m_allDiagrams; }
private:
MDiagram *findDiagram(const Uid &diagramKey) const;
diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp
index 938901e028..bba7e23c37 100644
--- a/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp
+++ b/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp
@@ -707,7 +707,8 @@ void ObjectItem::updateRelationStarter()
const QList<Toolbar> toolbars = stereotypeController->findToolbars(elementType);
if (!toolbars.isEmpty()) {
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 =
stereotypeController->findCustomRelation(tool.m_elementType);
if (!customRelation.isNull())
diff --git a/src/libs/modelinglib/qmt/infrastructure/geometryutilities.cpp b/src/libs/modelinglib/qmt/infrastructure/geometryutilities.cpp
index 461897ee75..d00aaff555 100644
--- a/src/libs/modelinglib/qmt/infrastructure/geometryutilities.cpp
+++ b/src/libs/modelinglib/qmt/infrastructure/geometryutilities.cpp
@@ -121,21 +121,20 @@ bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line,
{
QMT_ASSERT(placement, return false);
- QList<Candidate> candidates;
- candidates << Candidate(QVector2D(rect.topRight() - rect.topLeft()), QPointF(0.0, 0.0), SideTop)
- << Candidate(QVector2D(rect.topLeft() - rect.topRight()), rect.topRight() - rect.topLeft(), SideTop)
- << Candidate(QVector2D(rect.bottomLeft() - rect.topLeft()), QPointF(0.0, 0.0), SideLeft)
- << Candidate(QVector2D(rect.topLeft() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideLeft)
- << Candidate(QVector2D(rect.bottomRight() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideBottom)
- << Candidate(QVector2D(rect.bottomLeft() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideBottom)
- << Candidate(QVector2D(rect.bottomRight() - rect.topRight()), rect.topRight() - rect.topLeft(), SideRight)
- << Candidate(QVector2D(rect.topRight() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideRight);
-
- QVector<QVector2D> rectEdgeVectors;
- rectEdgeVectors << QVector2D(rect.topLeft() - rect.topLeft())
- << QVector2D(rect.topRight() - rect.topLeft())
- << QVector2D(rect.bottomLeft() - rect.topLeft())
- << QVector2D(rect.bottomRight() -rect.topLeft());
+ const QList<Candidate> candidates{
+ {QVector2D(rect.topRight() - rect.topLeft()), QPointF(0.0, 0.0), SideTop},
+ {QVector2D(rect.topLeft() - rect.topRight()), rect.topRight() - rect.topLeft(), SideTop},
+ {QVector2D(rect.bottomLeft() - rect.topLeft()), QPointF(0.0, 0.0), SideLeft},
+ {QVector2D(rect.topLeft() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideLeft},
+ {QVector2D(rect.bottomRight() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideBottom},
+ {QVector2D(rect.bottomLeft() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideBottom},
+ {QVector2D(rect.bottomRight() - rect.topRight()), rect.topRight() - rect.topLeft(), SideRight},
+ {QVector2D(rect.topRight() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideRight}};
+
+ const QVector<QVector2D> rectEdgeVectors{{QVector2D(rect.topLeft() - rect.topLeft())},
+ {QVector2D(rect.topRight() - rect.topLeft())},
+ {QVector2D(rect.bottomLeft() - rect.topLeft())},
+ {QVector2D(rect.bottomRight() - rect.topLeft())}};
QVector2D directionVector(line.p2() - line.p1());
directionVector.normalize();
@@ -155,7 +154,7 @@ bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line,
Side side = SideUnspecified;
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
double r = directionVector.x() * intersectionVector.y() - directionVector.y() * intersectionVector.x();
if (r <= -1e-5 || r >= 1e-5) {
@@ -166,7 +165,7 @@ bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line,
bool ok = true;
int sign = 0;
QVector2D rectOriginVector = directionVector * a - QVector2D(candidate.second);
- foreach (const QVector2D &rectEdgeVector, rectEdgeVectors) {
+ for (const QVector2D &rectEdgeVector : rectEdgeVectors) {
QVector2D edgeVector = rectOriginVector + rectEdgeVector;
double aa = QVector2D::dotProduct(outsideVector, edgeVector);
if (aa < 0.0) {
diff --git a/src/libs/modelinglib/qmt/model/mobject.cpp b/src/libs/modelinglib/qmt/model/mobject.cpp
index 259120d3c7..dd68ac1915 100644
--- a/src/libs/modelinglib/qmt/model/mobject.cpp
+++ b/src/libs/modelinglib/qmt/model/mobject.cpp
@@ -47,7 +47,7 @@ void MObject::setName(const QString &name)
void MObject::setChildren(const Handles<MObject> &children)
{
m_children = children;
- foreach (const Handle<MObject> &handle, children) {
+ for (const Handle<MObject> &handle : children) {
if (handle.hasTarget())
handle.target()->setOwner(this);
}
@@ -116,7 +116,7 @@ void MObject::decontrolChild(MObject *child)
void MObject::setRelations(const Handles<MRelation> &relations)
{
m_relations = relations;
- foreach (const Handle<MRelation> &handle, relations) {
+ for (const Handle<MRelation> &handle : relations) {
if (handle.hasTarget())
handle.target()->setOwner(this);
}
diff --git a/src/libs/modelinglib/qmt/model_controller/mclonevisitor.cpp b/src/libs/modelinglib/qmt/model_controller/mclonevisitor.cpp
index 38d3450787..21e0de78e5 100644
--- a/src/libs/modelinglib/qmt/model_controller/mclonevisitor.cpp
+++ b/src/libs/modelinglib/qmt/model_controller/mclonevisitor.cpp
@@ -64,7 +64,7 @@ void MCloneVisitor::visitMDiagram(const MDiagram *diagram)
QMT_CHECK(m_cloned);
auto cloned = dynamic_cast<MDiagram *>(m_cloned);
QMT_ASSERT(cloned, return);
- foreach (const DElement *element, diagram->diagramElements()) {
+ for (const DElement *element : diagram->diagramElements()) {
DCloneDeepVisitor visitor;
element->accept(&visitor);
DElement *clonedElement = visitor.cloned();
@@ -187,7 +187,7 @@ void MCloneDeepVisitor::visitMDiagram(const MDiagram *diagram)
QMT_CHECK(m_cloned);
auto cloned = dynamic_cast<MDiagram *>(m_cloned);
QMT_ASSERT(cloned, return);
- foreach (const DElement *element, diagram->diagramElements()) {
+ for (const DElement *element : diagram->diagramElements()) {
DCloneDeepVisitor visitor;
element->accept(&visitor);
DElement *clonedElement = visitor.cloned();
diff --git a/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp b/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp
index 5c65094859..61a9d6e904 100644
--- a/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp
+++ b/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp
@@ -184,7 +184,7 @@ public:
~AddElementsCommand() override
{
- foreach (const Clone &clone, m_clonedElements)
+ for (const Clone &clone : std::as_const(m_clonedElements))
delete clone.m_clonedElement;
}
@@ -314,7 +314,7 @@ public:
~RemoveElementsCommand() override
{
- foreach (const Clone &clone, m_clonedElements)
+ for (const Clone &clone : std::as_const(m_clonedElements))
delete clone.m_clonedElement;
}
@@ -722,8 +722,8 @@ void ModelController::finishUpdateObject(MObject *object, bool cancelled)
if (!m_isResettingModel) {
emit endUpdateObject(row, parent);
if (!cancelled) {
- QList<MRelation *> relations = findRelationsOfObject(object);
- foreach (MRelation *relation, relations)
+ const QList<MRelation *> relations = findRelationsOfObject(object);
+ for (MRelation *relation : relations)
emit relationEndChanged(relation, object);
if (auto package = dynamic_cast<MPackage *>(object)) {
if (m_oldPackageName != package->name())
@@ -892,7 +892,8 @@ MContainer ModelController::copyElements(const MSelection &modelSelection)
{
MReferences simplifiedSelection = simplify(modelSelection);
MContainer copiedElements;
- foreach (MElement *element, simplifiedSelection.elements()) {
+ const QList<MElement *> elements = simplifiedSelection.elements();
+ for (MElement *element : elements) {
MCloneDeepVisitor visitor;
element->accept(&visitor);
MElement *clonedElement = visitor.cloned();
@@ -906,7 +907,8 @@ void ModelController::pasteElements(MObject *owner, const MReferences &modelCont
// clone all elements and renew their keys
QHash<Uid, Uid> renewedKeys;
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())) {
MCloneDeepVisitor visitor;
element->accept(&visitor);
@@ -917,13 +919,13 @@ void ModelController::pasteElements(MObject *owner, const MReferences &modelCont
}
}
// fix all keys referencing between pasting elements
- foreach (MElement *clonedElement, clonedElements)
+ for (MElement *clonedElement : std::as_const(clonedElements))
updateRelationKeys(clonedElement, renewedKeys);
if (m_undoController)
m_undoController->beginMergeSequence(tr("Paste"));
// insert all elements
bool added = false;
- foreach (MElement *clonedElement, clonedElements) {
+ for (MElement *clonedElement : std::as_const(clonedElements)) {
if (auto object = dynamic_cast<MObject *>(clonedElement)) {
MObject *objectOwner = owner;
if (!dynamic_cast<MPackage*>(owner))
@@ -974,7 +976,8 @@ void ModelController::deleteElements(const MSelection &modelSelection, const QSt
if (m_undoController)
m_undoController->beginMergeSequence(commandLabel);
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
if ((element = findElement(element->uid()))) {
if (auto object = dynamic_cast<MObject *>(element)) {
@@ -1018,7 +1021,8 @@ void ModelController::deleteElements(const MSelection &modelSelection, const QSt
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);
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
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());
QMT_ASSERT(element, return MReferences());
// 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();
while (owner) {
Uid ownerKey = owner->uid();
- foreach (const MSelection::Index &index, modelSelection.indices()) {
- if (index.elementKey() == ownerKey) {
+ for (const MSelection::Index &otherIndex : indices) {
+ if (otherIndex.elementKey() == ownerKey) {
ignore = true;
break;
}
@@ -1162,13 +1167,13 @@ void ModelController::verifyModelIntegrity() const
verifyModelIntegrity(m_rootPackage, &objectsMap, &relationsMap, &objectRelationsMap);
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(m_objectsMap.contains(object->uid()), return);
QMT_ASSERT(objectsMap.contains(object->uid()), 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(m_relationsMap.contains(relation->uid()), return);
QMT_ASSERT(relationsMap.contains(relation->uid()), return);
diff --git a/src/libs/modelinglib/qmt/model_ui/stereotypescontroller.cpp b/src/libs/modelinglib/qmt/model_ui/stereotypescontroller.cpp
index 68f20ece07..0ed1c06e06 100644
--- a/src/libs/modelinglib/qmt/model_ui/stereotypescontroller.cpp
+++ b/src/libs/modelinglib/qmt/model_ui/stereotypescontroller.cpp
@@ -14,8 +14,8 @@ StereotypesController::StereotypesController(QObject *parent) :
bool StereotypesController::isParsable(const QString &stereotypes)
{
- QStringList list = stereotypes.split(QLatin1Char(','));
- foreach (const QString &part, list) {
+ const QStringList list = stereotypes.split(QLatin1Char(','));
+ for (const QString &part : list) {
QString stereotype = part.trimmed();
if (stereotype.length() == 0)
return false;
@@ -27,7 +27,7 @@ QString StereotypesController::toString(const QList<QString> &stereotypes)
{
QString s;
bool first = true;
- foreach (const QString &stereotype, stereotypes) {
+ for (const QString &stereotype : stereotypes) {
if (!first)
s += ", ";
s += stereotype;
@@ -39,8 +39,8 @@ QString StereotypesController::toString(const QList<QString> &stereotypes)
QList<QString> StereotypesController::fromString(const QString &stereotypes)
{
QList<QString> result;
- QStringList list = stereotypes.split(QLatin1Char(','));
- foreach (const QString &part, list) {
+ const QStringList list = stereotypes.split(QLatin1Char(','));
+ for (const QString &part : list) {
QString stereotype = part.trimmed();
if (stereotype.length() > 0)
result.append(stereotype);
diff --git a/src/libs/modelinglib/qmt/model_ui/treemodelmanager.cpp b/src/libs/modelinglib/qmt/model_ui/treemodelmanager.cpp
index e88772d7f8..2a4b274d9c 100644
--- a/src/libs/modelinglib/qmt/model_ui/treemodelmanager.cpp
+++ b/src/libs/modelinglib/qmt/model_ui/treemodelmanager.cpp
@@ -36,7 +36,8 @@ void TreeModelManager::setModelTreeView(ModelTreeViewInterface *modelTreeView)
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));
if (object && !object->owner())
return true;
@@ -75,7 +76,8 @@ MPackage *TreeModelManager::selectedPackage() const
MSelection TreeModelManager::selectedObjects() const
{
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);
if (auto object = dynamic_cast<MObject *>(element))
modelSelection.append(object->uid(), m_treeModel->modelController()->ownerKey(object));
diff --git a/src/libs/modelinglib/qmt/model_widgets_ui/classmembersedit.cpp b/src/libs/modelinglib/qmt/model_widgets_ui/classmembersedit.cpp
index 88e9c69066..87262bf737 100644
--- a/src/libs/modelinglib/qmt/model_widgets_ui/classmembersedit.cpp
+++ b/src/libs/modelinglib/qmt/model_widgets_ui/classmembersedit.cpp
@@ -242,7 +242,7 @@ QString ClassMembersEdit::Cursor::preparse(const QString &text)
bool inCComment = false;
bool inCppComment = false;
int braces = 0;
- foreach (QChar c, text) {
+ for (QChar c : text) {
if (!inCComment && !inCppComment && lastChar == QLatin1Char('/') && c == QLatin1Char('/')) {
inCppComment = true;
lastChar = QLatin1Char(' ');
@@ -345,7 +345,7 @@ QString ClassMembersEdit::build(const QList<MClassMember> &members)
QString currentGroup;
QString text;
- foreach (const MClassMember &member, members) {
+ for (const MClassMember &member : members) {
bool addNewline = false;
bool addSpace = false;
if (member.visibility() != currentVisibility) {
diff --git a/src/libs/modelinglib/qmt/model_widgets_ui/modeltreeview.cpp b/src/libs/modelinglib/qmt/model_widgets_ui/modeltreeview.cpp
index 5f53304e8f..50bbb79938 100644
--- a/src/libs/modelinglib/qmt/model_widgets_ui/modeltreeview.cpp
+++ b/src/libs/modelinglib/qmt/model_widgets_ui/modeltreeview.cpp
@@ -51,7 +51,8 @@ QList<QModelIndex> ModelTreeView::selectedSourceModelIndexes() const
{
QList<QModelIndex> indexes;
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));
}
return indexes;
@@ -101,16 +102,15 @@ void ModelTreeView::startDrag(Qt::DropActions supportedActions)
indexes = selectedSourceModelIndexes();
else if (currentSourceModelIndex().isValid())
indexes.append(currentSourceModelIndex());
- if (!indexes.isEmpty()) {
- foreach (const QModelIndex &index, indexes) {
- MElement *element = treeModel->element(index);
- if (element) {
- dataStream << element->uid().toString();
- if (dragIcon.isNull()) {
- QIcon icon = treeModel->icon(index);
- if (!icon.isNull())
- dragIcon = icon;
- }
+
+ for (const QModelIndex &index : std::as_const(indexes)) {
+ MElement *element = treeModel->element(index);
+ if (element) {
+ dataStream << element->uid().toString();
+ if (dragIcon.isNull()) {
+ QIcon icon = treeModel->icon(index);
+ if (!icon.isNull())
+ dragIcon = icon;
}
}
}
diff --git a/src/libs/modelinglib/qmt/stereotype/iconshape.cpp b/src/libs/modelinglib/qmt/stereotype/iconshape.cpp
index dd397e112f..4260554722 100644
--- a/src/libs/modelinglib/qmt/stereotype/iconshape.cpp
+++ b/src/libs/modelinglib/qmt/stereotype/iconshape.cpp
@@ -15,7 +15,7 @@ template<class T>
QList<T *> cloneAll(const QList<T *> &rhs)
{
QList<T *> result;
- foreach (T *t, rhs)
+ for (T *t : rhs)
result.append(t ? t->clone() : nullptr);
return result;
}
@@ -157,7 +157,7 @@ void IconShape::closePath()
void IconShape::visitShapes(ShapeConstVisitor *visitor) const
{
- foreach (IShape *p, d->m_shapes)
+ for (IShape *p : d->m_shapes)
p->accept(visitor);
}
diff --git a/src/libs/modelinglib/qmt/stereotype/shapepaintvisitor.cpp b/src/libs/modelinglib/qmt/stereotype/shapepaintvisitor.cpp
index 2c8db71d93..0d30240f92 100644
--- a/src/libs/modelinglib/qmt/stereotype/shapepaintvisitor.cpp
+++ b/src/libs/modelinglib/qmt/stereotype/shapepaintvisitor.cpp
@@ -96,7 +96,8 @@ void ShapePaintVisitor::visitArc(const ArcShape *shapeArc)
void ShapePaintVisitor::visitPath(const PathShape *shapePath)
{
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) {
case PathShape::TypeNone:
// nothing to do
@@ -206,7 +207,8 @@ void ShapeSizeVisitor::visitArc(const ArcShape *shapeArc)
void ShapeSizeVisitor::visitPath(const PathShape *shapePath)
{
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) {
case PathShape::TypeNone:
// nothing to do
diff --git a/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp b/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp
index 91894ced2d..16d06a8653 100644
--- a/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp
+++ b/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp
@@ -163,7 +163,8 @@ void DiagramSceneController::deleteFromDiagram(const DSelection &dselection, MDi
if (!dselection.isEmpty()) {
MSelection mselection;
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);
QMT_ASSERT(delement, return);
if (delement->modelUid().isValid()) {
@@ -421,7 +422,8 @@ void DiagramSceneController::dropNewModelElement(MObject *modelObject, MPackage
void DiagramSceneController::addRelatedElements(const DSelection &selection, MDiagram *diagram)
{
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);
QMT_ASSERT(delement, return);
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,
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);
if (auto selectedObject = dynamic_cast<DObject *>(element)) {
if (selectedObject != object) {
@@ -774,7 +777,8 @@ void DiagramSceneController::alignSize(DObject *object, const DSelection &select
size.setHeight(minimumSize.height());
else
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);
if (auto selectedObject = dynamic_cast<DObject *>(element)) {
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 *> 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);
if (object)
list.append(object);
@@ -839,7 +844,7 @@ DObject *DiagramSceneController::addObject(MObject *modelObject, const QPointF &
alignOnRaster(diagramObject, diagram);
// 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) {
auto dobject = dynamic_cast<DObject *>(delement);
if (dobject) {
@@ -925,7 +930,7 @@ DRelation *DiagramSceneController::addRelation(MRelation *modelRelation, const Q
relationPoints.append(DRelation::IntermediatePoint(i2));
relationPoints.append(DRelation::IntermediatePoint(i3));
} else {
- foreach (const QPointF &intermediatePoint, intermediatePoints)
+ for (const QPointF &intermediatePoint : intermediatePoints)
relationPoints.append(DRelation::IntermediatePoint(intermediatePoint));
}
diagramRelation->setIntermediatePoints(relationPoints);
@@ -957,7 +962,8 @@ bool DiagramSceneController::relocateRelationEnd(DRelation *relation, DObject *t
if (currentTargetMObject == modelRelation->owner())
m_modelController->moveRelation(targetMObject, modelRelation);
// 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 (!m_diagramController->findDelegate(targetMObject, diagram)) {
m_diagramController->removeElement(diagramRelation, diagram);
diff --git a/src/libs/modelinglib/qtserialization/inc/qark/qxmlinarchive.h b/src/libs/modelinglib/qtserialization/inc/qark/qxmlinarchive.h
index 2b9cd118da..b3485904ea 100644
--- a/src/libs/modelinglib/qtserialization/inc/qark/qxmlinarchive.h
+++ b/src/libs/modelinglib/qtserialization/inc/qark/qxmlinarchive.h
@@ -834,9 +834,10 @@ QXmlInArchive::XmlTag QXmlInArchive::readTag()
while (!m_stream.atEnd()) {
switch (m_stream.readNext()) {
- case QXmlStreamReader::StartElement:
+ case QXmlStreamReader::StartElement: {
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")) {
bool ok = false;
int id = attribute.value().toString().toInt(&ok);
@@ -848,8 +849,8 @@ QXmlInArchive::XmlTag QXmlInArchive::readTag()
attribute.value().toString());
}
}
-
return xmlTag;
+ }
case QXmlStreamReader::EndElement:
xmlTag.m_tagName = m_stream.name().toString();
xmlTag.m_isEndTag = true;