示例#1
0
QString Ui3Reader::trcall(const QString& sourceText, const QString& comment)
{
    if (sourceText.isEmpty() && comment.isEmpty())
        return QLatin1String("QString()");

    QString t = trmacro;
    bool encode = false;
    if (t.isNull()) {
        t = QLatin1String("tr");
        for (int i = 0; i < (int) sourceText.length(); i++) {
            if (sourceText[i].unicode() >= 0x80) {
                t = QLatin1String("trUtf8");
                encode = true;
                break;
            }
        }
    }

    if (comment.isEmpty()) {
        return t + QLatin1Char('(') + fixString(sourceText, encode) + QLatin1Char(')');
    } else {
        return t + QLatin1Char('(')
               + fixString(sourceText, encode)
               + QLatin1String(", ")
               + fixString(comment, encode) + QLatin1Char(')');
    }
}
示例#2
0
/*print table in CSV format*/
void fprintTableCSV(FILE *fo, char **column, char **row, double **val, int nrow, int ncol, int rgrp, int doMax, int sgn) {
	int i, j, k, n;
	char form[50];
	n = nrow/rgrp;
	if(column != NULL) {
		for(j=0; j<ncol; j++)
			if(column[j] != NULL) {
				fixString(column[j]);
				fprintf(fo, "\t%s", column[j]);
			} else
				fprintf(fo, "\t ");
		fprintf(fo, "\n");
	}
	for(i=0; i<n; i++) {
		if(row != NULL && row[i] != NULL) {
			fixString(row[i]);
			fprintf(fo, "%s", row[i]);
		}
		for(j=0; j<rgrp; j++) {
			for(k=0; k<ncol; k++) {
				if(val[i*rgrp+j][k] != TABLE_NO_VALUE) {
					sprintf(form, "\\t%%.%df", sgn);
					fprintf(fo, form, val[i*rgrp+j][k]);
				} else
					fprintf(fo, "\t ");
			}
			fprintf(fo, "\n");
		}
	}
}
示例#3
0
文件: uic.cpp 项目: aroraujjwal/qt3
QString Uic::trcall( const QString& sourceText, const QString& comment )
{
    if ( sourceText.isEmpty() && comment.isEmpty() )
	return "QString::null";

    QString t = trmacro;
    bool encode = FALSE;
    if ( t.isNull() ) {
	t = "tr";
	for ( int i = 0; i < (int) sourceText.length(); i++ ) {
	    if ( sourceText[i].unicode() >= 0x80 ) {
		t = "trUtf8";
		encode = TRUE;
		break;
	    }
	}
    }

    if ( comment.isEmpty() ) {
	return t + "( " + fixString( sourceText, encode ) + " )";
    } else {
	return t + "( " + fixString( sourceText, encode ) + ", " +
	       fixString( comment, encode ) + " )";
    }
}
示例#4
0
Song & OnlineService::encode(Song &song)
{
    song.file=QUrl(song.file).toEncoded()+constUrlGuard+
              fixString(song.artist)+constDeliminator+
              fixString(song.albumartist)+constDeliminator+
              fixString(song.album)+constDeliminator+
              fixString(song.title)+constDeliminator+
              fixString(song.genres[0])+constDeliminator+
              QString::number(song.time)+constDeliminator+
              QString::number(song.year)+constDeliminator+
              QString::number(song.track)+constDeliminator+
              QString::number(song.disc)+constDeliminator+
              song.onlineService();
    return song;
}
示例#5
0
void WriteIconInitialization::acceptImage(DomImage *image)
{
    QString img = image->attributeName() + QLatin1String("_data");
    QString data = image->elementData()->text();
    QString fmt = image->elementData()->attributeFormat();

    QString imageId = image->attributeName() + QLatin1String("_ID");
    QString imageData = image->attributeName() + QLatin1String("_data");
    QString ind = option.indent;

    output << ind << "if( $id == " << imageId << " ) {\n";

    if (fmt == QLatin1String("XPM.GZ")) {
        output << option.indent << option.indent << "return " << "Qt::Pixmap(@" << imageData << ");\n";
        output << option.indent << "}\n";
    } else {
        output << option.indent << option.indent << 
                "my $img = Qt::Image();\n";
        output << option.indent << option.indent << "$img->loadFromData(" << imageData << ", " << 
                "$imageData->length, " << fixString(fmt, ind) << ");\n";
        output << option.indent << option.indent << 
                "return Qt::Pixmap->fromImage($img)\n";
        output << option.indent << "}\n";
    }
}
示例#6
0
void Uic::createFormImpl( const QDomElement& e, const QString& form, const QString& connection, const QString& table )
{
    if ( e.tagName() == "widget" &&
	 e.attribute( "class" ) != "QDataTable" ) {
	QString field = getDatabaseInfo( e, "field" );
	if ( !field.isEmpty() ) {
	    if ( isWidgetInTable( e, connection, table ) )
		out << indent << form << "Form->insert( " << getObjectName( e ) << ", " << fixString( field ) << " );" << endl;
	}
    }
    QDomElement n;
    for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
	createFormImpl( n, form, connection, table );
    }
}
示例#7
0
/*print table in Latex format*/
void fprintTableLatex(FILE *fo, char **column, char **row, double **val, int nrow, int ncol, int rgrp, int doMax, int sgn) {
	int i, j, k, n;
	n = nrow/rgrp;
	double prec = pow(10., (double) -sgn);
	char form[50];
	fprintf(fo, "%%\\usepackage{adjustbox}\n%%\\usepackage{array}\n\n\\newcolumntype{R}[2]{>{\\adjustbox{angle=#1,lap=\\width-(#2)}\\bgroup}l<{\\egroup}}\n\\newcommand*\\rot{\\multicolumn{1}{R{45}{1em}}}\n");
	fprintf(fo, "\\begin{tabular}{l");
	if(column != NULL) {
		for(i=0; i<ncol; i++)
			fprintf(fo, "r");
		fprintf(fo, "}\n~");
		for(i=0; i<ncol; i++)
			if(column[i] != NULL) {
				fixString(column[i]);
				fprintf(fo, "& \\rot{%s} ", column[i]);
			}else
				fprintf(fo, "& ");
		fprintf(fo, "\\\\\n\\hline\n");
	}
	for(i=0; i<n; i++) {
		double max;
		if(row != NULL && row[i] != NULL) {
			fixString(row[i]);
			fprintf(fo, "\\texttt{%s} ", row[i]);
		}
		if(doMax) {
			max = 0.;
			for(j=0; j<rgrp; j++)
				for(k=0; k<ncol; k++)
					if(val[i*rgrp+j][k] != TABLE_NO_VALUE && val[i*rgrp+j][k]>=max)
						max = val[i*rgrp+j][k];
			max = prec*(round(max/prec));
			for(j=0; j<rgrp; j++) {
				for(k=0; k<ncol; k++)
					if(val[i*rgrp+j][k] != TABLE_NO_VALUE && prec*(round(val[i*rgrp+j][k]/prec)) == max) {
						sprintf(form, "& \\textbf{%%.%df} ", sgn);
						fprintf(fo, form, val[i*rgrp+j][k]);
					} else {
						if(val[i*rgrp+j][k] != TABLE_NO_VALUE) {
							sprintf(form, "& %%.%df ", sgn);
							fprintf(fo, form, val[i*rgrp+j][k]);
						} else
							fprintf(fo, "& -- ");
					}
				fprintf(fo, "\\\\\n");
			}
		} else {
			for(j=0; j<rgrp; j++) {
				for(k=0; k<ncol; k++)
					if(val[i*rgrp+j][k] != TABLE_NO_VALUE) {
						sprintf(form, "& %%.%df ", sgn);
						fprintf(fo, form, val[i*rgrp+j][k]);
					} else
						fprintf(fo, "& -- ");
				fprintf(fo, "\\\\\n");
			}
		}
		if(rgrp > 1)
			fprintf(fo, "\\hline\n");
	}
	if(rgrp == 1)
		fprintf(fo, "\\hline\n");
	fprintf(fo, "\\end{tabular}\n");
}
示例#8
0
文件: main.cpp 项目: CIP-SSA/odktools
//This function construct an INSERT SQL and execute it againts the database.
QList<TfieldDef > createSQL(QSqlDatabase db,QVariantMap jsonData,QString table,QList< TfieldDef> fields,QList< TfieldDef> parentkeys,bool mTable = false, QVariantMap jsonData2 = emptyMap)
{
    QString sqlHeader;
    QString sqlValues;
    QString sql;
    QVariant variantValue;
    int pos;

    QList<TfieldDef > resKeys;

    QString fieldValue;

    int tblIndex;

    //log("Table:" + table);

    tblIndex = getLastIndex(table);

    sqlHeader = "INSERT INTO " + table + "(";
    sqlValues = " VALUES (";
    for (pos = 0; pos <= parentkeys.count()-1;pos++)
    {
        sqlHeader = sqlHeader + parentkeys[pos].name + ",";
        sqlValues = sqlValues + "'" + parentkeys[pos].value + "',";
    }
    for (pos = 0; pos <= fields.count()-1;pos++)
    {
        // If a new key is found in the list of fields
        // then we added to the result of keys that will be passes to any possible child table
        if (fields[pos].key == true)
        {
            TfieldDef key;
            key.key = true;
            key.name = fields[pos].name;
            key.xmlCode = fields[pos].xmlCode;


            key.value = extractNumber(jsonData[fields[pos].xmlCode].toString());
            key.value = key.value.simplified();

            // If its empty. The try to find it in jsonData2
            // This happens when the cover information is stored in a repeat of one
            // so part of the information for the main table must be searched in jsonData
            // and part in jsonData2
            if (key.value.isEmpty())
            {
                key.value = jsonData2[fields[pos].xmlCode].toString();
                key.value = key.value.simplified();
            }

            //If the key is empty (Normal as in the JSON such key does not exist) set the key value to tblIndex
            if (key.value.isEmpty())
            {                                
                if (!mTable)
                {
                    key.value = QString::number(tblIndex);
                    sqlHeader = sqlHeader + key.name + ",";
                    sqlValues = sqlValues + "'" + QString::number(tblIndex) + "',";
                }
                else
                {
                    key.value = "";
                    sqlHeader = sqlHeader + key.name + ",";
                    sqlValues = sqlValues + "'',";
                }
            }
            else
            {                
                sqlHeader = sqlHeader + key.name + ",";
                sqlValues = sqlValues + "'" + fixString(key.value) + "',";
            }
            //Append the key to the list of returned keys
            key.value = key.value;
            resKeys.append(key);

        }
        else
        {
            sqlHeader = sqlHeader + fields[pos].name + ",";
            if (mainTable == table)
            {
                if (fields[pos].name == "surveyid")
                  sqlValues = sqlValues + "'" + fileID + "',";
                else
                {
                    if (fields[pos].name == "originid")
                        sqlValues = sqlValues + "'FORMHUB-JSON',";
                    else
                    {
                        fieldValue = fixString(jsonData[fields[pos].xmlCode].toString());
                        if (fieldValue.isEmpty())
                        {
                            // This happens when the cover information is stored in a repeat of one
                            // so part of the information for the main table must be searched in jsonData
                            // and part in jsonData2                            
                            fieldValue = fixString(jsonData2[fields[pos].xmlCode].toString());
                        }

                        sqlValues = sqlValues + "'" + fieldValue + "',";
                    }
                }
            }
            else
            {                                
                variantValue =  jsonData[fields[pos].xmlCode];                
                fieldValue = QString::fromUtf8(variantValue.toByteArray());                
                if (fieldValue.isEmpty())
                {
                    // This happens when the cover information is stored in a repeat of one
                    // so part of the information for the main table must be searched in jsonData
                    // and part in jsonData2
                    variantValue = jsonData2[fields[pos].xmlCode];                    
                    fieldValue = QString::fromUtf8(variantValue.toByteArray());
                }

                sqlValues = sqlValues + "'" + fixString(fieldValue) + "',";
            }
        }
    }

    //Removing final , and appending )
    sqlHeader = sqlHeader.left(sqlHeader.length()-1) + ")";
    sqlValues = sqlValues.left(sqlValues.length()-1) + ")";
    //Create the final sql
    sql = sqlHeader + " " + sqlValues;
    //Change all empty valued to NULL. This minimize foreign key errors in skips
    sql = sql.replace("''","NULL");

    //Execute the SQL to the database

    if (outSQL)
    {
        sqlStream << sql + ";\n";
    }

    if (!mTable)
    {
        QSqlQuery query(db);
        if (!query.exec(sql))
        {
            SQLError = true; //An error occurred. This will trigger a rollback
            logError(db,query.lastError().databaseText(),table,tblIndex,jsonData,fields,sql); //Write the error to the log
        }
    }
    else
    {
        if (!ignorePKError)
        {
            QSqlQuery query(db);
            if (!query.exec(sql))
            {
                SQLError = true; //An error occurred. This will trigger a rollback
                logError(db,query.lastError().databaseText(),table,tblIndex,jsonData,fields,sql); //Write the error to the log
            }
        }
    }



    return resKeys;
}
示例#9
0
文件: uic.cpp 项目: aroraujjwal/qt3
QString Uic::createTableRowColumnImpl( const QDomElement &e, const QString &parent,
				       QString *value )
{
    QString objClass = getClassName( e.parentNode().toElement() );
    QDomElement n = e.firstChild().toElement();
    QString txt;
    QString com;
    QString pix;
    QString field;
    bool isRow = e.tagName() == "row";
    while ( !n.isNull() ) {
	if ( n.tagName() == "property" ) {
	    QString attrib = n.attribute("name");
	    QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
	    if ( attrib == "text" ) {
		txt = v.toString();
		com = getComment( n );
	    } else if ( attrib == "pixmap" ) {
		pix = v.toString();
		if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) {
		    pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) );
		    pix.append( QString( externPixmaps ? "\"" : "" ) + " )" );
		}
	    } else if ( attrib == "field" )
		field = v.toString();
	}
	n = n.nextSibling().toElement();
    }

    if ( value )
	*value = trcall( txt, com );

    // ### This generated code sucks! We have to set the number of
    // rows/cols before and then only do setLabel/()
    // ### careful, though, since QDataTable has an API which makes this code pretty good

    QString s;
    if ( isRow ) {
	s = indent + parent + "->setNumRows( " + parent + "->numRows() + 1 );\n";
	if ( pix.isEmpty() )
	    s += indent + parent + "->verticalHeader()->setLabel( " + parent + "->numRows() - 1, "
		 + trcall( txt, com ) + " );\n";
	else
	    s += indent + parent + "->verticalHeader()->setLabel( " + parent + "->numRows() - 1, "
		 + pix + ", " + trcall( txt, com ) + " );\n";
    } else {
	if ( objClass == "QTable" ) {
	    s = indent + parent + "->setNumCols( " + parent + "->numCols() + 1 );\n";
	    if ( pix.isEmpty() )
		s += indent + parent + "->horizontalHeader()->setLabel( " + parent + "->numCols() - 1, "
		     + trcall( txt, com ) + " );\n";
	    else
		s += indent + parent + "->horizontalHeader()->setLabel( " + parent + "->numCols() - 1, "
		     + pix + ", " + trcall( txt, com ) + " );\n";
	} else if ( objClass == "QDataTable" ) {
	    if ( !txt.isEmpty() && !field.isEmpty() ) {
		if ( pix.isEmpty() )
		    out << indent << parent << "->addColumn( " << fixString( field ) << ", " << trcall( txt, com ) << " );" << endl;
		else
		    out << indent << parent << "->addColumn( " << fixString( field ) << ", " << trcall( txt, com ) << ", " << pix << " );" << endl;
	    }
	}
    }
    return s;
}
示例#10
0
文件: main.cpp 项目: qlands/GOBLET
void printResult(QSqlQuery query)
{
    int pos;
    QList<TfieldDef> fields;
    int ncols;
    ncols = 0;
    for (pos = 0; pos <= query.record().count()-1;pos++)
    {
        ncols++;
        TfieldDef field;
        field.fieldName = query.record().field(pos).name();


        switch (query.record().field(pos).type())
        {
        case QVariant::Bool:
            field.fieldType = "BOL";
            break;
        case QVariant::Char:
            field.fieldType = "CHR";
            break;
        case QVariant::Date:
            field.fieldType = "DAT";
            break;
        case QVariant::DateTime:
            field.fieldType = "DTM";
            break;
        case QVariant::Double:
            field.fieldType = "DBL";
            break;
        case QVariant::Int:
            field.fieldType = "INT";
            break;
        case QVariant::String:
            field.fieldType = "STR";
            break;
        case QVariant::Time:
            field.fieldType = "TIM";
            break;
        case QVariant::UInt:
            field.fieldType = "UIN";
            break;
        default:
            field.fieldType = "NA";
        }
        fields.append(field);
    }
    int nrows;
    nrows = 0;
    while (query.next())
    {
        nrows++;
    }
    nrows++; //Heads

    QVector<QVector<QString> >  grid;
    grid.resize(nrows);
    int r;
    for(r=0; r<nrows; r++)
    {
        grid[r].resize(ncols);
    }
    //Append the field names


    for (pos = 0; pos <= fields.count()-1;pos++)
        grid[0][pos] = fields[pos].fieldName;

    for (pos = 0; pos <= fields.count()-1;pos++)
        grid[0][pos] = fields[pos].fieldName;
    r = 1;
    query.first();
    QString value;
    while (query.isValid())
    {
        for (pos = 0; pos <= fields.count()-1;pos++)
        {
            if (fields[pos].fieldType == "DBL")
                value = QString::number(query.value(getFieldIndex(query,fields[pos].fieldName)).toDouble(),'f',3);
            else
            {
                if (fields[pos].fieldName != "ogc_geom")
                    value = query.value(getFieldIndex(query,fields[pos].fieldName)).toString().simplified();
                else
                    value = "Geometry data";
            }
            grid[r][pos] = value;
        }
        r++;
        query.next();
    }

    QVector< int> colSizes;
    colSizes.resize(ncols);
    for (pos = 0; pos <= ncols-1;pos++)
        colSizes[pos] = 0;
    //Get the maximum size of each column
    for (pos = 0; pos <= ncols-1;pos++)
    {
        for(r=0; r<nrows; r++)
        {
            if (grid[r][pos].length() +2 > colSizes[pos])
            {
                colSizes[pos] = grid[r][pos].length() +2;
            }
        }
    }
    //Print the table
    printf("\n");
    //Print top line
    for (pos=0;pos<= ncols-1;pos++)
    {
        printf("+");
        printf(fixLine("-",colSizes[pos]).toLocal8Bit().data());
    }
    printf("+");
    printf("\n");
    //Print the columns headings

    for (pos=0;pos<= ncols-1;pos++)
    {
        printf("+");
        printf(fixString(" " + grid[0][pos] + " ",colSizes[pos]).toLocal8Bit().data());

    }
    printf("+");
    printf("\n");

    //Print separation
    for (pos=0;pos<= ncols-1;pos++)
    {
        printf("+");
        printf(fixLine("-",colSizes[pos]).toLocal8Bit().data());
    }
    printf("+");
    printf("\n");

    //Print the values
    for (r=1;r<=nrows-1;r++)
    {
        printf("|");
        for (pos=0;pos<= ncols-1;pos++)
        {
            printf(fixString(" " + grid[r][pos] + " ",colSizes[pos]).toLocal8Bit().data());
            printf("|");
        }
        printf("\n");
    }

    //Print the end
    //Print separation
    for (pos=0;pos<= ncols-1;pos++)
    {
        printf("+");
        printf(fixLine("-",colSizes[pos]).toLocal8Bit().data());
    }
    printf("+");
    printf("\n");

}
void WriteIconInitialization::acceptImage(DomImage *image)
{
    QString img = image->attributeName() + QLatin1String("_data");
    QString data = image->elementData()->text();
    QString fmt = image->elementData()->attributeFormat();

    QString imageId = image->attributeName() + QLatin1String("_ID");
    QString imageData = image->attributeName() + QLatin1String("_data");
    QString ind = option.indent + option.indent;

    output << ind << "case " << imageId << ": ";

    if (fmt == QLatin1String("XPM.GZ")) {
        output << "return " << "QPixmap((const char**)" << imageData << ");\n";
    } else {
        output << " { QImage img; img.loadFromData(" << imageData << ", sizeof(" << imageData << "), " << fixString(fmt, ind) << "); return QPixmap::fromImage(img); }\n";
    }
}
示例#12
0
文件: main.cpp 项目: qlands/GOBLET
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    //Command line arguments
    TCLAP::CmdLine cmd("GOBLET (c) 2012, International Livestock Research Institute (ILRI) \n Developed by Carlos Quiros ([email protected])", ' ', "1.0 (Beta 1)");
    //Required arguments
    TCLAP::ValueArg<std::string> databaseArg("d","database","Database name",true,"","string");
    TCLAP::ValueArg<std::string> calculationArg("c","calculation","Calculation to perform. For example: 'sum(DatasetA),sum(DatasetB)' ",true,"","string");
    TCLAP::ValueArg<std::string> ouputArg("o","output","Output type: (h)uman readable or (c)omputer readable",true,"","string");


    //Non required arguments
    TCLAP::ValueArg<std::string> pathArg("a","path","Path to database. Default .",false,".","string");
    TCLAP::ValueArg<std::string> hostArg("H","host","Connect to host. Default localhost",false,"localhost","string");
    TCLAP::ValueArg<std::string> portArg("P","port","Port number to use. Default 3306",false,"3306","string");
    TCLAP::ValueArg<std::string> userArg("u","user","User. Default empty",false,"","string");
    TCLAP::ValueArg<std::string> passArg("p","password","Passwork. Default no password",false,"","string");
    TCLAP::ValueArg<std::string> descArg("s","descriptions","Descriptions for the calculations separated by coma. Default value is the calculation string",false,"","string");
    //Switches
    TCLAP::SwitchArg remoteSwitch("r","remote","Connect to remote host", cmd, false);
    cmd.add(databaseArg);
    cmd.add(calculationArg);
    cmd.add(ouputArg);


    cmd.add(pathArg);
    cmd.add(hostArg);
    cmd.add(portArg);
    cmd.add(userArg);
    cmd.add(passArg);
    cmd.add(descArg);


    //Parsing the command lines
    cmd.parse( argc, argv );

    //Getting the variables from the command
    bool remote = remoteSwitch.getValue();
    QString path = QString::fromUtf8(pathArg.getValue().c_str());
    QString dbName = QString::fromUtf8(databaseArg.getValue().c_str());
    QString host = QString::fromUtf8(hostArg.getValue().c_str());
    QString port = QString::fromUtf8(portArg.getValue().c_str());
    QString userName = QString::fromUtf8(userArg.getValue().c_str());
    QString password = QString::fromUtf8(passArg.getValue().c_str());
    QString calculation = QString::fromUtf8(calculationArg.getValue().c_str());
    QString format = QString::fromUtf8(ouputArg.getValue().c_str());
    QString description = QString::fromUtf8(descArg.getValue().c_str());

    myDBConn con;
    QSqlDatabase mydb;
    if (!remote)
    {
        QDir dir;
        dir.setPath(path);
        if (con.connectToDB(dir.absolutePath()) == 1)
        {
            if (!dir.cd(dbName))
            {
                gbtLog(QObject::tr("The database does not exists"));
                con.closeConnection();
                return 1;
            }
            mydb = QSqlDatabase::addDatabase(con.getDriver(),"connection1");
        }
    }
    else
    {
        mydb = QSqlDatabase::addDatabase("QMYSQL","connection1");
        mydb.setHostName(host);
        mydb.setPort(port.toInt());
        if (!userName.isEmpty())
           mydb.setUserName(userName);
        if (!password.isEmpty())
           mydb.setPassword(password);
    }

    mydb.setDatabaseName(dbName);

    if (!mydb.open())
    {
        gbtLog(QObject::tr("Cannot open database"));
        con.closeConnection();
        return 1;
    }
    else
    {
        QTime procTime;
        procTime.start();

        QString sql;
        QSqlQuery qry(mydb);

        QList <TdatasetInfo> datasets;

        if (constructSQL(calculation,sql,mydb,datasets))
        {
            gbtLog(QObject::tr("Error in calculation."));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }


        QDomDocument doc;
        QDomElement root;

        doc = QDomDocument("GOBLETXML");

        root = doc.createElement("CalcXML");
        root.setAttribute("version", "1.0");
        doc.appendChild(root);

        QDomElement varName;
        QDomText varValue;

        QList<TfieldDef> fields;
        int ncols;
        ncols = 0;

        if (!qry.exec(sql))
        {
            gbtLog(QObject::tr("Cannot reset dataset."));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }
        int nfields;
        nfields = qry.record().count();
        QString nfield;

        int pos;
        QStringList descriptions;
        descriptions = getDescriptions(description);

        if (descriptions.count() != nfields)
        {
            descriptions.clear();
            descriptions.append("Class code");
            for (pos = 1; pos <= nfields-1; pos++)
            {
                descriptions.append(qry.record().field(pos).name());
            }
        }


        for (pos = 0; pos <= nfields-1;pos++)
        {
            ncols++;
            nfield = descriptions[pos];
            nfield.replace("T" + datasets[pos].code + ".",datasets[pos].name + ".");
            nfield.replace(".cellvalue","");
            TfieldDef field;
            field.fieldName = nfield;
            field.fieldDesc = nfield; //Change for description

            if (pos == 0)
            {
                field.fieldType = "CHAR";
            }
            else
                field.fieldType = "DEC";
            fields.append(field);
        }

        QDomElement shapevars;
        shapevars = doc.createElement("Values");
        root.appendChild(shapevars);


        for (pos = 0; pos <= fields.count()-1;pos++)
        {
            varName = doc.createElement("Field");
            shapevars.appendChild(varName);
            varValue = doc.createTextNode(fields[pos].fieldDesc);
            varName.appendChild(varValue);
        }

        int nrows;

        nrows = 0;
        while (qry.next())
        {
            nrows++;
        }
        nrows++;

        QVector<QVector<QString> >  grid;
        grid.resize(nrows);
        int r;
        for(r=0; r<nrows; r++)
        {
            grid[r].resize(ncols);
        }

        for (pos = 0; pos <= fields.count()-1;pos++)
            grid[0][pos] = fields[pos].fieldDesc;
        r = 1;
        qry.first();
        QString value;
        while (qry.isValid())
        {
            for (pos = 0; pos <= fields.count()-1;pos++)
            {
                if (fields[pos].fieldType == "DEC")
                    value = QString::number(qry.value(pos).toDouble(),'f',3);
                else
                    value = qry.value(pos).toString();
                grid[r][pos] = value;
            }
            r++;
            qry.next();
        }


        if (format == "h")
        {
            QVector< int> colSizes;
            colSizes.resize(ncols);
            for (pos = 0; pos <= ncols-1;pos++)
                colSizes[pos] = 0;
            //Get the maximum size of each column
            for (pos = 0; pos <= ncols-1;pos++)
            {
                for(r=0; r<nrows; r++)
                {
                    if (grid[r][pos].length() +2 > colSizes[pos])
                    {
                        colSizes[pos] = grid[r][pos].length() +2;
                    }
                }
            }
            //Print the table
            printf("\n");
            //Print top line
            for (pos=0;pos<= ncols-1;pos++)
            {
                printf("+");
                printf(fixLine("-",colSizes[pos]).toLocal8Bit().data());
            }
            printf("+");
            printf("\n");
            //Print the columns headings

            for (pos=0;pos<= ncols-1;pos++)
            {
                printf("+");
                printf(fixString(" " + grid[0][pos] + " ",colSizes[pos]).toLocal8Bit().data());

            }
            printf("+");
            printf("\n");

            //Print separation
            for (pos=0;pos<= ncols-1;pos++)
            {
                printf("+");
                printf(fixLine("-",colSizes[pos]).toLocal8Bit().data());
            }
            printf("+");
            printf("\n");

            //Print the values
            for (r=1;r<=nrows-1;r++)
            {
                printf("|");
                for (pos=0;pos<= ncols-1;pos++)
                {
                    printf(fixString(" " + grid[r][pos] + " ",colSizes[pos]).toLocal8Bit().data());
                    printf("|");
                }
                printf("\n");
            }

            //Print the end
            //Print separation
            for (pos=0;pos<= ncols-1;pos++)
            {
                printf("+");
                printf(fixLine("-",colSizes[pos]).toLocal8Bit().data());
            }
            printf("+");
            printf("\n");
        }
        else
        {
            QDomElement shapeData;
            shapeData = doc.createElement("CalcData");
            root.appendChild(shapeData);

            QDomElement rowData;
            QDomElement fieldData;
            QDomText fieldValue;

            for (r=1;r<=nrows-1;r++)
            {
                rowData = doc.createElement("Row");
                shapeData.appendChild(rowData);
                for (pos=0;pos<= ncols-1;pos++)
                {
                    fieldData = doc.createElement("Field");
                    fieldData.setAttribute("Name",fields[pos].fieldDesc);
                    rowData.appendChild(fieldData);
                    fieldValue = doc.createTextNode(grid[r][pos]);
                    fieldData.appendChild(fieldValue);
                }

            }

            QTextStream out(stdout);
            out.setCodec("UTF-8");
            doc.save(out,1,QDomNode::EncodingFromTextStream);
        }

        int Hours;
        int Minutes;
        int Seconds;
        int Milliseconds;

        Milliseconds = procTime.elapsed();

        Hours = Milliseconds / (1000*60*60);
        Minutes = (Milliseconds % (1000*60*60)) / (1000*60);
        Seconds = ((Milliseconds % (1000*60*60)) % (1000*60)) / 1000;

        if (format == "h")
            gbtLog("Finished in " + QString::number(Hours) + " Hours," + QString::number(Minutes) + " Minutes and " + QString::number(Seconds) + " Seconds.");

        mydb.close();
        con.closeConnection();

        return 0;
    }

    return 0;

}