summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/abstract3dcontroller_p.h
blob: 1419c0f4ca42bcc4b45386176ee6816fdda06334 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/****************************************************************************
**
** 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 QtDataVisualization 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
**
****************************************************************************/

//
//  W A R N I N G
//  -------------
//
// This file is not part of the QtDataVisualization API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.

#ifndef CONTROLLER3DBASE_H
#define CONTROLLER3DBASE_H

#include <QObject>

#include "datavisualizationglobal_p.h"
#include "theme_p.h"
#include "q3dabstractaxis.h"
#include "drawer_p.h"
#include "qabstract3dinputhandler.h"
#include "qabstractdataproxy.h"
#include "q3dscene.h"
#include "q3dbox.h"

class QFont;

QT_DATAVISUALIZATION_BEGIN_NAMESPACE

class CameraHelper;
class Abstract3DRenderer;

struct Abstract3DChangeBitField {
    bool positionChanged             : 1;
    bool zoomLevelChanged            : 1;
    bool themeChanged                : 1;
    bool fontChanged                 : 1;
    bool labelTransparencyChanged    : 1;
    bool boundingRectChanged         : 1;
    bool sizeChanged                 : 1;
    bool shadowQualityChanged        : 1;
    bool selectionModeChanged        : 1;
    bool objFileChanged              : 1;
    bool gridEnabledChanged          : 1;
    bool backgroundEnabledChanged    : 1;
    bool axisXTypeChanged            : 1;
    bool axisYTypeChanged            : 1;
    bool axisZTypeChanged            : 1;
    bool axisXTitleChanged           : 1;
    bool axisYTitleChanged           : 1;
    bool axisZTitleChanged           : 1;
    bool axisXLabelsChanged          : 1;
    bool axisYLabelsChanged          : 1;
    bool axisZLabelsChanged          : 1;
    bool axisXRangeChanged           : 1;
    bool axisYRangeChanged           : 1;
    bool axisZRangeChanged           : 1;
    bool axisXSegmentCountChanged    : 1;
    bool axisYSegmentCountChanged    : 1;
    bool axisZSegmentCountChanged    : 1;
    bool axisXSubSegmentCountChanged : 1;
    bool axisYSubSegmentCountChanged : 1;
    bool axisZSubSegmentCountChanged : 1;
    bool axisXLabelFormatChanged     : 1;
    bool axisYLabelFormatChanged     : 1;
    bool axisZLabelFormatChanged     : 1;

    Abstract3DChangeBitField() :
        positionChanged(true),
        zoomLevelChanged(true),
        themeChanged(true),
        fontChanged(true),
        labelTransparencyChanged(true),
        boundingRectChanged(true),
        sizeChanged(true),
        shadowQualityChanged(true),
        selectionModeChanged(true),
        objFileChanged(true),
        gridEnabledChanged(true),
        backgroundEnabledChanged(true),
        axisXTypeChanged(true),
        axisYTypeChanged(true),
        axisZTypeChanged(true),
        axisXTitleChanged(true),
        axisYTitleChanged(true),
        axisZTitleChanged(true),
        axisXLabelsChanged(true),
        axisYLabelsChanged(true),
        axisZLabelsChanged(true),
        axisXRangeChanged(true),
        axisYRangeChanged(true),
        axisZRangeChanged(true),
        axisXSegmentCountChanged(true),
        axisYSegmentCountChanged(true),
        axisZSegmentCountChanged(true),
        axisXSubSegmentCountChanged(true),
        axisYSubSegmentCountChanged(true),
        axisZSubSegmentCountChanged(true),
        axisXLabelFormatChanged(true),
        axisYLabelFormatChanged(true),
        axisZLabelFormatChanged(true)
    {
    }
};

class QT_DATAVISUALIZATION_EXPORT Abstract3DController : public QObject
{
    Q_OBJECT

public:
    enum SelectionType {
        SelectionNone = 0,
        SelectionItem,
        SelectionRow,
        SelectionColumn
    };

