diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-01-14 11:17:47 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-02-16 16:21:15 +0000 |
commit | 515e802ae20c045e5c47b400ee6ef6e92349c978 (patch) | |
tree | f9f4be4c9e360611b5823ef28c2cb293733aee42 /examples/widgets/itemviews | |
parent | 3d835eb62e70435fe32318441dc7c10aba3a6fba (diff) |
Use C++ <cmath> instead of <math.h>
Including math.h can pollute the default namespace, and break
some compilers if cmath versions of the method are declared as using.
Switching to C++ math functions also greatly simplifies handling of
float qreal as C++ automatically chooses the right method.
[ChangeLog][QtCore][QtMath] qmath.h no longer includes math.h, so any
sources depending on that indirect inclusion may fail to build.
Change-Id: I4d0e331dafba354ec05dc5052e61ef4ff8d387fe
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Diffstat (limited to 'examples/widgets/itemviews')
-rw-r--r-- | examples/widgets/itemviews/chart/pieview.cpp | 6 | ||||
-rw-r--r-- | examples/widgets/itemviews/stardelegate/starrating.cpp | 6 | ||||
-rw-r--r-- | examples/widgets/itemviews/storageview/storagemodel.cpp | 5 |
3 files changed, 9 insertions, 8 deletions
diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp index 6e55afa5f0..9793e7d89b 100644 --- a/examples/widgets/itemviews/chart/pieview.cpp +++ b/examples/widgets/itemviews/chart/pieview.cpp @@ -38,8 +38,8 @@ ** ****************************************************************************/ -#include <math.h> #include <QtWidgets> +#include <cmath> #ifndef M_PI #define M_PI 3.1415927 @@ -109,13 +109,13 @@ QModelIndex PieView::indexAt(const QPoint &point) const double cy = totalSize / 2 - wy; // positive cy for items above the center // Determine the distance from the center point of the pie chart. - double d = pow(pow(cx, 2) + pow(cy, 2), 0.5); + double d = std::sqrt(std::pow(cx, 2) + std::pow(cy, 2)); if (d == 0 || d > pieSize / 2) return QModelIndex(); // Determine the angle of the point. - double angle = (180 / M_PI) * acos(cx / d); + double angle = (180 / M_PI) * std::acos(cx / d); if (cy < 0) angle = 360 - angle; diff --git a/examples/widgets/itemviews/stardelegate/starrating.cpp b/examples/widgets/itemviews/stardelegate/starrating.cpp index af67ae11da..568666f93a 100644 --- a/examples/widgets/itemviews/stardelegate/starrating.cpp +++ b/examples/widgets/itemviews/stardelegate/starrating.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ #include <QtWidgets> -#include <math.h> +#include <cmath> #include "starrating.h" @@ -53,8 +53,8 @@ StarRating::StarRating(int starCount, int maxStarCount) starPolygon << QPointF(1.0, 0.5); for (int i = 1; i < 5; ++i) - starPolygon << QPointF(0.5 + 0.5 * cos(0.8 * i * 3.14), - 0.5 + 0.5 * sin(0.8 * i * 3.14)); + starPolygon << QPointF(0.5 + 0.5 * std::cos(0.8 * i * 3.14), + 0.5 + 0.5 * std::sin(0.8 * i * 3.14)); diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4) << QPointF(0.6, 0.5) << QPointF(0.5, 0.6) diff --git a/examples/widgets/itemviews/storageview/storagemodel.cpp b/examples/widgets/itemviews/storageview/storagemodel.cpp index d70f53ce89..9f8d229c77 100644 --- a/examples/widgets/itemviews/storageview/storagemodel.cpp +++ b/examples/widgets/itemviews/storageview/storagemodel.cpp @@ -43,6 +43,7 @@ #include <QDir> #include <qmath.h> +#include <cmath> static QString sizeToString(qint64 size) { @@ -51,11 +52,11 @@ static QString sizeToString(qint64 size) if (size <= 0) return StorageModel::tr("0 b"); - double power = log((double)size)/log(1024.0); + double power = std::log((double)size)/std::log(1024.0); int intPower = (int)power; intPower = intPower >= 8 ? 8 - 1 : intPower; - double normSize = size / pow(1024.0, intPower); + double normSize = size / std::pow(1024.0, intPower); //: this should expand to "1.23 GB" return StorageModel::tr("%1 %2").arg(normSize, 0, 'f', intPower > 0 ? 2 : 0).arg(strings[intPower]); } |