summaryrefslogtreecommitdiff
path: root/src/modinfodialogconflicts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modinfodialogconflicts.cpp')
-rw-r--r--src/modinfodialogconflicts.cpp332
1 files changed, 1 insertions, 331 deletions
diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp
index b61dbb7b..06f0a31c 100644
--- a/src/modinfodialogconflicts.cpp
+++ b/src/modinfodialogconflicts.cpp
@@ -1,5 +1,6 @@
#include "modinfodialogconflicts.h"
#include "ui_modinfodialog.h"
+#include "modinfodialogconflictsmodels.h"
#include "modinfodialog.h"
#include "utility.h"
#include "settings.h"
@@ -15,337 +16,6 @@ using namespace MOBase;
// checking whether menu items apply to them, just show all of them
const std::size_t max_small_selection = 50;
-class ConflictItem
-{
-public:
- ConflictItem(
- QString before, QString relativeName, QString after,
- FileIndex index, QString fileName,
- bool hasAltOrigins, QString altOrigin, bool archive) :
- m_before(std::move(before)),
- m_relativeName(std::move(relativeName)),
- m_after(std::move(after)),
- m_index(index),
- m_fileName(std::move(fileName)),
- m_hasAltOrigins(hasAltOrigins),
- m_altOrigin(std::move(altOrigin)),
- m_isArchive(archive)
- {
- }
-
- const QString& before() const
- {
- return m_before;
- }
-
- const QString& relativeName() const
- {
- return m_relativeName;
- }
-
- const QString& after() const
- {
- return m_after;
- }
-
- const QString& fileName() const
- {
- return m_fileName;
- }
-
- const QString& altOrigin() const
- {
- return m_altOrigin;
- }
-
- bool hasAlts() const
- {
- return m_hasAltOrigins;
- }
-
- bool isArchive() const
- {
- return m_isArchive;
- }
-
- FileIndex fileIndex() const
- {
- return m_index;
- }
-
- bool canHide() const
- {
- return canHideFile(isArchive(), fileName());
- }
-
- bool canUnhide() const
- {
- return canUnhideFile(isArchive(), fileName());
- }
-
- bool canRun() const
- {
- return canRunFile(isArchive(), fileName());
- }
-
- bool canOpen() const
- {
- return canOpenFile(isArchive(), fileName());
- }
-
- bool canPreview(PluginContainer& pluginContainer) const
- {
- return canPreviewFile(pluginContainer, isArchive(), fileName());
- }
-
- bool canExplore() const
- {
- return canExploreFile(isArchive(), fileName());
- }
-
-private:
- QString m_before;
- QString m_relativeName;
- QString m_after;
- FileIndex m_index;
- QString m_fileName;
- bool m_hasAltOrigins;
- QString m_altOrigin;
- bool m_isArchive;
-};
-
-
-class ConflictListModel : public QAbstractItemModel
-{
-public:
- struct Column
- {
- QString caption;
- const QString& (ConflictItem::*getText)() const;
- };
-
- ConflictListModel(QTreeView* tree, std::vector<Column> columns) :
- m_tree(tree), m_columns(std::move(columns)),
- m_sortColumn(-1), m_sortOrder(Qt::AscendingOrder)
- {
- m_tree->setModel(this);
- }
-
- void clear()
- {
- m_items.clear();
- endResetModel();
- }
-
- void reserve(std::size_t s)
- {
- m_items.reserve(s);
- }
-
- QModelIndex index(int row, int col, const QModelIndex& ={}) const override
- {
- return createIndex(row, col);
- }
-
- QModelIndex parent(const QModelIndex&) const override
- {
- return {};
- }
-
- int rowCount(const QModelIndex& parent={}) const override
- {
- if (parent.isValid()) {
- return 0;
- }
-
- return static_cast<int>(m_items.size());
- }
-
- int columnCount(const QModelIndex& ={}) const override
- {
- return static_cast<int>(m_columns.size());
- }
-
- QVariant data(const QModelIndex& index, int role) const override
- {
- if (role == Qt::DisplayRole || role == Qt::FontRole) {
- const auto row = index.row();
- if (row < 0) {
- return {};
- }
-
- const auto i = static_cast<std::size_t>(row);
- if (i >= m_items.size()) {
- return {};
- }
-
- const auto col = index.column();
- if (col < 0) {
- return {};
- }
-
- const auto c = static_cast<std::size_t>(col);
- if (c >= m_columns.size()) {
- return {};
- }
-
- const auto& item = m_items[i];
-
- if (role == Qt::DisplayRole) {
- return (item.*m_columns[c].getText)();
- } else if (role == Qt::FontRole) {
- if (item.isArchive()) {
- QFont f = m_tree->font();
- f.setItalic(true);
- return f;
- }
- }
- }
-
- return {};
- }
-
- QVariant headerData(int col, Qt::Orientation, int role) const
- {
- if (role == Qt::DisplayRole) {
- if (col < 0) {
- return {};
- }
-
- const auto i = static_cast<std::size_t>(col);
- if (i >= m_columns.size()) {
- return {};
- }
-
- return m_columns[i].caption;
- }
-
- return {};
- }
-
- void sort(int colIndex, Qt::SortOrder order=Qt::AscendingOrder)
- {
- m_sortColumn = colIndex;
- m_sortOrder = order;
-
- doSort();
- emit layoutChanged({}, QAbstractItemModel::VerticalSortHint);
- }
-
- void add(ConflictItem item)
- {
- m_items.emplace_back(std::move(item));
- }
-
- void finished()
- {
- endResetModel();
- doSort();
- }
-
- const ConflictItem* getItem(std::size_t row) const
- {
- if (row >= m_items.size()) {
- return nullptr;
- }
-
- return &m_items[row];
- }
-
-private:
- QTreeView* m_tree;
- std::vector<Column> m_columns;
- std::vector<ConflictItem> m_items;
- int m_sortColumn;
- Qt::SortOrder m_sortOrder;
-
- void doSort()
- {
- if (m_items.empty()) {
- return;
- }
-
- if (m_sortColumn < 0) {
- return;
- }
-
- const auto c = static_cast<std::size_t>(m_sortColumn);
- if (c >= m_columns.size()) {
- return;
- }
-
- const auto& col = m_columns[c];
-
- // avoids branching on sort order while sorting
- auto sortAsc = [&](const auto& a, const auto& b) {
- return (naturalCompare((a.*col.getText)(), (b.*col.getText)()) < 0);
- };
-
- auto sortDesc = [&](const auto& a, const auto& b) {
- return (naturalCompare((a.*col.getText)(), (b.*col.getText)()) > 0);
- };
-
- if (m_sortOrder == Qt::AscendingOrder) {
- std::sort(m_items.begin(), m_items.end(), sortAsc);
- } else {
- std::sort(m_items.begin(), m_items.end(), sortDesc);
- }
- }
-};
-
-
-class OverwriteConflictListModel : public ConflictListModel
-{
-public:
- OverwriteConflictListModel(QTreeView* tree)
- : ConflictListModel(tree, {
- {tr("File"), &ConflictItem::relativeName},
- {tr("Overwritten Mods"), &ConflictItem::before}
- })
- {
- }
-};
-
-
-class OverwrittenConflictListModel : public ConflictListModel
-{
-public:
- OverwrittenConflictListModel(QTreeView* tree)
- : ConflictListModel(tree, {
- {tr("File"), &ConflictItem::relativeName},
- {tr("Providing Mod"), &ConflictItem::after}
- })
- {
- }
-};
-
-
-class NoConflictListModel : public ConflictListModel
-{
-public:
- NoConflictListModel(QTreeView* tree)
- : ConflictListModel(tree, {
- {tr("File"), &ConflictItem::relativeName}
- })
- {
- }
-};
-
-
-class AdvancedConflictListModel : public ConflictListModel
-{
-public:
- AdvancedConflictListModel(QTreeView* tree)
- : ConflictListModel(tree, {
- {tr("Overwrites"), &ConflictItem::before},
- {tr("File"), &ConflictItem::relativeName},
- {tr("Overwritten By"), &ConflictItem::after}
- })
- {
- }
-};
-
-
std::size_t smallSelectionSize(const QTreeView* tree)
{
const std::size_t too_many = std::numeric_limits<std::size_t>::max();