1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 19:45:35 +00:00
openmw/components/esxselector/view/contentselector.cpp

151 lines
4.4 KiB
C++
Raw Normal View History

#include "contentselector.hpp"
#include "../model/datafilesmodel.hpp"
2013-09-07 20:57:40 +00:00
#include "../model/contentmodel.hpp"
#include "../model/esmfile.hpp"
#include <QSortFilterProxyModel>
#include <QDebug>
2013-08-18 13:54:51 +00:00
#include <QMenu>
#include <QContextMenuEvent>
EsxView::ContentSelector::ContentSelector(QWidget *parent) :
2013-08-20 17:34:39 +00:00
QDialog(parent)
{
setupUi(this);
2013-09-18 07:36:23 +00:00
buildSourceModel();
buildMasterView();
buildPluginsView();
buildProfilesView();
updateViews();
2013-09-07 20:57:40 +00:00
}
2013-09-18 07:36:23 +00:00
void EsxView::ContentSelector::buildSourceModel()
2013-09-07 20:57:40 +00:00
{
mContentModel = new EsxModel::ContentModel();
2013-09-18 07:36:23 +00:00
connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
}
2013-09-07 20:57:40 +00:00
2013-09-18 07:36:23 +00:00
void EsxView::ContentSelector::buildMasterView()
{
mMasterProxyModel = new QSortFilterProxyModel(this);
mMasterProxyModel->setFilterRegExp(QString("game"));
mMasterProxyModel->setFilterRole (Qt::UserRole);
mMasterProxyModel->setSourceModel (mContentModel);
2013-09-07 20:57:40 +00:00
masterView->setPlaceholderText(QString("Select a game file..."));
masterView->setModel(mMasterProxyModel);
connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int)));
2013-09-18 07:36:23 +00:00
masterView->setCurrentIndex(-1);
masterView->setCurrentIndex(0);
}
2013-09-18 07:36:23 +00:00
void EsxView::ContentSelector::buildPluginsView()
{
2013-09-18 07:36:23 +00:00
mPluginsProxyModel = new QSortFilterProxyModel(this);
mPluginsProxyModel->setFilterRegExp (QString("addon"));
mPluginsProxyModel->setFilterRole (Qt::UserRole);
mPluginsProxyModel->setDynamicSortFilter (true);
mPluginsProxyModel->setSourceModel (mContentModel);
2013-09-18 07:36:23 +00:00
tableView->setModel (mPluginsProxyModel);
pluginView->setModel(mPluginsProxyModel);
2013-08-18 22:11:23 +00:00
2013-08-18 13:54:51 +00:00
connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &)));
2013-09-18 07:36:23 +00:00
connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &)));
}
void EsxView::ContentSelector::buildProfilesView()
{
profilesComboBox->setPlaceholderText(QString("Select a profile..."));
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
}
2013-09-18 07:36:23 +00:00
void EsxView::ContentSelector::updateViews()
{
// Ensure the columns are hidden because sort() re-enables them
pluginView->setColumnHidden(1, true);
pluginView->setColumnHidden(2, 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 EsxView::ContentSelector::addFiles(const QString &path)
{
2013-09-07 20:57:40 +00:00
mContentModel->addFiles(path);
mContentModel->sort(3); // Sort by date accessed
masterView->setCurrentIndex(-1);
2013-09-07 20:57:40 +00:00
mContentModel->uncheckAll();
}
void EsxView::ContentSelector::setEncoding(const QString &encoding)
{
2013-09-07 20:57:40 +00:00
mContentModel->setEncoding(encoding);
}
QStringList EsxView::ContentSelector::checkedItemsPaths()
{
2013-09-07 20:57:40 +00:00
QStringList itemPaths;
foreach( const EsxModel::EsmFile *file, mContentModel->checkedItems())
itemPaths << file->path();
return itemPaths;
}
void EsxView::ContentSelector::slotCurrentProfileIndexChanged(int index)
{
emit profileChanged(index);
}
void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index)
{
2013-09-18 07:36:23 +00:00
static int oldIndex = -1;
QAbstractItemModel *const model = masterView->model();
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
if (proxy)
proxy->setDynamicSortFilter(false);
if (oldIndex > -1)
model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1);
oldIndex = index;
2013-09-18 07:36:23 +00:00
model->setData(model->index(index, 0), true, Qt::UserRole + 1);
2013-09-18 07:36:23 +00:00
if (proxy)
proxy->setDynamicSortFilter(true);
}
2013-08-18 13:54:51 +00:00
void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index)
2013-08-18 13:54:51 +00:00
{
2013-09-07 20:57:40 +00:00
qDebug() << "setting checkstate in plugin...";
2013-09-18 07:36:23 +00:00
QAbstractItemModel *const model = pluginView->model();
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
if (proxy)
proxy->setDynamicSortFilter(false);
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
model->setData(index, Qt::Checked, Qt::CheckStateRole);
else
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
if (proxy)
proxy->setDynamicSortFilter(true);
2013-08-18 13:54:51 +00:00
}