Began migrating code to ContentSelector base

actorid
graffy76 12 years ago
parent 4c8c6d6971
commit 61602789e1

@ -15,7 +15,7 @@
#include <components/fileorderlist/utils/naturalsort.hpp>
#include <components/fileorderlist/utils/profilescombobox.hpp>
#include <components/fileorderlist/masterproxymodel.hpp>"a.out.h"
#include "components/fileorderlist/masterproxymodel.hpp"
#include "settings/gamesettings.hpp"
#include "settings/launchersettings.hpp"
@ -25,10 +25,11 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
: mCfgMgr(cfg)
, mGameSettings(gameSettings)
, mLauncherSettings(launcherSettings)
, QWidget(parent)
, ContentSelector(parent)
{
setupUi(this);
buildModelsAndViews();
/*
// Models
mDataFilesModel = new DataFilesModel (this);
@ -41,11 +42,11 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
masterView->setModel (mMastersProxyModel);
/*
QCheckBox checkBox;
unsigned int height = checkBox.sizeHint().height() + 4;
*/
/*
//QCheckBox checkBox;
// unsigned int height = checkBox.sizeHint().height() + 4;
mastersTable->setModel(mMastersProxyModel);
mastersTable->setObjectName("MastersTable");
mastersTable->setContextMenuPolicy(Qt::CustomContextMenu);
@ -61,7 +62,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
mastersTable->verticalHeader()->setDefaultSectionSize(height);
mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
mastersTable->verticalHeader()->hide();
*/
pluginsTable->setModel(mFilterProxyModel);
pluginsTable->setObjectName("PluginsTable");
pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu);
@ -76,7 +77,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
//pluginsTable->verticalHeader()->setDefaultSectionSize(height);
//pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
*/
// Adjust the tableview widths inside the splitter
QList<int> sizeList;
sizeList << mLauncherSettings.value(QString("General/MastersTable/width"), QString("200")).toInt();

@ -5,6 +5,7 @@
#include <QModelIndex>
#include "ui_datafilespage.h"
#include "components/fileorderlist/contentselector.hpp"
class QSortFilterProxyModel;
class QAbstractItemModel;
@ -19,10 +20,9 @@ class PluginsProxyModel;
namespace Files { struct ConfigurationManager; }
class DataFilesPage : public QWidget, private Ui::DataFilesPage
class DataFilesPage : public FileOrderList::ContentSelector
{
Q_OBJECT
public:
DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent = 0);

@ -19,10 +19,11 @@
#include "components/fileorderlist/masterproxymodel.hpp"
FileDialog::FileDialog(QWidget *parent) :
QDialog(parent)
ContentSelector(parent)
{
setupUi(this);
buildModelsAndViews();
/*
// Models
mDataFilesModel = new DataFilesModel (this);
@ -33,12 +34,12 @@ FileDialog::FileDialog(QWidget *parent) :
mFilterProxyModel = new QSortFilterProxyModel();
mFilterProxyModel->setDynamicSortFilter(true);
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
/*
QCheckBox checkBox;
unsigned int height = checkBox.sizeHint().height() + 4;
*/
// QCheckBox checkBox;
// unsigned int height = checkBox.sizeHint().height() + 4;
masterView->setModel(mMastersProxyModel);
/*
mastersTable->setModel(mMastersProxyModel);
mastersTable->setObjectName("MastersTable");
mastersTable->setContextMenuPolicy(Qt::CustomContextMenu);
@ -53,7 +54,7 @@ FileDialog::FileDialog(QWidget *parent) :
mastersTable->verticalHeader()->setDefaultSectionSize(height);
mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
mastersTable->verticalHeader()->hide();
*/
pluginsTable->setModel(mFilterProxyModel);
pluginsTable->setObjectName("PluginsTable");
pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu);
@ -64,10 +65,11 @@ FileDialog::FileDialog(QWidget *parent) :
pluginsTable->setAlternatingRowColors(true);
pluginsTable->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
pluginsTable->horizontalHeader()->setStretchLastSection(true);
/*
pluginsTable->verticalHeader()->setDefaultSectionSize(height);
pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
*/
// pluginsTable->verticalHeader()->setDefaultSectionSize(height);
// pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
*/
// Hide the profile elements
profileLabel->hide();
profilesComboBox->hide();
@ -105,43 +107,19 @@ FileDialog::FileDialog(QWidget *parent) :
resize(600, 400);
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
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(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
connect(pluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex)));
// 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()));
connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
void FileDialog::updateViews()
{
// 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(3, true);
pluginsTable->setColumnHidden(4, true);
pluginsTable->setColumnHidden(5, true);
pluginsTable->setColumnHidden(6, true);
pluginsTable->setColumnHidden(7, true);
pluginsTable->setColumnHidden(8, true);
pluginsTable->resizeColumnsToContents();
// connect(mCreateButton, SIGNAL(clicked()), this, SLOT(createButtonClicked()));
// connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
// connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
void FileDialog::updateOpenButton(const QStringList &items)
@ -161,64 +139,13 @@ 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);
}
void FileDialog::addFiles(const QString &path)
{
mDataFilesModel->addFiles(path);
mDataFilesModel->sort(3); // Sort by date accessed
}
void FileDialog::setEncoding(const QString &encoding)
{
mDataFilesModel->setEncoding(encoding);
}
void FileDialog::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;
}
QStringList FileDialog::checkedItemsPaths()
{
return mDataFilesModel->checkedItemsPaths();
}
*/
QString FileDialog::fileName()
{

@ -4,6 +4,7 @@
#include <QDialog>
#include <QModelIndex>
#include "components/fileorderlist/contentselector.hpp"
#include "ui_datafilespage.h"
class QDialogButtonBox;
@ -17,19 +18,16 @@ class QMenu;
class DataFilesModel;
class PluginsProxyModel;
class FileDialog : public QDialog, private Ui::DataFilesPage
class FileDialog : public FileOrderList::ContentSelector
{
Q_OBJECT
public:
explicit FileDialog(QWidget *parent = 0);
void addFiles(const QString &path);
void setEncoding(const QString &encoding);
void openFile();
void newFile();
void accepted();
QStringList checkedItemsPaths();
QString fileName();
signals:
@ -40,12 +38,12 @@ public slots:
void accept();
private slots:
void updateViews();
//void updateViews();
void updateOpenButton(const QStringList &items);
void updateCreateButton(const QString &name);
void setCheckState(QModelIndex index);
void filterChanged(const QString &filter);
//void filterChanged(const QString &filter);
void createButtonClicked();

@ -66,22 +66,25 @@ add_component_dir (translation
translation
)
set (ESM_UI ${CMAKE_SOURCE_DIR}/files/ui/datafilespage.ui
)
find_package(Qt4 COMPONENTS QtCore QtGui)
if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY)
add_component_qt_dir (fileorderlist
masterproxymodel
masterproxymodel contentselector
model/modelitem model/datafilesmodel model/pluginsproxymodel model/esm/esmfile
utils/profilescombobox utils/comboboxlineedit utils/lineedit utils/naturalsort
)
include(${QT_USE_FILE})
QT4_WRAP_UI(ESM_UI_HDR ${ESM_UI})
QT4_WRAP_CPP(MOC_SRCS ${COMPONENT_MOC_FILES})
endif(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY)
include_directories(${BULLET_INCLUDE_DIRS})
include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS})
add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR})
target_link_libraries(components ${Boost_LIBRARIES} ${OGRE_LIBRARIES})

