diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index fba1291a4c..d2cc89520c 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -781,7 +781,7 @@ namespace EsmTool for (int skill : mData.mData.mSkills) if (skill != -1) std::cout << " Skill: " << skillLabel(skill) << " (" << skill << ")" << std::endl; - for (int i = 0; i != mData.mData.mRankData.size(); i++) + for (size_t i = 0; i != mData.mData.mRankData.size(); i++) if (!mData.mRanks[i].empty()) { std::cout << " Rank: " << mData.mRanks[i] << std::endl; diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index 001305f362..93b4e2c810 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -249,7 +249,7 @@ namespace ESSImport { ESM::InventoryState& invState = mContext->mPlayer.mObject.mInventory; - for (unsigned int i = 0; i < invState.mItems.size(); ++i) + for (size_t i = 0; i < invState.mItems.size(); ++i) { // FIXME: in case of conflict (multiple items with this refID) use the already equipped one? if (invState.mItems[i].mRef.mRefID == ESM::RefId::stringRefId(refr.mActorData.mSelectedEnchantItem)) diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index 1692193b93..76b685c8a3 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -162,7 +162,7 @@ namespace ESSImport read(mOutFile, file2); // todo rename variable // FIXME: use max(size1, size2) - for (unsigned int i = 0; i < file1.mRecords.size(); ++i) + for (size_t i = 0; i < file1.mRecords.size(); ++i) { File::Record rec = file1.mRecords[i]; @@ -185,7 +185,7 @@ namespace ESSImport } // FIXME: use max(size1, size2) - for (unsigned int j = 0; j < rec.mSubrecords.size(); ++j) + for (size_t j = 0; j < rec.mSubrecords.size(); ++j) { File::Subrecord sub = rec.mSubrecords[j]; @@ -221,7 +221,7 @@ namespace ESSImport << std::hex << sub.mFileOffset << " (2) 0x" << sub2.mFileOffset << std::endl; std::cout << "Data 1:" << std::endl; - for (unsigned int k = 0; k < sub.mData.size(); ++k) + for (size_t k = 0; k < sub.mData.size(); ++k) { bool different = false; if (k >= sub2.mData.size() || sub2.mData[k] != sub.mData[k]) @@ -236,7 +236,7 @@ namespace ESSImport std::cout << std::endl; std::cout << "Data 2:" << std::endl; - for (unsigned int k = 0; k < sub2.mData.size(); ++k) + for (size_t k = 0; k < sub2.mData.size(); ++k) { bool different = false; if (k >= sub.mData.size() || sub.mData[k] != sub2.mData[k]) diff --git a/apps/opencs/model/prefs/enumsetting.cpp b/apps/opencs/model/prefs/enumsetting.cpp index 3d35aa5825..a3ac9bce2b 100644 --- a/apps/opencs/model/prefs/enumsetting.cpp +++ b/apps/opencs/model/prefs/enumsetting.cpp @@ -82,9 +82,9 @@ std::pair CSMPrefs::EnumSetting::makeWidgets(QWidget* parent mWidget = new QComboBox(parent); - int index = 0; + size_t index = 0; - for (int i = 0; i < static_cast(mValues.mValues.size()); ++i) + for (size_t i = 0; i < mValues.mValues.size(); ++i) { if (mDefault.mValue == mValues.mValues[i].mValue) index = i; @@ -95,7 +95,7 @@ std::pair CSMPrefs::EnumSetting::makeWidgets(QWidget* parent mWidget->setItemData(i, QString::fromUtf8(mValues.mValues[i].mTooltip.c_str()), Qt::ToolTipRole); } - mWidget->setCurrentIndex(index); + mWidget->setCurrentIndex(static_cast(index)); if (!mTooltip.empty()) { diff --git a/apps/opencs/model/tools/referenceablecheck.cpp b/apps/opencs/model/tools/referenceablecheck.cpp index 8249597b8a..6effa2cbf6 100644 --- a/apps/opencs/model/tools/referenceablecheck.cpp +++ b/apps/opencs/model/tools/referenceablecheck.cpp @@ -1039,14 +1039,14 @@ void CSMTools::ReferenceableCheckStage::listCheck( someID, "Chance that no object is used is over 100 percent", "", CSMDoc::Message::Severity_Warning); } - for (unsigned i = 0; i < someList.mList.size(); ++i) + for (const auto& element : someList.mList) { - if (mReferencables.searchId(someList.mList[i].mId).first == -1) - messages.add(someID, "Object '" + someList.mList[i].mId.getRefIdString() + "' does not exist", "", + if (mReferencables.searchId(element.mId).first == -1) + messages.add(someID, "Object '" + element.mId.getRefIdString() + "' does not exist", "", CSMDoc::Message::Severity_Error); - if (someList.mList[i].mLevel < 1) - messages.add(someID, "Level of item '" + someList.mList[i].mId.getRefIdString() + "' is non-positive", "", + if (element.mLevel < 1) + messages.add(someID, "Level of item '" + element.mId.getRefIdString() + "' is non-positive", "", CSMDoc::Message::Severity_Error); } } diff --git a/apps/opencs/model/world/columnbase.cpp b/apps/opencs/model/world/columnbase.cpp index de2e31b0fa..1f963b0e4a 100644 --- a/apps/opencs/model/world/columnbase.cpp +++ b/apps/opencs/model/world/columnbase.cpp @@ -134,9 +134,9 @@ CSMWorld::NestableColumn::NestableColumn(int columnId, CSMWorld::ColumnBase::Dis CSMWorld::NestableColumn::~NestableColumn() { - for (unsigned int i = 0; i < mNestedColumns.size(); ++i) + for (auto* col : mNestedColumns) { - delete mNestedColumns[i]; + delete col; } } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 78fa2dd066..1653e8a6b1 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -1026,12 +1026,12 @@ int CSMWorld::Data::getTotalRecords(const std::vector& fi std::unique_ptr reader = std::make_unique(); - for (unsigned int i = 0; i < files.size(); ++i) + for (const auto& file : files) { - if (!std::filesystem::exists(files[i])) + if (!std::filesystem::exists(file)) continue; - reader->open(files[i]); + reader->open(file); records += reader->getRecordCount(); reader->close(); } diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index 37d9a37887..1814e551c1 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -45,21 +45,21 @@ std::string CSMWorld::TableMimeData::getIcon() const std::string tmpIcon; bool firstIteration = true; - for (unsigned i = 0; i < mUniversalId.size(); ++i) + for (const auto& id : mUniversalId) { if (firstIteration) { firstIteration = false; - tmpIcon = mUniversalId[i].getIcon(); + tmpIcon = id.getIcon(); continue; } - if (tmpIcon != mUniversalId[i].getIcon()) + if (tmpIcon != id.getIcon()) { return ":/multitype.png"; // icon stolen from gnome TODO: get new icon } - tmpIcon = mUniversalId[i].getIcon(); + tmpIcon = id.getIcon(); } return mUniversalId.begin()->getIcon(); // All objects are of the same type; diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 2ca2afe128..00d519ecc8 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -698,9 +698,9 @@ bool CSVRender::PagedWorldspaceWidget::handleDrop( return false; bool selectionChanged = false; - for (unsigned i = 0; i < universalIdData.size(); ++i) + for (const auto& id : universalIdData) { - std::pair coordinates(getCoordinatesFromId(universalIdData[i].getId())); + std::pair coordinates(getCoordinatesFromId(id.getId())); if (mSelection.add(CSMWorld::CellCoordinates(coordinates.first, coordinates.second))) { selectionChanged = true; diff --git a/apps/opencs/view/render/pathgrid.cpp b/apps/opencs/view/render/pathgrid.cpp index fe5d87fb81..44e85e7193 100644 --- a/apps/opencs/view/render/pathgrid.cpp +++ b/apps/opencs/view/render/pathgrid.cpp @@ -347,10 +347,10 @@ namespace CSVRender QModelIndex parent = model->index(recordIndex, parentColumn); - for (size_t i = 0; i < mSelected.size(); ++i) + for (const auto& selected : mSelected) { - const CSMWorld::Pathgrid::Point& point = source->mPoints[mSelected[i]]; - int row = static_cast(mSelected[i]); + const CSMWorld::Pathgrid::Point& point = source->mPoints[selected]; + int row = static_cast(selected); commands.push(new CSMWorld::ModifyCommand( *model, model->index(row, posXColumn, parent), clampToCell(point.mX + offsetX))); @@ -378,9 +378,9 @@ namespace CSVRender const CSMWorld::Pathgrid* source = getPathgridSource(); if (source) { - for (size_t i = 0; i < mSelected.size(); ++i) + for (const auto& selected : mSelected) { - addEdge(commands, *source, node, mSelected[i]); + addEdge(commands, *source, node, selected); } } } diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index c20692ba9f..24fe70af94 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -227,11 +227,11 @@ void CSVWorld::DialogueDelegateDispatcher::setEditorData(QWidget* editor, const delegateIt->second->setEditorData(editor, index, true); } - for (unsigned i = 0; i < mProxys.size(); ++i) + for (const auto& proxy : mProxys) { - if (mProxys[i]->getEditor() == editor) + if (proxy->getEditor() == editor) { - mProxys[i]->setIndex(index); + proxy->setIndex(index); } } } @@ -341,9 +341,9 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor( CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher() { - for (unsigned i = 0; i < mProxys.size(); ++i) + for (auto* proxy : mProxys) { - delete mProxys[i]; // unique_ptr could be handy + delete proxy; // unique_ptr could be handy } } @@ -477,8 +477,8 @@ void CSVWorld::EditWidget::createEditorContextMenu( CSVWorld::EditWidget::~EditWidget() { - for (unsigned i = 0; i < mNestedModels.size(); ++i) - delete mNestedModels[i]; + for (auto* model : mNestedModels) + delete model; if (mDispatcher) delete mDispatcher; @@ -511,8 +511,8 @@ void CSVWorld::EditWidget::remake(int row) } mMainWidget = new QWidget(this); - for (unsigned i = 0; i < mNestedModels.size(); ++i) - delete mNestedModels[i]; + for (auto* model : mNestedModels) + delete model; mNestedModels.clear(); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index f5f3fa20ef..1e80805630 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -611,7 +611,7 @@ void CSVWorld::Table::moveRecords(QDropEvent* event) std::vector newOrder(highestDifference + 1); - for (long unsigned int i = 0; i < newOrder.size(); ++i) + for (int i = 0; i <= highestDifference; ++i) { newOrder[i] = i; } diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 2e6fbddf49..9bab0345cb 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -108,7 +108,7 @@ namespace MWClass // hide effects the player doesn't know about MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - for (unsigned int i = 0; i < info.effects.size(); ++i) + for (size_t i = 0; i < info.effects.size(); ++i) info.effects[i].mKnown = MWMechanics::Alchemy::knownEffect(i, player); info.isPotion = true; diff --git a/apps/openmw/mwgui/formatting.cpp b/apps/openmw/mwgui/formatting.cpp index f725801782..0c193b4987 100644 --- a/apps/openmw/mwgui/formatting.cpp +++ b/apps/openmw/mwgui/formatting.cpp @@ -462,7 +462,7 @@ namespace MWGui::Formatting mPaginator.setIgnoreLeadingEmptyLines(true); const MyGUI::VectorLineInfo& lines = mEditBox->getSubWidgetText()->castType()->getLineInfo(); - for (unsigned int i = lastLine; i < lines.size(); ++i) + for (size_t i = lastLine; i < lines.size(); ++i) { if (lines[i].width == 0) ret += lineHeight; diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index ab2d9bce2d..e239e641c7 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -163,13 +163,13 @@ namespace MWGui setGender(proto.isMale() ? GM_Male : GM_Female); recountParts(); - for (unsigned int i = 0; i < mAvailableHeads.size(); ++i) + for (size_t i = 0; i < mAvailableHeads.size(); ++i) { if (mAvailableHeads[i] == proto.mHead) mFaceIndex = i; } - for (unsigned int i = 0; i < mAvailableHairs.size(); ++i) + for (size_t i = 0; i < mAvailableHairs.size(); ++i) { if (mAvailableHairs[i] == proto.mHair) mHairIndex = i; diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 2c3310b891..b371d979f9 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -121,19 +121,19 @@ namespace MWGui else if (mPtr.getType() == ESM::Creature::sRecordId) transport = mPtr.get()->mBase->getTransport(); - for (unsigned int i = 0; i < transport.size(); i++) + for (const auto& dest : transport) { - std::string_view cellname = transport[i].mCellName; + std::string_view cellname = dest.mCellName; bool interior = true; const ESM::ExteriorCellLocation cellIndex - = ESM::positionToExteriorCellLocation(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); + = ESM::positionToExteriorCellLocation(dest.mPos.pos[0], dest.mPos.pos[1]); if (cellname.empty()) { MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex); cellname = MWBase::Environment::get().getWorld()->getCellName(&cell); interior = false; } - addDestination(ESM::RefId::stringRefId(cellname), transport[i].mPos, interior); + addDestination(ESM::RefId::stringRefId(cellname), dest.mPos, interior); } updateLabels();