diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index 492807eb93..6db00c593f 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -406,7 +406,7 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages) if (references != nullptr) { writeReferences(persistentRefs, interior); - cellRecord.saveTempMarker(writer, static_cast(references->size()) - persistentRefs.size()); + cellRecord.saveTempMarker(writer, static_cast(references->size() - persistentRefs.size())); writeReferences(tempRefs, interior); } diff --git a/apps/opencs/model/tools/referenceablecheck.cpp b/apps/opencs/model/tools/referenceablecheck.cpp index b9ed2cec0d..4ebf626f51 100644 --- a/apps/opencs/model/tools/referenceablecheck.cpp +++ b/apps/opencs/model/tools/referenceablecheck.cpp @@ -462,7 +462,7 @@ void CSMTools::ReferenceableCheckStage::creatureCheck( for (size_t i = 0; i < creature.mData.mAttributes.size(); ++i) { if (creature.mData.mAttributes[i] < 0) - messages.add(id, ESM::Attribute::indexToRefId(i).toDebugString() + " is negative", {}, + messages.add(id, ESM::Attribute::indexToRefId(static_cast(i)).toDebugString() + " is negative", {}, CSMDoc::Message::Severity_Warning); } diff --git a/apps/opencs/model/world/actoradapter.cpp b/apps/opencs/model/world/actoradapter.cpp index f7796acd76..ce489aee19 100644 --- a/apps/opencs/model/world/actoradapter.cpp +++ b/apps/opencs/model/world/actoradapter.cpp @@ -640,7 +640,7 @@ namespace CSMWorld reservedList.emplace_back(pr); } - int priority = parts.size(); + int priority = static_cast(parts.size()); addParts(clothing.mParts.mParts, priority); addParts(reservedList, priority); diff --git a/apps/opencs/model/world/cellselection.cpp b/apps/opencs/model/world/cellselection.cpp index e6b346be98..d0f9497dcf 100644 --- a/apps/opencs/model/world/cellselection.cpp +++ b/apps/opencs/model/world/cellselection.cpp @@ -34,7 +34,7 @@ bool CSMWorld::CellSelection::has(const CellCoordinates& coordinates) const int CSMWorld::CellSelection::getSize() const { - return mCells.size(); + return static_cast(mCells.size()); } CSMWorld::CellCoordinates CSMWorld::CellSelection::getCentre() const diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 18fb73330c..9d3658cdf0 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -367,7 +367,7 @@ namespace CSMWorld template int Collection::getSize() const { - return mRecords.size(); + return static_cast(mRecords.size()); } template @@ -391,7 +391,7 @@ namespace CSMWorld template int Collection::getColumns() const { - return mColumns.size(); + return static_cast(mColumns.size()); } template diff --git a/apps/opencs/model/world/nestedcoladapterimp.cpp b/apps/opencs/model/world/nestedcoladapterimp.cpp index 181c7d80e8..185ebd7e4c 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.cpp +++ b/apps/opencs/model/world/nestedcoladapterimp.cpp @@ -41,7 +41,7 @@ namespace CSMWorld point.mConnectionNum = 0; points.insert(points.begin() + position, point); - pathgrid.mData.mPoints = pathgrid.mPoints.size(); + pathgrid.mData.mPoints = static_cast(pathgrid.mPoints.size()); record.setModified(pathgrid); } @@ -58,7 +58,7 @@ namespace CSMWorld // Do not remove dangling edges, does not work with current undo mechanism // Do not automatically adjust indices, what would be done with dangling edges? points.erase(points.begin() + rowToRemove); - pathgrid.mData.mPoints = pathgrid.mPoints.size(); + pathgrid.mData.mPoints = static_cast(pathgrid.mPoints.size()); record.setModified(pathgrid); } @@ -67,7 +67,7 @@ namespace CSMWorld { Pathgrid pathgrid = record.get(); pathgrid.mPoints = static_cast&>(nestedTable).mNestedTable; - pathgrid.mData.mPoints = pathgrid.mPoints.size(); + pathgrid.mData.mPoints = static_cast(pathgrid.mPoints.size()); record.setModified(pathgrid); } @@ -462,7 +462,7 @@ namespace CSMWorld soundRef.mSound = ESM::RefId::stringRefId(value.toString().toUtf8().constData()); break; case 1: - soundRef.mChance = static_cast(value.toInt()); + soundRef.mChance = static_cast(value.toInt()); break; default: throw std::runtime_error("Region sounds subcolumn index out of range"); @@ -543,7 +543,7 @@ namespace CSMWorld // default row ESM::DialogueCondition condStruct; - condStruct.mIndex = conditions.size(); + condStruct.mIndex = static_cast(conditions.size()); conditions.insert(conditions.begin() + position, condStruct); @@ -855,7 +855,7 @@ namespace CSMWorld int RaceSkillsBonusAdapter::getRowsCount(const Record& record) const { - return record.get().mData.mBonus.size(); + return static_cast(record.get().mData.mBonus.size()); } void CellListAdapter::addRow(Record& record, int position) const diff --git a/apps/opencs/model/world/nestedtablewrapper.hpp b/apps/opencs/model/world/nestedtablewrapper.hpp index 69a00bf9c7..b96e05fa09 100644 --- a/apps/opencs/model/world/nestedtablewrapper.hpp +++ b/apps/opencs/model/world/nestedtablewrapper.hpp @@ -7,9 +7,7 @@ namespace CSMWorld { virtual ~NestedTableWrapperBase() = default; - virtual int size() const { return -5; } - - NestedTableWrapperBase() = default; + virtual size_t size() const = 0; }; template @@ -24,7 +22,7 @@ namespace CSMWorld ~NestedTableWrapper() override = default; - int size() const override + size_t size() const override { return mNestedTable.size(); // i hope that this will be enough } diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 6fff14674f..b10340de62 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -665,7 +665,7 @@ int CSMWorld::RefIdCollection::getIndex(const ESM::RefId& id) const int CSMWorld::RefIdCollection::getColumns() const { - return mColumns.size(); + return static_cast(mColumns.size()); } const CSMWorld::ColumnBase& CSMWorld::RefIdCollection::getColumn(int column) const diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index bab9ae38d6..4af538bad4 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -275,7 +275,7 @@ void CSMWorld::RefIdData::erase(const LocalIndex& index, int count) int CSMWorld::RefIdData::getSize() const { - return mIndex.size(); + return static_cast(mIndex.size()); } std::vector CSMWorld::RefIdData::getIds(bool listDeleted) const diff --git a/apps/opencs/view/filter/editwidget.cpp b/apps/opencs/view/filter/editwidget.cpp index 54ed388441..feaa4d4465 100644 --- a/apps/opencs/view/filter/editwidget.cpp +++ b/apps/opencs/view/filter/editwidget.cpp @@ -115,7 +115,7 @@ void CSVFilter::EditWidget::createFilterRequest(const std::vector& s newFilter.emplace_back(newFilterData); } - const unsigned count = newFilter.size(); + const size_t count = newFilter.size(); bool multipleElements = false; switch (count) // setting multipleElements; @@ -181,7 +181,7 @@ void CSVFilter::EditWidget::createFilterRequest(const std::vector& s ss << orAnd << oldContent.toUtf8().constData() << ','; } - for (unsigned i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) { ss << generateFilter(newFilter[i], filterType); @@ -221,13 +221,13 @@ void CSVFilter::EditWidget::createFilterRequest(const std::vector& s std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData, FilterType filterType) const { - const unsigned columns = filterData.columns.size(); + const size_t columns = filterData.columns.size(); bool multipleColumns = false; switch (columns) { case 0: // empty - return ""; // no column to filter + return {}; // no column to filter case 1: // one column to look for multipleColumns = false; @@ -244,7 +244,7 @@ std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData, else { Log(Debug::Warning) << "Generating record filter failed."; - return ""; + return {}; } if (filterType == FilterType::String) quotesResolved = '"' + quotesResolved + '"'; @@ -254,7 +254,7 @@ std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData, if (multipleColumns) { ss << "or("; - for (unsigned i = 0; i < columns; ++i) + for (size_t i = 0; i < columns; ++i) { ss << filterTypeName(filterType) << "(" << '"' << filterData.columns[i] << '"' << ',' << quotesResolved << ')'; diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp index 3f33ae4d1b..ec2a6c4689 100644 --- a/apps/opencs/view/render/brushdraw.cpp +++ b/apps/opencs/view/render/brushdraw.cpp @@ -190,7 +190,7 @@ void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::V osg::ref_ptr colors(new osg::Vec4Array()); const int amountOfPoints = 128; - const float step((osg::PI * 2.0f) / static_cast(amountOfPoints)); + const float step((osg::PIf * 2.0f) / static_cast(amountOfPoints)); const float brushOutlineHeight(1.0f); osg::Vec4f lineColor(1.0f, 1.0f, 1.0f, 0.6f); diff --git a/apps/opencs/view/render/cellborder.cpp b/apps/opencs/view/render/cellborder.cpp index 704db13e89..49a2ca8fa5 100644 --- a/apps/opencs/view/render/cellborder.cpp +++ b/apps/opencs/view/render/cellborder.cpp @@ -17,13 +17,16 @@ #include "../../model/world/cellcoordinates.hpp" -const int CSVRender::CellBorder::CellSize = ESM::Land::REAL_SIZE; +namespace +{ + constexpr int CellSize = ESM::Land::REAL_SIZE; -/* - The number of vertices per cell border is equal to the number of vertices per edge - minus the duplicated corner vertices. An additional vertex to close the loop is NOT needed. -*/ -const int CSVRender::CellBorder::VertexCount = (ESM::Land::LAND_SIZE * 4) - 4; + /* + The number of vertices per cell border is equal to the number of vertices per edge + minus the duplicated corner vertices. An additional vertex to close the loop is NOT needed. + */ + constexpr unsigned VertexCount = (ESM::Land::LAND_SIZE * 4) - 4; +} CSVRender::CellBorder::CellBorder(osg::Group* cellNode, const CSMWorld::CellCoordinates& coords) : mParentNode(cellNode) @@ -105,7 +108,7 @@ void CSVRender::CellBorder::buildShape(const ESM::Land& esmLand) = new osg::DrawElementsUShort(osg::PrimitiveSet::LINE_STRIP, VertexCount + 1); // Assign one primitive to each vertex. - for (size_t i = 0; i < VertexCount; ++i) + for (unsigned i = 0; i < VertexCount; ++i) primitives->setElement(i, i); // Assign the last primitive to the first vertex to close the loop. diff --git a/apps/opencs/view/render/cellborder.hpp b/apps/opencs/view/render/cellborder.hpp index e1201a1f39..1d10aecf12 100644 --- a/apps/opencs/view/render/cellborder.hpp +++ b/apps/opencs/view/render/cellborder.hpp @@ -34,9 +34,6 @@ namespace CSVRender void buildShape(const ESM::Land& esmLand); private: - static const int CellSize; - static const int VertexCount; - size_t landIndex(int x, int y); float scaleToWorld(int val); diff --git a/apps/opencs/view/render/lighting.cpp b/apps/opencs/view/render/lighting.cpp index 3c5bbb4fb0..9e6a48c678 100644 --- a/apps/opencs/view/render/lighting.cpp +++ b/apps/opencs/view/render/lighting.cpp @@ -27,16 +27,16 @@ public: void apply(osg::Switch& switchNode) override { - constexpr int noIndex = -1; + constexpr unsigned noIndex = static_cast(-1); - int initialIndex = noIndex; + unsigned initialIndex = noIndex; if (!switchNode.getUserValue("initialIndex", initialIndex)) { for (size_t i = 0; i < switchNode.getValueList().size(); ++i) { if (switchNode.getValueList()[i]) { - initialIndex = i; + initialIndex = static_cast(i); break; } } diff --git a/apps/opencs/view/render/objectmarker.cpp b/apps/opencs/view/render/objectmarker.cpp index e21436430f..9737bda5cc 100644 --- a/apps/opencs/view/render/objectmarker.cpp +++ b/apps/opencs/view/render/objectmarker.cpp @@ -203,11 +203,11 @@ namespace CSVRender void ObjectMarker::detachMarker() { - for (std::size_t index = mRootNode->getNumParents(); index > 0;) + for (unsigned index = mRootNode->getNumParents(); index > 0;) mRootNode->getParent(--index)->removeChild(mRootNode); osg::ref_ptr widgetRoot = mMarkerNodes["unitArrows"]->asGroup(); - for (std::size_t index = widgetRoot->getNumChildren(); index > 0;) + for (unsigned index = widgetRoot->getNumChildren(); index > 0;) widgetRoot->getChild(--index)->setNodeMask(Mask_Hidden); } diff --git a/apps/opencs/view/render/pathgrid.cpp b/apps/opencs/view/render/pathgrid.cpp index a8b2c81659..2a65001c86 100644 --- a/apps/opencs/view/render/pathgrid.cpp +++ b/apps/opencs/view/render/pathgrid.cpp @@ -306,15 +306,17 @@ namespace CSVRender commands.push(new CSMWorld::RevertCommand(*model, idString)); int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints); - for (int row = source->mPoints.size() - 1; row >= 0; --row) + for (size_t row = source->mPoints.size(); row > 0; --row) { - commands.push(new CSMWorld::DeleteNestedCommand(*model, idString, row, parentColumn)); + commands.push( + new CSMWorld::DeleteNestedCommand(*model, idString, static_cast(row - 1), parentColumn)); } parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); - for (int row = source->mEdges.size() - 1; row >= 0; --row) + for (size_t row = source->mEdges.size(); row > 0; --row) { - commands.push(new CSMWorld::DeleteNestedCommand(*model, idString, row, parentColumn)); + commands.push( + new CSMWorld::DeleteNestedCommand(*model, idString, static_cast(row), parentColumn)); } } } @@ -420,8 +422,8 @@ namespace CSVRender for (size_t edge = 0; edge < source->mEdges.size(); ++edge) { - int adjustment0 = 0; - int adjustment1 = 0; + size_t adjustment0 = 0; + size_t adjustment1 = 0; // Determine necessary adjustment for (const auto point : mSelected) @@ -436,24 +438,24 @@ namespace CSVRender } if (source->mEdges[edge].mV0 > point) - --adjustment0; + ++adjustment0; if (source->mEdges[edge].mV1 > point) - --adjustment1; + ++adjustment1; } if (adjustment0 != 0) { - int adjustedEdge = source->mEdges[edge].mV0 + adjustment0; - commands.push( - new CSMWorld::ModifyCommand(*model, model->index(edge, edge0Column, parent), adjustedEdge)); + int adjustedEdge = static_cast(source->mEdges[edge].mV0 - adjustment0); + commands.push(new CSMWorld::ModifyCommand( + *model, model->index(static_cast(edge), edge0Column, parent), adjustedEdge)); } if (adjustment1 != 0) { - int adjustedEdge = source->mEdges[edge].mV1 + adjustment1; - commands.push( - new CSMWorld::ModifyCommand(*model, model->index(edge, edge1Column, parent), adjustedEdge)); + int adjustedEdge = static_cast(source->mEdges[edge].mV1 - adjustment1); + commands.push(new CSMWorld::ModifyCommand( + *model, model->index(static_cast(edge), edge1Column, parent), adjustedEdge)); } } diff --git a/apps/opencs/view/render/terrainselection.cpp b/apps/opencs/view/render/terrainselection.cpp index bdeb1a0958..672b35d688 100644 --- a/apps/opencs/view/render/terrainselection.cpp +++ b/apps/opencs/view/render/terrainselection.cpp @@ -112,8 +112,8 @@ void CSVRender::TerrainSelection::update() mGeometry->setVertexArray(vertices); osg::ref_ptr drawArrays = new osg::DrawArrays(osg::PrimitiveSet::LINES); - drawArrays->setCount(vertices->size()); - if (vertices->size() != 0) + drawArrays->setCount(static_cast(vertices->size())); + if (!vertices->empty()) mGeometry->addPrimitiveSet(drawArrays); mSelectionNode->addChild(mGeometry); } diff --git a/apps/opencs/view/widget/scenetooltexturebrush.cpp b/apps/opencs/view/widget/scenetooltexturebrush.cpp index 27d628a384..e8d965334a 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.cpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.cpp @@ -308,24 +308,27 @@ void CSVWidget::SceneToolTextureBrush::showPanel(const QPoint& position) void CSVWidget::SceneToolTextureBrush::updatePanel() { - mTable->setRowCount(mBrushHistory.size()); + mTable->setRowCount(static_cast(mBrushHistory.size())); - for (int i = mBrushHistory.size() - 1; i >= 0; --i) + for (size_t i = mBrushHistory.size(); i > 0; --i) { CSMWorld::IdCollection& landtexturesCollection = mDocument.getData().getLandTextures(); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); - const int index = landtexturesCollection.searchId(mBrushHistory[i]); + const int index = landtexturesCollection.searchId(mBrushHistory[i - 1]); + const int row = static_cast(i - 1); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) { - mTable->setItem(i, 1, + mTable->setItem(row, 1, new QTableWidgetItem(landtexturesCollection.getData(index, landTextureFilename).value())); - mTable->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(mBrushHistory[i].getRefIdString()))); + mTable->setItem( + row, 0, new QTableWidgetItem(QString::fromStdString(mBrushHistory[i - 1].getRefIdString()))); } else { - mTable->setItem(i, 1, new QTableWidgetItem("Invalid/deleted texture")); - mTable->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(mBrushHistory[i].getRefIdString()))); + mTable->setItem(row, 1, new QTableWidgetItem("Invalid/deleted texture")); + mTable->setItem( + row, 0, new QTableWidgetItem(QString::fromStdString(mBrushHistory[i - 1].getRefIdString()))); } } } diff --git a/apps/opencs/view/world/scripterrortable.cpp b/apps/opencs/view/world/scripterrortable.cpp index 4bd8c3f390..4db785fea4 100644 --- a/apps/opencs/view/world/scripterrortable.cpp +++ b/apps/opencs/view/world/scripterrortable.cpp @@ -28,7 +28,7 @@ void CSVWorld::ScriptErrorTable::report(const std::string& message, const Compil addMessage(stream.str(), type == Compiler::ErrorHandler::WarningMessage ? CSMDoc::Message::Severity_Warning : CSMDoc::Message::Severity_Error, - loc.mLine, loc.mColumn - loc.mLiteral.length()); + loc.mLine, loc.mColumn - static_cast(loc.mLiteral.length())); } void CSVWorld::ScriptErrorTable::report(const std::string& message, Type type)