diff options
| -rw-r--r-- | src/mainwindow.cpp | 32 | ||||
| -rw-r--r-- | src/mainwindow.h | 2 | ||||
| -rw-r--r-- | src/mainwindow.ui | 3 | ||||
| -rw-r--r-- | src/modlistsortproxy.cpp | 39 | ||||
| -rw-r--r-- | src/modlistsortproxy.h | 4 | ||||
| -rw-r--r-- | src/profile.cpp | 4 | ||||
| -rw-r--r-- | src/profilesdialog.cpp | 17 |
7 files changed, 62 insertions, 39 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2efbdc0f..65633ab1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -87,6 +87,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QIdentityProxyModel> #include <boost/bind.hpp> #include <boost/foreach.hpp> +#include <boost/assign.hpp> #include <Psapi.h> #include <shlobj.h> #include <TlHelp32.h> @@ -2293,7 +2294,6 @@ void MainWindow::refreshFilters() QString previousFilter = currentItem != NULL ? currentItem->text(0) : tr("<All>"); ui->categoriesList->clear(); - addFilterItem(NULL, tr("<All>"), CategoryFactory::CATEGORY_NONE); addFilterItem(NULL, tr("<Checked>"), CategoryFactory::CATEGORY_SPECIAL_CHECKED); addFilterItem(NULL, tr("<Unchecked>"), CategoryFactory::CATEGORY_SPECIAL_UNCHECKED); addFilterItem(NULL, tr("<Update>"), CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE); @@ -3010,14 +3010,28 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) } -void MainWindow::on_categoriesList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *) +void MainWindow::on_categoriesList_itemSelectionChanged() { - if (current != NULL) { - int filter = current->data(0, Qt::UserRole).toInt(); - m_ModListSortProxy->setCategoryFilter(filter); - ui->currentCategoryLabel->setText(QString("(%1)").arg(current->text(0))); - ui->modList->reset(); +// int filter = current->data(0, Qt::UserRole).toInt(); + QModelIndexList indices = ui->categoriesList->selectionModel()->selectedRows(); + std::vector<int> categories; + foreach (const QModelIndex &index, indices) { + int categoryId = index.data(Qt::UserRole).toInt(); + if (categoryId != CategoryFactory::CATEGORY_NONE) { + categories.push_back(categoryId); + } + } + + m_ModListSortProxy->setCategoryFilter(categories); +// ui->currentCategoryLabel->setText(QString("(%1)").arg(current->text(0))); + if (indices.count() == 0) { + ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("<All>"))); + } else if (indices.count() > 1) { + ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("<Multiple>"))); + } else { + ui->currentCategoryLabel->setText(QString("(%1)").arg(indices.first().data().toString())); } + ui->modList->reset(); } @@ -3720,7 +3734,7 @@ void MainWindow::modDetailsUpdated(bool) --m_ModsToUpdate; if (m_ModsToUpdate == 0) { statusBar()->hide(); - m_ModListSortProxy->setCategoryFilter(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE); + m_ModListSortProxy->setCategoryFilter(boost::assign::list_of(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE)); for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) { if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i)); @@ -3759,7 +3773,7 @@ void MainWindow::nxmUpdatesAvailable(const std::vector<int> &modIDs, QVariant us if (m_ModsToUpdate <= 0) { statusBar()->hide(); - m_ModListSortProxy->setCategoryFilter(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE); + m_ModListSortProxy->setCategoryFilter(boost::assign::list_of(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE)); for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) { if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i)); diff --git a/src/mainwindow.h b/src/mainwindow.h index 91c2b17d..4dfc5d76 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -423,7 +423,6 @@ private slots: // ui slots void on_bsaList_customContextMenuRequested(const QPoint &pos); void on_bsaList_itemChanged(QTreeWidgetItem *item, int column); void on_btnRefreshData_clicked(); - void on_categoriesList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void on_categoriesList_customContextMenuRequested(const QPoint &pos); void on_compactBox_toggled(bool checked); void on_conflictsCheckBox_toggled(bool checked); @@ -440,6 +439,7 @@ private slots: // ui slots void on_espList_customContextMenuRequested(const QPoint &pos); void on_displayCategoriesBtn_toggled(bool checked); void on_groupCombo_currentIndexChanged(int index); + void on_categoriesList_itemSelectionChanged(); }; #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index b7d0057e..4b5b48de 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -71,6 +71,9 @@ <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 071e0384..a61ba2de 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -29,7 +29,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent) : QSortFilterProxyModel(parent), m_Profile(profile), - m_CategoryFilter(CategoryFactory::CATEGORY_NONE), m_CurrentFilter() + m_CategoryFilter(), m_CurrentFilter() { m_EnabledColumns.set(ModList::COL_FLAGS); m_EnabledColumns.set(ModList::COL_NAME); @@ -47,12 +47,12 @@ void ModListSortProxy::setProfile(Profile *profile) void ModListSortProxy::updateFilterActive() { - emit filterActive((m_CategoryFilter != CategoryFactory::CATEGORY_NONE) || !m_CurrentFilter.isEmpty()); + emit filterActive((m_CategoryFilter.size() > 0) || !m_CurrentFilter.isEmpty()); } -void ModListSortProxy::setCategoryFilter(int category) +void ModListSortProxy::setCategoryFilter(const std::vector<int> &categories) { - m_CategoryFilter = category; + m_CategoryFilter = categories; updateFilterActive(); this->invalidate(); } @@ -197,13 +197,30 @@ bool ModListSortProxy::filterMatches(ModInfo::Ptr info, bool enabled) const 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())))); + for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) { + switch (*iter) { + case CategoryFactory::CATEGORY_SPECIAL_CHECKED: { + if (!enabled) return false; + } break; + case CategoryFactory::CATEGORY_SPECIAL_UNCHECKED: { + if (enabled) return false; + } break; + case CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE: { + if (!info->updateAvailable()) return false; + } break; + case CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY: { + if (info->getCategories().size() > 0) return false; + } break; + case CategoryFactory::CATEGORY_SPECIAL_CONFLICT: { + if (!hasConflictFlag(info->getFlags())) return false; + } break; + default: { + if (!info->categorySet(*iter)) return false; + } break; + } + } + + return true; } diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h index 8b86b222..d615c430 100644 --- a/src/modlistsortproxy.h +++ b/src/modlistsortproxy.h @@ -36,7 +36,7 @@ public: void setProfile(Profile *profile); - void setCategoryFilter(int category); + void setCategoryFilter(const std::vector<int> &categories); virtual Qt::ItemFlags flags(const QModelIndex &modelIndex) const; virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, @@ -79,7 +79,7 @@ private: Profile *m_Profile; - int m_CategoryFilter; + std::vector<int> m_CategoryFilter; std::bitset<ModList::COL_LASTCOLUMN + 1> m_EnabledColumns; QString m_CurrentFilter; diff --git a/src/profile.cpp b/src/profile.cpp index 204a71aa..24c6d943 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -84,7 +84,7 @@ Profile::Profile(const QDir& directory) { initTimer(); if (!QFile::exists(m_Directory.filePath("modlist.txt"))) { - throw std::runtime_error(QObject::tr("modlist.txt missing").toUtf8().constData()); + qWarning("missing modlist.txt in %s", qPrintable(directory.path())); } GameInfo::instance().repairProfile(ToWString(m_Directory.absolutePath())); @@ -185,7 +185,7 @@ void Profile::createTweakedIniFile() { QString tweakedIni = m_Directory.absoluteFilePath("initweaks.ini"); - if (!shellDelete(QStringList(tweakedIni), NULL)) { + if (QFile::exists(tweakedIni) && !shellDelete(QStringList(tweakedIni), NULL)) { reportError(tr("failed to update tweaked ini file, wrong settings may be used: %1").arg(windowsErrorString(::GetLastError()))); return; } diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 54e9147b..1f644a2f 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -90,11 +90,9 @@ void ProfilesDialog::on_closeButton_clicked() void ProfilesDialog::addItem(const QString &name) { + QDir profileDir(name); + QListWidgetItem *newItem = new QListWidgetItem(profileDir.dirName(), m_ProfilesList); try { -// QVariant temp; - QDir profileDir(name); -// temp.setValue(Profile(profileDir)); - QListWidgetItem *newItem = new QListWidgetItem(profileDir.dirName(), m_ProfilesList); newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(profileDir)))); m_FailState = false; } catch (const std::exception& e) { @@ -106,8 +104,6 @@ void ProfilesDialog::addItem(const QString &name) void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) { try { -// QVariant temp; -// temp.setValue(Profile(name, useDefaultSettings)); QListWidget *profilesList = findChild<QListWidget*>("profilesList"); QListWidgetItem *newItem = new QListWidgetItem(name, profilesList); newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, useDefaultSettings)))); @@ -123,10 +119,6 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) void ProfilesDialog::createProfile(const QString &name, const Profile &reference) { try { -// Profile newProfile = Profile::createFrom(name, reference); - -// QVariant temp; -// temp.setValue(newProfile); QListWidget *profilesList = findChild<QListWidget*>("profilesList"); QListWidgetItem *newItem = new QListWidgetItem(name, profilesList); newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference)))); @@ -212,10 +204,6 @@ void ProfilesDialog::on_renameButton_clicked() ui->profilesList->currentItem()->setText(name); currentProfile->rename(name); - -// QVariant temp; -// temp.setValue(currentProfile); -// ui->profilesList->currentItem()->setData(Qt::UserRole, temp); } @@ -257,6 +245,7 @@ void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem *current QPushButton *renameButton = findChild<QPushButton*>("renameButton"); if (current != NULL) { + if (!current->data(Qt::UserRole).isValid()) return; const Profile::Ptr currentProfile = current->data(Qt::UserRole).value<Profile::Ptr>(); try { |
