Salome HOME
Copyright update 2022
[modules/gui.git] / src / Plot2d / Plot2d_PlotItems.h
1 // Copyright (C) 2007-2022  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_label.h>
31 #include <qwt_legend.h>
32 #include <qwt_plot_item.h>
33 #include <qwt_plot_curve.h>
34 #include <qwt_plot.h>
35 #include <qwt_series_data.h>
36 #include <qwt_compat.h>
37
38 class PLOT2D_EXPORT Plot2d_QwtLegendLabel : public QwtLegendLabel
39 {
40 public:
41   enum YAxisIdentifierMode { IM_None = 0, IM_Left, IM_Right };
42
43 public:
44   Plot2d_QwtLegendLabel( QWidget* = 0 );
45   virtual ~Plot2d_QwtLegendLabel();
46
47 public:
48   void             setYAxisIdentifierMode( const int );
49   void             updateHighlit();
50   void             setSelected( const bool on );
51   bool             isSelected() const;
52   QColor           getColorFromPalette( QPalette::ColorRole role );
53   void             drawIdentifier( QPainter*, const QRect& );
54   void             setSymbol( const QwtSymbol* );
55   void             setSymbolType( const int );
56   void             setPen( const QPen& );
57
58 protected:
59   virtual void     drawText( QPainter*, const QRectF& );
60   virtual void     paintEvent( QPaintEvent* );
61
62 private:
63
64 private:
65   int              myYAxisIdentifierMode;
66   QPixmap          myYAxisLeftIcon;
67   QPixmap          myYAxisRightIcon;
68   int              mySpacingCollapsed;
69   int              mySpacingExpanded;
70   bool             myIsSelected;
71   QwtSymbol*       mySymbol;
72   int              mySymbolType;
73   QPen             myPen;
74 };
75
76 class PLOT2D_EXPORT Plot2d_SelectableItem {
77 public:
78   Plot2d_SelectableItem();
79   ~Plot2d_SelectableItem();
80
81   void             setSelected( const bool );
82   bool             isSelected() const;
83
84   void             setLegendPen( const QPen& );
85   QPen             legendPen() const;
86
87   void             setLegendSymbol( const QwtSymbol* );
88   QwtSymbol*       legendSymbol() const;
89
90 private:
91   bool             myIsSelected;
92   QPen             myLegendPen;
93   QwtSymbol*       myLegendSymbol;
94 };
95
96 class PLOT2D_EXPORT Plot2d_QwtPlotCurve : public QwtPlotCurve, public Plot2d_SelectableItem
97 {
98 public:
99   Plot2d_QwtPlotCurve( const QString&, QwtPlot::Axis = QwtPlot::yLeft );
100   virtual ~Plot2d_QwtPlotCurve();
101
102 public:
103   virtual void     setYAxisIdentifierEnabled( const bool );
104   virtual void     drawSeries( QPainter* p,
105                                const QwtScaleMap& xMap,
106                                const QwtScaleMap& yMap,
107                                const QRectF& canvasRect,
108                                int from, int to) const;
109
110   void             setDeviationData( const double* min, const double* max, const QList<int>& idx );
111   bool             hasDeviationData() const;
112   void             clearDeviationData();
113
114 protected:
115   virtual void     updateLegend( const QwtPlotItem*,
116                                  const QList<QwtLegendData>& );
117   virtual void     itemChanged();
118
119   QColor           deviationMarkerColor() const;
120   int              deviationMarkerLineWidth() const;
121   int              deviationMarkerTickSize() const;
122
123 private:
124   QwtPlot::Axis    myYAxis;
125   bool             myYAxisIdentifierEnabled;
126   
127   class Plot2d_DeviationData;
128   Plot2d_DeviationData* myDeviationData;
129 };
130
131 class PLOT2D_EXPORT Plot2d_HistogramQwtItem: public QwtPlotItem
132 {
133 public:
134   enum HistogramAttribute 
135   {
136     Auto = 0,
137     Xfy  = 1
138   };
139
140   explicit Plot2d_HistogramQwtItem( const QString& = QString() );
141   explicit Plot2d_HistogramQwtItem( const QwtText& );
142   virtual ~Plot2d_HistogramQwtItem();
143
144   void                   setData( const QwtIntervalSeriesData& );
145   const QwtIntervalSeriesData& data() const;
146
147   void                   setColor( const QColor& );
148   QColor                 color() const;
149
150   virtual QwtDoubleRect  boundingRect() const;
151   virtual int            rtti() const;
152   virtual void           draw( QPainter*, const QwtScaleMap&, 
153                                const QwtScaleMap&, const QRectF& ) const;
154
155   void                   setBaseline( double );
156   double                 baseline() const;
157
158   void                   setHistogramAttribute( HistogramAttribute, bool = true );
159   bool                   testHistogramAttribute( HistogramAttribute ) const;
160
161 protected:
162   virtual void           drawBar( QPainter*, Qt::Orientation, const QRect& ) const;
163
164 private:
165   void                   init();
166
167 private:
168   int                    myAttributes;
169   QwtIntervalSeriesData  myData;
170   QColor                 myColor;
171   double                 myReference;
172 };
173
174 class PLOT2D_EXPORT Plot2d_HistogramItem : public Plot2d_HistogramQwtItem, public Plot2d_SelectableItem
175 {
176 public:
177   explicit Plot2d_HistogramItem( const QString& = QString() );
178   explicit Plot2d_HistogramItem( const QwtText& );
179   virtual ~Plot2d_HistogramItem();
180
181   QList<QRect>     getBars() const;
182
183
184   virtual void     updateLegend( const QwtPlotItem *,
185                                   const QList<QwtLegendData> & );
186   virtual void     draw( QPainter*, const QwtScaleMap&,
187                          const QwtScaleMap&, const QRectF& ) const;
188
189   virtual void     itemChanged();
190
191   virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
192
193   void             setCrossItems( bool theCross );
194   bool             isCrossItems() const;
195
196 protected:
197   void             drawRectAndLowers( QPainter*, Qt::Orientation,
198                                       const QRect& ) const;
199   int              getCrossedTop( const QRect& ) const;
200
201 protected:
202   QList<QRect>     myBarItems;
203   bool             myCrossed;
204 };
205
206 class PLOT2D_EXPORT Plot2d_QwtLegend : public QwtLegend
207 {
208 public:
209   explicit Plot2d_QwtLegend( QWidget *parent = NULL );
210   virtual ~Plot2d_QwtLegend();
211
212 protected:
213   virtual QWidget* createWidget( const QwtLegendData& ) const;
214 };
215
216 #endif // PLOT2D_PLOTITEMS_H