Implementing ContentSelector class in DataFilesPage

Moved AdjusterWidget / FileWidget to ContentSelectorView
pull/51/head
graffy76 11 years ago
parent 24b167b755
commit 00c78a4aa1

@ -19,7 +19,6 @@
#include "utils/textinputdialog.hpp"
#include "components/contentselector/view/contentselector.hpp"
#include "components/contentselector/model/contentmodel.hpp"
#include <QDebug>
@ -28,176 +27,59 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
, mGameSettings(gameSettings)
, mLauncherSettings(launcherSettings)
{
setupUi(this);
/*
// QMetaObject::connectSlotsByName(this);
unsigned char flags;
projectGroupBox->hide();
flags = ContentSelectorView::Flag_Content | ContentSelectorView::Flag_Profile;
// Create a dialog for the new profile name input
mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this);
ContentSelectorView::ContentSelector::configure(this, flags);
connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString)));
buildContentModel();
buildGameFileView();
buildAddonView();
buildProfilesView();
createActions();
setupDataFiles();
ContentSelectorView::ContentSelector &cSelector =
ContentSelectorView::ContentSelector::instance();
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 (&cSelector, SIGNAL (signalProfileRenamed (QString, QString)),
this, SLOT (slotProfileRenamed (QString, QString)));
connect(addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &)));
}
connect (&cSelector, SIGNAL (signalProfileChanged (QString, QString)),
this, SLOT (slotProfileChanged (QString, QString)));
void DataFilesPage::buildProfilesView()
{
profilesComboBox->setPlaceholderText(QString("Select a profile..."));
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
}
connect (&cSelector, SIGNAL (signalProfileDeleted (QString)),
this, SLOT (slotProfileDeleted (QString)));
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
// ui.gameFileView->setCurrentIndex(-1);
// mContentModel->uncheckAll();
}
void DataFilesPage::createActions()
{
// Add the actions to the toolbuttons
newProfileButton->setDefaultAction(newProfileAction);
deleteProfileButton->setDefaultAction(deleteProfileAction);
}
void DataFilesPage::setupDataFiles()
{
// Set the encoding to the one found in openmw.cfg or the default
//mContentSelector.setEncoding(mGameSettings.value(QString("encoding"), QString("win1252")));
QStringList paths = mGameSettings.getDataDirs();
foreach (const QString &path, paths) {
//mContentSelector.
mContentModel->addFiles(path);
}
QString dataLocal = mGameSettings.getDataLocal();
if (!dataLocal.isEmpty())
//mContentSelector.
mContentModel->addFiles(dataLocal);
// Sort by date accessed for now
//mContentSelector->sort(3);
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
if (!profiles.isEmpty())
profilesComboBox->addItems(profiles);
// Add the current profile if empty
if (profilesComboBox->findText(profile) == -1 && !profile.isEmpty())
profilesComboBox->addItem(profile);
if (profilesComboBox->findText(QString("Default")) == -1)
profilesComboBox->addItem(QString("Default"));
if (profile.isEmpty() || profile == QLatin1String("Default")) {
deleteProfileAction->setEnabled(false);
profilesComboBox->setEditEnabled(false);
profilesComboBox->setCurrentIndex(profilesComboBox->findText(QString("Default")));
} else {
profilesComboBox->setEditEnabled(true);
profilesComboBox->setCurrentIndex(profilesComboBox->findText(profile));
}
// We do this here to prevent deletion of profiles when initializing the combobox
connect(profilesComboBox, SIGNAL(profileRenamed(QString,QString)), this, SLOT(profileRenamed(QString,QString)));
connect(profilesComboBox, SIGNAL(profileChanged(QString,QString)), this, SLOT(profileChanged(QString,QString)));
loadSettings();
gameFileView->setCurrentIndex(-1);
connect (&cSelector, SIGNAL (signalProfileAdded ()),
this, SLOT (slotProfileAdded ()));
}
void DataFilesPage::loadSettings()
{
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
if (profile.isEmpty())
return;
// mContentSelector.
mContentModel->uncheckAll();
QStringList gameFiles = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly);
QStringList files = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly);
QStringList addons = mLauncherSettings.values(QString("Profiles/") + profile + QString("/plugin"), Qt::MatchExactly);
foreach (const QString &file, addons)
files.append(file);
//ContentSelectorView::ContentSelector::instance().setCheckStates(files);
}
void DataFilesPage::saveSettings()
{
if (mContentModel->rowCount() < 1)
return;
ContentSelectorModel::ContentFileList items =
ContentSelectorView::ContentSelector::instance().selectedFiles();
if (items.size() == 0)
return;
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
if (profile.isEmpty()) {
profile = profilesComboBox->currentText();
profile = ContentSelectorView::ContentSelector::instance().getProfileText();
mLauncherSettings.setValue(QString("Profiles/currentprofile"), profile);
}
@ -207,8 +89,6 @@ void DataFilesPage::saveSettings()
mGameSettings.remove(QString("master"));
mGameSettings.remove(QString("plugin"));
ContentSelectorModel::ContentFileList items = mContentModel->checkedItems();
foreach(const ContentSelectorModel::EsmFile *item, items) {
if (item->gameFiles().size() == 0) {
@ -223,109 +103,18 @@ void DataFilesPage::saveSettings()
}
void DataFilesPage::updateOkButton(const QString &text)
void DataFilesPage::slotProfileDeleted (const QString &item)
{
// We do this here because we need the profiles combobox text
if (text.isEmpty()) {
mNewProfileDialog->setOkButtonEnabled(false);
return;
}
(profilesComboBox->findText(text) == -1)
? mNewProfileDialog->setOkButtonEnabled(true)
: mNewProfileDialog->setOkButtonEnabled(false);
}
void DataFilesPage::setProfilesComboBoxIndex(int index)
{
profilesComboBox->setCurrentIndex(index);
}
QAbstractItemModel* DataFilesPage::profilesComboBoxModel()
{
return profilesComboBox->model();
}
int DataFilesPage::profilesComboBoxIndex()
{
return profilesComboBox->currentIndex();
}
void DataFilesPage::on_newProfileAction_triggered()
{
if (mNewProfileDialog->exec() == QDialog::Accepted) {
QString profile = mNewProfileDialog->lineEdit()->text();
profilesComboBox->addItem(profile);
profilesComboBox->setCurrentIndex(profilesComboBox->findText(profile));
}
}
void DataFilesPage::on_deleteProfileAction_triggered()
{
QString profile = profilesComboBox->currentText();
if (profile.isEmpty())
return;
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Delete Profile"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setText(tr("Are you sure you want to delete <b>%0</b>?").arg(profile));
QAbstractButton *deleteButton =
msgBox.addButton(tr("Delete"), QMessageBox::ActionRole);
msgBox.exec();
if (msgBox.clickedButton() == deleteButton) {
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/master"));
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/plugin"));
// Remove the profile from the combobox
profilesComboBox->removeItem(profilesComboBox->findText(profile));
}
}
void DataFilesPage::setPluginsCheckstates(Qt::CheckState state)
{
if (!addonView->selectionModel()->hasSelection()) {
return;
}
QModelIndexList indexes = addonView->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, indexes)
{
if (!index.isValid())
return;
QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index);
if (!sourceIndex.isValid())
return;
//bool isChecked = ( state == Qt::Checked );
mContentModel->setData(sourceIndex, state, Qt::CheckStateRole);
}
mLauncherSettings.remove(QString("Profiles/") + item + QString("/master"));
mLauncherSettings.remove(QString("Profiles/") + item + QString("/plugin"));
}
void DataFilesPage::profileChanged(const QString &previous, const QString &current)
void DataFilesPage::slotProfileChanged(const QString &previous, const QString &current)
{
// Prevent the deletion of the default profile
if (current == QLatin1String("Default")) {
deleteProfileAction->setEnabled(false);
profilesComboBox->setEditEnabled(false);
} else {
deleteProfileAction->setEnabled(true);
profilesComboBox->setEditEnabled(true);
}
if (previous.isEmpty())
return;
if (profilesComboBox->findText(previous) == -1)
if (ContentSelectorView::ContentSelector::instance().getProfileIndex (previous) == -1)
return; // Profile was deleted
// Store the previous profile
@ -336,7 +125,7 @@ void DataFilesPage::profileChanged(const QString &previous, const QString &curre
loadSettings();
}
void DataFilesPage::profileRenamed(const QString &previous, const QString &current)
void DataFilesPage::slotProfileRenamed(const QString &previous, const QString &current)
{
if (previous.isEmpty())
return;
@ -350,56 +139,55 @@ void DataFilesPage::profileRenamed(const QString &previous, const QString &curre
mLauncherSettings.remove(QString("Profiles/") + previous + QString("/plugin"));
// Remove the profile from the combobox
profilesComboBox->removeItem(profilesComboBox->findText(previous));
ContentSelectorView::ContentSelector::instance().removeProfile (previous);
loadSettings();
}
////////////////////////////
QStringList DataFilesPage::checkedItemsPaths()
void DataFilesPage::slotProfileAdded()
{
QStringList itemPaths;
TextInputDialog newDialog (tr("New Profile"), tr("Profile name:"), this);
foreach( const ContentSelectorModel::EsmFile *file, mContentModel->checkedItems())
itemPaths << file->path();
// connect(mNewDialog->lineEdit(), SIGNAL(textChanged(QString)),
// this, SLOT(updateOkButton(QString)));
return itemPaths;
if (newDialog.exec() == QDialog::Accepted)
{
QString profile = newDialog.lineEdit()->text();
ContentSelectorView::ContentSelector
::instance().addProfile(profile, true);
}
}
void DataFilesPage::slotCurrentProfileIndexChanged(int index)
void DataFilesPage::setProfilesComboBoxIndex(int index)
{
emit profileChanged(index);
ContentSelectorView::ContentSelector::instance().setProfileIndex(index);
}
void DataFilesPage::slotCurrentGameFileIndexChanged(int index)
void DataFilesPage::setupDataFiles()
{
static int oldIndex = -1;
ContentSelectorView::ContentSelector &cSelector =
ContentSelectorView::ContentSelector::instance();
QStringList paths = mGameSettings.getDataDirs();
QAbstractItemModel *const model = gameFileView->model();
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
foreach (const QString &path, paths)
cSelector.addFiles(path);
if (proxy)
proxy->setDynamicSortFilter(false);
QString dataLocal = mGameSettings.getDataLocal();
if (oldIndex > -1)
model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1);
if (!dataLocal.isEmpty())
cSelector.addFiles(dataLocal);
oldIndex = index;
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
model->setData(model->index(index, 0), true, Qt::UserRole + 1);
if (proxy)
proxy->setDynamicSortFilter(true);
}
foreach (const QString &item, profiles)
cSelector.addProfile (item);
void DataFilesPage::slotAddonTableItemClicked(const QModelIndex &index)
{
QAbstractItemModel *const model = addonView->model();
//QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
cSelector.addProfile (profile, true);
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
model->setData(index, Qt::Checked, Qt::CheckStateRole);
else
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
loadSettings();
}

@ -4,9 +4,6 @@
#include <QWidget>
#include <QModelIndex>
#include "ui_datafilespage.h"
#include "components/contentselector/view/contentselector.hpp"
class QSortFilterProxyModel;
class QAbstractItemModel;
class QAction;
@ -19,7 +16,7 @@ class LauncherSettings;
namespace Files { struct ConfigurationManager; }
class DataFilesPage : public QWidget, private Ui::DataFilesPage
class DataFilesPage : public QWidget
{
Q_OBJECT
@ -36,58 +33,33 @@ signals:
void profileChanged(int index);
public slots:
void setProfilesComboBoxIndex(int index);
//void showContextMenu(const QPoint &point);
//void showContextMenu(const QPoint &point);
void profileChanged(const QString &previous, const QString &current);
void profileRenamed(const QString &previous, const QString &current);
void updateOkButton(const QString &text);
void updateViews();
// Action slots
void on_newProfileAction_triggered();
void on_deleteProfileAction_triggered();
private slots:
void slotProfileAdded();
void slotProfileChanged(const QString &previous, const QString &current);
void slotProfileRenamed(const QString &previous, const QString &current);
void slotProfileDeleted(const QString &item);
void setProfilesComboBoxIndex(int index);
private:
QMenu *mContextMenu;
//ContentSelectorView::ContentSelector mContentSelector;
ContentSelectorModel::ContentModel *mContentModel;
Files::ConfigurationManager &mCfgMgr;
GameSettings &mGameSettings;
LauncherSettings &mLauncherSettings;
TextInputDialog *mNewProfileDialog;
QSortFilterProxyModel *mGameFileProxyModel;
QSortFilterProxyModel *mAddonProxyModel;
void setPluginsCheckstates(Qt::CheckState state);
void createActions();
void setupDataFiles();
void setupConfig();
void readConfig();
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

@ -106,10 +106,10 @@ void MainDialog::createPages()
mPlayPage = new PlayPage(this);
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, mLauncherSettings, this);
/// reimplement datafilespage functions to provide access
// Set the combobox of the play page to imitate the combobox on the datafilespage
mPlayPage->setProfilesComboBoxModel(mDataFilesPage->profilesComboBoxModel());
mPlayPage->setProfilesComboBoxIndex(mDataFilesPage->profilesComboBoxIndex());
// mPlayPage->setProfilesComboBoxModel(mDataFilesPage->profilesComboBoxModel());
// mPlayPage->setProfilesComboBoxIndex(mDataFilesPage->profilesComboBoxIndex());
// Add the pages to the stacked widget
pagesWidget->addWidget(mPlayPage);

@ -43,8 +43,7 @@ opencs_units_noqt (model/tools
opencs_units (view/doc
viewmanager view operations operation subview startup filedialog newgame filewidget
adjusterwidget
viewmanager view operations operation subview startup filedialog newgame
)

@ -124,7 +124,7 @@ void CS::Editor::openFiles()
{
std::vector<boost::filesystem::path> files;
foreach (const QString &path, mFileDialog.selectedFilepaths()) {
foreach (const QString &path, mFileDialog.selectedFilePaths()) {
files.push_back(path.toStdString());
}
@ -139,7 +139,7 @@ void CS::Editor::createNewFile()
{
std::vector<boost::filesystem::path> files;
foreach (const QString &path, mFileDialog.selectedFilepaths()) {
foreach (const QString &path, mFileDialog.selectedFilePaths()) {
files.push_back(path.toStdString());
}

@ -37,9 +37,16 @@ QString CSVDoc::FileDialog::filename()
return ContentSelectorView::ContentSelector::instance().filename();
}
QStringList CSVDoc::FileDialog::selectedFilepaths()
QStringList CSVDoc::FileDialog::selectedFilePaths()
{
return ContentSelectorView::ContentSelector::instance().selectedFiles();
QStringList filePaths;
foreach (ContentSelectorModel::EsmFile *file, ContentSelectorView::ContentSelector::
instance().selectedFiles() )
{
filePaths.append(file->fileName());
}
return filePaths;
}
void CSVDoc::FileDialog::showDialog()

@ -41,7 +41,7 @@ namespace CSVDoc
void addFiles (const QString &path);
QString filename();
QStringList selectedFilepaths();
QStringList selectedFilePaths();
private:

@ -7,8 +7,8 @@
#include <QDialogButtonBox>
#include <QPushButton>
#include "filewidget.hpp"
#include "adjusterwidget.hpp"
#include "components/contentselector/view/filewidget.hpp"
#include "components/contentselector/view/adjusterwidget.hpp"
CSVDoc::NewGameDialogue::NewGameDialogue()
{

@ -84,6 +84,7 @@ if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY)
model/naturalsort model/contentmodel
view/profilescombobox view/comboboxlineedit
view/lineedit view/contentselector
view/filewidget view/adjusterwidget
)
include(${QT_USE_FILE})

@ -1,7 +1,7 @@
#include "contentselector.hpp"
#include "../model/contentmodel.hpp"
#include "../model/esmfile.hpp"
#include "lineedit.hpp"
#include <QSortFilterProxyModel>
@ -9,10 +9,11 @@
#include <QMenu>
#include <QContextMenuEvent>
#include <QGridLayout>
#include <QMessageBox>
#include <assert.h>
#include "../../../apps/opencs/view/doc/filewidget.hpp"
#include "../../../apps/opencs/view/doc/adjusterwidget.hpp"
#include "filewidget.hpp"
#include "adjusterwidget.hpp"
ContentSelectorView::ContentSelector *ContentSelectorView::ContentSelector::mInstance = 0;
QStringList ContentSelectorView::ContentSelector::mFilePaths;
@ -25,6 +26,7 @@ void ContentSelectorView::ContentSelector::configure(QWidget *subject, unsigned
ContentSelectorView::ContentSelector& ContentSelectorView::ContentSelector::instance()
{
assert(mInstance);
return *mInstance;
}
@ -33,6 +35,7 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned
QWidget(parent), mFlags (flags),
mAdjusterWidget (0), mFileWidget (0)
{
ui.setupUi (this);
parent->setLayout(new QGridLayout());
@ -41,15 +44,23 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned
buildContentModel();
buildGameFileView();
buildAddonView();
buildProfilesView();
buildNewAddonView();
buildLoadAddonView();
buildProfilesView();
/*
//mContentModel->sort(3); // Sort by date accessed
*/
}
QString ContentSelectorView::ContentSelector::getNewProfileName()
{
// 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)));
return "";
}
bool ContentSelectorView::ContentSelector::isFlagged(SelectorFlags flag) const
{
@ -123,8 +134,17 @@ void ContentSelectorView::ContentSelector::buildProfilesView()
return;
}
ui.profilesComboBox->setPlaceholderText(QString("Select a profile..."));
connect(ui.profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
// Add the actions to the toolbuttons
ui.newProfileButton->setDefaultAction (ui.newProfileAction);
ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction);
ui.profilesComboBox->addItem ("Default");
ui.profilesComboBox->setPlaceholderText (QString("Select a profile..."));
connect (ui.profilesComboBox, SIGNAL (currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
connect (ui.profilesComboBox, SIGNAL (profileRenamed(QString,QString)), this, SIGNAL(signalProfileRenamed(QString,QString)));
connect (ui.profilesComboBox, SIGNAL (profileChanged(QString,QString)), this, SIGNAL(signalProfileChanged(QString,QString)));
connect (ui.profilesComboBox, SIGNAL (signalProfileTextChanged(QString)), this, SLOT (slotProfileTextChanged (QString)));
}
void ContentSelectorView::ContentSelector::buildLoadAddonView()
@ -136,7 +156,6 @@ void ContentSelectorView::ContentSelector::buildLoadAddonView()
}
ui.projectCreateButton->setVisible (false);
// ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Open | QDialogButtonBox::Cancel);
ui.projectGroupBox->setTitle ("");
connect(ui.projectButtonBox, SIGNAL(accepted()), this, SIGNAL(accepted()));
@ -172,6 +191,17 @@ void ContentSelectorView::ContentSelector::buildNewAddonView()
connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected()));
}
void ContentSelectorView::ContentSelector::setCheckStates(const QStringList &list)
{
if (list.isEmpty())
return;
mContentModel->uncheckAll();
foreach (const QString &file, list)
mContentModel->setCheckState(file, Qt::Checked);
}
QString ContentSelectorView::ContentSelector::filename() const
{
QString filepath = "";
@ -182,7 +212,7 @@ QString ContentSelectorView::ContentSelector::filename() const
return filepath;
}
QStringList ContentSelectorView::ContentSelector::selectedFiles() const
QStringList ContentSelectorView::ContentSelector::selectedFilePaths() const
{
QStringList filePaths;
@ -195,6 +225,15 @@ QStringList ContentSelectorView::ContentSelector::selectedFiles() const
return filePaths;
}
ContentSelectorModel::ContentFileList
ContentSelectorView::ContentSelector::selectedFiles() const
{
if (mContentModel)
return mContentModel->checkedItems();
return ContentSelectorModel::ContentFileList();
}
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
{
@ -209,6 +248,55 @@ void ContentSelectorView::ContentSelector::addFiles(const QString &path)
}
}
void ContentSelectorView::ContentSelector::removeProfile(const QString &item)
{
int idx = ui.profilesComboBox->findText(item);
if (idx != -1)
ui.profilesComboBox->removeItem(idx);
}
int ContentSelectorView::ContentSelector::getProfileIndex ( const QString &item) const
{
return ui.profilesComboBox->findText (item);
}
void ContentSelectorView::ContentSelector::setProfileIndex(int index)
{
if (index >=0 && index < ui.profilesComboBox->count())
ui.profilesComboBox->setCurrentIndex(index);
}
void ContentSelectorView::ContentSelector::addProfile (const QString &item, bool setAsCurrent)
{
if (item.isEmpty())
return;
if (ui.profilesComboBox->findText(item) == -1)
ui.profilesComboBox->addItem(item);
if (setAsCurrent)
ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(item));
enableProfilesComboBox();
}
QString ContentSelectorView::ContentSelector::getProfileText() const
{
return ui.profilesComboBox->currentText();
}
void ContentSelectorView::ContentSelector::enableProfilesComboBox()
{
if (!ui.profilesComboBox->isEnabled())
ui.profilesComboBox->setEnabled(true);
if (!ui.deleteProfileAction->isEnabled())
ui.deleteProfileAction->setEnabled(true);
ui.projectButtonBox->button(QDialogButtonBox::Open)->setEnabled (true);
}
QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
{
QStringList itemPaths;
@ -221,6 +309,12 @@ QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index)
{
//don't allow deleting "Default" profile
bool success = (ui.profilesComboBox->itemText(index) == "Default");
ui.deleteProfileAction->setEnabled(success);
ui.profilesComboBox->setEditEnabled(success);
emit signalProfileChanged(index);
}
@ -247,6 +341,14 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
slotUpdateCreateButton(true);
}
void ContentSelectorView::ContentSelector::slotProfileTextChanged(const QString &text)
{
QPushButton *opnBtn = ui.projectButtonBox->button(QDialogButtonBox::Open);
if (opnBtn->isEnabled())
opnBtn->setEnabled (false);
}
void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index)
{
QAbstractItemModel *const model = ui.addonView->model();
@ -257,16 +359,6 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QMode
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
}
void ContentSelectorView::ContentSelector::slotUpdateOpenButton(const QStringList &items)
{
QPushButton *openButton = ui.projectButtonBox->button(QDialogButtonBox::Open);
if (!openButton)
return;
openButton->setEnabled(!items.isEmpty());
}
void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool)
{
//enable only if a game file is selected and the adjuster widget is non-empty
@ -278,3 +370,44 @@ void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool)
ui.projectCreateButton->setEnabled(validGameFile && validFilename);
}
void ContentSelectorView::ContentSelector::on_newProfileAction_triggered()
{
emit signalProfileAdded();
}
void ContentSelectorView::ContentSelector::on_deleteProfileAction_triggered()
{
QString profile = ui.profilesComboBox->currentText();
if (profile.isEmpty())
return;
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Delete Profile"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setText(tr("Are you sure you want to delete <b>%0</b>?").arg(profile));
QAbstractButton *deleteButton =
msgBox.addButton(tr("Delete"), QMessageBox::ActionRole);
msgBox.exec();
if (msgBox.clickedButton() != deleteButton)
return;
// Remove the profile from the combobox
ui.profilesComboBox->removeItem(ui.profilesComboBox->findText(profile));
//signal for removal from model
emit signalProfileDeleted (profile);
}
/*
void ContentSelectorView::ContentSelector::slotUpdateOkButton(const QString &text)
{
bool success = (ui.profilesComboBox->findText(text) == -1);
mNewDialog->setOkButtonEnabled(success);
}*/

