Sort the bus alias set by name

If we place pointers in a set, they are sorted by the pointer value in
memory, not the data, so we need a custom comparator

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11890

(cherry picked from commit f7f67c6d53)
This commit is contained in:
Seth Hillbrand 2023-07-21 09:02:38 -07:00
parent 124be52411
commit 2fa05ed245
3 changed files with 17 additions and 5 deletions

View File

@ -291,7 +291,7 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow()
}
}
std::set<std::shared_ptr<BUS_ALIAS>> sheetAliases = screen->GetBusAliases();
auto& sheetAliases = screen->GetBusAliases();
busAliases.insert( busAliases.end(), sheetAliases.begin(), sheetAliases.end() );
}

View File

@ -307,7 +307,7 @@ int ERC_TESTER::TestConflictingBusAliases()
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
{
const std::set< std::shared_ptr<BUS_ALIAS> > screen_aliases = screen->GetBusAliases();
const auto& screen_aliases = screen->GetBusAliases();
for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
{

View File

@ -505,9 +505,9 @@ public:
}
/**
* Return a list of bus aliases defined in this screen
* Return a set of bus aliases defined in this screen
*/
std::set< std::shared_ptr<BUS_ALIAS> > GetBusAliases() const
auto& GetBusAliases() const
{
return m_aliases;
}
@ -571,6 +571,18 @@ private:
*/
size_t getLibSymbolNameMatches( const SCH_SYMBOL& aSymbol, std::vector<wxString>& aMatches );
/**
* Compare two #BUS_ALIAS objects by name. For sorting in the set.
*/
struct BusAliasCmp
{
bool operator()( const std::shared_ptr<BUS_ALIAS>& a, const std::shared_ptr<BUS_ALIAS>& b ) const
{
return a->GetName() < b->GetName();
}
};
public:
/**
* last value for the zoom level, useful in Eeschema when changing the current displayed
@ -610,7 +622,7 @@ private:
bool m_fileExists;
/// List of bus aliases stored in this screen.
std::set< std::shared_ptr< BUS_ALIAS > > m_aliases;
std::set< std::shared_ptr< BUS_ALIAS >, BusAliasCmp > m_aliases;
/// Library symbols required for this schematic.
std::map<wxString, LIB_SYMBOL*> m_libSymbols;