    enum MouseState {
        MouseNone = 0,
        MouseOnScene,
        MouseOnOverview,
        MouseOnZoom,
        MouseRotating,
        MouseOnPinch
    };

private:
    Abstract3DChangeBitField m_changeTracker;
    QRect m_boundingRect;
    GLfloat m_horizontalRotation;
    GLfloat m_verticalRotation;
    Theme m_theme;
    QFont m_font;
    QDataVis::SelectionMode m_selectionMode;
    QDataVis::ShadowQuality m_shadowQuality;
    QDataVis::LabelTransparency m_labelTransparency;
    bool m_isBackgroundEnabled;
    bool m_isGridEnabled;
    QString m_objFile;

    Q3DScene *m_scene;

protected:
    QList<QAbstract3DInputHandler *> m_inputHandlers; // List of all added input handlers
    QAbstract3DInputHandler *m_activeInputHandler;
    CameraHelper *m_cameraHelper;
    // Active axes
    Q3DAbstractAxis *m_axisX;
    Q3DAbstractAxis *m_axisY;
    Q3DAbstractAxis *m_axisZ;

    QList<Q3DAbstractAxis *> m_axes; // List of all added axes
    Abstract3DRenderer *m_renderer;
    bool m_isDataDirty;

    QAbstractDataProxy *m_data;
    QList<QAbstractDataProxy *> m_dataProxies;

    bool m_renderPending;

    explicit Abstract3DController(QRect boundRect, QObject *parent = 0);
    ~Abstract3DController();

public:

    inline bool isInitialized() { return (m_renderer != 0); }

    /**
     * @brief synchDataToRenderer Called on the render thread while main GUI thread is blocked before rendering.
     */
    virtual void synchDataToRenderer();

    virtual void render(const GLuint defaultFboHandle = 0);

    /**
     * @brief setRenderer Sets the renderer to be used. isInitialized returns true from this point onwards.
     * @param renderer Renderer to be used.
     */
    void setRenderer(Abstract3DRenderer *renderer);

    // Size
    virtual void setSize(const int width, const int height);
    virtual const QSize size();
    virtual const QRect boundingRect();
    virtual void setBoundingRect(const QRect boundingRect);
    virtual void setWidth(const int width);
    virtual int width();
    virtual void setHeight(const int height);
    virtual int height();
    virtual void setX(const int x);
    virtual int x();
    virtual void setY(const int y);
    virtual int y();

    virtual QRect mainViewport() const;
    virtual void setMainViewport(const QRect &mainViewport);

    virtual QRect sliceViewport() const;
    virtual void setSliceViewport(const QRect &sliceViewport);

    virtual void setAxisX(Q3DAbstractAxis *axis);
    virtual Q3DAbstractAxis *axisX();
    virtual void setAxisY(Q3DAbstractAxis *axis);
    virtual Q3DAbstractAxis *axisY();
    virtual void setAxisZ(Q3DAbstractAxis *axis);
    virtual Q3DAbstractAxis *axisZ();
    virtual void addAxis(Q3DAbstractAxis *axis);
    virtual void releaseAxis(Q3DAbstractAxis *axis);
    virtual QList<Q3DAbstractAxis *> axes() const; // Omits default axes

    virtual void addInputHandler(QAbstract3DInputHandler *inputHandler);
    virtual void releaseInputHandler(QAbstract3DInputHandler *inputHandler);
    virtual void setActiveInputHandler(QAbstract3DInputHandler *inputHandler);
    virtual QAbstract3DInputHandler *activeInputHandler();

    virtual QAbstractDataProxy *activeDataProxy() const;
    virtual void addDataProxy(QAbstractDataProxy *proxy);
    virtual void releaseDataProxy(QAbstractDataProxy *proxy);
    virtual QList<QAbstractDataProxy *> dataProxies() const;
    virtual void setActiveDataProxy(QAbstractDataProxy *proxy);

