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.h
|
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
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/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
|
|
|
#ifndef VCONTAINER_H
|
|
|
|
#define VCONTAINER_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QSharedData>
|
|
|
|
#include <QSharedDataPointer>
|
2023-06-24 08:33:01 +02:00
|
|
|
#include <QSharedPointer>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTypeInfo>
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <new>
|
|
|
|
|
2015-06-12 10:55:44 +02:00
|
|
|
#include "../ifc/exception/vexceptionbadid.h"
|
2016-04-01 23:15:04 +02:00
|
|
|
#include "../vgeometry/vabstractcubicbezierpath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
2023-06-24 08:33:01 +02:00
|
|
|
#include "../vmisc/def.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "variables/vinternalvariable.h"
|
2016-11-08 11:52:07 +01:00
|
|
|
#include "vpiece.h"
|
2016-11-24 20:30:26 +01:00
|
|
|
#include "vpiecepath.h"
|
2015-10-22 11:28:17 +02:00
|
|
|
#include "vtranslatevars.h"
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2016-12-17 02:40:17 +01:00
|
|
|
class VEllipticalArc;
|
2022-11-10 10:30:08 +01:00
|
|
|
class VMeasurement;
|
|
|
|
class VIncrement;
|
|
|
|
class VLengthLine;
|
|
|
|
class VCurveLength;
|
|
|
|
class VCurveCLength;
|
|
|
|
class VLineAngle;
|
|
|
|
class VArcRadius;
|
|
|
|
class VCurveAngle;
|
|
|
|
class VPieceArea;
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
|
|
|
QT_WARNING_DISABLE_INTEL(2021)
|
2017-05-30 17:44:16 +02:00
|
|
|
QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
|
2014-08-23 08:18:07 +02:00
|
|
|
|
2021-09-25 10:43:05 +02:00
|
|
|
class VContainerData final : public QSharedData //-V690
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
public:
|
2023-07-13 16:49:20 +02:00
|
|
|
VContainerData(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace);
|
|
|
|
VContainerData(const VContainerData &data) = default;
|
2014-09-11 18:52:02 +02:00
|
|
|
virtual ~VContainerData();
|
2014-08-21 14:44:40 +02:00
|
|
|
|
2023-07-13 16:49:20 +02:00
|
|
|
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
|
|
|
|
QHash<quint32, QSharedPointer<VGObject>> calculationObjects{};
|
|
|
|
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
|
|
|
|
QSharedPointer<QHash<quint32, QSharedPointer<VGObject>>> modelingObjects{
|
|
|
|
QSharedPointer<QHash<quint32, QSharedPointer<VGObject>>>::create()};
|
2014-08-21 14:44:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief variables container for measurements, increments, lines lengths, lines angles, arcs lengths, curve lengths
|
|
|
|
*/
|
2023-07-13 16:49:20 +02:00
|
|
|
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
|
|
|
|
QHash<QString, QSharedPointer<VInternalVariable>> variables{};
|
2017-01-21 18:12:57 +01:00
|
|
|
|
2023-07-13 16:49:20 +02:00
|
|
|
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
|
|
|
|
QSharedPointer<QHash<quint32, VPiece>> pieces{QSharedPointer<QHash<quint32, VPiece>>::create()};
|
|
|
|
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
|
|
|
|
QSharedPointer<QHash<quint32, VPiecePath>> piecePaths{QSharedPointer<QHash<quint32, VPiecePath>>::create()};
|
2015-06-11 14:40:43 +02:00
|
|
|
|
2023-07-13 16:49:20 +02:00
|
|
|
const VTranslateVars *trVars; // NOLINT(misc-non-private-member-variables-in-classes)
|
|
|
|
const Unit *patternUnit; // NOLINT(misc-non-private-member-variables-in-classes)
|
2015-10-31 13:56:28 +01:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
/** @brief nspace namespace for static variables */
|
2023-07-13 16:49:20 +02:00
|
|
|
QString nspace; // NOLINT(misc-non-private-member-variables-in-classes)
|
2018-09-18 15:38:16 +02:00
|
|
|
|
2015-10-31 13:56:28 +01:00
|
|
|
private:
|
2023-05-02 16:38:30 +02:00
|
|
|
Q_DISABLE_ASSIGN_MOVE(VContainerData) // NOLINT
|
2014-08-21 14:44:40 +02:00
|
|
|
};
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2014-08-23 08:18:07 +02:00
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
/**
|
2013-10-07 17:34:14 +02:00
|
|
|
* @brief The VContainer class container of all variables.
|
2013-08-05 10:37:56 +02:00
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
class VContainer
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(VContainer) // NOLINT
|
2023-06-24 08:33:01 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
public:
|
2018-09-18 15:38:16 +02:00
|
|
|
VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace);
|
2014-05-07 18:55:57 +02:00
|
|
|
VContainer(const VContainer &data);
|
|
|
|
~VContainer();
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
friend class VContainerData;
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto operator=(const VContainer &data) -> VContainer &;
|
2017-04-19 12:27:17 +02:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
2023-07-13 16:49:20 +02:00
|
|
|
VContainer(VContainer &&data) noexcept;
|
|
|
|
auto operator=(VContainer &&data) noexcept -> VContainer &;
|
2017-04-19 12:27:17 +02:00
|
|
|
#endif
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto UniqueNamespace() -> QString;
|
|
|
|
|
|
|
|
template <typename T> auto GeometricObject(const quint32 &id) const -> const QSharedPointer<T>;
|
|
|
|
auto GetGObject(quint32 id) const -> const QSharedPointer<VGObject>;
|
|
|
|
static auto GetFakeGObject(quint32 id) -> const QSharedPointer<VGObject>;
|
|
|
|
auto GetPiece(quint32 id) const -> VPiece;
|
|
|
|
auto GetPiecePath(quint32 id) const -> VPiecePath;
|
|
|
|
auto GetPieceForPiecePath(quint32 id) const -> quint32;
|
|
|
|
template <typename T> auto GetVariable(const QString &name) const -> QSharedPointer<T>;
|
|
|
|
auto getId() const -> quint32;
|
|
|
|
auto getNextId() const -> quint32;
|
2023-06-24 08:33:01 +02:00
|
|
|
void UpdateId(quint32 newId) const;
|
|
|
|
static void UpdateId(quint32 newId, const QString &nspace);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2023-06-24 08:33:01 +02:00
|
|
|
void RegisterUniqueName(VGObject *obj) const;
|
|
|
|
void RegisterUniqueName(const QSharedPointer<VGObject> &obj) const;
|
2020-11-04 17:14:21 +01:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto AddGObject(VGObject *obj) -> quint32;
|
|
|
|
auto AddGObject(const QSharedPointer<VGObject> &obj) -> quint32;
|
|
|
|
auto AddPiece(const VPiece &detail) -> quint32;
|
|
|
|
auto AddPiecePath(const VPiecePath &path) -> quint32;
|
2023-06-24 08:33:01 +02:00
|
|
|
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId);
|
|
|
|
void AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32 &id, const quint32 &parentId = NULL_ID);
|
|
|
|
void AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId = NULL_ID);
|
|
|
|
void AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierPath> &curve, const quint32 &id,
|
|
|
|
quint32 parentId = NULL_ID);
|
|
|
|
|
|
|
|
template <typename T> void AddUniqueVariable(T *var);
|
|
|
|
template <typename T> void AddUniqueVariable(const QSharedPointer<T> &var);
|
|
|
|
template <typename T> void AddVariable(T *var);
|
|
|
|
template <typename T> void AddVariable(const QSharedPointer<T> &var);
|
|
|
|
void RemoveVariable(const QString &name);
|
|
|
|
void RemovePiece(quint32 id);
|
|
|
|
|
|
|
|
template <class T> void UpdateGObject(quint32 id, T *obj);
|
|
|
|
template <class T> void UpdateGObject(quint32 id, const QSharedPointer<T> &obj);
|
|
|
|
void UpdatePiece(quint32 id, const VPiece &detail);
|
|
|
|
void UpdatePiecePath(quint32 id, const VPiecePath &path);
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
void ClearForFullParse();
|
|
|
|
void ClearGObjects();
|
|
|
|
void ClearCalculationGObjects();
|
|
|
|
void ClearVariables(const VarType &type = VarType::Unknown);
|
|
|
|
void ClearVariables(const QVector<VarType> &types);
|
|
|
|
void ClearUniqueNames() const;
|
|
|
|
void ClearUniqueIncrementNames() const;
|
|
|
|
void ClearExceptUniqueIncrementNames() const;
|
|
|
|
|
|
|
|
void RemoveIncrement(const QString &name);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2022-11-10 10:30:08 +01:00
|
|
|
void FillPiecesAreas(Unit unit);
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto CalculationGObjects() const -> const QHash<quint32, QSharedPointer<VGObject>> *;
|
|
|
|
auto DataPieces() const -> const QHash<quint32, VPiece> *;
|
|
|
|
auto DataVariables() const -> const QHash<QString, QSharedPointer<VInternalVariable>> *;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto DataMeasurements() const -> const QMap<QString, QSharedPointer<VMeasurement>>;
|
|
|
|
auto DataMeasurementsWithSeparators() const -> const QMap<QString, QSharedPointer<VMeasurement>>;
|
|
|
|
auto DataIncrements() const -> const QMap<QString, QSharedPointer<VIncrement>>;
|
|
|
|
auto DataIncrementsWithSeparators() const -> const QMap<QString, QSharedPointer<VIncrement>>;
|
|
|
|
auto DataLengthLines() const -> const QMap<QString, QSharedPointer<VLengthLine>>;
|
|
|
|
auto DataLengthCurves() const -> const QMap<QString, QSharedPointer<VCurveLength>>;
|
|
|
|
auto DataCurvesCLength() const -> const QMap<QString, QSharedPointer<VCurveCLength>>;
|
|
|
|
auto DataAngleLines() const -> const QMap<QString, QSharedPointer<VLineAngle>>;
|
|
|
|
auto DataRadiusesArcs() const -> const QMap<QString, QSharedPointer<VArcRadius>>;
|
|
|
|
auto DataAnglesCurves() const -> const QMap<QString, QSharedPointer<VCurveAngle>>;
|
|
|
|
auto DataPieceArea() const -> const QMap<QString, QSharedPointer<VPieceArea>>;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto IsUnique(const QString &name) const -> bool;
|
|
|
|
static auto IsUnique(const QString &name, const QString &nspace) -> bool;
|
2018-09-18 15:38:16 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto AllUniqueNames() const -> QStringList;
|
|
|
|
static auto AllUniqueNames(const QString &nspace) -> QStringList;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto GetPatternUnit() const -> const Unit *;
|
|
|
|
auto GetTrVars() const -> const VTranslateVars *;
|
2015-06-11 19:36:17 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
private:
|
2013-11-18 17:37:17 +01:00
|
|
|
/**
|
2014-01-07 11:46:23 +01:00
|
|
|
* @brief _id current id. New object will have value +1. For empty class equal 0.
|
2013-11-18 17:37:17 +01:00
|
|
|
*/
|
2018-09-18 15:38:16 +02:00
|
|
|
static QMap<QString, quint32> _id;
|
|
|
|
static QMap<QString, QSet<QString>> uniqueNames;
|
|
|
|
static QMap<QString, quint32> copyCounter;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedDataPointer<VContainerData> d;
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
void AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId = NULL_ID);
|
|
|
|
|
2023-07-13 16:49:20 +02:00
|
|
|
template <typename T> void AddVariable(const QSharedPointer<T> &var, const QString &name);
|
2020-11-04 09:58:57 +01:00
|
|
|
|
2023-06-24 08:33:35 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
template <class T> auto qHash(const QSharedPointer<T> &p, uint seed = 0) -> uint;
|
|
|
|
#else
|
|
|
|
template <class T> auto qHash(const QSharedPointer<T> &p, size_t seed = 0) -> size_t;
|
|
|
|
#endif
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void UpdateObject(const quint32 &id, const QSharedPointer<T> &point);
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
template <typename T> auto DataVar(const VarType &type) const -> const QMap<QString, QSharedPointer<T>>;
|
2018-09-18 15:38:16 +02:00
|
|
|
|
|
|
|
static void ClearNamespace(const QString &nspace);
|
2014-07-29 13:28:18 +02:00
|
|
|
};
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE); // NOLINT
|
2015-06-04 15:58:38 +02:00
|
|
|
|
|
|
|
/*
|
2023-06-24 08:33:01 +02:00
|
|
|
* Defintion of templated member functions of VContainer
|
|
|
|
*/
|
2015-06-04 15:58:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
template <typename T> auto VContainer::GeometricObject(const quint32 &id) const -> const QSharedPointer<T>
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2017-09-16 16:25:14 +02:00
|
|
|
if (id == NULL_ID)
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
|
2017-10-26 11:54:08 +02:00
|
|
|
QSharedPointer<VGObject> gObj;
|
|
|
|
if (d->calculationObjects.contains(id))
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
gObj = d->calculationObjects.value(id);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
else if (d->modelingObjects->contains(id))
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
gObj = d->modelingObjects->value(id);
|
2017-01-17 12:49:21 +01:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
else
|
2017-01-17 12:49:21 +01:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
2017-01-17 12:49:21 +01:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
|
|
|
|
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(gObj);
|
|
|
|
SCASSERT(obj.isNull() == false)
|
|
|
|
return obj;
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2023-06-24 08:33:01 +02:00
|
|
|
* @brief GetVariable return varible by name
|
|
|
|
* @param name variable's name
|
|
|
|
* @return variable
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
template <typename T> auto VContainer::GetVariable(const QString &name) const -> QSharedPointer<T>
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2023-06-24 08:33:01 +02:00
|
|
|
SCASSERT(name.isEmpty() == false)
|
2015-06-04 15:58:38 +02:00
|
|
|
if (d->variables.contains(name))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QSharedPointer<T> value = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(value.isNull() == false)
|
2015-06-04 15:58:38 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc &)
|
|
|
|
{
|
2023-05-08 16:50:58 +02:00
|
|
|
throw VExceptionBadId(QCoreApplication::translate("VContainer", "Can't cast object"), name);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-08 16:50:58 +02:00
|
|
|
throw VExceptionBadId(QCoreApplication::translate("VContainer", "Can't find object"), name);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 14:14:05 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void VContainer::AddUniqueVariable(T *var)
|
2020-01-09 14:14:05 +01:00
|
|
|
{
|
|
|
|
AddUniqueVariable(QSharedPointer<T>(var));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void VContainer::AddUniqueVariable(const QSharedPointer<T> &var)
|
2020-01-09 14:14:05 +01:00
|
|
|
{
|
|
|
|
AddVariable(var);
|
|
|
|
|
|
|
|
if (d->variables.contains(var->GetName()))
|
|
|
|
{
|
|
|
|
uniqueNames[d->nspace].insert(var->GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 15:58:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void VContainer::AddVariable(T *var)
|
2017-04-14 10:30:00 +02:00
|
|
|
{
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(QSharedPointer<T>(var));
|
2017-04-14 10:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void VContainer::AddVariable(const QSharedPointer<T> &var)
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2019-11-24 12:09:16 +01:00
|
|
|
SCASSERT(not var->GetName().isEmpty())
|
2020-11-04 09:58:57 +01:00
|
|
|
AddVariable(var, var->GetName());
|
|
|
|
|
|
|
|
if (not var->GetAlias().isEmpty())
|
|
|
|
{
|
|
|
|
AddVariable(var, var->GetAlias());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void VContainer::AddVariable(const QSharedPointer<T> &var, const QString &name)
|
2020-11-04 09:58:57 +01:00
|
|
|
{
|
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->variables.contains(name))
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
if (d->variables.value(name)->GetType() == var->GetType())
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
2017-10-24 18:50:16 +02:00
|
|
|
if (v.isNull())
|
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
throw VExceptionBadId(tr("Can't cast object."), name);
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
|
|
|
*v = *var;
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
else
|
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
d->variables.insert(name, var);
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:35 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
template <class T> auto VContainer::qHash(const QSharedPointer<T> &p, uint seed) -> uint
|
|
|
|
#else
|
|
|
|
template <class T> auto VContainer::qHash(const QSharedPointer<T> &p, size_t seed) -> size_t
|
|
|
|
#endif
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2023-06-24 08:33:35 +02:00
|
|
|
return qHash(p.data(), seed);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdateGObject update GObject by id
|
|
|
|
* @param id id of existing GObject
|
|
|
|
* @param obj object
|
|
|
|
*/
|
2023-06-24 08:33:01 +02:00
|
|
|
template <class T> void VContainer::UpdateGObject(quint32 id, T *obj)
|
2017-10-24 18:50:16 +02:00
|
|
|
{
|
|
|
|
SCASSERT(obj != nullptr)
|
|
|
|
UpdateGObject(id, QSharedPointer<T>(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-24 08:33:01 +02:00
|
|
|
template <class T> void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
|
2017-10-24 18:50:16 +02:00
|
|
|
{
|
|
|
|
SCASSERT(not obj.isNull())
|
|
|
|
UpdateObject(id, obj);
|
2020-11-04 17:14:21 +01:00
|
|
|
RegisterUniqueName(obj);
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdateObject update object in container
|
|
|
|
* @param id id of existing object
|
|
|
|
* @param point object
|
|
|
|
*/
|
2023-06-24 08:33:01 +02:00
|
|
|
template <typename T> void VContainer::UpdateObject(const quint32 &id, const QSharedPointer<T> &point)
|
2017-10-24 18:50:16 +02:00
|
|
|
{
|
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
|
|
|
SCASSERT(point.isNull() == false)
|
|
|
|
point->setId(id);
|
2017-10-26 11:54:08 +02:00
|
|
|
|
|
|
|
if (d->calculationObjects.contains(id) && point->getMode() == Draw::Calculation)
|
2017-10-24 18:50:16 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(d->calculationObjects.value(id));
|
2017-10-24 18:50:16 +02:00
|
|
|
if (obj.isNull())
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), id);
|
|
|
|
}
|
|
|
|
*obj = *point;
|
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
else if (d->modelingObjects->contains(id) && point->getMode() == Draw::Modeling)
|
|
|
|
{
|
|
|
|
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(d->modelingObjects->value(id));
|
|
|
|
if (obj.isNull())
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), id);
|
|
|
|
}
|
|
|
|
*obj = *point;
|
|
|
|
}
|
|
|
|
else if (point->getMode() == Draw::Calculation)
|
|
|
|
{
|
|
|
|
d->calculationObjects.insert(id, point);
|
|
|
|
}
|
|
|
|
else if (point->getMode() == Draw::Modeling)
|
|
|
|
{
|
|
|
|
d->modelingObjects->insert(id, point);
|
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
else
|
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
qWarning("Can't update an object with mode 'Layout'");
|
|
|
|
return;
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
|
2017-10-24 18:50:16 +02:00
|
|
|
UpdateId(id);
|
|
|
|
}
|
2013-07-13 12:51:31 +02:00
|
|
|
#endif // VCONTAINER_H
|