Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
860 B
Raw Blame
/*
 * SPDX-FileCopyrightText: 2019 Boudewijn Rempt <[email protected]>
 *
 * SPDX-License-Identifier: LGPL-2.0-or-later
 */
#ifndef KISDIRTYSTATESAVER_H
#define KISDIRTYSTATESAVER_H

#include <KoResource.h>

#include "kritaresources_export.h"
/**
 * Never use manual save/restore calls to
 * KoResource::isDirty()/KoResource::setDirty()! They will lead to
 * hard-to-tack-down bugs when the dirty state will not be
 * restored on jumps like 'return', 'break' or exception.
 */
template <typename T>
class KisDirtyStateSaver
{
public:
    KisDirtyStateSaver(T resource)
        : m_resource(resource)
        , m_isDirty(resource->isDirty())

    {
    }

    ~KisDirtyStateSaver() {
        if (m_resource) {
            m_resource->setDirty(m_isDirty);
        }
    }

private:
    T m_resource;
    bool m_isDirty = false;
};

#endif // KISDIRTYSTATESAVER_H