@@ -141,9 +141,10 void HorizontalAxis::updateGeometry() | |||
|
141 | 141 | qreal widthDiff = rect.width() - boundingRect.width(); |
|
142 | 142 | |
|
143 | 143 | //ticks and label position |
|
144 | QPointF labelPos; | |
|
144 | 145 | if (axis()->alignment() == Qt::AlignTop) { |
|
145 | 146 | if (axis()->isReverse()) { |
|
146 |
label |
|
|
147 | labelPos = QPointF(gridRect.right() - layout[layout.size() - i - 1] | |
|
147 | 148 | + gridRect.left() - center.x(), |
|
148 | 149 | axisRect.bottom() - rect.height() |
|
149 | 150 | + (heightDiff / 2.0) - labelPadding()); |
@@ -152,21 +153,21 void HorizontalAxis::updateGeometry() | |||
|
152 | 153 | gridRect.right() + gridRect.left() - layout[i], |
|
153 | 154 | axisRect.bottom() - labelPadding()); |
|
154 | 155 | } else { |
|
155 |
label |
|
|
156 | labelPos = QPointF(layout[i] - center.x(), axisRect.bottom() - rect.height() | |
|
156 | 157 | + (heightDiff / 2.0) - labelPadding()); |
|
157 | 158 | tickItem->setLine(layout[i], axisRect.bottom(), |
|
158 | 159 | layout[i], axisRect.bottom() - labelPadding()); |
|
159 | 160 | } |
|
160 | 161 | } else if (axis()->alignment() == Qt::AlignBottom) { |
|
161 | 162 | if (axis()->isReverse()) { |
|
162 |
label |
|
|
163 | labelPos = QPointF(gridRect.right() - layout[layout.size() - i - 1] | |
|
163 | 164 | + gridRect.left() - center.x(), |
|
164 | 165 | axisRect.top() - (heightDiff / 2.0) + labelPadding()); |
|
165 | 166 | tickItem->setLine(gridRect.right() + gridRect.left() - layout[i], axisRect.top(), |
|
166 | 167 | gridRect.right() + gridRect.left() - layout[i], |
|
167 | 168 | axisRect.top() + labelPadding()); |
|
168 | 169 | } else { |
|
169 |
label |
|
|
170 | labelPos = QPointF(layout[i] - center.x(), axisRect.top() - (heightDiff / 2.0) | |
|
170 | 171 | + labelPadding()); |
|
171 | 172 | tickItem->setLine(layout[i], axisRect.top(), |
|
172 | 173 | layout[i], axisRect.top() + labelPadding()); |
@@ -193,7 +194,7 void HorizontalAxis::updateGeometry() | |||
|
193 | 194 | && (leftBound == gridRect.left() || rightBound == gridRect.right())) { |
|
194 | 195 | forceHide = true; |
|
195 | 196 | } else { |
|
196 |
label |
|
|
197 | labelPos.setX(leftBound + (delta / 2.0) - center.x()); | |
|
197 | 198 | } |
|
198 | 199 | } else { |
|
199 | 200 | QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis()); |
@@ -202,19 +203,21 void HorizontalAxis::updateGeometry() | |||
|
202 | 203 | && (leftBound == gridRect.left() || rightBound == gridRect.right())) { |
|
203 | 204 | forceHide = true; |
|
204 | 205 | } else { |
|
205 |
label |
|
|
206 | labelItem->pos().y()); | |
|
206 | labelPos.setX(leftBound + (delta / 2.0) - center.x()); | |
|
207 | 207 | } |
|
208 | 208 | } else if (categoryAxis->labelsPosition() |
|
209 | 209 | == QCategoryAxis::AxisLabelsPositionOnValue) { |
|
210 | 210 | if (axis()->isReverse()) |
|
211 |
label |
|
|
211 | labelPos.setX(leftBound - center.x()); | |
|
212 | 212 | else |
|
213 |
label |
|
|
213 | labelPos.setX(rightBound - center.x()); | |
|
214 | 214 | } |
|
215 | 215 | } |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases | |
|
219 | labelItem->setPos(labelPos.toPoint()); | |
|
220 | ||
|
218 | 221 | //label overlap detection - compensate one pixel for rounding errors |
|
219 | 222 | if ((labelItem->pos().x() < width && labelItem->toPlainText() == ellipsis) || forceHide || |
|
220 | 223 | (labelItem->pos().x() + (widthDiff / 2.0)) < (axisRect.left() - 1.0) || |
@@ -143,9 +143,10 void VerticalAxis::updateGeometry() | |||
|
143 | 143 | qreal heightDiff = rect.height() - boundingRect.height(); |
|
144 | 144 | |
|
145 | 145 | //ticks and label position |
|
146 | QPointF labelPos; | |
|
146 | 147 | if (axis()->alignment() == Qt::AlignLeft) { |
|
147 | 148 | if (axis()->isReverse()) { |
|
148 |
label |
|
|
149 | labelPos = QPointF(axisRect.right() - rect.width() + (widthDiff / 2.0) | |
|
149 | 150 | - labelPadding(), |
|
150 | 151 | gridRect.top() + gridRect.bottom() |
|
151 | 152 | - layout[layout.size() - i - 1] - center.y()); |
@@ -154,7 +155,7 void VerticalAxis::updateGeometry() | |||
|
154 | 155 | axisRect.right(), |
|
155 | 156 | gridRect.top() + gridRect.bottom() - layout[i]); |
|
156 | 157 | } else { |
|
157 |
label |
|
|
158 | labelPos = QPointF(axisRect.right() - rect.width() + (widthDiff / 2.0) | |
|
158 | 159 | - labelPadding(), |
|
159 | 160 | layout[i] - center.y()); |
|
160 | 161 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], |
@@ -166,11 +167,11 void VerticalAxis::updateGeometry() | |||
|
166 | 167 | gridRect.top() + gridRect.bottom() - layout[i], |
|
167 | 168 | axisRect.left() + labelPadding(), |
|
168 | 169 | gridRect.top() + gridRect.bottom() - layout[i]); |
|
169 |
label |
|
|
170 | labelPos = QPointF(axisRect.left() + labelPadding() - (widthDiff / 2.0), | |
|
170 | 171 | gridRect.top() + gridRect.bottom() |
|
171 | 172 | - layout[layout.size() - i - 1] - center.y()); |
|
172 | 173 | } else { |
|
173 |
label |
|
|
174 | labelPos = QPointF(axisRect.left() + labelPadding() - (widthDiff / 2.0), | |
|
174 | 175 | layout[i] - center.y()); |
|
175 | 176 | tickItem->setLine(axisRect.left(), layout[i], |
|
176 | 177 | axisRect.left() + labelPadding(), layout[i]); |
@@ -199,8 +200,7 void VerticalAxis::updateGeometry() | |||
|
199 | 200 | && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) { |
|
200 | 201 | forceHide = true; |
|
201 | 202 | } else { |
|
202 | labelItem->setPos(labelItem->pos().x(), | |
|
203 | lowerBound - (delta / 2.0) - center.y()); | |
|
203 | labelPos.setY(lowerBound - (delta / 2.0) - center.y()); | |
|
204 | 204 | } |
|
205 | 205 | } else { |
|
206 | 206 | QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis()); |
@@ -209,22 +209,24 void VerticalAxis::updateGeometry() | |||
|
209 | 209 | && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) { |
|
210 | 210 | forceHide = true; |
|
211 | 211 | } else { |
|
212 | labelItem->setPos(labelItem->pos().x(), | |
|
213 | lowerBound - (delta / 2.0) - center.y()); | |
|
212 | labelPos.setY(lowerBound - (delta / 2.0) - center.y()); | |
|
214 | 213 | } |
|
215 | 214 | } else if (categoryAxis->labelsPosition() |
|
216 | 215 | == QCategoryAxis::AxisLabelsPositionOnValue) { |
|
217 | 216 | labelOnValue = true; |
|
218 | 217 | if (axis()->isReverse()) { |
|
219 |
label |
|
|
218 | labelPos.setY(gridRect.top() + gridRect.bottom() | |
|
220 | 219 | - layout[i + 1] - center.y()); |
|
221 | 220 | } else { |
|
222 |
label |
|
|
221 | labelPos.setY(upperBound - center.y()); | |
|
223 | 222 | } |
|
224 | 223 | } |
|
225 | 224 | } |
|
226 | 225 | } |
|
227 | 226 | |
|
227 | // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases | |
|
228 | labelItem->setPos(labelPos.toPoint()); | |
|
229 | ||
|
228 | 230 | //label overlap detection - compensate one pixel for rounding errors |
|
229 | 231 | if (axis()->isReverse()) { |
|
230 | 232 | if (forceHide) |
@@ -156,7 +156,9 QRectF AbstractChartLayout::calculateLegendMinimum(const QRectF &geometry, QLege | |||
|
156 | 156 | QRectF AbstractChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const |
|
157 | 157 | { |
|
158 | 158 | title->setGeometry(geometry); |
|
159 | QPointF center = geometry.center() - title->boundingRect().center(); | |
|
159 | // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases | |
|
160 | QPointF center((geometry.center() - title->boundingRect().center()).toPoint()); | |
|
161 | ||
|
160 | 162 | title->setPos(center.x(), title->pos().y()); |
|
161 | 163 | return geometry.adjusted(0, title->boundingRect().height()+1, 0, 0); |
|
162 | 164 | } |
@@ -233,10 +233,13 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||
|
233 | 233 | // Delete structs from the container |
|
234 | 234 | qDeleteAll(legendWidthList); |
|
235 | 235 | |
|
236 | if (m_width < geometry.width()) | |
|
237 | m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top()); | |
|
238 | else | |
|
239 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
|
236 | // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases | |
|
237 | if (m_width < geometry.width()) { | |
|
238 | m_legend->d_ptr->items()->setPos(QPoint(geometry.width() / 2 - m_width / 2, | |
|
239 | geometry.top())); | |
|
240 | } else { | |
|
241 | m_legend->d_ptr->items()->setPos(geometry.topLeft().toPoint()); | |
|
242 | } | |
|
240 | 243 | m_height = size.height(); |
|
241 | 244 | } |
|
242 | 245 | break; |
@@ -262,10 +265,13 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||
|
262 | 265 | } |
|
263 | 266 | } |
|
264 | 267 | |
|
265 | if (m_height < geometry.height()) | |
|
266 | m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2); | |
|
267 | else | |
|
268 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
|
268 | // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases | |
|
269 | if (m_height < geometry.height()) { | |
|
270 | m_legend->d_ptr->items()->setPos(QPoint(geometry.left(), | |
|
271 | geometry.height() / 2 - m_height / 2)); | |
|
272 | } else { | |
|
273 | m_legend->d_ptr->items()->setPos(geometry.topLeft().toPoint()); | |
|
274 | } | |
|
269 | 275 | m_width = size.width(); |
|
270 | 276 | break; |
|
271 | 277 | } |
@@ -3,7 +3,6 | |||
|
3 | 3 | } |
|
4 | 4 | include(charts/charts.pri) |
|
5 | 5 | TARGET = chartviewer |
|
6 | QT += opengl | |
|
7 | 6 | INCLUDEPATH += . |
|
8 | 7 | SOURCES += main.cpp window.cpp view.cpp grid.cpp |
|
9 | 8 | HEADERS += window.h view.h charts.h model.h grid.h |
@@ -34,7 +34,7 | |||
|
34 | 34 | #include <QtWidgets/QGraphicsScene> |
|
35 | 35 | #include <QtWidgets/QGraphicsLinearLayout> |
|
36 | 36 | #include <QtWidgets/QGraphicsProxyWidget> |
|
37 |
#include <QtOpen |
|
|
37 | #include <QtWidgets/QOpenGLWidget> | |
|
38 | 38 | #include <QtWidgets/QApplication> |
|
39 | 39 | #include <QtCore/QDebug> |
|
40 | 40 | #include <QtWidgets/QMenu> |
@@ -398,11 +398,11 void Window::checkLegend() | |||
|
398 | 398 | void Window::checkOpenGL() |
|
399 | 399 | { |
|
400 | 400 | bool opengl = m_openGLCheckBox->isChecked(); |
|
401 | bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); | |
|
401 | bool isOpengl = qobject_cast<QOpenGLWidget *>(m_view->viewport()); | |
|
402 | 402 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
403 | 403 | m_view->deleteLater(); |
|
404 | 404 | m_view = new View(m_scene, m_form); |
|
405 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); | |
|
405 | m_view->setViewport(!opengl ? new QWidget() : new QOpenGLWidget()); | |
|
406 | 406 | setCentralWidget(m_view); |
|
407 | 407 | } |
|
408 | 408 |
@@ -4,7 +4,7 | |||
|
4 | 4 | |
|
5 | 5 | TEMPLATE = app |
|
6 | 6 | |
|
7 |
QT += core gui |
|
|
7 | QT += core gui widgets | |
|
8 | 8 | |
|
9 | 9 | SOURCES += main.cpp \ |
|
10 | 10 | mainwidget.cpp \ |
@@ -41,7 +41,7 | |||
|
41 | 41 | #include <QtCore/QDebug> |
|
42 | 42 | #include <QtGui/QStandardItemModel> |
|
43 | 43 | #include <QtCharts/QBarCategoryAxis> |
|
44 |
#include <QtOpen |
|
|
44 | #include <QtWidgets/QOpenGLWidget> | |
|
45 | 45 | |
|
46 | 46 | QT_CHARTS_USE_NAMESPACE |
|
47 | 47 | |
@@ -164,7 +164,7 void MainWidget::initCheckboxes(QGridLayout *grid) | |||
|
164 | 164 | aliasCheckBox->setChecked(false); |
|
165 | 165 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | 166 | |
|
167 | QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget"); | |
|
167 | QCheckBox *openGLCheckBox = new QCheckBox("Use QOpenGLWidget"); | |
|
168 | 168 | connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); |
|
169 | 169 | openGLCheckBox->setChecked(false); |
|
170 | 170 | grid->addWidget(openGLCheckBox, grid->rowCount(), 0); |
@@ -178,11 +178,10 void MainWidget::antiAliasToggled(bool enabled) | |||
|
178 | 178 | void MainWidget::openGLToggled(bool enabled) |
|
179 | 179 | { |
|
180 | 180 | if (enabled) { |
|
181 |
Q |
|
|
182 | f.setSampleBuffers(true); | |
|
181 | QSurfaceFormat f = QSurfaceFormat::defaultFormat(); | |
|
183 | 182 | f.setSamples(4); |
|
184 |
Q |
|
|
185 | QGLWidget *g = new QGLWidget(); | |
|
183 | QSurfaceFormat::setDefaultFormat(f); | |
|
184 | QOpenGLWidget *g = new QOpenGLWidget(); | |
|
186 | 185 | m_chartView->setViewport(g); |
|
187 | 186 | } else { |
|
188 | 187 | m_chartView->setViewport(0); |
@@ -19,7 +19,7 | |||
|
19 | 19 | #include "wavechart.h" |
|
20 | 20 | #include <QtWidgets/QApplication> |
|
21 | 21 | #include <QtWidgets/QMainWindow> |
|
22 |
#include <QtOpen |
|
|
22 | #include <QtWidgets/QOpenGLWidget> | |
|
23 | 23 | |
|
24 | 24 | int main(int argc, char *argv[]) |
|
25 | 25 | { |
@@ -29,7 +29,7 int main(int argc, char *argv[]) | |||
|
29 | 29 | QChart *chart = new QChart(); |
|
30 | 30 | WaveChart *waveChart = new WaveChart(chart,&window); |
|
31 | 31 | |
|
32 | waveChart->setViewport( new QGLWidget() ); | |
|
32 | waveChart->setViewport( new QOpenGLWidget() ); | |
|
33 | 33 | waveChart->setRenderHint(QPainter::Antialiasing); |
|
34 | 34 | chart->setAnimationOptions(QChart::AllAnimations); |
|
35 | 35 | chart->setTitle("This is wave generator."); |
General Comments 0
You need to be logged in to leave comments.
Login now