summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/engine/abstract3dcontroller_p.h
blob: 8f21c97f567d1434da7b07b24ab8db0707c708a8 (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
/****************************************************************************
**
** 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
**
****************************************************************************/

//
//  W A R N I N G
//  -------------
//
// This file is not part of the QtDataVis3D 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 "datavis3dglobal_p.h"
#include "theme_p.h"
#include "qabstractaxis.h"
#include "drawer_p.h"

class QFont;

QT_DATAVIS3D_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;

    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)
    {
    }
};

class QT_DATAVIS3D_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;

protected:
    CameraHelper *m_cameraHelper;
    int m_zoomLevel;
    QAbstractAxis *m_axisX;
    QAbstractAxis *m_axisY;
    QAbstractAxis *m_axisZ;
    Abstract3DRenderer *m_renderer;
    bool m_isDataDirty;

    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 void setAxisX(QAbstractAxis *axis);
    virtual QAbstractAxis *axisX();
    virtual void setAxisY(QAbstractAxis *axis);
    virtual QAbstractAxis *axisY();
    virtual void setAxisZ(QAbstractAxis *axis);
    virtual QAbstractAxis *axisZ();

    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(QColor baseColor, QColor heightColor, 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();

    // Font size adjustment
    virtual void setFontSize(float fontsize);
    virtual float fontSize();

    // 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();

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

    virtual void handleAxisTitleChangedBySender(QObject *sender, const QString &title);
    virtual void handleAxisLabelsChangedBySender(QObject *sender);
    virtual void handleAxisRangeChangedBySender(QObject *sender, qreal min, qreal max);
    virtual void handleAxisSegmentCountChangedBySender(QObject *sender, int count);
    virtual void handleAxisSubSegmentCountChangedBySender(QObject *sender, int count);
    virtual void handleAxisAutoAdjustRangeChangedInOrientation(QAbstractAxis::AxisOrientation orientation, bool autoAdjust) = 0;

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);

signals:
    void boundingRectChanged(QRect boundingRect);
    void sizeChanged(QRect boundingRect);
    void positionChanged(QRect boundingRect);
    void zoomLevelChanged(int zoomLevel);
    void themeChanged(Theme theme);
    void fontChanged(QFont font); // TODO should be handled via axis?? What about font for selection label?
    void shadowQualityChanged(QDataVis::ShadowQuality quality);
    void labelTransparencyChanged(QDataVis::LabelTransparency transparency);
    void axisTypeChanged(QAbstractAxis::AxisOrientation orientation, QAbstractAxis::AxisType type);
    void axisTitleChanged(QAbstractAxis::AxisOrientation orientation, QString title);
    void axisLabelsChanged(QAbstractAxis::AxisOrientation orientation, QStringList labels);
    void axisRangeChanged(QAbstractAxis::AxisOrientation orientation, qreal min, qreal max);
    void axisSegmentCountChanged(QAbstractAxis::AxisOrientation orientation, int count);
    void axisSubSegmentCountChanged(QAbstractAxis::AxisOrientation orientation, int count);
    void selectionModeChanged(QDataVis::SelectionMode mode);
    void backgroundEnabledChanged(bool enable);
    void gridEnabledChanged(bool enable); // TODO: Should be handled via axes?
    void meshFileNameChanged(QString fileName);

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

QT_DATAVIS3D_END_NAMESPACE

#endif // CONTROLLER3DBASE_H