summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2019-12-23 23:16:36 -0600
committerJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-09-21 17:03:43 -0500
commit127db7799ed4847b151a35a16cefab6c494128ef (patch)
treedd31c995fee70d2fd0367eeaa6ad916755060256 /src
parent4fd45b937c0577a0c5c1699726e8132b97be8f5d (diff)
WIP: Category QObj refactor
Diffstat (limited to 'src')
-rw-r--r--src/categories.cpp39
-rw-r--r--src/categories.h40
-rw-r--r--src/categoriesdialog.cpp41
-rw-r--r--src/categoriesdialog.h3
-rw-r--r--src/categoriesdialog.ui75
-rw-r--r--src/installationmanager.cpp10
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/modinfo.cpp12
-rw-r--r--src/modinfodialogcategories.cpp18
-rw-r--r--src/modinfodialogcategories.h5
-rw-r--r--src/modinforegular.cpp11
-rw-r--r--src/modlist.cpp22
-rw-r--r--src/modlistsortproxy.cpp185
13 files changed, 249 insertions, 214 deletions
diff --git a/src/categories.cpp b/src/categories.cpp
index e64d35c3..cf8008e5 100644
--- a/src/categories.cpp
+++ b/src/categories.cpp
@@ -33,7 +33,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
using namespace MOBase;
-CategoryFactory* CategoryFactory::s_Instance = nullptr;
QString CategoryFactory::categoriesFilePath()
{
@@ -47,9 +46,8 @@ QString CategoryFactory::nexusMappingFilePath()
}
-CategoryFactory::CategoryFactory()
+CategoryFactory::CategoryFactory() : QObject()
{
- atexit(&cleanup);
}
void CategoryFactory::loadCategories()
@@ -76,7 +74,7 @@ void CategoryFactory::loadCategories()
bool ok = false;
int temp = iter->toInt(&ok);
if (!ok) {
- log::error(tr("invalid category id {}"), iter->constData());
+ log::error(tr("invalid category id {}").toStdString(), iter->constData());
}
nexusCats.push_back(NexusCategory("Unknown", temp));
}
@@ -86,7 +84,7 @@ void CategoryFactory::loadCategories()
int id = cells[0].toInt(&cell0Ok);
int parentID = cells[3].trimmed().toInt(&cell3Ok);
if (!cell0Ok || !cell3Ok) {
- log::error(tr("invalid category line {}: {}"), lineNum, line.constData());
+ log::error(tr("invalid category line {}: {}").toStdString(), lineNum, line.constData());
}
addCategory(id, QString::fromUtf8(cells[1].constData()), nexusCats, parentID);
} else if (cells.count() == 3) {
@@ -95,13 +93,13 @@ void CategoryFactory::loadCategories()
int id = cells[0].toInt(&cell0Ok);
int parentID = cells[2].trimmed().toInt(&cell3Ok);
if (!cell0Ok || !cell3Ok) {
- log::error(tr("invalid category line {}: {}"), lineNum, line.constData());
+ log::error(tr("invalid category line {}: {}").toStdString(), lineNum, line.constData());
}
addCategory(id, QString::fromUtf8(cells[1].constData()), std::vector<NexusCategory>(), parentID);
} else {
log::error(
- tr("invalid category line {}: {} ({} cells)"),
+ tr("invalid category line {}: {} ({} cells)").toStdString(),
lineNum, line.constData(), cells.count());
}
}
@@ -121,11 +119,11 @@ void CategoryFactory::loadCategories()
bool ok = false;
int nexID = nexCells[2].toInt(&ok);
if (!ok) {
- log::error(tr("invalid nexus ID {}"), nexCells[2].constData());
+ log::error(tr("invalid nexus ID {}").toStdString(), nexCells[2].constData());
}
int catID = nexCells[0].toInt(&ok);
if (!ok) {
- log::error(tr("invalid category id {}"), nexCells[0].constData());
+ log::error(tr("invalid category id {}").toStdString(), nexCells[0].constData());
}
m_NexusMap[NexusCategory(nexName, nexID)] = catID;
}
@@ -139,10 +137,8 @@ void CategoryFactory::loadCategories()
CategoryFactory* CategoryFactory::instance()
{
- if (s_Instance == nullptr) {
- s_Instance = new CategoryFactory;
- }
- return s_Instance;
+ static CategoryFactory s_Instance;
+ return &s_Instance;
}
void CategoryFactory::reset()
@@ -175,11 +171,6 @@ void CategoryFactory::setParents()
}
}
-void CategoryFactory::cleanup()
-{
- delete s_Instance;
- s_Instance = nullptr;
-}
void CategoryFactory::saveCategories()
{
@@ -252,7 +243,7 @@ int CategoryFactory::addCategory(const QString& name, const std::vector<NexusCat
void CategoryFactory::addCategory(int id, const QString& name, int parentID)
{
int index = static_cast<int>(m_Categories.size());
- m_Categories.push_back(Category(index, id, name, parentID));
+ m_Categories.push_back(Category(index, id, name, parentID, std::vector<NexusCategory>()));
m_IDMap[id] = index;
}
@@ -261,7 +252,9 @@ void CategoryFactory::addCategory(int id, const QString& name, const std::vector
for (auto nexusCat : nexusCats) {
m_NexusMap[nexusCat] = id;
}
- addCategory(id, name, parentID);
+ int index = static_cast<int>(m_Categories.size());
+ m_Categories.push_back(Category(index, id, name, parentID, nexusCats));
+ m_IDMap[id] = index;
}
@@ -323,7 +316,7 @@ bool CategoryFactory::isDescendantOfImpl(int id, int parentID,
return isDescendantOfImpl(m_Categories[index].m_ParentID, parentID, seen);
}
} else {
- log::warn(tr("{} is no valid category id"), id);
+ log::warn(tr("{} is no valid category id").toStdString(), id);
return false;
}
}
@@ -443,10 +436,10 @@ unsigned int CategoryFactory::resolveNexusID(int nexusID) const
return el.first.m_ID == nexusID;
});
if (result != m_NexusMap.end()) {
- log::debug(tr("nexus category id {} maps to internal {}"), nexusID, result->second);
+ log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, result->second);
return result->second;
} else {
- log::debug(tr("nexus category id {} not mapped"), nexusID);
+ log::debug(tr("nexus category id {} not mapped").toStdString(), nexusID);
return 0U;
}
}
diff --git a/src/categories.h b/src/categories.h
index 232288a7..e9f00726 100644
--- a/src/categories.h
+++ b/src/categories.h
@@ -31,7 +31,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*to look up categories, optimized to where the request comes from. Therefore be very
*careful which of the two you have available
**/
-class CategoryFactory : QObject {
+class CategoryFactory : public QObject {
Q_OBJECT;
friend class CategoriesDialog;
@@ -53,14 +53,35 @@ public:
};
public:
+ struct NexusCategory {
+ NexusCategory(const QString& name, const int nexusID)
+ : m_Name(name), m_ID(nexusID) {}
+ QString m_Name;
+ int m_ID;
+
+ friend bool operator==(const NexusCategory& LHS, const NexusCategory& RHS) {
+ return LHS.m_ID == RHS.m_ID;
+ }
+
+ friend bool operator==(const NexusCategory& LHS, const int RHS) {
+ return LHS.m_ID == RHS;
+ }
+
+ friend bool operator<(const NexusCategory& LHS, const NexusCategory& RHS) {
+ return LHS.m_ID < RHS.m_ID;
+ }
+ };
+
struct Category {
- Category(int sortValue, int id, const QString& name, int parentID)
- : m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false), m_ParentID(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) {}
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)
{
@@ -68,13 +89,6 @@ public:
}
};
- struct NexusCategory {
- NexusCategory(const QString &name, const int nexusID)
- : m_Name(name), m_ID(nexusID) {}
- QString m_Name;
- int m_ID;
- };
-
public:
/**
* @brief reset the list of categories
@@ -206,7 +220,7 @@ signals:
void requestNexusCategories();
private:
- CategoryFactory();
+ explicit CategoryFactory();
void loadDefaultCategories();
@@ -215,11 +229,7 @@ private:
void setParents();
- static void cleanup();
-
private:
- static CategoryFactory* s_Instance;
-
std::vector<Category> m_Categories;
std::map<int, unsigned int> m_IDMap;
std::map<NexusCategory, unsigned int> m_NexusMap;
diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp
index 70759419..03a7fc59 100644
--- a/src/categoriesdialog.cpp
+++ b/src/categoriesdialog.cpp
@@ -136,18 +136,19 @@ void CategoriesDialog::commitChanges()
categories->reset();
for (int i = 0; i < ui->categoriesTable->rowCount(); ++i) {
- int index = ui->categoriesTable->verticalHeader()->logicalIndex(i);
- QString nexusIDString = ui->categoriesTable->item(index, 2)->text();
- QStringList nexusIDStringList = nexusIDString.split(',', Qt::SkipEmptyParts);
- std::vector<int> nexusIDs;
- for (QStringList::iterator iter = nexusIDStringList.begin();
- iter != nexusIDStringList.end(); ++iter) {
- nexusIDs.push_back(iter->toInt());
+ int index = ui->categoriesTable->verticalHeader()->logicalIndex(i);
+ QVariantList nexusData = ui->categoriesTable->item(index, 2)->data(Qt::UserRole).toList();
+ std::vector<CategoryFactory::NexusCategory> nexusCats;
+ for (QVariantList::iterator iter = nexusData.begin();
+ iter != nexusData.end(); ++iter) {
+ QVariantList nexusInfo = iter->toList();
+ nexusCats.push_back(CategoryFactory::NexusCategory(nexusInfo[0].toString(), nexusInfo[1].toInt()));
}
categories->addCategory(
ui->categoriesTable->item(index, 0)->text().toInt(),
- ui->categoriesTable->item(index, 1)->text(), nexusIDs,
+ ui->categoriesTable->item(index, 1)->text(),
+ nexusCats,
ui->categoriesTable->item(index, 3)->text().toInt());
}
categories->setParents();
@@ -169,8 +170,8 @@ void CategoriesDialog::refreshIDs()
void CategoriesDialog::fillTable()
{
- CategoryFactory& categories = CategoryFactory::instance();
- QTableWidget* table = ui->categoriesTable;
+ CategoryFactory* categories = CategoryFactory::instance();
+ QTableWidget* table = ui->categoriesTable;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
@@ -198,9 +199,8 @@ void CategoriesDialog::fillTable()
3, new ValidatingDelegate(this, new ExistingIDValidator(m_IDs)));
int row = 0;
- for (std::vector<CategoryFactory::Category>::const_iterator iter =
- categories.m_Categories.begin();
- iter != categories.m_Categories.end(); ++iter, ++row) {
+ for (std::vector<CategoryFactory::Category>::const_iterator iter = categories->m_Categories.begin();
+ iter != categories->m_Categories.end(); ++iter, ++row) {
const CategoryFactory::Category& category = *iter;
if (category.m_ID == 0) {
--row;
@@ -213,14 +213,23 @@ void CategoriesDialog::fillTable()
idItem->setData(Qt::DisplayRole, category.m_ID);
QScopedPointer<QTableWidgetItem> nameItem(new QTableWidgetItem(category.m_Name));
- QScopedPointer<QTableWidgetItem> nexusIDItem(
- new QTableWidgetItem(MOBase::VectorJoin(category.m_NexusIDs, ",")));
+ QStringList nexusLabel;
+ QVariantList nexusData;
+ for (auto iter = category.m_NexusCats.begin(); iter < category.m_NexusCats.end(); ++iter) {
+ nexusLabel.append(iter->m_Name);
+ QVariantList data;
+ data.append(QVariant(iter->m_Name));
+ data.append(QVariant(iter->m_ID));
+ nexusData.append(data);
+ }
+ QScopedPointer<QTableWidgetItem> nexusCatItem(new QTableWidgetItem(nexusLabel.join(", ")));
+ nexusCatItem->setData(Qt::UserRole, nexusData);
QScopedPointer<QTableWidgetItem> parentIDItem(new QTableWidgetItem());
parentIDItem->setData(Qt::DisplayRole, category.m_ParentID);
table->setItem(row, 0, idItem.take());
table->setItem(row, 1, nameItem.take());
- table->setItem(row, 2, nexusIDItem.take());
+ table->setItem(row, 2, nexusCatItem.take());
table->setItem(row, 3, parentIDItem.take());
}
diff --git a/src/categoriesdialog.h b/src/categoriesdialog.h
index 2ac84124..c1c1c673 100644
--- a/src/categoriesdialog.h
+++ b/src/categoriesdialog.h
@@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define CATEGORIESDIALOG_H
#include "tutorabledialog.h"
+#include "categories.h"
#include <set>
namespace Ui
@@ -66,6 +67,8 @@ private:
int m_HighestID;
std::set<int> m_IDs;
+ std::vector<CategoryFactory::NexusCategory> m_NexusCategories;
+
};
#endif // CATEGORIESDIALOG_H
diff --git a/src/categoriesdialog.ui b/src/categoriesdialog.ui
index 582a7608..03209d53 100644
--- a/src/categoriesdialog.ui
+++ b/src/categoriesdialog.ui
@@ -6,19 +6,32 @@
<rect>
<x>0</x>
<y>0</y>
- <width>553</width>
+ <width>735</width>
<height>444</height>
</rect>
</property>
<property name="windowTitle">
<string>Categories</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="2" colspan="4">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
<widget class="QTableWidget" name="categoriesTable">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
<property name="dragEnabled">
<bool>false</bool>
</property>
@@ -26,7 +39,7 @@
<bool>false</bool>
</property>
<property name="dragDropMode">
- <enum>QAbstractItemView::NoDragDrop</enum>
+ <enum>QAbstractItemView::DropOnly</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::IgnoreAction</enum>
@@ -46,15 +59,15 @@
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
+ <attribute name="horizontalHeaderMinimumSectionSize">
+ <number>26</number>
+ </attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>100</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>true</bool>
</attribute>
- <attribute name="horizontalHeaderMinimumSectionSize">
- <number>26</number>
- </attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
@@ -85,7 +98,15 @@
</column>
<column>
<property name="text">
- <string>Nexus IDs</string>
+ <string>Parent ID</string>
+ </property>
+ <property name="toolTip">
+ <string>If set, the category is defined as a sub-category of another one. Parent ID needs to be a valid category ID.</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Nexus Categories</string>
</property>
<property name="toolTip">
<string>Comma-Separated list of Nexus IDs to be matched to the internal ID.</string>
@@ -100,24 +121,34 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;To find out a category id used by the nexus, visit the categories list of the nexus page and hover over the links there.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
- <column>
- <property name="text">
- <string>Parent ID</string>
- </property>
- <property name="toolTip">
- <string>If set, the category is defined as a sub-category of another one. Parent ID needs to be a valid category ID.</string>
- </property>
- </column>
</widget>
</item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
+ <item row="0" column="5">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
</property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ <property name="title">
+ <string>Nexus Categories</string>
</property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QListWidget" name="listWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="dragEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DragOnly</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
</layout>
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp
index 8c2ce78d..dce81bd1 100644
--- a/src/installationmanager.cpp
+++ b/src/installationmanager.cpp
@@ -659,12 +659,12 @@ InstallationResult InstallationManager::install(const QString& fileName,
modName.update(doc.toPlainText(), GUESS_FALLBACK);
modName.update(metaFile.value("modName", "").toString(), GUESS_META);
- version = metaFile.value("version", "").toString();
- newestVersion = metaFile.value("newestVersion", "").toString();
- unsigned int categoryIndex = CategoryFactory::instance().resolveNexusID(
+ version = metaFile.value("version", "").toString();
+ newestVersion = metaFile.value("newestVersion", "").toString();
+ unsigned int categoryIndex = CategoryFactory::instance()->resolveNexusID(
metaFile.value("category", 0).toInt());
- categoryID = CategoryFactory::instance().getCategoryID(categoryIndex);
- repository = metaFile.value("repository", "").toString();
+ categoryID = CategoryFactory::instance()->getCategoryID(categoryIndex);
+ repository = metaFile.value("repository", "").toString();
fileCategoryID = metaFile.value("fileCategory", 1).toInt();
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 37113954..e9106caa 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -419,7 +419,7 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore,
connect(&NexusInterface::instance(), SIGNAL(needLogin()), &m_OrganizerCore,
SLOT(nexusApi()));
- connect(m_CategoryFactory, SIGNAL(requestNexusCategories()), &m_OrganizerCore, SLOT(requestNexusCategories()));
+ connect(CategoryFactory::instance(), SIGNAL(requestNexusCategories()), &m_OrganizerCore, SLOT(requestNexusCategories()));
connect(
NexusInterface::instance(&pluginContainer)->getAccessManager(),
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index 1d30ac95..68c8ea9e 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -493,16 +493,16 @@ void ModInfo::setPluginSelected(const bool& isSelected)
void ModInfo::addCategory(const QString& categoryName)
{
- int id = CategoryFactory::instance().getCategoryID(categoryName);
+ int id = CategoryFactory::instance()->getCategoryID(categoryName);
if (id == -1) {
- id = CategoryFactory::instance().addCategory(categoryName, std::vector<int>(), 0);
+ id = CategoryFactory::instance()->addCategory(categoryName, std::vector<CategoryFactory::NexusCategory>(), 0);
}
setCategory(id, true);
}
bool ModInfo::removeCategory(const QString& categoryName)
{
- int id = CategoryFactory::instance().getCategoryID(categoryName);
+ int id = CategoryFactory::instance()->getCategoryID(categoryName);
if (id == -1) {
return false;
}
@@ -517,9 +517,9 @@ QStringList ModInfo::categories() const
{
QStringList result;
- CategoryFactory& catFac = CategoryFactory::instance();
+ CategoryFactory* catFac = CategoryFactory::instance();
for (int id : m_Categories) {
- result.append(catFac.getCategoryName(catFac.getCategoryIndex(id)));
+ result.append(catFac->getCategoryName(catFac->getCategoryIndex(id)));
}
return result;
@@ -549,7 +549,7 @@ bool ModInfo::categorySet(int categoryID) const
for (std::set<int>::const_iterator iter = m_Categories.begin();
iter != m_Categories.end(); ++iter) {
if ((*iter == categoryID) ||
- (CategoryFactory::instance().isDescendantOf(*iter, categoryID))) {
+ (CategoryFactory::instance()->isDecendantOf(*iter, categoryID))) {
return true;
}
}
diff --git a/src/modinfodialogcategories.cpp b/src/modinfodialogcategories.cpp
index a7a4ce1e..8819c0fa 100644
--- a/src/modinfodialogcategories.cpp
+++ b/src/modinfodialogcategories.cpp
@@ -44,19 +44,19 @@ bool CategoriesTab::usesOriginFiles() const
return false;
}
-void CategoriesTab::add(const CategoryFactory& factory,
- const std::set<int>& enabledCategories, QTreeWidgetItem* root,
- int rootLevel)
+void CategoriesTab::add(
+ const CategoryFactory* factory, const std::set<int>& enabledCategories,
+ QTreeWidgetItem* root, int rootLevel)
{
- for (int i = 0; i < static_cast<int>(factory.numCategories()); ++i) {
- if (factory.getParentID(i) != rootLevel) {
+ for (int i=0; i<static_cast<int>(factory->numCategories()); ++i) {
+ if (factory->getParentID(i) != rootLevel) {
continue;
}
- int categoryID = factory.getCategoryID(i);
+ int categoryID = factory->getCategoryID(i);
- QTreeWidgetItem* newItem =
- new QTreeWidgetItem(QStringList(factory.getCategoryName(i)));
+ QTreeWidgetItem* newItem
+ = new QTreeWidgetItem(QStringList(factory->getCategoryName(i)));
newItem->setFlags(newItem->flags() | Qt::ItemIsUserCheckable);
@@ -67,7 +67,7 @@ void CategoriesTab::add(const CategoryFactory& factory,
newItem->setData(0, Qt::UserRole, categoryID);
- if (factory.hasChildren(i)) {
+ if (factory->hasChildren(i)) {
add(factory, enabledCategories, newItem, categoryID);
}
diff --git a/src/modinfodialogcategories.h b/src/modinfodialogcategories.h
index 03b3555b..e73bfa32 100644
--- a/src/modinfodialogcategories.h
+++ b/src/modinfodialogcategories.h
@@ -13,8 +13,9 @@ public:
bool usesOriginFiles() const override;
private:
- void add(const CategoryFactory& factory, const std::set<int>& enabledCategories,
- QTreeWidgetItem* root, int rootLevel);
+ void add(
+ const CategoryFactory* factory, const std::set<int>& enabledCategories,
+ QTreeWidgetItem* root, int rootLevel);
void updatePrimary();
void addChecked(QTreeWidgetItem* tree);
diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp
index 4c1004e6..275b76a3 100644
--- a/src/modinforegular.cpp
+++ b/src/modinforegular.cpp
@@ -210,8 +210,7 @@ void ModInfoRegular::readMeta()
// ignore invalid id
continue;
}
- if (ok && (categoryID != 0) &&
- (CategoryFactory::instance().categoryExists(categoryID))) {
+ if (ok && (categoryID != 0) && (CategoryFactory::instance()->categoryExists(categoryID))) {
m_Categories.insert(categoryID);
if (iter == categories.begin()) {
m_PrimaryCategory = categoryID;
@@ -575,7 +574,7 @@ void ModInfoRegular::setInstallationFile(const QString& fileName)
void ModInfoRegular::addNexusCategory(int categoryID)
{
- m_Categories.insert(CategoryFactory::instance().resolveNexusID(categoryID));
+ m_Categories.insert(CategoryFactory::instance()->resolveNexusID(categoryID));
}
void ModInfoRegular::setIsEndorsed(bool endorsed)
@@ -731,15 +730,15 @@ QString ModInfoRegular::getDescription() const
const std::set<int>& categories = getCategories();
std::wostringstream categoryString;
categoryString << ToWString(tr("Categories: <br>"));
- CategoryFactory& categoryFactory = CategoryFactory::instance();
+ CategoryFactory* categoryFactory = CategoryFactory::instance();
for (std::set<int>::const_iterator catIter = categories.begin();
catIter != categories.end(); ++catIter) {
if (catIter != categories.begin()) {
categoryString << " , ";
}
categoryString << "<span style=\"white-space: nowrap;\"><i>"
- << ToWString(categoryFactory.getCategoryName(
- categoryFactory.getCategoryIndex(*catIter)))
+ << ToWString(categoryFactory->getCategoryName(
+ categoryFactory->getCategoryIndex(*catIter)))
<< "</font></span>";
}
diff --git a/src/modlist.cpp b/src/modlist.cpp
index 7a951369..41d679d9 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -232,11 +232,11 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const
} else {
int category = modInfo->primaryCategory();
if (category != -1) {
- CategoryFactory& categoryFactory = CategoryFactory::instance();
- if (categoryFactory.categoryExists(category)) {
+ CategoryFactory* categoryFactory = CategoryFactory::instance();
+ if (categoryFactory->categoryExists(category)) {
try {
- int categoryIdx = categoryFactory.getCategoryIndex(category);
- return categoryFactory.getCategoryName(categoryIdx);
+ int categoryIdx = categoryFactory->getCategoryIndex(category);
+ return categoryFactory->getCategoryName(categoryIdx);
} catch (const std::exception& e) {
log::error("failed to retrieve category name: {}", e.what());
return QString();
@@ -285,11 +285,10 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const
} else if (role == GroupingRole) {
if (column == COL_CATEGORY) {
QVariantList categoryNames;
- std::set<int> categories = modInfo->getCategories();
- CategoryFactory& categoryFactory = CategoryFactory::instance();
+ std::set<int> categories = modInfo->getCategories();
+ CategoryFactory* categoryFactory = CategoryFactory::instance();
for (auto iter = categories.begin(); iter != categories.end(); ++iter) {
- categoryNames.append(
- categoryFactory.getCategoryName(categoryFactory.getCategoryIndex(*iter)));
+ categoryNames.append(categoryFactory->getCategoryName(categoryFactory->getCategoryIndex(*iter)));
}
if (categoryNames.count() != 0) {
return categoryNames;
@@ -447,17 +446,14 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const
const std::set<int>& categories = modInfo->getCategories();
std::wostringstream categoryString;
categoryString << ToWString(tr("Categories: <br>"));
- CategoryFactory& categoryFactory = CategoryFactory::instance();
+ CategoryFactory* categoryFactory = CategoryFactory::instance();
for (std::set<int>::const_iterator catIter = categories.begin();
catIter != categories.end(); ++catIter) {
if (catIter != categories.begin()) {
categoryString << " , ";
}
try {
- categoryString << "<span style=\"white-space: nowrap;\"><i>"
- << ToWString(categoryFactory.getCategoryName(
- categoryFactory.getCategoryIndex(*catIter)))
- << "</font></span>";
+ categoryString << "<span style=\"white-space: nowrap;\"><i>" << ToWString(categoryFactory->getCategoryName(categoryFactory->getCategoryIndex(*catIter))) << "</font></span>";
} catch (const std::exception& e) {
log::error("failed to generate tooltip: {}", e.what());
return QString();
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index 704ec10b..1d54dfa4 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -125,111 +125,104 @@ bool ModListSortProxy::lessThan(const QModelIndex& left, const QModelIndex& righ
right.data(ModList::PriorityRole).toInt();
switch (left.column()) {
- case ModList::COL_FLAGS: {
- std::vector<ModInfo::EFlag> leftFlags = leftMod->getFlags();
- std::vector<ModInfo::EFlag> rightFlags = rightMod->getFlags();
- if (leftFlags.size() != rightFlags.size()) {
- lt = leftFlags.size() < rightFlags.size();
- } else {
- lt = flagsId(leftFlags) < flagsId(rightFlags);
- }
- } break;
- case ModList::COL_CONFLICTFLAGS: {
- std::vector<ModInfo::EConflictFlag> leftFlags = leftMod->getConflictFlags();
- std::vector<ModInfo::EConflictFlag> rightFlags = rightMod->getConflictFlags();
- if (leftFlags.size() != rightFlags.size()) {
- lt = leftFlags.size() < rightFlags.size();
- } else {
- lt = conflictFlagsId(leftFlags) < conflictFlagsId(rightFlags);
- }
- } break;
- case ModList::COL_CONTENT: {
- const auto& lContents = leftMod->getContents();
- const auto& rContents = rightMod->getContents();
- unsigned int lValue = 0;
- unsigned int rValue = 0;
- m_Organizer->modDataContents().forEachContentIn(
+ case ModList::COL_FLAGS: {
+ std::vector<ModInfo::EFlag> leftFlags = leftMod->getFlags();
+ std::vector<ModInfo::EFlag> rightFlags = rightMod->getFlags();
+ if (leftFlags.size() != rightFlags.size()) {
+ lt = leftFlags.size() < rightFlags.size();
+ } else {
+ lt = flagsId(leftFlags) < flagsId(rightFlags);
+ }
+ } break;
+ case ModList::COL_CONFLICTFLAGS: {
+ std::vector<ModInfo::EConflictFlag> leftFlags = leftMod->getConflictFlags();
+ std::vector<ModInfo::EConflictFlag> rightFlags = rightMod->getConflictFlags();
+ if (leftFlags.size() != rightFlags.size()) {
+ lt = leftFlags.size() < rightFlags.size();
+ } else {
+ lt = conflictFlagsId(leftFlags) < conflictFlagsId(rightFlags);
+ }
+ } break;
+ case ModList::COL_CONTENT: {
+ const auto& lContents = leftMod->getContents();
+ const auto& rContents = rightMod->getContents();
+ unsigned int lValue = 0;
+ unsigned int rValue = 0;
+ m_Organizer->modDataContents().forEachContentIn(
lContents, [&lValue](auto const& content) {
lValue += 2U << static_cast<unsigned int>(content.id());
});
- m_Organizer->modDataContents().forEachContentIn(
+ m_Organizer->modDataContents().forEachContentIn(
rContents, [&rValue](auto const& content) {
rValue += 2U << static_cast<unsigned int>(content.id());
- });
- lt = lValue < rValue;
- } break;
- case ModList::COL_NAME: {
- int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
- if (comp != 0)
- lt = comp < 0;
- } break;
- case ModList::COL_CATEGORY: {
- if (leftMod->primaryCategory() != rightMod->primaryCategory()) {
- if (leftMod->primaryCategory() < 0)
- lt = false;
- else if (rightMod->primaryCategory() < 0)
- lt = true;
- else {
- try {
- CategoryFactory& categories = CategoryFactory::instance();
- QString leftCatName = categories.getCategoryName(
- categories.getCategoryIndex(leftMod->primaryCategory()));
- QString rightCatName = categories.getCategoryName(
- categories.getCategoryIndex(rightMod->primaryCategory()));
- lt = leftCatName < rightCatName;
- } catch (const std::exception& e) {
- log::error("failed to compare categories: {}", e.what());
- }
- }
- }
- } break;
- case ModList::COL_MODID: {
- if (leftMod->nexusId() != rightMod->nexusId())
- lt = leftMod->nexusId() < rightMod->nexusId();
- } break;
- case ModList::COL_VERSION: {
- if (leftMod->version() != rightMod->version())
- lt = leftMod->version() < rightMod->version();
- } break;
- case ModList::COL_INSTALLTIME: {
- QDateTime leftTime = left.data().toDateTime();
- QDateTime rightTime = right.data().toDateTime();
- if (leftTime != rightTime)
- return leftTime < rightTime;
- } break;
- case ModList::COL_GAME: {
- if (leftMod->gameName() != rightMod->gameName()) {
- lt = leftMod->gameName() < rightMod->gameName();
- } else {
- int comp =
- QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
+ });
+ lt = lValue < rValue;
+ } break;
+ case ModList::COL_NAME: {
+ int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
if (comp != 0)
lt = comp < 0;
- }
- } break;
- case ModList::COL_NOTES: {
- QString leftComments = leftMod->comments();
- QString rightComments = rightMod->comments();
- if (leftComments != rightComments) {
- if (leftComments.isEmpty()) {
- lt = sortOrder() == Qt::DescendingOrder;
- } else if (rightComments.isEmpty()) {
- lt = sortOrder() == Qt::AscendingOrder;
+ } break;
+ case ModList::COL_CATEGORY: {
+ if (leftMod->primaryCategory() != rightMod->primaryCategory()) {
+ if (leftMod->primaryCategory() < 0)
+ lt = false;
+ else if (rightMod->primaryCategory() < 0)
+ lt = true;
+ else {
+ try {
+ CategoryFactory* categories = CategoryFactory::instance();
+ QString leftCatName = categories->getCategoryName(categories->getCategoryIndex(leftMod->primaryCategory()));
+ QString rightCatName = categories->getCategoryName(categories->getCategoryIndex(rightMod->primaryCategory()));
+ lt = leftCatName < rightCatName;
+ } catch (const std::exception& e) {
+ log::error("failed to compare categories: {}", e.what());
+ }
+ }
+ }
+ } break;
+ case ModList::COL_MODID: {
+ if (leftMod->nexusId() != rightMod->nexusId())
+ lt = leftMod->nexusId() < rightMod->nexusId();
+ } break;
+ case ModList::COL_VERSION: {
+ if (leftMod->version() != rightMod->version())
+ lt = leftMod->version() < rightMod->version();
+ } break;
+ case ModList::COL_INSTALLTIME: {
+ QDateTime leftTime = left.data().toDateTime();
+ QDateTime rightTime = right.data().toDateTime();
+ if (leftTime != rightTime)
+ return leftTime < rightTime;
+ } break;
+ case ModList::COL_GAME: {
+ if (leftMod->gameName() != rightMod->gameName()) {
+ lt = leftMod->gameName() < rightMod->gameName();
} else {
- lt = leftComments < rightComments;
+ int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
+ if (comp != 0)
+ lt = comp < 0;
+ }
+ } break;
+ case ModList::COL_NOTES: {
+ QString leftComments = leftMod->comments();
+ QString rightComments = rightMod->comments();
+ if (leftComments != rightComments) {
+ if (leftComments.isEmpty()) {
+ lt = sortOrder() == Qt::DescendingOrder;
+ } else if (rightComments.isEmpty()) {
+ lt = sortOrder() == Qt::AscendingOrder;
+ } else {
+ lt = leftComments < rightComments;
+ }
}
- }
- } break;
- case ModList::COL_PRIORITY: {
- if (leftMod->isBackup() != rightMod->isBackup()) {
- lt = leftMod->isBackup();
- } else if (leftMod->isOverwrite() != rightMod->isOverwrite()) {
- lt = rightMod->isOverwrite();
- }
- } break;
- default: {
- log::warn("Sorting is not defined for column {}", left.column());
- } break;
+ } break;
+ case ModList::COL_PRIORITY: {
+ // nop, already compared by priority
+ } break;
+ default: {
+ log::warn("Sorting is not defined for column {}", left.column());
+ } break;
}
return lt;
}