QtiPlot 0.9.8.2
|
00001 /*************************************************************************** 00002 File : RangeSelectorTool.h 00003 Project : QtiPlot 00004 -------------------------------------------------------------------- 00005 Copyright : (C) 2006,2007 by Ion Vasilief, Knut Franke 00006 Email (use @ for *) : ion_vasilief*yahoo.fr, knut.franke*gmx.de 00007 Description : Plot tool for selecting ranges on curves. 00008 00009 ***************************************************************************/ 00010 00011 /*************************************************************************** 00012 * * 00013 * This program is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU General Public License as published by * 00015 * the Free Software Foundation; either version 2 of the License, or * 00016 * (at your option) any later version. * 00017 * * 00018 * This program is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00021 * GNU General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU General Public License * 00024 * along with this program; if not, write to the Free Software * 00025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 00026 * Boston, MA 02110-1301 USA * 00027 * * 00028 ***************************************************************************/ 00029 #ifndef RANGE_SELECTOR_TOOL_H 00030 #define RANGE_SELECTOR_TOOL_H 00031 00032 #include "PlotToolInterface.h" 00033 00034 #include <QPointer> 00035 00036 #include <qwt_double_rect.h> 00037 #include <qwt_plot_marker.h> 00038 #include <qwt_plot_picker.h> 00039 00040 class QwtPlotCurve; 00041 class QPoint; 00042 class QEvent; 00043 class QDialog; 00044 class QCheckBox; 00045 00057 class RangeSelectorTool : public QwtPlotPicker, public PlotToolInterface 00058 { 00059 Q_OBJECT 00060 public: 00061 RangeSelectorTool(Graph *graph, const QObject *status_target=NULL, const char *status_slot=""); 00062 virtual ~RangeSelectorTool(); 00063 double minXValue() const { return QMIN(d_active_marker.xValue(), d_inactive_marker.xValue()); } 00064 double maxXValue() const { return QMAX(d_active_marker.xValue(), d_inactive_marker.xValue()); } 00065 double minYValue() const { return QMIN(d_active_marker.yValue(), d_inactive_marker.yValue()); } 00066 double maxYValue() const { return QMAX(d_active_marker.yValue(), d_inactive_marker.yValue()); } 00067 int dataSize() const { return qAbs(d_active_point - d_inactive_point); } 00068 virtual bool eventFilter(QObject *obj, QEvent *event); 00069 bool keyEventFilter(QKeyEvent *ke); 00070 00071 QwtPlotCurve *selectedCurve() const { return d_selected_curve; } 00073 void setSelectedCurve(QwtPlotCurve *curve); 00074 00075 void copySelection(); 00076 void cutSelection(); 00077 void clearSelection(); 00078 void pasteSelection(); 00079 virtual int rtti() const {return PlotToolInterface::Rtti_RangeSelector;}; 00080 00081 void setVisible(bool on); 00082 bool isVisible(){return d_visible;}; 00083 00084 public slots: 00085 virtual void pointSelected(const QPoint &point); 00086 void setCurveRange(); 00087 void setEnabled(bool on = true); 00088 00089 private slots: 00090 void copyMultipleSelection(); 00091 void clearMultipleSelection(); 00092 void cutMultipleSelection(); 00093 00094 signals: 00099 void statusText(const QString&); 00101 void changed(); 00102 00103 protected: 00104 virtual void append(const QPoint& point) { pointSelected(point); } 00105 void emitStatusText(); 00106 void switchActiveMarker(); 00108 void setActivePoint(int index); 00109 00110 private: 00111 enum RangeEditOperation{Copy, Cut, Delete}; 00112 00113 void showSelectionDialog(RangeEditOperation op = Copy); 00114 bool mightNeedMultipleSelection(); 00116 void copySelectedCurve(); 00118 void clearSelectedCurve(); 00119 00120 QwtPlotMarker d_active_marker, d_inactive_marker; 00121 int d_active_point, d_inactive_point; 00122 QwtPlotCurve *d_selected_curve; 00123 bool d_enabled; 00124 bool d_visible; 00125 00126 QPointer <QDialog> d_selection_dialog; 00128 QList<QCheckBox *> d_selection_lst; 00129 }; 00130 00131 #endif // ifndef RANGE_SELECTOR_TOOL_H