Exemple #1
0
void RootContainer::outputItem(NPT_XmlSerializer& xml, const Item *obj, const NPT_String& resUriTmpl)
{
	xml.StartElement(NULL, "item");
	xml.Attribute(NULL, "id", obj->id());
	xml.Attribute(NULL, "parentID", obj->parent() ? obj->parent()->id() : "-1");
	xml.Attribute(NULL, "restricted", "0");//obj->restricted() ? "true" : "false");

	outputObject(xml, obj, resUriTmpl);

	xml.EndElement(NULL, "item");
}
Exemple #2
0
void RootContainer::outputContainer(NPT_XmlSerializer& xml, const Container *obj, const NPT_String& resUriTmpl)
{
	xml.StartElement(NULL, "container");
	xml.Attribute(NULL, "id", obj->id());
	xml.Attribute(NULL, "parentID", obj->parent() ? obj->parent()->id() : "-1");
	xml.Attribute(NULL, "childCount", NPT_String::FromInteger(obj->childCount()));
	xml.Attribute(NULL, "searchable", obj->searchable() ? "true" : "false");
	xml.Attribute(NULL, "restricted", obj->restricted() ? "true" : "false");

	outputObject(xml, obj, resUriTmpl);

	xml.EndElement(NULL, "container");
}
Exemple #3
0
static void outputLayoutWidgetsSubLayout( QMap<int, QStringList>& buddies,
					  UibIndexMap& objects,
					  UibStrTable& strings,
					  QDataStream& out, QDomElement elem )
{
    int subLayoutNo = -1;
    QCString name;
    QDomElement nameElem;

    QDomElement f = elem.firstChild().toElement();
    while ( !f.isNull() ) {
	QString tag = f.tagName();
	if ( tag == "grid" || tag == "hbox" || tag == "vbox" ) {
	    out << (Q_UINT8) Object_SubLayout;
	    subLayoutNo = outputObject( buddies, objects, strings, out, f,
					layoutForTag(tag) );
	} else if ( tag == "property" ) {
	    if ( f.attribute("name") == "name" ) {
		name = DomTool::elementToVariant( f, name ).asCString();
		nameElem = f;
	    }
	}
	f = f.nextSibling().toElement();
    }

    if ( subLayoutNo != -1 ) {
	/*
	  Remove the sub-layout's Object_End marker, append the grid
	  cell and the correct name property, and put the Object_End
	  marker back.
	*/
	out.device()->at( out.device()->at() - 1 );
	outputGridCell( out, elem );
	outputProperty( buddies, subLayoutNo, strings, out, nameElem );
	out << (Q_UINT8) Object_End;

	objects.setName( subLayoutNo, name );
    }
}
Exemple #4
0
void convertUiToUib( QDomDocument& doc, QDataStream& out )
{
    QByteArray introBlock;
    QByteArray actionsBlock;
    QByteArray buddiesBlock;
    QByteArray connectionsBlock;
    QByteArray functionsBlock;
    QByteArray imagesBlock;
    QByteArray menubarBlock;
    QByteArray slotsBlock;
    QByteArray tabstopsBlock;
    QByteArray toolbarsBlock;
    QByteArray variablesBlock;
    QByteArray widgetBlock;

    QDomElement actionsElem;
    QDomElement connectionsElem;
    QDomElement imagesElem;
    QDomElement menubarElem;
    QDomElement tabstopsElem;
    QDomElement toolbarsElem;
    QDomElement widgetElem;

    QMap<int, QStringList> buddies;
    UibStrTable strings;
    UibIndexMap objects;
    int widgetNo = -1;
    QCString className;
    Q_INT16 defaultMargin = -32768;
    Q_INT16 defaultSpacing = -32768;
    Q_UINT8 introFlags = 0;

    QDomElement elem = doc.firstChild().toElement().firstChild().toElement();
    while ( !elem.isNull() ) {
	QString tag = elem.tagName();

	switch ( tag[0].latin1() ) {
	case 'a':
	    if ( tag == "actions" )
		actionsElem = elem;
	    break;
	case 'c':
	    if ( tag == "class" ) {
		className = elem.firstChild().toText().data().latin1();
	    } else if ( tag == "connections" ) {
		connectionsElem = elem;
	    }
	    break;
	case 'f':
	    if ( tag == "functions" ) {
		QDataStream out2( functionsBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "function" ) {
			packStringSplit( strings, out2,
					 f.attribute("name").latin1(), '(' );
			packString( strings, out2,
				    f.firstChild().toText().data() );
		    }
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 'i':
	    if ( tag == "images" ) {
		QDataStream out2( imagesBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "image" ) {
			QString name = f.attribute( "name" );
			QDomElement g = f.firstChild().toElement();
			if ( g.tagName() == "data" ) {
			    QString format = g.attribute( "format", "PNG" );
			    QString hex = g.firstChild().toText().data();
			    int n = hex.length() / 2;
			    QByteArray data( n );
			    for ( int i = 0; i < n; i++ )
				data[i] = (char) hex.mid( 2 * i, 2 )
						    .toUInt( 0, 16 );

			    packString( strings, out2, name );
			    packString( strings, out2, format );
			    packUInt32( out2, g.attribute("length").toInt() );
			    packByteArray( out2, data );
			}
		    }
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 'l':
	    if ( tag == "layoutdefaults" ) {
		QString margin = elem.attribute( "margin" );
		if ( !margin.isEmpty() )
		    defaultMargin = margin.toInt();
		QString spacing = elem.attribute( "spacing" );
		if ( !spacing.isEmpty() )
		    defaultSpacing = spacing.toInt();
	    }
	    break;
	case 'm':
	    if ( tag == "menubar" )
		menubarElem = elem;
	    break;
	case 'p':
	    if ( tag == "pixmapinproject" )
		introFlags |= Intro_Pixmapinproject;
	    break;
	case 's':
	    if ( tag == "slots" ) {
		QDataStream out2( slotsBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "slot" ) {
			QString language = f.attribute( "language", "C++" );
			QString slot = UibHack::normalize(
				f.firstChild().toText().data() );
			packString( strings, out2, language );
			packStringSplit( strings, out2, slot, '(' );
		    }
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 't':
	    if ( tag == "tabstops" ) {
		tabstopsElem = elem;
	    } else if ( tag == "toolbars" ) {
		toolbarsElem = elem;
	    }
	    break;
	case 'v':
	    if ( tag == "variable" ) {
		QDataStream out2( variablesBlock, IO_WriteOnly | IO_Append );
		packString( strings, out2, elem.firstChild().toText().data() );
	    } else if ( tag == "variables" ) {
		QDataStream out2( variablesBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "variable" )
			packString( strings, out2,
				    f.firstChild().toText().data() );
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 'w':
	    if ( tag == "widget" )
		widgetElem = elem;
	}
	elem = elem.nextSibling().toElement();
    }

    {
	QDataStream out2( widgetBlock, IO_WriteOnly );
	widgetNo = outputObject( buddies, objects, strings, out2, widgetElem,
				 "QWidget" );
    }

    if ( !tabstopsElem.isNull() ) {
	QDataStream out2( tabstopsBlock, IO_WriteOnly );
	QDomElement f = tabstopsElem.firstChild().toElement();
	while ( !f.isNull() ) {
	    if ( f.tagName() == "tabstop" ) {
		QString widgetName = f.firstChild().toText().data();
		int no = objects.find( widgetName );
		if ( no != -1 )
		    packUInt16( out2, no );
	    }
	    f = f.nextSibling().toElement();
	}
    }

    if ( !actionsElem.isNull() ) {
	QDataStream out2( actionsBlock, IO_WriteOnly );
	outputObject( buddies, objects, strings, out2, actionsElem );
    }

    if ( !menubarElem.isNull() ) {
	QDataStream out2( menubarBlock, IO_WriteOnly );
	outputObject( buddies, objects, strings, out2, menubarElem,
		      "QMenuBar" );
    }

    if ( !toolbarsElem.isNull() ) {
	QDataStream out2( toolbarsBlock, IO_WriteOnly );
	QDomElement f = toolbarsElem.firstChild().toElement();
	while ( !f.isNull() ) {
	    if ( f.tagName() == "toolbar" )
		outputObject( buddies, objects, strings, out2, f, "QToolBar" );
	    f = f.nextSibling().toElement();
	}
    }

    if ( !buddies.isEmpty() ) {
	QDataStream out2( buddiesBlock, IO_WriteOnly );
	QMap<int, QStringList>::ConstIterator a = buddies.begin();
	while ( a != buddies.end() ) {
	    QStringList::ConstIterator b = (*a).begin();
	    while ( b != (*a).end() ) {
		int no = objects.find( *b );
		if ( no != -1 ) {
		    packUInt16( out2, a.key() );
		    packUInt16( out2, no );
		}
		++b;
	    }
	    ++a;
	}
    }

    if ( !connectionsElem.isNull() ) {
	QString prevLanguage = "C++";
	int prevSenderNo = 0;
	QString prevSignal = "clicked()";
	int prevReceiverNo = 0;
	QString prevSlot = "accept()";

	QDataStream out2( connectionsBlock, IO_WriteOnly );
	QDomElement f = connectionsElem.firstChild().toElement();
	while ( !f.isNull() ) {
	    if ( f.tagName() == "connection" ) {
		QMap<QString, QString> argMap;

		QDomElement g = f.firstChild().toElement();
		while ( !g.isNull() ) {
		    argMap[g.tagName()] = g.firstChild().toText().data();
		    g = g.nextSibling().toElement();
		}

		QString language = f.attribute( "language", "C++" );
		int senderNo = objects.find( argMap["sender"], widgetNo );
		int receiverNo = objects.find( argMap["receiver"], widgetNo );
		QString signal = UibHack::normalize( argMap["signal"] );
		QString slot = UibHack::normalize( argMap["slot"] );

		Q_UINT8 connectionFlags = 0;
		if ( language != prevLanguage )
		    connectionFlags |= Connection_Language;
		if ( senderNo != prevSenderNo )
		    connectionFlags |= Connection_Sender;
		if ( signal != prevSignal )
		    connectionFlags |= Connection_Signal;
		if ( receiverNo != prevReceiverNo )
		    connectionFlags |= Connection_Receiver;
		if ( slot != prevSlot )
		    connectionFlags |= Connection_Slot;
		out2 << connectionFlags;

		if ( connectionFlags & Connection_Language )
		    packString( strings, out2, language );
		if ( connectionFlags & Connection_Sender )
		    packUInt16( out2, senderNo );
		if ( connectionFlags & Connection_Signal )
		    packStringSplit( strings, out2, signal, '(' );
		if ( connectionFlags & Connection_Receiver )
		    packUInt16( out2, receiverNo );
		if ( connectionFlags & Connection_Slot )
		    packStringSplit( strings, out2, slot, '(' );

		prevLanguage = language;
		prevSenderNo = senderNo;
		prevSignal = signal;
		prevReceiverNo = receiverNo;
		prevSlot = slot;
	    } else if ( f.tagName() == "slot" ) {
		// ###
	    }
	    f = f.nextSibling().toElement();
	}
    }

    {
	QDataStream out2( introBlock, IO_WriteOnly );
	out2 << introFlags;
	out2 << defaultMargin;
	out2 << defaultSpacing;
	packUInt16( out2, objects.count() );
	packCString( strings, out2, className );
    }

    out << UibMagic;
    out << (Q_UINT8) '\n';
    out << (Q_UINT8) '\r';
    out << (Q_UINT8) out.version();
    outputBlock( out, Block_Strings, strings.block() );
    outputBlock( out, Block_Intro, introBlock );
    outputBlock( out, Block_Images, imagesBlock );
    outputBlock( out, Block_Widget, widgetBlock );
    outputBlock( out, Block_Slots, slotsBlock );
    outputBlock( out, Block_Tabstops, tabstopsBlock );
    outputBlock( out, Block_Actions, actionsBlock );
    outputBlock( out, Block_Menubar, menubarBlock );
    outputBlock( out, Block_Toolbars, toolbarsBlock );
    outputBlock( out, Block_Variables, variablesBlock );
    outputBlock( out, Block_Functions, functionsBlock );
    outputBlock( out, Block_Buddies, buddiesBlock );
    outputBlock( out, Block_Connections, connectionsBlock );
    out << (Q_UINT8) Block_End;
}
Exemple #5
0
static int outputObject( QMap<int, QStringList>& buddies,
			 UibIndexMap& objects, UibStrTable& strings,
			 QDataStream& out, QDomElement elem,
			 QCString className )
{
    bool isQObject = !className.isEmpty();

    if ( className == "QToolBar" )
	out << (Q_UINT8) elem.attribute( "dock", "0" ).toInt();
    if ( className == "QWidget" )
	className = elem.attribute( "class", className ).latin1();

    int objectNo = -1;
    if ( isQObject ) {
	packCString( strings, out, className );
	objectNo = objects.insert();
    }

    outputGridCell( out, elem );

    // optimization: insert '&Foo' into string-table before 'Foo'
    if ( className == "QAction" || className == "QActionGroup" ) {
	QVariant value = DomTool::readProperty( elem, "menuText", QVariant() );
	if ( value.asString().startsWith("&") )
	    strings.insertString( value.asString() );
    }

    QDomElement f = elem.firstChild().toElement();
    while ( !f.isNull() ) {
	QString tag = f.tagName();
	if ( tag == "action" ) {
	    if ( elem.tagName() == "item" || elem.tagName() == "toolbar" ) {
		QString actionName = f.attribute( "name" );
		int no = objects.find( actionName );
		if ( no != -1 ) {
		    out << (Q_UINT8) Object_ActionRef;
		    packUInt16( out, no );
		}
	    } else {
		out << (Q_UINT8) Object_SubAction;
		outputObject( buddies, objects, strings, out, f, "QAction" );
	    }
	} else if ( tag == "actiongroup" ) {
	    out << (Q_UINT8) Object_SubAction;
	    outputObject( buddies, objects, strings, out, f, "QActionGroup" );
	} else if ( tag == "attribute" ) {
	    out << (Q_UINT8) Object_Attribute;
	    outputProperty( buddies, objectNo, strings, out, f );
	} else if ( tag == "column" ) {
	    out << (Q_UINT8) Object_Column;
	    outputObject( buddies, objects, strings, out, f );
	} else if ( tag == "event" ) {
	    out << (Q_UINT8) Object_Event;
	    packCString( strings, out, f.attribute("name").latin1() );
	    packVariant( strings, out,
			 QStringList::split(',', f.attribute("functions")) );
	} else if ( tag == "grid" || tag == "hbox" || tag == "vbox" ) {
	    out << (Q_UINT8) Object_SubLayout;
	    outputObject( buddies, objects, strings, out, f,
			  layoutForTag(tag) );
	} else if ( tag == "item" ) {
	    if ( elem.tagName() == "menubar" ) {
		out << (Q_UINT8) Object_MenuItem;
		packCString( strings, out, f.attribute("name").latin1() );
		packCString( strings, out, f.attribute("text").utf8() );
		outputObject( buddies, objects, strings, out, f );
	    } else {
		out << (Q_UINT8) Object_Item;
		outputObject( buddies, objects, strings, out, f );
	    }
	} else if ( tag == "property" ) {
	    outputProperty( buddies, objectNo, strings, out, f );
	} else if ( tag == "row" ) {
	    out << (Q_UINT8) Object_Row;
	    outputObject( buddies, objects, strings, out, f );
	} else if ( tag == "separator" ) {
	    out << (Q_UINT8) Object_Separator;
	} else if ( tag == "spacer" ) {
	    out << (Q_UINT8) Object_Spacer;
	    outputObject( buddies, objects, strings, out, f );
	} else if ( tag == "widget" ) {
	    if ( f.attribute("class") == "QLayoutWidget" &&
		 elem.tagName() != "widget" ) {
		outputLayoutWidgetsSubLayout( buddies, objects, strings, out,
					      f );
	    } else {
		out << (Q_UINT8) Object_SubWidget;
		outputObject( buddies, objects, strings, out, f, "QWidget" );
	    }
	}
	f = f.nextSibling().toElement();
    }
    out << (Q_UINT8) Object_End;
    if ( isQObject )
	objects.setName( objectNo,
			 DomTool::readProperty(elem, "name", "").asString() );
    return objectNo;
}