~ubuntu-branches/ubuntu/precise/grantlee/precise

« back to all changes in this revision

Viewing changes to scriptabletags/scriptablenode.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2010-06-11 23:41:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100611234145-oas7rhdrbwy8j55c
Tags: upstream-0.1.1
ImportĀ upstreamĀ versionĀ 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file is part of the Grantlee template system.
 
3
 
 
4
  Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
 
5
 
 
6
  This library is free software; you can redistribute it and/or
 
7
  modify it under the terms of the GNU Lesser General Public
 
8
  License as published by the Free Software Foundation; either version
 
9
  2 of the Licence, or (at your option) any later version.
 
10
 
 
11
  This library is distributed in the hope that it will be useful,
 
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
  Library General Public License for more details.
 
15
 
 
16
  You should have received a copy of the GNU Lesser General Public
 
17
  License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
*/
 
20
 
 
21
#ifndef SCRIPTABLE_NODE_H
 
22
#define SCRIPTABLE_NODE_H
 
23
 
 
24
#include <QtScript/QScriptValue>
 
25
 
 
26
#include <QtCore/QSharedPointer>
 
27
 
 
28
#include "node.h"
 
29
 
 
30
class QScriptEngine;
 
31
class QScriptContext;
 
32
 
 
33
namespace Grantlee
 
34
{
 
35
class Context;
 
36
class Engine;
 
37
}
 
38
 
 
39
typedef QSharedPointer<QScriptEngine> ScriptEnginePointer;
 
40
 
 
41
using namespace Grantlee;
 
42
 
 
43
Q_DECLARE_METATYPE( Grantlee::Node* )
 
44
 
 
45
QScriptValue ScriptableNodeConstructor( QScriptContext *context,
 
46
                                        QScriptEngine *engine );
 
47
 
 
48
 
 
49
QScriptValue nodeToScriptValue( QScriptEngine *engine, Node* const &node );
 
50
 
 
51
void nodeFromScriptValue( const QScriptValue &object, Node* &out );
 
52
 
 
53
class ScriptableNode : public Node
 
54
{
 
55
  Q_OBJECT
 
56
public:
 
57
  ScriptableNode( QObject* parent = 0 );
 
58
  void setScriptEngine( QScriptEngine* engine );
 
59
  void init( const QScriptValue &concreteNode,
 
60
             const QScriptValue &renderMethod );
 
61
 
 
62
  QScriptEngine* engine();
 
63
 
 
64
  void render( OutputStream *stream, Context *c );
 
65
 
 
66
private:
 
67
  QScriptEngine* m_scriptEngine;
 
68
  QScriptValue m_concreteNode;
 
69
  QScriptValue m_renderMethod;
 
70
 
 
71
public Q_SLOTS:
 
72
  void setNodeList( const QString &name, QObjectList );
 
73
 
 
74
};
 
75
 
 
76
class ScriptableNodeFactory : public AbstractNodeFactory
 
77
{
 
78
  Q_OBJECT
 
79
public:
 
80
  ScriptableNodeFactory( QObject* parent = 0 );
 
81
  void setScriptEngine( QScriptEngine *engine );
 
82
 
 
83
  /* reimp */ void setEngine( Grantlee::Engine *engine );
 
84
  void setFactory( QScriptValue factoryMethod );
 
85
 
 
86
  Node* getNode( const QString &tagContent, Parser *p = 0 ) const;
 
87
 
 
88
private:
 
89
  QScriptEngine* m_scriptEngine;
 
90
  QScriptValue m_factoryMethod;
 
91
};
 
92
 
 
93
 
 
94
#endif
 
95