Skip to content

Commit c30b518

Browse files
committed
Convert for loops, move nexusCats
1 parent 11522cf commit c30b518

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

src/categories.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,14 @@ void CategoryFactory::reset()
162162

163163
void CategoryFactory::setParents()
164164
{
165-
for (std::vector<Category>::iterator iter = m_Categories.begin();
166-
iter != m_Categories.end(); ++iter) {
167-
iter->setHasChildren(false);
165+
for (auto& category : m_Categories) {
166+
category.setHasChildren(false);
168167
}
169168

170-
for (std::vector<Category>::const_iterator categoryIter = m_Categories.begin();
171-
categoryIter != m_Categories.end(); ++categoryIter) {
172-
if (categoryIter->parentID() != 0) {
169+
for (const auto& category : m_Categories) {
170+
if (category.parentID() != 0) {
173171
std::map<int, unsigned int>::const_iterator iter =
174-
m_IDMap.find(categoryIter->parentID());
172+
m_IDMap.find(category.parentID());
175173
if (iter != m_IDMap.end()) {
176174
m_Categories[iter->second].setHasChildren(true);
177175
}
@@ -195,17 +193,16 @@ void CategoryFactory::saveCategories()
195193
}
196194

197195
categoryFile.resize(0);
198-
for (std::vector<Category>::const_iterator iter = m_Categories.begin();
199-
iter != m_Categories.end(); ++iter) {
200-
if (iter->ID() == 0) {
196+
for (const auto& category : m_Categories) {
197+
if (category.ID() == 0) {
201198
continue;
202199
}
203200
QByteArray line;
204-
line.append(QByteArray::number(iter->ID()))
201+
line.append(QByteArray::number(category.ID()))
205202
.append("|")
206-
.append(iter->name().toUtf8())
203+
.append(category.name().toUtf8())
207204
.append("|")
208-
.append(QByteArray::number(iter->parentID()))
205+
.append(QByteArray::number(category.parentID()))
209206
.append("\n");
210207
categoryFile.write(line);
211208
}
@@ -219,11 +216,11 @@ void CategoryFactory::saveCategories()
219216
}
220217

221218
nexusMapFile.resize(0);
222-
for (auto iter = m_NexusMap.begin(); iter != m_NexusMap.end(); ++iter) {
219+
for (const auto& nexMap : m_NexusMap) {
223220
QByteArray line;
224-
line.append(QByteArray::number(iter->second.categoryID())).append("|");
225-
line.append(iter->second.name().toUtf8()).append("|");
226-
line.append(QByteArray::number(iter->second.ID())).append("\n");
221+
line.append(QByteArray::number(nexMap.second.categoryID())).append("|");
222+
line.append(nexMap.second.name().toUtf8()).append("|");
223+
line.append(QByteArray::number(nexMap.second.ID())).append("\n");
227224
nexusMapFile.write(line);
228225
}
229226
nexusMapFile.close();
@@ -269,7 +266,7 @@ void CategoryFactory::addCategory(int id, const QString& name,
269266
const std::vector<NexusCategory>& nexusCats,
270267
int parentID)
271268
{
272-
for (auto nexusCat : nexusCats) {
269+
for (const auto& nexusCat : nexusCats) {
273270
m_NexusMap.insert_or_assign(nexusCat.ID(), nexusCat);
274271
m_NexusMap.at(nexusCat.ID()).setCategoryID(id);
275272
}
@@ -279,9 +276,9 @@ void CategoryFactory::addCategory(int id, const QString& name,
279276
}
280277

281278
void CategoryFactory::setNexusCategories(
282-
std::vector<CategoryFactory::NexusCategory>& nexusCats)
279+
const std::vector<CategoryFactory::NexusCategory>& nexusCats)
283280
{
284-
for (auto nexusCat : nexusCats) {
281+
for (const auto& nexusCat : nexusCats) {
285282
m_NexusMap.emplace(nexusCat.ID(), nexusCat);
286283
}
287284

src/categories.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CategoryFactory : public QObject
9292
Category(int sortValue, int id, const QString name, int parentID,
9393
std::vector<NexusCategory> nexusCats)
9494
: m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false),
95-
m_ParentID(parentID), m_NexusCats(nexusCats)
95+
m_ParentID(parentID), m_NexusCats(std::move(nexusCats))
9696
{}
9797

9898
friend bool operator<(const Category& LHS, const Category& RHS)
@@ -132,7 +132,7 @@ class CategoryFactory : public QObject
132132
**/
133133
void saveCategories();
134134

135-
void setNexusCategories(std::vector<CategoryFactory::NexusCategory>& nexusCats);
135+
void setNexusCategories(const std::vector<CategoryFactory::NexusCategory>& nexusCats);
136136

137137
void refreshNexusCategories(CategoriesDialog* dialog);
138138

src/categoriesdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void CategoriesDialog::fillTable()
234234
table->setItem(row, 3, nexusCatItem.take());
235235
}
236236

237-
for (auto nexusCat : categories.m_NexusMap) {
237+
for (const auto& nexusCat : categories.m_NexusMap) {
238238
QScopedPointer<QListWidgetItem> nexusItem(new QListWidgetItem());
239239
nexusItem->setData(Qt::DisplayRole, nexusCat.second.name());
240240
nexusItem->setData(Qt::UserRole, nexusCat.second.ID());
@@ -355,7 +355,7 @@ void CategoriesDialog::nxmGameInfoAvailable(QString gameName, QVariant,
355355
CategoryFactory& catFactory = CategoryFactory::instance();
356356
QListWidget* list = ui->nexusCategoryList;
357357
list->clear();
358-
for (auto category : categories) {
358+
for (const auto& category : categories) {
359359
auto catMap = category.toMap();
360360
QScopedPointer<QListWidgetItem> nexusItem(new QListWidgetItem());
361361
nexusItem->setData(Qt::DisplayRole, catMap["name"].toString());

0 commit comments

Comments
 (0)