File indexing completed on 2024-12-15 04:01:00
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QUndoCommand> 0010 0011 namespace glaxnimate::command { 0012 0013 0014 enum class Id { 0015 SetPropertyValue, 0016 SetMultipleProperties, 0017 SetKeyframe, 0018 SetMultipleAnimated, 0019 SetPositionBezier, 0020 0021 // For additional commands, use values increadising from here 0022 CustomCommand, 0023 }; 0024 0025 template<Id id_enum, class Derived> 0026 class MergeableCommand : public QUndoCommand 0027 { 0028 public: 0029 int id() const final 0030 { 0031 return int(id_enum); 0032 } 0033 0034 bool mergeWith ( const QUndoCommand * other ) final 0035 { 0036 if ( commit ) 0037 return false; 0038 auto oth = static_cast<const Derived*>(other); 0039 if ( static_cast<Derived*>(this)->merge_with(*oth) ) 0040 { 0041 commit = oth->commit; 0042 return true; 0043 } 0044 return false; 0045 } 0046 0047 protected: 0048 using Parent = MergeableCommand; 0049 0050 MergeableCommand(const QString& name, bool commit = true) 0051 : QUndoCommand(name), commit(commit) 0052 {} 0053 0054 bool commit; 0055 }; 0056 0057 } // namespace glaxnimate::command