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 QwtLegend* legend = dynamic_cast<QwtLegend*>( thePlotItem->plot()->legend() );
354 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();
376 Redefined method, which updates and calls QwtPlot::autoRefresh() for the parent plot
378 void Plot2d_QwtPlotCurve::itemChanged()
381 updateLegend( this, legendData() );
383 QwtPlotItem::itemChanged();
387 Redefined method, which draw a set of points of a curve.
389 void Plot2d_QwtPlotCurve::drawSeries( QPainter *painter,
390 const QwtScaleMap &xMap,
391 const QwtScaleMap &yMap,
392 const QRectF &canvasRect,
393 int from, int to) const
397 QwtPlotCurve::drawSeries(painter, xMap, yMap, canvasRect, from, to);
399 //draw deviation data
400 if(hasDeviationData()) {
402 int lineW = deviationMarkerLineWidth();
403 int tickSz = deviationMarkerTickSize() + qRound(lineW/2);
404 double min, max, xi, yi;
405 int xp, ytop, ybtm, tickl, tickr;
406 QColor c = isSelected() ? Plot2d_Object::selectionColor() : deviationMarkerColor();
407 QPen p = QPen(c, lineW, Qt::SolidLine);
409 for (int i = from; i <= to; i++) {
410 if(!myDeviationData->values(i,min,max)) continue;
411 const QPointF sample = data()->sample( i );
414 xp = xMap.transform(xi);
415 ytop = yMap.transform(yi + max);
416 ybtm = yMap.transform(yi - min);
419 painter->drawLine(tickl,ytop,tickr,ytop);
420 painter->drawLine(xp,ytop,xp,ybtm);
421 painter->drawLine(tickl,ybtm,tickr,ybtm);
428 * Return color of the deviation marker.
430 QColor Plot2d_QwtPlotCurve::deviationMarkerColor() const {
433 QVariant var = plot()->property(PLOT2D_DEVIATION_COLOR);
435 c = var.value<QColor>();
440 * Return line width of the deviation marker.
442 int Plot2d_QwtPlotCurve::deviationMarkerLineWidth() const {
445 QVariant var = plot()->property(PLOT2D_DEVIATION_LW);
453 * Return tick size of the deviation marker.
455 int Plot2d_QwtPlotCurve::deviationMarkerTickSize() const {
458 QVariant var = plot()->property(PLOT2D_DEVIATION_TS);
466 * Sets deviation data for the plot item.
468 void Plot2d_QwtPlotCurve::setDeviationData(const double* min, const double* max,const QList<int> &idx) {
469 clearDeviationData();
470 myDeviationData = new Plot2d_DeviationData(min,max,idx);
474 * Return true if deviation is assigned to the plot item,
477 bool Plot2d_QwtPlotCurve::hasDeviationData() const {
478 return myDeviationData != 0;
482 * Remove deviation data from the plot item.
484 void Plot2d_QwtPlotCurve::clearDeviationData()
487 delete myDeviationData;
496 Plot2d_SelectableItem::Plot2d_SelectableItem():
498 myLegendSymbol( new QwtSymbol() ),
499 myLegendPen( QPen() )
506 Plot2d_SelectableItem::~Plot2d_SelectableItem()
511 Sets selected property.
513 void Plot2d_SelectableItem::setSelected( const bool on) {
518 Return selected property.
520 bool Plot2d_SelectableItem::isSelected() const {
525 Sets legend pen property.
527 void Plot2d_SelectableItem::setLegendPen( const QPen & p) {
532 Return legend pen property.
534 QPen Plot2d_SelectableItem::legendPen() const {
539 Sets legend symbol property.
541 void Plot2d_SelectableItem::setLegendSymbol( const QwtSymbol* s ) {
542 myLegendSymbol->setStyle( s->style() );
543 myLegendSymbol->setBrush( s->brush() );
544 myLegendSymbol->setPen( s->pen() );
545 myLegendSymbol->setSize( s->size() );
549 Sets legend symbol property.
551 QwtSymbol* Plot2d_SelectableItem::legendSymbol() const {
552 return new QwtSymbol( myLegendSymbol->style(), myLegendSymbol->brush(),
553 myLegendSymbol->pen(), myLegendSymbol->size() );
559 Plot2d_HistogramQwtItem::Plot2d_HistogramQwtItem( const QwtText& theTitle )
560 : QwtPlotItem( theTitle )
568 Plot2d_HistogramQwtItem::Plot2d_HistogramQwtItem( const QString& theTitle )
569 : QwtPlotItem( QwtText( theTitle ) )
577 Plot2d_HistogramQwtItem::~Plot2d_HistogramQwtItem()
582 Initialization of object
584 void Plot2d_HistogramQwtItem::init()
587 myAttributes = Plot2d_HistogramQwtItem::Auto;
589 setItemAttribute( QwtPlotItem::AutoScale, true );
590 setItemAttribute( QwtPlotItem::Legend, true );
596 Sets base line to object
599 void Plot2d_HistogramQwtItem::setBaseline( double theRef )
601 if ( myReference != theRef ) {
602 myReference = theRef;
608 Returns base line of object
610 double Plot2d_HistogramQwtItem::baseline() const
618 void Plot2d_HistogramQwtItem::setData( const QwtIntervalSeriesData& theData )
620 myData.setSamples( theData.samples() );
625 Returns data from object
627 const QwtIntervalSeriesData& Plot2d_HistogramQwtItem::data() const
635 void Plot2d_HistogramQwtItem::setColor( const QColor& theColor )
637 if ( myColor != theColor ) {
644 Returns color from object
646 QColor Plot2d_HistogramQwtItem::color() const
652 Returns bounding rect of object
654 QwtDoubleRect Plot2d_HistogramQwtItem::boundingRect() const
656 QwtDoubleRect aRect = myData.boundingRect();
657 if ( !aRect.isValid() )
660 if ( myAttributes & Xfy ) {
661 aRect = QwtDoubleRect( aRect.y(), aRect.x(),
662 aRect.height(), aRect.width() );
663 if ( aRect.left() > myReference )
664 aRect.setLeft( myReference );
665 else if ( aRect.right() < myReference )
666 aRect.setRight( myReference );
669 if ( aRect.bottom() < myReference )
670 aRect.setBottom( myReference );
671 else if ( aRect.top() > myReference )
672 aRect.setTop( myReference );
678 Returns type of plot object
680 int Plot2d_HistogramQwtItem::rtti() const
682 return QwtPlotItem::Rtti_PlotHistogram;
686 Sets histogram attributes
688 void Plot2d_HistogramQwtItem::setHistogramAttribute( HistogramAttribute theAttr,
691 if ( testHistogramAttribute( theAttr ) != isOn ) {
693 myAttributes |= theAttr;
695 myAttributes &= ~theAttr;
702 Tests histogram attributes
704 bool Plot2d_HistogramQwtItem::testHistogramAttribute( HistogramAttribute theAttr ) const
706 return myAttributes & theAttr;
710 Draws histogram object
712 void Plot2d_HistogramQwtItem::draw( QPainter* thePainter,
713 const QwtScaleMap& theXMap,
714 const QwtScaleMap& theYMap,
715 const QRectF& ) const
717 thePainter->setPen( QPen( myColor ) );
719 const int x0 = theXMap.transform( baseline() );
720 const int y0 = theYMap.transform( baseline() );
722 for ( int i = 0; i < (int)myData.size(); i++ ) {
723 if ( myAttributes & Plot2d_HistogramQwtItem::Xfy ) {
724 const int x2 = theXMap.transform( myData.sample(i).value );
727 int y1 = theYMap.transform( myData.sample( i ).interval.minValue() );
728 int y2 = theYMap.transform( myData.sample( i ).interval.maxValue() );
732 if ( i < (int)myData.size() - 2 ) {
733 const int yy1 = theYMap.transform( myData.sample(i+1).interval.minValue() );
734 const int yy2 = theYMap.transform( myData.sample(i+1).interval.maxValue() );
735 if ( y2 == qwtMin( yy1, yy2 ) ) {
736 const int xx2 = theXMap.transform( myData.sample(i+1).interval.minValue() );
737 if ( xx2 != x0 && ( ( xx2 < x0 && x2 < x0 ) ||
738 ( xx2 > x0 && x2 > x0 ) ) ) {
739 // One pixel distance between neighboured bars
744 drawBar( thePainter, Qt::Horizontal, QRect( x0, y1, x2 - x0, y2 - y1 ) );
747 const int y2 = theYMap.transform( myData.sample( i ).value );
750 int x1 = theXMap.transform( myData.sample( i ).interval.minValue() );
751 int x2 = theXMap.transform( myData.sample( i ).interval.maxValue() );
755 if ( i < (int)myData.size() - 2 ) {
756 const int xx1 = theXMap.transform( myData.sample(i+1).interval.minValue() );
757 const int xx2 = theXMap.transform( myData.sample(i+1).interval.maxValue() );
758 if ( x2 == qwtMin( xx1, xx2 ) ) {
759 const int yy2 = theYMap.transform( myData.sample(i+1).value );
760 if ( yy2 != y0 && ( ( yy2 < y0 && y2 < y0 ) ||
761 ( yy2 > y0 && y2 > y0 ) ) ) {
762 // One pixel distance between neighboured bars
767 drawBar( thePainter, Qt::Vertical, QRect( x1, y0, x2 - x1, y2 - y0 ) );
773 Draws single bar of histogram
775 void Plot2d_HistogramQwtItem::drawBar( QPainter* thePainter,
777 const QRect& theRect ) const
781 const QColor color( thePainter->pen().color() );
782 QRect r = theRect.normalized();
784 const int factor = 125;
785 const QColor light( color.light( factor ) );
786 const QColor dark( color.dark( factor ) );
788 thePainter->setBrush( color );
789 thePainter->setPen( Qt::NoPen );
790 QwtPainter::drawRect( thePainter, r.x() + 1, r.y() + 1,
791 r.width() - 2, r.height() - 2 );
792 thePainter->setBrush( Qt::NoBrush );
794 thePainter->setPen( QPen( light, 2 ) );
795 QwtPainter::drawLine( thePainter, r.left() + 1, r.top() + 2,
796 r.right() + 1, r.top() + 2 );
798 thePainter->setPen( QPen( dark, 2 ) );
799 QwtPainter::drawLine( thePainter, r.left() + 1, r.bottom(),
800 r.right() + 1, r.bottom() );
801 thePainter->setPen( QPen( light, 1 ) );
803 QwtPainter::drawLine( thePainter, r.left(), r.top() + 1,
804 r.left(), r.bottom() );
805 QwtPainter::drawLine( thePainter, r.left() + 1, r.top() + 2,
806 r.left() + 1, r.bottom() - 1 );
807 thePainter->setPen( QPen( dark, 1 ) );
809 QwtPainter::drawLine( thePainter, r.right() + 1, r.top() + 1,
810 r.right() + 1, r.bottom() );
811 QwtPainter::drawLine(thePainter, r.right(), r.top() + 2,
812 r.right(), r.bottom() - 1 );
813 thePainter->restore();
819 Plot2d_HistogramItem::Plot2d_HistogramItem( const QwtText& theTitle )
820 : Plot2d_HistogramQwtItem( theTitle ),
821 Plot2d_SelectableItem(),
829 Plot2d_HistogramItem::Plot2d_HistogramItem( const QString& theTitle )
830 : Plot2d_HistogramQwtItem( theTitle ),
838 Plot2d_HistogramItem::~Plot2d_HistogramItem()
843 Get histogram bar items
845 QList<QRect> Plot2d_HistogramItem::getBars() const
851 Set to legend item symbol with color of item
853 void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem,
854 QList<QwtLegendData>& theLegendData )
856 if ( !thePlotItem || !thePlotItem->plot() )
859 Plot2d_HistogramQwtItem::updateLegend( thePlotItem, theLegendData );
861 const QVariant itemInfo = thePlotItem->plot()->itemToInfo( const_cast< QwtPlotItem *>( thePlotItem ) );
862 QwtLegend *legend = dynamic_cast<QwtLegend *>( thePlotItem->plot()->legend() );
863 QWidget* widget = legend->legendWidget( itemInfo );
865 if ( !widget || !widget->inherits( "QwtLegendItem" ) )
868 QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( widget );
869 if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)( label ) ) {
870 QFontMetrics aFMetrics( anItem->font() );
871 int aSize = aFMetrics.height();
872 QwtSymbol* aSymbol = new QwtSymbol( QwtSymbol::Rect, QBrush( legendPen().color() ),
873 QPen( legendPen().color() ), QSize( aSize, aSize ) );
874 anItem->setSymbol( aSymbol );
875 if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
876 anItem->setSymbolType( plot->getLegendSymbolType() );
877 anItem->setSelected( isSelected() );
878 anItem->updateHighlit();
885 Draws histogram object
887 void Plot2d_HistogramItem::draw( QPainter* thePainter,
888 const QwtScaleMap& theXMap,
889 const QwtScaleMap& theYMap,
890 const QRectF& ) const
892 // nds: clear list of bar items
893 Plot2d_HistogramItem* anItem = (Plot2d_HistogramItem*)this;
894 anItem->myBarItems.clear();
896 thePainter->setPen( QPen( color() ) );
897 const int x0 = theXMap.transform( baseline() );
898 const int y0 = theYMap.transform( baseline() );
900 const QwtIntervalSeriesData& iData = data();
902 for ( int i = 0; i < (int)iData.size(); i++ ) {
903 if ( testHistogramAttribute( Plot2d_HistogramItem::Xfy ) ) {
904 const int x2 = theXMap.transform( iData.sample(i).value );
907 int y1 = theYMap.transform( iData.sample(i).interval.minValue() );
908 int y2 = theYMap.transform( iData.sample(i).interval.maxValue() );
912 if ( i < (int)iData.size() - 2 ) {
913 const int yy1 = theYMap.transform( iData.sample(i+1).interval.minValue() );
914 const int yy2 = theYMap.transform( iData.sample(i+1).interval.maxValue() );
915 if ( y2 == qwtMin( yy1, yy2 ) ) {
916 const int xx2 = theXMap.transform( iData.sample(i+1).interval.minValue() );
917 if ( xx2 != x0 && ( ( xx2 < x0 && x2 < x0 ) ||
918 ( xx2 > x0 && x2 > x0 ) ) ) {
919 // One pixel distance between neighboured bars
924 // nds: draw rect with the other lower rects
925 QRect aRect( x0, y1, x2 - x0, y2 - y1 );
926 drawRectAndLowers( thePainter, Qt::Horizontal, aRect );
927 anItem->myBarItems.append( aRect );
930 const int y2 = theYMap.transform( iData.sample(i).value );
933 int x1 = theXMap.transform( iData.sample(i).interval.minValue() );
934 int x2 = theXMap.transform( iData.sample(i).interval.maxValue() );
938 if ( i < (int)iData.size() - 2 ) {
939 const int xx1 = theXMap.transform( iData.sample(i+1).interval.minValue() );
940 const int xx2 = theXMap.transform( iData.sample(i+1).interval.maxValue() );
941 if ( x2 == qwtMin( xx1, xx2 ) ) {
942 const int yy2 = theYMap.transform( iData.sample(i+1).value );
943 if ( yy2 != y0 && ( ( yy2 < y0 && y2 < y0 ) ||
944 ( yy2 > y0 && y2 > y0 ) ) ) {
945 // One pixel distance between neighboured bars
950 // nds: draw rect with the other lower rects
951 QRect aRect(x1, y0, x2 - x1, y2 - y0 );
952 drawRectAndLowers( thePainter, Qt::Vertical, aRect );
953 anItem->myBarItems.append( aRect );
959 Set/clear "cross items" option
961 void Plot2d_HistogramItem::setCrossItems( bool theCross )
963 myCrossed = theCross;
967 Get "cross items" option
969 bool Plot2d_HistogramItem::isCrossItems() const
975 Draws bar of histogram and on it bars of histograms with lower height.
977 void Plot2d_HistogramItem::drawRectAndLowers( QPainter* thePainter,
978 Qt::Orientation theOr,
979 const QRect& theRect ) const
981 QRect aRect = theRect;
982 // theRect has inversed coordinates on Y axis.
983 // The top of the rect is bottom in standard QRect coordinates,
984 // and it bottom is the top.
985 if ( myCrossed )//&& theOr == Qt::Horizontal )
986 aRect.setTop( getCrossedTop( theRect ) );
988 drawBar( thePainter, Qt::Horizontal, aRect );
992 Returns top value of the given rect in the context of other bars.
994 It's necessary to remember, that \a theRect has inverted coordinate Y.
996 int Plot2d_HistogramItem::getCrossedTop( const QRect& theRect ) const
998 int aRes = theRect.top();
999 QwtPlot* aPlot = plot();
1000 // int aHeight = theRect.height();
1002 QwtPlotItemList anItems = aPlot->itemList();
1003 QwtPlotItemIterator anIt = anItems.begin(), aLast = anItems.end();
1004 Plot2d_HistogramItem* anItem;
1005 QList<QRect> aRects;
1006 for ( ; anIt != aLast; anIt++ ) {
1007 if ( !((*anIt)->rtti() == QwtPlotItem::Rtti_PlotHistogram) )
1009 anItem = dynamic_cast<Plot2d_HistogramItem*>( *anIt );
1010 if( !anItem || anItem == this )
1013 aRects = anItem->getBars();
1014 for ( int i = 0, aSize = aRects.size(); i < aSize; i++ ) {
1015 if ( qMax( theRect.x(), aRects[i].x() ) <=
1016 qMin( theRect.left(), aRects[i].left() ) ) {
1017 if ( theRect.bottom() < aRects[i].bottom() )
1018 if ( aRects[i].bottom() < aRes )
1019 aRes = aRects[i].bottom();
1027 Plot2d_QwtLegend::Plot2d_QwtLegend( QWidget *parent ):
1030 setAutoFillBackground(true);
1033 Plot2d_QwtLegend::~Plot2d_QwtLegend()
1038 Redefined method, which create a widget to be inserted into the legend.
1040 QWidget *Plot2d_QwtLegend::createWidget( const QwtLegendData &data ) const
1044 Plot2d_QwtLegendLabel *label = new Plot2d_QwtLegendLabel();
1045 label->setItemMode( defaultItemMode() );
1047 connect( label, SIGNAL( clicked() ), SLOT( itemClicked() ) );
1048 connect( label, SIGNAL( checked( bool ) ), SLOT( itemChecked( bool ) ) );