    virtual int zoomLevel();
    virtual void setZoomLevel(int zoomLevel);

    // Select preset camera placement
    virtual void setCameraPreset(QDataVis::CameraPreset preset);

    // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and
    // vertical (0...90) (or (-90...90) if there are negative values) angles and distance in
    // percentage (10...500))
    virtual void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100);

    // Set color if you don't want to use themes. Set uniform to false if you want the (height)
    // color to change from bottom to top
    virtual void setObjectColor(const QColor &baseColor, const QColor &heightColor,
                                const QColor &depthColor, bool uniform = true);

    // Set theme (bar colors, shaders, window color, background colors, light intensity and text
    // colors are affected)
    virtual void setColorTheme(QDataVis::ColorTheme colorTheme);
    virtual Theme theme();

    // Set font
    virtual void setFont(const QFont &font);
    virtual QFont font();

    // Selection mode
    virtual void setSelectionMode(QDataVis::SelectionMode mode);
    virtual QDataVis::SelectionMode selectionMode();

    // Adjust shadow quality
    virtual void setShadowQuality(QDataVis::ShadowQuality quality);
    virtual QDataVis::ShadowQuality shadowQuality();

    // Label transparency adjustment
    virtual void setLabelTransparency(QDataVis::LabelTransparency transparency);
    virtual QDataVis::LabelTransparency labelTransparency();

    // Enable or disable background mesh
    virtual void setBackgroundEnabled(bool enable);
    virtual bool backgroundEnabled();

    // Enable or disable background grid
    virtual void setGridEnabled(bool enable);
    virtual bool gridEnabled();

    // Query input state and position
    QDataVis::InputState inputState();
    QPoint inputPosition();

    // Enable or disable slicing mode
    bool isSlicingActive();
    void setSlicingActive(bool isSlicing);


    // override bar type with own mesh
    virtual void setMeshFileName(const QString &fileName);
    virtual QString meshFileName();

    Q3DScene *scene();

    virtual void mouseDoubleClickEvent(QMouseEvent *event);
    virtual void touchEvent(QTouchEvent *event);
    virtual void mousePressEvent(QMouseEvent *event, const QPoint &mousePos);
    virtual void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos);
    virtual void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos);
    virtual void wheelEvent(QWheelEvent *event);

    virtual void handleAxisTitleChangedBySender(QObject *sender);
    virtual void handleAxisLabelsChangedBySender(QObject *sender);
    virtual void handleAxisRangeChangedBySender(QObject *sender);
    virtual void handleAxisSegmentCountChangedBySender(QObject *sender);
    virtual void handleAxisSubSegmentCountChangedBySender(QObject *sender);
    virtual void handleAxisAutoAdjustRangeChangedInOrientation(
            Q3DAbstractAxis::AxisOrientation orientation, bool autoAdjust) = 0;
    virtual void handleAxisLabelFormatChangedBySender(QObject *sender);

public slots:
    void handleAxisTitleChanged(const QString &title);
    void handleAxisLabelsChanged();
    void handleAxisRangeChanged(qreal min, qreal max);
    void handleAxisSegmentCountChanged(int count);
    void handleAxisSubSegmentCountChanged(int count);
    void handleAxisAutoAdjustRangeChanged(bool autoAdjust);
    void handleAxisLabelFormatChanged(const QString &format);

signals:
    void shadowQualityChanged(QDataVis::ShadowQuality quality);
    void needRender();

protected:
    virtual Q3DAbstractAxis *createDefaultAxis(Q3DAbstractAxis::AxisOrientation orientation);
    Q3DValueAxis *createDefaultValueAxis();
    Q3DCategoryAxis *createDefaultCategoryAxis();
    void emitNeedRender();

private:
    void setAxisHelper(Q3DAbstractAxis::AxisOrientation orientation, Q3DAbstractAxis *axis,
                       Q3DAbstractAxis **axisPtr);
};

QT_DATAVISUALIZATION_END_NAMESPACE

#endif // CONTROLLER3DBASE_H