diff options
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 140 |
1 files changed, 106 insertions, 34 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f2f3af65..2f6710cc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -23,9 +23,10 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "spawn.h" #include "report.h" #include "modlist.h" +#include "modlistsortproxy.h" +#include "qtgroupingproxy.h" #include "profile.h" #include "pluginlist.h" -#include "installdialog.h" #include "profilesdialog.h" #include "editexecutablesdialog.h" #include "categories.h" @@ -43,7 +44,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "syncoverwritedialog.h" #include "logbuffer.h" #include "downloadlistsortproxy.h" -#include "modlistsortproxy.h" #include "motddialog.h" #include "filedialogmemory.h" #include "questionboxmemory.h" @@ -84,6 +84,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QPluginLoader> #include <QRadioButton> #include <QDesktopWidget> +#include <QIdentityProxyModel> #include <boost/bind.hpp> #include <boost/foreach.hpp> #include <Psapi.h> @@ -99,7 +100,7 @@ MainWindow::MainWindow(const QString &exeName, QSettings &initSettings, QWidget : QMainWindow(parent), ui(new Ui::MainWindow), m_Tutorial(this, "MainWindow"), m_ExeName(exeName), m_OldProfileIndex(-1), m_DirectoryStructure(new DirectoryEntry(L"data", NULL, 0)), - m_ModList(NexusInterface::instance()), + m_ModList(NexusInterface::instance()), m_ModListSortProxy(NULL), m_OldExecutableIndex(-1), m_GamePath(ToQString(GameInfo::instance().getGameDirectory())), m_NexusDialog(NexusInterface::instance()->getAccessManager(), NULL), m_DownloadManager(NexusInterface::instance(), this), @@ -132,13 +133,17 @@ MainWindow::MainWindow(const QString &exeName, QSettings &initSettings, QWidget // set up mod list m_ModListSortProxy = new ModListSortProxy(m_CurrentProfile, this); m_ModListSortProxy->setSourceModel(&m_ModList); - ui->modList->setModel(m_ModListSortProxy); + + QAbstractProxyModel *proxyModel = new QIdentityProxyModel(this); + proxyModel->setSourceModel(m_ModListSortProxy); + ui->modList->setModel(proxyModel); ui->modList->sortByColumn(ModList::COL_PRIORITY, Qt::AscendingOrder); - ui->modList->setItemDelegateForColumn(ModList::COL_FLAGS, new IconDelegate(m_ModListSortProxy)); + ui->modList->setItemDelegateForColumn(ModList::COL_FLAGS, new IconDelegate(ui->modList)); ui->modList->header()->installEventFilter(&m_ModList); ui->modList->header()->restoreState(initSettings.value("mod_list_state").toByteArray()); ui->modList->installEventFilter(&m_ModList); + // restoreState also seems to restores the resize mode from previous session, // I don't really like that #if QT_VERSION >= 0x50000 @@ -205,7 +210,7 @@ MainWindow::MainWindow(const QString &exeName, QSettings &initSettings, QWidget connect(ui->modFilterEdit, SIGNAL(textChanged(QString)), m_ModListSortProxy, SLOT(updateFilter(QString))); connect(ui->espFilterEdit, SIGNAL(textChanged(QString)), m_PluginListSortProxy, SLOT(updateFilter(QString))); connect(ui->espFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(espFilterChanged(QString))); - connect(&m_ModList, SIGNAL(modlist_changed(QModelIndex, int)), m_ModListSortProxy, SLOT(invalidate())); + connect(&m_ModList, SIGNAL(modlist_changed(int)), this, SLOT(modlistChanged(int))); connect(&m_ModList, SIGNAL(modlist_changed(QModelIndex, int)), this, SLOT(modlistChanged(QModelIndex, int))); connect(&m_ModList, SIGNAL(removeSelectedMods()), this, SLOT(removeMod_clicked())); @@ -269,6 +274,25 @@ void MainWindow::resizeEvent(QResizeEvent *event) } +static QModelIndex mapToModel(const QAbstractItemModel *targetModel, QModelIndex idx) +{ + QModelIndex result = idx; + const QAbstractItemModel *model = idx.model(); + while (model != targetModel) { + if (model == NULL) { + return QModelIndex(); + } + const QAbstractProxyModel *proxyModel = qobject_cast<const QAbstractProxyModel*>(model); + if (proxyModel == NULL) { + return QModelIndex(); + } + result = proxyModel->mapToSource(result); + model = proxyModel->sourceModel(); + } + return result; +} + + void MainWindow::actionToToolButton(QAction *&sourceAction) { QToolButton *button = new QToolButton(ui->toolBar); @@ -1188,11 +1212,11 @@ void MainWindow::on_profileBox_currentIndexChanged(int index) } if (ui->profileBox->currentIndex() == 0) { - ui->profileBox->setCurrentIndex(previousIndex); ProfilesDialog(m_GamePath).exec(); while (!refreshProfiles()) { ProfilesDialog(m_GamePath).exec(); } + ui->profileBox->setCurrentIndex(previousIndex); } else { activateSelectedProfile(); } @@ -1625,6 +1649,9 @@ void MainWindow::readSettings() languageChange(m_Settings.language()); int selectedExecutable = settings.value("selected_executable").toInt(); setExecutableIndex(selectedExecutable); + + int grouping = settings.value("group_state").toInt(); + ui->groupCombo->setCurrentIndex(grouping); } @@ -1645,8 +1672,10 @@ void MainWindow::storeSettings() } settings.setValue("mod_list_state", ui->modList->header()->saveState()); - settings.setValue("plugin_list_state", ui->espList->header()->saveState()); + + settings.setValue("group_state", ui->groupCombo->currentIndex()); + settings.setValue("compact_downloads", ui->compactBox->isChecked()); settings.setValue("ask_for_nexuspw", m_AskForNexusPW); @@ -1712,14 +1741,13 @@ void MainWindow::on_tabWidget_currentChanged(int index) void MainWindow::installMod(const QString &fileName) { bool hasIniTweaks = false; - QString modName; + GuessedValue<QString> modName; m_CurrentProfile->writeModlistNow(); - if (m_InstallationManager.install(fileName, m_CurrentProfile->getPluginsFileName(), m_Settings.getModDirectory(), m_Settings.preferIntegratedInstallers(), - m_Settings.enableQuickInstaller(), modName, hasIniTweaks)) { + if (m_InstallationManager.install(fileName, m_Settings.getModDirectory(), modName, hasIniTweaks)) { MessageDialog::showMessage(tr("Installation successful"), this); refreshModList(); - QModelIndexList posList = m_ModList.match(m_ModList.index(0, 0), Qt::DisplayRole, modName); + QModelIndexList posList = m_ModList.match(m_ModList.index(0, 0), Qt::DisplayRole, static_cast<const QString&>(modName)); if (posList.count() == 1) { ui->modList->scrollTo(posList.at(0)); } @@ -2220,6 +2248,12 @@ void MainWindow::modRenamed(const QString &oldName, const QString &newName) } +void MainWindow::modlistChanged(int) +{ + m_ModListSortProxy->invalidate(); +} + + QTreeWidgetItem *MainWindow::addFilterItem(QTreeWidgetItem *root, const QString &name, int categoryID) { QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name)); @@ -2299,9 +2333,11 @@ void MainWindow::refreshFilters() void MainWindow::renameMod_clicked() { try { - QModelIndex treeIdx = m_ModListSortProxy->mapFromSource(m_ModList.index(m_ContextRow, 0)); +/* QModelIndex treeIdx = m_ModListGroupProxy->mapFromSource(m_ModListSortProxy->mapFromSource(m_ModList.index(m_ContextRow, 0))); ui->modList->setCurrentIndex(treeIdx); - ui->modList->edit(treeIdx); + ui->modList->edit(treeIdx);*/ + + ui->modList->edit(ui->modList->currentIndex()); } catch (const std::exception &e) { reportError(tr("failed to rename mod: %1").arg(e.what())); } @@ -2364,7 +2400,8 @@ void MainWindow::removeMod_clicked() QString mods; QStringList modNames; foreach (QModelIndex idx, selection->selectedRows()) { - QString name = ModInfo::getByIndex(m_ModListSortProxy->mapToSource(idx).row())->name(); +// QString name = ModInfo::getByIndex(m_ModListGroupProxy->mapToSource(idx).row())->name(); + QString name = idx.data().toString(); mods += "<li>" + name + "</li>"; modNames.append(name); } @@ -2647,9 +2684,19 @@ void MainWindow::cancelModListEditor() void MainWindow::on_modList_doubleClicked(const QModelIndex &index) { + if (!index.isValid()) { + return; + } +// QModelIndex sourceIdx = m_ModListGroupProxy->mapToSource(index); + QModelIndex sourceIdx = mapToModel(&m_ModList, index); + if (!sourceIdx.isValid()) { + return; + } + try { m_ContextRow = m_ModListSortProxy->mapToSource(index).row(); - displayModInformation(m_ModListSortProxy->mapToSource(index).row()); +// displayModInformation(m_ModListSortProxy->mapToSource(index).row()); + displayModInformation(sourceIdx.row()); // workaround to cancel the editor that might have opened because of // selection-click ui->modList->closePersistentEditor(index); @@ -2889,13 +2936,12 @@ void MainWindow::exportModListCSV() } } - void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) { try { QTreeView *modList = findChild<QTreeView*>("modList"); - m_ContextRow = m_ModListSortProxy->mapToSource(modList->indexAt(pos)).row(); + m_ContextRow = mapToModel(&m_ModList, modList->indexAt(pos)).row(); QMenu menu; menu.addAction(tr("Install Mod..."), this, SLOT(installMod_clicked())); @@ -2971,6 +3017,7 @@ void MainWindow::on_categoriesList_currentItemChanged(QTreeWidgetItem *current, int filter = current->data(0, Qt::UserRole).toInt(); m_ModListSortProxy->setCategoryFilter(filter); ui->currentCategoryLabel->setText(QString("(%1)").arg(current->text(0))); + ui->modList->reset(); } } @@ -3278,32 +3325,29 @@ void MainWindow::installDownload(int index) try { QString fileName = m_DownloadManager.getFilePath(index); int modID = m_DownloadManager.getModID(index); - QString modName; + GuessedValue<QString> modName; // see if there already are mods with the specified mod id if (modID != 0) { - ModInfo::Ptr modInfo = ModInfo::getByModID(modID, true); - if (!modInfo.isNull()) { - std::vector<ModInfo::EFlag> flags = modInfo->getFlags(); + std::vector<ModInfo::Ptr> modInfo = ModInfo::getByModID(modID); + for (auto iter = modInfo.begin(); iter != modInfo.end(); ++iter) { + std::vector<ModInfo::EFlag> flags = (*iter)->getFlags(); if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_BACKUP) == flags.end()) { - modName = modInfo->name(); - modInfo->saveMeta(); + modName.update((*iter)->name(), GUESS_PRESET); + (*iter)->saveMeta(); } } - // TODO there may be multiple mods with the same id! -// modName = m_ModList.getModByModID(modID); } m_CurrentProfile->writeModlistNow(); bool hasIniTweaks = false; - if (m_InstallationManager.install(fileName, m_CurrentProfile->getPluginsFileName(), m_Settings.getModDirectory(), m_Settings.preferIntegratedInstallers(), - m_Settings.enableQuickInstaller(), modName, hasIniTweaks)) { + if (m_InstallationManager.install(fileName, m_Settings.getModDirectory(), modName, hasIniTweaks)) { MessageDialog::showMessage(tr("Installation successful"), this); refreshModList(); - QModelIndexList posList = m_ModList.match(m_ModList.index(0, 0), Qt::DisplayRole, modName); + QModelIndexList posList = m_ModList.match(m_ModList.index(0, 0), Qt::DisplayRole, static_cast<const QString&>(modName)); if (posList.count() == 1) { ui->modList->scrollTo(posList.at(0)); } @@ -3702,13 +3746,13 @@ void MainWindow::nxmUpdatesAvailable(const std::vector<int> &modIDs, QVariant us ui->actionEndorseMO->setVisible(true); } } else { - ModInfo::Ptr info = ModInfo::getByModID(result["id"].toInt(), true); - if (!info.isNull()) { - info->setNewestVersion(VersionInfo(result["version"].toString())); - info->setNexusDescription(result["description"].toString()); + std::vector<ModInfo::Ptr> info = ModInfo::getByModID(result["id"].toInt()); + for (auto iter = info.begin(); iter != info.end(); ++iter) { + (*iter)->setNewestVersion(VersionInfo(result["version"].toString())); + (*iter)->setNexusDescription(result["description"].toString()); if (NexusInterface::instance()->getAccessManager()->loggedIn()) { // don't use endorsement info if we're not logged in - info->setIsEndorsed(result["voted_by_user"].toBool()); + (*iter)->setIsEndorsed(result["voted_by_user"].toBool()); } } } @@ -4013,3 +4057,31 @@ void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos) reportError(tr("Unknown exception")); } } + +void MainWindow::on_groupCombo_currentIndexChanged(int index) +{ + QAbstractProxyModel *newModel = NULL; + switch (index) { + case 1: { + newModel = new QtGroupingProxy(m_ModListSortProxy, QModelIndex(), ModList::COL_CATEGORY); + } break; + case 2: { + newModel = new QtGroupingProxy(m_ModListSortProxy, QModelIndex(), ModList::COL_MODID); + } break; + default: { + newModel = NULL; + } break; + } + + if (newModel != NULL) { + newModel->setSourceModel(m_ModListSortProxy); + connect(ui->modList, SIGNAL(expanded(QModelIndex)),newModel, SLOT(expanded(QModelIndex))); + connect(ui->modList, SIGNAL(collapsed(QModelIndex)), newModel, SLOT(collapsed(QModelIndex))); + connect(newModel, SIGNAL(expandItem(QModelIndex)), ui->modList, SLOT(expand(QModelIndex))); + + ui->modList->setModel(newModel); + } else { + ui->modList->setModel(m_ModListSortProxy); + } + // ui->modList->setSelectionMode(QAbstractItemView::ExtendedSelection); +} |
