- QMenu *sort_menu = menu.addMenu( qtr( "Sort by" ) + QString(" ") +
- qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
- sort_menu->addAction( qtr( "Ascending" ),
- this, SLOT( popupSortAsc() ) );
- sort_menu->addAction( qtr( "Descending" ),
- this, SLOT( popupSortDesc() ) );
+ if( !sortingMenu )
+ {
+ sortingMenu = new QMenu( qtr( "Sort by" ) );
+ sortingMapper = new QSignalMapper( this );
+ int i, j;
+ for( i = 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
+ {
+ if( i == COLUMN_NUMBER ) continue;
+ QMenu *m = sortingMenu->addMenu( qfu( psz_column_title( i ) ) );
+ QAction *asc = m->addAction( qtr("Ascending") );
+ QAction *desc = m->addAction( qtr("Descending") );
+ sortingMapper->setMapping( asc, j );
+ sortingMapper->setMapping( desc, -j );
+ CONNECT( asc, triggered(), sortingMapper, map() );
+ CONNECT( desc, triggered(), sortingMapper, map() );
+ }
+ CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
+ }
+ menu.addMenu( sortingMenu );