summaryrefslogtreecommitdiffstats
path: root/src/datavis3dqml2/declarativemaps.cpp
blob: a3346a0a4becab4dbce02033f1d5620724e6c465 (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
/****************************************************************************
**
** 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 "declarativemaps_p.h"
#include "declarativemapsrenderer_p.h"
#include "qitemmodelmapdataproxy.h"

QT_DATAVIS3D_BEGIN_NAMESPACE

DeclarativeMaps::DeclarativeMaps(QQuickItem *parent)
    : QQuickItem(parent),
      m_shared(0),
      m_initializedSize(0, 0)
{
    setFlags(QQuickItem::ItemHasContents);
    setAcceptedMouseButtons(Qt::AllButtons);

    // TODO: These seem to have no effect; find a way to activate anti-aliasing
    setAntialiasing(true);
    setSmooth(true);
}

DeclarativeMaps::~DeclarativeMaps()
{
    delete m_shared;
}

void DeclarativeMaps::classBegin()
{
    //qDebug() << "classBegin";
}

void DeclarativeMaps::componentComplete()
{
    //qDebug() << "componentComplete";
}

QSGNode *DeclarativeMaps::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
    if (!m_shared) {
        m_shared = new Maps3DController(boundingRect().toRect());
        m_shared->setDataProxy(new QItemModelMapDataProxy);
        m_shared->initializeOpenGL();
    }

    // If old node exists and has right size, reuse it.
    if (oldNode && m_initializedSize == boundingRect().size().toSize()) {
        // Update bounding rectangle (that has same size as before).
        static_cast<DeclarativeMapsRenderer *>( oldNode )->setRect(boundingRect());
        return oldNode;
    }

    // Create a new render node when size changes or if there is no node yet
    m_initializedSize = boundingRect().size().toSize();

    // Delete old node
    if (oldNode)
        delete oldNode;

    // Create a new one and set it's bounding rectangle
    DeclarativeMapsRenderer *node = new DeclarativeMapsRenderer(window(), m_shared);
    node->setRect(boundingRect());
    m_shared->setBoundingRect(boundingRect().toRect());
    return node;
}

void DeclarativeMaps::setData(const QAbstractItemModel *data)
{
    static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->setItemModel(data);
}

const QAbstractItemModel *DeclarativeMaps::data() const
{
    return static_cast<const QItemModelMapDataProxy *>(m_shared->dataProxy())->itemModel();
}

void DeclarativeMaps::setBarSpecs(const QVector3D &thickness,
                                  Q3DMaps::AdjustmentDirection direction)
{
    m_shared->setBarSpecs(thickness, direction);
}

void DeclarativeMaps::setBarType(QDataVis::MeshStyle style, bool smooth)
{
    m_shared->setBarType(style, smooth);
}

void DeclarativeMaps::setMeshFileName(const QString &objFileName)
{
    m_shared->setMeshFileName(objFileName);
}

void DeclarativeMaps::setCameraPreset(QDataVis::CameraPreset preset)
{
    m_shared->setCameraPreset(preset);
}

void DeclarativeMaps::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance)
{
    m_shared->setCameraPosition(horizontal, vertical, distance);
}

void DeclarativeMaps::setTheme(QDataVis::ColorTheme theme)
{
    m_shared->setTheme(theme);
}

void DeclarativeMaps::setBarColor(const QColor &baseColor, const QColor &heightColor, bool uniform)
{
    m_shared->setBarColor(baseColor, heightColor, uniform);
}

void DeclarativeMaps::setAreaSpecs(const QRect &areaRect, const QImage &image)
{
    m_shared->setAreaSpecs(areaRect, image);
}

void DeclarativeMaps::setImage(const QImage &image)
{
    m_shared->setImage(image);
}

void DeclarativeMaps::setImage(const QString &imageUrl)
{
    m_shared->setImage(QImage(imageUrl));
}

void DeclarativeMaps::setSelectionMode(QDataVis::SelectionMode mode)
{
    m_shared->setSelectionMode(mode);
}

QDataVis::SelectionMode DeclarativeMaps::selectionMode()
{
    return m_shared->selectionMode();
}

void DeclarativeMaps::setFont(const QFont &font)
{
    m_shared->setFont(font);
}

QFont DeclarativeMaps::font()
{
    return m_shared->font();
}

void DeclarativeMaps::setLabelTransparency(QDataVis::LabelTransparency transparency)
{
    m_shared->setLabelTransparency(transparency);
}

QDataVis::LabelTransparency DeclarativeMaps::labelTransparency()
{
    return m_shared->labelTransparency();
}

void DeclarativeMaps::setShadowQuality(QDataVis::ShadowQuality quality)
{
    m_shared->setShadowQuality(quality);
}

QDataVis::ShadowQuality DeclarativeMaps::shadowQuality()
{
    return m_shared->shadowQuality();
}

QItemModelMapDataMapping *DeclarativeMaps::mapping() const
{
    return static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->activeMapping();
}

void DeclarativeMaps::setMapping(QItemModelMapDataMapping *mapping)
{
    static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->setActiveMapping(mapping);
}

void DeclarativeMaps::mouseDoubleClickEvent(QMouseEvent *event)
{
#if defined(Q_OS_ANDROID)
    m_shared->mouseDoubleClickEvent(event);
#endif
}

void DeclarativeMaps::touchEvent(QTouchEvent *event)
{
#if defined(Q_OS_ANDROID)
    m_shared->touchEvent(event);
    update();
#endif
}

void DeclarativeMaps::mousePressEvent(QMouseEvent *event)
{
    QPoint mousePos = event->pos();
    //mousePos.setY(height() - mousePos.y());
    m_shared->mousePressEvent(event, mousePos);
}

void DeclarativeMaps::mouseReleaseEvent(QMouseEvent *event)
{
    QPoint mousePos = event->pos();
    //mousePos.setY(height() - mousePos.y());
    m_shared->mouseReleaseEvent(event, mousePos);
}

void DeclarativeMaps::mouseMoveEvent(QMouseEvent *event)
{
    QPoint mousePos = event->pos();
    //mousePos.setY(height() - mousePos.y());
    m_shared->mouseMoveEvent(event, mousePos);
}

void DeclarativeMaps::wheelEvent(QWheelEvent *event)
{
    m_shared->wheelEvent(event);
}

QT_DATAVIS3D_END_NAMESPACE