@@ -40,16 +40,19 int main(int argc, char *argv[]) | |||
|
40 | 40 | QApplication a(argc, argv); |
|
41 | 41 | |
|
42 | 42 | QVector<double> *xSeries = new QVector<double>(); |
|
43 | xSeries->reserve(1028); | |
|
43 | 44 | for(int i=0;i<1028;i++) |
|
44 | 45 | { |
|
45 |
xSeries->append(i |
|
|
46 | xSeries->append(i); | |
|
46 | 47 | } |
|
47 | 48 | QVector<double> *ySeries = new QVector<double>(); |
|
49 | ySeries->reserve(768); | |
|
48 | 50 | for(int i=0;i<768;i++) |
|
49 | 51 | { |
|
50 |
ySeries->append(i |
|
|
52 | ySeries->append(i); | |
|
51 | 53 | } |
|
52 | 54 | QVector<double> *zSeries = new QVector<double>(); |
|
55 | zSeries->reserve(1028*768); | |
|
53 | 56 | for(int i=0;i<1028*768;i++) |
|
54 | 57 | { |
|
55 | 58 |
|
@@ -79,6 +82,5 int main(int argc, char *argv[]) | |||
|
79 | 82 | window.resize(100-77, 100-53); |
|
80 | 83 | window.show(); |
|
81 | 84 | |
|
82 | ||
|
83 | 85 | return a.exec(); |
|
84 | 86 | } |
@@ -10,10 +10,12 | |||
|
10 | 10 | |
|
11 | 11 | QT_CHARTS_BEGIN_NAMESPACE |
|
12 | 12 | |
|
13 | ChartColorBarAxisY::ChartColorBarAxisY(QColorBarAxis *axis, QLinearGradient gradient, QGraphicsItem *item) | |
|
13 | ChartColorBarAxisY::ChartColorBarAxisY(QColorBarAxis *axis, QPoint pos, qreal height, QLinearGradient gradient, QGraphicsItem *item) | |
|
14 | 14 | : VerticalAxis(axis, item), |
|
15 | 15 | m_axis(axis), |
|
16 | m_gradient(gradient) | |
|
16 | m_gradient(gradient), | |
|
17 | m_position(pos), | |
|
18 | m_height(height) | |
|
17 | 19 | { |
|
18 | 20 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); |
|
19 | 21 | QObject::connect(m_axis, SIGNAL(minorTickCountChanged(int)), |
@@ -94,7 +96,7 QSizeF ChartColorBarAxisY::sizeHint(Qt:: | |||
|
94 | 96 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), |
|
95 | 97 | QStringLiteral("..."), |
|
96 | 98 | axis()->labelsAngle()); |
|
97 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
99 | width = boundingRect.width() + labelPadding() + base.width() + 61.0; //TODO : hint changed 1.0 to 61.0 | |
|
98 | 100 | height = boundingRect.height() / 2.0; |
|
99 | 101 | sh = QSizeF(width, height); |
|
100 | 102 | break; |
@@ -109,7 +111,7 QSizeF ChartColorBarAxisY::sizeHint(Qt:: | |||
|
109 | 111 | if (firstHeight < 0.0) |
|
110 | 112 | firstHeight = height; |
|
111 | 113 | } |
|
112 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
|
114 | width = labelWidth + labelPadding() + base.width() + 62.0; //two pixels of tolerance //TODO : hint changed 2.0 to 62.0 | |
|
113 | 115 | height = qMax(height, firstHeight) / 2.0; |
|
114 | 116 | sh = QSizeF(width, height); |
|
115 | 117 | break; |
@@ -122,20 +124,22 QSizeF ChartColorBarAxisY::sizeHint(Qt:: | |||
|
122 | 124 | |
|
123 | 125 | void ChartColorBarAxisY::createColorBar() |
|
124 | 126 | { |
|
125 | QGradientStops stops = m_gradient.stops(); | |
|
127 | //m_position.setX(80+m_position.x());// TODO : remove this when you know how to move labels | |
|
126 | 128 | |
|
127 | QLinearGradient gradient(0,0,1,250); | |
|
129 | //gradient | |
|
130 | QGradientStops stops = m_gradient.stops(); | |
|
131 | QLinearGradient gradient(0,0,1,m_height); | |
|
128 | 132 | foreach(QGradientStop stop, stops) |
|
129 | 133 | { |
|
130 | 134 | gradient.setColorAt(1-stop.first,stop.second); |
|
131 | 135 | } |
|
132 | 136 | |
|
133 | QPixmap image = QPixmap(50,250); | |
|
134 | QPainter painter(&image); | |
|
135 | QRectF rect(0,0,50,250); | |
|
136 | painter.fillRect(rect,gradient); | |
|
137 | //colorbar | |
|
138 | QRectF rect(m_position.x(),m_position.y(),m_height/20,m_height); | |
|
137 | 139 | |
|
138 | 140 | QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this); |
|
141 | colorbar->setZValue(ChartPresenter::AxisZValue); | |
|
142 | colorbar->setBrush(gradient); | |
|
139 | 143 | setGraphicsItem(colorbar); |
|
140 | 144 | } |
|
141 | 145 |
@@ -12,7 +12,7 class ChartColorBarAxisY : public Vertic | |||
|
12 | 12 | { |
|
13 | 13 | Q_OBJECT |
|
14 | 14 | public: |
|
15 | ChartColorBarAxisY(QColorBarAxis *axis, QLinearGradient gradient, QGraphicsItem *item = 0); | |
|
15 | ChartColorBarAxisY(QColorBarAxis *axis, QPoint pos, qreal height, QLinearGradient gradient, QGraphicsItem *item = 0); | |
|
16 | 16 | ~ChartColorBarAxisY(); |
|
17 | 17 | |
|
18 | 18 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
@@ -32,6 +32,8 private Q_SLOTS: | |||
|
32 | 32 | private: |
|
33 | 33 | QColorBarAxis *m_axis; |
|
34 | 34 | QLinearGradient m_gradient; |
|
35 | QPoint m_position; | |
|
36 | qreal m_height; | |
|
35 | 37 | }; |
|
36 | 38 | |
|
37 | 39 | QT_CHARTS_END_NAMESPACE |
@@ -18,10 +18,10 QT_CHARTS_BEGIN_NAMESPACE | |||
|
18 | 18 | /*! |
|
19 | 19 | Constructs an axis object which is a child of \a parent. |
|
20 | 20 | */ |
|
21 | QColorBarAxis::QColorBarAxis(QLinearGradient gradient, qreal min, qreal max,QObject *parent) : | |
|
22 | QAbstractAxis(*new QColorBarAxisPrivate(gradient, min, max, this), parent) | |
|
21 | QColorBarAxis::QColorBarAxis(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QObject *parent) : | |
|
22 | QAbstractAxis(*new QColorBarAxisPrivate(plotArea, gradient, min, max, this), parent) | |
|
23 | 23 | { |
|
24 | ||
|
24 | setGridLineVisible(false); | |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | 27 | /*! |
@@ -130,8 +130,9 QAbstractAxis::AxisType QColorBarAxis::t | |||
|
130 | 130 | |
|
131 | 131 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 | 132 | |
|
133 | QColorBarAxisPrivate::QColorBarAxisPrivate(QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) | |
|
133 | QColorBarAxisPrivate::QColorBarAxisPrivate(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) | |
|
134 | 134 | : QAbstractAxisPrivate(q), |
|
135 | m_plotArea(plotArea), | |
|
135 | 136 | m_min(min), |
|
136 | 137 | m_max(max), |
|
137 | 138 |
|
@@ -155,7 +156,14 void QColorBarAxisPrivate::initializeGra | |||
|
155 | 156 | |
|
156 | 157 | setAlignment(Qt::AlignRight); //also set orientation (Vertical in this case) |
|
157 | 158 | |
|
158 | axis = new ChartColorBarAxisY(q, m_gradient, parent); | |
|
159 | //TODO : change this position | |
|
160 | qreal x1; | |
|
161 | qreal y1; | |
|
162 | qreal x2; | |
|
163 | qreal y2; | |
|
164 | m_plotArea.getCoords(&x1,&y1,&x2,&y2); | |
|
165 | QPoint pos(x2+5,y1); | |
|
166 | axis = new ChartColorBarAxisY(q, pos, m_plotArea.height(),m_gradient, parent); | |
|
159 | 167 | |
|
160 | 168 | m_item.reset(axis); |
|
161 | 169 | QAbstractAxisPrivate::initializeGraphics(parent); |
@@ -11,7 +11,7 class QT_CHARTS_EXPORT QColorBarAxis : p | |||
|
11 | 11 | { |
|
12 | 12 | Q_OBJECT |
|
13 | 13 | public: |
|
14 | explicit QColorBarAxis(QLinearGradient gradient, qreal min, qreal max,QObject *parent = 0); | |
|
14 | explicit QColorBarAxis(QRectF plotArea,QLinearGradient gradient, qreal min, qreal max,QObject *parent = 0); | |
|
15 | 15 | ~QColorBarAxis(); |
|
16 | 16 | |
|
17 | 17 | protected: |
@@ -11,7 +11,7 class QColorBarAxisPrivate : public QAbs | |||
|
11 | 11 | { |
|
12 | 12 | Q_OBJECT |
|
13 | 13 | public: |
|
14 | QColorBarAxisPrivate(QLinearGradient gradient, qreal min, qreal max,QColorBarAxis *q); | |
|
14 | QColorBarAxisPrivate(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max,QColorBarAxis *q); | |
|
15 | 15 | ~QColorBarAxisPrivate(); |
|
16 | 16 | |
|
17 | 17 | public: |
@@ -35,6 +35,7 private: | |||
|
35 | 35 | QString m_format; |
|
36 | 36 | // bool m_applying; |
|
37 | 37 | QLinearGradient m_gradient; |
|
38 | QRectF m_plotArea; | |
|
38 | 39 | Q_DECLARE_PUBLIC(QColorBarAxis) |
|
39 | 40 | }; |
|
40 | 41 |
@@ -7,9 +7,6 | |||
|
7 | 7 | #include <private/qabstractaxis_p.h> |
|
8 | 8 | #include <QtGui/QPainter> |
|
9 | 9 | |
|
10 | //#include <QtCharts/QColorBarAxis> TODO : fix this | |
|
11 | #include "qcolorbaraxis.h" | |
|
12 | ||
|
13 | 10 | #include <QRgb> |
|
14 | 11 | |
|
15 | 12 | #define nbOfColors 65000 |
@@ -56,6 +53,10 void ColorMapChart::paint(QPainter *pain | |||
|
56 | 53 | Q_UNUSED(widget) |
|
57 | 54 | Q_UNUSED(option) |
|
58 | 55 | |
|
56 | m_series->setUseOpenGL(); | |
|
57 | ||
|
58 | painter->save(); | |
|
59 | ||
|
59 | 60 | QRectF clipRect = QRectF(QPointF(0, 0), domain()->size()); |
|
60 | 61 | painter->setClipRect(clipRect); |
|
61 | 62 | |
@@ -64,37 +65,54 void ColorMapChart::paint(QPainter *pain | |||
|
64 | 65 | //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter. |
|
65 | 66 | colorMapImage.fill(QColor(Qt::white).rgb()); |
|
66 | 67 | |
|
67 | ColorMapDataPart * grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel); | |
|
68 | QElapsedTimer timer; | |
|
69 | timer.start(); | |
|
70 | ||
|
71 | QVector<double> * grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel); | |
|
72 | ||
|
73 | int msec = timer.elapsed(); | |
|
74 | int msec2 = 0+msec; | |
|
68 | 75 | |
|
69 | 76 | double maxZ = m_series->maxZ(); |
|
70 | 77 | double minZ = m_series->minZ(); |
|
71 | 78 | double rangeZ = maxZ - minZ; |
|
72 | 79 | |
|
73 |
|
|
|
80 | int imageWidth = colorMapImage.width(); | |
|
81 | int imageHeight = colorMapImage.height(); | |
|
82 | ||
|
83 | for(int i=0;i<imageWidth;i++) | |
|
74 | 84 | { |
|
75 |
for(int j=0;j< |
|
|
85 | for(int j=0;j<imageHeight;j++) | |
|
76 | 86 | { |
|
77 |
double value = grid-> |
|
|
87 | double value = grid->at(i+j*(imageWidth)); | |
|
78 | 88 | double pix=((value-minZ)/rangeZ); |
|
79 | 89 | int indexInColorTable = pix*(nbOfColors-1); |
|
80 | 90 | colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable)); |
|
81 | 91 | } |
|
82 | 92 | } |
|
83 | 93 | |
|
84 | if(!m_colorbar) | |
|
85 | addColorBar(); | |
|
94 | addColorBar(plotAreaRect); | |
|
95 | ||
|
86 | 96 | |
|
87 | 97 | painter->drawImage(clipRect,colorMapImage); |
|
88 | update(); | |
|
98 | update();//Qt docs: Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion | |
|
99 | ||
|
100 | painter->restore(); | |
|
101 | ||
|
102 | ||
|
89 | 103 | } |
|
90 | 104 | |
|
91 | void ColorMapChart::addColorBar() | |
|
105 | void ColorMapChart::addColorBar(QRectF plotAreaRect) | |
|
92 | 106 | { |
|
93 | 107 | double maxZ = m_series->maxZ(); |
|
94 | 108 | double minZ = m_series->minZ(); |
|
95 | QColorBarAxis *colorbar = new QColorBarAxis(createColorMapGradient(m_gradientType),minZ, maxZ,this); | |
|
96 | m_series->chart()->addAxis(colorbar, Qt::AlignRight); | |
|
97 | m_colorbar = true; | |
|
109 | ||
|
110 | if(m_isColorBarDrawn) | |
|
111 | m_series->chart()->removeAxis(m_colorbar); | |
|
112 | ||
|
113 | m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this); | |
|
114 | m_series->chart()->addAxis(m_colorbar, Qt::AlignRight); | |
|
115 | m_isColorBarDrawn = true; | |
|
98 | 116 | } |
|
99 | 117 | |
|
100 | 118 | /*! |
@@ -7,6 +7,9 | |||
|
7 | 7 | #include <QtCharts/QValueAxis> |
|
8 | 8 | #include <QtGui/QPen> |
|
9 | 9 | |
|
10 | //#include <QtCharts/QColorBarAxis> TODO : fix this | |
|
11 | #include "qcolorbaraxis.h" | |
|
12 | ||
|
10 | 13 | QT_CHARTS_BEGIN_NAMESPACE |
|
11 | 14 | |
|
12 | 15 | class ChartPresenter; |
@@ -56,7 +59,7 Q_SIGNALS: | |||
|
56 | 59 | |
|
57 | 60 | private: |
|
58 | 61 | inline bool isEmpty(); |
|
59 | void addColorBar(); | |
|
62 | void addColorBar(QRectF plotAreaRect); | |
|
60 | 63 | QLinearGradient createColorMapGradient(GradientType gradientType); |
|
61 | 64 | void changeGradient(GradientType gradientType); |
|
62 | 65 | |
@@ -67,7 +70,8 protected: | |||
|
67 | 70 | bool m_dirty; |
|
68 | 71 | QVector<QRgb> *m_colorTable; |
|
69 | 72 | GradientType m_gradientType; |
|
70 |
bool m_ |
|
|
73 | bool m_isColorBarDrawn; | |
|
74 | QColorBarAxis *m_colorbar; | |
|
71 | 75 | }; |
|
72 | 76 | |
|
73 | 77 | //class PixmapMarker: public QGraphicsRectItem |
@@ -120,7 +120,7 QColorMapSeries &QColorMapSeries::operat | |||
|
120 | 120 | from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n |
|
121 | 121 | When there are more points than pixels, \a strategy is applied to determine which to choose. |
|
122 | 122 | */ |
|
123 |
|
|
|
123 | QVector<double> *QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy) | |
|
124 | 124 | { |
|
125 | 125 | Q_D(QColorMapSeries); |
|
126 | 126 | return d->getUniformGrid(xpos, ypos,width,height, strategy); |
@@ -433,14 +433,9 QAbstractAxis* QColorMapSeriesPrivate::c | |||
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | |
|
436 |
|
|
|
436 | QVector<double> *QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QColorMapSeries::Strategy strategy) | |
|
437 | 437 | { |
|
438 |
|
|
|
439 | // QVector<double> *ySeries = new QVector<double>(height); | |
|
440 | QVector<double> *dataSeries = new QVector<double>(width*height); | |
|
441 | QVector<double> *timeSeries = new QVector<double>(); | |
|
442 | QVector<double> *ySeries = new QVector<double>(); | |
|
443 | ColorMapDataPart* grid = new ColorMapDataPart(timeSeries,ySeries,dataSeries); | |
|
438 | QVector<double> *grid = new QVector<double>(width*height); | |
|
444 | 439 | |
|
445 | 440 | double dx = (m_maxX - m_minX)/(double)width; |
|
446 | 441 | double dy = (m_maxY - m_minY)/(double)height; |
@@ -448,15 +443,12 ColorMapDataPart *QColorMapSeriesPrivate | |||
|
448 | 443 | int x=0; |
|
449 | 444 | int y=0; |
|
450 | 445 | |
|
451 | for(int i=0;i<width;i++) //width-1? | |
|
452 | { | |
|
453 | timeSeries->append((double)i); | |
|
454 | } | |
|
446 | QVector<Point3D> cluster; | |
|
447 | cluster.reserve(height*width/1000); | |
|
455 | 448 | |
|
456 | ||
|
457 | for (auto cell= dataSeries->begin();cell<dataSeries->end();++cell) | |
|
449 | for (auto cell= grid->begin();cell<grid->end();++cell) | |
|
458 | 450 | { |
|
459 | QVector<Point3D> cluster; | |
|
451 | cluster.resize(0); | |
|
460 | 452 | this->buildCluster(x,y,dx,dy,cluster); |
|
461 | 453 | if(strategy == QColorMapSeries::LastPixel) |
|
462 | 454 | *cell=this->clusterStrategyLast(cluster); |
@@ -471,11 +463,10 ColorMapDataPart *QColorMapSeriesPrivate | |||
|
471 | 463 | else |
|
472 | 464 | { |
|
473 | 465 | x=0; |
|
474 | ySeries->append((double)y); | |
|
475 | 466 | y++; |
|
476 | ||
|
477 | 467 | } |
|
478 | 468 | } |
|
469 | ||
|
479 | 470 | return grid; |
|
480 | 471 | } |
|
481 | 472 | |
@@ -598,6 +589,8 void QColorMapSeriesPrivate::buildClust | |||
|
598 | 589 | QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_minX+xpos*dx,m_minX+(xpos+1)*dx); |
|
599 | 590 | QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy); |
|
600 | 591 | |
|
592 | int timeSeriesSize = dataPart->timesSeries().size(); | |
|
593 | ||
|
601 | 594 | if(xRange.first != xRange.second && yRange.first != yRange.second) |
|
602 | 595 | { |
|
603 | 596 | for(int i =xRange.first+1;i<xRange.second;i++) |
@@ -606,7 +599,7 void QColorMapSeriesPrivate::buildClust | |||
|
606 | 599 | for(int j=yRange.first+1;j<yRange.second;j++) |
|
607 | 600 | { |
|
608 | 601 | qreal yval=dataPart->ySeries()[j]; |
|
609 |
qreal val=dataPart->dataSeries()[ i + ( |
|
|
602 | qreal val=dataPart->dataSeries()[ i + (timeSeriesSize * j)]; | |
|
610 | 603 | cluster.append(Point3D(xval,yval,val)); |
|
611 | 604 | } |
|
612 | 605 | } |
@@ -48,8 +48,8 public : | |||
|
48 | 48 | QColorMapSeries &operator << (const ColorMapDataPart &dataPart); |
|
49 | 49 | QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts); |
|
50 | 50 | |
|
51 |
|
|
|
52 | //double getUniformGrid(int width, int height, Strategy lambda); | |
|
51 | QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, Strategy strategy); | |
|
52 | // QVector<double> *getUniformGrid(int width, int height, Strategy lambda); | |
|
53 | 53 | |
|
54 | 54 | // virtual void attachAxis(QAbstractAxis *axis); |
|
55 | 55 |
@@ -31,7 +31,7 public : | |||
|
31 | 31 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
32 | 32 | QAbstractAxis* createDefaultAxis(Qt::Orientation) const; |
|
33 | 33 | |
|
34 |
|
|
|
34 | QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy); | |
|
35 | 35 | |
|
36 | 36 | Q_SIGNALS: |
|
37 | 37 | void updated(); |
@@ -55,8 +55,6 private: | |||
|
55 | 55 | double m_minZ; |
|
56 | 56 | double m_maxZ; |
|
57 | 57 | void recomputeDataRange(); |
|
58 | QPair<int,int> getLastX(double start, double end); | |
|
59 | int getLastY(int x,double start, double end); | |
|
60 | 58 | double clusterStrategyLast(QVector<Point3D>& cluster); |
|
61 | 59 | double clusterStrategyMean(QVector<Point3D> &cluster); |
|
62 | 60 | double clusterStrategyMedian(QVector<Point3D>& cluster); |
General Comments 0
You need to be logged in to leave comments.
Login now