1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-20 19:39:41 +00:00

Throw exceptions with some info int the editor if dynamic_cast failed

This commit is contained in:
Andrei Kortunov 2018-11-14 15:53:43 +04:00
parent f20d1b1b72
commit 5ac81cfbff
4 changed files with 33 additions and 20 deletions

View file

@ -199,8 +199,10 @@ CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelI
if (mIndex.parent().isValid())
{
CSMWorld::IdTree* tree = dynamic_cast<CSMWorld::IdTree*>(mModel);
assert(tree != nullptr);
if (tree == nullptr)
{
throw std::logic_error("CSMWorld::ModifyCommand: Attempt to add nested values to the non-nested model");
}
setText ("Modify " + tree->nestedHeaderData (
mIndex.parent().column(), mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString());

View file

@ -224,10 +224,11 @@ namespace CSVRender
void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos)
{
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids));
assert(model != nullptr);
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();
if (source)
@ -359,10 +360,11 @@ namespace CSVRender
const CSMWorld::Pathgrid* source = getPathgridSource();
if (source)
{
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids));
assert(model != nullptr);
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
std::sort(mSelected.begin(), mSelected.end(), std::greater<int>());
@ -462,10 +464,11 @@ namespace CSVRender
}
}
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids));
assert(model != nullptr);
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);
@ -639,10 +642,11 @@ namespace CSVRender
void Pathgrid::addEdge(CSMWorld::CommandMacro& commands, const CSMWorld::Pathgrid& source, unsigned short node1,
unsigned short node2)
{
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids));
assert(model != nullptr);
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 parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges);

View file

@ -25,7 +25,11 @@ std::string CSVWorld::CellCreator::getId() const
void CSVWorld::CellCreator::configureCreateCommand(CSMWorld::CreateCommand& command) const
{
CSMWorld::IdTree *model = dynamic_cast<CSMWorld::IdTree *>(getData().getTableModel(getCollectionId()));
assert(model != nullptr);
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 index = model->findNestedColumnIndex(parentIndex, CSMWorld::Columns::ColumnId_Interior);
command.addNestedValue(parentIndex, index, mType->currentIndex() == 0);

View file

@ -556,7 +556,10 @@ void CSVWorld::EditWidget::remake(int row)
!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List))
{
CSMWorld::IdTree *innerTable = dynamic_cast<CSMWorld::IdTree*>(mTable);
assert(innerTable != nullptr);
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));