##// END OF EJS Templates
Add support for reversed axis when useOpenGL is true...
Andy Shaw -
r2863:15eed6371853
parent child
Show More
@@ -280,7 +280,7 bool ChartDataSet::attachAxis(QAbstractSeries *series,QAbstractAxis *axis)
280
280
281 series->d_ptr->initializeAxes();
281 series->d_ptr->initializeAxes();
282 axis->d_ptr->initializeDomain(domain);
282 axis->d_ptr->initializeDomain(domain);
283
283 connect(axis, &QAbstractAxis::reverseChanged, this, &ChartDataSet::reverseChanged);
284 foreach (AbstractDomain *blockedDomain, blockedDomains)
284 foreach (AbstractDomain *blockedDomain, blockedDomains)
285 blockedDomain->blockRangeSignals(false);
285 blockedDomain->blockRangeSignals(false);
286
286
@@ -319,7 +319,7 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
319 domain->detachAxis(axis);
319 domain->detachAxis(axis);
320 series->d_ptr->m_axes.removeAll(axis);
320 series->d_ptr->m_axes.removeAll(axis);
321 axis->d_ptr->m_series.removeAll(series);
321 axis->d_ptr->m_series.removeAll(series);
322
322 disconnect(axis, &QAbstractAxis::reverseChanged, this, &ChartDataSet::reverseChanged);
323 return true;
323 return true;
324 }
324 }
325
325
@@ -645,6 +645,13 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
645 }
645 }
646 }
646 }
647
647
648 void ChartDataSet::reverseChanged()
649 {
650 QAbstractAxis *axis = qobject_cast<QAbstractAxis *>(sender());
651 if (axis)
652 m_glXYSeriesDataManager->handleAxisReverseChanged(axis->d_ptr->m_series);
653 }
654
648 #include "moc_chartdataset_p.cpp"
655 #include "moc_chartdataset_p.cpp"
649
656
650 QT_CHARTS_END_NAMESPACE
657 QT_CHARTS_END_NAMESPACE
@@ -86,7 +86,8 Q_SIGNALS:
86 void axisRemoved(QAbstractAxis* axis);
86 void axisRemoved(QAbstractAxis* axis);
87 void seriesAdded(QAbstractSeries* series);
87 void seriesAdded(QAbstractSeries* series);
88 void seriesRemoved(QAbstractSeries* series);
88 void seriesRemoved(QAbstractSeries* series);
89
89 public Q_SLOTS:
90 void reverseChanged();
90 private:
91 private:
91 void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation);
92 void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation);
92 QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation);
93 QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation);
@@ -109,9 +109,10 static const char *vertexSource =
109 "uniform highp vec2 min;\n"
109 "uniform highp vec2 min;\n"
110 "uniform highp vec2 delta;\n"
110 "uniform highp vec2 delta;\n"
111 "uniform highp float pointSize;\n"
111 "uniform highp float pointSize;\n"
112 "uniform highp mat4 matrix;\n"
112 "void main() {\n"
113 "void main() {\n"
113 " vec2 normalPoint = vec2(-1, -1) + ((points - min) / delta);\n"
114 " vec2 normalPoint = vec2(-1, -1) + ((points - min) / delta);\n"
114 " gl_Position = vec4(normalPoint, 0, 1);\n"
115 " gl_Position = matrix * vec4(normalPoint, 0, 1);\n"
115 " gl_PointSize = pointSize;\n"
116 " gl_PointSize = pointSize;\n"
116 "}";
117 "}";
117 static const char *fragmentSource =
118 static const char *fragmentSource =
@@ -138,6 +139,7 void GLWidget::initializeGL()
138 m_minUniformLoc = m_program->uniformLocation("min");
139 m_minUniformLoc = m_program->uniformLocation("min");
139 m_deltaUniformLoc = m_program->uniformLocation("delta");
140 m_deltaUniformLoc = m_program->uniformLocation("delta");
140 m_pointSizeUniformLoc = m_program->uniformLocation("pointSize");
141 m_pointSizeUniformLoc = m_program->uniformLocation("pointSize");
142 m_matrixUniformLoc = m_program->uniformLocation("matrix");
141
143
142
144
143 // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
145 // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
@@ -179,6 +181,7 void GLWidget::paintGL()
179 m_program->setUniformValue(m_colorUniformLoc, data->color);
181 m_program->setUniformValue(m_colorUniformLoc, data->color);
180 m_program->setUniformValue(m_minUniformLoc, data->min);
182 m_program->setUniformValue(m_minUniformLoc, data->min);
181 m_program->setUniformValue(m_deltaUniformLoc, data->delta);
183 m_program->setUniformValue(m_deltaUniformLoc, data->delta);
184 m_program->setUniformValue(m_matrixUniformLoc, data->matrix);
182
185
183 if (!vbo) {
186 if (!vbo) {
184 vbo = new QOpenGLBuffer;
187 vbo = new QOpenGLBuffer;
@@ -79,6 +79,7 private:
79 int m_minUniformLoc;
79 int m_minUniformLoc;
80 int m_deltaUniformLoc;
80 int m_deltaUniformLoc;
81 int m_pointSizeUniformLoc;
81 int m_pointSizeUniformLoc;
82 int m_matrixUniformLoc;
82 QOpenGLVertexArrayObject m_vao;
83 QOpenGLVertexArrayObject m_vao;
83
84
84 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
85 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
@@ -74,16 +74,30 void GLXYSeriesDataManager::setPoints(QXYSeries *series, const AbstractDomain *d
74 QVector<float> &array = data->array;
74 QVector<float> &array = data->array;
75
75
76 bool logAxis = false;
76 bool logAxis = false;
77 bool reverseX = false;
78 bool reverseY = false;
77 foreach (QAbstractAxis* axis, series->attachedAxes()) {
79 foreach (QAbstractAxis* axis, series->attachedAxes()) {
78 if (axis->type() == QAbstractAxis::AxisTypeLogValue) {
80 if (axis->type() == QAbstractAxis::AxisTypeLogValue) {
79 logAxis = true;
81 logAxis = true;
82 }
83 if (axis->isReverse()) {
84 if (axis->orientation() == Qt::Horizontal)
85 reverseX = true;
86 else
87 reverseY = true;
88 if (reverseX && reverseY)
80 break;
89 break;
81 }
90 }
82 }
91 }
83
84 int count = series->count();
92 int count = series->count();
85 int index = 0;
93 int index = 0;
86 array.resize(count * 2);
94 array.resize(count * 2);
95 QMatrix4x4 matrix;
96 if (reverseX)
97 matrix.scale(-1.0, 1.0);
98 if (reverseY)
99 matrix.scale(1.0, -1.0);
100 data->matrix = matrix;
87 if (logAxis) {
101 if (logAxis) {
88 // Use domain to resolve geometry points. Not as fast as shaders, but simpler that way
102 // Use domain to resolve geometry points. Not as fast as shaders, but simpler that way
89 QVector<QPointF> geometryPoints = domain->calculateGeometryPoints(series->pointsVector());
103 QVector<QPointF> geometryPoints = domain->calculateGeometryPoints(series->pointsVector());
@@ -185,5 +199,35 void GLXYSeriesDataManager::handleScatterMarkerSizeChange()
185 }
199 }
186 }
200 }
187
201
202 void GLXYSeriesDataManager::handleAxisReverseChanged(const QList<QAbstractSeries *> &seriesList)
203 {
204 bool reverseX = false;
205 bool reverseY = false;
206 foreach (QAbstractSeries *series, seriesList) {
207 if (QXYSeries *xyseries = qobject_cast<QXYSeries *>(series)) {
208 GLXYSeriesData *data = m_seriesDataMap.value(xyseries);
209 if (data) {
210 foreach (QAbstractAxis* axis, xyseries->attachedAxes()) {
211 if (axis->isReverse()) {
212 if (axis->orientation() == Qt::Horizontal)
213 reverseX = true;
214 else
215 reverseY = true;
216 }
217 if (reverseX && reverseY)
218 break;
219 }
220 QMatrix4x4 matrix;
221 if (reverseX)
222 matrix.scale(-1.0, 1.0);
223 if (reverseY)
224 matrix.scale(1.0, -1.0);
225 data->matrix = matrix;
226 data->dirty = true;
227 }
228 }
229 }
230 }
231
188 QT_CHARTS_END_NAMESPACE
232 QT_CHARTS_END_NAMESPACE
189
233
@@ -44,6 +44,7
44 #include <QtCharts/QXYSeries>
44 #include <QtCharts/QXYSeries>
45 #include <QtGui/QVector3D>
45 #include <QtGui/QVector3D>
46 #include <QtGui/QVector2D>
46 #include <QtGui/QVector2D>
47 #include <QtGui/QMatrix4x4>
47
48
48 QT_CHARTS_BEGIN_NAMESPACE
49 QT_CHARTS_BEGIN_NAMESPACE
49
50
@@ -57,6 +58,19 struct GLXYSeriesData {
57 QAbstractSeries::SeriesType type;
58 QAbstractSeries::SeriesType type;
58 QVector2D min;
59 QVector2D min;
59 QVector2D delta;
60 QVector2D delta;
61 QMatrix4x4 matrix;
62 public:
63 GLXYSeriesData &operator=(const GLXYSeriesData &data) {
64 array = data.array;
65 dirty = data.dirty;
66 color = data.color;
67 width = data.width;
68 type = data.type;
69 min = data.min;
70 delta = data.delta;
71 matrix = data.matrix;
72 return *this;
73 }
60 };
74 };
61
75
62 typedef QMap<const QXYSeries *, GLXYSeriesData *> GLXYDataMap;
76 typedef QMap<const QXYSeries *, GLXYSeriesData *> GLXYDataMap;
@@ -83,6 +97,7 public:
83 foreach (GLXYSeriesData *data, m_seriesDataMap.values())
97 foreach (GLXYSeriesData *data, m_seriesDataMap.values())
84 data->dirty = false;
98 data->dirty = false;
85 }
99 }
100 void handleAxisReverseChanged(const QList<QAbstractSeries *> &seriesList);
86
101
87 public Q_SLOTS:
102 public Q_SLOTS:
88 void cleanup();
103 void cleanup();
@@ -96,9 +96,10 static const char *vertexSource =
96 "uniform highp vec2 min;\n"
96 "uniform highp vec2 min;\n"
97 "uniform highp vec2 delta;\n"
97 "uniform highp vec2 delta;\n"
98 "uniform highp float pointSize;\n"
98 "uniform highp float pointSize;\n"
99 "uniform highp mat4 matrix;\n"
99 "void main() {\n"
100 "void main() {\n"
100 " vec2 normalPoint = vec2(-1, -1) + ((points - min) / delta);\n"
101 " vec2 normalPoint = vec2(-1, -1) + ((points - min) / delta);\n"
101 " gl_Position = vec4(normalPoint, 0, 1);\n"
102 " gl_Position = matrix * vec4(normalPoint, 0, 1);\n"
102 " gl_PointSize = pointSize;\n"
103 " gl_PointSize = pointSize;\n"
103 "}";
104 "}";
104 static const char *fragmentSource =
105 static const char *fragmentSource =
@@ -123,6 +124,7 void DeclarativeRenderNode::initGL()
123 m_minUniformLoc = m_program->uniformLocation("min");
124 m_minUniformLoc = m_program->uniformLocation("min");
124 m_deltaUniformLoc = m_program->uniformLocation("delta");
125 m_deltaUniformLoc = m_program->uniformLocation("delta");
125 m_pointSizeUniformLoc = m_program->uniformLocation("pointSize");
126 m_pointSizeUniformLoc = m_program->uniformLocation("pointSize");
127 m_matrixUniformLoc = m_program->uniformLocation("matrix");
126
128
127 // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
129 // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
128 // implementations this is optional and support may not be present
130 // implementations this is optional and support may not be present
@@ -183,13 +185,7 void DeclarativeRenderNode::setSeriesData(bool mapDirty, const GLXYDataMap &data
183 const GLXYSeriesData *newData = i.value();
185 const GLXYSeriesData *newData = i.value();
184 if (!data || newData->dirty) {
186 if (!data || newData->dirty) {
185 data = new GLXYSeriesData;
187 data = new GLXYSeriesData;
186 data->array = newData->array;
188 *data = *newData;
187 data->color = newData->color;
188 data->dirty = newData->dirty;
189 data->width = newData->width;
190 data->type = newData->type;
191 data->min = newData->min;
192 data->delta = newData->delta;
193 }
189 }
194 m_xyDataMap.insert(i.key(), data);
190 m_xyDataMap.insert(i.key(), data);
195 }
191 }
@@ -208,15 +204,8 void DeclarativeRenderNode::setSeriesData(bool mapDirty, const GLXYDataMap &data
208 const GLXYSeriesData *newData = i.value();
204 const GLXYSeriesData *newData = i.value();
209 if (i.value()->dirty) {
205 if (i.value()->dirty) {
210 GLXYSeriesData *data = m_xyDataMap.value(i.key());
206 GLXYSeriesData *data = m_xyDataMap.value(i.key());
211 if (data) {
207 if (data)
212 data->array = newData->array;
208 *data = *newData;
213 data->color = newData->color;
214 data->dirty = newData->dirty;
215 data->width = newData->width;
216 data->type = newData->type;
217 data->min = newData->min;
218 data->delta = newData->delta;
219 }
220 }
209 }
221 }
210 }
222 }
211 }
@@ -246,6 +235,7 void DeclarativeRenderNode::renderGL()
246 m_program->setUniformValue(m_colorUniformLoc, data->color);
235 m_program->setUniformValue(m_colorUniformLoc, data->color);
247 m_program->setUniformValue(m_minUniformLoc, data->min);
236 m_program->setUniformValue(m_minUniformLoc, data->min);
248 m_program->setUniformValue(m_deltaUniformLoc, data->delta);
237 m_program->setUniformValue(m_deltaUniformLoc, data->delta);
238 m_program->setUniformValue(m_matrixUniformLoc, data->matrix);
249
239
250 if (!vbo) {
240 if (!vbo) {
251 vbo = new QOpenGLBuffer;
241 vbo = new QOpenGLBuffer;
@@ -74,6 +74,7 private:
74 int m_minUniformLoc;
74 int m_minUniformLoc;
75 int m_deltaUniformLoc;
75 int m_deltaUniformLoc;
76 int m_pointSizeUniformLoc;
76 int m_pointSizeUniformLoc;
77 int m_matrixUniformLoc;
77 QOpenGLVertexArrayObject m_vao;
78 QOpenGLVertexArrayObject m_vao;
78 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
79 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
79 bool m_renderNeeded;
80 bool m_renderNeeded;
General Comments 0
You need to be logged in to leave comments. Login now