1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-18 22:20:53 +00:00

Refactor dynamic casts in the editor

This commit is contained in:
Andrei Kortunov 2018-11-15 17:50:23 +04:00
parent a21792657a
commit 059a8fd32a
4 changed files with 8 additions and 44 deletions

View File

@ -198,12 +198,7 @@ CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelI
if (mIndex.parent().isValid()) if (mIndex.parent().isValid())
{ {
CSMWorld::IdTree* tree = dynamic_cast<CSMWorld::IdTree*>(mModel); CSMWorld::IdTree* tree = &dynamic_cast<CSMWorld::IdTree&>(*mModel);
if (tree == nullptr)
{
throw std::logic_error("CSMWorld::ModifyCommand: Attempt to add nested values to the non-nested model");
}
setText ("Modify " + tree->nestedHeaderData ( setText ("Modify " + tree->nestedHeaderData (
mIndex.parent().column(), mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); mIndex.parent().column(), mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString());
} }
@ -249,12 +244,7 @@ void CSMWorld::CreateCommand::applyModifications()
{ {
if (!mNestedValues.empty()) if (!mNestedValues.empty())
{ {
CSMWorld::IdTree *tree = dynamic_cast<CSMWorld::IdTree *>(&mModel); CSMWorld::IdTree* tree = &dynamic_cast<CSMWorld::IdTree&>(mModel);
if (tree == nullptr)
{
throw std::logic_error("CSMWorld::CreateCommand: Attempt to add nested values to the non-nested model");
}
std::map<int, std::pair<int, QVariant> >::const_iterator current = mNestedValues.begin(); std::map<int, std::pair<int, QVariant> >::const_iterator current = mNestedValues.begin();
std::map<int, std::pair<int, QVariant> >::const_iterator end = mNestedValues.end(); std::map<int, std::pair<int, QVariant> >::const_iterator end = mNestedValues.end();
for (; current != end; ++current) for (; current != end; ++current)

View File

@ -224,11 +224,7 @@ namespace CSVRender
void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos) void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos)
{ {
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
if (model == nullptr)
{
throw std::logic_error("CSVRender::Pathgrid: Attempt to add nested values to the non-nested model");
}
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
@ -360,11 +356,7 @@ namespace CSVRender
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
{ {
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
if (model == nullptr)
{
throw std::logic_error("CSVRender::Pathgrid: Attempt to add nested values to the non-nested model");
}
// Want to remove nodes from end of list first // Want to remove nodes from end of list first
std::sort(mSelected.begin(), mSelected.end(), std::greater<int>()); std::sort(mSelected.begin(), mSelected.end(), std::greater<int>());
@ -464,12 +456,7 @@ namespace CSVRender
} }
} }
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
if (model == nullptr)
{
throw std::logic_error("CSVRender::Pathgrid: Attempt to add nested values to the non-nested model");
}
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges);
std::set<int, std::greater<int> >::iterator row; std::set<int, std::greater<int> >::iterator row;
@ -642,11 +629,7 @@ namespace CSVRender
void Pathgrid::addEdge(CSMWorld::CommandMacro& commands, const CSMWorld::Pathgrid& source, unsigned short node1, void Pathgrid::addEdge(CSMWorld::CommandMacro& commands, const CSMWorld::Pathgrid& source, unsigned short node1,
unsigned short node2) unsigned short node2)
{ {
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
if (model == nullptr)
{
throw std::logic_error("CSVRender::Pathgrid: Attempt to add nested values to the non-nested model");
}
int recordIndex = mPathgridCollection.getIndex(mId); int recordIndex = mPathgridCollection.getIndex(mId);
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges);

View File

@ -24,11 +24,7 @@ std::string CSVWorld::CellCreator::getId() const
void CSVWorld::CellCreator::configureCreateCommand(CSMWorld::CreateCommand& command) const void CSVWorld::CellCreator::configureCreateCommand(CSMWorld::CreateCommand& command) const
{ {
CSMWorld::IdTree *model = dynamic_cast<CSMWorld::IdTree *>(getData().getTableModel(getCollectionId())); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*getData().getTableModel(getCollectionId()));
if (model == nullptr)
{
throw std::logic_error("CSVWorld::CellCreator: Attempt to add nested values to the non-nested model");
}
int parentIndex = model->findColumnIndex(CSMWorld::Columns::ColumnId_Cell); int parentIndex = model->findColumnIndex(CSMWorld::Columns::ColumnId_Cell);
int index = model->findNestedColumnIndex(parentIndex, CSMWorld::Columns::ColumnId_Interior); int index = model->findNestedColumnIndex(parentIndex, CSMWorld::Columns::ColumnId_Interior);

View File

@ -555,12 +555,7 @@ void CSVWorld::EditWidget::remake(int row)
if (mTable->hasChildren(mTable->index(row, i)) && if (mTable->hasChildren(mTable->index(row, i)) &&
!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List)) !(flags & CSMWorld::ColumnBase::Flag_Dialogue_List))
{ {
CSMWorld::IdTree *innerTable = dynamic_cast<CSMWorld::IdTree*>(mTable); CSMWorld::IdTree* innerTable = &dynamic_cast<CSMWorld::IdTree&>(*mTable);
if (innerTable == nullptr)
{
throw std::logic_error("CSVWorld::EditWidget: Attempt to add nested values to the non-nested model");
}
mNestedModels.push_back(new CSMWorld::NestedTableProxyModel (mTable->index(row, i), display, innerTable)); mNestedModels.push_back(new CSMWorld::NestedTableProxyModel (mTable->index(row, i), display, innerTable));
int idColumn = mTable->findColumnIndex (CSMWorld::Columns::ColumnId_Id); int idColumn = mTable->findColumnIndex (CSMWorld::Columns::ColumnId_Id);