-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "Plot2d_PlotItems.h"
#include "Plot2d_Object.h"
+#include "Plot2d_ViewFrame.h"
#include <QPainter>
#include <QPalette>
#include <QLayout>
#include <QLine>
#include <QVariant>
+#include <QStyleOption>
+#include <QPaintEvent>
+#include <QTileRules>
+
#include <qwt_plot.h>
#include <qwt_painter.h>
#include <qwt_scale_map.h>
#include <qwt_legend.h>
-#include <qwt_legend_item.h>
+#include <qwt_legend_label.h>
#include <qwt_plot_dict.h>
+const int SPACING = 10;
+const int SYMBOL_SIZE = 13;
+
const char* yAxisLeft[] = {
"12 12 2 1",
" c None",
" "};
/*!
- Constructor of Plot2d_QwtLegendItem
+ Constructor of Plot2d_QwtLegendLabel
*/
-Plot2d_QwtLegendItem::Plot2d_QwtLegendItem( QWidget* parent ) :
- QwtLegendItem( parent ),
+Plot2d_QwtLegendLabel::Plot2d_QwtLegendLabel( QWidget* parent ) :
+ QwtLegendLabel( parent ),
myYAxisIdentifierMode( IM_None ),
- myIsSelected(false)
+ myIsSelected(false),
+ mySymbol( new QwtSymbol() ),
+ mySymbolType(0),
+ myPen( QPen() )
{
- myYAxisLeftIcon = yAxisLeft;
- myYAxisRightIcon = yAxisRight;
+ myYAxisLeftIcon = QPixmap(yAxisLeft);
+ myYAxisRightIcon = QPixmap(yAxisRight);
int anIconWidth = qMax( myYAxisLeftIcon.width(), myYAxisRightIcon.width() );
+ setSpacing( SPACING );
mySpacingCollapsed = spacing();
- mySpacingExpanded = anIconWidth - mySpacingCollapsed;
+ mySpacingExpanded = anIconWidth + mySpacingCollapsed;
}
/*!
- Destructor of Plot2d_QwtLegendItem
+ Destructor of Plot2d_QwtLegendLabel
*/
-Plot2d_QwtLegendItem::~Plot2d_QwtLegendItem()
+Plot2d_QwtLegendLabel::~Plot2d_QwtLegendLabel()
{
+ delete mySymbol;
}
/*!
Set Y axis identifier displaying mode
*/
-void Plot2d_QwtLegendItem::setYAxisIdentifierMode( const int theMode )
+void Plot2d_QwtLegendLabel::setYAxisIdentifierMode( const int theMode )
{
myYAxisIdentifierMode = theMode;
setSpacing( theMode == IM_None ? mySpacingCollapsed : mySpacingExpanded );
}
/*!
- Redefined method of drawing identifier of legend item
+ Paint the identifier to a given rect.
+ \param painter Painter
+ \param rect Rect where to paint
*/
-void Plot2d_QwtLegendItem::drawIdentifier( QPainter* painter, const QRect& rect ) const
+void Plot2d_QwtLegendLabel::drawIdentifier( QPainter* painter, const QRect& rect )
{
- QwtLegendItem::drawIdentifier( painter, rect );
+ if ( rect.isEmpty() )
+ return;
+ if( myPen.style() != Qt::NoPen ) {
+ painter->save();
+ painter->setPen(myPen);
+ QwtPainter::drawLine( painter, rect.left() - 2, rect.center().y() + mySymbolType * 4,
+ rect.right() + 2, rect.center().y() + mySymbolType * 4 );
+ painter->restore();
+ }
+ if ( mySymbol->style() != QwtSymbol::NoSymbol )
+ {
+ QRect symbolRect;
+ symbolRect.setSize( QSize( SYMBOL_SIZE, SYMBOL_SIZE ) );
+ symbolRect.moveCenter( QPoint( rect.center().x(), rect.center().y() - mySymbolType * 4 ) );
+ painter->save();
+ painter->setBrush( mySymbol->brush() );
+ painter->setPen( mySymbol->pen() );
+ mySymbol->drawSymbol( painter, symbolRect );
+ painter->restore();
+ }
if( myYAxisIdentifierMode != IM_None ) {
QPixmap aPixmap( myYAxisIdentifierMode == IM_Left ? yAxisLeft : yAxisRight );
painter->save();
/*!
Update highliting on the item.
*/
-void Plot2d_QwtLegendItem::updateHighlit() {
+void Plot2d_QwtLegendLabel::updateHighlit() {
QwtText txt = text();
- if(isSelected()) {
+ if( isSelected() ) {
QColor highlightColor = Plot2d_Object::selectionColor();
- if(highlightColor != txt.backgroundBrush().color()) {
- txt.setBackgroundBrush(highlightColor);
+ if( highlightColor != txt.backgroundBrush().color() ) {
+ txt.setBackgroundBrush( highlightColor );
setText(txt);
}
- } else if( QWidget* parent = qobject_cast<QWidget*>(this->parent()->parent()) ) {
- QPalette aPal = parent->palette();
- if(aPal.color(QPalette::Background) != txt.backgroundBrush().color()) {
- txt.setBackgroundBrush(aPal.color(QPalette::Background));
- setText(txt);
+ }
+ else if( this->parent() ) {
+ if(QWidget* parent = qobject_cast<QWidget*>( this->parent()->parent() ) ) {
+ QPalette aPal = parent->palette();
+ if( aPal.color( QPalette::Background) != txt.backgroundBrush().color() ) {
+ txt.setBackgroundBrush( aPal.color( QPalette::Background ) );
+ setText( txt );
+ }
}
}
}
/*!
Sets selected property.
*/
-void Plot2d_QwtLegendItem::setSelected(const bool on) {
+void Plot2d_QwtLegendLabel::setSelected(const bool on) {
myIsSelected = on;
}
/*!
Gets selected property.
*/
-bool Plot2d_QwtLegendItem::isSelected() const {
+bool Plot2d_QwtLegendLabel::isSelected() const {
return myIsSelected;
}
/*
Draw text of the item.
*/
-void Plot2d_QwtLegendItem::drawText(QPainter * painter, const QRect &rect) {
+void Plot2d_QwtLegendLabel::drawText( QPainter * painter, const QRectF &rect ) {
painter->setPen( isSelected() ? Plot2d_Object::highlightedLegendTextColor() :
- getColorFromPalette( QPalette::Text) );
+ getColorFromPalette( QPalette::Text) );
- QwtLegendItem::drawText( painter, rect );
+ QwtTextLabel::drawText( painter, rect );
+}
+
+/*!
+ Sets symbol.
+*/
+void Plot2d_QwtLegendLabel::setSymbol( const QwtSymbol* theSymbol )
+{
+ delete mySymbol;
+ mySymbol = new QwtSymbol( theSymbol->style(), theSymbol->brush(),
+ theSymbol->pen(), theSymbol->size() );
+}
+
+/*!
+ Sets symbol type 0(marker on line) or 1(marker above line).
+*/
+void Plot2d_QwtLegendLabel::setSymbolType( const int theType )
+{
+ mySymbolType = theType;
+}
+
+/*!
+ Sets pen.
+*/
+void Plot2d_QwtLegendLabel::setPen (const QPen& thePen )
+{
+ myPen = thePen;
+}
+
+/*!
+ Redefined method paintEvent of QwtLegendLabel
+*/
+void Plot2d_QwtLegendLabel::paintEvent( QPaintEvent *e )
+{
+ const QRect cr = contentsRect();
+
+ int ButtonFrame = 6;
+ QPainter painter( this );
+ painter.setClipRegion( e->region() );
+
+ if ( isDown() )
+ {
+ qDrawWinButton( &painter, 0, 0, width(), height(),
+ palette(), true );
+ }
+
+ painter.save();
+ painter.setClipRect( cr );
+
+ drawContents( &painter );
+
+ QRect iconRect = cr;
+ if ( !icon().isNull() )
+ {
+ if ( itemMode() != QwtLegendData::ReadOnly ) {
+ iconRect.setX( iconRect.x() + ButtonFrame );
+ iconRect.setSize( QSize( icon().size().width() + spacing() ,
+ icon().size().height() + spacing() ) );
+ iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
+ }
+ }
+
+ drawIdentifier( &painter, iconRect );
+
+ painter.restore();
}
/*
Get color from the legend pallete by 'role' flag.
*/
-QColor Plot2d_QwtLegendItem::getColorFromPalette(QPalette::ColorRole role) {
+QColor Plot2d_QwtLegendLabel::getColorFromPalette(QPalette::ColorRole role) {
QWidget* pw = parentWidget();
QColor col = palette().color( role );
while( pw ) {
return qwtMin(myMin.size(), myMax.size());
}
bool values(size_t i, double &min, double &max) {
- if(myMin.contains(i) && myMax.contains(i)) {
- min = myMin[i];
- max = myMax[i];
+ if(myMin.contains((int)i) && myMax.contains((int)i)) { //!< TODO: conversion from size_t to int
+ min = myMin[(int)i];
+ max = myMax[(int)i];
return true;
}
return false;
*/
Plot2d_QwtPlotCurve::Plot2d_QwtPlotCurve( const QString& title,
QwtPlot::Axis yAxis /*const int index*/ ) :
- Plot2d_SelectableItem(),
QwtPlotCurve( title ),
+ Plot2d_SelectableItem(),
myYAxis( yAxis ),
myYAxisIdentifierEnabled( false ),
myDeviationData(0)
/*!
Redefined method, which updates legend of the curve
*/
-void Plot2d_QwtPlotCurve::updateLegend( QwtLegend* legend ) const
+void Plot2d_QwtPlotCurve::updateLegend( const QwtPlotItem* thePlotItem,
+ const QList<QwtLegendData>& theLegendData )
{
- if ( !legend )
+ if ( !thePlotItem || !thePlotItem->plot() )
return;
- QWidget* widget = legend->find( this );
-
- if ( testItemAttribute(QwtPlotItem::Legend) ) {
-
- if ( widget == NULL ) {
- widget = legendItem();
- if ( widget ) {
- if ( widget->inherits("QwtLegendItem") ) {
- QwtLegendItem *label = (QwtLegendItem *)widget;
- label->setItemMode(legend->itemMode());
-
- if ( plot() ) {
- QObject::connect(label, SIGNAL(clicked()),
- plot(), SLOT(legendItemClicked()));
- QObject::connect(label, SIGNAL(checked(bool)),
- plot(), SLOT(legendItemChecked(bool)));
- }
- }
- legend->contentsWidget()->layout()->addWidget(widget);
- legend->insert(this, widget);
- }
- }
-
- QwtPlotCurve::updateLegend( legend );
-
+ if ( !testItemAttribute( QwtPlotItem::Legend ) )
+ return;
- if( Plot2d_QwtLegendItem* anItem = dynamic_cast<Plot2d_QwtLegendItem*>( widget ) ) {
- int aMode = Plot2d_QwtLegendItem::IM_None;
- if( myYAxisIdentifierEnabled )
- aMode = myYAxis == QwtPlot::yRight ?
- Plot2d_QwtLegendItem::IM_Right :
- Plot2d_QwtLegendItem::IM_Left;
- anItem->setYAxisIdentifierMode( aMode );
- if(isSelected()) {
- anItem->setCurvePen(legendPen());
- anItem->setSymbol(legendSymbol());
+ QwtPlotCurve::updateLegend( thePlotItem, theLegendData );
+
+ const QVariant itemInfo = thePlotItem->plot()->itemToInfo( const_cast< QwtPlotItem *>( thePlotItem ) );
+ if( QwtLegend* legend = dynamic_cast<QwtLegend*>( thePlotItem->plot()->legend() ) ) {
+ if( QWidget* widget = legend->legendWidget( itemInfo ) ) {
+ QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( widget );
+ if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)label ) {
+ int aMode = Plot2d_QwtLegendLabel::IM_None;
+ if( myYAxisIdentifierEnabled )
+ aMode = myYAxis == QwtPlot::yRight ?
+ Plot2d_QwtLegendLabel::IM_Right :
+ Plot2d_QwtLegendLabel::IM_Left;
+ anItem->setYAxisIdentifierMode( aMode );
+
+ anItem->setSymbol( legendSymbol() );
+ if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
+ anItem->setSymbolType( plot->getLegendSymbolType() );
+ anItem->setPen( legendPen() );
+
+ anItem->setSelected( isSelected() );
+ anItem->updateHighlit();
+ anItem->repaint();
}
- anItem->setSelected(isSelected());
- anItem->updateHighlit();
}
}
}
/*!
- Redefined method, which creates and returns legend item of the curve
+ Redefined method, which updates and calls QwtPlot::autoRefresh() for the parent plot
*/
-QWidget* Plot2d_QwtPlotCurve::legendItem() const
+void Plot2d_QwtPlotCurve::itemChanged()
{
- return new Plot2d_QwtLegendItem;
+ if ( plot() )
+ updateLegend( this, legendData() );
+
+ QwtPlotItem::itemChanged();
}
/*!
Redefined method, which draw a set of points of a curve.
*/
-void Plot2d_QwtPlotCurve::draw(QPainter *painter,
- const QwtScaleMap &xMap, const QwtScaleMap &yMap,
- int from, int to) const
+void Plot2d_QwtPlotCurve::drawSeries( QPainter *painter,
+ const QwtScaleMap &xMap,
+ const QwtScaleMap &yMap,
+ const QRectF &canvasRect,
+ int from, int to) const
{
if (to < 0)
- to = dataSize() - 1;
- QwtPlotCurve::draw(painter, xMap, yMap, from, to);
+ to = (int)dataSize() - 1; //!< TODO: conversion from size_t to int
+ QwtPlotCurve::drawSeries(painter, xMap, yMap, canvasRect, from, to);
//draw deviation data
if(hasDeviationData()) {
painter->save();
int lineW = deviationMarkerLineWidth();
- int tickSz = deviationMarkerTickSize() + qRound(lineW/2);
+ int tickSz = deviationMarkerTickSize() + qRound(double(lineW)/2);
double min, max, xi, yi;
int xp, ytop, ybtm, tickl, tickr;
QColor c = isSelected() ? Plot2d_Object::selectionColor() : deviationMarkerColor();
painter->setPen(p);
for (int i = from; i <= to; i++) {
if(!myDeviationData->values(i,min,max)) continue;
- xi = x(i);
- yi = y(i);
+ const QPointF sample = data()->sample( i );
+ xi = sample.x();
+ yi = sample.y();
xp = xMap.transform(xi);
ytop = yMap.transform(yi + max);
ybtm = yMap.transform(yi - min);
painter->drawLine(xp,ytop,xp,ybtm);
painter->drawLine(tickl,ybtm,tickr,ybtm);
}
- painter->restore();
+ painter->restore();
}
}
Constructor.
*/
Plot2d_SelectableItem::Plot2d_SelectableItem():
- myIsSelected(false)
+ myIsSelected(false),
+ myLegendPen( QPen() ),
+ myLegendSymbol( new QwtSymbol() )
{
}
/*!
Sets legend symbol property.
*/
-void Plot2d_SelectableItem::setLegendSymbol(const QwtSymbol& s) {
- myLegendSymbol = s;
+void Plot2d_SelectableItem::setLegendSymbol( const QwtSymbol* s ) {
+ myLegendSymbol->setStyle( s->style() );
+ myLegendSymbol->setBrush( s->brush() );
+ myLegendSymbol->setPen( s->pen() );
+ myLegendSymbol->setSize( s->size() );
}
/*!
Sets legend symbol property.
*/
-QwtSymbol Plot2d_SelectableItem::legendSymbol() const {
- return myLegendSymbol;
+QwtSymbol* Plot2d_SelectableItem::legendSymbol() const {
+ return new QwtSymbol( myLegendSymbol->style(), myLegendSymbol->brush(),
+ myLegendSymbol->pen(), myLegendSymbol->size() );
}
/*!
/*!
Sets data to object
*/
-void Plot2d_HistogramQwtItem::setData( const QwtIntervalData& theData )
+void Plot2d_HistogramQwtItem::setData( const QwtIntervalSeriesData& theData )
{
- myData = theData;
+ myData.setSamples( theData.samples() );
itemChanged();
}
/*!
Returns data from object
*/
-const QwtIntervalData& Plot2d_HistogramQwtItem::data() const
+const QwtIntervalSeriesData& Plot2d_HistogramQwtItem::data() const
{
return myData;
}
Sets histogram attributes
*/
void Plot2d_HistogramQwtItem::setHistogramAttribute( HistogramAttribute theAttr,
- bool isOn )
+ bool isOn )
{
if ( testHistogramAttribute( theAttr ) != isOn ) {
if ( isOn )
Draws histogram object
*/
void Plot2d_HistogramQwtItem::draw( QPainter* thePainter,
- const QwtScaleMap& theXMap,
- const QwtScaleMap& theYMap,
- const QRect& ) const
+ const QwtScaleMap& theXMap,
+ const QwtScaleMap& theYMap,
+ const QRectF& ) const
{
thePainter->setPen( QPen( myColor ) );
for ( int i = 0; i < (int)myData.size(); i++ ) {
if ( myAttributes & Plot2d_HistogramQwtItem::Xfy ) {
- const int x2 = theXMap.transform( myData.value( i ) );
+ const int x2 = theXMap.transform( myData.sample(i).value );
if ( x2 == x0 )
continue;
- int y1 = theYMap.transform( myData.interval( i ).minValue() );
- int y2 = theYMap.transform( myData.interval( i ).maxValue() );
+ int y1 = theYMap.transform( myData.sample( i ).interval.minValue() );
+ int y2 = theYMap.transform( myData.sample( i ).interval.maxValue() );
if ( y1 > y2 )
qSwap( y1, y2 );
if ( i < (int)myData.size() - 2 ) {
- const int yy1 = theYMap.transform( myData.interval(i+1).minValue() );
- const int yy2 = theYMap.transform( myData.interval(i+1).maxValue() );
+ const int yy1 = theYMap.transform( myData.sample(i+1).interval.minValue() );
+ const int yy2 = theYMap.transform( myData.sample(i+1).interval.maxValue() );
if ( y2 == qwtMin( yy1, yy2 ) ) {
- const int xx2 = theXMap.transform( myData.interval(i+1).minValue() );
+ const int xx2 = theXMap.transform( myData.sample(i+1).interval.minValue() );
if ( xx2 != x0 && ( ( xx2 < x0 && x2 < x0 ) ||
( xx2 > x0 && x2 > x0 ) ) ) {
// One pixel distance between neighboured bars
drawBar( thePainter, Qt::Horizontal, QRect( x0, y1, x2 - x0, y2 - y1 ) );
}
else {
- const int y2 = theYMap.transform( myData.value( i ) );
+ const int y2 = theYMap.transform( myData.sample( i ).value );
if ( y2 == y0 )
continue;
- int x1 = theXMap.transform( myData.interval( i ).minValue() );
- int x2 = theXMap.transform( myData.interval( i ).maxValue() );
+ int x1 = theXMap.transform( myData.sample( i ).interval.minValue() );
+ int x2 = theXMap.transform( myData.sample( i ).interval.maxValue() );
if ( x1 > x2 )
qSwap( x1, x2 );
if ( i < (int)myData.size() - 2 ) {
- const int xx1 = theXMap.transform( myData.interval(i+1).minValue() );
- const int xx2 = theXMap.transform( myData.interval(i+1).maxValue() );
+ const int xx1 = theXMap.transform( myData.sample(i+1).interval.minValue() );
+ const int xx2 = theXMap.transform( myData.sample(i+1).interval.maxValue() );
if ( x2 == qwtMin( xx1, xx2 ) ) {
- const int yy2 = theYMap.transform( myData.value(i+1) );
+ const int yy2 = theYMap.transform( myData.sample(i+1).value );
if ( yy2 != y0 && ( ( yy2 < y0 && y2 < y0 ) ||
( yy2 > y0 && y2 > y0 ) ) ) {
// One pixel distance between neighboured bars
Draws single bar of histogram
*/
void Plot2d_HistogramQwtItem::drawBar( QPainter* thePainter,
- Qt::Orientation,
- const QRect& theRect ) const
+ Qt::Orientation,
+ const QRect& theRect ) const
{
thePainter->save();
/*!
Set to legend item symbol with color of item
*/
-void Plot2d_HistogramItem::updateLegend( QwtLegend* theLegend ) const
+void Plot2d_HistogramItem::updateLegend( const QwtPlotItem* thePlotItem,
+ const QList<QwtLegendData>& theLegendData )
{
- if ( !theLegend )
+ if ( !thePlotItem || !thePlotItem->plot() )
return;
- Plot2d_HistogramQwtItem::updateLegend( theLegend );
+ Plot2d_HistogramQwtItem::updateLegend( thePlotItem, theLegendData );
+
+ const QVariant itemInfo = thePlotItem->plot()->itemToInfo( const_cast< QwtPlotItem *>( thePlotItem ) );
+ QwtLegend *legend = dynamic_cast<QwtLegend *>( thePlotItem->plot()->legend() );
+ QWidget* widget = legend->legendWidget( itemInfo );
- QWidget* theWidget = theLegend->find( this );
- if ( !theWidget || !theWidget->inherits( "QwtLegendItem" ) )
+ if ( !widget || !widget->inherits( "QwtLegendLabel" ) )
return;
- Plot2d_QwtLegendItem* anItem = ( Plot2d_QwtLegendItem* )theWidget;
- QFontMetrics aFMetrics( anItem->font() );
- int aSize = aFMetrics.height();
- QwtSymbol aSymbol( QwtSymbol::Rect, QBrush( legendPen().color() ),
- QPen( legendPen().color() ), QSize( aSize, aSize ) );
- anItem->setSymbol( aSymbol );
- anItem->setIdentifierMode( theLegend->identifierMode()
- | QwtLegendItem::ShowSymbol );
- anItem->setSelected(isSelected());
- anItem->updateHighlit();
- anItem->update();
+ QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( widget );
+ if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)( label ) ) {
+ QFontMetrics aFMetrics( anItem->font() );
+ int aSize = aFMetrics.height();
+ QPen aPen( legendPen().color() );
+ aPen.setStyle(Qt::NoPen);
+ anItem->setPen(aPen);
+ QwtSymbol* aSymbol = new QwtSymbol( QwtSymbol::Rect, QBrush( legendPen().color() ),
+ aPen, QSize( aSize, aSize ) );
+ anItem->setSymbol( aSymbol );
+ if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
+ anItem->setSymbolType( plot->getLegendSymbolType() );
+ anItem->setSelected( isSelected() );
+ anItem->updateHighlit();
+ anItem->update();
+ anItem->repaint();
+ }
}
/*!
Draws histogram object
*/
void Plot2d_HistogramItem::draw( QPainter* thePainter,
- const QwtScaleMap& theXMap,
- const QwtScaleMap& theYMap,
- const QRect& ) const
+ const QwtScaleMap& theXMap,
+ const QwtScaleMap& theYMap,
+ const QRectF& ) const
{
// nds: clear list of bar items
Plot2d_HistogramItem* anItem = (Plot2d_HistogramItem*)this;
const int x0 = theXMap.transform( baseline() );
const int y0 = theYMap.transform( baseline() );
- const QwtIntervalData& iData = data();
+ const QwtIntervalSeriesData& iData = data();
for ( int i = 0; i < (int)iData.size(); i++ ) {
if ( testHistogramAttribute( Plot2d_HistogramItem::Xfy ) ) {
- const int x2 = theXMap.transform( iData.value( i ) );
+ const int x2 = theXMap.transform( iData.sample(i).value );
if ( x2 == x0 )
continue;
- int y1 = theYMap.transform( iData.interval( i ).minValue() );
- int y2 = theYMap.transform( iData.interval( i ).maxValue() );
+ int y1 = theYMap.transform( iData.sample(i).interval.minValue() );
+ int y2 = theYMap.transform( iData.sample(i).interval.maxValue() );
if ( y1 > y2 )
qSwap( y1, y2 );
if ( i < (int)iData.size() - 2 ) {
- const int yy1 = theYMap.transform( iData.interval(i+1).minValue() );
- const int yy2 = theYMap.transform( iData.interval(i+1).maxValue() );
+ const int yy1 = theYMap.transform( iData.sample(i+1).interval.minValue() );
+ const int yy2 = theYMap.transform( iData.sample(i+1).interval.maxValue() );
if ( y2 == qwtMin( yy1, yy2 ) ) {
- const int xx2 = theXMap.transform( iData.interval(i+1).minValue() );
+ const int xx2 = theXMap.transform( iData.sample(i+1).interval.minValue() );
if ( xx2 != x0 && ( ( xx2 < x0 && x2 < x0 ) ||
( xx2 > x0 && x2 > x0 ) ) ) {
// One pixel distance between neighboured bars
anItem->myBarItems.append( aRect );
}
else {
- const int y2 = theYMap.transform( iData.value( i ) );
+ const int y2 = theYMap.transform( iData.sample(i).value );
if ( y2 == y0 )
continue;
- int x1 = theXMap.transform( iData.interval( i ).minValue() );
- int x2 = theXMap.transform( iData.interval( i ).maxValue() );
+ int x1 = theXMap.transform( iData.sample(i).interval.minValue() );
+ int x2 = theXMap.transform( iData.sample(i).interval.maxValue() );
if ( x1 > x2 )
qSwap( x1, x2 );
if ( i < (int)iData.size() - 2 ) {
- const int xx1 = theXMap.transform( iData.interval(i+1).minValue() );
- const int xx2 = theXMap.transform( iData.interval(i+1).maxValue() );
+ const int xx1 = theXMap.transform( iData.sample(i+1).interval.minValue() );
+ const int xx2 = theXMap.transform( iData.sample(i+1).interval.maxValue() );
if ( x2 == qwtMin( xx1, xx2 ) ) {
- const int yy2 = theYMap.transform( iData.value(i+1) );
+ const int yy2 = theYMap.transform( iData.sample(i+1).value );
if ( yy2 != y0 && ( ( yy2 < y0 && y2 < y0 ) ||
( yy2 > y0 && y2 > y0 ) ) ) {
// One pixel distance between neighboured bars
return myCrossed;
}
-/*!
- Redefined method, which creates and returns legend item of the curve
-*/
-QWidget* Plot2d_HistogramItem::legendItem() const
-{
- return new Plot2d_QwtLegendItem;
-}
-
-
/*!
Draws bar of histogram and on it bars of histograms with lower height.
*/
void Plot2d_HistogramItem::drawRectAndLowers( QPainter* thePainter,
- Qt::Orientation theOr,
- const QRect& theRect ) const
+ Qt::Orientation /*theOr*/,
+ const QRect& theRect ) const
{
QRect aRect = theRect;
// theRect has inversed coordinates on Y axis.
drawBar( thePainter, Qt::Horizontal, aRect );
}
+void Plot2d_HistogramItem::itemChanged()
+{
+ if ( plot() )
+ updateLegend( this, legendData() );
+
+ QwtPlotItem::itemChanged();
+}
+
+
/*!
Returns top value of the given rect in the context of other bars.
qMin( theRect.left(), aRects[i].left() ) ) {
if ( theRect.bottom() < aRects[i].bottom() )
if ( aRects[i].bottom() < aRes )
- aRes = aRects[i].bottom();
+ aRes = aRects[i].bottom();
}
}
}
}
return aRes;
}
+
+QwtGraphic Plot2d_HistogramItem::legendIcon( int /*index*/, const QSizeF &size ) const
+{
+ return defaultIcon( color(), size );
+}
+
+Plot2d_QwtLegend::Plot2d_QwtLegend( QWidget *parent ):
+QwtLegend( parent )
+{
+ setAutoFillBackground(true);
+}
+
+Plot2d_QwtLegend::~Plot2d_QwtLegend()
+{
+}
+
+/*!
+ Redefined method, which create a widget to be inserted into the legend.
+*/
+QWidget *Plot2d_QwtLegend::createWidget( const QwtLegendData& /*data*/ ) const
+{
+ Plot2d_QwtLegendLabel *label = new Plot2d_QwtLegendLabel();
+ label->setItemMode( defaultItemMode() );
+
+ connect( label, SIGNAL( clicked() ), SLOT( itemClicked() ) );
+ connect( label, SIGNAL( checked( bool ) ), SLOT( itemChecked( bool ) ) );
+
+ return label;
+}