diff options
| author | Tannin <Tannin@Miranda> | 2013-02-16 19:09:57 +0100 |
|---|---|---|
| committer | Tannin <Tannin@Miranda> | 2013-02-16 19:09:57 +0100 |
| commit | 5d1154c24e2475ed2b7ac248de27ab7b501a1e5e (patch) | |
| tree | 265341b9c8d057da46b56ad9fde40c9b39963ebb /src/modlistsortproxy.cpp | |
| parent | 44b96e6fb5f484e9a60fe03b99021a1c5f78488d (diff) | |
- hooks for CreateHardLink
- createprocess hook will now reroute the cwd (fixes SUM, may break other tools?)
- profile code moved to separate file
- executables can now be linked to toolbar
- category filters are now represented as a tree
- csv export of mod list
- ModInfoDialog is now "window modal" instead of "application modal"
- nexus dialog now updates the mod-id field while browsing
- right-click in nexus browser allows to open in external browser
- ini viewer is no longer modal
- bugfix: another attempt to fix processing of invalid header lines in fomod xmls (bom now handled)
- bugfix: integrated fomod installer will no longer overwrite detected mod name by the one from the xml
- bugfix: "hide file" from conflicted files list now updates that list
- bugfix: conflicted files list no longer offers to hide files in BSAs
- bugfix: pressing delete on the mod list with multiplie files selected offered to delete the wrong files
- regression: mod name guessing with the old regular expression was less likely to lead to an empty mod name. Now both are tried
Diffstat (limited to 'src/modlistsortproxy.cpp')
| -rw-r--r-- | src/modlistsortproxy.cpp | 425 |
1 files changed, 215 insertions, 210 deletions
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index de1e3230..bf70f238 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -17,213 +17,218 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. */ -#include "modlistsortproxy.h"
-#include "modinfo.h"
-#include "profile.h"
-#include "modlist.h"
-#include <QMenu>
-#include <QCheckBox>
-#include <QWidgetAction>
-#include <QMessageBox>
-
-
-ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent)
- : QSortFilterProxyModel(parent), m_Profile(profile),
- m_CategoryFilter(CategoryFactory::CATEGORY_NONE), m_CurrentFilter()
-{
- m_EnabledColumns.set(ModList::COL_FLAGS);
- m_EnabledColumns.set(ModList::COL_NAME);
- m_EnabledColumns.set(ModList::COL_VERSION);
- m_EnabledColumns.set(ModList::COL_PRIORITY);
- setDynamicSortFilter(true); // this seems to work without dynamicsortfilter
- // but I don't know why. This should be necessary
-}
-
-
-void ModListSortProxy::setProfile(Profile *profile)
-{
- m_Profile = profile;
-}
-
-
-void ModListSortProxy::setCategoryFilter(int category)
-{
- m_CategoryFilter = category;
- this->invalidate();
-}
-
-
-Qt::ItemFlags ModListSortProxy::flags(const QModelIndex &modelIndex) const
-{
- Qt::ItemFlags flags = sourceModel()->flags(mapToSource(modelIndex));
- if (sortColumn() != ModList::COL_PRIORITY) {
- flags &= ~Qt::ItemIsDragEnabled;
- }
- return flags;
-}
-
-
-
-void ModListSortProxy::displayColumnSelection(const QPoint &pos)
-{
- QMenu menu;
-
- for (int i = 0; i <= ModList::COL_LASTCOLUMN; ++i) {
- QCheckBox *checkBox = new QCheckBox(&menu);
- checkBox->setText(ModList::getColumnName(i));
- checkBox->setChecked(m_EnabledColumns.test(i) ? Qt::Checked : Qt::Unchecked);
- QWidgetAction *checkableAction = new QWidgetAction(&menu);
- checkableAction->setDefaultWidget(checkBox);
- menu.addAction(checkableAction);
- }
- menu.exec(pos);
- int i = 0;
-
- emit layoutAboutToBeChanged();
- m_EnabledColumns.reset();
- foreach (const QAction *action, menu.actions()) {
- const QWidgetAction *widgetAction = qobject_cast<const QWidgetAction*>(action);
- if (widgetAction != NULL) {
- const QCheckBox *checkBox = qobject_cast<const QCheckBox*>(widgetAction->defaultWidget());
- if (checkBox != NULL) {
- m_EnabledColumns.set(i, checkBox->checkState() == Qt::Checked);
- }
- }
- ++i;
- }
- emit layoutChanged();
-}
-
-
-void ModListSortProxy::enableAllVisible()
-{
- if (m_Profile == NULL) return;
-
- for (int i = 0; i < this->rowCount(); ++i) {
- int modID = mapToSource(index(i, 0)).row();
- m_Profile->setModEnabled(modID, true);
- }
-}
-
-
-void ModListSortProxy::disableAllVisible()
-{
- if (m_Profile == NULL) return;
- for (int i = 0; i < this->rowCount(); ++i) {
- int modID = mapToSource(index(i, 0)).row();
- m_Profile->setModEnabled(modID, false);
- }
-}
-
-
-bool ModListSortProxy::lessThan(const QModelIndex &left,
- const QModelIndex &right) const
-{
- int leftIndex = left.internalId();
- int rightIndex = right.internalId();
- ModInfo::Ptr leftMod = ModInfo::getByIndex(leftIndex);
- ModInfo::Ptr rightMod = ModInfo::getByIndex(rightIndex);
-
- bool lt = false;
- switch (left.column()) {
- case ModList::COL_FLAGS: lt = leftMod->getFlags().size() < rightMod->getFlags().size(); break;
- case ModList::COL_NAME: lt = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive) < 0; break;
- case ModList::COL_CATEGORY: {
- if (leftMod->getPrimaryCategory() < 0) lt = false;
- else if (rightMod->getPrimaryCategory() < 0) lt = true;
- else {
- try {
- CategoryFactory &categories = CategoryFactory::instance();
- QString leftCatName = categories.getCategoryName(categories.getCategoryIndex(leftMod->getPrimaryCategory()));
- QString rightCatName = categories.getCategoryName(categories.getCategoryIndex(rightMod->getPrimaryCategory()));
- lt = leftCatName < rightCatName;
- } catch (const std::exception &e) {
- qCritical("failed to compare categories: %s", e.what());
- }
- }
- } break;
- case ModList::COL_MODID: lt = leftMod->getNexusID() < rightMod->getNexusID(); break;
- case ModList::COL_VERSION: lt = leftMod->getVersion() < rightMod->getVersion(); break;
- case ModList::COL_PRIORITY: {
- if (m_Profile != NULL) {
- int leftPrio = leftMod->getFixedPriority();
- int rightPrio = rightMod->getFixedPriority();
- if (leftPrio == INT_MIN) leftPrio = m_Profile->getModPriority(leftIndex);
- if (rightPrio == INT_MIN) rightPrio = m_Profile->getModPriority(rightIndex);
-
- lt = leftPrio < rightPrio;
- } else {
- lt = leftMod->name() < rightMod->name();
- }
- } break;
- }
- return lt;
-}
-
-
-void ModListSortProxy::updateFilter(const QString &filter)
-{
- m_CurrentFilter = filter;
- invalidateFilter();
-}
-
-
-bool ModListSortProxy::hasConflictFlag(const std::vector<ModInfo::EFlag> &flags) const
-{
- foreach (ModInfo::EFlag flag, flags) {
- if ((flag == ModInfo::FLAG_CONFLICT_MIXED) ||
- (flag == ModInfo::FLAG_CONFLICT_OVERWRITE) ||
- (flag == ModInfo::FLAG_CONFLICT_OVERWRITTEN) ||
- (flag == ModInfo::FLAG_CONFLICT_REDUNDANT)) {
- return true;
- }
- }
-
- return false;
-}
-
-
-bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex&) const
-{
- ModInfo::Ptr modInfo = ModInfo::getByIndex(row);
-
- if (!m_CurrentFilter.isEmpty() &&
- !modInfo->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) {
- return false;
- }
-
- bool modEnabled = m_Profile != NULL ? m_Profile->modEnabled(row) : false;
- return ((m_CategoryFilter == CategoryFactory::CATEGORY_NONE) ||
- ((m_CategoryFilter < CategoryFactory::CATEGORY_SPECIAL_FIRST) && (modInfo->categorySet(m_CategoryFilter))) ||
- ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_CHECKED) && modEnabled) ||
- ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_UNCHECKED) && !modEnabled) ||
- ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) && modInfo->updateAvailable()) ||
- ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY) && (modInfo->getCategories().size() == 0)) ||
- ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_CONFLICT) && (hasConflictFlag(modInfo->getFlags()))));
-}
-
-
-/*bool ModListSortProxy::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const
-{
- return m_EnabledColumns.test(source_column);
-}*/
-
-
-bool ModListSortProxy::dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent)
-{
- if ((row == -1) && (column == -1)) {
- return this->sourceModel()->dropMimeData(data, action, -1, -1, mapToSource(parent));
- }
- // in the regular model, when dropping between rows, the row-value passed to
- // the sourceModel is inconsistent between ascending and descending ordering.
- // This should fix that
- if (sortOrder() == Qt::DescendingOrder) {
- --row;
- }
-
- QModelIndex proxyIndex = index(row, column, parent);
- QModelIndex sourceIndex = mapToSource(proxyIndex);
- return this->sourceModel()->dropMimeData(data, action, sourceIndex.row(), sourceIndex.column(),
- sourceIndex.parent());
-}
+#include "modlistsortproxy.h" +#include "modinfo.h" +#include "profile.h" +#include "modlist.h" +#include <QMenu> +#include <QCheckBox> +#include <QWidgetAction> +#include <QMessageBox> + + +ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent) + : QSortFilterProxyModel(parent), m_Profile(profile), + m_CategoryFilter(CategoryFactory::CATEGORY_NONE), m_CurrentFilter() +{ + m_EnabledColumns.set(ModList::COL_FLAGS); + m_EnabledColumns.set(ModList::COL_NAME); + m_EnabledColumns.set(ModList::COL_VERSION); + m_EnabledColumns.set(ModList::COL_PRIORITY); + setDynamicSortFilter(true); // this seems to work without dynamicsortfilter + // but I don't know why. This should be necessary +} + + +void ModListSortProxy::setProfile(Profile *profile) +{ + m_Profile = profile; +} + + +void ModListSortProxy::setCategoryFilter(int category) +{ + m_CategoryFilter = category; + this->invalidate(); +} + + +Qt::ItemFlags ModListSortProxy::flags(const QModelIndex &modelIndex) const +{ + Qt::ItemFlags flags = sourceModel()->flags(mapToSource(modelIndex)); + if (sortColumn() != ModList::COL_PRIORITY) { + flags &= ~Qt::ItemIsDragEnabled; + } + return flags; +} + + + +void ModListSortProxy::displayColumnSelection(const QPoint &pos) +{ + QMenu menu; + + for (int i = 0; i <= ModList::COL_LASTCOLUMN; ++i) { + QCheckBox *checkBox = new QCheckBox(&menu); + checkBox->setText(ModList::getColumnName(i)); + checkBox->setChecked(m_EnabledColumns.test(i) ? Qt::Checked : Qt::Unchecked); + QWidgetAction *checkableAction = new QWidgetAction(&menu); + checkableAction->setDefaultWidget(checkBox); + menu.addAction(checkableAction); + } + menu.exec(pos); + int i = 0; + + emit layoutAboutToBeChanged(); + m_EnabledColumns.reset(); + foreach (const QAction *action, menu.actions()) { + const QWidgetAction *widgetAction = qobject_cast<const QWidgetAction*>(action); + if (widgetAction != NULL) { + const QCheckBox *checkBox = qobject_cast<const QCheckBox*>(widgetAction->defaultWidget()); + if (checkBox != NULL) { + m_EnabledColumns.set(i, checkBox->checkState() == Qt::Checked); + } + } + ++i; + } + emit layoutChanged(); +} + + +void ModListSortProxy::enableAllVisible() +{ + if (m_Profile == NULL) return; + + for (int i = 0; i < this->rowCount(); ++i) { + int modID = mapToSource(index(i, 0)).row(); + m_Profile->setModEnabled(modID, true); + } +} + + +void ModListSortProxy::disableAllVisible() +{ + if (m_Profile == NULL) return; + for (int i = 0; i < this->rowCount(); ++i) { + int modID = mapToSource(index(i, 0)).row(); + m_Profile->setModEnabled(modID, false); + } +} + + +bool ModListSortProxy::lessThan(const QModelIndex &left, + const QModelIndex &right) const +{ + int leftIndex = left.internalId(); + int rightIndex = right.internalId(); + ModInfo::Ptr leftMod = ModInfo::getByIndex(leftIndex); + ModInfo::Ptr rightMod = ModInfo::getByIndex(rightIndex); + + bool lt = false; + switch (left.column()) { + case ModList::COL_FLAGS: lt = leftMod->getFlags().size() < rightMod->getFlags().size(); break; + case ModList::COL_NAME: lt = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive) < 0; break; + case ModList::COL_CATEGORY: { + if (leftMod->getPrimaryCategory() < 0) lt = false; + else if (rightMod->getPrimaryCategory() < 0) lt = true; + else { + try { + CategoryFactory &categories = CategoryFactory::instance(); + QString leftCatName = categories.getCategoryName(categories.getCategoryIndex(leftMod->getPrimaryCategory())); + QString rightCatName = categories.getCategoryName(categories.getCategoryIndex(rightMod->getPrimaryCategory())); + lt = leftCatName < rightCatName; + } catch (const std::exception &e) { + qCritical("failed to compare categories: %s", e.what()); + } + } + } break; + case ModList::COL_MODID: lt = leftMod->getNexusID() < rightMod->getNexusID(); break; + case ModList::COL_VERSION: lt = leftMod->getVersion() < rightMod->getVersion(); break; + case ModList::COL_PRIORITY: { + if (m_Profile != NULL) { + int leftPrio = leftMod->getFixedPriority(); + int rightPrio = rightMod->getFixedPriority(); + if (leftPrio == INT_MIN) leftPrio = m_Profile->getModPriority(leftIndex); + if (rightPrio == INT_MIN) rightPrio = m_Profile->getModPriority(rightIndex); + + lt = leftPrio < rightPrio; + } else { + lt = leftMod->name() < rightMod->name(); + } + } break; + } + return lt; +} + + +void ModListSortProxy::updateFilter(const QString &filter) +{ + m_CurrentFilter = filter; + invalidateFilter(); +} + + +bool ModListSortProxy::hasConflictFlag(const std::vector<ModInfo::EFlag> &flags) const +{ + foreach (ModInfo::EFlag flag, flags) { + if ((flag == ModInfo::FLAG_CONFLICT_MIXED) || + (flag == ModInfo::FLAG_CONFLICT_OVERWRITE) || + (flag == ModInfo::FLAG_CONFLICT_OVERWRITTEN) || + (flag == ModInfo::FLAG_CONFLICT_REDUNDANT)) { + return true; + } + } + + return false; +} + + +bool ModListSortProxy::filterMatches(ModInfo::Ptr info, bool enabled) const +{ + if (!m_CurrentFilter.isEmpty() && + !info->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) { + return false; + } + + return ((m_CategoryFilter == CategoryFactory::CATEGORY_NONE) || + ((m_CategoryFilter < CategoryFactory::CATEGORY_SPECIAL_FIRST) && (info->categorySet(m_CategoryFilter))) || + ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_CHECKED) && enabled) || + ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_UNCHECKED) && !enabled) || + ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) && info->updateAvailable()) || + ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY) && (info->getCategories().size() == 0)) || + ((m_CategoryFilter == CategoryFactory::CATEGORY_SPECIAL_CONFLICT) && (hasConflictFlag(info->getFlags())))); +} + + +bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex&) const +{ + bool modEnabled = m_Profile != NULL ? m_Profile->modEnabled(row) : false; + + return filterMatches(ModInfo::getByIndex(row), modEnabled); +} + + +/*bool ModListSortProxy::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const +{ + return m_EnabledColumns.test(source_column); +}*/ + + +bool ModListSortProxy::dropMimeData(const QMimeData *data, Qt::DropAction action, + int row, int column, const QModelIndex &parent) +{ + if ((row == -1) && (column == -1)) { + return this->sourceModel()->dropMimeData(data, action, -1, -1, mapToSource(parent)); + } + // in the regular model, when dropping between rows, the row-value passed to + // the sourceModel is inconsistent between ascending and descending ordering. + // This should fix that + if (sortOrder() == Qt::DescendingOrder) { + --row; + } + + QModelIndex proxyIndex = index(row, column, parent); + QModelIndex sourceIndex = mapToSource(proxyIndex); + return this->sourceModel()->dropMimeData(data, action, sourceIndex.row(), sourceIndex.column(), + sourceIndex.parent()); +} |
