diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/envfs.cpp | 2 | ||||
| -rw-r--r-- | src/loot.cpp | 2 | ||||
| -rw-r--r-- | src/modinfodialogconflicts.cpp | 332 | ||||
| -rw-r--r-- | src/modinfodialogconflictsmodels.cpp | 285 | ||||
| -rw-r--r-- | src/modinfodialogconflictsmodels.h | 118 | ||||
| -rw-r--r-- | src/overwriteinfodialog.cpp | 44 | ||||
| -rw-r--r-- | src/overwriteinfodialog.h | 43 | ||||
| -rw-r--r-- | src/statusbar.h | 2 |
9 files changed, 455 insertions, 376 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1430963..7452a01b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,6 +64,7 @@ SET(organizer_SRCS modinfodialog.cpp modinfodialogcategories.cpp modinfodialogconflicts.cpp + modinfodialogconflictsmodels.cpp modinfodialogesps.cpp modinfodialogfiletree.cpp modinfodialogimages.cpp @@ -198,6 +199,7 @@ SET(organizer_HDRS modinfodialog.h modinfodialogcategories.h modinfodialogconflicts.h + modinfodialogconflictsmodels.h modinfodialogesps.h modinfodialogfiletree.h modinfodialogfwd.h @@ -445,6 +447,7 @@ set(modinfo\\dialog modinfodialog modinfodialogcategories modinfodialogconflicts + modinfodialogconflictsmodels modinfodialogesps modinfodialogfiletree modinfodialogfwd diff --git a/src/envfs.cpp b/src/envfs.cpp index 4aaef082..721f561a 100644 --- a/src/envfs.cpp +++ b/src/envfs.cpp @@ -158,7 +158,7 @@ public: HandleCloserThread() : m_ready(false) { - m_handles.reserve(50'000); + m_handles.reserve(50000); } void shrink() diff --git a/src/loot.cpp b/src/loot.cpp index 3feb95c9..485afa7a 100644 --- a/src/loot.cpp +++ b/src/loot.cpp @@ -55,7 +55,7 @@ public: } private: - static const std::size_t bufferSize = 50'000; + static const std::size_t bufferSize = 50000; env::HandlePtr m_stdout; env::HandlePtr m_readEvent; 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(); diff --git a/src/modinfodialogconflictsmodels.cpp b/src/modinfodialogconflictsmodels.cpp new file mode 100644 index 00000000..e8ad19ad --- /dev/null +++ b/src/modinfodialogconflictsmodels.cpp @@ -0,0 +1,285 @@ +#include "modinfodialogconflictsmodels.h" +#include "modinfodialog.h" + +ConflictItem::ConflictItem( + QString before, QString relativeName, QString after, + MOShared::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& ConflictItem::before() const +{ + return m_before; +} + +const QString& ConflictItem::relativeName() const +{ + return m_relativeName; +} + +const QString& ConflictItem::after() const +{ + return m_after; +} + +const QString& ConflictItem::fileName() const +{ + return m_fileName; +} + +const QString& ConflictItem::altOrigin() const +{ + return m_altOrigin; +} + +bool ConflictItem::hasAlts() const +{ + return m_hasAltOrigins; +} + +bool ConflictItem::isArchive() const +{ + return m_isArchive; +} + +MOShared::FileIndex ConflictItem::fileIndex() const +{ + return m_index; +} + +bool ConflictItem::canHide() const +{ + return canHideFile(isArchive(), fileName()); +} + +bool ConflictItem::canUnhide() const +{ + return canUnhideFile(isArchive(), fileName()); +} + +bool ConflictItem::canRun() const +{ + return canRunFile(isArchive(), fileName()); +} + +bool ConflictItem::canOpen() const +{ + return canOpenFile(isArchive(), fileName()); +} + +bool ConflictItem::canPreview(PluginContainer& pluginContainer) const +{ + return canPreviewFile(pluginContainer, isArchive(), fileName()); +} + +bool ConflictItem::canExplore() const +{ + return canExploreFile(isArchive(), fileName()); +} + + +ConflictListModel::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 ConflictListModel::clear() +{ + m_items.clear(); + endResetModel(); +} + +void ConflictListModel::reserve(std::size_t s) +{ + m_items.reserve(s); +} + +QModelIndex ConflictListModel::index(int row, int col, const QModelIndex&) const +{ + return createIndex(row, col); +} + +QModelIndex ConflictListModel::parent(const QModelIndex&) const +{ + return {}; +} + +int ConflictListModel::rowCount(const QModelIndex& parent) const +{ + if (parent.isValid()) { + return 0; + } + + return static_cast<int>(m_items.size()); +} + +int ConflictListModel::columnCount(const QModelIndex&) const +{ + return static_cast<int>(m_columns.size()); +} + +QVariant ConflictListModel::data(const QModelIndex& index, int role) const +{ + 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 ConflictListModel::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 ConflictListModel::sort(int colIndex, Qt::SortOrder order) +{ + m_sortColumn = colIndex; + m_sortOrder = order; + + doSort(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); +} + +void ConflictListModel::add(ConflictItem item) +{ + m_items.emplace_back(std::move(item)); +} + +void ConflictListModel::finished() +{ + endResetModel(); + doSort(); +} + +const ConflictItem* ConflictListModel::getItem(std::size_t row) const +{ + if (row >= m_items.size()) { + return nullptr; + } + + return &m_items[row]; +} + +void ConflictListModel::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); + } +} + + +OverwriteConflictListModel::OverwriteConflictListModel(QTreeView* tree) + : ConflictListModel(tree, { + {tr("File"), &ConflictItem::relativeName}, + {tr("Overwritten Mods"), &ConflictItem::before} + }) +{ +} + + +OverwrittenConflictListModel::OverwrittenConflictListModel(QTreeView* tree) + : ConflictListModel(tree, { + {tr("File"), &ConflictItem::relativeName}, + {tr("Providing Mod"), &ConflictItem::after} + }) +{ +} + + +NoConflictListModel::NoConflictListModel(QTreeView* tree) + : ConflictListModel(tree, { + {tr("File"), &ConflictItem::relativeName} + }) +{ +} + + +AdvancedConflictListModel::AdvancedConflictListModel(QTreeView* tree) + : ConflictListModel(tree, { + {tr("Overwrites"), &ConflictItem::before}, + {tr("File"), &ConflictItem::relativeName}, + {tr("Overwritten By"), &ConflictItem::after} + }) +{ +} diff --git a/src/modinfodialogconflictsmodels.h b/src/modinfodialogconflictsmodels.h new file mode 100644 index 00000000..a37e85c8 --- /dev/null +++ b/src/modinfodialogconflictsmodels.h @@ -0,0 +1,118 @@ +#include "shared/fileentry.h" + +class PluginContainer; + +class ConflictItem +{ +public: + ConflictItem( + QString before, QString relativeName, QString after, + MOShared::FileIndex index, QString fileName, + bool hasAltOrigins, QString altOrigin, bool archive); + + const QString& before() const; + const QString& relativeName() const; + const QString& after() const; + + const QString& fileName() const; + const QString& altOrigin() const; + + bool hasAlts() const; + bool isArchive() const; + + MOShared::FileIndex fileIndex() const; + + bool canHide() const; + bool canUnhide() const; + bool canRun() const; + bool canOpen() const; + bool canPreview(PluginContainer& pluginContainer) const; + bool canExplore() const; + +private: + QString m_before; + QString m_relativeName; + QString m_after; + MOShared::FileIndex m_index; + QString m_fileName; + bool m_hasAltOrigins; + QString m_altOrigin; + bool m_isArchive; +}; + + +class ConflictListModel : public QAbstractItemModel +{ + Q_OBJECT; + +public: + struct Column + { + QString caption; + const QString& (ConflictItem::*getText)() const; + }; + + ConflictListModel(QTreeView* tree, std::vector<Column> columns); + + void clear(); + void reserve(std::size_t s); + + QModelIndex index(int row, int col, const QModelIndex& ={}) const override; + QModelIndex parent(const QModelIndex&) const override; + int rowCount(const QModelIndex& parent={}) const override; + int columnCount(const QModelIndex& ={}) const override; + QVariant data(const QModelIndex& index, int role) const override; + QVariant headerData(int col, Qt::Orientation, int role) const; + + void sort(int colIndex, Qt::SortOrder order=Qt::AscendingOrder); + void add(ConflictItem item); + + void finished(); + + const ConflictItem* getItem(std::size_t row) const; + +private: + QTreeView* m_tree; + std::vector<Column> m_columns; + std::vector<ConflictItem> m_items; + int m_sortColumn; + Qt::SortOrder m_sortOrder; + + void doSort(); +}; + + +class OverwriteConflictListModel : public ConflictListModel +{ + Q_OBJECT; + +public: + OverwriteConflictListModel(QTreeView* tree); +}; + + +class OverwrittenConflictListModel : public ConflictListModel +{ + Q_OBJECT; + +public: + OverwrittenConflictListModel(QTreeView* tree); +}; + + +class NoConflictListModel : public ConflictListModel +{ + Q_OBJECT; + +public: + NoConflictListModel(QTreeView* tree); +}; + + +class AdvancedConflictListModel : public ConflictListModel +{ + Q_OBJECT; + +public: + AdvancedConflictListModel(QTreeView* tree); +}; diff --git a/src/overwriteinfodialog.cpp b/src/overwriteinfodialog.cpp index ab726fb3..32aae07a 100644 --- a/src/overwriteinfodialog.cpp +++ b/src/overwriteinfodialog.cpp @@ -27,50 +27,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QShortcut>
#include <Shlwapi.h>
-
using namespace MOBase;
-
-class MyFileSystemModel : public QFileSystemModel {
-public:
- MyFileSystemModel(QObject *parent)
- : QFileSystemModel(parent), m_RegularColumnCount(0) {}
-
- virtual int columnCount(const QModelIndex &parent) const {
- m_RegularColumnCount = QFileSystemModel::columnCount(parent);
- return m_RegularColumnCount;
- }
-
- virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const {
- if ((orientation == Qt::Horizontal) &&
- (section >= m_RegularColumnCount)) {
- if (role == Qt::DisplayRole) {
- return tr("Overwrites");
- } else {
- return QVariant();
- }
- } else {
- return QFileSystemModel::headerData(section, orientation, role);
- }
- }
-
- virtual QVariant data(const QModelIndex &index, int role) const {
- if (index.column() == m_RegularColumnCount + 0) {
- if (role == Qt::DisplayRole) {
- return tr("not implemented");
- } else {
- return QVariant();
- }
- } else {
- return QFileSystemModel::data(index, role);
- }
- }
-
-private:
- mutable int m_RegularColumnCount;
-};
-
-
OverwriteInfoDialog::OverwriteInfoDialog(ModInfo::Ptr modInfo, QWidget *parent)
: QDialog(parent), ui(new Ui::OverwriteInfoDialog), m_FileSystemModel(nullptr),
m_DeleteAction(nullptr), m_RenameAction(nullptr), m_OpenAction(nullptr)
@@ -79,7 +37,7 @@ OverwriteInfoDialog::OverwriteInfoDialog(ModInfo::Ptr modInfo, QWidget *parent) this->setWindowModality(Qt::NonModal);
- m_FileSystemModel = new MyFileSystemModel(this);
+ m_FileSystemModel = new OverwriteFileSystemModel(this);
m_FileSystemModel->setReadOnly(false);
setModInfo(modInfo);
ui->filesView->setModel(m_FileSystemModel);
diff --git a/src/overwriteinfodialog.h b/src/overwriteinfodialog.h index bedb779a..6b3ab0ea 100644 --- a/src/overwriteinfodialog.h +++ b/src/overwriteinfodialog.h @@ -28,6 +28,49 @@ namespace Ui { class OverwriteInfoDialog;
}
+class OverwriteFileSystemModel : public QFileSystemModel
+{
+ Q_OBJECT;
+
+public:
+ OverwriteFileSystemModel(QObject *parent)
+ : QFileSystemModel(parent), m_RegularColumnCount(0) {}
+
+ virtual int columnCount(const QModelIndex &parent) const {
+ m_RegularColumnCount = QFileSystemModel::columnCount(parent);
+ return m_RegularColumnCount;
+ }
+
+ virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const {
+ if ((orientation == Qt::Horizontal) &&
+ (section >= m_RegularColumnCount)) {
+ if (role == Qt::DisplayRole) {
+ return tr("Overwrites");
+ } else {
+ return QVariant();
+ }
+ } else {
+ return QFileSystemModel::headerData(section, orientation, role);
+ }
+ }
+
+ virtual QVariant data(const QModelIndex &index, int role) const {
+ if (index.column() == m_RegularColumnCount + 0) {
+ if (role == Qt::DisplayRole) {
+ return tr("not implemented");
+ } else {
+ return QVariant();
+ }
+ } else {
+ return QFileSystemModel::data(index, role);
+ }
+ }
+
+private:
+ mutable int m_RegularColumnCount;
+};
+
+
class OverwriteInfoDialog : public QDialog
{
Q_OBJECT
diff --git a/src/statusbar.h b/src/statusbar.h index 7ff8fcbb..6e033cbd 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -33,6 +33,8 @@ private: class StatusBar : public QStatusBar { + Q_OBJECT; + public: StatusBar(QWidget* parent=nullptr); |
