bool Converter::convertList(QTextCursor *cursor, const QDomElement &element) { const QString styleName = element.attribute("style-name"); const ListFormatProperty property = m_StyleInformation->listProperty(styleName); QTextListFormat format; QTextList *list = 0; if (cursor->currentList()) { format = cursor->currentList()->format(); } property.apply(&format); if (!firstTime) list = cursor->insertList(format); else list = cursor->createList(format); firstTime = true; QDomElement itemChild = element.firstChildElement(); while (!itemChild.isNull()) { if (itemChild.tagName() == QLatin1String("list-item")) { QDomElement childElement = itemChild.firstChildElement(); while (!childElement.isNull()) { if (childElement.tagName() == QLatin1String("p")) { if (!convertParagraph(cursor, childElement, QTextBlockFormat(), true)) { return false; } list->add(cursor->block()); } else if (childElement.tagName() == QLatin1String("list")) { if (!convertList(cursor, childElement)) { return false; } list->add(cursor->block()); } childElement = childElement.nextSiblingElement(); } } itemChild = itemChild.nextSiblingElement(); } firstTime = false; return true; }
bool Converter::convertList( QTextCursor *cursor, const QDomElement &element ) { const QString styleName = element.attribute( QStringLiteral("style-name") ); const ListFormatProperty property = mStyleInformation->listProperty( styleName ); QTextListFormat format; if ( cursor->currentList() ) { // we are in a nested list format = cursor->currentList()->format(); format.setIndent( format.indent() + 1 ); } property.apply( &format, 0 ); QTextList *list = cursor->insertList( format ); QDomElement itemChild = element.firstChildElement(); int loop = 0; while ( !itemChild.isNull() ) { if ( itemChild.tagName() == QLatin1String( "list-item" ) ) { loop++; QDomElement childElement = itemChild.firstChildElement(); while ( !childElement.isNull() ) { QTextBlock prevBlock; if ( childElement.tagName() == QLatin1String( "p" ) ) { if ( loop > 1 ) cursor->insertBlock(); prevBlock = cursor->block(); if ( !convertParagraph( cursor, childElement, QTextBlockFormat(), true ) ) return false; } else if ( childElement.tagName() == QLatin1String( "list" ) ) { prevBlock = cursor->block(); if ( !convertList( cursor, childElement ) ) return false; } if( prevBlock.isValid() ) list->add( prevBlock ); childElement = childElement.nextSiblingElement(); } } itemChild = itemChild.nextSiblingElement(); } return true; }