2018-10-05 08:59:19 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-10-05 08:59:19 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-10-05 08:59:19 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-10-05 08:59:19 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiuQwtPlotItemGroup.h"
|
|
|
|
|
2022-03-18 07:16:07 -05:00
|
|
|
#include "qwt_graphic.h"
|
|
|
|
|
|
|
|
#include <QRect>
|
|
|
|
|
2018-10-05 08:59:19 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
RiuQwtPlotItemGroup::RiuQwtPlotItemGroup()
|
|
|
|
{
|
|
|
|
}
|
2018-10-05 08:59:19 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuQwtPlotItemGroup::~RiuQwtPlotItemGroup()
|
|
|
|
{
|
|
|
|
this->detach();
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( QwtPlotItem* item : m_plotItems )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( QwtPlotItem* legendItem : m_legendItems )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
|
|
|
delete legendItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuQwtPlotItemGroup::addPlotItem( QwtPlotItem* plotItem )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
m_plotItems.push_back( plotItem );
|
2018-10-05 08:59:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuQwtPlotItemGroup::addLegendItem( QwtPlotItem* legendItem )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
m_legendItems.push_back( legendItem );
|
2018-10-05 08:59:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:43:15 -06:00
|
|
|
void RiuQwtPlotItemGroup::draw( QPainter* painter, const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& canvasRect ) const
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const QwtPlotItem* item : m_plotItems )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
item->draw( painter, xMap, yMap, canvasRect );
|
2018-10-05 08:59:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QRectF RiuQwtPlotItemGroup::boundingRect() const
|
|
|
|
{
|
|
|
|
QRectF totalBoundingRect;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const QwtPlotItem* item : m_plotItems )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
totalBoundingRect = totalBoundingRect.united( item->boundingRect() );
|
2018-10-05 08:59:19 -05:00
|
|
|
}
|
|
|
|
return totalBoundingRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QwtGraphic RiuQwtPlotItemGroup::legendIcon( int index, const QSizeF& size ) const
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
|
|
|
QwtGraphic graphic;
|
2019-09-06 03:40:57 -05:00
|
|
|
graphic.setDefaultSize( size );
|
2018-10-05 08:59:19 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QPainter painter( &graphic );
|
|
|
|
painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) );
|
2018-10-05 08:59:19 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( QwtPlotItem* legendItem : m_legendItems )
|
2018-10-05 08:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QwtGraphic subGraphic = legendItem->legendIcon( index, legendItem->legendIconSize() );
|
|
|
|
QRectF boundingRect = legendItem->boundingRect();
|
|
|
|
QImage subImage = subGraphic.toImage();
|
|
|
|
QRectF subRect( 0.0, 0.0, legendItem->legendIconSize().width(), legendItem->legendIconSize().height() );
|
2018-10-05 08:59:19 -05:00
|
|
|
// Symbols may not have a bounding width/height. Force the width height to be the same as the icon
|
2019-09-06 03:40:57 -05:00
|
|
|
boundingRect.setWidth( subRect.width() );
|
|
|
|
boundingRect.setHeight( subRect.height() );
|
2018-10-05 08:59:19 -05:00
|
|
|
// Paint onto the existing icon
|
2019-09-06 03:40:57 -05:00
|
|
|
painter.drawImage( boundingRect, subImage, subRect );
|
2018-10-05 08:59:19 -05:00
|
|
|
}
|
|
|
|
return graphic;
|
|
|
|
}
|