@ -4,10 +4,10 @@
#include <QDialog>
#include "ui_datafilespage.h"
namespace ContentSelectorModel { class ContentModel; }
#include "../model/contentmodel.hpp"
class QSortFilterProxyModel;
class TextInputDialog;
namespace CSVDoc
{
@ -36,6 +36,8 @@ namespace ContentSelectorView
CSVDoc::FileWidget *mFileWidget;
CSVDoc::AdjusterWidget *mAdjusterWidget;
TextInputDialog *mNewDialog;
protected:
ContentSelectorModel::ContentModel *mContentModel;
@ -43,19 +45,28 @@ namespace ContentSelectorView
QSortFilterProxyModel *mAddonProxyModel;
public:
explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content);
static void configure(QWidget *subject, unsigned char flags = Flag_Content);
static ContentSelector &instance();
static void addFiles(const QString &path);
void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
void setCheckStates (const QStringList &list);
QStringList checkedItemsPaths();
ContentSelectorModel::ContentFileList *CheckedItems();
QString filename() const;
QStringList selectedFiles() const;
ContentSelectorModel::ContentFileList selectedFiles() const;
QStringList selectedFilePaths() const;
void addProfile (const QString &item, bool setAsCurrent = false);
void removeProfile (const QString &item);
int getProfileIndex (const QString &item) const;
void setProfileIndex (int index);
QString getProfileText() const;
private:
explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content);
Ui::DataFilesPage ui;
void buildContentModel();
@ -66,6 +77,8 @@ namespace ContentSelectorView
void buildLoadAddonView();
bool isFlagged(SelectorFlags flag) const;
QString getNewProfileName();
void enableProfilesComboBox();
signals:
void accepted();
@ -76,14 +89,24 @@ namespace ContentSelectorView
void signalCreateButtonClicked();
void signalProfileRenamed(QString,QString);
void signalProfileChanged(QString,QString);
void signalProfileDeleted(QString);
void signalProfileAdded();
private slots:
void slotProfileTextChanged (const QString &text);
void slotCurrentProfileIndexChanged(int index);
void slotCurrentGameFileIndexChanged(int index);
void slotAddonTableItemClicked(const QModelIndex &index);
void slotUpdateCreateButton (bool);
void slotUpdateOpenButton(const QStringList &items);
// void slotUpdateOpenButton(const QStringList &items);
// Action slots
void on_newProfileAction_triggered();
void on_deleteProfileAction_triggered();
};
}

