File indexing completed on 2024-04-14 14:32:23

0001 //
0002 // C++ Interface: cscripteval
0003 //
0004 // Description: 
0005 //
0006 /*
0007 Copyright 2010-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef CSCRIPTEVAL_H
0024 #define CSCRIPTEVAL_H
0025 
0026 #include <cactionbase.h>
0027 #include <kmuddy_export.h>
0028 #include <QString>
0029 #include <QMap>
0030 #include <QVariant>
0031 
0032 class QEvent;
0033 
0034 /** cScriptEval - evaluates QtScript scripts. */
0035 class KMUDDY_EXPORT cScriptEval : public QObject, public cActionBase
0036 {
0037 Q_OBJECT
0038 public:
0039   cScriptEval (int sess);
0040   ~cScriptEval() override;
0041 
0042   /** Add object to the global script namespace. */
0043   void addObject (QString name, QObject *object);
0044 
0045   /* Evaluate */
0046   void eval (QString script, QMap<QString, QVariant> variables = QMap<QString, QVariant>());
0047   /** Abort evaluation. */
0048   void abort ();
0049 
0050   /* Validate. Returns an empty string if it's ok, error message if not. */
0051   static QString validate (QString script);
0052 
0053 private:
0054   bool event(QEvent *e) override;
0055   class Private;
0056   Private *d;
0057 };
0058 
0059 #endif  // CSCRIPTEVAL_H