##// 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 281 series->d_ptr->initializeAxes();
282 282 axis->d_ptr->initializeDomain(domain);
283
283 connect(axis, &QAbstractAxis::reverseChanged, this, &ChartDataSet::reverseChanged);
284 284 foreach (AbstractDomain *blockedDomain, blockedDomains)
285 285 blockedDomain->blockRangeSignals(false);
286 286
@@ -319,7 +319,7 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
319 319 domain->detachAxis(axis);
320 320 series->d_ptr->m_axes.removeAll(axis);
321 321 axis->d_ptr->m_series.removeAll(series);
322
322 disconnect(axis, &QAbstractAxis::reverseChanged, this, &ChartDataSet::reverseChanged);
323 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 655 #include "moc_chartdataset_p.cpp"
649 656
650 657 QT_CHARTS_END_NAMESPACE
@@ -86,7 +86,8 Q_SIGNALS:
86 86 void axisRemoved(QAbstractAxis* axis);
87 87 void seriesAdded(QAbstractSeries* series);
88 88 void seriesRemoved(QAbstractSeries* series);
89
89 public Q_SLOTS:
90 void reverseChanged();
90 91 private:
91 92 void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation);
92 93 QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation);
@@ -109,9 +109,10 static const char *vertexSource =
109 109 "uniform highp vec2 min;\n"
110 110 "uniform highp vec2 delta;\n"
111 111 "uniform highp float pointSize;\n"
112 "uniform highp mat4 matrix;\n"
112 113 "void main() {\n"
113 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 116 " gl_PointSize = pointSize;\n"
116 117 "}";
117 118 static const char *fragmentSource =
@@ -138,6 +139,7 void GLWidget::initializeGL()
138 139 m_minUniformLoc = m_program->uniformLocation("min");
139 140 m_deltaUniformLoc = m_program->uniformLocation("delta");
140 141 m_pointSizeUniformLoc = m_program->uniformLocation("pointSize");
142 m_matrixUniformLoc = m_program->uniformLocation("matrix");
141 143
142 144
143 145 // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
@@ -179,6 +181,7 void GLWidget::paintGL()
179 181 m_program->setUniformValue(m_colorUniformLoc, data->color);
180 182 m_program->setUniformValue(m_minUniformLoc, data->min);
181 183 m_program->setUniformValue(m_deltaUniformLoc, data->delta);
184 m_program->setUniformValue(m_matrixUniformLoc, data->matrix);
182 185
183 186 if (!vbo) {
184 187 vbo = new QOpenGLBuffer;
@@ -79,6 +79,7 private:
79 79 int m_minUniformLoc;
80 80 int m_deltaUniformLoc;
81 81 int m_pointSizeUniformLoc;
82 int m_matrixUniformLoc;
82 83 QOpenGLVertexArrayObject m_vao;
83 84
84 85 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
@@ -74,16 +74,30 void GLXYSeriesDataManager::setPoints(QXYSeries *series, const AbstractDomain *d
74 74 QVector<float> &array = data->array;
75 75
76 76 bool logAxis = false;
77 bool reverseX = false;
78 bool reverseY = false;
77 79 foreach (QAbstractAxis* axis, series->attachedAxes()) {
78 80 if (axis->type() == QAbstractAxis::AxisTypeLogValue) {
79 81 logAxis = true;
80 break;
82 }
83 if (axis->isReverse()) {
84 if (axis->orientation() == Qt::Horizontal)
85 reverseX = true;
86 else
87 reverseY = true;
88 if (reverseX && reverseY)
89 break;
81 90 }
82 91 }
83
84 92 int count = series->count();
85 93 int index = 0;
86 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 101 if (logAxis) {
88 102 // Use domain to resolve geometry points. Not as fast as shaders, but simpler that way
89 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 232 QT_CHARTS_END_NAMESPACE
189 233
@@ -44,6 +44,7
44 44 #include <QtCharts/QXYSeries>
45 45 #include <QtGui/QVector3D>
46 46 #include <QtGui/QVector2D>
47 #include <QtGui/QMatrix4x4>
47 48
48 49 QT_CHARTS_BEGIN_NAMESPACE
49 50
@@ -57,6 +58,19 struct GLXYSeriesData {
57 58 QAbstractSeries::SeriesType type;
58 59 QVector2D min;
59 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 76 typedef QMap<const QXYSeries *, GLXYSeriesData *> GLXYDataMap;
@@ -83,6 +97,7 public:
83 97 foreach (GLXYSeriesData *data, m_seriesDataMap.values())
84 98 data->dirty = false;
85 99 }
100 void handleAxisReverseChanged(const QList<QAbstractSeries *> &seriesList);
86 101
87 102 public Q_SLOTS:
88 103 void cleanup();
@@ -96,9 +96,10 static const char *vertexSource =
96 96 "uniform highp vec2 min;\n"
97 97 "uniform highp vec2 delta;\n"
98 98 "uniform highp float pointSize;\n"
99 "uniform highp mat4 matrix;\n"
99 100 "void main() {\n"
100 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 103 " gl_PointSize = pointSize;\n"
103 104 "}";
104 105 static const char *fragmentSource =
@@ -123,6 +124,7 void DeclarativeRenderNode::initGL()
123 124 m_minUniformLoc = m_program->uniformLocation("min");
124 125 m_deltaUniformLoc = m_program->uniformLocation("delta");
125 126 m_pointSizeUniformLoc = m_program->uniformLocation("pointSize");
127 m_matrixUniformLoc = m_program->uniformLocation("matrix");
126 128
127 129 // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
128 130 // implementations this is optional and support may not be present
@@ -183,13 +185,7 void DeclarativeRenderNode::setSeriesData(bool mapDirty, const GLXYDataMap &data
183 185 const GLXYSeriesData *newData = i.value();
184 186 if (!data || newData->dirty) {
185 187 data = new GLXYSeriesData;
186 data->array = newData->array;
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;
188 *data = *newData;
193 189 }
194 190 m_xyDataMap.insert(i.key(), data);
195 191 }
@@ -208,15 +204,8 void DeclarativeRenderNode::setSeriesData(bool mapDirty, const GLXYDataMap &data
208 204 const GLXYSeriesData *newData = i.value();
209 205 if (i.value()->dirty) {
210 206 GLXYSeriesData *data = m_xyDataMap.value(i.key());
211 if (data) {
212 data->array = newData->array;
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 }
207 if (data)
208 *data = *newData;
220 209 }
221 210 }
222 211 }
@@ -246,6 +235,7 void DeclarativeRenderNode::renderGL()
246 235 m_program->setUniformValue(m_colorUniformLoc, data->color);
247 236 m_program->setUniformValue(m_minUniformLoc, data->min);
248 237 m_program->setUniformValue(m_deltaUniformLoc, data->delta);
238 m_program->setUniformValue(m_matrixUniformLoc, data->matrix);
249 239
250 240 if (!vbo) {
251 241 vbo = new QOpenGLBuffer;
@@ -74,6 +74,7 private:
74 74 int m_minUniformLoc;
75 75 int m_deltaUniformLoc;
76 76 int m_pointSizeUniformLoc;
77 int m_matrixUniformLoc;
77 78 QOpenGLVertexArrayObject m_vao;
78 79 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
79 80 bool m_renderNeeded;
General Comments 0
You need to be logged in to leave comments. Login now