File indexing completed on 2022-09-27 12:21:23

0001 /*************************************************************************************
0002  *  Copyright (C) 2010 by Aleix Pol <aleixpol@kde.org>                               *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 
0020 #ifndef GRAPH2DMOBILE_H
0021 #define GRAPH2DMOBILE_H
0022 
0023 #include <QtQuick/QQuickPaintedItem>
0024 #include <analitzaplot/plotter2d.h>
0025 #include <QPixmap>
0026 #include <QAbstractItemModel>
0027 
0028 namespace Analitza {
0029 class Variables;
0030 }
0031 
0032 class Graph2DMobile : public QQuickItem, public Analitza::Plotter2D
0033 {
0034     Q_OBJECT
0035     Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelHasChanged)
0036     Q_PROPERTY(QRectF viewport READ lastViewport WRITE setViewport RESET resetViewport)
0037     Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid NOTIFY showGridChanged)
0038     Q_PROPERTY(bool showMinorGrid READ showMinorGrid WRITE setShowMinorGrid)
0039     Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
0040     Q_PROPERTY(bool currentFunction READ currentFunction WRITE setCurrentFunction)
0041     Q_PROPERTY(bool ticksShown READ ticksShownAtAll WRITE setTicksShownAtAll)
0042     Q_PROPERTY(bool minorTicksShown READ minorTicksShown WRITE setShowMinorTicks)
0043     Q_PROPERTY(QStringList filters READ filters CONSTANT)
0044     public:
0045         explicit Graph2DMobile(QQuickItem* parent = nullptr);
0046         
0047         virtual void forceRepaint() override;
0048         virtual void viewportChanged() override {}
0049         virtual void modelChanged() override;
0050         virtual int currentFunction() const override { return m_currentFunction; }
0051         
0052 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0053         void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override;
0054 #else
0055         void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
0056 #endif
0057         QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override;
0058         
0059         void setCurrentFunction(int f) { m_currentFunction = f; }
0060         bool ticksShownAtAll() const { return ticksShown()!=0; }
0061         void setTicksShownAtAll(bool shown);
0062         
0063         QStringList filters() const;
0064 
0065 
0066     public Q_SLOTS:
0067         void translate(qreal x, qreal y);
0068         void scale(qreal s, int x, int y);
0069         void resetViewport();
0070         QStringList addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars = {});
0071         bool save(const QUrl &url) const;
0072         
0073     Q_SIGNALS:
0074         void showGridChanged() override;
0075         void modelHasChanged();
0076 
0077     private:
0078         void paint();
0079 
0080         bool m_dirty;
0081         int m_currentFunction;
0082         
0083         QImage m_buffer;
0084         QRectF defViewport;
0085 };
0086 
0087 #endif // GRAPH2DMOBILE_H