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

0001 /*************************************************************************************
0002  *  Copyright (C) 2015 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 #ifndef GRAPH3DITEM_H
0020 #define GRAPH3DITEM_H
0021 
0022 #include <QQuickFramebufferObject>
0023 #include "plotter3d_es.h"
0024 
0025 class Graph3DItem;
0026 
0027 class Plotter3DRenderer : public QObject, public Analitza::Plotter3DES
0028 {
0029 public:
0030     explicit Plotter3DRenderer(Graph3DItem* item);
0031 
0032     int currentPlot() const override { return 0; }
0033     void modelChanged() override {}
0034     void renderGL() override;
0035 
0036     QQuickWindow* window() const;
0037     QImage grabImage() override;
0038 
0039 private:
0040     Graph3DItem * m_item;
0041 };
0042 
0043 class Graph3DItem : public QQuickFramebufferObject
0044 {
0045     Q_OBJECT
0046     Q_PROPERTY(QStringList filters READ filters CONSTANT)
0047     Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged)
0048     public:
0049         explicit Graph3DItem(QQuickItem* parent = Q_NULLPTR);
0050         ~Graph3DItem() override;
0051 
0052         QAbstractItemModel* model() const;
0053         void setModel(QAbstractItemModel* model);
0054 
0055         QQuickFramebufferObject::Renderer * createRenderer() const override;
0056 
0057         Q_SCRIPTABLE QStringList addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars = {});
0058         Q_SCRIPTABLE void rotate(qreal x, qreal y);
0059         Q_SCRIPTABLE void scale(qreal s);
0060         Q_SCRIPTABLE void resetViewport();
0061 
0062         Q_SCRIPTABLE bool save(const QUrl &url);
0063 
0064         QStringList filters() const;
0065 
0066     Q_SIGNALS:
0067         void modelChanged(QAbstractItemModel* model);
0068 
0069     private:
0070         Plotter3DRenderer *m_plotter;
0071 };
0072 
0073 #endif