Reimplemented dependency selection feature

Moved more code to ContentSelector
Added support for omwgame and omwaddon files
actorid
graffy76 12 years ago
parent b24dd5c6ac
commit 2878f51cd3

@ -29,29 +29,14 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
, mLauncherSettings(launcherSettings)
, ContentSelector(parent)
{
// Adjust the tableview widths inside the splitter
QList<int> sizeList;
sizeList << mLauncherSettings.value(QString("General/MastersTable/width"), QString("200")).toInt();
sizeList << mLauncherSettings.value(QString("General/PluginTable/width"), QString("340")).toInt();
splitter->setSizes(sizeList);
// Create a dialog for the new profile name input
mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this);
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentIndexChanged(int)));
connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString)));
connect(pluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
//connect(mastersTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
connect(pluginsTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
//connect(mastersTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
//connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
connect(splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(updateSplitter()));
//connect(pluginView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
//connect(masterView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
createActions();
setupDataFiles();
@ -193,49 +178,11 @@ void DataFilesPage::updateOkButton(const QString &text)
: mNewProfileDialog->setOkButtonEnabled(false);
}
void DataFilesPage::updateSplitter()
{
// Sigh, update the saved splitter size in settings only when moved
// Since getting mSplitter->sizes() if page is hidden returns invalid values
QList<int> sizes = splitter->sizes();
mLauncherSettings.setValue(QString("General/MastersTable/width"), QString::number(sizes.at(0)));
mLauncherSettings.setValue(QString("General/PluginsTable/width"), QString::number(sizes.at(1)));
}
void DataFilesPage::updateViews()
{
// Ensure the columns are hidden because sort() re-enables them
/*
mastersTable->setColumnHidden(1, true);
mastersTable->setColumnHidden(2, true);
mastersTable->setColumnHidden(3, true);
mastersTable->setColumnHidden(4, true);
mastersTable->setColumnHidden(5, true);
mastersTable->setColumnHidden(6, true);
mastersTable->setColumnHidden(7, true);
mastersTable->setColumnHidden(8, true);
*/
pluginsTable->setColumnHidden(1, true);
pluginsTable->setColumnHidden(2, 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);
}
void DataFilesPage::setProfilesComboBoxIndex(int index)
{
profilesComboBox->setCurrentIndex(index);
}
void DataFilesPage::slotCurrentIndexChanged(int index)
{
emit profileChanged(index);
}
QAbstractItemModel* DataFilesPage::profilesComboBoxModel()
{
return profilesComboBox->model();
@ -282,54 +229,13 @@ void DataFilesPage::on_deleteProfileAction_triggered()
}
}
void DataFilesPage::on_checkAction_triggered()
{
if (pluginsTable->hasFocus())
setPluginsCheckstates(Qt::Checked);
//if (mastersTable->hasFocus())
// setMastersCheckstates(Qt::Checked);
}
void DataFilesPage::on_uncheckAction_triggered()
{
if (pluginsTable->hasFocus())
setPluginsCheckstates(Qt::Unchecked);
//if (mastersTable->hasFocus())
// setMastersCheckstates(Qt::Unchecked);
}
void DataFilesPage::setMastersCheckstates(Qt::CheckState state)
{/*
//if (!mastersTable->selectionModel()->hasSelection()) {
// return;
//}
//QModelIndexList indexes = mastersTable->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, indexes)
{
if (!index.isValid())
return;
QModelIndex sourceIndex = mMastersProxyModel->mapToSource(index);
if (!sourceIndex.isValid())
return;
mDataFilesModel->setCheckState(sourceIndex, state);
}*/
}
void DataFilesPage::setPluginsCheckstates(Qt::CheckState state)
{
if (!pluginsTable->selectionModel()->hasSelection()) {
if (!pluginView->selectionModel()->hasSelection()) {
return;
}
QModelIndexList indexes = pluginsTable->selectionModel()->selectedIndexes();
QModelIndexList indexes = pluginView->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, indexes)
{
@ -389,7 +295,7 @@ void DataFilesPage::profileRenamed(const QString &previous, const QString &curre
loadSettings();
}
/*
void DataFilesPage::showContextMenu(const QPoint &point)
{
QObject *object = QObject::sender();
@ -398,12 +304,12 @@ void DataFilesPage::showContextMenu(const QPoint &point)
if (!object)
return;
if (object->objectName() == QLatin1String("PluginsTable")) {
if (!pluginsTable->selectionModel()->hasSelection())
if (object->objectName() == QLatin1String("PluginView")) {
if (!pluginView->selectionModel()->hasSelection())
return;
QPoint globalPos = pluginsTable->mapToGlobal(point);
QModelIndexList indexes = pluginsTable->selectionModel()->selectedIndexes();
QPoint globalPos = pluginView->mapToGlobal(point);
QModelIndexList indexes = pluginView->selectionModel()->selectedIndexes();
// Show the check/uncheck actions depending on the state of the selected items
uncheckAction->setEnabled(false);
@ -427,13 +333,13 @@ void DataFilesPage::showContextMenu(const QPoint &point)
// Show menu
mContextMenu->exec(globalPos);
}
/*
if (object->objectName() == QLatin1String("MastersTable")) {
if (!mastersTable->selectionModel()->hasSelection())
if (object->objectName() == QLatin1String("MasterView")) {
if (!masterView->selectionModel()->hasSelection())
return;
QPoint globalPos = mastersTable->mapToGlobal(point);
QModelIndexList indexes = mastersTable->selectionModel()->selectedIndexes();
QPoint globalPos = masterView->mapToGlobal(point);
QModelIndexList indexes = masterView->selectionModel()->selectedIndexes();
// Show the check/uncheck actions depending on the state of the selected items
uncheckAction->setEnabled(false);
@ -456,5 +362,6 @@ void DataFilesPage::showContextMenu(const QPoint &point)
mContextMenu->exec(globalPos);
}
*/
}
*/

@ -38,21 +38,16 @@ signals:
public slots:
void setProfilesComboBoxIndex(int index);
void showContextMenu(const QPoint &point);
//void showContextMenu(const QPoint &point);
void profileChanged(const QString &previous, const QString &current);
void profileRenamed(const QString &previous, const QString &current);
void updateOkButton(const QString &text);
void updateSplitter();
void updateViews();
// Action slots
void on_newProfileAction_triggered();
void on_deleteProfileAction_triggered();
void on_checkAction_triggered();
void on_uncheckAction_triggered();
private slots:
void slotCurrentIndexChanged(int index);
private:
@ -65,7 +60,6 @@ private:
TextInputDialog *mNewProfileDialog;
void setMastersCheckstates(Qt::CheckState state);
void setPluginsCheckstates(Qt::CheckState state);
void createActions();

@ -49,23 +49,11 @@ FileDialog::FileDialog(QWidget *parent) :
verticalLayout->addLayout(nameLayout);
verticalLayout->addWidget(mButtonBox);
// Set sizes
QList<int> sizeList;
sizeList << 175;
sizeList << 200;
splitter->setSizes(sizeList);
resize(600, 400);
// connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList)));
//connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString)));
//connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
// connect(pluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
//connect(mastersTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
// connect(mCreateButton, SIGNAL(clicked()), this, SLOT(createButtonClicked()));
// connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
@ -89,13 +77,6 @@ void FileDialog::updateCreateButton(const QString &name)
mCreateButton->setEnabled(!name.isEmpty());
}
/*
void FileDialog::filterChanged(const QString &filter)
{
QRegExp filterRe(filter, Qt::CaseInsensitive, QRegExp::FixedString);
mFilterProxyModel->setFilterRegExp(filterRe);
}
*/
QString FileDialog::fileName()
{

@ -42,9 +42,6 @@ private slots:
void updateOpenButton(const QStringList &items);
void updateCreateButton(const QString &name);
//void filterChanged(const QString &filter);
void createButtonClicked();
private:

@ -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);
}

@ -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);
};
}

@ -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;
}

@ -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));
}
};

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

@ -10,7 +10,7 @@
<height>304</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="filterLayout">
<item>
@ -23,21 +23,33 @@
</layout>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QTableView" name="pluginsTable"/>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="pluginView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideLeft</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">

Loading…
Cancel
Save