Git commit eee97d6a5285a7ae02aeb51c1476eaab5cdffc6e by Denis Kuplyakov. Committed on 31/08/2015 at 22:24. Pushed by deniskuplyakov into branch 'words-newsectionmodel-deniskup'. Free KoSection::children() from returning non-const reference Summary: Also removed all tabs Test Plan: Reviewers: Subscribers: M +28 -10 libs/kotext/KoSection.cpp M +14 -1 libs/kotext/KoSection.h M +49 -47 libs/kotext/KoSectionModel.cpp M +2 -2 libs/kotext/KoSectionModel.h M +8 -8 libs/kotext/KoTextEditor.cpp M +120 -120 libs/kotext/commands/DeleteCommand.cpp M +10 -10 libs/kotext/commands/DeleteCommand.h M +10 -10 libs/kotext/commands/NewSectionCommand.cpp M +42 -42 libs/kotext/commands/SplitSectionsCommand.cpp M +2 -2 libs/kotext/commands/SplitSectionsCommand.h M +2 -2 libs/kotext/opendocument/KoTextLoader.cpp M +414 -414 libs/kotext/tests/TestDeleteSectionHandling_data.cpp M +182 -182 libs/kotext/tests/TestInsertSectionHandling_data.cpp M +85 -85 libs/kotext/tests/TestKoTextEditor.cpp M +12 -12 libs/kotext/tests/TestKoTextEditor.h M +29 -29 plugins/textshape/dialogs/SectionFormatDialog.cpp M +8 -8 plugins/textshape/dialogs/SectionsSplitDialog.cpp M +17 -17 plugins/textshape/dialogs/SimpleInsertWidget.ui M +7 -7 words/part/KWOdfLoader.cpp M +1 -1 words/part/dockers/KWDebugWidget.cpp http://commits.kde.org/calligra/eee97d6a5285a7ae02aeb51c1476eaab5cdffc6e diff --git a/libs/kotext/KoSection.cpp b/libs/kotext/KoSection.cpp index 02344cc..a98aec7 100644 --- a/libs/kotext/KoSection.cpp +++ b/libs/kotext/KoSection.cpp @@ -40,11 +40,11 @@ class KoSectionPrivate public: explicit KoSectionPrivate(const QTextCursor &cursor, const QString &_n= ame, KoSection *_parent) : document(cursor.block().document()) - , name(_name) + , name(_name) , sectionStyle(0) - , boundingCursorStart(cursor) - , boundingCursorEnd(cursor) - , parent(_parent) + , boundingCursorStart(cursor) + , boundingCursorEnd(cursor) + , parent(_parent) , inlineRdf(0) { } @@ -86,9 +86,9 @@ KoSection::KoSection(const QTextCursor &cursor, const QSt= ring &name, KoSection * d->boundingCursorEnd.setKeepPositionOnInsert(false); // and end one sh= ould move forward = if (parent) { - d->level =3D parent->level() + 1; + d->level =3D parent->level() + 1; } else { - d->level =3D 0; + d->level =3D 0; } } = @@ -107,8 +107,8 @@ QPair KoSection::bounds() const { Q_D(const KoSection); return QPair( - d->boundingCursorStart.position(), - d->boundingCursorEnd.position() + d->boundingCursorStart.position(), + d->boundingCursorEnd.position() ); } = @@ -175,7 +175,7 @@ void KoSection::saveOdf(KoShapeSavingContext &context) = const if (!d->text_protected.isEmpty()) writer->addAttribute("text:text-prot= ected", d->text_protected); if (!d->protection_key.isEmpty()) writer->addAttribute("text:protectio= n-key", d->protection_key); if (!d->protection_key_digest_algorithm.isEmpty()) { - writer->addAttribute("text:protection-key-digest-algorihtm", d->protectio= n_key_digest_algorithm); + writer->addAttribute("text:protection-key-digest-algorihtm", d->pr= otection_key_digest_algorithm); } if (!d->style_name.isEmpty()) writer->addAttribute("text:style-name", = d->style_name); = @@ -214,12 +214,30 @@ KoSection *KoSection::parent() const return d->parent; } = -QVector &KoSection::children() +QVector KoSection::children() { Q_D(KoSection); return d->children; } = +const QVector &KoSection::children() const +{ + Q_D(const KoSection); + return d->children; +} + +void KoSection::insertChild(int childIdx, KoSection *section) +{ + Q_D(KoSection); + d->children.insert(childIdx, section); +} + +void KoSection::removeChild(int childIdx) +{ + Q_D(KoSection); + d->children.remove(childIdx); +} + KoTextInlineRdf *KoSection::inlineRdf() const { Q_D(const KoSection); diff --git a/libs/kotext/KoSection.h b/libs/kotext/KoSection.h index 0934aaa..131a24b 100644 --- a/libs/kotext/KoSection.h +++ b/libs/kotext/KoSection.h @@ -104,7 +104,10 @@ private: KoSection *parent() const; = /// Returns a vector of pointers to the children of the section. - QVector &children(); + QVector children(); + + /// Returns a vector of pointers to the children of the section. Const= version. + const QVector &children() const; = /** * Specifies if end bound of section should stay on place when inserti= ng text. @@ -113,6 +116,16 @@ private: */ void setKeepEndBound(bool state); = + /** + * Inserts @param section to position @param childIdx of children + */ + void insertChild(int childIdx, KoSection *section); + + /** + * Removes child on position @param childIdx + */ + void removeChild(int childIdx); + friend class KoSectionModel; friend class KoTextLoader; // accesses setKeepEndBound() function friend class KoSectionEnd; diff --git a/libs/kotext/KoSectionModel.cpp b/libs/kotext/KoSectionModel.cpp index 70bd2b1..22445ef 100644 --- a/libs/kotext/KoSectionModel.cpp +++ b/libs/kotext/KoSectionModel.cpp @@ -14,26 +14,26 @@ KoSectionModel::KoSectionModel(QTextDocument *doc) KoSectionModel::~KoSectionModel() { foreach(KoSection *sec, m_registeredSections) { - delete sec; // This will delete associated KoSectionEnd in KoSection dest= ructor + delete sec; // This will delete associated KoSectionEnd in KoSecti= on destructor } } = KoSection *KoSectionModel::createSection(const QTextCursor &cursor, KoSect= ion *parent, const QString &name) { if (!isValidNewName(name)) { - return 0; + return 0; } = KoSection *result =3D new KoSection(cursor, name, parent); = // Lets find our number in parent's children by cursor position - QVector &children =3D (parent ? parent->children() : m_ro= otSections); + QVector children =3D (parent ? parent->children() : m_roo= tSections); int childrenId =3D children.size(); for (int i =3D 0; i < children.size(); i++) { - if (cursor.position() < children[i]->bounds().first) { - childrenId =3D i; - break; - } + if (cursor.position() < children[i]->bounds().first) { + childrenId =3D i; + break; + } } // We need to place link from parent to children in childId place // Also need to find corresponding index and declare operations in ter= ms of model @@ -59,15 +59,15 @@ KoSection *KoSectionModel::sectionAtPosition(int pos) int level =3D -1; // Seeking the section with maximum level QHash::iterator it =3D m_sectionNames.begin(); for (; it !=3D m_sectionNames.end(); it++) { - QPair bounds =3D it.value()->bounds(); - if (bounds.first > pos || bounds.second < pos) { - continue; - } + QPair bounds =3D it.value()->bounds(); + if (bounds.first > pos || bounds.second < pos) { + continue; + } = - if (it.value()->level() > level) { - result =3D it.value(); - level =3D it.value()->level(); - } + if (it.value()->level() > level) { + result =3D it.value(); + level =3D it.value()->level(); + } } = return result; @@ -83,8 +83,8 @@ QString KoSectionModel::possibleNewName() QString newName; int i =3D m_registeredSections.count(); do { - i++; - newName =3D i18nc("new numbered section name", "New section %1", i); + i++; + newName =3D i18nc("new numbered section name", "New section %1", i= ); } while (!isValidNewName(newName)); = return newName; @@ -93,10 +93,10 @@ QString KoSectionModel::possibleNewName() bool KoSectionModel::setName(KoSection *section, const QString &name) { if (section->name() =3D=3D name || isValidNewName(name)) { - section->setName(name); - //TODO: we don't have name in columns, but need something to notify views= about change - emit dataChanged(m_modelIndex[section], m_modelIndex[section]); - return true; + section->setName(name); + //TODO: we don't have name in columns, but need something to notif= y views about change + emit dataChanged(m_modelIndex[section], m_modelIndex[section]); + return true; } return false; } @@ -105,7 +105,7 @@ void KoSectionModel::allowMovingEndBound() { QSet::iterator it =3D m_registeredSections.begin(); for (; it !=3D m_registeredSections.end(); it++) { - (*it)->setKeepEndBound(false); + (*it)->setKeepEndBound(false); } } = @@ -113,9 +113,9 @@ int KoSectionModel::findRowOfChild(KoSection *section) = const { QVector lookOn; if (!section->parent()) { - lookOn =3D m_rootSections; + lookOn =3D m_rootSections; } else { - lookOn =3D section->parent()->children(); + lookOn =3D section->parent()->children(); } = int result =3D lookOn.indexOf(section); @@ -126,11 +126,11 @@ int KoSectionModel::findRowOfChild(KoSection *section= ) const QModelIndex KoSectionModel::index(int row, int column, const QModelIndex &= parentIdx) const { if (!hasIndex(row, column, parentIdx)) { - return QModelIndex(); + return QModelIndex(); } = if (!parentIdx.isValid()) { - return createIndex(row, column, m_rootSections[row]); + return createIndex(row, column, m_rootSections[row]); } = KoSection *parent =3D static_cast(parentIdx.internalPoint= er()); @@ -140,13 +140,13 @@ QModelIndex KoSectionModel::index(int row, int column= , const QModelIndex &parent QModelIndex KoSectionModel::parent(const QModelIndex &child) const { if (!child.isValid()) { - return QModelIndex(); + return QModelIndex(); } = KoSection *section =3D static_cast(child.internalPointer(= )); KoSection *parent =3D section->parent(); if (parent) { - return createIndex(findRowOfChild(parent), 0, parent); + return createIndex(findRowOfChild(parent), 0, parent); } return QModelIndex(); } @@ -154,7 +154,7 @@ QModelIndex KoSectionModel::parent(const QModelIndex &c= hild) const int KoSectionModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) { - return m_rootSections.size(); + return m_rootSections.size(); } return static_cast(parent.internalPointer())->children().= size(); } @@ -167,13 +167,13 @@ int KoSectionModel::columnCount(const QModelIndex &/*= parent*/) const QVariant KoSectionModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { - return QVariant(); + return QVariant(); } = if (index.column() =3D=3D 0 && role =3D=3D PointerRole) { - QVariant v; - v.setValue(static_cast(index.internalPointer())); - return v; + QVariant v; + v.setValue(static_cast(index.internalPointer())); + return v; } return QVariant(); } @@ -184,15 +184,16 @@ void KoSectionModel::insertToModel(KoSection *section= , int childIdx) = KoSection *parent =3D section->parent(); if (parent) { // Inserting to some section - beginInsertRows(m_modelIndex[parent], childIdx, childIdx); - parent->children().insert(childIdx, section); - endInsertRows(); - m_modelIndex[section] =3D QPersistentModelIndex(index(childIdx, 0, m_mode= lIndex[parent])); + beginInsertRows(m_modelIndex[parent], childIdx, childIdx); + parent->insertChild(childIdx, section); +// parent->children().insert(childIdx, section); + endInsertRows(); + m_modelIndex[section] =3D QPersistentModelIndex(index(childIdx, 0,= m_modelIndex[parent])); } else { // It will be root section - beginInsertRows(QModelIndex(), childIdx, childIdx); - m_rootSections.insert(childIdx, section); - endInsertRows(); - m_modelIndex[section] =3D QPersistentModelIndex(index(childIdx, 0, QModel= Index())); + beginInsertRows(QModelIndex(), childIdx, childIdx); + m_rootSections.insert(childIdx, section); + endInsertRows(); + m_modelIndex[section] =3D QPersistentModelIndex(index(childIdx, 0,= QModelIndex())); } = m_registeredSections.insert(section); @@ -204,13 +205,14 @@ void KoSectionModel::deleteFromModel(KoSection *secti= on) KoSection *parent =3D section->parent(); int childIdx =3D findRowOfChild(section); if (parent) { // Deleting non root section - beginRemoveRows(m_modelIndex[parent], childIdx, childIdx); - parent->children().remove(childIdx); - endRemoveRows(); + beginRemoveRows(m_modelIndex[parent], childIdx, childIdx); + parent->removeChild(childIdx); +// parent->children().remove(childIdx); + endRemoveRows(); } else { // Deleting root section - beginRemoveRows(QModelIndex(), childIdx, childIdx); - m_rootSections.remove(childIdx); - endRemoveRows(); + beginRemoveRows(QModelIndex(), childIdx, childIdx); + m_rootSections.remove(childIdx); + endRemoveRows(); } m_modelIndex.remove(section); m_sectionNames.remove(section->name()); diff --git a/libs/kotext/KoSectionModel.h b/libs/kotext/KoSectionModel.h index 38a69bc..9c5a86d 100644 --- a/libs/kotext/KoSectionModel.h +++ b/libs/kotext/KoSectionModel.h @@ -36,8 +36,8 @@ * isn't moving if text inserted in its position, and end cursor * moves. But in the case of initial document loading, it is necessary * to make some end cursors stop moving, so we have: - * KoTextLoader -> calling -> KoSection::setKeepEndBound() - * KoTextLoader -> calling -> KoSectionModel::allowMovingEndBound() + * KoTextLoader -> calling -> KoSection::setKeepEndBound() + * KoTextLoader -> calling -> KoSectionModel::allowMovingEndBound() * ^-- this needed to restore defaul behaviour after load * * 2) Level. Level means the depth of the section in tree. Root diff --git a/libs/kotext/KoTextEditor.cpp b/libs/kotext/KoTextEditor.cpp index f2bd756..b0d9160 100644 --- a/libs/kotext/KoTextEditor.cpp +++ b/libs/kotext/KoTextEditor.cpp @@ -1519,24 +1519,24 @@ void KoTextEditor::newSection() void KoTextEditor::splitSectionsStartings(int sectionIdToInsertBefore) { if (isEditProtected()) { - return; + return; } addCommand(new SplitSectionsCommand( - d->document, - SplitSectionsCommand::Startings, - sectionIdToInsertBefore)); + d->document, + SplitSectionsCommand::Startings, + sectionIdToInsertBefore)); emit cursorPositionChanged(); } = void KoTextEditor::splitSectionsEndings(int sectionIdToInsertAfter) { if (isEditProtected()) { - return; + return; } addCommand(new SplitSectionsCommand( - d->document, - SplitSectionsCommand::Endings, - sectionIdToInsertAfter)); + d->document, + SplitSectionsCommand::Endings, + sectionIdToInsertAfter)); emit cursorPositionChanged(); } = diff --git a/libs/kotext/commands/DeleteCommand.cpp b/libs/kotext/commands/= DeleteCommand.cpp index 8e8caef..c3e9b70 100644 --- a/libs/kotext/commands/DeleteCommand.cpp +++ b/libs/kotext/commands/DeleteCommand.cpp @@ -50,7 +50,7 @@ bool DeleteCommand::SectionDeleteInfo::operator<(const De= leteCommand::SectionDel // section on position 2 while the number of children is less than 2. = if (section->level() !=3D other.section->level()) { - return section->level() > other.section->level(); + return section->level() > other.section->level(); } return childIdx > other.childIdx; } @@ -96,9 +96,9 @@ void DeleteCommand::redo() { if (!m_first) { KoTextCommandBase::redo(); - UndoRedoFinalizer finalizer(this); // Look at KoTextCommandBase documenta= tion + UndoRedoFinalizer finalizer(this); // Look at KoTextCommandBase do= cumentation = - // KoTextRange + // KoTextRange KoTextRangeManager *rangeManager =3D KoTextDocument(m_document).te= xtRangeManager(); foreach (KoTextRange *range, m_rangesToRemove) { rangeManager->remove(range); @@ -107,7 +107,7 @@ void DeleteCommand::redo() // KoSectionModel deleteSectionsFromModel(); = - // TODO: there is nothing for InlineObjects and Lists. Is it OK? + // TODO: there is nothing for InlineObjects and Lists. Is it OK? } else { m_first =3D false; if (m_document) { @@ -154,9 +154,9 @@ public: QTextCursor fragmentSelection(caret); fragmentSelection.setPosition(qMax(caret.selectionStart(), it.= fragment().position())); fragmentSelection.setPosition( - qMin(caret.selectionEnd(), it.fragment().position() + it.fragment().leng= th()), - QTextCursor::KeepAnchor - ); + qMin(caret.selectionEnd(), it.fragment().position() + it.f= ragment().length()), + QTextCursor::KeepAnchor + ); = if (fragmentSelection.anchor() >=3D fragmentSelection.position= ()) { continue; @@ -181,17 +181,17 @@ public: QList closeList =3D KoSectionUtils::sectionEnd= ings(block.blockFormat()); foreach (KoSectionEnd *se, closeList) { if (!m_curSectionDelimiters.empty() && m_curSectionDelimit= ers.last().name =3D=3D se->name()) { - KoSection *section =3D se->correspondingSection(); - int childIdx =3D KoTextDocument(m_command->m_document).sectionModel() - ->findRowOfChild(section); - - m_command->m_sectionsToRemove.push_back( - DeleteCommand::SectionDeleteInfo( - section, - childIdx - ) - ); - m_curSectionDelimiters.pop_back(); // This section will die + KoSection *section =3D se->correspondingSection(); + int childIdx =3D KoTextDocument(m_command->m_document)= .sectionModel() + ->findRowOfChild(section); + + m_command->m_sectionsToRemove.push_back( + DeleteCommand::SectionDeleteInfo( + section, + childIdx + ) + ); + m_curSectionDelimiters.pop_back(); // This section wil= l die } else { m_curSectionDelimiters.push_back(SectionHandle(se->nam= e(), se)); } @@ -215,7 +215,7 @@ public: } = if (m_command->m_mergePossible && fragmentSelection.charFormat() != =3D m_firstFormat) { - m_command->m_mergePossible =3D false; + m_command->m_mergePossible =3D false; } = // Handling InlineObjects below @@ -281,97 +281,97 @@ void DeleteCommand::finalizeSectionHandling(QTextCurs= or *cur, DeleteVisitor &v) // Lets handle pointers from block formats first // It means that selection isn't within one block. if (v.m_hasEntirelyInsideBlock || v.m_startBlockNum !=3D -1 || v.m_end= BlockNum !=3D -1) { - QList openList; - QList closeList; - foreach (const DeleteVisitor::SectionHandle &handle, v.m_curSectionDelimi= ters) { - if (handle.type =3D=3D v.SectionOpen) { // Start of the section. - openList << handle.dataSec; - } else { // End of the section. - closeList << handle.dataSecEnd; - } - } - - // We're expanding ends in affected blocks to the end of the start block, - // delete all sections, that are entirely in affected blocks, - // and move ends, we have, to the begin of the next after the end block. - if (v.m_startBlockNum !=3D -1) { - QTextBlockFormat fmt =3D cur->document()->findBlockByNumber(v.m_start= BlockNum).blockFormat(); - QTextBlockFormat fmt2 =3D cur->document()->findBlockByNumber(v.m_endB= lockNum + 1).blockFormat(); - fmt.clearProperty(KoParagraphStyle::SectionEndings); - - // m_endBlockNum !=3D -1 in this case. - QList closeListEndBlock =3D KoSectionUtils::sectionEn= dings( - cur->document()->findBlockByNumber(v.m_endBlockNum).blockFormat()); - - while (!openList.empty() && !closeListEndBlock.empty() - && openList.last()->name() =3D=3D closeListEndBlock.first()->name()) { - - int childIdx =3D KoTextDocument(m_document) - .sectionModel()->findRowOfChild(openList.back()); - m_sectionsToRemove.push_back( - DeleteCommand::SectionDeleteInfo( - openList.back(), - childIdx - ) - ); - - openList.pop_back(); - closeListEndBlock.pop_front(); - } - openList << KoSectionUtils::sectionStartings(fmt2); - closeList << closeListEndBlock; - - // We leave open section of start block untouched. - KoSectionUtils::setSectionStartings(fmt2, openList); - KoSectionUtils::setSectionEndings(fmt, closeList); - - QTextCursor changer =3D *cur; - changer.setPosition(cur->document()->findBlockByNumber(v.m_startBlock= Num).position()); - changer.setBlockFormat(fmt); - if (v.m_endBlockNum + 1 < cur->document()->blockCount()) { - changer.setPosition(cur->document()->findBlockByNumber(v.m_endBlockNum += 1).position()); - changer.setBlockFormat(fmt2); - } - } else { // v.m_startBlockNum =3D=3D -1 - // v.m_endBlockNum !=3D -1 in this case. - // We're pushing all new section info to the end block. - QTextBlockFormat fmt =3D cur->document()->findBlockByNumber(v.m_endBl= ockNum).blockFormat(); - QList allStartings =3D KoSectionUtils::sectionStartings(= fmt); - fmt.clearProperty(KoParagraphStyle::SectionStartings); - - QList pairedEndings; - QList unpairedEndings; - - foreach (KoSectionEnd *se, KoSectionUtils::sectionEndings(fmt)) { - KoSection *sec =3D se->correspondingSection(); - - if (allStartings.contains(sec)) { - pairedEndings << se; - } else { - unpairedEndings << se; - } - } - - if (cur->selectionStart()) { - QTextCursor changer =3D *cur; - changer.setPosition(cur->selectionStart() - 1); - - QTextBlockFormat prevFmt =3D changer.blockFormat(); - QList prevEndings =3D KoSectionUtils::sectionEndings(pre= vFmt); - - prevEndings =3D prevEndings + closeList; - - KoSectionUtils::setSectionEndings(prevFmt, prevEndings); - changer.setBlockFormat(prevFmt); - } - - KoSectionUtils::setSectionStartings(fmt, openList); - KoSectionUtils::setSectionEndings(fmt, pairedEndings + unpairedEnding= s); - - QTextCursor changer =3D *cur; - changer.setPosition(cur->document()->findBlockByNumber(v.m_endBlockNu= m).position()); - changer.setBlockFormat(fmt); - } + QList openList; + QList closeList; + foreach (const DeleteVisitor::SectionHandle &handle, v.m_curSectio= nDelimiters) { + if (handle.type =3D=3D v.SectionOpen) { // Start of the sectio= n. + openList << handle.dataSec; + } else { // End of the section. + closeList << handle.dataSecEnd; + } + } + + // We're expanding ends in affected blocks to the end of the start= block, + // delete all sections, that are entirely in affected blocks, + // and move ends, we have, to the begin of the next after the end = block. + if (v.m_startBlockNum !=3D -1) { + QTextBlockFormat fmt =3D cur->document()->findBlockByNumber(v.= m_startBlockNum).blockFormat(); + QTextBlockFormat fmt2 =3D cur->document()->findBlockByNumber(v= .m_endBlockNum + 1).blockFormat(); + fmt.clearProperty(KoParagraphStyle::SectionEndings); + + // m_endBlockNum !=3D -1 in this case. + QList closeListEndBlock =3D KoSectionUtils::se= ctionEndings( + cur->document()->findBlockByNumber(v.m_endBlockNum).blockF= ormat()); + + while (!openList.empty() && !closeListEndBlock.empty() + && openList.last()->name() =3D=3D closeListEndBlock.first(= )->name()) { + + int childIdx =3D KoTextDocument(m_document) + .sectionModel()->findRowOfChild(openList.back()); + m_sectionsToRemove.push_back( + DeleteCommand::SectionDeleteInfo( + openList.back(), + childIdx + ) + ); + + openList.pop_back(); + closeListEndBlock.pop_front(); + } + openList << KoSectionUtils::sectionStartings(fmt2); + closeList << closeListEndBlock; + + // We leave open section of start block untouched. + KoSectionUtils::setSectionStartings(fmt2, openList); + KoSectionUtils::setSectionEndings(fmt, closeList); + + QTextCursor changer =3D *cur; + changer.setPosition(cur->document()->findBlockByNumber(v.m_sta= rtBlockNum).position()); + changer.setBlockFormat(fmt); + if (v.m_endBlockNum + 1 < cur->document()->blockCount()) { + changer.setPosition(cur->document()->findBlockByNumber(v.m= _endBlockNum + 1).position()); + changer.setBlockFormat(fmt2); + } + } else { // v.m_startBlockNum =3D=3D -1 + // v.m_endBlockNum !=3D -1 in this case. + // We're pushing all new section info to the end block. + QTextBlockFormat fmt =3D cur->document()->findBlockByNumber(v.= m_endBlockNum).blockFormat(); + QList allStartings =3D KoSectionUtils::sectionSta= rtings(fmt); + fmt.clearProperty(KoParagraphStyle::SectionStartings); + + QList pairedEndings; + QList unpairedEndings; + + foreach (KoSectionEnd *se, KoSectionUtils::sectionEndings(fmt)= ) { + KoSection *sec =3D se->correspondingSection(); + + if (allStartings.contains(sec)) { + pairedEndings << se; + } else { + unpairedEndings << se; + } + } + + if (cur->selectionStart()) { + QTextCursor changer =3D *cur; + changer.setPosition(cur->selectionStart() - 1); + + QTextBlockFormat prevFmt =3D changer.blockFormat(); + QList prevEndings =3D KoSectionUtils::sect= ionEndings(prevFmt); + + prevEndings =3D prevEndings + closeList; + + KoSectionUtils::setSectionEndings(prevFmt, prevEndings); + changer.setBlockFormat(prevFmt); + } + + KoSectionUtils::setSectionStartings(fmt, openList); + KoSectionUtils::setSectionEndings(fmt, pairedEndings + unpaire= dEndings); + + QTextCursor changer =3D *cur; + changer.setPosition(cur->document()->findBlockByNumber(v.m_end= BlockNum).position()); + changer.setBlockFormat(fmt); + } } = // Now lets deal with KoSectionModel @@ -383,7 +383,7 @@ void DeleteCommand::deleteSectionsFromModel() { KoSectionModel *model =3D KoTextDocument(m_document).sectionModel(); foreach (const SectionDeleteInfo &info, m_sectionsToRemove) { - model->deleteFromModel(info.section); + model->deleteFromModel(info.section); } } = @@ -392,8 +392,8 @@ void DeleteCommand::insertSectionsToModel() KoSectionModel *model =3D KoTextDocument(m_document).sectionModel(); QList::iterator it =3D m_sectionsToRemove.end(); while (it !=3D m_sectionsToRemove.begin()) { - it--; - model->insertToModel(it->section, it->childIdx); + it--; + model->insertToModel(it->section, it->childIdx); } } = @@ -428,11 +428,11 @@ void DeleteCommand::doDelete() KoTextRangeManager *rangeManager =3D KoTextDocument(m_document).textRa= ngeManager(); = m_rangesToRemove =3D rangeManager->textRangesChangingWithin( - textEditor->document(), - textEditor->selectionStart(), - textEditor->selectionEnd(), - textEditor->selectionStart(), - textEditor->selectionEnd() + textEditor->document(), + textEditor->selectionStart(), + textEditor->selectionEnd(), + textEditor->selectionStart(), + textEditor->selectionEnd() ); = foreach (KoTextRange *range, m_rangesToRemove) { @@ -442,7 +442,7 @@ void DeleteCommand::doDelete() // we should only delete the anchor if the selection is coveri= ng it... not if the selection is // just adjecent to the anchor. This is more in line with what= other wordprocessors do if (anchorRange->position() !=3D textEditor->selectionStart() - && anchorRange->position() !=3D textEditor->selectionEnd()) { + && anchorRange->position() !=3D textEditor->selectionE= nd()) { KoShape *shape =3D anchorRange->anchor()->shape(); if (m_shapeController) { KUndo2Command *shapeDeleteCommand =3D m_shapeControlle= r->removeShape(shape, this); @@ -471,7 +471,7 @@ void DeleteCommand::doDelete() = //FIXME: lets forbid merging of "section affecting" deletions by now if (!m_sectionsToRemove.empty()) { - m_mergePossible =3D false; + m_mergePossible =3D false; } = if (m_mergePossible) { diff --git a/libs/kotext/commands/DeleteCommand.h b/libs/kotext/commands/De= leteCommand.h index 49cb7ac..90ce10c 100644 --- a/libs/kotext/commands/DeleteCommand.h +++ b/libs/kotext/commands/DeleteCommand.h @@ -59,16 +59,16 @@ private: friend class DeleteVisitor; = struct SectionDeleteInfo { - SectionDeleteInfo(KoSection *_section, int _childIdx) - : section(_section) - , childIdx(_childIdx) - { - } - = - bool operator<(const SectionDeleteInfo &other) const; - - KoSection *section; ///< Section to remove - int childIdx; ///< Position of section in parent's children() list + SectionDeleteInfo(KoSection *_section, int _childIdx) + : section(_section) + , childIdx(_childIdx) + { + } + = + bool operator<(const SectionDeleteInfo &other) const; + + KoSection *section; ///< Section to remove + int childIdx; ///< Position of section in parent's children() list }; = QWeakPointer m_document; diff --git a/libs/kotext/commands/NewSectionCommand.cpp b/libs/kotext/comma= nds/NewSectionCommand.cpp index e8d537f..412d102 100644 --- a/libs/kotext/commands/NewSectionCommand.cpp +++ b/libs/kotext/commands/NewSectionCommand.cpp @@ -58,22 +58,22 @@ void NewSectionCommand::redo() = if (!m_first) { KUndo2Command::redo(); - //FIXME: if it will go to KoTextCommandBase, place UndoRedoFinalizer here + //FIXME: if it will go to KoTextCommandBase, place UndoRedoFinaliz= er here = - // All formatting changes will be redone automatically. - // Lets handle Model Level (see KoSectionModel). - sectionModel->insertToModel(m_section, m_childIdx); + // All formatting changes will be redone automatically. + // Lets handle Model Level (see KoSectionModel). + sectionModel->insertToModel(m_section, m_childIdx); } else { m_first =3D false; = KoTextEditor *editor =3D koDocument.textEditor(); editor->newLine(); = - m_section =3D sectionModel->createSection( - editor->constCursor(), - sectionModel->sectionAtPosition(editor->constCursor().position()) - ); - m_childIdx =3D sectionModel->findRowOfChild(m_section); + m_section =3D sectionModel->createSection( + editor->constCursor(), + sectionModel->sectionAtPosition(editor->constCursor().position= ()) + ); + m_childIdx =3D sectionModel->findRowOfChild(m_section); = KoSectionEnd *sectionEnd =3D sectionModel->createSectionEnd(m_sect= ion); QTextBlockFormat fmt =3D editor->blockFormat(); @@ -82,7 +82,7 @@ void NewSectionCommand::redo() QList sectionEndings =3D KoSectionUtils::sectionEn= dings(fmt); = sectionStartings.append(m_section); - sectionEndings.prepend(sectionEnd); + sectionEndings.prepend(sectionEnd); = KoSectionUtils::setSectionStartings(fmt, sectionStartings); KoSectionUtils::setSectionEndings(fmt, sectionEndings); diff --git a/libs/kotext/commands/SplitSectionsCommand.cpp b/libs/kotext/co= mmands/SplitSectionsCommand.cpp index 7bce074..021a192 100644 --- a/libs/kotext/commands/SplitSectionsCommand.cpp +++ b/libs/kotext/commands/SplitSectionsCommand.cpp @@ -36,9 +36,9 @@ SplitSectionsCommand::SplitSectionsCommand(QTextDocument = *document, SplitType ty , m_splitPosition(splitPosition) { if (m_type =3D=3D Startings) { - setText(kundo2_i18n("Split sections startings")); + setText(kundo2_i18n("Split sections startings")); } else { // Endings - setText(kundo2_i18n("Split sections endings")); + setText(kundo2_i18n("Split sections endings")); } } = @@ -60,46 +60,46 @@ void SplitSectionsCommand::redo() KoTextDocument koDocument(m_document); = if (!m_first) { - KUndo2Command::redo(); - //FIXME: if it will go to KoTextCommandBase, place UndoRedoFinalizer here - = - // All formatting changes will be redone automatically. - // Model level is untouched. + KUndo2Command::redo(); + //FIXME: if it will go to KoTextCommandBase, place UndoRedoFinaliz= er here + = + // All formatting changes will be redone automatically. + // Model level is untouched. } else { - m_first =3D false; - = - KoTextEditor *editor =3D koDocument.textEditor(); - = - if (m_type =3D=3D Startings) { - editor->movePosition(QTextCursor::StartOfBlock); - editor->newLine(); - editor->movePosition(QTextCursor::PreviousBlock); - = - QTextBlockFormat fmt =3D editor->blockFormat(); - KoSectionUtils::setSectionEndings(fmt, QList()); - QList firstBlockStartings =3D KoSectionUtils::sectionSta= rtings(fmt).mid(0, m_splitPosition); - QList moveForward =3D KoSectionUtils::sectionStartings(f= mt).mid(m_splitPosition); - KoSectionUtils::setSectionStartings(fmt, firstBlockStartings); - editor->setBlockFormat(fmt); - editor->movePosition(QTextCursor::NextBlock); - fmt =3D editor->blockFormat(); - KoSectionUtils::setSectionStartings(fmt, moveForward); - editor->setBlockFormat(fmt); - editor->movePosition(QTextCursor::PreviousBlock); - } else { // Endings - editor->movePosition(QTextCursor::EndOfBlock); - editor->newLine(); - = - QTextBlockFormat fmt =3D editor->blockFormat(); - QList secondBlockEndings =3D KoSectionUtils::sectionE= ndings(fmt).mid(m_splitPosition + 1); - QList moveBackward =3D KoSectionUtils::sectionEndings= (fmt).mid(0, m_splitPosition + 1); - KoSectionUtils::setSectionEndings(fmt, secondBlockEndings); - editor->setBlockFormat(fmt); - editor->movePosition(QTextCursor::PreviousBlock); - fmt =3D editor->blockFormat(); - KoSectionUtils::setSectionEndings(fmt, moveBackward); - editor->setBlockFormat(fmt); - editor->movePosition(QTextCursor::NextBlock); - } + m_first =3D false; + = + KoTextEditor *editor =3D koDocument.textEditor(); + = + if (m_type =3D=3D Startings) { + editor->movePosition(QTextCursor::StartOfBlock); + editor->newLine(); + editor->movePosition(QTextCursor::PreviousBlock); + = + QTextBlockFormat fmt =3D editor->blockFormat(); + KoSectionUtils::setSectionEndings(fmt, QList()= ); + QList firstBlockStartings =3D KoSectionUtils::sec= tionStartings(fmt).mid(0, m_splitPosition); + QList moveForward =3D KoSectionUtils::sectionStar= tings(fmt).mid(m_splitPosition); + KoSectionUtils::setSectionStartings(fmt, firstBlockStartings); + editor->setBlockFormat(fmt); + editor->movePosition(QTextCursor::NextBlock); + fmt =3D editor->blockFormat(); + KoSectionUtils::setSectionStartings(fmt, moveForward); + editor->setBlockFormat(fmt); + editor->movePosition(QTextCursor::PreviousBlock); + } else { // Endings + editor->movePosition(QTextCursor::EndOfBlock); + editor->newLine(); + = + QTextBlockFormat fmt =3D editor->blockFormat(); + QList secondBlockEndings =3D KoSectionUtils::s= ectionEndings(fmt).mid(m_splitPosition + 1); + QList moveBackward =3D KoSectionUtils::section= Endings(fmt).mid(0, m_splitPosition + 1); + KoSectionUtils::setSectionEndings(fmt, secondBlockEndings); + editor->setBlockFormat(fmt); + editor->movePosition(QTextCursor::PreviousBlock); + fmt =3D editor->blockFormat(); + KoSectionUtils::setSectionEndings(fmt, moveBackward); + editor->setBlockFormat(fmt); + editor->movePosition(QTextCursor::NextBlock); + } } } diff --git a/libs/kotext/commands/SplitSectionsCommand.h b/libs/kotext/comm= ands/SplitSectionsCommand.h index 243ec49..473b404 100644 --- a/libs/kotext/commands/SplitSectionsCommand.h +++ b/libs/kotext/commands/SplitSectionsCommand.h @@ -33,8 +33,8 @@ class SplitSectionsCommand : public KUndo2Command public: enum SplitType { - Startings, - Endings + Startings, + Endings }; = explicit SplitSectionsCommand(QTextDocument *document, SplitType type,= int splitPosition); diff --git a/libs/kotext/opendocument/KoTextLoader.cpp b/libs/kotext/opendo= cument/KoTextLoader.cpp index c041590..027328a 100644 --- a/libs/kotext/opendocument/KoTextLoader.cpp +++ b/libs/kotext/opendocument/KoTextLoader.cpp @@ -433,8 +433,8 @@ void KoTextLoader::loadBody(const KoXmlElement &bodyEle= m, QTextCursor &cursor, L //} = if (!rootCallChecker) { - // Allow to move end bounds of sections with inserting text - KoTextDocument(cursor.block().document()).sectionModel()->allowMovingEndB= ound(); + // Allow to move end bounds of sections with inserting text + KoTextDocument(cursor.block().document()).sectionModel()->allowMov= ingEndBound(); } } = diff --git a/libs/kotext/tests/TestDeleteSectionHandling_data.cpp b/libs/ko= text/tests/TestDeleteSectionHandling_data.cpp index 5b3cc18..c096b3d 100644 --- a/libs/kotext/tests/TestDeleteSectionHandling_data.cpp +++ b/libs/kotext/tests/TestDeleteSectionHandling_data.cpp @@ -27,440 +27,440 @@ void TestKoTextEditor::testDeleteSectionHandling_data= () QTest::addColumn< QVector< QVector > >("needEndings"); = QTest::newRow("Simple deletion, no effect to sections.") << 1 << 2 << = 11 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting entire 1st section begin.") << 4 << 8 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1" << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1" << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting entire 1st section begin and part of 2nd.") <<= 4 << 9 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1" << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1" << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting part of 1st section begin.") << 5 << 8 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting part of 1st section begin and part of 2nd.") <= < 5 << 9 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting all sections except 0th one.") << 4 << 36 << 3 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting 3rd and part of 4th.") << 20 << 32 << 8 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting all the sections.") << 0 << 40 << 1 - << (QVector< QVector >() - << (QVector())) - << (QVector< QVector >() - << (QVector())); + << (QVector< QVector >() + << (QVector())) + << (QVector< QVector >() + << (QVector())); QTest::newRow("Deleting part of 3rd and part of 4th.") << 25 << 29 << = 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting 2nd end.") << 12 << 16 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting 2nd end and part of 1st.") << 12 << 17 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting part of 2nd end.") << 13 << 16 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2" << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2" << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Deleting part of 2nd end and part of 1st.") << 13 << 17= << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2" << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2" << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #0") << 5 << 36 << 3 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1" << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1" << "0") + << (QVector())); QTest::newRow("Random test #1") << 0 << 23 << 6 - << (QVector< QVector >() - << (QVector() << "0" << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0" << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #2") << 7 << 19 << 8 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #3") << 6 << 32 << 4 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #4") << 17 << 23 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #5") << 6 << 27 << 6 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #6") << 6 << 17 << 8 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #7") << 8 << 22 << 8 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #8") << 14 << 19 << 10 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2" << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2" << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Random test #9") << 3 << 13 << 8 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); } diff --git a/libs/kotext/tests/TestInsertSectionHandling_data.cpp b/libs/ko= text/tests/TestInsertSectionHandling_data.cpp index 201aab8..26eb670 100644 --- a/libs/kotext/tests/TestInsertSectionHandling_data.cpp +++ b/libs/kotext/tests/TestInsertSectionHandling_data.cpp @@ -26,192 +26,192 @@ void TestKoTextEditor::testInsertSectionHandling_data= () QTest::addColumn< QVector< QVector > >("needEndings"); = QTest::newRow("Test #0") << 0 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "New section 6") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "New section 6") - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "New section 6") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "New section 6") + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Test #1") << 39 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector() << "New section 6") - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector() << "New section 6" << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector() << "New section 6") + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector() << "New section 6" << "0") + << (QVector())); QTest::newRow("Test #2") << 40 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "New section 6")) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector()) - << (QVector() << "New section 6")); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "New section 6")) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector()) + << (QVector() << "New section 6")); QTest::newRow("Test #3") << 5 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "New section 6") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector() << "New section 6") - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "New section 6") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector() << "New section 6") + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Test #4") << 8 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector() << "New section 6") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "New section 6") - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector() << "New section 6") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "New section 6") + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Test #5") << 20 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector() << "New section 6") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "New section 6") - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector() << "New section 6") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "New section 6") + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); QTest::newRow("Test #6") << 1 << 12 - << (QVector< QVector >() - << (QVector() << "0") - << (QVector() << "New section 6") - << (QVector() << "1") - << (QVector() << "2") - << (QVector()) - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector()) - << (QVector()) - << (QVector())) - << (QVector< QVector >() - << (QVector()) - << (QVector() << "New section 6") - << (QVector()) - << (QVector()) - << (QVector() << "2") - << (QVector() << "1") - << (QVector()) - << (QVector() << "3") - << (QVector()) - << (QVector() << "4") - << (QVector() << "0") - << (QVector())); + << (QVector< QVector >() + << (QVector() << "0") + << (QVector() << "New section 6") + << (QVector() << "1") + << (QVector() << "2") + << (QVector()) + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector()) + << (QVector()) + << (QVector())) + << (QVector< QVector >() + << (QVector()) + << (QVector() << "New section 6") + << (QVector()) + << (QVector()) + << (QVector() << "2") + << (QVector() << "1") + << (QVector()) + << (QVector() << "3") + << (QVector()) + << (QVector() << "4") + << (QVector() << "0") + << (QVector())); } diff --git a/libs/kotext/tests/TestKoTextEditor.cpp b/libs/kotext/tests/Tes= tKoTextEditor.cpp index e6056fb..5564d60 100644 --- a/libs/kotext/tests/TestKoTextEditor.cpp +++ b/libs/kotext/tests/TestKoTextEditor.cpp @@ -57,42 +57,42 @@ public: = TestDocument() { - m_document =3D new QTextDocument(); + m_document =3D new QTextDocument(); = - KoTextDocument textDoc(m_document); - KoTextEditor *editor =3D new KoTextEditor(m_document); - KUndo2Stack *undoStack =3D new KUndo2Stack(); - textDoc.setUndoStack(undoStack); + KoTextDocument textDoc(m_document); + KoTextEditor *editor =3D new KoTextEditor(m_document); + KUndo2Stack *undoStack =3D new KUndo2Stack(); + textDoc.setUndoStack(undoStack); = - textDoc.setInlineTextObjectManager(&m_inlineObjectManager); - textDoc.setTextRangeManager(&m_rangeManager); - textDoc.setStyleManager(new KoStyleManager(0)); - textDoc.setTextEditor(editor); + textDoc.setInlineTextObjectManager(&m_inlineObjectManager); + textDoc.setTextRangeManager(&m_rangeManager); + textDoc.setStyleManager(new KoStyleManager(0)); + textDoc.setTextEditor(editor); } = virtual ~TestDocument() { - delete m_document; + delete m_document; } = virtual void addShape(KoShape *shape) { - m_shapes << shape; + m_shapes << shape; } = virtual void removeShape(KoShape *shape) { - m_shapes.removeAll(shape); + m_shapes.removeAll(shape); } = KoTextEditor *textEditor() { - return KoTextDocument(m_document).textEditor(); + return KoTextDocument(m_document).textEditor(); } = KoSectionModel *sectionModel() { - return KoTextDocument(m_document).sectionModel(); + return KoTextDocument(m_document).sectionModel(); } = QList m_shapes; @@ -275,17 +275,17 @@ bool TestKoTextEditor::checkStartings(const QVector &needStartings, KoT QList lst =3D KoSectionUtils::sectionStartings(editor->bl= ockFormat()); = if (lst.size() !=3D needStartings.size()) { - kDebug() << QString("Startings list size is wrong." - " Found %1, Expected %2.").arg(lst.size()).arg(needStartings.size()); - return false; + kDebug() << QString("Startings list size is wrong." + " Found %1, Expected %2.").arg(lst.size()).arg(needSta= rtings.size()); + return false; } = for (int i =3D 0; i < needStartings.size(); i++) { - if (lst[i]->name() !=3D needStartings[i]) { - kDebug() << QString("Found unexpected section starting." - " Expected %1 section.").arg(needStartings[i]); - return false; - } + if (lst[i]->name() !=3D needStartings[i]) { + kDebug() << QString("Found unexpected section starting." + " Expected %1 section.").arg(needStartings[i]); + return false; + } } = return true; @@ -296,17 +296,17 @@ bool TestKoTextEditor::checkEndings(const QVector &needEndings, KoTextE QList lst =3D KoSectionUtils::sectionEndings(editor->b= lockFormat()); = if (lst.size() !=3D needEndings.size()) { - kDebug() << QString("Endings list size is wrong." - " Found %1, expected %2.").arg(lst.size()).arg(needEndings.size()); - return false; + kDebug() << QString("Endings list size is wrong." + " Found %1, expected %2.").arg(lst.size()).arg(needEnd= ings.size()); + return false; } = for (int i =3D 0; i < needEndings.size(); i++) { - if (lst[i]->correspondingSection()->name() !=3D needEndings[i]) { - kDebug() << QString("Found unexpected section ending." - " Expected %1 section.").arg(needEndings[i]); - return false; - } + if (lst[i]->correspondingSection()->name() !=3D needEndings[i]) { + kDebug() << QString("Found unexpected section ending." + " Expected %1 section.").arg(needEndings[i]); + return false; + } } = return true; @@ -328,11 +328,11 @@ void TestKoTextEditor::checkSectionFormattingLevel( = QCOMPARE(doc->m_document->blockCount(), neededBlockCount); for (int i =3D 0; i < doc->m_document->blockCount(); i++) { - if (!checkStartings(needStartings[i], editor) - || !checkEndings(needEndings[i], editor)) { - QFAIL("Wrong section information."); - } - editor->movePosition(QTextCursor::NextBlock); + if (!checkStartings(needStartings[i], editor) + || !checkEndings(needEndings[i], editor)) { + QFAIL("Wrong section information."); + } + editor->movePosition(QTextCursor::NextBlock); } } = @@ -343,7 +343,7 @@ void TestKoTextEditor::checkSectionModelLevelRecursive(= QModelIndex index, TestKo QModelIndex parent =3D index.parent(); QCOMPARE(parent.data(KoSectionModel::PointerRole).value()= , handle->parent); for (int i =3D 0; i < handle->children.size(); i++) { - checkSectionModelLevelRecursive(index.child(i, 0), handle->children[i]); + checkSectionModelLevelRecursive(index.child(i, 0), handle->childre= n[i]); } } = @@ -360,39 +360,39 @@ void TestKoTextEditor::checkSectionModelLevel(TestDoc= ument *doc) // This kind of cycle should visit all blocks // including ones in tables and frames. while (curBlock.isValid()) { - QList secStartings =3D KoSectionUtils::sectionStartings(curB= lock.blockFormat()); - QList secEndings =3D KoSectionUtils::sectionEndings(curBl= ock.blockFormat()); - - foreach(KoSection *sec, secStartings) { - SectionHandle *handle =3D new SectionHandle(sec); - if (sectionStack.empty()) { - rootSections.push_back(handle); - handle->parent =3D 0; - } else { - sectionStack.top()->children.push_back(handle); - handle->parent =3D sectionStack.top()->sec; - } - - allSections.push_back(handle); - sectionStack.push(handle); - } - - foreach(KoSectionEnd *secEnd, secEndings) { - sectionStack.pop(); - } - - curBlock =3D curBlock.next(); + QList secStartings =3D KoSectionUtils::sectionStartin= gs(curBlock.blockFormat()); + QList secEndings =3D KoSectionUtils::sectionEnding= s(curBlock.blockFormat()); + + foreach(KoSection *sec, secStartings) { + SectionHandle *handle =3D new SectionHandle(sec); + if (sectionStack.empty()) { + rootSections.push_back(handle); + handle->parent =3D 0; + } else { + sectionStack.top()->children.push_back(handle); + handle->parent =3D sectionStack.top()->sec; + } + + allSections.push_back(handle); + sectionStack.push(handle); + } + + foreach(KoSectionEnd *secEnd, secEndings) { + sectionStack.pop(); + } + + curBlock =3D curBlock.next(); } = // Now lets compare builded tree with KoSectionModel KoSectionModel *model =3D doc->sectionModel(); QCOMPARE(model->rowCount(), rootSections.size()); for (int i =3D 0; i < rootSections.size(); i++) { - checkSectionModelLevelRecursive(model->index(i, 0), rootSections[i]); + checkSectionModelLevelRecursive(model->index(i, 0), rootSections[i= ]); } = foreach (SectionHandle *handle, allSections) { - delete handle; + delete handle; } } = @@ -405,41 +405,41 @@ void TestKoTextEditor::dumpSectionFormattingLevel(Tes= tDocument *doc) // This kind of cycle should visit all blocks // including ones in tables and frames. while (curBlock.isValid()) { - result +=3D " << (QVector()"; - QList l =3D KoSectionUtils::sectionStartings(curBlock.blockF= ormat()); - foreach (KoSection *s, l) { - result +=3D QString(" << \"%1\"").arg(s->name()); - } - result +=3D ")"; - curBlock =3D curBlock.next(); - if (curBlock.isValid()) { - result +=3D "\n"; - } else { - result +=3D ")\n"; - } + result +=3D " << (QVector()"; + QList l =3D KoSectionUtils::sectionStartings(curBlock= .blockFormat()); + foreach (KoSection *s, l) { + result +=3D QString(" << \"%1\"").arg(s->name()); + } + result +=3D ")"; + curBlock =3D curBlock.next(); + if (curBlock.isValid()) { + result +=3D "\n"; + } else { + result +=3D ")\n"; + } } = result +=3D " << (QVector< QVector >()\n"; curBlock =3D doc->m_document->firstBlock(); while (curBlock.isValid()) { - result +=3D " << (QVector()"; - QList l =3D KoSectionUtils::sectionEndings(curBlock.block= Format()); - foreach (KoSectionEnd *e, l) { - result +=3D QString(" << \"%1\"").arg(e->correspondingSection()->name= ()); - } - result +=3D ")"; - curBlock =3D curBlock.next(); - if (curBlock.isValid()) { - result +=3D "\n"; - } else { - result +=3D ")\n"; - } + result +=3D " << (QVector()"; + QList l =3D KoSectionUtils::sectionEndings(curBloc= k.blockFormat()); + foreach (KoSectionEnd *e, l) { + result +=3D QString(" << \"%1\"").arg(e->correspondingSection(= )->name()); + } + result +=3D ")"; + curBlock =3D curBlock.next(); + if (curBlock.isValid()) { + result +=3D "\n"; + } else { + result +=3D ")\n"; + } } result +=3D ";"; = QFile out(QString("dump_%1.txt").arg(QTest::currentDataTag())); if (out.open(QIODevice::ReadWrite)) { - QTextStream(&out) << result; + QTextStream(&out) << result; } out.close(); } diff --git a/libs/kotext/tests/TestKoTextEditor.h b/libs/kotext/tests/TestK= oTextEditor.h index 851f212..e61f59d 100644 --- a/libs/kotext/tests/TestKoTextEditor.h +++ b/libs/kotext/tests/TestKoTextEditor.h @@ -51,24 +51,24 @@ private: // Sections stuff struct SectionHandle { - explicit SectionHandle(KoSection *_sec) - : sec(_sec) - , parent(0) - { - } + explicit SectionHandle(KoSection *_sec) + : sec(_sec) + , parent(0) + { + } = - KoSection *sec; - KoSection *parent; - QList children; + KoSection *sec; + KoSection *parent; + QList children; }; = bool checkEndings(const QVector &needEndings, KoTextEditor *e= ditor); bool checkStartings(const QVector &needStartings, KoTextEdito= r *editor); void checkSectionFormattingLevel( - TestDocument *doc, - int neededBlockCount, - const QVector< QVector > &needStartings, - const QVector< QVector > &needEndings); + TestDocument *doc, + int neededBlockCount, + const QVector< QVector > &needStartings, + const QVector< QVector > &needEndings); void checkSectionModelLevel(TestDocument *doc); void checkSectionModelLevelRecursive(QModelIndex index, SectionHandle = *handle); = diff --git a/plugins/textshape/dialogs/SectionFormatDialog.cpp b/plugins/te= xtshape/dialogs/SectionFormatDialog.cpp index 325413e..865167a 100644 --- a/plugins/textshape/dialogs/SectionFormatDialog.cpp +++ b/plugins/textshape/dialogs/SectionFormatDialog.cpp @@ -33,55 +33,55 @@ class SectionFormatDialog::ProxyModel : public QIdentit= yProxyModel { public: ProxyModel(KoSectionModel *model, QObject *parent =3D 0) - : QIdentityProxyModel(parent) + : QIdentityProxyModel(parent) { - setSourceModel(model); + setSourceModel(model); } = virtual int columnCount(const QModelIndex &parent =3D QModelIndex()) c= onst { - Q_UNUSED(parent); - return 1; // We have one column with "Name of section" + Q_UNUSED(parent); + return 1; // We have one column with "Name of section" } = virtual QVariant headerData(int section, Qt::Orientation orientation, = int role) const { - if (orientation !=3D Qt::Horizontal || section !=3D 0) { - return QVariant(); - } - - if (role =3D=3D Qt::DisplayRole) { - return i18n("Section name"); - } - return QVariant(); + if (orientation !=3D Qt::Horizontal || section !=3D 0) { + return QVariant(); + } + + if (role =3D=3D Qt::DisplayRole) { + return i18n("Section name"); + } + return QVariant(); } = virtual QVariant data(const QModelIndex &proxyIndex, int role =3D Qt::= DisplayRole) const { - if (!proxyIndex.isValid() || proxyIndex.column() !=3D 0) { - return QVariant(); - } - - if (role =3D=3D Qt::DisplayRole) { - KoSection *ptr =3D getSectionByIndex(proxyIndex); - return ptr->name(); - } - return QVariant(); + if (!proxyIndex.isValid() || proxyIndex.column() !=3D 0) { + return QVariant(); + } + + if (role =3D=3D Qt::DisplayRole) { + KoSection *ptr =3D getSectionByIndex(proxyIndex); + return ptr->name(); + } + return QVariant(); } = KoSection *getSectionByIndex(const QModelIndex &idx) const { - return sourceModel()->data( - mapToSource(idx), - KoSectionModel::PointerRole - ).value(); + return sourceModel()->data( + mapToSource(idx), + KoSectionModel::PointerRole + ).value(); } = private: // Make it private. It is intented to be used only with KoSectionModel= that is passed through constructor virtual void setSourceModel(QAbstractItemModel *sourceModel) { - QAbstractProxyModel::setSourceModel(sourceModel); + QAbstractProxyModel::setSourceModel(sourceModel); } }; = @@ -89,9 +89,9 @@ class SectionFormatDialog::SectionNameValidator : public = QValidator { public: SectionNameValidator(QObject *parent, KoSectionModel *sectionManager, = KoSection *section) - : QValidator(parent) - , m_sectionModel(sectionManager) - , m_section(section) + : QValidator(parent) + , m_sectionModel(sectionManager) + , m_section(section) { } = diff --git a/plugins/textshape/dialogs/SectionsSplitDialog.cpp b/plugins/te= xtshape/dialogs/SectionsSplitDialog.cpp index 7f2f8f9..53e7b17 100644 --- a/plugins/textshape/dialogs/SectionsSplitDialog.cpp +++ b/plugins/textshape/dialogs/SectionsSplitDialog.cpp @@ -41,10 +41,10 @@ SectionsSplitDialog::SectionsSplitDialog(QWidget *paren= t, KoTextEditor *editor) QList secStartings =3D KoSectionUtils::sectionStartings(e= ditor->blockFormat()); QList secEndings =3D KoSectionUtils::sectionEndings(ed= itor->blockFormat()); foreach (KoSection *sec, secStartings) { - m_widget.beforeList->addItem(sec->name()); + m_widget.beforeList->addItem(sec->name()); } foreach (KoSectionEnd *secEnd, secEndings) { - m_widget.afterList->addItem(secEnd->name()); + m_widget.afterList->addItem(secEnd->name()); } = connect(m_widget.beforeList, SIGNAL(itemSelectionChanged()), this, SLO= T(beforeListSelection())); @@ -56,25 +56,25 @@ SectionsSplitDialog::SectionsSplitDialog(QWidget *paren= t, KoTextEditor *editor) void SectionsSplitDialog::afterListSelection() { if (m_widget.afterList->selectedItems().size()) { // FIXME: more elega= nt way to check selection? - enableButton(KDialog::Ok, true); - m_widget.beforeList->clearSelection(); + enableButton(KDialog::Ok, true); + m_widget.beforeList->clearSelection(); } } = void SectionsSplitDialog::beforeListSelection() { if (m_widget.beforeList->selectedItems().size()) { - enableButton(KDialog::Ok, true); - m_widget.afterList->clearSelection(); + enableButton(KDialog::Ok, true); + m_widget.afterList->clearSelection(); } } = void SectionsSplitDialog::okClicked() { if (m_widget.beforeList->selectedItems().size()) { - m_editor->splitSectionsStartings(m_widget.beforeList->currentRow()); + m_editor->splitSectionsStartings(m_widget.beforeList->currentRow()= ); } else { - m_editor->splitSectionsEndings(m_widget.afterList->currentRow()); + m_editor->splitSectionsEndings(m_widget.afterList->currentRow()); } } = diff --git a/plugins/textshape/dialogs/SimpleInsertWidget.ui b/plugins/text= shape/dialogs/SimpleInsertWidget.ui index 4090c2f..2433f50 100644 --- a/plugins/textshape/dialogs/SimpleInsertWidget.ui +++ b/plugins/textshape/dialogs/SimpleInsertWidget.ui @@ -35,23 +35,23 @@ 2 - - - ... - - - - 16 - 16 - - - - QToolButton::InstantPopup - - - true - - + + + ... + + + + 16 + 16 + + + + QToolButton::InstantPopup + + + true + + diff --git a/words/part/KWOdfLoader.cpp b/words/part/KWOdfLoader.cpp index f2145b2..298bf45 100644 --- a/words/part/KWOdfLoader.cpp +++ b/words/part/KWOdfLoader.cpp @@ -349,18 +349,18 @@ void KWOdfLoader::loadHeaderFooterFrame(KoShapeLoadin= gContext &context, const KW = //1.6: KWOasisLoader::loadOasisHeaderFooter void KWOdfLoader::loadHeaderFooter(KoShapeLoadingContext &context, KWPageS= tyle &pageStyle, - const KoXmlElement &masterPage, HFLoadType headerFooter) + const KoXmlElement &masterPage, HFLoadT= ype headerFooter) { // The actual content of the header/footer. KoXmlElement elem =3D KoXml::namedItemNS(masterPage, KoXmlNS::style, - headerFooter =3D=3D LoadHeader ? "header" : "footer"); + headerFooter =3D=3D LoadHeader = ? "header" : "footer"); = // The two additional elements and // specifies if defined that even and odd pages should be displayed // different. If they are missing, the content of odd and even (aka le= ft // and right) pages are the same. KoXmlElement leftElem =3D KoXml::namedItemNS(masterPage, KoXmlNS::styl= e, - headerFooter =3D=3D LoadHeader ? "header-left" : "footer-left"= ); + headerFooter =3D=3D LoadHea= der ? "header-left" : "footer-left"); = // Used in KWPageStyle to determine if, and what kind of header/footer= to use. Words::HeaderFooterType hfType =3D elem.isNull() ? Words::HFTypeNone @@ -370,15 +370,15 @@ void KWOdfLoader::loadHeaderFooter(KoShapeLoadingCont= ext &context, KWPageStyle & // header-left and footer-left if (! leftElem.isNull()) { loadHeaderFooterFrame(context, pageStyle, leftElem, - headerFooter =3D=3D LoadHeader ? Words::EvenPagesHeaderTextFrameS= et - : Words::EvenPagesFooterTextFrameSet); + headerFooter =3D=3D LoadHeader ? Words::Even= PagesHeaderTextFrameSet + : Words::EvenPage= sFooterTextFrameSet); } = // header and footer if (! elem.isNull()) { loadHeaderFooterFrame(context, pageStyle, elem, - headerFooter =3D=3D LoadHeader ? Words::OddPagesHeaderTextFrameSet - : Words::OddPagesFooterTextFrameSet); + headerFooter =3D=3D LoadHeader ? Words::OddP= agesHeaderTextFrameSet + : Words::OddPages= FooterTextFrameSet); } = if (headerFooter =3D=3D LoadHeader) { diff --git a/words/part/dockers/KWDebugWidget.cpp b/words/part/dockers/KWDe= bugWidget.cpp index d6def11..4a05c8c 100644 --- a/words/part/dockers/KWDebugWidget.cpp +++ b/words/part/dockers/KWDebugWidget.cpp @@ -93,7 +93,7 @@ void KWDebugWidget::updateData() = QString willShow =3D "This sections starts here :"; foreach (const KoSection *sec, KoSectionUtils::sectionStartings(fmt)) { - QPair bnds =3D sec->bounds(); + QPair bnds =3D sec->bounds(); willShow +=3D " \"" + sec->name() + "\"(" + QString::number(bnds.f= irst) + "; " + QString::number(bnds.second) + ")"; } willShow.append("\n");