Skip to content

Commit

Permalink
Clang cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Silarn committed Sep 19, 2023
1 parent 2444096 commit f9be24f
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 252 deletions.
65 changes: 36 additions & 29 deletions src/categories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QFile>
#include <QList>
#include <QObject>
#include <QCoreApplication>

#include "nexusinterface.h"

Expand Down Expand Up @@ -85,23 +84,25 @@ 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 {}: {}").toStdString(), 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) {
bool cell0Ok = true;
bool cell3Ok = true;
int id = cells[0].toInt(&cell0Ok);
int parentID = cells[2].trimmed().toInt(&cell3Ok);
if (!cell0Ok || !cell3Ok) {
log::error(tr("invalid category line {}: {}").toStdString(), lineNum, line.constData());
}
bool cell0Ok = true;
bool cell3Ok = true;
int id = cells[0].toInt(&cell0Ok);
int parentID = cells[2].trimmed().toInt(&cell3Ok);
if (!cell0Ok || !cell3Ok) {
log::error(tr("invalid category line {}: {}").toStdString(), lineNum,
line.constData());
}

addCategory(id, QString::fromUtf8(cells[1].constData()), std::vector<NexusCategory>(), parentID);
addCategory(id, QString::fromUtf8(cells[1].constData()),
std::vector<NexusCategory>(), parentID);
} else {
log::error(
tr("invalid category line {}: {} ({} cells)").toStdString(),
lineNum, line.constData(), cells.count());
log::error(tr("invalid category line {}: {} ({} cells)").toStdString(), lineNum,
line.constData(), cells.count());
}
}
categoryFile.close();
Expand All @@ -118,29 +119,31 @@ void CategoryFactory::loadCategories()
if (nexCells.count() == 3) {
std::vector<NexusCategory> nexusCats;
QString nexName = nexCells[1];
bool ok = false;
int nexID = nexCells[2].toInt(&ok);
bool ok = false;
int nexID = nexCells[2].toInt(&ok);
if (!ok) {
log::error(tr("invalid nexus ID {}").toStdString(), 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 {}").toStdString(), nexCells[0].constData());
log::error(tr("invalid category id {}").toStdString(),
nexCells[0].constData());
}
m_NexusMap.insert_or_assign(nexID, NexusCategory(nexName, nexID));
m_NexusMap.at(nexID).m_CategoryID = catID;
} else {
log::error(
tr("invalid nexus category line {}: {} ({} cells)").toStdString(),
lineNum, nexLine.constData(), nexCells.count());
log::error(tr("invalid nexus category line {}: {} ({} cells)").toStdString(),
lineNum, nexLine.constData(), nexCells.count());
}
}
}
nexusMapFile.close();
}
std::sort(m_Categories.begin(), m_Categories.end());
setParents();
if (needLoad) loadDefaultCategories();
if (needLoad)
loadDefaultCategories();
}

CategoryFactory* CategoryFactory::instance()
Expand Down Expand Up @@ -244,7 +247,8 @@ CategoryFactory::countCategories(std::function<bool(const Category& category)> f
return result;
}

int CategoryFactory::addCategory(const QString& name, const std::vector<NexusCategory>& nexusCats,
int CategoryFactory::addCategory(const QString& name,
const std::vector<NexusCategory>& nexusCats,
int parentID)
{
int id = 1;
Expand All @@ -257,15 +261,17 @@ int CategoryFactory::addCategory(const QString& name, const std::vector<NexusCat
return id;
}

void CategoryFactory::addCategory(int id, const QString& name,
int parentID)
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, std::vector<NexusCategory>()));
m_Categories.push_back(
Category(index, id, name, parentID, std::vector<NexusCategory>()));
m_IDMap[id] = index;
}

