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,8 +107,7 @@ void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
|||
mEditLock = locked;
|
||||
}
|
||||
|
||||
|
||||
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
|
@ -117,15 +116,55 @@ void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
|||
if (mCreateAction)
|
||||
menu.addAction (mCreateAction);
|
||||
|
||||
if (selectedRows.size()>0)
|
||||
if (listRevertableSelectedIds().size()>0)
|
||||
menu.addAction (mRevertAction);
|
||||
|
||||
if (selectedRows.size()>0)
|
||||
if (listDeletableSelectedIds().size()>0)
|
||||
menu.addAction (mDeleteAction);
|
||||
|
||||
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,
|
||||
bool createAndDelete)
|
||||
: mUndoStack (undoStack), mCreateAction (0)
|
||||
|
@ -189,20 +228,7 @@ void CSVWorld::Table::createRecord()
|
|||
|
||||
void CSVWorld::Table::revertRecord()
|
||||
{
|
||||
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);
|
||||
}
|
||||
std::vector<std::string> revertableIds = listRevertableSelectedIds();
|
||||
|
||||
if (revertableIds.size()>0)
|
||||
{
|
||||
|
@ -219,30 +245,17 @@ void CSVWorld::Table::revertRecord()
|
|||
|
||||
void CSVWorld::Table::deleteRecord()
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
std::vector<std::string> deletableIds = listDeletableSelectedIds();
|
||||
|
||||
std::vector<std::string> revertableIds;
|
||||
|
||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter)
|
||||
if (deletableIds.size()>0)
|
||||
{
|
||||
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)
|
||||
revertableIds.push_back (id);
|
||||
}
|
||||
|
||||
if (revertableIds.size()>0)
|
||||
{
|
||||
if (revertableIds.size()>1)
|
||||
if (deletableIds.size()>1)
|
||||
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));
|
||||
|
||||
if (revertableIds.size()>1)
|
||||
if (deletableIds.size()>1)
|
||||
mUndoStack.endMacro();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#define CSV_WORLD_TABLE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
|
@ -37,6 +38,10 @@ namespace CSVWorld
|
|||
|
||||
void contextMenuEvent (QContextMenuEvent *event);
|
||||
|
||||
std::vector<std::string> listRevertableSelectedIds() const;
|
||||
|
||||
std::vector<std::string> listDeletableSelectedIds() const;
|
||||
|
||||
public:
|
||||
|
||||
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete);
|
||||
|
|
Loading…
Reference in a new issue