1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : Plot2d_PlotItems.cxx
23 // Author : Natalia ERMOLAEVA, Open CASCADE S.A.S. (natalia.donis@opencascade.com)
25 #include "Plot2d_PlotItems.h"
26 #include "Plot2d_Object.h"
27 #include "Plot2d_ViewFrame.h"
34 #include <QStyleOption>
35 #include <QPaintEvent>
37 #include <qwt_painter.h>
38 #include <qwt_scale_map.h>
39 #include <qwt_legend.h>
40 #include <qwt_legend_label.h>
41 #include <qwt_plot_dict.h>
43 const int SPACING = 10;
44 const int SYMBOL_SIZE = 13;
46 const char* yAxisLeft[] = {
63 const char* yAxisRight[] = {
81 Constructor of Plot2d_QwtLegendLabel
83 Plot2d_QwtLegendLabel::Plot2d_QwtLegendLabel( QWidget* parent ) :
84 QwtLegendLabel( parent ),
85 myYAxisIdentifierMode( IM_None ),
87 mySymbol( new QwtSymbol() ),
91 myYAxisLeftIcon = yAxisLeft;
92 myYAxisRightIcon = yAxisRight;
93 int anIconWidth = qMax( myYAxisLeftIcon.width(), myYAxisRightIcon.width() );
94 setSpacing( SPACING );
96 mySpacingCollapsed = spacing();
97 mySpacingExpanded = anIconWidth + mySpacingCollapsed;
101 Destructor of Plot2d_QwtLegendLabel
103 Plot2d_QwtLegendLabel::~Plot2d_QwtLegendLabel()
108 Set Y axis identifier displaying mode
110 void Plot2d_QwtLegendLabel::setYAxisIdentifierMode( const int theMode )
112 myYAxisIdentifierMode = theMode;
113 setSpacing( theMode == IM_None ? mySpacingCollapsed : mySpacingExpanded );
117 Paint the identifier to a given rect.
118 \param painter Painter
119 \param rect Rect where to paint
121 void Plot2d_QwtLegendLabel::drawIdentifier( QPainter* painter, const QRect& rect )
123 if ( rect.isEmpty() )
126 if( myPen.style() != Qt::NoPen ) {
128 painter->setPen(myPen);
129 QwtPainter::drawLine( painter, rect.left() - 2, rect.center().y() + mySymbolType * 4,
130 rect.right() + 2, rect.center().y() + mySymbolType * 4 );
133 if ( mySymbol->style() != QwtSymbol::NoSymbol )
136 symbolRect.setSize( QSize( SYMBOL_SIZE, SYMBOL_SIZE ) );
137 symbolRect.moveCenter( QPoint( rect.center().x(), rect.center().y() - mySymbolType * 4 ) );
139 painter->setBrush( mySymbol->brush() );
140 painter->setPen( mySymbol->pen() );
141 mySymbol->drawSymbol( painter, symbolRect );
144 if( myYAxisIdentifierMode != IM_None ) {
145 QPixmap aPixmap( myYAxisIdentifierMode == IM_Left ? yAxisLeft : yAxisRight );
147 painter->drawPixmap( rect.topRight() + QPoint( mySpacingExpanded/2, mySpacingExpanded/2 ), aPixmap );
153 Update highliting on the item.
155 void Plot2d_QwtLegendLabel::updateHighlit() {
156 QwtText txt = text();
158 QColor highlightColor = Plot2d_Object::selectionColor();
159 if( highlightColor != txt.backgroundBrush().color() ) {
160 txt.setBackgroundBrush( highlightColor );
164 else if( this->parent() ) {
165 if(QWidget* parent = qobject_cast<QWidget*>( this->parent()->parent() ) ) {
166 QPalette aPal = parent->palette();
167 if( aPal.color( QPalette::Background) != txt.backgroundBrush().color() ) {
168 txt.setBackgroundBrush( aPal.color( QPalette::Background ) );
176 Sets selected property.
178 void Plot2d_QwtLegendLabel::setSelected(const bool on) {
183 Gets selected property.
185 bool Plot2d_QwtLegendLabel::isSelected() const {
191 Draw text of the item.
193 void Plot2d_QwtLegendLabel::drawText( QPainter * painter, const QRectF &rect ) {
194 painter->setPen( isSelected() ? Plot2d_Object::highlightedLegendTextColor() :
195 getColorFromPalette( QPalette::Text) );
197 QwtTextLabel::drawText( painter, rect );
203 void Plot2d_QwtLegendLabel::setSymbol( const QwtSymbol* theSymbol )
205 mySymbol = new QwtSymbol( theSymbol->style(), theSymbol->brush(),
206 theSymbol->pen(), theSymbol->size() );
210 Sets symbol type 0(marker on line) or 1(marker above line).
212 void Plot2d_QwtLegendLabel::setSymbolType( const int theType )
214 mySymbolType = theType;
220 void Plot2d_QwtLegendLabel::setPen (const QPen& thePen )
226 Redefined method paintEvent of QwtLegendLabel
228 void Plot2d_QwtLegendLabel::paintEvent( QPaintEvent *e )
230 const QRect cr = contentsRect();
233 QPainter painter( this );
234 painter.setClipRegion( e->region() );
238 qDrawWinButton( &painter, 0, 0, width(), height(),
243 painter.setClipRect( cr );
245 drawContents( &painter );
248 if ( !icon().isNull() )
250 if ( itemMode() != QwtLegendData::ReadOnly )
251 iconRect.setX( iconRect.x() + ButtonFrame );
252 iconRect.setSize( QSize( icon().size().width() + spacing() ,
253 icon().size().height() + spacing() ) );
254 iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
257 drawIdentifier( &painter, iconRect );
263 Get color from the legend pallete by 'role' flag.
265 QColor Plot2d_QwtLegendLabel::getColorFromPalette(QPalette::ColorRole role) {
266 QWidget* pw = parentWidget();
267 QColor col = palette().color( role );
269 if ( qobject_cast<QwtLegend*>( pw ) ) {
270 col = pw->palette().color(role );
273 pw = pw->parentWidget();
278 * Internal class to store deviation data on the curve.
280 class Plot2d_QwtPlotCurve::Plot2d_DeviationData {
282 Plot2d_DeviationData(const double *min, const double *max,const QList<int>& idx)
284 foreach(int index,idx) {
285 myMin[index] = min[index];
286 myMax[index] = max[index];
289 ~Plot2d_DeviationData(){}
293 return qwtMin(myMin.size(), myMax.size());
295 bool values(size_t i, double &min, double &max) {
296 if(myMin.contains(i) && myMax.contains(i)) {
304 QMap<int,double> myMin;
305 QMap<int,double> myMax;
310 Constructor of Plot2d_QwtPlotCurve
312 Plot2d_QwtPlotCurve::Plot2d_QwtPlotCurve( const QString& title,
313 QwtPlot::Axis yAxis /*const int index*/ ) :
314 Plot2d_SelectableItem(),
315 QwtPlotCurve( title ),
317 myYAxisIdentifierEnabled( false ),
323 Destructor of Plot2d_QwtPlotCurve
325 Plot2d_QwtPlotCurve::~Plot2d_QwtPlotCurve()
327 clearDeviationData();
331 Enable / disable Y axis identifier
333 void Plot2d_QwtPlotCurve::setYAxisIdentifierEnabled( const bool on )
335 myYAxisIdentifierEnabled = on;
339 Redefined method, which updates legend of the curve
341 void Plot2d_QwtPlotCurve::updateLegend( const QwtPlotItem* thePlotItem,
342 const QList<QwtLegendData>& theLegendData )
344 if ( !thePlotItem || !thePlotItem->plot() )
347 if ( !testItemAttribute( QwtPlotItem::Legend ) )
350 QwtPlotCurve::updateLegend( thePlotItem, theLegendData );
352 const QVariant itemInfo = thePlotItem->plot()->itemToInfo( const_cast< QwtPlotItem *>( thePlotItem ) );
353 if( QwtLegend* legend = dynamic_cast<QwtLegend*>( thePlotItem->plot()->legend() ) ) {
354 if( QWidget* widget = legend->legendWidget( itemInfo ) ) {
355 QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( widget );
356 if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)label ) {
357 int aMode = Plot2d_QwtLegendLabel::IM_None;
358 if( myYAxisIdentifierEnabled )
359 aMode = myYAxis == QwtPlot::yRight ?
360 Plot2d_QwtLegendLabel::IM_Right :
361 Plot2d_QwtLegendLabel::IM_Left;
362 anItem->setYAxisIdentifierMode( aMode );
364 anItem->setSymbol( legendSymbol() );
365 if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
366 anItem->setSymbolType( plot->getLegendSymbolType() );
367 anItem->setPen( legendPen() );
369 anItem->setSelected( isSelected() );
370 anItem->updateHighlit();
378 Redefined method, which updates and calls QwtPlot::autoRefresh() for the parent plot
380 void Plot2d_QwtPlotCurve::itemChanged()
383 updateLegend( this, legendData() );
385 QwtPlotItem::itemChanged();
389 Redefined method, which draw a set of points of a curve.
391 void Plot2d_QwtPlotCurve::drawSeries( QPainter *painter,
392 const QwtScaleMap &xMap,
393 const QwtScaleMap &yMap,
394 const QRectF &canvasRect,
395 int from, int to) const
399 QwtPlotCurve::drawSeries(painter, xMap, yMap, canvasRect, from, to);
401 //draw deviation data
402 if(hasDeviationData()) {
404 int lineW = deviationMarkerLineWidth();
405 int tickSz = deviationMarkerTickSize() + qRound(lineW/2);
406 double min, max, xi, yi;
407 int xp, ytop, ybtm, tickl, tickr;
408 QColor c = isSelected() ? Plot2d_Object::selectionColor() : deviationMarkerColor();
409 QPen p = QPen(c, lineW, Qt::SolidLine);
411 for (int i = from; i <= to; i++) {
412 if(!myDeviationData->values(i,min,max)) continue;
413 const QPointF sample = data()->sample( i );
416 xp = xMap.transform(xi);
417 ytop = yMap.transform(yi + max);
418 ybtm = yMap.transform(yi - min);
421 painter->drawLine(tickl,ytop,tickr,ytop);
422 painter->drawLine(xp,ytop,xp,ybtm);
423 painter->drawLine(tickl,ybtm,tickr,ybtm);
430 * Return color of the deviation marker.
432 QColor Plot2d_QwtPlotCurve::deviationMarkerColor() const {
435 QVariant var = plot()->property(PLOT2D_DEVIATION_COLOR);
437 c = var.value<QColor>();
442 * Return line width of the deviation marker.
444 int Plot2d_QwtPlotCurve::deviationMarkerLineWidth() const {
447 QVariant var = plot()->property(PLOT2D_DEVIATION_LW);
455 * Return tick size of the deviation marker.
457 int Plot2d_QwtPlotCurve::deviationMarkerTickSize() const {
460 QVariant var = plot()->property(PLOT2D_DEVIATION_TS);
468 * Sets deviation data for the plot item.
470 void Plot2d_QwtPlotCurve::setDeviationData(const double* min, const double* max,const QList<int> &idx) {
471 clearDeviationData();
472 myDeviationData = new Plot2d_DeviationData(min,max,idx);
476 * Return true if deviation is assigned to the plot item,
479 bool Plot2d_QwtPlotCurve::hasDeviationData() const {
480 return myDeviationData != 0;
484 * Remove deviation data from the plot item.
486 void Plot2d_QwtPlotCurve::clearDeviationData()
489 delete myDeviationData;
498 Plot2d_SelectableItem::Plot2d_SelectableItem():
500 myLegendSymbol( new QwtSymbol() ),
501 myLegendPen( QPen() )
508 Plot2d_SelectableItem::~Plot2d_SelectableItem()
513 Sets selected property.
515 void Plot2d_SelectableItem::setSelected( const bool on) {
520 Return selected property.
522 bool Plot2d_SelectableItem::isSelected() const {
527 Sets legend pen property.
529 void Plot2d_SelectableItem::setLegendPen( const QPen & p) {
534 Return legend pen property.
536 QPen Plot2d_SelectableItem::legendPen() const {
541 Sets legend symbol property.
543 void Plot2d_SelectableItem::setLegendSymbol( const QwtSymbol* s ) {
544 myLegendSymbol->setStyle( s->style() );
545 myLegendSymbol->setBrush( s->brush() );
546 myLegendSymbol->setPen( s->pen() );
547 myLegendSymbol->setSize( s->size() );
551 Sets legend symbol property.
553 QwtSymbol* Plot2d_SelectableItem::legendSymbol() const {
554 return new QwtSymbol( myLegendSymbol->style(), myLegendSymbol->brush(),
555 myLegendSymbol->pen(), myLegendSymbol->size() );
561 Plot2d_HistogramQwtItem::Plot2d_HistogramQwtItem( const QwtText& theTitle )
562 : QwtPlotItem( theTitle )
570 Plot2d_HistogramQwtItem::Plot2d_HistogramQwtItem( const QString& theTitle )
571 : QwtPlotItem( QwtText( theTitle ) )
579 Plot2d_HistogramQwtItem::~Plot2d_HistogramQwtItem()
584 Initialization of object
586 void Plot2d_HistogramQwtItem::init()
589 myAttributes = Plot2d_HistogramQwtItem::Auto;
591 setItemAttribute( QwtPlotItem::AutoScale, true );
592 setItemAttribute( QwtPlotItem::Legend, true );
598 Sets base line to object
601 void Plot2d_HistogramQwtItem::setBaseline( double theRef )
603 if ( myReference != theRef ) {
604 myReference = theRef;
610 Returns base line of object
612 double Plot2d_HistogramQwtItem::baseline() const
620 void Plot2d_HistogramQwtItem::setData( const QwtIntervalSeriesData& theData )
622 myData.setSamples( theData.samples() );
627 Returns data from object
629 const QwtIntervalSeriesData& Plot2d_HistogramQwtItem::data() const
637 void Plot2d_HistogramQwtItem::setColor( const QColor& theColor )
639 if ( myColor != theColor ) {
646 Returns color from object
648 QColor Plot2d_HistogramQwtItem::color() const
654 Returns bounding rect of object
656 QwtDoubleRect Plot2d_HistogramQwtItem::boundingRect() const
658 QwtDoubleRect aRect = myData.boundingRect();
659 if ( !aRect.isValid() )
662 if ( myAttributes & Xfy ) {
663 aRect = QwtDoubleRect( aRect.y(), aRect.x(),
664 aRect.height(), aRect.width() );
665 if ( aRect.left() > myReference )
666 aRect.setLeft( myReference );
667 else if ( aRect.right() < myReference )
668 aRect.setRight( myReference );
671 if ( aRect.bottom() < myReference )
672 aRect.setBottom( myReference );
673 else if ( aRect.top() > myReference )
674 aRect.setTop( myReference );
680 Returns type of plot object
682 int Plot2d_HistogramQwtItem::rtti() const
684 return QwtPlotItem::Rtti_PlotHistogram;
688 Sets histogram attributes
690 void Plot2d_HistogramQwtItem::setHistogramAttribute( HistogramAttribute theAttr,
693 if ( testHistogramAttribute( theAttr ) != isOn ) {
695 myAttributes |= theAttr;
697 myAttributes &= ~theAttr;
704 Tests histogram attributes
706 bool Plot2d_HistogramQwtItem::testHistogramAttribute( HistogramAttribute theAttr ) const
708 return myAttributes & theAttr;
712 Draws histogram object
714 void Plot2d_HistogramQwtItem::draw( QPainter* thePainter,
715 const QwtScaleMap& theXMap,
716 const QwtScaleMap& theYMap,
717 const QRectF& ) const
719 thePainter->setPen( QPen( myColor ) );
721 const int x0 = theXMap.transform( baseline() );
722 const int y0 = theYMap.transform( baseline() );
724 for ( int i = 0; i < (int)myData.size(); i++ ) {
725 if ( myAttributes & Plot2d_HistogramQwtItem::Xfy ) {
726 const int x2 = theXMap.transform( myData.sample(i).value );
729 int y1 = theYMap.transform( myData.sample( i ).interval.minValue() );
730 int y2 = theYMap.transform( myData.sample( i ).interval.maxValue() );
734 if ( i < (int)myData.size() - 2 ) {
735 const int yy1 = theYMap.transform( myData.sample(i+1).interval.minValue() );
736 const int yy2 = theYMap.transform( myData.sample(i+1).interval.maxValue() );
737 if ( y2 == qwtMin( yy1, yy2 ) ) {
738 const int xx2 = theXMap.transform( myData.sample(i+1).interval.minValue() );
739 if ( xx2 != x0 && ( ( xx2 < x0 && x2 < x0 ) ||
740 ( xx2 > x0 && x2 > x0 ) ) ) {
741 // One pixel distance between neighboured bars
746 drawBar( thePainter, Qt::Horizontal, QRect( x0, y1, x2 - x0, y2 - y1 ) );
749 const int y2 = theYMap.transform( myData.sample( i ).value );
752 int x1 = theXMap.transform( myData.sample( i ).interval.minValue() );
753 int x2 = theXMap.transform( myData.sample( i ).interval.maxValue() );
757 if ( i < (int)myData.size() - 2 ) {
758 const int xx1 = theXMap.transform( myData.sample(i+1).interval.minValue() );
759 const int xx2 = theXMap.transform( myData.sample(i+1).interval.maxValue() );
760 if ( x2 == qwtMin( xx1, xx2 ) ) {
761 const int yy2 = theYMap.transform( myData.sample(i+1).value );
762 if ( yy2 != y0 && ( ( yy2 < y0 && y2 < y0 ) ||
763 ( yy2 > y0 && y2 > y0 ) ) ) {
764 // One pixel distance between neighboured bars
769 drawBar( thePainter, Qt::Vertical, QRect( x1, y0, x2 - x1, y2 - y0 ) );
775 Draws single bar of histogram
777 void Plot2d_HistogramQwtItem::drawBar( QPainter* thePainter,
779 const QRect& theRect ) const
783 const QColor color( thePainter->pen().color() );
784 QRect r = theRect.normalized();
786 const int factor = 125;
787 const QColor light( color.light( factor ) );
788 const QColor dark( color.dark( factor ) );
790 thePainter->setBrush( color );
791 thePainter->setPen( Qt::NoPen );
792 QwtPainter::drawRect( thePainter, r.x() + 1, r.y() + 1,
793 r.width() - 2, r.height() - 2 );
794 thePainter->setBrush( Qt::NoBrush );
796 thePainter->setPen( QPen( light, 2 ) );
797 QwtPainter::drawLine( thePainter, r.left() + 1, r.top() + 2,
798 r.right() + 1, r.top() + 2 );
800 thePainter->setPen( QPen( dark, 2 ) );
801 QwtPainter::drawLine( thePainter, r.left() + 1, r.bottom(),
802 r.right() + 1, r.bottom() );
803 thePainter->setPen( QPen( light, 1 ) );
805 QwtPainter::drawLine( thePainter, r.left(), r.top() + 1,
806 r.left(), r.bottom() );
807 QwtPainter::drawLine( thePainter, r.left() + 1, r.top() + 2,
808 r.left() + 1, r.bottom() - 1 );
809 thePainter->setPen( QPen( dark, 1 ) );
811 QwtPainter::drawLine( thePainter, r.right() + 1, r.top() + 1,
812 r.right() + 1, r.bottom() );
813 QwtPainter::drawLine(thePainter, r.right(), r.top() + 2,
814 r.right(), r.bottom() - 1 );
815 thePainter->restore();
821 Plot2d_HistogramItem::Plot2d_HistogramItem( const QwtText& theTitle )
822 : Plot2d_HistogramQwtItem( theTitle ),
823 Plot2d_SelectableItem(),
831 Plot2d_HistogramItem::Plot2d_HistogramItem( const QString& theTitle )
832 : Plot2d_HistogramQwtItem( theTitle ),
840 Plot2d_HistogramItem::~Plot2d_HistogramItem()
845 Get histogram bar items
847 QList<QRect> Plot2d_HistogramItem::getBars() const
853 Set to legend item symbol with color of item
855 void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem,
856 QList<QwtLegendData>& theLegendData )
858 if ( !thePlotItem || !thePlotItem->plot() )
861 Plot2d_HistogramQwtItem::updateLegend( thePlotItem, theLegendData );
863 const QVariant itemInfo = thePlotItem->plot()->itemToInfo( const_cast< QwtPlotItem *>( thePlotItem ) );
864 QwtLegend *legend = dynamic_cast<QwtLegend *>( thePlotItem->plot()->legend() );
865 QWidget* widget = legend->legendWidget( itemInfo );
867 if ( !widget || !widget->inherits( "QwtLegendItem" ) )
870 QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( widget );
871 if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)( label ) ) {
872 QFontMetrics aFMetrics( anItem->font() );
873 int aSize = aFMetrics.height();
874 QwtSymbol* aSymbol = new QwtSymbol( QwtSymbol::Rect, QBrush( legendPen().color() ),
875 QPen( legendPen().color() ), QSize( aSize, aSize ) );
876 anItem->setSymbol( aSymbol );
877 if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
878 anItem->setSymbolType( plot->getLegendSymbolType() );
879 anItem->setSelected( isSelected() );
880 anItem->updateHighlit();
887 Draws histogram object
889 void Plot2d_HistogramItem::draw( QPainter* thePainter,
890 const QwtScaleMap& theXMap,
891 const QwtScaleMap& theYMap,
892 const QRectF& ) const
894 // nds: clear list of bar items
895 Plot2d_HistogramItem* anItem = (Plot2d_HistogramItem*)this;
896 anItem->myBarItems.clear();
898 thePainter->setPen( QPen( color() ) );
899 const int x0 = theXMap.transform( baseline() );
900 const int y0 = theYMap.transform( baseline() );
902 const QwtIntervalSeriesData& iData = data();
904 for ( int i = 0; i < (int)iData.size(); i++ ) {
905 if ( testHistogramAttribute( Plot2d_HistogramItem::Xfy ) ) {
906 const int x2 = theXMap.transform( iData.sample(i).value );
909 int y1 = theYMap.transform( iData.sample(i).interval.minValue() );
910 int y2 = theYMap.transform( iData.sample(i).interval.maxValue() );
914 if ( i < (int)iData.size() - 2 ) {
915 const int yy1 = theYMap.transform( iData.sample(i+1).interval.minValue() );
916 const int yy2 = theYMap.transform( iData.sample(i+1).interval.maxValue() );
917 if ( y2 == qwtMin( yy1, yy2 ) ) {
918 const int xx2 = theXMap.transform( iData.sample(i+1).interval.minValue() );
919 if ( xx2 != x0 && ( ( xx2 < x0 && x2 < x0 ) ||
920 ( xx2 > x0 && x2 > x0 ) ) ) {
921 // One pixel distance between neighboured bars
926 // nds: draw rect with the other lower rects
927 QRect aRect( x0, y1, x2 - x0, y2 - y1 );
928 drawRectAndLowers( thePainter, Qt::Horizontal, aRect );
929 anItem->myBarItems.append( aRect );
932 const int y2 = theYMap.transform( iData.sample(i).value );
935 int x1 = theXMap.transform( iData.sample(i).interval.minValue() );
936 int x2 = theXMap.transform( iData.sample(i).interval.maxValue() );
940 if ( i < (int)iData.size() - 2 ) {
941 const int xx1 = theXMap.transform( iData.sample(i+1).interval.minValue() );
942 const int xx2 = theXMap.transform( iData.sample(i+1).interval.maxValue() );
943 if ( x2 == qwtMin( xx1, xx2 ) ) {
944 const int yy2 = theYMap.transform( iData.sample(i+1).value );
945 if ( yy2 != y0 && ( ( yy2 < y0 && y2 < y0 ) ||
946 ( yy2 > y0 && y2 > y0 ) ) ) {
947 // One pixel distance between neighboured bars
952 // nds: draw rect with the other lower rects
953 QRect aRect(x1, y0, x2 - x1, y2 - y0 );
954 drawRectAndLowers( thePainter, Qt::Vertical, aRect );
955 anItem->myBarItems.append( aRect );
961 Set/clear "cross items" option
963 void Plot2d_HistogramItem::setCrossItems( bool theCross )
965 myCrossed = theCross;
969 Get "cross items" option
971 bool Plot2d_HistogramItem::isCrossItems() const
977 Draws bar of histogram and on it bars of histograms with lower height.
979 void Plot2d_HistogramItem::drawRectAndLowers( QPainter* thePainter,
980 Qt::Orientation theOr,
981 const QRect& theRect ) const
983 QRect aRect = theRect;
984 // theRect has inversed coordinates on Y axis.
985 // The top of the rect is bottom in standard QRect coordinates,
986 // and it bottom is the top.
987 if ( myCrossed )//&& theOr == Qt::Horizontal )
988 aRect.setTop( getCrossedTop( theRect ) );
990 drawBar( thePainter, Qt::Horizontal, aRect );
994 Returns top value of the given rect in the context of other bars.
996 It's necessary to remember, that \a theRect has inverted coordinate Y.
998 int Plot2d_HistogramItem::getCrossedTop( const QRect& theRect ) const
1000 int aRes = theRect.top();
1001 QwtPlot* aPlot = plot();
1002 // int aHeight = theRect.height();
1004 QwtPlotItemList anItems = aPlot->itemList();
1005 QwtPlotItemIterator anIt = anItems.begin(), aLast = anItems.end();
1006 Plot2d_HistogramItem* anItem;
1007 QList<QRect> aRects;
1008 for ( ; anIt != aLast; anIt++ ) {
1009 if ( !((*anIt)->rtti() == QwtPlotItem::Rtti_PlotHistogram) )
1011 anItem = dynamic_cast<Plot2d_HistogramItem*>( *anIt );
1012 if( !anItem || anItem == this )
1015 aRects = anItem->getBars();
1016 for ( int i = 0, aSize = aRects.size(); i < aSize; i++ ) {
1017 if ( qMax( theRect.x(), aRects[i].x() ) <=
1018 qMin( theRect.left(), aRects[i].left() ) ) {
1019 if ( theRect.bottom() < aRects[i].bottom() )
1020 if ( aRects[i].bottom() < aRes )
1021 aRes = aRects[i].bottom();
1029 Plot2d_QwtLegend::Plot2d_QwtLegend( QWidget *parent ):
1032 setAutoFillBackground(true);
1035 Plot2d_QwtLegend::~Plot2d_QwtLegend()
1040 Redefined method, which create a widget to be inserted into the legend.
1042 QWidget *Plot2d_QwtLegend::createWidget( const QwtLegendData &data ) const
1046 Plot2d_QwtLegendLabel *label = new Plot2d_QwtLegendLabel();
1047 label->setItemMode( defaultItemMode() );
1049 connect( label, SIGNAL( clicked() ), SLOT( itemClicked() ) );
1050 connect( label, SIGNAL( checked( bool ) ), SLOT( itemChecked( bool ) ) );