From d2a7a7849617ac6e16974e5ad08627b08d4eae6d 2016-06-30 22:00:14 From: jeandet Date: 2016-06-30 22:00:14 Subject: [PATCH] Added colormap chart examples Improved Zoom, added direction parameter. Signed-off-by: jeandet --- diff --git a/examples/charts/charts.pro b/examples/charts/charts.pro index 5caa03c..3793741 100644 --- a/examples/charts/charts.pro +++ b/examples/charts/charts.pro @@ -32,7 +32,8 @@ SUBDIRS += areachart \ nesteddonuts \ chartinteractions \ callout \ - chartthemes + chartthemes \ + colormap qtHaveModule(quick) { SUBDIRS += qmlboxplot \ diff --git a/examples/charts/colormap/colormap.pro b/examples/charts/colormap/colormap.pro new file mode 100644 index 0000000..9172f0b --- /dev/null +++ b/examples/charts/colormap/colormap.pro @@ -0,0 +1,8 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = colormap +SOURCES += main.cpp + +HEADERS += diff --git a/examples/charts/colormap/main.cpp b/examples/charts/colormap/main.cpp new file mode 100644 index 0000000..5981736 --- /dev/null +++ b/examples/charts/colormap/main.cpp @@ -0,0 +1,80 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QVector *xSeries = new QVector(); + xSeries->reserve(1028); + for(int i=0;i<1028;i++) + { + xSeries->append(i); + } + QVector *ySeries = new QVector(); + ySeries->reserve(768); + for(int i=0;i<768;i++) + { + ySeries->append(i); + } + QVector *zSeries = new QVector(); + zSeries->reserve(1028*768); + for(int i=0;i<1028*768;i++) + { + zSeries->append(i); + } + + ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries); + + QColorMapSeries *series = new QColorMapSeries(); + series->append(data); + + QChart *chart = new QChart(); + chart->addSeries(series); + + chart->createDefaultAxes(); + + chart->setTitle("Simple Colormap Example"); + + chart->axisX()->setGridLineVisible(false); + chart->axisY()->setGridLineVisible(false); + + chart->legend()->setVisible(false); + + QChartView *chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + + QMainWindow window; + window.setCentralWidget(chartView); + window.resize(400, 400); + window.show(); + + return a.exec(); +} diff --git a/src/charts/qchart.cpp b/src/charts/qchart.cpp index 1d4ff29..669f4fc 100644 --- a/src/charts/qchart.cpp +++ b/src/charts/qchart.cpp @@ -354,9 +354,9 @@ void QChart::zoomIn() d_ptr->zoomIn(2.0); } -void QChart::zoomIn2(double factor) +void QChart::zoomIn2(double factor, Qt::Orientation orientation) { - d_ptr->zoomIn2(factor); + d_ptr->zoomIn2(factor, orientation); } /*! @@ -378,9 +378,9 @@ void QChart::zoomOut() d_ptr->zoomOut(2.0); } -void QChart::zoomOut2(double factor) +void QChart::zoomOut2(double factor, Qt::Orientation orientation) { - d_ptr->zoomOut2(factor); + d_ptr->zoomOut2(factor, orientation); } /*! @@ -422,7 +422,7 @@ void QChart::zoomReset() */ bool QChart::isZoomed() { - return d_ptr->isZoomed(); + return d_ptr->isZoomed(); } /*! @@ -844,10 +844,13 @@ void QChartPrivate::zoomIn(qreal factor) zoomIn(rect); } -void QChartPrivate::zoomIn2(qreal factor) +void QChartPrivate::zoomIn2(qreal factor, Qt::Orientation orientation) { QRectF rect = m_presenter->geometry(); - rect.setWidth(rect.width() / factor); + if(orientation == Qt::Vertical) + rect.setHeight(rect.height() / factor); + else + rect.setWidth(rect.width() / factor); rect.moveCenter(m_presenter->geometry().center()); zoomIn(rect); } @@ -897,13 +900,16 @@ void QChartPrivate::zoomOut(qreal factor) m_presenter->setState(ChartPresenter::ShowState,QPointF()); } -void QChartPrivate::zoomOut2(qreal factor) +void QChartPrivate::zoomOut2(qreal factor, Qt::Orientation orientation) { const QRectF geometry = m_presenter->geometry(); QRectF r; QSizeF size = geometry.size(); - size.setWidth(size.width()/factor); + if(orientation == Qt::Vertical) + size.setHeight(size.height()/factor); + else + size.setWidth(size.width()/factor); r.setSize(size); r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); if (!r.isValid()) diff --git a/src/charts/qchart.h b/src/charts/qchart.h index 21ee8fd..ba4c29c 100644 --- a/src/charts/qchart.h +++ b/src/charts/qchart.h @@ -147,9 +147,9 @@ public: QEasingCurve animationEasingCurve() const; void zoomIn(); - void zoomIn2(double factor); + void zoomIn2(double factor, Qt::Orientation orientation); void zoomOut(); - void zoomOut2(double factor); + void zoomOut2(double factor, Qt::Orientation orientation); void zoomIn(const QRectF &rect); void zoom(qreal factor); diff --git a/src/charts/qchart_p.h b/src/charts/qchart_p.h index 05441c7..cebe785 100644 --- a/src/charts/qchart_p.h +++ b/src/charts/qchart_p.h @@ -68,9 +68,9 @@ public: void init(); void zoomIn(qreal factor); - void zoomIn2(qreal factor); + void zoomIn2(qreal factor, Qt::Orientation orientation); void zoomOut(qreal factor); - void zoomOut2(qreal factor); + void zoomOut2(qreal factor, Qt::Orientation orientation); void zoomIn(const QRectF &rect); void zoomReset(); bool isZoomed();