improve the channel sorting algorithm (much cleaner code now)
This commit is contained in:
parent
77c24059b5
commit
e7b291d906
1 changed files with 14 additions and 18 deletions
|
@ -766,30 +766,26 @@ void CAudioMixerBoard::HideAll()
|
||||||
|
|
||||||
void CAudioMixerBoard::ChangeFaderOrder ( const bool bDoSort )
|
void CAudioMixerBoard::ChangeFaderOrder ( const bool bDoSort )
|
||||||
{
|
{
|
||||||
// TODO better solution to sort by names and get the indexes after sorting (here
|
// create a pair list of lower strings and fader ID for each channel
|
||||||
// we utilize the "data" property to store the original ID value)
|
QList<QPair<QString, int> > PairList;
|
||||||
QListWidget ListWidget;
|
|
||||||
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
|
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||||
{
|
{
|
||||||
// fill list widget (used for sorting the channels)
|
PairList << QPair<QString, int> ( vecpChanFader[i]->GetReceivedName().toLower(), i );
|
||||||
QListWidgetItem* pNewItem = new QListWidgetItem ( vecpChanFader[i]->GetReceivedName() );
|
|
||||||
pNewItem->setData ( Qt::UserRole, i );
|
|
||||||
ListWidget.addItem ( pNewItem );
|
|
||||||
|
|
||||||
// remove channels from layout (note that we keep the spacer on the right side)
|
|
||||||
pMainLayout->removeWidget ( vecpChanFader[i]->GetMainWidget() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if requested, sort the channels
|
||||||
if ( bDoSort )
|
if ( bDoSort )
|
||||||
{
|
{
|
||||||
ListWidget.sortItems();
|
qStableSort ( PairList.begin(), PairList.end() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// add channels to the layout in the new order (since we insert on the left, we
|
// add channels to the layout in the new order (since we insert on the left, we
|
||||||
// have to use a backwards counting loop)
|
// have to use a backwards counting loop), note that it is not required to remove
|
||||||
|
// the widget from the layout first but it is moved to the new position automatically
|
||||||
for ( int i = MAX_NUM_CHANNELS - 1; i >= 0; i-- )
|
for ( int i = MAX_NUM_CHANNELS - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
// add fader frame to the audio mixer board layout
|
pMainLayout->insertWidget ( 0, vecpChanFader[PairList[i].second]->GetMainWidget() );
|
||||||
pMainLayout->insertWidget ( 0, vecpChanFader[ListWidget.item ( i )->data ( Qt::UserRole ).toInt()]->GetMainWidget() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue