![]() |
GQLLC GMC-300
0.1
GQ Electronics Geiger-Counter Model 300
|
00001 // ************************************************************************** 00002 // File: plotter.hh 00003 // 00004 // Author: Phil Gillaspy 00005 // 00006 // Last Modified: 04/18/2012 00007 // 00008 // Description: 00009 // This is the class which plots the GQ GMC's CPM data. 00010 // 00011 // This code is virtually copied verbatim from the book "C++ GUI 00012 // Programming with Qt4. 00013 // 00014 // 00015 // ************************************************************************* 00016 00017 #ifndef PLOTTER_HH 00018 #define PLOTTER_HH 00019 00020 #include <QMap> 00021 #include <QPixmap> 00022 #include <QVector> 00023 #include <QWidget> 00024 00025 class QToolButton; 00026 class PlotSettings; 00027 00028 class Plotter : public QWidget 00029 { 00030 Q_OBJECT 00031 00032 public: 00033 Plotter(QWidget *parent = 0); 00034 00035 void startSample(void); 00036 void setPlotSettings(const PlotSettings &settings); 00037 void setCurveData(int id, const QVector<QPointF> &data); 00038 void clearCurve(int id); 00039 QSize minimumSizeHint() const; 00040 QSize sizeHint() const; 00041 00042 bool bScroll; 00043 00044 public slots: 00045 void zoomIn(); 00046 void zoomOut(); 00047 void timerEvent(QTimerEvent * event); 00048 00049 protected: 00050 void paintEvent(QPaintEvent *event); 00051 void resizeEvent(QResizeEvent *event); 00052 void mousePressEvent(QMouseEvent *event); 00053 void mouseMoveEvent(QMouseEvent *event); 00054 void mouseReleaseEvent(QMouseEvent *event); 00055 void keyPressEvent(QKeyEvent *event); 00056 void wheelEvent(QWheelEvent *event); 00057 00058 private: 00059 void updateRubberBandRegion(); 00060 void refreshPixmap(); 00061 void drawGrid(QPainter *painter); 00062 void drawCurves(QPainter *painter); 00063 00064 enum { Margin = 50 }; 00065 00066 QToolButton *zoomInButton; 00067 QToolButton *zoomOutButton; 00068 QMap<int, QVector<QPointF> > curveMap; 00069 QVector<PlotSettings> zoomStack; 00070 int curZoom; 00071 bool rubberBandIsShown; 00072 QRect rubberBandRect; 00073 QPixmap pixmap; 00074 00075 int myTimerID; 00076 int sampleCnt; 00077 }; 00078 00079 class PlotSettings 00080 { 00081 public: 00082 PlotSettings(); 00083 00084 void scroll(int dx, int dy); 00085 void adjust(); 00086 double spanX() const { return maxX - minX; } 00087 double spanY() const { return maxY - minY; } 00088 00089 double minX; 00090 double maxX; 00091 int numXTicks; 00092 double minY; 00093 double maxY; 00094 int numYTicks; 00095 00096 private: 00097 static void adjustAxis(double &min, double &max, int &numTicks); 00098 }; 00099 00100 #endif // PLOTTER_HH