mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 09:09:43 +00:00
avoid the use of hardcoded column numbers
This commit is contained in:
parent
76b9d3dbc1
commit
0944338c27
6 changed files with 49 additions and 13 deletions
|
@ -157,4 +157,25 @@ void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& reco
|
|||
const CSMWorld::RecordBase& CSMWorld::IdTable::getRecord (const std::string& id) const
|
||||
{
|
||||
return mIdCollection->getRecord (id);
|
||||
}
|
||||
|
||||
int CSMWorld::IdTable::searchColumnIndex (Columns::ColumnId id) const
|
||||
{
|
||||
int columns = mIdCollection->getColumns();
|
||||
|
||||
for (int i=0; i<columns; ++i)
|
||||
if (mIdCollection->getColumn (i).mColumnId==id)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CSMWorld::IdTable::findColumnIndex (Columns::ColumnId id) const
|
||||
{
|
||||
int index = searchColumnIndex (id);
|
||||
|
||||
if (index==-1)
|
||||
throw std::logic_error ("invalid column index");
|
||||
|
||||
return index;
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include <QAbstractItemModel>
|
||||
|
||||
#include "universalid.hpp"
|
||||
#include "columns.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
|
@ -55,6 +56,13 @@ namespace CSMWorld
|
|||
///< Add record or overwrite existing recrod.
|
||||
|
||||
const RecordBase& getRecord (const std::string& id) const;
|
||||
|
||||
int searchColumnIndex (Columns::ColumnId id) const;
|
||||
///< Return index of column with the given \a id. If no such column exists, -1 is returned.
|
||||
|
||||
int findColumnIndex (Columns::ColumnId id) const;
|
||||
///< Return index of column with the given \a id. If no such column exists, an exception is
|
||||
/// thrown.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -46,14 +46,14 @@ std::string CSVWorld::GenericCreator::getId() const
|
|||
|
||||
void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {}
|
||||
|
||||
const CSMWorld::Data& CSVWorld::GenericCreator::getData() const
|
||||
CSMWorld::Data& CSVWorld::GenericCreator::getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
CSMWorld::Data& CSVWorld::GenericCreator::getData()
|
||||
const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
|
||||
{
|
||||
return mData;
|
||||
return mListId;
|
||||
}
|
||||
|
||||
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
|
|
|
@ -44,9 +44,9 @@ namespace CSVWorld
|
|||
|
||||
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||
|
||||
const CSMWorld::Data& getData() const;
|
||||
CSMWorld::Data& getData() const;
|
||||
|
||||
CSMWorld::Data& getData();
|
||||
const CSMWorld::UniversalId& getCollectionId() const;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "../../model/world/data.hpp"
|
||||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/columns.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
|
||||
std::string CSVWorld::ReferenceCreator::getId() const
|
||||
{
|
||||
|
@ -14,8 +16,11 @@ std::string CSVWorld::ReferenceCreator::getId() const
|
|||
|
||||
void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const
|
||||
{
|
||||
/// \todo avoid using hard-coded column numbers
|
||||
command.addValue (2, mCell->text());
|
||||
int index =
|
||||
dynamic_cast<CSMWorld::IdTable&> (*getData().getTableModel (getCollectionId())).
|
||||
findColumnIndex (CSMWorld::Columns::ColumnId_Cell);
|
||||
|
||||
command.addValue (index, mCell->text());
|
||||
}
|
||||
|
||||
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
|
|
|
@ -44,7 +44,6 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
|||
|
||||
std::vector<std::string> CSVWorld::Table::listRevertableSelectedIds() const
|
||||
{
|
||||
/// \todo Do not use hardcoded column numbers
|
||||
std::vector<std::string> revertableIds;
|
||||
|
||||
if (mProxyModel->columnCount()>0)
|
||||
|
@ -62,7 +61,9 @@ std::vector<std::string> CSVWorld::Table::listRevertableSelectedIds() const
|
|||
|
||||
if (state!=CSMWorld::RecordBase::State_BaseOnly)
|
||||
{
|
||||
std::string id = mModel->data (mModel->index (index.row(), 0)).
|
||||
int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
||||
|
||||
std::string id = mModel->data (mModel->index (index.row(), columnIndex)).
|
||||
toString().toUtf8().constData();
|
||||
|
||||
revertableIds.push_back (id);
|
||||
|
@ -75,7 +76,6 @@ std::vector<std::string> CSVWorld::Table::listRevertableSelectedIds() const
|
|||
|
||||
std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
|
||||
{
|
||||
/// \todo Do not use hardcoded column numbers
|
||||
std::vector<std::string> deletableIds;
|
||||
|
||||
if (mProxyModel->columnCount()>0)
|
||||
|
@ -93,7 +93,9 @@ std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
|
|||
|
||||
if (state!=CSMWorld::RecordBase::State_Deleted)
|
||||
{
|
||||
std::string id = mModel->data (mModel->index (index.row(), 0)).
|
||||
int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
||||
|
||||
std::string id = mModel->data (mModel->index (index.row(), columnIndex)).
|
||||
toString().toUtf8().constData();
|
||||
|
||||
deletableIds.push_back (id);
|
||||
|
@ -263,8 +265,8 @@ void CSVWorld::Table::tableSizeUpdate()
|
|||
{
|
||||
QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (i, 0));
|
||||
|
||||
/// \todo Do not use hardcoded column numbers
|
||||
int state = mModel->data (mModel->index (index.row(), 1)).toInt();
|
||||
int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
||||
int state = mModel->data (mModel->index (index.row(), columnIndex)).toInt();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue