File indexing completed on 2024-04-21 11:13:43

0001 /*************************************************************************************
0002  *  Copyright (C) 2007 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 VARIABLESMODEL_H
0020 #define VARIABLESMODEL_H
0021 
0022 #include <QAbstractTableModel>
0023 #include <QSharedPointer>
0024 #include "analitzaguiexport.h"
0025 #include <analitza/variables.h>
0026 
0027 namespace Analitza
0028 {
0029 class Expression;
0030 
0031 /**
0032  * \class VariablesModel
0033  * 
0034  * \ingroup AnalitzaGUIModule
0035  *
0036  * \brief Is a model class that has a relation of all operators string with their VariableType.
0037  */
0038 
0039 class ANALITZAGUI_EXPORT VariablesModel : public QAbstractTableModel
0040 {
0041     Q_OBJECT
0042     Q_PROPERTY(QSharedPointer<Analitza::Variables> variables READ variables WRITE setVariables)
0043     public:
0044         /** Constructor. Creates a new Variable Model. */
0045         explicit VariablesModel(QObject *parent=nullptr);
0046         VariablesModel(const QSharedPointer<Analitza::Variables> &v, QObject *parent = nullptr);
0047         void setVariables(const QSharedPointer<Analitza::Variables> &v);
0048         
0049         virtual QFlags< Qt::ItemFlag > flags(const QModelIndex& index) const override;
0050         bool setData(const QModelIndex& index, const QVariant& value, int role=Qt::EditRole) override;
0051         QVariant data( const QModelIndex &index, int role=Qt::DisplayRole) const override;
0052         QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override;
0053         int rowCount(const QModelIndex &parent) const override;
0054         int columnCount(const QModelIndex &) const override { return 2; }
0055         
0056         void insertVariable(const QString& name, const Analitza::Expression& value);
0057         void setEditable(bool ed) { m_editable=ed; }
0058         
0059         QSharedPointer<Analitza::Variables> variables() const { return m_vars; }
0060     public Q_SLOTS:
0061         /** Updates the variables information */
0062         void updateInformation();
0063         
0064     private:
0065         QSharedPointer<Analitza::Variables> m_vars;
0066         bool m_editable;
0067 };
0068 
0069 }
0070 #endif