forked from teamnwah/openmw-tes3coop
do not list actions in the pop up menu that do not apply to any of the selected records
This commit is contained in:
parent
c12ee129f7
commit
2b53cf6547
2 changed files with 54 additions and 36 deletions
|
@ -107,7 +107,6 @@ void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
||||||
mEditLock = locked;
|
mEditLock = locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||||
|
@ -117,15 +116,55 @@ void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
||||||
if (mCreateAction)
|
if (mCreateAction)
|
||||||
menu.addAction (mCreateAction);
|
menu.addAction (mCreateAction);
|
||||||
|
|
||||||
if (selectedRows.size()>0)
|
if (listRevertableSelectedIds().size()>0)
|
||||||
menu.addAction (mRevertAction);
|
menu.addAction (mRevertAction);
|
||||||
|
|
||||||
if (selectedRows.size()>0)
|
if (listDeletableSelectedIds().size()>0)
|
||||||
menu.addAction (mDeleteAction);
|
menu.addAction (mDeleteAction);
|
||||||
|
|
||||||
menu.exec (event->globalPos());
|
menu.exec (event->globalPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> CSVWorld::Table::listRevertableSelectedIds() const
|
||||||
|
{
|
||||||
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||||
|
|
||||||
|
std::vector<std::string> revertableIds;
|
||||||
|
|
||||||
|
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter)
|
||||||
|
{
|
||||||
|
std::string id = mProxyModel->data (*iter).toString().toStdString();
|
||||||
|
|
||||||
|
CSMWorld::RecordBase::State state =
|
||||||
|
static_cast<CSMWorld::RecordBase::State> (mModel->data (mModel->getModelIndex (id, 1)).toInt());
|
||||||
|
|
||||||
|
if (state!=CSMWorld::RecordBase::State_BaseOnly)
|
||||||
|
revertableIds.push_back (id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return revertableIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
|
||||||
|
{
|
||||||
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||||
|
|
||||||
|
std::vector<std::string> deletableIds;
|
||||||
|
|
||||||
|
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter)
|
||||||
|
{
|
||||||
|
std::string id = mProxyModel->data (*iter).toString().toStdString();
|
||||||
|
|
||||||
|
CSMWorld::RecordBase::State state =
|
||||||
|
static_cast<CSMWorld::RecordBase::State> (mModel->data (mModel->getModelIndex (id, 1)).toInt());
|
||||||
|
|
||||||
|
if (state!=CSMWorld::RecordBase::State_Deleted)
|
||||||
|
deletableIds.push_back (id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deletableIds;
|
||||||
|
}
|
||||||
|
|
||||||
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack,
|
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
bool createAndDelete)
|
bool createAndDelete)
|
||||||
: mUndoStack (undoStack), mCreateAction (0)
|
: mUndoStack (undoStack), mCreateAction (0)
|
||||||
|
@ -189,20 +228,7 @@ void CSVWorld::Table::createRecord()
|
||||||
|
|
||||||
void CSVWorld::Table::revertRecord()
|
void CSVWorld::Table::revertRecord()
|
||||||
{
|
{
|
||||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
std::vector<std::string> revertableIds = listRevertableSelectedIds();
|
||||||
|
|
||||||
std::vector<std::string> revertableIds;
|
|
||||||
|
|
||||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter)
|
|
||||||
{
|
|
||||||
std::string id = mProxyModel->data (*iter).toString().toStdString();
|
|
||||||
|
|
||||||
CSMWorld::RecordBase::State state =
|
|
||||||
static_cast<CSMWorld::RecordBase::State> (mModel->data (mModel->getModelIndex (id, 1)).toInt());
|
|
||||||
|
|
||||||
if (state!=CSMWorld::RecordBase::State_BaseOnly)
|
|
||||||
revertableIds.push_back (id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (revertableIds.size()>0)
|
if (revertableIds.size()>0)
|
||||||
{
|
{
|
||||||
|
@ -219,30 +245,17 @@ void CSVWorld::Table::revertRecord()
|
||||||
|
|
||||||
void CSVWorld::Table::deleteRecord()
|
void CSVWorld::Table::deleteRecord()
|
||||||
{
|
{
|
||||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
std::vector<std::string> deletableIds = listDeletableSelectedIds();
|
||||||
|
|
||||||
std::vector<std::string> revertableIds;
|
if (deletableIds.size()>0)
|
||||||
|
|
||||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter)
|
|
||||||
{
|
{
|
||||||
std::string id = mProxyModel->data (*iter).toString().toStdString();
|
if (deletableIds.size()>1)
|
||||||
|
|
||||||
CSMWorld::RecordBase::State state =
|
|
||||||
static_cast<CSMWorld::RecordBase::State> (mModel->data (mModel->getModelIndex (id, 1)).toInt());
|
|
||||||
|
|
||||||
if (state!=CSMWorld::RecordBase::State_Deleted)
|
|
||||||
revertableIds.push_back (id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (revertableIds.size()>0)
|
|
||||||
{
|
|
||||||
if (revertableIds.size()>1)
|
|
||||||
mUndoStack.beginMacro (tr ("Delete multiple records"));
|
mUndoStack.beginMacro (tr ("Delete multiple records"));
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator iter (revertableIds.begin()); iter!=revertableIds.end(); ++iter)
|
for (std::vector<std::string>::const_iterator iter (deletableIds.begin()); iter!=deletableIds.end(); ++iter)
|
||||||
mUndoStack.push (new CSMWorld::DeleteCommand (*mModel, *iter));
|
mUndoStack.push (new CSMWorld::DeleteCommand (*mModel, *iter));
|
||||||
|
|
||||||
if (revertableIds.size()>1)
|
if (deletableIds.size()>1)
|
||||||
mUndoStack.endMacro();
|
mUndoStack.endMacro();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
#define CSV_WORLD_TABLE_H
|
#define CSV_WORLD_TABLE_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
|
||||||
|
@ -37,6 +38,10 @@ namespace CSVWorld
|
||||||
|
|
||||||
void contextMenuEvent (QContextMenuEvent *event);
|
void contextMenuEvent (QContextMenuEvent *event);
|
||||||
|
|
||||||
|
std::vector<std::string> listRevertableSelectedIds() const;
|
||||||
|
|
||||||
|
std::vector<std::string> listDeletableSelectedIds() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete);
|
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete);
|
||||||
|
|
Loading…
Reference in a new issue