diff options
| author | Silarn <jrim@rimpo.org> | 2019-12-31 02:42:00 -0600 |
|---|---|---|
| committer | Jeremy Rimpo <jeremy.rimpo@servermonkey.com> | 2023-09-21 17:11:59 -0500 |
| commit | 2f7478f8fc3ab047eaab44cd666bcc06bf15a127 (patch) | |
| tree | 3788291a5fd73032263fdf0eb5649e8590bd060e | |
| parent | f764271b1f1fa457af9dd4f7d044005d46fcd84b (diff) | |
WIP: Fix data storage and fix loading
| -rw-r--r-- | src/categories.cpp | 62 | ||||
| -rw-r--r-- | src/categories.h | 3 | ||||
| -rw-r--r-- | src/categoriesdialog.cpp | 103 | ||||
| -rw-r--r-- | src/categoriesdialog.h | 1 | ||||
| -rw-r--r-- | src/categoriesdialog.ui | 49 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 61 | ||||
| -rw-r--r-- | src/mainwindow.h | 7 |
7 files changed, 210 insertions, 76 deletions
diff --git a/src/categories.cpp b/src/categories.cpp index cf8008e5..59b26c07 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -114,18 +114,25 @@ void CategoryFactory::loadCategories() QByteArray nexLine = nexusMapFile.readLine(); ++nexLineNum; QList<QByteArray> nexCells = nexLine.split('|'); - std::vector<NexusCategory> nexusCats; - QString nexName = nexCells[1]; - bool ok = false; - int nexID = nexCells[2].toInt(&ok); - if (!ok) { - 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()); + if (nexCells.count() == 3) { + std::vector<NexusCategory> nexusCats; + QString nexName = nexCells[1]; + bool ok = false; + int nexID = nexCells[2].toInt(&ok); + if (!ok) { + 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()); + } + 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()); } - m_NexusMap[NexusCategory(nexName, nexID)] = catID; } } nexusMapFile.close(); @@ -206,14 +213,14 @@ void CategoryFactory::saveCategories() } nexusMapFile.resize(0); - QByteArray line; for (auto iter = m_NexusMap.begin(); iter != m_NexusMap.end(); ++iter) { - line.append(iter->first.m_Name).append("|"); - line.append(iter->first.m_ID).append("|"); - line.append(iter->second).append("\n"); - categoryFile.write(line); + 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"); + nexusMapFile.write(line); } - categoryFile.close(); + nexusMapFile.close(); } unsigned int @@ -250,7 +257,8 @@ void CategoryFactory::addCategory(int id, const QString& name, int parentID) void CategoryFactory::addCategory(int id, const QString& name, const std::vector<NexusCategory>& nexusCats, int parentID) { for (auto nexusCat : nexusCats) { - m_NexusMap[nexusCat] = id; + m_NexusMap.insert_or_assign(nexusCat.m_ID, nexusCat); + m_NexusMap.at(nexusCat.m_ID).m_CategoryID = id; } int index = static_cast<int>(m_Categories.size()); m_Categories.push_back(Category(index, id, name, parentID, nexusCats)); @@ -262,11 +270,11 @@ void CategoryFactory::loadDefaultCategories() { // the order here is relevant as it defines the order in which the // mods appear in the combo box - if (QMessageBox::question(nullptr, tr("Load Nexus Categories?"), - tr("This is either a new or old instance which lacks modern Nexus category mappings. Would you like to import and map categories from Nexus now?"), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit requestNexusCategories(); - } + //if (QMessageBox::question(nullptr, tr("Load Nexus Categories?"), + // tr("This is either a new or old instance which lacks modern Nexus category mappings. Would you like to import and map categories from Nexus now?"), + // QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + // emit requestNexusCategories(); + //} } @@ -432,12 +440,10 @@ int CategoryFactory::getCategoryID(const QString& name) const unsigned int CategoryFactory::resolveNexusID(int nexusID) const { - auto result = std::find_if(m_NexusMap.begin(), m_NexusMap.end(), [nexusID](const std::pair<NexusCategory, unsigned int> el) { - return el.first.m_ID == nexusID; - }); + auto result = m_NexusMap.find(nexusID); if (result != m_NexusMap.end()) { - log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, result->second); - return result->second; + log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, result->second.m_ID); + return m_IDMap.at(result->second.m_CategoryID); } else { log::debug(tr("nexus category id {} not mapped").toStdString(), nexusID); return 0U; diff --git a/src/categories.h b/src/categories.h index e9f00726..63d72672 100644 --- a/src/categories.h +++ b/src/categories.h @@ -58,6 +58,7 @@ public: : 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; @@ -232,7 +233,7 @@ private: private: std::vector<Category> m_Categories; std::map<int, unsigned int> m_IDMap; - std::map<NexusCategory, unsigned int> m_NexusMap; + std::map<int, NexusCategory> m_NexusMap; private: // called by isDescendantOf() diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index 08397cb8..a94484ae 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -109,7 +109,9 @@ CategoriesDialog::CategoriesDialog(PluginContainer* pluginContainer, QWidget* pa ui->setupUi(this); fillTable(); connect(ui->categoriesTable, SIGNAL(cellChanged(int, int)), this, - SLOT(cellChanged(int, int))); + SLOT(cellChanged(int,int))); + connect(ui->nexusRefresh, SIGNAL(clicked()), this, SLOT(nexusRefresh_clicked())); + connect(ui->nexusImportButton, SIGNAL(clicked()), this, SLOT(nexusImport_clicked())); } CategoriesDialog::~CategoriesDialog() @@ -138,19 +140,17 @@ void CategoriesDialog::commitChanges() for (int i = 0; i < ui->categoriesTable->rowCount(); ++i) { int index = ui->categoriesTable->verticalHeader()->logicalIndex(i); - QVariantList nexusData = ui->categoriesTable->item(index, 2)->data(Qt::UserRole).toList(); + QVariantList nexusData = ui->categoriesTable->item(index, 3)->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())); + for (auto nexusCat : nexusData) { + nexusCats.push_back(CategoryFactory::NexusCategory(nexusCat.toList()[0].toString(), nexusCat.toList()[1].toInt())); } categories->addCategory( ui->categoriesTable->item(index, 0)->text().toInt(), ui->categoriesTable->item(index, 1)->text(), nexusCats, - ui->categoriesTable->item(index, 3)->text().toInt()); + ui->categoriesTable->item(index, 2)->text().toInt()); } categories->setParents(); @@ -179,12 +179,12 @@ void CategoriesDialog::fillTable() table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed); table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); table->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed); - table->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed); + table->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); table->verticalHeader()->setSectionsMovable(true); table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); table->setItemDelegateForColumn(0, new ValidatingDelegate(this, new NewIDValidator(m_IDs))); - table->setItemDelegateForColumn(2, new ValidatingDelegate(this, new QRegExpValidator(QRegExp("([0-9]+)?(,[0-9]+)*"), this))); - table->setItemDelegateForColumn(3, new ValidatingDelegate(this, new ExistingIDValidator(m_IDs))); + table->setItemDelegateForColumn(2, new ValidatingDelegate(this, new ExistingIDValidator(m_IDs))); + table->setItemDelegateForColumn(3, new ValidatingDelegate(this, new QRegExpValidator(QRegExp("([0-9]+)?(,[0-9]+)*"), this))); int row = 0; for (std::vector<CategoryFactory::Category>::const_iterator iter = categories->m_Categories.begin(); @@ -201,32 +201,36 @@ void CategoriesDialog::fillTable() idItem->setData(Qt::DisplayRole, category.m_ID); QScopedPointer<QTableWidgetItem> nameItem(new QTableWidgetItem(category.m_Name)); - 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); + QScopedPointer<QTableWidgetItem> nexusCatItem(new QTableWidgetItem()); table->setItem(row, 0, idItem.take()); table->setItem(row, 1, nameItem.take()); - table->setItem(row, 2, nexusCatItem.take()); - table->setItem(row, 3, parentIDItem.take()); + table->setItem(row, 2, parentIDItem.take()); + table->setItem(row, 3, nexusCatItem.take()); } for (auto nexusCat : categories->m_NexusMap) { QScopedPointer<QListWidgetItem> nexusItem(new QListWidgetItem()); - nexusItem->setData(Qt::DisplayRole, nexusCat.first.m_Name); - nexusItem->setData(Qt::UserRole, nexusCat.first.m_ID); + nexusItem->setData(Qt::DisplayRole, nexusCat.second.m_Name); + nexusItem->setData(Qt::UserRole, nexusCat.second.m_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); + itemData.insert(itemData.length(), newData); + QStringList names; + for (auto cat : itemData) { + names.append(categories->getCategoryName(categories->resolveNexusID(cat.toList()[1].toInt()))); + } + item->setData(Qt::UserRole, itemData); + item->setData(Qt::DisplayRole, names.join(", ")); + } } refreshIDs(); @@ -240,8 +244,8 @@ void CategoriesDialog::addCategory_clicked() ui->categoriesTable->setItem(row, 0, new QTableWidgetItem(QString::number(++m_HighestID))); ui->categoriesTable->setItem(row, 1, new QTableWidgetItem("new")); - ui->categoriesTable->setItem(row, 2, new QTableWidgetItem("")); - ui->categoriesTable->setItem(row, 3, new QTableWidgetItem("0")); + ui->categoriesTable->setItem(row, 2, new QTableWidgetItem("0")); + ui->categoriesTable->setItem(row, 3, new QTableWidgetItem("")); } void CategoriesDialog::removeCategory_clicked() @@ -256,10 +260,53 @@ void CategoriesDialog::nexusRefresh_clicked() nexus->requestGameInfo(Settings::instance().game().plugin()->gameShortName(), this, QVariant(), QString()); } + +void CategoriesDialog::nexusImport_clicked() +{ + if (QMessageBox::question(nullptr, tr("Import Nexus Categories?"), + tr("This will overwrite your existing categories with the loaded Nexus categories."), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + QTableWidget* table = ui->categoriesTable; + QListWidget* list = ui->nexusCategoryList; + + table->setRowCount(0); + refreshIDs(); + int row = 0; + for (int i = 0; i < list->count(); ++i) { + row = table->rowCount(); + table->insertRow(table->rowCount()); + // table->setVerticalHeaderItem(row, new QTableWidgetItem(" ")); + + QScopedPointer<QTableWidgetItem> idItem(new QTableWidgetItem()); + idItem->setData(Qt::DisplayRole, ++m_HighestID); + + QScopedPointer<QTableWidgetItem> nameItem(new QTableWidgetItem(list->item(i)->data(Qt::DisplayRole).toString())); + QStringList nexusLabel; + QVariantList nexusData; + nexusLabel.append(list->item(i)->data(Qt::DisplayRole).toString()); + QVariantList data; + data.append(QVariant(list->item(i)->data(Qt::DisplayRole).toString())); + data.append(QVariant(list->item(i)->data(Qt::UserRole).toInt())); + nexusData.insert(nexusData.size(), data); + QScopedPointer<QTableWidgetItem> nexusCatItem(new QTableWidgetItem(nexusLabel.join(", "))); + nexusCatItem->setData(Qt::UserRole, nexusData); + QScopedPointer<QTableWidgetItem> parentIDItem(new QTableWidgetItem()); + parentIDItem->setData(Qt::DisplayRole, 0); + + table->setItem(row, 0, idItem.take()); + table->setItem(row, 1, nameItem.take()); + table->setItem(row, 2, parentIDItem.take()); + table->setItem(row, 3, nexusCatItem.take()); + } + refreshIDs(); + } +} + + void CategoriesDialog::nxmGameInfoAvailable(QString gameName, QVariant, QVariant resultData, int) { QVariantMap result = resultData.toMap(); - QVariantList categories = result["categories"].toList().first().toList(); + QVariantList categories = result["categories"].toList(); auto catFactory = CategoryFactory::instance(); QListWidget* list = ui->nexusCategoryList; list->clear(); diff --git a/src/categoriesdialog.h b/src/categoriesdialog.h index b6fe832f..49749a0f 100644 --- a/src/categoriesdialog.h +++ b/src/categoriesdialog.h @@ -64,6 +64,7 @@ private slots: void addCategory_clicked(); void removeCategory_clicked(); void nexusRefresh_clicked(); + void nexusImport_clicked(); void cellChanged(int row, int column); private: diff --git a/src/categoriesdialog.ui b/src/categoriesdialog.ui index 993de2ad..d2fbf537 100644 --- a/src/categoriesdialog.ui +++ b/src/categoriesdialog.ui @@ -14,6 +14,36 @@ <string>Categories</string>
</property>
<layout class="QGridLayout" name="gridLayout">
+ <item row="4" column="3">
+ <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="4" column="5">
+ <widget class="QPushButton" name="nexusRefresh">
+ <property name="text">
+ <string>Refresh from Nexus</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="4">
+ <widget class="QPushButton" name="nexusImportButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string><-- Import Nexus Cats</string>
+ </property>
+ </widget>
+ </item>
<item row="0" column="3">
<widget class="QTableWidget" name="categoriesTable">
<property name="contextMenuPolicy">
@@ -113,17 +143,7 @@ p, li { white-space: pre-wrap; } </column>
</widget>
</item>
- <item row="4" column="3">
- <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="5">
+ <item row="0" column="4" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
@@ -151,13 +171,6 @@ p, li { white-space: pre-wrap; } </layout>
</widget>
</item>
- <item row="4" column="5">
- <widget class="QPushButton" name="nexusRefresh">
- <property name="text">
- <string>Refresh Nexus Categories</string>
- </property>
- </widget>
- </item>
</layout>
</widget>
<resources/>
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2b653059..76b7e37f 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(CategoryFactory::instance(), SIGNAL(requestNexusCategories()), &m_OrganizerCore, SLOT(requestNexusCategories())); + connect(CategoryFactory::instance(), SIGNAL(requestNexusCategories()), this, SLOT(requestNexusCategories())); connect( NexusInterface::instance(&pluginContainer)->getAccessManager(), @@ -3913,6 +3913,65 @@ void MainWindow::originModified(int originID) DirectoryRefresher::cleanStructure(m_OrganizerCore.directoryStructure()); } + +void MainWindow::enableSelectedPlugins_clicked() +{ + m_OrganizerCore.pluginList()->enableSelected(ui->espList->selectionModel()); +} + + +void MainWindow::disableSelectedPlugins_clicked() +{ + m_OrganizerCore.pluginList()->disableSelected(ui->espList->selectionModel()); +} + +void MainWindow::sendSelectedPluginsToTop_clicked() +{ + m_OrganizerCore.pluginList()->sendToPriority(ui->espList->selectionModel(), 0); +} + +void MainWindow::sendSelectedPluginsToBottom_clicked() +{ + m_OrganizerCore.pluginList()->sendToPriority(ui->espList->selectionModel(), INT_MAX); +} + +void MainWindow::sendSelectedPluginsToPriority_clicked() +{ + bool ok; + int newPriority = QInputDialog::getInt(this, + tr("Set Priority"), tr("Set the priority of the selected plugins"), + 0, 0, INT_MAX, 1, &ok); + if (!ok) return; + + m_OrganizerCore.pluginList()->sendToPriority(ui->espList->selectionModel(), newPriority); +} + +void MainWindow::requestNexusCategories() +{ + CategoriesDialog dialog(&m_PluginContainer, this); + + if (dialog.exec() == QDialog::Accepted) { + dialog.commitChanges(); + } +} + +void MainWindow::enableSelectedMods_clicked() +{ + m_OrganizerCore.modList()->enableSelected(ui->modList->selectionModel()); + if (m_ModListSortProxy != nullptr) { + m_ModListSortProxy->invalidate(); + } +} + + +void MainWindow::disableSelectedMods_clicked() +{ + m_OrganizerCore.modList()->disableSelected(ui->modList->selectionModel()); + if (m_ModListSortProxy != nullptr) { + m_ModListSortProxy->invalidate(); + } +} + void MainWindow::updateAvailable() { ui->actionUpdate->setEnabled(true); diff --git a/src/mainwindow.h b/src/mainwindow.h index 42ffc83e..50ff893f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -157,6 +157,13 @@ public: public slots: void refresherProgress(const DirectoryRefreshProgress* p); + void directory_refreshed(); + + void toolPluginInvoke(); + void modPagePluginInvoke(); + + void requestNexusCategories(); + signals: // emitted after the information dialog has been closed, used by tutorials // |
