QmlDesigner: Use view instead of const &

A span of constant elements is a view.

Change-Id: I4fad60673bc2ba98491dfffb7c854beeeb0ae12b
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2022-08-20 13:43:05 +02:00
committed by Thomas Hartmann
parent 45aa6a12c4
commit fe5848a47c
5 changed files with 8 additions and 5 deletions

View File

@@ -313,11 +313,12 @@ void DebugView::selectedNodesChanged(const QList<ModelNode> &selectedNodes /*sel
}
auto auxiliaryData = selectedNode.auxiliaryData();
AuxiliaryDatas sortedaAuxiliaryData{auxiliaryData.begin(), auxiliaryData.end()};
Utils::sort(auxiliaryData, [](const auto &first, const auto &second) {
Utils::sort(sortedaAuxiliaryData, [](const auto &first, const auto &second) {
return first.first < second.first;
});
for (const auto &element : auxiliaryData) {
for (const auto &element : sortedaAuxiliaryData) {
message << element.first.type << ' ' << element.first.name.data() << ' '
<< element.second.toString() << lineBreak;
}

View File

@@ -28,6 +28,7 @@
#include <nodeinstanceglobal.h>
#include <utils/smallstring.h>
#include <utils/span.h>
#include <vector>
@@ -75,5 +76,6 @@ bool operator!=(const BasicAuxiliaryDataKey<First> &first, const BasicAuxiliaryD
using AuxiliaryDataKey = BasicAuxiliaryDataKey<Utils::SmallString>;
using AuxiliaryDataKeyView = BasicAuxiliaryDataKey<Utils::SmallStringView>;
using AuxiliaryDatas = std::vector<std::pair<AuxiliaryDataKey, QVariant>>;
using AuxiliaryDatasView = Utils::span<const std::pair<AuxiliaryDataKey, QVariant>>;
using AuxiliaryDatasForType = std::vector<std::pair<Utils::SmallString, QVariant>>;
} // namespace QmlDesigner

View File

@@ -214,7 +214,7 @@ public:
bool hasAuxiliaryData(AuxiliaryDataKeyView key) const;
bool hasAuxiliaryData(AuxiliaryDataType type, Utils::SmallStringView name) const;
AuxiliaryDatasForType auxiliaryData(AuxiliaryDataType type) const;
const AuxiliaryDatas &auxiliaryData() const;
AuxiliaryDatasView auxiliaryData() const;
QString customId() const;
bool hasCustomId() const;

View File

@@ -87,7 +87,7 @@ public:
bool removeAuxiliaryData(AuxiliaryDataKeyView key);
bool hasAuxiliaryData(AuxiliaryDataKeyView key) const;
AuxiliaryDatasForType auxiliaryData(AuxiliaryDataType type) const;
const AuxiliaryDatas &auxiliaryData() const { return m_auxiliaryDatas; }
AuxiliaryDatasView auxiliaryData() const { return std::as_const(m_auxiliaryDatas); }
InternalProperty::Pointer property(const PropertyName &name) const;
InternalBindingProperty::Pointer bindingProperty(const PropertyName &name) const;

View File

@@ -1136,7 +1136,7 @@ AuxiliaryDatasForType ModelNode::auxiliaryData(AuxiliaryDataType type) const
return m_internalNode->auxiliaryData(type);
}
const AuxiliaryDatas &ModelNode::auxiliaryData() const
AuxiliaryDatasView ModelNode::auxiliaryData() const
{
if (!isValid())
throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);