Skip to content

Commit

Permalink
Merge pull request #52 from rcsoccersim/fix/ubuntu22-warnings
Browse files Browse the repository at this point in the history
Fix compiler warnings caused by Qt updates.
  • Loading branch information
hidehisaakiyama authored Mar 23, 2024
2 parents 7ed529a + fd6cce3 commit eaf3964
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 47 deletions.
8 changes: 8 additions & 0 deletions src/config_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,11 @@ ConfigDialog::createPlayerSelectionControls()
M_player_choice->addItem( QString( "Right number: %1" ).arg( i ) );
}
M_player_choice->setCurrentIndex( 0 );
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int id_width = this->fontMetrics().horizontalAdvance( tr( "Right Number: 11" ) );
#else
int id_width = this->fontMetrics().width( tr( "Right Number: 11" ) );
#endif
M_player_choice->setMaximumWidth( id_width + 40 );
connect( M_player_choice, SIGNAL( currentIndexChanged( int ) ),
this, SLOT( choicePlayer( int ) ) );
Expand Down Expand Up @@ -1112,7 +1116,11 @@ ConfigDialog::createColorList()

createColorItems();

#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int font_width = this->fontMetrics().horizontalAdvance( tr( "Score Board Background" ) );
#else
int font_width = this->fontMetrics().width( tr( "Score Board Background" ) );
#endif
M_color_list_box->setMinimumWidth( font_width + 16 + 10 );
M_color_list_box->setMinimumHeight( 300 );
connect( M_color_list_box, SIGNAL( itemClicked( QListWidgetItem * ) ),
Expand Down
4 changes: 2 additions & 2 deletions src/field_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ FieldCanvas::mousePressEvent( QMouseEvent * event )

// selectPlayer( event->pos() );
}
else if ( event->button() == Qt::MidButton )
else if ( event->button() == Qt::MiddleButton )
{
M_mouse_state[1].pressed( event->pos() );
if ( M_mouse_state[1].isMenuFailed() )
Expand Down Expand Up @@ -189,7 +189,7 @@ FieldCanvas::mouseReleaseEvent( QMouseEvent * event )
{
M_mouse_state[0].released();
}
else if ( event->button() == Qt::MidButton )
else if ( event->button() == Qt::MiddleButton )
{
M_mouse_state[1].released();
}
Expand Down
12 changes: 8 additions & 4 deletions src/field_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,11 @@ FieldPainter::drawGrid( QPainter & painter ) const

const QFontMetrics metrics = painter.fontMetrics();
const int text_step_x = ( opt.showGridCoord()
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
? metrics.horizontalAdvance( QObject::tr( "-00.000" ) )
#else
? metrics.width( QObject::tr( "-00.000" ) )
#endif
: 100000 );
const int text_step_y = ( opt.showGridCoord()
? metrics.ascent()
Expand Down Expand Up @@ -627,7 +631,7 @@ FieldPainter::drawGrid( QPainter & painter ) const
int ix = opt.screenX( x );
if ( istep > text_step_x )
{
text.sprintf( "%.3f", x );
text.asprintf( "%.3f", x );
painter.drawText( ix, coord_x_print_y , text );
}
painter.drawLine( ix, max_iy, ix, min_iy );
Expand All @@ -640,7 +644,7 @@ FieldPainter::drawGrid( QPainter & painter ) const
int ix = opt.screenX( x );
if ( istep > text_step_x )
{
text.sprintf( "%.3f", x );
text.asprintf( "%.3f", x );
painter.drawText( ix, coord_x_print_y, text );
}
painter.drawLine( ix, max_iy, ix, min_iy );
Expand All @@ -654,7 +658,7 @@ FieldPainter::drawGrid( QPainter & painter ) const
int iy = opt.screenY( y );
if ( istep > text_step_y )
{
text.sprintf( "%.3f", y );
text.asprintf( "%.3f", y );
painter.drawText( min_ix, iy, text );
}
painter.drawLine( max_ix, iy, min_ix, iy );
Expand All @@ -667,7 +671,7 @@ FieldPainter::drawGrid( QPainter & painter ) const
int iy = opt.screenY( y );
if ( istep > text_step_y )
{
text.sprintf( "%.3f", y );
text.asprintf( "%.3f", y );
painter.drawText( min_ix, iy, text );
}
painter.drawLine( max_ix, iy, min_ix, iy );
Expand Down
17 changes: 14 additions & 3 deletions src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,14 @@ MainWindow::createStatusBar()
M_position_label = new QLabel( tr( "(0.0, 0.0)" ) );

min_width
= M_position_label->fontMetrics().width( tr( "(-60.0, -30.0)" ) )
=
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
M_position_label->fontMetrics().horizontalAdvance( tr( "(-60.0, -30.0)" ) )
#else
M_position_label->fontMetrics().width( tr( "(-60.0, -30.0)" ) )
#endif
+ 16;

M_position_label->setMinimumWidth( min_width );
M_position_label->setAlignment( Qt::AlignRight );

Expand Down Expand Up @@ -1306,7 +1312,12 @@ MainWindow::closeEvent( QCloseEvent * event )
void
MainWindow::wheelEvent( QWheelEvent * event )
{
if ( event->delta() < 0 )
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
const int delta = event->angleDelta().y();
#else
const int delta = event->delta();
#endif
if ( delta < 0 )
{
M_log_player_step_forward_act->trigger();
}
Expand Down Expand Up @@ -1450,7 +1461,7 @@ MainWindow::openGameLogFileImpl( const QString & filepath )
// progress_dialog.setCancelButton( 0 ); // no cancel button
// progress_dialog.setMinimumDuration( 0 ); // no duration

QTime timer;
QElapsedTimer timer;
timer.start();

rcss::rcg::Parser::Ptr parser = rcss::rcg::Parser::create( fin );
Expand Down
56 changes: 33 additions & 23 deletions src/player_type_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ PlayerTypeDialog::createModel()
updateData();
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
#define HORIZONTAL_ADVANCE horizontalAdvance
#else
#define HORIZONTAL_ADVANCE width
#endif

/*-------------------------------------------------------------------*/
/*!
Expand All @@ -204,37 +210,37 @@ PlayerTypeDialog::adjustSize()

int i = 0;
// id
M_item_view->setColumnWidth( i, metrics.width( " 1" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 1" ) + 4 ); ++i;
// size
M_item_view->setColumnWidth( i, metrics.width( " 0.00" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.00" ) + 4 ); ++i;
// speed max
M_item_view->setColumnWidth( i, metrics.width( "00.000 / 00.000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( "00.000 / 00.000" ) + 4 ); ++i;
// accel max
M_item_view->setColumnWidth( i, metrics.width( " 0.000000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.000000" ) + 4 ); ++i;
// dash power rate
M_item_view->setColumnWidth( i, metrics.width( " 0.000000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.000000" ) + 4 ); ++i;
// decay
M_item_view->setColumnWidth( i, metrics.width( " 0.0000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.0000" ) + 4 ); ++i;
// inertia
M_item_view->setColumnWidth( i, metrics.width( " 0.0000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.0000" ) + 4 ); ++i;
// kickable area
M_item_view->setColumnWidth( i, metrics.width( " 0.0000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.0000" ) + 4 ); ++i;
// kickable margin
M_item_view->setColumnWidth( i, metrics.width( " 0.0000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.0000" ) + 4 ); ++i;
// kick power rate
M_item_view->setColumnWidth( i, metrics.width( " 0.000000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.000000" ) + 4 ); ++i;
// kick rand
M_item_view->setColumnWidth( i, metrics.width( " 0.0000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.0000" ) + 4 ); ++i;
// catchable area
M_item_view->setColumnWidth( i, metrics.width( " 0.000 - 0.000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.000 - 0.000" ) + 4 ); ++i;
// stamina inc max
M_item_view->setColumnWidth( i, metrics.width( " 00.00" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 00.00" ) + 4 ); ++i;
// extra stamina
M_item_view->setColumnWidth( i, metrics.width( " 00.00" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 00.00" ) + 4 ); ++i;
// effort max - min
M_item_view->setColumnWidth( i, metrics.width( " 0.000 - 0.000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.000 - 0.000" ) + 4 ); ++i;
// foul detect probability
M_item_view->setColumnWidth( i, metrics.width( " 0.0000" ) + 4 ); ++i;
M_item_view->setColumnWidth( i, metrics.HORIZONTAL_ADVANCE( " 0.0000" ) + 4 ); ++i;

QRect rect = this->geometry();
QRect child_rect = this->childrenRect();
Expand Down Expand Up @@ -308,8 +314,8 @@ PlayerTypeDialog::updateData()
real_speed_max = param.player_speed_max_;
}

text.sprintf( "%5.3f / %5.3f",
real_speed_max, param.player_speed_max_ );
text.asprintf( "%5.3f / %5.3f",
real_speed_max, param.player_speed_max_ );
M_model->setData( M_model->index( row, i ), text ); ++i;

// accel max
Expand Down Expand Up @@ -357,7 +363,7 @@ PlayerTypeDialog::updateData()
+ std::pow( SP.catchable_area_l_ * ( 1.0 - ( param.catchable_area_l_stretch_ - 1.0 ) ), 2.0 ) );
double max_r = std::sqrt( std::pow( SP.catchable_area_w_ * 0.5, 2.0 )
+ std::pow( SP.catchable_area_l_ * param.catchable_area_l_stretch_, 2.0 ) );
text.sprintf( "%.3f - %.3f", min_r, max_r );
text.asprintf( "%.3f - %.3f", min_r, max_r );
M_model->setData( M_model->index( row, i ), text ); ++i;

// stamina inc max
Expand All @@ -371,8 +377,8 @@ PlayerTypeDialog::updateData()
M_model->setData( M_model->index( row, i ), text ); ++i;

// effort max - min
text.sprintf( "%.3f - %.3f",
param.effort_max_, param.effort_min_ );
text.asprintf( "%.3f - %.3f",
param.effort_max_, param.effort_min_ );
M_model->setData( M_model->index( row, i ), text ); ++i;

// foul detect probability
Expand Down Expand Up @@ -403,8 +409,12 @@ PlayerTypeDialog::showEvent( QShowEvent * event )
void
PlayerTypeDialog::wheelEvent( QWheelEvent * event )
{

if ( event->delta() < 0 )
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
const int delta = event->angleDelta().y();
#else
const int delta = event->delta();
#endif
if ( delta < 0 )
{
this->setWindowOpacity( std::max( 0.1, this->windowOpacity() - 0.05 ) );
}
Expand Down
30 changes: 15 additions & 15 deletions src/score_board_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ ScoreBoardPainter::draw( QPainter & painter )

if ( ! show_pen_score )
{
main_buf.sprintf( " %10s %d:%d %-10s %19s %6d ",
all_name_l.c_str(),
team_l.score_,
team_r.score_,
all_name_r.c_str(),
s_playmode_strings[pmode].c_str(),
current_time );
main_buf.asprintf( " %10s %d:%d %-10s %19s %6d ",
all_name_l.c_str(),
team_l.score_,
team_r.score_,
all_name_r.c_str(),
s_playmode_strings[pmode].c_str(),
current_time );
}
else
{
Expand Down Expand Up @@ -191,14 +191,14 @@ ScoreBoardPainter::draw( QPainter & painter )
}
}

main_buf.sprintf( " %10s %d:%d |%-5s:%-5s| %-10s %19s %6d",
all_name_l.c_str(),
team_l.score_, team_r.score_,
left_penalty.c_str(),
right_penalty.c_str(),
all_name_r.c_str(),
s_playmode_strings[pmode].c_str(),
current_time );
main_buf.asprintf( " %10s %d:%d |%-5s:%-5s| %-10s %19s %6d",
all_name_l.c_str(),
team_l.score_, team_r.score_,
left_penalty.c_str(),
right_penalty.c_str(),
all_name_r.c_str(),
s_playmode_strings[pmode].c_str(),
current_time );
}

//painter.setFont( M_font );
Expand Down

0 comments on commit eaf3964

Please sign in to comment.