summaryrefslogtreecommitdiffstats
path: root/examples/widgets/graphicsview/boxes
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-01-14 11:17:47 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-16 16:21:15 +0000
commit515e802ae20c045e5c47b400ee6ef6e92349c978 (patch)
treef9f4be4c9e360611b5823ef28c2cb293733aee42 /examples/widgets/graphicsview/boxes
parent3d835eb62e70435fe32318441dc7c10aba3a6fba (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/graphicsview/boxes')
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.cpp10
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp5
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp7
3 files changed, 12 insertions, 10 deletions
diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp
index e368ddb307..5e142832e0 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.cpp
+++ b/examples/widgets/graphicsview/boxes/qtbox.cpp
@@ -242,7 +242,7 @@ void ItemBase::keyPressEvent(QKeyEvent *event)
void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
{
prepareGeometryChange();
- m_size = int(m_size * exp(-event->delta() / 600.0));
+ m_size = int(m_size * qExp(-event->delta() / 600.0));
if (m_size > MAX_ITEM_SIZE)
m_size = MAX_ITEM_SIZE;
else if (m_size < MIN_ITEM_SIZE)
@@ -404,10 +404,10 @@ void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
{
int dt = m_startTime.msecsTo(QTime::currentTime());
- qreal r0 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 3800) % 4000)));
- qreal r1 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 0) % 4000)));
- qreal r2 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 1800) % 4000)));
- qreal r3 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 2000) % 4000)));
+ qreal r0 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 3800) % 4000)));
+ qreal r1 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 0) % 4000)));
+ qreal r2 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 1800) % 4000)));
+ qreal r3 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 2000) % 4000)));
if (r0 > r1)
r0 = 0.0;
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
index 2ca061a43a..48bdcb9d93 100644
--- a/examples/widgets/graphicsview/boxes/scene.cpp
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -35,6 +35,7 @@
#include "scene.h"
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qvector3d.h>
+#include <cmath>
#include "3rdparty/fbm.h"
@@ -856,7 +857,7 @@ void Scene::renderCubemaps()
float angle = 2.0f * PI * i / m_cubemaps.size();
- center = m_trackBalls[1].rotation().rotatedVector(QVector3D(cos(angle), sin(angle), 0.0f));
+ center = m_trackBalls[1].rotation().rotatedVector(QVector3D(std::cos(angle), std::sin(angle), 0.0f));
for (int face = 0; face < 6; ++face) {
m_cubemaps[i]->begin(face);
@@ -910,7 +911,7 @@ void Scene::drawBackground(QPainter *painter, const QRectF &)
QMatrix4x4 view;
view.rotate(m_trackBalls[2].rotation());
- view(2, 3) -= 2.0f * exp(m_distExp / 1200.0f);
+ view(2, 3) -= 2.0f * std::exp(m_distExp / 1200.0f);
renderBoxes(view);
defaultStates();
diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp
index 2267636fa4..b1159b4989 100644
--- a/examples/widgets/graphicsview/boxes/trackball.cpp
+++ b/examples/widgets/graphicsview/boxes/trackball.cpp
@@ -33,6 +33,7 @@
#include "trackball.h"
#include "scene.h"
+#include <cmath>
//============================================================================//
// TrackBall //
@@ -94,19 +95,19 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
QVector3D lastPos3D = QVector3D(m_lastPos.x(), m_lastPos.y(), 0.0f);
float sqrZ = 1 - QVector3D::dotProduct(lastPos3D, lastPos3D);
if (sqrZ > 0)
- lastPos3D.setZ(sqrt(sqrZ));
+ lastPos3D.setZ(std::sqrt(sqrZ));
else
lastPos3D.normalize();
QVector3D currentPos3D = QVector3D(p.x(), p.y(), 0.0f);
sqrZ = 1 - QVector3D::dotProduct(currentPos3D, currentPos3D);
if (sqrZ > 0)
- currentPos3D.setZ(sqrt(sqrZ));
+ currentPos3D.setZ(std::sqrt(sqrZ));
else
currentPos3D.normalize();
m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
- float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
+ float angle = 180 / PI * std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis)));
m_angularVelocity = angle / msecs;
m_axis.normalize();