static void saveSingleProperty( QTextStream &ts, const QString& name, const QString& value, int indent ) { ts << makeIndent( indent ) << "<property name=\"" << name << "\">" << endl; ++indent; ts << makeIndent( indent ) << "<string>" << value << "</string>" << endl; --indent; ts << makeIndent( indent ) << "</property>" << endl; }
json_string internalJSONNode::WriteChildren(unsigned int indent){ //Iterate through the children and write them if (Children.empty()) return WRITER_EMPTY; json_string indent_plus_one; json_string indent_this; json_string res; //handle whether or not it's formatted JSON if (indent != 0xFFFFFFFF){ //it's formatted, make the indentation strings indent_this = NEW_LINE + makeIndent(indent); indent_plus_one = NEW_LINE + makeIndent(++indent); } //else it's not formatted, leave the indentation strings empty const size_t size_minus_one = Children.size() - 1; size_t i=0; json_foreach(Children, it){ res += indent_plus_one + (*it) -> internal -> Write(indent, type() == JSON_ARRAY); if (i < size_minus_one) res += JSON_TEXT(","); //the last one does not get a comma, but all of the others do ++i; }
void Project::saveConnections() { #ifndef QT_NO_SQL if ( dbFile.isEmpty() ) { QFileInfo fi( fileName() ); setDatabaseDescription( fi.baseName() + ".db" ); } QFile f( makeAbsolute( dbFile ) ); if ( dbConnections.isEmpty() ) { if ( f.exists() ) f.remove(); setDatabaseDescription( "" ); modified = TRUE; return; } /* .db xml */ if ( f.open( IO_WriteOnly | IO_Translate ) ) { QTextStream ts( &f ); ts.setCodec( QTextCodec::codecForName( "UTF-8" ) ); ts << "<!DOCTYPE DB><DB version=\"1.0\">" << endl; /* db connections */ int indent = 0; for ( DatabaseConnection *conn = dbConnections.first(); conn; conn = dbConnections.next() ) { ts << makeIndent( indent ) << "<connection>" << endl; ++indent; saveSingleProperty( ts, "name", conn->name(), indent ); saveSingleProperty( ts, "driver", conn->driver(), indent ); saveSingleProperty( ts, "database", conn->database(), indent ); saveSingleProperty( ts, "username", conn->username(), indent ); saveSingleProperty( ts, "hostname", conn->hostname(), indent ); saveSingleProperty( ts, "port", QString::number( conn->port() ), indent ); /* connection tables */ QStringList tables = conn->tables(); for ( QStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) { ts << makeIndent( indent ) << "<table>" << endl; ++indent; saveSingleProperty( ts, "name", (*it), indent ); /* tables fields */ QStringList fields = conn->fields( *it ); for ( QStringList::Iterator it2 = fields.begin(); it2 != fields.end(); ++it2 ) { ts << makeIndent( indent ) << "<field>" << endl; ++indent; saveSingleProperty( ts, "name", (*it2), indent ); --indent; ts << makeIndent( indent ) << "</field>" << endl; } --indent; ts << makeIndent( indent ) << "</table>" << endl; } --indent; ts << makeIndent( indent ) << "</connection>" << endl; } ts << "</DB>" << endl; f.close(); } #endif }
static void createDescription( const QValueList<Widget> &l, QTextStream &ts ) { int indent = 0; ts << "<!DOCTYPE CW><CW>" << endl; ts << makeIndent( indent ) << "<customwidgets>" << endl; indent++; for ( QValueList<Widget>::ConstIterator it = l.begin(); it != l.end(); ++it ) { Widget w = *it; ts << makeIndent( indent ) << "<customwidget>" << endl; indent++; ts << makeIndent( indent ) << "<class>" << w.w->className() << "</class>" << endl; ts << makeIndent( indent ) << "<header location=\"" << w.location << "\">" << w.include << "</header>" << endl; ts << makeIndent( indent ) << "<sizehint>" << endl; indent++; ts << makeIndent( indent ) << "<width>" << w.w->sizeHint().width() << "</width>" << endl; ts << makeIndent( indent ) << "<height>" << w.w->sizeHint().height() << "</height>" << endl; indent--; ts << makeIndent( indent ) << "</sizehint>" << endl; ts << makeIndent( indent ) << "<container>" << ( w.w->inherits( "QGroupBox" ) || w.w->inherits( "QWidgetStack" ) ) << "</container>" << endl; ts << makeIndent( indent ) << "<sizepolicy>" << endl; indent++; ts << makeIndent( indent ) << "<hordata>" << (int)w.w->sizePolicy().horData() << "</hordata>" << endl; ts << makeIndent( indent ) << "<verdata>" << (int)w.w->sizePolicy().verData() << "</verdata>" << endl; indent--; ts << makeIndent( indent ) << "</sizepolicy>" << endl; QStrList sigs = w.w->metaObject()->signalNames( TRUE ); if ( !sigs.isEmpty() ) { for ( int i = 0; i < (int)sigs.count(); ++i ) ts << makeIndent( indent ) << "<signal>" << entitize( sigs.at( i ) ) << "</signal>" << endl; } QStrList slts = w.w->metaObject()->slotNames( TRUE ); if ( !slts.isEmpty() ) { for ( int i = 0; i < (int)slts.count(); ++i ) { QMetaData::Access data = w.w->metaObject()->slot( i, TRUE )->access; if ( data == QMetaData::Private ) continue; ts << makeIndent( indent ) << "<slot access=\"" << ( data == QMetaData::Protected ? "protected" : "public" ) << "\">" << entitize( slts.at( i ) ) << "</slot>" << endl; } } QStrList props = w.w->metaObject()->propertyNames( TRUE ); if ( !props.isEmpty() ) { for ( int i = 0; i < (int)props.count(); ++i ) { const QMetaProperty *p = w.w->metaObject()-> property( w.w->metaObject()-> findProperty( props.at( i ), TRUE ), TRUE ); if ( !p ) continue; if ( !p->writable() || !p->designable( w.w ) ) continue; ts << makeIndent( indent ) << "<property type=\"" << convert_type( p->type() ) << "\">" << entitize( p->name() ) << "</property>" << endl; } } indent--; ts << makeIndent( indent ) << "</customwidget>" << endl; } indent--; ts << makeIndent( indent ) << "</customwidgets>" << endl; ts << "</CW>" << endl; }