diff options
| author | Jeremy Rimpo <jrim@rimpo.org> | 2023-09-24 05:46:09 -0500 |
|---|---|---|
| committer | Jeremy Rimpo <jrim@rimpo.org> | 2023-09-24 05:54:27 -0500 |
| commit | c30b5183aeea55290ec9072cac958cd6e90fdf30 (patch) | |
| tree | fa8dec2bf12e6f8979e7b938f861661e934665da /src | |
| parent | 11522cf700e07a6c39bad45c346e62a73935c083 (diff) | |
Convert for loops, move nexusCats
Diffstat (limited to 'src')
| -rw-r--r-- | src/categories.cpp | 37 | ||||
| -rw-r--r-- | src/categories.h | 4 | ||||
| -rw-r--r-- | src/categoriesdialog.cpp | 4 |
3 files changed, 21 insertions, 24 deletions
diff --git a/src/categories.cpp b/src/categories.cpp index 1e2997fb..c1aa756f 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -162,16 +162,14 @@ void CategoryFactory::reset() void CategoryFactory::setParents() { - for (std::vector<Category>::iterator iter = m_Categories.begin(); - iter != m_Categories.end(); ++iter) { - iter->setHasChildren(false); + for (auto& category : m_Categories) { + category.setHasChildren(false); } - for (std::vector<Category>::const_iterator categoryIter = m_Categories.begin(); - categoryIter != m_Categories.end(); ++categoryIter) { - if (categoryIter->parentID() != 0) { + for (const auto& category : m_Categories) { + if (category.parentID() != 0) { std::map<int, unsigned int>::const_iterator iter = - m_IDMap.find(categoryIter->parentID()); + m_IDMap.find(category.parentID()); if (iter != m_IDMap.end()) { m_Categories[iter->second].setHasChildren(true); } @@ -195,17 +193,16 @@ void CategoryFactory::saveCategories() } categoryFile.resize(0); - for (std::vector<Category>::const_iterator iter = m_Categories.begin(); - iter != m_Categories.end(); ++iter) { - if (iter->ID() == 0) { + for (const auto& category : m_Categories) { + if (category.ID() == 0) { continue; } QByteArray line; - line.append(QByteArray::number(iter->ID())) + line.append(QByteArray::number(category.ID())) .append("|") - .append(iter->name().toUtf8()) + .append(category.name().toUtf8()) .append("|") - .append(QByteArray::number(iter->parentID())) + .append(QByteArray::number(category.parentID())) .append("\n"); categoryFile.write(line); } @@ -219,11 +216,11 @@ void CategoryFactory::saveCategories() } nexusMapFile.resize(0); - for (auto iter = m_NexusMap.begin(); iter != m_NexusMap.end(); ++iter) { + for (const auto& nexMap : m_NexusMap) { QByteArray line; - line.append(QByteArray::number(iter->second.categoryID())).append("|"); - line.append(iter->second.name().toUtf8()).append("|"); - line.append(QByteArray::number(iter->second.ID())).append("\n"); + line.append(QByteArray::number(nexMap.second.categoryID())).append("|"); + line.append(nexMap.second.name().toUtf8()).append("|"); + line.append(QByteArray::number(nexMap.second.ID())).append("\n"); nexusMapFile.write(line); } nexusMapFile.close(); @@ -269,7 +266,7 @@ void CategoryFactory::addCategory(int id, const QString& name, const std::vector<NexusCategory>& nexusCats, int parentID) { - for (auto nexusCat : nexusCats) { + for (const auto& nexusCat : nexusCats) { m_NexusMap.insert_or_assign(nexusCat.ID(), nexusCat); m_NexusMap.at(nexusCat.ID()).setCategoryID(id); } @@ -279,9 +276,9 @@ void CategoryFactory::addCategory(int id, const QString& name, } void CategoryFactory::setNexusCategories( - std::vector<CategoryFactory::NexusCategory>& nexusCats) + const std::vector<CategoryFactory::NexusCategory>& nexusCats) { - for (auto nexusCat : nexusCats) { + for (const auto& nexusCat : nexusCats) { m_NexusMap.emplace(nexusCat.ID(), nexusCat); } diff --git a/src/categories.h b/src/categories.h index a6ee2e24..15b9bbc1 100644 --- a/src/categories.h +++ b/src/categories.h @@ -92,7 +92,7 @@ public: Category(int sortValue, int id, const QString name, int parentID, std::vector<NexusCategory> nexusCats) : m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false), - m_ParentID(parentID), m_NexusCats(nexusCats) + m_ParentID(parentID), m_NexusCats(std::move(nexusCats)) {} friend bool operator<(const Category& LHS, const Category& RHS) @@ -132,7 +132,7 @@ public: **/ void saveCategories(); - void setNexusCategories(std::vector<CategoryFactory::NexusCategory>& nexusCats); + void setNexusCategories(const std::vector<CategoryFactory::NexusCategory>& nexusCats); void refreshNexusCategories(CategoriesDialog* dialog); diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index b770fa0b..21523e85 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -234,7 +234,7 @@ void CategoriesDialog::fillTable() table->setItem(row, 3, nexusCatItem.take()); } - for (auto nexusCat : categories.m_NexusMap) { + for (const auto& nexusCat : categories.m_NexusMap) { QScopedPointer<QListWidgetItem> nexusItem(new QListWidgetItem()); nexusItem->setData(Qt::DisplayRole, nexusCat.second.name()); nexusItem->setData(Qt::UserRole, nexusCat.second.ID()); @@ -355,7 +355,7 @@ void CategoriesDialog::nxmGameInfoAvailable(QString gameName, QVariant, CategoryFactory& catFactory = CategoryFactory::instance(); QListWidget* list = ui->nexusCategoryList; list->clear(); - for (auto category : categories) { + for (const auto& category : categories) { auto catMap = category.toMap(); QScopedPointer<QListWidgetItem> nexusItem(new QListWidgetItem()); nexusItem->setData(Qt::DisplayRole, catMap["name"].toString()); |