void CategoryFactory::addCategory(int id, const QString& name, const std::vector<NexusCategory>& nexusCats, int parentID)
void CategoryFactory::addCategory(int id, const QString& name,
const std::vector<NexusCategory>& nexusCats,
int parentID)
{
for (auto nexusCat : nexusCats) {
m_NexusMap.insert_or_assign(nexusCat.m_ID, nexusCat);
Expand All @@ -276,7 +282,8 @@ void CategoryFactory::addCategory(int id, const QString& name, const std::vector
m_IDMap[id] = index;
}

void CategoryFactory::setNexusCategories(std::vector<CategoryFactory::NexusCategory>& nexusCats)
void CategoryFactory::setNexusCategories(
std::vector<CategoryFactory::NexusCategory>& nexusCats)
{
m_NexusMap.empty();
for (auto nexusCat : nexusCats) {
Expand All @@ -286,7 +293,6 @@ void CategoryFactory::setNexusCategories(std::vector<CategoryFactory::NexusCateg
saveCategories();
}


void CategoryFactory::loadDefaultCategories()
{
// the order here is relevant as it defines the order in which the
Expand Down Expand Up @@ -510,7 +516,8 @@ 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)) {
log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, m_IDMap.at(result->second.m_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);
}
}
Expand Down
38 changes: 23 additions & 15 deletions src/categories.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ 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 : public QObject {
class CategoryFactory : public QObject
{
Q_OBJECT;

friend class CategoriesDialog;
Expand All @@ -53,31 +54,37 @@ class CategoryFactory : public QObject {
};

public:
struct NexusCategory {
NexusCategory(const QString& name, const int nexusID)
: m_Name(name), m_ID(nexusID) {}
struct NexusCategory
{
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) {
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) {
friend bool operator==(const NexusCategory& LHS, const int RHS)
{
return LHS.m_ID == RHS;
}

friend bool operator<(const NexusCategory& LHS, const NexusCategory& 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, std::vector<NexusCategory> nexusCats)
: m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false), m_ParentID(parentID)
, m_NexusCats(nexusCats) {}
struct Category
{
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;
Expand Down Expand Up @@ -109,7 +116,8 @@ class CategoryFactory : public QObject {

void setNexusCategories(std::vector<CategoryFactory::NexusCategory>& nexusCats);

int addCategory(const QString& name, const std::vector<NexusCategory>& nexusCats, int parentID);
int addCategory(const QString& name, const std::vector<NexusCategory>& nexusCats,
int parentID);

/**
* @brief retrieve the number of available categories
Expand Down Expand Up @@ -223,8 +231,8 @@ class CategoryFactory : public QObject {

void loadDefaultCategories();

void addCategory(int id, const QString& name, const std::vector<NexusCategory>& nexusCats,
int parentID);
void addCategory(int id, const QString& name,
const std::vector<NexusCategory>& nexusCats, int parentID);
void addCategory(int id, const QString& name, int parentID);

void setParents();
Expand Down
15 changes: 8 additions & 7 deletions src/categoriestable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.

CategoriesTable::CategoriesTable(QWidget* parent) : QTableWidget(parent) {}

bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, Qt::DropAction action)
bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data,
Qt::DropAction action)
{
if (row == -1)
return false;
Expand All @@ -35,15 +36,15 @@ bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, Q
QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist");
QDataStream stream(&encoded, QIODevice::ReadOnly);

while (!stream.atEnd())
{
while (!stream.atEnd()) {
int curRow, curCol;
QMap<int, QVariant> roleDataMap;
stream >> curRow >> curCol >> roleDataMap;

for (auto item : findItems(roleDataMap.value(Qt::DisplayRole).toString(), Qt::MatchContains | Qt::MatchWrap))
{
if (item->column() != 3) continue;
for (auto item : findItems(roleDataMap.value(Qt::DisplayRole).toString(),
Qt::MatchContains | Qt::MatchWrap)) {
if (item->column() != 3)
continue;
QVariantList newData;
for (auto nexData : item->data(Qt::UserRole).toList()) {
if (nexData.toList()[1].toInt() != roleDataMap.value(Qt::UserRole)) {
Expand All @@ -59,7 +60,7 @@ bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, Q
}

auto nexusItem = item(row, 3);
auto itemData = nexusItem->data(Qt::UserRole).toList();
auto itemData = nexusItem->data(Qt::UserRole).toList();
QVariantList newData;
newData.append(roleDataMap.value(Qt::DisplayRole).toString());
newData.append(roleDataMap.value(Qt::UserRole).toInt());
Expand Down
8 changes: 4 additions & 4 deletions src/categoriestable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class CategoriesTable : public QTableWidget
{
Q_OBJECT
public:
CategoriesTable(QWidget *parent = 0);
CategoriesTable(QWidget* parent = 0);

protected:
virtual bool dropMimeData(int row, int column, const QMimeData* data, Qt::DropAction action);

virtual bool dropMimeData(int row, int column, const QMimeData* data,
Qt::DropAction action);
};

#endif // CATEGORIESTABLE_H
#endif // CATEGORIESTABLE_H
4 changes: 1 addition & 3 deletions src/createinstancedialogpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,7 @@ bool NamePage::checkName(QString parentDir, QString name)
return okay;
}

ProfilePage::ProfilePage(CreateInstanceDialog& dlg)
: Page(dlg)
{}
ProfilePage::ProfilePage(CreateInstanceDialog& dlg) : Page(dlg) {}

bool ProfilePage::ready() const
{
Expand Down
3 changes: 0 additions & 3 deletions src/createinstancedialogpages.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ class PathsPage : public Page
void setIfEmpty(QLineEdit* e, const QString& path, bool force);
};


// default settings for profiles page; allow the user to set their preferred
// defaults for the profile options
//
Expand All @@ -577,10 +576,8 @@ class ProfilePage : public Page
CreateInstanceDialog::ProfileSettings profileSettings() const override;

protected:

};


// nexus connection page; this reuses the ui found in the settings dialog and
// is skipped if there's already an api key in the credentials manager
//
Expand Down
10 changes: 6 additions & 4 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,10 +1323,12 @@ QString DownloadManager::getFileName(int index) const

int DownloadManager::getDownloadIndex(QString filename) const
{
auto file = std::find_if(m_ActiveDownloads.begin(), m_ActiveDownloads.end(), [=](DownloadManager::DownloadInfo *const val) {
if (val->m_FileName == filename) return true;
return false;
});
auto file = std::find_if(m_ActiveDownloads.begin(), m_ActiveDownloads.end(),
[=](DownloadManager::DownloadInfo* const val) {
if (val->m_FileName == filename)
return true;
return false;
});
if (file != m_ActiveDownloads.end()) {
int fileIndex = m_ActiveDownloads.indexOf(*file);
return fileIndex;
Expand Down
3 changes: 2 additions & 1 deletion src/modinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ void ModInfo::addCategory(const QString& categoryName)
{
int id = CategoryFactory::instance()->getCategoryID(categoryName);
if (id == -1) {
id = CategoryFactory::instance()->addCategory(categoryName, std::vector<CategoryFactory::NexusCategory>(), 0);
id = CategoryFactory::instance()->addCategory(
categoryName, std::vector<CategoryFactory::NexusCategory>(), 0);
}
setCategory(id, true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/modinforegular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ QString ModInfoRegular::getDescription() const
categoryString << " , ";
}
categoryString << "<span style=\"white-space: nowrap;\"><i>"
<< ToWString(categoryFactory->getCategoryName(categoryFactory->getCategoryIndex(*catIter)))
<< ToWString(categoryFactory->getCategoryName(
categoryFactory->getCategoryIndex(*catIter)))
<< "</font></span>";
}

Expand Down
4 changes: 3 additions & 1 deletion src/modlistcontextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ void ModListContextMenu::addRegularActions(ModInfo::Ptr mod)
}

if (mod->nexusId() > 0 && !mod->installationFile().isEmpty()) {
addAction(tr("Remap Category (From Nexus)"), [=]() { m_actions.remapCategory(m_selected); });
addAction(tr("Remap Category (From Nexus)"), [=]() {
m_actions.remapCategory(m_selected);
});
}

if (mod->nexusId() > 0 && Settings::instance().nexus().trackedIntegration()) {
Expand Down
Loading

0 comments on commit f9be24f

Please sign in to comment.