Warning, file /education/analitza/analitzawidgets/plotsview2d.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /************************************************************************************* 0002 * Copyright (C) 2007-2008 by Aleix Pol <aleixpol@kde.org> * 0003 * Copyright (C) 2012-2013 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU General Public License * 0007 * as published by the Free Software Foundation; either version 2 * 0008 * of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the Free Software * 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0018 *************************************************************************************/ 0019 0020 #ifndef PLOTSVIEW2D_H 0021 #define PLOTSVIEW2D_H 0022 0023 #include <QResizeEvent> 0024 #include <QWheelEvent> 0025 #include <QMouseEvent> 0026 #include <QPaintEvent> 0027 #include <QKeyEvent> 0028 #include <QWidget> 0029 #include <QPainter> 0030 #include <QLabel> 0031 #include <QPixmap> 0032 #include <QModelIndex> 0033 0034 #include "analitzawidgets_export.h" 0035 #include <analitzaplot/plotter2d.h> 0036 0037 class QItemSelectionModel; 0038 0039 namespace Analitza 0040 { 0041 0042 /** 0043 * \class PlotsView2D 0044 * 0045 * \ingroup AnalitzaGUIModule 0046 * 0047 * \brief Widget that allows visualization of 2D plots. 0048 * 0049 * This class lets you create a widget that can draw multiple 2D graphs. This widget 0050 * use Plotter2D as a backend. 0051 */ 0052 0053 class ANALITZAWIDGETS_EXPORT PlotsView2D : public QWidget, public Plotter2D 0054 { 0055 Q_OBJECT 0056 0057 Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid) 0058 0059 /** The default grid color is a soft mix between KColorScheme::NormalBackground and KColorScheme::NormalText (foreground) of QPalette::Active. **/ 0060 Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor) 0061 0062 /** The default background color is KColorScheme::NormalBackground of QPalette::Active. **/ 0063 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) 0064 0065 Q_PROPERTY(bool autoGridStyle READ autoGridStyle WRITE setAutoGridStyle) 0066 0067 public: 0068 enum Format { PNG, SVG }; 0069 0070 /** Constructor. Constructs a new Graph2D. */ 0071 explicit PlotsView2D(QWidget* parent = nullptr); 0072 0073 ~PlotsView2D() override; 0074 0075 QSize sizeHint() const override { return QSize(100, 100); } 0076 0077 /** Saves the graphs to a file located at @p path. */ 0078 bool toImage(const QString& path, Format f); 0079 0080 /** Returns the viewing port */ 0081 QRectF definedViewport() const; 0082 0083 void setSelectionModel(QItemSelectionModel* selection); 0084 0085 public Q_SLOTS: 0086 /** Marks the image as dirty and repaints everything. */ 0087 void forceRepaint() override { valid=false; repaint(); } 0088 0089 /** Sets the viewport to a default viewport. */ 0090 void resetViewport() { setViewport(defViewport); } 0091 0092 /** Returns whether it has a little border frame. */ 0093 bool isFramed() const { return m_framed; } 0094 0095 /** Sets whether it has a little border frame. */ 0096 void setFramed(bool fr) { m_framed=fr; } 0097 0098 /** Returns whether it is a read-only widget. */ 0099 bool isReadOnly() const { return m_readonly; } 0100 0101 /** Sets whether it is a read-only widget. */ 0102 void setReadOnly(bool ro); 0103 0104 void snapshotToClipboard(); 0105 0106 //exposed from plotter2d as slots... 0107 void setXAxisLabel(const QString &label) { Plotter2D::setXAxisLabel(label); } 0108 void setYAxisLabel(const QString &label) { Plotter2D::setYAxisLabel(label); } 0109 void setGridColor(const QColor &color) { Plotter2D::setGridColor(color); } 0110 void setTicksShown(QFlags<Qt::Orientation> o) { Plotter2D::setShowTickLabels(o); } 0111 void setAxesShown(QFlags<Qt::Orientation> o) { Plotter2D::setShowAxes(o); } 0112 //TODO set bgcolor, setbgcolormode auto means that colo is chosses based in lumninosisty onf current bgprofiles 0113 0114 /** Zooms in to the Viewport center */ 0115 virtual void zoomIn() { Plotter2D::zoomIn(true); } 0116 0117 /** Zooms out */ 0118 virtual void zoomOut() { Plotter2D::zoomOut(true); } 0119 0120 void modelChanged() override; 0121 0122 private Q_SLOTS: 0123 void changeViewport(const QRectF& vp) { setViewport(vp); } 0124 0125 Q_SIGNALS: 0126 /** Emits a status when it changes. */ 0127 void status(const QString &msg); 0128 0129 void viewportChanged(const QRectF&); 0130 0131 void showGridChanged() override; 0132 0133 private: 0134 //TODO setviewmodemosusemovemode, pan 0135 /** The graph mode will especify the selection mode we are using at the moment */ 0136 enum GraphMode { 0137 None=0, /**< Normal behaviour */ 0138 Pan, /**< Panning, translates the viewport. */ 0139 Selection /**< There is a rectangle delimiting a region, for zooming. */ 0140 }; 0141 0142 private: 0143 virtual void viewportChanged() override; 0144 virtual int currentFunction() const override; 0145 0146 //painting 0147 QPixmap buffer; 0148 bool valid; 0149 QPointF mark; 0150 QPoint cursorPos; 0151 0152 //events 0153 void paintEvent( QPaintEvent * ) override; 0154 void mousePressEvent(QMouseEvent *e) override; 0155 void mouseReleaseEvent(QMouseEvent *e) override; 0156 void mouseMoveEvent(QMouseEvent *e) override; 0157 void keyPressEvent(QKeyEvent * e ) override; 0158 void wheelEvent(QWheelEvent *e) override; 0159 void resizeEvent(QResizeEvent *) override; 0160 0161 GraphMode mode; 0162 QPoint press; QPoint last; 0163 0164 //presentation 0165 QPointF ant; 0166 QRectF defViewport; 0167 0168 void sendStatus(const QString& msg) { emit status(msg); } 0169 bool m_framed; 0170 bool m_readonly; 0171 QString m_posText; 0172 QItemSelectionModel* m_selection; 0173 }; 0174 0175 } 0176 0177 #endif