File indexing completed on 2024-05-12 15:59:48
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #ifndef KISDIRTYSTATESAVER_H 0007 #define KISDIRTYSTATESAVER_H 0008 0009 #include <KoResource.h> 0010 0011 #include "kritaresources_export.h" 0012 /** 0013 * Never use manual save/restore calls to 0014 * KoResource::isDirty()/KoResource::setDirty()! They will lead to 0015 * hard-to-tack-down bugs when the dirty state will not be 0016 * restored on jumps like 'return', 'break' or exception. 0017 */ 0018 template <typename T> 0019 class KisDirtyStateSaver 0020 { 0021 public: 0022 KisDirtyStateSaver(T resource) 0023 : m_resource(resource) 0024 , m_isDirty(resource->isDirty()) 0025 0026 { 0027 } 0028 0029 ~KisDirtyStateSaver() { 0030 if (m_resource) { 0031 m_resource->setDirty(m_isDirty); 0032 } 0033 } 0034 0035 private: 0036 T m_resource; 0037 bool m_isDirty = false; 0038 }; 0039 0040 #endif // KISDIRTYSTATESAVER_H