From bfb71f23c9f2e1c3b9f6525ef1ed8b1185425c6d Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 17:26:23 -0500 Subject: [PATCH 01/42] Changed filter mechanism for game / addons Filters by number of master references, regardless of extension --- apps/opencs/view/doc/filedialog.cpp | 8 ++++---- components/fileorderlist/model/datafilesmodel.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index f956317a7..02421a788 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -25,13 +25,13 @@ FileDialog::FileDialog(QWidget *parent) : mDataFilesModel = new DataFilesModel(this); mMastersProxyModel = new QSortFilterProxyModel(); - mMastersProxyModel->setFilterRegExp(QString("^.*\\.esm")); - mMastersProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + mMastersProxyModel->setFilterRegExp("game"); //QString("^.*\\.esm")); + mMastersProxyModel->setFilterRole (Qt::UserRole); mMastersProxyModel->setSourceModel(mDataFilesModel); mPluginsProxyModel = new PluginsProxyModel(); - mPluginsProxyModel->setFilterRegExp(QString("^.*\\.esp")); - mPluginsProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + mPluginsProxyModel->setFilterRegExp("addon"); //QString("^.*\\.esp")); + mPluginsProxyModel->setFilterRole (Qt::UserRole); mPluginsProxyModel->setSourceModel(mDataFilesModel); mFilterProxyModel = new QSortFilterProxyModel(); diff --git a/components/fileorderlist/model/datafilesmodel.cpp b/components/fileorderlist/model/datafilesmodel.cpp index 02a6766b0..cf1fa1b0a 100644 --- a/components/fileorderlist/model/datafilesmodel.cpp +++ b/components/fileorderlist/model/datafilesmodel.cpp @@ -144,6 +144,15 @@ QVariant DataFilesModel::data(const QModelIndex &index, int role) const return tooltip; } + + case Qt::UserRole: + { + if (file->masters().size() == 0) + return "game"; + else + return "addon"; + } + default: return QVariant(); } From 84e5c2610ab0347127645e277f08dd83e11383fd Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 18:00:23 -0500 Subject: [PATCH 02/42] Implemented combobox for game file selection --- apps/launcher/datafilespage.cpp | 2 +- apps/opencs/view/doc/filedialog.cpp | 20 +++++++------- apps/opencs/view/doc/filedialog.hpp | 2 +- .../fileorderlist/utils/profilescombobox.cpp | 16 +++++++++++ .../fileorderlist/utils/profilescombobox.hpp | 5 +++- files/ui/datafilespage.ui | 27 +++---------------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index add3dea40..1fafd5922 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -101,7 +101,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam 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())); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 02421a788..b06c97008 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -41,6 +41,8 @@ FileDialog::FileDialog(QWidget *parent) : QCheckBox checkBox; unsigned int height = checkBox.sizeHint().height() + 4; + masterView->setModel(mMastersProxyModel); + mastersTable->setModel(mMastersProxyModel); mastersTable->setObjectName("MastersTable"); mastersTable->setContextMenuPolicy(Qt::CustomContextMenu); @@ -83,12 +85,12 @@ FileDialog::FileDialog(QWidget *parent) : mNameLabel = new QLabel(tr("File Name:"), this); QRegExpValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9\\s]*$")); - mNameLineEdit = new LineEdit(this); - mNameLineEdit->setValidator(validator); + //mNameLineEdit = new LineEdit(this); + //mNameLineEdit->setValidator(validator); nameLayout->addSpacerItem(spacer); nameLayout->addWidget(mNameLabel); - nameLayout->addWidget(mNameLineEdit); + //nameLayout->addWidget(mNameLineEdit); mButtonBox = new QDialogButtonBox(this); @@ -109,9 +111,9 @@ FileDialog::FileDialog(QWidget *parent) : connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); 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))); - connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(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))); @@ -223,7 +225,7 @@ QStringList FileDialog::checkedItemsPaths() QString FileDialog::fileName() { - return mNameLineEdit->text(); + //return mNameLineEdit->text(); } void FileDialog::openFile() @@ -231,7 +233,7 @@ void FileDialog::openFile() setWindowTitle(tr("Open")); mNameLabel->hide(); - mNameLineEdit->hide(); + //mNameLineEdit->hide(); mCreateButton->hide(); mButtonBox->removeButton(mCreateButton); @@ -249,8 +251,8 @@ void FileDialog::newFile() setWindowTitle(tr("New")); mNameLabel->show(); - mNameLineEdit->clear(); - mNameLineEdit->show(); + //mNameLineEdit->clear(); + //mNameLineEdit->show(); mCreateButton->show(); mButtonBox->setStandardButtons(QDialogButtonBox::Cancel); diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index b21618d5d..4c3fe9ffa 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -51,7 +51,7 @@ private slots: private: QLabel *mNameLabel; - LineEdit *mNameLineEdit; + //LineEdit *mNameLineEdit; QPushButton *mCreateButton; QDialogButtonBox *mButtonBox; diff --git a/components/fileorderlist/utils/profilescombobox.cpp b/components/fileorderlist/utils/profilescombobox.cpp index c3ff953ae..9346276da 100644 --- a/components/fileorderlist/utils/profilescombobox.cpp +++ b/components/fileorderlist/utils/profilescombobox.cpp @@ -90,3 +90,19 @@ void ProfilesComboBox::slotIndexChanged(int index) emit(profileChanged(mOldProfile, currentText())); mOldProfile = itemText(index); } + +void ProfilesComboBox::paintEvent(QPaintEvent *) +{ + QStylePainter painter(this); + painter.setPen(palette().color(QPalette::Text)); + + // draw the combobox frame, focusrect and selected etc. + QStyleOptionComboBox opt; + initStyleOption(&opt); + painter.drawComplexControl(QStyle::CC_ComboBox, opt); + + // draw the icon and text + if (!opt.editable && currentIndex() == -1) // <<< we adjust the text displayed when nothing is selected + opt.currentText = tr("Select a game file..."); + painter.drawControl(QStyle::CE_ComboBoxLabel, opt); +} diff --git a/components/fileorderlist/utils/profilescombobox.hpp b/components/fileorderlist/utils/profilescombobox.hpp index 08ead9a7a..55913d7fe 100644 --- a/components/fileorderlist/utils/profilescombobox.hpp +++ b/components/fileorderlist/utils/profilescombobox.hpp @@ -2,7 +2,7 @@ #define PROFILESCOMBOBOX_HPP #include - +#include class QString; class QRegExpValidator; @@ -25,6 +25,9 @@ private slots: private: QString mOldProfile; QRegExpValidator *mValidator; + +protected: + void paintEvent(QPaintEvent *); }; #endif // PROFILESCOMBOBOX_HPP diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 041a9576d..342e4d9e9 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -14,28 +14,12 @@ - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Filter: + + + false - - - @@ -151,11 +135,6 @@ - - LineEdit - QLineEdit -
components/fileorderlist/utils/lineedit.hpp
-
ProfilesComboBox QComboBox From 49c4e1bf9eccd1efd91c371a22e0810a5c8cb815 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 18:23:02 -0500 Subject: [PATCH 03/42] Removed master table widget --- apps/launcher/datafilespage.cpp | 34 +++++++++++++++-------------- apps/opencs/view/doc/filedialog.cpp | 9 ++++---- files/ui/datafilespage.ui | 1 - 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 1fafd5922..077f3c292 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -47,7 +47,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam QCheckBox checkBox; unsigned int height = checkBox.sizeHint().height() + 4; - +/* mastersTable->setModel(mMastersProxyModel); mastersTable->setObjectName("MastersTable"); mastersTable->setContextMenuPolicy(Qt::CustomContextMenu); @@ -63,7 +63,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); @@ -94,10 +94,10 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam 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(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(mastersTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); @@ -255,6 +255,7 @@ void DataFilesPage::updateSplitter() 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); @@ -263,7 +264,7 @@ void DataFilesPage::updateViews() mastersTable->setColumnHidden(6, true); mastersTable->setColumnHidden(7, true); mastersTable->setColumnHidden(8, true); - +*/ pluginsTable->setColumnHidden(1, true); pluginsTable->setColumnHidden(2, true); pluginsTable->setColumnHidden(3, true); @@ -335,8 +336,8 @@ void DataFilesPage::on_checkAction_triggered() if (pluginsTable->hasFocus()) setPluginsCheckstates(Qt::Checked); - if (mastersTable->hasFocus()) - setMastersCheckstates(Qt::Checked); + //if (mastersTable->hasFocus()) + // setMastersCheckstates(Qt::Checked); } @@ -345,17 +346,17 @@ void DataFilesPage::on_uncheckAction_triggered() if (pluginsTable->hasFocus()) setPluginsCheckstates(Qt::Unchecked); - if (mastersTable->hasFocus()) - setMastersCheckstates(Qt::Unchecked); + //if (mastersTable->hasFocus()) + // setMastersCheckstates(Qt::Unchecked); } void DataFilesPage::setMastersCheckstates(Qt::CheckState state) -{ - if (!mastersTable->selectionModel()->hasSelection()) { - return; - } +{/* + //if (!mastersTable->selectionModel()->hasSelection()) { + // return; + //} - QModelIndexList indexes = mastersTable->selectionModel()->selectedIndexes(); + //QModelIndexList indexes = mastersTable->selectionModel()->selectedIndexes(); foreach (const QModelIndex &index, indexes) { @@ -368,7 +369,7 @@ void DataFilesPage::setMastersCheckstates(Qt::CheckState state) return; mDataFilesModel->setCheckState(sourceIndex, state); - } + }*/ } void DataFilesPage::setPluginsCheckstates(Qt::CheckState state) @@ -519,7 +520,7 @@ void DataFilesPage::showContextMenu(const QPoint &point) // Show menu mContextMenu->exec(globalPos); } - +/* if (object->objectName() == QLatin1String("MastersTable")) { if (!mastersTable->selectionModel()->hasSelection()) return; @@ -548,4 +549,5 @@ void DataFilesPage::showContextMenu(const QPoint &point) mContextMenu->exec(globalPos); } + */ } diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index b06c97008..a07b854df 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -42,7 +42,7 @@ FileDialog::FileDialog(QWidget *parent) : unsigned int height = checkBox.sizeHint().height() + 4; masterView->setModel(mMastersProxyModel); - +/* mastersTable->setModel(mMastersProxyModel); mastersTable->setObjectName("MastersTable"); mastersTable->setContextMenuPolicy(Qt::CustomContextMenu); @@ -57,7 +57,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); @@ -116,7 +116,7 @@ FileDialog::FileDialog(QWidget *parent) : //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(mastersTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex))); connect(mCreateButton, SIGNAL(clicked()), this, SLOT(createButtonClicked())); @@ -127,6 +127,7 @@ FileDialog::FileDialog(QWidget *parent) : 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); @@ -135,7 +136,7 @@ void FileDialog::updateViews() mastersTable->setColumnHidden(7, true); mastersTable->setColumnHidden(8, true); mastersTable->resizeColumnsToContents(); - +*/ pluginsTable->setColumnHidden(1, true); pluginsTable->setColumnHidden(3, true); pluginsTable->setColumnHidden(4, true); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 342e4d9e9..816d288a6 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -36,7 +36,6 @@ false -
From b850fe02895dca508685d1ebbabb647f1e71c048 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 18:59:01 -0500 Subject: [PATCH 04/42] Removed vertical headers from plugin view --- apps/launcher/datafilespage.cpp | 6 ++++-- components/fileorderlist/model/datafilesmodel.cpp | 4 ++-- components/fileorderlist/model/pluginsproxymodel.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 077f3c292..fe2fe8255 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -32,12 +32,14 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam mDataFilesModel = new DataFilesModel(this); mMastersProxyModel = new QSortFilterProxyModel(); - mMastersProxyModel->setFilterRegExp(QString("^.*\\.esm")); + mMastersProxyModel->setFilterRegExp(QString("game")); //QString("^.*\\.esm")); + mMastersProxyModel->setFilterRole (Qt::UserRole); mMastersProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); mMastersProxyModel->setSourceModel(mDataFilesModel); mPluginsProxyModel = new PluginsProxyModel(); - mPluginsProxyModel->setFilterRegExp(QString("^.*\\.esp")); + mPluginsProxyModel->setFilterRegExp(QString("addon")); //^.*\\.esp")); + mPluginsProxyModel->setFilterRole (Qt::UserRole); mPluginsProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); mPluginsProxyModel->setSourceModel(mDataFilesModel); diff --git a/components/fileorderlist/model/datafilesmodel.cpp b/components/fileorderlist/model/datafilesmodel.cpp index cf1fa1b0a..99c1aaebf 100644 --- a/components/fileorderlist/model/datafilesmodel.cpp +++ b/components/fileorderlist/model/datafilesmodel.cpp @@ -202,11 +202,11 @@ QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, in case 7: return tr("Masters"); case 8: return tr("Description"); } - } else { + } /* else { // Show row numbers return ++section; } - +*/ return QVariant(); } diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/fileorderlist/model/pluginsproxymodel.cpp index 6be152b55..726a3f158 100644 --- a/components/fileorderlist/model/pluginsproxymodel.cpp +++ b/components/fileorderlist/model/pluginsproxymodel.cpp @@ -11,7 +11,7 @@ PluginsProxyModel::~PluginsProxyModel() QVariant PluginsProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation != Qt::Vertical || role != Qt::DisplayRole) + //if (orientation != Qt::Vertical || role != Qt::DisplayRole) return QSortFilterProxyModel::headerData(section, orientation, role); - return section + 1; + // return section + 1; } From 2bc56d0b5c092a2e230281d55da9bdcecbc7e81c Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 20:59:58 -0500 Subject: [PATCH 05/42] Fixed missing item list in launcher combobox --- apps/launcher/datafilespage.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index fe2fe8255..ddeb43ab7 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -47,6 +47,8 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam mFilterProxyModel->setDynamicSortFilter(true); mFilterProxyModel->setSourceModel(mPluginsProxyModel); + masterView->setModel (mMastersProxyModel); + QCheckBox checkBox; unsigned int height = checkBox.sizeHint().height() + 4; /* From 7389507eb52d2dadda0eba4f52624eb2d6f63360 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 21:12:30 -0500 Subject: [PATCH 06/42] Created masterproxylist class --- apps/launcher/datafilespage.cpp | 7 ++++--- apps/opencs/view/doc/filedialog.cpp | 4 +++- components/CMakeLists.txt | 1 + components/fileorderlist/masterproxymodel.cpp | 11 +++++++++++ components/fileorderlist/masterproxymodel.hpp | 19 +++++++++++++++++++ .../fileorderlist/model/pluginsproxymodel.cpp | 6 ++---- .../fileorderlist/model/pluginsproxymodel.hpp | 2 +- 7 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 components/fileorderlist/masterproxymodel.cpp create mode 100644 components/fileorderlist/masterproxymodel.hpp diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index ddeb43ab7..f674e9dc7 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -48,9 +48,10 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam mFilterProxyModel->setSourceModel(mPluginsProxyModel); masterView->setModel (mMastersProxyModel); - +/* QCheckBox checkBox; unsigned int height = checkBox.sizeHint().height() + 4; + */ /* mastersTable->setModel(mMastersProxyModel); mastersTable->setObjectName("MastersTable"); @@ -80,8 +81,8 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam pluginsTable->horizontalHeader()->setStretchLastSection(true); pluginsTable->horizontalHeader()->hide(); - pluginsTable->verticalHeader()->setDefaultSectionSize(height); - pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed); + //pluginsTable->verticalHeader()->setDefaultSectionSize(height); + //pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed); // Adjust the tableview widths inside the splitter QList sizeList; diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index a07b854df..d49906949 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -16,6 +16,8 @@ #include +#include "components/fileorderlist/masterproxymodel.hpp" + FileDialog::FileDialog(QWidget *parent) : QDialog(parent) { @@ -24,7 +26,7 @@ FileDialog::FileDialog(QWidget *parent) : // Models mDataFilesModel = new DataFilesModel(this); - mMastersProxyModel = new QSortFilterProxyModel(); + mMastersProxyModel = new MasterProxyModel(); mMastersProxyModel->setFilterRegExp("game"); //QString("^.*\\.esm")); mMastersProxyModel->setFilterRole (Qt::UserRole); mMastersProxyModel->setSourceModel(mDataFilesModel); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 529891b4c..bbaca4805 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -70,6 +70,7 @@ find_package(Qt4 COMPONENTS QtCore QtGui) if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) add_component_qt_dir (fileorderlist + masterproxymodel model/modelitem model/datafilesmodel model/pluginsproxymodel model/esm/esmfile utils/profilescombobox utils/comboboxlineedit utils/lineedit utils/naturalsort ) diff --git a/components/fileorderlist/masterproxymodel.cpp b/components/fileorderlist/masterproxymodel.cpp new file mode 100644 index 000000000..ce874318d --- /dev/null +++ b/components/fileorderlist/masterproxymodel.cpp @@ -0,0 +1,11 @@ +#include "masterproxymodel.hpp" + +MasterProxyModel::MasterProxyModel(QObject *parent) : + QSortFilterProxyModel(parent) +{ +} + +QVariant MasterProxyModel::data(const QModelIndex &index, int role) const +{ + return QSortFilterProxyModel::data (index, role); +} diff --git a/components/fileorderlist/masterproxymodel.hpp b/components/fileorderlist/masterproxymodel.hpp new file mode 100644 index 000000000..d0d288873 --- /dev/null +++ b/components/fileorderlist/masterproxymodel.hpp @@ -0,0 +1,19 @@ +#ifndef MASTERPROXYMODEL_HPP +#define MASTERPROXYMODEL_HPP + +#include + +class MasterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + explicit MasterProxyModel(QObject *parent = 0); + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + +signals: + +public slots: + +}; + +#endif // MASTERPROXYMODEL_HPP diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/fileorderlist/model/pluginsproxymodel.cpp index 726a3f158..4648d2833 100644 --- a/components/fileorderlist/model/pluginsproxymodel.cpp +++ b/components/fileorderlist/model/pluginsproxymodel.cpp @@ -9,9 +9,7 @@ PluginsProxyModel::~PluginsProxyModel() { } -QVariant PluginsProxyModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant PluginsProxyModel::data(const QModelIndex &index, int role) const { - //if (orientation != Qt::Vertical || role != Qt::DisplayRole) - return QSortFilterProxyModel::headerData(section, orientation, role); - // return section + 1; + return QSortFilterProxyModel::data (index, role); } diff --git a/components/fileorderlist/model/pluginsproxymodel.hpp b/components/fileorderlist/model/pluginsproxymodel.hpp index 8fde73236..08baa2338 100644 --- a/components/fileorderlist/model/pluginsproxymodel.hpp +++ b/components/fileorderlist/model/pluginsproxymodel.hpp @@ -12,7 +12,7 @@ public: explicit PluginsProxyModel(QObject *parent = 0); ~PluginsProxyModel(); - QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; }; #endif // PLUGINSPROXYMODEL_HPP From 4c8c6d697119c84d6ac27233cb480483074d6f66 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 21:20:48 -0500 Subject: [PATCH 07/42] Moved init code to master / plugin proxy classes --- apps/launcher/datafilespage.cpp | 15 ++++---------- apps/opencs/view/doc/filedialog.cpp | 20 +++++++------------ components/fileorderlist/masterproxymodel.cpp | 7 ++++++- components/fileorderlist/masterproxymodel.hpp | 4 +++- .../fileorderlist/model/pluginsproxymodel.cpp | 7 ++++++- .../fileorderlist/model/pluginsproxymodel.hpp | 3 ++- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index f674e9dc7..42e10c76b 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -15,6 +15,7 @@ #include #include +#include "a.out.h" #include "settings/gamesettings.hpp" #include "settings/launchersettings.hpp" @@ -29,19 +30,11 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam setupUi(this); // Models - mDataFilesModel = new DataFilesModel(this); + mDataFilesModel = new DataFilesModel (this); - mMastersProxyModel = new QSortFilterProxyModel(); - mMastersProxyModel->setFilterRegExp(QString("game")); //QString("^.*\\.esm")); - mMastersProxyModel->setFilterRole (Qt::UserRole); - mMastersProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - mMastersProxyModel->setSourceModel(mDataFilesModel); + mMastersProxyModel = new MasterProxyModel (this, mDataFilesModel); - mPluginsProxyModel = new PluginsProxyModel(); - mPluginsProxyModel->setFilterRegExp(QString("addon")); //^.*\\.esp")); - mPluginsProxyModel->setFilterRole (Qt::UserRole); - mPluginsProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - mPluginsProxyModel->setSourceModel(mDataFilesModel); + mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel); mFilterProxyModel = new QSortFilterProxyModel(); mFilterProxyModel->setDynamicSortFilter(true); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index d49906949..dd94b0571 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -24,25 +24,19 @@ FileDialog::FileDialog(QWidget *parent) : setupUi(this); // Models - mDataFilesModel = new DataFilesModel(this); + mDataFilesModel = new DataFilesModel (this); - mMastersProxyModel = new MasterProxyModel(); - mMastersProxyModel->setFilterRegExp("game"); //QString("^.*\\.esm")); - mMastersProxyModel->setFilterRole (Qt::UserRole); - mMastersProxyModel->setSourceModel(mDataFilesModel); + mMastersProxyModel = new MasterProxyModel (this, mDataFilesModel); + mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel); - mPluginsProxyModel = new PluginsProxyModel(); - mPluginsProxyModel->setFilterRegExp("addon"); //QString("^.*\\.esp")); - mPluginsProxyModel->setFilterRole (Qt::UserRole); - mPluginsProxyModel->setSourceModel(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); @@ -70,10 +64,10 @@ FileDialog::FileDialog(QWidget *parent) : pluginsTable->setAlternatingRowColors(true); pluginsTable->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); pluginsTable->horizontalHeader()->setStretchLastSection(true); - +/* pluginsTable->verticalHeader()->setDefaultSectionSize(height); pluginsTable->verticalHeader()->setResizeMode(QHeaderView::Fixed); - +*/ // Hide the profile elements profileLabel->hide(); profilesComboBox->hide(); diff --git a/components/fileorderlist/masterproxymodel.cpp b/components/fileorderlist/masterproxymodel.cpp index ce874318d..dc702e945 100644 --- a/components/fileorderlist/masterproxymodel.cpp +++ b/components/fileorderlist/masterproxymodel.cpp @@ -1,8 +1,13 @@ #include "masterproxymodel.hpp" -MasterProxyModel::MasterProxyModel(QObject *parent) : +MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : QSortFilterProxyModel(parent) { + setFilterRegExp(QString("game")); + setFilterRole (Qt::UserRole); + + if (model) + setSourceModel (model); } QVariant MasterProxyModel::data(const QModelIndex &index, int role) const diff --git a/components/fileorderlist/masterproxymodel.hpp b/components/fileorderlist/masterproxymodel.hpp index d0d288873..d9e12dada 100644 --- a/components/fileorderlist/masterproxymodel.hpp +++ b/components/fileorderlist/masterproxymodel.hpp @@ -3,11 +3,13 @@ #include +class QAbstractTableModel; + class MasterProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - explicit MasterProxyModel(QObject *parent = 0); + explicit MasterProxyModel(QObject *parent = 0, QAbstractTableModel *model = 0); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; signals: diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/fileorderlist/model/pluginsproxymodel.cpp index 4648d2833..61ffb8894 100644 --- a/components/fileorderlist/model/pluginsproxymodel.cpp +++ b/components/fileorderlist/model/pluginsproxymodel.cpp @@ -1,8 +1,13 @@ #include "pluginsproxymodel.hpp" -PluginsProxyModel::PluginsProxyModel(QObject *parent) : +PluginsProxyModel::PluginsProxyModel(QObject *parent, QAbstractTableModel *model) : QSortFilterProxyModel(parent) { + setFilterRegExp(QString("addon")); + setFilterRole (Qt::UserRole); + + if (model) + setSourceModel (model); } PluginsProxyModel::~PluginsProxyModel() diff --git a/components/fileorderlist/model/pluginsproxymodel.hpp b/components/fileorderlist/model/pluginsproxymodel.hpp index 08baa2338..238d2aac7 100644 --- a/components/fileorderlist/model/pluginsproxymodel.hpp +++ b/components/fileorderlist/model/pluginsproxymodel.hpp @@ -4,12 +4,13 @@ #include class QVariant; +class QAbstractTableModel; class PluginsProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - explicit PluginsProxyModel(QObject *parent = 0); + explicit PluginsProxyModel(QObject *parent = 0, QAbstractTableModel *model = 0); ~PluginsProxyModel(); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; From 61602789e1092eb80bdcb677f03ce7a02fce6501 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 16 Aug 2013 22:23:21 -0500 Subject: [PATCH 08/42] Began migrating code to ContentSelector base --- apps/launcher/datafilespage.cpp | 21 +-- apps/launcher/datafilespage.hpp | 4 +- apps/opencs/view/doc/filedialog.cpp | 117 +++------------- apps/opencs/view/doc/filedialog.hpp | 12 +- components/CMakeLists.txt | 9 +- components/fileorderlist/contentselector.cpp | 132 ++++++++++++++++++ components/fileorderlist/contentselector.hpp | 40 ++++++ components/fileorderlist/masterproxymodel.cpp | 4 +- components/fileorderlist/masterproxymodel.hpp | 22 +-- 9 files changed, 232 insertions(+), 129 deletions(-) create mode 100644 components/fileorderlist/contentselector.cpp create mode 100644 components/fileorderlist/contentselector.hpp diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 42e10c76b..7a4890051 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -15,7 +15,7 @@ #include #include -#include "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 sizeList; sizeList << mLauncherSettings.value(QString("General/MastersTable/width"), QString("200")).toInt(); diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index a0b029330..99aa24ff3 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -5,6 +5,7 @@ #include #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); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index dd94b0571..f770e80a1 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -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() { diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 4c3fe9ffa..2f4d4e381 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -4,6 +4,7 @@ #include #include +#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(); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index bbaca4805..19af6c3b2 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -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}) diff --git a/components/fileorderlist/contentselector.cpp b/components/fileorderlist/contentselector.cpp new file mode 100644 index 000000000..16e071891 --- /dev/null +++ b/components/fileorderlist/contentselector.cpp @@ -0,0 +1,132 @@ +#include "contentselector.hpp" + +#include "model/datafilesmodel.hpp" +#include "masterproxymodel.hpp" +#include "model/pluginsproxymodel.hpp" + +#include + +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(); + +} diff --git a/components/fileorderlist/contentselector.hpp b/components/fileorderlist/contentselector.hpp new file mode 100644 index 000000000..f17e3a909 --- /dev/null +++ b/components/fileorderlist/contentselector.hpp @@ -0,0 +1,40 @@ +#ifndef CONTENTSELECTOR_HPP +#define CONTENTSELECTOR_HPP + +#include + +#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 diff --git a/components/fileorderlist/masterproxymodel.cpp b/components/fileorderlist/masterproxymodel.cpp index dc702e945..7701d4f17 100644 --- a/components/fileorderlist/masterproxymodel.cpp +++ b/components/fileorderlist/masterproxymodel.cpp @@ -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); } diff --git a/components/fileorderlist/masterproxymodel.hpp b/components/fileorderlist/masterproxymodel.hpp index d9e12dada..49ca369de 100644 --- a/components/fileorderlist/masterproxymodel.hpp +++ b/components/fileorderlist/masterproxymodel.hpp @@ -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 From 0087b0d67c4b36cfb9e9e9ce5af5d282673d9419 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 17 Aug 2013 05:37:23 -0500 Subject: [PATCH 09/42] Removed checkboxes from master list Moved checkbox code from datafilesmodel to pluginsproxymodel --- .../fileorderlist/model/datafilesmodel.cpp | 5 ----- .../fileorderlist/model/pluginsproxymodel.cpp | 16 ++++++++++++++-- .../fileorderlist/model/pluginsproxymodel.hpp | 7 ++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/components/fileorderlist/model/datafilesmodel.cpp b/components/fileorderlist/model/datafilesmodel.cpp index 99c1aaebf..3f63e73cc 100644 --- a/components/fileorderlist/model/datafilesmodel.cpp +++ b/components/fileorderlist/model/datafilesmodel.cpp @@ -117,11 +117,6 @@ QVariant DataFilesModel::data(const QModelIndex &index, int role) const } } - case Qt::CheckStateRole: { - if (column != 0) - return QVariant(); - return mCheckStates[file->fileName()]; - } case Qt::ToolTipRole: { if (column != 0) diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/fileorderlist/model/pluginsproxymodel.cpp index 61ffb8894..f6864d85c 100644 --- a/components/fileorderlist/model/pluginsproxymodel.cpp +++ b/components/fileorderlist/model/pluginsproxymodel.cpp @@ -1,7 +1,8 @@ #include "pluginsproxymodel.hpp" +#include "datafilesmodel.hpp" -PluginsProxyModel::PluginsProxyModel(QObject *parent, QAbstractTableModel *model) : - QSortFilterProxyModel(parent) +PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : + QSortFilterProxyModel(parent), mSourceModel (model) { setFilterRegExp(QString("addon")); setFilterRole (Qt::UserRole); @@ -16,5 +17,16 @@ PluginsProxyModel::~PluginsProxyModel() QVariant PluginsProxyModel::data(const QModelIndex &index, int role) const { + switch (role) + { + case Qt::CheckStateRole: + { + if (index.column() != 0) + return QVariant(); + + return mSourceModel->checkState(index); + } + }; + return QSortFilterProxyModel::data (index, role); } diff --git a/components/fileorderlist/model/pluginsproxymodel.hpp b/components/fileorderlist/model/pluginsproxymodel.hpp index 238d2aac7..e148ea3b1 100644 --- a/components/fileorderlist/model/pluginsproxymodel.hpp +++ b/components/fileorderlist/model/pluginsproxymodel.hpp @@ -5,12 +5,17 @@ class QVariant; class QAbstractTableModel; +class DataFilesModel; class PluginsProxyModel : public QSortFilterProxyModel { Q_OBJECT + + DataFilesModel *mSourceModel; + public: - explicit PluginsProxyModel(QObject *parent = 0, QAbstractTableModel *model = 0); + + explicit PluginsProxyModel(QObject *parent = 0, DataFilesModel *model = 0); ~PluginsProxyModel(); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; From b24dd5c6acf9985b34aa9af45c24d817cc211a0c Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 17 Aug 2013 05:55:43 -0500 Subject: [PATCH 10/42] Continued migration of code to ContentSelector --- apps/launcher/datafilespage.cpp | 106 ++---------------- apps/launcher/datafilespage.hpp | 8 -- apps/opencs/view/doc/filedialog.cpp | 50 --------- apps/opencs/view/doc/filedialog.hpp | 6 - components/fileorderlist/contentselector.cpp | 26 +---- components/fileorderlist/contentselector.hpp | 3 +- .../fileorderlist/model/pluginsproxymodel.cpp | 3 +- 7 files changed, 17 insertions(+), 185 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 7a4890051..d077c3e0e 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -21,63 +21,14 @@ #include "utils/textinputdialog.hpp" +#include + DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent) : mCfgMgr(cfg) , mGameSettings(gameSettings) , mLauncherSettings(launcherSettings) , 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 QList sizeList; 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(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(splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(updateSplitter())); @@ -123,6 +72,9 @@ void DataFilesPage::createActions() void DataFilesPage::setupDataFiles() { + if (!mDataFilesModel) + qDebug() << "data files model undefined"; + // Set the encoding to the one found in openmw.cfg or the default mDataFilesModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); @@ -384,8 +336,7 @@ void DataFilesPage::setPluginsCheckstates(Qt::CheckState state) if (!index.isValid()) return; - QModelIndex sourceIndex = mPluginsProxyModel->mapToSource( - mFilterProxyModel->mapToSource(index)); + QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index); if (!sourceIndex.isValid()) 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 ¤t) { // Prevent the deletion of the default profile @@ -505,8 +414,7 @@ void DataFilesPage::showContextMenu(const QPoint &point) if (!index.isValid()) return; - QModelIndex sourceIndex = mPluginsProxyModel->mapToSource( - mFilterProxyModel->mapToSource(index)); + QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index); if (!sourceIndex.isValid()) return; diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 99aa24ff3..1c528ab26 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -36,10 +36,8 @@ signals: void profileChanged(int index); public slots: - void setCheckState(QModelIndex index); void setProfilesComboBoxIndex(int index); - void filterChanged(const QString filter); void showContextMenu(const QPoint &point); void profileChanged(const QString &previous, const QString ¤t); void profileRenamed(const QString &previous, const QString ¤t); @@ -57,12 +55,6 @@ private slots: void slotCurrentIndexChanged(int index); private: - DataFilesModel *mDataFilesModel; - - PluginsProxyModel *mPluginsProxyModel; - QSortFilterProxyModel *mMastersProxyModel; - - QSortFilterProxyModel *mFilterProxyModel; QMenu *mContextMenu; diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index f770e80a1..2f3a6dc21 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -21,55 +21,6 @@ FileDialog::FileDialog(QWidget *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 profileLabel->hide(); profilesComboBox->hide(); @@ -107,7 +58,6 @@ FileDialog::FileDialog(QWidget *parent) : resize(600, 400); - // // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); //connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 2f4d4e381..7944b7fb3 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -53,12 +53,6 @@ private: QPushButton *mCreateButton; QDialogButtonBox *mButtonBox; - - DataFilesModel *mDataFilesModel; - - PluginsProxyModel *mPluginsProxyModel; - QSortFilterProxyModel *mMastersProxyModel; - QSortFilterProxyModel *mFilterProxyModel; }; #endif // FILEDIALOG_HPP diff --git a/components/fileorderlist/contentselector.cpp b/components/fileorderlist/contentselector.cpp index 16e071891..6f8a86a49 100644 --- a/components/fileorderlist/contentselector.cpp +++ b/components/fileorderlist/contentselector.cpp @@ -9,6 +9,8 @@ FileOrderList::ContentSelector::ContentSelector(QWidget *parent) : QWidget(parent) { + setupUi(this); + buildModelsAndViews(); } void FileOrderList::ContentSelector::buildModelsAndViews() @@ -19,11 +21,6 @@ void FileOrderList::ContentSelector::buildModelsAndViews() 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); @@ -41,7 +38,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews() mastersTable->verticalHeader()->setResizeMode(QHeaderView::Fixed); mastersTable->verticalHeader()->hide(); */ - pluginsTable->setModel(mFilterProxyModel); + pluginsTable->setModel(mPluginsProxyModel); pluginsTable->setObjectName("PluginsTable"); pluginsTable->setContextMenuPolicy(Qt::CustomContextMenu); pluginsTable->setSortingEnabled(false); @@ -79,8 +76,7 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index) if (object->objectName() == QLatin1String("PluginsTable")) { - QModelIndex sourceIndex = mPluginsProxyModel->mapToSource( - mFilterProxyModel->mapToSource(index)); + QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index); if (sourceIndex.isValid()) { (mDataFilesModel->checkState(sourceIndex) == Qt::Checked) @@ -88,7 +84,7 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index) : mDataFilesModel->setCheckState(sourceIndex, Qt::Checked); } } -/* + if (object->objectName() == QLatin1String("MastersTable")) { QModelIndex sourceIndex = mMasterProxyModel->mapToSource(index); @@ -98,7 +94,7 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index) : mDataFilesModel->setCheckState(sourceIndex, Qt::Checked); } } -*/ + return; } @@ -110,16 +106,6 @@ QStringList FileOrderList::ContentSelector::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); diff --git a/components/fileorderlist/contentselector.hpp b/components/fileorderlist/contentselector.hpp index f17e3a909..914e8bacb 100644 --- a/components/fileorderlist/contentselector.hpp +++ b/components/fileorderlist/contentselector.hpp @@ -17,10 +17,11 @@ namespace FileOrderList { Q_OBJECT + protected: + DataFilesModel *mDataFilesModel; MasterProxyModel *mMasterProxyModel; PluginsProxyModel *mPluginsProxyModel; - QSortFilterProxyModel *mFilterProxyModel; public: explicit ContentSelector(QWidget *parent = 0); diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/fileorderlist/model/pluginsproxymodel.cpp index f6864d85c..9e3cdd730 100644 --- a/components/fileorderlist/model/pluginsproxymodel.cpp +++ b/components/fileorderlist/model/pluginsproxymodel.cpp @@ -4,8 +4,9 @@ PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : QSortFilterProxyModel(parent), mSourceModel (model) { - setFilterRegExp(QString("addon")); + setFilterRegExp (QString("addon")); setFilterRole (Qt::UserRole); + setDynamicSortFilter (true); if (model) setSourceModel (model); From 2878f51cd324c0dcc605b54f00b927a3dafac31c Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 17 Aug 2013 19:40:28 -0500 Subject: [PATCH 11/42] Reimplemented dependency selection feature Moved more code to ContentSelector Added support for omwgame and omwaddon files --- apps/launcher/datafilespage.cpp | 125 +++--------------- apps/launcher/datafilespage.hpp | 8 +- apps/opencs/view/doc/filedialog.cpp | 19 --- apps/opencs/view/doc/filedialog.hpp | 3 - components/fileorderlist/contentselector.cpp | 99 ++++++-------- components/fileorderlist/contentselector.hpp | 7 +- .../fileorderlist/model/datafilesmodel.cpp | 15 +-- .../fileorderlist/model/pluginsproxymodel.cpp | 4 +- .../fileorderlist/model/pluginsproxymodel.hpp | 2 - files/ui/datafilespage.ui | 44 +++--- 10 files changed, 99 insertions(+), 227 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index d077c3e0e..5cbcae545 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -29,29 +29,14 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , mLauncherSettings(launcherSettings) , ContentSelector(parent) { - // Adjust the tableview widths inside the splitter - QList 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 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); } - */ + } +*/ diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 1c528ab26..db391519f 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -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 ¤t); void profileRenamed(const QString &previous, const QString ¤t); 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(); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 2f3a6dc21..9f1c72068 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -49,23 +49,11 @@ FileDialog::FileDialog(QWidget *parent) : verticalLayout->addLayout(nameLayout); verticalLayout->addWidget(mButtonBox); - // Set sizes - QList 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() { diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 7944b7fb3..232f250be 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -42,9 +42,6 @@ private slots: void updateOpenButton(const QStringList &items); void updateCreateButton(const QString &name); - - //void filterChanged(const QString &filter); - void createButtonClicked(); private: diff --git a/components/fileorderlist/contentselector.cpp b/components/fileorderlist/contentselector.cpp index 6f8a86a49..e7ab9b0cf 100644 --- a/components/fileorderlist/contentselector.cpp +++ b/components/fileorderlist/contentselector.cpp @@ -6,6 +6,7 @@ #include +#include 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); +} diff --git a/components/fileorderlist/contentselector.hpp b/components/fileorderlist/contentselector.hpp index 914e8bacb..138ffc629 100644 --- a/components/fileorderlist/contentselector.hpp +++ b/components/fileorderlist/contentselector.hpp @@ -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); }; } diff --git a/components/fileorderlist/model/datafilesmodel.cpp b/components/fileorderlist/model/datafilesmodel.cpp index 3f63e73cc..8e27f1f75 100644 --- a/components/fileorderlist/model/datafilesmodel.cpp +++ b/components/fileorderlist/model/datafilesmodel.cpp @@ -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; } diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/fileorderlist/model/pluginsproxymodel.cpp index 9e3cdd730..18aebc6b6 100644 --- a/components/fileorderlist/model/pluginsproxymodel.cpp +++ b/components/fileorderlist/model/pluginsproxymodel.cpp @@ -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(sourceModel())->checkState(mapToSource(index)); } }; diff --git a/components/fileorderlist/model/pluginsproxymodel.hpp b/components/fileorderlist/model/pluginsproxymodel.hpp index e148ea3b1..cfade092e 100644 --- a/components/fileorderlist/model/pluginsproxymodel.hpp +++ b/components/fileorderlist/model/pluginsproxymodel.hpp @@ -11,8 +11,6 @@ class PluginsProxyModel : public QSortFilterProxyModel { Q_OBJECT - DataFilesModel *mSourceModel; - public: explicit PluginsProxyModel(QObject *parent = 0, DataFilesModel *model = 0); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 816d288a6..87213c5cc 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -10,7 +10,7 @@ 304 - + @@ -23,21 +23,33 @@ - - - - 0 - 0 - - - - Qt::Horizontal - - - false - - - + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectItems + + + Qt::ElideLeft + + + false + + + false + + + false + + + + From a9db983233dde491c0b90b53ca427e4427d0188f Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 07:29:48 -0500 Subject: [PATCH 12/42] Fixing row-click selection --- components/fileorderlist/contentselector.cpp | 2 +- files/ui/datafilespage.ui | 24 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/fileorderlist/contentselector.cpp b/components/fileorderlist/contentselector.cpp index e7ab9b0cf..6254601dc 100644 --- a/components/fileorderlist/contentselector.cpp +++ b/components/fileorderlist/contentselector.cpp @@ -26,8 +26,8 @@ void FileOrderList::ContentSelector::buildModelsAndViews() pluginView->setModel(mPluginsProxyModel); connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); + //connect(pluginView, SIGNAL()) connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); - connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); } diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 87213c5cc..cf6f30b99 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -29,11 +29,14 @@ QAbstractItemView::NoEditTriggers + + true + QAbstractItemView::SingleSelection - QAbstractItemView::SelectItems + QAbstractItemView::SelectRows Qt::ElideLeft @@ -153,5 +156,22 @@ - + + + pluginView + clicked(QModelIndex) + checkAction + toggle() + + + 258 + 151 + + + -1 + -1 + + + + From 66e50343adba0bfca059da804dee0b865eba84d9 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 08:54:51 -0500 Subject: [PATCH 13/42] Fixed row-selection/check feature --- components/fileorderlist/contentselector.cpp | 11 ++++++-- components/fileorderlist/contentselector.hpp | 3 ++ .../fileorderlist/model/datafilesmodel.cpp | 27 +++++++++--------- files/ui/datafilespage.ui | 28 +++++++------------ 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/components/fileorderlist/contentselector.cpp b/components/fileorderlist/contentselector.cpp index 6254601dc..b2a5c5ba5 100644 --- a/components/fileorderlist/contentselector.cpp +++ b/components/fileorderlist/contentselector.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + FileOrderList::ContentSelector::ContentSelector(QWidget *parent) : QWidget(parent) { @@ -26,7 +29,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews() pluginView->setModel(mPluginsProxyModel); connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); - //connect(pluginView, SIGNAL()) + connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); } @@ -88,7 +91,6 @@ void FileOrderList::ContentSelector::slotCurrentProfileIndexChanged(int index) void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index) { - qDebug() << "index Changed: " << index; QObject *object = QObject::sender(); // Not a signal-slot call @@ -97,3 +99,8 @@ void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index) setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel); } + +void FileOrderList::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) +{ + setCheckState(index, mPluginsProxyModel); +} diff --git a/components/fileorderlist/contentselector.hpp b/components/fileorderlist/contentselector.hpp index 138ffc629..f1d8f6927 100644 --- a/components/fileorderlist/contentselector.hpp +++ b/components/fileorderlist/contentselector.hpp @@ -30,8 +30,10 @@ namespace FileOrderList void addFiles(const QString &path); void setEncoding(const QString &encoding); + void setPluginCheckState(); void setCheckState(QModelIndex index, QSortFilterProxyModel *model); QStringList checkedItemsPaths(); + void on_checkAction_triggered(); signals: void profileChanged(int index); @@ -40,6 +42,7 @@ namespace FileOrderList void updateViews(); void slotCurrentProfileIndexChanged(int index); void slotCurrentMasterIndexChanged(int index); + void slotPluginTableItemClicked(const QModelIndex &index); }; } diff --git a/components/fileorderlist/model/datafilesmodel.cpp b/components/fileorderlist/model/datafilesmodel.cpp index 8e27f1f75..ae842381e 100644 --- a/components/fileorderlist/model/datafilesmodel.cpp +++ b/components/fileorderlist/model/datafilesmodel.cpp @@ -30,7 +30,19 @@ void DataFilesModel::setEncoding(const QString &encoding) void DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState state) { - setData(index, state, Qt::CheckStateRole); + if (!index.isValid()) + return; + + QString name = item(index.row())->fileName(); + mCheckStates[name] = state; + + // Force a redraw of the view since unchecking one item can affect another + QModelIndex firstIndex = indexFromItem(mFiles.first()); + QModelIndex lastIndex = indexFromItem(mFiles.last()); + + emit dataChanged(firstIndex, lastIndex); + emit checkedItemsChanged(checkedItems()); + } Qt::CheckState DataFilesModel::checkState(const QModelIndex &index) @@ -210,19 +222,6 @@ bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, in if (!index.isValid()) return false; - if (role == Qt::CheckStateRole) { - QString name = item(index.row())->fileName(); - mCheckStates[name] = static_cast(value.toInt()); - - // Force a redraw of the view since unchecking one item can affect another - QModelIndex firstIndex = indexFromItem(mFiles.first()); - QModelIndex lastIndex = indexFromItem(mFiles.last()); - - emit dataChanged(firstIndex, lastIndex); - emit checkedItemsChanged(checkedItems()); - return true; - } - return false; } diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index cf6f30b99..a6c1768b5 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -10,6 +10,9 @@ 304 + + Qt::DefaultContextMenu + @@ -26,6 +29,9 @@ + + Qt::DefaultContextMenu + QAbstractItemView::NoEditTriggers @@ -138,6 +144,9 @@ + + true + Check Selection @@ -156,22 +165,5 @@ - - - pluginView - clicked(QModelIndex) - checkAction - toggle() - - - 258 - 151 - - - -1 - -1 - - - - + From 45277c00825c759bb826a25e0e73cf940968086f Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 09:34:33 -0500 Subject: [PATCH 14/42] Minor changes Stretched table columns to fit widget width Reduced width of opencs file dialog Hid the file size column for launcher Added alternating row colors in table view --- apps/launcher/datafilespage.cpp | 1 + apps/opencs/view/doc/filedialog.cpp | 2 +- components/fileorderlist/contentselector.cpp | 1 + files/ui/datafilespage.ui | 9 +++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 5cbcae545..44f92d7fe 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -30,6 +30,7 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , ContentSelector(parent) { + pluginView->hideColumn(2); // Create a dialog for the new profile name input mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 9f1c72068..252c760fa 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -49,7 +49,7 @@ FileDialog::FileDialog(QWidget *parent) : verticalLayout->addLayout(nameLayout); verticalLayout->addWidget(mButtonBox); - resize(600, 400); + resize(400, 400); // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); //connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); diff --git a/components/fileorderlist/contentselector.cpp b/components/fileorderlist/contentselector.cpp index b2a5c5ba5..27be996fc 100644 --- a/components/fileorderlist/contentselector.cpp +++ b/components/fileorderlist/contentselector.cpp @@ -27,6 +27,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews() masterView->setModel(mMasterProxyModel); pluginView->setModel(mPluginsProxyModel); + pluginView-> connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index a6c1768b5..07ad9d3ba 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -29,6 +29,12 @@ + + + 0 + 0 + + Qt::DefaultContextMenu @@ -53,6 +59,9 @@ false + + true + false From d0363b037cc9716ceb5f7d03594a1a836e8724c1 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 09:41:02 -0500 Subject: [PATCH 15/42] Renamed components/fileorderlist to components/esxselector --- components/CMakeLists.txt | 2 +- components/{fileorderlist => esxselector}/contentselector.cpp | 0 components/{fileorderlist => esxselector}/contentselector.hpp | 0 components/{fileorderlist => esxselector}/masterproxymodel.cpp | 0 components/{fileorderlist => esxselector}/masterproxymodel.hpp | 0 .../{fileorderlist => esxselector}/model/datafilesmodel.cpp | 0 .../{fileorderlist => esxselector}/model/datafilesmodel.hpp | 0 components/{fileorderlist => esxselector}/model/esm/esmfile.cpp | 0 components/{fileorderlist => esxselector}/model/esm/esmfile.hpp | 0 components/{fileorderlist => esxselector}/model/modelitem.cpp | 0 components/{fileorderlist => esxselector}/model/modelitem.hpp | 0 .../{fileorderlist => esxselector}/model/pluginsproxymodel.cpp | 0 .../{fileorderlist => esxselector}/model/pluginsproxymodel.hpp | 0 .../{fileorderlist => esxselector}/utils/comboboxlineedit.cpp | 0 .../{fileorderlist => esxselector}/utils/comboboxlineedit.hpp | 0 components/{fileorderlist => esxselector}/utils/lineedit.cpp | 0 components/{fileorderlist => esxselector}/utils/lineedit.hpp | 0 components/{fileorderlist => esxselector}/utils/naturalsort.cpp | 0 components/{fileorderlist => esxselector}/utils/naturalsort.hpp | 0 .../{fileorderlist => esxselector}/utils/profilescombobox.cpp | 0 .../{fileorderlist => esxselector}/utils/profilescombobox.hpp | 0 21 files changed, 1 insertion(+), 1 deletion(-) rename components/{fileorderlist => esxselector}/contentselector.cpp (100%) rename components/{fileorderlist => esxselector}/contentselector.hpp (100%) rename components/{fileorderlist => esxselector}/masterproxymodel.cpp (100%) rename components/{fileorderlist => esxselector}/masterproxymodel.hpp (100%) rename components/{fileorderlist => esxselector}/model/datafilesmodel.cpp (100%) rename components/{fileorderlist => esxselector}/model/datafilesmodel.hpp (100%) rename components/{fileorderlist => esxselector}/model/esm/esmfile.cpp (100%) rename components/{fileorderlist => esxselector}/model/esm/esmfile.hpp (100%) rename components/{fileorderlist => esxselector}/model/modelitem.cpp (100%) rename components/{fileorderlist => esxselector}/model/modelitem.hpp (100%) rename components/{fileorderlist => esxselector}/model/pluginsproxymodel.cpp (100%) rename components/{fileorderlist => esxselector}/model/pluginsproxymodel.hpp (100%) rename components/{fileorderlist => esxselector}/utils/comboboxlineedit.cpp (100%) rename components/{fileorderlist => esxselector}/utils/comboboxlineedit.hpp (100%) rename components/{fileorderlist => esxselector}/utils/lineedit.cpp (100%) rename components/{fileorderlist => esxselector}/utils/lineedit.hpp (100%) rename components/{fileorderlist => esxselector}/utils/naturalsort.cpp (100%) rename components/{fileorderlist => esxselector}/utils/naturalsort.hpp (100%) rename components/{fileorderlist => esxselector}/utils/profilescombobox.cpp (100%) rename components/{fileorderlist => esxselector}/utils/profilescombobox.hpp (100%) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 19af6c3b2..85f1a3508 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -71,7 +71,7 @@ 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 + add_component_qt_dir (esxselector masterproxymodel contentselector model/modelitem model/datafilesmodel model/pluginsproxymodel model/esm/esmfile utils/profilescombobox utils/comboboxlineedit utils/lineedit utils/naturalsort diff --git a/components/fileorderlist/contentselector.cpp b/components/esxselector/contentselector.cpp similarity index 100% rename from components/fileorderlist/contentselector.cpp rename to components/esxselector/contentselector.cpp diff --git a/components/fileorderlist/contentselector.hpp b/components/esxselector/contentselector.hpp similarity index 100% rename from components/fileorderlist/contentselector.hpp rename to components/esxselector/contentselector.hpp diff --git a/components/fileorderlist/masterproxymodel.cpp b/components/esxselector/masterproxymodel.cpp similarity index 100% rename from components/fileorderlist/masterproxymodel.cpp rename to components/esxselector/masterproxymodel.cpp diff --git a/components/fileorderlist/masterproxymodel.hpp b/components/esxselector/masterproxymodel.hpp similarity index 100% rename from components/fileorderlist/masterproxymodel.hpp rename to components/esxselector/masterproxymodel.hpp diff --git a/components/fileorderlist/model/datafilesmodel.cpp b/components/esxselector/model/datafilesmodel.cpp similarity index 100% rename from components/fileorderlist/model/datafilesmodel.cpp rename to components/esxselector/model/datafilesmodel.cpp diff --git a/components/fileorderlist/model/datafilesmodel.hpp b/components/esxselector/model/datafilesmodel.hpp similarity index 100% rename from components/fileorderlist/model/datafilesmodel.hpp rename to components/esxselector/model/datafilesmodel.hpp diff --git a/components/fileorderlist/model/esm/esmfile.cpp b/components/esxselector/model/esm/esmfile.cpp similarity index 100% rename from components/fileorderlist/model/esm/esmfile.cpp rename to components/esxselector/model/esm/esmfile.cpp diff --git a/components/fileorderlist/model/esm/esmfile.hpp b/components/esxselector/model/esm/esmfile.hpp similarity index 100% rename from components/fileorderlist/model/esm/esmfile.hpp rename to components/esxselector/model/esm/esmfile.hpp diff --git a/components/fileorderlist/model/modelitem.cpp b/components/esxselector/model/modelitem.cpp similarity index 100% rename from components/fileorderlist/model/modelitem.cpp rename to components/esxselector/model/modelitem.cpp diff --git a/components/fileorderlist/model/modelitem.hpp b/components/esxselector/model/modelitem.hpp similarity index 100% rename from components/fileorderlist/model/modelitem.hpp rename to components/esxselector/model/modelitem.hpp diff --git a/components/fileorderlist/model/pluginsproxymodel.cpp b/components/esxselector/model/pluginsproxymodel.cpp similarity index 100% rename from components/fileorderlist/model/pluginsproxymodel.cpp rename to components/esxselector/model/pluginsproxymodel.cpp diff --git a/components/fileorderlist/model/pluginsproxymodel.hpp b/components/esxselector/model/pluginsproxymodel.hpp similarity index 100% rename from components/fileorderlist/model/pluginsproxymodel.hpp rename to components/esxselector/model/pluginsproxymodel.hpp diff --git a/components/fileorderlist/utils/comboboxlineedit.cpp b/components/esxselector/utils/comboboxlineedit.cpp similarity index 100% rename from components/fileorderlist/utils/comboboxlineedit.cpp rename to components/esxselector/utils/comboboxlineedit.cpp diff --git a/components/fileorderlist/utils/comboboxlineedit.hpp b/components/esxselector/utils/comboboxlineedit.hpp similarity index 100% rename from components/fileorderlist/utils/comboboxlineedit.hpp rename to components/esxselector/utils/comboboxlineedit.hpp diff --git a/components/fileorderlist/utils/lineedit.cpp b/components/esxselector/utils/lineedit.cpp similarity index 100% rename from components/fileorderlist/utils/lineedit.cpp rename to components/esxselector/utils/lineedit.cpp diff --git a/components/fileorderlist/utils/lineedit.hpp b/components/esxselector/utils/lineedit.hpp similarity index 100% rename from components/fileorderlist/utils/lineedit.hpp rename to components/esxselector/utils/lineedit.hpp diff --git a/components/fileorderlist/utils/naturalsort.cpp b/components/esxselector/utils/naturalsort.cpp similarity index 100% rename from components/fileorderlist/utils/naturalsort.cpp rename to components/esxselector/utils/naturalsort.cpp diff --git a/components/fileorderlist/utils/naturalsort.hpp b/components/esxselector/utils/naturalsort.hpp similarity index 100% rename from components/fileorderlist/utils/naturalsort.hpp rename to components/esxselector/utils/naturalsort.hpp diff --git a/components/fileorderlist/utils/profilescombobox.cpp b/components/esxselector/utils/profilescombobox.cpp similarity index 100% rename from components/fileorderlist/utils/profilescombobox.cpp rename to components/esxselector/utils/profilescombobox.cpp diff --git a/components/fileorderlist/utils/profilescombobox.hpp b/components/esxselector/utils/profilescombobox.hpp similarity index 100% rename from components/fileorderlist/utils/profilescombobox.hpp rename to components/esxselector/utils/profilescombobox.hpp From a14e0b32d8daa1fad311d535a65bb14c5b123b91 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 09:48:13 -0500 Subject: [PATCH 16/42] Restructured esxselector directory Added ./view Removed ./utils and ./model/esm Relocated code accordingly. --- apps/launcher/datafilespage.hpp | 2 +- apps/opencs/view/doc/filedialog.hpp | 2 +- components/CMakeLists.txt | 7 +-- components/esxselector/model/esm/esmfile.cpp | 50 ----------------- components/esxselector/model/esm/esmfile.hpp | 54 ------------------- .../{ => model}/masterproxymodel.cpp | 4 +- .../{ => model}/masterproxymodel.hpp | 2 +- .../{utils => model}/naturalsort.cpp | 0 .../{utils => model}/naturalsort.hpp | 0 .../{utils => view}/comboboxlineedit.cpp | 0 .../{utils => view}/comboboxlineedit.hpp | 0 .../{ => view}/contentselector.cpp | 22 ++++---- .../{ => view}/contentselector.hpp | 0 .../esxselector/{utils => view}/lineedit.cpp | 0 .../esxselector/{utils => view}/lineedit.hpp | 0 .../{utils => view}/profilescombobox.cpp | 0 .../{utils => view}/profilescombobox.hpp | 0 17 files changed, 20 insertions(+), 123 deletions(-) delete mode 100644 components/esxselector/model/esm/esmfile.cpp delete mode 100644 components/esxselector/model/esm/esmfile.hpp rename components/esxselector/{ => model}/masterproxymodel.cpp (57%) rename components/esxselector/{ => model}/masterproxymodel.hpp (95%) rename components/esxselector/{utils => model}/naturalsort.cpp (100%) rename components/esxselector/{utils => model}/naturalsort.hpp (100%) rename components/esxselector/{utils => view}/comboboxlineedit.cpp (100%) rename components/esxselector/{utils => view}/comboboxlineedit.hpp (100%) rename components/esxselector/{ => view}/contentselector.cpp (74%) rename components/esxselector/{ => view}/contentselector.hpp (100%) rename components/esxselector/{utils => view}/lineedit.cpp (100%) rename components/esxselector/{utils => view}/lineedit.hpp (100%) rename components/esxselector/{utils => view}/profilescombobox.cpp (100%) rename components/esxselector/{utils => view}/profilescombobox.hpp (100%) diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index db391519f..356cb88d6 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -20,7 +20,7 @@ class PluginsProxyModel; namespace Files { struct ConfigurationManager; } -class DataFilesPage : public FileOrderList::ContentSelector +class DataFilesPage : public EsxSelector::ContentSelector { Q_OBJECT public: diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 232f250be..1b4d09745 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -18,7 +18,7 @@ class QMenu; class DataFilesModel; class PluginsProxyModel; -class FileDialog : public FileOrderList::ContentSelector +class FileDialog : public EsxSelector::ContentSelector { Q_OBJECT public: diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 85f1a3508..4f14fa9d9 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -72,9 +72,10 @@ find_package(Qt4 COMPONENTS QtCore QtGui) if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) add_component_qt_dir (esxselector - masterproxymodel contentselector - model/modelitem model/datafilesmodel model/pluginsproxymodel model/esm/esmfile - utils/profilescombobox utils/comboboxlineedit utils/lineedit utils/naturalsort + model/masterproxymodel model/modelitem model/datafilesmodel + model/pluginsproxymodel model/esm/esmfile model/naturalsort + view/profilescombobox view/comboboxlineedit + view/lineedit view/contentselector ) include(${QT_USE_FILE}) diff --git a/components/esxselector/model/esm/esmfile.cpp b/components/esxselector/model/esm/esmfile.cpp deleted file mode 100644 index 93d83091e..000000000 --- a/components/esxselector/model/esm/esmfile.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "esmfile.hpp" - -EsmFile::EsmFile(QString fileName, ModelItem *parent) - : ModelItem(parent) -{ - mFileName = fileName; - mSize = 0; - mVersion = 0.0f; -} - -void EsmFile::setFileName(const QString &fileName) -{ - mFileName = fileName; -} - -void EsmFile::setAuthor(const QString &author) -{ - mAuthor = author; -} - -void EsmFile::setSize(const int size) -{ - mSize = size; -} - -void EsmFile::setDates(const QDateTime &modified, const QDateTime &accessed) -{ - mModified = modified; - mAccessed = accessed; -} - -void EsmFile::setVersion(float version) -{ - mVersion = version; -} - -void EsmFile::setPath(const QString &path) -{ - mPath = path; -} - -void EsmFile::setMasters(const QStringList &masters) -{ - mMasters = masters; -} - -void EsmFile::setDescription(const QString &description) -{ - mDescription = description; -} diff --git a/components/esxselector/model/esm/esmfile.hpp b/components/esxselector/model/esm/esmfile.hpp deleted file mode 100644 index 52b3fbd00..000000000 --- a/components/esxselector/model/esm/esmfile.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef ESMFILE_HPP -#define ESMFILE_HPP - -#include -#include - -#include "../modelitem.hpp" - -class EsmFile : public ModelItem -{ - Q_OBJECT - Q_PROPERTY(QString filename READ fileName) - -public: - EsmFile(QString fileName = QString(), ModelItem *parent = 0); - - ~EsmFile() - {} - - void setFileName(const QString &fileName); - void setAuthor(const QString &author); - void setSize(const int size); - void setDates(const QDateTime &modified, const QDateTime &accessed); - void setVersion(const float version); - void setPath(const QString &path); - void setMasters(const QStringList &masters); - void setDescription(const QString &description); - - inline QString fileName() const { return mFileName; } - inline QString author() const { return mAuthor; } - inline int size() const { return mSize; } - inline QDateTime modified() const { return mModified; } - inline QDateTime accessed() const { return mAccessed; } - inline float version() const { return mVersion; } - inline QString path() const { return mPath; } - inline QStringList masters() const { return mMasters; } - inline QString description() const { return mDescription; } - - -private: - QString mFileName; - QString mAuthor; - int mSize; - QDateTime mModified; - QDateTime mAccessed; - float mVersion; - QString mPath; - QStringList mMasters; - QString mDescription; - -}; - - -#endif diff --git a/components/esxselector/masterproxymodel.cpp b/components/esxselector/model/masterproxymodel.cpp similarity index 57% rename from components/esxselector/masterproxymodel.cpp rename to components/esxselector/model/masterproxymodel.cpp index 7701d4f17..04a7f0033 100644 --- a/components/esxselector/masterproxymodel.cpp +++ b/components/esxselector/model/masterproxymodel.cpp @@ -1,6 +1,6 @@ #include "masterproxymodel.hpp" -FileOrderList::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : +EsxSelector::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : QSortFilterProxyModel(parent) { setFilterRegExp(QString("game")); @@ -10,7 +10,7 @@ FileOrderList::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTabl setSourceModel (model); } -QVariant FileOrderList::MasterProxyModel::data(const QModelIndex &index, int role) const +QVariant EsxSelector::MasterProxyModel::data(const QModelIndex &index, int role) const { return QSortFilterProxyModel::data (index, role); } diff --git a/components/esxselector/masterproxymodel.hpp b/components/esxselector/model/masterproxymodel.hpp similarity index 95% rename from components/esxselector/masterproxymodel.hpp rename to components/esxselector/model/masterproxymodel.hpp index 49ca369de..6fbdd3154 100644 --- a/components/esxselector/masterproxymodel.hpp +++ b/components/esxselector/model/masterproxymodel.hpp @@ -5,7 +5,7 @@ class QAbstractTableModel; -namespace FileOrderList +namespace EsxSelector { class MasterProxyModel : public QSortFilterProxyModel { diff --git a/components/esxselector/utils/naturalsort.cpp b/components/esxselector/model/naturalsort.cpp similarity index 100% rename from components/esxselector/utils/naturalsort.cpp rename to components/esxselector/model/naturalsort.cpp diff --git a/components/esxselector/utils/naturalsort.hpp b/components/esxselector/model/naturalsort.hpp similarity index 100% rename from components/esxselector/utils/naturalsort.hpp rename to components/esxselector/model/naturalsort.hpp diff --git a/components/esxselector/utils/comboboxlineedit.cpp b/components/esxselector/view/comboboxlineedit.cpp similarity index 100% rename from components/esxselector/utils/comboboxlineedit.cpp rename to components/esxselector/view/comboboxlineedit.cpp diff --git a/components/esxselector/utils/comboboxlineedit.hpp b/components/esxselector/view/comboboxlineedit.hpp similarity index 100% rename from components/esxselector/utils/comboboxlineedit.hpp rename to components/esxselector/view/comboboxlineedit.hpp diff --git a/components/esxselector/contentselector.cpp b/components/esxselector/view/contentselector.cpp similarity index 74% rename from components/esxselector/contentselector.cpp rename to components/esxselector/view/contentselector.cpp index 27be996fc..16139d9e6 100644 --- a/components/esxselector/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -10,19 +10,19 @@ #include #include -FileOrderList::ContentSelector::ContentSelector(QWidget *parent) : +EsxSelector::ContentSelector::ContentSelector(QWidget *parent) : QWidget(parent) { setupUi(this); buildModelsAndViews(); } -void FileOrderList::ContentSelector::buildModelsAndViews() +void EsxSelector::ContentSelector::buildModelsAndViews() { // Models mDataFilesModel = new DataFilesModel (this); - mMasterProxyModel = new FileOrderList::MasterProxyModel (this, mDataFilesModel); + mMasterProxyModel = new EsxSelector::MasterProxyModel (this, mDataFilesModel); mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel); masterView->setModel(mMasterProxyModel); @@ -35,7 +35,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews() connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); } -void FileOrderList::ContentSelector::addFiles(const QString &path) +void EsxSelector::ContentSelector::addFiles(const QString &path) { mDataFilesModel->addFiles(path); mDataFilesModel->sort(3); // Sort by date accessed @@ -43,12 +43,12 @@ void FileOrderList::ContentSelector::addFiles(const QString &path) mDataFilesModel->uncheckAll(); } -void FileOrderList::ContentSelector::setEncoding(const QString &encoding) +void EsxSelector::ContentSelector::setEncoding(const QString &encoding) { mDataFilesModel->setEncoding(encoding); } -void FileOrderList::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model) +void EsxSelector::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model) { if (!index.isValid()) return; @@ -66,12 +66,12 @@ void FileOrderList::ContentSelector::setCheckState(QModelIndex index, QSortFilte } } -QStringList FileOrderList::ContentSelector::checkedItemsPaths() +QStringList EsxSelector::ContentSelector::checkedItemsPaths() { return mDataFilesModel->checkedItemsPaths(); } -void FileOrderList::ContentSelector::updateViews() +void EsxSelector::ContentSelector::updateViews() { // Ensure the columns are hidden because sort() re-enables them pluginView->setColumnHidden(1, true); @@ -85,12 +85,12 @@ void FileOrderList::ContentSelector::updateViews() } -void FileOrderList::ContentSelector::slotCurrentProfileIndexChanged(int index) +void EsxSelector::ContentSelector::slotCurrentProfileIndexChanged(int index) { emit profileChanged(index); } -void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index) +void EsxSelector::ContentSelector::slotCurrentMasterIndexChanged(int index) { QObject *object = QObject::sender(); @@ -101,7 +101,7 @@ void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index) setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel); } -void FileOrderList::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) +void EsxSelector::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) { setCheckState(index, mPluginsProxyModel); } diff --git a/components/esxselector/contentselector.hpp b/components/esxselector/view/contentselector.hpp similarity index 100% rename from components/esxselector/contentselector.hpp rename to components/esxselector/view/contentselector.hpp diff --git a/components/esxselector/utils/lineedit.cpp b/components/esxselector/view/lineedit.cpp similarity index 100% rename from components/esxselector/utils/lineedit.cpp rename to components/esxselector/view/lineedit.cpp diff --git a/components/esxselector/utils/lineedit.hpp b/components/esxselector/view/lineedit.hpp similarity index 100% rename from components/esxselector/utils/lineedit.hpp rename to components/esxselector/view/lineedit.hpp diff --git a/components/esxselector/utils/profilescombobox.cpp b/components/esxselector/view/profilescombobox.cpp similarity index 100% rename from components/esxselector/utils/profilescombobox.cpp rename to components/esxselector/view/profilescombobox.cpp diff --git a/components/esxselector/utils/profilescombobox.hpp b/components/esxselector/view/profilescombobox.hpp similarity index 100% rename from components/esxselector/utils/profilescombobox.hpp rename to components/esxselector/view/profilescombobox.hpp From f6217f9c6ac160d6372236698f1abcf24b3c785c Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 15:11:29 -0500 Subject: [PATCH 17/42] Moved esx selector classes out of global namespace --- apps/launcher/datafilespage.cpp | 14 ++-- apps/launcher/datafilespage.hpp | 4 +- apps/launcher/graphicspage.cpp | 2 +- apps/launcher/utils/textinputdialog.cpp | 4 +- apps/launcher/utils/textinputdialog.hpp | 10 ++- apps/opencs/editor.hpp | 2 +- apps/opencs/view/doc/filedialog.cpp | 26 +++--- apps/opencs/view/doc/filedialog.hpp | 54 +++++++------ components/CMakeLists.txt | 2 +- .../esxselector/model/datafilesmodel.cpp | 53 ++++++------ .../esxselector/model/datafilesmodel.hpp | 81 ++++++++++--------- components/esxselector/model/esmfile.cpp | 50 ++++++++++++ components/esxselector/model/esmfile.hpp | 56 +++++++++++++ .../esxselector/model/masterproxymodel.cpp | 4 +- .../esxselector/model/masterproxymodel.hpp | 2 +- components/esxselector/model/modelitem.cpp | 18 ++--- components/esxselector/model/modelitem.hpp | 37 +++++---- components/esxselector/model/naturalsort.hpp | 8 +- .../esxselector/model/pluginsproxymodel.cpp | 6 +- .../esxselector/model/pluginsproxymodel.hpp | 20 +++-- .../esxselector/view/comboboxlineedit.cpp | 6 +- .../esxselector/view/comboboxlineedit.hpp | 26 +++--- .../esxselector/view/contentselector.cpp | 32 ++++---- .../esxselector/view/contentselector.hpp | 19 +++-- components/esxselector/view/lineedit.cpp | 6 +- components/esxselector/view/lineedit.hpp | 26 +++--- .../esxselector/view/profilescombobox.cpp | 12 +-- .../esxselector/view/profilescombobox.hpp | 43 +++++----- files/ui/datafilespage.ui | 8 +- 29 files changed, 381 insertions(+), 250 deletions(-) create mode 100644 components/esxselector/model/esmfile.cpp create mode 100644 components/esxselector/model/esmfile.hpp diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 44f92d7fe..2346a0b01 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -7,15 +7,15 @@ #include -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include -#include "components/fileorderlist/masterproxymodel.hpp" +#include "components/esxselector/model/masterproxymodel.hpp" #include "settings/gamesettings.hpp" #include "settings/launchersettings.hpp" diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 356cb88d6..f3792b1f1 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -5,7 +5,7 @@ #include #include "ui_datafilespage.h" -#include "components/fileorderlist/contentselector.hpp" +#include "components/esxselector/view/contentselector.hpp" class QSortFilterProxyModel; class QAbstractItemModel; @@ -20,7 +20,7 @@ class PluginsProxyModel; namespace Files { struct ConfigurationManager; } -class DataFilesPage : public EsxSelector::ContentSelector +class DataFilesPage : public EsxView::ContentSelector { Q_OBJECT public: diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 1bbf7f897..4d5975e58 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include "settings/graphicssettings.hpp" diff --git a/apps/launcher/utils/textinputdialog.cpp b/apps/launcher/utils/textinputdialog.cpp index a4b36b95e..052fc58e4 100644 --- a/apps/launcher/utils/textinputdialog.cpp +++ b/apps/launcher/utils/textinputdialog.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWidget *parent) : QDialog(parent) @@ -19,7 +19,7 @@ TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWid // Line edit QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore - mLineEdit = new LineEdit(this); + mLineEdit = new EsxView::LineEdit(this); mLineEdit->setValidator(validator); mLineEdit->setCompleter(0); diff --git a/apps/launcher/utils/textinputdialog.hpp b/apps/launcher/utils/textinputdialog.hpp index cbb453ac8..2fb6e0f6b 100644 --- a/apps/launcher/utils/textinputdialog.hpp +++ b/apps/launcher/utils/textinputdialog.hpp @@ -5,17 +5,21 @@ //#include "lineedit.hpp" class QDialogButtonBox; -class LineEdit; + +namespace EsxView { + class LineEdit; +} + class TextInputDialog : public QDialog { Q_OBJECT public: explicit TextInputDialog(const QString& title, const QString &text, QWidget *parent = 0); - inline LineEdit *lineEdit() { return mLineEdit; } + inline EsxView::LineEdit *lineEdit() { return mLineEdit; } void setOkButtonEnabled(bool enabled); - LineEdit *mLineEdit; + EsxView::LineEdit *mLineEdit; int exec(); diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 380e434c2..c88efcfb9 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -22,7 +22,7 @@ namespace CS CSMDoc::DocumentManager mDocumentManager; CSVDoc::ViewManager mViewManager; CSVDoc::StartupDialogue mStartup; - FileDialog mFileDialog; + CSVDoc::FileDialog mFileDialog; Files::ConfigurationManager mCfgMgr; void setupDataFiles(); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 252c760fa..12849d6ee 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -10,15 +10,15 @@ #include #include -#include -#include -#include +#include +#include +#include -#include +#include -#include "components/fileorderlist/masterproxymodel.hpp" +#include "components/esxselector/model/masterproxymodel.hpp" -FileDialog::FileDialog(QWidget *parent) : +CSVDoc::FileDialog::FileDialog(QWidget *parent) : ContentSelector(parent) { // Hide the profile elements @@ -60,7 +60,7 @@ FileDialog::FileDialog(QWidget *parent) : // connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject())); } -void FileDialog::updateOpenButton(const QStringList &items) +void CSVDoc::FileDialog::updateOpenButton(const QStringList &items) { QPushButton *openButton = mButtonBox->button(QDialogButtonBox::Open); @@ -70,7 +70,7 @@ void FileDialog::updateOpenButton(const QStringList &items) openButton->setEnabled(!items.isEmpty()); } -void FileDialog::updateCreateButton(const QString &name) +void CSVDoc::FileDialog::updateCreateButton(const QString &name) { if (!mCreateButton->isVisible()) return; @@ -78,12 +78,12 @@ void FileDialog::updateCreateButton(const QString &name) mCreateButton->setEnabled(!name.isEmpty()); } -QString FileDialog::fileName() +QString CSVDoc::FileDialog::fileName() { //return mNameLineEdit->text(); } -void FileDialog::openFile() +void CSVDoc::FileDialog::openFile() { setWindowTitle(tr("Open")); @@ -101,7 +101,7 @@ void FileDialog::openFile() activateWindow(); } -void FileDialog::newFile() +void CSVDoc::FileDialog::newFile() { setWindowTitle(tr("New")); @@ -118,12 +118,12 @@ void FileDialog::newFile() activateWindow(); } -void FileDialog::accept() +void CSVDoc::FileDialog::accept() { emit openFiles(); } -void FileDialog::createButtonClicked() +void CSVDoc::FileDialog::createButtonClicked() { emit createNewFile(); } diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 1b4d09745..d016ad32d 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -4,7 +4,7 @@ #include #include -#include "components/fileorderlist/contentselector.hpp" +#include "components/esxselector/view/contentselector.hpp" #include "ui_datafilespage.h" class QDialogButtonBox; @@ -18,38 +18,40 @@ class QMenu; class DataFilesModel; class PluginsProxyModel; -class FileDialog : public EsxSelector::ContentSelector +namespace CSVDoc { - Q_OBJECT -public: - explicit FileDialog(QWidget *parent = 0); + class FileDialog : public EsxView::ContentSelector + { + Q_OBJECT + public: + explicit FileDialog(QWidget *parent = 0); - void openFile(); - void newFile(); - void accepted(); + void openFile(); + void newFile(); + void accepted(); - QString fileName(); + QString fileName(); -signals: - void openFiles(); - void createNewFile(); - -public slots: - void accept(); + signals: + void openFiles(); + void createNewFile(); -private slots: - //void updateViews(); - void updateOpenButton(const QStringList &items); - void updateCreateButton(const QString &name); + public slots: + void accept(); - void createButtonClicked(); + private slots: + //void updateViews(); + void updateOpenButton(const QStringList &items); + void updateCreateButton(const QString &name); -private: - QLabel *mNameLabel; - //LineEdit *mNameLineEdit; + void createButtonClicked(); - QPushButton *mCreateButton; - QDialogButtonBox *mButtonBox; -}; + private: + QLabel *mNameLabel; + //LineEdit *mNameLineEdit; + QPushButton *mCreateButton; + QDialogButtonBox *mButtonBox; + }; +} #endif // FILEDIALOG_HPP diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 4f14fa9d9..8b07a4e00 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -73,7 +73,7 @@ find_package(Qt4 COMPONENTS QtCore QtGui) if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) add_component_qt_dir (esxselector model/masterproxymodel model/modelitem model/datafilesmodel - model/pluginsproxymodel model/esm/esmfile model/naturalsort + model/pluginsproxymodel model/esmfile model/naturalsort view/profilescombobox view/comboboxlineedit view/lineedit view/contentselector ) diff --git a/components/esxselector/model/datafilesmodel.cpp b/components/esxselector/model/datafilesmodel.cpp index ae842381e..2980313f0 100644 --- a/components/esxselector/model/datafilesmodel.cpp +++ b/components/esxselector/model/datafilesmodel.cpp @@ -2,33 +2,34 @@ #include #include #include +#include #include #include -#include "esm/esmfile.hpp" +#include "esmfile.hpp" #include "datafilesmodel.hpp" #include -DataFilesModel::DataFilesModel(QObject *parent) : +EsxModel::DataFilesModel::DataFilesModel(QObject *parent) : QAbstractTableModel(parent) { mEncoding = QString("win1252"); } -DataFilesModel::~DataFilesModel() +EsxModel::DataFilesModel::~DataFilesModel() { } -void DataFilesModel::setEncoding(const QString &encoding) +void EsxModel::DataFilesModel::setEncoding(const QString &encoding) { mEncoding = encoding; } -void DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState state) +void EsxModel::DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState state) { if (!index.isValid()) return; @@ -45,24 +46,24 @@ void DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState stat } -Qt::CheckState DataFilesModel::checkState(const QModelIndex &index) +Qt::CheckState EsxModel::DataFilesModel::checkState(const QModelIndex &index) { EsmFile *file = item(index.row()); return mCheckStates[file->fileName()]; } -int DataFilesModel::columnCount(const QModelIndex &parent) const +int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : 9; } -int DataFilesModel::rowCount(const QModelIndex &parent) const +int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : mFiles.count(); } -bool DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &parent) +bool EsxModel::DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &parent) { if (oldrow < 0 || row < 0 || oldrow == row) return false; @@ -76,7 +77,7 @@ bool DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &parent) return true; } -QVariant DataFilesModel::data(const QModelIndex &index, int role) const +QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -166,7 +167,7 @@ QVariant DataFilesModel::data(const QModelIndex &index, int role) const } -Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const +Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; @@ -192,7 +193,7 @@ Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const } -QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) return QVariant(); @@ -217,7 +218,7 @@ QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, in return QVariant(); } -bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid()) return false; @@ -225,7 +226,7 @@ bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, in return false; } -bool lessThanEsmFile(const EsmFile *e1, const EsmFile *e2) +bool lessThanEsmFile(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) { //Masters first then alphabetically if (e1->fileName().endsWith(".esm") && !e2->fileName().endsWith(".esm")) @@ -236,7 +237,7 @@ bool lessThanEsmFile(const EsmFile *e1, const EsmFile *e2) return e1->fileName().toLower() < e2->fileName().toLower(); } -bool lessThanDate(const EsmFile *e1, const EsmFile *e2) +bool lessThanDate(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) { if (e1->modified().toString(Qt::ISODate) < e2->modified().toString(Qt::ISODate)) { return true; @@ -245,7 +246,7 @@ bool lessThanDate(const EsmFile *e1, const EsmFile *e2) } } -void DataFilesModel::sort(int column, Qt::SortOrder order) +void EsxModel::DataFilesModel::sort(int column, Qt::SortOrder order) { emit layoutAboutToBeChanged(); @@ -258,14 +259,14 @@ void DataFilesModel::sort(int column, Qt::SortOrder order) emit layoutChanged(); } -void DataFilesModel::addFile(EsmFile *file) +void EsxModel::DataFilesModel::addFile(EsmFile *file) { emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); mFiles.append(file); emit endInsertRows(); } -void DataFilesModel::addFiles(const QString &path) +void EsxModel::DataFilesModel::addFiles(const QString &path) { QDir dir(path); QStringList filters; @@ -330,7 +331,7 @@ void DataFilesModel::addFiles(const QString &path) delete decoder; } -QModelIndex DataFilesModel::indexFromItem(EsmFile *item) const +QModelIndex EsxModel::DataFilesModel::indexFromItem(EsmFile *item) const { if (item) return createIndex(mFiles.indexOf(item), 0); @@ -338,7 +339,7 @@ QModelIndex DataFilesModel::indexFromItem(EsmFile *item) const return QModelIndex(); } -EsmFile* DataFilesModel::findItem(const QString &name) +EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) { QList::ConstIterator it; QList::ConstIterator itEnd = mFiles.constEnd(); @@ -356,7 +357,7 @@ EsmFile* DataFilesModel::findItem(const QString &name) return 0; } -EsmFile* DataFilesModel::item(int row) const +EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const { if (row >= 0 && row < mFiles.count()) return mFiles.at(row); @@ -364,7 +365,7 @@ EsmFile* DataFilesModel::item(int row) const return 0; } -QStringList DataFilesModel::checkedItems() +QStringList EsxModel::DataFilesModel::checkedItems() { QStringList list; @@ -386,7 +387,7 @@ QStringList DataFilesModel::checkedItems() return list; } -QStringList DataFilesModel::checkedItemsPaths() +QStringList EsxModel::DataFilesModel::checkedItemsPaths() { QStringList list; @@ -405,14 +406,14 @@ QStringList DataFilesModel::checkedItemsPaths() return list; } -void DataFilesModel::uncheckAll() +void EsxModel::DataFilesModel::uncheckAll() { emit layoutAboutToBeChanged(); mCheckStates.clear(); emit layoutChanged(); } -QStringList DataFilesModel::uncheckedItems() +QStringList EsxModel::DataFilesModel::uncheckedItems() { QStringList list; QStringList checked = checkedItems(); @@ -433,7 +434,7 @@ QStringList DataFilesModel::uncheckedItems() return list; } -bool DataFilesModel::canBeChecked(EsmFile *file) const +bool EsxModel::DataFilesModel::canBeChecked(EsmFile *file) const { //element can be checked if all its dependencies are foreach (const QString &master, file->masters()) diff --git a/components/esxselector/model/datafilesmodel.hpp b/components/esxselector/model/datafilesmodel.hpp index 0a07a536f..bc55bb6cf 100644 --- a/components/esxselector/model/datafilesmodel.hpp +++ b/components/esxselector/model/datafilesmodel.hpp @@ -6,61 +6,62 @@ #include #include - -class EsmFile; - -class DataFilesModel : public QAbstractTableModel +namespace EsxModel { - Q_OBJECT + class EsmFile; -public: - explicit DataFilesModel(QObject *parent = 0); - virtual ~DataFilesModel(); - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + class DataFilesModel : public QAbstractTableModel + { + Q_OBJECT - bool moveRow(int oldrow, int row, const QModelIndex &parent = QModelIndex()); + public: + explicit DataFilesModel(QObject *parent = 0); + virtual ~DataFilesModel(); + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; + bool moveRow(int oldrow, int row, const QModelIndex &parent = QModelIndex()); - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const; - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const - { return QAbstractTableModel::index(row, column, parent); } + virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); - void setEncoding(const QString &encoding); + inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const + { return QAbstractTableModel::index(row, column, parent); } - void addFiles(const QString &path); + void setEncoding(const QString &encoding); - void uncheckAll(); + void addFiles(const QString &path); - QStringList checkedItems(); - QStringList uncheckedItems(); - QStringList checkedItemsPaths(); + void uncheckAll(); - Qt::CheckState checkState(const QModelIndex &index); - void setCheckState(const QModelIndex &index, Qt::CheckState state); + QStringList checkedItems(); + QStringList uncheckedItems(); + QStringList checkedItemsPaths(); - QModelIndex indexFromItem(EsmFile *item) const; - EsmFile* findItem(const QString &name); - EsmFile* item(int row) const; + Qt::CheckState checkState(const QModelIndex &index); + void setCheckState(const QModelIndex &index, Qt::CheckState state); -signals: - void checkedItemsChanged(const QStringList &items); - -private: - bool canBeChecked(EsmFile *file) const; - void addFile(EsmFile *file); - - QList mFiles; - QHash mCheckStates; + QModelIndex indexFromItem(EsmFile *item) const; + EsmFile* findItem(const QString &name); + EsmFile* item(int row) const; - QString mEncoding; + signals: + void checkedItemsChanged(const QStringList &items); -}; + private: + bool canBeChecked(EsmFile *file) const; + void addFile(EsmFile *file); + QList mFiles; + QHash mCheckStates; + + QString mEncoding; + + }; +} #endif // DATAFILESMODEL_HPP diff --git a/components/esxselector/model/esmfile.cpp b/components/esxselector/model/esmfile.cpp new file mode 100644 index 000000000..96b90e44e --- /dev/null +++ b/components/esxselector/model/esmfile.cpp @@ -0,0 +1,50 @@ +#include "esmfile.hpp" + +EsxModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) + : ModelItem(parent) +{ + mFileName = fileName; + mSize = 0; + mVersion = 0.0f; +} + +void EsxModel::EsmFile::setFileName(const QString &fileName) +{ + mFileName = fileName; +} + +void EsxModel::EsmFile::setAuthor(const QString &author) +{ + mAuthor = author; +} + +void EsxModel::EsmFile::setSize(const int size) +{ + mSize = size; +} + +void EsxModel::EsmFile::setDates(const QDateTime &modified, const QDateTime &accessed) +{ + mModified = modified; + mAccessed = accessed; +} + +void EsxModel::EsmFile::setVersion(float version) +{ + mVersion = version; +} + +void EsxModel::EsmFile::setPath(const QString &path) +{ + mPath = path; +} + +void EsxModel::EsmFile::setMasters(const QStringList &masters) +{ + mMasters = masters; +} + +void EsxModel::EsmFile::setDescription(const QString &description) +{ + mDescription = description; +} diff --git a/components/esxselector/model/esmfile.hpp b/components/esxselector/model/esmfile.hpp new file mode 100644 index 000000000..6a3e36b53 --- /dev/null +++ b/components/esxselector/model/esmfile.hpp @@ -0,0 +1,56 @@ +#ifndef ESMFILE_HPP +#define ESMFILE_HPP + +#include +#include + +#include "modelitem.hpp" + +namespace EsxModel +{ + class EsmFile : public ModelItem + { + Q_OBJECT + Q_PROPERTY(QString filename READ fileName) + + public: + EsmFile(QString fileName = QString(), ModelItem *parent = 0); + + ~EsmFile() + {} + + void setFileName(const QString &fileName); + void setAuthor(const QString &author); + void setSize(const int size); + void setDates(const QDateTime &modified, const QDateTime &accessed); + void setVersion(const float version); + void setPath(const QString &path); + void setMasters(const QStringList &masters); + void setDescription(const QString &description); + + inline QString fileName() const { return mFileName; } + inline QString author() const { return mAuthor; } + inline int size() const { return mSize; } + inline QDateTime modified() const { return mModified; } + inline QDateTime accessed() const { return mAccessed; } + inline float version() const { return mVersion; } + inline QString path() const { return mPath; } + inline QStringList masters() const { return mMasters; } + inline QString description() const { return mDescription; } + + + private: + QString mFileName; + QString mAuthor; + int mSize; + QDateTime mModified; + QDateTime mAccessed; + float mVersion; + QString mPath; + QStringList mMasters; + QString mDescription; + + }; +} + +#endif diff --git a/components/esxselector/model/masterproxymodel.cpp b/components/esxselector/model/masterproxymodel.cpp index 04a7f0033..011e5ebd5 100644 --- a/components/esxselector/model/masterproxymodel.cpp +++ b/components/esxselector/model/masterproxymodel.cpp @@ -1,6 +1,6 @@ #include "masterproxymodel.hpp" -EsxSelector::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : +EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : QSortFilterProxyModel(parent) { setFilterRegExp(QString("game")); @@ -10,7 +10,7 @@ EsxSelector::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableM setSourceModel (model); } -QVariant EsxSelector::MasterProxyModel::data(const QModelIndex &index, int role) const +QVariant EsxModel::MasterProxyModel::data(const QModelIndex &index, int role) const { return QSortFilterProxyModel::data (index, role); } diff --git a/components/esxselector/model/masterproxymodel.hpp b/components/esxselector/model/masterproxymodel.hpp index 6fbdd3154..fed01bdb1 100644 --- a/components/esxselector/model/masterproxymodel.hpp +++ b/components/esxselector/model/masterproxymodel.hpp @@ -5,7 +5,7 @@ class QAbstractTableModel; -namespace EsxSelector +namespace EsxModel { class MasterProxyModel : public QSortFilterProxyModel { diff --git a/components/esxselector/model/modelitem.cpp b/components/esxselector/model/modelitem.cpp index 0ff7e45cb..8c1e83695 100644 --- a/components/esxselector/model/modelitem.cpp +++ b/components/esxselector/model/modelitem.cpp @@ -1,23 +1,23 @@ #include "modelitem.hpp" -ModelItem::ModelItem(ModelItem *parent) +EsxModel::ModelItem::ModelItem(ModelItem *parent) : mParentItem(parent) , QObject(parent) { } -ModelItem::~ModelItem() +EsxModel::ModelItem::~ModelItem() { qDeleteAll(mChildItems); } -ModelItem *ModelItem::parent() +EsxModel::ModelItem *EsxModel::ModelItem::parent() { return mParentItem; } -int ModelItem::row() const +int EsxModel::ModelItem::row() const { if (mParentItem) return 1; @@ -28,30 +28,30 @@ int ModelItem::row() const } -int ModelItem::childCount() const +int EsxModel::ModelItem::childCount() const { return mChildItems.count(); } -int ModelItem::childRow(ModelItem *child) const +int EsxModel::ModelItem::childRow(ModelItem *child) const { Q_ASSERT(child); return mChildItems.indexOf(child); } -ModelItem *ModelItem::child(int row) +EsxModel::ModelItem *EsxModel::ModelItem::child(int row) { return mChildItems.value(row); } -void ModelItem::appendChild(ModelItem *item) +void EsxModel::ModelItem::appendChild(ModelItem *item) { mChildItems.append(item); } -void ModelItem::removeChild(int row) +void EsxModel::ModelItem::removeChild(int row) { mChildItems.removeAt(row); } diff --git a/components/esxselector/model/modelitem.hpp b/components/esxselector/model/modelitem.hpp index f4cb4322f..64596302c 100644 --- a/components/esxselector/model/modelitem.hpp +++ b/components/esxselector/model/modelitem.hpp @@ -4,29 +4,32 @@ #include #include -class ModelItem : public QObject +namespace EsxModel { - Q_OBJECT + class ModelItem : public QObject + { + Q_OBJECT -public: - ModelItem(ModelItem *parent = 0); - ~ModelItem(); + public: + ModelItem(ModelItem *parent = 0); + ~ModelItem(); - ModelItem *parent(); - int row() const; + ModelItem *parent(); + int row() const; - int childCount() const; - int childRow(ModelItem *child) const; - ModelItem *child(int row); + int childCount() const; + int childRow(ModelItem *child) const; + ModelItem *child(int row); - void appendChild(ModelItem *child); - void removeChild(int row); + void appendChild(ModelItem *child); + void removeChild(int row); - //virtual bool acceptChild(ModelItem *child); + //virtual bool acceptChild(ModelItem *child); -protected: - ModelItem *mParentItem; - QList mChildItems; -}; + protected: + ModelItem *mParentItem; + QList mChildItems; + }; +} #endif diff --git a/components/esxselector/model/naturalsort.hpp b/components/esxselector/model/naturalsort.hpp index 59271547a..8386e4e9f 100644 --- a/components/esxselector/model/naturalsort.hpp +++ b/components/esxselector/model/naturalsort.hpp @@ -3,9 +3,9 @@ #include -bool naturalSortLessThanCS( const QString &left, const QString &right ); -bool naturalSortLessThanCI( const QString &left, const QString &right ); -bool naturalSortGreaterThanCS( const QString &left, const QString &right ); -bool naturalSortGreaterThanCI( const QString &left, const QString &right ); + bool naturalSortLessThanCS( const QString &left, const QString &right ); + bool naturalSortLessThanCI( const QString &left, const QString &right ); + bool naturalSortGreaterThanCS( const QString &left, const QString &right ); + bool naturalSortGreaterThanCI( const QString &left, const QString &right ); #endif diff --git a/components/esxselector/model/pluginsproxymodel.cpp b/components/esxselector/model/pluginsproxymodel.cpp index 18aebc6b6..4fde11f47 100644 --- a/components/esxselector/model/pluginsproxymodel.cpp +++ b/components/esxselector/model/pluginsproxymodel.cpp @@ -1,7 +1,7 @@ #include "pluginsproxymodel.hpp" #include "datafilesmodel.hpp" -PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : +EsxModel::PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : QSortFilterProxyModel(parent) { setFilterRegExp (QString("addon")); @@ -12,11 +12,11 @@ PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : setSourceModel (model); } -PluginsProxyModel::~PluginsProxyModel() +EsxModel::PluginsProxyModel::~PluginsProxyModel() { } -QVariant PluginsProxyModel::data(const QModelIndex &index, int role) const +QVariant EsxModel::PluginsProxyModel::data(const QModelIndex &index, int role) const { switch (role) { diff --git a/components/esxselector/model/pluginsproxymodel.hpp b/components/esxselector/model/pluginsproxymodel.hpp index cfade092e..04c18c2e2 100644 --- a/components/esxselector/model/pluginsproxymodel.hpp +++ b/components/esxselector/model/pluginsproxymodel.hpp @@ -5,18 +5,22 @@ class QVariant; class QAbstractTableModel; -class DataFilesModel; -class PluginsProxyModel : public QSortFilterProxyModel +namespace EsxModel { - Q_OBJECT + class DataFilesModel; -public: + class PluginsProxyModel : public QSortFilterProxyModel + { + Q_OBJECT - explicit PluginsProxyModel(QObject *parent = 0, DataFilesModel *model = 0); - ~PluginsProxyModel(); + public: - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -}; + explicit PluginsProxyModel(QObject *parent = 0, DataFilesModel *model = 0); + ~PluginsProxyModel(); + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + }; +} #endif // PLUGINSPROXYMODEL_HPP diff --git a/components/esxselector/view/comboboxlineedit.cpp b/components/esxselector/view/comboboxlineedit.cpp index 4d62e1399..815a1130b 100644 --- a/components/esxselector/view/comboboxlineedit.cpp +++ b/components/esxselector/view/comboboxlineedit.cpp @@ -3,7 +3,7 @@ #include "comboboxlineedit.hpp" -ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) +EsxView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) : QLineEdit(parent) { mClearButton = new QToolButton(this); @@ -21,7 +21,7 @@ ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1)); } -void ComboBoxLineEdit::resizeEvent(QResizeEvent *) +void EsxView::ComboBoxLineEdit::resizeEvent(QResizeEvent *) { QSize sz = mClearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); @@ -29,7 +29,7 @@ void ComboBoxLineEdit::resizeEvent(QResizeEvent *) (rect().bottom() + 1 - sz.height())/2); } -void ComboBoxLineEdit::updateClearButton(const QString& text) +void EsxView::ComboBoxLineEdit::updateClearButton(const QString& text) { mClearButton->setVisible(!text.isEmpty()); } diff --git a/components/esxselector/view/comboboxlineedit.hpp b/components/esxselector/view/comboboxlineedit.hpp index ba10731ae..f3b251955 100644 --- a/components/esxselector/view/comboboxlineedit.hpp +++ b/components/esxselector/view/comboboxlineedit.hpp @@ -14,22 +14,24 @@ class QToolButton; -class ComboBoxLineEdit : public QLineEdit +namespace EsxView { - Q_OBJECT + class ComboBoxLineEdit : public QLineEdit + { + Q_OBJECT -public: - ComboBoxLineEdit(QWidget *parent = 0); + public: + ComboBoxLineEdit(QWidget *parent = 0); -protected: - void resizeEvent(QResizeEvent *); + protected: + void resizeEvent(QResizeEvent *); -private slots: - void updateClearButton(const QString &text); - -private: - QToolButton *mClearButton; -}; + private slots: + void updateClearButton(const QString &text); + private: + QToolButton *mClearButton; + }; +} #endif // LIENEDIT_H diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index 16139d9e6..2de68e5bf 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -1,8 +1,8 @@ #include "contentselector.hpp" -#include "model/datafilesmodel.hpp" -#include "masterproxymodel.hpp" -#include "model/pluginsproxymodel.hpp" +#include "../model/datafilesmodel.hpp" +#include "../model/masterproxymodel.hpp" +#include "../model/pluginsproxymodel.hpp" #include @@ -10,20 +10,20 @@ #include #include -EsxSelector::ContentSelector::ContentSelector(QWidget *parent) : +EsxView::ContentSelector::ContentSelector(QWidget *parent) : QWidget(parent) { setupUi(this); buildModelsAndViews(); } -void EsxSelector::ContentSelector::buildModelsAndViews() +void EsxView::ContentSelector::buildModelsAndViews() { // Models - mDataFilesModel = new DataFilesModel (this); + mDataFilesModel = new EsxModel::DataFilesModel (this); - mMasterProxyModel = new EsxSelector::MasterProxyModel (this, mDataFilesModel); - mPluginsProxyModel = new PluginsProxyModel (this, mDataFilesModel); + mMasterProxyModel = new EsxModel::MasterProxyModel (this, mDataFilesModel); + mPluginsProxyModel = new EsxModel::PluginsProxyModel (this, mDataFilesModel); masterView->setModel(mMasterProxyModel); pluginView->setModel(mPluginsProxyModel); @@ -35,7 +35,7 @@ void EsxSelector::ContentSelector::buildModelsAndViews() connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); } -void EsxSelector::ContentSelector::addFiles(const QString &path) +void EsxView::ContentSelector::addFiles(const QString &path) { mDataFilesModel->addFiles(path); mDataFilesModel->sort(3); // Sort by date accessed @@ -43,12 +43,12 @@ void EsxSelector::ContentSelector::addFiles(const QString &path) mDataFilesModel->uncheckAll(); } -void EsxSelector::ContentSelector::setEncoding(const QString &encoding) +void EsxView::ContentSelector::setEncoding(const QString &encoding) { mDataFilesModel->setEncoding(encoding); } -void EsxSelector::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model) +void EsxView::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model) { if (!index.isValid()) return; @@ -66,12 +66,12 @@ void EsxSelector::ContentSelector::setCheckState(QModelIndex index, QSortFilterP } } -QStringList EsxSelector::ContentSelector::checkedItemsPaths() +QStringList EsxView::ContentSelector::checkedItemsPaths() { return mDataFilesModel->checkedItemsPaths(); } -void EsxSelector::ContentSelector::updateViews() +void EsxView::ContentSelector::updateViews() { // Ensure the columns are hidden because sort() re-enables them pluginView->setColumnHidden(1, true); @@ -85,12 +85,12 @@ void EsxSelector::ContentSelector::updateViews() } -void EsxSelector::ContentSelector::slotCurrentProfileIndexChanged(int index) +void EsxView::ContentSelector::slotCurrentProfileIndexChanged(int index) { emit profileChanged(index); } -void EsxSelector::ContentSelector::slotCurrentMasterIndexChanged(int index) +void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index) { QObject *object = QObject::sender(); @@ -101,7 +101,7 @@ void EsxSelector::ContentSelector::slotCurrentMasterIndexChanged(int index) setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel); } -void EsxSelector::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) +void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) { setCheckState(index, mPluginsProxyModel); } diff --git a/components/esxselector/view/contentselector.hpp b/components/esxselector/view/contentselector.hpp index f1d8f6927..35ef3a07c 100644 --- a/components/esxselector/view/contentselector.hpp +++ b/components/esxselector/view/contentselector.hpp @@ -5,23 +5,26 @@ #include "ui_datafilespage.h" -class DataFilesModel; -class PluginsProxyModel; +namespace EsxModel +{ + class DataFilesModel; + class PluginsProxyModel; + class MasterProxyModel; +} + class QSortFilterProxyModel; -namespace FileOrderList +namespace EsxView { - class MasterProxyModel; - class ContentSelector : public QWidget, protected Ui::DataFilesPage { Q_OBJECT protected: - DataFilesModel *mDataFilesModel; - MasterProxyModel *mMasterProxyModel; - PluginsProxyModel *mPluginsProxyModel; + EsxModel::DataFilesModel *mDataFilesModel; + EsxModel::MasterProxyModel *mMasterProxyModel; + EsxModel::PluginsProxyModel *mPluginsProxyModel; public: explicit ContentSelector(QWidget *parent = 0); diff --git a/components/esxselector/view/lineedit.cpp b/components/esxselector/view/lineedit.cpp index b0f339589..8944251ae 100644 --- a/components/esxselector/view/lineedit.cpp +++ b/components/esxselector/view/lineedit.cpp @@ -3,7 +3,7 @@ #include "lineedit.hpp" -LineEdit::LineEdit(QWidget *parent) +EsxView::LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent) { mClearButton = new QToolButton(this); @@ -24,7 +24,7 @@ LineEdit::LineEdit(QWidget *parent) qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2)); } -void LineEdit::resizeEvent(QResizeEvent *) +void EsxView::LineEdit::resizeEvent(QResizeEvent *) { QSize sz = mClearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); @@ -32,7 +32,7 @@ void LineEdit::resizeEvent(QResizeEvent *) (rect().bottom() + 1 - sz.height())/2); } -void LineEdit::updateClearButton(const QString& text) +void EsxView::LineEdit::updateClearButton(const QString& text) { mClearButton->setVisible(!text.isEmpty()); } diff --git a/components/esxselector/view/lineedit.hpp b/components/esxselector/view/lineedit.hpp index 14bd7b1b4..e48392ba8 100644 --- a/components/esxselector/view/lineedit.hpp +++ b/components/esxselector/view/lineedit.hpp @@ -14,22 +14,24 @@ class QToolButton; -class LineEdit : public QLineEdit +namespace EsxView { - Q_OBJECT + class LineEdit : public QLineEdit + { + Q_OBJECT -public: - LineEdit(QWidget *parent = 0); + public: + LineEdit(QWidget *parent = 0); -protected: - void resizeEvent(QResizeEvent *); + protected: + void resizeEvent(QResizeEvent *); -private slots: - void updateClearButton(const QString &text); - -private: - QToolButton *mClearButton; -}; + private slots: + void updateClearButton(const QString &text); + private: + QToolButton *mClearButton; + }; +} #endif // LIENEDIT_H diff --git a/components/esxselector/view/profilescombobox.cpp b/components/esxselector/view/profilescombobox.cpp index 9346276da..b765f87ca 100644 --- a/components/esxselector/view/profilescombobox.cpp +++ b/components/esxselector/view/profilescombobox.cpp @@ -7,7 +7,7 @@ #include "profilescombobox.hpp" #include "comboboxlineedit.hpp" -ProfilesComboBox::ProfilesComboBox(QWidget *parent) : +EsxView::ProfilesComboBox::ProfilesComboBox(QWidget *parent) : QComboBox(parent) { mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore @@ -21,7 +21,7 @@ ProfilesComboBox::ProfilesComboBox(QWidget *parent) : setInsertPolicy(QComboBox::NoInsert); } -void ProfilesComboBox::setEditEnabled(bool editable) +void EsxView::ProfilesComboBox::setEditEnabled(bool editable) { if (isEditable() == editable) return; @@ -47,7 +47,7 @@ void ProfilesComboBox::setEditEnabled(bool editable) SLOT(slotTextChanged(QString))); } -void ProfilesComboBox::slotTextChanged(const QString &text) +void EsxView::ProfilesComboBox::slotTextChanged(const QString &text) { QPalette *palette = new QPalette(); palette->setColor(QPalette::Text,Qt::red); @@ -61,7 +61,7 @@ void ProfilesComboBox::slotTextChanged(const QString &text) } } -void ProfilesComboBox::slotEditingFinished() +void EsxView::ProfilesComboBox::slotEditingFinished() { QString current = currentText(); QString previous = itemText(currentIndex()); @@ -82,7 +82,7 @@ void ProfilesComboBox::slotEditingFinished() emit(profileRenamed(previous, current)); } -void ProfilesComboBox::slotIndexChanged(int index) +void EsxView::ProfilesComboBox::slotIndexChanged(int index) { if (index == -1) return; @@ -91,7 +91,7 @@ void ProfilesComboBox::slotIndexChanged(int index) mOldProfile = itemText(index); } -void ProfilesComboBox::paintEvent(QPaintEvent *) +void EsxView::ProfilesComboBox::paintEvent(QPaintEvent *) { QStylePainter painter(this); painter.setPen(palette().color(QPalette::Text)); diff --git a/components/esxselector/view/profilescombobox.hpp b/components/esxselector/view/profilescombobox.hpp index 55913d7fe..218948e7b 100644 --- a/components/esxselector/view/profilescombobox.hpp +++ b/components/esxselector/view/profilescombobox.hpp @@ -6,28 +6,31 @@ class QString; class QRegExpValidator; -class ProfilesComboBox : public QComboBox +namespace EsxView { - Q_OBJECT -public: - explicit ProfilesComboBox(QWidget *parent = 0); - void setEditEnabled(bool editable); - -signals: - void profileChanged(const QString &previous, const QString ¤t); - void profileRenamed(const QString &oldName, const QString &newName); - -private slots: - void slotEditingFinished(); - void slotIndexChanged(int index); - void slotTextChanged(const QString &text); + class ProfilesComboBox : public QComboBox + { + Q_OBJECT + public: + explicit ProfilesComboBox(QWidget *parent = 0); + void setEditEnabled(bool editable); -private: - QString mOldProfile; - QRegExpValidator *mValidator; + signals: + void profileChanged(const QString &previous, const QString ¤t); + void profileRenamed(const QString &oldName, const QString &newName); -protected: - void paintEvent(QPaintEvent *); -}; + private slots: + void slotEditingFinished(); + void slotIndexChanged(int index); + void slotTextChanged(const QString &text); + + private: + QString mOldProfile; + QRegExpValidator *mValidator; + + protected: + void paintEvent(QPaintEvent *); + }; +} #endif // PROFILESCOMBOBOX_HPP diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 07ad9d3ba..523ee69cc 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -17,7 +17,7 @@ - + false @@ -79,7 +79,7 @@ - + true @@ -168,9 +168,9 @@ - ProfilesComboBox + EsxView::ProfilesComboBox QComboBox -
components/fileorderlist/utils/profilescombobox.hpp
+
components/esxselector/view/profilescombobox.hpp
From e614ec335334d186dac0fba1147fa4c0e5bd6400 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 18 Aug 2013 17:11:23 -0500 Subject: [PATCH 18/42] Fixing profile code in progress... --- apps/opencs/view/doc/filedialog.cpp | 11 +- apps/opencs/view/doc/filedialog.hpp | 8 +- .../esxselector/view/contentselector.cpp | 4 +- .../esxselector/view/profilescombobox.cpp | 7 +- .../esxselector/view/profilescombobox.hpp | 2 + files/ui/datafilespage.ui | 257 +++++++++++------- 6 files changed, 175 insertions(+), 114 deletions(-) diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 12849d6ee..4f4aef4f2 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -22,10 +22,7 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : ContentSelector(parent) { // Hide the profile elements - profileLabel->hide(); - profilesComboBox->hide(); - newProfileButton->hide(); - deleteProfileButton->hide(); + profileGroupBox->hide(); // Add some extra widgets QHBoxLayout *nameLayout = new QHBoxLayout(); @@ -34,12 +31,12 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : mNameLabel = new QLabel(tr("File Name:"), this); QRegExpValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9\\s]*$")); - //mNameLineEdit = new LineEdit(this); - //mNameLineEdit->setValidator(validator); + mNameLineEdit = new EsxView::LineEdit(this); + mNameLineEdit->setValidator(validator); nameLayout->addSpacerItem(spacer); nameLayout->addWidget(mNameLabel); - //nameLayout->addWidget(mNameLineEdit); + nameLayout->addWidget(mNameLineEdit); mButtonBox = new QDialogButtonBox(this); diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index d016ad32d..0e2d8f32b 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -14,10 +14,16 @@ class QPushButton; class QStringList; class QString; class QMenu; +class QLabel; class DataFilesModel; class PluginsProxyModel; +namespace EsxView +{ + class LineEdit; +} + namespace CSVDoc { class FileDialog : public EsxView::ContentSelector @@ -48,7 +54,7 @@ namespace CSVDoc private: QLabel *mNameLabel; - //LineEdit *mNameLineEdit; + EsxView::LineEdit *mNameLineEdit; QPushButton *mCreateButton; QDialogButtonBox *mButtonBox; diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index 2de68e5bf..266fd76dc 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -25,9 +25,11 @@ void EsxView::ContentSelector::buildModelsAndViews() mMasterProxyModel = new EsxModel::MasterProxyModel (this, mDataFilesModel); mPluginsProxyModel = new EsxModel::PluginsProxyModel (this, mDataFilesModel); + masterView->setPlaceholderText(QString("Select a game file...")); masterView->setModel(mMasterProxyModel); pluginView->setModel(mPluginsProxyModel); - pluginView-> + profilesComboBox->setPlaceholderText(QString("Select a profile...")); + connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); diff --git a/components/esxselector/view/profilescombobox.cpp b/components/esxselector/view/profilescombobox.cpp index b765f87ca..0d709aa50 100644 --- a/components/esxselector/view/profilescombobox.cpp +++ b/components/esxselector/view/profilescombobox.cpp @@ -103,6 +103,11 @@ void EsxView::ProfilesComboBox::paintEvent(QPaintEvent *) // draw the icon and text if (!opt.editable && currentIndex() == -1) // <<< we adjust the text displayed when nothing is selected - opt.currentText = tr("Select a game file..."); + opt.currentText = mPlaceholderText; painter.drawControl(QStyle::CE_ComboBoxLabel, opt); } + +void EsxView::ProfilesComboBox::setPlaceholderText(const QString &text) +{ + mPlaceholderText = text; +} diff --git a/components/esxselector/view/profilescombobox.hpp b/components/esxselector/view/profilescombobox.hpp index 218948e7b..28740783b 100644 --- a/components/esxselector/view/profilescombobox.hpp +++ b/components/esxselector/view/profilescombobox.hpp @@ -14,6 +14,7 @@ namespace EsxView public: explicit ProfilesComboBox(QWidget *parent = 0); void setEditEnabled(bool editable); + void setPlaceholderText (const QString &text); signals: void profileChanged(const QString &previous, const QString ¤t); @@ -26,6 +27,7 @@ namespace EsxView private: QString mOldProfile; + QString mPlaceholderText; QRegExpValidator *mValidator; protected: diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 523ee69cc..6235f31af 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -14,113 +14,162 @@ Qt::DefaultContextMenu + + 6 + + + 6 + - - - - - false - - - - + + + Content + + + + 9 + + + 6 + + + 6 + + + + + + + false + + + + + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + Qt::ElideLeft + + + false + + + false + + + true + + + false + + + + + + + pluginView + masterView + pluginView + masterView + + + - - - - - - 0 - 0 - - - - Qt::DefaultContextMenu - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - Qt::ElideLeft - - - false - - - false - - - true - - - false - - - - - - - - - - - Current Profile: - - - - - - - true - - - - 0 - 0 - - - - - - - - New Profile - - - &New Profile - - - true - - - - - - - Delete Profile - - - Delete Profile - - - Ctrl+D - - - true - - - - + + + Qt::NoFocus + + + Profiles + + + false + + + + 6 + + + 9 + + + 9 + + + 0 + + + 6 + + + + + true + + + + 0 + 0 + + + + + + + + New Profile + + + &New Profile + + + true + + + + + + + Delete Profile + + + Delete Profile + + + Ctrl+D + + + true + + + + + From b52645bf2ac594b6762fabf2b79943fd3e42d8c7 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Tue, 20 Aug 2013 03:23:32 -0500 Subject: [PATCH 19/42] Fixes to accommodate master/plugin loading --- apps/launcher/datafilespage.cpp | 96 ++----------------- apps/opencs/view/doc/filedialog.cpp | 9 +- .../esxselector/model/datafilesmodel.cpp | 34 ++++--- .../esxselector/model/datafilesmodel.hpp | 10 +- .../esxselector/view/contentselector.cpp | 1 + files/ui/datafilespage.ui | 4 +- 6 files changed, 38 insertions(+), 116 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 2346a0b01..15f8d9ba2 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -29,16 +29,11 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , mLauncherSettings(launcherSettings) , ContentSelector(parent) { - - pluginView->hideColumn(2); // Create a dialog for the new profile name input mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this); connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString))); - //connect(pluginView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); - //connect(masterView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); - createActions(); setupDataFiles(); } @@ -49,11 +44,6 @@ void DataFilesPage::createActions() // Add the actions to the toolbuttons newProfileButton->setDefaultAction(newProfileAction); deleteProfileButton->setDefaultAction(deleteProfileAction); - - // Context menu actions - mContextMenu = new QMenu(this); - mContextMenu->addAction(checkAction); - mContextMenu->addAction(uncheckAction); } void DataFilesPage::setupDataFiles() @@ -150,17 +140,17 @@ void DataFilesPage::saveSettings() mGameSettings.remove(QString("master")); mGameSettings.remove(QString("plugin")); - QStringList items = mDataFilesModel->checkedItems(); + EsxModel::EsmFileList items = mDataFilesModel->checkedItems(); - foreach(const QString &item, items) { + foreach(const EsxModel::EsmFile *item, items) { - if (item.endsWith(QString(".esm"), Qt::CaseInsensitive)) { - mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/master"), item); - mGameSettings.setMultiValue(QString("master"), item); + if (item->masters().size() == 0) { + mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/master"), item->fileName()); + mGameSettings.setMultiValue(QString("master"), item->fileName()); - } else if (item.endsWith(QString(".esp"), Qt::CaseInsensitive)) { - mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/plugin"), item); - mGameSettings.setMultiValue(QString("plugin"), item); + } else { + mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/plugin"), item->fileName()); + mGameSettings.setMultiValue(QString("plugin"), item->fileName()); } } @@ -296,73 +286,3 @@ void DataFilesPage::profileRenamed(const QString &previous, const QString &curre loadSettings(); } -/* -void DataFilesPage::showContextMenu(const QPoint &point) -{ - QObject *object = QObject::sender(); - - // Not a signal-slot call - if (!object) - return; - - if (object->objectName() == QLatin1String("PluginView")) { - if (!pluginView->selectionModel()->hasSelection()) - return; - - 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); - checkAction->setEnabled(false); - - foreach (const QModelIndex &index, indexes) - { - if (!index.isValid()) - return; - - QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index); - - if (!sourceIndex.isValid()) - return; - - (mDataFilesModel->checkState(sourceIndex) == Qt::Checked) - ? uncheckAction->setEnabled(true) - : checkAction->setEnabled(true); - } - - // Show menu - mContextMenu->exec(globalPos); - } - - if (object->objectName() == QLatin1String("MasterView")) { - if (!masterView->selectionModel()->hasSelection()) - return; - - 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); - checkAction->setEnabled(false); - - foreach (const QModelIndex &index, indexes) - { - if (!index.isValid()) - return; - - QModelIndex sourceIndex = mMastersProxyModel->mapToSource(index); - - if (!sourceIndex.isValid()) - return; - - (mDataFilesModel->checkState(sourceIndex) == Qt::Checked) - ? uncheckAction->setEnabled(true) - : checkAction->setEnabled(true); - } - - mContextMenu->exec(globalPos); - } - -} -*/ diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 4f4aef4f2..69ed1c13a 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -23,6 +23,7 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : { // Hide the profile elements profileGroupBox->hide(); + pluginView->showColumn(2); // Add some extra widgets QHBoxLayout *nameLayout = new QHBoxLayout(); @@ -77,7 +78,7 @@ void CSVDoc::FileDialog::updateCreateButton(const QString &name) QString CSVDoc::FileDialog::fileName() { - //return mNameLineEdit->text(); + return mNameLineEdit->text(); } void CSVDoc::FileDialog::openFile() @@ -85,7 +86,7 @@ void CSVDoc::FileDialog::openFile() setWindowTitle(tr("Open")); mNameLabel->hide(); - //mNameLineEdit->hide(); + mNameLineEdit->hide(); mCreateButton->hide(); mButtonBox->removeButton(mCreateButton); @@ -103,8 +104,8 @@ void CSVDoc::FileDialog::newFile() setWindowTitle(tr("New")); mNameLabel->show(); - //mNameLineEdit->clear(); - //mNameLineEdit->show(); + mNameLineEdit->clear(); + mNameLineEdit->show(); mCreateButton->show(); mButtonBox->setStandardButtons(QDialogButtonBox::Cancel); diff --git a/components/esxselector/model/datafilesmodel.cpp b/components/esxselector/model/datafilesmodel.cpp index 2980313f0..49d0d6132 100644 --- a/components/esxselector/model/datafilesmodel.cpp +++ b/components/esxselector/model/datafilesmodel.cpp @@ -365,23 +365,21 @@ EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const return 0; } -QStringList EsxModel::DataFilesModel::checkedItems() +EsxModel::EsmFileList EsxModel::DataFilesModel::checkedItems() { - QStringList list; + EsmFileList list; - QList::ConstIterator it; - QList::ConstIterator itEnd = mFiles.constEnd(); + EsmFileList::ConstIterator it; + EsmFileList::ConstIterator itEnd = mFiles.constEnd(); int i = 0; - for (it = mFiles.constBegin(); it != itEnd; ++it) { - EsmFile *file = item(i); - ++i; - - QString name = file->fileName(); + for (it = mFiles.constBegin(); it != itEnd; ++it) + { + EsmFile *file = *it; // Only add the items that are in the checked list and available - if (mCheckStates[name] == Qt::Checked && canBeChecked(file)) - list << name; + if (mCheckStates[file->fileName()] == Qt::Checked && canBeChecked(file)) + list << file; } return list; @@ -413,13 +411,13 @@ void EsxModel::DataFilesModel::uncheckAll() emit layoutChanged(); } -QStringList EsxModel::DataFilesModel::uncheckedItems() +EsxModel::EsmFileList EsxModel::DataFilesModel::uncheckedItems() { - QStringList list; - QStringList checked = checkedItems(); + EsmFileList list; + EsmFileList checked = checkedItems(); - QList::ConstIterator it; - QList::ConstIterator itEnd = mFiles.constEnd(); + EsmFileList::ConstIterator it; + EsmFileList::ConstIterator itEnd = mFiles.constEnd(); int i = 0; for (it = mFiles.constBegin(); it != itEnd; ++it) { @@ -427,8 +425,8 @@ QStringList EsxModel::DataFilesModel::uncheckedItems() ++i; // Add the items that are not in the checked list - if (!checked.contains(file->fileName())) - list << file->fileName(); + if (!checked.contains(file)) + list << file; } return list; diff --git a/components/esxselector/model/datafilesmodel.hpp b/components/esxselector/model/datafilesmodel.hpp index bc55bb6cf..24b36aa88 100644 --- a/components/esxselector/model/datafilesmodel.hpp +++ b/components/esxselector/model/datafilesmodel.hpp @@ -10,6 +10,8 @@ namespace EsxModel { class EsmFile; + typedef QList EsmFileList; + class DataFilesModel : public QAbstractTableModel { Q_OBJECT @@ -39,8 +41,8 @@ namespace EsxModel void uncheckAll(); - QStringList checkedItems(); - QStringList uncheckedItems(); + EsmFileList checkedItems(); + EsmFileList uncheckedItems(); QStringList checkedItemsPaths(); Qt::CheckState checkState(const QModelIndex &index); @@ -51,13 +53,13 @@ namespace EsxModel EsmFile* item(int row) const; signals: - void checkedItemsChanged(const QStringList &items); + void checkedItemsChanged(const EsmFileList &items); private: bool canBeChecked(EsmFile *file) const; void addFile(EsmFile *file); - QList mFiles; + EsmFileList mFiles; QHash mCheckStates; QString mEncoding; diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index 266fd76dc..0b4780241 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -77,6 +77,7 @@ 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); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 6235f31af..ecc70dfcb 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -27,7 +27,7 @@ - 9 + 3 6 @@ -115,7 +115,7 @@ 6 - 9 + 3 9 From 24e38846da6f96b79f722cdad989672dcbb99c21 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Tue, 20 Aug 2013 03:53:23 -0500 Subject: [PATCH 20/42] Fixed broken profile actions --- apps/launcher/datafilespage.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 15f8d9ba2..6f8d1dfac 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -29,6 +29,8 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , mLauncherSettings(launcherSettings) , ContentSelector(parent) { + QMetaObject::connectSlotsByName(this); + // Create a dialog for the new profile name input mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this); @@ -40,10 +42,13 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam void DataFilesPage::createActions() { - + qDebug () << "adding actions..."; // Add the actions to the toolbuttons newProfileButton->setDefaultAction(newProfileAction); deleteProfileButton->setDefaultAction(deleteProfileAction); + + for (int i = 0; i < newProfileButton->actions().size(); i++) + qDebug() << newProfileButton->actions().at(i)->objectName(); } void DataFilesPage::setupDataFiles() @@ -186,6 +191,7 @@ int DataFilesPage::profilesComboBoxIndex() void DataFilesPage::on_newProfileAction_triggered() { + qDebug() << "new_profile_action_triggered"; if (mNewProfileDialog->exec() == QDialog::Accepted) { QString profile = mNewProfileDialog->lineEdit()->text(); profilesComboBox->addItem(profile); From 6898321676e0841cd2dbc70bf93b57748199d924 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Tue, 20 Aug 2013 08:16:56 -0500 Subject: [PATCH 21/42] Reenabling features Profile functions enabled New/load file functions partially enabled Layout reorganized --- apps/launcher/datafilespage.cpp | 4 +- apps/opencs/view/doc/filedialog.cpp | 67 +++++------------------- apps/opencs/view/doc/filedialog.hpp | 11 ---- components/esxselector/view/lineedit.cpp | 1 + components/esxselector/view/lineedit.hpp | 2 + files/ui/datafilespage.ui | 53 +++++++++++++++---- 6 files changed, 60 insertions(+), 78 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 6f8d1dfac..d51952b11 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -31,6 +31,8 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam { QMetaObject::connectSlotsByName(this); + projectGroupBox->hide(); + // Create a dialog for the new profile name input mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this); @@ -42,7 +44,6 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam void DataFilesPage::createActions() { - qDebug () << "adding actions..."; // Add the actions to the toolbuttons newProfileButton->setDefaultAction(newProfileAction); deleteProfileButton->setDefaultAction(deleteProfileAction); @@ -191,7 +192,6 @@ int DataFilesPage::profilesComboBoxIndex() void DataFilesPage::on_newProfileAction_triggered() { - qDebug() << "new_profile_action_triggered"; if (mNewProfileDialog->exec() == QDialog::Accepted) { QString profile = mNewProfileDialog->lineEdit()->text(); profilesComboBox->addItem(profile); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 69ed1c13a..a0360cc5e 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -25,42 +25,20 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : profileGroupBox->hide(); pluginView->showColumn(2); - // Add some extra widgets - QHBoxLayout *nameLayout = new QHBoxLayout(); - QSpacerItem *spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - mNameLabel = new QLabel(tr("File Name:"), this); - - QRegExpValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9\\s]*$")); - mNameLineEdit = new EsxView::LineEdit(this); - mNameLineEdit->setValidator(validator); - - nameLayout->addSpacerItem(spacer); - nameLayout->addWidget(mNameLabel); - nameLayout->addWidget(mNameLineEdit); - - mButtonBox = new QDialogButtonBox(this); - - mCreateButton = new QPushButton(tr("Create"), this); - mCreateButton->setEnabled(false); - - verticalLayout->addLayout(nameLayout); - verticalLayout->addWidget(mButtonBox); - resize(400, 400); // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); //connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); - // connect(mCreateButton, SIGNAL(clicked()), this, SLOT(createButtonClicked())); + connect(projectCreateButton, SIGNAL(clicked()), this, SIGNAL(createNewFile())); - // connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept())); - // connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(mButtonBox, SIGNAL(accepted()), this, SIGNAL(openFiles()); + // connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject())); } void CSVDoc::FileDialog::updateOpenButton(const QStringList &items) { - QPushButton *openButton = mButtonBox->button(QDialogButtonBox::Open); + QPushButton *openButton = projectButtonBox->button(QDialogButtonBox::Open); if (!openButton) return; @@ -70,29 +48,25 @@ void CSVDoc::FileDialog::updateOpenButton(const QStringList &items) void CSVDoc::FileDialog::updateCreateButton(const QString &name) { - if (!mCreateButton->isVisible()) + if (!projectCreateButton->isVisible()) return; - mCreateButton->setEnabled(!name.isEmpty()); + projectCreateButton->setEnabled(!name.isEmpty()); } QString CSVDoc::FileDialog::fileName() { - return mNameLineEdit->text(); + return projectNameLineEdit->text(); } void CSVDoc::FileDialog::openFile() { setWindowTitle(tr("Open")); - mNameLabel->hide(); - mNameLineEdit->hide(); - mCreateButton->hide(); - - mButtonBox->removeButton(mCreateButton); - mButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Open); - QPushButton *openButton = mButtonBox->button(QDialogButtonBox::Open); - openButton->setEnabled(false); + projectNameLineEdit->hide(); + projectCreateButton->hide(); + projectGroupBox->setTitle(tr("")); + projectButtonBox->button(QDialogButtonBox::Open)->setEnabled(false); show(); raise(); @@ -103,25 +77,10 @@ void CSVDoc::FileDialog::newFile() { setWindowTitle(tr("New")); - mNameLabel->show(); - mNameLineEdit->clear(); - mNameLineEdit->show(); - mCreateButton->show(); - - mButtonBox->setStandardButtons(QDialogButtonBox::Cancel); - mButtonBox->addButton(mCreateButton, QDialogButtonBox::ActionRole); + projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel); + projectButtonBox->addButton(projectCreateButton, QDialogButtonBox::ActionRole); show(); raise(); activateWindow(); } - -void CSVDoc::FileDialog::accept() -{ - emit openFiles(); -} - -void CSVDoc::FileDialog::createButtonClicked() -{ - emit createNewFile(); -} diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 0e2d8f32b..c749099d4 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -34,7 +34,6 @@ namespace CSVDoc void openFile(); void newFile(); - void accepted(); QString fileName(); @@ -43,21 +42,11 @@ namespace CSVDoc void createNewFile(); public slots: - void accept(); private slots: //void updateViews(); void updateOpenButton(const QStringList &items); void updateCreateButton(const QString &name); - - void createButtonClicked(); - - private: - QLabel *mNameLabel; - EsxView::LineEdit *mNameLineEdit; - - QPushButton *mCreateButton; - QDialogButtonBox *mButtonBox; }; } #endif // FILEDIALOG_HPP diff --git a/components/esxselector/view/lineedit.cpp b/components/esxselector/view/lineedit.cpp index 8944251ae..48be2f022 100644 --- a/components/esxselector/view/lineedit.cpp +++ b/components/esxselector/view/lineedit.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "lineedit.hpp" diff --git a/components/esxselector/view/lineedit.hpp b/components/esxselector/view/lineedit.hpp index e48392ba8..4e0cbe339 100644 --- a/components/esxselector/view/lineedit.hpp +++ b/components/esxselector/view/lineedit.hpp @@ -20,6 +20,8 @@ namespace EsxView { Q_OBJECT + QString mPlaceholderText; + public: LineEdit(QWidget *parent = 0); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index ecc70dfcb..60e8b8bf5 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -14,12 +14,6 @@ Qt::DefaultContextMenu - - 6 - - - 6 - @@ -91,21 +85,53 @@
- pluginView - masterView - pluginView - masterView
+ + + + Project + + + + + + Enter project name... + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Open + + + + + + + false + + + Create + + + + + projectButtonBox + projectCreateButton + projectNameLineEdit + + Qt::NoFocus - Profiles + Profile false @@ -221,6 +247,11 @@ QComboBox
components/esxselector/view/profilescombobox.hpp
+ + EsxView::LineEdit + QLineEdit +
components/esxselector/view/lineedit.hpp
+
From e6fdc7e7fdce784b2e540022087cc90b35a0bbc4 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Tue, 20 Aug 2013 12:34:39 -0500 Subject: [PATCH 22/42] ... --- apps/launcher/datafilespage.cpp | 3 --- apps/opencs/view/doc/filedialog.cpp | 8 ++++---- components/esxselector/view/contentselector.cpp | 2 +- components/esxselector/view/contentselector.hpp | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index d51952b11..070f455e4 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -47,9 +47,6 @@ void DataFilesPage::createActions() // Add the actions to the toolbuttons newProfileButton->setDefaultAction(newProfileAction); deleteProfileButton->setDefaultAction(deleteProfileAction); - - for (int i = 0; i < newProfileButton->actions().size(); i++) - qDebug() << newProfileButton->actions().at(i)->objectName(); } void DataFilesPage::setupDataFiles() diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index a0360cc5e..561f7f5d7 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -27,13 +27,13 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : resize(400, 400); - // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); - //connect(mNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); + connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); + connect(projectNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); connect(projectCreateButton, SIGNAL(clicked()), this, SIGNAL(createNewFile())); - connect(mButtonBox, SIGNAL(accepted()), this, SIGNAL(openFiles()); - // connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(projectButtonBox, SIGNAL(accepted()), this, SIGNAL(openFiles())); + connect(projectButtonBox, SIGNAL(rejected()), this, SLOT(reject())); } void CSVDoc::FileDialog::updateOpenButton(const QStringList &items) diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index 0b4780241..6cba643d2 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -11,7 +11,7 @@ #include EsxView::ContentSelector::ContentSelector(QWidget *parent) : - QWidget(parent) + QDialog(parent) { setupUi(this); buildModelsAndViews(); diff --git a/components/esxselector/view/contentselector.hpp b/components/esxselector/view/contentselector.hpp index 35ef3a07c..658e0176c 100644 --- a/components/esxselector/view/contentselector.hpp +++ b/components/esxselector/view/contentselector.hpp @@ -1,7 +1,7 @@ #ifndef CONTENTSELECTOR_HPP #define CONTENTSELECTOR_HPP -#include +#include #include "ui_datafilespage.h" @@ -16,7 +16,7 @@ class QSortFilterProxyModel; namespace EsxView { - class ContentSelector : public QWidget, protected Ui::DataFilesPage + class ContentSelector : public QDialog, protected Ui::DataFilesPage { Q_OBJECT From eef9df504a4f3c9a6254421ec5f2363861d40dc6 Mon Sep 17 00:00:00 2001 From: mckibbenta Date: Thu, 29 Aug 2013 20:25:36 -0400 Subject: [PATCH 23/42] fiddlings --- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwscript/miscextensions.cpp | 3 +-- apps/openmw/mwworld/worldimp.cpp | 9 +++++++-- apps/openmw/mwworld/worldimp.hpp | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index b8d0a8745..a6db0a909 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -272,7 +272,7 @@ namespace MWMechanics // workaround: always keep player alive for now // \todo remove workaround, once player death can be handled - if(iter->first.getRefData().getHandle()=="player") + if(iter->first.getRefData().getHandle()=="player" && false) { MWMechanics::DynamicStat stat(stats.getHealth()); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index c53cafa17..a8d8a5f2b 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -726,8 +726,7 @@ namespace MWScript bool enabled = MWBase::Environment::get().getWorld()->toggleGodMode(); - // context.report (enabled ? "God Mode -> On" : "God Mode -> Off"); - context.report("Unimplemented"); + context.report (enabled ? "God Mode -> On" : "God Mode -> Off"); } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5c08af612..a6489fc30 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -170,7 +170,7 @@ namespace MWWorld mSky (true), mCells (mStore, mEsm), mActivationDistanceOverride (mActivationDistanceOverride), mFallback(fallbackMap), mPlayIntro(0), mTeleportEnabled(true), - mFacedDistance(FLT_MAX) + mFacedDistance(FLT_MAX), mGodMode(false) { mPhysics = new PhysicsSystem(renderer); mPhysEngine = mPhysics->getEngine(); @@ -1945,7 +1945,12 @@ namespace MWWorld bool World::toggleGodMode() { - return false; + if (mGodMode) + mGodMode = false; + else + mGodMode = true; + + return mGodMode; } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 30ffcda40..5e6fe50f9 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -68,6 +68,8 @@ namespace MWWorld OEngine::Physic::PhysicEngine* mPhysEngine; + bool mGodMode; + // not implemented World (const World&); World& operator= (const World&); From a6e7cf9a8c795ffebd6c45e72f80b4650f1bbd7b Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 7 Sep 2013 15:57:40 -0500 Subject: [PATCH 24/42] Implementing drag and drop --- apps/opencs/view/doc/filedialog.cpp | 2 +- components/CMakeLists.txt | 3 +- components/esxselector/model/contentmodel.cpp | 428 ++++++++++++++++++ components/esxselector/model/contentmodel.hpp | 64 +++ .../esxselector/model/datafilesmodel.cpp | 216 ++++++--- .../esxselector/model/datafilesmodel.hpp | 25 +- components/esxselector/model/esmfile.cpp | 16 +- components/esxselector/model/esmfile.hpp | 5 + .../esxselector/model/masterproxymodel.cpp | 34 +- .../esxselector/model/masterproxymodel.hpp | 6 +- components/esxselector/model/modelitem.cpp | 16 +- components/esxselector/model/modelitem.hpp | 10 +- .../esxselector/model/pluginsproxymodel.cpp | 21 +- .../esxselector/model/pluginsproxymodel.hpp | 6 +- components/esxselector/model/sourcemodel.cpp | 6 + components/esxselector/model/sourcemodel.h | 18 + .../esxselector/view/contentselector.cpp | 58 ++- .../esxselector/view/contentselector.hpp | 3 + files/ui/datafilespage.ui | 63 ++- 19 files changed, 887 insertions(+), 113 deletions(-) create mode 100644 components/esxselector/model/contentmodel.cpp create mode 100644 components/esxselector/model/contentmodel.hpp create mode 100644 components/esxselector/model/sourcemodel.cpp create mode 100644 components/esxselector/model/sourcemodel.h diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 561f7f5d7..fb031fe5f 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -27,7 +27,7 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : resize(400, 400); - connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); + // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); connect(projectNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); connect(projectCreateButton, SIGNAL(clicked()), this, SIGNAL(createNewFile())); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 8b07a4e00..0f7c5017b 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -1,5 +1,5 @@ project (Components) - +set (CMAKE_BUILD_TYPE DEBUG) # source files add_component_dir (settings @@ -74,6 +74,7 @@ if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) add_component_qt_dir (esxselector model/masterproxymodel model/modelitem model/datafilesmodel model/pluginsproxymodel model/esmfile model/naturalsort + model/contentmodel view/profilescombobox view/comboboxlineedit view/lineedit view/contentselector ) diff --git a/components/esxselector/model/contentmodel.cpp b/components/esxselector/model/contentmodel.cpp new file mode 100644 index 000000000..673665775 --- /dev/null +++ b/components/esxselector/model/contentmodel.cpp @@ -0,0 +1,428 @@ +#include "contentmodel.hpp" +#include "esmfile.hpp" +#include +#include +#include +#include + +EsxModel::ContentModel::ContentModel(QObject *parent) : + QAbstractTableModel(parent), mEncoding("win1252") +{} + +void EsxModel::ContentModel::setEncoding(const QString &encoding) +{ + mEncoding = encoding; +} + +int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return 1; +} +/* +QModelIndex EsxModel::ContentModel::parent(const QModelIndex &child) const +{ + if(!child.isValid()) + return 0; + + return child.parent(); +} + +QModelIndex EsxModel::ContentModel::index(int row, int column, const QModelIndex &parent) const +{ + +} +*/ +int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const +{ + if(parent.isValid()) + return 0; + + return mFiles.size(); +} + +QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= mFiles.size()) + return QVariant(); + + EsmFile *file = item(index.row()); + + if (!file) + return QVariant(); + + const int column = index.column(); + + switch (role) + { + case Qt::EditRole: + case Qt::DisplayRole: + { + switch (column) + { + case 0: + return file->fileName(); + case 1: + return file->author(); + case 2: + return QString("%1 kB").arg(int((file->size() + 1023) / 1024)); + case 3: + return file->modified().toString(Qt::ISODate); + case 4: + return file->accessed().toString(Qt::TextDate); + case 5: + return file->version(); + case 6: + return file->path(); + case 7: + return file->masters().join(", "); + case 8: + return file->description(); + } + + return QVariant(); + } + + case Qt::TextAlignmentRole: + { + switch (column) + { + case 0: + case 1: + return Qt::AlignLeft + Qt::AlignVCenter; + case 2: + case 3: + case 4: + case 5: + return Qt::AlignRight + Qt::AlignVCenter; + default: + return Qt::AlignLeft + Qt::AlignVCenter; + } + return QVariant(); + } + + case Qt::ToolTipRole: + { + if (column != 0) + return QVariant(); + + if (file->version() == 0.0f) + return QVariant(); // Data not set + + return QString("Author: %1
\ + Version: %2
\ +
Description:
%3
\ +
Dependencies: %4
") + .arg(file->author()) + .arg(QString::number(file->version())) + .arg(file->description()) + .arg(file->masters().join(", ")); + } + + case Qt::UserRole: + { + if (file->masters().size() == 0) + return "game"; + else + return "addon"; + } + + default: + return QVariant(); + } +} + +Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + EsmFile *file = item(index.row()); + + if (!file) + return Qt::NoItemFlags; + + Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable; + Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; + + if (canBeChecked(file)) + return Qt::ItemIsEnabled | dragDropFlags | checkFlags | defaultFlags; + else + return defaultFlags; +} + +bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (index.isValid() && role == Qt::EditRole) + { + QString fname = value.value(); + mFiles.replace(index.row(), findItem(fname)); + emit dataChanged(index, index); + return true; + } + + return false; +} + +bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent) +{ + beginInsertRows(parent, position, position+rows-1); + + for (int row = 0; row < rows; ++row) + mFiles.insert(position, new EsmFile); + + endInsertRows(); + return true; +} + +bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelIndex &parent) +{ + beginRemoveRows(parent, position, position+rows-1); + + for (int row = 0; row < rows; ++row) + mFiles.removeAt(position); + + endRemoveRows(); + emit dataChanged(index(0,0,parent), index(rowCount()-1, 0, parent)); + return true; +} + +Qt::DropActions EsxModel::ContentModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction; +} + +QStringList EsxModel::ContentModel::mimeTypes() const +{ + QStringList types; + types << "application/omwcontent"; + return types; +} + +QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) const +{ + QMimeData *mimeData = new QMimeData(); + QByteArray encodedData; + + QDataStream stream(&encodedData, QIODevice::WriteOnly); + + foreach (const QModelIndex &index, indexes) + { + if (index.isValid()) + { + QString text = data(index, Qt::DisplayRole).toString(); + stream << text; + } + } + + mimeData->setData("application/omwcontent", encodedData); + return mimeData; +} + +bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if (action == Qt::IgnoreAction) + return true; + + if (!data->hasFormat("application/omwcontent")) + return false; + + if (column > 0) + return false; + + int beginRow; + + if (row != -1) + beginRow = row; + else if (parent.isValid()) + beginRow = parent.row(); + else + beginRow = rowCount(); + + QByteArray encodedData = data->data("application/omwcontent"); + QDataStream stream(&encodedData, QIODevice::ReadOnly); + QStringList newItems; + int rows = 0; + + while (!stream.atEnd()) + { + QString text; + stream >> text; + newItems << text; + ++rows; + } + + insertRows(beginRow, rows, QModelIndex()); + + foreach (const QString &text, newItems) + { + QModelIndex idx = index(beginRow, 0, QModelIndex()); + setData(idx, text); + beginRow++; + } + + return true; +} + +void EsxModel::ContentModel::addFile(EsmFile *file) +{ + emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); + mFiles.append(file); + emit endInsertRows(); +} + +void EsxModel::ContentModel::addFiles(const QString &path) +{ + QDir dir(path); + QStringList filters; + filters << "*.esp" << "*.esm" << "*.omwgame" << "*.omwaddon"; + dir.setNameFilters(filters); + + // Create a decoder for non-latin characters in esx metadata + QTextCodec *codec; + + if (mEncoding == QLatin1String("win1252")) { + codec = QTextCodec::codecForName("windows-1252"); + } else if (mEncoding == QLatin1String("win1251")) { + codec = QTextCodec::codecForName("windows-1251"); + } else if (mEncoding == QLatin1String("win1250")) { + codec = QTextCodec::codecForName("windows-1250"); + } else { + return; // This should never happen; + } + + QTextDecoder *decoder = codec->makeDecoder(); + + foreach (const QString &path, dir.entryList()) { + QFileInfo info(dir.absoluteFilePath(path)); + EsmFile *file = new EsmFile(path); + + try { + ESM::ESMReader fileReader; + ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(mEncoding.toStdString())); + fileReader.setEncoder(&encoder); + fileReader.open(dir.absoluteFilePath(path).toStdString()); + + std::vector mlist = fileReader.getMasters(); + + QStringList masters; + + for (unsigned int i = 0; i < mlist.size(); ++i) { + QString master = QString::fromStdString(mlist[i].name); + masters.append(master); + } + + file->setAuthor(decoder->toUnicode(fileReader.getAuthor().c_str())); + file->setSize(info.size()); + file->setDates(info.lastModified(), info.lastRead()); + file->setVersion(fileReader.getFVer()); + file->setPath(info.absoluteFilePath()); + file->setMasters(masters); + file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str())); + + + // 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 addon file: " << e.what(); + continue; + } + + } + + delete decoder; +} + +EsxModel::EsmFile* EsxModel::ContentModel::findItem(const QString &name) +{ + for (int i = 0; i < mFiles.size(); ++i) + { + if (name == item(i)->fileName()) + return item(i); + } + + // Not found + return 0; +} + +EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const +{ + if (row >= 0 && row < mFiles.count()) + return mFiles.at(row); + + return 0; +} + +QModelIndex EsxModel::ContentModel::indexFromItem(EsmFile *item) const +{ + if (item) + //return createIndex(mFiles.indexOf(item), 0); + return index(mFiles.indexOf(item),0); + + return QModelIndex(); +} + +Qt::CheckState EsxModel::ContentModel::checkState(const QModelIndex &index) +{ + return mCheckStates[item(index.row())->fileName()]; +} + +void EsxModel::ContentModel::setCheckState(const QModelIndex &index, Qt::CheckState state) +{ + if (!index.isValid()) + return; + + QString name = item(index.row())->fileName(); + mCheckStates[name] = state; + + // Force a redraw of the view since unchecking one item can affect another + QModelIndex firstIndex = indexFromItem(mFiles.first()); + QModelIndex lastIndex = indexFromItem(mFiles.last()); + + emit dataChanged(firstIndex, lastIndex); + //emit checkedItemsChanged(checkedItems()); + +} + +bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const +{ + //element can be checked if all its dependencies are + foreach (const QString &master, file->masters()) + { + if (!mCheckStates.contains(master) || mCheckStates[master] != Qt::Checked) + return false; + } + return true; +} + +EsxModel::ContentFileList EsxModel::ContentModel::checkedItems() const +{ + ContentFileList list; + + for (int i = 0; i < mFiles.size(); ++i) + { + EsmFile *file = item(i); + + // Only add the items that are in the checked list and available + if (mCheckStates[file->fileName()] == Qt::Checked && canBeChecked(file)) + list << file; + } + + return list; +} + +void EsxModel::ContentModel::uncheckAll() +{ + emit layoutAboutToBeChanged(); + mCheckStates.clear(); + emit layoutChanged(); +} diff --git a/components/esxselector/model/contentmodel.hpp b/components/esxselector/model/contentmodel.hpp new file mode 100644 index 000000000..a585ab63b --- /dev/null +++ b/components/esxselector/model/contentmodel.hpp @@ -0,0 +1,64 @@ +#ifndef CONTENTMODEL_HPP +#define CONTENTMODEL_HPP + +#include + +namespace EsxModel +{ + class EsmFile; + + typedef QList ContentFileList; + + class ContentModel : public QAbstractTableModel + { + Q_OBJECT + public: + explicit ContentModel(QObject *parent = 0); + + void setEncoding(const QString &encoding); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); + + Qt::DropActions supportedDropActions() const; + QStringList mimeTypes() const; + QMimeData *mimeData(const QModelIndexList &indexes) const; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + + void addFiles(const QString &path); + + QModelIndex indexFromItem(EsmFile *item) const; + EsxModel::EsmFile *findItem(const QString &name); + + Qt::CheckState checkState(const QModelIndex &index); + void setCheckState(const QModelIndex &index, Qt::CheckState state); + ContentFileList checkedItems() const; + void uncheckAll(); +/* + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &child) const; +*/ + private: + + void addFile(EsmFile *file); + EsmFile* item(int row) const; + bool canBeChecked(const EsmFile *file) const; + + ContentFileList mFiles; + QHash mCheckStates; + QString mEncoding; + + signals: + + public slots: + + }; +} +#endif // CONTENTMODEL_HPP diff --git a/components/esxselector/model/datafilesmodel.cpp b/components/esxselector/model/datafilesmodel.cpp index 49d0d6132..ee940bb27 100644 --- a/components/esxselector/model/datafilesmodel.cpp +++ b/components/esxselector/model/datafilesmodel.cpp @@ -48,13 +48,12 @@ void EsxModel::DataFilesModel::setCheckState(const QModelIndex &index, Qt::Check Qt::CheckState EsxModel::DataFilesModel::checkState(const QModelIndex &index) { - EsmFile *file = item(index.row()); - return mCheckStates[file->fileName()]; + return mCheckStates[item(index.row())->fileName()]; } int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const { - return parent.isValid() ? 0 : 9; + return parent.isValid() ? 0 : 1; } int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const @@ -82,7 +81,7 @@ QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) cons if (!index.isValid()) return QVariant(); - EsmFile *file = item(index.row()); + const EsmFile *file = item(index.row()); if (!file) return QVariant(); @@ -90,6 +89,7 @@ QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) cons const int column = index.column(); switch (role) { + case Qt::EditRole: case Qt::DisplayRole: { switch (column) { @@ -172,25 +172,26 @@ Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const if (!index.isValid()) return Qt::NoItemFlags; - EsmFile *file = item(index.row()); + const EsmFile *file = item(index.row()); + + Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable | Qt::ItemIsSelectable; if (!file) return Qt::NoItemFlags; - if (canBeChecked(file)) { - if (index.column() == 0) { - return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; - } else { - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; - } - } else { - if (index.column() == 0) { - return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable; - } else { - return Qt::ItemIsSelectable; - } + if (canBeChecked(file)) + { + if (index.column() == 0) + return dragDropFlags | checkFlags | Qt::ItemIsEnabled; + else + return Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable; } + if (index.column() == 0) + return dragDropFlags | checkFlags; + + return Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; } QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -210,22 +211,27 @@ QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orien case 7: return tr("Masters"); case 8: return tr("Description"); } - } /* else { - // Show row numbers - return ++section; } -*/ return QVariant(); } bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid()) - return false; + return false; + + if (role == Qt::EditRole) + { + qDebug() << "replacing: " << mFiles.at(index.row())->fileName(); +// mFiles.replace(index.row(), value.value()); + qDebug() << "with: " << mFiles.at(index.row())->fileName(); + emit dataChanged(index, index); + return true; + } return false; } - +//!!!!!!!!!!!!!!!!!!!!!!! bool lessThanEsmFile(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) { //Masters first then alphabetically @@ -236,16 +242,15 @@ bool lessThanEsmFile(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) return e1->fileName().toLower() < e2->fileName().toLower(); } - +//!!!!!!!!!!!!!!!!!!!!!!! bool lessThanDate(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) { - if (e1->modified().toString(Qt::ISODate) < e2->modified().toString(Qt::ISODate)) { + if (e1->modified().toString(Qt::ISODate) < e2->modified().toString(Qt::ISODate)) return true; - } else { + else return false; - } } - +//!!!!!!!!!!!!!!!!!!!!!!! void EsxModel::DataFilesModel::sort(int column, Qt::SortOrder order) { emit layoutAboutToBeChanged(); @@ -259,7 +264,7 @@ void EsxModel::DataFilesModel::sort(int column, Qt::SortOrder order) emit layoutChanged(); } -void EsxModel::DataFilesModel::addFile(EsmFile *file) +void EsxModel::DataFilesModel::addFile(const EsmFile *file) { emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); mFiles.append(file); @@ -331,22 +336,23 @@ void EsxModel::DataFilesModel::addFiles(const QString &path) delete decoder; } -QModelIndex EsxModel::DataFilesModel::indexFromItem(EsmFile *item) const +QModelIndex EsxModel::DataFilesModel::indexFromItem(const EsmFile *item) const { if (item) - return createIndex(mFiles.indexOf(item), 0); + //return createIndex(mFiles.indexOf(item), 0); + return index(mFiles.indexOf(item),0); return QModelIndex(); } -EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) +const EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) { - QList::ConstIterator it; - QList::ConstIterator itEnd = mFiles.constEnd(); + EsmFileList::ConstIterator it; + EsmFileList::ConstIterator itEnd = mFiles.constEnd(); int i = 0; for (it = mFiles.constBegin(); it != itEnd; ++it) { - EsmFile *file = item(i); + const EsmFile *file = item(i); ++i; if (name == file->fileName()) @@ -357,12 +363,12 @@ EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) return 0; } -EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const +const EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const { if (row >= 0 && row < mFiles.count()) return mFiles.at(row); - else - return 0; + + return 0; } EsxModel::EsmFileList EsxModel::DataFilesModel::checkedItems() @@ -372,14 +378,11 @@ EsxModel::EsmFileList EsxModel::DataFilesModel::checkedItems() EsmFileList::ConstIterator it; EsmFileList::ConstIterator itEnd = mFiles.constEnd(); - int i = 0; for (it = mFiles.constBegin(); it != itEnd; ++it) { - EsmFile *file = *it; - // Only add the items that are in the checked list and available - if (mCheckStates[file->fileName()] == Qt::Checked && canBeChecked(file)) - list << file; + if (mCheckStates[(*it)->fileName()] == Qt::Checked && canBeChecked(*it)) + list << (*it); } return list; @@ -389,12 +392,12 @@ QStringList EsxModel::DataFilesModel::checkedItemsPaths() { QStringList list; - QList::ConstIterator it; - QList::ConstIterator itEnd = mFiles.constEnd(); + EsmFileList::ConstIterator it; + EsmFileList::ConstIterator itEnd = mFiles.constEnd(); int i = 0; for (it = mFiles.constBegin(); it != itEnd; ++it) { - EsmFile *file = item(i); + const EsmFile *file = item(i); ++i; if (mCheckStates[file->fileName()] == Qt::Checked && canBeChecked(file)) @@ -403,7 +406,6 @@ QStringList EsxModel::DataFilesModel::checkedItemsPaths() return list; } - void EsxModel::DataFilesModel::uncheckAll() { emit layoutAboutToBeChanged(); @@ -411,18 +413,17 @@ void EsxModel::DataFilesModel::uncheckAll() emit layoutChanged(); } +/* EsxModel::EsmFileList EsxModel::DataFilesModel::uncheckedItems() { EsmFileList list; EsmFileList checked = checkedItems(); EsmFileList::ConstIterator it; - EsmFileList::ConstIterator itEnd = mFiles.constEnd(); - int i = 0; - for (it = mFiles.constBegin(); it != itEnd; ++it) { - EsmFile *file = item(i); - ++i; + for (it = mFiles.constBegin(); it != mFiles.constEnd(); ++it) + { + const EsmFile *file = *it; // Add the items that are not in the checked list if (!checked.contains(file)) @@ -431,8 +432,8 @@ EsxModel::EsmFileList EsxModel::DataFilesModel::uncheckedItems() return list; } - -bool EsxModel::DataFilesModel::canBeChecked(EsmFile *file) const +*/ +bool EsxModel::DataFilesModel::canBeChecked(const EsmFile *file) const { //element can be checked if all its dependencies are foreach (const QString &master, file->masters()) @@ -442,3 +443,110 @@ bool EsxModel::DataFilesModel::canBeChecked(EsmFile *file) const } return true; } + +Qt::DropActions EsxModel::DataFilesModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction; +} + +QStringList EsxModel::DataFilesModel::mimeTypes() const +{ + QStringList types; + types << "application/omwcontent"; + return types; +} + +QMimeData *EsxModel::DataFilesModel::mimeData(const QModelIndexList &indexes) const +{ +// if (indexes.at(0).isValid()) +// return new EsmFile(*item(indexes.at(0).row())); + + return 0; +} + +bool EsxModel::DataFilesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if (action == Qt::IgnoreAction) + return true; + + if (action != Qt::MoveAction) + return false; + + if (!data->hasFormat("application/omwcontent")) + return false; + + int dropRow = row; + + if (dropRow == -1) + { + if (parent.isValid()) + dropRow = parent.row(); + else + dropRow = rowCount(QModelIndex()); + } + + if (parent.isValid()) + qDebug() << "parent: " << parent.data().toString(); + qDebug() << "dragged file: " << (qobject_cast(data))->fileName(); +// qDebug() << "inserting file: " << droppedfile->fileName() << " ahead of " << file->fileName(); + insertRows (dropRow, 1, QModelIndex()); + + + const EsmFile *draggedFile = qobject_cast(data); + + int dragRow = -1; + + for (int i = 0; i < mFiles.size(); ++i) + if (draggedFile->fileName() == mFiles.at(i)->fileName()) + { + dragRow = i; + break; + } + + for (int i = 0; i < mFiles.count(); ++i) + { + qDebug() << "index: " << i << "file: " << item(i)->fileName(); + qDebug() << mFiles.at(i)->fileName(); + } + + qDebug() << "drop row: " << dropRow << "; drag row: " << dragRow; +// const EsmFile *file = qobject_cast(data); + // int index = mFiles.indexOf(file); + //qDebug() << "file name: " << file->fileName() << "; index: " << index; + mFiles.swap(dropRow, dragRow); + //setData(index(startRow, 0), varFile); + emit dataChanged(index(0,0), index(rowCount(),0)); + return true; +} + +bool EsxModel::DataFilesModel::insertRows(int row, int count, const QModelIndex &parent) +{ + qDebug() << "inserting row: " << row << " count: " << count; + beginInsertRows(QModelIndex(),row, row+count-1); + + EsmFile *file = new EsmFile(); + + for (int i = 0; i < count; ++i) + mFiles.insert(row + i, file); + + endInsertRows(); + return true; +} + +bool EsxModel::DataFilesModel::removeRows(int row, int count, const QModelIndex &parent) +{ + qDebug() << "removing row: " << row << " count: " << count; + beginRemoveRows(QModelIndex(), row, row+count-1); + + for (int i = 0; i < count; ++i) + { + mFiles.removeAt(i); + } + + endRemoveRows(); + qDebug() <<"remove success"; + + emit dataChanged(parent, index(rowCount()-1, 0, parent)); + return true; +} + diff --git a/components/esxselector/model/datafilesmodel.hpp b/components/esxselector/model/datafilesmodel.hpp index 24b36aa88..4f23cd530 100644 --- a/components/esxselector/model/datafilesmodel.hpp +++ b/components/esxselector/model/datafilesmodel.hpp @@ -10,7 +10,7 @@ namespace EsxModel { class EsmFile; - typedef QList EsmFileList; + typedef QList EsmFileList; class DataFilesModel : public QAbstractTableModel { @@ -21,6 +21,8 @@ namespace EsxModel virtual ~DataFilesModel(); virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool removeRows(int row, int count, const QModelIndex &parent); + bool insertRows(int row, int count, const QModelIndex &parent); bool moveRow(int oldrow, int row, const QModelIndex &parent = QModelIndex()); @@ -33,7 +35,10 @@ namespace EsxModel void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const - { return QAbstractTableModel::index(row, column, parent); } + { + QModelIndex idx = QAbstractTableModel::index(row, 0, parent); + return idx; + } void setEncoding(const QString &encoding); @@ -41,6 +46,11 @@ namespace EsxModel void uncheckAll(); + Qt::DropActions supportedDropActions() const; + QStringList mimeTypes() const; + QMimeData *mimeData(const QModelIndexList &indexes) const; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + EsmFileList checkedItems(); EsmFileList uncheckedItems(); QStringList checkedItemsPaths(); @@ -48,16 +58,17 @@ namespace EsxModel Qt::CheckState checkState(const QModelIndex &index); void setCheckState(const QModelIndex &index, Qt::CheckState state); - QModelIndex indexFromItem(EsmFile *item) const; - EsmFile* findItem(const QString &name); - EsmFile* item(int row) const; + QModelIndex indexFromItem(const EsmFile *item) const; + const EsmFile* findItem(const QString &name); + const EsmFile* item(int row) const; signals: void checkedItemsChanged(const EsmFileList &items); private: - bool canBeChecked(EsmFile *file) const; - void addFile(EsmFile *file); + + bool canBeChecked(const EsmFile *file) const; + void addFile(const EsmFile *file); EsmFileList mFiles; QHash mCheckStates; diff --git a/components/esxselector/model/esmfile.cpp b/components/esxselector/model/esmfile.cpp index 96b90e44e..95cf70312 100644 --- a/components/esxselector/model/esmfile.cpp +++ b/components/esxselector/model/esmfile.cpp @@ -1,13 +1,17 @@ #include "esmfile.hpp" EsxModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) - : ModelItem(parent) -{ - mFileName = fileName; - mSize = 0; - mVersion = 0.0f; -} + : ModelItem(parent), mFileName(fileName), mSize(0), mVersion(0.0f) +{} +/* +EsxModel::EsmFile::EsmFile(const EsmFile &file) + : ModelItem(file.parent()), mFileName(file.mFileName), mSize(file.mSize), + mVersion(file.mVersion), mAuthor(file.mAuthor), mModified(file.mModified), + mAccessed(file.mAccessed), mPath(file.mPath), mMasters(file.mMasters), + mDescription(file.mDescription) +{} +*/ void EsxModel::EsmFile::setFileName(const QString &fileName) { mFileName = fileName; diff --git a/components/esxselector/model/esmfile.hpp b/components/esxselector/model/esmfile.hpp index 6a3e36b53..0cda018b3 100644 --- a/components/esxselector/model/esmfile.hpp +++ b/components/esxselector/model/esmfile.hpp @@ -14,7 +14,9 @@ namespace EsxModel Q_PROPERTY(QString filename READ fileName) public: + EsmFile(QString fileName = QString(), ModelItem *parent = 0); + // EsmFile(const EsmFile &); ~EsmFile() {} @@ -38,6 +40,7 @@ namespace EsxModel inline QStringList masters() const { return mMasters; } inline QString description() const { return mDescription; } + //inline ModelItem *parent() const { return ModelItem::parent(); this->} private: QString mFileName; @@ -53,4 +56,6 @@ namespace EsxModel }; } +Q_DECLARE_METATYPE (EsxModel::EsmFile *) + #endif diff --git a/components/esxselector/model/masterproxymodel.cpp b/components/esxselector/model/masterproxymodel.cpp index 011e5ebd5..46d68ca51 100644 --- a/components/esxselector/model/masterproxymodel.cpp +++ b/components/esxselector/model/masterproxymodel.cpp @@ -1,4 +1,6 @@ #include "masterproxymodel.hpp" +#include +#include EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : QSortFilterProxyModel(parent) @@ -7,10 +9,36 @@ EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableMode setFilterRole (Qt::UserRole); if (model) - setSourceModel (model); + setSourceModel (model); + //connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotSourceModelChanged(QModelIndex, QModelIndex))); } - +/* QVariant EsxModel::MasterProxyModel::data(const QModelIndex &index, int role) const { - return QSortFilterProxyModel::data (index, role); + if (index.isValid()) + return QSortFilterProxyModel::data (index, role); + + return 0; +} +*/ +void EsxModel::MasterProxyModel::slotSourceModelChanged(QModelIndex topLeft, QModelIndex botRight) +{ + qDebug() << "source data changed.. updating master proxy"; + emit dataChanged(index(0,0), index(rowCount()-1,0)); + + int curRow = -1; +/* + for (int i = 0; i < rowCount() - 1; ++i) + { + if (index(i,0).data(Qt::CheckState) == Qt::Checked) + { + curRow = i; + break; + } + } + + reset(); +*/ + if (curRow != -1); + // index(curRow, 0).setDataQt::CheckState) } diff --git a/components/esxselector/model/masterproxymodel.hpp b/components/esxselector/model/masterproxymodel.hpp index fed01bdb1..8a5c73032 100644 --- a/components/esxselector/model/masterproxymodel.hpp +++ b/components/esxselector/model/masterproxymodel.hpp @@ -2,6 +2,8 @@ #define MASTERPROXYMODEL_HPP #include +#include +#include class QAbstractTableModel; @@ -12,12 +14,12 @@ namespace EsxModel Q_OBJECT public: explicit MasterProxyModel(QObject *parent = 0, QAbstractTableModel *model = 0); - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + // virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; signals: public slots: - + void slotSourceModelChanged(QModelIndex topLeft, QModelIndex botRight); }; } #endif // MASTERPROXYMODEL_HPP diff --git a/components/esxselector/model/modelitem.cpp b/components/esxselector/model/modelitem.cpp index 8c1e83695..03b19f691 100644 --- a/components/esxselector/model/modelitem.cpp +++ b/components/esxselector/model/modelitem.cpp @@ -2,9 +2,14 @@ EsxModel::ModelItem::ModelItem(ModelItem *parent) : mParentItem(parent) - , QObject(parent) { } +/* +EsxModel::ModelItem::ModelItem(const ModelItem *parent) + // : mParentItem(parent) +{ +} +*/ EsxModel::ModelItem::~ModelItem() { @@ -12,11 +17,18 @@ EsxModel::ModelItem::~ModelItem() } -EsxModel::ModelItem *EsxModel::ModelItem::parent() +EsxModel::ModelItem *EsxModel::ModelItem::parent() const { return mParentItem; } +bool EsxModel::ModelItem::hasFormat(const QString &mimetype) const +{ + if (mimetype == "application/omwcontent") + return true; + + return QMimeData::hasFormat(mimetype); +} int EsxModel::ModelItem::row() const { if (mParentItem) diff --git a/components/esxselector/model/modelitem.hpp b/components/esxselector/model/modelitem.hpp index 64596302c..5ee5e417e 100644 --- a/components/esxselector/model/modelitem.hpp +++ b/components/esxselector/model/modelitem.hpp @@ -1,20 +1,22 @@ #ifndef MODELITEM_HPP #define MODELITEM_HPP -#include +#include #include namespace EsxModel { - class ModelItem : public QObject + class ModelItem : public QMimeData { Q_OBJECT public: ModelItem(ModelItem *parent = 0); + //ModelItem(const ModelItem *parent = 0); + ~ModelItem(); - ModelItem *parent(); + ModelItem *parent() const; int row() const; int childCount() const; @@ -24,6 +26,8 @@ namespace EsxModel void appendChild(ModelItem *child); void removeChild(int row); + bool hasFormat(const QString &mimetype) const; + //virtual bool acceptChild(ModelItem *child); protected: diff --git a/components/esxselector/model/pluginsproxymodel.cpp b/components/esxselector/model/pluginsproxymodel.cpp index 4fde11f47..412367b64 100644 --- a/components/esxselector/model/pluginsproxymodel.cpp +++ b/components/esxselector/model/pluginsproxymodel.cpp @@ -1,7 +1,8 @@ #include "pluginsproxymodel.hpp" -#include "datafilesmodel.hpp" +#include "contentmodel.hpp" +#include -EsxModel::PluginsProxyModel::PluginsProxyModel(QObject *parent, DataFilesModel *model) : +EsxModel::PluginsProxyModel::PluginsProxyModel(QObject *parent, ContentModel *model) : QSortFilterProxyModel(parent) { setFilterRegExp (QString("addon")); @@ -22,12 +23,18 @@ QVariant EsxModel::PluginsProxyModel::data(const QModelIndex &index, int role) c { case Qt::CheckStateRole: { - if (index.column() != 0) + if (index.column() != 0) return QVariant(); - return static_cast(sourceModel())->checkState(mapToSource(index)); + return static_cast(sourceModel())->checkState(mapToSource(index)); } - }; - - return QSortFilterProxyModel::data (index, role); + } + return QSortFilterProxyModel::data(index, role); +} + +bool EsxModel::PluginsProxyModel::removeRows(int position, int rows, const QModelIndex &parent) +{ + bool success = QSortFilterProxyModel::removeRows(position, rows, parent); + + return success; } diff --git a/components/esxselector/model/pluginsproxymodel.hpp b/components/esxselector/model/pluginsproxymodel.hpp index 04c18c2e2..4415df716 100644 --- a/components/esxselector/model/pluginsproxymodel.hpp +++ b/components/esxselector/model/pluginsproxymodel.hpp @@ -8,7 +8,7 @@ class QAbstractTableModel; namespace EsxModel { - class DataFilesModel; + class ContentModel; class PluginsProxyModel : public QSortFilterProxyModel { @@ -16,10 +16,12 @@ namespace EsxModel public: - explicit PluginsProxyModel(QObject *parent = 0, DataFilesModel *model = 0); + explicit PluginsProxyModel(QObject *parent = 0, ContentModel *model = 0); ~PluginsProxyModel(); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + bool removeRows(int row, int count, const QModelIndex &parent); }; } diff --git a/components/esxselector/model/sourcemodel.cpp b/components/esxselector/model/sourcemodel.cpp new file mode 100644 index 000000000..7b54adba9 --- /dev/null +++ b/components/esxselector/model/sourcemodel.cpp @@ -0,0 +1,6 @@ +#include "sourcemodel.h" + +SourceModel::SourceModel(QObject *parent) : + QAbstractTableClass(parent) +{ +} diff --git a/components/esxselector/model/sourcemodel.h b/components/esxselector/model/sourcemodel.h new file mode 100644 index 000000000..cf5145675 --- /dev/null +++ b/components/esxselector/model/sourcemodel.h @@ -0,0 +1,18 @@ +#ifndef SOURCEMODEL_H +#define SOURCEMODEL_H + +#include + +class SourceModel : public QAbstractTableClass +{ + Q_OBJECT +public: + explicit SourceModel(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // SOURCEMODEL_H diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index 6cba643d2..bc7cc2b8b 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -3,6 +3,8 @@ #include "../model/datafilesmodel.hpp" #include "../model/masterproxymodel.hpp" #include "../model/pluginsproxymodel.hpp" +#include "../model/contentmodel.hpp" +#include "../model/esmfile.hpp" #include @@ -14,7 +16,33 @@ EsxView::ContentSelector::ContentSelector(QWidget *parent) : QDialog(parent) { setupUi(this); - buildModelsAndViews(); + // buildModelsAndViews(); + buildDragDropModelView(); +} +void EsxView::ContentSelector::buildDragDropModelView() +{ + mContentModel = new EsxModel::ContentModel(); + + //mContentModel->addFiles("/home/joel/Projects/OpenMW/Data_Files"); + mMasterProxyModel = new EsxModel::MasterProxyModel(this, mContentModel); + mPluginsProxyModel = new EsxModel::PluginsProxyModel(this, mContentModel); + + tableView->setModel (mPluginsProxyModel); + + masterView->setPlaceholderText(QString("Select a game file...")); + masterView->setModel(mMasterProxyModel); + pluginView->setModel(mPluginsProxyModel); + + profilesComboBox->setPlaceholderText(QString("Select a profile...")); + + updateViews(); + connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); + connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); + connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); + + + connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); + connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); } void EsxView::ContentSelector::buildModelsAndViews() @@ -22,15 +50,15 @@ void EsxView::ContentSelector::buildModelsAndViews() // Models mDataFilesModel = new EsxModel::DataFilesModel (this); - mMasterProxyModel = new EsxModel::MasterProxyModel (this, mDataFilesModel); - mPluginsProxyModel = new EsxModel::PluginsProxyModel (this, mDataFilesModel); + // mMasterProxyModel = new EsxModel::MasterProxyModel (this, mDataFilesModel); + // mPluginsProxyModel = new EsxModel::PluginsProxyModel (this, mDataFilesModel); masterView->setPlaceholderText(QString("Select a game file...")); masterView->setModel(mMasterProxyModel); pluginView->setModel(mPluginsProxyModel); profilesComboBox->setPlaceholderText(QString("Select a profile...")); - + updateViews(); connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); @@ -39,15 +67,15 @@ void EsxView::ContentSelector::buildModelsAndViews() void EsxView::ContentSelector::addFiles(const QString &path) { - mDataFilesModel->addFiles(path); - mDataFilesModel->sort(3); // Sort by date accessed + mContentModel->addFiles(path); + mContentModel->sort(3); // Sort by date accessed masterView->setCurrentIndex(-1); - mDataFilesModel->uncheckAll(); + mContentModel->uncheckAll(); } void EsxView::ContentSelector::setEncoding(const QString &encoding) { - mDataFilesModel->setEncoding(encoding); + mContentModel->setEncoding(encoding); } void EsxView::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model) @@ -62,15 +90,20 @@ void EsxView::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxy if (sourceIndex.isValid()) { - (mDataFilesModel->checkState(sourceIndex) == Qt::Checked) - ? mDataFilesModel->setCheckState(sourceIndex, Qt::Unchecked) - : mDataFilesModel->setCheckState(sourceIndex, Qt::Checked); + (mContentModel->checkState(sourceIndex) == Qt::Checked) + ? mContentModel->setCheckState(sourceIndex, Qt::Unchecked) + : mContentModel->setCheckState(sourceIndex, Qt::Checked); } } QStringList EsxView::ContentSelector::checkedItemsPaths() { - return mDataFilesModel->checkedItemsPaths(); + QStringList itemPaths; + + foreach( const EsxModel::EsmFile *file, mContentModel->checkedItems()) + itemPaths << file->path(); + + return itemPaths; } void EsxView::ContentSelector::updateViews() @@ -106,5 +139,6 @@ void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index) void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) { + qDebug() << "setting checkstate in plugin..."; setCheckState(index, mPluginsProxyModel); } diff --git a/components/esxselector/view/contentselector.hpp b/components/esxselector/view/contentselector.hpp index 658e0176c..06cc8f3f0 100644 --- a/components/esxselector/view/contentselector.hpp +++ b/components/esxselector/view/contentselector.hpp @@ -7,6 +7,7 @@ namespace EsxModel { + class ContentModel; class DataFilesModel; class PluginsProxyModel; class MasterProxyModel; @@ -23,6 +24,7 @@ namespace EsxView protected: EsxModel::DataFilesModel *mDataFilesModel; + EsxModel::ContentModel *mContentModel; EsxModel::MasterProxyModel *mMasterProxyModel; EsxModel::PluginsProxyModel *mPluginsProxyModel; @@ -37,6 +39,7 @@ namespace EsxView void setCheckState(QModelIndex index, QSortFilterProxyModel *model); QStringList checkedItemsPaths(); void on_checkAction_triggered(); + void buildDragDropModelView(); signals: void profileChanged(int index); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 60e8b8bf5..76689627b 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -7,28 +7,19 @@ 0 0 518 - 304 + 310
Qt::DefaultContextMenu - + Content - - - 3 - - - 6 - - - 6 - + @@ -41,7 +32,7 @@ - + @@ -56,6 +47,18 @@ QAbstractItemView::NoEditTriggers + + true + + + false + + + QAbstractItemView::DragDrop + + + Qt::MoveAction + true @@ -82,6 +85,40 @@ + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + QAbstractItemView::DragDrop + + + Qt::MoveAction + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + false + + + From 89b7d6121d35ca400fc490326adbf278922a1dfe Mon Sep 17 00:00:00 2001 From: mckibbenta Date: Thu, 12 Sep 2013 08:30:00 -0400 Subject: [PATCH 25/42] Initial toggleGodMod/tgm instruction. Currently only affects player health. --- apps/openmw/mwbase/world.hpp | 2 ++ apps/openmw/mwmechanics/actors.cpp | 4 +--- apps/openmw/mwworld/worldimp.cpp | 10 ++++++---- apps/openmw/mwworld/worldimp.hpp | 2 ++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 6101358de..f8453afed 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -396,6 +396,8 @@ namespace MWBase /// It only applies to the current form the NPC is in. virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) = 0; + virtual bool getGodModeState() = 0; + virtual bool toggleGodMode() = 0; }; } diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index f5caff359..1e41eb740 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -275,9 +275,7 @@ namespace MWMechanics continue; } - // workaround: always keep player alive for now - // \todo remove workaround, once player death can be handled - if(iter->first.getRefData().getHandle()=="player" && false) + if(iter->first.getRefData().getHandle()=="player" && MWBase::Environment::get().getWorld()->getGodModeState()) { MWMechanics::DynamicStat stat(stats.getHealth()); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 2b4b5d225..d262747b9 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1948,12 +1948,14 @@ namespace MWWorld stats.getSkill(ESM::Skill::Acrobatics).setModified(gmst.find("fWerewolfAcrobatics")->getFloat(), 0); } + bool World::getGodModeState() + { + return mGodMode; + } + bool World::toggleGodMode() { - if (mGodMode) - mGodMode = false; - else - mGodMode = true; + mGodMode ? mGodMode = false : mGodMode = true; return mGodMode; } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 5e6fe50f9..53b01f1ab 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -442,6 +442,8 @@ namespace MWWorld virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor); + virtual bool getGodModeState(); + virtual bool toggleGodMode(); }; } From 9637e1641be22db6b77fb5aff0f8068b51106de6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 14 Sep 2013 13:33:49 +0200 Subject: [PATCH 26/42] fix for building with system tinyxml --- CMakeLists.txt | 1 + apps/openmw/CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ec306e5a..625239aa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,6 +167,7 @@ if(USE_SYSTEM_TINYXML) find_library(TINYXML_LIBRARIES tinyxml) find_path(TINYXML_INCLUDE_DIR tinyxml.h) message(STATUS "Found TinyXML: ${TINYXML_LIBRARIES} ${TINYXML_INCLUDE_DIR}") + add_definitions (-DTIXML_USE_STL) if(TINYXML_LIBRARIES AND TINYXML_INCLUDE_DIR) include_directories(${TINYXML_INCLUDE_DIR}) message(STATUS "Using system TinyXML library.") diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index a44fd4b34..b367e2a1e 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -119,6 +119,10 @@ target_link_libraries(openmw components ) +if (USE_SYSTEM_TINYXML) + target_link_libraries(openmw ${TINYXML_LIBRARIES}) +endif() + if (NOT UNIX) target_link_libraries(openmw ${SDL2MAIN_LIBRARY}) endif() From 644f081c604c91e98e0a81d38c3566c1aca04d76 Mon Sep 17 00:00:00 2001 From: mckibbenta Date: Sun, 15 Sep 2013 15:48:32 -0400 Subject: [PATCH 27/42] minor changes --- apps/openmw/mwworld/worldimp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index d262747b9..f3d4c81b7 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1955,7 +1955,7 @@ namespace MWWorld bool World::toggleGodMode() { - mGodMode ? mGodMode = false : mGodMode = true; + mGodMode = !mGodMode; return mGodMode; } From 6bb6ba6372dc3749bd2aee9f2df74e118d199deb Mon Sep 17 00:00:00 2001 From: mckibbenta Date: Sun, 15 Sep 2013 16:12:59 -0400 Subject: [PATCH 28/42] added god mode comment --- apps/openmw/mwmechanics/actors.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 1e41eb740..ca26e88ce 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -275,6 +275,7 @@ namespace MWMechanics continue; } + // If it's the player and God Mode is turned on, keep it alive if(iter->first.getRefData().getHandle()=="player" && MWBase::Environment::get().getWorld()->getGodModeState()) { MWMechanics::DynamicStat stat(stats.getHealth()); From d5ef843f5615c309d784794028179eee6d21cd0d Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Sep 2013 19:22:08 +0200 Subject: [PATCH 29/42] Fix a missing model update --- apps/openmw/mwgui/hud.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index f9d31bdcd..edcd49738 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -250,6 +250,7 @@ namespace MWGui // remove object from the container it was coming from mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount); mDragAndDrop->finish(); + mDragAndDrop->mSourceModel->update(); } else { From 0eb06ada39ca9ca8857325e816b61048348d896c Mon Sep 17 00:00:00 2001 From: graffy76 Date: Wed, 18 Sep 2013 02:36:23 -0500 Subject: [PATCH 30/42] Implemneting drag and drop --- apps/launcher/datafilespage.cpp | 32 +- apps/launcher/datafilespage.hpp | 1 + components/CMakeLists.txt | 2 +- components/esxselector/model/contentmodel.cpp | 343 ++++++---- components/esxselector/model/contentmodel.hpp | 9 +- .../esxselector/model/datafilesmodel.cpp | 612 ++++++++++-------- components/esxselector/model/esmfile.cpp | 64 +- components/esxselector/model/esmfile.hpp | 28 +- .../esxselector/model/masterproxymodel.cpp | 31 - .../esxselector/model/pluginsproxymodel.cpp | 26 - .../esxselector/view/contentselector.cpp | 150 ++--- .../esxselector/view/contentselector.hpp | 13 +- 12 files changed, 725 insertions(+), 586 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 070f455e4..7069737ef 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -7,7 +7,6 @@ #include -#include #include #include @@ -20,6 +19,7 @@ #include "settings/launchersettings.hpp" #include "utils/textinputdialog.hpp" +#include "components/esxselector/view/contentselector.hpp" #include @@ -27,8 +27,8 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam : mCfgMgr(cfg) , mGameSettings(gameSettings) , mLauncherSettings(launcherSettings) - , ContentSelector(parent) { + mContentSelector.setParent(parent); QMetaObject::connectSlotsByName(this); projectGroupBox->hide(); @@ -51,24 +51,21 @@ void DataFilesPage::createActions() void DataFilesPage::setupDataFiles() { - if (!mDataFilesModel) - qDebug() << "data files model undefined"; - // Set the encoding to the one found in openmw.cfg or the default - mDataFilesModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); + mContentSelector.setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); QStringList paths = mGameSettings.getDataDirs(); foreach (const QString &path, paths) { - mDataFilesModel->addFiles(path); + mContentSelector.addFiles(path); } QString dataLocal = mGameSettings.getDataLocal(); if (!dataLocal.isEmpty()) - mDataFilesModel->addFiles(dataLocal); + mContentSelector.addFiles(dataLocal); // Sort by date accessed for now - mDataFilesModel->sort(3); + //mContentSelector->sort(3); QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/")); QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); @@ -107,11 +104,11 @@ void DataFilesPage::loadSettings() if (profile.isEmpty()) return; - mDataFilesModel->uncheckAll(); + // mContentSelector.uncheckAll(); QStringList masters = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly); QStringList plugins = mLauncherSettings.values(QString("Profiles/") + profile + QString("/plugin"), Qt::MatchExactly); - +/* foreach (const QString &master, masters) { QModelIndex index = mDataFilesModel->indexFromItem(mDataFilesModel->findItem(master)); if (index.isValid()) @@ -123,12 +120,13 @@ void DataFilesPage::loadSettings() if (index.isValid()) mDataFilesModel->setCheckState(index, Qt::Checked); } + */ } void DataFilesPage::saveSettings() { - if (mDataFilesModel->rowCount() < 1) - return; +// if (mDataFilesModel->rowCount() < 1) +// return; QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); @@ -143,8 +141,8 @@ void DataFilesPage::saveSettings() mGameSettings.remove(QString("master")); mGameSettings.remove(QString("plugin")); - EsxModel::EsmFileList items = mDataFilesModel->checkedItems(); - + // EsxModel::EsmFileList items = mDataFilesModel->checkedItems(); +/* foreach(const EsxModel::EsmFile *item, items) { if (item->masters().size() == 0) { @@ -156,7 +154,7 @@ void DataFilesPage::saveSettings() mGameSettings.setMultiValue(QString("plugin"), item->fileName()); } } - +*/ } void DataFilesPage::updateOkButton(const QString &text) @@ -241,7 +239,7 @@ void DataFilesPage::setPluginsCheckstates(Qt::CheckState state) if (!sourceIndex.isValid()) return; - mDataFilesModel->setCheckState(sourceIndex, state); + //mDataFilesModel->setCheckState(sourceIndex, state); } } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index f3792b1f1..ed92da749 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -52,6 +52,7 @@ private slots: private: QMenu *mContextMenu; + ContentSelector mContentSelector; Files::ConfigurationManager &mCfgMgr; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 0f7c5017b..b79fa027e 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -72,7 +72,7 @@ find_package(Qt4 COMPONENTS QtCore QtGui) if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) add_component_qt_dir (esxselector - model/masterproxymodel model/modelitem model/datafilesmodel + model/masterproxymodel model/modelitem model/pluginsproxymodel model/esmfile model/naturalsort model/contentmodel view/profilescombobox view/comboboxlineedit diff --git a/components/esxselector/model/contentmodel.cpp b/components/esxselector/model/contentmodel.cpp index 673665775..bfbb1bef7 100644 --- a/components/esxselector/model/contentmodel.cpp +++ b/components/esxselector/model/contentmodel.cpp @@ -21,20 +21,7 @@ int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const return 1; } -/* -QModelIndex EsxModel::ContentModel::parent(const QModelIndex &child) const -{ - if(!child.isValid()) - return 0; - return child.parent(); -} - -QModelIndex EsxModel::ContentModel::index(int row, int column, const QModelIndex &parent) const -{ - -} -*/ int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const { if(parent.isValid()) @@ -43,6 +30,53 @@ int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const return mFiles.size(); } +EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const +{ + if (row >= 0 && row < mFiles.count()) + return mFiles.at(row); + + return 0; +} + +EsxModel::EsmFile* EsxModel::ContentModel::findItem(const QString &name) +{ + for (int i = 0; i < mFiles.size(); ++i) + { + if (name == item(i)->fileName()) + return item(i); + } + + return 0; +} + +QModelIndex EsxModel::ContentModel::indexFromItem(EsmFile *item) const +{ + if (item) + return index(mFiles.indexOf(item),0); + + return QModelIndex(); +} + +Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + EsmFile *file = item(index.row()); + + if (!file) + return Qt::NoItemFlags; + + Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable; + Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; + + if (canBeChecked(file)) + return Qt::ItemIsEnabled | dragDropFlags | checkFlags | defaultFlags; + else + return defaultFlags; +} + QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -70,18 +104,14 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const case 1: return file->author(); case 2: - return QString("%1 kB").arg(int((file->size() + 1023) / 1024)); - case 3: return file->modified().toString(Qt::ISODate); - case 4: - return file->accessed().toString(Qt::TextDate); - case 5: + case 3: return file->version(); - case 6: + case 4: return file->path(); - case 7: + case 5: return file->masters().join(", "); - case 8: + case 6: return file->description(); } @@ -97,8 +127,6 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const return Qt::AlignLeft + Qt::AlignVCenter; case 2: case 3: - case 4: - case 5: return Qt::AlignRight + Qt::AlignVCenter; default: return Qt::AlignLeft + Qt::AlignVCenter; @@ -124,47 +152,88 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const .arg(file->masters().join(", ")); } + case Qt::CheckStateRole: + if (!file->isMaster()) + return isChecked(file->fileName()); + break; + case Qt::UserRole: { - if (file->masters().size() == 0) + if (file->isMaster()) return "game"; else return "addon"; } - default: - return QVariant(); + case Qt::UserRole + 1: + return isChecked(file->fileName()); + break; } -} - -Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - - EsmFile *file = item(index.row()); - - if (!file) - return Qt::NoItemFlags; - - Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; - Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable; - Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; - - if (canBeChecked(file)) - return Qt::ItemIsEnabled | dragDropFlags | checkFlags | defaultFlags; - else - return defaultFlags; + return QVariant(); } bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (index.isValid() && role == Qt::EditRole) + if(!index.isValid()) + return false; + + EsmFile *file = item(index.row()); + QString fileName = file->fileName(); + + switch(role) { - QString fname = value.value(); - mFiles.replace(index.row(), findItem(fname)); - emit dataChanged(index, index); - return true; + case Qt::EditRole: + { + QStringList list = value.toStringList(); + + //iterate the string list, assigning values to proeprties + //index-enum correspondence 1:1 + for (int i = 0; i < EsxModel::Property_Master; i++) + file->setProperty(static_cast(i), list.at(i)); + + //iterate the remainder of the string list, assifning everything + // as + for (int i = EsxModel::Property_Master; i < list.size(); i++) + file->setProperty (EsxModel::Property_Master, list.at(i)); + + //emit data changed for the item itself + emit dataChanged(index, index); + + return true; + } + break; + + case Qt::UserRole+1: + { + setCheckState(fileName, value.toBool()); + + emit dataChanged(index, index); + + for(int i = 0; i < mFiles.size(); i++) + { + + if (mFiles.at(i)->masters().contains(fileName)) + { + QModelIndex idx = QAbstractTableModel::index(i, 0); + emit dataChanged(idx, idx); + } + } + + return true; + } + break; + + case Qt::CheckStateRole: + { + bool checked = ((value.toInt() == Qt::Checked) && !isChecked(fileName)); + + setCheckState(fileName, checked); + + emit dataChanged(index, index); + + return true; + } + break; } return false; @@ -172,24 +241,31 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent) { + if (parent.isValid()) + return false; + beginInsertRows(parent, position, position+rows-1); + { + for (int row = 0; row < rows; ++row) + mFiles.insert(position, new EsmFile); - for (int row = 0; row < rows; ++row) - mFiles.insert(position, new EsmFile); + } endInsertRows(); - endInsertRows(); return true; } bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelIndex &parent) { + if (parent.isValid()) + return false; + beginRemoveRows(parent, position, position+rows-1); + { + for (int row = 0; row < rows; ++row) + delete mFiles.takeAt(position); - for (int row = 0; row < rows; ++row) - mFiles.removeAt(position); + } endRemoveRows(); - endRemoveRows(); - emit dataChanged(index(0,0,parent), index(rowCount()-1, 0, parent)); return true; } @@ -201,27 +277,30 @@ Qt::DropActions EsxModel::ContentModel::supportedDropActions() const QStringList EsxModel::ContentModel::mimeTypes() const { QStringList types; + types << "application/omwcontent"; + return types; } QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) const { - QMimeData *mimeData = new QMimeData(); QByteArray encodedData; - QDataStream stream(&encodedData, QIODevice::WriteOnly); - foreach (const QModelIndex &index, indexes) { - if (index.isValid()) - { - QString text = data(index, Qt::DisplayRole).toString(); - stream << text; - } + if (!index.isValid()) + continue; + + QByteArray fileData = item(index.row())->encodedData(); + + foreach (const char c, fileData) + encodedData.append(c); } + QMimeData *mimeData = new QMimeData(); mimeData->setData("application/omwcontent", encodedData); + return mimeData; } @@ -240,31 +319,66 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction if (row != -1) beginRow = row; + else if (parent.isValid()) beginRow = parent.row(); + else beginRow = rowCount(); QByteArray encodedData = data->data("application/omwcontent"); QDataStream stream(&encodedData, QIODevice::ReadOnly); - QStringList newItems; - int rows = 0; while (!stream.atEnd()) { - QString text; - stream >> text; - newItems << text; - ++rows; + QStringList values; + + for (int i = 0; i < EsmFile::sPropertyCount; ++i) + stream >> values; + + insertRows(beginRow, 1); + + QModelIndex idx = index(beginRow++, 0, QModelIndex()); + setData(idx, values, Qt::EditRole); } - insertRows(beginRow, rows, QModelIndex()); + return true; +} - foreach (const QString &text, newItems) +bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const +{ + //element can be checked if all its dependencies are + foreach (const QString &master, file->masters()) { - QModelIndex idx = index(beginRow, 0, QModelIndex()); - setData(idx, text); - beginRow++; + {// if the master is not found in checkstates + // or it is not specifically checked, return false + if (!mCheckStates.contains(master)) + return false; + + if (!isChecked(master)) + return false; + } + + bool found = false; + + //iterate each file, if it is not a master and + //does not have a master that is currently checked, + //return false. + foreach(const EsmFile *file, mFiles) + { + QString filename = file->fileName(); + + found = (filename == master); + + if (found) + { + if (!isChecked(filename)) + return false; + } + } + + if (!found) + return false; } return true; @@ -272,9 +386,10 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction void EsxModel::ContentModel::addFile(EsmFile *file) { - emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); - mFiles.append(file); - emit endInsertRows(); + beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); + { + mFiles.append(file); + } endInsertRows(); } void EsxModel::ContentModel::addFiles(const QString &path) @@ -319,9 +434,9 @@ void EsxModel::ContentModel::addFiles(const QString &path) } file->setAuthor(decoder->toUnicode(fileReader.getAuthor().c_str())); - file->setSize(info.size()); - file->setDates(info.lastModified(), info.lastRead()); - file->setVersion(fileReader.getFVer()); + //file->setSize(info.size()); + file->setDate(info.lastModified()); + file->setVersion(0.0f); file->setPath(info.absoluteFilePath()); file->setMasters(masters); file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str())); @@ -342,66 +457,22 @@ void EsxModel::ContentModel::addFiles(const QString &path) delete decoder; } -EsxModel::EsmFile* EsxModel::ContentModel::findItem(const QString &name) +bool EsxModel::ContentModel::isChecked(const QString& name) const { - for (int i = 0; i < mFiles.size(); ++i) - { - if (name == item(i)->fileName()) - return item(i); - } - - // Not found - return 0; + return (mCheckStates[name] == Qt::Checked); } -EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const +void EsxModel::ContentModel::setCheckState(const QString &name, bool isChecked) { - if (row >= 0 && row < mFiles.count()) - return mFiles.at(row); - - return 0; -} - -QModelIndex EsxModel::ContentModel::indexFromItem(EsmFile *item) const -{ - if (item) - //return createIndex(mFiles.indexOf(item), 0); - return index(mFiles.indexOf(item),0); - - return QModelIndex(); -} - -Qt::CheckState EsxModel::ContentModel::checkState(const QModelIndex &index) -{ - return mCheckStates[item(index.row())->fileName()]; -} - -void EsxModel::ContentModel::setCheckState(const QModelIndex &index, Qt::CheckState state) -{ - if (!index.isValid()) + if (name.isEmpty()) return; - QString name = item(index.row())->fileName(); + Qt::CheckState state = Qt::Unchecked; + + if (isChecked) + state = Qt::Checked; + mCheckStates[name] = state; - - // Force a redraw of the view since unchecking one item can affect another - QModelIndex firstIndex = indexFromItem(mFiles.first()); - QModelIndex lastIndex = indexFromItem(mFiles.last()); - - emit dataChanged(firstIndex, lastIndex); - //emit checkedItemsChanged(checkedItems()); - -} - -bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const -{ - //element can be checked if all its dependencies are - foreach (const QString &master, file->masters()) - { - if (!mCheckStates.contains(master) || mCheckStates[master] != Qt::Checked) - return false; - } - return true; } EsxModel::ContentFileList EsxModel::ContentModel::checkedItems() const diff --git a/components/esxselector/model/contentmodel.hpp b/components/esxselector/model/contentmodel.hpp index a585ab63b..61c823ab3 100644 --- a/components/esxselector/model/contentmodel.hpp +++ b/components/esxselector/model/contentmodel.hpp @@ -37,14 +37,11 @@ namespace EsxModel QModelIndex indexFromItem(EsmFile *item) const; EsxModel::EsmFile *findItem(const QString &name); - Qt::CheckState checkState(const QModelIndex &index); - void setCheckState(const QModelIndex &index, Qt::CheckState state); + bool isChecked(const QString &name) const; + void setCheckState(const QString &name, bool isChecked); ContentFileList checkedItems() const; void uncheckAll(); -/* - QModelIndex index(int row, int column, const QModelIndex &parent) const; - QModelIndex parent(const QModelIndex &child) const; -*/ + private: void addFile(EsmFile *file); diff --git a/components/esxselector/model/datafilesmodel.cpp b/components/esxselector/model/datafilesmodel.cpp index ee940bb27..c98f70b16 100644 --- a/components/esxselector/model/datafilesmodel.cpp +++ b/components/esxselector/model/datafilesmodel.cpp @@ -24,6 +24,340 @@ EsxModel::DataFilesModel::~DataFilesModel() { } +int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : mFiles.count(); +} + +int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : 1; +} + +const EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) +{ + for (int i = 0; i < mFiles.size(); ++i) + { + const EsmFile *file = item(i); + + if (name == file->fileName()) + return file; + } + + return 0; +} + +const EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const +{ + if (row >= 0 && row < mFiles.count()) + return mFiles.at(row); + + return 0; +} + +Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + const EsmFile *file = item(index.row()); + + if (!file) + return Qt::NoItemFlags; + + Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable | Qt::ItemIsEditable; + Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; + + if (canBeChecked(file)) + return defaultFlags | dragDropFlags | checkFlags | Qt::ItemIsEnabled; + else + return defaultFlags; +} + +QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= mFiles.size()) + return QVariant(); + + const EsmFile *file = item(index.row()); + + if (!file) + return QVariant(); + + const int column = index.column(); + + switch (role) + { + case Qt::EditRole: + case Qt::DisplayRole: + { + + switch (column) + { + case 0: + return file->fileName(); + case 1: + return file->author(); + case 2: + return file->modified().toString(Qt::ISODate); + case 3: + return file->version(); + case 4: + return file->path(); + case 5: + return file->masters().join(", "); + case 6: + return file->description(); + } + break; + } + + case Qt::TextAlignmentRole: + { + switch (column) + { + case 0: + case 1: + return Qt::AlignLeft + Qt::AlignVCenter; + case 2: + case 3: + return Qt::AlignRight + Qt::AlignVCenter; + default: + return Qt::AlignLeft + Qt::AlignVCenter; + } + break; + } + + case Qt::ToolTipRole: + { + if (column != 0) + return QVariant(); + + if (file->version() == 0.0f) + return QVariant(); // Data not set + + QString tooltip = + QString("Author: %1
\ + Version: %2
\ +
Description:
%3
\ +
Dependencies: %4
") + .arg(file->author()) + .arg(QString::number(file->version())) + .arg(file->description()) + .arg(file->masters().join(", ")); + + + return tooltip; + break; + } + + case Qt::UserRole: + { + if (file->masters().size() == 0) + return "game"; + else + return "addon"; + + break; + } + + case Qt::UserRole + 1: + //return check state here + break; + + default: + return QVariant(); + break; + } + +} + +bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid()) + return false; + + switch (role) + { + case Qt::EditRole: + { + const EsmFile *file = item(index.row()); + + // iterate loop to repopulate file pointer with data in string list. + QStringList list = value.toStringList(); + for (int i = 0; i <999; ++i) + { + file->setProperty(i, value.at(i)); + } + + //populate master list here (emit data changed for each master and + //each item (other than the dropped item) which share each of the masters + file->masters().append(masterList); + + emit dataChanged(index, index); + return true; + } + break; + + case Qt::UserRole + 1: + { + EsmFile *file = item(index.row()); + //set file's checkstate to the passed checkstate + emit dataChanged(index, index); + + for (int i = 0; i < mFiles.size(); ++i) + if (mFiles.at(i)->getMasters().contains(file->fileName())) + emit dataChanged(QAbstractTableModel::index(i,0), QAbstractTableModel::index(i,0)); + + return true; + } + break; + + case Qt::CheckStateRole: + { + EsmFile *file = item(index.row()); + + if ((value.toInt() == Qt::Checked) && !file->isChecked()) + file->setChecked(true); + else if (value.toInt() == Qt::Checked && file->isChecked()) + file->setChecked(false); + else if (value.toInt() == Qt::UnChecked) + file->setChecked(false); + + emit dataChanged(index, index); + + return true; + } + break; + } + return false; +} + +bool EsxModel::DataFilesModel::insertRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid()) + return false; + + beginInsertRows(QModelIndex(),row, row+count-1); + { + for (int i = 0; i < count; ++i) + mFiles.insert(row, new EsmFile()); + } endInsertRows(); + + return true; +} + +bool EsxModel::DataFilesModel::removeRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid()) + return false; + + beginRemoveRows(QModelIndex(), row, row+count-1); + { + for (int i = 0; i < count; ++i) + delete mFiles.takeAt(row); + } endRemoveRows(); + + return true; +} + +Qt::DropActions EsxModel::DataFilesModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction; +} + +QStringList EsxModel::DataFilesModel::mimeTypes() const +{ + QStringList types; + types << "application/omwcontent"; + return types; +} + +QMimeData *EsxModel::DataFilesModel::mimeData(const QModelIndexList &indexes) const +{ + QMimeData *mimeData = new QMimeData(); + QByteArray encodedData; + + QDataStream stream (&encodedData, QIODevice::WriteOnly); + + foreach (const QModelIndex &index, indexes) + { + if (index.isValid()) + { + EsmFile *file = item (index.row()); + + for (int i = 0; i < file->propertyCount(); ++i) + stream << data(index, Qt::DisplayRole).toString(); + + EsmFile *file = item(index.row()); + stream << file->getMasters(); + } + } + + mimeData->setData("application/omwcontent", encodedData); + + return mimeData; +} + +bool EsxModel::DataFilesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if (action == Qt::IgnoreAction) + return true; + + if (action != Qt::MoveAction) + return false; + + if (!data->hasFormat("application/omwcontent")) + return false; + + int dropRow = row; + + if (dropRow == -1) + { + if (parent.isValid()) + dropRow = parent.row(); + else + dropRow = rowCount(QModelIndex()); + } + + if (parent.isValid()) + qDebug() << "parent: " << parent.data().toString(); + qDebug() << "dragged file: " << (qobject_cast(data))->fileName(); +// qDebug() << "inserting file: " << droppedfile->fileName() << " ahead of " << file->fileName(); + insertRows (dropRow, 1, QModelIndex()); + + + const EsmFile *draggedFile = qobject_cast(data); + + int dragRow = -1; + + for (int i = 0; i < mFiles.size(); ++i) + if (draggedFile->fileName() == mFiles.at(i)->fileName()) + { + dragRow = i; + break; + } + + for (int i = 0; i < mFiles.count(); ++i) + { + qDebug() << "index: " << i << "file: " << item(i)->fileName(); + qDebug() << mFiles.at(i)->fileName(); + } + + qDebug() << "drop row: " << dropRow << "; drag row: " << dragRow; +// const EsmFile *file = qobject_cast(data); + // int index = mFiles.indexOf(file); + //qDebug() << "file name: " << file->fileName() << "; index: " << index; + mFiles.swap(dropRow, dragRow); + //setData(index(startRow, 0), varFile); + emit dataChanged(index(0,0), index(rowCount(),0)); + return true; +} + void EsxModel::DataFilesModel::setEncoding(const QString &encoding) { mEncoding = encoding; @@ -51,17 +385,6 @@ Qt::CheckState EsxModel::DataFilesModel::checkState(const QModelIndex &index) return mCheckStates[item(index.row())->fileName()]; } -int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : 1; -} - -int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : mFiles.count(); -} - - bool EsxModel::DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &parent) { if (oldrow < 0 || row < 0 || oldrow == row) @@ -76,124 +399,6 @@ bool EsxModel::DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &p return true; } -QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - const EsmFile *file = item(index.row()); - - if (!file) - return QVariant(); - - const int column = index.column(); - - switch (role) { - case Qt::EditRole: - case Qt::DisplayRole: { - - switch (column) { - case 0: - return file->fileName(); - case 1: - return file->author(); - case 2: - return QString("%1 kB").arg(int((file->size() + 1023) / 1024)); - case 3: - //return file->modified().toString(Qt::TextDate); - return file->modified().toString(Qt::ISODate); - case 4: - return file->accessed().toString(Qt::TextDate); - case 5: - return file->version(); - case 6: - return file->path(); - case 7: - return file->masters().join(", "); - case 8: - return file->description(); - } - } - - case Qt::TextAlignmentRole: { - switch (column) { - case 0: - case 1: - return Qt::AlignLeft + Qt::AlignVCenter; - case 2: - case 3: - case 4: - case 5: - return Qt::AlignRight + Qt::AlignVCenter; - default: - return Qt::AlignLeft + Qt::AlignVCenter; - } - } - - case Qt::ToolTipRole: - { - if (column != 0) - return QVariant(); - - if (file->version() == 0.0f) - return QVariant(); // Data not set - - QString tooltip = - QString("Author: %1
\ - Version: %2
\ -
Description:
%3
\ -
Dependencies: %4
") - .arg(file->author()) - .arg(QString::number(file->version())) - .arg(file->description()) - .arg(file->masters().join(", ")); - - - return tooltip; - - } - - case Qt::UserRole: - { - if (file->masters().size() == 0) - return "game"; - else - return "addon"; - } - - default: - return QVariant(); - } - -} - -Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - - const EsmFile *file = item(index.row()); - - Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; - Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable | Qt::ItemIsSelectable; - - if (!file) - return Qt::NoItemFlags; - - if (canBeChecked(file)) - { - if (index.column() == 0) - return dragDropFlags | checkFlags | Qt::ItemIsEnabled; - else - return Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable; - } - - if (index.column() == 0) - return dragDropFlags | checkFlags; - - return Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; -} - QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) @@ -215,22 +420,6 @@ QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orien return QVariant(); } -bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (!index.isValid()) - return false; - - if (role == Qt::EditRole) - { - qDebug() << "replacing: " << mFiles.at(index.row())->fileName(); -// mFiles.replace(index.row(), value.value()); - qDebug() << "with: " << mFiles.at(index.row())->fileName(); - emit dataChanged(index, index); - return true; - } - - return false; -} //!!!!!!!!!!!!!!!!!!!!!!! bool lessThanEsmFile(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) { @@ -345,32 +534,6 @@ QModelIndex EsxModel::DataFilesModel::indexFromItem(const EsmFile *item) const return QModelIndex(); } -const EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) -{ - EsmFileList::ConstIterator it; - EsmFileList::ConstIterator itEnd = mFiles.constEnd(); - - int i = 0; - for (it = mFiles.constBegin(); it != itEnd; ++it) { - const EsmFile *file = item(i); - ++i; - - if (name == file->fileName()) - return file; - } - - // Not found - return 0; -} - -const EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const -{ - if (row >= 0 && row < mFiles.count()) - return mFiles.at(row); - - return 0; -} - EsxModel::EsmFileList EsxModel::DataFilesModel::checkedItems() { EsmFileList list; @@ -443,110 +606,3 @@ bool EsxModel::DataFilesModel::canBeChecked(const EsmFile *file) const } return true; } - -Qt::DropActions EsxModel::DataFilesModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -QStringList EsxModel::DataFilesModel::mimeTypes() const -{ - QStringList types; - types << "application/omwcontent"; - return types; -} - -QMimeData *EsxModel::DataFilesModel::mimeData(const QModelIndexList &indexes) const -{ -// if (indexes.at(0).isValid()) -// return new EsmFile(*item(indexes.at(0).row())); - - return 0; -} - -bool EsxModel::DataFilesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -{ - if (action == Qt::IgnoreAction) - return true; - - if (action != Qt::MoveAction) - return false; - - if (!data->hasFormat("application/omwcontent")) - return false; - - int dropRow = row; - - if (dropRow == -1) - { - if (parent.isValid()) - dropRow = parent.row(); - else - dropRow = rowCount(QModelIndex()); - } - - if (parent.isValid()) - qDebug() << "parent: " << parent.data().toString(); - qDebug() << "dragged file: " << (qobject_cast(data))->fileName(); -// qDebug() << "inserting file: " << droppedfile->fileName() << " ahead of " << file->fileName(); - insertRows (dropRow, 1, QModelIndex()); - - - const EsmFile *draggedFile = qobject_cast(data); - - int dragRow = -1; - - for (int i = 0; i < mFiles.size(); ++i) - if (draggedFile->fileName() == mFiles.at(i)->fileName()) - { - dragRow = i; - break; - } - - for (int i = 0; i < mFiles.count(); ++i) - { - qDebug() << "index: " << i << "file: " << item(i)->fileName(); - qDebug() << mFiles.at(i)->fileName(); - } - - qDebug() << "drop row: " << dropRow << "; drag row: " << dragRow; -// const EsmFile *file = qobject_cast(data); - // int index = mFiles.indexOf(file); - //qDebug() << "file name: " << file->fileName() << "; index: " << index; - mFiles.swap(dropRow, dragRow); - //setData(index(startRow, 0), varFile); - emit dataChanged(index(0,0), index(rowCount(),0)); - return true; -} - -bool EsxModel::DataFilesModel::insertRows(int row, int count, const QModelIndex &parent) -{ - qDebug() << "inserting row: " << row << " count: " << count; - beginInsertRows(QModelIndex(),row, row+count-1); - - EsmFile *file = new EsmFile(); - - for (int i = 0; i < count; ++i) - mFiles.insert(row + i, file); - - endInsertRows(); - return true; -} - -bool EsxModel::DataFilesModel::removeRows(int row, int count, const QModelIndex &parent) -{ - qDebug() << "removing row: " << row << " count: " << count; - beginRemoveRows(QModelIndex(), row, row+count-1); - - for (int i = 0; i < count; ++i) - { - mFiles.removeAt(i); - } - - endRemoveRows(); - qDebug() <<"remove success"; - - emit dataChanged(parent, index(rowCount()-1, 0, parent)); - return true; -} - diff --git a/components/esxselector/model/esmfile.cpp b/components/esxselector/model/esmfile.cpp index 95cf70312..0e7f18373 100644 --- a/components/esxselector/model/esmfile.cpp +++ b/components/esxselector/model/esmfile.cpp @@ -1,7 +1,12 @@ #include "esmfile.hpp" +#include +#include + +int EsxModel::EsmFile::sPropertyCount = 7; + EsxModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) - : ModelItem(parent), mFileName(fileName), mSize(0), mVersion(0.0f) + : ModelItem(parent), mFileName(fileName), mVersion(0.0f) {} /* EsxModel::EsmFile::EsmFile(const EsmFile &file) @@ -22,15 +27,9 @@ void EsxModel::EsmFile::setAuthor(const QString &author) mAuthor = author; } -void EsxModel::EsmFile::setSize(const int size) -{ - mSize = size; -} - -void EsxModel::EsmFile::setDates(const QDateTime &modified, const QDateTime &accessed) +void EsxModel::EsmFile::setDate(const QDateTime &modified) { mModified = modified; - mAccessed = accessed; } void EsxModel::EsmFile::setVersion(float version) @@ -52,3 +51,52 @@ void EsxModel::EsmFile::setDescription(const QString &description) { mDescription = description; } + +QByteArray EsxModel::EsmFile::encodedData() const +{ + QByteArray encodedData; + QDataStream stream(&encodedData, QIODevice::WriteOnly); + + stream << mFileName << mAuthor << QString::number(mVersion) + << mModified.toString() << mPath << mDescription + << mMasters; + + return encodedData; +} + +void EsxModel::EsmFile::setProperty (const EsmFileProperty prop, const QString &value) +{ + switch (prop) + { + case Property_FileName: + mFileName = value; + break; + + case Property_Author: + mAuthor = value; + break; + + case Property_Version: + mVersion = value.toFloat(); + break; + + case Property_DateModified: + mModified = QDateTime::fromString(value); + break; + + case Property_Path: + mPath = value; + break; + + case Property_Description: + mDescription = value; + break; + + case Property_Master: + mMasters << value; + break; + + default: + break; + } +} diff --git a/components/esxselector/model/esmfile.hpp b/components/esxselector/model/esmfile.hpp index 0cda018b3..9a1ea8af1 100644 --- a/components/esxselector/model/esmfile.hpp +++ b/components/esxselector/model/esmfile.hpp @@ -6,8 +6,21 @@ #include "modelitem.hpp" +class QMimeData; + namespace EsxModel { + enum EsmFileProperty + { + Property_FileName = 0, + Property_Author = 1, + Property_Version = 2, + Property_DateModified = 3, + Property_Path = 4, + Property_Description = 5, + Property_Master = 6 + }; + class EsmFile : public ModelItem { Q_OBJECT @@ -21,10 +34,12 @@ namespace EsxModel ~EsmFile() {} + void setProperty (const EsmFileProperty prop, const QString &value); + void setFileName(const QString &fileName); void setAuthor(const QString &author); void setSize(const int size); - void setDates(const QDateTime &modified, const QDateTime &accessed); + void setDate(const QDateTime &modified); void setVersion(const float version); void setPath(const QString &path); void setMasters(const QStringList &masters); @@ -32,22 +47,23 @@ namespace EsxModel inline QString fileName() const { return mFileName; } inline QString author() const { return mAuthor; } - inline int size() const { return mSize; } inline QDateTime modified() const { return mModified; } - inline QDateTime accessed() const { return mAccessed; } inline float version() const { return mVersion; } inline QString path() const { return mPath; } inline QStringList masters() const { return mMasters; } inline QString description() const { return mDescription; } - //inline ModelItem *parent() const { return ModelItem::parent(); this->} + inline bool isMaster() const { return (mMasters.size() == 0); } + QByteArray encodedData() const; + + public: + static int sPropertyCount; private: + QString mFileName; QString mAuthor; - int mSize; QDateTime mModified; - QDateTime mAccessed; float mVersion; QString mPath; QStringList mMasters; diff --git a/components/esxselector/model/masterproxymodel.cpp b/components/esxselector/model/masterproxymodel.cpp index 46d68ca51..df74d0356 100644 --- a/components/esxselector/model/masterproxymodel.cpp +++ b/components/esxselector/model/masterproxymodel.cpp @@ -10,35 +10,4 @@ EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableMode if (model) setSourceModel (model); - //connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotSourceModelChanged(QModelIndex, QModelIndex))); -} -/* -QVariant EsxModel::MasterProxyModel::data(const QModelIndex &index, int role) const -{ - if (index.isValid()) - return QSortFilterProxyModel::data (index, role); - - return 0; -} -*/ -void EsxModel::MasterProxyModel::slotSourceModelChanged(QModelIndex topLeft, QModelIndex botRight) -{ - qDebug() << "source data changed.. updating master proxy"; - emit dataChanged(index(0,0), index(rowCount()-1,0)); - - int curRow = -1; -/* - for (int i = 0; i < rowCount() - 1; ++i) - { - if (index(i,0).data(Qt::CheckState) == Qt::Checked) - { - curRow = i; - break; - } - } - - reset(); -*/ - if (curRow != -1); - // index(curRow, 0).setDataQt::CheckState) } diff --git a/components/esxselector/model/pluginsproxymodel.cpp b/components/esxselector/model/pluginsproxymodel.cpp index 412367b64..c543672b0 100644 --- a/components/esxselector/model/pluginsproxymodel.cpp +++ b/components/esxselector/model/pluginsproxymodel.cpp @@ -12,29 +12,3 @@ EsxModel::PluginsProxyModel::PluginsProxyModel(QObject *parent, ContentModel *mo if (model) setSourceModel (model); } - -EsxModel::PluginsProxyModel::~PluginsProxyModel() -{ -} - -QVariant EsxModel::PluginsProxyModel::data(const QModelIndex &index, int role) const -{ - switch (role) - { - case Qt::CheckStateRole: - { - if (index.column() != 0) - return QVariant(); - - return static_cast(sourceModel())->checkState(mapToSource(index)); - } - } - return QSortFilterProxyModel::data(index, role); -} - -bool EsxModel::PluginsProxyModel::removeRows(int position, int rows, const QModelIndex &parent) -{ - bool success = QSortFilterProxyModel::removeRows(position, rows, parent); - - return success; -} diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index bc7cc2b8b..1f5e36d65 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -1,8 +1,6 @@ #include "contentselector.hpp" #include "../model/datafilesmodel.hpp" -#include "../model/masterproxymodel.hpp" -#include "../model/pluginsproxymodel.hpp" #include "../model/contentmodel.hpp" #include "../model/esmfile.hpp" @@ -16,55 +14,73 @@ EsxView::ContentSelector::ContentSelector(QWidget *parent) : QDialog(parent) { setupUi(this); - // buildModelsAndViews(); - buildDragDropModelView(); + + buildSourceModel(); + buildMasterView(); + buildPluginsView(); + buildProfilesView(); + + updateViews(); + } -void EsxView::ContentSelector::buildDragDropModelView() + +void EsxView::ContentSelector::buildSourceModel() { mContentModel = new EsxModel::ContentModel(); + connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); +} - //mContentModel->addFiles("/home/joel/Projects/OpenMW/Data_Files"); - mMasterProxyModel = new EsxModel::MasterProxyModel(this, mContentModel); - mPluginsProxyModel = new EsxModel::PluginsProxyModel(this, mContentModel); - - tableView->setModel (mPluginsProxyModel); +void EsxView::ContentSelector::buildMasterView() +{ + mMasterProxyModel = new QSortFilterProxyModel(this); + mMasterProxyModel->setFilterRegExp(QString("game")); + mMasterProxyModel->setFilterRole (Qt::UserRole); + mMasterProxyModel->setSourceModel (mContentModel); masterView->setPlaceholderText(QString("Select a game file...")); masterView->setModel(mMasterProxyModel); + + connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); + + masterView->setCurrentIndex(-1); + masterView->setCurrentIndex(0); +} + +void EsxView::ContentSelector::buildPluginsView() +{ + mPluginsProxyModel = new QSortFilterProxyModel(this); + mPluginsProxyModel->setFilterRegExp (QString("addon")); + mPluginsProxyModel->setFilterRole (Qt::UserRole); + mPluginsProxyModel->setDynamicSortFilter (true); + mPluginsProxyModel->setSourceModel (mContentModel); + + tableView->setModel (mPluginsProxyModel); pluginView->setModel(mPluginsProxyModel); - profilesComboBox->setPlaceholderText(QString("Select a profile...")); - - updateViews(); connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); - connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); - connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); - - - connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); } -void EsxView::ContentSelector::buildModelsAndViews() +void EsxView::ContentSelector::buildProfilesView() { - // Models - mDataFilesModel = new EsxModel::DataFilesModel (this); - - // mMasterProxyModel = new EsxModel::MasterProxyModel (this, mDataFilesModel); - // mPluginsProxyModel = new EsxModel::PluginsProxyModel (this, mDataFilesModel); - - masterView->setPlaceholderText(QString("Select a game file...")); - masterView->setModel(mMasterProxyModel); - pluginView->setModel(mPluginsProxyModel); profilesComboBox->setPlaceholderText(QString("Select a profile...")); - - updateViews(); - connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); - connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); - connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); } +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) { mContentModel->addFiles(path); @@ -78,24 +94,6 @@ void EsxView::ContentSelector::setEncoding(const QString &encoding) mContentModel->setEncoding(encoding); } -void EsxView::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model) -{ - if (!index.isValid()) - return; - - if (!model) - return; - - QModelIndex sourceIndex = model->mapToSource(index); - - if (sourceIndex.isValid()) - { - (mContentModel->checkState(sourceIndex) == Qt::Checked) - ? mContentModel->setCheckState(sourceIndex, Qt::Unchecked) - : mContentModel->setCheckState(sourceIndex, Qt::Checked); - } -} - QStringList EsxView::ContentSelector::checkedItemsPaths() { QStringList itemPaths; @@ -106,21 +104,6 @@ QStringList EsxView::ContentSelector::checkedItemsPaths() return itemPaths; } -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::slotCurrentProfileIndexChanged(int index) { emit profileChanged(index); @@ -128,17 +111,40 @@ void EsxView::ContentSelector::slotCurrentProfileIndexChanged(int index) void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index) { - QObject *object = QObject::sender(); + static int oldIndex = -1; - // Not a signal-slot call - if (!object) - return; + QAbstractItemModel *const model = masterView->model(); + QSortFilterProxyModel *proxy = dynamic_cast(model); - setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel); + if (proxy) + proxy->setDynamicSortFilter(false); + + if (oldIndex > -1) + model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); + + oldIndex = index; + + model->setData(model->index(index, 0), true, Qt::UserRole + 1); + + if (proxy) + proxy->setDynamicSortFilter(true); } void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) { qDebug() << "setting checkstate in plugin..."; - setCheckState(index, mPluginsProxyModel); + + QAbstractItemModel *const model = pluginView->model(); + QSortFilterProxyModel *proxy = dynamic_cast(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); } diff --git a/components/esxselector/view/contentselector.hpp b/components/esxselector/view/contentselector.hpp index 06cc8f3f0..e074fe688 100644 --- a/components/esxselector/view/contentselector.hpp +++ b/components/esxselector/view/contentselector.hpp @@ -9,8 +9,6 @@ namespace EsxModel { class ContentModel; class DataFilesModel; - class PluginsProxyModel; - class MasterProxyModel; } class QSortFilterProxyModel; @@ -25,8 +23,8 @@ namespace EsxView EsxModel::DataFilesModel *mDataFilesModel; EsxModel::ContentModel *mContentModel; - EsxModel::MasterProxyModel *mMasterProxyModel; - EsxModel::PluginsProxyModel *mPluginsProxyModel; + QSortFilterProxyModel *mMasterProxyModel; + QSortFilterProxyModel *mPluginsProxyModel; public: explicit ContentSelector(QWidget *parent = 0); @@ -39,7 +37,12 @@ namespace EsxView void setCheckState(QModelIndex index, QSortFilterProxyModel *model); QStringList checkedItemsPaths(); void on_checkAction_triggered(); - void buildDragDropModelView(); + + private: + void buildSourceModel(); + void buildMasterView(); + void buildPluginsView(); + void buildProfilesView(); signals: void profileChanged(int index); From 78f7f80fc3d7ed744a4c7ec07d78325550041a16 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 19 Sep 2013 08:58:27 +0200 Subject: [PATCH 31/42] configured script highlighting with extensions --- apps/opencs/view/world/scripthighlighter.cpp | 5 +++++ apps/opencs/view/world/scripthighlighter.hpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/apps/opencs/view/world/scripthighlighter.cpp b/apps/opencs/view/world/scripthighlighter.cpp index 288a3d12a..f06d5542e 100644 --- a/apps/opencs/view/world/scripthighlighter.cpp +++ b/apps/opencs/view/world/scripthighlighter.cpp @@ -4,6 +4,7 @@ #include #include +#include bool CSVWorld::ScriptHighlighter::parseInt (int value, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) @@ -101,6 +102,10 @@ CSVWorld::ScriptHighlighter::ScriptHighlighter (QTextDocument *parent) format.setForeground (Qt::green); mScheme.insert (std::make_pair (Type_Comment, format)); } + + // configure compiler + Compiler::registerExtensions (mExtensions); + mContext.setExtensions (&mExtensions); } void CSVWorld::ScriptHighlighter::highlightBlock (const QString& text) diff --git a/apps/opencs/view/world/scripthighlighter.hpp b/apps/opencs/view/world/scripthighlighter.hpp index 3ef697809..406935b8d 100644 --- a/apps/opencs/view/world/scripthighlighter.hpp +++ b/apps/opencs/view/world/scripthighlighter.hpp @@ -7,6 +7,7 @@ #include #include +#include #include "../../model/world/scriptcontext.hpp" @@ -29,6 +30,7 @@ namespace CSVWorld private: Compiler::NullErrorHandler mErrorHandler; + Compiler::Extensions mExtensions; CSMWorld::ScriptContext mContext; std::map mScheme; From 3d2281fe808447bfc65ea2bfee13eada450fbf02 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 19 Sep 2013 12:11:27 +0200 Subject: [PATCH 32/42] added signals and functions to Data for handling ID list changes --- apps/opencs/CMakeLists.txt | 4 +- apps/opencs/model/world/collection.hpp | 20 +++++++ apps/opencs/model/world/collectionbase.hpp | 6 +- apps/opencs/model/world/data.cpp | 62 +++++++++++++++++++-- apps/opencs/model/world/data.hpp | 29 +++++++++- apps/opencs/model/world/refidcollection.cpp | 5 ++ apps/opencs/model/world/refidcollection.hpp | 5 ++ apps/opencs/model/world/refiddata.cpp | 22 ++++++++ apps/opencs/model/world/refiddata.hpp | 5 ++ 9 files changed, 147 insertions(+), 11 deletions(-) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index aa6f6ba76..a719750c6 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -18,12 +18,12 @@ opencs_hdrs_noqt (model/doc opencs_units (model/world - idtable idtableproxymodel regionmap + idtable idtableproxymodel regionmap data ) opencs_units_noqt (model/world - universalid data record commands columnbase scriptcontext cell refidcollection + universalid record commands columnbase scriptcontext cell refidcollection refidadapter refiddata refidadapterimp ref collectionbase refcollection columns ) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 6cf31d0a4..a5014e66c 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -107,6 +107,11 @@ namespace CSMWorld virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const; ///< \param type Will be ignored, unless the collection supports multiple record types + virtual std::vector getIds() const; + ///< Return a sorted collection of all IDs + /// + /// \note Deleted records are not listed. + void addColumn (Column *column); void setRecord (int index, const Record& record); @@ -293,6 +298,21 @@ namespace CSMWorld return static_cast (mRecords.size()); } + template + std::vector Collection::getIds() const + { + std::vector ids; + + for (typename std::map::const_iterator iter = mIndex.begin(); + iter!=mIndex.end(); ++iter) + { + if (!mRecords[iter->second].isDeleted()) + ids.push_back (IdAccessorT().getId (mRecords[iter->second].get())); + } + + return ids; + } + template const Record& Collection::getRecord (const std::string& id) const { diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index 1700a68ec..16b88e5e1 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -78,8 +78,12 @@ namespace CSMWorld virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0; ///< \param type Will be ignored, unless the collection supports multiple record types - }; + virtual std::vector getIds() const = 0; + ///< Return a sorted collection of all IDs + /// + /// \note Deleted records are not listed. + }; } #endif \ No newline at end of file diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index fbdbb4413..06fbf61bf 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -2,6 +2,7 @@ #include "data.hpp" #include +#include #include @@ -15,13 +16,30 @@ #include "columns.hpp" void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1, - UniversalId::Type type2) + UniversalId::Type type2, bool update) { mModels.push_back (model); mModelIndex.insert (std::make_pair (type1, model)); if (type2!=UniversalId::Type_None) mModelIndex.insert (std::make_pair (type2, model)); + + if (update) + { + connect (model, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), + this, SLOT (dataChanged (const QModelIndex&, const QModelIndex&))); + connect (model, SIGNAL (rowsInserted (const QModelIndex&, int, int)), + this, SLOT (rowsChanged (const QModelIndex&, int, int))); + connect (model, SIGNAL (rowsRemoved (const QModelIndex&, int, int)), + this, SLOT (rowsChanged (const QModelIndex&, int, int))); + } +} + +void CSMWorld::Data::appendIds (std::vector& ids, const CollectionBase& collection) +{ + std::vector ids2 = collection.getIds(); + + ids.insert (ids.end(), ids2.begin(), ids2.end()); } CSMWorld::Data::Data() : mRefs (mCells) @@ -155,7 +173,7 @@ CSMWorld::Data::Data() : mRefs (mCells) addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global); addModel (new IdTable (&mGmsts), UniversalId::Type_Gmsts, UniversalId::Type_Gmst); - addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill); + addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill, false); addModel (new IdTable (&mClasses), UniversalId::Type_Classes, UniversalId::Type_Class); addModel (new IdTable (&mFactions), UniversalId::Type_Factions, UniversalId::Type_Faction); addModel (new IdTable (&mRaces), UniversalId::Type_Races, UniversalId::Type_Race); @@ -167,8 +185,8 @@ CSMWorld::Data::Data() : mRefs (mCells) addModel (new IdTable (&mCells), UniversalId::Type_Cells, UniversalId::Type_Cell); addModel (new IdTable (&mReferenceables), UniversalId::Type_Referenceables, UniversalId::Type_Referenceable); - addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference); - addModel (new IdTable (&mFilters), UniversalId::Type_Filters, UniversalId::Type_Filter); + addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference, false); + addModel (new IdTable (&mFilters), UniversalId::Type_Filters, UniversalId::Type_Filter, false); } CSMWorld::Data::~Data() @@ -341,7 +359,7 @@ QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id) { RegionMap *table = 0; addModel (table = new RegionMap (*this), UniversalId::Type_RegionMap, - UniversalId::Type_None); + UniversalId::Type_None, false); return table; } throw std::logic_error ("No table model available for " + id.toString()); @@ -440,3 +458,37 @@ bool CSMWorld::Data::hasId (const std::string& id) const getCells().searchId (id)!=-1 || getReferenceables().searchId (id)!=-1; } + +std::vector CSMWorld::Data::getIds() const +{ + std::vector ids; + + appendIds (ids, mGlobals); + appendIds (ids, mGmsts); + appendIds (ids, mClasses); + appendIds (ids, mFactions); + appendIds (ids, mRaces); + appendIds (ids, mSounds); + appendIds (ids, mScripts); + appendIds (ids, mRegions); + appendIds (ids, mBirthsigns); + appendIds (ids, mSpells); + appendIds (ids, mCells); + appendIds (ids, mReferenceables); + + std::sort (ids.begin(), ids.end()); + + return ids; +} + +void CSMWorld::Data::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) +{ + // Note: The performance of of ID list change updates could be improved only emit the signal, if + // the state of the record is changed. + emit idListChanged(); +} + +void CSMWorld::Data::rowsChanged (const QModelIndex& parent, int start, int end) +{ + emit idListChanged(); +} \ No newline at end of file diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index 2f8a2117e..1b024751d 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -6,6 +6,9 @@ #include +#include +#include + #include #include #include @@ -30,8 +33,10 @@ class QAbstractItemModel; namespace CSMWorld { - class Data + class Data : public QObject { + Q_OBJECT + IdCollection mGlobals; IdCollection mGmsts; IdCollection mSkills; @@ -55,13 +60,16 @@ namespace CSMWorld Data& operator= (const Data&); void addModel (QAbstractItemModel *model, UniversalId::Type type1, - UniversalId::Type type2 = UniversalId::Type_None); + UniversalId::Type type2 = UniversalId::Type_None, bool update = true); + + static void appendIds (std::vector& ids, const CollectionBase& collection); + ///< Append all IDs from collection to \a ids. public: Data(); - ~Data(); + virtual ~Data(); const IdCollection& getGlobals() const; @@ -136,6 +144,21 @@ namespace CSMWorld ///< Merging content of a file into base or modified. bool hasId (const std::string& id) const; + + std::vector getIds() const; + ///< Return a sorted collection of all IDs that are not internal to the editor. + /// + /// \note Deleted records are not listed. + + signals: + + void idListChanged(); + + private slots: + + void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); + + void rowsChanged (const QModelIndex& parent, int start, int end); }; } diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 343cbe302..5aadb1be3 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -534,3 +534,8 @@ int CSMWorld::RefIdCollection::getAppendIndex (UniversalId::Type type) const { return mData.getAppendIndex (type); } + +std::vector CSMWorld::RefIdCollection::getIds() const +{ + return mData.getIds(); +} diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index c10d1d2d0..b6c8efdce 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -89,6 +89,11 @@ namespace CSMWorld virtual int getAppendIndex (UniversalId::Type type) const; ///< \param type Will be ignored, unless the collection supports multiple record types + + virtual std::vector getIds() const; + ///< Return a sorted collection of all IDs + /// + /// \note Deleted records are not listed. }; } diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index c95db045f..fca0d8a71 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -196,3 +196,25 @@ int CSMWorld::RefIdData::getSize() const { return mIndex.size(); } + +std::vector CSMWorld::RefIdData::getIds() const +{ + std::vector ids; + + for (std::map::const_iterator iter (mIndex.begin()); iter!=mIndex.end(); + ++iter) + { + if (!getRecord (iter->second).isDeleted()) + { + std::map::const_iterator container = + mRecordContainers.find (iter->second.second); + + if (container==mRecordContainers.end()) + throw std::logic_error ("Invalid referenceable ID type"); + + ids.push_back (container->second->getId (iter->second.first)); + } + } + + return ids; +} diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index 475566fb5..bb8c83360 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -182,6 +182,11 @@ namespace CSMWorld void load (const LocalIndex& index, ESM::ESMReader& reader, bool base); int getSize() const; + + std::vector getIds() const; + ///< Return a sorted collection of all IDs + /// + /// \note Deleted records are not listed. }; } From 9c751ae37053346af2f2ded990a956ef5bd15348 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 19 Sep 2013 12:30:42 +0200 Subject: [PATCH 33/42] separate highlight colour for IDs --- apps/opencs/model/world/scriptcontext.cpp | 24 +++++++++++++++++++- apps/opencs/model/world/scriptcontext.hpp | 13 +++++++++++ apps/opencs/view/world/scripthighlighter.cpp | 14 ++++++++---- apps/opencs/view/world/scripthighlighter.hpp | 5 ++-- apps/opencs/view/world/scriptsubview.cpp | 2 +- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/apps/opencs/model/world/scriptcontext.cpp b/apps/opencs/model/world/scriptcontext.cpp index 69b72abf2..86689d823 100644 --- a/apps/opencs/model/world/scriptcontext.cpp +++ b/apps/opencs/model/world/scriptcontext.cpp @@ -1,6 +1,14 @@ #include "scriptcontext.hpp" +#include + +#include + +#include "data.hpp" + +CSMWorld::ScriptContext::ScriptContext (const Data& data) : mData (data), mIdsUpdated (false) {} + bool CSMWorld::ScriptContext::canDeclareLocals() const { return false; @@ -18,5 +26,19 @@ char CSMWorld::ScriptContext::getMemberType (const std::string& name, const std: bool CSMWorld::ScriptContext::isId (const std::string& name) const { - return false; + if (!mIdsUpdated) + { + mIds = mData.getIds(); + + std::for_each (mIds.begin(), mIds.end(), &Misc::StringUtils::lowerCase); + + mIdsUpdated = true; + } + + return std::binary_search (mIds.begin(), mIds.end(), Misc::StringUtils::lowerCase (name)); +} + +void CSMWorld::ScriptContext::invalidateIds() +{ + mIdsUpdated = false; } \ No newline at end of file diff --git a/apps/opencs/model/world/scriptcontext.hpp b/apps/opencs/model/world/scriptcontext.hpp index 1231aea64..b839b5a43 100644 --- a/apps/opencs/model/world/scriptcontext.hpp +++ b/apps/opencs/model/world/scriptcontext.hpp @@ -1,14 +1,25 @@ #ifndef CSM_WORLD_SCRIPTCONTEXT_H #define CSM_WORLD_SCRIPTCONTEXT_H +#include +#include + #include namespace CSMWorld { + class Data; + class ScriptContext : public Compiler::Context { + const Data& mData; + mutable std::vector mIds; + mutable bool mIdsUpdated; + public: + ScriptContext (const Data& data); + virtual bool canDeclareLocals() const; ///< Is the compiler allowed to declare local variables? @@ -20,6 +31,8 @@ namespace CSMWorld virtual bool isId (const std::string& name) const; ///< Does \a name match an ID, that can be referenced? + + void invalidateIds(); }; } diff --git a/apps/opencs/view/world/scripthighlighter.cpp b/apps/opencs/view/world/scripthighlighter.cpp index f06d5542e..a16077f8a 100644 --- a/apps/opencs/view/world/scripthighlighter.cpp +++ b/apps/opencs/view/world/scripthighlighter.cpp @@ -23,7 +23,7 @@ bool CSVWorld::ScriptHighlighter::parseFloat (float value, const Compiler::Token bool CSVWorld::ScriptHighlighter::parseName (const std::string& name, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) { - highlight (loc, Type_Name); + highlight (loc, mContext.isId (name) ? Type_Id : Type_Name); return true; } @@ -63,10 +63,10 @@ void CSVWorld::ScriptHighlighter::highlight (const Compiler::TokenLoc& loc, Type setFormat (index, length, mScheme[type]); } -CSVWorld::ScriptHighlighter::ScriptHighlighter (QTextDocument *parent) -: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext) +CSVWorld::ScriptHighlighter::ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent) +: QSyntaxHighlighter (parent), Compiler::Parser (mErrorHandler, mContext), mContext (data) { - /// \ŧodo replace this with user settings + /// \todo replace this with user settings { QTextCharFormat format; format.setForeground (Qt::darkMagenta); @@ -103,6 +103,12 @@ CSVWorld::ScriptHighlighter::ScriptHighlighter (QTextDocument *parent) mScheme.insert (std::make_pair (Type_Comment, format)); } + { + QTextCharFormat format; + format.setForeground (Qt::blue); + mScheme.insert (std::make_pair (Type_Id, format)); + } + // configure compiler Compiler::registerExtensions (mExtensions); mContext.setExtensions (&mExtensions); diff --git a/apps/opencs/view/world/scripthighlighter.hpp b/apps/opencs/view/world/scripthighlighter.hpp index 406935b8d..e29a66490 100644 --- a/apps/opencs/view/world/scripthighlighter.hpp +++ b/apps/opencs/view/world/scripthighlighter.hpp @@ -24,7 +24,8 @@ namespace CSVWorld Type_Name, Type_Keyword, Type_Special, - Type_Comment + Type_Comment, + Type_Id }; private: @@ -73,7 +74,7 @@ namespace CSVWorld public: - ScriptHighlighter (QTextDocument *parent); + ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent); virtual void highlightBlock (const QString& text); }; diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index ab1c2d57c..6a7ec752f 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -58,7 +58,7 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc: connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int))); - new ScriptHighlighter (mEditor->document()); + new ScriptHighlighter (document.getData(), mEditor->document()); } void CSVWorld::ScriptSubView::setEditLock (bool locked) From ba5e2a0330d203bac77b8d0185c6cca12d9176ed Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 19 Sep 2013 13:42:19 +0200 Subject: [PATCH 34/42] changed ID listing to include deleted records by default --- apps/opencs/model/world/collection.hpp | 8 ++--- apps/opencs/model/world/collectionbase.hpp | 4 +-- apps/opencs/model/world/data.cpp | 36 ++++++++++----------- apps/opencs/model/world/data.hpp | 7 ++-- apps/opencs/model/world/refidcollection.cpp | 4 +-- apps/opencs/model/world/refidcollection.hpp | 4 +-- apps/opencs/model/world/refiddata.cpp | 4 +-- apps/opencs/model/world/refiddata.hpp | 4 +-- 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index a5014e66c..84a00cef8 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -107,10 +107,10 @@ namespace CSMWorld virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const; ///< \param type Will be ignored, unless the collection supports multiple record types - virtual std::vector getIds() const; + virtual std::vector getIds (bool listDeleted = true) const; ///< Return a sorted collection of all IDs /// - /// \note Deleted records are not listed. + /// \param listDeleted include deleted record in the list void addColumn (Column *column); @@ -299,14 +299,14 @@ namespace CSMWorld } template - std::vector Collection::getIds() const + std::vector Collection::getIds (bool listDeleted) const { std::vector ids; for (typename std::map::const_iterator iter = mIndex.begin(); iter!=mIndex.end(); ++iter) { - if (!mRecords[iter->second].isDeleted()) + if (listDeleted || !mRecords[iter->second].isDeleted()) ids.push_back (IdAccessorT().getId (mRecords[iter->second].get())); } diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index 16b88e5e1..ff6dab247 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -79,10 +79,10 @@ namespace CSMWorld virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0; ///< \param type Will be ignored, unless the collection supports multiple record types - virtual std::vector getIds() const = 0; + virtual std::vector getIds (bool listDeleted = true) const = 0; ///< Return a sorted collection of all IDs /// - /// \note Deleted records are not listed. + /// \param listDeleted include deleted record in the list }; } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 06fbf61bf..7eb96a5c3 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -35,9 +35,10 @@ void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type } } -void CSMWorld::Data::appendIds (std::vector& ids, const CollectionBase& collection) +void CSMWorld::Data::appendIds (std::vector& ids, const CollectionBase& collection, + bool listDeleted) { - std::vector ids2 = collection.getIds(); + std::vector ids2 = collection.getIds (listDeleted); ids.insert (ids.end(), ids2.begin(), ids2.end()); } @@ -459,22 +460,22 @@ bool CSMWorld::Data::hasId (const std::string& id) const getReferenceables().searchId (id)!=-1; } -std::vector CSMWorld::Data::getIds() const +std::vector CSMWorld::Data::getIds (bool listDeleted) const { std::vector ids; - appendIds (ids, mGlobals); - appendIds (ids, mGmsts); - appendIds (ids, mClasses); - appendIds (ids, mFactions); - appendIds (ids, mRaces); - appendIds (ids, mSounds); - appendIds (ids, mScripts); - appendIds (ids, mRegions); - appendIds (ids, mBirthsigns); - appendIds (ids, mSpells); - appendIds (ids, mCells); - appendIds (ids, mReferenceables); + appendIds (ids, mGlobals, listDeleted); + appendIds (ids, mGmsts, listDeleted); + appendIds (ids, mClasses, listDeleted); + appendIds (ids, mFactions, listDeleted); + appendIds (ids, mRaces, listDeleted); + appendIds (ids, mSounds, listDeleted); + appendIds (ids, mScripts, listDeleted); + appendIds (ids, mRegions, listDeleted); + appendIds (ids, mBirthsigns, listDeleted); + appendIds (ids, mSpells, listDeleted); + appendIds (ids, mCells, listDeleted); + appendIds (ids, mReferenceables, listDeleted); std::sort (ids.begin(), ids.end()); @@ -483,9 +484,8 @@ std::vector CSMWorld::Data::getIds() const void CSMWorld::Data::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) { - // Note: The performance of of ID list change updates could be improved only emit the signal, if - // the state of the record is changed. - emit idListChanged(); + if (topLeft.column()<=0) + emit idListChanged(); } void CSMWorld::Data::rowsChanged (const QModelIndex& parent, int start, int end) diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index 1b024751d..e900bb10f 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -62,7 +62,8 @@ namespace CSMWorld void addModel (QAbstractItemModel *model, UniversalId::Type type1, UniversalId::Type type2 = UniversalId::Type_None, bool update = true); - static void appendIds (std::vector& ids, const CollectionBase& collection); + static void appendIds (std::vector& ids, const CollectionBase& collection, + bool listDeleted); ///< Append all IDs from collection to \a ids. public: @@ -145,10 +146,10 @@ namespace CSMWorld bool hasId (const std::string& id) const; - std::vector getIds() const; + std::vector getIds (bool listDeleted = true) const; ///< Return a sorted collection of all IDs that are not internal to the editor. /// - /// \note Deleted records are not listed. + /// \param listDeleted include deleted record in the list signals: diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 5aadb1be3..cda2711cc 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -535,7 +535,7 @@ int CSMWorld::RefIdCollection::getAppendIndex (UniversalId::Type type) const return mData.getAppendIndex (type); } -std::vector CSMWorld::RefIdCollection::getIds() const +std::vector CSMWorld::RefIdCollection::getIds (bool listDeleted) const { - return mData.getIds(); + return mData.getIds (listDeleted); } diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index b6c8efdce..22f83150d 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -90,10 +90,10 @@ namespace CSMWorld virtual int getAppendIndex (UniversalId::Type type) const; ///< \param type Will be ignored, unless the collection supports multiple record types - virtual std::vector getIds() const; + virtual std::vector getIds (bool listDeleted) const; ///< Return a sorted collection of all IDs /// - /// \note Deleted records are not listed. + /// \param listDeleted include deleted record in the list }; } diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index fca0d8a71..9457937f1 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -197,14 +197,14 @@ int CSMWorld::RefIdData::getSize() const return mIndex.size(); } -std::vector CSMWorld::RefIdData::getIds() const +std::vector CSMWorld::RefIdData::getIds (bool listDeleted) const { std::vector ids; for (std::map::const_iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter) { - if (!getRecord (iter->second).isDeleted()) + if (listDeleted || !getRecord (iter->second).isDeleted()) { std::map::const_iterator container = mRecordContainers.find (iter->second.second); diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index bb8c83360..e221fbc7c 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -183,10 +183,10 @@ namespace CSMWorld int getSize() const; - std::vector getIds() const; + std::vector getIds (bool listDeleted = true) const; ///< Return a sorted collection of all IDs /// - /// \note Deleted records are not listed. + /// \param listDeleted include deleted record in the list }; } From 244e5819529e2be6e4c0a790442d228fc4a133fc Mon Sep 17 00:00:00 2001 From: graffy76 Date: Thu, 19 Sep 2013 06:53:09 -0500 Subject: [PATCH 35/42] Finished implementing drag / drop refactored datafilesmodel (now contentmodel) refactored esmfil --- components/esxselector/model/contentmodel.cpp | 302 ++++++++---------- components/esxselector/model/contentmodel.hpp | 19 +- components/esxselector/model/esmfile.cpp | 67 +++- components/esxselector/model/esmfile.hpp | 50 +-- .../esxselector/view/contentselector.cpp | 6 +- files/ui/datafilespage.ui | 39 +-- 6 files changed, 224 insertions(+), 259 deletions(-) diff --git a/components/esxselector/model/contentmodel.cpp b/components/esxselector/model/contentmodel.cpp index bfbb1bef7..d23ea7801 100644 --- a/components/esxselector/model/contentmodel.cpp +++ b/components/esxselector/model/contentmodel.cpp @@ -1,17 +1,37 @@ #include "contentmodel.hpp" #include "esmfile.hpp" -#include + #include #include #include +#include EsxModel::ContentModel::ContentModel(QObject *parent) : - QAbstractTableModel(parent), mEncoding("win1252") -{} + QAbstractTableModel(parent), + mMimeType ("application/omwcontent"), + mMimeTypes (QStringList() << mMimeType), + mColumnCount (1), + mDragDropFlags (Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled), + mDefaultFlags (Qt::ItemIsDropEnabled | Qt::ItemIsSelectable), + mDropActions (Qt::CopyAction | Qt::MoveAction) +{ + setEncoding ("win1252"); + uncheckAll(); +} void EsxModel::ContentModel::setEncoding(const QString &encoding) { - mEncoding = encoding; + if (encoding == QLatin1String("win1252")) + mCodec = QTextCodec::codecForName("windows-1252"); + + else if (encoding == QLatin1String("win1251")) + mCodec = QTextCodec::codecForName("windows-1251"); + + else if (encoding == QLatin1String("win1250")) + mCodec = QTextCodec::codecForName("windows-1250"); + + else + return; // This should never happen; } int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const @@ -19,7 +39,7 @@ int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const if (parent.isValid()) return 0; - return 1; + return mColumnCount; } int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const @@ -30,22 +50,28 @@ int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const return mFiles.size(); } -EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const +const EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const +{ + if (row >= 0 && row < mFiles.size()) + return mFiles.at(row); + + return 0; +} + +EsxModel::EsmFile *EsxModel::ContentModel::item(int row) { if (row >= 0 && row < mFiles.count()) return mFiles.at(row); return 0; } - -EsxModel::EsmFile* EsxModel::ContentModel::findItem(const QString &name) +const EsxModel::EsmFile *EsxModel::ContentModel::findItem(const QString &name) const { - for (int i = 0; i < mFiles.size(); ++i) + foreach (const EsmFile *file, mFiles) { - if (name == item(i)->fileName()) - return item(i); + if (name == file->fileName()) + return file; } - return 0; } @@ -62,19 +88,15 @@ Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const if (!index.isValid()) return Qt::NoItemFlags; - EsmFile *file = item(index.row()); + const EsmFile *file = item(index.row()); if (!file) return Qt::NoItemFlags; - Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; - Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable; - Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; - if (canBeChecked(file)) - return Qt::ItemIsEnabled | dragDropFlags | checkFlags | defaultFlags; - else - return defaultFlags; + return Qt::ItemIsEnabled | mDragDropFlags | mDefaultFlags; + + return mDefaultFlags; } QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const @@ -85,7 +107,7 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const if (index.row() >= mFiles.size()) return QVariant(); - EsmFile *file = item(index.row()); + const EsmFile *file = item(index.row()); if (!file) return QVariant(); @@ -97,25 +119,11 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const case Qt::EditRole: case Qt::DisplayRole: { - switch (column) - { - case 0: - return file->fileName(); - case 1: - return file->author(); - case 2: - return file->modified().toString(Qt::ISODate); - case 3: - return file->version(); - case 4: - return file->path(); - case 5: - return file->masters().join(", "); - case 6: - return file->description(); - } + if (column >=0 && column <=EsmFile::FileProperty_Master) + return file->fileProperty(static_cast(column)); return QVariant(); + break; } case Qt::TextAlignmentRole: @@ -132,6 +140,7 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const return Qt::AlignLeft + Qt::AlignVCenter; } return QVariant(); + break; } case Qt::ToolTipRole: @@ -139,23 +148,16 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const if (column != 0) return QVariant(); - if (file->version() == 0.0f) - return QVariant(); // Data not set - - return QString("Author: %1
\ - Version: %2
\ -
Description:
%3
\ -
Dependencies: %4
") - .arg(file->author()) - .arg(QString::number(file->version())) - .arg(file->description()) - .arg(file->masters().join(", ")); + return file->toolTip(); + break; } case Qt::CheckStateRole: + { if (!file->isMaster()) return isChecked(file->fileName()); break; + } case Qt::UserRole: { @@ -179,64 +181,63 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v EsmFile *file = item(index.row()); QString fileName = file->fileName(); + bool success = false; switch(role) { case Qt::EditRole: - { - QStringList list = value.toStringList(); + { + QStringList list = value.toStringList(); - //iterate the string list, assigning values to proeprties - //index-enum correspondence 1:1 - for (int i = 0; i < EsxModel::Property_Master; i++) - file->setProperty(static_cast(i), list.at(i)); + for (int i = 0; i < EsmFile::FileProperty_Master; i++) + file->setFileProperty(static_cast(i), list.at(i)); - //iterate the remainder of the string list, assifning everything - // as - for (int i = EsxModel::Property_Master; i < list.size(); i++) - file->setProperty (EsxModel::Property_Master, list.at(i)); + for (int i = EsmFile::FileProperty_Master; i < list.size(); i++) + file->setFileProperty (EsmFile::FileProperty_Master, list.at(i)); - //emit data changed for the item itself - emit dataChanged(index, index); + emit dataChanged(index, index); - return true; - } - break; + success = true; + } + break; case Qt::UserRole+1: + { + setCheckState(fileName, value.toBool()); + + emit dataChanged(index, index); + + foreach (EsmFile *file, mFiles) { - setCheckState(fileName, value.toBool()); - - emit dataChanged(index, index); - - for(int i = 0; i < mFiles.size(); i++) + if (file->masters().contains(fileName)) { - - if (mFiles.at(i)->masters().contains(fileName)) - { - QModelIndex idx = QAbstractTableModel::index(i, 0); - emit dataChanged(idx, idx); - } + QModelIndex idx = indexFromItem(file); + emit dataChanged(idx, idx); } - - return true; } - break; + success = true; + } + break; case Qt::CheckStateRole: - { - bool checked = ((value.toInt() == Qt::Checked) && !isChecked(fileName)); + { + int checkValue = value.toInt(); - setCheckState(fileName, checked); + if ((checkValue==Qt::Checked) && !isChecked(fileName)) + setCheckState(fileName, true); + else if ((checkValue == Qt::Checked) && isChecked (fileName)) + setCheckState(fileName, false); + else if (checkValue == Qt::Unchecked) + setCheckState(fileName, false); - emit dataChanged(index, index); + emit dataChanged(index, index); - return true; - } - break; + success = true; + } + break; } - return false; + return success; } bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent) @@ -271,16 +272,12 @@ bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelInde Qt::DropActions EsxModel::ContentModel::supportedDropActions() const { - return Qt::CopyAction | Qt::MoveAction; + return mDropActions; } QStringList EsxModel::ContentModel::mimeTypes() const { - QStringList types; - - types << "application/omwcontent"; - - return types; + return mMimeTypes; } QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) const @@ -292,14 +289,11 @@ QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) cons if (!index.isValid()) continue; - QByteArray fileData = item(index.row())->encodedData(); - - foreach (const char c, fileData) - encodedData.append(c); + encodedData.append(item(index.row())->encodedData()); } QMimeData *mimeData = new QMimeData(); - mimeData->setData("application/omwcontent", encodedData); + mimeData->setData(mMimeType, encodedData); return mimeData; } @@ -309,13 +303,13 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction if (action == Qt::IgnoreAction) return true; - if (!data->hasFormat("application/omwcontent")) - return false; - if (column > 0) return false; - int beginRow; + if (!data->hasFormat(mMimeType)) + return false; + + int beginRow = rowCount(); if (row != -1) beginRow = row; @@ -323,23 +317,28 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction else if (parent.isValid()) beginRow = parent.row(); - else - beginRow = rowCount(); - - QByteArray encodedData = data->data("application/omwcontent"); + QByteArray encodedData = data->data(mMimeType); QDataStream stream(&encodedData, QIODevice::ReadOnly); while (!stream.atEnd()) { - QStringList values; - for (int i = 0; i < EsmFile::sPropertyCount; ++i) - stream >> values; + QString value; + QStringList values; + QStringList masters; + + for (int i = 0; i < EsmFile::FileProperty_Master; ++i) + { + stream >> value; + values << value; + } + + stream >> masters; insertRows(beginRow, 1); QModelIndex idx = index(beginRow++, 0, QModelIndex()); - setData(idx, values, Qt::EditRole); + setData(idx, QStringList() << values << masters, Qt::EditRole); } return true; @@ -349,37 +348,8 @@ bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const { //element can be checked if all its dependencies are foreach (const QString &master, file->masters()) - { - {// if the master is not found in checkstates - // or it is not specifically checked, return false - if (!mCheckStates.contains(master)) - return false; - - if (!isChecked(master)) - return false; - } - - bool found = false; - - //iterate each file, if it is not a master and - //does not have a master that is currently checked, - //return false. - foreach(const EsmFile *file, mFiles) - { - QString filename = file->fileName(); - - found = (filename == master); - - if (found) - { - if (!isChecked(filename)) - return false; - } - } - - if (!found) + if (!isChecked(master)) return false; - } return true; } @@ -387,9 +357,8 @@ bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const void EsxModel::ContentModel::addFile(EsmFile *file) { beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); - { mFiles.append(file); - } endInsertRows(); + endInsertRows(); } void EsxModel::ContentModel::addFiles(const QString &path) @@ -400,45 +369,26 @@ void EsxModel::ContentModel::addFiles(const QString &path) dir.setNameFilters(filters); // Create a decoder for non-latin characters in esx metadata - QTextCodec *codec; + QTextDecoder *decoder = mCodec->makeDecoder(); - if (mEncoding == QLatin1String("win1252")) { - codec = QTextCodec::codecForName("windows-1252"); - } else if (mEncoding == QLatin1String("win1251")) { - codec = QTextCodec::codecForName("windows-1251"); - } else if (mEncoding == QLatin1String("win1250")) { - codec = QTextCodec::codecForName("windows-1250"); - } else { - return; // This should never happen; - } - - QTextDecoder *decoder = codec->makeDecoder(); - - foreach (const QString &path, dir.entryList()) { + foreach (const QString &path, dir.entryList()) + { QFileInfo info(dir.absoluteFilePath(path)); EsmFile *file = new EsmFile(path); try { ESM::ESMReader fileReader; - ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(mEncoding.toStdString())); + ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(QString(mCodec->name()).toStdString())); fileReader.setEncoder(&encoder); fileReader.open(dir.absoluteFilePath(path).toStdString()); - std::vector mlist = fileReader.getMasters(); + foreach (const ESM::Header::MasterData &item, fileReader.getMasters()) + file->addMaster(QString::fromStdString(item.name)); - QStringList masters; - - for (unsigned int i = 0; i < mlist.size(); ++i) { - QString master = QString::fromStdString(mlist[i].name); - masters.append(master); - } - - file->setAuthor(decoder->toUnicode(fileReader.getAuthor().c_str())); - //file->setSize(info.size()); - file->setDate(info.lastModified()); - file->setVersion(0.0f); - file->setPath(info.absoluteFilePath()); - file->setMasters(masters); + file->setAuthor (decoder->toUnicode(fileReader.getAuthor().c_str())); + file->setDate (info.lastModified()); + file->setVersion (fileReader.getFVer()); + file->setPath (info.absoluteFilePath()); file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str())); @@ -459,7 +409,10 @@ void EsxModel::ContentModel::addFiles(const QString &path) bool EsxModel::ContentModel::isChecked(const QString& name) const { - return (mCheckStates[name] == Qt::Checked); + if (mCheckStates.contains(name)) + return (mCheckStates[name] == Qt::Checked); + + return false; } void EsxModel::ContentModel::setCheckState(const QString &name, bool isChecked) @@ -479,12 +432,9 @@ EsxModel::ContentFileList EsxModel::ContentModel::checkedItems() const { ContentFileList list; - for (int i = 0; i < mFiles.size(); ++i) + foreach (EsmFile *file, mFiles) { - EsmFile *file = item(i); - - // Only add the items that are in the checked list and available - if (mCheckStates[file->fileName()] == Qt::Checked && canBeChecked(file)) + if (isChecked(file->fileName())) list << file; } diff --git a/components/esxselector/model/contentmodel.hpp b/components/esxselector/model/contentmodel.hpp index 61c823ab3..6a2dd88ca 100644 --- a/components/esxselector/model/contentmodel.hpp +++ b/components/esxselector/model/contentmodel.hpp @@ -2,7 +2,7 @@ #define CONTENTMODEL_HPP #include - +#include namespace EsxModel { class EsmFile; @@ -35,7 +35,7 @@ namespace EsxModel void addFiles(const QString &path); QModelIndex indexFromItem(EsmFile *item) const; - EsxModel::EsmFile *findItem(const QString &name); + const EsxModel::EsmFile *findItem(const QString &name) const; bool isChecked(const QString &name) const; void setCheckState(const QString &name, bool isChecked); @@ -45,16 +45,21 @@ namespace EsxModel private: void addFile(EsmFile *file); - EsmFile* item(int row) const; + const EsmFile *item(int row) const; + EsmFile *item(int row); bool canBeChecked(const EsmFile *file) const; ContentFileList mFiles; QHash mCheckStates; - QString mEncoding; + QTextCodec *mCodec; - signals: - - public slots: + public: + QString mMimeType; + QStringList mMimeTypes; + int mColumnCount; + Qt::ItemFlags mDragDropFlags; + Qt::ItemFlags mDefaultFlags; + Qt::DropActions mDropActions; }; } diff --git a/components/esxselector/model/esmfile.cpp b/components/esxselector/model/esmfile.cpp index 0e7f18373..bd76dc4a0 100644 --- a/components/esxselector/model/esmfile.cpp +++ b/components/esxselector/model/esmfile.cpp @@ -4,19 +4,15 @@ #include int EsxModel::EsmFile::sPropertyCount = 7; +QString EsxModel::EsmFile::sToolTip = QString("Author: %1
\ + Version: %2
\ +
Description:
%3
\ +
Dependencies: %4
"); + EsxModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) : ModelItem(parent), mFileName(fileName), mVersion(0.0f) {} -/* -EsxModel::EsmFile::EsmFile(const EsmFile &file) - : ModelItem(file.parent()), mFileName(file.mFileName), mSize(file.mSize), - mVersion(file.mVersion), mAuthor(file.mAuthor), mModified(file.mModified), - mAccessed(file.mAccessed), mPath(file.mPath), mMasters(file.mMasters), - mDescription(file.mDescription) -{} - -*/ void EsxModel::EsmFile::setFileName(const QString &fileName) { mFileName = fileName; @@ -64,35 +60,72 @@ QByteArray EsxModel::EsmFile::encodedData() const return encodedData; } -void EsxModel::EsmFile::setProperty (const EsmFileProperty prop, const QString &value) +QVariant EsxModel::EsmFile::fileProperty(const FileProperty prop) const { switch (prop) { - case Property_FileName: + case FileProperty_FileName: + return mFileName; + break; + + case FileProperty_Author: + return mAuthor; + break; + + case FileProperty_Version: + return mVersion; + break; + + case FileProperty_DateModified: + return mModified.toString(Qt::ISODate); + break; + + case FileProperty_Path: + return mPath; + break; + + case FileProperty_Description: + return mDescription; + break; + + case FileProperty_Master: + return mMasters; + break; + + default: + break; + } + return QVariant(); +} +void EsxModel::EsmFile::setFileProperty (const FileProperty prop, const QString &value) +{ + switch (prop) + { + case FileProperty_FileName: mFileName = value; break; - case Property_Author: + case FileProperty_Author: mAuthor = value; break; - case Property_Version: + case FileProperty_Version: mVersion = value.toFloat(); break; - case Property_DateModified: + case FileProperty_DateModified: mModified = QDateTime::fromString(value); break; - case Property_Path: + case FileProperty_Path: mPath = value; break; - case Property_Description: + case FileProperty_Description: mDescription = value; break; - case Property_Master: + case FileProperty_Master: mMasters << value; break; diff --git a/components/esxselector/model/esmfile.hpp b/components/esxselector/model/esmfile.hpp index 9a1ea8af1..4f6d7a624 100644 --- a/components/esxselector/model/esmfile.hpp +++ b/components/esxselector/model/esmfile.hpp @@ -10,17 +10,6 @@ class QMimeData; namespace EsxModel { - enum EsmFileProperty - { - Property_FileName = 0, - Property_Author = 1, - Property_Version = 2, - Property_DateModified = 3, - Property_Path = 4, - Property_Description = 5, - Property_Master = 6 - }; - class EsmFile : public ModelItem { Q_OBJECT @@ -28,13 +17,24 @@ namespace EsxModel public: + enum FileProperty + { + FileProperty_FileName = 0, + FileProperty_Author = 1, + FileProperty_Version = 2, + FileProperty_DateModified = 3, + FileProperty_Path = 4, + FileProperty_Description = 5, + FileProperty_Master = 6 + }; + EsmFile(QString fileName = QString(), ModelItem *parent = 0); // EsmFile(const EsmFile &); ~EsmFile() {} - void setProperty (const EsmFileProperty prop, const QString &value); + void setFileProperty (const FileProperty prop, const QString &value); void setFileName(const QString &fileName); void setAuthor(const QString &author); @@ -45,19 +45,28 @@ namespace EsxModel void setMasters(const QStringList &masters); void setDescription(const QString &description); - inline QString fileName() const { return mFileName; } - inline QString author() const { return mAuthor; } - inline QDateTime modified() const { return mModified; } - inline float version() const { return mVersion; } - inline QString path() const { return mPath; } - inline QStringList masters() const { return mMasters; } - inline QString description() const { return mDescription; } + inline void addMaster (const QString &name) {mMasters.append(name); } + QVariant fileProperty (const FileProperty prop) const; - inline bool isMaster() const { return (mMasters.size() == 0); } + inline QString fileName() const { return mFileName; } + inline QString author() const { return mAuthor; } + inline QDateTime modified() const { return mModified; } + inline float version() const { return mVersion; } + inline QString path() const { return mPath; } + inline const QStringList &masters() const { return mMasters; } + inline QString description() const { return mDescription; } + inline QString toolTip() const { return sToolTip.arg(mAuthor) + .arg(mVersion) + .arg(mDescription) + .arg(mMasters.join(", ")); + } + + inline bool isMaster() const { return (mMasters.size() == 0); } QByteArray encodedData() const; public: static int sPropertyCount; + static QString sToolTip; private: @@ -68,6 +77,7 @@ namespace EsxModel QString mPath; QStringList mMasters; QString mDescription; + QString mToolTip; }; } diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp index 1f5e36d65..4f8ac7253 100644 --- a/components/esxselector/view/contentselector.cpp +++ b/components/esxselector/view/contentselector.cpp @@ -54,11 +54,9 @@ void EsxView::ContentSelector::buildPluginsView() mPluginsProxyModel->setDynamicSortFilter (true); mPluginsProxyModel->setSourceModel (mContentModel); - tableView->setModel (mPluginsProxyModel); pluginView->setModel(mPluginsProxyModel); connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); - connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &))); } void EsxView::ContentSelector::buildProfilesView() @@ -120,10 +118,12 @@ void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index) proxy->setDynamicSortFilter(false); if (oldIndex > -1) + qDebug() << "clearing old master check state"; model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); oldIndex = index; + qDebug() << "setting new master check state"; model->setData(model->index(index, 0), true, Qt::UserRole + 1); if (proxy) @@ -132,8 +132,6 @@ void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index) void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) { - qDebug() << "setting checkstate in plugin..."; - QAbstractItemModel *const model = pluginView->model(); QSortFilterProxyModel *proxy = dynamic_cast(model); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 76689627b..5b0a6d229 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -7,7 +7,7 @@ 0 0 518 - 310 + 313 @@ -44,6 +44,9 @@ Qt::DefaultContextMenu + + true + QAbstractItemView::NoEditTriggers @@ -85,40 +88,6 @@
- - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - QAbstractItemView::DragDrop - - - Qt::MoveAction - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - false - - - false - - -
From 8d4f4e395fc596fc15e7b3e0156e21608a51e072 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 19 Sep 2013 14:26:09 +0200 Subject: [PATCH 36/42] update syntax highlighting when ID list changes --- apps/opencs/view/world/scripthighlighter.cpp | 4 +++ apps/opencs/view/world/scripthighlighter.hpp | 2 ++ apps/opencs/view/world/scriptsubview.cpp | 31 +++++++++++++++++++- apps/opencs/view/world/scriptsubview.hpp | 14 ++++++++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/scripthighlighter.cpp b/apps/opencs/view/world/scripthighlighter.cpp index a16077f8a..e06dab372 100644 --- a/apps/opencs/view/world/scripthighlighter.cpp +++ b/apps/opencs/view/world/scripthighlighter.cpp @@ -125,5 +125,9 @@ void CSVWorld::ScriptHighlighter::highlightBlock (const QString& text) scanner.scan (*this); } catch (...) {} // ignore syntax errors +} +void CSVWorld::ScriptHighlighter::invalidateIds() +{ + mContext.invalidateIds(); } \ No newline at end of file diff --git a/apps/opencs/view/world/scripthighlighter.hpp b/apps/opencs/view/world/scripthighlighter.hpp index e29a66490..495c2e6a3 100644 --- a/apps/opencs/view/world/scripthighlighter.hpp +++ b/apps/opencs/view/world/scripthighlighter.hpp @@ -77,6 +77,8 @@ namespace CSVWorld ScriptHighlighter (const CSMWorld::Data& data, QTextDocument *parent); virtual void highlightBlock (const QString& text); + + void invalidateIds(); }; } diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index 6a7ec752f..446c34e5f 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -58,7 +58,13 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc: connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int))); - new ScriptHighlighter (document.getData(), mEditor->document()); + connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged())); + + mHighlighter = new ScriptHighlighter (document.getData(), mEditor->document()); + + connect (&mUpdateTimer, SIGNAL (timeout()), this, SLOT (updateHighlighting())); + + mUpdateTimer.setSingleShot (true); } void CSVWorld::ScriptSubView::setEditLock (bool locked) @@ -66,8 +72,19 @@ void CSVWorld::ScriptSubView::setEditLock (bool locked) mEditor->setReadOnly (locked); } +void CSVWorld::ScriptSubView::idListChanged() +{ + mHighlighter->invalidateIds(); + + if (!mUpdateTimer.isActive()) + mUpdateTimer.start (0); +} + void CSVWorld::ScriptSubView::textChanged() { + if (mChangeLocked) + return; + ChangeLock lock (*this); mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*mModel, @@ -79,6 +96,8 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo if (mChangeLocked) return; + ChangeLock lock (*this); + QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn); if (index.row()>=topLeft.row() && index.row()<=bottomRight.row() && @@ -96,4 +115,14 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i if (!parent.isValid() && index.row()>=start && index.row()<=end) deleteLater(); +} + +void CSVWorld::ScriptSubView::updateHighlighting() +{ + if (mChangeLocked) + return; + + ChangeLock lock (*this); + + mHighlighter->rehighlight(); } \ No newline at end of file diff --git a/apps/opencs/view/world/scriptsubview.hpp b/apps/opencs/view/world/scriptsubview.hpp index 07d87d947..7ceab70ba 100644 --- a/apps/opencs/view/world/scriptsubview.hpp +++ b/apps/opencs/view/world/scriptsubview.hpp @@ -3,6 +3,8 @@ #include "../doc/subview.hpp" +#include + class QTextEdit; class QModelIndex; @@ -18,6 +20,8 @@ namespace CSMWorld namespace CSVWorld { + class ScriptHighlighter; + class ScriptSubView : public CSVDoc::SubView { Q_OBJECT @@ -27,6 +31,8 @@ namespace CSVWorld CSMWorld::IdTable *mModel; int mColumn; int mChangeLocked; + ScriptHighlighter *mHighlighter; + QTimer mUpdateTimer; class ChangeLock { @@ -49,13 +55,19 @@ namespace CSVWorld virtual void setEditLock (bool locked); - private slots: + public slots: + + void idListChanged(); void textChanged(); void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end); + + private slots: + + void updateHighlighting(); }; } From 58bb0b8773bfbe0ba832590d12fdf17ebd65e109 Mon Sep 17 00:00:00 2001 From: Xethik Date: Fri, 20 Sep 2013 21:26:12 -0400 Subject: [PATCH 37/42] Bug #907 Added a check to make sure playerview is allowed when attempting to scroll, locking out zooming before character creation. --- apps/openmw/mwinput/inputmanagerimp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 1039a0dce..430a5d843 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -585,7 +585,7 @@ namespace MWInput mPlayer->pitch(-y/scale); } - if (arg.zrel) + if (arg.zrel && mControlSwitch["playerviewswitch"]) //Check to make sure you are allowed to zoomout and there is a change { MWBase::Environment::get().getWorld()->changeVanityModeScale(arg.zrel); MWBase::Environment::get().getWorld()->setCameraDistance(arg.zrel, true, true); From 094e4d93b7ac90ab0a688140a6ad2f4588687a9b Mon Sep 17 00:00:00 2001 From: Xethik Date: Fri, 20 Sep 2013 21:38:10 -0400 Subject: [PATCH 38/42] Generally speaking, you should never compare iterators from two different compilers http://stackoverflow.com/questions/4657513/comparing-iterators-from-different-containers It seems like this was just an overlook that happened to work on most systems. I was not able to thoroughly test this change, but it fixed an issue I was having in VC10. It's possible the prev.end() was a copy paste error that was meant to be new.end() anyways. --- apps/openmw/mwmechanics/magiceffects.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index 1a7b34817..32ac1e088 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -151,8 +151,7 @@ namespace MWMechanics for (Collection::const_iterator iter (prev.begin()); iter!=prev.end(); ++iter) { Collection::const_iterator other = now.mCollection.find (iter->first); - - if (other==prev.end()) + if (other==now.end()) { result.add (iter->first, EffectParam() - iter->second); } From 94bb97e766854d6042686ebb2ea773c98f30f13a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 21 Sep 2013 08:40:00 +0200 Subject: [PATCH 39/42] replacing tabs with spaces --- apps/openmw/mwmechanics/magiceffects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index 32ac1e088..3ed458c3f 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -151,7 +151,7 @@ namespace MWMechanics for (Collection::const_iterator iter (prev.begin()); iter!=prev.end(); ++iter) { Collection::const_iterator other = now.mCollection.find (iter->first); - if (other==now.end()) + if (other==now.end()) { result.add (iter->first, EffectParam() - iter->second); } From 4e5e3bd694d2cd9ca47846f369b05df3735e6f3a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 21 Sep 2013 10:04:31 +0200 Subject: [PATCH 40/42] updated credits file --- credits.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/credits.txt b/credits.txt index 9a84c5327..c766c34c3 100644 --- a/credits.txt +++ b/credits.txt @@ -47,6 +47,7 @@ Marc Bouvier (CramitDeFrog) Marcin Hulist (Gohan) Mark Siewert (mark76) Mateusz KoÅ‚aczek (PL_kolek) +Michael Hogan (Xethik) Michael Mc Donnell Michael Papageorgiou (werdanith) MichaÅ‚ BieÅ„ (Glorf) From cfdc19c4272804b9ed682704e8fa30d31a85a062 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 21 Sep 2013 23:06:29 -0500 Subject: [PATCH 41/42] Renamed esxSelector to contentSelector Fixed datafilespage model implementation in launcher Filtered addons in table view by selected game file --- apps/esmtool/esmtool.cpp | 4 +- apps/launcher/datafilespage.cpp | 195 ++++-- apps/launcher/datafilespage.hpp | 32 +- apps/launcher/graphicspage.cpp | 2 +- apps/launcher/utils/textinputdialog.cpp | 4 +- apps/launcher/utils/textinputdialog.hpp | 7 +- apps/opencs/editor.cpp | 4 +- apps/opencs/main.cpp | 2 +- apps/opencs/view/doc/filedialog.cpp | 12 +- apps/opencs/view/doc/filedialog.hpp | 6 +- apps/openmw/mwworld/esmstore.cpp | 2 +- components/CMakeLists.txt | 7 +- .../model/contentmodel.cpp | 137 ++-- .../model/contentmodel.hpp | 15 +- .../model/esmfile.cpp | 53 +- .../model/esmfile.hpp | 42 +- .../contentselector/model/modelitem.cpp | 69 ++ .../model/modelitem.hpp | 2 +- .../model/naturalsort.cpp | 0 .../model/naturalsort.hpp | 0 .../view/comboboxlineedit.cpp | 6 +- .../view/comboboxlineedit.hpp | 2 +- .../contentselector/view/contentselector.cpp | 134 ++++ .../view/contentselector.hpp | 32 +- .../view/lineedit.cpp | 6 +- .../view/lineedit.hpp | 2 +- .../view/profilescombobox.cpp | 14 +- .../view/profilescombobox.hpp | 2 +- components/esm/esmreader.hpp | 2 +- components/esm/loadcell.cpp | 4 +- .../esxselector/model/datafilesmodel.cpp | 608 ------------------ .../esxselector/model/datafilesmodel.hpp | 80 --- .../esxselector/model/masterproxymodel.cpp | 13 - .../esxselector/model/masterproxymodel.hpp | 25 - components/esxselector/model/modelitem.cpp | 69 -- .../esxselector/model/pluginsproxymodel.cpp | 14 - .../esxselector/model/pluginsproxymodel.hpp | 28 - components/esxselector/model/sourcemodel.cpp | 6 - components/esxselector/model/sourcemodel.h | 18 - .../esxselector/view/contentselector.cpp | 148 ----- files/ui/datafilespage.ui | 12 +- 41 files changed, 585 insertions(+), 1235 deletions(-) rename components/{esxselector => contentselector}/model/contentmodel.cpp (64%) rename components/{esxselector => contentselector}/model/contentmodel.hpp (86%) rename components/{esxselector => contentselector}/model/esmfile.cpp (54%) rename components/{esxselector => contentselector}/model/esmfile.hpp (58%) create mode 100644 components/contentselector/model/modelitem.cpp rename components/{esxselector => contentselector}/model/modelitem.hpp (96%) rename components/{esxselector => contentselector}/model/naturalsort.cpp (100%) rename components/{esxselector => contentselector}/model/naturalsort.hpp (100%) rename components/{esxselector => contentselector}/view/comboboxlineedit.cpp (83%) rename components/{esxselector => contentselector}/view/comboboxlineedit.hpp (96%) create mode 100644 components/contentselector/view/contentselector.cpp rename components/{esxselector => contentselector}/view/contentselector.hpp (51%) rename components/{esxselector => contentselector}/view/lineedit.cpp (87%) rename components/{esxselector => contentselector}/view/lineedit.hpp (96%) rename components/{esxselector => contentselector}/view/profilescombobox.cpp (83%) rename components/{esxselector => contentselector}/view/profilescombobox.hpp (96%) delete mode 100644 components/esxselector/model/datafilesmodel.cpp delete mode 100644 components/esxselector/model/datafilesmodel.hpp delete mode 100644 components/esxselector/model/masterproxymodel.cpp delete mode 100644 components/esxselector/model/masterproxymodel.hpp delete mode 100644 components/esxselector/model/modelitem.cpp delete mode 100644 components/esxselector/model/pluginsproxymodel.cpp delete mode 100644 components/esxselector/model/pluginsproxymodel.hpp delete mode 100644 components/esxselector/model/sourcemodel.cpp delete mode 100644 components/esxselector/model/sourcemodel.h delete mode 100644 components/esxselector/view/contentselector.cpp diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index a60e9f0e2..6ccf9c3f3 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -305,14 +305,14 @@ int load(Arguments& info) info.data.author = esm.getAuthor(); info.data.description = esm.getDesc(); - info.data.masters = esm.getMasters(); + info.data.masters = esm.getGameFiles(); if (!quiet) { std::cout << "Author: " << esm.getAuthor() << std::endl << "Description: " << esm.getDesc() << std::endl << "File format version: " << esm.getFVer() << std::endl; - std::vector m = esm.getMasters(); + std::vector m = esm.getGameFiles(); if (!m.empty()) { std::cout << "Masters:" << std::endl; diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 7069737ef..1526b705a 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -4,22 +4,22 @@ #include #include #include +#include #include -#include -#include +#include -#include -#include -#include +#include +#include +#include -#include "components/esxselector/model/masterproxymodel.hpp" #include "settings/gamesettings.hpp" #include "settings/launchersettings.hpp" #include "utils/textinputdialog.hpp" -#include "components/esxselector/view/contentselector.hpp" +#include "components/contentselector/view/contentselector.hpp" +#include "components/contentselector/model/contentmodel.hpp" #include @@ -28,8 +28,10 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , mGameSettings(gameSettings) , mLauncherSettings(launcherSettings) { - mContentSelector.setParent(parent); - QMetaObject::connectSlotsByName(this); + setupUi(this); + // mContentSelector.setParent(parent); + + // QMetaObject::connectSlotsByName(this); projectGroupBox->hide(); @@ -38,8 +40,82 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString))); + + + buildContentModel(); + buildGameFileView(); + buildAddonView(); + buildProfilesView(); + + createActions(); setupDataFiles(); + + + updateViews(); +} + +void DataFilesPage::buildContentModel() +{ + mContentModel = new ContentSelectorModel::ContentModel(); + connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); +} + +void DataFilesPage::buildGameFileView() +{ + mGameFileProxyModel = new QSortFilterProxyModel(this); + mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile)); + mGameFileProxyModel->setFilterRole (Qt::UserRole); + mGameFileProxyModel->setSourceModel (mContentModel); + + gameFileView->setPlaceholderText(QString("Select a game file...")); + gameFileView->setModel(mGameFileProxyModel); + + connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentGameFileIndexChanged(int))); + + gameFileView->setCurrentIndex(-1); + gameFileView->setCurrentIndex(0); +} + +void DataFilesPage::buildAddonView() +{ + mAddonProxyModel = new QSortFilterProxyModel(this); + mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon)); + mAddonProxyModel->setFilterRole (Qt::UserRole); + mAddonProxyModel->setDynamicSortFilter (true); + mAddonProxyModel->setSourceModel (mContentModel); + + addonView->setModel(mAddonProxyModel); + + connect(addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &))); +} + +void DataFilesPage::buildProfilesView() +{ + profilesComboBox->setPlaceholderText(QString("Select a profile...")); + connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); +} + +void DataFilesPage::updateViews() +{ + // Ensure the columns are hidden because sort() re-enables them + addonView->setColumnHidden(1, true); + addonView->setColumnHidden(2, true); + addonView->setColumnHidden(3, true); + addonView->setColumnHidden(4, true); + addonView->setColumnHidden(5, true); + addonView->setColumnHidden(6, true); + addonView->setColumnHidden(7, true); + addonView->setColumnHidden(8, true); + addonView->resizeColumnsToContents(); +} + +void ContentSelectorView::ContentSelector::addFiles(const QString &path) +{ + mContentModel->addFiles(path); + //mContentModel->sort(3); // Sort by date accessed + gameFileView->setCurrentIndex(-1); + mContentModel->uncheckAll(); } void DataFilesPage::createActions() @@ -52,17 +128,19 @@ void DataFilesPage::createActions() void DataFilesPage::setupDataFiles() { // Set the encoding to the one found in openmw.cfg or the default - mContentSelector.setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); + //mContentSelector.setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); QStringList paths = mGameSettings.getDataDirs(); foreach (const QString &path, paths) { - mContentSelector.addFiles(path); + //mContentSelector. + mContentModel->addFiles(path); } QString dataLocal = mGameSettings.getDataLocal(); if (!dataLocal.isEmpty()) - mContentSelector.addFiles(dataLocal); + //mContentSelector. + mContentModel->addFiles(dataLocal); // Sort by date accessed for now //mContentSelector->sort(3); @@ -95,6 +173,7 @@ void DataFilesPage::setupDataFiles() loadSettings(); + gameFileView->setCurrentIndex(-1); } void DataFilesPage::loadSettings() @@ -104,29 +183,17 @@ void DataFilesPage::loadSettings() if (profile.isEmpty()) return; - // mContentSelector.uncheckAll(); + // mContentSelector. + mContentModel->uncheckAll(); - QStringList masters = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly); - QStringList plugins = mLauncherSettings.values(QString("Profiles/") + profile + QString("/plugin"), Qt::MatchExactly); -/* - foreach (const QString &master, masters) { - QModelIndex index = mDataFilesModel->indexFromItem(mDataFilesModel->findItem(master)); - if (index.isValid()) - mDataFilesModel->setCheckState(index, Qt::Checked); - } - - foreach (const QString &plugin, plugins) { - QModelIndex index = mDataFilesModel->indexFromItem(mDataFilesModel->findItem(plugin)); - if (index.isValid()) - mDataFilesModel->setCheckState(index, Qt::Checked); - } - */ + QStringList gameFiles = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly); + QStringList addons = mLauncherSettings.values(QString("Profiles/") + profile + QString("/plugin"), Qt::MatchExactly); } void DataFilesPage::saveSettings() { -// if (mDataFilesModel->rowCount() < 1) -// return; + if (mContentModel->rowCount() < 1) + return; QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); @@ -141,11 +208,11 @@ void DataFilesPage::saveSettings() mGameSettings.remove(QString("master")); mGameSettings.remove(QString("plugin")); - // EsxModel::EsmFileList items = mDataFilesModel->checkedItems(); -/* - foreach(const EsxModel::EsmFile *item, items) { + ContentSelectorModel::ContentFileList items = mContentModel->checkedItems(); - if (item->masters().size() == 0) { + foreach(const ContentSelectorModel::EsmFile *item, items) { + + if (item->gameFiles().size() == 0) { mLauncherSettings.setMultiValue(QString("Profiles/") + profile + QString("/master"), item->fileName()); mGameSettings.setMultiValue(QString("master"), item->fileName()); @@ -154,7 +221,7 @@ void DataFilesPage::saveSettings() mGameSettings.setMultiValue(QString("plugin"), item->fileName()); } } -*/ + } void DataFilesPage::updateOkButton(const QString &text) @@ -223,23 +290,25 @@ void DataFilesPage::on_deleteProfileAction_triggered() void DataFilesPage::setPluginsCheckstates(Qt::CheckState state) { - if (!pluginView->selectionModel()->hasSelection()) { + if (!addonView->selectionModel()->hasSelection()) { return; } - QModelIndexList indexes = pluginView->selectionModel()->selectedIndexes(); + QModelIndexList indexes = addonView->selectionModel()->selectedIndexes(); foreach (const QModelIndex &index, indexes) { if (!index.isValid()) return; - QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index); + QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index); if (!sourceIndex.isValid()) return; - //mDataFilesModel->setCheckState(sourceIndex, state); + bool isChecked = ( state == Qt::Checked ); + + mContentModel->setData(sourceIndex, state, Qt::CheckStateRole); } } @@ -287,3 +356,51 @@ void DataFilesPage::profileRenamed(const QString &previous, const QString &curre loadSettings(); } +//////////////////////////// + +QStringList DataFilesPage::checkedItemsPaths() +{ + QStringList itemPaths; + + foreach( const ContentSelectorModel::EsmFile *file, mContentModel->checkedItems()) + itemPaths << file->path(); + + return itemPaths; +} + +void DataFilesPage::slotCurrentProfileIndexChanged(int index) +{ + emit profileChanged(index); +} + +void DataFilesPage::slotCurrentGameFileIndexChanged(int index) +{ + static int oldIndex = -1; + + QAbstractItemModel *const model = gameFileView->model(); + QSortFilterProxyModel *proxy = dynamic_cast(model); + + if (proxy) + proxy->setDynamicSortFilter(false); + + if (oldIndex > -1) + model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); + + oldIndex = index; + + model->setData(model->index(index, 0), true, Qt::UserRole + 1); + + if (proxy) + proxy->setDynamicSortFilter(true); +} + +void DataFilesPage::slotAddonTableItemClicked(const QModelIndex &index) +{ + QAbstractItemModel *const model = addonView->model(); + QSortFilterProxyModel *proxy = dynamic_cast(model); + + if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) + model->setData(index, Qt::Checked, Qt::CheckStateRole); + else + model->setData(index, Qt::Unchecked, Qt::CheckStateRole); +} diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index ed92da749..9c7b0538e 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -5,24 +5,24 @@ #include #include "ui_datafilespage.h" -#include "components/esxselector/view/contentselector.hpp" +#include "components/contentselector/view/contentselector.hpp" class QSortFilterProxyModel; class QAbstractItemModel; class QAction; class QMenu; -class DataFilesModel; class TextInputDialog; class GameSettings; class LauncherSettings; -class PluginsProxyModel; + namespace Files { struct ConfigurationManager; } -class DataFilesPage : public EsxView::ContentSelector +class DataFilesPage : public QWidget, private Ui::DataFilesPage { Q_OBJECT + public: DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent = 0); @@ -42,7 +42,7 @@ public slots: void profileChanged(const QString &previous, const QString ¤t); void profileRenamed(const QString &previous, const QString ¤t); void updateOkButton(const QString &text); - + void updateViews(); // Action slots void on_newProfileAction_triggered(); void on_deleteProfileAction_triggered(); @@ -52,14 +52,16 @@ private slots: private: QMenu *mContextMenu; - ContentSelector mContentSelector; - + //ContentSelectorView::ContentSelector mContentSelector; + ContentSelectorModel::ContentModel *mContentModel; Files::ConfigurationManager &mCfgMgr; GameSettings &mGameSettings; LauncherSettings &mLauncherSettings; TextInputDialog *mNewProfileDialog; + QSortFilterProxyModel *mGameFileProxyModel; + QSortFilterProxyModel *mAddonProxyModel; void setPluginsCheckstates(Qt::CheckState state); @@ -70,6 +72,22 @@ private: void loadSettings(); + ////////////////////////////////////// + void buildContentModel(); + void buildGameFileView(); + void buildAddonView(); + void buildProfilesView(); + + //void addFiles(const QString &path); + + QStringList checkedItemsPaths(); + +private slots: + void slotCurrentProfileIndexChanged(int index); + void slotCurrentGameFileIndexChanged(int index); + void slotAddonTableItemClicked(const QModelIndex &index); + + }; #endif diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index e71fc429f..4d9ce14d6 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include "settings/graphicssettings.hpp" diff --git a/apps/launcher/utils/textinputdialog.cpp b/apps/launcher/utils/textinputdialog.cpp index 052fc58e4..51928c09a 100644 --- a/apps/launcher/utils/textinputdialog.cpp +++ b/apps/launcher/utils/textinputdialog.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWidget *parent) : QDialog(parent) @@ -19,7 +19,7 @@ TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWid // Line edit QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore - mLineEdit = new EsxView::LineEdit(this); + mLineEdit = new ContentSelectorView::LineEdit(this); mLineEdit->setValidator(validator); mLineEdit->setCompleter(0); diff --git a/apps/launcher/utils/textinputdialog.hpp b/apps/launcher/utils/textinputdialog.hpp index 2fb6e0f6b..de3a9fb72 100644 --- a/apps/launcher/utils/textinputdialog.hpp +++ b/apps/launcher/utils/textinputdialog.hpp @@ -2,11 +2,10 @@ #define TEXTINPUTDIALOG_HPP #include -//#include "lineedit.hpp" class QDialogButtonBox; -namespace EsxView { +namespace ContentSelectorView { class LineEdit; } @@ -16,10 +15,10 @@ class TextInputDialog : public QDialog Q_OBJECT public: explicit TextInputDialog(const QString& title, const QString &text, QWidget *parent = 0); - inline EsxView::LineEdit *lineEdit() { return mLineEdit; } + inline ContentSelectorView::LineEdit *lineEdit() { return mLineEdit; } void setOkButtonEnabled(bool enabled); - EsxView::LineEdit *mLineEdit; + ContentSelectorView::LineEdit *mLineEdit; int exec(); diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 9a6832ec0..ba1dfb57e 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -79,8 +79,8 @@ void CS::Editor::setupDataFiles() } // Set the charset for reading the esm/esp files - QString encoding = QString::fromStdString(variables["encoding"].as()); - mFileDialog.setEncoding(encoding); + // QString encoding = QString::fromStdString(variables["encoding"].as()); + //mFileDialog.setEncoding(encoding); dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end()); diff --git a/apps/opencs/main.cpp b/apps/opencs/main.cpp index ef7123c20..e5e7514ce 100644 --- a/apps/opencs/main.cpp +++ b/apps/opencs/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) if(!editor.makeIPCServer()) { editor.connectToIPCServer(); - return 0; + // return 0; } return editor.run(); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index fb031fe5f..1d6bed7a7 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -10,24 +10,18 @@ #include #include -#include -#include -#include - -#include - -#include "components/esxselector/model/masterproxymodel.hpp" +#include +#include CSVDoc::FileDialog::FileDialog(QWidget *parent) : ContentSelector(parent) { // Hide the profile elements profileGroupBox->hide(); - pluginView->showColumn(2); + addonView->showColumn(2); resize(400, 400); - // connect(mDataFilesModel, SIGNAL(checkedItemsChanged(QStringList)), this, SLOT(updateOpenButton(QStringList))); connect(projectNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); connect(projectCreateButton, SIGNAL(clicked()), this, SIGNAL(createNewFile())); diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index c749099d4..d0c3461b9 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -4,7 +4,7 @@ #include #include -#include "components/esxselector/view/contentselector.hpp" +#include "components/contentselector/view/contentselector.hpp" #include "ui_datafilespage.h" class QDialogButtonBox; @@ -19,14 +19,14 @@ class QLabel; class DataFilesModel; class PluginsProxyModel; -namespace EsxView +namespace ContentSelectorView { class LineEdit; } namespace CSVDoc { - class FileDialog : public EsxView::ContentSelector + class FileDialog : public ContentSelectorView::ContentSelector { Q_OBJECT public: diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 7703f2d23..963316070 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -36,7 +36,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) // all files/readers used by the engine. This will greaty accelerate // refnumber mangling, as required for handling moved references. int index = ~0; - const std::vector &masters = esm.getMasters(); + const std::vector &masters = esm.getGameFiles(); std::vector *allPlugins = esm.getGlobalReaderList(); for (size_t j = 0; j < masters.size(); j++) { ESM::Header::MasterData &mast = const_cast(masters[j]); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 34ef43ab5..7053bb973 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -79,10 +79,9 @@ 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 (esxselector - model/masterproxymodel model/modelitem - model/pluginsproxymodel model/esmfile model/naturalsort - model/contentmodel + add_component_qt_dir (contentselector + model/modelitem model/esmfile + model/naturalsort model/contentmodel view/profilescombobox view/comboboxlineedit view/lineedit view/contentselector ) diff --git a/components/esxselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp similarity index 64% rename from components/esxselector/model/contentmodel.cpp rename to components/contentselector/model/contentmodel.cpp index d23ea7801..b85da25c6 100644 --- a/components/esxselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -6,7 +6,7 @@ #include #include -EsxModel::ContentModel::ContentModel(QObject *parent) : +ContentSelectorModel::ContentModel::ContentModel(QObject *parent) : QAbstractTableModel(parent), mMimeType ("application/omwcontent"), mMimeTypes (QStringList() << mMimeType), @@ -15,11 +15,11 @@ EsxModel::ContentModel::ContentModel(QObject *parent) : mDefaultFlags (Qt::ItemIsDropEnabled | Qt::ItemIsSelectable), mDropActions (Qt::CopyAction | Qt::MoveAction) { - setEncoding ("win1252"); + // setEncoding ("win1252"); uncheckAll(); } - -void EsxModel::ContentModel::setEncoding(const QString &encoding) +/* +void ContentSelectorModel::ContentModel::setEncoding(const QString &encoding) { if (encoding == QLatin1String("win1252")) mCodec = QTextCodec::codecForName("windows-1252"); @@ -33,8 +33,8 @@ void EsxModel::ContentModel::setEncoding(const QString &encoding) else return; // This should never happen; } - -int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const +*/ +int ContentSelectorModel::ContentModel::columnCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; @@ -42,7 +42,7 @@ int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const return mColumnCount; } -int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const +int ContentSelectorModel::ContentModel::rowCount(const QModelIndex &parent) const { if(parent.isValid()) return 0; @@ -50,7 +50,7 @@ int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const return mFiles.size(); } -const EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const +const ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::item(int row) const { if (row >= 0 && row < mFiles.size()) return mFiles.at(row); @@ -58,14 +58,14 @@ const EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const return 0; } -EsxModel::EsmFile *EsxModel::ContentModel::item(int row) +ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::item(int row) { if (row >= 0 && row < mFiles.count()) return mFiles.at(row); return 0; } -const EsxModel::EsmFile *EsxModel::ContentModel::findItem(const QString &name) const +const ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::findItem(const QString &name) const { foreach (const EsmFile *file, mFiles) { @@ -75,15 +75,18 @@ const EsxModel::EsmFile *EsxModel::ContentModel::findItem(const QString &name) c return 0; } -QModelIndex EsxModel::ContentModel::indexFromItem(EsmFile *item) const +QModelIndex ContentSelectorModel::ContentModel::indexFromItem(const EsmFile *item) const { + //workaround: non-const pointer cast for calls from outside contentmodel/contentselector + EsmFile *non_const_file_ptr = const_cast(item); + if (item) - return index(mFiles.indexOf(item),0); + return index(mFiles.indexOf(non_const_file_ptr),0); return QModelIndex(); } -Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const +Qt::ItemFlags ContentSelectorModel::ContentModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; @@ -99,7 +102,7 @@ Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const return mDefaultFlags; } -QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const +QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -119,7 +122,7 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const case Qt::EditRole: case Qt::DisplayRole: { - if (column >=0 && column <=EsmFile::FileProperty_Master) + if (column >=0 && column <=EsmFile::FileProperty_GameFile) return file->fileProperty(static_cast(column)); return QVariant(); @@ -154,17 +157,20 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const case Qt::CheckStateRole: { - if (!file->isMaster()) + if (!file->isGameFile()) return isChecked(file->fileName()); break; } case Qt::UserRole: { - if (file->isMaster()) - return "game"; + if (file->isGameFile()) + return ContentType_GameFile; else - return "addon"; + if (flags(index) & Qt::ItemIsEnabled) + return ContentType_Addon; + + break; } case Qt::UserRole + 1: @@ -174,7 +180,7 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const return QVariant(); } -bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool ContentSelectorModel::ContentModel::setData(const QModelIndex &index, const QVariant &value, int role) { if(!index.isValid()) return false; @@ -189,11 +195,11 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v { QStringList list = value.toStringList(); - for (int i = 0; i < EsmFile::FileProperty_Master; i++) + for (int i = 0; i < EsmFile::FileProperty_GameFile; i++) file->setFileProperty(static_cast(i), list.at(i)); - for (int i = EsmFile::FileProperty_Master; i < list.size(); i++) - file->setFileProperty (EsmFile::FileProperty_Master, list.at(i)); + for (int i = EsmFile::FileProperty_GameFile; i < list.size(); i++) + file->setFileProperty (EsmFile::FileProperty_GameFile, list.at(i)); emit dataChanged(index, index); @@ -209,7 +215,7 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v foreach (EsmFile *file, mFiles) { - if (file->masters().contains(fileName)) + if (file->gameFiles().contains(fileName)) { QModelIndex idx = indexFromItem(file); emit dataChanged(idx, idx); @@ -222,15 +228,36 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v case Qt::CheckStateRole: { int checkValue = value.toInt(); - + bool success = false; + bool setState = false; if ((checkValue==Qt::Checked) && !isChecked(fileName)) - setCheckState(fileName, true); + { + setState = true; + success = true; + } else if ((checkValue == Qt::Checked) && isChecked (fileName)) - setCheckState(fileName, false); + setState = true; else if (checkValue == Qt::Unchecked) - setCheckState(fileName, false); + setState = true; - emit dataChanged(index, index); + if (setState) + { + setCheckState(fileName, success); + emit dataChanged(index, index); + + } + else + return success; + + + foreach (EsmFile *file, mFiles) + { + if (file->gameFiles().contains(fileName)) + { + QModelIndex idx = indexFromItem(file); + emit dataChanged(idx, idx); + } + } success = true; } @@ -240,7 +267,7 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v return success; } -bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent) +bool ContentSelectorModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent) { if (parent.isValid()) return false; @@ -255,7 +282,7 @@ bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelInde return true; } -bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelIndex &parent) +bool ContentSelectorModel::ContentModel::removeRows(int position, int rows, const QModelIndex &parent) { if (parent.isValid()) return false; @@ -270,17 +297,17 @@ bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelInde return true; } -Qt::DropActions EsxModel::ContentModel::supportedDropActions() const +Qt::DropActions ContentSelectorModel::ContentModel::supportedDropActions() const { return mDropActions; } -QStringList EsxModel::ContentModel::mimeTypes() const +QStringList ContentSelectorModel::ContentModel::mimeTypes() const { return mMimeTypes; } -QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) const +QMimeData *ContentSelectorModel::ContentModel::mimeData(const QModelIndexList &indexes) const { QByteArray encodedData; @@ -298,7 +325,7 @@ QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) cons return mimeData; } -bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +bool ContentSelectorModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { if (action == Qt::IgnoreAction) return true; @@ -325,51 +352,53 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction QString value; QStringList values; - QStringList masters; + QStringList gamefiles; - for (int i = 0; i < EsmFile::FileProperty_Master; ++i) + for (int i = 0; i < EsmFile::FileProperty_GameFile; ++i) { stream >> value; values << value; } - stream >> masters; + stream >> gamefiles; insertRows(beginRow, 1); QModelIndex idx = index(beginRow++, 0, QModelIndex()); - setData(idx, QStringList() << values << masters, Qt::EditRole); + setData(idx, QStringList() << values << gamefiles, Qt::EditRole); } return true; } -bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const +bool ContentSelectorModel::ContentModel::canBeChecked(const EsmFile *file) const { //element can be checked if all its dependencies are - foreach (const QString &master, file->masters()) - if (!isChecked(master)) + foreach (const QString &gamefile, file->gameFiles()) + if (!isChecked(gamefile)) return false; return true; } -void EsxModel::ContentModel::addFile(EsmFile *file) +void ContentSelectorModel::ContentModel::addFile(EsmFile *file) { beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); mFiles.append(file); endInsertRows(); } -void EsxModel::ContentModel::addFiles(const QString &path) +void ContentSelectorModel::ContentModel::addFiles(const QString &path) { QDir dir(path); QStringList filters; filters << "*.esp" << "*.esm" << "*.omwgame" << "*.omwaddon"; dir.setNameFilters(filters); + QTextCodec *codec = QTextCodec::codecForName("UTF8"); + // Create a decoder for non-latin characters in esx metadata - QTextDecoder *decoder = mCodec->makeDecoder(); + QTextDecoder *decoder = codec->makeDecoder(); foreach (const QString &path, dir.entryList()) { @@ -378,16 +407,16 @@ void EsxModel::ContentModel::addFiles(const QString &path) try { ESM::ESMReader fileReader; - ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(QString(mCodec->name()).toStdString())); - fileReader.setEncoder(&encoder); + ToUTF8::Utf8Encoder encoder(); //ToUTF8::calculateEncoding(QString(mCodec->name()).toStdString())); + //fileReader.setEncoder(&encoder); fileReader.open(dir.absoluteFilePath(path).toStdString()); - foreach (const ESM::Header::MasterData &item, fileReader.getMasters()) - file->addMaster(QString::fromStdString(item.name)); + foreach (const ESM::Header::MasterData &item, fileReader.getGameFiles()) + file->addGameFile(QString::fromStdString(item.name)); file->setAuthor (decoder->toUnicode(fileReader.getAuthor().c_str())); file->setDate (info.lastModified()); - file->setVersion (fileReader.getFVer()); + file->setFormat (fileReader.getFormat()); file->setPath (info.absoluteFilePath()); file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str())); @@ -407,7 +436,7 @@ void EsxModel::ContentModel::addFiles(const QString &path) delete decoder; } -bool EsxModel::ContentModel::isChecked(const QString& name) const +bool ContentSelectorModel::ContentModel::isChecked(const QString& name) const { if (mCheckStates.contains(name)) return (mCheckStates[name] == Qt::Checked); @@ -415,7 +444,7 @@ bool EsxModel::ContentModel::isChecked(const QString& name) const return false; } -void EsxModel::ContentModel::setCheckState(const QString &name, bool isChecked) +void ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool isChecked) { if (name.isEmpty()) return; @@ -428,7 +457,7 @@ void EsxModel::ContentModel::setCheckState(const QString &name, bool isChecked) mCheckStates[name] = state; } -EsxModel::ContentFileList EsxModel::ContentModel::checkedItems() const +ContentSelectorModel::ContentFileList ContentSelectorModel::ContentModel::checkedItems() const { ContentFileList list; @@ -441,7 +470,7 @@ EsxModel::ContentFileList EsxModel::ContentModel::checkedItems() const return list; } -void EsxModel::ContentModel::uncheckAll() +void ContentSelectorModel::ContentModel::uncheckAll() { emit layoutAboutToBeChanged(); mCheckStates.clear(); diff --git a/components/esxselector/model/contentmodel.hpp b/components/contentselector/model/contentmodel.hpp similarity index 86% rename from components/esxselector/model/contentmodel.hpp rename to components/contentselector/model/contentmodel.hpp index 6a2dd88ca..a8ff103da 100644 --- a/components/esxselector/model/contentmodel.hpp +++ b/components/contentselector/model/contentmodel.hpp @@ -3,19 +3,26 @@ #include #include -namespace EsxModel + +namespace ContentSelectorModel { class EsmFile; typedef QList ContentFileList; + enum ContentType + { + ContentType_GameFile, + ContentType_Addon + }; + class ContentModel : public QAbstractTableModel { Q_OBJECT public: explicit ContentModel(QObject *parent = 0); - void setEncoding(const QString &encoding); + //void setEncoding(const QString &encoding); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -34,8 +41,8 @@ namespace EsxModel void addFiles(const QString &path); - QModelIndex indexFromItem(EsmFile *item) const; - const EsxModel::EsmFile *findItem(const QString &name) const; + QModelIndex indexFromItem(const EsmFile *item) const; + const EsmFile *findItem(const QString &name) const; bool isChecked(const QString &name) const; void setCheckState(const QString &name, bool isChecked); diff --git a/components/esxselector/model/esmfile.cpp b/components/contentselector/model/esmfile.cpp similarity index 54% rename from components/esxselector/model/esmfile.cpp rename to components/contentselector/model/esmfile.cpp index bd76dc4a0..9dfe49eba 100644 --- a/components/esxselector/model/esmfile.cpp +++ b/components/contentselector/model/esmfile.cpp @@ -3,64 +3,65 @@ #include #include -int EsxModel::EsmFile::sPropertyCount = 7; -QString EsxModel::EsmFile::sToolTip = QString("Author: %1
\ +int ContentSelectorModel::EsmFile::sPropertyCount = 7; +QString ContentSelectorModel::EsmFile::sToolTip = QString("Author: %1
\ Version: %2
\
Description:
%3
\
Dependencies: %4
"); -EsxModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) - : ModelItem(parent), mFileName(fileName), mVersion(0.0f) +ContentSelectorModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) + : ModelItem(parent), mFileName(fileName), mFormat(0) {} -void EsxModel::EsmFile::setFileName(const QString &fileName) + +void ContentSelectorModel::EsmFile::setFileName(const QString &fileName) { mFileName = fileName; } -void EsxModel::EsmFile::setAuthor(const QString &author) +void ContentSelectorModel::EsmFile::setAuthor(const QString &author) { mAuthor = author; } -void EsxModel::EsmFile::setDate(const QDateTime &modified) +void ContentSelectorModel::EsmFile::setDate(const QDateTime &modified) { mModified = modified; } -void EsxModel::EsmFile::setVersion(float version) +void ContentSelectorModel::EsmFile::setFormat(int format) { - mVersion = version; + mFormat = format; } -void EsxModel::EsmFile::setPath(const QString &path) +void ContentSelectorModel::EsmFile::setPath(const QString &path) { mPath = path; } -void EsxModel::EsmFile::setMasters(const QStringList &masters) +void ContentSelectorModel::EsmFile::setGameFiles(const QStringList &gamefiles) { - mMasters = masters; + mGameFiles = gamefiles; } -void EsxModel::EsmFile::setDescription(const QString &description) +void ContentSelectorModel::EsmFile::setDescription(const QString &description) { mDescription = description; } -QByteArray EsxModel::EsmFile::encodedData() const +QByteArray ContentSelectorModel::EsmFile::encodedData() const { QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); - stream << mFileName << mAuthor << QString::number(mVersion) + stream << mFileName << mAuthor << QString::number(mFormat) << mModified.toString() << mPath << mDescription - << mMasters; + << mGameFiles; return encodedData; } -QVariant EsxModel::EsmFile::fileProperty(const FileProperty prop) const +QVariant ContentSelectorModel::EsmFile::fileProperty(const FileProperty prop) const { switch (prop) { @@ -72,8 +73,8 @@ QVariant EsxModel::EsmFile::fileProperty(const FileProperty prop) const return mAuthor; break; - case FileProperty_Version: - return mVersion; + case FileProperty_Format: + return mFormat; break; case FileProperty_DateModified: @@ -88,8 +89,8 @@ QVariant EsxModel::EsmFile::fileProperty(const FileProperty prop) const return mDescription; break; - case FileProperty_Master: - return mMasters; + case FileProperty_GameFile: + return mGameFiles; break; default: @@ -97,7 +98,7 @@ QVariant EsxModel::EsmFile::fileProperty(const FileProperty prop) const } return QVariant(); } -void EsxModel::EsmFile::setFileProperty (const FileProperty prop, const QString &value) +void ContentSelectorModel::EsmFile::setFileProperty (const FileProperty prop, const QString &value) { switch (prop) { @@ -109,8 +110,8 @@ void EsxModel::EsmFile::setFileProperty (const FileProperty prop, const QString mAuthor = value; break; - case FileProperty_Version: - mVersion = value.toFloat(); + case FileProperty_Format: + mFormat = value.toInt(); break; case FileProperty_DateModified: @@ -125,8 +126,8 @@ void EsxModel::EsmFile::setFileProperty (const FileProperty prop, const QString mDescription = value; break; - case FileProperty_Master: - mMasters << value; + case FileProperty_GameFile: + mGameFiles << value; break; default: diff --git a/components/esxselector/model/esmfile.hpp b/components/contentselector/model/esmfile.hpp similarity index 58% rename from components/esxselector/model/esmfile.hpp rename to components/contentselector/model/esmfile.hpp index 4f6d7a624..743b1c5a6 100644 --- a/components/esxselector/model/esmfile.hpp +++ b/components/contentselector/model/esmfile.hpp @@ -8,7 +8,7 @@ class QMimeData; -namespace EsxModel +namespace ContentSelectorModel { class EsmFile : public ModelItem { @@ -21,11 +21,11 @@ namespace EsxModel { FileProperty_FileName = 0, FileProperty_Author = 1, - FileProperty_Version = 2, + FileProperty_Format = 2, FileProperty_DateModified = 3, FileProperty_Path = 4, FileProperty_Description = 5, - FileProperty_Master = 6 + FileProperty_GameFile = 6 }; EsmFile(QString fileName = QString(), ModelItem *parent = 0); @@ -40,28 +40,28 @@ namespace EsxModel void setAuthor(const QString &author); void setSize(const int size); void setDate(const QDateTime &modified); - void setVersion(const float version); + void setFormat(const int format); void setPath(const QString &path); - void setMasters(const QStringList &masters); + void setGameFiles(const QStringList &gameFiles); void setDescription(const QString &description); - inline void addMaster (const QString &name) {mMasters.append(name); } + inline void addGameFile (const QString &name) {mGameFiles.append(name); } QVariant fileProperty (const FileProperty prop) const; - inline QString fileName() const { return mFileName; } - inline QString author() const { return mAuthor; } - inline QDateTime modified() const { return mModified; } - inline float version() const { return mVersion; } - inline QString path() const { return mPath; } - inline const QStringList &masters() const { return mMasters; } - inline QString description() const { return mDescription; } - inline QString toolTip() const { return sToolTip.arg(mAuthor) - .arg(mVersion) + inline QString fileName() const { return mFileName; } + inline QString author() const { return mAuthor; } + inline QDateTime modified() const { return mModified; } + inline float format() const { return mFormat; } + inline QString path() const { return mPath; } + inline const QStringList &gameFiles() const { return mGameFiles; } + inline QString description() const { return mDescription; } + inline QString toolTip() const { return sToolTip.arg(mAuthor) + .arg(mFormat) .arg(mDescription) - .arg(mMasters.join(", ")); - } + .arg(mGameFiles.join(", ")); + } - inline bool isMaster() const { return (mMasters.size() == 0); } + inline bool isGameFile() const { return (mGameFiles.size() == 0); } QByteArray encodedData() const; public: @@ -73,15 +73,13 @@ namespace EsxModel QString mFileName; QString mAuthor; QDateTime mModified; - float mVersion; + int mFormat; QString mPath; - QStringList mMasters; + QStringList mGameFiles; QString mDescription; QString mToolTip; }; } -Q_DECLARE_METATYPE (EsxModel::EsmFile *) - #endif diff --git a/components/contentselector/model/modelitem.cpp b/components/contentselector/model/modelitem.cpp new file mode 100644 index 000000000..e1d737c2d --- /dev/null +++ b/components/contentselector/model/modelitem.cpp @@ -0,0 +1,69 @@ +#include "modelitem.hpp" + +ContentSelectorModel::ModelItem::ModelItem(ModelItem *parent) + : mParentItem(parent) +{ +} +/* +ContentSelectorModel::ModelItem::ModelItem(const ModelItem *parent) + // : mParentItem(parent) +{ +} +*/ + +ContentSelectorModel::ModelItem::~ModelItem() +{ + qDeleteAll(mChildItems); +} + + +ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::parent() const +{ + return mParentItem; +} + +bool ContentSelectorModel::ModelItem::hasFormat(const QString &mimetype) const +{ + if (mimetype == "application/omwcontent") + return true; + + return QMimeData::hasFormat(mimetype); +} +int ContentSelectorModel::ModelItem::row() const +{ + if (mParentItem) + return 1; + //return mParentItem->childRow(const_cast(this)); + //return mParentItem->mChildItems.indexOf(const_cast(this)); + + return -1; +} + + +int ContentSelectorModel::ModelItem::childCount() const +{ + return mChildItems.count(); +} + +int ContentSelectorModel::ModelItem::childRow(ModelItem *child) const +{ + Q_ASSERT(child); + + return mChildItems.indexOf(child); +} + +ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::child(int row) +{ + return mChildItems.value(row); +} + + +void ContentSelectorModel::ModelItem::appendChild(ModelItem *item) +{ + mChildItems.append(item); +} + +void ContentSelectorModel::ModelItem::removeChild(int row) +{ + mChildItems.removeAt(row); +} diff --git a/components/esxselector/model/modelitem.hpp b/components/contentselector/model/modelitem.hpp similarity index 96% rename from components/esxselector/model/modelitem.hpp rename to components/contentselector/model/modelitem.hpp index 5ee5e417e..57214b09c 100644 --- a/components/esxselector/model/modelitem.hpp +++ b/components/contentselector/model/modelitem.hpp @@ -4,7 +4,7 @@ #include #include -namespace EsxModel +namespace ContentSelectorModel { class ModelItem : public QMimeData { diff --git a/components/esxselector/model/naturalsort.cpp b/components/contentselector/model/naturalsort.cpp similarity index 100% rename from components/esxselector/model/naturalsort.cpp rename to components/contentselector/model/naturalsort.cpp diff --git a/components/esxselector/model/naturalsort.hpp b/components/contentselector/model/naturalsort.hpp similarity index 100% rename from components/esxselector/model/naturalsort.hpp rename to components/contentselector/model/naturalsort.hpp diff --git a/components/esxselector/view/comboboxlineedit.cpp b/components/contentselector/view/comboboxlineedit.cpp similarity index 83% rename from components/esxselector/view/comboboxlineedit.cpp rename to components/contentselector/view/comboboxlineedit.cpp index 815a1130b..df647a4a0 100644 --- a/components/esxselector/view/comboboxlineedit.cpp +++ b/components/contentselector/view/comboboxlineedit.cpp @@ -3,7 +3,7 @@ #include "comboboxlineedit.hpp" -EsxView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) +ContentSelectorView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) : QLineEdit(parent) { mClearButton = new QToolButton(this); @@ -21,7 +21,7 @@ EsxView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1)); } -void EsxView::ComboBoxLineEdit::resizeEvent(QResizeEvent *) +void ContentSelectorView::ComboBoxLineEdit::resizeEvent(QResizeEvent *) { QSize sz = mClearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); @@ -29,7 +29,7 @@ void EsxView::ComboBoxLineEdit::resizeEvent(QResizeEvent *) (rect().bottom() + 1 - sz.height())/2); } -void EsxView::ComboBoxLineEdit::updateClearButton(const QString& text) +void ContentSelectorView::ComboBoxLineEdit::updateClearButton(const QString& text) { mClearButton->setVisible(!text.isEmpty()); } diff --git a/components/esxselector/view/comboboxlineedit.hpp b/components/contentselector/view/comboboxlineedit.hpp similarity index 96% rename from components/esxselector/view/comboboxlineedit.hpp rename to components/contentselector/view/comboboxlineedit.hpp index f3b251955..1aef2f57b 100644 --- a/components/esxselector/view/comboboxlineedit.hpp +++ b/components/contentselector/view/comboboxlineedit.hpp @@ -14,7 +14,7 @@ class QToolButton; -namespace EsxView +namespace ContentSelectorView { class ComboBoxLineEdit : public QLineEdit { diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp new file mode 100644 index 000000000..615e9a846 --- /dev/null +++ b/components/contentselector/view/contentselector.cpp @@ -0,0 +1,134 @@ +#include "contentselector.hpp" + +#include "../model/contentmodel.hpp" +#include "../model/esmfile.hpp" + +#include + +#include +#include +#include + +ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) : + QDialog(parent) +{ + setupUi(this); + + buildContentModel(); + buildGameFileView(); + buildAddonView(); + buildProfilesView(); + + updateViews(); + +} + +void ContentSelectorView::ContentSelector::buildContentModel() +{ + mContentModel = new ContentSelectorModel::ContentModel(); + connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); +} + +void ContentSelectorView::ContentSelector::buildGameFileView() +{ + mGameFileProxyModel = new QSortFilterProxyModel(this); + mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile)); + mGameFileProxyModel->setFilterRole (Qt::UserRole); + mGameFileProxyModel->setSourceModel (mContentModel); + + gameFileView->setPlaceholderText(QString("Select a game file...")); + gameFileView->setModel(mGameFileProxyModel); + + connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentGameFileIndexChanged(int))); + + gameFileView->setCurrentIndex(-1); + gameFileView->setCurrentIndex(0); +} + +void ContentSelectorView::ContentSelector::buildAddonView() +{ + mAddonProxyModel = new QSortFilterProxyModel(this); + mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon)); + mAddonProxyModel->setFilterRole (Qt::UserRole); + mAddonProxyModel->setDynamicSortFilter (true); + mAddonProxyModel->setSourceModel (mContentModel); + + addonView->setModel(mAddonProxyModel); + + connect(addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &))); +} + +void ContentSelectorView::ContentSelector::buildProfilesView() +{ + profilesComboBox->setPlaceholderText(QString("Select a profile...")); + connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); +} + +void ContentSelectorView::ContentSelector::updateViews() +{ + // Ensure the columns are hidden because sort() re-enables them + addonView->setColumnHidden(1, true); + addonView->setColumnHidden(2, true); + addonView->setColumnHidden(3, true); + addonView->setColumnHidden(4, true); + addonView->setColumnHidden(5, true); + addonView->setColumnHidden(6, true); + addonView->setColumnHidden(7, true); + addonView->setColumnHidden(8, true); + addonView->resizeColumnsToContents(); +} + +void ContentSelectorView::ContentSelector::addFiles(const QString &path) +{ + mContentModel->addFiles(path); + //mContentModel->sort(3); // Sort by date accessed + gameFileView->setCurrentIndex(-1); + mContentModel->uncheckAll(); +} + +QStringList ContentSelectorView::ContentSelector::checkedItemsPaths() +{ + QStringList itemPaths; + + foreach( const ContentSelectorModel::EsmFile *file, mContentModel->checkedItems()) + itemPaths << file->path(); + + return itemPaths; +} + +void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index) +{ + emit profileChanged(index); +} + +void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index) +{ + static int oldIndex = -1; + + QAbstractItemModel *const model = gameFileView->model(); + QSortFilterProxyModel *proxy = dynamic_cast(model); + + if (proxy) + proxy->setDynamicSortFilter(false); + + if (oldIndex > -1) + model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); + + oldIndex = index; + + model->setData(model->index(index, 0), true, Qt::UserRole + 1); + + if (proxy) + proxy->setDynamicSortFilter(true); +} + +void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index) +{ + QAbstractItemModel *const model = addonView->model(); + QSortFilterProxyModel *proxy = dynamic_cast(model); + + if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) + model->setData(index, Qt::Checked, Qt::CheckStateRole); + else + model->setData(index, Qt::Unchecked, Qt::CheckStateRole); +} diff --git a/components/esxselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp similarity index 51% rename from components/esxselector/view/contentselector.hpp rename to components/contentselector/view/contentselector.hpp index e074fe688..8032b0449 100644 --- a/components/esxselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -5,15 +5,11 @@ #include "ui_datafilespage.h" -namespace EsxModel -{ - class ContentModel; - class DataFilesModel; -} +namespace ContentSelectorModel { class ContentModel; } class QSortFilterProxyModel; -namespace EsxView +namespace ContentSelectorView { class ContentSelector : public QDialog, protected Ui::DataFilesPage { @@ -21,27 +17,25 @@ namespace EsxView protected: - EsxModel::DataFilesModel *mDataFilesModel; - EsxModel::ContentModel *mContentModel; - QSortFilterProxyModel *mMasterProxyModel; - QSortFilterProxyModel *mPluginsProxyModel; + ContentSelectorModel::ContentModel *mContentModel; + QSortFilterProxyModel *mGameFileProxyModel; + QSortFilterProxyModel *mAddonProxyModel; public: + explicit ContentSelector(QWidget *parent = 0); - void buildModelsAndViews(); + static ContentSelector &cast(QWidget *subject); //static constructor function for singleton performance. void addFiles(const QString &path); - void setEncoding(const QString &encoding); - void setPluginCheckState(); void setCheckState(QModelIndex index, QSortFilterProxyModel *model); QStringList checkedItemsPaths(); - void on_checkAction_triggered(); private: - void buildSourceModel(); - void buildMasterView(); - void buildPluginsView(); + + void buildContentModel(); + void buildGameFileView(); + void buildAddonView(); void buildProfilesView(); signals: @@ -50,8 +44,8 @@ namespace EsxView private slots: void updateViews(); void slotCurrentProfileIndexChanged(int index); - void slotCurrentMasterIndexChanged(int index); - void slotPluginTableItemClicked(const QModelIndex &index); + void slotCurrentGameFileIndexChanged(int index); + void slotAddonTableItemClicked(const QModelIndex &index); }; } diff --git a/components/esxselector/view/lineedit.cpp b/components/contentselector/view/lineedit.cpp similarity index 87% rename from components/esxselector/view/lineedit.cpp rename to components/contentselector/view/lineedit.cpp index 48be2f022..b6fdfa805 100644 --- a/components/esxselector/view/lineedit.cpp +++ b/components/contentselector/view/lineedit.cpp @@ -4,7 +4,7 @@ #include "lineedit.hpp" -EsxView::LineEdit::LineEdit(QWidget *parent) +ContentSelectorView::LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent) { mClearButton = new QToolButton(this); @@ -25,7 +25,7 @@ EsxView::LineEdit::LineEdit(QWidget *parent) qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2)); } -void EsxView::LineEdit::resizeEvent(QResizeEvent *) +void ContentSelectorView::LineEdit::resizeEvent(QResizeEvent *) { QSize sz = mClearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); @@ -33,7 +33,7 @@ void EsxView::LineEdit::resizeEvent(QResizeEvent *) (rect().bottom() + 1 - sz.height())/2); } -void EsxView::LineEdit::updateClearButton(const QString& text) +void ContentSelectorView::LineEdit::updateClearButton(const QString& text) { mClearButton->setVisible(!text.isEmpty()); } diff --git a/components/esxselector/view/lineedit.hpp b/components/contentselector/view/lineedit.hpp similarity index 96% rename from components/esxselector/view/lineedit.hpp rename to components/contentselector/view/lineedit.hpp index 4e0cbe339..ab1c37203 100644 --- a/components/esxselector/view/lineedit.hpp +++ b/components/contentselector/view/lineedit.hpp @@ -14,7 +14,7 @@ class QToolButton; -namespace EsxView +namespace ContentSelectorView { class LineEdit : public QLineEdit { diff --git a/components/esxselector/view/profilescombobox.cpp b/components/contentselector/view/profilescombobox.cpp similarity index 83% rename from components/esxselector/view/profilescombobox.cpp rename to components/contentselector/view/profilescombobox.cpp index 0d709aa50..cb0ba7b77 100644 --- a/components/esxselector/view/profilescombobox.cpp +++ b/components/contentselector/view/profilescombobox.cpp @@ -7,7 +7,7 @@ #include "profilescombobox.hpp" #include "comboboxlineedit.hpp" -EsxView::ProfilesComboBox::ProfilesComboBox(QWidget *parent) : +ContentSelectorView::ProfilesComboBox::ProfilesComboBox(QWidget *parent) : QComboBox(parent) { mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore @@ -21,7 +21,7 @@ EsxView::ProfilesComboBox::ProfilesComboBox(QWidget *parent) : setInsertPolicy(QComboBox::NoInsert); } -void EsxView::ProfilesComboBox::setEditEnabled(bool editable) +void ContentSelectorView::ProfilesComboBox::setEditEnabled(bool editable) { if (isEditable() == editable) return; @@ -47,7 +47,7 @@ void EsxView::ProfilesComboBox::setEditEnabled(bool editable) SLOT(slotTextChanged(QString))); } -void EsxView::ProfilesComboBox::slotTextChanged(const QString &text) +void ContentSelectorView::ProfilesComboBox::slotTextChanged(const QString &text) { QPalette *palette = new QPalette(); palette->setColor(QPalette::Text,Qt::red); @@ -61,7 +61,7 @@ void EsxView::ProfilesComboBox::slotTextChanged(const QString &text) } } -void EsxView::ProfilesComboBox::slotEditingFinished() +void ContentSelectorView::ProfilesComboBox::slotEditingFinished() { QString current = currentText(); QString previous = itemText(currentIndex()); @@ -82,7 +82,7 @@ void EsxView::ProfilesComboBox::slotEditingFinished() emit(profileRenamed(previous, current)); } -void EsxView::ProfilesComboBox::slotIndexChanged(int index) +void ContentSelectorView::ProfilesComboBox::slotIndexChanged(int index) { if (index == -1) return; @@ -91,7 +91,7 @@ void EsxView::ProfilesComboBox::slotIndexChanged(int index) mOldProfile = itemText(index); } -void EsxView::ProfilesComboBox::paintEvent(QPaintEvent *) +void ContentSelectorView::ProfilesComboBox::paintEvent(QPaintEvent *) { QStylePainter painter(this); painter.setPen(palette().color(QPalette::Text)); @@ -107,7 +107,7 @@ void EsxView::ProfilesComboBox::paintEvent(QPaintEvent *) painter.drawControl(QStyle::CE_ComboBoxLabel, opt); } -void EsxView::ProfilesComboBox::setPlaceholderText(const QString &text) +void ContentSelectorView::ProfilesComboBox::setPlaceholderText(const QString &text) { mPlaceholderText = text; } diff --git a/components/esxselector/view/profilescombobox.hpp b/components/contentselector/view/profilescombobox.hpp similarity index 96% rename from components/esxselector/view/profilescombobox.hpp rename to components/contentselector/view/profilescombobox.hpp index 28740783b..d81c1e6a5 100644 --- a/components/esxselector/view/profilescombobox.hpp +++ b/components/contentselector/view/profilescombobox.hpp @@ -6,7 +6,7 @@ class QString; class QRegExpValidator; -namespace EsxView +namespace ContentSelectorView { class ProfilesComboBox : public QComboBox { diff --git a/components/esm/esmreader.hpp b/components/esm/esmreader.hpp index edc724cd2..3bf194c4e 100644 --- a/components/esm/esmreader.hpp +++ b/components/esm/esmreader.hpp @@ -34,7 +34,7 @@ public: float getFVer() const { if(mHeader.mData.version == VER_12) return 1.2; else return 1.3; } const std::string getAuthor() const { return mHeader.mData.author.toString(); } const std::string getDesc() const { return mHeader.mData.desc.toString(); } - const std::vector &getMasters() const { return mHeader.mMaster; } + const std::vector &getGameFiles() const { return mHeader.mMaster; } int getFormat() const; const NAME &retSubName() const { return mCtx.subName; } uint32_t getSubSize() const { return mCtx.leftSub; } diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index d8d0c1291..9793391ed 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -172,7 +172,7 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) // If the most significant 8 bits are used, then this reference already exists. // In this case, do not spawn a new reference, but overwrite the old one. ref.mRefnum &= 0x00ffffff; // delete old plugin ID - const std::vector &masters = esm.getMasters(); + const std::vector &masters = esm.getGameFiles(); global = masters[local-1].index + 1; ref.mRefnum |= global << 24; // insert global plugin ID } @@ -276,7 +276,7 @@ bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref) int local = (mref.mRefnum & 0xff000000) >> 24; size_t global = esm.getIndex() + 1; mref.mRefnum &= 0x00ffffff; // delete old plugin ID - const std::vector &masters = esm.getMasters(); + const std::vector &masters = esm.getGameFiles(); global = masters[local-1].index + 1; mref.mRefnum |= global << 24; // insert global plugin ID diff --git a/components/esxselector/model/datafilesmodel.cpp b/components/esxselector/model/datafilesmodel.cpp deleted file mode 100644 index c98f70b16..000000000 --- a/components/esxselector/model/datafilesmodel.cpp +++ /dev/null @@ -1,608 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -#include - -#include "esmfile.hpp" - -#include "datafilesmodel.hpp" - -#include - -EsxModel::DataFilesModel::DataFilesModel(QObject *parent) : - QAbstractTableModel(parent) -{ - mEncoding = QString("win1252"); -} - -EsxModel::DataFilesModel::~DataFilesModel() -{ -} - -int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : mFiles.count(); -} - -int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : 1; -} - -const EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name) -{ - for (int i = 0; i < mFiles.size(); ++i) - { - const EsmFile *file = item(i); - - if (name == file->fileName()) - return file; - } - - return 0; -} - -const EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const -{ - if (row >= 0 && row < mFiles.count()) - return mFiles.at(row); - - return 0; -} - -Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - - const EsmFile *file = item(index.row()); - - if (!file) - return Qt::NoItemFlags; - - Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; - Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable | Qt::ItemIsEditable; - Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable; - - if (canBeChecked(file)) - return defaultFlags | dragDropFlags | checkFlags | Qt::ItemIsEnabled; - else - return defaultFlags; -} - -QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() >= mFiles.size()) - return QVariant(); - - const EsmFile *file = item(index.row()); - - if (!file) - return QVariant(); - - const int column = index.column(); - - switch (role) - { - case Qt::EditRole: - case Qt::DisplayRole: - { - - switch (column) - { - case 0: - return file->fileName(); - case 1: - return file->author(); - case 2: - return file->modified().toString(Qt::ISODate); - case 3: - return file->version(); - case 4: - return file->path(); - case 5: - return file->masters().join(", "); - case 6: - return file->description(); - } - break; - } - - case Qt::TextAlignmentRole: - { - switch (column) - { - case 0: - case 1: - return Qt::AlignLeft + Qt::AlignVCenter; - case 2: - case 3: - return Qt::AlignRight + Qt::AlignVCenter; - default: - return Qt::AlignLeft + Qt::AlignVCenter; - } - break; - } - - case Qt::ToolTipRole: - { - if (column != 0) - return QVariant(); - - if (file->version() == 0.0f) - return QVariant(); // Data not set - - QString tooltip = - QString("Author: %1
\ - Version: %2
\ -
Description:
%3
\ -
Dependencies: %4
") - .arg(file->author()) - .arg(QString::number(file->version())) - .arg(file->description()) - .arg(file->masters().join(", ")); - - - return tooltip; - break; - } - - case Qt::UserRole: - { - if (file->masters().size() == 0) - return "game"; - else - return "addon"; - - break; - } - - case Qt::UserRole + 1: - //return check state here - break; - - default: - return QVariant(); - break; - } - -} - -bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (!index.isValid()) - return false; - - switch (role) - { - case Qt::EditRole: - { - const EsmFile *file = item(index.row()); - - // iterate loop to repopulate file pointer with data in string list. - QStringList list = value.toStringList(); - for (int i = 0; i <999; ++i) - { - file->setProperty(i, value.at(i)); - } - - //populate master list here (emit data changed for each master and - //each item (other than the dropped item) which share each of the masters - file->masters().append(masterList); - - emit dataChanged(index, index); - return true; - } - break; - - case Qt::UserRole + 1: - { - EsmFile *file = item(index.row()); - //set file's checkstate to the passed checkstate - emit dataChanged(index, index); - - for (int i = 0; i < mFiles.size(); ++i) - if (mFiles.at(i)->getMasters().contains(file->fileName())) - emit dataChanged(QAbstractTableModel::index(i,0), QAbstractTableModel::index(i,0)); - - return true; - } - break; - - case Qt::CheckStateRole: - { - EsmFile *file = item(index.row()); - - if ((value.toInt() == Qt::Checked) && !file->isChecked()) - file->setChecked(true); - else if (value.toInt() == Qt::Checked && file->isChecked()) - file->setChecked(false); - else if (value.toInt() == Qt::UnChecked) - file->setChecked(false); - - emit dataChanged(index, index); - - return true; - } - break; - } - return false; -} - -bool EsxModel::DataFilesModel::insertRows(int row, int count, const QModelIndex &parent) -{ - if (parent.isValid()) - return false; - - beginInsertRows(QModelIndex(),row, row+count-1); - { - for (int i = 0; i < count; ++i) - mFiles.insert(row, new EsmFile()); - } endInsertRows(); - - return true; -} - -bool EsxModel::DataFilesModel::removeRows(int row, int count, const QModelIndex &parent) -{ - if (parent.isValid()) - return false; - - beginRemoveRows(QModelIndex(), row, row+count-1); - { - for (int i = 0; i < count; ++i) - delete mFiles.takeAt(row); - } endRemoveRows(); - - return true; -} - -Qt::DropActions EsxModel::DataFilesModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -QStringList EsxModel::DataFilesModel::mimeTypes() const -{ - QStringList types; - types << "application/omwcontent"; - return types; -} - -QMimeData *EsxModel::DataFilesModel::mimeData(const QModelIndexList &indexes) const -{ - QMimeData *mimeData = new QMimeData(); - QByteArray encodedData; - - QDataStream stream (&encodedData, QIODevice::WriteOnly); - - foreach (const QModelIndex &index, indexes) - { - if (index.isValid()) - { - EsmFile *file = item (index.row()); - - for (int i = 0; i < file->propertyCount(); ++i) - stream << data(index, Qt::DisplayRole).toString(); - - EsmFile *file = item(index.row()); - stream << file->getMasters(); - } - } - - mimeData->setData("application/omwcontent", encodedData); - - return mimeData; -} - -bool EsxModel::DataFilesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -{ - if (action == Qt::IgnoreAction) - return true; - - if (action != Qt::MoveAction) - return false; - - if (!data->hasFormat("application/omwcontent")) - return false; - - int dropRow = row; - - if (dropRow == -1) - { - if (parent.isValid()) - dropRow = parent.row(); - else - dropRow = rowCount(QModelIndex()); - } - - if (parent.isValid()) - qDebug() << "parent: " << parent.data().toString(); - qDebug() << "dragged file: " << (qobject_cast(data))->fileName(); -// qDebug() << "inserting file: " << droppedfile->fileName() << " ahead of " << file->fileName(); - insertRows (dropRow, 1, QModelIndex()); - - - const EsmFile *draggedFile = qobject_cast(data); - - int dragRow = -1; - - for (int i = 0; i < mFiles.size(); ++i) - if (draggedFile->fileName() == mFiles.at(i)->fileName()) - { - dragRow = i; - break; - } - - for (int i = 0; i < mFiles.count(); ++i) - { - qDebug() << "index: " << i << "file: " << item(i)->fileName(); - qDebug() << mFiles.at(i)->fileName(); - } - - qDebug() << "drop row: " << dropRow << "; drag row: " << dragRow; -// const EsmFile *file = qobject_cast(data); - // int index = mFiles.indexOf(file); - //qDebug() << "file name: " << file->fileName() << "; index: " << index; - mFiles.swap(dropRow, dragRow); - //setData(index(startRow, 0), varFile); - emit dataChanged(index(0,0), index(rowCount(),0)); - return true; -} - -void EsxModel::DataFilesModel::setEncoding(const QString &encoding) -{ - mEncoding = encoding; -} - -void EsxModel::DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState state) -{ - if (!index.isValid()) - return; - - QString name = item(index.row())->fileName(); - mCheckStates[name] = state; - - // Force a redraw of the view since unchecking one item can affect another - QModelIndex firstIndex = indexFromItem(mFiles.first()); - QModelIndex lastIndex = indexFromItem(mFiles.last()); - - emit dataChanged(firstIndex, lastIndex); - emit checkedItemsChanged(checkedItems()); - -} - -Qt::CheckState EsxModel::DataFilesModel::checkState(const QModelIndex &index) -{ - return mCheckStates[item(index.row())->fileName()]; -} - -bool EsxModel::DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &parent) -{ - if (oldrow < 0 || row < 0 || oldrow == row) - return false; - - emit layoutAboutToBeChanged(); - //emit beginMoveRows(parent, oldrow, oldrow, parent, row); - mFiles.swap(oldrow, row); - //emit endInsertRows(); - emit layoutChanged(); - - return true; -} - -QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole) - return QVariant(); - - if (orientation == Qt::Horizontal) { - switch (section) { - case 0: return tr("Name"); - case 1: return tr("Author"); - case 2: return tr("Size"); - case 3: return tr("Modified"); - case 4: return tr("Accessed"); - case 5: return tr("Version"); - case 6: return tr("Path"); - case 7: return tr("Masters"); - case 8: return tr("Description"); - } - } - return QVariant(); -} - -//!!!!!!!!!!!!!!!!!!!!!!! -bool lessThanEsmFile(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) -{ - //Masters first then alphabetically - if (e1->fileName().endsWith(".esm") && !e2->fileName().endsWith(".esm")) - return true; - if (!e1->fileName().endsWith(".esm") && e2->fileName().endsWith(".esm")) - return false; - - return e1->fileName().toLower() < e2->fileName().toLower(); -} -//!!!!!!!!!!!!!!!!!!!!!!! -bool lessThanDate(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2) -{ - if (e1->modified().toString(Qt::ISODate) < e2->modified().toString(Qt::ISODate)) - return true; - else - return false; -} -//!!!!!!!!!!!!!!!!!!!!!!! -void EsxModel::DataFilesModel::sort(int column, Qt::SortOrder order) -{ - emit layoutAboutToBeChanged(); - - if (column == 3) { - qSort(mFiles.begin(), mFiles.end(), lessThanDate); - } else { - qSort(mFiles.begin(), mFiles.end(), lessThanEsmFile); - } - - emit layoutChanged(); -} - -void EsxModel::DataFilesModel::addFile(const EsmFile *file) -{ - emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); - mFiles.append(file); - emit endInsertRows(); -} - -void EsxModel::DataFilesModel::addFiles(const QString &path) -{ - QDir dir(path); - QStringList filters; - filters << "*.esp" << "*.esm" << "*.omwgame" << "*.omwaddon"; - dir.setNameFilters(filters); - - // Create a decoder for non-latin characters in esx metadata - QTextCodec *codec; - - if (mEncoding == QLatin1String("win1252")) { - codec = QTextCodec::codecForName("windows-1252"); - } else if (mEncoding == QLatin1String("win1251")) { - codec = QTextCodec::codecForName("windows-1251"); - } else if (mEncoding == QLatin1String("win1250")) { - codec = QTextCodec::codecForName("windows-1250"); - } else { - return; // This should never happen; - } - - QTextDecoder *decoder = codec->makeDecoder(); - - foreach (const QString &path, dir.entryList()) { - QFileInfo info(dir.absoluteFilePath(path)); - EsmFile *file = new EsmFile(path); - - try { - ESM::ESMReader fileReader; - ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(mEncoding.toStdString())); - fileReader.setEncoder(&encoder); - fileReader.open(dir.absoluteFilePath(path).toStdString()); - - std::vector mlist = fileReader.getMasters(); - - QStringList masters; - - for (unsigned int i = 0; i < mlist.size(); ++i) { - QString master = QString::fromStdString(mlist[i].name); - masters.append(master); - } - - file->setAuthor(decoder->toUnicode(fileReader.getAuthor().c_str())); - file->setSize(info.size()); - file->setDates(info.lastModified(), info.lastRead()); - file->setVersion(fileReader.getFVer()); - file->setPath(info.absoluteFilePath()); - file->setMasters(masters); - file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str())); - - - // 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 addon file: " << e.what(); - continue; - } - - } - - delete decoder; -} - -QModelIndex EsxModel::DataFilesModel::indexFromItem(const EsmFile *item) const -{ - if (item) - //return createIndex(mFiles.indexOf(item), 0); - return index(mFiles.indexOf(item),0); - - return QModelIndex(); -} - -EsxModel::EsmFileList EsxModel::DataFilesModel::checkedItems() -{ - EsmFileList list; - - EsmFileList::ConstIterator it; - EsmFileList::ConstIterator itEnd = mFiles.constEnd(); - - for (it = mFiles.constBegin(); it != itEnd; ++it) - { - // Only add the items that are in the checked list and available - if (mCheckStates[(*it)->fileName()] == Qt::Checked && canBeChecked(*it)) - list << (*it); - } - - return list; -} - -QStringList EsxModel::DataFilesModel::checkedItemsPaths() -{ - QStringList list; - - EsmFileList::ConstIterator it; - EsmFileList::ConstIterator itEnd = mFiles.constEnd(); - - int i = 0; - for (it = mFiles.constBegin(); it != itEnd; ++it) { - const EsmFile *file = item(i); - ++i; - - if (mCheckStates[file->fileName()] == Qt::Checked && canBeChecked(file)) - list << file->path(); - } - - return list; -} -void EsxModel::DataFilesModel::uncheckAll() -{ - emit layoutAboutToBeChanged(); - mCheckStates.clear(); - emit layoutChanged(); -} - -/* -EsxModel::EsmFileList EsxModel::DataFilesModel::uncheckedItems() -{ - EsmFileList list; - EsmFileList checked = checkedItems(); - - EsmFileList::ConstIterator it; - - for (it = mFiles.constBegin(); it != mFiles.constEnd(); ++it) - { - const EsmFile *file = *it; - - // Add the items that are not in the checked list - if (!checked.contains(file)) - list << file; - } - - return list; -} -*/ -bool EsxModel::DataFilesModel::canBeChecked(const EsmFile *file) const -{ - //element can be checked if all its dependencies are - foreach (const QString &master, file->masters()) - { - if (!mCheckStates.contains(master) || mCheckStates[master] != Qt::Checked) - return false; - } - return true; -} diff --git a/components/esxselector/model/datafilesmodel.hpp b/components/esxselector/model/datafilesmodel.hpp deleted file mode 100644 index 4f23cd530..000000000 --- a/components/esxselector/model/datafilesmodel.hpp +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef DATAFILESMODEL_HPP -#define DATAFILESMODEL_HPP - -#include -#include -#include -#include - -namespace EsxModel -{ - class EsmFile; - - typedef QList EsmFileList; - - class DataFilesModel : public QAbstractTableModel - { - Q_OBJECT - - public: - explicit DataFilesModel(QObject *parent = 0); - virtual ~DataFilesModel(); - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - bool removeRows(int row, int count, const QModelIndex &parent); - bool insertRows(int row, int count, const QModelIndex &parent); - - bool moveRow(int oldrow, int row, const QModelIndex &parent = QModelIndex()); - - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); - - inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const - { - QModelIndex idx = QAbstractTableModel::index(row, 0, parent); - return idx; - } - - void setEncoding(const QString &encoding); - - void addFiles(const QString &path); - - void uncheckAll(); - - Qt::DropActions supportedDropActions() const; - QStringList mimeTypes() const; - QMimeData *mimeData(const QModelIndexList &indexes) const; - bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); - - EsmFileList checkedItems(); - EsmFileList uncheckedItems(); - QStringList checkedItemsPaths(); - - Qt::CheckState checkState(const QModelIndex &index); - void setCheckState(const QModelIndex &index, Qt::CheckState state); - - QModelIndex indexFromItem(const EsmFile *item) const; - const EsmFile* findItem(const QString &name); - const EsmFile* item(int row) const; - - signals: - void checkedItemsChanged(const EsmFileList &items); - - private: - - bool canBeChecked(const EsmFile *file) const; - void addFile(const EsmFile *file); - - EsmFileList mFiles; - QHash mCheckStates; - - QString mEncoding; - - }; -} -#endif // DATAFILESMODEL_HPP diff --git a/components/esxselector/model/masterproxymodel.cpp b/components/esxselector/model/masterproxymodel.cpp deleted file mode 100644 index df74d0356..000000000 --- a/components/esxselector/model/masterproxymodel.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "masterproxymodel.hpp" -#include -#include - -EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) : - QSortFilterProxyModel(parent) -{ - setFilterRegExp(QString("game")); - setFilterRole (Qt::UserRole); - - if (model) - setSourceModel (model); -} diff --git a/components/esxselector/model/masterproxymodel.hpp b/components/esxselector/model/masterproxymodel.hpp deleted file mode 100644 index 8a5c73032..000000000 --- a/components/esxselector/model/masterproxymodel.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MASTERPROXYMODEL_HPP -#define MASTERPROXYMODEL_HPP - -#include -#include -#include - -class QAbstractTableModel; - -namespace EsxModel -{ - 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: - void slotSourceModelChanged(QModelIndex topLeft, QModelIndex botRight); - }; -} -#endif // MASTERPROXYMODEL_HPP diff --git a/components/esxselector/model/modelitem.cpp b/components/esxselector/model/modelitem.cpp deleted file mode 100644 index 03b19f691..000000000 --- a/components/esxselector/model/modelitem.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "modelitem.hpp" - -EsxModel::ModelItem::ModelItem(ModelItem *parent) - : mParentItem(parent) -{ -} -/* -EsxModel::ModelItem::ModelItem(const ModelItem *parent) - // : mParentItem(parent) -{ -} -*/ - -EsxModel::ModelItem::~ModelItem() -{ - qDeleteAll(mChildItems); -} - - -EsxModel::ModelItem *EsxModel::ModelItem::parent() const -{ - return mParentItem; -} - -bool EsxModel::ModelItem::hasFormat(const QString &mimetype) const -{ - if (mimetype == "application/omwcontent") - return true; - - return QMimeData::hasFormat(mimetype); -} -int EsxModel::ModelItem::row() const -{ - if (mParentItem) - return 1; - //return mParentItem->childRow(const_cast(this)); - //return mParentItem->mChildItems.indexOf(const_cast(this)); - - return -1; -} - - -int EsxModel::ModelItem::childCount() const -{ - return mChildItems.count(); -} - -int EsxModel::ModelItem::childRow(ModelItem *child) const -{ - Q_ASSERT(child); - - return mChildItems.indexOf(child); -} - -EsxModel::ModelItem *EsxModel::ModelItem::child(int row) -{ - return mChildItems.value(row); -} - - -void EsxModel::ModelItem::appendChild(ModelItem *item) -{ - mChildItems.append(item); -} - -void EsxModel::ModelItem::removeChild(int row) -{ - mChildItems.removeAt(row); -} diff --git a/components/esxselector/model/pluginsproxymodel.cpp b/components/esxselector/model/pluginsproxymodel.cpp deleted file mode 100644 index c543672b0..000000000 --- a/components/esxselector/model/pluginsproxymodel.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "pluginsproxymodel.hpp" -#include "contentmodel.hpp" -#include - -EsxModel::PluginsProxyModel::PluginsProxyModel(QObject *parent, ContentModel *model) : - QSortFilterProxyModel(parent) -{ - setFilterRegExp (QString("addon")); - setFilterRole (Qt::UserRole); - setDynamicSortFilter (true); - - if (model) - setSourceModel (model); -} diff --git a/components/esxselector/model/pluginsproxymodel.hpp b/components/esxselector/model/pluginsproxymodel.hpp deleted file mode 100644 index 4415df716..000000000 --- a/components/esxselector/model/pluginsproxymodel.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef PLUGINSPROXYMODEL_HPP -#define PLUGINSPROXYMODEL_HPP - -#include - -class QVariant; -class QAbstractTableModel; - -namespace EsxModel -{ - class ContentModel; - - class PluginsProxyModel : public QSortFilterProxyModel - { - Q_OBJECT - - public: - - explicit PluginsProxyModel(QObject *parent = 0, ContentModel *model = 0); - ~PluginsProxyModel(); - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - bool removeRows(int row, int count, const QModelIndex &parent); - }; -} - -#endif // PLUGINSPROXYMODEL_HPP diff --git a/components/esxselector/model/sourcemodel.cpp b/components/esxselector/model/sourcemodel.cpp deleted file mode 100644 index 7b54adba9..000000000 --- a/components/esxselector/model/sourcemodel.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "sourcemodel.h" - -SourceModel::SourceModel(QObject *parent) : - QAbstractTableClass(parent) -{ -} diff --git a/components/esxselector/model/sourcemodel.h b/components/esxselector/model/sourcemodel.h deleted file mode 100644 index cf5145675..000000000 --- a/components/esxselector/model/sourcemodel.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SOURCEMODEL_H -#define SOURCEMODEL_H - -#include - -class SourceModel : public QAbstractTableClass -{ - Q_OBJECT -public: - explicit SourceModel(QObject *parent = 0); - -signals: - -public slots: - -}; - -#endif // SOURCEMODEL_H diff --git a/components/esxselector/view/contentselector.cpp b/components/esxselector/view/contentselector.cpp deleted file mode 100644 index 4f8ac7253..000000000 --- a/components/esxselector/view/contentselector.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "contentselector.hpp" - -#include "../model/datafilesmodel.hpp" -#include "../model/contentmodel.hpp" -#include "../model/esmfile.hpp" - -#include - -#include -#include -#include - -EsxView::ContentSelector::ContentSelector(QWidget *parent) : - QDialog(parent) -{ - setupUi(this); - - buildSourceModel(); - buildMasterView(); - buildPluginsView(); - buildProfilesView(); - - updateViews(); - -} - -void EsxView::ContentSelector::buildSourceModel() -{ - mContentModel = new EsxModel::ContentModel(); - connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); -} - -void EsxView::ContentSelector::buildMasterView() -{ - mMasterProxyModel = new QSortFilterProxyModel(this); - mMasterProxyModel->setFilterRegExp(QString("game")); - mMasterProxyModel->setFilterRole (Qt::UserRole); - mMasterProxyModel->setSourceModel (mContentModel); - - masterView->setPlaceholderText(QString("Select a game file...")); - masterView->setModel(mMasterProxyModel); - - connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); - - masterView->setCurrentIndex(-1); - masterView->setCurrentIndex(0); -} - -void EsxView::ContentSelector::buildPluginsView() -{ - mPluginsProxyModel = new QSortFilterProxyModel(this); - mPluginsProxyModel->setFilterRegExp (QString("addon")); - mPluginsProxyModel->setFilterRole (Qt::UserRole); - mPluginsProxyModel->setDynamicSortFilter (true); - mPluginsProxyModel->setSourceModel (mContentModel); - - pluginView->setModel(mPluginsProxyModel); - - connect(pluginView, 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))); -} - -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) -{ - mContentModel->addFiles(path); - mContentModel->sort(3); // Sort by date accessed - masterView->setCurrentIndex(-1); - mContentModel->uncheckAll(); -} - -void EsxView::ContentSelector::setEncoding(const QString &encoding) -{ - mContentModel->setEncoding(encoding); -} - -QStringList EsxView::ContentSelector::checkedItemsPaths() -{ - 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) -{ - static int oldIndex = -1; - - QAbstractItemModel *const model = masterView->model(); - QSortFilterProxyModel *proxy = dynamic_cast(model); - - if (proxy) - proxy->setDynamicSortFilter(false); - - if (oldIndex > -1) - qDebug() << "clearing old master check state"; - model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); - - oldIndex = index; - - qDebug() << "setting new master check state"; - model->setData(model->index(index, 0), true, Qt::UserRole + 1); - - if (proxy) - proxy->setDynamicSortFilter(true); -} - -void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index) -{ - QAbstractItemModel *const model = pluginView->model(); - QSortFilterProxyModel *proxy = dynamic_cast(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); -} diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 5b0a6d229..82d00922b 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -23,7 +23,7 @@ - + false @@ -34,7 +34,7 @@ - + 0 @@ -102,7 +102,7 @@ - + Enter project name... @@ -159,7 +159,7 @@ 6 - + true @@ -251,12 +251,12 @@ EsxView::ProfilesComboBox QComboBox -
components/esxselector/view/profilescombobox.hpp
+
components/contentselector/view/profilescombobox.hpp
EsxView::LineEdit QLineEdit -
components/esxselector/view/lineedit.hpp
+
components/contentselector/view/lineedit.hpp
From 513f0c4b3ef1d15160619b49eb95d6a23a411c59 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 22 Sep 2013 23:52:53 -0500 Subject: [PATCH 42/42] Implemented file/adjuster widgets into new addon creation dialog --- apps/launcher/datafilespage.cpp | 4 +- apps/opencs/view/doc/adjusterwidget.cpp | 6 +- apps/opencs/view/doc/adjusterwidget.hpp | 5 +- apps/opencs/view/doc/filedialog.cpp | 53 ++++++++++-- apps/opencs/view/doc/filedialog.hpp | 17 +++- apps/opencs/view/doc/filewidget.cpp | 7 +- apps/opencs/view/doc/filewidget.hpp | 2 + .../contentselector/view/contentselector.cpp | 5 +- .../contentselector/view/contentselector.hpp | 1 + files/ui/datafilespage.ui | 80 ++++++++++++++++--- 10 files changed, 152 insertions(+), 28 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 1526b705a..44392794b 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -306,7 +306,7 @@ void DataFilesPage::setPluginsCheckstates(Qt::CheckState state) if (!sourceIndex.isValid()) return; - bool isChecked = ( state == Qt::Checked ); + //bool isChecked = ( state == Qt::Checked ); mContentModel->setData(sourceIndex, state, Qt::CheckStateRole); } @@ -397,7 +397,7 @@ void DataFilesPage::slotCurrentGameFileIndexChanged(int index) void DataFilesPage::slotAddonTableItemClicked(const QModelIndex &index) { QAbstractItemModel *const model = addonView->model(); - QSortFilterProxyModel *proxy = dynamic_cast(model); + //QSortFilterProxyModel *proxy = dynamic_cast(model); if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) model->setData(index, Qt::Checked, Qt::CheckStateRole); diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp index 910819700..2784bca8c 100644 --- a/apps/opencs/view/doc/adjusterwidget.cpp +++ b/apps/opencs/view/doc/adjusterwidget.cpp @@ -43,6 +43,10 @@ boost::filesystem::path CSVDoc::AdjusterWidget::getPath() const return mResultPath; } +bool CSVDoc::AdjusterWidget::isValid() const +{ + return mValid; +} void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) { QString message; @@ -88,4 +92,4 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) pixmap (QSize (16, 16))); emit stateChanged (mValid); -} \ No newline at end of file +} diff --git a/apps/opencs/view/doc/adjusterwidget.hpp b/apps/opencs/view/doc/adjusterwidget.hpp index f578dc4ae..d970cffee 100644 --- a/apps/opencs/view/doc/adjusterwidget.hpp +++ b/apps/opencs/view/doc/adjusterwidget.hpp @@ -25,6 +25,9 @@ namespace CSVDoc void setLocalData (const boost::filesystem::path& localData); + QString getText() const; + bool isValid() const; + boost::filesystem::path getPath() const; ///< This function must not be called if there is no valid path. @@ -38,4 +41,4 @@ namespace CSVDoc }; } -#endif \ No newline at end of file +#endif diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 1d6bed7a7..9dce090a1 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -9,12 +9,22 @@ #include #include #include +#include #include #include +#include "filewidget.hpp" +#include "adjusterwidget.hpp" + +#include + CSVDoc::FileDialog::FileDialog(QWidget *parent) : - ContentSelector(parent) + ContentSelector(parent), + mFileWidget (new FileWidget (this)), + mAdjusterWidget (new AdjusterWidget (this)), + mEnable_1(false), + mEnable_2(false) { // Hide the profile elements profileGroupBox->hide(); @@ -22,12 +32,20 @@ CSVDoc::FileDialog::FileDialog(QWidget *parent) : resize(400, 400); - connect(projectNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateCreateButton(QString))); + mFileWidget->setType(true); + mFileWidget->extensionLabelIsVisible(false); connect(projectCreateButton, SIGNAL(clicked()), this, SIGNAL(createNewFile())); connect(projectButtonBox, SIGNAL(accepted()), this, SIGNAL(openFiles())); connect(projectButtonBox, SIGNAL(rejected()), this, SLOT(reject())); + + connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)), + mAdjusterWidget, SLOT (setName (const QString&, bool))); + + connect (mAdjusterWidget, SIGNAL (stateChanged (bool)), this, SLOT (slotAdjusterChanged(bool))); + connect (this, SIGNAL (signalGameFileChanged(int)), this, SLOT (slotGameFileSelected(int))); + connect (this, SIGNAL (signalUpdateCreateButton(bool, int)), this, SLOT (slotEnableCreateButton(bool, int))); } void CSVDoc::FileDialog::updateOpenButton(const QStringList &items) @@ -40,24 +58,30 @@ void CSVDoc::FileDialog::updateOpenButton(const QStringList &items) openButton->setEnabled(!items.isEmpty()); } -void CSVDoc::FileDialog::updateCreateButton(const QString &name) +void CSVDoc::FileDialog::slotEnableCreateButton(bool enable, int widgetNumber) { - if (!projectCreateButton->isVisible()) - return; - projectCreateButton->setEnabled(!name.isEmpty()); + if (widgetNumber == 1) + mEnable_1 = enable; + + if (widgetNumber == 2) + mEnable_2 = enable; + + qDebug() << "update enabled" << mEnable_1 << mEnable_2 << enable; + projectCreateButton->setEnabled(mEnable_1 && mEnable_2); } QString CSVDoc::FileDialog::fileName() { - return projectNameLineEdit->text(); + return mFileWidget->getName(); } void CSVDoc::FileDialog::openFile() { setWindowTitle(tr("Open")); - projectNameLineEdit->hide(); + mFileWidget->hide(); + adjusterWidgetFrame->hide(); projectCreateButton->hide(); projectGroupBox->setTitle(tr("")); projectButtonBox->button(QDialogButtonBox::Open)->setEnabled(false); @@ -71,6 +95,9 @@ void CSVDoc::FileDialog::newFile() { setWindowTitle(tr("New")); + fileWidgetFrame->layout()->addWidget(mFileWidget); + adjusterWidgetFrame->layout()->addWidget(mAdjusterWidget); + projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel); projectButtonBox->addButton(projectCreateButton, QDialogButtonBox::ActionRole); @@ -78,3 +105,13 @@ void CSVDoc::FileDialog::newFile() raise(); activateWindow(); } + +void CSVDoc::FileDialog::slotAdjusterChanged(bool value) +{ + emit signalUpdateCreateButton(mAdjusterWidget->isValid(), 2); +} + +void CSVDoc::FileDialog::slotGameFileSelected(int value) +{ + emit signalUpdateCreateButton(value > -1, 1); +} diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index d0c3461b9..7782dd94e 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -26,9 +26,19 @@ namespace ContentSelectorView namespace CSVDoc { + class FileWidget; + class AdjusterWidget; + class FileDialog : public ContentSelectorView::ContentSelector { Q_OBJECT + + FileWidget *mFileWidget; + AdjusterWidget *mAdjusterWidget; + + bool mEnable_1; + bool mEnable_2; + public: explicit FileDialog(QWidget *parent = 0); @@ -41,12 +51,17 @@ namespace CSVDoc void openFiles(); void createNewFile(); + void signalUpdateCreateButton (bool, int); + void signalUpdateCreateButtonFlags(int); + public slots: private slots: //void updateViews(); void updateOpenButton(const QStringList &items); - void updateCreateButton(const QString &name); + void slotEnableCreateButton(bool enable, int widgetNumber); + void slotAdjusterChanged(bool value); + void slotGameFileSelected(int value); }; } #endif // FILEDIALOG_HPP diff --git a/apps/opencs/view/doc/filewidget.cpp b/apps/opencs/view/doc/filewidget.cpp index c8f33e92d..9cd2fad42 100644 --- a/apps/opencs/view/doc/filewidget.cpp +++ b/apps/opencs/view/doc/filewidget.cpp @@ -50,4 +50,9 @@ QString CSVDoc::FileWidget::getName() const void CSVDoc::FileWidget::textChanged (const QString& text) { emit nameChanged (getName(), mAddon); -} \ No newline at end of file +} + +void CSVDoc::FileWidget::extensionLabelIsVisible(bool visible) +{ + mType->setVisible(visible); +} diff --git a/apps/opencs/view/doc/filewidget.hpp b/apps/opencs/view/doc/filewidget.hpp index c51c29632..ff09d71a3 100644 --- a/apps/opencs/view/doc/filewidget.hpp +++ b/apps/opencs/view/doc/filewidget.hpp @@ -27,6 +27,8 @@ namespace CSVDoc QString getName() const; + void extensionLabelIsVisible(bool visible); + private slots: void textChanged (const QString& text); diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 615e9a846..e6ed0ec56 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -40,6 +40,7 @@ void ContentSelectorView::ContentSelector::buildGameFileView() gameFileView->setModel(mGameFileProxyModel); connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentGameFileIndexChanged(int))); + connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SIGNAL(signalGameFileChanged(int))); gameFileView->setCurrentIndex(-1); gameFileView->setCurrentIndex(0); @@ -120,12 +121,14 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i if (proxy) proxy->setDynamicSortFilter(true); + + emit signalGameFileChanged(true); } void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index) { QAbstractItemModel *const model = addonView->model(); - QSortFilterProxyModel *proxy = dynamic_cast(model); + //QSortFilterProxyModel *proxy = dynamic_cast(model); if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) model->setData(index, Qt::Checked, Qt::CheckStateRole); diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 8032b0449..5af53dc46 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -40,6 +40,7 @@ namespace ContentSelectorView signals: void profileChanged(int index); + void signalGameFileChanged(int value); private slots: void updateViews(); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 82d00922b..949407759 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -10,6 +10,12 @@ 313 + + + 0 + 0 + + Qt::DefaultContextMenu @@ -97,15 +103,44 @@
+ + + 0 + 0 + + Project + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + - - - Enter project name... + + + + 0 + 0 + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + @@ -126,9 +161,33 @@
- projectButtonBox - projectCreateButton - projectNameLineEdit +
+
+ + + + + 1 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + @@ -249,14 +308,9 @@
- EsxView::ProfilesComboBox + ContentSelectorView::ProfilesComboBox QComboBox -
components/contentselector/view/profilescombobox.hpp
-
- - EsxView::LineEdit - QLineEdit -
components/contentselector/view/lineedit.hpp
+
components/contentselector/view/profilescombobox.hpp