2019-08-29 14:01:27 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file testpath.h
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 28 8, 2019
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2019 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2019-08-29 14:01:27 +02:00
|
|
|
**
|
|
|
|
** 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 TESTPATH_H
|
|
|
|
#define TESTPATH_H
|
|
|
|
|
2019-09-01 11:58:54 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QJsonDocument>
|
2021-03-30 15:20:38 +02:00
|
|
|
#include <QJsonArray>
|
2019-09-01 11:58:54 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QTextStream>
|
2023-02-14 13:52:48 +01:00
|
|
|
#include <QtCore/qcontainerfwd.h>
|
2019-09-01 11:58:54 +02:00
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
class QPointF;
|
2019-09-01 11:58:54 +02:00
|
|
|
class VSAPoint;
|
2021-03-30 15:20:38 +02:00
|
|
|
class VRawSAPoint;
|
2019-08-29 14:01:27 +02:00
|
|
|
|
|
|
|
#if !defined(V_NO_ASSERT)
|
2023-05-03 13:07:02 +02:00
|
|
|
auto PointToJson(const QPointF &point) -> QJsonObject;
|
2019-08-29 14:01:27 +02:00
|
|
|
void VectorToJson(const QVector<QPointF> &points, QJsonObject &json);
|
2021-03-30 15:20:38 +02:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void VectorToJson(const QVector<T> &points, QJsonObject &json);
|
2019-09-01 11:58:54 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
void DumpVector(const QVector<T> &points, const QString &templateName=QString())
|
|
|
|
{
|
|
|
|
QTemporaryFile temp; // Go to tmp folder to find dump
|
|
|
|
temp.setAutoRemove(false); // Remove dump manually
|
|
|
|
|
|
|
|
if (not templateName.isEmpty())
|
|
|
|
{
|
|
|
|
temp.setFileTemplate(QDir::tempPath() + QDir::separator() + templateName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (temp.open())
|
|
|
|
{
|
2021-02-17 18:20:25 +01:00
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
|
|
// On Linux, QTemporaryFile will attempt to create unnamed temporary
|
|
|
|
// files. If that succeeds, open() will return true but exists() will be
|
|
|
|
// false. If you call fileName() or any function that calls it,
|
|
|
|
// QTemporaryFile will give the file a name, so most applications will
|
|
|
|
// not see a difference.
|
|
|
|
temp.fileName(); // call to create a file on disk
|
|
|
|
#endif
|
|
|
|
#endif
|
2019-09-01 11:58:54 +02:00
|
|
|
QJsonObject vectorObject;
|
|
|
|
VectorToJson(points, vectorObject);
|
|
|
|
QJsonDocument vector(vectorObject);
|
|
|
|
|
|
|
|
QTextStream out(&temp);
|
|
|
|
out << vector.toJson();
|
|
|
|
out.flush();
|
|
|
|
}
|
|
|
|
}
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2021-03-30 15:20:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
void VectorToJson(const QVector<T> &points, QJsonObject &json)
|
|
|
|
{
|
|
|
|
QJsonArray pointsArray;
|
|
|
|
for (auto point: points)
|
|
|
|
{
|
|
|
|
pointsArray.append(point.toJson());
|
|
|
|
}
|
|
|
|
json[QLatin1String("vector")] = pointsArray;
|
|
|
|
}
|
|
|
|
#endif // !defined(V_NO_ASSERT)
|
2019-08-29 14:01:27 +02:00
|
|
|
#endif // TESTPATH_H
|