Add the ability to configure extended commands for tables

sceneinput
Stanislav Bas 10 years ago
parent fcf69555f4
commit b8772c6902

@ -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);

@ -32,28 +32,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
@ -375,16 +361,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);
connect (mProxyModel, SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
@ -430,6 +412,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))
@ -562,6 +560,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")

@ -93,6 +93,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:
@ -112,6 +114,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();
@ -128,6 +134,10 @@ namespace CSVWorld
void previewRecord();
void executeExtendedDelete();
void executeExtendedRevert();
public slots:
void tableSizeUpdate();

@ -39,9 +39,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);
@ -185,12 +186,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);
}

@ -45,7 +45,8 @@ namespace CSVWorld
void updateStatus();
void extendedConfigRequest(ExtendedCommandConfigurator::Mode mode);
void extendedConfigRequest(ExtendedCommandConfigurator::Mode mode,
const std::vector<std::string> &selectedIds);
public:
@ -89,8 +90,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);
};
}

@ -71,6 +71,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…
Cancel
Save