Merge pull request #20449 from hyarion/refactor/cpp20-contains
Avoid using `count` and `std::find` where `contains` and `isEmpty` express intent better
This commit is contained in:
@@ -92,7 +92,7 @@ MaterialLibrary::getMaterialTree(const std::shared_ptr<Materials::MaterialFilter
|
||||
for (auto& itp : list) {
|
||||
if (!itp.isEmpty()) {
|
||||
// Add the folder only if it's not already there
|
||||
if (node->count(itp) == 0) {
|
||||
if (!node->contains(itp)) {
|
||||
auto mapPtr = std::make_shared<
|
||||
std::map<QString, std::shared_ptr<MaterialTreeNode>>>();
|
||||
std::shared_ptr<MaterialTreeNode> child =
|
||||
@@ -125,7 +125,7 @@ MaterialLibrary::getMaterialTree(const std::shared_ptr<Materials::MaterialFilter
|
||||
// auto node = materialTree;
|
||||
// for (auto& itp : list) {
|
||||
// // Add the folder only if it's not already there
|
||||
// if (node->count(itp) == 0) {
|
||||
// if (!node->contains(itp)) {
|
||||
// std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
|
||||
// mapPtr = std::make_shared<
|
||||
// std::map<QString, std::shared_ptr<MaterialTreeNode>>>();
|
||||
|
||||
@@ -87,7 +87,7 @@ ModelLibrary::getModelTree(ModelFilter filter) const
|
||||
std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> node = modelTree;
|
||||
for (auto& itp : list) {
|
||||
// Add the folder only if it's not already there
|
||||
if (node->count(itp) == 0) {
|
||||
if (!node->contains(itp)) {
|
||||
auto mapPtr =
|
||||
std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>();
|
||||
std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>();
|
||||
|
||||
@@ -163,7 +163,7 @@ void ModelLoader::dereference(const QString& uuid,
|
||||
auto childProperties = childYaml[childBase];
|
||||
for (auto it = childProperties.begin(); it != childProperties.end(); it++) {
|
||||
std::string name = it->first.as<std::string>();
|
||||
if (exclude.count(QString::fromStdString(name)) == 0) {
|
||||
if (!exclude.contains(QString::fromStdString(name))) {
|
||||
// showYaml(it->second);
|
||||
if (!parentProperties[name]) {
|
||||
parentProperties[name] = it->second;
|
||||
@@ -261,7 +261,7 @@ void ModelLoader::addToTree(std::shared_ptr<ModelEntry> model,
|
||||
auto yamlProperties = yamlModel[base];
|
||||
for (auto it = yamlProperties.begin(); it != yamlProperties.end(); it++) {
|
||||
std::string propName = it->first.as<std::string>();
|
||||
if (exclude.count(QString::fromStdString(propName)) == 0) {
|
||||
if (!exclude.contains(QString::fromStdString(propName))) {
|
||||
// showYaml(it->second);
|
||||
auto yamlProp = yamlProperties[propName];
|
||||
auto propDisplayName = yamlValue(yamlProp, "DisplayName", "");
|
||||
@@ -304,7 +304,7 @@ void ModelLoader::addToTree(std::shared_ptr<ModelEntry> model,
|
||||
}
|
||||
|
||||
auto key = std::pair<QString, QString>(uuid, QString::fromStdString(propName));
|
||||
if (inheritances->count(key) > 0) {
|
||||
if (inheritances->contains(key)) {
|
||||
property.setInheritance((*inheritances)[key]);
|
||||
}
|
||||
|
||||
|
||||
@@ -404,7 +404,7 @@ void MaterialSave::onSelectModel(const QItemSelection& selected, const QItemSele
|
||||
_filename = QString(ui->editFilename->text()); // No filename by default
|
||||
auto model = static_cast<QStandardItemModel*>(ui->treeMaterials->model());
|
||||
QModelIndexList indexes = selected.indexes();
|
||||
if (indexes.count() == 0) {
|
||||
if (indexes.isEmpty()) {
|
||||
_selectedPath = QStringLiteral("/") + _libraryName;
|
||||
_selectedFull = _selectedPath;
|
||||
_selectedUUID = QString();
|
||||
|
||||
Reference in New Issue
Block a user