|
|
/*------------------------------------------------------------------------------
|
|
|
-- 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
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
|
#ifndef COLORMAPCHART_H
|
|
|
#define COLORMAPCHART_H
|
|
|
|
|
|
#include "point3d.h"
|
|
|
#include <QtCharts/QChartGlobal>
|
|
|
#include <private/chartitem_p.h>
|
|
|
#include <QtCharts/QValueAxis>
|
|
|
#include <QtGui/QPen>
|
|
|
|
|
|
//#include <QtCharts/QColorBarAxis> TODO : fix this
|
|
|
#include "qcolorbaraxis.h"
|
|
|
|
|
|
QT_CHARTS_BEGIN_NAMESPACE
|
|
|
|
|
|
class ChartPresenter;
|
|
|
class QColorMapSeries;
|
|
|
|
|
|
class ColorMapChart : public ChartItem
|
|
|
{
|
|
|
Q_OBJECT
|
|
|
public:
|
|
|
|
|
|
enum GradientType
|
|
|
{
|
|
|
Rainbow,
|
|
|
CyclingRainbow,
|
|
|
BlackAndWhite,
|
|
|
ReverseBlackAndWhite
|
|
|
};
|
|
|
|
|
|
explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0);
|
|
|
~ColorMapChart();
|
|
|
|
|
|
bool isDirty() const { return m_dirty; }
|
|
|
void setDirty(bool dirty);
|
|
|
|
|
|
// from QGraphicsItem
|
|
|
QRectF boundingRect() const;
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
void handlePointAdded(int index);
|
|
|
void handlePointRemoved(int index);
|
|
|
void handlePointsRemoved(int index, int count);
|
|
|
void handlePointReplaced(int index);
|
|
|
void handlePointsReplaced();
|
|
|
void handleDomainUpdated();
|
|
|
|
|
|
private slots :
|
|
|
void populateColorTable();
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
void clicked(const Point3D &point);
|
|
|
void hovered(const Point3D &point, bool state);
|
|
|
void pressed(const Point3D &point);
|
|
|
void released(const Point3D &point);
|
|
|
void doubleClicked(const Point3D &point);
|
|
|
void gradientTypeChanged();
|
|
|
|
|
|
private:
|
|
|
inline bool isEmpty();
|
|
|
void addColorBar(QRectF plotAreaRect);
|
|
|
|
|
|
QRectF mapColorMapToPlotArea();
|
|
|
void fillColorMapImage(QImage &colorMapImage);
|
|
|
QLinearGradient createColorMapGradient(GradientType gradientType);
|
|
|
void changeGradient(GradientType gradientType);
|
|
|
|
|
|
protected:
|
|
|
QColorMapSeries *m_series;
|
|
|
QVector<Point3D> m_points;
|
|
|
QRectF m_rect;
|
|
|
bool m_dirty;
|
|
|
QVector<QRgb> *m_colorTable;
|
|
|
GradientType m_gradientType;
|
|
|
bool m_isColorBarDrawn;
|
|
|
QColorBarAxis *m_colorbar;
|
|
|
QRectF m_currentClipRect;
|
|
|
QVector<double> m_grid;
|
|
|
};
|
|
|
|
|
|
//class PixmapMarker: public QGraphicsRectItem
|
|
|
//{
|
|
|
|
|
|
//public:
|
|
|
// PixmapMarker(qreal x, qreal y, qreal w, qreal h, ColorMapChart *parent)
|
|
|
// : QGraphicsRectItem(x, y, w, h, parent),
|
|
|
// m_parent(parent)
|
|
|
// {
|
|
|
// setAcceptHoverEvents(true);
|
|
|
// setFlag(QGraphicsItem::ItemIsSelectable);
|
|
|
// }
|
|
|
|
|
|
//protected:
|
|
|
// void mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
// {
|
|
|
// QGraphicsRectItem::mousePressEvent(event);
|
|
|
// m_parent->markerPressed(this);
|
|
|
// m_parent->setMousePressed();
|
|
|
// }
|
|
|
// void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
// {
|
|
|
// QGraphicsRectItem::hoverEnterEvent(event);
|
|
|
// m_parent->markerHovered(this, true);
|
|
|
// }
|
|
|
// void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
// {
|
|
|
// QGraphicsRectItem::hoverLeaveEvent(event);
|
|
|
// m_parent->markerHovered(this, false);
|
|
|
// }
|
|
|
// void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
// {
|
|
|
// QGraphicsRectItem::mouseReleaseEvent(event);
|
|
|
// m_parent->markerReleased(this);
|
|
|
// if (m_parent->mousePressed())
|
|
|
// m_parent->markerSelected(this);
|
|
|
// m_parent->setMousePressed(false);
|
|
|
// }
|
|
|
// void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|
|
// {
|
|
|
// QGraphicsRectItem::mouseDoubleClickEvent(event);
|
|
|
// m_parent->markerDoubleClicked(this);
|
|
|
// }
|
|
|
|
|
|
//private:
|
|
|
// ColorMapChart *m_parent;
|
|
|
//};
|
|
|
|
|
|
|
|
|
QT_CHARTS_END_NAMESPACE
|
|
|
|
|
|
#endif // COLORMAPCHART_H
|
|
|
|