mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-30 03:32:36 +00:00
Add the ability to configure extended commands for tables
This commit is contained in:
parent
832e910b6f
commit
94725f32d9
@ -37,7 +37,7 @@ CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Docum
|
||||
|
||||
mCancelButton = new QPushButton("Cancel", this);
|
||||
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->setAlignment(Qt::AlignCenter);
|
||||
@ -61,12 +61,14 @@ CSVWorld::ExtendedCommandConfigurator::~ExtendedCommandConfigurator()
|
||||
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;
|
||||
if (mMode != Mode_None)
|
||||
{
|
||||
mTypeGroup->setTitle(getTypeGroupTitle(mMode));
|
||||
mCommandDispatcher->setSelection(selectedIds);
|
||||
setupCheckBoxes(mCommandDispatcher->getExtendedTypes());
|
||||
setupGroupLayout();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ namespace CSVWorld
|
||||
QWidget *parent = 0);
|
||||
virtual ~ExtendedCommandConfigurator();
|
||||
|
||||
void configure(Mode mode);
|
||||
void configure(Mode mode, const std::vector<std::string> &selectedIds);
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
|
@ -36,28 +36,14 @@
|
||||
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||
{
|
||||
// configure dispatcher
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
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);
|
||||
mDispatcher->setSelection (getSelectedIds());
|
||||
|
||||
std::vector<CSMWorld::UniversalId> extendedTypes = mDispatcher->getExtendedTypes();
|
||||
|
||||
mDispatcher->setExtendedTypes (extendedTypes);
|
||||
|
||||
// create context menu
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
QMenu menu (this);
|
||||
|
||||
/// \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()));
|
||||
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);
|
||||
connect (mExtendedDeleteAction, SIGNAL (triggered()), mDispatcher, SLOT (executeExtendedDelete()));
|
||||
connect (mExtendedDeleteAction, SIGNAL (triggered()), this, SLOT (executeExtendedDelete()));
|
||||
addAction (mExtendedDeleteAction);
|
||||
|
||||
mExtendedRevertAction = new QAction (tr ("Extended Revert Record"), this);
|
||||
connect (mExtendedRevertAction, SIGNAL (triggered()), mDispatcher, SLOT (executeExtendedRevert()));
|
||||
connect (mExtendedRevertAction, SIGNAL (triggered()), this, SLOT (executeExtendedRevert()));
|
||||
addAction (mExtendedRevertAction);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (name=="table-input/jump-to-added")
|
||||
|
@ -97,6 +97,8 @@ namespace CSVWorld
|
||||
|
||||
std::vector<std::string> getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const;
|
||||
|
||||
std::vector<std::string> getSelectedIds() const;
|
||||
|
||||
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
|
||||
|
||||
signals:
|
||||
@ -116,6 +118,10 @@ namespace CSVWorld
|
||||
|
||||
void closeRequest();
|
||||
|
||||
void extendedDeleteConfigRequest(const std::vector<std::string> &selectedIds);
|
||||
|
||||
void extendedRevertConfigRequest(const std::vector<std::string> &selectedIds);
|
||||
|
||||
private slots:
|
||||
|
||||
void editCell();
|
||||
@ -132,6 +138,10 @@ namespace CSVWorld
|
||||
|
||||
void previewRecord();
|
||||
|
||||
void executeExtendedDelete();
|
||||
|
||||
void executeExtendedRevert();
|
||||
|
||||
public slots:
|
||||
|
||||
void tableSizeUpdate();
|
||||
|
@ -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);
|
||||
mEditMode = EditMode_ExtendedConfig;
|
||||
setVisible (true);
|
||||
@ -207,12 +208,12 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id,
|
||||
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);
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ namespace CSVWorld
|
||||
|
||||
void updateStatus();
|
||||
|
||||
void extendedConfigRequest(ExtendedCommandConfigurator::Mode mode);
|
||||
void extendedConfigRequest(ExtendedCommandConfigurator::Mode mode,
|
||||
const std::vector<std::string> &selectedIds);
|
||||
|
||||
public:
|
||||
|
||||
@ -96,8 +97,8 @@ namespace CSVWorld
|
||||
void cloneRequest(const std::string& id,
|
||||
const CSMWorld::UniversalId::Type type);
|
||||
|
||||
void extendedDeleteConfigRequest();
|
||||
void extendedRevertConfigRequest();
|
||||
void extendedDeleteConfigRequest(const std::vector<std::string> &selectedIds);
|
||||
void extendedRevertConfigRequest(const std::vector<std::string> &selectedIds);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
|
||||
|
||||
connect (this, SIGNAL(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&)),
|
||||
mTable, SLOT (requestFocus (const std::string&)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user