Remove usages of deprecated APIs (part 2)

Replace the uses of deprecated APIs listed below, while keeping in mind
that compatibility with Qt 5.12 (the latest LTS) must be kept. This
means that the new alternatives must be used only when compiling with
Qt versions where the replacement is available.

Replaced:
  QLineF::intersect() -> QLine::intersects() (since 5.14)
  QComboBox::activated() -> QComboBox::textActivated() (since 5.14)
  QWheelEvent::pos() -> QWheelEvent::position() (since 5.14)
  QList::swap() -> QList::swapItemsAt() (since 5.13)

Task-number: QTBUG-76491
Change-Id: I62adc4f0826607b0156bf4bc5648ffb0e41cd895
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Sona Kurazyan
2019-08-29 14:41:14 +02:00
parent d39d26a54f
commit 6f4aa0458c
8 changed files with 53 additions and 2 deletions

View File

@@ -58,7 +58,11 @@ bool GeometryUtilities::intersect(const QPolygonF &polygon, const QLineF &line,
{ {
for (int i = 0; i <= polygon.size() - 2; ++i) { for (int i = 0; i <= polygon.size() - 2; ++i) {
QLineF polygonLine(polygon.at(i), polygon.at(i+1)); QLineF polygonLine(polygon.at(i), polygon.at(i+1));
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QLineF::IntersectType intersectionType = polygonLine.intersect(line, intersectionPoint); QLineF::IntersectType intersectionType = polygonLine.intersect(line, intersectionPoint);
#else
QLineF::IntersectType intersectionType = polygonLine.intersects(line, intersectionPoint);
#endif
if (intersectionType == QLineF::BoundedIntersection) { if (intersectionType == QLineF::BoundedIntersection) {
if (intersectionLine) if (intersectionLine)
*intersectionLine = polygonLine; *intersectionLine = polygonLine;

View File

@@ -352,8 +352,13 @@ void PropertiesView::MView::visitMElement(const MElement *element)
m_stereotypeComboBox->addItems(m_propertiesView->stereotypeController()->knownStereotypes(m_stereotypeElement)); m_stereotypeComboBox->addItems(m_propertiesView->stereotypeController()->knownStereotypes(m_stereotypeElement));
connect(m_stereotypeComboBox->lineEdit(), &QLineEdit::textEdited, connect(m_stereotypeComboBox->lineEdit(), &QLineEdit::textEdited,
this, &PropertiesView::MView::onStereotypesChanged); this, &PropertiesView::MView::onStereotypesChanged);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
connect(m_stereotypeComboBox, QOverload<const QString &>::of(&QComboBox::activated), connect(m_stereotypeComboBox, QOverload<const QString &>::of(&QComboBox::activated),
this, &PropertiesView::MView::onStereotypesChanged); this, &PropertiesView::MView::onStereotypesChanged);
#else
connect(m_stereotypeComboBox, &QComboBox::textActivated,
this, &PropertiesView::MView::onStereotypesChanged);
#endif
} }
if (!m_stereotypeComboBox->hasFocus()) { if (!m_stereotypeComboBox->hasFocus()) {
QList<QString> stereotypeList; QList<QString> stereotypeList;

View File

@@ -209,8 +209,13 @@ void TimelineRenderer::wheelEvent(QWheelEvent *event)
int degrees = (event->angleDelta().x() + event->angleDelta().y()) / 8; int degrees = (event->angleDelta().x() + event->angleDelta().y()) / 8;
const qint64 circle = 360; const qint64 circle = 360;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
qint64 mouseTime = event->pos().x() * zoom->windowDuration() / width() + qint64 mouseTime = event->pos().x() * zoom->windowDuration() / width() +
zoom->windowStart(); zoom->windowStart();
#else
qint64 mouseTime = event->position().toPoint().x() * zoom->windowDuration() / width() +
zoom->windowStart();
#endif
qint64 beforeMouse = (mouseTime - zoom->rangeStart()) * (circle - degrees) / circle; qint64 beforeMouse = (mouseTime - zoom->rangeStart()) * (circle - degrees) / circle;
qint64 afterMouse = (zoom->rangeEnd() - mouseTime) * (circle - degrees) / circle; qint64 afterMouse = (zoom->rangeEnd() - mouseTime) * (circle - degrees) / circle;

View File

@@ -71,10 +71,15 @@ void EditorDiagramView::wheelEvent(QWheelEvent *wheelEvent)
{ {
if (wheelEvent->modifiers() == Qt::ControlModifier) { if (wheelEvent->modifiers() == Qt::ControlModifier) {
int degree = wheelEvent->angleDelta().y() / 8; int degree = wheelEvent->angleDelta().y() / 8;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QPoint zoomOrigin = wheelEvent->pos();
#else
QPoint zoomOrigin = wheelEvent->position().toPoint();
#endif
if (degree > 0) if (degree > 0)
emit zoomIn(wheelEvent->pos()); emit zoomIn(zoomOrigin);
else if (degree < 0) else if (degree < 0)
emit zoomOut(wheelEvent->pos()); emit zoomOut(zoomOrigin);
} }
} }

View File

@@ -90,7 +90,11 @@ QWidget *ChangeStyleWidgetAction::createWidget(QWidget *parent)
}); });
connect(comboBox, connect(comboBox,
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QOverload<const QString &>::of(&QComboBox::activated), QOverload<const QString &>::of(&QComboBox::activated),
#else
&QComboBox::textActivated,
#endif
this, this,
[this](const QString &style) { [this](const QString &style) {

View File

@@ -80,7 +80,11 @@ void NavigatorGraphicsView::wheelEvent(QWheelEvent *event)
else else
emit zoomOut(); emit zoomOut();
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
emit moveMainViewTo(mapToScene(event->pos())); emit moveMainViewTo(mapToScene(event->pos()));
#else
emit moveMainViewTo(mapToScene(event->position().toPoint()));
#endif
} else } else
QGraphicsView::wheelEvent(event); QGraphicsView::wheelEvent(event);
} }

View File

@@ -224,7 +224,11 @@ void layout(const QList<QGraphicsItem*> &items)
firstItem = initialItem->outputTransitions().constFirst()->connectedItem(initialItem); firstItem = initialItem->outputTransitions().constFirst()->connectedItem(initialItem);
int index = childItems.indexOf(firstItem); int index = childItems.indexOf(firstItem);
if (index > 0) if (index > 0)
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
childItems.swap(index, 0); childItems.swap(index, 0);
#else
childItems.swapItemsAt(index, 0);
#endif
} }
// Search final-item // Search final-item

View File

@@ -306,11 +306,19 @@ void TransitionItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
QPointF intersPoint; QPointF intersPoint;
QLineF line2(p, p + QPointF(SELECTION_DISTANCE, SELECTION_DISTANCE)); QLineF line2(p, p + QPointF(SELECTION_DISTANCE, SELECTION_DISTANCE));
line2.setAngle(line.angle() + 90); line2.setAngle(line.angle() + 90);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
if (line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection) if (line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection)
#else
if (line.intersects(line2, &intersPoint) == QLineF::BoundedIntersection)
#endif
sel = true; sel = true;
else { else {
line2.setAngle(line.angle() - 90); line2.setAngle(line.angle() - 90);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
sel = line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection; sel = line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection;
#else
sel = line.intersects(line2, &intersPoint) == QLineF::BoundedIntersection;
#endif
} }
if (sel) if (sel)
@@ -797,7 +805,11 @@ QPointF TransitionItem::findIntersectionPoint(ConnectableItem *item, const QLine
for (int i = 1; i < itemPolygon.count(); ++i) { for (int i = 1; i < itemPolygon.count(); ++i) {
p2 = itemPolygon.at(i) + item->scenePos(); p2 = itemPolygon.at(i) + item->scenePos();
checkLine = QLineF(p1, p2); checkLine = QLineF(p1, p2);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
if (checkLine.intersect(line, &intersectPoint) == QLineF::BoundedIntersection) if (checkLine.intersect(line, &intersectPoint) == QLineF::BoundedIntersection)
#else
if (checkLine.intersects(line, &intersectPoint) == QLineF::BoundedIntersection)
#endif
return intersectPoint; return intersectPoint;
p1 = p2; p1 = p2;
} }
@@ -1083,11 +1095,19 @@ bool TransitionItem::containsScenePoint(const QPointF &p) const
QPointF intersPoint; QPointF intersPoint;
QLineF line2(pp, pp + QPointF(SELECTION_DISTANCE, SELECTION_DISTANCE)); QLineF line2(pp, pp + QPointF(SELECTION_DISTANCE, SELECTION_DISTANCE));
line2.setAngle(line.angle() + 90); line2.setAngle(line.angle() + 90);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
if (line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection) { if (line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection) {
#else
if (line.intersects(line2, &intersPoint) == QLineF::BoundedIntersection) {
#endif
return true; return true;
} else { } else {
line2.setAngle(line.angle() - 90); line2.setAngle(line.angle() - 90);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
if (line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection) if (line.intersect(line2, &intersPoint) == QLineF::BoundedIntersection)
#else
if (line.intersects(line2, &intersPoint) == QLineF::BoundedIntersection)
#endif
return true; return true;
} }
} }