QmlDesigner: Remove foreach / Q_FOREACH usage in componentcore

Task-number: QTCREATORBUG-27464
Change-Id: I89d78d131a11b84b592d3d10577fe1ea4c7a6b4c
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Artem Sokolovskii
2022-05-10 13:41:44 +02:00
parent 597a9dccb3
commit 427c26d900
14 changed files with 102 additions and 80 deletions

View File

@@ -73,7 +73,7 @@ bool checkForPropertyChanges(const QString &signal)
void AddSignalHandlerDialog::updateComboBox() void AddSignalHandlerDialog::updateComboBox()
{ {
m_ui->comboBox->clear(); m_ui->comboBox->clear();
foreach (const QString &signal, m_signals) { for (const QString &signal : qAsConst(m_signals)) {
if (m_ui->all->isChecked()) { if (m_ui->all->isChecked()) {
m_ui->comboBox->addItem(signal); m_ui->comboBox->addItem(signal);
} else if (m_ui->properties->isChecked()) { } else if (m_ui->properties->isChecked()) {

View File

@@ -39,7 +39,9 @@ static QString styleConfigFileName(const QString &qmlFileName)
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(Utils::FilePath::fromString(qmlFileName)); ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(Utils::FilePath::fromString(qmlFileName));
if (currentProject) { if (currentProject) {
foreach (const Utils::FilePath &fileName, currentProject->files(ProjectExplorer::Project::SourceFiles)) const QList<Utils::FilePath> fileNames = currentProject->files(
ProjectExplorer::Project::SourceFiles);
for (const Utils::FilePath &fileName : fileNames)
if (fileName.endsWith("qtquickcontrols2.conf")) if (fileName.endsWith("qtquickcontrols2.conf"))
return fileName.toString(); return fileName.toString();
} }

View File

@@ -178,7 +178,8 @@ void DesignerActionManagerView::setupContext(SelectionContext::UpdateMode update
} }
SelectionContext selectionContext(this); SelectionContext selectionContext(this);
selectionContext.setUpdateMode(updateMode); selectionContext.setUpdateMode(updateMode);
foreach (ActionInterface* action, m_designerActionManager.designerActions()) { const QList<ActionInterface *> actions = m_designerActionManager.designerActions();
for (ActionInterface *action : actions) {
action->currentContextChanged(selectionContext); action->currentContextChanged(selectionContext);
} }
m_setupContextDirty = false; m_setupContextDirty = false;

View File

@@ -290,8 +290,8 @@ QList<QmlJSEditor::FindReferences::Usage> FindImplementation::run(const QString
FindImplementationVisitor visitor(document, context); FindImplementationVisitor visitor(document, context);
FindImplementationVisitor::Results results = visitor(typeName, itemName, targetValue); const FindImplementationVisitor::Results results = visitor(typeName, itemName, targetValue);
foreach (const SourceLocation &location, results) { for (const SourceLocation &location : results) {
usages.append(QmlJSEditor::FindReferences::Usage(fileName, usages.append(QmlJSEditor::FindReferences::Usage(fileName,
matchingLine(location.offset, document->source()), matchingLine(location.offset, document->source()),
location.startLine, location.startColumn - 1, location.length)); location.startLine, location.startColumn - 1, location.length));

View File

@@ -103,7 +103,7 @@ static int lowerBound(int i)
static inline QPointF getUpperLeftPosition(const QList<ModelNode> &modelNodeList) static inline QPointF getUpperLeftPosition(const QList<ModelNode> &modelNodeList)
{ {
QPointF postion(std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()); QPointF postion(std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max());
foreach (const ModelNode &modelNode, modelNodeList) { for (const ModelNode &modelNode : modelNodeList) {
if (QmlItemNode::isValidQmlItemNode(modelNode)) { if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlIitemNode = QmlItemNode(modelNode); QmlItemNode qmlIitemNode = QmlItemNode(modelNode);
if (qmlIitemNode.instancePosition().x() < postion.x()) if (qmlIitemNode.instancePosition().x() < postion.x())
@@ -122,18 +122,20 @@ static void setUpperLeftPostionToNode(const ModelNode &layoutNode, const QList<M
layoutNode.variantProperty("y").setValue(qRound(upperLeftPosition.y())); layoutNode.variantProperty("y").setValue(qRound(upperLeftPosition.y()));
} }
void LayoutInGridLayout::reparentToNodeAndRemovePositionForModelNodes(const ModelNode &parentModelNode, void LayoutInGridLayout::reparentToNodeAndRemovePositionForModelNodes(
const QList<ModelNode> &modelNodeList) const ModelNode &parentModelNode, const QList<ModelNode> &modelNodeList)
{ {
foreach (ModelNode modelNode, modelNodeList) { for (ModelNode modelNode : modelNodeList) {
reparentTo(modelNode, parentModelNode); reparentTo(modelNode, parentModelNode);
modelNode.removeProperty("x"); modelNode.removeProperty("x");
modelNode.removeProperty("y"); modelNode.removeProperty("y");
foreach (const VariantProperty &variantProperty, modelNode.variantProperties()) { const QList<VariantProperty> variantProperties = modelNode.variantProperties();
for (const VariantProperty &variantProperty : variantProperties) {
if (variantProperty.name().contains("anchors.")) if (variantProperty.name().contains("anchors."))
modelNode.removeProperty(variantProperty.name()); modelNode.removeProperty(variantProperty.name());
} }
foreach (const BindingProperty &bindingProperty, modelNode.bindingProperties()) { const QList<BindingProperty> bindingProperties = modelNode.bindingProperties();
for (const BindingProperty &bindingProperty : bindingProperties) {
if (bindingProperty.name().contains("anchors.")) if (bindingProperty.name().contains("anchors."))
modelNode.removeProperty(bindingProperty.name()); modelNode.removeProperty(bindingProperty.name());
} }
@@ -142,7 +144,7 @@ void LayoutInGridLayout::reparentToNodeAndRemovePositionForModelNodes(const Mode
void LayoutInGridLayout::setSizeAsPreferredSize(const QList<ModelNode> &modelNodeList) void LayoutInGridLayout::setSizeAsPreferredSize(const QList<ModelNode> &modelNodeList)
{ {
foreach (ModelNode modelNode, modelNodeList) { for (ModelNode modelNode : modelNodeList) {
if (modelNode.hasVariantProperty("width")) { if (modelNode.hasVariantProperty("width")) {
modelNode.variantProperty("Layout.preferredWidth").setValue(modelNode.variantProperty("width").value()); modelNode.variantProperty("Layout.preferredWidth").setValue(modelNode.variantProperty("width").value());
modelNode.removeProperty("width"); modelNode.removeProperty("width");
@@ -249,7 +251,8 @@ int LayoutInGridLayout::rowCount() const
void LayoutInGridLayout::collectItemNodes() void LayoutInGridLayout::collectItemNodes()
{ {
foreach (const ModelNode &modelNode, m_selectionContext.selectedModelNodes()) { const QList<ModelNode> modelNodes = m_selectionContext.selectedModelNodes();
for (const ModelNode &modelNode : modelNodes) {
if (QmlItemNode::isValidQmlItemNode(modelNode)) { if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode itemNode = modelNode; QmlItemNode itemNode = modelNode;
if (itemNode.instanceSize().width() > 0 if (itemNode.instanceSize().width() > 0
@@ -267,7 +270,7 @@ void LayoutInGridLayout::collectItemNodes()
void LayoutInGridLayout::collectOffsets() void LayoutInGridLayout::collectOffsets()
{ {
//We collect all different x and y offsets that define the cells //We collect all different x and y offsets that define the cells
foreach (const QmlItemNode &qmlItemNode, m_qmlItemNodes) { for (const QmlItemNode &qmlItemNode : qAsConst(m_qmlItemNodes)) {
int x = qRound((qmlItemNode.instancePosition().x())); int x = qRound((qmlItemNode.instancePosition().x()));
m_xTopOffsets.append(x); m_xTopOffsets.append(x);
x = qRound((qmlItemNode.instancePosition().x() + lowerBound(qmlItemNode.instanceBoundingRect().width()))); x = qRound((qmlItemNode.instancePosition().x() + lowerBound(qmlItemNode.instanceBoundingRect().width())));
@@ -303,7 +306,7 @@ void LayoutInGridLayout::calculateGridOffsets()
int heightTolerance = defaultHeightTolerance; int heightTolerance = defaultHeightTolerance;
//The tolerance cannot be bigger then the size of an item //The tolerance cannot be bigger then the size of an item
foreach (const auto &qmlItemNode, m_qmlItemNodes) { for (const auto &qmlItemNode : qAsConst(m_qmlItemNodes)) {
widthTolerance = qMin(qmlItemNode.instanceSize().toSize().width() - 1, widthTolerance); widthTolerance = qMin(qmlItemNode.instanceSize().toSize().width() - 1, widthTolerance);
heightTolerance = qMin(qmlItemNode.instanceSize().toSize().height() - 1, heightTolerance); heightTolerance = qMin(qmlItemNode.instanceSize().toSize().height() - 1, heightTolerance);
} }
@@ -340,7 +343,7 @@ void LayoutInGridLayout::removeEmtpyRowsAndColumns()
m_columns = QVector<bool>(columnCount()); m_columns = QVector<bool>(columnCount());
m_columns.fill(false); m_columns.fill(false);
foreach (const auto &qmlItemNode, m_qmlItemNodes) { for (const auto &qmlItemNode : qAsConst(m_qmlItemNodes)) {
int xCell = getCell(m_xTopOffsets, qmlItemNode.instancePosition().x()); int xCell = getCell(m_xTopOffsets, qmlItemNode.instancePosition().x());
int yCell = getCell(m_yTopOffsets, qmlItemNode.instancePosition().y()); int yCell = getCell(m_yTopOffsets, qmlItemNode.instancePosition().y());
@@ -372,7 +375,7 @@ void LayoutInGridLayout::initializeCells()
void LayoutInGridLayout::markUsedCells() void LayoutInGridLayout::markUsedCells()
{ {
//We mark cells which are covered by items with true //We mark cells which are covered by items with true
foreach (const auto &qmlItemNode, m_qmlItemNodes) { for (const auto &qmlItemNode : qAsConst(m_qmlItemNodes)) {
int xCell = getCell(m_xTopOffsets, qmlItemNode.instancePosition().x()); int xCell = getCell(m_xTopOffsets, qmlItemNode.instancePosition().x());
int yCell = getCell(m_yTopOffsets, qmlItemNode.instancePosition().y()); int yCell = getCell(m_yTopOffsets, qmlItemNode.instancePosition().y());
@@ -391,7 +394,7 @@ void LayoutInGridLayout::fillEmptyCells()
//Cells which are not covered by items and are not marked as true have to be filled with a "spacer" item //Cells which are not covered by items and are not marked as true have to be filled with a "spacer" item
m_layoutedNodes = m_selectionContext.selectedModelNodes(); m_layoutedNodes = m_selectionContext.selectedModelNodes();
foreach (const QmlItemNode &itemNode, m_qmlItemNodes) { for (const auto &itemNode : qAsConst(m_qmlItemNodes)) {
m_layoutedNodes.append(itemNode); m_layoutedNodes.append(itemNode);
} }
@@ -431,7 +434,7 @@ void LayoutInGridLayout::setSpanning(const ModelNode &layoutNode)
layoutNode.variantProperty("columns").setValue(columnCount()); layoutNode.variantProperty("columns").setValue(columnCount());
layoutNode.variantProperty("rows").setValue(rowCount()); layoutNode.variantProperty("rows").setValue(rowCount());
foreach (const ModelNode &modelNode, m_layoutedNodes) { for (const ModelNode &modelNode : qAsConst(m_layoutedNodes)) {
QmlItemNode qmlItemNode(modelNode); QmlItemNode qmlItemNode(modelNode);
int xCell = getCell(m_xTopOffsets, qmlItemNode.instancePosition().x()); int xCell = getCell(m_xTopOffsets, qmlItemNode.instancePosition().x());
int yCell = getCell(m_yTopOffsets, qmlItemNode.instancePosition().y()); int yCell = getCell(m_yTopOffsets, qmlItemNode.instancePosition().y());
@@ -461,7 +464,7 @@ void LayoutInGridLayout::setSpanning(const ModelNode &layoutNode)
void LayoutInGridLayout::removeSpacersBySpanning(QList<ModelNode> &nodes) void LayoutInGridLayout::removeSpacersBySpanning(QList<ModelNode> &nodes)
{ {
foreach (const ModelNode &node, m_spacerNodes) { for (const ModelNode &node : qAsConst(m_spacerNodes)) {
if (int index = nodes.indexOf(node)) { if (int index = nodes.indexOf(node)) {
ModelNode before = nodes.at(index -1); ModelNode before = nodes.at(index -1);
if (m_spacerNodes.contains(before)) { if (m_spacerNodes.contains(before)) {

View File

@@ -41,19 +41,18 @@ ModelNodeContextMenu::ModelNodeContextMenu(AbstractView *view) :
{ {
} }
static QSet<ActionInterface* > findMembers(QSet<ActionInterface* > actionInterface, static QSet<ActionInterface *> findMembers(const QSet<ActionInterface *> actionInterface,
const QByteArray &category) const QByteArray &category)
{ {
QSet<ActionInterface *> ret; QSet<ActionInterface *> ret;
foreach (ActionInterface* factory, actionInterface) { for (ActionInterface *factory : actionInterface) {
if (factory->category() == category) if (factory->category() == category)
ret.insert(factory); ret.insert(factory);
} }
return ret; return ret;
} }
void populateMenu(QSet<ActionInterface* > &actionInterfaces, void populateMenu(QSet<ActionInterface* > &actionInterfaces,
const QByteArray &category, const QByteArray &category,
QMenu* menu, QMenu* menu,
@@ -68,7 +67,7 @@ void populateMenu(QSet<ActionInterface* > &actionInterfaces,
return l->priority() > r->priority(); return l->priority() > r->priority();
}); });
foreach (ActionInterface* actionInterface, matchingFactoriesList) { for (ActionInterface* actionInterface : qAsConst(matchingFactoriesList)) {
if (actionInterface->type() == ActionInterface::ContextMenu) { if (actionInterface->type() == ActionInterface::ContextMenu) {
actionInterface->currentContextChanged(selectionContext); actionInterface->currentContextChanged(selectionContext);
QMenu *newMenu = actionInterface->action()->menu(); QMenu *newMenu = actionInterface->action()->menu();

View File

@@ -54,7 +54,7 @@ static inline bool itemsHaveSameParent(const QList<ModelNode> &siblingList)
if (!parent.isValid()) if (!parent.isValid())
return false; return false;
foreach (const ModelNode &node, siblingList) { for (const ModelNode &node : siblingList) {
QmlItemNode currentItem(node); QmlItemNode currentItem(node);
if (!currentItem.isValid()) if (!currentItem.isValid())
return false; return false;

View File

@@ -114,7 +114,7 @@ static inline void reparentTo(const ModelNode &node, const QmlItemNode &parent)
static inline QPointF getUpperLeftPosition(const QList<ModelNode> &modelNodeList) static inline QPointF getUpperLeftPosition(const QList<ModelNode> &modelNodeList)
{ {
QPointF postion(std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()); QPointF postion(std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max());
foreach (const ModelNode &modelNode, modelNodeList) { for (const ModelNode &modelNode : modelNodeList) {
if (QmlItemNode::isValidQmlItemNode(modelNode)) { if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlIitemNode = QmlItemNode(modelNode); QmlItemNode qmlIitemNode = QmlItemNode(modelNode);
if (qmlIitemNode.instancePosition().x() < postion.x()) if (qmlIitemNode.instancePosition().x() < postion.x())
@@ -151,7 +151,8 @@ void deSelect(const SelectionContext &selectionState)
{ {
if (selectionState.view()) { if (selectionState.view()) {
QList<ModelNode> selectedNodes = selectionState.view()->selectedModelNodes(); QList<ModelNode> selectedNodes = selectionState.view()->selectedModelNodes();
foreach (const ModelNode &node, selectionState.selectedModelNodes()) { const QList<ModelNode> nodes = selectionState.selectedModelNodes();
for (const ModelNode &node : nodes) {
if (selectedNodes.contains(node)) if (selectedNodes.contains(node))
selectedNodes.removeAll(node); selectedNodes.removeAll(node);
} }
@@ -310,7 +311,8 @@ void resetSize(const SelectionContext &selectionState)
return; return;
selectionState.view()->executeInTransaction("DesignerActionManager|resetSize",[selectionState](){ selectionState.view()->executeInTransaction("DesignerActionManager|resetSize",[selectionState](){
foreach (ModelNode node, selectionState.selectedModelNodes()) { const QList<ModelNode> nodes = selectionState.selectedModelNodes();
for (const ModelNode &node : nodes) {
QmlItemNode itemNode(node); QmlItemNode itemNode(node);
if (itemNode.isValid()) { if (itemNode.isValid()) {
itemNode.removeProperty("width"); itemNode.removeProperty("width");
@@ -326,7 +328,8 @@ void resetPosition(const SelectionContext &selectionState)
return; return;
selectionState.view()->executeInTransaction("DesignerActionManager|resetPosition",[selectionState](){ selectionState.view()->executeInTransaction("DesignerActionManager|resetPosition",[selectionState](){
foreach (ModelNode node, selectionState.selectedModelNodes()) { const QList<ModelNode> nodes = selectionState.selectedModelNodes();
for (const ModelNode &node : nodes) {
QmlItemNode itemNode(node); QmlItemNode itemNode(node);
if (itemNode.isValid()) { if (itemNode.isValid()) {
itemNode.removeProperty("x"); itemNode.removeProperty("x");
@@ -602,8 +605,8 @@ static void addSignal(const QString &typeName, const QString &itemId, const QStr
signalHandlerName = "on" + toUpper(signalName).toUtf8(); signalHandlerName = "on" + toUpper(signalName).toUtf8();
else else
signalHandlerName = itemId.toUtf8() + ".on" + toUpper(signalName).toUtf8(); signalHandlerName = itemId.toUtf8() + ".on" + toUpper(signalName).toUtf8();
const QList<ModelNode> nodes = rewriterView.allModelNodes();
foreach (const ModelNode &modelNode, rewriterView.allModelNodes()) { for (const ModelNode &modelNode : nodes) {
if (modelNode.type() == typeName.toUtf8()) { if (modelNode.type() == typeName.toUtf8()) {
modelNode.signalHandlerProperty(signalHandlerName).setSource(QLatin1String("{\n}")); modelNode.signalHandlerProperty(signalHandlerName).setSource(QLatin1String("{\n}"));
} }
@@ -614,7 +617,7 @@ static QStringList cleanSignalNames(const QStringList &input)
{ {
QStringList output; QStringList output;
foreach (const QString &signal, input) for (const QString &signal : input)
if (!signal.startsWith(QLatin1String("__")) && !output.contains(signal)) if (!signal.startsWith(QLatin1String("__")) && !output.contains(signal))
output.append(signal); output.append(signal);
@@ -627,11 +630,13 @@ static QStringList getSortedSignalNameList(const ModelNode &modelNode)
QStringList signalNames; QStringList signalNames;
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
foreach (const PropertyName &signalName, sortedPropertyNameList(metaInfo.signalNames())) const PropertyNameList signalNameList = sortedPropertyNameList(metaInfo.signalNames());
for (const PropertyName &signalName : signalNameList)
if (!signalName.contains("Changed")) if (!signalName.contains("Changed"))
signalNames.append(QString::fromUtf8(signalName)); signalNames.append(QString::fromUtf8(signalName));
foreach (const PropertyName &propertyName, sortedPropertyNameList(metaInfo.propertyNames())) const PropertyNameList propertyNameList = sortedPropertyNameList(metaInfo.propertyNames());
for (const PropertyName &propertyName : propertyNameList)
if (!propertyName.contains(".")) if (!propertyName.contains("."))
signalNames.append(QString::fromUtf8(propertyName + "Changed")); signalNames.append(QString::fromUtf8(propertyName + "Changed"));
} }
@@ -743,7 +748,8 @@ void removeLayout(const SelectionContext &selectionContext)
return; return;
selectionContext.view()->executeInTransaction("DesignerActionManager|removeLayout", [selectionContext, &layoutItem, parent](){ selectionContext.view()->executeInTransaction("DesignerActionManager|removeLayout", [selectionContext, &layoutItem, parent](){
foreach (const ModelNode &modelNode, selectionContext.currentSingleSelectedNode().directSubModelNodes()) { const QList<ModelNode> modelNodes = selectionContext.currentSingleSelectedNode().directSubModelNodes();
for (const ModelNode &modelNode : modelNodes) {
if (QmlItemNode::isValidQmlItemNode(modelNode)) { if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlItem(modelNode); QmlItemNode qmlItem(modelNode);

View File

@@ -105,7 +105,8 @@ void BackendModel::resetModel()
} }
if (rootNode.isValid()) { if (rootNode.isValid()) {
foreach (const AbstractProperty &property ,rootNode.properties()) const QList<AbstractProperty> properties = rootNode.properties();
for (const AbstractProperty &property : properties)
if (property.isDynamic() && !simpleTypes.contains(property.dynamicTypeName())) { if (property.isDynamic() && !simpleTypes.contains(property.dynamicTypeName())) {
NodeMetaInfo metaInfo = m_connectionView->model()->metaInfo(property.dynamicTypeName()); NodeMetaInfo metaInfo = m_connectionView->model()->metaInfo(property.dynamicTypeName());
@@ -147,7 +148,8 @@ QStringList BackendModel::possibleCppTypes() const
QStringList list; QStringList list;
if (rewriterView) { if (rewriterView) {
foreach (const QmlTypeData &cppTypeData, rewriterView->getQMLTypes()) const QList<QmlTypeData> cppTypes = rewriterView->getQMLTypes();
for (const QmlTypeData &cppTypeData : cppTypes)
list.append(cppTypeData.typeName); list.append(cppTypeData.typeName);
} }

View File

@@ -139,7 +139,8 @@ QStringList BindingModel::possibleTargetProperties(const BindingProperty &bindin
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
QStringList possibleProperties; QStringList possibleProperties;
foreach (const PropertyName &propertyName, metaInfo.propertyNames()) { const QList<PropertyName> propertyNames = metaInfo.propertyNames();
for (const PropertyName &propertyName : propertyNames) {
if (metaInfo.propertyIsWritable(propertyName)) if (metaInfo.propertyIsWritable(propertyName))
possibleProperties << QString::fromUtf8(propertyName); possibleProperties << QString::fromUtf8(propertyName);
} }
@@ -232,7 +233,8 @@ static PropertyName unusedProperty(const ModelNode &modelNode)
{ {
PropertyName propertyName = "none"; PropertyName propertyName = "none";
if (modelNode.metaInfo().isValid()) { if (modelNode.metaInfo().isValid()) {
foreach (const PropertyName &propertyName, modelNode.metaInfo().propertyNames()) { const QList<PropertyName> propertyNames = modelNode.metaInfo().propertyNames();
for (const PropertyName &propertyName : propertyNames) {
if (modelNode.metaInfo().propertyIsWritable(propertyName) && !modelNode.hasProperty(propertyName)) if (modelNode.metaInfo().propertyIsWritable(propertyName) && !modelNode.hasProperty(propertyName))
return propertyName; return propertyName;
} }
@@ -305,7 +307,8 @@ void BindingModel::updateBindingProperty(int rowNumber)
void BindingModel::addModelNode(const ModelNode &modelNode) void BindingModel::addModelNode(const ModelNode &modelNode)
{ {
foreach (const BindingProperty &bindingProperty, modelNode.bindingProperties()) { const QList<BindingProperty> bindingProperties = modelNode.bindingProperties();
for (const BindingProperty &bindingProperty : bindingProperties) {
addBindingProperty(bindingProperty); addBindingProperty(bindingProperty);
} }
} }

View File

@@ -112,7 +112,7 @@ void ConnectionView::propertiesRemoved(const QList<AbstractProperty> &propertyLi
void ConnectionView::propertiesAboutToBeRemoved(const QList<AbstractProperty> &propertyList) void ConnectionView::propertiesAboutToBeRemoved(const QList<AbstractProperty> &propertyList)
{ {
foreach (const AbstractProperty &property, propertyList) { for (const AbstractProperty &property : propertyList) {
if (property.isBindingProperty()) { if (property.isBindingProperty()) {
bindingModel()->bindingRemoved(property.toBindingProperty()); bindingModel()->bindingRemoved(property.toBindingProperty());
dynamicPropertiesModel()->bindingRemoved(property.toBindingProperty()); dynamicPropertiesModel()->bindingRemoved(property.toBindingProperty());
@@ -127,7 +127,7 @@ void ConnectionView::propertiesAboutToBeRemoved(const QList<AbstractProperty> &p
void ConnectionView::variantPropertiesChanged(const QList<VariantProperty> &propertyList, void ConnectionView::variantPropertiesChanged(const QList<VariantProperty> &propertyList,
AbstractView::PropertyChangeFlags /*propertyChange*/) AbstractView::PropertyChangeFlags /*propertyChange*/)
{ {
foreach (const VariantProperty &variantProperty, propertyList) { for (const VariantProperty &variantProperty : propertyList) {
if (variantProperty.isDynamic()) if (variantProperty.isDynamic())
dynamicPropertiesModel()->variantPropertyChanged(variantProperty); dynamicPropertiesModel()->variantPropertyChanged(variantProperty);
if (variantProperty.isDynamic() && variantProperty.parentModelNode().isRootNode()) if (variantProperty.isDynamic() && variantProperty.parentModelNode().isRootNode())
@@ -141,7 +141,7 @@ void ConnectionView::variantPropertiesChanged(const QList<VariantProperty> &prop
void ConnectionView::bindingPropertiesChanged(const QList<BindingProperty> &propertyList, void ConnectionView::bindingPropertiesChanged(const QList<BindingProperty> &propertyList,
AbstractView::PropertyChangeFlags /*propertyChange*/) AbstractView::PropertyChangeFlags /*propertyChange*/)
{ {
foreach (const BindingProperty &bindingProperty, propertyList) { for (const BindingProperty &bindingProperty : propertyList) {
bindingModel()->bindingChanged(bindingProperty); bindingModel()->bindingChanged(bindingProperty);
if (bindingProperty.isDynamic()) if (bindingProperty.isDynamic())
dynamicPropertiesModel()->bindingPropertyChanged(bindingProperty); dynamicPropertiesModel()->bindingPropertyChanged(bindingProperty);

View File

@@ -345,7 +345,8 @@ QStringList DynamicPropertiesModel::possibleTargetProperties(const BindingProper
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
QStringList possibleProperties; QStringList possibleProperties;
foreach (const PropertyName &propertyName, metaInfo.propertyNames()) { const QList<PropertyName> propertyNames = metaInfo.propertyNames();
for (const PropertyName &propertyName : propertyNames) {
if (metaInfo.propertyIsWritable(propertyName)) if (metaInfo.propertyIsWritable(propertyName))
possibleProperties << QString::fromUtf8(propertyName); possibleProperties << QString::fromUtf8(propertyName);
} }
@@ -401,7 +402,8 @@ QStringList DynamicPropertiesModel::possibleSourceProperties(const BindingProper
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
QStringList possibleProperties; QStringList possibleProperties;
foreach (const PropertyName &propertyName, metaInfo.propertyNames()) { const QList<PropertyName> propertyNames = metaInfo.propertyNames();
for (const PropertyName &propertyName : propertyNames) {
if (metaInfo.propertyTypeName(propertyName) == typeName) //### todo proper check if (metaInfo.propertyTypeName(propertyName) == typeName) //### todo proper check
possibleProperties << QString::fromUtf8(propertyName); possibleProperties << QString::fromUtf8(propertyName);
} }
@@ -504,12 +506,14 @@ void DynamicPropertiesModel::updateVariantProperty(int rowNumber)
void DynamicPropertiesModel::addModelNode(const ModelNode &modelNode) void DynamicPropertiesModel::addModelNode(const ModelNode &modelNode)
{ {
foreach (const BindingProperty &bindingProperty, modelNode.bindingProperties()) { const QList<BindingProperty> bindingProperties = modelNode.bindingProperties();
for (const BindingProperty &bindingProperty : bindingProperties) {
if (bindingProperty.isDynamic()) if (bindingProperty.isDynamic())
addBindingProperty(bindingProperty); addBindingProperty(bindingProperty);
} }
foreach (const VariantProperty &variantProperty, modelNode.variantProperties()) { const QList<VariantProperty> variantProperties = modelNode.variantProperties();
for (const VariantProperty &variantProperty : variantProperties) {
if (variantProperty.isDynamic()) if (variantProperty.isDynamic())
addVariantProperty(variantProperty); addVariantProperty(variantProperty);
} }

View File

@@ -90,12 +90,12 @@ void DebugView::importsChanged(const QList<Import> &addedImports, const QList<Im
if (isDebugViewEnabled()) { if (isDebugViewEnabled()) {
QString message; QString message;
message += QString("added imports:") += lineBreak; message += QString("added imports:") += lineBreak;
foreach (const Import &import, addedImports) { for (const Import &import : addedImports) {
message += import.toImportString() += lineBreak; message += import.toImportString() += lineBreak;
} }
message += QString("removed imports:") += lineBreak; message += QString("removed imports:") += lineBreak;
foreach (const Import &import, removedImports) { for (const Import &import : removedImports) {
message += import.toImportString() += lineBreak; message += import.toImportString() += lineBreak;
} }
@@ -126,7 +126,8 @@ void DebugView::nodeAboutToBeRemoved(const ModelNode &removedNode)
QString string; QString string;
message.setString(&string); message.setString(&string);
message << removedNode << lineBreak; message << removedNode << lineBreak;
foreach (const ModelNode &modelNode, removedNode.allSubModelNodes()) { const QList<ModelNode> modelNodes = removedNode.allSubModelNodes();
for (const ModelNode &modelNode : modelNodes) {
message << "child node:" << modelNode << lineBreak; message << "child node:" << modelNode << lineBreak;
} }
@@ -192,7 +193,7 @@ void DebugView::variantPropertiesChanged(const QList<VariantProperty> &propertyL
QTextStream message; QTextStream message;
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const VariantProperty &property, propertyList) { for (const VariantProperty &property : propertyList) {
message << property; message << property;
} }
log("::variantPropertiesChanged:", string); log("::variantPropertiesChanged:", string);
@@ -206,7 +207,7 @@ void DebugView::bindingPropertiesChanged(const QList<BindingProperty> &propertyL
QTextStream message; QTextStream message;
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const BindingProperty &property, propertyList) { for (const BindingProperty &property : propertyList) {
message << property; message << property;
} }
log("::Binding properties changed:", string); log("::Binding properties changed:", string);
@@ -219,7 +220,7 @@ void DebugView::signalHandlerPropertiesChanged(const QVector<SignalHandlerProper
QTextStream message; QTextStream message;
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const SignalHandlerProperty &property, propertyList) { for (const SignalHandlerProperty &property : propertyList) {
message << property; message << property;
} }
log("::signalHandlerPropertiesChanged:", string); log("::signalHandlerPropertiesChanged:", string);
@@ -242,7 +243,7 @@ void DebugView::rootNodeTypeChanged(const QString &type, int majorVersion, int m
void DebugView::selectedNodesChanged(const QList<ModelNode> &selectedNodes /*selectedNodeList*/, void DebugView::selectedNodesChanged(const QList<ModelNode> &selectedNodes /*selectedNodeList*/,
const QList<ModelNode> & /*lastSelectedNodeList*/) const QList<ModelNode> & /*lastSelectedNodeList*/)
{ {
foreach (const ModelNode &selectedNode, selectedNodes) { for (const ModelNode &selectedNode : selectedNodes) {
QTextStream message; QTextStream message;
QString string; QString string;
message.setString(&string); message.setString(&string);
@@ -305,7 +306,7 @@ void DebugView::propertiesRemoved(const QList<AbstractProperty> &propertyList)
QTextStream message; QTextStream message;
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const AbstractProperty &property, propertyList) { for (const AbstractProperty &property : propertyList) {
message << property; message << property;
} }
log("::propertiesRemoved:", string); log("::propertiesRemoved:", string);
@@ -334,11 +335,11 @@ void DebugView::documentMessagesChanged(const QList<DocumentMessage> &errors, co
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const DocumentMessage &error, errors) { for (const DocumentMessage &error : errors) {
message << error.toString(); message << error.toString();
} }
foreach (const DocumentMessage &warning, warnings) { for (const DocumentMessage &warning : warnings) {
message << warning.toString(); message << warning.toString();
} }
@@ -380,7 +381,7 @@ void DebugView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyNam
using Pair = QPair<ModelNode, PropertyName>; using Pair = QPair<ModelNode, PropertyName>;
foreach (const Pair &pair, propertyList) { for (const Pair &pair : propertyList) {
message << pair.first; message << pair.first;
message << lineBreak; message << lineBreak;
message << pair.second; message << pair.second;
@@ -401,7 +402,7 @@ void DebugView::instancesCompleted(const QVector<ModelNode> &completedNodeList)
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const ModelNode &modelNode, completedNodeList) { for (const ModelNode &modelNode : completedNodeList) {
message << modelNode << lineBreak; message << modelNode << lineBreak;
if (QmlItemNode::isValidQmlItemNode(modelNode)) { if (QmlItemNode::isValidQmlItemNode(modelNode)) {
message << "parent: " << QmlItemNode(modelNode).instanceParent() << lineBreak; message << "parent: " << QmlItemNode(modelNode).instanceParent() << lineBreak;
@@ -419,7 +420,8 @@ void DebugView::instanceInformationsChanged(const QMultiHash<ModelNode, Informat
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const ModelNode &modelNode, informationChangedHash.keys()) { const QList<ModelNode> modelNodes = informationChangedHash.keys();
for (const ModelNode &modelNode : modelNodes) {
message << modelNode; message << modelNode;
message << informationChangedHash.value(modelNode); message << informationChangedHash.value(modelNode);
} }
@@ -444,7 +446,7 @@ void DebugView::instancesChildrenChanged(const QVector<ModelNode> & nodeList)
QString string; QString string;
message.setString(&string); message.setString(&string);
foreach (const ModelNode &modelNode, nodeList) { for (const ModelNode &modelNode : nodeList) {
message << modelNode << lineBreak; message << modelNode << lineBreak;
if (QmlItemNode::isValidQmlItemNode(modelNode)) { if (QmlItemNode::isValidQmlItemNode(modelNode)) {
message << "parent: " << QmlItemNode(modelNode).instanceParent() << lineBreak; message << "parent: " << QmlItemNode(modelNode).instanceParent() << lineBreak;
@@ -464,11 +466,11 @@ void DebugView::customNotification(const AbstractView *view, const QString &iden
message << view; message << view;
message << identifier; message << identifier;
foreach (const ModelNode &node, nodeList) { for (const ModelNode &node : nodeList) {
message << node; message << node;
} }
foreach (const QVariant &variant, data) { for (const QVariant &variant : data) {
message << variant.toString(); message << variant.toString();
} }

View File

@@ -70,7 +70,7 @@ static QStringList arrayToStringList(const QByteArray &byteArray)
static QByteArray stringListToArray(const QStringList &stringList) static QByteArray stringListToArray(const QStringList &stringList)
{ {
QString str; QString str;
foreach (const QString &subString, stringList) for (const QString &subString : stringList)
str += subString + QLatin1Char('\n'); str += subString + QLatin1Char('\n');
return str.toUtf8(); return str.toUtf8();
} }
@@ -83,7 +83,7 @@ void DesignDocumentView::toClipboard() const
data->setText(toText()); data->setText(toText());
QStringList imports; QStringList imports;
foreach (const Import &import, model()->imports()) for (const Import &import : model()->imports())
imports.append(import.toImportString()); imports.append(import.toImportString());
data->setData(QLatin1String("QmlDesigner::imports"), stringListToArray(imports)); data->setData(QLatin1String("QmlDesigner::imports"), stringListToArray(imports));
@@ -95,7 +95,7 @@ void DesignDocumentView::fromClipboard()
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
fromText(clipboard->text()); fromText(clipboard->text());
QStringList imports = arrayToStringList(clipboard->mimeData()->data(QLatin1String("QmlDesigner::imports"))); QStringList imports = arrayToStringList(clipboard->mimeData()->data(QLatin1String("QmlDesigner::imports")));
// foreach (const QString &importString, imports) { // for (const QString &importString, imports) {
// Import import(Import::createLibraryImport(); // Import import(Import::createLibraryImport();
// model()->addImport(import); //### imports // model()->addImport(import); //### imports
// } // }
@@ -109,7 +109,7 @@ QString DesignDocumentView::toText() const
QPlainTextEdit textEdit; QPlainTextEdit textEdit;
QString imports; QString imports;
foreach (const Import &import, model()->imports()) { for (const Import &import : model()->imports()) {
if (import.isFileImport()) if (import.isFileImport())
imports += QStringLiteral("import ") + QStringLiteral("\"") + import.file() + QStringLiteral("\"")+ QStringLiteral(";\n"); imports += QStringLiteral("import ") + QStringLiteral("\"") + import.file() + QStringLiteral("\"")+ QStringLiteral(";\n");
else else
@@ -215,10 +215,11 @@ void DesignDocumentView::copyModelNodes(const QList<ModelNode> &nodesToCopy)
if (selectedNodes.isEmpty()) if (selectedNodes.isEmpty())
return; return;
foreach (const ModelNode &node, selectedNodes) { QList<ModelNode> nodeList = selectedNodes;
foreach (const ModelNode &node2, selectedNodes) { for (int end = nodeList.length(), i = 0; i < end; ++i) {
if (node.isAncestorOf(node2)) for (int j = 0; j < end; ++j) {
selectedNodes.removeAll(node2); if (nodeList.at(i).isAncestorOf(nodeList.at(j)))
selectedNodes.removeAll(nodeList.at(j));
} }
} }
@@ -238,14 +239,13 @@ void DesignDocumentView::copyModelNodes(const QList<ModelNode> &nodesToCopy)
view.toClipboard(); view.toClipboard();
} else { // multi items selected } else { // multi items selected
for (ModelNode node : view.rootModelNode().directSubModelNodes()) {
foreach (ModelNode node, view.rootModelNode().directSubModelNodes()) {
node.destroy(); node.destroy();
} }
view.changeRootNodeType("QtQuick.Rectangle", 2, 0); view.changeRootNodeType("QtQuick.Rectangle", 2, 0);
view.rootModelNode().setIdWithRefactoring("__multi__selection__"); view.rootModelNode().setIdWithRefactoring("__multi__selection__");
foreach (const ModelNode &selectedNode, selectedNodes) { for (const ModelNode &selectedNode : qAsConst(selectedNodes)) {
ModelNode newNode(view.insertModel(selectedNode)); ModelNode newNode(view.insertModel(selectedNode));
view.rootModelNode().nodeListProperty("data").reparentHere(newNode); view.rootModelNode().nodeListProperty("data").reparentHere(newNode);
} }