Reimplemented dependency selection feature

Moved more code to ContentSelector
Added support for omwgame and omwaddon files
This commit is contained in:
graffy76 2013-08-17 19:40:28 -05:00
parent b24dd5c6ac
commit 2878f51cd3
10 changed files with 99 additions and 227 deletions

View file

@ -6,6 +6,7 @@
#include <QSortFilterProxyModel>
#include <QDebug>
FileOrderList::ContentSelector::ContentSelector(QWidget *parent) :
QWidget(parent)
{
@ -22,40 +23,20 @@ void FileOrderList::ContentSelector::buildModelsAndViews()
mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel);
masterView->setModel(mMasterProxyModel);
/*
mastersTable->setModel(mMastersProxyModel);
mastersTable->setObjectName("MastersTable");
mastersTable->setContextMenuPolicy(Qt::CustomContextMenu);
mastersTable->setSortingEnabled(false);
mastersTable->setSelectionBehavior(QAbstractItemView::SelectRows);
mastersTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
mastersTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
mastersTable->setAlternatingRowColors(true);
mastersTable->horizontalHeader()->setStretchLastSection(true);
// Set the row height to the size of the checkboxes
mastersTable->verticalHeader()->setDefaultSectionSize(height);
mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
mastersTable->verticalHeader()->hide();
*/
pluginsTable->setModel(mPluginsProxyModel);
pluginsTable->setObjectName("PluginsTable");
pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu);
pluginsTable->setSortingEnabled(false);
pluginsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
pluginsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
pluginsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
pluginsTable->setAlternatingRowColors(true);
pluginsTable->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
pluginsTable->horizontalHeader()->setStretchLastSection(true);
pluginView->setModel(mPluginsProxyModel);
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int)));
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
}
void FileOrderList::ContentSelector::addFiles(const QString &path)
{
mDataFilesModel->addFiles(path);
mDataFilesModel->sort(3); // Sort by date accessed
masterView->setCurrentIndex(-1);
mDataFilesModel->uncheckAll();
}
void FileOrderList::ContentSelector::setEncoding(const QString &encoding)
@ -63,39 +44,22 @@ void FileOrderList::ContentSelector::setEncoding(const QString &encoding)
mDataFilesModel->setEncoding(encoding);
}
void FileOrderList::ContentSelector::setCheckState(QModelIndex index)
void FileOrderList::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model)
{
if (!index.isValid())
return;
QObject *object = QObject::sender();
// Not a signal-slot call
if (!object)
if (!model)
return;
QModelIndex sourceIndex = model->mapToSource(index);
if (object->objectName() == QLatin1String("PluginsTable")) {
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
if (sourceIndex.isValid()) {
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
}
if (sourceIndex.isValid())
{
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
}
if (object->objectName() == QLatin1String("MastersTable")) {
QModelIndex sourceIndex = mMasterProxyModel->mapToSource(index);
if (sourceIndex.isValid()) {
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
}
}
return;
}
QStringList FileOrderList::ContentSelector::checkedItemsPaths()
@ -106,13 +70,30 @@ QStringList FileOrderList::ContentSelector::checkedItemsPaths()
void FileOrderList::ContentSelector::updateViews()
{
// Ensure the columns are hidden because sort() re-enables them
pluginsTable->setColumnHidden(1, true);
pluginsTable->setColumnHidden(3, true);
pluginsTable->setColumnHidden(4, true);
pluginsTable->setColumnHidden(5, true);
pluginsTable->setColumnHidden(6, true);
pluginsTable->setColumnHidden(7, true);
pluginsTable->setColumnHidden(8, true);
pluginsTable->resizeColumnsToContents();
pluginView->setColumnHidden(1, true);
pluginView->setColumnHidden(3, true);
pluginView->setColumnHidden(4, true);
pluginView->setColumnHidden(5, true);
pluginView->setColumnHidden(6, true);
pluginView->setColumnHidden(7, true);
pluginView->setColumnHidden(8, true);
pluginView->resizeColumnsToContents();
}
void FileOrderList::ContentSelector::slotCurrentProfileIndexChanged(int index)
{
emit profileChanged(index);
}
void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index)
{
qDebug() << "index Changed: " << index;
QObject *object = QObject::sender();
// Not a signal-slot call
if (!object)
return;
setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel);
}

View file

@ -30,11 +30,16 @@ namespace FileOrderList
void addFiles(const QString &path);
void setEncoding(const QString &encoding);
void setCheckState(QModelIndex index);
void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
QStringList checkedItemsPaths();
signals:
void profileChanged(int index);
private slots:
void updateViews();
void slotCurrentProfileIndexChanged(int index);
void slotCurrentMasterIndexChanged(int index);
};
}

View file

@ -174,7 +174,7 @@ Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
if (index.column() == 0) {
return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
} else {
return Qt::NoItemFlags | Qt::ItemIsSelectable;
return Qt::ItemIsSelectable;
}
}
@ -270,7 +270,7 @@ void DataFilesModel::addFiles(const QString &path)
{
QDir dir(path);
QStringList filters;
filters << "*.esp" << "*.esm";
filters << "*.esp" << "*.esm" << "*.omwgame" << "*.omwaddon";
dir.setNameFilters(filters);
// Create a decoder for non-latin characters in esx metadata
@ -319,9 +319,10 @@ void DataFilesModel::addFiles(const QString &path)
// Put the file in the table
if (findItem(path) == 0)
addFile(file);
} catch(std::runtime_error &e) {
// An error occurred while reading the .esp
qWarning() << "Error reading esp: " << e.what();
qWarning() << "Error reading addon file: " << e.what();
continue;
}
@ -436,14 +437,10 @@ QStringList DataFilesModel::uncheckedItems()
bool DataFilesModel::canBeChecked(EsmFile *file) const
{
//element can be checked if all its dependencies are
bool canBeChecked = true;
foreach (const QString &master, file->masters())
{
if (!mCheckStates.contains(master) || mCheckStates[master] != Qt::Checked)
{
canBeChecked = false;
break;
}
return false;
}
return canBeChecked;
return true;
}

View file

@ -2,7 +2,7 @@
#include "datafilesmodel.hpp"
PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) :
QSortFilterProxyModel(parent), mSourceModel (model)
QSortFilterProxyModel(parent)
{
setFilterRegExp (QString("addon"));
setFilterRole (Qt::UserRole);
@ -25,7 +25,7 @@ QVariant PluginsProxyModel::data(const QModelIndex &index, int role) const
if (index.column() != 0)
return QVariant();
return mSourceModel->checkState(index);
return static_cast<DataFilesModel *>(sourceModel())->checkState(mapToSource(index));
}
};

View file

@ -11,8 +11,6 @@ class PluginsProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
DataFilesModel *mSourceModel;
public:
explicit PluginsProxyModel(QObject *parent = 0, DataFilesModel *model = 0);