1 /*************************************************************************************
2  *  Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org>                               *
3  *                                                                                   *
4  *  This program is free software; you can redistribute it and/or                    *
5  *  modify it under the terms of the GNU General Public License                      *
6  *  as published by the Free Software Foundation; either version 2                   *
7  *  of the License, or (at your option) any later version.                           *
8  *                                                                                   *
9  *  This program is distributed in the hope that it will be useful,                  *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
12  *  GNU General Public License for more details.                                     *
13  *                                                                                   *
14  *  You should have received a copy of the GNU General Public License                *
15  *  along with this program; if not, write to the Free Software                      *
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
17  *************************************************************************************/
18 
19 #ifndef OPERATORSMODEL_H
20 #define OPERATORSMODEL_H
21 
22 #include <QAbstractTableModel>
23 #include <QSharedPointer>
24 #include "analitzaguiexport.h"
25 
26 namespace Analitza
27 {
28 class Variables;
29 class Operator;
30 }
31 
32 //TODO: get in the namespace
33 /** Operators model is a model class that has a relation of all operators string with their OperatorType. */
34 class ANALITZAGUI_EXPORT OperatorsModel : public QAbstractTableModel
35 {
36     Q_OBJECT
37     public:
38         enum Roles {
39             IsVariableRole = Qt::UserRole + 1,
40             DescriptionRole
41         };
42 
43         /** Constructor. Creates a new Operator Model. */
44         explicit OperatorsModel(QObject *parent=nullptr);
45 
46         /** Returns the description of the @p o operator. */
47         static QString description(const Analitza::Operator& o);
48 
49         /** Returns the description of the @p o operator. */
50         static QString sample(const Analitza::Operator& o);
51 
52         static QString example(const Analitza::Operator& o);
53 
54         QHash<int, QByteArray> roleNames() const override;
55 
56         /** Adds an entry to the model. */
57     //     void addEntry(int i, const QString&, const QString&, const QString& ex=QString());
58 
59         /** Updates the variables information */
60         void updateInformation();
61 
62         QVariant data( const QModelIndex &index, int role=Qt::DisplayRole) const override;
63         QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override;
64         int rowCount(const QModelIndex &parent=QModelIndex()) const override;
65         int columnCount(const QModelIndex &parent=QModelIndex()) const override;
66 
setVariables(const QSharedPointer<Analitza::Variables> & v)67         void setVariables(const QSharedPointer<Analitza::Variables> &v) { m_vars=v; }
68         QModelIndex indexForOperatorName(const QString& id) const;
69         QString parameterHelp(const QModelIndex& idx, int param, bool inbounds) const;
70         static QString standardFunctionCallHelp(const QString& funcname, int param, int paramcount, bool inbounds, bool isbounded);
71 
72         Q_SCRIPTABLE static QString lastWord(int pos, const QString &exp);
73 
74     private:
75         QSharedPointer<Analitza::Variables> m_vars;
76 };
77 
78 
79 #endif
80