1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00

Add the ability to configure extended commands for tables

This commit is contained in:
Stanislav Bas 2015-07-02 20:44:59 +03:00 committed by cc9cii
parent 832e910b6f
commit 94725f32d9
7 changed files with 79 additions and 34 deletions

View File

@ -37,7 +37,7 @@ CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Docum
mCancelButton = new QPushButton("Cancel", this); mCancelButton = new QPushButton("Cancel", this);
mCancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mCancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(mCancelButton, SIGNAL(clicked(bool)), this, SLOT(done())); connect(mCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(done()));
mButtonLayout = new QHBoxLayout(); mButtonLayout = new QHBoxLayout();
mButtonLayout->setAlignment(Qt::AlignCenter); mButtonLayout->setAlignment(Qt::AlignCenter);
@ -61,12 +61,14 @@ CSVWorld::ExtendedCommandConfigurator::~ExtendedCommandConfigurator()
delete mButtonLayout; delete mButtonLayout;
} }
void CSVWorld::ExtendedCommandConfigurator::configure(CSVWorld::ExtendedCommandConfigurator::Mode mode) void CSVWorld::ExtendedCommandConfigurator::configure(CSVWorld::ExtendedCommandConfigurator::Mode mode,
const std::vector<std::string> &selectedIds)
{ {
mMode = mode; mMode = mode;
if (mMode != Mode_None) if (mMode != Mode_None)
{ {
mTypeGroup->setTitle(getTypeGroupTitle(mMode)); mTypeGroup->setTitle(getTypeGroupTitle(mMode));
mCommandDispatcher->setSelection(selectedIds);
setupCheckBoxes(mCommandDispatcher->getExtendedTypes()); setupCheckBoxes(mCommandDispatcher->getExtendedTypes());
setupGroupLayout(); setupGroupLayout();
} }

View File

@ -52,7 +52,7 @@ namespace CSVWorld
QWidget *parent = 0); QWidget *parent = 0);
virtual ~ExtendedCommandConfigurator(); virtual ~ExtendedCommandConfigurator();
void configure(Mode mode); void configure(Mode mode, const std::vector<std::string> &selectedIds);
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);

View File

