2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vcontainer.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @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) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
#include "vcontainer.h"
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QDebug>
|
2014-03-19 19:27:11 +01:00
|
|
|
#include "../widgets/vapplication.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../geometry/varc.h"
|
|
|
|
#include "../geometry/vsplinepath.h"
|
2014-06-17 11:50:11 +02:00
|
|
|
#include <QLineF>
|
|
|
|
#include <QtAlgorithms>
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2014-08-17 17:20:55 +02:00
|
|
|
quint32 VContainer::_id = NULL_ID;
|
2013-08-15 22:39:00 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief VContainer create empty container
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer::VContainer()
|
2014-07-29 13:28:18 +02:00
|
|
|
:_size(50), sizeName(size_M), _height(176), heightName(height_M),
|
|
|
|
gObjects(QHash<quint32, VGObject *>()), variables(QHash<QString, VInternalVariable*> ()),
|
|
|
|
details(QHash<quint32, VDetail>())
|
|
|
|
{
|
|
|
|
}
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief operator = copy constructor
|
|
|
|
* @param data container
|
|
|
|
* @return copy container
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer &VContainer::operator =(const VContainer &data)
|
|
|
|
{
|
2014-07-27 14:30:28 +02:00
|
|
|
if ( &data == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2013-08-15 22:39:00 +02:00
|
|
|
setData(data);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief VContainer create container from another container
|
|
|
|
* @param data container
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer::VContainer(const VContainer &data)
|
2014-07-29 13:28:18 +02:00
|
|
|
:_size(50), sizeName(size_M), _height(176), heightName(height_M),
|
|
|
|
gObjects(QHash<quint32, VGObject *>()), variables(QHash<QString, VInternalVariable*> ()),
|
|
|
|
details(QHash<quint32, VDetail>())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
setData(data);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-12-30 19:59:33 +01:00
|
|
|
VContainer::~VContainer()
|
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
ClearGObjects();
|
|
|
|
ClearVariables();
|
2013-12-30 19:59:33 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief setData copy data from container
|
|
|
|
* @param data container
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VContainer::setData(const VContainer &data)
|
|
|
|
{
|
2014-03-11 21:19:13 +01:00
|
|
|
_size = data.size();
|
|
|
|
sizeName = data.SizeName();
|
|
|
|
_height = data.height();
|
|
|
|
heightName = data.HeightName();
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
|
|
|
ClearGObjects();
|
|
|
|
const QHash<quint32, VGObject*> *obj = data.DataGObjects();
|
|
|
|
SCASSERT(obj != nullptr);
|
|
|
|
QHashIterator<quint32, VGObject*> i(*obj);
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
switch (i.value()->getType())
|
|
|
|
{
|
|
|
|
case (GOType::Arc):
|
|
|
|
CopyGObject<VArc>(data, i.key());
|
|
|
|
break;
|
|
|
|
case (GOType::Point):
|
|
|
|
CopyGObject<VPointF>(data, i.key());
|
|
|
|
break;
|
|
|
|
case (GOType::Spline):
|
|
|
|
CopyGObject<VSpline>(data, i.key());
|
|
|
|
break;
|
|
|
|
case (GOType::SplinePath):
|
|
|
|
CopyGObject<VSplinePath>(data, i.key());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"Don't know how copy this type.";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 12:28:33 +01:00
|
|
|
|
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
ClearVariables();
|
|
|
|
const QHash<QString, VInternalVariable*> *vars = data.DataVariables();
|
|
|
|
SCASSERT(vars != nullptr);
|
|
|
|
QHashIterator<QString, VInternalVariable*> i(*vars);
|
|
|
|
while (i.hasNext())
|
2013-12-30 12:28:33 +01:00
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
i.next();
|
|
|
|
switch (i.value()->GetType())
|
|
|
|
{
|
|
|
|
case (VarType::Measurement):
|
|
|
|
CopyVar<VMeasurement>(data, i.key());
|
|
|
|
break;
|
|
|
|
case (VarType::Increment):
|
|
|
|
CopyVar<VIncrement>(data, i.key());
|
|
|
|
break;
|
2014-08-15 19:27:30 +02:00
|
|
|
case (VarType::LineLength):
|
2014-07-29 13:28:18 +02:00
|
|
|
CopyVar<VLengthLine>(data, i.key());
|
|
|
|
break;
|
2014-08-15 19:27:30 +02:00
|
|
|
case (VarType::SplineLength):
|
|
|
|
CopyVar<VSplineLength>(data, i.key());
|
2014-07-29 13:28:18 +02:00
|
|
|
break;
|
2014-08-15 19:27:30 +02:00
|
|
|
case (VarType::ArcLength):
|
|
|
|
CopyVar<VArcLength>(data, i.key());
|
2014-07-29 13:28:18 +02:00
|
|
|
break;
|
|
|
|
case (VarType::LineAngle):
|
|
|
|
CopyVar<VLineAngle>(data, i.key());
|
|
|
|
break;
|
|
|
|
case (VarType::Unknown):
|
|
|
|
default:
|
|
|
|
qDebug()<<"Don't know how copy this type.";
|
|
|
|
break;
|
|
|
|
}
|
2013-12-30 12:28:33 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
details = *data.DataDetails();
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief GetGObject returns a point by id
|
|
|
|
* @param id id of point
|
|
|
|
* @return point
|
|
|
|
*/
|
2014-05-02 10:09:10 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-02-25 15:40:24 +01:00
|
|
|
const VGObject *VContainer::GetGObject(quint32 id)const
|
2013-11-15 18:38:29 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
return GetObject(gObjects, id);
|
2013-11-15 18:38:29 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief GetObject return object from container
|
|
|
|
* @param obj container
|
|
|
|
* @param id id of object
|
|
|
|
* @return Object
|
|
|
|
*/
|
2013-08-13 18:48:36 +02:00
|
|
|
template <typename key, typename val>
|
2013-12-30 12:28:33 +01:00
|
|
|
const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (obj.contains(id))
|
|
|
|
{
|
2013-08-13 18:48:36 +02:00
|
|
|
return obj.value(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-23 14:08:06 +02:00
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
2013-07-13 12:51:31 +02:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-07-29 13:28:18 +02:00
|
|
|
* @brief GetDetail return detail by id
|
|
|
|
* @param id id of detail
|
|
|
|
* @return detail
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
const VDetail VContainer::GetDetail(quint32 id) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
if (details.contains(id))
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
return details.value(id);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-06-02 09:43:27 +02:00
|
|
|
* @brief AddGObject add new GObject to container
|
|
|
|
* @param obj new object
|
|
|
|
* @return return id of new object in container
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::AddGObject(VGObject *obj)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
return AddObject(gObjects, obj);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief AddDetail add new detail to container
|
|
|
|
* @param detail new detail
|
|
|
|
* @return return id of new detail in container
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::AddDetail(VDetail detail)
|
2013-12-30 19:59:33 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = getNextId();
|
2013-12-30 19:59:33 +01:00
|
|
|
details[id] = detail;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief getNextId generate next unique id
|
|
|
|
* @return next unique id
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::getNextId()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-09-12 16:18:31 +02:00
|
|
|
_id++;
|
2013-07-13 12:51:31 +02:00
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdateId update id. If new id bigger when current save new like current.
|
|
|
|
* @param newId id
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateId(quint32 newId)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (newId > _id)
|
|
|
|
{
|
2013-09-12 16:18:31 +02:00
|
|
|
_id = newId;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdateObject update object in container
|
|
|
|
* @param obj container
|
|
|
|
* @param id id of existing object
|
|
|
|
* @param point object
|
|
|
|
*/
|
2013-08-13 18:48:36 +02:00
|
|
|
template <typename val>
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateObject(QHash<quint32, val> &obj, const quint32 &id, val point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-17 17:20:55 +02:00
|
|
|
Q_ASSERT_X(id > NULL_ID, Q_FUNC_INFO, "id = 0");
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(point != nullptr);
|
2013-12-31 09:44:54 +01:00
|
|
|
point->setId(id);
|
2014-01-02 16:50:01 +01:00
|
|
|
if (gObjects.contains(id))
|
|
|
|
{
|
|
|
|
delete gObjects.value(id);
|
|
|
|
gObjects.remove(id);
|
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
obj[id] = point;
|
|
|
|
UpdateId(id);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief Clear clear data in container. Id will be 0.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VContainer::Clear()
|
|
|
|
{
|
2014-08-17 17:20:55 +02:00
|
|
|
_id = NULL_ID;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
details.clear();
|
2014-07-29 13:28:18 +02:00
|
|
|
ClearVariables();
|
2014-01-02 16:50:01 +01:00
|
|
|
ClearGObjects();
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief ClearObject points, splines, arcs, spline paths will be cleared.
|
|
|
|
*/
|
2014-01-02 16:50:01 +01:00
|
|
|
void VContainer::ClearGObjects()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
qDeleteAll(gObjects);
|
2013-12-29 17:48:57 +01:00
|
|
|
gObjects.clear();
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-02 16:50:01 +01:00
|
|
|
void VContainer::ClearCalculationGObjects()
|
|
|
|
{
|
|
|
|
if (gObjects.size()>0)
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
QHashIterator<quint32, VGObject*> i(gObjects);
|
2014-01-02 16:50:01 +01:00
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
2014-06-12 09:22:29 +02:00
|
|
|
if (i.value()->getMode() == Draw::Calculation)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
delete i.value();
|
|
|
|
gObjects.remove(i.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearVariables(const VarType &type)
|
|
|
|
{
|
|
|
|
if (variables.size()>0)
|
|
|
|
{
|
|
|
|
if (type == VarType::Unknown)
|
|
|
|
{
|
|
|
|
qDeleteAll(variables);
|
|
|
|
variables.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QHashIterator<QString, VInternalVariable*> i(variables);
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
if (i.value()->GetType() == type)
|
|
|
|
{
|
|
|
|
delete i.value();
|
|
|
|
variables.remove(i.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief AddLine add line to container
|
|
|
|
* @param firstPointId id of first point of line
|
|
|
|
* @param secondPointId id of second point of line
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPointId)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
const VPointF *first = GeometricObject<const VPointF *>(firstPointId);
|
|
|
|
const VPointF *second = GeometricObject<const VPointF *>(secondPointId);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
|
|
|
VLengthLine *length = new VLengthLine(first, firstPointId, second, secondPointId);
|
|
|
|
AddVariable(length->GetName(), length);
|
|
|
|
|
|
|
|
VLineAngle *angle = new VLineAngle(first, firstPointId, second, secondPointId);
|
|
|
|
AddVariable(angle->GetName(), angle);
|
2013-07-30 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief AddObject add object to container
|
|
|
|
* @param obj container
|
|
|
|
* @param value object
|
|
|
|
* @return id of object in container
|
|
|
|
*/
|
2013-10-27 11:22:44 +01:00
|
|
|
template <typename key, typename val>
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(value != nullptr);
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = getNextId();
|
2013-12-29 17:48:57 +01:00
|
|
|
value->setId(id);
|
2013-10-27 11:22:44 +01:00
|
|
|
obj[id] = value;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-06-02 09:43:27 +02:00
|
|
|
* @brief UpdateGObject update GObject by id
|
|
|
|
* @param id id of existing GObject
|
|
|
|
* @param obj object
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateGObject(quint32 id, VGObject* obj)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-07-11 16:22:00 +02:00
|
|
|
SCASSERT(obj != nullptr);
|
2013-12-29 17:48:57 +01:00
|
|
|
UpdateObject(gObjects, id, obj);
|
2013-10-27 11:22:44 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdateDetail update detail by id
|
|
|
|
* @param id id of existing detail
|
|
|
|
* @param detail detail
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateDetail(quint32 id, const VDetail &detail)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-17 17:20:55 +02:00
|
|
|
Q_ASSERT_X(id > NULL_ID, Q_FUNC_INFO, "id = 0");
|
2013-12-30 19:59:33 +01:00
|
|
|
details[id] = detail;
|
|
|
|
UpdateId(id);
|
2013-10-27 11:22:44 +01:00
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VContainer::GetTableValue(const QString &name) const
|
|
|
|
{
|
|
|
|
VVariable *m = GetVariable<VVariable*>(name);
|
|
|
|
if (qApp->patternType() == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
m->SetValue(size(), height());
|
|
|
|
}
|
|
|
|
return *m->GetValue();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-07-29 13:28:18 +02:00
|
|
|
* @brief RemoveIncrement remove increment by name from increment table
|
|
|
|
* @param name name of existing increment
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
void VContainer::RemoveIncrement(const QString &name)
|
|
|
|
{
|
|
|
|
delete variables.value(name);
|
|
|
|
variables.remove(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QMap<QString, VMeasurement*> VContainer::DataMeasurements() const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
return DataVar<VMeasurement>(VarType::Measurement);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QMap<QString, VIncrement *> VContainer::DataIncrements() const
|
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
return DataVar<VIncrement>(VarType::Increment);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-07-29 14:19:11 +02:00
|
|
|
const QMap<QString, VLengthLine *> VContainer::DataLengthLines() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-15 19:27:30 +02:00
|
|
|
return DataVar<VLengthLine>(VarType::LineLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-15 19:27:30 +02:00
|
|
|
const QMap<QString, VSplineLength *> VContainer::DataLengthSplines() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-15 19:27:30 +02:00
|
|
|
return DataVar<VSplineLength>(VarType::SplineLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-15 19:27:30 +02:00
|
|
|
const QMap<QString, VArcLength *> VContainer::DataLengthArcs() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-15 19:27:30 +02:00
|
|
|
return DataVar<VArcLength>(VarType::ArcLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-11 16:41:17 +02:00
|
|
|
const QMap<QString, VLineAngle *> VContainer::DataAngleLines() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
return DataVar<VLineAngle>(VarType::LineAngle);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2014-07-30 11:51:22 +02:00
|
|
|
* @brief VariableExist check if exist variable this same name.
|
2014-07-29 13:28:18 +02:00
|
|
|
* @param name name of row
|
|
|
|
* @return true if contains
|
|
|
|
*/
|
2014-07-30 11:51:22 +02:00
|
|
|
bool VContainer::VariableExist(const QString &name)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
|
|
|
return variables.contains(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::CopyGObject(const VContainer &data, const quint32 &id)
|
|
|
|
{
|
|
|
|
T *obj = new T(*data.GeometricObject<const T *>(id));
|
|
|
|
UpdateGObject(id, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::CopyVar(const VContainer &data, const QString &name)
|
|
|
|
{
|
|
|
|
T *var = new T(*data.GetVariable<T*>(name));
|
|
|
|
AddVariable(name, var);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2014-07-29 14:19:11 +02:00
|
|
|
const QMap<QString, T *> VContainer::DataVar(const VarType &type) const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
|
|
|
QHashIterator<QString, VInternalVariable*> i(variables);
|
|
|
|
QMap<QString, T*> map;
|
|
|
|
//Sorting QHash by id
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
if(i.value()->GetType() == type)
|
|
|
|
{
|
|
|
|
T *var = GetVariable<T *>(i.key());
|
|
|
|
map.insert(qApp->VarToUser(i.key()), var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return map;
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|