summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-09-23 20:59:40 -0500
committerJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-09-23 20:59:40 -0500
commitefdff42d5f6cdf5044e741ad7aa00bf73991c422 (patch)
tree0554ea7bec60e31d6a0110553c0a43eaefb7d91e
parentb7d4d20bf185e23e5d19451cccb66bdc94acf09f (diff)
Make category struct attributes private
-rw-r--r--src/categories.cpp61
-rw-r--r--src/categories.h44
-rw-r--r--src/categoriesdialog.cpp16
-rw-r--r--src/downloadmanager.cpp2
-rw-r--r--src/modlistviewactions.cpp3
5 files changed, 68 insertions, 58 deletions
diff --git a/src/categories.cpp b/src/categories.cpp
index 5d0d2bb7..1e2997fb 100644
--- a/src/categories.cpp
+++ b/src/categories.cpp
@@ -131,7 +131,7 @@ void CategoryFactory::loadCategories()
nexCells[0].constData());
}
m_NexusMap.insert_or_assign(nexID, NexusCategory(nexName, nexID));
- m_NexusMap.at(nexID).m_CategoryID = catID;
+ m_NexusMap.at(nexID).setCategoryID(catID);
} else {
log::error(tr("invalid nexus category line {}: {} ({} cells)").toStdString(),
lineNum, nexLine.constData(), nexCells.count());
@@ -157,10 +157,6 @@ void CategoryFactory::reset()
m_Categories.clear();
m_NexusMap.clear();
m_IDMap.clear();
- // 28 =
- // 43 = Savegames (makes no sense to install them through MO)
- // 45 = Videos and trailers
- // 87 = Miscelanous
addCategory(0, "None", std::vector<NexusCategory>(), 0);
}
@@ -168,16 +164,16 @@ void CategoryFactory::setParents()
{
for (std::vector<Category>::iterator iter = m_Categories.begin();
iter != m_Categories.end(); ++iter) {
- iter->m_HasChildren = false;
+ iter->setHasChildren(false);
}
for (std::vector<Category>::const_iterator categoryIter = m_Categories.begin();
categoryIter != m_Categories.end(); ++categoryIter) {
- if (categoryIter->m_ParentID != 0) {
+ if (categoryIter->parentID() != 0) {
std::map<int, unsigned int>::const_iterator iter =
- m_IDMap.find(categoryIter->m_ParentID);
+ m_IDMap.find(categoryIter->parentID());
if (iter != m_IDMap.end()) {
- m_Categories[iter->second].m_HasChildren = true;
+ m_Categories[iter->second].setHasChildren(true);
}
}
}
@@ -201,15 +197,15 @@ void CategoryFactory::saveCategories()
categoryFile.resize(0);
for (std::vector<Category>::const_iterator iter = m_Categories.begin();
iter != m_Categories.end(); ++iter) {
- if (iter->m_ID == 0) {
+ if (iter->ID() == 0) {
continue;
}
QByteArray line;
- line.append(QByteArray::number(iter->m_ID))
+ line.append(QByteArray::number(iter->ID()))
.append("|")
- .append(iter->m_Name.toUtf8())
+ .append(iter->name().toUtf8())
.append("|")
- .append(QByteArray::number(iter->m_ParentID))
+ .append(QByteArray::number(iter->parentID()))
.append("\n");
categoryFile.write(line);
}
@@ -225,9 +221,9 @@ void CategoryFactory::saveCategories()
nexusMapFile.resize(0);
for (auto iter = m_NexusMap.begin(); iter != m_NexusMap.end(); ++iter) {
QByteArray line;
- line.append(QByteArray::number(iter->second.m_CategoryID)).append("|");
- line.append(iter->second.m_Name.toUtf8()).append("|");
- line.append(QByteArray::number(iter->second.m_ID)).append("\n");
+ line.append(QByteArray::number(iter->second.categoryID())).append("|");
+ line.append(iter->second.name().toUtf8()).append("|");
+ line.append(QByteArray::number(iter->second.ID())).append("\n");
nexusMapFile.write(line);
}
nexusMapFile.close();
@@ -274,8 +270,8 @@ void CategoryFactory::addCategory(int id, const QString& name,
int parentID)
{
for (auto nexusCat : nexusCats) {
- m_NexusMap.insert_or_assign(nexusCat.m_ID, nexusCat);
- m_NexusMap.at(nexusCat.m_ID).m_CategoryID = id;
+ m_NexusMap.insert_or_assign(nexusCat.ID(), nexusCat);
+ m_NexusMap.at(nexusCat.ID()).setCategoryID(id);
}
int index = static_cast<int>(m_Categories.size());
m_Categories.push_back(Category(index, id, name, parentID, nexusCats));
@@ -285,9 +281,8 @@ void CategoryFactory::addCategory(int id, const QString& name,
void CategoryFactory::setNexusCategories(
std::vector<CategoryFactory::NexusCategory>& nexusCats)
{
- m_NexusMap.clear();
for (auto nexusCat : nexusCats) {
- m_NexusMap.emplace(nexusCat.m_ID, nexusCat);
+ m_NexusMap.emplace(nexusCat.ID(), nexusCat);
}
saveCategories();
@@ -367,7 +362,7 @@ int CategoryFactory::getParentID(unsigned int index) const
throw MyException(tr("invalid category index: %1").arg(index));
}
- return m_Categories[index].m_ParentID;
+ return m_Categories[index].parentID();
}
bool CategoryFactory::categoryExists(int id) const
@@ -394,12 +389,12 @@ bool CategoryFactory::isDescendantOfImpl(int id, int parentID,
if (iter != m_IDMap.end()) {
unsigned int index = iter->second;
- if (m_Categories[index].m_ParentID == 0) {
+ if (m_Categories[index].parentID() == 0) {
return false;
- } else if (m_Categories[index].m_ParentID == parentID) {
+ } else if (m_Categories[index].parentID() == parentID) {
return true;
} else {
- return isDescendantOfImpl(m_Categories[index].m_ParentID, parentID, seen);
+ return isDescendantOfImpl(m_Categories[index].parentID(), parentID, seen);
}
} else {
log::warn(tr("{} is no valid category id").toStdString(), id);
@@ -413,7 +408,7 @@ bool CategoryFactory::hasChildren(unsigned int index) const
throw MyException(tr("invalid category index: %1").arg(index));
}
- return m_Categories[index].m_HasChildren;
+ return m_Categories[index].hasChildren();
}
QString CategoryFactory::getCategoryName(unsigned int index) const
@@ -422,7 +417,7 @@ QString CategoryFactory::getCategoryName(unsigned int index) const
throw MyException(tr("invalid category index: %1").arg(index));
}
- return m_Categories[index].m_Name;
+ return m_Categories[index].name();
}
QString CategoryFactory::getSpecialCategoryName(SpecialCategories type) const
@@ -480,7 +475,7 @@ QString CategoryFactory::getCategoryNameByID(int id) const
return {};
}
- return m_Categories[index].m_Name;
+ return m_Categories[index].name();
}
}
@@ -490,7 +485,7 @@ int CategoryFactory::getCategoryID(unsigned int index) const
throw MyException(tr("invalid category index: %1").arg(index));
}
- return m_Categories[index].m_ID;
+ return m_Categories[index].ID();
}
int CategoryFactory::getCategoryIndex(int ID) const
@@ -506,11 +501,11 @@ int CategoryFactory::getCategoryID(const QString& name) const
{
auto iter = std::find_if(m_Categories.begin(), m_Categories.end(),
[name](const Category& cat) -> bool {
- return cat.m_Name == name;
+ return cat.name() == name;
});
if (iter != m_Categories.end()) {
- return iter->m_ID;
+ return iter->ID();
} else {
return -1;
}
@@ -520,10 +515,10 @@ unsigned int CategoryFactory::resolveNexusID(int nexusID) const
{
auto result = m_NexusMap.find(nexusID);
if (result != m_NexusMap.end()) {
- if (m_IDMap.count(result->second.m_CategoryID)) {
+ if (m_IDMap.count(result->second.categoryID())) {
log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID,
- m_IDMap.at(result->second.m_CategoryID));
- return m_IDMap.at(result->second.m_CategoryID);
+ m_IDMap.at(result->second.categoryID()));
+ return m_IDMap.at(result->second.categoryID());
}
}
log::debug(tr("nexus category id {} not mapped").toStdString(), nexusID);
diff --git a/src/categories.h b/src/categories.h
index b7a9c214..a6ee2e24 100644
--- a/src/categories.h
+++ b/src/categories.h
@@ -58,46 +58,62 @@ public:
public:
struct NexusCategory
{
- NexusCategory(const QString& name, const int nexusID) : m_Name(name), m_ID(nexusID)
+ NexusCategory(const QString name, const int nexusID) : m_Name(name), m_ID(nexusID)
{}
- QString m_Name;
- int m_ID;
- int m_CategoryID = -1;
friend bool operator==(const NexusCategory& LHS, const NexusCategory& RHS)
{
- return LHS.m_ID == RHS.m_ID;
+ return LHS.ID() == RHS.ID();
}
friend bool operator==(const NexusCategory& LHS, const int RHS)
{
- return LHS.m_ID == RHS;
+ return LHS.ID() == RHS;
}
friend bool operator<(const NexusCategory& LHS, const NexusCategory& RHS)
{
- return LHS.m_ID < RHS.m_ID;
+ return LHS.ID() < RHS.ID();
}
+
+ QString name() const { return m_Name; }
+ int ID() const { return m_ID; }
+ int categoryID() const { return m_CategoryID; }
+ void setCategoryID(int categoryID) { m_CategoryID = categoryID; }
+
+ private:
+ QString m_Name;
+ int m_ID;
+ int m_CategoryID = -1;
};
struct Category
{
- Category(int sortValue, int id, const QString& name, int parentID,
+ 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)
{}
+
+ friend bool operator<(const Category& LHS, const Category& RHS)
+ {
+ return LHS.sortValue() < RHS.sortValue();
+ }
+
+ int sortValue() const { return m_SortValue; }
+ int ID() const { return m_ID; }
+ int parentID() const { return m_ParentID; }
+ QString name() const { return m_Name; }
+ bool hasChildren() const { return m_HasChildren; }
+ void setHasChildren(bool b) { m_HasChildren = b; }
+
+ private:
int m_SortValue;
int m_ID;
int m_ParentID;
- bool m_HasChildren;
QString m_Name;
std::vector<NexusCategory> m_NexusCats;
-
- friend bool operator<(const Category& LHS, const Category& RHS)
- {
- return LHS.m_SortValue < RHS.m_SortValue;
- }
+ bool m_HasChildren;
};
public:
diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp
index 53c930f3..b770fa0b 100644
--- a/src/categoriesdialog.cpp
+++ b/src/categoriesdialog.cpp
@@ -213,7 +213,7 @@ void CategoriesDialog::fillTable()
categories.m_Categories.begin();
iter != categories.m_Categories.end(); ++iter, ++row) {
const CategoryFactory::Category& category = *iter;
- if (category.m_ID == 0) {
+ if (category.ID() == 0) {
--row;
continue;
}
@@ -221,11 +221,11 @@ void CategoriesDialog::fillTable()
// table->setVerticalHeaderItem(row, new QTableWidgetItem(" "));
QScopedPointer<QTableWidgetItem> idItem(new QTableWidgetItem());
- idItem->setData(Qt::DisplayRole, category.m_ID);
+ idItem->setData(Qt::DisplayRole, category.ID());
- QScopedPointer<QTableWidgetItem> nameItem(new QTableWidgetItem(category.m_Name));
+ QScopedPointer<QTableWidgetItem> nameItem(new QTableWidgetItem(category.name()));
QScopedPointer<QTableWidgetItem> parentIDItem(new QTableWidgetItem());
- parentIDItem->setData(Qt::DisplayRole, category.m_ParentID);
+ parentIDItem->setData(Qt::DisplayRole, category.parentID());
QScopedPointer<QTableWidgetItem> nexusCatItem(new QTableWidgetItem());
table->setItem(row, 0, idItem.take());
@@ -236,15 +236,15 @@ void CategoriesDialog::fillTable()
for (auto nexusCat : categories.m_NexusMap) {
QScopedPointer<QListWidgetItem> nexusItem(new QListWidgetItem());
- nexusItem->setData(Qt::DisplayRole, nexusCat.second.m_Name);
- nexusItem->setData(Qt::UserRole, nexusCat.second.m_ID);
+ nexusItem->setData(Qt::DisplayRole, nexusCat.second.name());
+ nexusItem->setData(Qt::UserRole, nexusCat.second.ID());
list->addItem(nexusItem.take());
auto item = table->item(categories.resolveNexusID(nexusCat.first) - 1, 3);
if (item != nullptr) {
auto itemData = item->data(Qt::UserRole).toList();
QVariantList newData;
- newData.append(nexusCat.second.m_Name);
- newData.append(nexusCat.second.m_ID);
+ newData.append(nexusCat.second.name());
+ newData.append(nexusCat.second.ID());
itemData.insert(itemData.length(), newData);
QStringList names;
for (auto cat : itemData) {
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index d7a72c0b..6894b401 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -432,7 +432,7 @@ void DownloadManager::refreshList()
log::debug("saw {} downloads", m_ActiveDownloads.size());
- emit update(-1);
+ emit update(-1);
} catch (const std::bad_alloc&) {
reportError(tr("Memory allocation error (in refreshing directory)."));
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index 983574ab..cbac9c6c 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -1135,8 +1135,7 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const
categoryID = downloadMeta.value("category", 0).toInt();
}
}
- unsigned int categoryIndex =
- CategoryFactory::instance().resolveNexusID(categoryID);
+ unsigned int categoryIndex = CategoryFactory::instance().resolveNexusID(categoryID);
if (categoryIndex != 0)
modInfo->setPrimaryCategory(
CategoryFactory::instance().getCategoryID(categoryIndex));