summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/data/qmapdataproxy.cpp
blob: 1e0db088f4a3930a7b94437bf5c17d8c1820b14f (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
/****************************************************************************
**
** 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 "qmapdataproxy.h"
#include "qmapdataproxy_p.h"

QT_DATAVIS3D_BEGIN_NAMESPACE

/*!
 * \class QMapDataProxy
 * \inmodule QtDataVis3D
 * \brief Proxy class for Q3DMaps.
 * \since 1.0.0
 *
 * QMapDataProxy handles adding, inserting, changing and removing data.
 *
 * QMapDataProxy takes ownership of all QMapDataArrays and QMapDataItems passed to it.
 */

/*!
 * Constructs QMapDataProxy with the given \a parent.
 */
QMapDataProxy::QMapDataProxy(QObject *parent) :
    QAbstractDataProxy(new QMapDataProxyPrivate(this), parent)
{
}

/*!
 * \internal
 */
QMapDataProxy::QMapDataProxy(QMapDataProxyPrivate *d, QObject *parent) :
    QAbstractDataProxy(d, parent)
{
}

/*!
 * Destroys QMapDataProxy.
 */
QMapDataProxy::~QMapDataProxy()
{
}

/*!
 * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer
 * to further modify data after QMapDataProxy assumes ownership of it, as such modifications will
 * not trigger proper signals.
 * Passing null array clears all data.
 */
void QMapDataProxy::resetArray(QMapDataArray *newArray)
{
    if (dptr()->resetArray(newArray))
        emit arrayReset();
}

/*!
 * \return item count in the array.
 */
int QMapDataProxy::itemCount() const
{
    return dptrc()->m_dataArray.size();
}

/*!
 * \return pointer to the data array.
 */
const QMapDataArray *QMapDataProxy::array() const
{
    return &dptrc()->m_dataArray;
}

/*!
 * \return pointer to the item at \a index. It is guaranteed to be valid only until next call
 * that modifies data.
 */
const QMapDataItem *QMapDataProxy::itemAt(int index) const
{
    return &dptrc()->m_dataArray.at(index);
}

/*!
 * \internal
 */
QMapDataProxyPrivate *QMapDataProxy::dptr()
{
    return static_cast<QMapDataProxyPrivate *>(d_ptr.data());
}

/*!
 * \internal
 */
const QMapDataProxyPrivate *QMapDataProxy::dptrc() const
{
    return static_cast<const QMapDataProxyPrivate *>(d_ptr.data());
}

/*!
 * \fn void QMapDataProxy::arrayReset()
 *
 * Emitted when data array is reset.
 */

/*!
 * \fn void QMapDataProxy::itemsAdded(int startIndex, int count)
 *
 * Emitted when items have been added. Provides \a startIndex and \a count of items added.
 */

/*!
 * \fn void QMapDataProxy::itemsChanged(int startIndex, int count)
 *
 * Emitted when items have changed. Provides \a startIndex and \a count of changed items.
 */

/*!
 * \fn void QMapDataProxy::itemsRemoved(int startIndex, int count)
 *
 * Emitted when items have been removed. Provides \a startIndex and \a count of items removed.
 * Index may be over current array size if removed from end.
 */

/*!
 * \fn void QMapDataProxy::itemsInserted(int startIndex, int count)
 *
 * Emitted when items have been inserted. Provides \a startIndex and \a count of inserted items.
 */

// QBarDataProxyPrivate

QMapDataProxyPrivate::QMapDataProxyPrivate(QMapDataProxy *q)
    : QAbstractDataProxyPrivate(q, QAbstractDataProxy::DataTypeMap)
{
}

QMapDataProxyPrivate::~QMapDataProxyPrivate()
{
    m_dataArray.clear();
}

bool QMapDataProxyPrivate::resetArray(QMapDataArray *newArray)
{
    if (!m_dataArray.size() && (!newArray || !newArray->size()))
        return false;

    m_dataArray.clear();

    if (newArray) {
        m_dataArray = *newArray;
        delete newArray;
    }

    return true;
}

QPair<GLfloat, GLfloat> QMapDataProxyPrivate::limitValues()
{
    QPair<GLfloat, GLfloat> limits = qMakePair(0.0f, 0.0f);
    for (int i = 0; i < m_dataArray.size(); i++) {
        const QMapDataItem &item = m_dataArray.at(i);
        qreal itemValue = item.value();
        if (limits.second < itemValue)
            limits.second = itemValue;
        if (limits.first > itemValue)
            limits.first = itemValue;
    }
    return limits;
}

QT_DATAVIS3D_END_NAMESPACE