QString Converter::listTypeFor(const QString &itemTypeName, KODE::Class &newClass)
{
    if (itemTypeName == QLatin1String("QString")) {
        newClass.addHeaderInclude("QtCore/QStringList");
        return "QStringList";
    }
    return "QList< " + itemTypeName + " >";
}
Beispiel #2
0
void Converter::convertOutputMessage( const Port&, const Message &message, KODE::Class &newClass )
{
  Message::Part part = message.parts().first();

  // signal
  QString messageName = message.name();
  messageName[ 0 ] = messageName[ 0 ].lower();
  KODE::Function respSignal( messageName, "void", KODE::Function::Signal );

  /**
    If one output message is used by two input messages, don't define
    it twice.
   */
  if ( newClass.hasFunction( respSignal.name() ) )
    return;

  const Message::Part::List parts = message.parts();
  Message::Part::List::ConstIterator it;
  for ( it = parts.begin(); it != parts.end(); ++it ) {
    QStringList headers = mTypeMapper.header( (*it).type() );
    for ( uint i = 0; i < headers.count(); ++i )
      if ( !headers[ i ].isEmpty() )
        newClass.addHeaderInclude( headers[ i ] );

    respSignal.addArgument( mTypeMapper.argument( "value", (*it).type() ) );
  }

  newClass.addFunction( respSignal );

  // slot
  KODE::Function respSlot( messageName + "Slot", "void", KODE::Function::Slot | KODE::Function::Private );
  respSlot.addArgument( "const QString &xml" );

  KODE::Code code;
  code += "QDomDocument doc;";
  code += "QString errorMsg;";
  code += "int column, row;";
  code.newLine();
  code += "qDebug( \"%s\", xml.latin1() );";
  code.newLine();
  code += "if ( !doc.setContent( xml, true, &errorMsg, &row, &column ) ) {";
  code.indent();
  code += "qDebug( \"Unable to parse xml: %s (%d:%d)\", errorMsg.latin1(), row, column );";
  code += "return;";
  code.unindent();
  code += "}";
  code.newLine();
  code += mTypeMapper.type( part.type() ) + "* value = new " + mTypeMapper.type( part.type() ) + ";";
  code += "QDomElement envelope = doc.documentElement();";
  code += "QDomElement body = envelope.firstChild().toElement();";
  code += "QDomElement method = body.firstChild().toElement();";
  code += "Serializer::demarshal( method.firstChild().toElement(), value );";
  code.newLine();
  code += "emit " + respSignal.name() + "( value );";
  respSlot.setBody( code );

  newClass.addFunction( respSlot );
}