File indexing completed on 2024-12-22 04:17:43
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #ifndef PLOTRENDERITEM_H 0014 #define PLOTRENDERITEM_H 0015 0016 #include "viewitem.h" 0017 0018 #include <QList> 0019 #include <QPainterPath> 0020 0021 #include "relation.h" 0022 #include "selectionrect.h" 0023 0024 namespace Kst { 0025 0026 class PlotItem; 0027 class PlotRenderItem; 0028 0029 class PlotRenderItem : public ViewItem 0030 { 0031 Q_OBJECT 0032 public: 0033 enum RenderType {First, Cartesian, Polar, Sinusoidal }; 0034 0035 explicit PlotRenderItem(PlotItem *parentItem); 0036 virtual ~PlotRenderItem(); 0037 0038 PlotItem *plotItem() const; 0039 0040 virtual RenderType renderType() const; 0041 void setRenderType(RenderType type); 0042 0043 QRectF plotRect() const; 0044 0045 QRectF projectionRect() const; 0046 0047 RelationList relationList() const; 0048 void addRelation(RelationPtr relation); 0049 void removeRelation(RelationPtr relation); 0050 void clearRelations(); 0051 void setRelationsList(const RelationList &relations); 0052 0053 virtual void save(QXmlStreamWriter &xml); 0054 virtual void saveInPlot(QXmlStreamWriter &xml); 0055 virtual void paint(QPainter *painter); 0056 virtual void paintRelations(QPainter *painter) = 0; 0057 void paintReferencePoint(QPainter *painter); 0058 void paintHighlightPoint(QPainter *painter); 0059 0060 virtual bool configureFromXml(QXmlStreamReader &xml, ObjectStore *store); 0061 0062 QString leftLabel() const; 0063 QString bottomLabel() const; 0064 QString rightLabel() const; 0065 QString topLabel() const; 0066 QString multiRenderItemLabel(bool isX) const; 0067 0068 QRectF computedProjectionRect() const; 0069 void computeBorder(Qt::Orientation orientation, double *min, double *max) const; 0070 void resetSelectionRect(); 0071 0072 static void sanitizeMaxMin(double *min, double *max); 0073 0074 virtual bool tryShortcut(const QString &keySequence); 0075 0076 QList<PlotItem*> sharedOrTiedPlots(bool sharedX, bool sharedY); 0077 0078 void hoverYZoomMouseCursor(qreal y); 0079 void hoverXZoomMouseCursor(qreal x); 0080 0081 void dragYZoomMouseCursor(qreal y); 0082 void dragXZoomMouseCursor(qreal x); 0083 QPointF statusMessagePoint; 0084 0085 virtual bool updateViewItemParent(bool force_toplevel = false); 0086 0087 public Q_SLOTS: 0088 virtual void edit(); 0089 virtual void raise(); 0090 virtual void lower(); 0091 virtual void createAutoLayout(); 0092 virtual void createCustomLayout(int columns = 0); 0093 virtual void remove(); 0094 virtual void referenceMode(); 0095 virtual void referenceModeDisabled(); 0096 0097 protected: 0098 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); 0099 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); 0100 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 0101 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); 0102 virtual void wheelEvent(QGraphicsSceneWheelEvent *event); 0103 0104 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); 0105 0106 virtual void keyPressEvent(QKeyEvent *event); 0107 virtual void keyReleaseEvent(QKeyEvent *event); 0108 0109 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); 0110 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); 0111 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); 0112 0113 void setCursorsMode(QPointF p, Qt::KeyboardModifiers modifiers=0); 0114 0115 virtual QPainterPath shape() const; 0116 0117 private Q_SLOTS: 0118 void updateGeometry(); 0119 void updateViewMode(); 0120 0121 private: 0122 virtual void addToMenuForContextEvent(QMenu &menu); 0123 0124 void updateCursor(const QPointF &pos); 0125 void updateSelectionRect(); 0126 0127 void computeXAxisRange(double *min, double *max) const; 0128 void computeYAxisRange(double *min, double *max) const; 0129 void computeAuto(Qt::Orientation orientation, double *min, double *max) const; 0130 void computeMeanCentered(Qt::Orientation orientation, double *min, double *max) const; 0131 void computeNoSpike(Qt::Orientation orientation, double *min, double *max) const; 0132 0133 void highlightNearestDataPoint(const QPointF& position, bool delayed); 0134 void setReferencePoint(const QPointF& point); 0135 void processHoverMoveEvent(const QPointF& p, bool delayed = false); 0136 private: 0137 RenderType _type; 0138 QPointF _lastPos; 0139 QPointF _hoverPos; 0140 bool _referencePointMode; 0141 QPointF _referencePoint; 0142 bool _highlightPointActive; 0143 bool _invertHighlight; 0144 QPointF _highlightPoint; 0145 0146 RelationList _relationList; 0147 SelectionRect _selectionRect; 0148 }; 0149 0150 } 0151 0152 #endif 0153 0154 // vim: ts=2 sw=2 et