File indexing completed on 2024-05-19 05:42:24
0001 // ct_lvtqtc_undo_rename_entity.cpp -*-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 0020 #include <ct_lvtqtc_undo_rename_entity.h> 0021 0022 #include <ct_lvtldr_lakosiannode.h> 0023 #include <ct_lvtldr_nodestorage.h> 0024 #include <ct_lvtqtc_graphicsscene.h> 0025 #include <ct_lvtqtc_graphicsview.h> 0026 #include <ct_lvtqtc_isa.h> 0027 #include <ct_lvtshr_graphenums.h> 0028 0029 #include <optional> 0030 0031 #include <QPointF> 0032 0033 using namespace Codethink::lvtqtc; 0034 using namespace Codethink::lvtldr; 0035 using namespace Codethink; 0036 0037 struct UndoRenameEntity::Private { 0038 std::string qualifiedName; 0039 std::string oldQualifiedName; 0040 lvtshr::DiagramType type; 0041 std::string oldName; 0042 std::string newName; 0043 NodeStorage& nodeStorage; 0044 }; 0045 0046 UndoRenameEntity::UndoRenameEntity(std::string qualifiedName, 0047 std::string oldQualifiedName, 0048 lvtshr::DiagramType type, 0049 std::string oldName, 0050 std::string newName, 0051 NodeStorage& nodeStorage): 0052 d(std::make_unique<Private>(Private{std::move(qualifiedName), 0053 std::move(oldQualifiedName), 0054 type, 0055 std::move(oldName), 0056 std::move(newName), 0057 nodeStorage})) 0058 { 0059 setText(QObject::tr("Rename entity")); 0060 } 0061 0062 UndoRenameEntity::~UndoRenameEntity() = default; 0063 0064 void UndoRenameEntity::redo() 0065 { 0066 IGNORE_FIRST_CALL 0067 0068 auto *node = d->nodeStorage.findByQualifiedName(d->type, d->oldQualifiedName); 0069 node->setName(d->newName); 0070 } 0071 0072 void UndoRenameEntity::undo() 0073 { 0074 auto *node = d->nodeStorage.findByQualifiedName(d->type, d->qualifiedName); 0075 node->setName(d->oldName); 0076 }