File indexing completed on 2024-04-21 14:42:57

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 #include <QtQml/qqmlregistration.h>
0028 
0029 namespace Analitza {
0030 class Variables;
0031 }
0032 
0033 class Graph2DMobile : public QQuickItem, public Analitza::Plotter2D
0034 {
0035     Q_OBJECT
0036     QML_NAMED_ELEMENT(Graph2DView)
0037     Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelHasChanged)
0038     Q_PROPERTY(QRectF viewport READ lastViewport WRITE setViewport RESET resetViewport)
0039     Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid NOTIFY showGridChanged)
0040     Q_PROPERTY(bool showMinorGrid READ showMinorGrid WRITE setShowMinorGrid)
0041     Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
0042     Q_PROPERTY(bool currentFunction READ currentFunction WRITE setCurrentFunction)
0043     Q_PROPERTY(bool ticksShown READ ticksShownAtAll WRITE setTicksShownAtAll)
0044     Q_PROPERTY(bool minorTicksShown READ minorTicksShown WRITE setShowMinorTicks)
0045     Q_PROPERTY(QStringList filters READ filters CONSTANT)
0046     public:
0047         explicit Graph2DMobile(QQuickItem* parent = nullptr);
0048 
0049         virtual void forceRepaint() override;
0050         virtual void viewportChanged() override {}
0051         virtual void modelChanged() override;
0052         virtual int currentFunction() const override { return m_currentFunction; }
0053 
0054         void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
0055 
0056         QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override;
0057 
0058         void setCurrentFunction(int f) { m_currentFunction = f; }
0059         bool ticksShownAtAll() const { return ticksShown()!=0; }
0060         void setTicksShownAtAll(bool shown);
0061 
0062         QStringList filters() const;
0063 
0064 
0065     public Q_SLOTS:
0066         void translate(qreal x, qreal y);
0067         void scale(qreal s, int x, int y);
0068         void resetViewport();
0069         QStringList addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars = {});
0070         bool save(const QUrl &url) const;
0071 
0072     Q_SIGNALS:
0073         void showGridChanged() override;
0074         void modelHasChanged();
0075 
0076     private:
0077         void paint();
0078 
0079         bool m_dirty;
0080         int m_currentFunction;
0081 
0082         QImage m_buffer;
0083         QRectF defViewport;
0084 };
0085 
0086 #endif // GRAPH2DMOBILE_H