@ -36,28 +36,14 @@
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
{ {
// configure dispatcher // configure dispatcher
QModelIndexList selectedRows = selectionModel()->selectedRows(); mDispatcher->setSelection (getSelectedIds());
std::vector<std::string> records;
int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
++iter)
{
int row = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)).row();
records.push_back (mModel->data (
mModel->index (row, columnIndex)).toString().toUtf8().constData());
}
mDispatcher->setSelection (records);
std::vector<CSMWorld::UniversalId> extendedTypes = mDispatcher->getExtendedTypes(); std::vector<CSMWorld::UniversalId> extendedTypes = mDispatcher->getExtendedTypes();
mDispatcher->setExtendedTypes (extendedTypes); mDispatcher->setExtendedTypes (extendedTypes);
// create context menu // create context menu
QModelIndexList selectedRows = selectionModel()->selectedRows();
QMenu menu (this); QMenu menu (this);
/// \todo add menu items for select all and clear selection /// \todo add menu items for select all and clear selection
@ -355,16 +341,12 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
connect (mPreviewAction, SIGNAL (triggered()), this, SLOT (previewRecord())); connect (mPreviewAction, SIGNAL (triggered()), this, SLOT (previewRecord()));
addAction (mPreviewAction); addAction (mPreviewAction);
/// \todo add a user option, that redirects the extended action to an input panel (in
/// the bottom bar) that lets the user select which record collections should be
/// modified.
mExtendedDeleteAction = new QAction (tr ("Extended Delete Record"), this); mExtendedDeleteAction = new QAction (tr ("Extended Delete Record"), this);
connect (mExtendedDeleteAction, SIGNAL (triggered()), mDispatcher, SLOT (executeExtendedDelete())); connect (mExtendedDeleteAction, SIGNAL (triggered()), this, SLOT (executeExtendedDelete()));
addAction (mExtendedDeleteAction); addAction (mExtendedDeleteAction);
mExtendedRevertAction = new QAction (tr ("Extended Revert Record"), this); mExtendedRevertAction = new QAction (tr ("Extended Revert Record"), this);
connect (mExtendedRevertAction, SIGNAL (triggered()), mDispatcher, SLOT (executeExtendedRevert())); connect (mExtendedRevertAction, SIGNAL (triggered()), this, SLOT (executeExtendedRevert()));
addAction (mExtendedRevertAction); addAction (mExtendedRevertAction);
mEditIdAction = new TableEditIdAction (*this, this); mEditIdAction = new TableEditIdAction (*this, this);
@ -434,6 +416,22 @@ CSMWorld::UniversalId CSVWorld::Table::getUniversalId (int row) const
mModel->data (mModel->index (row, idColumn)).toString().toUtf8().constData()); mModel->data (mModel->index (row, idColumn)).toString().toUtf8().constData());
} }
std::vector<std::string> CSVWorld::Table::getSelectedIds() const
{
std::vector<std::string> ids;
QModelIndexList selectedRows = selectionModel()->selectedRows();
int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
for (QModelIndexList::const_iterator iter (selectedRows.begin());
iter != selectedRows.end();
++iter)
{
int row = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)).row();
ids.push_back (mModel->data (mModel->index (row, columnIndex)).toString().toUtf8().constData());
}
return ids;
}
void CSVWorld::Table::editRecord() void CSVWorld::Table::editRecord()
{ {
if (!mEditLock || (mModel->getFeatures() & CSMWorld::IdTableBase::Feature_Constant)) if (!mEditLock || (mModel->getFeatures() & CSMWorld::IdTableBase::Feature_Constant))
@ -566,6 +564,34 @@ void CSVWorld::Table::previewRecord()
} }
} }
void CSVWorld::Table::executeExtendedDelete()
{
CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance();
QString configSetting = settings.settingValue ("table-input/extended-config");
if (configSetting == "true")
{
emit extendedDeleteConfigRequest(getSelectedIds());
}
else
{
QMetaObject::invokeMethod(mDispatcher, "executeExtendedDelete", Qt::QueuedConnection);
}
}
void CSVWorld::Table::executeExtendedRevert()
{
CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance();
QString configSetting = settings.settingValue ("table-input/extended-config");
if (configSetting == "true")
{
emit extendedRevertConfigRequest(getSelectedIds());
}
else
{
QMetaObject::invokeMethod(mDispatcher, "executeExtendedRevert", Qt::QueuedConnection);
}
}
void CSVWorld::Table::updateUserSetting (const QString &name, const QStringList &list) void CSVWorld::Table::updateUserSetting (const QString &name, const QStringList &list)
{ {
if (name=="table-input/jump-to-added") if (name=="table-input/jump-to-added")

View File

@ -97,6 +97,8 @@ namespace CSVWorld
std::vector<std::string> getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const; std::vector<std::string> getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const;
std::vector<std::string> getSelectedIds() const;
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const; virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
signals: signals:
@ -116,6 +118,10 @@ namespace CSVWorld
void closeRequest(); void closeRequest();
void extendedDeleteConfigRequest(const std::vector<std::string> &selectedIds);
void extendedRevertConfigRequest(const std::vector<std::string> &selectedIds);
private slots: private slots:
void editCell(); void editCell();
@ -132,6 +138,10 @@ namespace CSVWorld
void previewRecord(); void previewRecord();
void executeExtendedDelete();
void executeExtendedRevert();
public slots: public slots:
void tableSizeUpdate(); void tableSizeUpdate();

View File

@ -47,9 +47,10 @@ void CSVWorld::TableBottomBox::updateStatus()
} }
} }
void CSVWorld::TableBottomBox::extendedConfigRequest(CSVWorld::ExtendedCommandConfigurator::Mode mode) void CSVWorld::TableBottomBox::extendedConfigRequest(CSVWorld::ExtendedCommandConfigurator::Mode mode,
const std::vector<std::string> &selectedIds)
{ {
mExtendedConfigurator->configure (mode); mExtendedConfigurator->configure (mode, selectedIds);
mLayout->setCurrentWidget (mExtendedConfigurator); mLayout->setCurrentWidget (mExtendedConfigurator);
mEditMode = EditMode_ExtendedConfig; mEditMode = EditMode_ExtendedConfig;
setVisible (true); setVisible (true);
@ -207,12 +208,12 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id,
mCreator->focus(); mCreator->focus();
} }
void CSVWorld::TableBottomBox::extendedDeleteConfigRequest() void CSVWorld::TableBottomBox::extendedDeleteConfigRequest(const std::vector<std::string> &selectedIds)
{ {
extendedConfigRequest(ExtendedCommandConfigurator::Mode_Delete); extendedConfigRequest(ExtendedCommandConfigurator::Mode_Delete, selectedIds);
} }
void CSVWorld::TableBottomBox::extendedRevertConfigRequest() void CSVWorld::TableBottomBox::extendedRevertConfigRequest(const std::vector<std::string> &selectedIds)
{ {
extendedConfigRequest(ExtendedCommandConfigurator::Mode_Revert); extendedConfigRequest(ExtendedCommandConfigurator::Mode_Revert, selectedIds);
} }

View File

@ -48,7 +48,8 @@ namespace CSVWorld
void updateStatus(); void updateStatus();
void extendedConfigRequest(ExtendedCommandConfigurator::Mode mode); void extendedConfigRequest(ExtendedCommandConfigurator::Mode mode,
const std::vector<std::string> &selectedIds);
public: public:
@ -96,8 +97,8 @@ namespace CSVWorld
void cloneRequest(const std::string& id, void cloneRequest(const std::string& id,
const CSMWorld::UniversalId::Type type); const CSMWorld::UniversalId::Type type);
void extendedDeleteConfigRequest(); void extendedDeleteConfigRequest(const std::vector<std::string> &selectedIds);
void extendedRevertConfigRequest(); void extendedRevertConfigRequest(const std::vector<std::string> &selectedIds);
}; };
} }

View File

@ -89,6 +89,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)),
mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)));
connect (mTable, SIGNAL(extendedDeleteConfigRequest(const std::vector<std::string> &)),
mBottom, SLOT(extendedDeleteConfigRequest(const std::vector<std::string> &)));
connect (mTable, SIGNAL(extendedRevertConfigRequest(const std::vector<std::string> &)),
mBottom, SLOT(extendedRevertConfigRequest(const std::vector<std::string> &)));
} }
connect (mBottom, SIGNAL (requestFocus (const std::string&)), connect (mBottom, SIGNAL (requestFocus (const std::string&)),
mTable, SLOT (requestFocus (const std::string&))); mTable, SLOT (requestFocus (const std::string&)));