115 lines
3.3 KiB
C++
115 lines
3.3 KiB
C++
#ifndef CUSTOMQWTPLOT_H
|
|
#define CUSTOMQWTPLOT_H
|
|
|
|
#include <QMap>
|
|
#include <QwtPlot>
|
|
#include <QwtPlotPanner>
|
|
// #include <QwtPlotMagnifier>
|
|
#include <QwtPlotPicker>
|
|
|
|
class QwtPlotCurve;
|
|
class QwtPlotMarker;
|
|
class QwtPlotZoneItem;
|
|
class QwtPlotShapeItem;
|
|
class QwtScaleWidget;
|
|
class QwtPlotMagnifier;
|
|
|
|
class CustomQwtPlotAxisPanner : public QwtPlotPanner
|
|
{
|
|
public:
|
|
CustomQwtPlotAxisPanner(QwtScaleWidget *scale_widget);
|
|
virtual ~CustomQwtPlotAxisPanner();
|
|
protected:
|
|
virtual void moveCanvas(int dx, int dy) override;
|
|
};
|
|
|
|
// class CustomQwtPlotXaxisMagnifier : public QwtPlotMagnifier
|
|
// {
|
|
// public:
|
|
// CustomQwtPlotXaxisMagnifier(QWidget *canvas);
|
|
// virtual ~CustomQwtPlotXaxisMagnifier();
|
|
// protected:
|
|
// virtual void rescale(double factor) override;
|
|
// };
|
|
|
|
class CustomQwtPlotXaxisSelector : public QwtPlotPicker
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit CustomQwtPlotXaxisSelector(QWidget* canvas);
|
|
virtual ~CustomQwtPlotXaxisSelector();
|
|
|
|
double selectedMinX() const;
|
|
double selectedMaxX() const;
|
|
void clearSelection();
|
|
|
|
signals:
|
|
void selectionFinished(double min_x, double max_x);
|
|
|
|
protected:
|
|
virtual void move(const QPoint& pos) override;
|
|
virtual bool end(bool ok) override;
|
|
|
|
private:
|
|
QwtPlotShapeItem* _overlay = nullptr;
|
|
double _min_x;
|
|
double _max_x;
|
|
};
|
|
|
|
class CustomQwtPlot : public QwtPlot
|
|
{
|
|
public:
|
|
explicit CustomQwtPlot(QWidget* parent = nullptr);
|
|
virtual ~CustomQwtPlot();
|
|
|
|
void SetAxisDragScale(QwtPlot::Axis axis_id, bool enable);
|
|
void SetAxisInitRange(QwtPlot::Axis axis_id, double min, double max);
|
|
|
|
void RegisterEventFilterFunc(std::function<bool(QObject*, QEvent*)> event_filter_func);
|
|
// void SetXaxisDragScale(bool enable);
|
|
void ResetPlot();
|
|
|
|
QwtPlotCurve* GetCurve(const QString& curve_name);
|
|
QList<QwtPlotCurve*> GetCurveList() const;
|
|
void AddCurve(QwtPlotCurve* curve, bool auto_color = true);
|
|
|
|
QwtPlotMarker* GetMarker(const QString& marker_name, const QString& postion);
|
|
QList<QwtPlotMarker*> GetMarkerList() const;
|
|
void AddMarker(QwtPlotMarker *marker, const QString &marker_name, const QString &postion);
|
|
void RemoveMarker(const QString& marker_name, const QString& postion);
|
|
void CleanMarkers();
|
|
|
|
QwtPlotZoneItem* GetZoneItem(const QString& zone_item_name);
|
|
QList<QwtPlotZoneItem*> GetZoneItemList() const;
|
|
void AddZoneItem(QwtPlotZoneItem *zone_item, const QString &zone_item_name);
|
|
void RemoveZoneItem(const QString& zone_item_name);
|
|
void CleanZoneItems();
|
|
|
|
protected:
|
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
|
// virtual void showEvent(QShowEvent *event) override;
|
|
|
|
private:
|
|
double _init_x_min = 0, _init_x_max = 0;
|
|
double _init_y_min = 0, _init_y_max = 0;
|
|
// bool _is_dragging = false;
|
|
// QPoint _last_pos;
|
|
std::list<std::function<bool(QObject*, QEvent*)> > _event_filter_func_list = {};
|
|
private:
|
|
CustomQwtPlotAxisPanner* _x_axis_panner = nullptr;
|
|
CustomQwtPlotAxisPanner* _y_axis_panner = nullptr;
|
|
QwtPlotMagnifier* _x_axis_magnifier = nullptr;
|
|
QwtPlotMagnifier* _y_axis_magnifier = nullptr;
|
|
QMap<QString, QwtPlotCurve*> _curves;
|
|
QMap<QString, QMap<QString, QwtPlotMarker*> > _markers;
|
|
QMap<QString, QwtPlotZoneItem*> _zone_items;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QColor getDistinctColorForManyCurves(int curve_index);
|
|
|
|
#endif // CUSTOMQWTPLOT_H
|