• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

Analitza

  • sources
  • kde-4.14
  • kdeedu
  • analitza
  • analitzaplot
plotter2d.h
Go to the documentation of this file.
1 /*************************************************************************************
2  * Copyright (C) 2011 by Aleix Pol <aleixpol@kde.org> *
3  * Copyright (C) 2012-2013 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License *
7  * as published by the Free Software Foundation; either version 2 *
8  * of the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
18  *************************************************************************************/
19 
20 #ifndef PLOTTER2D_H
21 #define PLOTTER2D_H
22 
23 #include <QRectF>
24 #include <QLineF>
25 #include <QString>
26 #include <QPair>
27 #include <QColor>
28 
29 #include "analitzaplotexport.h"
30 #include <analitzaplot/plottingenums.h>
31 
32 class QAbstractItemModel;
33 class QPainter;
34 class QPaintDevice;
35 class QModelIndex;
36 
37 namespace Analitza
38 {
39 class PlotItem;
40 
55 class ANALITZAPLOT_EXPORT Plotter2D
56 {
57  private: // private structs
58  struct GridInfo; // interval structure for carry current grid state information across interval methods
59 
60  public:
61  Plotter2D(const QSizeF& size);
62  virtual ~Plotter2D();
63 
65  void setShowGrid(bool show) { m_showGrid=show; forceRepaint(); }
66  //only works if showgrid is true. for polar grid it affects to subdivision of angles/rays
67  void setShowMinorGrid(bool mt) { m_showMinorGrid=mt; forceRepaint(); }
68 
70  bool showGrid() const {return m_showGrid; }
71 
72  void setGridColor(const QColor &color) { m_gridColor = color; forceRepaint(); }
73 
74  //default Qt::lightGray
75  QColor gridColor() const { return m_gridColor; }
76 
77  void setBackgroundColor(const QColor &color) { m_backgroundColor = color; forceRepaint(); }
78 
79  // default Qt::white
80  QColor backgroundColor() const { return m_backgroundColor; }
81 
83  void setAutoGridStyle(bool autogs) { m_autoGridStyle = autogs; forceRepaint(); }
84 
86  bool autoGridStyle() const { return m_autoGridStyle; }
87 
89  void setGridStyleHint(GridStyle suggestedgs);
90 
92  void setKeepAspectRatio(bool ar);
93 
95  bool keepAspectRatio() const { return m_keepRatio; }
96 
98  void updateFunctions(const QModelIndex & parent, int start, int end);
99 
100  void setModel(QAbstractItemModel* f);
101  QAbstractItemModel* model() const { return m_model; }
102 
104  void setViewport(const QRectF& vp, bool repaint=true);
105 
106  //TODO doc
107  //normlized current viewport, that includes scale information
108  QRectF currentViewport() const { return viewport; }
109 
110  //DEPRECATED
111  QRectF lastViewport() const { return currentViewport(); }
112 
114  void moveViewport(const QPoint& delta);
115 
116  void setXAxisLabel(const QString &label);
117  void setYAxisLabel(const QString &label);
118 
119  //by default linear
120  void setScaleMode(ScaleMode sm) { m_scaleMode = sm; forceRepaint(); }
121  ScaleMode scaleMode() const { return m_scaleMode; }
122 
123  //default radiasn, this will afecto when scalemode is trig and for the angles in polargridmode
124  void setAngleMode(AngleMode am) { m_angleMode = am; forceRepaint(); }
125  AngleMode angleMode() const { return m_angleMode; }
126 
127  void setShowTicks(Qt::Orientations o) { m_showTicks = o; forceRepaint(); }
128  void setShowTickLabels(Qt::Orientations o) { m_showTickLabels = o; forceRepaint(); }
129  //only works if showticks is true
130  void setShowMinorTicks(bool mt) { m_showMinorTicks=mt; forceRepaint(); }
131 
132  //these 2 only work when gridmode is polar, showpolar axis aumenta cuando esta lejos de origin
133  void setShowPolarAxis(bool pt) { m_showPolarAxis = pt; forceRepaint(); }
134  void setShowPolarAngles(bool pt) { m_showPolarAngles = pt; forceRepaint(); }
135 
136  void setShowAxes(Qt::Orientations o) { m_showAxes = o; forceRepaint(); }
137 
138  Qt::Orientations ticksShown() const { return m_showTickLabels; }
139 
141  void zoomIn(bool repaint=true);
142 
144  void zoomOut(bool repaint=true);
145 
146  protected:
147  virtual void drawGrid(QPaintDevice *qpd);
148  virtual void drawFunctions(QPaintDevice *qpd);
149  virtual void forceRepaint() = 0;
150  virtual void viewportChanged() = 0;
151  virtual int currentFunction() const = 0;
152  virtual void modelChanged() = 0;
153 
154  protected: // utils
155  QRectF lastUserViewport() const { return userViewport; }
156  QRectF normalizeUserViewport(const QRectF uvp); // from userViewport to viewport, this one uses current scale information
157  void updateScale(bool repaint);
158 
159  QPointF toWidget(const QPointF &) const;
160  QPointF fromWidget(const QPoint& p) const;
161  QPointF toViewport(const QPoint& mv) const;
162  QPair<QPointF, QString> calcImage(const QPointF& ndp) const;
163  QLineF slope(const QPointF& dp) const;
164 
165  QLineF toWidget(const QLineF &) const;
166  void setPaintedSize(const QSize& size);
167  void scaleViewport(qreal scale, const QPoint& center, bool repaint=true);
168 
169  private:
170  void drawAxes(QPainter* painter, GridStyle a) const;
171  void drawCircles(QPainter* painter, const GridInfo& gridinfo, GridStyle gridStyle) const;
172  void drawSquares(QPainter* painter, const GridInfo& gridinfo, GridStyle gridStyle) const;
173  void drawMainAxes(QPainter* painter) const;
174  void drawCartesianTickLabels(QPainter* painter, const GridInfo& gridinfo, CartesianAxis axis) const;
175  void drawPolarTickLabels(QPainter* painter, const GridInfo& gridinfo) const;
176  void drawGridTickLabels(QPainter* painter, const GridInfo& gridinfo, GridStyle gridStyle) const;
177  PlotItem *itemAt(int row) const;
178  int width() const { return m_size.width(); }
179  int height() const { return m_size.height(); }
180  const GridInfo getGridInfo() const; // calculate correct grid params
181  const QColor computeSubGridColor() const;
182  const QString computeAngleLabelByFrac(unsigned int n, unsigned int d) const; // input npi/d return angle in m_angleMode
183  const QString computeAngleLabelByStep(unsigned int k, unsigned int step) const; // input n*step*pi return angle in m_angleMode
184 
185  bool m_showGrid;
186  bool m_showMinorGrid;
187  QColor m_gridColor;
188  QColor m_backgroundColor;
189  bool m_autoGridStyle;
190  GridStyle m_gridStyleHint;
191  //TODO set move auto tick labels
192 
193  double rang_x, rang_y;
194  bool m_keepRatio;
195  bool m_dirty; // or m_updated; como ahora contamos con setmodel, es necesario que se actualicen los datos antes de pintar, es necesario que no sea dirty
196  QRectF viewport; // normalized viewport (with scale information), this one is the current viewport (used in currentViewport)
197  QRectF userViewport; // raw viewport that user sets by setViewport, so we need to normalized userViewport into viewport to include scale and aspect radio information
198  QSizeF m_size;
199  QAbstractItemModel* m_model;
200 
201  AngleMode m_angleMode;
202  ScaleMode m_scaleMode;
203  Qt::Orientations m_showTicks;
204  Qt::Orientations m_showTickLabels;
205  bool m_showMinorTicks;
206  Qt::Orientations m_showAxes;
207  bool m_showPolarAxis;
208  bool m_showPolarAngles;
209  QString m_axisXLabel;
210  QString m_axisYLabel;
211 
212  private: // constants
213  static const QColor m_axeColor;
214  static const QColor m_derivativeColor;
215  static const QString PiSymbol;
216  static const QString DegreeSymbol;
217  static const QString GradianSymbol;
218  static const double Pi6; // pi/6
219  static const double Pi12; // pi/12
220  static const double Pi36; // pi/36
221  static const double ZoomInFactor;
222  static const double ZoomOutFactor;
223 };
224 
225 }
226 
227 #endif // PLOTTER2D_H
plottingenums.h
QModelIndex
Analitza::Plotter2D::showGrid
bool showGrid() const
Returns whether we have chosen to draw the grid.
Definition: plotter2d.h:70
analitzaplotexport.h
Analitza::Plotter2D::gridColor
QColor gridColor() const
Definition: plotter2d.h:75
Qt::Orientations
typedef Orientations
Analitza::Plotter2D::setAutoGridStyle
void setAutoGridStyle(bool autogs)
If true then we ignore the grid style suggested by setGridStyleHint, if false then we use as grid sty...
Definition: plotter2d.h:83
QPaintDevice
Analitza::PlotItem
Represents a visual item.
Definition: plotitem.h:45
Analitza::Plotter2D::setGridColor
void setGridColor(const QColor &color)
Definition: plotter2d.h:72
Analitza::Plotter2D::autoGridStyle
bool autoGridStyle() const
Returns whether we will change automatically the grid style based on the curent plot.
Definition: plotter2d.h:86
Analitza::Plotter2D::keepAspectRatio
bool keepAspectRatio() const
Sets whether it is keeping the aspect ratio (1:1 grid).
Definition: plotter2d.h:95
Analitza::Plotter2D::setShowTicks
void setShowTicks(Qt::Orientations o)
Definition: plotter2d.h:127
Analitza::Plotter2D::ticksShown
Qt::Orientations ticksShown() const
Definition: plotter2d.h:138
Analitza::Plotter2D::setAngleMode
void setAngleMode(AngleMode am)
Definition: plotter2d.h:124
QPoint
Analitza::Plotter2D::setShowMinorTicks
void setShowMinorTicks(bool mt)
Definition: plotter2d.h:130
Analitza::AngleMode
AngleMode
Definition: plottingenums.h:77
Analitza::Plotter2D::setShowMinorGrid
void setShowMinorGrid(bool mt)
Definition: plotter2d.h:67
Analitza::Plotter2D::setShowGrid
void setShowGrid(bool show)
Sets whether we will draw the grid.
Definition: plotter2d.h:65
Analitza::Plotter2D::angleMode
AngleMode angleMode() const
Definition: plotter2d.h:125
QPointF
Analitza::Plotter2D::model
QAbstractItemModel * model() const
Definition: plotter2d.h:101
Analitza::Plotter2D::setShowTickLabels
void setShowTickLabels(Qt::Orientations o)
Definition: plotter2d.h:128
QPainter
QString
QColor
Analitza::Plotter2D::setBackgroundColor
void setBackgroundColor(const QColor &color)
Definition: plotter2d.h:77
QLineF
Analitza::Plotter2D::scaleMode
ScaleMode scaleMode() const
Definition: plotter2d.h:121
Analitza::Plotter2D
Render 2D plots.
Definition: plotter2d.h:55
QPair
Analitza::GridStyle
GridStyle
Definition: plottingenums.h:68
Analitza::Plotter2D::currentViewport
QRectF currentViewport() const
Definition: plotter2d.h:108
QSize
Analitza::Plotter2D::backgroundColor
QColor backgroundColor() const
Definition: plotter2d.h:80
Analitza::Plotter2D::lastUserViewport
QRectF lastUserViewport() const
Definition: plotter2d.h:155
Analitza::Plotter2D::lastViewport
QRectF lastViewport() const
Definition: plotter2d.h:111
QSizeF
QRectF
ANALITZAPLOT_EXPORT
#define ANALITZAPLOT_EXPORT
Definition: analitzaplotexport.h:28
Analitza::CartesianAxis
CartesianAxis
Definition: plottingenums.h:45
Analitza::Plotter2D::setShowAxes
void setShowAxes(Qt::Orientations o)
Definition: plotter2d.h:136
Analitza::Plotter2D::setShowPolarAngles
void setShowPolarAngles(bool pt)
Definition: plotter2d.h:134
QAbstractItemModel
Analitza::Plotter2D::setScaleMode
void setScaleMode(ScaleMode sm)
Definition: plotter2d.h:120
Analitza::ScaleMode
ScaleMode
Definition: plottingenums.h:84
Analitza::Plotter2D::setShowPolarAxis
void setShowPolarAxis(bool pt)
Definition: plotter2d.h:133
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:11:37 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Analitza

Skip menu "Analitza"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal