File indexing completed on 2024-05-19 05:42:24
0001 // ct_lvtqtc_undo_add_entity_common.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 #ifndef CT_LVTQTC_UNDO_ADD_ENTITY_COMMON_H 0020 #define CT_LVTQTC_UNDO_ADD_ENTITY_COMMON_H 0021 0022 #include <ct_lvtldr_lakosiannode.h> 0023 #include <ct_lvtldr_nodestorage.h> 0024 #include <ct_lvtqtc_graphicsscene.h> 0025 #include <ct_lvtqtc_util.h> 0026 0027 #include <QPointF> 0028 #include <QUndoCommand> 0029 0030 #include <ct_lvtqtc_undo_manager.h> 0031 #include <lvtqtc_export.h> 0032 #include <string> 0033 0034 namespace Codethink::lvtqtc { 0035 0036 class LVTQTC_EXPORT UndoAddEntityBase : public QUndoCommand, public lvtqtc::UndoManager::IgnoreFirstRunMixin { 0037 public: 0038 UndoAddEntityBase(GraphicsScene *scene, 0039 const QPointF& pos, 0040 const std::string& name, 0041 const std::string& qualifiedName, 0042 const std::string& parentQualifiedName, 0043 QtcUtil::UndoActionType undoActionType, 0044 lvtldr::NodeStorage& storage); 0045 0046 // constructor for Add actions. 0047 void undo() override; 0048 void redo() override; 0049 0050 protected: 0051 virtual void addEntity() = 0; 0052 virtual void removeEntity() = 0; 0053 0054 oup::observer_ptr<GraphicsScene> m_scene; 0055 QtcUtil::UndoActionType m_undoActionType = QtcUtil::UndoActionType::e_Add; 0056 0057 struct { 0058 QPointF pos; 0059 std::string name; 0060 std::string qualifiedName; 0061 // uniqueid does not work here because it changes between add / removal of the db. 0062 std::string parentQualifiedName; 0063 std::string currentNotes; 0064 } m_addInfo; 0065 0066 struct { 0067 lvtldr::LakosianNode *nodeToRemove; 0068 } m_removeInfo; 0069 0070 lvtldr::NodeStorage& m_storage; 0071 }; 0072 } // namespace Codethink::lvtqtc 0073 #endif