MCPcopy Create free account
hub / github.com/KDE/krita / push

Method push

libs/command/kundo2stack.cpp:722–892  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

720*/
721
722void KUndo2QStack::push(KUndo2Command *cmd)
723{
724 cmd->redoMergedCommands();
725
726 if (cmd->endTime().isNull()) {
727 cmd->setEndTime();
728 }
729
730 bool macro = !m_macro_stack.isEmpty();
731
732 KUndo2Command *cur = 0;
733 if (macro) {
734 KUndo2Command *macro_cmd = m_macro_stack.last();
735 if (!macro_cmd->d->child_list.isEmpty())
736 cur = macro_cmd->d->child_list.last();
737 } else {
738 if (m_index > 0)
739 cur = m_command_list.at(m_index - 1);
740 while (m_index < m_command_list.size())
741 delete m_command_list.takeLast();
742 if (m_clean_index > m_index)
743 m_clean_index = -1; // we've deleted the clean state
744 }
745
746 bool try_merge = cur != 0
747 && cur->id() != -1
748 && cur->id() == cmd->id()
749 && (macro || m_index != m_clean_index);
750
751 /**
752 * Here we are going to try to merge several commands together using the
753 * QVector field in the commands using 3 parameters.
754 *
755 * N : Number of commands that should remain individual at the top of the
756 * stack.
757 *
758 * T1 : Timeout for the commands to be outdated and merged
759 *
760 * T2 : Time separation between two commands to be considered as belonging
761 * to the same group
762 *
763 */
764
765 if (!macro && m_command_list.size() > 1 && cmd->timedId() != -1 && m_useCumulativeUndoRedo) {
766 KUndo2Command* lastcmd = m_command_list.last();
767
768 auto tryMergeBack =
769 [this] (auto revIt, bool *isMerged) {
770 /// we have a guarantee that std::next(revIt) exists,
771 /// so we can safely iterate back in the forward order
772 auto dst = std::prev(revIt.base());
773 auto src = std::prev(dst);
774
775 if ((*dst)->timedId() != -1 &&
776 (*dst)->timedId() == (*src)->timedId() &&
777 (*src)->time().msecsTo((*dst)->endTime()) <= m_cumulativeUndoData.maxGroupDuration &&
778 (*src)->endTime().msecsTo((*dst)->time()) <= m_cumulativeUndoData.maxGroupSeparation &&
779 (*dst)->timedMergeWith(*src)) {

Callers 15

addCommandMethod · 0.45
testExcludeFromMergeMethod · 0.45
testMergeTimeoutMethod · 0.45
testGroupSeparationMethod · 0.45
testMaxGroupDurationMethod · 0.45
startElementMethod · 0.45
pushDirectoryMethod · 0.45
setPaletteTypeMethod · 0.45
addSwatchMethod · 0.45
removeSwatchMethod · 0.45

Calls 15

setIndexFunction · 0.85
redoMergedCommandsMethod · 0.80
lastMethod · 0.80
distanceFunction · 0.50
nextFunction · 0.50
isNullMethod · 0.45
endTimeMethod · 0.45
setEndTimeMethod · 0.45
isEmptyMethod · 0.45
atMethod · 0.45
sizeMethod · 0.45
idMethod · 0.45

Tested by 8

testExcludeFromMergeMethod · 0.36
testMergeTimeoutMethod · 0.36
testGroupSeparationMethod · 0.36
testMaxGroupDurationMethod · 0.36
rowsAboutToBeInsertedMethod · 0.36
rowsAboutToBeRemovedMethod · 0.36