// $Id: fgl_plot.h $ // ================================================================= // This code is distributed under the terms and conditions of the // CCP4 Program Suite Licence Agreement as 'Part 2' (Annex 2) // software. A copy of the CCP4 licence can be obtained by writing // to CCP4, Research Complex at Harwell, Rutherford Appleton // Laboratory, Didcot OX11 0FA, UK, or from // http://www.ccp4.ac.uk/ccp4license.php. // ================================================================= // // 29.08.13 <-- Date of Last Modification. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ---------------------------------------------------------------- // // **** Module : fgl_plot // ~~~~~~~~~ // **** Project : QtLibs/FGL - plotting in Qt // ~~~~~~~~~ // **** Classes : fgl::Plot // ~~~~~~~~~ // // (C) E. Krissinel 2012-2013 // // ================================================================= // #ifndef FGL_PLOT_H #define FGL_PLOT_H #include #include #include #include #include "fgl_axisdata.h" QT_BEGIN_NAMESPACE class QGraphicsLineItem; class QGraphicsRectItem; QT_END_NAMESPACE namespace fgl { class Scene; class XYFrame; class Range; class XYData; class XYZData; /// This is class for 2D plot. The plot may have several frames /// in case of broken axes class Plot { public: Plot (); ~Plot(); inline void setTitleBottom ( const QString & t ) { titleB = t; } inline void setTitleTop ( const QString & t ) { titleT = t; } inline void setTitleLeft ( const QString & t ) { titleL = t; } inline void setTitleRight ( const QString & t ) { titleR = t; } inline void setFont ( const QFont & f ) { font = f; } inline void setColor ( const QColor & c ) { color = c; } inline void setLineWidth ( const qreal lw ) { lineWidth = lw; } inline void setCharSize ( const qreal cs ) { charSize = cs; } inline QFont getFont () { return font; } inline QColor getColor () { return color; } inline qreal getLineWidth () { return lineWidth; } inline qreal getCharSize () { return charSize; } inline QRectF getBoundingRect() { return boundingRect; } qreal getNumbCharSize(); bool isCursorOn (); void setCursorOn ( Scene *scene, bool on ); bool isCursorVisible (); void setCursorVisible ( bool visible ); bool setCursor ( qreal screenX, qreal screenY, Scene *scene, XYFrame *&frame ); bool checkCursor ( qreal screenX, qreal screenY, Scene *scene, XYFrame *&frame ); inline qreal getCursorXValue() { return cursorXValue; } inline qreal getCursorYValue() { return cursorYValue; } inline int getDigBaseX () { return baseDigX; } inline int getDigBaseY () { return baseDigY; } bool isRectSelOn (); void setRectSelOn ( Scene *scene, bool on ); bool isRectSelVisible (); void setRectSelVisible ( bool visible ); bool setRectSel ( qreal screenX, qreal screenY, Scene *scene, XYFrame *&frame ); void getRectSel ( qreal &x1, qreal &y1, qreal &x2, qreal &y2 ); /// Adds frame to the plot and returns frame's reference. XYFrame *addFrame(); /// Returns list of frames inline QList getFrames() { return frames; } XYFrame *getFrame ( int i ); /// Removes frame from the plot. void removeFrame ( XYFrame *frame ); /// Makes frame tiles (plot with broken axes) void addFrameTiles ( const QList & xRanges, const QList & yRanges, const QRectF & plotRect ); /// Removes all frames. void clearFrames(); /// Adds 2D data to the plot and returns dataset pointer. XYData *addXYData ( const qreal *xvector, const qreal *yvector, const int npoints ); /// Adds 2D data to the plot and returns dataset pointer. XYData *addXYData ( const QVector & xvector, const QVector & yvector ); /// \brief Adds 3D data to the plot and returns dataset pointer. /// \param[in] xvector vector of x-nodes (monotonically increasing) /// \param[in] nx numver of x-nodes /// \param[in] yvector vector of y-nodes (monotonically increasing) /// \param[in] ny numver of y-nodes /// /// If nx=0 and ny=0, XY-grid is left undefined. XYZData *addXYZData ( const qreal *xvector, const int nx, const qreal *yvector, const int ny ); /// \brief Adds 3D data to the plot and returns dataset pointer. /// \param[in] xvector vector of x-nodes (monotonically increasing) /// \param[in] yvector vector of y-nodes (monotonically increasing) /// /// If length of x and y is zero, XY-grid is left undefined. XYZData *addXYZData ( const QVector & xvector, const QVector & yvector ); /// Returns number of 2D datasets inline int getNXYData() { return xydata.size(); } /// Returns number of 3D datasets inline int getNXYZData() { return xyzdata.size(); } /// Returns the specified 2D dataset (dataNo>=0) or NULL XYData *getXYData ( int dataNo ); /// Returns the specified 3D dataset (dataNo>=0) or NULL XYZData *getXYZData ( int dataNo ); /// Removes 2D dataset from the plot. void removeXYData ( XYData *dataset ); /// Removes 3D dataset from the plot. void removeXYZData ( XYZData *dataset ); /// Removes all data. void clearData(); /// Gets physical range of data in the plot bool getXYRange ( qreal & x1, qreal & x2, qreal & y1, qreal & y2 ); /// Removes all frames and data. void clear(); /// Chooses optimal plot scales to embed all data void fitToData ( XYFrame *frame ); /// Builds plot (not for external use). void makePlot ( Scene *scene ); /// Paints plot data (curves etc). void paintData ( QPainter *painter, Scene *scene ); protected: QList frames; //!< list of frames QList xydata; //!< list of 2D datasets QList xyzdata; //!< list of 3D datasets qreal sx1,sx2; //!< logical x-range of the plot qreal sy1,sy2; //!< logical y-range of the plot qreal qx1,qx2; //!< physical x-range of the plot qreal qy1,qy2; //!< physical y-range of the plot QRectF boundingRect; //!< bounding screen rect of the plot qreal titleBshift; //!< relative shift of bottom title qreal titleTshift; //!< relative shift of top title qreal titleLshift; //!< relative shift of left title qreal titleRshift; //!< relative shift of right title QString titleB; //!< axis title in the bottom QString titleT; //!< axis title on the top QString titleL; //!< axis title on the left QString titleR; //!< axis title on the right QGraphicsLineItem *xcursor; //!< cursor x-line QGraphicsLineItem *ycursor; //!< cursor y-line qreal cursorXValue; //!< physical x-value of cursor tip qreal cursorYValue; //!< physical y-value of cursor tip int baseDigX; //!< base number of digits for x-value int baseDigY; //!< base number of digits for y-value QGraphicsRectItem *rectSel; //!< rectangular area selector qreal rectSelX1; //!< physical x-value of rect sel left qreal rectSelY1; //!< physical y-value of rect sel top qreal rectSelX2; //!< physical x-value of rect sel right qreal rectSelY2; //!< physical y-value of rect sel bottom private: QFont font; QColor color; qreal lineWidth,charSize; }; } #endif // FGL_PLOT_H