File indexing completed on 2024-05-19 05:42:24
0001 // ct_lvtqtc_undo_notes.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_lakosentity.h> 0021 #include <ct_lvtqtc_undo_notes.h> 0022 0023 #include <ct_lvtldr_lakosiannode.h> 0024 #include <ct_lvtldr_nodestorage.h> 0025 #include <ct_lvtqtc_graphicsscene.h> 0026 #include <ct_lvtqtc_graphicsview.h> 0027 #include <ct_lvtqtc_isa.h> 0028 #include <ct_lvtshr_graphenums.h> 0029 0030 #include <optional> 0031 0032 #include <QPointF> 0033 0034 using namespace Codethink::lvtqtc; 0035 using namespace Codethink::lvtldr; 0036 using namespace Codethink; 0037 0038 struct UndoNotes::Private { 0039 std::string qualifiedName; 0040 lvtshr::DiagramType type; 0041 std::string oldNotes; 0042 std::string newNotes; 0043 GraphicsScene *scene; 0044 }; 0045 0046 UndoNotes::UndoNotes(std::string qualifiedName, 0047 lvtshr::DiagramType type, 0048 std::string oldNotes, 0049 std::string newNotes, 0050 GraphicsScene *scene): 0051 d(std::make_unique<Private>( 0052 Private{std::move(qualifiedName), type, std::move(oldNotes), std::move(newNotes), scene})) 0053 { 0054 setText(QObject::tr("Set Notes on Entity")); 0055 } 0056 0057 UndoNotes::~UndoNotes() = default; 0058 0059 void UndoNotes::redo() 0060 { 0061 IGNORE_FIRST_CALL 0062 0063 auto *thisEntity = d->scene->entityByQualifiedName(d->qualifiedName); 0064 if (thisEntity) { 0065 thisEntity->internalNode()->setNotes(d->newNotes); 0066 } 0067 } 0068 0069 void UndoNotes::undo() 0070 { 0071 auto *thisEntity = d->scene->entityByQualifiedName(d->qualifiedName); 0072 if (thisEntity) { 0073 thisEntity->internalNode()->setNotes(d->oldNotes); 0074 } 0075 }