Beispiel #1
0
void StrainPipeData::populate()
{
    if (!valid()) return;

    header(firstBlock());

    QTextCursor cursor(this);
    cursor.movePosition(QTextCursor::End);

    if (questMetrics->valid() && cgalMetrics->valid() && recipie->valid())
    {
        ScatterData cgalScatter(*cgalMetrics, *questMetrics);
        CPPlotLvN cgalScatterPlot(cgalScatter
                                  , directory.absolutePath()
                                  , *recipie);
        //cgalScatterPlot.populateDocument();
        QTextDocumentFragment qvCFrag = cgalScatterPlot.contents();
        cursor.insertFragment(qvCFrag);
        cursor.movePosition(QTextCursor::End);
    }



    if (questMetrics->valid() && aleMetrics->valid() && recipie->valid())
    {

        QTextBlockFormat format = cursor.blockFormat();
        format.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
        cursor.setBlockFormat(format);

        ScatterData cgalScatter(*aleMetrics, *questMetrics);
        CPPlotLvN cgalScatterPlot(cgalScatter
                                  , directory.absolutePath()
                                  , *recipie);
        QTextDocumentFragment qvAFrame = cgalScatterPlot.contents();
        cursor.insertFragment(qvAFrame);
        cursor.movePosition(QTextCursor::End);
    }

    if (runTimes->valid())
    {
        //runTimes->populateDocument();
        QTextDocumentFragment timesFrame = runTimes->contents();
        cursor.insertFragment(timesFrame);

        QTextBlockFormat format = cursor.blockFormat();
        format.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
        cursor.setBlockFormat(format);
    }



    cursor.movePosition(QTextCursor::End);
}
qreal KDReports::TextDocReportLayout::layoutAsOnePage(qreal docWidth)
{
    m_textDocument.layoutWithTextWidth(docWidth);
    qreal docHeight = m_textDocument.contentDocument().size().height();

#if QT_VERSION <= 0x040300
    // Qt-4.2 bug, fixed in Qt-4.3:  QTextDocumentLayout::dynamicPageCount()
    // returns docheight/pageheight + 1. So if the doc is just as high as the page, I get 2 pages.
    docHeight += 1;
#endif

    // We need to get rid of all page breaks...
    // Unittest: PageLayout::testEndlessPrinterWithPageBreaks()
    QTextCursor c(&m_textDocument.contentDocument());
    c.beginEditBlock();
    QTextBlock block = m_textDocument.contentDocument().firstBlock();
    do {
        //qDebug() << "addBlock: Looking at block" << block.blockNumber();
        QTextBlockFormat format = block.blockFormat();
        if ( format.pageBreakPolicy() != QTextBlockFormat::PageBreak_Auto )
            format.setPageBreakPolicy( QTextBlockFormat::PageBreak_Auto );
        c.setPosition( block.position() );
        c.setBlockFormat( format );
        block = block.next();
    } while ( block.isValid() );
    c.endEditBlock();

    setPageContentSize(QSizeF(docWidth, docHeight));
    qDebug() << "m_textDocument.layoutDocument().setPageSize" << docWidth << "x" << docHeight << numberOfPages() << "pages";
    qreal newDocHeight = m_textDocument.contentDocument().size().height();
    if (newDocHeight > docHeight) {
        // QTextDocument is playing tricks on us; it was able to layout as docWidth x docHeight
        // but once we set that as the page size, we end up with more height...
        // Unittest: PageLayout::testEndlessPrinterBug()
        qDebug() << "newDocHeight=" << newDocHeight << "expected" << docHeight;
        setPageContentSize(QSizeF(docWidth, newDocHeight));
        newDocHeight = m_textDocument.contentDocument().size().height();
        qDebug() << "final newDocHeight=" << newDocHeight << numberOfPages() << "pages";
    }

    Q_ASSERT(numberOfPages() == 1);
    return newDocHeight;
}
void CollectionPipeData::populate()
{    
    if (!valid()) return;
    header(firstBlock());

    QTextCursor cursor(this);
    cursor.movePosition(QTextCursor::End);
    for (int i = 0; i < strainsData.size(); ++i)
    {
        if (NULL != strainsData.at(i) && strainsData.at(i)->valid())
        {            
            QTextDocumentFragment frag = strainsData.at(i)->contents();
            cursor.insertFragment(frag);

            QTextBlockFormat format = cursor.blockFormat();
            format.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
            cursor.setBlockFormat(format);

            cursor.movePosition(QTextCursor::End);
        }
    }
}
Beispiel #4
0
bool PriceListPrinter::printODT( PriceListPrinter::PrintPriceItemsOption printOption,
                                 const QList<int> &fieldsToPrint,
                                 int priceDataSetToPrintInput,
                                 bool printPriceList,
                                 bool printPriceAP,
                                 bool APgroupPrAm,
                                 const QString &fileName,
                                 double pageWidth,
                                 double pageHeight,
                                 Qt::Orientation paperOrientation) {
    double borderWidth = 1.0f;
    if( m_d->priceList ){
        int priceDataSetToPrint = 0;
        // controlliamo se il valore di input è corretto
        if( priceDataSetToPrintInput >= 0 && priceDataSetToPrintInput < m_d->priceList->priceDataSetCount() ){
            priceDataSetToPrint = priceDataSetToPrintInput;
        }

        QTextDocument doc;
        QTextCursor cursor(&doc);

        if( paperOrientation == Qt::Horizontal ){
            if( pageHeight > pageWidth ){
                double com = pageHeight;
                pageHeight = pageWidth;
                pageWidth = com;
            }
        } else {
            if( pageHeight < pageWidth ){
                double com = pageHeight;
                pageHeight = pageWidth;
                pageWidth = com;
            }
        }
        double margin = 10.0;
        double tableWidth =  pageWidth - 2.0 * margin;

        QTextCharFormat headerBlockCharFormat;
        headerBlockCharFormat.setFontCapitalization( QFont::AllUppercase );
        headerBlockCharFormat.setFontWeight( QFont::Bold );

        QTextBlockFormat headerBlockFormat;
        headerBlockFormat.setAlignment( Qt::AlignHCenter );

        QTextBlockFormat headerWithPBBlockFormat = headerBlockFormat;
        headerWithPBBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore );

        QTextBlockFormat parBlockFormat;

        if( printPriceList ){
            cursor.setBlockFormat( headerWithPBBlockFormat );
            cursor.setBlockCharFormat( headerBlockCharFormat );
            cursor.insertText( m_d->priceList->name() );

            cursor.insertBlock( headerBlockFormat );
            cursor.setBlockCharFormat( headerBlockCharFormat );
            cursor.insertText(QObject::trUtf8("Elenco Prezzi") );

            cursor.insertBlock( parBlockFormat );

            QTextTableFormat tableFormat;
            tableFormat.setCellPadding(5);
            tableFormat.setHeaderRowCount(2);
            tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
            tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) );
            QVector<QTextLength> colWidths;
            if( paperOrientation == Qt::Horizontal ){
                double descColWidth = tableWidth - ( 30.0 + 20.0 + 35.0 * fieldsToPrint.size() );
                colWidths << QTextLength( QTextLength::FixedLength, 30.0 )
                          << QTextLength( QTextLength::FixedLength, descColWidth )
                          << QTextLength( QTextLength::FixedLength, 20.0 );
                for( int i=0; i < fieldsToPrint.size(); ++i ){
                    colWidths << QTextLength( QTextLength::FixedLength, 35.0 );
                }
            } else {
                double descColWidth = tableWidth - ( 25.0 + 15.0 + 30.0 * fieldsToPrint.size() );
                colWidths << QTextLength( QTextLength::FixedLength, 25.0 )
                          << QTextLength( QTextLength::FixedLength, descColWidth )
                          << QTextLength( QTextLength::FixedLength, 15.0 );
                for( int i=0; i < fieldsToPrint.size(); ++i ){
                    colWidths << QTextLength( QTextLength::FixedLength, 30.0 );
                }
            }
            tableFormat.setColumnWidthConstraints( colWidths );
            tableFormat.setHeaderRowCount( 2 );
            cursor.insertTable(1, colWidths.size(), tableFormat);

            m_d->priceList->writeODTOnTable( &cursor, printOption, fieldsToPrint, priceDataSetToPrint );

            cursor.movePosition( QTextCursor::End );
        }

        if( printPriceAP ){
            bool firstAP=true;

            QList<PriceItem *> priceItemList = m_d->priceList->priceItemList();
            for( int i=0; i < priceItemList.size(); ++i ){
                if( (!priceItemList.at(i)->hasChildren()) && (priceItemList.at(i)->associateAP(priceDataSetToPrint)) ){
                    if( firstAP ){
                        if( printPriceList ){
                            // abbiamo stampato già l'elenco prezzi
                            cursor.insertBlock( headerWithPBBlockFormat );
                        } else { //  printData == DataAP
                            // non abbiamo stampato l'elenco prezzi
                            cursor.setBlockFormat( headerWithPBBlockFormat );
                        }
                        cursor.setBlockCharFormat( headerBlockCharFormat );
                        cursor.insertText( m_d->priceList->name() );

                        cursor.insertBlock( headerBlockFormat );
                        cursor.setBlockCharFormat( headerBlockCharFormat );
                        cursor.insertText(QObject::trUtf8("Analisi Prezzi") );

                        cursor.insertBlock( parBlockFormat );

                        firstAP = false;
                    } else {
                        cursor.insertBlock( headerWithPBBlockFormat );
                        cursor.insertText( QString() );
                        cursor.insertBlock( parBlockFormat );
                    }

                    QTextTableCellFormat topLeftFormat;
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftWidth, QVariant(borderWidth) );
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopWidth, QVariant(borderWidth) );
                    QTextTableCellFormat topRightFormat;
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightWidth, QVariant(borderWidth) );
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopWidth, QVariant(borderWidth) );
                    QTextTableCellFormat bottomFormat;
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftWidth, QVariant(borderWidth) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightWidth, QVariant(borderWidth) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderBottomStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) );
                    bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderBottomWidth, QVariant(borderWidth) );

                    // tabella con informazioni generali sul prezzo
                    // descrizione, codice, etc
                    QTextTableFormat tableFormat;
                    tableFormat.setCellPadding(5);
                    tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
                    tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) );
                    QVector<QTextLength> colWidths;
                    colWidths << QTextLength( QTextLength::FixedLength, 25 )
                              << QTextLength( QTextLength::FixedLength, pageWidth-2.0*margin - 25 );
                    tableFormat.setColumnWidthConstraints( colWidths );
                    QTextTable * table = cursor.insertTable(1, colWidths.size(), tableFormat);

                    table->cellAt( cursor ).setFormat( topLeftFormat );
                    cursor.insertText( priceItemList.at(i)->codeFull() );

                    cursor.movePosition(QTextCursor::NextCell);
                    table->cellAt( cursor ).setFormat( topRightFormat );
                    cursor.insertText( priceItemList.at(i)->shortDescriptionFull() );

                    table->appendRows(1);
                    table->mergeCells( 1, 0, 1, 2 );
                    cursor.movePosition(QTextCursor::PreviousRow );
                    cursor.movePosition(QTextCursor::NextCell );
                    table->cellAt( cursor ).setFormat( bottomFormat );
                    cursor.insertText( priceItemList.at(i)->longDescriptionFull() );
                    cursor.movePosition( QTextCursor::End );

                    // tabella con l'analisi prezzi vera e propria
                    tableFormat.setCellPadding(5);
                    tableFormat.setHeaderRowCount(2);
                    tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
                    tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) );
                    colWidths.clear();
                    if( paperOrientation == Qt::Horizontal ){
                        if( fieldsToPrint.size() > 0 ){
                            colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                      << QTextLength( QTextLength::FixedLength, 30.0 )
                                      << QTextLength( QTextLength::FixedLength, 70.0 )
                                      << QTextLength( QTextLength::FixedLength, 20.0 );
                            double usedWidth =  10.0 + 30.0 + 70.0 + 20.0;
                            double colEqualWidth = (tableWidth - usedWidth ) / (1 + 2*fieldsToPrint.size() );
                            for( int i=0; i < (1 + 2*fieldsToPrint.size() ); ++i ){
                                colWidths << QTextLength( QTextLength::FixedLength, colEqualWidth );
                            }
                        } else { // fieldsToPrint.size() == 0
                            if( fieldsToPrint.size() > 1  ){
                                double descWidth = tableWidth - (10.0 + 30.0 + 20.0 + 30.0);
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 )
                                          << QTextLength( QTextLength::FixedLength, descWidth )
                                          << QTextLength( QTextLength::FixedLength, 20.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 );
                            }
                        }
                    } else {
                        if( fieldsToPrint.size() > 0 ){
                            double usedWidth = 0.0;
                            if( fieldsToPrint.size() > 1  ){
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 20.0 )
                                          << QTextLength( QTextLength::FixedLength, 45.0 )
                                          << QTextLength( QTextLength::FixedLength, 15.0 );
                                usedWidth =  10.0 + 20.0 + 45.0 + 15.0;
                            } else { // fieldsToPrint.size() == 1
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 25.0 )
                                          << QTextLength( QTextLength::FixedLength, 65.0 )
                                          << QTextLength( QTextLength::FixedLength, 15.0 );
                                usedWidth =  10.0 + 25.0 + 65.0 + 15.0;
                            }
                            double colEqualWidth = (tableWidth - usedWidth ) / (1 + 2*fieldsToPrint.size() );
                            for( int i=0; i < (1 + 2*fieldsToPrint.size() ); ++i ){
                                colWidths << QTextLength( QTextLength::FixedLength, colEqualWidth );
                            }
                        } else { // fieldsToPrint.size() == 0
                            if( fieldsToPrint.size() > 1  ){
                                double descWidth = tableWidth - (10.0 + 30.0 + 20.0 + 30.0);
                                colWidths << QTextLength( QTextLength::FixedLength, 10.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 )
                                          << QTextLength( QTextLength::FixedLength, descWidth )
                                          << QTextLength( QTextLength::FixedLength, 20.0 )
                                          << QTextLength( QTextLength::FixedLength, 30.0 );
                            }
                        }
                    }
                    tableFormat.setColumnWidthConstraints( colWidths );
                    tableFormat.setHeaderRowCount( 2 );
                    cursor.insertTable(1, colWidths.size(), tableFormat);

                    BillPrinter::PrintBillItemsOption billPrItemsOption = BillPrinter::PrintShortDesc;
                    if( printOption == PriceListPrinter::PrintShortDesc ){
                        billPrItemsOption = BillPrinter::PrintShortDesc;
                    } else if( printOption == PriceListPrinter::PrintLongDesc ){
                        billPrItemsOption = BillPrinter::PrintLongDesc;
                    } else if( printOption == PriceListPrinter::PrintShortLongDesc ){
                        billPrItemsOption = BillPrinter::PrintShortLongDesc;
                    } else if( printOption == PriceListPrinter::PrintShortLongDescOpt ){
                        billPrItemsOption = BillPrinter::PrintShortLongDescOpt;
                    }
                    priceItemList.at(i)->associatedAP(priceDataSetToPrint)->writeODTBillOnTable( &cursor, billPrItemsOption, fieldsToPrint, APgroupPrAm );

                    cursor.movePosition( QTextCursor::End );
                }

            }
        }

        QFile *file = new QFile(fileName);
        QString suf = QFileInfo(file->fileName()).suffix().toLower().toLatin1();
        if (suf == "odf" || suf == "opendocumentformat" || suf == "odt") {
            OdtWriter writer(doc, file);
            writer.setPageSizeMM( pageWidth, pageHeight );
            writer.setMarginsMM( margin, margin, margin, margin );
            writer.setPageOrientation( paperOrientation );
            // writer.setCodec(codec);
            return writer.writeAll();
        }
    }
    return false;
}
TableauDeRemplissage::TableauDeRemplissage(int idEvenement, QObject *parent)
    : Etat(tr("Tableau de remplissage"), idEvenement, parent)
{
    QSqlQuery query;
    if (query.prepare("select *"
                      " from tableau_de_remplissage"
                      " where id_evenement=:id_evenement")) {
        query.bindValue(":id_evenement", idEvenement);
        if (query.exec()) {
            // FIXME : ce rapport devrait être une feuille de calcul

            QString symboleAcceptee = "●";
            QString symboleProposee = "◍";
            QString symbolePossible = "○";
            QString symboleManquante = "◌";

            QTextCursor c(this);

            QTextBlockFormat formatDuTitreDeLaLegende;
            formatDuTitreDeLaLegende.setBottomMargin(10);

            QTextCharFormat formatDesCaracteresDuTitreDeLaLegende;
            formatDesCaracteresDuTitreDeLaLegende.setUnderlineStyle(QTextCharFormat::SingleUnderline);

            QTextBlockFormat formatDesBlocsDeLaLegende;

            QTextCharFormat formatDesCaracteresDeLaLegende;

            QTextListFormat formatDeLaListeDeLaLegende;

            QTextBlockFormat formatDuBlocJour;
            formatDuBlocJour.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
            formatDuBlocJour.setAlignment(Qt::AlignCenter);
            formatDuBlocJour.setBottomMargin(20);

            QTextCharFormat formatDesCaracteresDuJour;
            formatDesCaracteresDuJour.setFontCapitalization(QFont::Capitalize);
            formatDesCaracteresDuJour.setFontPointSize(14);
            formatDesCaracteresDuJour.setFontWeight(QFont::Bold);

            QTextBlockFormat formatDuBlocTour;
            formatDuBlocTour.setTopMargin(20);

            QTextCharFormat formatDesCaracteresDuTour;
            formatDesCaracteresDuTour.setFontWeight(QFont::Bold);

            QTextBlockFormat formatDuBlocDesResponsables;

            QTextCharFormat formatDesCaracteresDesResponsables;

            QTextBlockFormat formatDuBlocDuRemplissage;

            QTextCharFormat formatDesCaracteresDuRemplissage;

            if (query.first()) {
                c.movePosition(QTextCursor::End);
                c.insertBlock(formatDuTitreDeLaLegende, formatDesCaracteresDuTitreDeLaLegende);
                c.insertText(tr("Légende"));
                c.insertBlock(formatDesBlocsDeLaLegende, formatDesCaracteresDeLaLegende);
                c.insertList(formatDeLaListeDeLaLegende);
                c.insertText(tr("%1 affectation acceptée ou validée").arg(symboleAcceptee));
                c.insertText("\n");
                c.insertText(tr("%1 affectation proposée, en attente d'acceptation").arg(symboleProposee));
                c.insertText("\n");
                c.insertText(tr("%1 affectation possible, à proposer ou valider").arg(symbolePossible));
                c.insertText("\n");
                c.insertText(tr("%1 affectation manquante, reste à créer").arg(symboleManquante));
                QSqlRecord r = query.record();
                do {
                    QDate jour = r.value("debut_tour").toDate();
                    c.insertBlock(formatDuBlocJour, formatDesCaracteresDuJour);
                    c.insertText(QLocale().toString(jour));
                    do {
                        int
                                min = r.value("min").toInt(),
                                max = r.value("max").toInt(),
                                possibles = r.value("nombre_affectations_possibles").toInt(),
                                proposees = r.value("nombre_affectations_proposees").toInt(),
                                acceptees = r.value("nombre_affectations_validees_ou_acceptees").toInt(),
                                trouvees = acceptees + proposees + possibles,
                                manquantes = trouvees < min ? min - trouvees : 0,
                                enTrop = max < trouvees ? trouvees - max : 0;
                        QString responsables = r.value("liste_responsables").toString();
                        c.insertBlock(formatDuBlocTour, formatDesCaracteresDuTour);
                        c.insertText(tr("De %1 à %2 / %3")
                                     .arg(r.value("debut_tour").toTime().toString("H:mm"))
                                     .arg(r.value("fin_tour").toTime().toString("H:mm"))
                                     .arg(r.value("nom_poste").toString())
                                     );
                        if (!responsables.isEmpty()) {
                            c.insertBlock(formatDuBlocDesResponsables, formatDesCaracteresDesResponsables);
                            c.insertText(tr("Responsable(s) : %1").arg(responsables));
                        }
                        c.insertBlock(formatDuBlocDuRemplissage, formatDesCaracteresDuRemplissage);
                        c.insertText(symboleAcceptee.repeated(acceptees));
                        c.insertText(symboleProposee.repeated(proposees));
                        c.insertText(symbolePossible.repeated(possibles));
                        c.insertText(symboleManquante.repeated(manquantes));
                        if (enTrop) c.insertText(tr(" (%n affectation(s) en trop)", "", enTrop));
                        query.next();
                        r = query.record();
                    } while (query.isValid()
                             && r.value("debut_tour").toDate() == jour);
                } while (query.isValid());
            } else {
                qWarning() << tr("Aucune affectation trouvée");
            }
        } else {
            qCritical() << query.lastError();
        }
    } else {
        qCritical() << query.lastError();
    }
}
void QTextHtmlImporter::import()
{
    cursor.beginEditBlock();
    hasBlock = true;
    forceBlockMerging = false;
    compressNextWhitespace = RemoveWhiteSpace;
    blockTagClosed = false;
    for (currentNodeIdx = 0; currentNodeIdx < count(); ++currentNodeIdx) {
        currentNode = &at(currentNodeIdx);
        wsm = textEditMode ? QTextHtmlParserNode::WhiteSpacePreWrap : currentNode->wsm;

        /*
         * process each node in three stages:
         * 1) check if the hierarchy changed and we therefore passed the
         *    equivalent of a closing tag -> we may need to finish off
         *    some structures like tables
         *
         * 2) check if the current node is a special node like a
         *    <table>, <ul> or <img> tag that requires special processing
         *
         * 3) if the node should result in a QTextBlock create one and
         *    finally insert text that may be attached to the node
         */

        /* emit 'closing' table blocks or adjust current indent level
         * if we
         *  1) are beyond the first node
         *  2) the current node not being a child of the previous node
         *      means there was a tag closing in the input html
         */
        if (currentNodeIdx > 0 && (currentNode->parent != currentNodeIdx - 1)) {
            blockTagClosed = closeTag();
            // visually collapse subsequent block tags, but if the element after the closed block tag
            // is for example an inline element (!isBlock) we have to make sure we start a new paragraph by setting
            // hasBlock to false.
            if (blockTagClosed
                && !currentNode->isBlock()
                && currentNode->id != Html_unknown)
            {
                hasBlock = false;
            } else if (hasBlock) {
                // when collapsing subsequent block tags we need to clear the block format
                QTextBlockFormat blockFormat = currentNode->blockFormat;
                blockFormat.setIndent(indent);

                QTextBlockFormat oldFormat = cursor.blockFormat();
                if (oldFormat.hasProperty(QTextFormat::PageBreakPolicy)) {
                    QTextFormat::PageBreakFlags pageBreak = oldFormat.pageBreakPolicy();
                    if (pageBreak == QTextFormat::PageBreak_AlwaysAfter)
                        /* We remove an empty paragrah that requested a page break after.
                           moving that request to the next paragraph means we also need to make
                            that a pagebreak before to keep the same visual appearance.
                        */
                        pageBreak = QTextFormat::PageBreak_AlwaysBefore;
                    blockFormat.setPageBreakPolicy(pageBreak);
                }

                cursor.setBlockFormat(blockFormat);
            }
        }

        if (currentNode->displayMode == QTextHtmlElement::DisplayNone) {
            if (currentNode->id == Html_title)
                doc->setMetaInformation(QTextDocument::DocumentTitle, currentNode->text);
            // ignore explicitly 'invisible' elements
            continue;
        }

        if (processSpecialNodes() == ContinueWithNextNode)
            continue;

        // make sure there's a block for 'Blah' after <ul><li>foo</ul>Blah
        if (blockTagClosed
            && !hasBlock
            && !currentNode->isBlock()
            && !currentNode->text.isEmpty() && !currentNode->hasOnlyWhitespace()
            && currentNode->displayMode == QTextHtmlElement::DisplayInline) {

            QTextBlockFormat block = currentNode->blockFormat;
            block.setIndent(indent);

            appendBlock(block, currentNode->charFormat);

            hasBlock = true;
        }

        if (currentNode->isBlock()) {
            if (processBlockNode() == ContinueWithNextNode)
                continue;
        }

        if (currentNode->charFormat.isAnchor() && !currentNode->charFormat.anchorName().isEmpty()) {
            namedAnchors.append(currentNode->charFormat.anchorName());
        }

        if (appendNodeText())
            hasBlock = false; // if we actually appended text then we don't
                              // have an empty block anymore
    }

    cursor.endEditBlock();
}