Back to index

salome-gui  6.5.0
Plot2d_PlotItems.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : Plot2d_HistogramItem.h
00023 //  Author : Natalia ERMOLAEVA, Open CASCADE S.A.S. (natalia.donis@opencascade.com)
00024 
00025 #ifndef PLOT2D_PLOTITEMS_H
00026 #define PLOT2D_PLOTITEMS_H
00027 
00028 #include "Plot2d.h"
00029 
00030 #include <qwt_legend_item.h>
00031 #include <qwt_plot_item.h>
00032 #include <qwt_plot_curve.h>
00033 #include <qwt_interval_data.h>
00034 #include <qwt_plot.h>
00035 
00036 class PLOT2D_EXPORT Plot2d_QwtLegendItem : public QwtLegendItem
00037 {
00038 public:
00039   enum YAxisIdentifierMode { IM_None = 0, IM_Left, IM_Right };
00040 
00041 public:
00042   Plot2d_QwtLegendItem( QWidget* = 0 );
00043   virtual ~Plot2d_QwtLegendItem();
00044 
00045 public:
00046   void             setYAxisIdentifierMode( const int );
00047   void             updateHighlit();
00048   void             setSelected(const bool on);
00049   bool             isSelected() const;
00050   QColor           getColorFromPalette(QPalette::ColorRole role);  
00051 
00052 protected:
00053   virtual void     drawIdentifier( QPainter*, const QRect& ) const;
00054   virtual void     drawText(QPainter *, const QRect &);
00055 
00056 private:
00057 
00058 private:
00059   int              myYAxisIdentifierMode;
00060   QPixmap          myYAxisLeftIcon;
00061   QPixmap          myYAxisRightIcon;
00062   int              mySpacingCollapsed;
00063   int              mySpacingExpanded;
00064   bool             myIsSelected;
00065 };
00066 
00067 class PLOT2D_EXPORT Plot2d_SelectableItem {
00068 public:
00069     Plot2d_SelectableItem();
00070     ~Plot2d_SelectableItem();
00071   
00072     void             setSelected( const bool );
00073     bool             isSelected() const;
00074     
00075     void             setLegendPen( const QPen & );
00076     QPen             legendPen() const;
00077        
00078     void             setLegendSymbol( const QwtSymbol& );
00079     QwtSymbol        legendSymbol() const;
00080     
00081 private:
00082   bool             myIsSelected;
00083   QPen             myLegendPen;
00084   QwtSymbol        myLegendSymbol;
00085 };
00086 
00087 class PLOT2D_EXPORT Plot2d_QwtPlotCurve : public QwtPlotCurve, public Plot2d_SelectableItem
00088 {
00089 public:
00090   Plot2d_QwtPlotCurve( const QString&, QwtPlot::Axis = QwtPlot::yLeft );
00091   virtual ~Plot2d_QwtPlotCurve();
00092 
00093 public:
00094   virtual void     setYAxisIdentifierEnabled( const bool );
00095   virtual void     draw(QPainter *p, 
00096                         const QwtScaleMap &xMap, 
00097                         const QwtScaleMap &yMap,
00098                         int from, int to) const;
00099 
00100   void             setDeviationData(const double* min, const double* max, const QList<int> &idx);
00101   bool             hasDeviationData() const;
00102   void             clearDeviationData();
00103 
00104 
00105 protected:
00106   virtual void     updateLegend( QwtLegend* ) const;
00107   virtual QWidget* legendItem() const;
00108 
00109   QColor           deviationMarkerColor() const;
00110   int              deviationMarkerLineWidth() const;
00111   int              deviationMarkerTickSize() const;
00112 
00113 private:
00114   QwtPlot::Axis        myYAxis;
00115   bool                 myYAxisIdentifierEnabled;
00116   
00117   class Plot2d_DeviationData;
00118   Plot2d_DeviationData* myDeviationData;
00119 };
00120 
00121 class PLOT2D_EXPORT Plot2d_HistogramQwtItem: public QwtPlotItem
00122 {
00123 public:
00124   enum HistogramAttribute 
00125   {
00126     Auto = 0,
00127     Xfy  = 1
00128   };
00129 
00130   explicit Plot2d_HistogramQwtItem( const QString& = QString() );
00131   explicit Plot2d_HistogramQwtItem( const QwtText& );
00132   virtual ~Plot2d_HistogramQwtItem();
00133 
00134   void                   setData( const QwtIntervalData& );
00135   const QwtIntervalData& data() const;
00136 
00137   void                   setColor( const QColor& );
00138   QColor                 color() const;
00139 
00140   virtual QwtDoubleRect  boundingRect() const;
00141   virtual int            rtti() const;
00142   virtual void           draw( QPainter*, const QwtScaleMap&, 
00143                             const QwtScaleMap&, const QRect& ) const;
00144 
00145   void                   setBaseline( double );
00146   double                 baseline() const;
00147 
00148   void                   setHistogramAttribute( HistogramAttribute, bool = true );
00149   bool                   testHistogramAttribute( HistogramAttribute ) const;
00150 
00151 protected:
00152   virtual void           drawBar( QPainter*, Qt::Orientation, const QRect& ) const;
00153 
00154 private:
00155   void                   init();
00156 
00157 private:
00158   int                    myAttributes;
00159   QwtIntervalData        myData;
00160   QColor                 myColor;
00161   double                 myReference;
00162 };
00163 
00164 class PLOT2D_EXPORT Plot2d_HistogramItem : public Plot2d_HistogramQwtItem, public Plot2d_SelectableItem
00165 {
00166 public:
00167   explicit Plot2d_HistogramItem( const QString& = QString() );
00168   explicit Plot2d_HistogramItem( const QwtText& );
00169   virtual ~Plot2d_HistogramItem();
00170 
00171   QList<QRect>           getBars() const;
00172 
00173   virtual void           updateLegend( QwtLegend* ) const;
00174   virtual void           draw( QPainter*, const QwtScaleMap&, 
00175                             const QwtScaleMap&, const QRect& ) const;
00176 
00177   void                   setCrossItems( bool theCross );
00178   bool                   isCrossItems() const;
00179 
00180 protected:
00181   void                   drawRectAndLowers( QPainter*, Qt::Orientation,
00182                                        const QRect& ) const;
00183   int                    getCrossedTop( const QRect& ) const;
00184 
00185   virtual QWidget*       legendItem() const;
00186 
00187 protected:
00188   QList<QRect>           myBarItems;
00189   bool                   myCrossed;
00190 };
00191 
00192 #endif // PLOT2D_PLOTITEMS_H