File indexing completed on 2024-05-19 04:36:23

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2015 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "ConfigObject.h"
0021 
0022 namespace tikz {
0023 namespace core {
0024 
0025 ConfigObject::ConfigObject(QObject * parent)
0026     : QObject(parent)
0027 {
0028 }
0029 
0030 ConfigObject::~ConfigObject()
0031 {
0032 }
0033 
0034 void ConfigObject::beginConfig()
0035 {
0036     Q_ASSERT(m_refCounter >= 0);
0037     ++m_refCounter;
0038 }
0039 
0040 void ConfigObject::endConfig()
0041 {
0042     Q_ASSERT(m_refCounter > 0);
0043 
0044     --m_refCounter;
0045     if (m_refCounter == 0) {
0046         Q_EMIT changed();
0047     }
0048 }
0049 
0050 bool ConfigObject::configActive() const
0051 {
0052     return m_refCounter > 0;
0053 }
0054 
0055 void ConfigObject::emitChangedIfNeeded()
0056 {
0057     if (! configActive()) {
0058         Q_EMIT changed();
0059     }
0060 }
0061 
0062 ConfigTransaction::ConfigTransaction(ConfigObject * configObject)
0063     : m_configObject(configObject)
0064 {
0065     Q_ASSERT(configObject);
0066 
0067     m_configObject->beginConfig();
0068 }
0069 
0070 ConfigTransaction::~ConfigTransaction()
0071 {
0072     endConfig();
0073 }
0074 
0075 void ConfigTransaction::endConfig()
0076 {
0077     if (m_configObject) {
0078         m_configObject->endConfig();
0079         m_configObject = nullptr;
0080     }
0081 }
0082 
0083 }
0084 }
0085 
0086 // kate: indent-width 4; replace-tabs on;