Salome HOME
Update copyrights 2014.
[modules/gui.git] / src / Plot2d / Plot2d_PlotItems.h
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : Plot2d_HistogramItem.h
23 //  Author : Natalia ERMOLAEVA, Open CASCADE S.A.S. (natalia.donis@opencascade.com)
24
25 #ifndef PLOT2D_PLOTITEMS_H
26 #define PLOT2D_PLOTITEMS_H
27
28 #include "Plot2d.h"
29
30 #include <qwt_legend_item.h>
31 #include <qwt_plot_item.h>
32 #include <qwt_plot_curve.h>
33 #include <qwt_interval_data.h>
34 #include <qwt_plot.h>
35
36 class PLOT2D_EXPORT Plot2d_QwtLegendItem : public QwtLegendItem
37 {
38 public:
39   enum YAxisIdentifierMode { IM_None = 0, IM_Left, IM_Right };
40
41 public:
42   Plot2d_QwtLegendItem( QWidget* = 0 );
43   virtual ~Plot2d_QwtLegendItem();
44
45 public:
46   void             setYAxisIdentifierMode( const int );
47   void             updateHighlit();
48   void             setSelected(const bool on);
49   bool             isSelected() const;
50   QColor           getColorFromPalette(QPalette::ColorRole role);  
51
52 protected:
53   virtual void     drawIdentifier( QPainter*, const QRect& ) const;
54   virtual void     drawText(QPainter *, const QRect &);
55
56 private:
57
58 private:
59   int              myYAxisIdentifierMode;
60   QPixmap          myYAxisLeftIcon;
61   QPixmap          myYAxisRightIcon;
62   int              mySpacingCollapsed;
63   int              mySpacingExpanded;
64   bool             myIsSelected;
65 };
66
67 class PLOT2D_EXPORT Plot2d_SelectableItem {
68 public:
69     Plot2d_SelectableItem();
70     ~Plot2d_SelectableItem();
71   
72     void             setSelected( const bool );
73     bool             isSelected() const;
74     
75     void             setLegendPen( const QPen & );
76     QPen             legendPen() const;
77         
78     void             setLegendSymbol( const QwtSymbol& );
79     QwtSymbol        legendSymbol() const;
80     
81 private:
82   bool             myIsSelected;
83   QPen             myLegendPen;
84   QwtSymbol        myLegendSymbol;
85 };
86
87 class PLOT2D_EXPORT Plot2d_QwtPlotCurve : public QwtPlotCurve, public Plot2d_SelectableItem
88 {
89 public:
90   Plot2d_QwtPlotCurve( const QString&, QwtPlot::Axis = QwtPlot::yLeft );
91   virtual ~Plot2d_QwtPlotCurve();
92
93 public:
94   virtual void     setYAxisIdentifierEnabled( const bool );
95   virtual void     draw(QPainter *p, 
96                         const QwtScaleMap &xMap, 
97                         const QwtScaleMap &yMap,
98                         int from, int to) const;
99
100   void             setDeviationData(const double* min, const double* max, const QList<int> &idx);
101   bool             hasDeviationData() const;
102   void             clearDeviationData();
103
104
105 protected:
106   virtual void     updateLegend( QwtLegend* ) const;
107   virtual QWidget* legendItem() const;
108
109   QColor           deviationMarkerColor() const;
110   int              deviationMarkerLineWidth() const;
111   int              deviationMarkerTickSize() const;
112
113 private:
114   QwtPlot::Axis        myYAxis;
115   bool                 myYAxisIdentifierEnabled;
116   
117   class Plot2d_DeviationData;
118   Plot2d_DeviationData* myDeviationData;
119 };
120
121 class PLOT2D_EXPORT Plot2d_HistogramQwtItem: public QwtPlotItem
122 {
123 public:
124   enum HistogramAttribute 
125   {
126     Auto = 0,
127     Xfy  = 1
128   };
129
130   explicit Plot2d_HistogramQwtItem( const QString& = QString() );
131   explicit Plot2d_HistogramQwtItem( const QwtText& );
132   virtual ~Plot2d_HistogramQwtItem();
133
134   void                   setData( const QwtIntervalData& );
135   const QwtIntervalData& data() const;
136
137   void                   setColor( const QColor& );
138   QColor                 color() const;
139
140   virtual QwtDoubleRect  boundingRect() const;
141   virtual int            rtti() const;
142   virtual void           draw( QPainter*, const QwtScaleMap&, 
143                                const QwtScaleMap&, const QRect& ) const;
144
145   void                   setBaseline( double );
146   double                 baseline() const;
147
148   void                   setHistogramAttribute( HistogramAttribute, bool = true );
149   bool                   testHistogramAttribute( HistogramAttribute ) const;
150
151 protected:
152   virtual void           drawBar( QPainter*, Qt::Orientation, const QRect& ) const;
153
154 private:
155   void                   init();
156
157 private:
158   int                    myAttributes;
159   QwtIntervalData        myData;
160   QColor                 myColor;
161   double                 myReference;
162 };
163
164 class PLOT2D_EXPORT Plot2d_HistogramItem : public Plot2d_HistogramQwtItem, public Plot2d_SelectableItem
165 {
166 public:
167   explicit Plot2d_HistogramItem( const QString& = QString() );
168   explicit Plot2d_HistogramItem( const QwtText& );
169   virtual ~Plot2d_HistogramItem();
170
171   QList<QRect>           getBars() const;
172
173   virtual void           updateLegend( QwtLegend* ) const;
174   virtual void           draw( QPainter*, const QwtScaleMap&, 
175                                const QwtScaleMap&, const QRect& ) const;
176
177   void                   setCrossItems( bool theCross );
178   bool                   isCrossItems() const;
179
180 protected:
181   void                   drawRectAndLowers( QPainter*, Qt::Orientation,
182                                             const QRect& ) const;
183   int                    getCrossedTop( const QRect& ) const;
184
185   virtual QWidget*       legendItem() const;
186
187 protected:
188   QList<QRect>           myBarItems;
189   bool                   myCrossed;
190 };
191
192 #endif // PLOT2D_PLOTITEMS_H