/** Find match which corresponds to player 'a' and 'b' pair. */ Match& Group::match( Player a, Player b ) { for ( int i = 0; i < _matches.count(); i ++ ) { Match m = _matches.at( i ); if ( ( m.playerA() == a ) && ( m.playerB() == b ) ) { return _matches[ i ]; } else if ( ( m.playerB() == a ) && ( m.playerA() == b ) ) { _matches[i].swapPlayers(); return _matches[ i ]; } } // should never get here! qWarning() << "can't find match of " << a.name() << "and" << b.name(); return (* new Match( a, b ) ); }
/** removes player from players list and removes * all matches which he/she had participated */ void Group::removePlayer( Player player ) { _players.removeOne( player ); QMutableListIterator<Match> i( _matches ); while( i.hasNext() ) { Match m = i.next(); if ( ( m.playerA() == player ) || ( m.playerB() == player ) ) { i.remove(); } } }
MatchList Group::playedMatchList( Player p ) const { MatchList ml; for ( int i = 0; i < _matches.count(); i ++ ) { Match m = _matches.at( i ); if ( ( m.playerA() == p ) || ( m.playerB() == p ) ) { if ( m.played() ) { ml << m; } } } return ml; }
MatchResDialog::MatchResDialog( Match match, QWidget* parent ) : QDialog( parent ), _match( match ), _okButton( new QPushButton( tr( "Save" ) ) ) { setWindowTitle( tr( "Match score" ) ); _okButton->setEnabled( false ); QGridLayout* l = new QGridLayout( this ); QLabel* playerA = new QLabel( match.playerA().name(), this ); QLabel* playerB = new QLabel( match.playerB().name(), this ); l->addWidget( playerA, 0, 0, Qt::AlignJustify ); l->addWidget( playerB, 0, 1, Qt::AlignJustify ); unsigned int games = match.games_const().count(); for ( unsigned int i = 0; i < match.maxGames(); i ++ ) { QLineEdit* ballsA = new QLineEdit( this ); QLineEdit* ballsB = new QLineEdit( this ); if ( i < games ) { // this should be done before connecting of lineedits to textChanged // slot ballsA->setText( QString::number( match.games_const().at( i ).aBalls ) ); ballsB->setText( QString::number( match.games_const().at( i ).bBalls ) ); } connect( ballsA, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( ) ) ); connect( ballsB, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( ) ) ); l->addWidget( ballsA, i + 1, 0 ); l->addWidget( ballsB, i + 1, 1 ); } if ( games ) { textChanged(); } l->addWidget( _okButton, l->rowCount(), 0, 1, 2 ); connect( _okButton, SIGNAL( clicked() ), this, SLOT( okButtonClicked() ) ); }
MatchList Group::matchList( Player a, Player b ) const { MatchList ml; for ( int i = 0; i < _matches.count(); i ++ ) { Match m = _matches.at( i ); if ( m.participated( a ) && m.participated( b ) ) { if ( !( m.playerA() == a ) ) { // right player order required m.swapPlayers(); } ml << m; } } return ml; }
void Group::setMatchResults( Match m ) { setMatchResults( m.playerA(), m.playerB(), m.games_const() ); }