mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#9161 QtCharts: Refactor to make QtCharts optional again.
This commit is contained in:
parent
a87e05035d
commit
eedebd71a5
@ -6,6 +6,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuGeoQuestNavigation.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuInterfaceToViewWindow.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotCurveSymbol.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotCurveSymbolImageCreator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtSymbol.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotCurve.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotCurve.h
|
||||
@ -112,6 +113,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuGeoQuestNavigation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuInterfaceToViewWindow.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotCurveSymbol.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotCurveSymbolImageCreator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtSymbol.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuPlotCurve.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotCurve.cpp
|
||||
|
@ -37,10 +37,12 @@
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuPlotObjectPicker.h"
|
||||
#include "RiuPlotWidget.h"
|
||||
#include "RiuQtChartsPlotWidget.h"
|
||||
#include "RiuQwtPlotLegend.h"
|
||||
#include "RiuQwtPlotTools.h"
|
||||
#include "RiuQwtPlotWidget.h"
|
||||
#ifdef USE_QTCHARTS
|
||||
#include "RiuQtChartsPlotWidget.h"
|
||||
#endif
|
||||
|
||||
#include "cafCmdFeatureMenuBuilder.h"
|
||||
#include "cafSelectionManager.h"
|
||||
@ -183,10 +185,12 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef USE_QTCHARTS
|
||||
auto qtchartPlotWidget = dynamic_cast<RiuQtChartsPlotWidget*>( plotWidget );
|
||||
legend->connect( qtchartPlotWidget,
|
||||
SIGNAL( legendDataChanged( const QList<QwtLegendData>& ) ),
|
||||
SLOT( updateLegend( const QList<QwtLegendData>& ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
QObject::connect( legend, SIGNAL( legendUpdated() ), this, SLOT( onLegendUpdated() ) );
|
||||
|
@ -0,0 +1,551 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022- Equinor ASA
|
||||
//
|
||||
// ResInsight 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiuPlotCurveSymbolImageCreator.h"
|
||||
|
||||
#include "cafFontTools.h"
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createSymbolImage( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle,
|
||||
const QSize& size,
|
||||
const QPen& pen,
|
||||
const QColor& color )
|
||||
{
|
||||
if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_NONE )
|
||||
{
|
||||
return QImage();
|
||||
}
|
||||
|
||||
if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT )
|
||||
{
|
||||
return createRectImage( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_ELLIPSE )
|
||||
{
|
||||
return createEllipseImage( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_CROSS )
|
||||
{
|
||||
return createCrossImage( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_XCROSS )
|
||||
{
|
||||
return createXCrossImage( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_DIAMOND )
|
||||
{
|
||||
return createDiamondImage( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_HEXAGON )
|
||||
{
|
||||
return createHexagonImage( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_STAR1 )
|
||||
{
|
||||
return createStar1Image( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_STAR1 )
|
||||
{
|
||||
return createStar1Image( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_STAR2 )
|
||||
{
|
||||
return createStar2Image( size, pen, color );
|
||||
}
|
||||
else if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_TRIANGLE ||
|
||||
symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_UP_TRIANGLE ||
|
||||
symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_DOWN_TRIANGLE ||
|
||||
symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_LEFT_TRIANGLE ||
|
||||
symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RIGHT_TRIANGLE )
|
||||
{
|
||||
return createTriangleImage( symbolStyle, size, pen, color );
|
||||
}
|
||||
|
||||
return QImage();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createSymbolImage( RiuPlotCurveSymbol::RiuPlotCurveSymbol::PointSymbolEnum symbolStyle,
|
||||
const QSize& size,
|
||||
const QColor& color )
|
||||
{
|
||||
QPen defaultPen;
|
||||
return createSymbolImage( symbolStyle, size, defaultPen, color );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawTriangleSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createTriangleImage( RiuPlotCurveSymbol::RiuPlotCurveSymbol::PointSymbolEnum symbolStyle,
|
||||
const QSize& size,
|
||||
const QPen& m_pen,
|
||||
const QColor& color )
|
||||
{
|
||||
QImage star( size, QImage::Format_ARGB32 );
|
||||
star.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &star );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
double sw2 = 0.5 * size.width();
|
||||
double sh2 = 0.5 * size.height();
|
||||
|
||||
QPolygonF triangle( 3 );
|
||||
QPointF* trianglePoints = triangle.data();
|
||||
|
||||
double x = size.width() * 0.5;
|
||||
double y = size.width() * 0.5;
|
||||
|
||||
const double x1 = x - sw2;
|
||||
const double x2 = x1 + size.width();
|
||||
const double y1 = y - sh2;
|
||||
const double y2 = y1 + size.height();
|
||||
|
||||
if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_LEFT_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x2;
|
||||
trianglePoints[0].ry() = y1;
|
||||
|
||||
trianglePoints[1].rx() = x1;
|
||||
trianglePoints[1].ry() = y;
|
||||
|
||||
trianglePoints[2].rx() = x2;
|
||||
trianglePoints[2].ry() = y2;
|
||||
}
|
||||
|
||||
if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RIGHT_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x1;
|
||||
trianglePoints[0].ry() = y1;
|
||||
|
||||
trianglePoints[1].rx() = x2;
|
||||
trianglePoints[1].ry() = y;
|
||||
|
||||
trianglePoints[2].rx() = x1;
|
||||
trianglePoints[2].ry() = y2;
|
||||
}
|
||||
|
||||
if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_UP_TRIANGLE ||
|
||||
symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x1;
|
||||
trianglePoints[0].ry() = y2;
|
||||
|
||||
trianglePoints[1].rx() = x;
|
||||
trianglePoints[1].ry() = y1;
|
||||
|
||||
trianglePoints[2].rx() = x2;
|
||||
trianglePoints[2].ry() = y2;
|
||||
}
|
||||
|
||||
if ( symbolStyle == RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_DOWN_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x1;
|
||||
trianglePoints[0].ry() = y1;
|
||||
|
||||
trianglePoints[1].rx() = x;
|
||||
trianglePoints[1].ry() = y2;
|
||||
|
||||
trianglePoints[2].rx() = x2;
|
||||
trianglePoints[2].ry() = y1;
|
||||
}
|
||||
|
||||
painter.drawPolygon( triangle );
|
||||
|
||||
return star;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawLineSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createCrossImage( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
double midX = size.width() * 0.5;
|
||||
double midY = size.height() * 0.5;
|
||||
|
||||
{
|
||||
const double x = midX - sw2;
|
||||
const double y = midY;
|
||||
|
||||
painter.drawLine( x, y, x + sw, y );
|
||||
}
|
||||
{
|
||||
const double y = midY - sh2;
|
||||
const double x = midX;
|
||||
|
||||
painter.drawLine( x, y, x, y + sh );
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawXCrossSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createXCrossImage( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
double midX = size.width() * 0.5;
|
||||
double midY = size.height() * 0.5;
|
||||
|
||||
const double x1 = midX - sw2;
|
||||
const double x2 = x1 + sw;
|
||||
const double y1 = midY - sh2;
|
||||
const double y2 = y1 + sh;
|
||||
|
||||
painter.drawLine( x1, y1, x2, y2 );
|
||||
painter.drawLine( x1, y2, x2, y1 );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawRectSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createRectImage( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
// Mid point
|
||||
const double x = sw * 0.5;
|
||||
const double y = sw * 0.5;
|
||||
|
||||
const QRectF r( x - sw2, y - sh2, sw, sh );
|
||||
painter.drawRect( r );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawEllipseSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createEllipseImage( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
// Mid point
|
||||
const double x = sw * 0.5;
|
||||
const double y = sw * 0.5;
|
||||
|
||||
const QRectF r( x - sw2, y - sh2, sw, sh );
|
||||
painter.drawEllipse( r );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawStar1Symbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createStar1Image( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
QRectF r( 0, 0, size.width(), size.height() );
|
||||
|
||||
const double sqrt1_2 = 1.0 / std::sqrt( 2 );
|
||||
|
||||
const QPointF c = r.center();
|
||||
const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
|
||||
|
||||
painter.drawLine( r.left() + d1, r.top() + d1, r.right() - d1, r.bottom() - d1 );
|
||||
painter.drawLine( r.left() + d1, r.bottom() - d1, r.right() - d1, r.top() + d1 );
|
||||
painter.drawLine( c.x(), r.top(), c.x(), r.bottom() );
|
||||
painter.drawLine( r.left(), c.y(), r.right(), c.y() );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawStar2Symbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createStar2Image( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
QRectF r( 0, 0, size.width(), size.height() );
|
||||
|
||||
const double cos30 = 0.866025; // cos(30°)
|
||||
|
||||
const double dy = 0.25 * size.height();
|
||||
const double dx = 0.5 * size.width() * cos30 / 3.0;
|
||||
|
||||
QPolygonF star( 12 );
|
||||
QPointF* starPoints = star.data();
|
||||
|
||||
double x = size.width() * 0.5;
|
||||
double y = size.height() * 0.5;
|
||||
|
||||
double x1 = x - 3 * dx;
|
||||
double y1 = y - 2 * dy;
|
||||
|
||||
const double x2 = x1 + 1 * dx;
|
||||
const double x3 = x1 + 2 * dx;
|
||||
const double x4 = x1 + 3 * dx;
|
||||
const double x5 = x1 + 4 * dx;
|
||||
const double x6 = x1 + 5 * dx;
|
||||
const double x7 = x1 + 6 * dx;
|
||||
|
||||
const double y2 = y1 + 1 * dy;
|
||||
const double y3 = y1 + 2 * dy;
|
||||
const double y4 = y1 + 3 * dy;
|
||||
const double y5 = y1 + 4 * dy;
|
||||
|
||||
starPoints[0].rx() = x4;
|
||||
starPoints[0].ry() = y1;
|
||||
|
||||
starPoints[1].rx() = x5;
|
||||
starPoints[1].ry() = y2;
|
||||
|
||||
starPoints[2].rx() = x7;
|
||||
starPoints[2].ry() = y2;
|
||||
|
||||
starPoints[3].rx() = x6;
|
||||
starPoints[3].ry() = y3;
|
||||
|
||||
starPoints[4].rx() = x7;
|
||||
starPoints[4].ry() = y4;
|
||||
|
||||
starPoints[5].rx() = x5;
|
||||
starPoints[5].ry() = y4;
|
||||
|
||||
starPoints[6].rx() = x4;
|
||||
starPoints[6].ry() = y5;
|
||||
|
||||
starPoints[7].rx() = x3;
|
||||
starPoints[7].ry() = y4;
|
||||
|
||||
starPoints[8].rx() = x1;
|
||||
starPoints[8].ry() = y4;
|
||||
|
||||
starPoints[9].rx() = x2;
|
||||
starPoints[9].ry() = y3;
|
||||
|
||||
starPoints[10].rx() = x1;
|
||||
starPoints[10].ry() = y2;
|
||||
|
||||
starPoints[11].rx() = x3;
|
||||
starPoints[11].ry() = y2;
|
||||
|
||||
painter.drawPolygon( star );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawHexagonSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createHexagonImage( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
QRectF r( 0, 0, size.width(), size.height() );
|
||||
|
||||
const double cos30 = 0.866025; // cos(30°)
|
||||
const double dx = 0.5 * ( size.height() - cos30 );
|
||||
|
||||
const double dy = 0.25 * size.height();
|
||||
|
||||
QPolygonF hexaPolygon( 6 );
|
||||
QPointF* hexaPoints = hexaPolygon.data();
|
||||
|
||||
double x = size.width() * 0.5;
|
||||
double y = size.height() * 0.5;
|
||||
|
||||
double x1 = x - dx;
|
||||
double y1 = y - 2 * dy;
|
||||
|
||||
const double x2 = x1 + 1 * dx;
|
||||
const double x3 = x1 + 2 * dx;
|
||||
|
||||
const double y2 = y1 + 1 * dy;
|
||||
const double y3 = y1 + 3 * dy;
|
||||
const double y4 = y1 + 4 * dy;
|
||||
|
||||
hexaPoints[0].rx() = x2;
|
||||
hexaPoints[0].ry() = y1;
|
||||
|
||||
hexaPoints[1].rx() = x3;
|
||||
hexaPoints[1].ry() = y2;
|
||||
|
||||
hexaPoints[2].rx() = x3;
|
||||
hexaPoints[2].ry() = y3;
|
||||
|
||||
hexaPoints[3].rx() = x2;
|
||||
hexaPoints[3].ry() = y4;
|
||||
|
||||
hexaPoints[4].rx() = x1;
|
||||
hexaPoints[4].ry() = y3;
|
||||
|
||||
hexaPoints[5].rx() = x1;
|
||||
hexaPoints[5].ry() = y2;
|
||||
|
||||
painter.drawPolygon( hexaPolygon );
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawDiamondSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuPlotCurveSymbolImageCreator::createDiamondImage( const QSize& size, const QPen& m_pen, const QColor& color )
|
||||
{
|
||||
QImage image( size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( color );
|
||||
|
||||
double x = size.width() * 0.5;
|
||||
double y = size.height() * 0.5;
|
||||
const double x1 = x - 0.5 * size.width();
|
||||
const double y1 = y - 0.5 * size.height();
|
||||
const double x2 = x1 + size.width();
|
||||
const double y2 = y1 + size.height();
|
||||
|
||||
QPolygonF polygon;
|
||||
polygon += QPointF( x, y1 );
|
||||
polygon += QPointF( x2, y );
|
||||
polygon += QPointF( x, y2 );
|
||||
polygon += QPointF( x1, y );
|
||||
|
||||
painter.drawPolygon( polygon );
|
||||
|
||||
return image;
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Equinor ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiuPlotCurveSymbol.h"
|
||||
|
||||
#include <QImage>
|
||||
|
||||
class QColor;
|
||||
class QPen;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiuPlotCurveSymbolImageCreator
|
||||
{
|
||||
public:
|
||||
static QImage createSymbolImage( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle,
|
||||
const QSize& size,
|
||||
const QPen& pen,
|
||||
const QColor& color );
|
||||
|
||||
static QImage
|
||||
createSymbolImage( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle, const QSize& size, const QColor& color );
|
||||
|
||||
protected:
|
||||
static QImage createTriangleImage( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle,
|
||||
const QSize& size,
|
||||
const QPen& pen,
|
||||
const QColor& color );
|
||||
static QImage createRectImage( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createStar1Image( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createStar2Image( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createHexagonImage( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createEllipseImage( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createCrossImage( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createXCrossImage( const QSize& size, const QPen& pen, const QColor& color );
|
||||
static QImage createDiamondImage( const QSize& size, const QPen& pen, const QColor& color );
|
||||
};
|
@ -24,6 +24,8 @@
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RiuPlotCurveSymbol.h"
|
||||
#include "RiuPlotCurveSymbolImageCreator.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QPainter>
|
||||
@ -87,113 +89,16 @@ void RiuQtChartsPlotCurveSymbol::applyToScatterSeries( QtCharts::QScatterSeries*
|
||||
|
||||
series->show();
|
||||
|
||||
if ( m_style == PointSymbolEnum::SYMBOL_RECT )
|
||||
QImage image = RiuPlotCurveSymbolImageCreator::createSymbolImage( m_style, QSize( m_size, m_size ), m_pen, m_color );
|
||||
if ( !image.isNull() )
|
||||
{
|
||||
setImageBrush( series, createRectImage() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_ELLIPSE )
|
||||
{
|
||||
setImageBrush( series, createEllipseImage() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_CROSS )
|
||||
{
|
||||
setImageBrush( series, createCrossImage() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_XCROSS )
|
||||
{
|
||||
setImageBrush( series, createXCrossImage() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_DIAMOND )
|
||||
{
|
||||
setImageBrush( series, createDiamondImage() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_HEXAGON )
|
||||
{
|
||||
setImageBrush( series, createHexagonImage() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_STAR1 )
|
||||
{
|
||||
setImageBrush( series, createStar1Image() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_STAR1 )
|
||||
{
|
||||
setImageBrush( series, createStar1Image() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_STAR2 )
|
||||
{
|
||||
setImageBrush( series, createStar2Image() );
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_TRIANGLE || m_style == PointSymbolEnum::SYMBOL_UP_TRIANGLE ||
|
||||
m_style == PointSymbolEnum::SYMBOL_DOWN_TRIANGLE || m_style == PointSymbolEnum::SYMBOL_LEFT_TRIANGLE ||
|
||||
m_style == PointSymbolEnum::SYMBOL_RIGHT_TRIANGLE )
|
||||
{
|
||||
setImageBrush( series, createTriangleImage( m_style ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::warning( "Missing symbol style." );
|
||||
setImageBrush( series, image );
|
||||
}
|
||||
|
||||
series->setMarkerSize( m_size );
|
||||
series->setColor( m_color );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::image() const
|
||||
{
|
||||
if ( m_style == PointSymbolEnum::SYMBOL_NONE )
|
||||
{
|
||||
return QImage();
|
||||
}
|
||||
|
||||
if ( m_style == PointSymbolEnum::SYMBOL_RECT )
|
||||
{
|
||||
return createRectImage();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_ELLIPSE )
|
||||
{
|
||||
return createEllipseImage();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_CROSS )
|
||||
{
|
||||
return createCrossImage();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_XCROSS )
|
||||
{
|
||||
return createXCrossImage();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_DIAMOND )
|
||||
{
|
||||
return createDiamondImage();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_HEXAGON )
|
||||
{
|
||||
return createHexagonImage();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_STAR1 )
|
||||
{
|
||||
return createStar1Image();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_STAR1 )
|
||||
{
|
||||
return createStar1Image();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_STAR2 )
|
||||
{
|
||||
return createStar2Image();
|
||||
}
|
||||
else if ( m_style == PointSymbolEnum::SYMBOL_TRIANGLE || m_style == PointSymbolEnum::SYMBOL_UP_TRIANGLE ||
|
||||
m_style == PointSymbolEnum::SYMBOL_DOWN_TRIANGLE || m_style == PointSymbolEnum::SYMBOL_LEFT_TRIANGLE ||
|
||||
m_style == PointSymbolEnum::SYMBOL_RIGHT_TRIANGLE )
|
||||
{
|
||||
return createTriangleImage( m_style );
|
||||
}
|
||||
|
||||
return QImage();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -204,467 +109,6 @@ void RiuQtChartsPlotCurveSymbol::setImageBrush( QtCharts::QScatterSeries* series
|
||||
series->setPen( QColor( Qt::transparent ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawTriangleSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createTriangleImage( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle ) const
|
||||
{
|
||||
QSize size( m_size, m_size );
|
||||
|
||||
QImage star( size.width(), size.height(), QImage::Format_ARGB32 );
|
||||
star.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &star );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
double sw2 = 0.5 * size.width();
|
||||
double sh2 = 0.5 * size.height();
|
||||
|
||||
QPolygonF triangle( 3 );
|
||||
QPointF* trianglePoints = triangle.data();
|
||||
|
||||
double x = size.width() * 0.5;
|
||||
double y = size.width() * 0.5;
|
||||
|
||||
const double x1 = x - sw2;
|
||||
const double x2 = x1 + size.width();
|
||||
const double y1 = y - sh2;
|
||||
const double y2 = y1 + size.height();
|
||||
|
||||
if ( symbolStyle == PointSymbolEnum::SYMBOL_LEFT_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x2;
|
||||
trianglePoints[0].ry() = y1;
|
||||
|
||||
trianglePoints[1].rx() = x1;
|
||||
trianglePoints[1].ry() = y;
|
||||
|
||||
trianglePoints[2].rx() = x2;
|
||||
trianglePoints[2].ry() = y2;
|
||||
}
|
||||
|
||||
if ( symbolStyle == PointSymbolEnum::SYMBOL_RIGHT_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x1;
|
||||
trianglePoints[0].ry() = y1;
|
||||
|
||||
trianglePoints[1].rx() = x2;
|
||||
trianglePoints[1].ry() = y;
|
||||
|
||||
trianglePoints[2].rx() = x1;
|
||||
trianglePoints[2].ry() = y2;
|
||||
}
|
||||
|
||||
if ( symbolStyle == PointSymbolEnum::SYMBOL_UP_TRIANGLE || symbolStyle == PointSymbolEnum::SYMBOL_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x1;
|
||||
trianglePoints[0].ry() = y2;
|
||||
|
||||
trianglePoints[1].rx() = x;
|
||||
trianglePoints[1].ry() = y1;
|
||||
|
||||
trianglePoints[2].rx() = x2;
|
||||
trianglePoints[2].ry() = y2;
|
||||
}
|
||||
|
||||
if ( symbolStyle == PointSymbolEnum::SYMBOL_DOWN_TRIANGLE )
|
||||
{
|
||||
trianglePoints[0].rx() = x1;
|
||||
trianglePoints[0].ry() = y1;
|
||||
|
||||
trianglePoints[1].rx() = x;
|
||||
trianglePoints[1].ry() = y2;
|
||||
|
||||
trianglePoints[2].rx() = x2;
|
||||
trianglePoints[2].ry() = y1;
|
||||
}
|
||||
|
||||
painter.drawPolygon( triangle );
|
||||
|
||||
return star;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawLineSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createCrossImage() const
|
||||
{
|
||||
const QSize size( m_size, m_size );
|
||||
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
double midX = size.width() * 0.5;
|
||||
double midY = size.height() * 0.5;
|
||||
|
||||
{
|
||||
const double x = midX - sw2;
|
||||
const double y = midY;
|
||||
|
||||
painter.drawLine( x, y, x + sw, y );
|
||||
}
|
||||
{
|
||||
const double y = midY - sh2;
|
||||
const double x = midX;
|
||||
|
||||
painter.drawLine( x, y, x, y + sh );
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawXCrossSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createXCrossImage() const
|
||||
{
|
||||
const QSize size( m_size, m_size );
|
||||
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
double midX = size.width() * 0.5;
|
||||
double midY = size.height() * 0.5;
|
||||
|
||||
const double x1 = midX - sw2;
|
||||
const double x2 = x1 + sw;
|
||||
const double y1 = midY - sh2;
|
||||
const double y2 = y1 + sh;
|
||||
|
||||
painter.drawLine( x1, y1, x2, y2 );
|
||||
painter.drawLine( x1, y2, x2, y1 );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawRectSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createRectImage() const
|
||||
{
|
||||
const QSize size( m_size, m_size );
|
||||
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
// Mid point
|
||||
const double x = sw * 0.5;
|
||||
const double y = sw * 0.5;
|
||||
|
||||
const QRectF r( x - sw2, y - sh2, sw, sh );
|
||||
painter.drawRect( r );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawEllipseSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createEllipseImage() const
|
||||
{
|
||||
const QSize size( m_size, m_size );
|
||||
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
const double sw = size.width();
|
||||
const double sh = size.height();
|
||||
const double sw2 = 0.5 * size.width();
|
||||
const double sh2 = 0.5 * size.height();
|
||||
|
||||
// Mid point
|
||||
const double x = sw * 0.5;
|
||||
const double y = sw * 0.5;
|
||||
|
||||
const QRectF r( x - sw2, y - sh2, sw, sh );
|
||||
painter.drawEllipse( r );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawStar1Symbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createStar1Image() const
|
||||
{
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
QRectF r( 0, 0, m_size, m_size );
|
||||
|
||||
const double sqrt1_2 = 1.0 / sqrt( 2 );
|
||||
|
||||
const QPointF c = r.center();
|
||||
const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
|
||||
|
||||
painter.drawLine( r.left() + d1, r.top() + d1, r.right() - d1, r.bottom() - d1 );
|
||||
painter.drawLine( r.left() + d1, r.bottom() - d1, r.right() - d1, r.top() + d1 );
|
||||
painter.drawLine( c.x(), r.top(), c.x(), r.bottom() );
|
||||
painter.drawLine( r.left(), c.y(), r.right(), c.y() );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawStar2Symbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createStar2Image() const
|
||||
{
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
QRectF r( 0, 0, m_size, m_size );
|
||||
|
||||
const double cos30 = 0.866025; // cos(30°)
|
||||
|
||||
const double dy = 0.25 * m_size;
|
||||
const double dx = 0.5 * m_size * cos30 / 3.0;
|
||||
|
||||
QPolygonF star( 12 );
|
||||
QPointF* starPoints = star.data();
|
||||
|
||||
double x = m_size * 0.5;
|
||||
double y = m_size * 0.5;
|
||||
|
||||
double x1 = x - 3 * dx;
|
||||
double y1 = y - 2 * dy;
|
||||
|
||||
const double x2 = x1 + 1 * dx;
|
||||
const double x3 = x1 + 2 * dx;
|
||||
const double x4 = x1 + 3 * dx;
|
||||
const double x5 = x1 + 4 * dx;
|
||||
const double x6 = x1 + 5 * dx;
|
||||
const double x7 = x1 + 6 * dx;
|
||||
|
||||
const double y2 = y1 + 1 * dy;
|
||||
const double y3 = y1 + 2 * dy;
|
||||
const double y4 = y1 + 3 * dy;
|
||||
const double y5 = y1 + 4 * dy;
|
||||
|
||||
starPoints[0].rx() = x4;
|
||||
starPoints[0].ry() = y1;
|
||||
|
||||
starPoints[1].rx() = x5;
|
||||
starPoints[1].ry() = y2;
|
||||
|
||||
starPoints[2].rx() = x7;
|
||||
starPoints[2].ry() = y2;
|
||||
|
||||
starPoints[3].rx() = x6;
|
||||
starPoints[3].ry() = y3;
|
||||
|
||||
starPoints[4].rx() = x7;
|
||||
starPoints[4].ry() = y4;
|
||||
|
||||
starPoints[5].rx() = x5;
|
||||
starPoints[5].ry() = y4;
|
||||
|
||||
starPoints[6].rx() = x4;
|
||||
starPoints[6].ry() = y5;
|
||||
|
||||
starPoints[7].rx() = x3;
|
||||
starPoints[7].ry() = y4;
|
||||
|
||||
starPoints[8].rx() = x1;
|
||||
starPoints[8].ry() = y4;
|
||||
|
||||
starPoints[9].rx() = x2;
|
||||
starPoints[9].ry() = y3;
|
||||
|
||||
starPoints[10].rx() = x1;
|
||||
starPoints[10].ry() = y2;
|
||||
|
||||
starPoints[11].rx() = x3;
|
||||
starPoints[11].ry() = y2;
|
||||
|
||||
painter.drawPolygon( star );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawHexagonSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createHexagonImage() const
|
||||
{
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
QRectF r( 0, 0, m_size, m_size );
|
||||
|
||||
const double cos30 = 0.866025; // cos(30°)
|
||||
const double dx = 0.5 * ( m_size - cos30 );
|
||||
|
||||
const double dy = 0.25 * m_size;
|
||||
|
||||
QPolygonF hexaPolygon( 6 );
|
||||
QPointF* hexaPoints = hexaPolygon.data();
|
||||
|
||||
double x = m_size * 0.5;
|
||||
double y = m_size * 0.5;
|
||||
|
||||
double x1 = x - dx;
|
||||
double y1 = y - 2 * dy;
|
||||
|
||||
const double x2 = x1 + 1 * dx;
|
||||
const double x3 = x1 + 2 * dx;
|
||||
|
||||
const double y2 = y1 + 1 * dy;
|
||||
const double y3 = y1 + 3 * dy;
|
||||
const double y4 = y1 + 4 * dy;
|
||||
|
||||
hexaPoints[0].rx() = x2;
|
||||
hexaPoints[0].ry() = y1;
|
||||
|
||||
hexaPoints[1].rx() = x3;
|
||||
hexaPoints[1].ry() = y2;
|
||||
|
||||
hexaPoints[2].rx() = x3;
|
||||
hexaPoints[2].ry() = y3;
|
||||
|
||||
hexaPoints[3].rx() = x2;
|
||||
hexaPoints[3].ry() = y4;
|
||||
|
||||
hexaPoints[4].rx() = x1;
|
||||
hexaPoints[4].ry() = y3;
|
||||
|
||||
hexaPoints[5].rx() = x1;
|
||||
hexaPoints[5].ry() = y2;
|
||||
|
||||
painter.drawPolygon( hexaPolygon );
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adapted from QwtSymbol::qwtDrawDiamondSymbols
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QImage RiuQtChartsPlotCurveSymbol::createDiamondImage() const
|
||||
{
|
||||
QImage image( m_size, m_size, QImage::Format_ARGB32 );
|
||||
image.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &image );
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QPen pen( m_pen );
|
||||
pen.setWidth( 1.0 );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
painter.setPen( pen );
|
||||
painter.setBrush( m_color );
|
||||
|
||||
QSize size( m_size, m_size );
|
||||
|
||||
double x = size.width() * 0.5;
|
||||
double y = size.height() * 0.5;
|
||||
const double x1 = x - 0.5 * size.width();
|
||||
const double y1 = y - 0.5 * size.height();
|
||||
const double x2 = x1 + size.width();
|
||||
const double y2 = y1 + size.height();
|
||||
|
||||
QPolygonF polygon;
|
||||
polygon += QPointF( x, y1 );
|
||||
polygon += QPointF( x2, y );
|
||||
polygon += QPointF( x, y2 );
|
||||
polygon += QPointF( x1, y );
|
||||
|
||||
painter.drawPolygon( polygon );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -63,16 +63,6 @@ public:
|
||||
QImage image() const;
|
||||
|
||||
private:
|
||||
QImage createTriangleImage( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle ) const;
|
||||
QImage createRectImage() const;
|
||||
QImage createStar1Image() const;
|
||||
QImage createStar2Image() const;
|
||||
QImage createHexagonImage() const;
|
||||
QImage createEllipseImage() const;
|
||||
QImage createCrossImage() const;
|
||||
QImage createXCrossImage() const;
|
||||
QImage createDiamondImage() const;
|
||||
|
||||
void setImageBrush( QtCharts::QScatterSeries* series, const QImage& image ) const;
|
||||
|
||||
QColor m_color;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "RimPlotCurve.h"
|
||||
|
||||
#include "RiuGuiTheme.h"
|
||||
#include "RiuQtChartsPlotCurveSymbol.h"
|
||||
#include "RiuPlotCurveSymbolImageCreator.h"
|
||||
#include "RiuQwtPlotLegend.h"
|
||||
|
||||
#include "qwt_axis.h"
|
||||
@ -323,13 +323,12 @@ QList<QwtLegendData> RiuQwtPlotTools::createLegendData( const std::vector<RimPlo
|
||||
QwtPainter::drawLine( &painter, 0.0, y, size.width(), y );
|
||||
}
|
||||
|
||||
if ( c->symbol() != RiuQtChartsPlotCurveSymbol::SYMBOL_NONE )
|
||||
if ( c->symbol() != RiuPlotCurveSymbol::SYMBOL_NONE )
|
||||
{
|
||||
RiuQtChartsPlotCurveSymbol symbol( c->symbol() );
|
||||
symbol.setSize( size.height() / 2, size.height() / 2 );
|
||||
symbol.setColor( RiaColorTools::toQColor( c->color() ) );
|
||||
|
||||
auto image = symbol.image();
|
||||
auto image =
|
||||
RiuPlotCurveSymbolImageCreator::createSymbolImage( c->symbol(),
|
||||
QSize( size.width() / 2, size.height() / 2 ),
|
||||
RiaColorTools::toQColor( c->color() ) );
|
||||
|
||||
QPoint p( size.width() / 4, size.height() / 4 );
|
||||
painter.drawImage( p, image );
|
||||
|
Loading…
Reference in New Issue
Block a user