MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / recordCommand

Method recordCommand

ElaWidgetTools/ElaActionCommander.cpp:28–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28void ElaActionCommander::recordCommand(const QString& domainName, ElaActionCommand* command, bool isRedo)
29{
30 Q_D(ElaActionCommander);
31 if (!command)
32 {
33 return;
34 }
35 command->setParent(this);
36 auto& commandData = d->_commandDomainMap[domainName];
37 auto& commandList = commandData.commandList;
38 if (commandData.currentIndex <= 0 || commandList.count() == 0)
39 {
40 commandData.undoState = ElaActionCommanderType::UndoValid;
41 commandData.redoState = ElaActionCommanderType::RedoInvalid;
42 Q_EMIT commanderStateChanged(domainName, ElaActionCommanderType::UndoValid);
43 Q_EMIT commanderStateChanged(domainName, ElaActionCommanderType::RedoInvalid);
44 }
45 else
46 {
47 // 超过最大命令数 则移除第一条命令
48 if (commandList.count() >= d->_pMaxRouteCount)
49 {
50 delete commandList[0];
51 commandList.removeFirst();
52 commandData.currentIndex -= 1;
53 }
54 }
55 // 当前索引不位于末尾 则清除索引后的数据
56 if (commandData.currentIndex != commandList.count() - 1)
57 {
58 int deleteStartIndex = commandData.currentIndex + 1;
59 int deleteCount = commandList.count() - commandData.currentIndex - 1;
60 int deleteEndIndex = deleteStartIndex + deleteCount;
61 for (int i = deleteStartIndex; i < deleteEndIndex; i++)
62 {
63 delete commandList[i];
64 }
65 commandList.remove(deleteStartIndex, deleteCount);
66 if (commandData.currentIndex > 0)
67 {
68 commandData.redoState = ElaActionCommanderType::RedoInvalid;
69 Q_EMIT commanderStateChanged(domainName, ElaActionCommanderType::RedoInvalid);
70 }
71 }
72 commandList.append(command);
73 commandData.currentIndex = commandList.count() - 1;
74 if (isRedo)
75 {
76 // 加入时Redo一次
77 command->redo();
78 }
79}
80
81void ElaActionCommander::clearCommand(const QString& domainName)
82{

Callers 5

ElaScrollPageMethod · 0.80
navigationMethod · 0.80
setCurrentStackIndexMethod · 0.80
onTreeViewClickedMethod · 0.80
onFooterViewClickedMethod · 0.80

Calls 2

countMethod · 0.80
redoMethod · 0.45

Tested by

no test coverage detected