launcher: decouple Combo Box model from Plug-ins model.

fixes bug reported by scrawl
1. openmw.cfg had content files in order 'Bloodmoon.esm, Tribunal.esm, Morrowind.esm'
2. Blank_ESM_2.0.esm is in the Data Files directory
3. Do an ini file import.
4. Imported profile will have Blank_ESM_2.0.esm as the game file.  Should be Morrowind.esm.

Root cause: Game File combo box and Plugins Grid shared same data model, so changing plug-in file order also changed order of Game File combo box.
celladd
dteviot 9 years ago
parent 63af9d848a
commit 6878e317a7

@ -489,6 +489,19 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path)
sortFiles();
}
QStringList ContentSelectorModel::ContentModel::gameFiles() const
{
QStringList gameFiles;
foreach(const ContentSelectorModel::EsmFile *file, mFiles)
{
if (file->isGameFile())
{
gameFiles.append(file->fileName());
}
}
return gameFiles;
}
void ContentSelectorModel::ContentModel::sortFiles()
{
//first, sort the model such that all dependencies are ordered upstream (gamefile) first.
@ -589,7 +602,7 @@ void ContentSelectorModel::ContentModel::checkForLoadOrderErrors()
QList<ContentSelectorModel::LoadOrderError> ContentSelectorModel::ContentModel::checkForLoadOrderErrors(const EsmFile *file, int row) const
{
QList<LoadOrderError> errors = QList<LoadOrderError>();
foreach(QString dependentfileName, file->gameFiles())
foreach(const QString &dependentfileName, file->gameFiles())
{
const EsmFile* dependentFile = item(dependentfileName);

@ -47,6 +47,7 @@ namespace ContentSelectorModel
QModelIndex indexFromItem(const EsmFile *item) const;
const EsmFile *item(const QString &name) const;
QStringList gameFiles() const;
bool isEnabled (QModelIndex index) const;
bool isChecked(const QString &filepath) const;

@ -10,6 +10,7 @@
#include <QGridLayout>
#include <QMessageBox>
#include <QModelIndex>
#include <QDir>
#include <assert.h>
ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) :
@ -33,13 +34,7 @@ void ContentSelectorView::ContentSelector::buildGameFileView()
{
ui.gameFileView->setVisible (true);
mGameFileProxyModel = new QSortFilterProxyModel(this);
mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile));
mGameFileProxyModel->setFilterRole (Qt::UserRole);
mGameFileProxyModel->setSourceModel (mContentModel);
ui.gameFileView->setPlaceholderText(QString("Select a game file..."));
ui.gameFileView->setModel(mGameFileProxyModel);
connect (ui.gameFileView, SIGNAL (currentIndexChanged(int)),
this, SLOT (slotCurrentGameFileIndexChanged(int)));
@ -129,6 +124,15 @@ void ContentSelectorView::ContentSelector::addFiles(const QString &path)
{
mContentModel->addFiles(path);
// add any game files to the combo box
foreach(const QString gameFileName, mContentModel->gameFiles())
{
if (ui.gameFileView->findText(gameFileName) == -1)
{
ui.gameFileView->addItem(gameFileName);
}
}
if (ui.gameFileView->currentIndex() != -1)
ui.gameFileView->setCurrentIndex(-1);
@ -150,29 +154,33 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
{
static int oldIndex = -1;
QAbstractItemModel *const model = ui.gameFileView->model();
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
if (proxy)
proxy->setDynamicSortFilter(false);
if (index != oldIndex)
{
if (oldIndex > -1)
model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1);
{
setGameFileSelected(oldIndex, false);
}
oldIndex = index;
model->setData(model->index(index, 0), true, Qt::UserRole + 1);
setGameFileSelected(index, true);
mContentModel->checkForLoadOrderErrors();
}
if (proxy)
proxy->setDynamicSortFilter(true);
emit signalCurrentGamefileIndexChanged (index);
}
void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool selected)
{
QString fileName = ui.gameFileView->itemText(index);
const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName);
if (file != NULL)
{
QModelIndex index(mContentModel->indexFromItem(file));
mContentModel->setData(index, selected, Qt::UserRole + 1);
}
}
void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QModelIndex &index)
{
QModelIndex sourceIndex = mAddonProxyModel->mapToSource (index);

@ -19,7 +19,6 @@ namespace ContentSelectorView
protected:
ContentSelectorModel::ContentModel *mContentModel;
QSortFilterProxyModel *mGameFileProxyModel;
QSortFilterProxyModel *mAddonProxyModel;
public:
@ -52,6 +51,7 @@ namespace ContentSelectorView
void buildContentModel();
void buildGameFileView();
void buildAddonView();
void setGameFileSelected(int index, bool selected);
signals:
void signalCurrentGamefileIndexChanged (int);

Loading…
Cancel
Save