本文整理汇总了C++中KUndo2Command::mergeWith方法的典型用法代码示例。如果您正苦于以下问题:C++ KUndo2Command::mergeWith方法的具体用法?C++ KUndo2Command::mergeWith怎么用?C++ KUndo2Command::mergeWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KUndo2Command
的用法示例。
在下文中一共展示了KUndo2Command::mergeWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indexChanged
void KUndo2QStack::push(KUndo2Command *cmd)
{
cmd->redo();
bool macro = !m_macro_stack.isEmpty();
KUndo2Command *cur = 0;
if (macro) {
KUndo2Command *macro_cmd = m_macro_stack.last();
if (!macro_cmd->d->child_list.isEmpty())
cur = macro_cmd->d->child_list.last();
} else {
if (m_index > 0)
cur = m_command_list.at(m_index - 1);
while (m_index < m_command_list.size())
delete m_command_list.takeLast();
if (m_clean_index > m_index)
m_clean_index = -1; // we've deleted the clean state
}
bool try_merge = cur != 0
&& cur->id() != -1
&& cur->id() == cmd->id()
&& (macro || m_index != m_clean_index);
if (try_merge && cur->mergeWith(cmd)) {
delete cmd;
if (!macro) {
emit indexChanged(m_index);
emit canUndoChanged(canUndo());
emit undoTextChanged(undoText());
emit canRedoChanged(canRedo());
emit redoTextChanged(redoText());
}
} else {
if (macro) {
m_macro_stack.last()->d->child_list.append(cmd);
} else {
m_command_list.append(cmd);
checkUndoLimit();
setIndex(m_index + 1, false);
}
}
}
示例2: indexChanged
bool KUndo2QStack::push(KUndo2Command *cmd)
{
cmd->redoMergedCommands();
cmd->setEndTime();
bool macro = !m_macro_stack.isEmpty();
KUndo2Command *cur = 0;
if (macro) {
KUndo2Command *macro_cmd = m_macro_stack.last();
if (!macro_cmd->d->child_list.isEmpty())
cur = macro_cmd->d->child_list.last();
} else {
if (m_index > 0)
cur = m_command_list.at(m_index - 1);
while (m_index < m_command_list.size())
delete m_command_list.takeLast();
if (m_clean_index > m_index)
m_clean_index = -1; // we've deleted the clean state
}
bool try_merge = cur != 0
&& cur->id() != -1
&& cur->id() == cmd->id()
&& (macro || m_index != m_clean_index);
/*!
*Here we are going to try to merge several commands together using the QVector field in the commands using
*3 parameters. N : Number of commands that should remain individual at the top of the stack. T1 : Time lapsed between current command and previously merged command -- signal to
*merge throughout the stack. T2 : Time lapsed between two commands signalling both commands belong to the same set
*Whenever a KUndo2Command is initialized -- it consists of a start-time and when it is pushed --an end time.
*Every time a command is pushed -- it checks whether the command pushed was pushed after T1 seconds of the last merged command
*Then the merging begins with each group depending on the time in between each command (T2).
*
*@TODO : Currently it is not able to merge two merged commands together.
*/
if (!macro && m_command_list.size() > 1 && cmd->timedId() != -1 && m_useCumulativeUndoRedo) {
KUndo2Command* lastcmd = m_command_list.last();
if (qAbs(cmd->time().msecsTo(lastcmd->endTime())) < m_timeT2 * 1000) {
m_lastMergedSetCount++;
} else {
m_lastMergedSetCount = 0;
m_lastMergedIndex = m_index-1;
}
if (lastcmd->timedId() == -1){
m_lastMergedSetCount = 0;
m_lastMergedIndex = m_index;
}
if (m_lastMergedSetCount > m_strokesN) {
KUndo2Command* toMerge = m_command_list.at(m_lastMergedIndex);
if (toMerge && m_command_list.size() >= m_lastMergedIndex + 1 && m_command_list.at(m_lastMergedIndex + 1)) {
if(toMerge->timedMergeWith(m_command_list.at(m_lastMergedIndex + 1))){
m_command_list.removeAt(m_lastMergedIndex + 1);
}
m_lastMergedSetCount--;
m_lastMergedIndex = m_command_list.indexOf(toMerge);
}
}
m_index = m_command_list.size();
if(m_lastMergedIndex<m_index){
if (cmd->time().msecsTo(m_command_list.at(m_lastMergedIndex)->endTime()) < -m_timeT1 * 1000) { //T1 time elapsed
QListIterator<KUndo2Command*> it(m_command_list);
it.toBack();
m_lastMergedSetCount = 1;
while (it.hasPrevious()) {
KUndo2Command* curr = it.previous();
KUndo2Command* lastCmdInCurrent = curr;
if (!lastcmd->mergeCommandsVector().isEmpty()) {
if (qAbs(lastcmd->mergeCommandsVector().last()->time().msecsTo(lastCmdInCurrent->endTime())) < int(m_timeT2 * 1000) && lastcmd != lastCmdInCurrent && lastcmd != curr) {
if(lastcmd->timedMergeWith(curr)){
if (m_command_list.contains(curr)) {
m_command_list.removeOne(curr);
}
}
} else {
lastcmd = curr; //end of a merge set
}
} else {
if (qAbs(lastcmd->time().msecsTo(lastCmdInCurrent->endTime())) < int(m_timeT2 * 1000) && lastcmd != lastCmdInCurrent &&lastcmd!=curr) {
if(lastcmd->timedMergeWith(curr)){
if (m_command_list.contains(curr)){
m_command_list.removeOne(curr);
}
}
} else {
lastcmd = curr; //end of a merge set
}
}
}
m_lastMergedIndex = m_command_list.size()-1;
}
}
m_index = m_command_list.size();
}
if (try_merge && cur->mergeWith(cmd)) {
delete cmd;
cmd = 0;
//.........这里部分代码省略.........