summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/categoriesdialog.cpp67
-rw-r--r--src/categoryimportdialog.cpp75
-rw-r--r--src/categoryimportdialog.h44
3 files changed, 161 insertions, 25 deletions
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 <http://www.gnu.org/licenses/>.
#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<QTableWidgetItem> idItem(new QTableWidgetItem());
- idItem->setData(Qt::DisplayRole, ++m_HighestID);
-
- QScopedPointer<QTableWidgetItem> 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<QTableWidgetItem> nexusCatItem(
new QTableWidgetItem(nexusLabel.join(", ")));
nexusCatItem->setData(Qt::UserRole, nexusData);
- QScopedPointer<QTableWidgetItem> 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<QTableWidgetItem> idItem(new QTableWidgetItem());
+ idItem->setData(Qt::DisplayRole, ++m_HighestID);
+
+ QScopedPointer<QTableWidgetItem> nameItem(new QTableWidgetItem(name));
+ QScopedPointer<QTableWidgetItem> 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<QTableWidgetItem> blankItem(new QTableWidgetItem());
+ blankItem->setData(Qt::UserRole, QVariantList());
+ table->setItem(item->row(), 3, blankItem.get());
+ }
+ }
+ }
}
refreshIDs();
}
diff --git a/src/categoryimportdialog.cpp b/src/categoryimportdialog.cpp
new file mode 100644
index 00000000..4b09c391
--- /dev/null
+++ b/src/categoryimportdialog.cpp
@@ -0,0 +1,75 @@
+#include "categoryimportdialog.h"
+#include "ui_categoryimportdialog.h"
+
+#include "organizercore.h"
+
+using namespace MOBase;
+
+CategoryImportDialog::CategoryImportDialog(QWidget* parent)
+ : QDialog(parent), ui(new Ui::CategoryImportDialog)
+{
+ ui->setupUi(this);
+ connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
+ &CategoryImportDialog::accepted);
+ connect(ui->buttonBox, &QDialogButtonBox::rejected, this,
+ &CategoryImportDialog::rejected);
+ connect(ui->strategyGroup, &QButtonGroup::buttonClicked, this,
+ &CategoryImportDialog::on_strategyClicked);
+ connect(ui->assignOption, &QCheckBox::clicked, this,
+ &CategoryImportDialog::on_assignOptionClicked);
+}
+
+void CategoryImportDialog::accepted()
+{
+ accept();
+}
+
+void CategoryImportDialog::rejected()
+{
+ reject();
+}
+
+CategoryImportDialog::~CategoryImportDialog()
+{
+ delete ui;
+}
+
+CategoryImportDialog::ImportStrategy CategoryImportDialog::strategy()
+{
+ if (ui->mergeOption->isChecked()) {
+ return ImportStrategy::Merge;
+ } else if (ui->replaceOption->isChecked()) {
+ return ImportStrategy::Overwrite;
+ }
+ return ImportStrategy::None;
+}
+
+bool CategoryImportDialog::assign()
+{
+ return ui->assignOption->isChecked();
+}
+
+bool CategoryImportDialog::remap()
+{
+ return ui->remapOption->isChecked();
+}
+
+void CategoryImportDialog::on_strategyClicked(QAbstractButton* button)
+{
+ if (button == ui->replaceOption) {
+ ui->remapOption->setChecked(false);
+ ui->remapOption->setDisabled(true);
+ } else {
+ ui->remapOption->setEnabled(true);
+ }
+}
+
+void CategoryImportDialog::on_assignOptionClicked(bool checked)
+{
+ if (checked && strategy() == ImportStrategy::Merge) {
+ ui->remapOption->setEnabled(true);
+ } else {
+ ui->remapOption->setChecked(false);
+ ui->remapOption->setDisabled(true);
+ }
+}
diff --git a/src/categoryimportdialog.h b/src/categoryimportdialog.h
new file mode 100644
index 00000000..bfc2eee4
--- /dev/null
+++ b/src/categoryimportdialog.h
@@ -0,0 +1,44 @@
+#ifndef CATEGORYIMPORTDIALOG_H
+#define CATEGORYIMPORTDIALOG_H
+
+#include <QDialog>
+
+namespace Ui
+{
+class CategoryImportDialog;
+}
+
+/**
+ * @brief Dialog that allows users to configure mod categories
+ **/
+class CategoryImportDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ enum ImportStrategy
+ {
+ None,
+ Overwrite,
+ Merge
+ };
+
+public:
+ explicit CategoryImportDialog(QWidget* parent = 0);
+ ~CategoryImportDialog();
+
+ ImportStrategy strategy();
+ bool assign();
+ bool remap();
+
+public slots:
+ void accepted();
+ void rejected();
+ void on_strategyClicked(QAbstractButton* button);
+ void on_assignOptionClicked(bool clicked);
+
+private:
+ Ui::CategoryImportDialog* ui;
+};
+
+#endif // CATEGORYIMPORTDIALOG_H