LCOV - code coverage report
Current view: top level - templates/scriptabletags - scriptabletemplate.cpp (source / functions) Hit Total Coverage
Test: test_all.info Lines: 0 31 0.0 %
Date: 2011-06-24 Functions: 0 6 0.0 %
Branches: 0 82 0.0 %

           Branch data     Line data    Source code
       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.1 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                 :            :   Lesser 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                 :            : #include "scriptabletemplate.h"
      22                 :            : 
      23                 :            : #include <QtScript/QScriptContext>
      24                 :            : #include <QtScript/QScriptEngine>
      25                 :            : 
      26                 :            : #include "engine.h"
      27                 :            : #include "context.h"
      28                 :            : #include "node.h"
      29                 :            : #include "scriptablecontext.h"
      30                 :            : 
      31         [ #  # ]:          0 : Q_DECLARE_METATYPE( Engine* )
      32                 :            : 
      33                 :          0 : QScriptValue ScriptableTemplateConstructor( QScriptContext *context,
      34                 :            :     QScriptEngine *engine )
      35                 :            : {
      36 [ #  # ][ #  # ]:          0 :   QString content = context->argument( 0 ).toString();
      37 [ #  # ][ #  # ]:          0 :   QString name = context->argument( 1 ).toString();
         [ #  # ][ #  # ]
      38 [ #  # ][ #  # ]:          0 :   QObject *parent = context->argument( 2 ).toQObject();
                 [ #  # ]
      39 [ #  # ][ #  # ]:          0 :   Engine *templateEngine = engine->property( "templateEngine" ).value<Engine *>();
                 [ #  # ]
      40                 :            : 
      41         [ #  # ]:          0 :   if ( !templateEngine )
      42         [ #  # ]:          0 :     return QScriptValue();
      43                 :            : 
      44 [ #  # ][ #  # ]:          0 :   Template t = templateEngine->newTemplate( content, name );
      45                 :            : 
      46 [ #  # ][ #  # ]:          0 :   ScriptableTemplate *object = new ScriptableTemplate( t, parent );
         [ #  # ][ #  # ]
      47 [ #  # ][ #  # ]:          0 :   return engine->newQObject( object );
      48                 :            : }
      49                 :            : 
      50                 :          0 : ScriptableTemplate::ScriptableTemplate( Grantlee::Template t, QObject* parent )
      51         [ #  # ]:          0 :     : QObject( parent ), m_template( t )
      52                 :            : {
      53                 :            : 
      54                 :          0 : }
      55                 :            : 
      56                 :          0 : QString ScriptableTemplate::render( ScriptableContext* c )
      57                 :            : {
      58                 :          0 :   return m_template->render( c->context() );
      59                 :            : }
      60                 :            : 
      61                 :          0 : QObjectList ScriptableTemplate::nodeList() const
      62                 :            : {
      63                 :          0 :   NodeList nodeList = m_template->nodeList();
      64         [ #  # ]:          0 :   QObjectList objList;
      65                 :            : 
      66 [ #  # ][ #  # ]:          0 :   QListIterator<Node *> it( nodeList );
      67 [ #  # ][ #  # ]:          0 :   while ( it.hasNext() ) {
      68 [ #  # ][ #  # ]:          0 :     objList << it.next();
      69                 :            :   }
      70                 :            :   return objList;
      71                 :            : }
      72                 :            : 
      73                 :          0 : void ScriptableTemplate::setNodeList( const QObjectList& list )
      74                 :            : {
      75                 :          0 :   NodeList nodeList;
      76                 :            : 
      77 [ #  # ][ #  # ]:          0 :   QListIterator<QObject *> it( list );
      78                 :            : 
      79 [ #  # ][ #  # ]:          0 :   while ( it.hasNext() ) {
      80 [ #  # ][ #  # ]:          0 :     Node *n = qobject_cast<Node*>( it.next() );
      81         [ #  # ]:          0 :     if ( n ) {
      82         [ #  # ]:          0 :       nodeList << n;
      83                 :            :     }
      84                 :            :   }
      85 [ #  # ][ #  # ]:          0 :   m_template->setNodeList( nodeList );
      86                 :          0 : }
      87                 :            : 
      88                 :            : #include "scriptabletemplate.moc"
      89                 :            : 

Generated by: LCOV version 1.9