1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Continued migration of code to ContentSelector

This commit is contained in:
graffy76 2013-08-17 05:55:43 -05:00
parent 0087b0d67c
commit b24dd5c6ac
7 changed files with 17 additions and 185 deletions

View File

@ -21,63 +21,14 @@
#include "utils/textinputdialog.hpp" #include "utils/textinputdialog.hpp"
#include <QDebug>
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent) DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent)
: mCfgMgr(cfg) : mCfgMgr(cfg)
, mGameSettings(gameSettings) , mGameSettings(gameSettings)
, mLauncherSettings(launcherSettings) , mLauncherSettings(launcherSettings)
, ContentSelector(parent) , ContentSelector(parent)
{ {
setupUi(this);
buildModelsAndViews();
/*
// Models
mDataFilesModel = new DataFilesModel (this);
mMastersProxyModel = new MasterProxyModel (this, mDataFilesModel);
mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel);
mFilterProxyModel = new QSortFilterProxyModel();
mFilterProxyModel->setDynamicSortFilter(true);
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
masterView->setModel (mMastersProxyModel);
//QCheckBox checkBox;
// unsigned int height = checkBox.sizeHint().height() + 4;
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);
mastersTable->horizontalHeader()->hide();
// Set the row height to the size of the checkboxes
mastersTable->verticalHeader()->setDefaultSectionSize(height);
mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
mastersTable->verticalHeader()->hide();
pluginsTable->setModel(mFilterProxyModel);
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);
pluginsTable->horizontalHeader()->hide();
//pluginsTable->verticalHeader()->setDefaultSectionSize(height);
//pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
*/
// Adjust the tableview widths inside the splitter // Adjust the tableview widths inside the splitter
QList<int> sizeList; QList<int> sizeList;
sizeList << mLauncherSettings.value(QString("General/MastersTable/width"), QString("200")).toInt(); sizeList << mLauncherSettings.value(QString("General/MastersTable/width"), QString("200")).toInt();
@ -98,8 +49,6 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
connect(pluginsTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); connect(pluginsTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
//connect(mastersTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); //connect(mastersTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
//connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); //connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
connect(splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(updateSplitter())); connect(splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(updateSplitter()));
@ -123,6 +72,9 @@ void DataFilesPage::createActions()
void DataFilesPage::setupDataFiles() void DataFilesPage::setupDataFiles()
{ {
if (!mDataFilesModel)
qDebug() << "data files model undefined";
// Set the encoding to the one found in openmw.cfg or the default // Set the encoding to the one found in openmw.cfg or the default
mDataFilesModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); mDataFilesModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252")));
@ -384,8 +336,7 @@ void DataFilesPage::setPluginsCheckstates(Qt::CheckState state)
if (!index.isValid()) if (!index.isValid())
return; return;
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource( QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
mFilterProxyModel->mapToSource(index));
if (!sourceIndex.isValid()) if (!sourceIndex.isValid())
return; return;
@ -394,48 +345,6 @@ void DataFilesPage::setPluginsCheckstates(Qt::CheckState state)
} }
} }
void DataFilesPage::setCheckState(QModelIndex index)
{
if (!index.isValid())
return;
QObject *object = QObject::sender();
// Not a signal-slot call
if (!object)
return;
if (object->objectName() == QLatin1String("PluginsTable")) {
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(
mFilterProxyModel->mapToSource(index));
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 = mMastersProxyModel->mapToSource(index);
if (sourceIndex.isValid()) {
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked)
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
}
}
return;
}
void DataFilesPage::filterChanged(const QString filter)
{
QRegExp regExp(filter, Qt::CaseInsensitive, QRegExp::FixedString);
mFilterProxyModel->setFilterRegExp(regExp);
}
void DataFilesPage::profileChanged(const QString &previous, const QString &current) void DataFilesPage::profileChanged(const QString &previous, const QString &current)
{ {
// Prevent the deletion of the default profile // Prevent the deletion of the default profile
@ -505,8 +414,7 @@ void DataFilesPage::showContextMenu(const QPoint &point)
if (!index.isValid()) if (!index.isValid())
return; return;
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource( QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
mFilterProxyModel->mapToSource(index));
if (!sourceIndex.isValid()) if (!sourceIndex.isValid())
return; return;

View File

@ -36,10 +36,8 @@ signals:
void profileChanged(int index); void profileChanged(int index);
public slots: public slots:
void setCheckState(QModelIndex index);
void setProfilesComboBoxIndex(int index); void setProfilesComboBoxIndex(int index);
void filterChanged(const QString filter);
void showContextMenu(const QPoint &point); void showContextMenu(const QPoint &point);
void profileChanged(const QString &previous, const QString &current); void profileChanged(const QString &previous, const QString &current);
void profileRenamed(const QString &previous, const QString &current); void profileRenamed(const QString &previous, const QString &current);
@ -57,12 +55,6 @@ private slots:
void slotCurrentIndexChanged(int index); void slotCurrentIndexChanged(int index);
private: private:
DataFilesModel *mDataFilesModel;
PluginsProxyModel *mPluginsProxyModel;
QSortFilterProxyModel *mMastersProxyModel;
QSortFilterProxyModel *mFilterProxyModel;
QMenu *mContextMenu; QMenu *mContextMenu;

View File

@ -21,55 +21,6 @@
FileDialog::FileDialog(QWidget *parent) : FileDialog::FileDialog(QWidget *parent) :
ContentSelector(parent) ContentSelector(parent)
{ {
setupUi(this);
buildModelsAndViews();
/*
// Models
mDataFilesModel = new DataFilesModel (this);
mMastersProxyModel = new MasterProxyModel (this, mDataFilesModel);
mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel);
mFilterProxyModel = new QSortFilterProxyModel();
mFilterProxyModel->setDynamicSortFilter(true);
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
// QCheckBox checkBox;
// unsigned int height = checkBox.sizeHint().height() + 4;
masterView->setModel(mMastersProxyModel);
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(mFilterProxyModel);
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);
// pluginsTable->verticalHeader()->setDefaultSectionSize(height);
// pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
*/
// Hide the profile elements // Hide the profile elements
profileLabel->hide(); profileLabel->hide();
profilesComboBox->hide(); profilesComboBox->hide();
@ -107,7 +58,6 @@ FileDialog::FileDialog(QWidget *parent) :
resize(600, 400); resize(600, 400);
//
// connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList)));
//connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); //connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString)));

View File

@ -53,12 +53,6 @@ private:
QPushButton *mCreateButton; QPushButton *mCreateButton;
QDialogButtonBox *mButtonBox; QDialogButtonBox *mButtonBox;
DataFilesModel *mDataFilesModel;
PluginsProxyModel *mPluginsProxyModel;
QSortFilterProxyModel *mMastersProxyModel;
QSortFilterProxyModel *mFilterProxyModel;
}; };
#endif // FILEDIALOG_HPP #endif // FILEDIALOG_HPP

View File

@ -9,6 +9,8 @@
FileOrderList::ContentSelector::ContentSelector(QWidget *parent) : FileOrderList::ContentSelector::ContentSelector(QWidget *parent) :
QWidget(parent) QWidget(parent)
{ {
setupUi(this);
buildModelsAndViews();
} }
void FileOrderList::ContentSelector::buildModelsAndViews() void FileOrderList::ContentSelector::buildModelsAndViews()
@ -19,11 +21,6 @@ void FileOrderList::ContentSelector::buildModelsAndViews()
mMasterProxyModel = new FileOrderList::MasterProxyModel (this, mDataFilesModel); mMasterProxyModel = new FileOrderList::MasterProxyModel (this, mDataFilesModel);
mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel); mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel);
mFilterProxyModel = new QSortFilterProxyModel();
mFilterProxyModel->setDynamicSortFilter(true);
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
masterView->setModel(mMasterProxyModel); masterView->setModel(mMasterProxyModel);
/* /*
mastersTable->setModel(mMastersProxyModel); mastersTable->setModel(mMastersProxyModel);
@ -41,7 +38,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews()
mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed); mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
mastersTable->verticalHeader()->hide(); mastersTable->verticalHeader()->hide();
*/ */
pluginsTable->setModel(mFilterProxyModel); pluginsTable->setModel(mPluginsProxyModel);
pluginsTable->setObjectName("PluginsTable"); pluginsTable->setObjectName("PluginsTable");
pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu); pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu);
pluginsTable->setSortingEnabled(false); pluginsTable->setSortingEnabled(false);
@ -79,8 +76,7 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index)
if (object->objectName() == QLatin1String("PluginsTable")) { if (object->objectName() == QLatin1String("PluginsTable")) {
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource( QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
mFilterProxyModel->mapToSource(index));
if (sourceIndex.isValid()) { if (sourceIndex.isValid()) {
(mDataFilesModel->checkState(sourceIndex) == Qt::Checked) (mDataFilesModel->checkState(sourceIndex) == Qt::Checked)
@ -88,7 +84,7 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index)
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked); : mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
} }
} }
/*
if (object->objectName() == QLatin1String("MastersTable")) { if (object->objectName() == QLatin1String("MastersTable")) {
QModelIndex sourceIndex = mMasterProxyModel->mapToSource(index); QModelIndex sourceIndex = mMasterProxyModel->mapToSource(index);
@ -98,7 +94,7 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index)
: mDataFilesModel->setCheckState(sourceIndex, Qt::Checked); : mDataFilesModel->setCheckState(sourceIndex, Qt::Checked);
} }
} }
*/
return; return;
} }
@ -110,16 +106,6 @@ QStringList FileOrderList::ContentSelector::checkedItemsPaths()
void FileOrderList::ContentSelector::updateViews() void FileOrderList::ContentSelector::updateViews()
{ {
// Ensure the columns are hidden because sort() re-enables them // Ensure the columns are hidden because sort() re-enables them
/*
mastersTable->setColumnHidden(1, 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);
mastersTable->resizeColumnsToContents();
*/
pluginsTable->setColumnHidden(1, true); pluginsTable->setColumnHidden(1, true);
pluginsTable->setColumnHidden(3, true); pluginsTable->setColumnHidden(3, true);
pluginsTable->setColumnHidden(4, true); pluginsTable->setColumnHidden(4, true);

View File

@ -17,10 +17,11 @@ namespace FileOrderList
{ {
Q_OBJECT Q_OBJECT
protected:
DataFilesModel *mDataFilesModel; DataFilesModel *mDataFilesModel;
MasterProxyModel *mMasterProxyModel; MasterProxyModel *mMasterProxyModel;
PluginsProxyModel *mPluginsProxyModel; PluginsProxyModel *mPluginsProxyModel;
QSortFilterProxyModel *mFilterProxyModel;
public: public:
explicit ContentSelector(QWidget *parent = 0); explicit ContentSelector(QWidget *parent = 0);

View File

@ -4,8 +4,9 @@
PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) :
QSortFilterProxyModel(parent), mSourceModel (model) QSortFilterProxyModel(parent), mSourceModel (model)
{ {
setFilterRegExp(QString("addon")); setFilterRegExp (QString("addon"));
setFilterRole (Qt::UserRole); setFilterRole (Qt::UserRole);
setDynamicSortFilter (true);
if (model) if (model)
setSourceModel (model); setSourceModel (model);