Adjust pin table sort
The sort routine requires the value to be true with a is strictly lower than b. But just inverting the '<' doesn't yield strictly lower, it includes '>='. This causes items to jump in the list.
This commit is contained in:
parent
42f5c944b3
commit
f4a1fef3b0
|
@ -246,29 +246,40 @@ public:
|
||||||
rhStr = GetValue( rhs, sortCol, units );
|
rhStr = GetValue( rhs, sortCol, units );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmp;
|
bool res;
|
||||||
|
|
||||||
|
// N.B. To meet the iterator sort conditions, we cannot simply invert the truth
|
||||||
|
// to get the opposite sort. i.e. ~(a<b) != (a>b)
|
||||||
|
auto cmp = [ ascending ]( const auto a, const auto b )
|
||||||
|
{
|
||||||
|
if( ascending )
|
||||||
|
return a < b;
|
||||||
|
else
|
||||||
|
return b < a;
|
||||||
|
};
|
||||||
|
|
||||||
switch( sortCol )
|
switch( sortCol )
|
||||||
{
|
{
|
||||||
case COL_NUMBER:
|
case COL_NUMBER:
|
||||||
case COL_NAME:
|
case COL_NAME:
|
||||||
cmp = PinNumbers::Compare( lhStr, rhStr ) < 0;
|
res = cmp( PinNumbers::Compare( lhStr, rhStr ), 0 );
|
||||||
break;
|
break;
|
||||||
case COL_NUMBER_SIZE:
|
case COL_NUMBER_SIZE:
|
||||||
case COL_NAME_SIZE:
|
case COL_NAME_SIZE:
|
||||||
cmp = ValueFromString( units, lhStr, true ) < ValueFromString( units, rhStr, true );
|
res = cmp( ValueFromString( units, lhStr, true ),
|
||||||
|
ValueFromString( units, rhStr, true ) );
|
||||||
break;
|
break;
|
||||||
case COL_LENGTH:
|
case COL_LENGTH:
|
||||||
case COL_POSX:
|
case COL_POSX:
|
||||||
case COL_POSY:
|
case COL_POSY:
|
||||||
cmp = ValueFromString( units, lhStr ) < ValueFromString( units, rhStr );
|
res = cmp( ValueFromString( units, lhStr ), ValueFromString( units, rhStr ) );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cmp = StrNumCmp( lhStr, rhStr ) < 0;
|
res = cmp( StrNumCmp( lhStr, rhStr ), 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ascending == cmp;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RebuildRows( LIB_PINS& aPins, bool groupByName )
|
void RebuildRows( LIB_PINS& aPins, bool groupByName )
|
||||||
|
@ -325,7 +336,7 @@ public:
|
||||||
void SortRows( int aSortCol, bool ascending )
|
void SortRows( int aSortCol, bool ascending )
|
||||||
{
|
{
|
||||||
std::sort( m_rows.begin(), m_rows.end(),
|
std::sort( m_rows.begin(), m_rows.end(),
|
||||||
[ aSortCol, ascending, this ]( LIB_PINS& lhs, LIB_PINS& rhs ) -> bool
|
[ aSortCol, ascending, this ]( const LIB_PINS& lhs, const LIB_PINS& rhs ) -> bool
|
||||||
{
|
{
|
||||||
return compare( lhs, rhs, aSortCol, ascending, m_userUnits );
|
return compare( lhs, rhs, aSortCol, ascending, m_userUnits );
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue