예제 #1
0
 virtual void run() {
     KDReports::Report report;
     report.associateTextValue( "title_element", "Price list example" );
     report.associateImageValue( "image_system", QImage( ":/system.png" ) );
     QFile reportFile( ":/PriceList.xml" );
     if( !reportFile.open( QIODevice::ReadOnly ) ) {
         Q_ASSERT( false );
     }
     KDReports::ErrorDetails details;
     if( !report.loadFromXML( &reportFile, &details ) ) {
         qWarning( "ERROR: %s", qPrintable( details.message() ) );
     }
     report.exportToImage( QSize(800, 600), "xml.png", "PNG" ); // deleted by main() below
     report.exportToFile( "xml.pdf" ); // deleted by main() below
 }
bool TestXmlElementHandlerV1::imageElement( KDReports::ImageElement& imageElement, QDomElement& xmlElement )
{
    Q_UNUSED( imageElement );
    Q_UNUSED( xmlElement ); // unused in release mode
    Q_ASSERT( xmlElement.tagName() == "image" );

    if ( xmlElement.hasAttribute("broken") ) {
        KDReports::ErrorDetails details;
        details.setDriverMessage( QString("PC LOAD LETTER") );
        setErrorDetails( details );
        return false;
    }
    cb << "imageElement";
    return true;
}
예제 #3
0
int main( int argc, char** argv ) {
    QApplication app( argc, argv );

    // Create a report
    KDReports::Report report;

    // open a DB connection to an in-memory database
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(":memory:");
    if( !db.open() ) {
        QMessageBox::critical(0, QObject::tr("Cannot open database"),
                              QObject::tr("Cannot create connection to the requested database. Your Qt is probably lacking the QSQLITE driver. Please check your Qt installation." ), QMessageBox::Cancel );
        return false;
    }

    // fill the DB with some test data
    QSqlQuery query;
    query.exec("create table airlines (id int primary key, "
               "name varchar(20), homecountry varchar(2))");
    query.exec("insert into airlines values(1, 'Lufthansa', 'DE')");
    query.exec("insert into airlines values(2, 'SAS', 'SE')");
    query.exec("insert into airlines values(3, 'United', 'US')");
    query.exec("insert into airlines values(4, 'KLM', 'NL')");
    query.exec("insert into airlines values(5, 'Aeroflot', 'RU')");

    // Create a QSqlTableModel, connect to the previously created database, fill
    // the db with some data.
    QSqlTableModel tableModel( 0, db );
    tableModel.setTable( "airlines" );
    tableModel.select();
    tableModel.removeColumn( 0 );
    tableModel.setHeaderData( 0, Qt::Horizontal, QObject::tr("Name") );
    tableModel.setHeaderData( 1, Qt::Horizontal, QObject::tr("Home country") );
    QFont font = app.font();
    font.setBold( true );
    tableModel.setHeaderData( 0, Qt::Horizontal, font, Qt::FontRole );
    tableModel.setHeaderData( 1, Qt::Horizontal, font, Qt::FontRole );

    // associate the model and load the XML file
    report.associateModel( "airlines", &tableModel );
    QFile reportFile( ":/Database.xml" );
    if( !reportFile.open( QIODevice::ReadOnly ) ) {
        QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Could not open report description file 'Database.xml'. Please start this program from the DatabaseXML directory." ) );
        return -1;
    }

    KDReports::ErrorDetails details;
    if( !report.loadFromXML( &reportFile, &details ) ) {
        QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Could not parse report description file:\n%1" ).arg(details.message()) );
        reportFile.close();
        return -2;
    }

    // To show a print preview:
    KDReports::PreviewDialog preview( &report );
    return preview.exec();

    //return app.exec();
}
예제 #4
0
int main( int argc, char** argv ) {
    QApplication app( argc, argv );

    // Create a report
    KDReports::Report report;

    // Set the content of a text field - this shows how xml files can be used as templates for reports,
    // not only as complete (generated) reports.
    report.associateTextValue( "title_element", "Price list example" );
    report.associateTextValue( "company_address", "Klarälvdalens Datakonsult AB\n"
"Rysktorp\n"
"SE-68392 Hagfors\n"
"Sweden" );
    // Note how id="table1_title" is used twice in the xml, both places get the right value
    report.associateTextValue( "table1_title", "Network Peripherals" );
    report.associateTextValue( "table2_title", "Printer Cartridges" );

    report.associateImageValue( "image_system", QPixmap( ":/system.png" ) );

    // Create two table models which will be used by one table element each.
    TableModel table1;
    table1.setDataHasVerticalHeaders( false );
    table1.loadFromCSV( ":/table1" );
    report.associateModel( QLatin1String( "table1" ), &table1 );
    TableModel table2;
    table2.setDataHasVerticalHeaders( false );
    table2.loadFromCSV( ":/table2" );
    report.associateModel( QLatin1String( "table2" ), &table2 );

    QFile reportFile( ":/PriceList.xml" );
    if( !reportFile.open( QIODevice::ReadOnly ) ) {
        QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Could not open report description file 'PriceList.xml'. Please start this program from the PriceListXML directory." ) );
        return -1;
    }

    KDReports::ErrorDetails details;
    if( !report.loadFromXML( &reportFile, &details ) ) {
        QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Could not parse report description file:\n%1" ).arg(details.message()) );
        reportFile.close();
        return -2;
    }

    // To show a print preview:
    KDReports::PreviewDialog preview( &report );
    return preview.exec();

    //return app.exec();
}
예제 #5
0
int main( int argc, char** argv ) {
    QApplication app( argc, argv );

    // Create a report
    KDReports::Report report;

    QFile reportFile( ":/MailMerge.xml" );
    if( !reportFile.open( QIODevice::ReadOnly ) ) {
        QMessageBox::warning(
            0, QObject::tr( "Warning" ),
            QObject::tr( "Could not open report description file 'MailMerge.xml'. "
                         "Please start this program from the HelloWorldXML directory." ) );
        return -1;
    }

    TableModel members;
    members.setDataHasVerticalHeaders( false );
    members.loadFromCSV( ":/members.csv" );
    report.associateModel( QLatin1String( "members" ), &members);
  
    for (int i = 0; i < members.rowCount(); i++ ) {
        report.setCurrentRow(&members, i);
        KDReports::ErrorDetails details;
        if( !report.loadFromXML( &reportFile, &details ) ) {
            QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Could not parse report description file:\n%1" ).arg(details.message()) );
            reportFile.close();
            return -2;
        }
        
        if ( i < members.rowCount() - 1 )
            report.addPageBreak();

        // show a print preview:
    }
    KDReports::PreviewDialog preview( &report );
    return preview.exec();
}