void UndoHistory::moveTo(const UndoState* new_state) { const UndoState* common = findCommonParent(m_cur, new_state); if (m_cur) { while (m_cur != common) { m_cur->m_cmd->undo(); m_cur = m_cur->m_parent; } } if (new_state) { std::stack<const UndoState*> redo_parents; const UndoState* p = new_state; while (p != common) { redo_parents.push(p); p = p->m_parent; } while (!redo_parents.empty()) { p = redo_parents.top(); redo_parents.pop(); p->m_cmd->redo(); } } m_cur = const_cast<UndoState*>(new_state); }
int CModelRowForwardIterator::compare(const QModelIndex &ndx1, int nRow1, const QModelIndex &ndx2, int nRow2) { int nCommonRow1; int nCommonRow2; findCommonParent(ndx1, ndx2, nCommonRow1, nCommonRow2); // If either parent ended up containing the other, use the provided row; // otherwise use the higher level row found from the model: if (nCommonRow1 == -1) nCommonRow1 = nRow1; if (nCommonRow2 == -1) nCommonRow2 = nRow2; if (nCommonRow1 < nCommonRow2) { return -1; } else if (nCommonRow1 > nCommonRow2) { return 1; } return 0; }