@ -45,6 +45,9 @@ void ContentSelectorView::ProfilesComboBox::setEditEnabled(bool editable)
connect(lineEdit(), SIGNAL(textChanged(QString)), this,
SLOT(slotTextChanged(QString)));
connect (lineEdit(), SIGNAL(textChanged(QString)), this,
SIGNAL (signalProfileTextChanged (QString)));
}
void ContentSelectorView::ProfilesComboBox::slotTextChanged(const QString &text)

@ -17,10 +17,12 @@ namespace ContentSelectorView
void setPlaceholderText (const QString &text);
signals:
void signalProfileTextChanged (const QString &item);
void profileChanged(const QString &previous, const QString &current);
void profileRenamed(const QString &oldName, const QString &newName);
private slots:
void slotEditingFinished();
void slotIndexChanged(int index);
void slotTextChanged(const QString &text);

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>518</width>
<height>313</height>
<height>424</height>
</rect>
</property>
<property name="sizePolicy">
@ -26,6 +26,9 @@
<string>Content</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<layout class="QHBoxLayout" name="filterLayout">
<item>
@ -116,6 +119,18 @@
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="fileWidgetFrame">
<property name="sizePolicy">
@ -143,18 +158,17 @@
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="projectButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Open</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="projectCreateButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Create</string>
</property>
@ -209,7 +223,7 @@
<number>3</number>
</property>
<property name="topMargin">
<number>9</number>
<number>6</number>
</property>
<property name="rightMargin">
<number>0</number>
@ -220,7 +234,7 @@
<item>
<widget class="ContentSelectorView::ProfilesComboBox" name="profilesComboBox">
<property name="enabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -228,6 +242,11 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
</widget>
</item>
<item>
@ -262,6 +281,13 @@
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="projectButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Open</set>
</property>
</widget>
</item>
</layout>
<action name="newProfileAction">
<property name="icon">
@ -280,6 +306,9 @@
</property>
</action>
<action name="deleteProfileAction">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="edit-delete">
<normaloff/>

Loading…
Cancel
Save