mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
SonarCloud fixes
This commit is contained in:
@@ -1603,7 +1603,7 @@ void CObjectListWindow::init(std::shared_ptr<CIntObject> titleWidget_, std::stri
|
|||||||
|
|
||||||
void CObjectListWindow::trimTextIfTooWide(std::string & text) const
|
void CObjectListWindow::trimTextIfTooWide(std::string & text) const
|
||||||
{
|
{
|
||||||
int maxWidth = pos.w - 60;
|
int maxWidth = pos.w - 60; // 60 px for scrollbar and borders
|
||||||
|
|
||||||
// Create a temporary label to measure text width
|
// Create a temporary label to measure text width
|
||||||
auto label = std::make_shared<CLabel>(0, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, text);
|
auto label = std::make_shared<CLabel>(0, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, text);
|
||||||
@@ -1646,7 +1646,7 @@ void CObjectListWindow::itemsSearchCallback(const std::string & text)
|
|||||||
itemsVisible.clear();
|
itemsVisible.clear();
|
||||||
std::vector<std::pair<int, decltype(items)::value_type>> rankedItems; // Store (score, item)
|
std::vector<std::pair<int, decltype(items)::value_type>> rankedItems; // Store (score, item)
|
||||||
|
|
||||||
for(auto & item : items)
|
for(const auto & item : items)
|
||||||
{
|
{
|
||||||
int score = TextOperations::textSearchSimilarityScore(text, item.second);
|
int score = TextOperations::textSearchSimilarityScore(text, item.second);
|
||||||
if(score < 100) // Keep only relevant items
|
if(score < 100) // Keep only relevant items
|
||||||
@@ -1659,7 +1659,7 @@ void CObjectListWindow::itemsSearchCallback(const std::string & text)
|
|||||||
return a.first < b.first;
|
return a.first < b.first;
|
||||||
});
|
});
|
||||||
|
|
||||||
for(auto & rankedItem : rankedItems)
|
for(const auto & rankedItem : rankedItems)
|
||||||
itemsVisible.push_back(rankedItem.second);
|
itemsVisible.push_back(rankedItem.second);
|
||||||
|
|
||||||
selected = 0;
|
selected = 0;
|
||||||
|
|||||||
@@ -308,16 +308,16 @@ DLL_LINKAGE std::string TextOperations::getLocaleName()
|
|||||||
const std::string localeName = Languages::getLanguageOptions(LIBRARY->generaltexth->getPreferredLanguage()).localeName;
|
const std::string localeName = Languages::getLanguageOptions(LIBRARY->generaltexth->getPreferredLanguage()).localeName;
|
||||||
|
|
||||||
if(localeName.empty())
|
if(localeName.empty())
|
||||||
throw std::runtime_error("Locale name is empty, will use fallback option.");
|
throw std::runtime_error("Using fallback: en_US.UTF-8");
|
||||||
|
|
||||||
return localeName;
|
return localeName;
|
||||||
}
|
}
|
||||||
catch(const std::exception & e)
|
catch(const std::exception & e)
|
||||||
{
|
{
|
||||||
logGlobal->warn("Failed to retrieve locale. Using fallback: en_US.UTF-8");
|
logGlobal->warn("Failed to retrieve locale. %s", e.what());
|
||||||
|
|
||||||
return "en_US.UTF-8";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "en_US.UTF-8";
|
||||||
}
|
}
|
||||||
|
|
||||||
int TextOperations::textSearchSimilarityScore(const std::string & s, const std::string & t)
|
int TextOperations::textSearchSimilarityScore(const std::string & s, const std::string & t)
|
||||||
|
|||||||
Reference in New Issue
Block a user