enlarge connection dialog, sort the list by the minimum ping time of a server

This commit is contained in:
Volker Fischer 2011-11-15 20:06:27 +00:00
parent e0dc85a5f1
commit 40d22e6220
2 changed files with 26 additions and 4 deletions

View File

@ -72,13 +72,17 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
cbxServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS );
cbxServerAddr->setInsertPolicy ( QComboBox::NoInsert );
// set up list view for connected clients
// set up list view for connected clients (note that the last column size
// must not be specified since this column takes all the remaining space)
lvwServers->setColumnWidth ( 0, 170 );
lvwServers->setColumnWidth ( 1, 65 );
lvwServers->setColumnWidth ( 2, 55 );
lvwServers->setColumnWidth ( 3, 130 );
lvwServers->clear();
// add invisible column which is used for sorting the list
lvwServers->setColumnCount ( 5 );
lvwServers->hideColumn ( 4 );
// make sure the connect button has the focus
butConnect->setFocus();
@ -282,6 +286,10 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
pNewListViewItem->setText ( 3, strLocation );
// init the minimum ping time with a large number (note that this number
// must fit in an integer type)
pNewListViewItem->setText ( 4, "99999999" );
// store host address
pNewListViewItem->setData ( 0, Qt::UserRole,
CurHostAddress.toString() );
@ -411,6 +419,20 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& InetAddr,
lvwServers->topLevelItem ( iIdx )->
setText ( 2, QString().setNum ( iNumClients ) );
// update minimum ping time column (invisible, used for sorting) if
// the new value is smaller than the old value
if ( lvwServers->topLevelItem ( iIdx )->text ( 4 ).toInt() > iPingTime )
{
// we pad to a total of 8 characters with zeros to make sure the
// sorting is done correctly
lvwServers->topLevelItem ( iIdx )->
setText ( 4, QString ( "%1" ).arg (
iPingTime, 8, 10, QLatin1Char( '0' ) ) );
// update the sorting (lowest number on top)
lvwServers->sortByColumn ( 4, Qt::AscendingOrder );
}
// a ping time was received, set item to visible
lvwServers->topLevelItem ( iIdx )->setHidden ( false );
}

View File

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>255</height>
<width>521</width>
<height>294</height>
</rect>
</property>
<property name="windowTitle" >