Beispiel #1
0
void Lua::LuaGraphTreeModel::loadLuaModel( QString name, const Diluculum::LuaValue value, LuaGraphTreeItem* parent )
{
	if ( value.type() == 5 ) {
		LuaGraphTreeItem* newParent = new LuaGraphTreeItem( QList<QVariant>() << name << "", parent );
		parent->appendChild( newParent );
		Diluculum::LuaValueMap tableValue = value.asTable();
		for ( Diluculum::LuaValueMap::iterator i = tableValue.begin(); i != tableValue.end(); ++i ) {
			loadLuaModel( QString::fromStdString( i->first.asString() ), i->second, newParent );
		}
	}
	else {
		Lua::LuaInterface* lua = Lua::LuaInterface::getInstance();
		Diluculum::LuaValueList param;
		param.push_back( value );
		std::string textValue = lua->callFunction( "tostring", param )[0].asString();
		QList<QVariant> list = QList<QVariant>() << name << QString::fromStdString( textValue );
		parent->appendChild( new LuaGraphTreeItem( list, parent ) );
	}
}
void QWebViewImage::showTemplate( const std::string& templateName, Diluculum::LuaValueMap models, const std::string& templateType )
{
    qDebug() << templateName.c_str() << templateType.c_str();
	// Initialize lua interface to call slt2 renderer
	Lua::LuaInterface* lua = Lua::LuaInterface::getInstance();
	QString renderer[] = {"slt2_renderer", "render"};

	// Prepare parameters to be passed to template renderer
	Diluculum::LuaValueList params;
	params.push_back( templateName );
	params.push_back( models );

	// Call slt2 renderer
	std::string html = lua->callFunction( 2, renderer, params )[0].asString();
//    qDebug() << html.c_str();

	// Create relative webview dir url
	QString appPath = QCoreApplication::applicationDirPath();
	QString webviewPath = appPath.append( "/../share/3dsoftviz/webview/index.html" );
	QUrl baseUrl = QUrl::fromLocalFile( webviewPath );

	// Set angular template type using query string
	if ( !templateType.empty() ) {

		// Fragment represents value after # hash in url. For example: http://something/index.html#<fragment>
        baseUrl.setFragment( QString::fromStdString( templateType ) );
//        baseUrl.setFragment( "git" );
	}

    qDebug() << "Webview url: " << baseUrl;

	// Set html and baseUrl working directory
    _webView->setHtml( html.c_str(), baseUrl );

//    qDebug() << _webView->page()->currentFrame()->toHtml();
}