From 7c900bb1c86406669119a71bbbe156fedc8341cd Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Thu, 21 Sep 2023 21:04:45 -0500 Subject: Add new dialog for category import - Merge or replace strategies - Nexus mappings are optional - If mappings are applied, remapping is optional --- src/categoriesdialog.cpp | 67 ++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'src/categoriesdialog.cpp') diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index 4b42495e..5b6270f8 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -19,6 +19,7 @@ along with Mod Organizer. If not, see . #include "categoriesdialog.h" #include "categories.h" +#include "categoryimportdialog.h" #include "messagedialog.h" #include "nexusinterface.h" #include "settings.h" @@ -292,43 +293,59 @@ void CategoriesDialog::nexusRefresh_clicked() 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) { + auto importDialog = CategoryImportDialog(this); + if (importDialog.exec() && importDialog.strategy()) { + refreshIDs(); QTableWidget* table = ui->categoriesTable; QListWidget* list = ui->nexusCategoryList; - - table->setRowCount(0); - refreshIDs(); + if (importDialog.strategy() == CategoryImportDialog::Overwrite) { + table->setRowCount(0); + m_HighestID = 0; + } int row = 0; for (int i = 0; i < list->count(); ++i) { - row = table->rowCount(); - table->insertRow(table->rowCount()); - // table->setVerticalHeaderItem(row, new QTableWidgetItem(" ")); - - QScopedPointer idItem(new QTableWidgetItem()); - idItem->setData(Qt::DisplayRole, ++m_HighestID); - - QScopedPointer nameItem( - new QTableWidgetItem(list->item(i)->data(Qt::DisplayRole).toString())); + QString name = list->item(i)->data(Qt::DisplayRole).toString(); + int nexusID = list->item(i)->data(Qt::UserRole).toInt(); QStringList nexusLabel; QVariantList nexusData; - nexusLabel.append(list->item(i)->data(Qt::DisplayRole).toString()); + nexusLabel.append(name); QVariantList data; - data.append(QVariant(list->item(i)->data(Qt::DisplayRole).toString())); - data.append(QVariant(list->item(i)->data(Qt::UserRole).toInt())); + data.append(QVariant(name)); + data.append(QVariant(nexusID)); nexusData.insert(nexusData.size(), data); QScopedPointer nexusCatItem( new QTableWidgetItem(nexusLabel.join(", "))); nexusCatItem->setData(Qt::UserRole, nexusData); - QScopedPointer parentIDItem(new QTableWidgetItem()); - parentIDItem->setData(Qt::DisplayRole, 0); + if (!table->findItems(name, Qt::MatchExactly).size()) { + row = table->rowCount(); + table->insertRow(table->rowCount()); + // table->setVerticalHeaderItem(row, new QTableWidgetItem(" ")); - table->setItem(row, 0, idItem.take()); - table->setItem(row, 1, nameItem.take()); - table->setItem(row, 2, parentIDItem.take()); - table->setItem(row, 3, nexusCatItem.take()); + QScopedPointer idItem(new QTableWidgetItem()); + idItem->setData(Qt::DisplayRole, ++m_HighestID); + + QScopedPointer nameItem(new QTableWidgetItem(name)); + QScopedPointer parentIDItem(new QTableWidgetItem()); + parentIDItem->setData(Qt::DisplayRole, 0); // No parent + + table->setItem(row, 0, idItem.take()); + table->setItem(row, 1, nameItem.take()); + table->setItem(row, 2, parentIDItem.take()); + + if (importDialog.assign()) { + table->setItem(row, 3, nexusCatItem.take()); + } + } else { + for (auto item : table->findItems(name, Qt::MatchContains | Qt::MatchWrap)) { + if (item->column() == 1 && item->text() == name && importDialog.remap()) { + table->setItem(item->row(), 3, nexusCatItem.take()); + } else if (importDialog.remap()) { + QScopedPointer blankItem(new QTableWidgetItem()); + blankItem->setData(Qt::UserRole, QVariantList()); + table->setItem(item->row(), 3, blankItem.get()); + } + } + } } refreshIDs(); } -- cgit v1.3.1