• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/RocsCore

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • RocsCore
KrossBackend.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2004-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "KrossBackend.h"
19 #include "DataStructure.h"
20 #include "Data.h"
21 #include <kross/core/action.h>
22 #include <kross/core/manager.h>
23 #include <QDebug>
24 
25 KrossBackend::KrossBackend(QVariantList *dataStructures)
26 {
27  _dataStructures = dataStructures;
28 }
29 
30 void KrossBackend::setScript(const QString& s)
31 {
32  _script = s;
33 }
34 
35 void KrossBackend::setBackend(const QString& backend)
36 {
37  _backend = backend;
38 }
39 
40 Kross::Action* KrossBackend::execute()
41 {
42  qDebug() << "entering the Execute part";
43 
44  if (_backend == "javascript") {
45  qDebug() << "implementing the jsDefaults";
46  jsDefaults();
47  } else if (_backend == "python") {
48  qDebug() << "implementing the Python Defaults";
49  pyDefaults();
50  } else if (_backend == "ruby") {
51  qDebug() << "implementing the Ruby Defaults ";
52  rbDefaults();
53  } else {
54  qDebug() << "Backend Not Implemented Yet.";
55  return 0;
56  }
57  qDebug() << "creating the action";
58  Kross::Action *action = new Kross::Action(0, "myScript");
59 
60  qDebug() << "setting the backend" << _backend.toAscii();
61  action->setInterpreter(_backend);
62  qDebug() << "interpreter set.";
63 
64  // action->addObject( _dataStructures, "Graphs" );
65 
66 
67  DataStructure *g = 0;
68  foreach(const QVariant & v, (*_dataStructures)) {
69  qDebug() << "Got inside of the foreach";
70  g = qobject_cast<DataStructure*>(v.value<QObject*>());
71  if (!g) {
72  qDebug() << "Graph is NULL";
73  continue;
74  }
75  if (g->property("name") != QVariant()) {
76  qDebug() << "adding the Graph " << g->property("name").toString().toAscii();
77  action->addObject(g, g->property("name").toString());
78  }
80 // Datum *n = 0;
81 // foreach( QVariant v2, g->data()){
82 // n = v2.value<Datum*>();
83 // if (n == 0){
84 // qDebug() << "Datum is NULL";
85 // continue;
86 // }
87 // if ( n->property("name") != QVariant() ){
88 // qDebug() << "adding the Graph " << n->property("name").toString().toAscii();
89 // action->addObject( n, n->property("name").toString());
90 // }
91 // }
92  }
93 
94  QString codeToBeExecuted = "";
95 
96  codeToBeExecuted += _autoGeneratedScript;
97  codeToBeExecuted += _script;
98  qDebug() << "Code to be Executed: \n" << codeToBeExecuted.toAscii();
99  qDebug() << " \nsetting the code";
100  action->setCode(codeToBeExecuted.toAscii());
101 
102  qDebug() << "triggering the code";
103  action->trigger();
104 
105  qDebug() << "triggering the action";
106  return action;
107 }
108 
109 
110 void KrossBackend::javaDefaults()
111 {
112 
113 }
114 
115 void KrossBackend::raptorDefaults()
116 {
117 
118 }
119 
120 void KrossBackend::pyDefaults()
121 {
122  _autoGeneratedScript.clear();
123  //_autoGeneratedScript += "import Graphs \n";
124 
126  DataStructure *g = 0;
127  foreach(const QVariant & v, (*_dataStructures)) {
128  g = qobject_cast<DataStructure*>(v.value<QObject*>());
129  _autoGeneratedScript += "# -*- coding: utf-8 -*- \n";
130  if (g->property("name") != QVariant()) {
131  _autoGeneratedScript += "import ";
132  _autoGeneratedScript += g->property("name").toString();
133  _autoGeneratedScript += '\n';
134  }
135  }
136 
137 }
138 
139 void KrossBackend::rbDefaults()
140 {
141  _autoGeneratedScript.clear();
142  //_autoGeneratedScript += "require 'Graphs' \n";
143 
145  DataStructure *g = 0;
146  foreach(const QVariant & v, (*_dataStructures)) {
147  g = qobject_cast<DataStructure*>(v.value<QObject*>());
148  if (g->property("name") != QVariant()) {
149  _autoGeneratedScript += "require '";
150  _autoGeneratedScript += g->property("name").toString();
151  _autoGeneratedScript += "' \n";
152  }
153  }
154 
155 }
156 
157 void KrossBackend::jsDefaults()
158 {
159 
160 }
161 
162 void KrossBackend::luaDefaults()
163 {
164 
165 }
166 
167 void KrossBackend::csDefaults()
168 {
169 
170 }
171 
172 void KrossBackend::loadFile(const QString& file)
173 {
174  qDebug() << "Got in here";
175  _script.clear();
176 
177  QFile f(file);
178  if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
179  qDebug() << "File not found";
180  return;
181  }
182 
183  while (! f.atEnd()) {
184  QByteArray line = f.readLine();
185  _script += line;
186  }
187  _script += '\n';
188 }
KrossBackend.h
DataStructure
Definition: DataStructure.h:43
QByteArray
QVariant::value
T value() const
Data.h
QFile
KrossBackend::loadFile
void loadFile(const QString &file)
Definition: KrossBackend.cpp:172
QString::clear
void clear()
KrossBackend::setScript
void setScript(const QString &s)
Definition: KrossBackend.cpp:30
DataStructure.h
QObject::property
QVariant property(const char *name) const
QObject
QString
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QFile::atEnd
virtual bool atEnd() const
KrossBackend::execute
Kross::Action * execute()
Definition: KrossBackend.cpp:40
KrossBackend::setBackend
void setBackend(const QString &backend)
Definition: KrossBackend.cpp:35
KrossBackend::KrossBackend
KrossBackend(QVariantList *dataStructures)
Definition: KrossBackend.cpp:25
QVariant::toString
QString toString() const
QString::toAscii
QByteArray toAscii() const
QIODevice::readLine
qint64 readLine(char *data, qint64 maxSize)
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal