summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/engine/surface3dcontroller.cpp
blob: 8b7d38a7c5ed22f5072902a294525771eac8cf7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the QtDataVis3D module.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
**
****************************************************************************/

#include "surface3dcontroller_p.h"
#include "surface3drenderer_p.h"
#include "camerahelper_p.h"
#include "q3dabstractaxis_p.h"
#include "q3dvalueaxis_p.h"
#include "q3dcategoryaxis.h"
#include "qsurfacedataproxy_p.h"

#include <QMatrix4x4>
#include <QMouseEvent>

#include <QDebug>

QT_DATAVIS3D_BEGIN_NAMESPACE

Surface3DController::Surface3DController(QRect rect)
    : Abstract3DController(rect),
      m_renderer(0),
      m_smoothSurface(false),
      m_surfaceGrid(true)
{
    setActiveDataProxy(0);

    // Setting a null axis creates a new default axis according to orientation and chart type.
    // Note: These cannot be set in Abstract3DController constructor, as they will call virtual
    //       functions implemented by subclasses.
    setAxisX(0);
    setAxisY(0);
    setAxisZ(0);
    QObject::connect(m_activeInputHandler, &QAbstract3DInputHandler::selectionAtPoint,
                     this, &Surface3DController::handleSelectionAtPoint);
}

Surface3DController::~Surface3DController()
{
}

void Surface3DController::initializeOpenGL()
{
    // Initialization is called multiple times when Qt Quick components are used
    if (isInitialized())
        return;

    m_renderer = new Surface3DRenderer(this);
    setRenderer(m_renderer);
    synchDataToRenderer();
    emitNeedRender();
}

void Surface3DController::synchDataToRenderer()
{
    Abstract3DController::synchDataToRenderer();

    if (!isInitialized())
        return;

    // Notify changes to renderer
    if (m_isDataDirty) {
        m_renderer->updateDataModel(static_cast<QSurfaceDataProxy *>(m_data));
        m_isDataDirty = false;
    }
}

void Surface3DController::handleAxisAutoAdjustRangeChangedInOrientation(Q3DAbstractAxis::AxisOrientation orientation, bool autoAdjust)
{
    Q_UNUSED(orientation)
    Q_UNUSED(autoAdjust)

    // TODO: Implement!
}

void Surface3DController::setSmoothSurface(bool enable)
{
    m_smoothSurface = enable;
    emit smoothStatusChanged(m_smoothSurface);
    emitNeedRender();
}

bool Surface3DController::smoothSurface()
{
    return m_smoothSurface;
}

void Surface3DController::setSurfaceGrid(bool enable)
{
    m_surfaceGrid = enable;
    emit surfaceGridChanged(m_surfaceGrid);
    emitNeedRender();
}

bool Surface3DController::surfaceGrid()
{
    return m_surfaceGrid;
}

void Surface3DController::setActiveDataProxy(QAbstractDataProxy *proxy)
{
    // Setting null proxy indicates default proxy
    if (!proxy) {
        proxy = new QSurfaceDataProxy;
        proxy->d_ptr->setDefaultProxy(true);
    }

    Q_ASSERT(proxy->type() == QAbstractDataProxy::DataTypeSurface);

    Abstract3DController::setActiveDataProxy(proxy);

    QSurfaceDataProxy *surfaceDataProxy = static_cast<QSurfaceDataProxy *>(m_data);

    // TODO connections and handler for proxy changes
    QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::arrayReset,
                     this, &Surface3DController::handleArrayReset);
}

void Surface3DController::handleArrayReset()
{
    m_isDataDirty = true;
    emitNeedRender();
}

void Surface3DController::setSegmentCount(GLint segmentCount, GLfloat step, GLfloat minimum)
{
    m_segmentCount   = segmentCount;
    m_segmentStep    = step;
    m_segmentMinimum = minimum;

    emit segmentCountChanged(m_segmentCount, m_segmentStep, m_segmentMinimum);
    emitNeedRender();
}

void Surface3DController::setGradientColorAt(qreal pos, const QColor &color)
{
    Theme t = theme();
    t.m_surfaceGradient.setColorAt(pos, color);
    emitNeedRender();
}

void Surface3DController::handleSelectionAtPoint(const QPoint &point)
{
    emit leftMousePressed(point);
}

QT_DATAVIS3D_END_NAMESPACE