diff --git a/apps/opencs/model/filter/parser.cpp b/apps/opencs/model/filter/parser.cpp index 705137e0d7..5443db2854 100644 --- a/apps/opencs/model/filter/parser.cpp +++ b/apps/opencs/model/filter/parser.cpp @@ -643,7 +643,7 @@ bool CSMFilter::Parser::parse(const std::string& filter, bool allowPredefined) return false; } - int index = mData.getFilters().searchId(token.mString); + const int index = mData.getFilters().searchId(ESM::RefId::stringRefId(token.mString)); if (index == -1) { diff --git a/apps/opencs/model/tools/referencecheck.cpp b/apps/opencs/model/tools/referencecheck.cpp index cf6d0b3a4d..87d133a59e 100644 --- a/apps/opencs/model/tools/referencecheck.cpp +++ b/apps/opencs/model/tools/referencecheck.cpp @@ -87,7 +87,7 @@ void CSMTools::ReferenceCheckStage::perform(int stage, CSMDoc::Messages& message messages.add(id, "Invalid faction rank", "", CSMDoc::Message::Severity_Error); } - if (!cellRef.mDestCell.empty() && mCells.searchId(cellRef.mDestCell) == -1) + if (!cellRef.mDestCell.empty() && mCells.searchId(ESM::RefId::stringRefId(cellRef.mDestCell)) == -1) messages.add( id, "Destination cell '" + cellRef.mDestCell + "' does not exist", "", CSMDoc::Message::Severity_Error); diff --git a/apps/opencs/model/tools/topicinfocheck.cpp b/apps/opencs/model/tools/topicinfocheck.cpp index 39d1262f26..ba99a33a28 100644 --- a/apps/opencs/model/tools/topicinfocheck.cpp +++ b/apps/opencs/model/tools/topicinfocheck.cpp @@ -78,7 +78,7 @@ int CSMTools::TopicInfoCheckStage::setup() mCellNames.insert(regionRecord.get().mName); } // Default cell name - int index = mGameSettings.searchId("sDefaultCellname"); + const int index = mGameSettings.searchId(ESM::RefId::stringRefId("sDefaultCellname")); if (index != -1) { const CSMWorld::Record& gmstRecord = mGameSettings.getRecord(index); diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index b00393b8af..fd39950bba 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -86,7 +86,7 @@ namespace CSMWorld private: std::vector>> mRecords; - std::map mIndex; + std::map mIndex; std::vector*> mColumns; // not implemented @@ -148,10 +148,6 @@ namespace CSMWorld ///< Change the state of a record from base to modified, if it is not already. /// \return True if the record was changed. - int searchId(std::string_view id) const override; - ////< Search record with \a id. - /// \return index of record (if found) or -1 (not found) - int searchId(const ESM::RefId& id) const override; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) @@ -232,9 +228,9 @@ namespace CSMWorld std::move(buffer.begin(), buffer.end(), mRecords.begin() + baseIndex); // adjust index - for (std::map::iterator iter(mIndex.begin()); iter != mIndex.end(); ++iter) - if (iter->second >= baseIndex && iter->second < baseIndex + size) - iter->second = newOrder.at(iter->second - baseIndex) + baseIndex; + for (auto& [id, index] : mIndex) + if (index >= baseIndex && index < baseIndex + size) + index = newOrder.at(index - baseIndex) + baseIndex; } return true; @@ -329,9 +325,9 @@ namespace CSMWorld template void Collection::add(const ESXRecordT& record) { - auto id = IdAccessorT().getId(record); + const ESM::RefId id = IdAccessorT().getId(record); - auto iter = mIndex.find(Misc::StringUtils::lowerCase(id.getRefIdString())); + auto iter = mIndex.find(id); if (iter == mIndex.end()) { @@ -438,7 +434,7 @@ namespace CSMWorld { mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count); - typename std::map::iterator iter = mIndex.begin(); + auto iter = mIndex.begin(); while (iter != mIndex.end()) { @@ -451,7 +447,7 @@ namespace CSMWorld } else { - mIndex.erase(iter++); + iter = mIndex.erase(iter); } } else @@ -474,11 +470,9 @@ namespace CSMWorld } template - int Collection::searchId(std::string_view id) const + int Collection::searchId(const ESM::RefId& id) const { - std::string id2 = Misc::StringUtils::lowerCase(id); - - std::map::const_iterator iter = mIndex.find(id2); + const auto iter = mIndex.find(id); if (iter == mIndex.end()) return -1; @@ -486,13 +480,6 @@ namespace CSMWorld return iter->second; } - template - int Collection::searchId(const ESM::RefId& id) const - { - - return searchId(id.getRefIdString()); - } - template void Collection::replace(int index, std::unique_ptr record) { @@ -549,7 +536,7 @@ namespace CSMWorld throw std::runtime_error("index out of range"); std::unique_ptr> record2(static_cast*>(record.release())); - std::string id = Misc::StringUtils::lowerCase(IdAccessorT().getId(record2->get()).getRefIdString()); + ESM::RefId id = IdAccessorT().getId(record2->get()); if (index == size) mRecords.push_back(std::move(record2)); @@ -558,10 +545,10 @@ namespace CSMWorld if (index < size - 1) { - for (std::map::iterator iter(mIndex.begin()); iter != mIndex.end(); ++iter) + for (auto& [key, value] : mIndex) { - if (iter->second >= index) - ++(iter->second); + if (value >= index) + ++value; } } diff --git a/apps/opencs/model/world/collectionbase.cpp b/apps/opencs/model/world/collectionbase.cpp index 42c0718609..e3fb3cf63c 100644 --- a/apps/opencs/model/world/collectionbase.cpp +++ b/apps/opencs/model/world/collectionbase.cpp @@ -11,9 +11,9 @@ CSMWorld::CollectionBase::CollectionBase() {} CSMWorld::CollectionBase::~CollectionBase() {} -int CSMWorld::CollectionBase::getInsertIndex(const std::string& id, UniversalId::Type type, RecordBase* record) const +int CSMWorld::CollectionBase::getInsertIndex(const ESM::RefId& id, UniversalId::Type type, RecordBase* record) const { - return getAppendIndex(ESM::RefId::stringRefId(id), type); + return getAppendIndex(id, type); } int CSMWorld::CollectionBase::searchColumnIndex(Columns::ColumnId id) const diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index de3623fac0..64bfb58109 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -65,10 +65,6 @@ namespace CSMWorld virtual void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) = 0; ///< \param type Will be ignored, unless the collection supports multiple record types - virtual int searchId(std::string_view id) const = 0; - ////< Search record with \a id. - /// \return index of record (if found) or -1 (not found) - virtual int searchId(const ESM::RefId& id) const = 0; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) @@ -107,7 +103,7 @@ namespace CSMWorld /// \return Success? virtual int getInsertIndex( - const std::string& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const; + const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const; ///< Works like getAppendIndex unless an overloaded method uses the record pointer /// to get additional info about the record that results in an alternative index. diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 3fe87cde40..09296b55d6 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -1072,13 +1072,14 @@ void CSMWorld::Data::loadFallbackEntries() std::pair doorMarkers[] = { std::make_pair("PrisonMarker", "marker_prison.nif") }; - for (const auto& marker : staticMarkers) + for (const auto& [id, model] : staticMarkers) { - if (mReferenceables.searchId(marker.first) == -1) + const ESM::RefId refId = ESM::RefId::stringRefId(id); + if (mReferenceables.searchId(refId) == -1) { ESM::Static newMarker; - newMarker.mId = ESM::RefId::stringRefId(marker.first); - newMarker.mModel = marker.second; + newMarker.mId = refId; + newMarker.mModel = model; newMarker.mRecordFlags = 0; auto record = std::make_unique>(); record->mBase = newMarker; @@ -1087,13 +1088,14 @@ void CSMWorld::Data::loadFallbackEntries() } } - for (const auto& marker : doorMarkers) + for (const auto& [id, model] : doorMarkers) { - if (mReferenceables.searchId(marker.first) == -1) + const ESM::RefId refId = ESM::RefId::stringRefId(id); + if (mReferenceables.searchId(refId) == -1) { ESM::Door newMarker; - newMarker.mId = ESM::RefId::stringRefId(marker.first); - newMarker.mModel = marker.second; + newMarker.mId = refId; + newMarker.mModel = model; newMarker.mRecordFlags = 0; auto record = std::make_unique>(); record->mBase = newMarker; @@ -1280,25 +1282,24 @@ bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages) bool isDeleted = false; record.load(*mReader, isDeleted); - const std::string& recordIdString = record.mId.getRefIdString(); if (isDeleted) { // record vector can be shuffled around which would make pointer to record invalid mDialogue = nullptr; - if (mJournals.tryDelete(recordIdString)) + if (mJournals.tryDelete(record.mId)) { removeDialogueInfos(record.mId, mJournalInfosByTopic, mJournalInfos); } - else if (mTopics.tryDelete(recordIdString)) + else if (mTopics.tryDelete(record.mId)) { removeDialogueInfos(record.mId, mTopicInfosByTopic, mTopicInfos); } else { messages.add(UniversalId::Type_None, - "Trying to delete dialogue record " + recordIdString + " which does not exist", "", + "Trying to delete dialogue record " + record.mId.getRefIdString() + " which does not exist", "", CSMDoc::Message::Severity_Warning); } } @@ -1378,13 +1379,15 @@ bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages) bool CSMWorld::Data::hasId(const std::string& id) const { - return getGlobals().searchId(id) != -1 || getGmsts().searchId(id) != -1 || getSkills().searchId(id) != -1 - || getClasses().searchId(id) != -1 || getFactions().searchId(id) != -1 || getRaces().searchId(id) != -1 - || getSounds().searchId(id) != -1 || getScripts().searchId(id) != -1 || getRegions().searchId(id) != -1 - || getBirthsigns().searchId(id) != -1 || getSpells().searchId(id) != -1 || getTopics().searchId(id) != -1 - || getJournals().searchId(id) != -1 || getCells().searchId(id) != -1 || getEnchantments().searchId(id) != -1 - || getBodyParts().searchId(id) != -1 || getSoundGens().searchId(id) != -1 - || getMagicEffects().searchId(id) != -1 || getReferenceables().searchId(id) != -1; + const ESM::RefId refId = ESM::RefId::stringRefId(id); + return getGlobals().searchId(refId) != -1 || getGmsts().searchId(refId) != -1 || getSkills().searchId(refId) != -1 + || getClasses().searchId(refId) != -1 || getFactions().searchId(refId) != -1 || getRaces().searchId(refId) != -1 + || getSounds().searchId(refId) != -1 || getScripts().searchId(refId) != -1 || getRegions().searchId(refId) != -1 + || getBirthsigns().searchId(refId) != -1 || getSpells().searchId(refId) != -1 + || getTopics().searchId(refId) != -1 || getJournals().searchId(refId) != -1 || getCells().searchId(refId) != -1 + || getEnchantments().searchId(refId) != -1 || getBodyParts().searchId(refId) != -1 + || getSoundGens().searchId(refId) != -1 || getMagicEffects().searchId(refId) != -1 + || getReferenceables().searchId(refId) != -1; } int CSMWorld::Data::count(RecordBase::State state) const diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 95165b021c..2382ff3274 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -40,7 +40,7 @@ namespace CSMWorld /// \return index int load(const ESXRecordT& record, bool base, int index = -2); - bool tryDelete(const std::string& id); + bool tryDelete(const ESM::RefId& id); ///< Try deleting \a id. If the id does not exist or can't be deleted the call is ignored. /// /// \return Has the ID been deleted? @@ -135,7 +135,7 @@ namespace CSMWorld } template - bool IdCollection::tryDelete(const std::string& id) + bool IdCollection::tryDelete(const ESM::RefId& id) { int index = this->searchId(id); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index c0da8e7fac..8d2e676725 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -243,7 +243,8 @@ std::string CSMWorld::IdTable::getId(int row) const /// This method can return only indexes to the top level table cells QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column) const { - int row = mIdCollection->searchId(id); + const int row = mIdCollection->searchId(ESM::RefId::stringRefId(id)); + if (row != -1) return index(row, column); @@ -253,7 +254,8 @@ QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column) void CSMWorld::IdTable::setRecord( const std::string& id, std::unique_ptr record, CSMWorld::UniversalId::Type type) { - int index = mIdCollection->searchId(id); + const ESM::RefId refId = ESM::RefId::stringRefId(id); + const int index = mIdCollection->searchId(refId); if (index == -1) { @@ -263,7 +265,7 @@ void CSMWorld::IdTable::setRecord( // // Use an alternative method to get the correct index. For non-Info records the // record pointer is ignored and internally calls getAppendIndex. - int index2 = mIdCollection->getInsertIndex(id, type, record.get()); + const int index2 = mIdCollection->getInsertIndex(refId, type, record.get()); beginInsertRows(QModelIndex(), index2, index2); @@ -377,9 +379,10 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import for (const std::string& id : ids) { int plugin, index; - LandTexture::parseUniqueRecordId(id, plugin, index); - int oldRow = idCollection()->searchId(id); + + const ESM::RefId refId = ESM::RefId::stringRefId(id); + const int oldRow = idCollection()->searchId(refId); // If it does not exist or it is in the current plugin, it can be skipped. if (oldRow < 0 || plugin == 0) @@ -403,12 +406,13 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import do { std::string newId = LandTexture::createUniqueRecordId(0, index); - int newRow = idCollection()->searchId(newId); + const ESM::RefId newRefId = ESM::RefId::stringRefId(newId); + int newRow = idCollection()->searchId(newRefId); if (newRow < 0) { // Id not taken, clone it - cloneRecord(ESM::RefId::stringRefId(id), ESM::RefId::stringRefId(newId), UniversalId::Type_LandTexture); + cloneRecord(refId, newRefId, UniversalId::Type_LandTexture); results.createdRecords.push_back(newId); results.recordMapping.emplace_back(id, newId); reverseLookupMap.emplace(texture, newId); diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index b06f7d05f8..3343275b4d 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -12,7 +12,7 @@ bool CSMWorld::InfoCollection::load(const Info& record, bool base) { - int index = searchId(record.mId.getRefIdString()); + const int index = searchId(record.mId); if (index == -1) { @@ -48,7 +48,7 @@ void CSMWorld::InfoCollection::load( bool isDeleted = false; info.load(reader, isDeleted); - std::string id = dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString(); + const ESM::RefId id = ESM::RefId::stringRefId(dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString()); if (isDeleted) { @@ -75,7 +75,7 @@ void CSMWorld::InfoCollection::load( { info.mTopicId = dialogue.mId; info.mOriginalId = info.mId; - info.mId = ESM::RefId::stringRefId(id); + info.mId = id; if (load(info, base)) infosByTopic[dialogue.mId].push_back(info.mId); diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index d3e16188e7..0685471463 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -725,9 +725,9 @@ void CSMWorld::RefIdCollection::appendBlankRecord(const ESM::RefId& id, Universa mData.appendRecord(type, id, false); } -int CSMWorld::RefIdCollection::searchId(std::string_view id) const +int CSMWorld::RefIdCollection::searchId(const ESM::RefId& id) const { - RefIdData::LocalIndex localIndex = mData.searchId(ESM::RefId::stringRefId(id)); + const RefIdData::LocalIndex localIndex = mData.searchId(id); if (localIndex.first == -1) return -1; @@ -735,11 +735,6 @@ int CSMWorld::RefIdCollection::searchId(std::string_view id) const return mData.localToGlobalIndex(localIndex); } -int CSMWorld::RefIdCollection::searchId(const ESM::RefId& id) const -{ - return searchId(id.getRefIdString()); -} - void CSMWorld::RefIdCollection::replace(int index, std::unique_ptr record) { mData.getRecord(mData.globalToLocalIndex(index)).assign(*record.release()); diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 45e3a65223..10892535cf 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -89,10 +89,6 @@ namespace CSMWorld void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type) override; ///< \param type Will be ignored, unless the collection supports multiple record types - int searchId(std::string_view id) const override; - ////< Search record with \a id. - /// \return index of record (if found) or -1 (not found) - int searchId(const ESM::RefId& id) const override; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) diff --git a/apps/opencs/model/world/scriptcontext.cpp b/apps/opencs/model/world/scriptcontext.cpp index da762d6226..7f554a75af 100644 --- a/apps/opencs/model/world/scriptcontext.cpp +++ b/apps/opencs/model/world/scriptcontext.cpp @@ -32,7 +32,7 @@ bool CSMWorld::ScriptContext::canDeclareLocals() const char CSMWorld::ScriptContext::getGlobalType(const std::string& name) const { - int index = mData.getGlobals().searchId(name); + const int index = mData.getGlobals().searchId(ESM::RefId::stringRefId(name)); if (index != -1) { diff --git a/apps/opencs/view/render/actor.cpp b/apps/opencs/view/render/actor.cpp index c85a484e67..803299bd25 100644 --- a/apps/opencs/view/render/actor.cpp +++ b/apps/opencs/view/render/actor.cpp @@ -128,7 +128,7 @@ namespace CSVRender { const auto& bodyParts = mData.getBodyParts(); - int index = bodyParts.searchId(bodyPartId); + const int index = bodyParts.searchId(ESM::RefId::stringRefId(bodyPartId)); if (index != -1 && !bodyParts.getRecord(index).isDeleted()) return MeshPrefix + bodyParts.getRecord(index).get().mModel; else diff --git a/apps/opencs/view/render/cellwater.cpp b/apps/opencs/view/render/cellwater.cpp index 7fe72f282c..7589f2c1fc 100644 --- a/apps/opencs/view/render/cellwater.cpp +++ b/apps/opencs/view/render/cellwater.cpp @@ -57,7 +57,7 @@ namespace CSVRender mWaterGroup = new osg::Group(); mWaterTransform->addChild(mWaterGroup); - int cellIndex = mData.getCells().searchId(mId); + const int cellIndex = mData.getCells().searchId(ESM::RefId::stringRefId(mId)); if (cellIndex > -1) { updateCellData(mData.getCells().getRecord(cellIndex)); diff --git a/apps/opencs/view/render/instancemode.cpp b/apps/opencs/view/render/instancemode.cpp index 30d77052f9..e0f05c2fab 100644 --- a/apps/opencs/view/render/instancemode.cpp +++ b/apps/opencs/view/render/instancemode.cpp @@ -965,7 +965,7 @@ void CSVRender::InstanceMode::dropEvent(QDropEvent* event) CSMWorld::IdTree& cellTable = dynamic_cast(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells)); - bool noCell = document.getData().getCells().searchId(cellId) == -1; + const bool noCell = document.getData().getCells().searchId(ESM::RefId::stringRefId(cellId)) == -1; if (noCell) { diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 64be1f32a4..2ca2afe128 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -77,7 +77,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells() else { // update - int index = cells.searchId(iter->first.getId(mWorldspace)); + const int index = cells.searchId(ESM::RefId::stringRefId(iter->first.getId(mWorldspace))); bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted; @@ -460,7 +460,7 @@ void CSVRender::PagedWorldspaceWidget::addCellToScene(const CSMWorld::CellCoordi { const CSMWorld::IdCollection& cells = mDocument.getData().getCells(); - int index = cells.searchId(coordinates.getId(mWorldspace)); + const int index = cells.searchId(ESM::RefId::stringRefId(coordinates.getId(mWorldspace))); bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted; diff --git a/apps/opencs/view/render/terrainselection.cpp b/apps/opencs/view/render/terrainselection.cpp index 030d441c9b..bdeb1a0958 100644 --- a/apps/opencs/view/render/terrainselection.cpp +++ b/apps/opencs/view/render/terrainselection.cpp @@ -296,14 +296,14 @@ bool CSVRender::TerrainSelection::noCell(const std::string& cellId) { CSMDoc::Document& document = mWorldspaceWidget->getDocument(); const CSMWorld::IdCollection& cellCollection = document.getData().getCells(); - return cellCollection.searchId(cellId) == -1; + return cellCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1; } bool CSVRender::TerrainSelection::noLand(const std::string& cellId) { CSMDoc::Document& document = mWorldspaceWidget->getDocument(); const CSMWorld::IdCollection& landCollection = document.getData().getLand(); - return landCollection.searchId(cellId) == -1; + return landCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1; } bool CSVRender::TerrainSelection::noLandLoaded(const std::string& cellId) diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index 36da957270..3c4a1e5570 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -1326,14 +1326,14 @@ bool CSVRender::TerrainShapeMode::noCell(const std::string& cellId) { CSMDoc::Document& document = getWorldspaceWidget().getDocument(); const CSMWorld::IdCollection& cellCollection = document.getData().getCells(); - return cellCollection.searchId(cellId) == -1; + return cellCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1; } bool CSVRender::TerrainShapeMode::noLand(const std::string& cellId) { CSMDoc::Document& document = getWorldspaceWidget().getDocument(); const CSMWorld::IdCollection& landCollection = document.getData().getLand(); - return landCollection.searchId(cellId) == -1; + return landCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1; } bool CSVRender::TerrainShapeMode::noLandLoaded(const std::string& cellId) diff --git a/apps/opencs/view/render/terrainstorage.cpp b/apps/opencs/view/render/terrainstorage.cpp index 0fccd08193..da9c00e33b 100644 --- a/apps/opencs/view/render/terrainstorage.cpp +++ b/apps/opencs/view/render/terrainstorage.cpp @@ -32,7 +32,8 @@ namespace CSVRender { // The cell isn't guaranteed to have Land. This is because the terrain implementation // has to wrap the vertices of the last row and column to the next cell, which may be a nonexisting cell - int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)); + const int index + = mData.getLand().searchId(ESM::RefId::stringRefId(CSMWorld::Land::createUniqueRecordId(cellX, cellY))); if (index == -1) return nullptr; @@ -43,7 +44,8 @@ namespace CSVRender const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin) { - int row = mData.getLandTextures().searchId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index)); + const int row = mData.getLandTextures().searchId( + ESM::RefId::stringRefId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index))); if (row == -1) return nullptr; @@ -65,7 +67,8 @@ namespace CSVRender { float height = 0.f; - int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)); + const int index + = mData.getLand().searchId(ESM::RefId::stringRefId(CSMWorld::Land::createUniqueRecordId(cellX, cellY))); if (index == -1) // no land! return height; diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 97f81e2511..dfac049acb 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -137,7 +137,7 @@ void CSVRender::TerrainTextureMode::primaryEditPressed(const WorldspaceHitResult QUndoStack& undoStack = document.getUndoStack(); CSMWorld::IdCollection& landtexturesCollection = document.getData().getLandTextures(); - int index = landtexturesCollection.searchId(mBrushTexture); + int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture)); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr) { @@ -186,7 +186,7 @@ bool CSVRender::TerrainTextureMode::primaryEditStartDrag(const QPoint& pos) mDragMode = InteractionType_PrimaryEdit; CSMWorld::IdCollection& landtexturesCollection = document.getData().getLandTextures(); - int index = landtexturesCollection.searchId(mBrushTexture); + const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture)); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr) { @@ -242,7 +242,7 @@ void CSVRender::TerrainTextureMode::drag(const QPoint& pos, int diffX, int diffY CSMDoc::Document& document = getWorldspaceWidget().getDocument(); CSMWorld::IdCollection& landtexturesCollection = document.getData().getLandTextures(); - int index = landtexturesCollection.searchId(mBrushTexture); + const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture)); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr) { @@ -273,7 +273,7 @@ void CSVRender::TerrainTextureMode::dragCompleted(const QPoint& pos) QUndoStack& undoStack = document.getUndoStack(); CSMWorld::IdCollection& landtexturesCollection = document.getData().getLandTextures(); - int index = landtexturesCollection.searchId(mBrushTexture); + const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture)); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) { @@ -718,8 +718,9 @@ bool CSVRender::TerrainTextureMode::allowLandTextureEditing(std::string cellId) CSMWorld::IdTree& cellTable = dynamic_cast(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells)); - bool noCell = document.getData().getCells().searchId(cellId) == -1; - bool noLand = document.getData().getLand().searchId(cellId) == -1; + const ESM::RefId cellRefId = ESM::RefId::stringRefId(cellId); + const bool noCell = document.getData().getCells().searchId(cellRefId) == -1; + const bool noLand = document.getData().getLand().searchId(cellRefId) == -1; if (noCell) { diff --git a/apps/opencs/view/widget/scenetooltexturebrush.cpp b/apps/opencs/view/widget/scenetooltexturebrush.cpp index 51149b36ad..cc372753f6 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.cpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.cpp @@ -77,7 +77,7 @@ CSVWidget::TextureBrushWindow::TextureBrushWindow(CSMDoc::Document& document, QW CSMWorld::IdCollection& landtexturesCollection = mDocument.getData().getLandTextures(); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); - int index = landtexturesCollection.searchId(mBrushTexture); + const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture)); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) { @@ -164,9 +164,11 @@ void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture) int index = 0; int pluginInDragged = 0; CSMWorld::LandTexture::parseUniqueRecordId(brushTexture, pluginInDragged, index); + const ESM::RefId brushTextureRefId = ESM::RefId::stringRefId(brushTexture); std::string newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, index); - int rowInBase = landtexturesCollection.searchId(brushTexture); - int rowInNew = landtexturesCollection.searchId(newBrushTextureId); + ESM::RefId newBrushTextureRefId = ESM::RefId::stringRefId(newBrushTextureId); + int rowInBase = landtexturesCollection.searchId(brushTextureRefId); + int rowInNew = landtexturesCollection.searchId(newBrushTextureRefId); // Check if texture exists in current plugin, and clone if id found in base, otherwise reindex the texture // TO-DO: Handle case when texture is not found in neither base or plugin properly (finding new index is not enough) @@ -181,10 +183,11 @@ void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture) do { newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, counter); - if (landtexturesCollection.searchId(brushTexture) != -1 - && landtexturesCollection.getRecord(ESM::RefId::stringRefId(brushTexture)).isDeleted() == 0 - && landtexturesCollection.searchId(newBrushTextureId) != -1 - && landtexturesCollection.getRecord(ESM::RefId::stringRefId(newBrushTextureId)).isDeleted() == 0) + newBrushTextureRefId = ESM::RefId::stringRefId(newBrushTextureId); + if (landtexturesCollection.searchId(brushTextureRefId) != -1 + && landtexturesCollection.getRecord(brushTextureRefId).isDeleted() == 0 + && landtexturesCollection.searchId(newBrushTextureRefId) != -1 + && landtexturesCollection.getRecord(newBrushTextureRefId).isDeleted() == 0) counter = (counter + 1) % maxCounter; else freeIndexFound = true; @@ -307,7 +310,7 @@ void CSVWidget::SceneToolTextureBrush::setButtonIcon(CSVWidget::BrushShape brush CSMWorld::IdCollection& landtexturesCollection = mDocument.getData().getLandTextures(); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); - int index = landtexturesCollection.searchId(mTextureBrushWindow->mBrushTexture); + const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mTextureBrushWindow->mBrushTexture)); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) { @@ -339,7 +342,7 @@ void CSVWidget::SceneToolTextureBrush::updatePanel() { CSMWorld::IdCollection& landtexturesCollection = mDocument.getData().getLandTextures(); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); - int index = landtexturesCollection.searchId(mBrushHistory[i]); + const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushHistory[i])); if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) { diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index cdea2b27f9..c8f92630f3 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -126,7 +126,7 @@ std::string CSVWorld::InfoCreator::getErrors() const // We ignore errors from GenericCreator here, because they can never happen in an InfoCreator. std::string errors; - std::string topic = mTopic->text().toUtf8().constData(); + const ESM::RefId topic = ESM::RefId::stringRefId(mTopic->text().toStdString()); if ((getCollectionId().getType() == CSMWorld::UniversalId::Type_TopicInfos ? getData().getTopics() : getData().getJournals()) diff --git a/apps/opencs/view/world/landcreator.cpp b/apps/opencs/view/world/landcreator.cpp index bc8d4d2d06..5ba2de603e 100644 --- a/apps/opencs/view/world/landcreator.cpp +++ b/apps/opencs/view/world/landcreator.cpp @@ -89,7 +89,7 @@ namespace CSVWorld std::string LandCreator::getErrors() const { - if (getData().getLand().searchId(getId()) >= 0) + if (getData().getLand().searchId(ESM::RefId::stringRefId(getId())) >= 0) return "A land with that name already exists."; return ""; diff --git a/apps/opencs/view/world/landtexturecreator.cpp b/apps/opencs/view/world/landtexturecreator.cpp index f82a6a1298..a46e5b6dbe 100644 --- a/apps/opencs/view/world/landtexturecreator.cpp +++ b/apps/opencs/view/world/landtexturecreator.cpp @@ -72,7 +72,7 @@ namespace CSVWorld std::string LandTextureCreator::getErrors() const { - if (getData().getLandTextures().searchId(getId()) >= 0) + if (getData().getLandTextures().searchId(ESM::RefId::stringRefId(getId())) >= 0) { return "Index is already in use"; } diff --git a/apps/opencs/view/world/pathgridcreator.cpp b/apps/opencs/view/world/pathgridcreator.cpp index 582ef46e9d..51c3b1d282 100644 --- a/apps/opencs/view/world/pathgridcreator.cpp +++ b/apps/opencs/view/world/pathgridcreator.cpp @@ -62,7 +62,7 @@ void CSVWorld::PathgridCreator::cloneMode(const std::string& originId, const CSM std::string CSVWorld::PathgridCreator::getErrors() const { - std::string cellId = getId(); + const ESM::RefId cellId = ESM::RefId::stringRefId(getId()); // Check user input for any errors. std::string errors; diff --git a/apps/opencs/view/world/previewsubview.cpp b/apps/opencs/view/world/previewsubview.cpp index b2148d5ee0..73ecb2157a 100644 --- a/apps/opencs/view/world/previewsubview.cpp +++ b/apps/opencs/view/world/previewsubview.cpp @@ -22,7 +22,7 @@ CSVWorld::PreviewSubView::PreviewSubView(const CSMWorld::UniversalId& id, CSMDoc { QHBoxLayout* layout = new QHBoxLayout; - if (document.getData().getReferenceables().searchId(id.getId()) == -1) + if (document.getData().getReferenceables().searchId(ESM::RefId::stringRefId(id.getId())) == -1) { std::string referenceableId = document.getData() .getReferences() diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 9228f0f87a..925ae53789 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -65,7 +65,7 @@ std::string CSVWorld::ReferenceCreator::getErrors() const // record is internal and requires neither user input nor verification. std::string errors; - std::string cell = mCell->text().toUtf8().constData(); + const ESM::RefId cell = ESM::RefId::stringRefId(mCell->text().toStdString()); if (cell.empty()) errors += "Missing Cell ID"; diff --git a/apps/opencs/view/world/startscriptcreator.cpp b/apps/opencs/view/world/startscriptcreator.cpp index 8145438039..fcbbc76159 100644 --- a/apps/opencs/view/world/startscriptcreator.cpp +++ b/apps/opencs/view/world/startscriptcreator.cpp @@ -62,7 +62,7 @@ void CSVWorld::StartScriptCreator::cloneMode(const std::string& originId, const std::string CSVWorld::StartScriptCreator::getErrors() const { - std::string scriptId = getId(); + const ESM::RefId scriptId = ESM::RefId::stringRefId(getId()); // Check user input for any errors. std::string errors; diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 035be5ffa2..80f0c33cec 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -152,7 +152,7 @@ void CSVWorld::Table::contextMenuEvent(QContextMenuEvent* event) { CSMWorld::UniversalId id = mModel->view(row).first; - int index = mDocument.getData().getCells().searchId(id.getId()); + const int index = mDocument.getData().getCells().searchId(ESM::RefId::stringRefId(id.getId())); // index==-1: the ID references a worldspace instead of a cell (ignore for now and go // ahead)