worldlist now sorted case insensetive

Dieser Commit ist enthalten in:
Reinder Feenstra 2024-07-15 23:53:04 +02:00
Ursprung db50f112b8
Commit 8e655f7c2e
2 geänderte Dateien mit 16 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,7 @@
* *
* This file is part of the traintastic source code. * This file is part of the traintastic source code.
* *
* Copyright (C) 2019-2020,2022-2023 Reinder Feenstra * Copyright (C) 2019-2020,2022-2024 Reinder Feenstra
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -98,7 +98,7 @@ void WorldList::buildIndex()
} }
} }
std::sort(m_items.begin(), m_items.end(), [](const WorldInfo& a, const WorldInfo& b) -> bool { return a > b; }); sort();
//for(auto& model : m_models) //for(auto& model : m_models)
// model->setRowCount(m_items.size()); // model->setRowCount(m_items.size());
@ -138,3 +138,12 @@ bool WorldList::readInfo(const json& world, WorldInfo& info)
return !info.uuid.is_nil(); return !info.uuid.is_nil();
} }
void WorldList::sort()
{
std::sort(m_items.begin(), m_items.end(),
[](const WorldInfo& a, const WorldInfo& b) -> bool
{
return a > b;
});
}

Datei anzeigen

@ -3,7 +3,7 @@
* *
* This file is part of the traintastic source code. * This file is part of the traintastic source code.
* *
* Copyright (C) 2019-2020,2023 Reinder Feenstra * Copyright (C) 2019-2020,2023-2024 Reinder Feenstra
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -45,10 +45,13 @@ class WorldList : public Object, public Table
bool operator >(const WorldInfo& that) const bool operator >(const WorldInfo& that) const
{ {
return name.compare(that.name) > 0; return strcasecmp(name.c_str(), that.name.c_str()) < 0;
} }
}; };
private:
void sort();
protected: protected:
static bool readInfo(const nlohmann::json& world, WorldInfo& info); static bool readInfo(const nlohmann::json& world, WorldInfo& info);