From 4aeade9cf544d0e2de7913fc8b7b28d2b8024a3e Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Tue, 20 Jul 2021 21:09:05 +0200 Subject: [PATCH] Add assignment operators to some classes The implicitly defined assignment operator for classes having custom defined copy constructor is deprecated. This patch adds explicit assignment operators. --- .../qtsolutions/segmentcontrol/qtsegmentcontrol.cpp | 10 ++++++++++ qwt/src/qwt_point_3d.h | 12 ++++++++++++ src/Core/Measures.h | 4 ++++ src/FileIO/LocationInterpolation.h | 1 + src/FileIO/RideFile.h | 10 ++++++++-- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/contrib/qtsolutions/segmentcontrol/qtsegmentcontrol.cpp b/contrib/qtsolutions/segmentcontrol/qtsegmentcontrol.cpp index fd9f74b45..128d39f18 100644 --- a/contrib/qtsolutions/segmentcontrol/qtsegmentcontrol.cpp +++ b/contrib/qtsolutions/segmentcontrol/qtsegmentcontrol.cpp @@ -49,6 +49,16 @@ public: : position(OnlyOneSegment), selectedPosition(NotAdjacent) { } QtStyleOptionSegmentControlSegment(const QtStyleOptionSegmentControlSegment &other) : QStyleOption(Version, Type) { *this = other; } + QtStyleOptionSegmentControlSegment& operator=(const QtStyleOptionSegmentControlSegment &other) + { + QStyleOption::operator=(other); + text = other.text; + icon = other.icon; + iconSize = other.iconSize; + position = other.position; + selectedPosition = other.selectedPosition; + return *this; + } protected: QtStyleOptionSegmentControlSegment(int version); diff --git a/qwt/src/qwt_point_3d.h b/qwt/src/qwt_point_3d.h index 5b0b40e89..9684bdc30 100644 --- a/qwt/src/qwt_point_3d.h +++ b/qwt/src/qwt_point_3d.h @@ -27,6 +27,7 @@ public: QwtPoint3D(); QwtPoint3D( double x, double y, double z ); QwtPoint3D( const QwtPoint3D & ); + QwtPoint3D& operator=( const QwtPoint3D & ); QwtPoint3D( const QPointF & ); bool isNull() const; @@ -90,6 +91,17 @@ inline QwtPoint3D::QwtPoint3D( const QwtPoint3D &other ): { } +/*! + Assignment operator. +*/ +inline QwtPoint3D& QwtPoint3D::operator=( const QwtPoint3D &other ) +{ + d_x = other.d_x; + d_y = other.d_y; + d_z = other.d_z; + return *this; +} + /*! Constructs a point with x and y coordinates from a 2D point, and a z coordinate of 0. diff --git a/src/Core/Measures.h b/src/Core/Measures.h index a853072b4..27d5d4826 100644 --- a/src/Core/Measures.h +++ b/src/Core/Measures.h @@ -41,11 +41,15 @@ public: for (int i = 0; iwhen = other.when; this->comment = other.comment; this->source = other.source; this->originalSource = other.originalSource; for (int i = 0; ivalues[i] = other.values[i]; + return *this; } ~Measure() {} diff --git a/src/FileIO/LocationInterpolation.h b/src/FileIO/LocationInterpolation.h index 4dc7dc2e2..bef8a9691 100644 --- a/src/FileIO/LocationInterpolation.h +++ b/src/FileIO/LocationInterpolation.h @@ -41,6 +41,7 @@ public: v3(double a, double b, double c) : m_t(a, b, c) {}; v3(const v3& o) : m_t(o.m_t) {} + v3& operator=(const v3& o) { m_t = o.m_t; return *this; } double x() const { return std::get<0>(m_t); } double y() const { return std::get<1>(m_t); } diff --git a/src/FileIO/RideFile.h b/src/FileIO/RideFile.h index fc4ddcbd7..f4cb45932 100644 --- a/src/FileIO/RideFile.h +++ b/src/FileIO/RideFile.h @@ -562,13 +562,17 @@ public: string[i]=""; } } - XDataPoint (const XDataPoint &other) { + XDataPoint(const XDataPoint &other) { + *this = other; + } + XDataPoint& operator=(const XDataPoint &other) { this->secs=other.secs; this->km=other.km; for(int i=0; inumber[i]= other.number[i]; this->string[i]= other.string[i]; } + return *this; } double secs, km; @@ -579,7 +583,8 @@ public: class XDataSeries { public: XDataSeries() {} - XDataSeries(XDataSeries &other) { + XDataSeries(const XDataSeries& other) { *this = other; } + XDataSeries& operator=(const XDataSeries &other) { name = other.name; valuename = other.valuename; unitname = other.unitname; @@ -589,6 +594,7 @@ public: foreach (XDataPoint *p, other.datapoints) { datapoints.push_back(new XDataPoint(*p)); } + return *this; } ~XDataSeries() { foreach(XDataPoint *p, datapoints) delete p; }