Skip to content

Commit

Permalink
Fix Qt 5.15 API deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Nov 5, 2023
1 parent ff4e004 commit 4129ee4
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/rviz/add_display_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct PluginGroup
QMap<QString, Info> plugins;
};

void getPluginGroups(const QMap<QString, QString>& datatype_plugins,
void getPluginGroups(const QMultiMap<QString, QString>& datatype_plugins,
QList<PluginGroup>* groups,
QList<ros::master::TopicInfo>* unvisualizable)
{
Expand Down Expand Up @@ -563,7 +563,7 @@ void TopicDisplayWidget::findPlugins(DisplayFactory* factory)
Q_FOREACH (QString topic_type, topic_types)
{
// ROS_INFO("Type: %s", topic_type.toStdString().c_str());
datatype_plugins_.insertMulti(topic_type, lookup_name);
datatype_plugins_.insert(topic_type, lookup_name);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/add_display_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private Q_SLOTS:

// Map from ROS topic type to all displays that can visualize it.
// One key may have multiple values.
QMap<QString, QString> datatype_plugins_;
QMultiMap<QString, QString> datatype_plugins_;
};

/** A combo box that can be inserted into a QTreeWidgetItem
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/default_plugin/tools/interaction_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int InteractionTool::processMouseEvent(ViewportMouseEvent& event)
bool need_selection_update = context_->getFrameCount() > last_selection_frame_count_;

// We are dragging if a button was down and is still down
Qt::MouseButtons buttons = event.buttons_down & (Qt::LeftButton | Qt::RightButton | Qt::MidButton);
Qt::MouseButtons buttons = event.buttons_down & (Qt::LeftButton | Qt::RightButton | Qt::MiddleButton);
if (event.type == QEvent::MouseButtonPress)
buttons &= ~event.acting_button;
bool dragging = buttons != 0;
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/panel_dock_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PanelDockWidget::PanelDockWidget(const QString& name)
QWidget* title_bar = new QWidget(this);

QPalette pal(palette());
pal.setColor(QPalette::Background, QApplication::palette().color(QPalette::Mid));
pal.setColor(QPalette::Window, QApplication::palette().color(QPalette::Mid));
title_bar->setAutoFillBackground(true);
title_bar->setPalette(pal);
title_bar->setContentsMargins(0, 0, 0, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/rviz/properties/editable_enum_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ QWidget* EditableEnumProperty::createEditor(QWidget* parent, const QStyleOptionV
cb->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
cb->addItems(strings_);
cb->setEditText(getValue().toString());
QObject::connect(cb, qOverload<const QString&>(&QComboBox::currentIndexChanged), this,
&EditableEnumProperty::setString);
QObject::connect(cb, qOverload<int>(&QComboBox::currentIndexChanged), this,
[this, cb](int idx) { setString(cb->itemText(idx)); });

// TODO: need to better handle string value which is not in list.
return cb;
Expand Down
4 changes: 2 additions & 2 deletions src/rviz/properties/enum_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ QWidget* EnumProperty::createEditor(QWidget* parent, const QStyleOptionViewItem&
ComboBox* cb = new ComboBox(parent);
cb->addItems(strings_);
cb->setCurrentIndex(strings_.indexOf(getValue().toString()));
QObject::connect(cb, qOverload<const QString&>(&QComboBox::currentIndexChanged), this,
&EnumProperty::setString);
QObject::connect(cb, qOverload<int>(&QComboBox::currentIndexChanged), this,
[this, cb](int idx) { setString(cb->itemText(idx)); });

// TODO: need to better handle string value which is not in list.
return cb;
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/properties/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void Property::setParent(Property* new_parent)

QVariant Property::getViewData(int column, int role) const
{
if (role == Qt::TextColorRole && parent_ && parent_->getDisableChildren())
if (role == Qt::ForegroundRole && parent_ && parent_->getDisableChildren())
return QApplication::palette().brush(QPalette::Disabled, QPalette::Text);

switch (column)
Expand Down
5 changes: 5 additions & 0 deletions src/rviz/render_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ void RenderPanel::wheelEvent(QWheelEvent* event)
int last_x = mouse_x_;
int last_y = mouse_y_;

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
mouse_x_ = event->position().x();
mouse_y_ = event->position().y();
#else
mouse_x_ = event->x();
mouse_y_ = event->y();
#endif

if (context_)
{
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/view_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ QString ViewController::formatClassId(const QString& class_id)

QVariant ViewController::getViewData(int column, int role) const
{
if (role == Qt::TextColorRole)
if (role == Qt::ForegroundRole)
return QVariant();

if (is_active_)
Expand Down
13 changes: 9 additions & 4 deletions src/rviz/viewport_mouse_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ class ViewportMouseEvent
: panel(p)
, viewport(vp)
, type(e->type())
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
, x(e->position().x())
, y(e->position().y())
#else
, x(e->x())
, y(e->y())
, wheel_delta(e->delta())
#endif
, wheel_delta(e->angleDelta().y())
, acting_button(Qt::NoButton)
, buttons_down(e->buttons())
, modifiers(e->modifiers())
Expand All @@ -93,7 +98,7 @@ class ViewportMouseEvent
}
bool middle()
{
return buttons_down & Qt::MidButton;
return buttons_down & Qt::MiddleButton;
}
bool right()
{
Expand Down Expand Up @@ -121,7 +126,7 @@ class ViewportMouseEvent
}
bool middleUp()
{
return type == QEvent::MouseButtonRelease && acting_button == Qt::MidButton;
return type == QEvent::MouseButtonRelease && acting_button == Qt::MiddleButton;
}
bool rightUp()
{
Expand All @@ -134,7 +139,7 @@ class ViewportMouseEvent
}
bool middleDown()
{
return type == QEvent::MouseButtonPress && acting_button == Qt::MidButton;
return type == QEvent::MouseButtonPress && acting_button == Qt::MiddleButton;
}
bool rightDown()
{
Expand Down
8 changes: 4 additions & 4 deletions src/test/render_points_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void MyFrame::mousePressEvent(QMouseEvent* event)
case Qt::LeftButton:
left_mouse_down_ = true;
break;
case Qt::MidButton:
case Qt::MiddleButton:
middle_mouse_down_ = true;
break;
case Qt::RightButton:
Expand All @@ -211,7 +211,7 @@ void MyFrame::mouseReleaseEvent(QMouseEvent* event)
case Qt::LeftButton:
left_mouse_down_ = false;
break;
case Qt::MidButton:
case Qt::MiddleButton:
middle_mouse_down_ = false;
break;
case Qt::RightButton:
Expand Down Expand Up @@ -250,13 +250,13 @@ void MyFrame::mouseMoveEvent(QMouseEvent* event)

void MyFrame::wheelEvent(QWheelEvent* event)
{
if (event->delta() != 0)
if (event->angleDelta().y() != 0)
{
bool cmd = event->modifiers() & Qt::ControlModifier;
bool shift = event->modifiers() & Qt::ShiftModifier;
bool alt = event->modifiers() & Qt::AltModifier;

camera_->scrollWheel(event->delta(), cmd, alt, shift);
camera_->scrollWheel(event->angleDelta().y(), cmd, alt, shift);
}
}

Expand Down

0 comments on commit 4129ee4

Please sign in to comment.