Copy-on-write for class VAbstractFloatItemData.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-02-23 13:50:13 +02:00
parent c5c3c73429
commit 9714e8cb07
4 changed files with 102 additions and 12 deletions

View File

@ -27,13 +27,29 @@
*************************************************************************/
#include "vabstractfloatitemdata.h"
#include "vabstractfloatitemdata_p.h"
//---------------------------------------------------------------------------------------------------------------------
VAbstractFloatItemData::VAbstractFloatItemData()
: m_ptPos(),
m_bVisible(false)
: d(new VAbstractFloatItemDataPrivate())
{}
//---------------------------------------------------------------------------------------------------------------------
VAbstractFloatItemData::VAbstractFloatItemData(const VAbstractFloatItemData &data)
: d (data.d)
{}
//---------------------------------------------------------------------------------------------------------------------
VAbstractFloatItemData &VAbstractFloatItemData::operator=(const VAbstractFloatItemData &data)
{
if ( &data == this )
{
return *this;
}
d = data.d;
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
VAbstractFloatItemData::~VAbstractFloatItemData()
{}
@ -41,23 +57,23 @@ VAbstractFloatItemData::~VAbstractFloatItemData()
//---------------------------------------------------------------------------------------------------------------------
QPointF VAbstractFloatItemData::GetPos() const
{
return m_ptPos;
return d->m_ptPos;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractFloatItemData::SetPos(const QPointF &ptPos)
{
m_ptPos = ptPos;
d->m_ptPos = ptPos;
}
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractFloatItemData::IsVisible() const
{
return m_bVisible;
return d->m_bVisible;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractFloatItemData::SetVisible(bool bVisible)
{
m_bVisible = bVisible;
d->m_bVisible = bVisible;
}

View File

@ -30,11 +30,16 @@
#define VABSTRACTFLOATITEMDATA_H
#include <QPointF>
#include <QSharedDataPointer>
class VAbstractFloatItemDataPrivate;
class VAbstractFloatItemData
{
public:
VAbstractFloatItemData();
VAbstractFloatItemData(const VAbstractFloatItemData &data);
VAbstractFloatItemData &operator=(const VAbstractFloatItemData &data);
virtual ~VAbstractFloatItemData();
// methods, which set and return values of different parameters
@ -44,11 +49,8 @@ public:
bool IsVisible() const;
void SetVisible(bool bVisible);
protected:
/** @brief m_ptPos position of label's top left corner */
QPointF m_ptPos;
/** @brief m_bVisible visibility flag */
bool m_bVisible;
private:
QSharedDataPointer<VAbstractFloatItemDataPrivate> d;
};
#endif // VABSTRACTFLOATITEMDATA_H

View File

@ -0,0 +1,71 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 23 2, 2017
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VABSTRACTFLOATITEMDATA_P_H
#define VABSTRACTFLOATITEMDATA_P_H
#include <QPointF>
#include <QSharedData>
#include "../vmisc/diagnostic.h"
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
class VAbstractFloatItemDataPrivate : public QSharedData
{
public:
VAbstractFloatItemDataPrivate()
: m_ptPos(),
m_bVisible(false)
{}
VAbstractFloatItemDataPrivate(const VAbstractFloatItemDataPrivate &data)
: QSharedData(data),
m_ptPos(data.m_ptPos),
m_bVisible(data.m_bVisible)
{}
~VAbstractFloatItemDataPrivate();
/** @brief m_ptPos position of label's top left corner */
QPointF m_ptPos;
/** @brief m_bVisible visibility flag */
bool m_bVisible;
private:
VAbstractFloatItemDataPrivate &operator=(const VAbstractFloatItemDataPrivate &) Q_DECL_EQ_DELETE;
};
VAbstractFloatItemDataPrivate::~VAbstractFloatItemDataPrivate()
{}
QT_WARNING_POP
#endif // VABSTRACTFLOATITEMDATA_P_H

View File

@ -67,4 +67,5 @@ HEADERS += \
$$PWD/floatItemData/vpiecelabeldata.h \
$$PWD/floatItemData/vpatternlabeldata.h \
$$PWD/floatItemData/vgrainlinedata.h \
$$PWD/floatItemData/vabstractfloatitemdata.h
$$PWD/floatItemData/vabstractfloatitemdata.h \
$$PWD/floatItemData/vabstractfloatitemdata_p.h