@ -0,0 +1,132 @@
#include "contentselector.hpp"
#include "model/datafilesmodel.hpp"
#include "masterproxymodel.hpp"
#include "model/pluginsproxymodel.hpp"
#include <QSortFilterProxyModel>
FileOrderList::ContentSelector::ContentSelector(QWidget *parent) :
QWidget(parent)
{
}
void FileOrderList::ContentSelector::buildModelsAndViews()
{
// Models
mDataFilesModel = new DataFilesModel (this);
mMasterProxyModel = new FileOrderList::MasterProxyModel (this, mDataFilesModel);
mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel);
mFilterProxyModel = new QSortFilterProxyModel();
mFilterProxyModel->setDynamicSortFilter(true);
mFilterProxyModel->setSourceModel(mPluginsProxyModel);
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(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);
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
}
void FileOrderList::ContentSelector::addFiles(const QString &path)
{
mDataFilesModel->addFiles(path);
mDataFilesModel->sort(3); // Sort by date accessed
}
void FileOrderList::ContentSelector::setEncoding(const QString &encoding)
{
mDataFilesModel->setEncoding(encoding);
}
void FileOrderList::ContentSelector::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 = 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()
{
return mDataFilesModel->checkedItemsPaths();
}
void FileOrderList::ContentSelector::updateViews()
{
// 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(3, true);
pluginsTable->setColumnHidden(4, true);
pluginsTable->setColumnHidden(5, true);
pluginsTable->setColumnHidden(6, true);
pluginsTable->setColumnHidden(7, true);
pluginsTable->setColumnHidden(8, true);
pluginsTable->resizeColumnsToContents();
}

@ -0,0 +1,40 @@
#ifndef CONTENTSELECTOR_HPP
#define CONTENTSELECTOR_HPP
#include <QWidget>
#include "ui_datafilespage.h"
class DataFilesModel;
class PluginsProxyModel;
class QSortFilterProxyModel;
namespace FileOrderList
{
class MasterProxyModel;
class ContentSelector : public QWidget, protected Ui::DataFilesPage
{
Q_OBJECT
DataFilesModel *mDataFilesModel;
MasterProxyModel *mMasterProxyModel;
PluginsProxyModel *mPluginsProxyModel;
QSortFilterProxyModel *mFilterProxyModel;
public:
explicit ContentSelector(QWidget *parent = 0);
void buildModelsAndViews();
void addFiles(const QString &path);
void setEncoding(const QString &encoding);
void setCheckState(QModelIndex index);
QStringList checkedItemsPaths();
private slots:
void updateViews();
};
}
#endif // CONTENTSELECTOR_HPP

@ -1,6 +1,6 @@
#include "masterproxymodel.hpp"
MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) :
FileOrderList::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) :
QSortFilterProxyModel(parent)
{
setFilterRegExp(QString("game"));
@ -10,7 +10,7 @@ MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model)
setSourceModel (model);
}
QVariant MasterProxyModel::data(const QModelIndex &index, int role) const
QVariant FileOrderList::MasterProxyModel::data(const QModelIndex &index, int role) const
{
return QSortFilterProxyModel::data (index, role);
}

@ -5,17 +5,19 @@
class QAbstractTableModel;
class MasterProxyModel : public QSortFilterProxyModel
namespace FileOrderList
{
Q_OBJECT
public:
explicit MasterProxyModel(QObject *parent = 0, QAbstractTableModel *model = 0);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
class MasterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit MasterProxyModel(QObject *parent = 0, QAbstractTableModel *model = 0);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
signals:
public slots:
};
signals:
public slots:
};
}
#endif // MASTERPROXYMODEL_HPP

Loading…
Cancel
Save