mirror of
https://github.com/OpenMW/openmw.git
synced 2025-05-30 21:11:31 +00:00
replaced selection model in CommandDispatcher with a slightly slower but more robust implementation
This commit is contained in:
parent
f6ae967ba0
commit
85fca19fd9
3 changed files with 30 additions and 24 deletions
|
@ -7,18 +7,20 @@
|
||||||
#include "record.hpp"
|
#include "record.hpp"
|
||||||
#include "commands.hpp"
|
#include "commands.hpp"
|
||||||
|
|
||||||
std::vector<int> CSMWorld::CommandDispatcher::getDeletableRecords() const
|
std::vector<std::string> CSMWorld::CommandDispatcher::getDeletableRecords() const
|
||||||
{
|
{
|
||||||
std::vector<int> result;
|
std::vector<std::string> result;
|
||||||
|
|
||||||
IdTable& model = dynamic_cast<IdTable&> (*mDocument.getData().getTableModel (mId));
|
IdTable& model = dynamic_cast<IdTable&> (*mDocument.getData().getTableModel (mId));
|
||||||
|
|
||||||
for (std::vector<int>::const_iterator iter (mSelection.begin());
|
for (std::vector<std::string>::const_iterator iter (mSelection.begin());
|
||||||
iter!=mSelection.end(); ++iter)
|
iter!=mSelection.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
int row = model.getModelIndex (*iter, 0).row();
|
||||||
|
|
||||||
// check record state
|
// check record state
|
||||||
RecordBase::State state =
|
RecordBase::State state =
|
||||||
static_cast<RecordBase::State> (model.data (model.index (*iter, 1)).toInt());
|
static_cast<RecordBase::State> (model.data (model.index (row, 1)).toInt());
|
||||||
|
|
||||||
if (state==RecordBase::State_Deleted)
|
if (state==RecordBase::State_Deleted)
|
||||||
continue;
|
continue;
|
||||||
|
@ -28,7 +30,7 @@ std::vector<int> CSMWorld::CommandDispatcher::getDeletableRecords() const
|
||||||
|
|
||||||
if (dialogueTypeIndex!=-1)
|
if (dialogueTypeIndex!=-1)
|
||||||
{
|
{
|
||||||
int type = model.data (model.index (*iter, dialogueTypeIndex)).toInt();
|
int type = model.data (model.index (row, dialogueTypeIndex)).toInt();
|
||||||
|
|
||||||
if (type!=ESM::Dialogue::Topic && type!=ESM::Dialogue::Journal)
|
if (type!=ESM::Dialogue::Topic && type!=ESM::Dialogue::Journal)
|
||||||
continue;
|
continue;
|
||||||
|
@ -40,9 +42,9 @@ std::vector<int> CSMWorld::CommandDispatcher::getDeletableRecords() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> CSMWorld::CommandDispatcher::getRevertableRecords() const
|
std::vector<std::string> CSMWorld::CommandDispatcher::getRevertableRecords() const
|
||||||
{
|
{
|
||||||
std::vector<int> result;
|
std::vector<std::string> result;
|
||||||
|
|
||||||
IdTable& model = dynamic_cast<IdTable&> (*mDocument.getData().getTableModel (mId));
|
IdTable& model = dynamic_cast<IdTable&> (*mDocument.getData().getTableModel (mId));
|
||||||
|
|
||||||
|
@ -51,12 +53,14 @@ std::vector<int> CSMWorld::CommandDispatcher::getRevertableRecords() const
|
||||||
if (model.getFeatures() & IdTable::Feature_ReorderWithinTopic)
|
if (model.getFeatures() & IdTable::Feature_ReorderWithinTopic)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
for (std::vector<int>::const_iterator iter (mSelection.begin());
|
for (std::vector<std::string>::const_iterator iter (mSelection.begin());
|
||||||
iter!=mSelection.end(); ++iter)
|
iter!=mSelection.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
int row = model.getModelIndex (*iter, 0).row();
|
||||||
|
|
||||||
// check record state
|
// check record state
|
||||||
RecordBase::State state =
|
RecordBase::State state =
|
||||||
static_cast<RecordBase::State> (model.data (model.index (*iter, 1)).toInt());
|
static_cast<RecordBase::State> (model.data (model.index (row, 1)).toInt());
|
||||||
|
|
||||||
if (state==RecordBase::State_BaseOnly)
|
if (state==RecordBase::State_BaseOnly)
|
||||||
continue;
|
continue;
|
||||||
|
@ -77,7 +81,7 @@ void CSMWorld::CommandDispatcher::setEditLock (bool locked)
|
||||||
mLocked = locked;
|
mLocked = locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::CommandDispatcher::setSelection (const std::vector<int>& selection)
|
void CSMWorld::CommandDispatcher::setSelection (const std::vector<std::string>& selection)
|
||||||
{
|
{
|
||||||
mSelection = selection;
|
mSelection = selection;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +107,7 @@ void CSMWorld::CommandDispatcher::executeDelete()
|
||||||
if (mLocked)
|
if (mLocked)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<int> rows = getDeletableRecords();
|
std::vector<std::string> rows = getDeletableRecords();
|
||||||
|
|
||||||
if (rows.empty())
|
if (rows.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -115,9 +119,9 @@ void CSMWorld::CommandDispatcher::executeDelete()
|
||||||
if (rows.size()>1)
|
if (rows.size()>1)
|
||||||
mDocument.getUndoStack().beginMacro (tr ("Delete multiple records"));
|
mDocument.getUndoStack().beginMacro (tr ("Delete multiple records"));
|
||||||
|
|
||||||
for (std::vector<int>::const_iterator iter (rows.begin()); iter!=rows.end(); ++iter)
|
for (std::vector<std::string>::const_iterator iter (rows.begin()); iter!=rows.end(); ++iter)
|
||||||
{
|
{
|
||||||
std::string id = model.data (model.index (*iter, columnIndex)).
|
std::string id = model.data (model.getModelIndex (*iter, columnIndex)).
|
||||||
toString().toUtf8().constData();
|
toString().toUtf8().constData();
|
||||||
|
|
||||||
mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (model, id));
|
mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (model, id));
|
||||||
|
@ -132,7 +136,7 @@ void CSMWorld::CommandDispatcher::executeRevert()
|
||||||
if (mLocked)
|
if (mLocked)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<int> rows = getRevertableRecords();
|
std::vector<std::string> rows = getRevertableRecords();
|
||||||
|
|
||||||
if (rows.empty())
|
if (rows.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -144,9 +148,9 @@ void CSMWorld::CommandDispatcher::executeRevert()
|
||||||
if (rows.size()>1)
|
if (rows.size()>1)
|
||||||
mDocument.getUndoStack().beginMacro (tr ("Revert multiple records"));
|
mDocument.getUndoStack().beginMacro (tr ("Revert multiple records"));
|
||||||
|
|
||||||
for (std::vector<int>::const_iterator iter (rows.begin()); iter!=rows.end(); ++iter)
|
for (std::vector<std::string>::const_iterator iter (rows.begin()); iter!=rows.end(); ++iter)
|
||||||
{
|
{
|
||||||
std::string id = model.data (model.index (*iter, columnIndex)).
|
std::string id = model.data (model.getModelIndex (*iter, columnIndex)).
|
||||||
toString().toUtf8().constData();
|
toString().toUtf8().constData();
|
||||||
|
|
||||||
mDocument.getUndoStack().push (new CSMWorld::RevertCommand (model, id));
|
mDocument.getUndoStack().push (new CSMWorld::RevertCommand (model, id));
|
||||||
|
|
|
@ -21,11 +21,11 @@ namespace CSMWorld
|
||||||
bool mLocked;
|
bool mLocked;
|
||||||
CSMDoc::Document& mDocument;
|
CSMDoc::Document& mDocument;
|
||||||
UniversalId mId;
|
UniversalId mId;
|
||||||
std::vector<int> mSelection;
|
std::vector<std::string> mSelection;
|
||||||
|
|
||||||
std::vector<int> getDeletableRecords() const;
|
std::vector<std::string> getDeletableRecords() const;
|
||||||
|
|
||||||
std::vector<int> getRevertableRecords() const;
|
std::vector<std::string> getRevertableRecords() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
void setEditLock (bool locked);
|
void setEditLock (bool locked);
|
||||||
|
|
||||||
void setSelection (const std::vector<int>& selection);
|
void setSelection (const std::vector<std::string>& selection);
|
||||||
|
|
||||||
bool canDelete() const;
|
bool canDelete() const;
|
||||||
|
|
||||||
|
|
|
@ -29,16 +29,18 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||||
// configure dispatcher
|
// configure dispatcher
|
||||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||||
|
|
||||||
std::vector<int> rows;
|
std::vector<std::string> records;
|
||||||
|
|
||||||
|
int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
||||||
|
|
||||||
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
|
for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
|
||||||
++iter)
|
++iter)
|
||||||
{
|
{
|
||||||
QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0));
|
records.push_back (mProxyModel->data (
|
||||||
rows.push_back (index.row());
|
mProxyModel->index (iter->row(), columnIndex)).toString().toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
mDispatcher->setSelection (rows);
|
mDispatcher->setSelection (records);
|
||||||
|
|
||||||
// create context menu
|
// create context menu
|
||||||
QMenu menu (this);
|
QMenu menu (this);
|
||||||
|
|
Loading…
Reference in a new issue