Refactoring.

Fix code style.
This commit is contained in:
Roman Telezhynskyi 2023-05-16 19:20:49 +03:00
parent 3ce8e6e5a7
commit 7320c1c5df
12 changed files with 877 additions and 773 deletions

View File

@ -27,11 +27,12 @@
*************************************************************************/ *************************************************************************/
#include "preferencesconfigurationpage.h" #include "preferencesconfigurationpage.h"
#include "ui_preferencesconfigurationpage.h"
#include "../../core/vapplication.h" #include "../../core/vapplication.h"
#include "../vpatterndb/pmsystems.h"
#include "../vmisc/vvalentinasettings.h"
#include "../vmisc/literals.h" #include "../vmisc/literals.h"
#include "../vmisc/vvalentinasettings.h"
#include "../vpatterndb/pmsystems.h"
#include "def.h"
#include "ui_preferencesconfigurationpage.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
@ -55,10 +56,8 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
ui->autoSaveCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetAutosaveState()); ui->autoSaveCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetAutosaveState());
InitLanguages(ui->langCombo); InitLanguages(ui->langCombo);
connect(ui->langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() connect(ui->langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
{ [this]() { m_langChanged = true; });
m_langChanged = true;
});
//-------------------- Decimal separator setup //-------------------- Decimal separator setup
ui->osOptionCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator()); ui->osOptionCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator());
@ -71,10 +70,8 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
ui->unitCombo->setCurrentIndex(indexUnit); ui->unitCombo->setCurrentIndex(indexUnit);
} }
connect(ui->unitCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() connect(ui->unitCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
{ [this]() { m_unitChanged = true; });
m_unitChanged = true;
});
//----------------------- Label language //----------------------- Label language
SetLabelComboBox(VApplication::LabelLanguages()); SetLabelComboBox(VApplication::LabelLanguages());
@ -84,18 +81,17 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
{ {
ui->labelCombo->setCurrentIndex(index); ui->labelCombo->setCurrentIndex(index);
} }
connect(ui->labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() connect(ui->labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
{ [this]() { m_labelLangChanged = true; });
m_labelLangChanged = true;
});
//---------------------- Pattern making system //---------------------- Pattern making system
ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing()); ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing());
connect(ui->systemCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() connect(ui->systemCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this]()
{ {
m_systemChanged = true; m_systemChanged = true;
QString text = VAbstractApplication::VApp()->TrVars() QString text =
->PMSystemAuthor(ui->systemCombo->currentData().toString()); VAbstractApplication::VApp()->TrVars()->PMSystemAuthor(ui->systemCombo->currentData().toString());
ui->systemAuthorValueLabel->setText(text); ui->systemAuthorValueLabel->setText(text);
ui->systemAuthorValueLabel->setToolTip(text); ui->systemAuthorValueLabel->setToolTip(text);
@ -111,7 +107,8 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
} }
//----------------------------- Pattern Editing //----------------------------- Pattern Editing
connect(ui->resetWarningsButton, &QPushButton::released, this, []() connect(ui->resetWarningsButton, &QPushButton::released, this,
[]()
{ {
VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings();
@ -181,7 +178,7 @@ auto PreferencesConfigurationPage::Apply() -> QStringList
QTimer *autoSaveTimer = VApplication::VApp()->getAutoSaveTimer(); QTimer *autoSaveTimer = VApplication::VApp()->getAutoSaveTimer();
SCASSERT(autoSaveTimer) SCASSERT(autoSaveTimer)
ui->autoSaveCheck->isChecked() ? autoSaveTimer->start(ui->autoTime->value()*60000) : autoSaveTimer->stop(); ui->autoSaveCheck->isChecked() ? autoSaveTimer->start(ui->autoTime->value() * 60000) : autoSaveTimer->stop();
settings->SetOsSeparator(ui->osOptionCheck->isChecked()); settings->SetOsSeparator(ui->osOptionCheck->isChecked());
settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked());

View File

@ -31,24 +31,23 @@
#include <QWidget> #include <QWidget>
#include "../vmisc/defglobal.h"
namespace Ui namespace Ui
{ {
class PreferencesConfigurationPage; class PreferencesConfigurationPage;
} }
class PreferencesConfigurationPage : public QWidget class PreferencesConfigurationPage : public QWidget
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public : explicit PreferencesConfigurationPage(QWidget *parent = nullptr);
explicit PreferencesConfigurationPage(QWidget *parent = nullptr);
~PreferencesConfigurationPage() override; ~PreferencesConfigurationPage() override;
auto Apply() -> QStringList; auto Apply() -> QStringList;
protected: protected:
void changeEvent(QEvent* event) override; void changeEvent(QEvent *event) override;
private: private:
// cppcheck-suppress unknownMacro // cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(PreferencesConfigurationPage) // NOLINT Q_DISABLE_COPY_MOVE(PreferencesConfigurationPage) // NOLINT

View File

@ -26,28 +26,29 @@
** **
*************************************************************************/ *************************************************************************/
#include <QApplication>
#include <QDate> #include <QDate>
#include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QFlags> // QFlags<Qt::Alignment>
#include <QFontMetrics> #include <QFontMetrics>
#include <QGlobalStatic>
#include <QLatin1String> #include <QLatin1String>
#include <QRegularExpression> #include <QRegularExpression>
#include <QApplication>
#include <QDebug>
#include <QFlags> // QFlags<Qt::Alignment>
#include <QtMath> #include <QtMath>
#include <QGlobalStatic> #include <QGlobalStatic>
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vabstractvalapplication.h"
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
# include "../vmisc/vdatastreamenum.h" #include "../vmisc/vdatastreamenum.h"
#endif #endif
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"
#include "../vpatterndb/variables/vmeasurement.h" #include "../vpatterndb/variables/vmeasurement.h"
#include "../vpatterndb/vcontainer.h"
#include "vtextmanager.h" #include "vtextmanager.h"
const quint32 TextLine::streamHeader = 0xA3881E49; // CRC-32Q string "TextLine" const quint32 TextLine::streamHeader = 0xA3881E49; // CRC-32Q string "TextLine"
@ -55,7 +56,7 @@ const quint16 TextLine::classVersion = 1;
// Friend functions // Friend functions
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto operator<<(QDataStream &dataStream, const TextLine &data) -> QDataStream& auto operator<<(QDataStream &dataStream, const TextLine &data) -> QDataStream &
{ {
dataStream << TextLine::streamHeader << TextLine::classVersion; dataStream << TextLine::streamHeader << TextLine::classVersion;
@ -72,7 +73,7 @@ auto operator<<(QDataStream &dataStream, const TextLine &data) -> QDataStream&
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto operator>>(QDataStream &dataStream, TextLine &data) -> QDataStream& auto operator>>(QDataStream &dataStream, TextLine &data) -> QDataStream &
{ {
quint32 actualStreamHeader = 0; quint32 actualStreamHeader = 0;
dataStream >> actualStreamHeader; dataStream >> actualStreamHeader;
@ -93,7 +94,8 @@ auto operator>>(QDataStream &dataStream, TextLine &data) -> QDataStream&
{ {
QString message = QCoreApplication::tr("TextLine compatibility error: actualClassVersion = %1 and " QString message = QCoreApplication::tr("TextLine compatibility error: actualClassVersion = %1 and "
"classVersion = %2") "classVersion = %2")
.arg(actualClassVersion).arg(TextLine::classVersion); .arg(actualClassVersion)
.arg(TextLine::classVersion);
throw VException(message); throw VException(message);
} }
@ -103,10 +105,10 @@ auto operator>>(QDataStream &dataStream, TextLine &data) -> QDataStream&
dataStream >> data.m_italic; dataStream >> data.m_italic;
dataStream >> data.m_eAlign; dataStream >> data.m_eAlign;
// if (actualClassVersion >= 2) // if (actualClassVersion >= 2)
// { // {
// } // }
return dataStream; return dataStream;
} }
@ -121,7 +123,7 @@ Q_GLOBAL_STATIC(QVector<TextLine>, m_patternLabelLines) // NOLINT
// Friend functions // Friend functions
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto operator<<(QDataStream &dataStream, const VTextManager &data) -> QDataStream& auto operator<<(QDataStream &dataStream, const VTextManager &data) -> QDataStream &
{ {
dataStream << VTextManager::streamHeader << VTextManager::classVersion; dataStream << VTextManager::streamHeader << VTextManager::classVersion;
@ -135,7 +137,7 @@ auto operator<<(QDataStream &dataStream, const VTextManager &data) -> QDataStrea
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto operator>>(QDataStream &dataStream, VTextManager &data) -> QDataStream& auto operator>>(QDataStream &dataStream, VTextManager &data) -> QDataStream &
{ {
quint32 actualStreamHeader = 0; quint32 actualStreamHeader = 0;
dataStream >> actualStreamHeader; dataStream >> actualStreamHeader;
@ -156,17 +158,18 @@ auto operator>>(QDataStream &dataStream, VTextManager &data) -> QDataStream&
{ {
QString message = QCoreApplication::tr("VTextManager compatibility error: actualClassVersion = %1 and " QString message = QCoreApplication::tr("VTextManager compatibility error: actualClassVersion = %1 and "
"classVersion = %2") "classVersion = %2")
.arg(actualClassVersion).arg(VTextManager::classVersion); .arg(actualClassVersion)
.arg(VTextManager::classVersion);
throw VException(message); throw VException(message);
} }
dataStream >> data.m_font; dataStream >> data.m_font;
dataStream >> data.m_liLines; dataStream >> data.m_liLines;
// if (actualClassVersion >= 2) // if (actualClassVersion >= 2)
// { // {
// } // }
return dataStream; return dataStream;
} }
@ -205,8 +208,8 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) ->
{ {
placeholders.insert(pl_customer, VAbstractValApplication::VApp()->GetCustomerName()); placeholders.insert(pl_customer, VAbstractValApplication::VApp()->GetCustomerName());
const QString birthDate = locale.toString(VAbstractValApplication::VApp()->GetCustomerBirthDate(), const QString birthDate =
doc->GetLabelDateFormat()); locale.toString(VAbstractValApplication::VApp()->GetCustomerBirthDate(), doc->GetLabelDateFormat());
placeholders.insert(pl_birthDate, birthDate); placeholders.insert(pl_birthDate, birthDate);
placeholders.insert(pl_email, VAbstractValApplication::VApp()->CustomerEmail()); placeholders.insert(pl_email, VAbstractValApplication::VApp()->CustomerEmail());
@ -256,7 +259,8 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) ->
} }
placeholders.insert(pl_mExt, VAbstractValApplication::VApp()->GetMeasurementsType() == MeasurementsType::Multisize placeholders.insert(pl_mExt, VAbstractValApplication::VApp()->GetMeasurementsType() == MeasurementsType::Multisize
? QStringLiteral("vst") : QStringLiteral("vit")); ? QStringLiteral("vst")
: QStringLiteral("vit"));
const QMap<int, QString> materials = doc->GetPatternMaterials(); const QMap<int, QString> materials = doc->GetPatternMaterials();
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i) for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
@ -273,7 +277,7 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) ->
} }
{ {
const QMap<QString, QSharedPointer<VMeasurement> > measurements = data->DataMeasurements(); const QMap<QString, QSharedPointer<VMeasurement>> measurements = data->DataMeasurements();
auto i = measurements.constBegin(); auto i = measurements.constBegin();
while (i != measurements.constEnd()) while (i != measurements.constEnd())
{ {
@ -290,7 +294,7 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) ->
placeholders.insert(pl_currentArea, QString()); placeholders.insert(pl_currentArea, QString());
placeholders.insert(pl_currentSeamLineArea, QString()); placeholders.insert(pl_currentSeamLineArea, QString());
for (int i=0; i < measurements.size(); ++i) for (int i = 0; i < measurements.size(); ++i)
{ {
const VFinalMeasurement &m = measurements.at(i); const VFinalMeasurement &m = measurements.at(i);
@ -304,9 +308,12 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) ->
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
const QString errorMsg = QObject::tr("Failed to prepare final measurement placeholder. Parser error at " const QString errorMsg = QObject::tr("Failed to prepare final measurement placeholder. Parser error at "
"line %1: %2.").arg(i+1).arg(e.GetMsg()); "line %1: %2.")
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : .arg(i + 1)
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; .arg(e.GetMsg());
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }
} }
@ -362,8 +369,9 @@ void InitPiecePlaceholders(QMap<QString, QString> &placeholders, const QString &
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg()); const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
try try
@ -375,8 +383,9 @@ void InitPiecePlaceholders(QMap<QString, QString> &placeholders, const QString &
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg()); const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }
@ -387,10 +396,11 @@ auto ReplacePlaceholders(const QMap<QString, QString> &placeholders, QString lin
auto TestDimension = [per, placeholders, line](const QString &placeholder, const QString &errorMsg) auto TestDimension = [per, placeholders, line](const QString &placeholder, const QString &errorMsg)
{ {
if (line.contains(per+placeholder+per) && placeholders.value(placeholder) == QChar('0')) if (line.contains(per + placeholder + per) && placeholders.value(placeholder) == QChar('0'))
{ {
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
}; };
@ -407,7 +417,7 @@ auto ReplacePlaceholders(const QMap<QString, QString> &placeholders, QString lin
auto i = placeholders.constBegin(); auto i = placeholders.constBegin();
while (i != placeholders.constEnd()) while (i != placeholders.constEnd())
{ {
line.replace(per+i.key()+per, i.value()); line.replace(per + i.key() + per, i.value());
++i; ++i;
} }
return line; return line;
@ -452,7 +462,7 @@ auto VTextManager::GetSpacing() const -> int
* @brief SetFont set the text base font * @brief SetFont set the text base font
* @param font text base font * @param font text base font
*/ */
void VTextManager::SetFont(const QFont& font) void VTextManager::SetFont(const QFont &font)
{ {
m_font = font; m_font = font;
} }
@ -462,7 +472,7 @@ void VTextManager::SetFont(const QFont& font)
* @brief GetFont returns the text base font * @brief GetFont returns the text base font
* @return text base font * @return text base font
*/ */
auto VTextManager::GetFont() const -> const QFont& auto VTextManager::GetFont() const -> const QFont &
{ {
return m_font; return m_font;
} }
@ -505,7 +515,7 @@ auto VTextManager::GetSourceLinesCount() const -> vsizetype
* @param i index of the requested line * @param i index of the requested line
* @return reference to the requested TextLine object * @return reference to the requested TextLine object
*/ */
auto VTextManager::GetSourceLine(vsizetype i) const -> const TextLine& auto VTextManager::GetSourceLine(vsizetype i) const -> const TextLine &
{ {
Q_ASSERT(i >= 0); Q_ASSERT(i >= 0);
Q_ASSERT(i < m_liLines.count()); Q_ASSERT(i < m_liLines.count());
@ -518,7 +528,7 @@ auto VTextManager::MaxLineWidth(int width) const -> int
int maxWidth = 0; int maxWidth = 0;
for (int i = 0; i < m_liLines.count(); ++i) for (int i = 0; i < m_liLines.count(); ++i)
{ {
const TextLine& tl = m_liLines.at(i); const TextLine &tl = m_liLines.at(i);
QFont fnt = m_font; QFont fnt = m_font;
fnt.setPixelSize(fnt.pixelSize() + tl.m_iFontSize); fnt.setPixelSize(fnt.pixelSize() + tl.m_iFontSize);
@ -551,8 +561,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
{ {
int iFS = 0; int iFS = 0;
if (GetSourceLinesCount() > 0) if (GetSourceLinesCount() > 0)
{//division by zero { // division by zero
iFS = 3*qFloor(fH/static_cast<int>(GetSourceLinesCount()))/4; iFS = 3 * qFloor(fH / static_cast<int>(GetSourceLinesCount())) / 4;
} }
if (iFS < MIN_FONT_SIZE) if (iFS < MIN_FONT_SIZE)
@ -567,7 +577,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
QFont fnt; QFont fnt;
for (vsizetype i = 0; i < GetSourceLinesCount(); ++i) for (vsizetype i = 0; i < GetSourceLinesCount(); ++i)
{ {
const TextLine& tl = GetSourceLine(i); const TextLine &tl = GetSourceLine(i);
fnt = m_font; fnt = m_font;
fnt.setPixelSize(iFS + tl.m_iFontSize); fnt.setPixelSize(iFS + tl.m_iFontSize);
fnt.setBold(tl.m_bold); fnt.setBold(tl.m_bold);
@ -593,8 +603,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
fnt.setPixelSize(iFS + maxLine.m_iFontSize); fnt.setPixelSize(iFS + maxLine.m_iFontSize);
QFontMetrics fm(fnt); QFontMetrics fm(fnt);
lineLength = TextWidth(fm, maxLine.m_qsText); lineLength = TextWidth(fm, maxLine.m_qsText);
} } while (lineLength > fW && iFS > MIN_FONT_SIZE);
while (lineLength > fW && iFS > MIN_FONT_SIZE);
} }
SetFontSize(iFS); SetFontSize(iFS);
} }
@ -605,7 +614,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
* @param qsName detail name * @param qsName detail name
* @param data reference to the detail data * @param data reference to the detail data
*/ */
void VTextManager::Update(const QString& qsName, const VPieceLabelData& data, const VContainer *pattern) void VTextManager::Update(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern)
{ {
m_liLines.clear(); m_liLines.clear();
@ -615,7 +624,7 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data, co
QVector<VLabelTemplateLine> lines = data.GetLabelTemplate(); QVector<VLabelTemplateLine> lines = data.GetLabelTemplate();
for (auto & line : lines) for (auto &line : lines)
{ {
line.line = ReplacePlaceholders(placeholders, line.line); line.line = ReplacePlaceholders(placeholders, line.line);
} }
@ -642,7 +651,7 @@ void VTextManager::Update(VAbstractPattern *pDoc, const VContainer *pattern)
const QMap<QString, QString> placeholders = PreparePlaceholders(pDoc, pattern); const QMap<QString, QString> placeholders = PreparePlaceholders(pDoc, pattern);
for (auto & line : lines) for (auto &line : lines)
{ {
line.line = ReplacePlaceholders(placeholders, line.line); line.line = ReplacePlaceholders(placeholders, line.line);
} }

View File

@ -33,9 +33,12 @@
#include <QColor> #include <QColor>
#include <QComboBox> #include <QComboBox>
#include <QCursor> #include <QCursor>
#include <QDesktopServices>
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
#include <QFileInfo> #include <QFileInfo>
#include <QGlobalStatic>
#include <QGraphicsItem>
#include <QGuiApplication> #include <QGuiApplication>
#include <QImage> #include <QImage>
#include <QLatin1Char> #include <QLatin1Char>
@ -44,19 +47,16 @@
#include <QMessageLogger> #include <QMessageLogger>
#include <QObject> #include <QObject>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache>
#include <QPrinterInfo> #include <QPrinterInfo>
#include <QProcess> #include <QProcess>
#include <QRgb> #include <QRgb>
#include <QtDebug>
#include <QPixmapCache>
#include <QGraphicsItem>
#include <QGlobalStatic>
#include <QDesktopServices>
#include <QUrl> #include <QUrl>
#include <QtDebug>
#include "vabstractapplication.h" #include "vabstractapplication.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
# include "vdatastreamenum.h" #include "vdatastreamenum.h"
#endif #endif
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "literals.h" #include "literals.h"
@ -95,27 +95,8 @@ void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int h
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto SupportedLocales() -> QStringList auto SupportedLocales() -> QStringList
{ {
return QStringList return QStringList{"uk_UA", "de_DE", "cs_CZ", "he_IL", "fr_FR", "it_IT", "nl_NL", "id_ID", "es_ES",
{ "fi_FI", "en_US", "en_CA", "en_IN", "ro_RO", "zh_CN", "pt_BR", "el_GR", "pl_PL"};
"uk_UA",
"de_DE",
"cs_CZ",
"he_IL",
"fr_FR",
"it_IT",
"nl_NL",
"id_ID",
"es_ES",
"fi_FI",
"en_US",
"en_CA",
"en_IN",
"ro_RO",
"zh_CN",
"pt_BR",
"el_GR",
"pl_PL"
};
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -224,12 +205,10 @@ auto darkenPixmap(const QPixmap &pixmap) -> QPixmap
void ShowInGraphicalShell(const QString &filePath) void ShowInGraphicalShell(const QString &filePath)
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QStringList args{ QStringList args{"-e", "tell application \"Finder\"",
"-e", "tell application \"Finder\"",
"-e", "activate", "-e", "activate",
"-e", "select POSIX file \""+filePath+"\"", "-e", "select POSIX file \"" + filePath + "\"",
"-e", "end tell" "-e", "end tell"};
};
QProcess::startDetached(QStringLiteral("osascript"), args); QProcess::startDetached(QStringLiteral("osascript"), args);
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
QProcess::startDetached(QStringLiteral("explorer"), QStringList{"/select", QDir::toNativeSeparators(filePath)}); QProcess::startDetached(QStringLiteral("explorer"), QStringList{"/select", QDir::toNativeSeparators(filePath)});
@ -238,7 +217,8 @@ void ShowInGraphicalShell(const QString &filePath)
QString command = QStringLiteral("dbus-send --reply-timeout=%1 --session --dest=org.freedesktop.FileManager1 " QString command = QStringLiteral("dbus-send --reply-timeout=%1 --session --dest=org.freedesktop.FileManager1 "
"--type=method_call /org/freedesktop/FileManager1 " "--type=method_call /org/freedesktop/FileManager1 "
"org.freedesktop.FileManager1.ShowItems array:string:\"%2\" string:\"\"") "org.freedesktop.FileManager1.ShowItems array:string:\"%2\" string:\"\"")
.arg(timeout).arg(QUrl::fromLocalFile(filePath).toString()); .arg(timeout)
.arg(QUrl::fromLocalFile(filePath).toString());
// Sending message through dbus will highlighting file // Sending message through dbus will highlighting file
QProcess dbus; QProcess dbus;
@ -331,7 +311,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, strCheckMark, (QLatin1String("checkMark
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto PassmarkLineTypeToString(PassmarkLineType type) -> QString auto PassmarkLineTypeToString(PassmarkLineType type) -> QString
{ {
switch(type) switch (type)
{ {
case PassmarkLineType::OneLine: case PassmarkLineType::OneLine:
return strOne; return strOne;
@ -364,7 +344,7 @@ auto StringToPassmarkLineType(const QString &value) -> PassmarkLineType
const QStringList values{strOne, strTwo, strThree, *strTMark, *strVMark, const QStringList values{strOne, strTwo, strThree, *strTMark, *strVMark,
*strVMark2, *strUMark, *strBoxMark, *strCheckMark}; *strVMark2, *strUMark, *strBoxMark, *strCheckMark};
switch(values.indexOf(value)) switch (values.indexOf(value))
{ {
case 0: // strOne case 0: // strOne
return PassmarkLineType::OneLine; return PassmarkLineType::OneLine;
@ -393,7 +373,7 @@ auto StringToPassmarkLineType(const QString &value) -> PassmarkLineType
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto PassmarkAngleTypeToString(PassmarkAngleType type) -> QString auto PassmarkAngleTypeToString(PassmarkAngleType type) -> QString
{ {
switch(type) switch (type)
{ {
case PassmarkAngleType::Straightforward: case PassmarkAngleType::Straightforward:
return strStraightforward; return strStraightforward;
@ -425,7 +405,7 @@ auto StringToPassmarkAngleType(const QString &value) -> PassmarkAngleType
strStraightforward, strBisector, strIntersection, strIntersectionOnlyLeft, strStraightforward, strBisector, strIntersection, strIntersectionOnlyLeft,
strIntersectionOnlyRight, strIntersection2, strIntersection2OnlyLeft, strIntersection2OnlyRight}; strIntersectionOnlyRight, strIntersection2, strIntersection2OnlyLeft, strIntersection2OnlyRight};
switch(values.indexOf(value)) switch (values.indexOf(value))
{ {
case 0: case 0:
return PassmarkAngleType::Straightforward; return PassmarkAngleType::Straightforward;
@ -449,20 +429,19 @@ auto StringToPassmarkAngleType(const QString &value) -> PassmarkAngleType
return PassmarkAngleType::Straightforward; return PassmarkAngleType::Straightforward;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto StrToUnits(const QString &unit) -> Unit auto StrToUnits(const QString &unit) -> Unit
{ {
const QStringList units{unitMM, unitCM, unitINCH, unitPX}; const QStringList units{unitMM, unitCM, unitINCH, unitPX};
switch (units.indexOf(unit)) switch (units.indexOf(unit))
{ {
case 0:// mm case 0: // mm
return Unit::Mm; return Unit::Mm;
case 2:// inch case 2: // inch
return Unit::Inch; return Unit::Inch;
case 3:// px case 3: // px
return Unit::Px; return Unit::Px;
case 1:// cm case 1: // cm
default: default:
return Unit::Cm; return Unit::Cm;
} }
@ -603,7 +582,8 @@ auto operator>>(QDataStream &in, CustomSARecord &record) -> QDataStream &
{ {
QString message = QCoreApplication::tr("CustomSARecord compatibility error: actualClassVersion = %1 and " QString message = QCoreApplication::tr("CustomSARecord compatibility error: actualClassVersion = %1 and "
"classVersion = %2") "classVersion = %2")
.arg(actualClassVersion).arg(CustomSARecord::classVersion); .arg(actualClassVersion)
.arg(CustomSARecord::classVersion);
throw VException(message); throw VException(message);
} }
@ -613,10 +593,10 @@ auto operator>>(QDataStream &in, CustomSARecord &record) -> QDataStream &
in >> record.reverse; in >> record.reverse;
in >> record.includeType; in >> record.includeType;
// if (actualClassVersion >= 2) // if (actualClassVersion >= 2)
// { // {
// } // }
return in; return in;
} }
@ -624,7 +604,7 @@ auto operator>>(QDataStream &in, CustomSARecord &record) -> QDataStream &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto IncrementTypeToString(IncrementType type) -> QString auto IncrementTypeToString(IncrementType type) -> QString
{ {
switch(type) switch (type)
{ {
case IncrementType::Increment: case IncrementType::Increment:
return strTypeIncrement; return strTypeIncrement;
@ -640,9 +620,9 @@ auto IncrementTypeToString(IncrementType type) -> QString
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto StringToIncrementType(const QString &value) -> IncrementType auto StringToIncrementType(const QString &value) -> IncrementType
{ {
const QStringList values { strTypeIncrement, strTypeSeparator }; const QStringList values{strTypeIncrement, strTypeSeparator};
switch(values.indexOf(value)) switch (values.indexOf(value))
{ {
case 0: case 0:
return IncrementType::Increment; return IncrementType::Increment;
@ -657,7 +637,7 @@ auto StringToIncrementType(const QString &value) -> IncrementType
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto MeasurementTypeToString(MeasurementType type) -> QString auto MeasurementTypeToString(MeasurementType type) -> QString
{ {
switch(type) switch (type)
{ {
case MeasurementType::Measurement: case MeasurementType::Measurement:
return strTypeMeasurement; return strTypeMeasurement;
@ -673,9 +653,9 @@ auto MeasurementTypeToString(MeasurementType type) -> QString
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto StringToMeasurementType(const QString &value) -> MeasurementType auto StringToMeasurementType(const QString &value) -> MeasurementType
{ {
const QStringList values { strTypeMeasurement, strTypeSeparator }; const QStringList values{strTypeMeasurement, strTypeSeparator};
switch(values.indexOf(value)) switch (values.indexOf(value))
{ {
case 0: case 0:
return MeasurementType::Measurement; return MeasurementType::Measurement;
@ -703,8 +683,7 @@ auto SplitFilePaths(const QString &path) -> QStringList
result.prepend(lastFileName); result.prepend(lastFileName);
subPath = fileInfo.path(); subPath = fileInfo.path();
} }
} } while (not lastFileName.isEmpty());
while(not lastFileName.isEmpty());
return result; return result;
} }

View File

@ -31,17 +31,17 @@
#include <QtGlobal> #include <QtGlobal>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# include <qt_windows.h> #include <qt_windows.h>
#endif /*Q_OS_WIN*/ #endif /*Q_OS_WIN*/
#include <qcompilerdetection.h> #include <QLineF>
#include <QMargins>
#include <QPrinter> #include <QPrinter>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <Qt> #include <Qt>
#include <csignal> #include <csignal>
#include <QMargins> #include <qcompilerdetection.h>
#include <QLineF>
#include "debugbreak.h" #include "debugbreak.h"
#include "defglobal.h" #include "defglobal.h"
@ -56,16 +56,16 @@ template <class T> class QSharedPointer;
// Backport of relaxed constexpr // Backport of relaxed constexpr
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#if defined Q_COMPILER_CONSTEXPR #if defined Q_COMPILER_CONSTEXPR
# if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304 #if defined(__cpp_constexpr) && __cpp_constexpr - 0 >= 201304
# define Q_DECL_RELAXED_CONSTEXPR constexpr #define Q_DECL_RELAXED_CONSTEXPR constexpr
# define Q_RELAXED_CONSTEXPR constexpr #define Q_RELAXED_CONSTEXPR constexpr
# else
# define Q_DECL_RELAXED_CONSTEXPR
# define Q_RELAXED_CONSTEXPR const
# endif
#else #else
# define Q_DECL_RELAXED_CONSTEXPR #define Q_DECL_RELAXED_CONSTEXPR
# define Q_RELAXED_CONSTEXPR const #define Q_RELAXED_CONSTEXPR const
#endif
#else
#define Q_DECL_RELAXED_CONSTEXPR
#define Q_RELAXED_CONSTEXPR const
#endif #endif
#endif #endif
@ -83,15 +83,63 @@ constexpr qreal maxCurveApproximationScale = 10.0;
constexpr int minLabelFontSize = 5; constexpr int minLabelFontSize = 5;
constexpr int maxLabelFontSize = 100; constexpr int maxLabelFontSize = 100;
enum class NodeDetail : qint8 { Contour, Modeling }; enum class NodeDetail : qint8
enum class SceneObject : qint8 { Point, Line, Spline, Arc, ElArc, SplinePath, Detail, Unknown }; {
enum class MeasurementsType : qint8 { Multisize, Individual, Unknown}; Contour,
enum class Unit : qint8 { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE}; Modeling
enum class Source : qint8 { FromGui, FromFile, FromTool }; };
enum class NodeUsage : bool {NotInUse = false, InUse = true}; enum class SceneObject : qint8
enum class SelectionType : bool {ByMousePress, ByMouseRelease}; {
enum class PageOrientation : bool {Portrait = true, Landscape = false}; Point,
enum class Draw : qint8 { Calculation, Modeling, Layout }; Line,
Spline,
Arc,
ElArc,
SplinePath,
Detail,
Unknown
};
enum class MeasurementsType : qint8
{
Multisize,
Individual,
Unknown
};
enum class Unit : qint8
{
Mm = 0,
Cm,
Inch,
Px,
LAST_UNIT_DO_NOT_USE
};
enum class Source : qint8
{
FromGui,
FromFile,
FromTool
};
enum class NodeUsage : bool
{
NotInUse = false,
InUse = true
};
enum class SelectionType : bool
{
ByMousePress,
ByMouseRelease
};
enum class PageOrientation : bool
{
Portrait = true,
Landscape = false
};
enum class Draw : qint8
{
Calculation,
Modeling,
Layout
};
enum class PieceNodeAngle : quint8 enum class PieceNodeAngle : quint8
{ {
@ -147,7 +195,13 @@ enum class PiecePathIncludeType : quint8
AsCustomSA = 1 AsCustomSA = 1
}; };
enum class PiecePathType : quint8 {PiecePath = 0, CustomSeamAllowance = 1, InternalPath = 2, Unknown = 3}; enum class PiecePathType : quint8
{
PiecePath = 0,
CustomSeamAllowance = 1,
InternalPath = 2,
Unknown = 3
};
typedef int ToolVisHolderType; typedef int ToolVisHolderType;
enum class Tool : ToolVisHolderType enum class Tool : ToolVisHolderType
@ -211,7 +265,7 @@ enum class Tool : ToolVisHolderType
BackgroundImageControls, BackgroundImageControls,
BackgroundPixmapImage, BackgroundPixmapImage,
BackgroundSVGImage, BackgroundSVGImage,
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used LAST_ONE_DO_NOT_USE // add new stuffs above this, this constant must be last and never used
}; };
enum class Vis : ToolVisHolderType enum class Vis : ToolVisHolderType
@ -270,30 +324,51 @@ enum class Vis : ToolVisHolderType
PieceItem, PieceItem,
TextGraphicsItem, TextGraphicsItem,
ScenePoint, ScenePoint,
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used LAST_ONE_DO_NOT_USE // add new stuffs above this, this constant must be last and never used
}; };
enum class Layout : ToolVisHolderType enum class Layout : ToolVisHolderType
{ {
GrainlineItem = static_cast<ToolVisHolderType>(Vis::LAST_ONE_DO_NOT_USE), GrainlineItem = static_cast<ToolVisHolderType>(Vis::LAST_ONE_DO_NOT_USE),
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used LAST_ONE_DO_NOT_USE // add new stuffs above this, this constant must be last and never used
}; };
enum class VarType : qint8 { Measurement, MeasurementSeparator, Increment, IncrementSeparator, LineLength, CurveLength, enum class VarType : qint8
CurveCLength, LineAngle, CurveAngle, ArcRadius, PieceExternalArea, PieceSeamLineArea, {
Unknown }; Measurement,
MeasurementSeparator,
Increment,
IncrementSeparator,
LineLength,
CurveLength,
CurveCLength,
LineAngle,
CurveAngle,
ArcRadius,
PieceExternalArea,
PieceSeamLineArea,
Unknown
};
enum class IncrementType : qint8 { Increment, Separator }; enum class IncrementType : qint8
{
Increment,
Separator
};
auto IncrementTypeToString(IncrementType type) -> QString; auto IncrementTypeToString(IncrementType type) -> QString;
auto StringToIncrementType(const QString &value) -> IncrementType; auto StringToIncrementType(const QString &value) -> IncrementType;
enum class MeasurementType : qint8 { Measurement, Separator }; enum class MeasurementType : qint8
{
Measurement,
Separator
};
auto MeasurementTypeToString(MeasurementType type) -> QString; auto MeasurementTypeToString(MeasurementType type) -> QString;
auto StringToMeasurementType(const QString &value) -> MeasurementType; auto StringToMeasurementType(const QString &value) -> MeasurementType;
enum class IMD: qint8 // Individual measurement dimension enum class IMD : qint8 // Individual measurement dimension
{ {
N, // None N, // None
X, // height X, // height
@ -328,46 +403,45 @@ enum class IMD: qint8 // Individual measurement dimension
#ifndef V_NO_ASSERT #ifndef V_NO_ASSERT
#define SCASSERT(cond) \ #define SCASSERT(cond) \
if (!(cond)) \ if (!(cond)) \
{ \ { \
qCritical("ASSERT: %s in %s (%s:%u)", \ qCritical("ASSERT: %s in %s (%s:%u)", #cond, Q_FUNC_INFO, __FILE__, __LINE__); \
#cond, Q_FUNC_INFO , __FILE__, __LINE__); \
debug_break(); \ debug_break(); \
abort(); \ abort(); \
} }
#else // define but disable this function if debugging is not set #else // define but disable this function if debugging is not set
#define SCASSERT(cond) qt_noop(); #define SCASSERT(cond) qt_noop();
#endif /* V_NO_ASSERT */ #endif /* V_NO_ASSERT */
#ifndef __has_cpp_attribute #ifndef __has_cpp_attribute
# define __has_cpp_attribute(x) 0 #define __has_cpp_attribute(x) 0
#endif #endif
#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
#ifndef QT_HAS_CPP_ATTRIBUTE #ifndef QT_HAS_CPP_ATTRIBUTE
#ifdef __has_cpp_attribute #ifdef __has_cpp_attribute
# define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) #define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
#else #else
# define QT_HAS_CPP_ATTRIBUTE(x) 0 #define QT_HAS_CPP_ATTRIBUTE(x) 0
#endif #endif
#endif // QT_HAS_CPP_ATTRIBUTE #endif // QT_HAS_CPP_ATTRIBUTE
#if defined(__cplusplus) #if defined(__cplusplus)
#if QT_HAS_CPP_ATTRIBUTE(clang::fallthrough) #if QT_HAS_CPP_ATTRIBUTE(clang::fallthrough)
# define Q_FALLTHROUGH() [[clang::fallthrough]] #define Q_FALLTHROUGH() [[clang::fallthrough]]
#elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough) #elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
# define Q_FALLTHROUGH() [[gnu::fallthrough]] #define Q_FALLTHROUGH() [[gnu::fallthrough]]
#elif QT_HAS_CPP_ATTRIBUTE(fallthrough) #elif QT_HAS_CPP_ATTRIBUTE(fallthrough)
# define Q_FALLTHROUGH() [[fallthrough]] #define Q_FALLTHROUGH() [[fallthrough]]
#endif #endif
#endif #endif
#ifndef Q_FALLTHROUGH #ifndef Q_FALLTHROUGH
# if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL) #if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL)
# define Q_FALLTHROUGH() __attribute__((fallthrough)) #define Q_FALLTHROUGH() __attribute__((fallthrough))
# else #else
# define Q_FALLTHROUGH() (void)0 #define Q_FALLTHROUGH() (void)0
#endif #endif
#endif // defined(__cplusplus) #endif // defined(__cplusplus)
#endif // QT_VERSION < QT_VERSION_CHECK(5, 8, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
@ -393,10 +467,9 @@ void InitHighDpiScaling(int argc, char *argv[]);
// We'll assume that it will be fixed in 5.12.11, 5.15.3, and 6.0.1. // We'll assume that it will be fixed in 5.12.11, 5.15.3, and 6.0.1.
// Feel free to add other versions if needed. // Feel free to add other versions if needed.
#define MACOS_LAYER_BACKING_AFFECTED \ #define MACOS_LAYER_BACKING_AFFECTED \
(QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) && QT_VERSION < QT_VERSION_CHECK(5, 12, 11) \ (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) && QT_VERSION < QT_VERSION_CHECK(5, 12, 11) || \
|| (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) && QT_VERSION < QT_VERSION_CHECK(5, 15, 3)) \ (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) && QT_VERSION < QT_VERSION_CHECK(5, 15, 3)) || \
|| (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 1)) \ (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 1)))
)
#if MACOS_LAYER_BACKING_AFFECTED #if MACOS_LAYER_BACKING_AFFECTED
#include <QOperatingSystemVersion> #include <QOperatingSystemVersion>
@ -408,7 +481,7 @@ void MacosEnableLayerBacking();
const int userMaterialPlaceholdersQuantity = 20; const int userMaterialPlaceholdersQuantity = 20;
auto QPixmapFromCache(const QString &pixmapPath) -> QPixmap; auto QPixmapFromCache(const QString &pixmapPath) -> QPixmap;
void SetItemOverrideCursor(QGraphicsItem *item, const QString & pixmapPath, int hotX = -1, int hotY = -1); void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX = -1, int hotY = -1);
template <typename T> constexpr inline auto MmToPixel(T val) noexcept -> T template <typename T> constexpr inline auto MmToPixel(T val) noexcept -> T
{ {
@ -442,9 +515,18 @@ Q_DECL_RELAXED_CONSTEXPR inline auto ToPixel(double val, const Unit &unit) -> do
return 0; return 0;
} }
template<typename T> constexpr inline auto PixelToInch(T pix) -> T {return pix / PrintDPI;} template <typename T> constexpr inline auto PixelToInch(T pix) -> T
template<typename T> constexpr inline auto PixelToMm(T pix) -> T {return PixelToInch(pix) * 25.4;} {
template<typename T> constexpr inline auto PixelToCm(T pix) -> T {return PixelToInch(pix) * 2.54;} return pix / PrintDPI;
}
template <typename T> constexpr inline auto PixelToMm(T pix) -> T
{
return PixelToInch(pix) * 25.4;
}
template <typename T> constexpr inline auto PixelToCm(T pix) -> T
{
return PixelToInch(pix) * 2.54;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Q_DECL_RELAXED_CONSTEXPR inline auto FromPixel(double pix, const Unit &unit) -> double Q_DECL_RELAXED_CONSTEXPR inline auto FromPixel(double pix, const Unit &unit) -> double
@ -465,9 +547,18 @@ Q_DECL_RELAXED_CONSTEXPR inline auto FromPixel(double pix, const Unit &unit) ->
return 0; return 0;
} }
template<typename T> constexpr inline auto Inch2ToPixel2(T val) -> T {return val * (PrintDPI * PrintDPI);} template <typename T> constexpr inline auto Inch2ToPixel2(T val) -> T
template<typename T> constexpr inline auto Mm2ToPixel2(T val) -> T {return Inch2ToPixel2(val * 0.001550031);} {
template<typename T> constexpr inline auto Cm2ToPixel2(T val) -> T {return Inch2ToPixel2(val * 0.15500031);} return val * (PrintDPI * PrintDPI);
}
template <typename T> constexpr inline auto Mm2ToPixel2(T val) -> T
{
return Inch2ToPixel2(val * 0.001550031);
}
template <typename T> constexpr inline auto Cm2ToPixel2(T val) -> T
{
return Inch2ToPixel2(val * 0.15500031);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Q_DECL_RELAXED_CONSTEXPR inline auto ToPixel2(double val, const Unit &unit) -> double Q_DECL_RELAXED_CONSTEXPR inline auto ToPixel2(double val, const Unit &unit) -> double
@ -488,9 +579,18 @@ Q_DECL_RELAXED_CONSTEXPR inline auto ToPixel2(double val, const Unit &unit) -> d
return 0; return 0;
} }
template<typename T> constexpr inline auto Pixel2ToInch2(T pix) -> T { return pix / (PrintDPI * PrintDPI);} template <typename T> constexpr inline auto Pixel2ToInch2(T pix) -> T
template<typename T> constexpr inline auto Pixel2ToMm2(T pix) -> T { return Pixel2ToInch2(pix) / 0.001550031;} {
template<typename T> constexpr inline auto Pixel2ToCm2(T pix) -> T { return Pixel2ToInch2(pix) / 0.15500031;} return pix / (PrintDPI * PrintDPI);
}
template <typename T> constexpr inline auto Pixel2ToMm2(T pix) -> T
{
return Pixel2ToInch2(pix) / 0.001550031;
}
template <typename T> constexpr inline auto Pixel2ToCm2(T pix) -> T
{
return Pixel2ToInch2(pix) / 0.15500031;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Q_DECL_RELAXED_CONSTEXPR inline auto FromPixel2(double pix, const Unit &unit) -> double Q_DECL_RELAXED_CONSTEXPR inline auto FromPixel2(double pix, const Unit &unit) -> double
@ -587,8 +687,8 @@ Q_DECL_RELAXED_CONSTEXPR inline auto UnitConvertor(qreal value, const Unit &from
* @brief UnitConvertor Converts the values of the given margin from given unit to the new unit. * @brief UnitConvertor Converts the values of the given margin from given unit to the new unit.
* returns a new instand of QMarginsF. * returns a new instand of QMarginsF.
*/ */
Q_DECL_RELAXED_CONSTEXPR inline auto UnitConvertor(const QMarginsF &margins, const Unit &from, Q_DECL_RELAXED_CONSTEXPR inline auto UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to)
const Unit &to) -> QMarginsF -> QMarginsF
{ {
const qreal left = UnitConvertor(margins.left(), from, to); const qreal left = UnitConvertor(margins.left(), from, to);
const qreal top = UnitConvertor(margins.top(), from, to); const qreal top = UnitConvertor(margins.top(), from, to);
@ -617,11 +717,11 @@ void ShowInGraphicalShell(const QString &filePath);
Q_REQUIRED_RESULT Q_DECL_RELAXED_CONSTEXPR static inline auto VFuzzyComparePossibleNulls(double p1, double p2) -> bool; Q_REQUIRED_RESULT Q_DECL_RELAXED_CONSTEXPR static inline auto VFuzzyComparePossibleNulls(double p1, double p2) -> bool;
Q_DECL_RELAXED_CONSTEXPR static inline auto VFuzzyComparePossibleNulls(double p1, double p2) -> bool Q_DECL_RELAXED_CONSTEXPR static inline auto VFuzzyComparePossibleNulls(double p1, double p2) -> bool
{ {
if(qFuzzyIsNull(p1)) if (qFuzzyIsNull(p1))
{ {
return qFuzzyIsNull(p2); return qFuzzyIsNull(p2);
} }
else if(qFuzzyIsNull(p2)) else if (qFuzzyIsNull(p2))
{ {
return false; return false;
} }
@ -642,7 +742,8 @@ struct CustomSARecord
endPoint(0), endPoint(0),
reverse(false), reverse(false),
includeType(PiecePathIncludeType::AsCustomSA) includeType(PiecePathIncludeType::AsCustomSA)
{} {
}
friend auto operator<<(QDataStream &out, const CustomSARecord &record) -> QDataStream &; friend auto operator<<(QDataStream &out, const CustomSARecord &record) -> QDataStream &;
friend auto operator>>(QDataStream &in, CustomSARecord &record) -> QDataStream &; friend auto operator>>(QDataStream &in, CustomSARecord &record) -> QDataStream &;
@ -672,28 +773,27 @@ Q_DECLARE_TYPEINFO(CustomSARecord, Q_MOVABLE_TYPE); // NOLINT
** this file shall be copyright (C) 2006-2008 by Adam Higerd. ** this file shall be copyright (C) 2006-2008 by Adam Higerd.
****************************************************************************/ ****************************************************************************/
#define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d; #define QXT_DECLARE_PRIVATE(PUB) \
friend class PUB##Private; \
QxtPrivateInterface<PUB, PUB##Private> qxt_d;
#define QXT_DECLARE_PUBLIC(PUB) friend class PUB; #define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
#define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this); #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
#define QXT_D(PUB) PUB##Private& d = qxt_d() #define QXT_D(PUB) PUB##Private &d = qxt_d()
#define QXT_P(PUB) PUB& p = qxt_p() #define QXT_P(PUB) PUB &p = qxt_p()
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wsuggest-final-types") QT_WARNING_DISABLE_GCC("-Wsuggest-final-types")
QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods") QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
template <typename PUB> template <typename PUB> class QxtPrivate
class QxtPrivate
{ {
public: public:
QxtPrivate(): qxt_p_ptr(nullptr) QxtPrivate()
{} : qxt_p_ptr(nullptr)
virtual ~QxtPrivate()
{}
inline void QXT_setPublic(PUB* pub)
{ {
qxt_p_ptr = pub;
} }
virtual ~QxtPrivate() {}
inline void QXT_setPublic(PUB *pub) { qxt_p_ptr = pub; }
protected: protected:
inline auto qxt_p() -> PUB & { return *qxt_p_ptr; } inline auto qxt_p() -> PUB & { return *qxt_p_ptr; }
@ -703,28 +803,24 @@ protected:
private: private:
Q_DISABLE_COPY_MOVE(QxtPrivate) // NOLINT Q_DISABLE_COPY_MOVE(QxtPrivate) // NOLINT
PUB* qxt_p_ptr; PUB *qxt_p_ptr;
}; };
// cppcheck-suppress unknownMacro // cppcheck-suppress unknownMacro
QT_WARNING_POP QT_WARNING_POP
template <typename PUB, typename PVT> template <typename PUB, typename PVT> class QxtPrivateInterface
class QxtPrivateInterface
{ {
friend class QxtPrivate<PUB>; friend class QxtPrivate<PUB>;
public:
QxtPrivateInterface() : pvt(new PVT)
{}
~QxtPrivateInterface()
{
delete pvt;
}
inline void setPublic(PUB* pub) public:
QxtPrivateInterface()
: pvt(new PVT)
{ {
pvt->QXT_setPublic(pub);
} }
~QxtPrivateInterface() { delete pvt; }
inline void setPublic(PUB *pub) { pvt->QXT_setPublic(pub); }
inline auto operator()() -> PVT & { return *static_cast<PVT *>(pvt); } inline auto operator()() -> PVT & { return *static_cast<PVT *>(pvt); }
inline auto operator()() const -> const PVT & { return *static_cast<PVT *>(pvt); } inline auto operator()() const -> const PVT & { return *static_cast<PVT *>(pvt); }
inline auto operator->() -> PVT * { return static_cast<PVT *>(pvt); } inline auto operator->() -> PVT * { return static_cast<PVT *>(pvt); }
@ -732,7 +828,7 @@ public:
private: private:
Q_DISABLE_COPY_MOVE(QxtPrivateInterface) // NOLINT Q_DISABLE_COPY_MOVE(QxtPrivateInterface) // NOLINT
QxtPrivate<PUB>* pvt; QxtPrivate<PUB> *pvt;
}; };
#endif // DEF_H #endif // DEF_H

View File

@ -29,12 +29,14 @@
#include "customevents.h" #include "customevents.h"
#include "vvalentinasettings.h" #include "vvalentinasettings.h"
#include <QTranslator>
#include <QWidget> #include <QWidget>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractValApplication::VAbstractValApplication(int &argc, char **argv) VAbstractValApplication::VAbstractValApplication(int &argc, char **argv)
: VAbstractApplication(argc, argv) : VAbstractApplication(argc, argv)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstractValApplication::toPixel(double val) const -> double auto VAbstractValApplication::toPixel(double val) const -> double
@ -71,11 +73,12 @@ void VAbstractValApplication::OpenSettings()
auto VAbstractValApplication::ValentinaSettings() -> VValentinaSettings * auto VAbstractValApplication::ValentinaSettings() -> VValentinaSettings *
{ {
SCASSERT(settings != nullptr) SCASSERT(settings != nullptr)
return qobject_cast<VValentinaSettings *>(settings); return qobject_cast<VValentinaSettings *>(settings);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstractValApplication::VApp() -> VAbstractValApplication * auto VAbstractValApplication::VApp() -> VAbstractValApplication *
{ {
return qobject_cast<VAbstractValApplication*>(QCoreApplication::instance()); return qobject_cast<VAbstractValApplication *>(QCoreApplication::instance());
} }

View File

@ -32,18 +32,19 @@
#include <QDate> #include <QDate>
class VAbstractValApplication;// use in define class VAbstractValApplication; // use in define
class VAbstractPattern; class VAbstractPattern;
class VMainGraphicsView; class VMainGraphicsView;
class QGraphicsScene; class QGraphicsScene;
class VValentinaSettings; class VValentinaSettings;
class QTranslator;
class VAbstractValApplication : public VAbstractApplication class VAbstractValApplication : public VAbstractApplication
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public:
VAbstractValApplication(int &argc, char **argv); public : VAbstractValApplication(int &argc, char **argv);
virtual ~VAbstractValApplication() =default; virtual ~VAbstractValApplication() = default;
auto GetCustomerName() const -> QString; auto GetCustomerName() const -> QString;
void SetCustomerName(const QString &name); void SetCustomerName(const QString &name);

View File

@ -29,16 +29,16 @@
#include "vcommonsettings.h" #include "vcommonsettings.h"
#include <QApplication> #include <QApplication>
#include <QColor>
#include <QDate> #include <QDate>
#include <QDir> #include <QDir>
#include <QFont>
#include <QGlobalStatic>
#include <QLocale> #include <QLocale>
#include <QMarginsF>
#include <QMessageLogger> #include <QMessageLogger>
#include <QVariant> #include <QVariant>
#include <QtDebug> #include <QtDebug>
#include <QFont>
#include <QGlobalStatic>
#include <QMarginsF>
#include <QColor>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "vtextcodec.h" #include "vtextcodec.h"
@ -46,9 +46,9 @@
#include <QTextCodec> #include <QTextCodec>
#endif #endif
#include "compatibility.h"
#include "def.h" #include "def.h"
#include "defglobal.h" #include "defglobal.h"
#include "compatibility.h"
#include "literals.h" #include "literals.h"
const int VCommonSettings::defaultScrollingDuration = 300; const int VCommonSettings::defaultScrollingDuration = 300;
@ -77,60 +77,92 @@ Q_DECLARE_METATYPE(QMarginsF) // NOLINT
namespace namespace
{ {
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsMultisizeMeasurements, (QLatin1String("paths/standard_measurements"))) // NOLINT (QLatin1String("paths/individual_measurements"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsMultisizeMeasurements,
(QLatin1String("paths/standard_measurements"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsPattern, (QLatin1String("paths/pattern"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsPattern, (QLatin1String("paths/pattern"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsTemplates, (QLatin1String("paths/templates"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsTemplates, (QLatin1String("paths/templates"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsLabelTemplate, (QLatin1String("paths/labels"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsLabelTemplate, (QLatin1String("paths/labels"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsManualLayouts, (QLatin1String("paths/manualLayouts"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsManualLayouts, (QLatin1String("paths/manualLayouts"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationOsSeparator, (QLatin1String("configuration/osSeparator"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationOsSeparator,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveState, (QLatin1String("configuration/autosave/state"))) // NOLINT (QLatin1String("configuration/osSeparator"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveTime , (QLatin1String("configuration/autosave/time"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveState,
(QLatin1String("configuration/autosave/state"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveTime,
(QLatin1String("configuration/autosave/time"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationLocale, (QLatin1String("configuration/locale"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationLocale, (QLatin1String("configuration/locale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPMSystemCode, (QLatin1String("configuration/pmscode"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPMSystemCode, (QLatin1String("configuration/pmscode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationUnit, (QLatin1String("configuration/unit"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationUnit, (QLatin1String("configuration/unit"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmItemDeletion, (QLatin1String("configuration/confirm_item_deletion"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmItemDeletion,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmFormatRewriting, (QLatin1String("configuration/confirm_format_rewriting"))) // NOLINT (QLatin1String("configuration/confirm_item_deletion"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAskContinueIfLayoutStale, (QLatin1String("configuration/askContinueIfLayoutStale"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmFormatRewriting,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationToolBarStyle, (QLatin1String("configuration/tool_bar_style"))) // NOLINT (QLatin1String("configuration/confirm_format_rewriting"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationFreeCurveMode, (QLatin1String("configuration/freeCurveMode"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAskContinueIfLayoutStale,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDoubleClickZoomFitBestCurrentPP, (QLatin1String("configuration/doubleClickZoomFitBestCurrentPP"))) // NOLINT (QLatin1String("configuration/askContinueIfLayoutStale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationInteractiveTools, (QLatin1String("configuration/interactiveTools"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationToolBarStyle,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDontUseNativeDialog, (QLatin1String("configuration/dontUseNativeDialog"))) // NOLINT (QLatin1String("configuration/tool_bar_style"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationFreeCurveMode,
(QLatin1String("configuration/freeCurveMode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDoubleClickZoomFitBestCurrentPP,
(QLatin1String("configuration/doubleClickZoomFitBestCurrentPP"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationInteractiveTools,
(QLatin1String("configuration/interactiveTools"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDontUseNativeDialog,
(QLatin1String("configuration/dontUseNativeDialog"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUndo, (QLatin1String("pattern/undo"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUndo, (QLatin1String("pattern/undo"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForbidFlipping, (QLatin1String("pattern/forbidFlipping"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForbidFlipping,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForceFlipping, (QLatin1String("pattern/forceFlipping"))) // NOLINT (QLatin1String("pattern/forbidFlipping"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternSewLineOnDrawing, (QLatin1String("pattern/sewLineOnDrawing"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForceFlipping,
(QLatin1String("pattern/forceFlipping"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternSewLineOnDrawing,
(QLatin1String("pattern/sewLineOnDrawing"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideMainPath, (QLatin1String("pattern/hideMainPath"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideMainPath, (QLatin1String("pattern/hideMainPath"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDoublePassmark, (QLatin1String("pattern/doublePassmark"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDoublePassmark, (QLatin1String("pattern/doublePassmark"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternDefaultSeamAllowance, (QLatin1String("pattern/defaultSeamAllowance"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternDefaultSeamAllowance,
(QLatin1String("pattern/defaultSeamAllowance"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFont, (QLatin1String("pattern/labelFont"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFont, (QLatin1String("pattern/labelFont"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLineWidth, (QLatin1String("pattern/lineWidth"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLineWidth, (QLatin1String("pattern/lineWidth"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternCurveApproximationScale, (QLatin1String("pattern/curveApproximationScale"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternCurveApproximationScale,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowCurveDetails, (QLatin1String("pattern/showCurveDetails"))) // NOLINT (QLatin1String("pattern/curveApproximationScale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternPieceShowMainPath, (QLatin1String("pattern/pieceShowMainPath"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowCurveDetails,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFontSize, (QLatin1String("pattern/labelFontSize"))) // NOLINT (QLatin1String("pattern/showCurveDetails"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternPieceShowMainPath,
(QLatin1String("pattern/pieceShowMainPath"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFontSize,
(QLatin1String("pattern/labelFontSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideLabels, (QLatin1String("pattern/hideLabels"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideLabels, (QLatin1String("pattern/hideLabels"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowAccuracyRadius, (QLatin1String("pattern/showAccuracyRadius"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowAccuracyRadius,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender, (QLatin1String("pattern/useOpenGLRender"))) // NOLINT (QLatin1String("pattern/showAccuracyRadius"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput, (QLatin1String("pattern/graphicalOutput"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender,
(QLatin1String("pattern/useOpenGLRender"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput,
(QLatin1String("pattern/graphicalOutput"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRecentFileList, (QLatin1String("recentFileList"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRecentFileList, (QLatin1String("recentFileList"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRestoreFileList, (QLatin1String("restoreFileList"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRestoreFileList, (QLatin1String("restoreFileList"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralGeometry, (QLatin1String("geometry"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralGeometry, (QLatin1String("geometry"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralToolbarsState, (QLatin1String("toolbarsState"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralToolbarsState, (QLatin1String("toolbarsState"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDarkMode, (QLatin1String("configuration/dark_mode"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDarkMode,
(QLatin1String("configuration/dark_mode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPreferenceDialogSize, (QLatin1String("preferenceDialogSize"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPreferenceDialogSize, (QLatin1String("preferenceDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingToolSeamAllowanceDialogSize, (QLatin1String("toolSeamAllowanceDialogSize"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingToolSeamAllowanceDialogSize,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIncrementsDialogSize, (QLatin1String("toolIncrementsDialogSize"))) // NOLINT (QLatin1String("toolSeamAllowanceDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFormulaWizardDialogSize, (QLatin1String("formulaWizardDialogSize"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIncrementsDialogSize,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFinalMeasurementsDialogSize, (QLatin1String("finalMeasurementsDialogSize"))) // NOLINT (QLatin1String("toolIncrementsDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSettingsDialogSize, (QLatin1String("layoutSettingsDialogSize"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFormulaWizardDialogSize,
(QLatin1String("formulaWizardDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFinalMeasurementsDialogSize,
(QLatin1String("finalMeasurementsDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSettingsDialogSize,
(QLatin1String("layoutSettingsDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDialogSplinePathSize, (QLatin1String("splinePathDialogSize"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDialogSplinePathSize, (QLatin1String("splinePathDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingAutomaticallyCheckUpdates, (QLatin1String("automaticallyCheckUpdates"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingAutomaticallyCheckUpdates,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLatestSkippedVersion, (QLatin1String("lastestSkippedVersion"))) // NOLINT (QLatin1String("automaticallyCheckUpdates"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLatestSkippedVersion,
(QLatin1String("lastestSkippedVersion"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDateOfLastRemind, (QLatin1String("dateOfLastRemind"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDateOfLastRemind, (QLatin1String("dateOfLastRemind"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVWithHeader, (QLatin1String("csv/withHeader"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVWithHeader, (QLatin1String("csv/withHeader"))) // NOLINT
@ -138,21 +170,28 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVCodec, (QLatin1String("csv/wi
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVSeparator, (QLatin1String("csv/withSeparator"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVSeparator, (QLatin1String("csv/withSeparator"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelDateFormat, (QLatin1String("label/dateFormat"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelDateFormat, (QLatin1String("label/dateFormat"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserDateFormats, (QLatin1String("label/userDateFormats"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserDateFormats,
(QLatin1String("label/userDateFormats"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats, (QLatin1String("label/userTimeFormats"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats,
(QLatin1String("label/userTimeFormats"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingSensorMouseScale, (QLatin1String("scrolling/sensorMouseScale"))) // NOLINT (QLatin1String("scrolling/updateInterval"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingWheelMouseScale, (QLatin1String("scrolling/wheelMouseScale"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingSensorMouseScale,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingAcceleration, (QLatin1String("scrolling/acceleration"))) // NOLINT (QLatin1String("scrolling/sensorMouseScale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingWheelMouseScale,
(QLatin1String("scrolling/wheelMouseScale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingAcceleration,
(QLatin1String("scrolling/acceleration"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkEditorSize, (QLatin1String("watermarkEditorSize"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkEditorSize, (QLatin1String("watermarkEditorSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkCustomColors, (QLatin1String("watermarkCustomColors"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkCustomColors,
(QLatin1String("watermarkCustomColors"))) // NOLINT
// Reading settings file is very expensive, cache curve approximation to speed up getting value // Reading settings file is very expensive, cache curve approximation to speed up getting value
qreal curveApproximationCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) qreal curveApproximationCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
@ -272,7 +311,7 @@ auto PrepareStandardFiles(const QString &currentPath, const QString &standardPat
QDir currentPathDir(currentPath); QDir currentPathDir(currentPath);
if ((currentPath == defPath || not currentPathDir.exists()) && standardPathDir.exists()) if ((currentPath == defPath || not currentPathDir.exists()) && standardPathDir.exists())
{ {
const QDir localdata (defPath); const QDir localdata(defPath);
if (localdata.mkpath(QChar('.'))) if (localdata.mkpath(QChar('.')))
{ {
SymlinkCopyDirRecursive(standardPath, defPath, false); SymlinkCopyDirRecursive(standardPath, defPath, false);
@ -284,15 +323,17 @@ auto PrepareStandardFiles(const QString &currentPath, const QString &standardPat
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VCommonSettings::VCommonSettings(Format format, Scope scope, const QString &organization, VCommonSettings::VCommonSettings(Format format, Scope scope, const QString &organization, const QString &application,
const QString &application, QObject *parent) QObject *parent)
:QSettings(format, scope, organization, application, parent) : QSettings(format, scope, organization, application, parent)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VCommonSettings::VCommonSettings(const QString &fileName, QSettings::Format format, QObject *parent) VCommonSettings::VCommonSettings(const QString &fileName, QSettings::Format format, QObject *parent)
:QSettings(fileName, format, parent) : QSettings(fileName, format, parent)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::SharePath(const QString &shareItem) -> QString auto VCommonSettings::SharePath(const QString &shareItem) -> QString
@ -357,7 +398,7 @@ auto VCommonSettings::LabelTemplatesPath() -> QString
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::PrepareStandardTemplates(const QString & currentPath) -> QString auto VCommonSettings::PrepareStandardTemplates(const QString &currentPath) -> QString
{ {
return PrepareStandardFiles(currentPath, StandardTemplatesPath(), GetDefPathTemplate()); return PrepareStandardFiles(currentPath, StandardTemplatesPath(), GetDefPathTemplate());
} }
@ -542,8 +583,8 @@ auto VCommonSettings::GetAutosaveTime() const -> int
int val = value(*settingConfigurationAutosaveTime, 1).toInt(&ok); int val = value(*settingConfigurationAutosaveTime, 1).toInt(&ok);
if (not ok) if (not ok)
{ {
qDebug()<<"Could not convert value"<<value(*settingConfigurationAutosaveTime, 1) qDebug() << "Could not convert value" << value(*settingConfigurationAutosaveTime, 1)
<<"to int. Return default value for autosave time"<<1<<"minutes."; << "to int. Return default value for autosave time" << 1 << "minutes.";
val = 1; val = 1;
} }
return val; return val;
@ -596,8 +637,8 @@ void VCommonSettings::SetPMSystemCode(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetUnit() const -> QString auto VCommonSettings::GetUnit() const -> QString
{ {
return value(*settingConfigurationUnit, return value(*settingConfigurationUnit, QLocale().measurementSystem() == QLocale::MetricSystem ? unitCM : unitINCH)
QLocale().measurementSystem() == QLocale::MetricSystem ? unitCM : unitINCH).toString(); .toString();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -666,7 +707,6 @@ void VCommonSettings::SetDarkMode(const bool &value)
setValue(*settingConfigurationDarkMode, value); setValue(*settingConfigurationDarkMode, value);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::IsFreeCurveMode() const -> bool auto VCommonSettings::IsFreeCurveMode() const -> bool
{ {
@ -710,8 +750,8 @@ auto VCommonSettings::GetUndoCount() const -> int
int val = value(*settingPatternUndo, 0).toInt(&ok); int val = value(*settingPatternUndo, 0).toInt(&ok);
if (not ok) if (not ok)
{ {
qDebug()<<"Could not convert value"<<value(*settingPatternUndo, 0) qDebug() << "Could not convert value" << value(*settingPatternUndo, 0)
<<"to int. Return default value for undo counts 0 (no limit)."; << "to int. Return default value for undo counts 0 (no limit).";
val = 0; val = 0;
} }
return val; return val;
@ -789,7 +829,7 @@ auto VCommonSettings::GetPreferenceDialogSize() const -> QSize
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPreferenceDialogSize(const QSize& sz) void VCommonSettings::SetPreferenceDialogSize(const QSize &sz)
{ {
setValue(*settingPreferenceDialogSize, sz); setValue(*settingPreferenceDialogSize, sz);
} }
@ -1025,7 +1065,7 @@ auto VCommonSettings::GetDefCSVCodec() -> int
void VCommonSettings::SetCSVSeparator(const QChar &separator) void VCommonSettings::SetCSVSeparator(const QChar &separator)
{ {
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
switch(separator.toLatin1()) switch (separator.toLatin1())
{ {
case '\t': case '\t':
settings.setValue(*settingCSVSeparator, 0); settings.setValue(*settingCSVSeparator, 0);
@ -1047,7 +1087,7 @@ auto VCommonSettings::GetCSVSeparator() const -> QChar
{ {
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
const quint8 separator = static_cast<quint8>(settings.value(*settingCSVSeparator, 3).toUInt()); const quint8 separator = static_cast<quint8>(settings.value(*settingCSVSeparator, 3).toUInt());
switch(separator) switch (separator)
{ {
case 0: case 0:
return QChar('\t'); return QChar('\t');
@ -1101,9 +1141,8 @@ auto VCommonSettings::GetDefaultSeamAllowance() -> double
double val = value(*settingPatternDefaultSeamAllowance, -1).toDouble(&ok); double val = value(*settingPatternDefaultSeamAllowance, -1).toDouble(&ok);
if (not ok) if (not ok)
{ {
qDebug()<< "Could not convert value"<<value(*settingPatternDefaultSeamAllowance, 0) qDebug() << "Could not convert value" << value(*settingPatternDefaultSeamAllowance, 0)
<< "to real. Return default value for default seam allowance is " << "to real. Return default value for default seam allowance is " << defaultValue << QChar('.');
<< defaultValue << QChar('.');
val = defaultValue; val = defaultValue;
} }
@ -1188,11 +1227,11 @@ void VCommonSettings::SetShowAccuracyRadius(bool value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetLabelDateFormat() const -> QString auto VCommonSettings::GetLabelDateFormat() const -> QString
{ {
const QString format = value(*settingLabelDateFormat, const QString format =
ConstFirst<QString> (VCommonSettings::PredefinedDateFormats())).toString(); value(*settingLabelDateFormat, ConstFirst<QString>(VCommonSettings::PredefinedDateFormats())).toString();
const QStringList allFormats = VCommonSettings::PredefinedDateFormats() + GetUserDefinedDateFormats(); const QStringList allFormats = VCommonSettings::PredefinedDateFormats() + GetUserDefinedDateFormats();
return allFormats.contains(format) ? format : ConstFirst<QString> (VCommonSettings::PredefinedDateFormats()); return allFormats.contains(format) ? format : ConstFirst<QString>(VCommonSettings::PredefinedDateFormats());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1204,9 +1243,7 @@ void VCommonSettings::SetLabelDateFormat(const QString &format)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::PredefinedDateFormats() -> QStringList auto VCommonSettings::PredefinedDateFormats() -> QStringList
{ {
return QStringList return QStringList{"MM-dd-yyyy",
{
"MM-dd-yyyy",
"d/M/yy", "d/M/yy",
"ddddMMMM dd, yyyy", "ddddMMMM dd, yyyy",
"dd/MM/yy", "dd/MM/yy",
@ -1225,8 +1262,7 @@ auto VCommonSettings::PredefinedDateFormats() -> QStringList
"yyyy-MM-dd", "yyyy-MM-dd",
"MM/yy", "MM/yy",
"MMM dd", "MMM dd",
"MMMM" "MMMM"};
};
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1244,11 +1280,11 @@ void VCommonSettings::SetUserDefinedDateFormats(const QStringList &formats)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetLabelTimeFormat() const -> QString auto VCommonSettings::GetLabelTimeFormat() const -> QString
{ {
const QString format = value(*settingLabelTimeFormat, const QString format =
ConstFirst<QString> (VCommonSettings::PredefinedTimeFormats())).toString(); value(*settingLabelTimeFormat, ConstFirst<QString>(VCommonSettings::PredefinedTimeFormats())).toString();
const QStringList allFormats = VCommonSettings::PredefinedTimeFormats() + GetUserDefinedTimeFormats(); const QStringList allFormats = VCommonSettings::PredefinedTimeFormats() + GetUserDefinedTimeFormats();
return allFormats.contains(format) ? format : ConstFirst<QString> (VCommonSettings::PredefinedTimeFormats()); return allFormats.contains(format) ? format : ConstFirst<QString>(VCommonSettings::PredefinedTimeFormats());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1260,13 +1296,7 @@ void VCommonSettings::SetLabelTimeFormat(const QString &format)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::PredefinedTimeFormats() -> QStringList auto VCommonSettings::PredefinedTimeFormats() -> QStringList
{ {
return QStringList return QStringList{"hh:mm:ss", "hh:mm:ss AP", "hh:mm", "hh:mm AP"};
{
"hh:mm:ss",
"hh:mm:ss AP",
"hh:mm",
"hh:mm AP"
};
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1383,7 +1413,7 @@ auto VCommonSettings::WidthMainLine() const -> qreal
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::WidthHairLine() const -> qreal auto VCommonSettings::WidthHairLine() const -> qreal
{ {
return WidthMainLine()/3.0; return WidthMainLine() / 3.0;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1512,8 +1542,8 @@ void VCommonSettings::SetGraphicalOutput(const bool &value)
auto VCommonSettings::GetTiledPDFMargins(const Unit &unit) const -> QMarginsF auto VCommonSettings::GetTiledPDFMargins(const Unit &unit) const -> QMarginsF
{ {
// default value is 10mm. We save the margins in mm in the setting. // default value is 10mm. We save the margins in mm in the setting.
return UnitConvertor( return UnitConvertor(ValueOrDef<QMarginsF>(*this, *settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm,
ValueOrDef<QMarginsF>(*this, *settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit); unit);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1539,7 +1569,7 @@ auto VCommonSettings::GetTiledPDFOrientation() const -> PageOrientation
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetTiledPDFOrientation(PageOrientation value) void VCommonSettings::SetTiledPDFOrientation(PageOrientation value)
{ {
setValue(*settingTiledPDFOrientation, static_cast<bool> (value)); setValue(*settingTiledPDFOrientation, static_cast<bool>(value));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -38,19 +38,18 @@
#include <QStringList> #include <QStringList>
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/def.h"
#include "../vlayout/vlayoutdef.h" #include "../vlayout/vlayoutdef.h"
#include "../vmisc/def.h"
class QMarginsF; class QMarginsF;
class VCommonSettings : public QSettings class VCommonSettings : public QSettings
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public : VCommonSettings(Format format, Scope scope, const QString &organization,
VCommonSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), const QString &application = QString(), QObject *parent = nullptr);
QObject *parent = nullptr);
VCommonSettings(const QString &fileName, Format format, QObject *parent = nullptr); VCommonSettings(const QString &fileName, Format format, QObject *parent = nullptr);
~VCommonSettings() override =default; ~VCommonSettings() override = default;
static auto SharePath(const QString &shareItem) -> QString; static auto SharePath(const QString &shareItem) -> QString;
static auto MultisizeTablesPath() -> QString; static auto MultisizeTablesPath() -> QString;
@ -146,25 +145,25 @@ public:
void SetToolbarsState(const QByteArray &value); void SetToolbarsState(const QByteArray &value);
auto GetPreferenceDialogSize() const -> QSize; auto GetPreferenceDialogSize() const -> QSize;
void SetPreferenceDialogSize(const QSize& sz); void SetPreferenceDialogSize(const QSize &sz);
auto GetToolSeamAllowanceDialogSize() const -> QSize; auto GetToolSeamAllowanceDialogSize() const -> QSize;
void SetToolSeamAllowanceDialogSize(const QSize& sz); void SetToolSeamAllowanceDialogSize(const QSize &sz);
auto GetFormulaWizardDialogSize() const -> QSize; auto GetFormulaWizardDialogSize() const -> QSize;
void SetFormulaWizardDialogSize(const QSize& sz); void SetFormulaWizardDialogSize(const QSize &sz);
auto GetIncrementsDialogSize() const -> QSize; auto GetIncrementsDialogSize() const -> QSize;
void SetIncrementsDialogSize(const QSize& sz); void SetIncrementsDialogSize(const QSize &sz);
auto GetFinalMeasurementsDialogSize() const -> QSize; auto GetFinalMeasurementsDialogSize() const -> QSize;
void SetFinalMeasurementsDialogSize(const QSize& sz); void SetFinalMeasurementsDialogSize(const QSize &sz);
auto GetLayoutSettingsDialogSize() const -> QSize; auto GetLayoutSettingsDialogSize() const -> QSize;
void SetLayoutSettingsDialogSize(const QSize& sz); void SetLayoutSettingsDialogSize(const QSize &sz);
auto GetDialogSplinePathSize() const -> QSize; auto GetDialogSplinePathSize() const -> QSize;
void SetDialogSplinePathSize(const QSize& sz); void SetDialogSplinePathSize(const QSize &sz);
auto IsAutomaticallyCheckUpdates() const -> bool; auto IsAutomaticallyCheckUpdates() const -> bool;
void SetAutomaticallyCheckUpdates(bool value); void SetAutomaticallyCheckUpdates(bool value);
@ -300,13 +299,12 @@ public:
void SetGraphicalOutput(const bool &value); void SetGraphicalOutput(const bool &value);
auto GetWatermarkEditorSize() const -> QSize; auto GetWatermarkEditorSize() const -> QSize;
void SetWatermarkEditorSize(const QSize& sz); void SetWatermarkEditorSize(const QSize &sz);
auto GetWatermarkCustomColors() const -> QVector<QColor>; auto GetWatermarkCustomColors() const -> QVector<QColor>;
void SetWatermarkCustomColors(QVector<QColor> colors); void SetWatermarkCustomColors(QVector<QColor> colors);
protected: protected:
template <typename T> template <typename T>
static auto GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue, T valueMin, static auto GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue, T valueMin,
T valueMax) -> T; T valueMax) -> T;
@ -337,7 +335,7 @@ inline auto VCommonSettings::MaximalLineWidth() -> qreal
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template<typename T> template <typename T>
auto VCommonSettings::GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue, auto VCommonSettings::GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue,
T valueMin, T valueMax) -> T T valueMin, T valueMax) -> T
{ {
@ -359,8 +357,8 @@ inline auto VCommonSettings::ValueOrDef(const QSettings &settings, const QString
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <> template <>
inline auto VCommonSettings::ValueOrDef<Cases>(const QSettings &settings, const QString &setting, inline auto VCommonSettings::ValueOrDef<Cases>(const QSettings &settings, const QString &setting, const Cases &defValue)
const Cases &defValue) -> Cases -> Cases
{ {
const QVariant val = settings.value(setting, QVariant::fromValue(static_cast<int>(defValue))); const QVariant val = settings.value(setting, QVariant::fromValue(static_cast<int>(defValue)));
const int g = val.canConvert<int>() ? val.toInt() : static_cast<int>(defValue); const int g = val.canConvert<int>() ? val.toInt() : static_cast<int>(defValue);

View File

@ -28,26 +28,26 @@
#include "vcontainer.h" #include "vcontainer.h"
#include <climits> #include <QLoggingCategory>
#include <QUuid>
#include <QVector> #include <QVector>
#include <QtDebug> #include <QtDebug>
#include <QUuid> #include <climits>
#include <QLoggingCategory>
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "../vgeometry/vabstractcubicbezierpath.h" #include "../vgeometry/vabstractcubicbezierpath.h"
#include "../vgeometry/vabstractcurve.h" #include "../vgeometry/vabstractcurve.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vellipticalarc.h"
#include "../vgeometry/vgeometrydef.h" #include "../vgeometry/vgeometrydef.h"
#include "../vgeometry/vgobject.h" #include "../vgeometry/vgobject.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vgeometry/vspline.h" #include "../vgeometry/vspline.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vellipticalarc.h"
#include "../vmisc/literals.h" #include "../vmisc/literals.h"
#include "variables/varcradius.h" #include "variables/varcradius.h"
#include "variables/vcurveangle.h" #include "variables/vcurveangle.h"
#include "variables/vcurvelength.h"
#include "variables/vcurveclength.h" #include "variables/vcurveclength.h"
#include "variables/vcurvelength.h"
#include "variables/vincrement.h" #include "variables/vincrement.h"
#include "variables/vlineangle.h" #include "variables/vlineangle.h"
#include "variables/vlinelength.h" #include "variables/vlinelength.h"
@ -72,7 +72,7 @@ QMap<QString, quint32> VContainer::copyCounter = QMap<QString, quint32>();
* @brief VContainer create empty container * @brief VContainer create empty container
*/ */
VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace) VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace)
:d(new VContainerData(trVars, patternUnit, nspace)) : d(new VContainerData(trVars, patternUnit, nspace))
{ {
if (nspace.isEmpty()) if (nspace.isEmpty())
{ {
@ -108,7 +108,7 @@ VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit, co
*/ */
auto VContainer::operator=(const VContainer &data) -> VContainer & auto VContainer::operator=(const VContainer &data) -> VContainer &
{ {
if ( &data == this ) if (&data == this)
{ {
return *this; return *this;
} }
@ -119,9 +119,9 @@ auto VContainer::operator=(const VContainer &data) -> VContainer &
#ifdef Q_COMPILER_RVALUE_REFS #ifdef Q_COMPILER_RVALUE_REFS
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VContainer::VContainer(VContainer &&data) Q_DECL_NOTHROW VContainer::VContainer(VContainer &&data) Q_DECL_NOTHROW : d(std::move(data.d))
:d(std::move(data.d)) {
{} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VContainer::operator=(VContainer &&data) Q_DECL_NOTHROW->VContainer & auto VContainer::operator=(VContainer &&data) Q_DECL_NOTHROW->VContainer &
@ -137,14 +137,15 @@ auto VContainer::operator=(VContainer &&data) Q_DECL_NOTHROW->VContainer &
* @param data container * @param data container
*/ */
VContainer::VContainer(const VContainer &data) VContainer::VContainer(const VContainer &data)
:d(data.d) : d(data.d)
{ {
++copyCounter[d->nspace]; ++copyCounter[d->nspace];
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VContainer::~VContainer() VContainer::~VContainer()
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VContainer::UniqueNamespace() -> QString auto VContainer::UniqueNamespace() -> QString
@ -153,8 +154,7 @@ auto VContainer::UniqueNamespace() -> QString
do do
{ {
candidate = QUuid::createUuid().toString(); candidate = QUuid::createUuid().toString();
} } while (_id.contains(candidate));
while(_id.contains(candidate));
return candidate; return candidate;
} }
@ -204,10 +204,8 @@ auto VContainer::GetPiece(quint32 id) const -> VPiece
{ {
return d->pieces->value(id); return d->pieces->value(id);
} }
else
{
throw VExceptionBadId(tr("Can't find object"), id); throw VExceptionBadId(tr("Can't find object"), id);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -330,12 +328,12 @@ auto VContainer::getId() const -> quint32
*/ */
auto VContainer::getNextId() const -> quint32 auto VContainer::getNextId() const -> quint32
{ {
//TODO. Current count of ids are very big and allow us save time before someone will reach its max value. // TODO. Current count of ids are very big and allow us save time before someone will reach its max value.
//Better way, of cource, is to seek free ids inside the set of values and reuse them. // Better way, of cource, is to seek free ids inside the set of values and reuse them.
//But for now better to keep it as it is now. // But for now better to keep it as it is now.
if (_id.value(d->nspace) == UINT_MAX) if (_id.value(d->nspace) == UINT_MAX)
{ {
qCritical()<<(tr("Number of free id exhausted.")); qCritical() << (tr("Number of free id exhausted."));
} }
_id[d->nspace]++; _id[d->nspace]++;
return _id.value(d->nspace); return _id.value(d->nspace);
@ -392,15 +390,9 @@ void VContainer::ClearForFullParse()
d->pieces->clear(); d->pieces->clear();
d->piecePaths->clear(); d->piecePaths->clear();
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types"); Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types");
ClearVariables(QVector<VarType>{VarType::Increment, ClearVariables(QVector<VarType>{VarType::Increment, VarType::IncrementSeparator, VarType::LineAngle,
VarType::IncrementSeparator, VarType::LineLength, VarType::CurveLength, VarType::CurveCLength,
VarType::LineAngle, VarType::ArcRadius, VarType::CurveAngle, VarType::PieceExternalArea,
VarType::LineLength,
VarType::CurveLength,
VarType::CurveCLength,
VarType::ArcRadius,
VarType::CurveAngle,
VarType::PieceExternalArea,
VarType::PieceSeamLineArea}); VarType::PieceSeamLineArea});
ClearGObjects(); ClearGObjects();
ClearUniqueNames(); ClearUniqueNames();
@ -439,7 +431,7 @@ void VContainer::ClearVariables(const QVector<VarType> &types)
} }
else else
{ {
QHash<QString, QSharedPointer<VInternalVariable> >::iterator i; QHash<QString, QSharedPointer<VInternalVariable>>::iterator i;
for (i = d->variables.begin(); i != d->variables.end();) for (i = d->variables.begin(); i != d->variables.end();)
{ {
if (types.contains(i.value()->GetType())) if (types.contains(i.value()->GetType()))
@ -495,9 +487,8 @@ void VContainer::AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32
void VContainer::AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId) void VContainer::AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId)
{ {
const GOType curveType = curve->getType(); const GOType curveType = curve->getType();
if (curveType != GOType::Spline && curveType != GOType::SplinePath && if (curveType != GOType::Spline && curveType != GOType::SplinePath && curveType != GOType::CubicBezier &&
curveType != GOType::CubicBezier && curveType != GOType::CubicBezierPath && curveType != GOType::CubicBezierPath && curveType != GOType::Arc && curveType != GOType::EllipticalArc)
curveType != GOType::Arc && curveType != GOType::EllipticalArc)
{ {
throw VException(tr("Can't create a curve with type '%1'").arg(static_cast<int>(curveType))); throw VException(tr("Can't create a curve with type '%1'").arg(static_cast<int>(curveType)));
} }
@ -595,8 +586,8 @@ auto VContainer::DataMeasurements() const -> const QMap<QString, QSharedPointer<
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VContainer::DataMeasurementsWithSeparators() const -> const QMap<QString, QSharedPointer<VMeasurement>> auto VContainer::DataMeasurementsWithSeparators() const -> const QMap<QString, QSharedPointer<VMeasurement>>
{ {
QMap<QString, QSharedPointer<VMeasurement> > measurements = DataVar<VMeasurement>(VarType::Measurement); QMap<QString, QSharedPointer<VMeasurement>> measurements = DataVar<VMeasurement>(VarType::Measurement);
QMap<QString, QSharedPointer<VMeasurement> > separators = DataVar<VMeasurement>(VarType::MeasurementSeparator); QMap<QString, QSharedPointer<VMeasurement>> separators = DataVar<VMeasurement>(VarType::MeasurementSeparator);
Insert(measurements, separators); Insert(measurements, separators);
@ -612,8 +603,8 @@ auto VContainer::DataIncrements() const -> const QMap<QString, QSharedPointer<VI
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VContainer::DataIncrementsWithSeparators() const -> const QMap<QString, QSharedPointer<VIncrement>> auto VContainer::DataIncrementsWithSeparators() const -> const QMap<QString, QSharedPointer<VIncrement>>
{ {
QMap<QString, QSharedPointer<VIncrement> > increments = DataVar<VIncrement>(VarType::Increment); QMap<QString, QSharedPointer<VIncrement>> increments = DataVar<VIncrement>(VarType::Increment);
QMap<QString, QSharedPointer<VIncrement> > separators = DataVar<VIncrement>(VarType::IncrementSeparator); QMap<QString, QSharedPointer<VIncrement>> separators = DataVar<VIncrement>(VarType::IncrementSeparator);
Insert(increments, separators); Insert(increments, separators);
@ -659,8 +650,8 @@ auto VContainer::DataAnglesCurves() const -> const QMap<QString, QSharedPointer<
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VContainer::DataPieceArea() const -> const QMap<QString, QSharedPointer<VPieceArea>> auto VContainer::DataPieceArea() const -> const QMap<QString, QSharedPointer<VPieceArea>>
{ {
QMap<QString, QSharedPointer<VPieceArea> > externalAreas = DataVar<VPieceArea>(VarType::PieceExternalArea); QMap<QString, QSharedPointer<VPieceArea>> externalAreas = DataVar<VPieceArea>(VarType::PieceExternalArea);
QMap<QString, QSharedPointer<VPieceArea> > seamLineAreas = DataVar<VPieceArea>(VarType::PieceSeamLineArea); QMap<QString, QSharedPointer<VPieceArea>> seamLineAreas = DataVar<VPieceArea>(VarType::PieceSeamLineArea);
Insert(externalAreas, seamLineAreas); Insert(externalAreas, seamLineAreas);
@ -722,9 +713,9 @@ auto VContainer::GetTrVars() const -> const VTranslateVars *
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> auto VContainer::DataVar(const VarType &type) const -> const QMap<QString, QSharedPointer<T>> template <typename T> auto VContainer::DataVar(const VarType &type) const -> const QMap<QString, QSharedPointer<T>>
{ {
QMap<QString, QSharedPointer<T> > map; QMap<QString, QSharedPointer<T>> map;
//Sorting QHash by id // Sorting QHash by id
QHash<QString, QSharedPointer<VInternalVariable> >::const_iterator i; QHash<QString, QSharedPointer<VInternalVariable>>::const_iterator i;
for (i = d->variables.constBegin(); i != d->variables.constEnd(); ++i) for (i = d->variables.constBegin(); i != d->variables.constEnd(); ++i)
{ {
if (i.value()->GetType() == type) if (i.value()->GetType() == type)

View File

@ -27,28 +27,28 @@
*************************************************************************/ *************************************************************************/
#include "dialogeditlabel.h" #include "dialogeditlabel.h"
#include "ui_dialogeditlabel.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "ui_dialogeditlabel.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vformat/vlabeltemplate.h"
#include "../ifc/xml/vlabeltemplateconverter.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "../vpatterndb/vcontainer.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vpiece.h" #include "../ifc/xml/vlabeltemplateconverter.h"
#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../tools/dialogtool.h"
#include "../vformat/vlabeltemplate.h"
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
#include "../vpatterndb/variables/vmeasurement.h" #include "../vpatterndb/variables/vmeasurement.h"
#include "../vpatterndb/variables/vpiecearea.h" #include "../vpatterndb/variables/vpiecearea.h"
#include "../tools/dialogtool.h" #include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vpiece.h"
#include <QDate>
#include <QDir> #include <QDir>
#include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QMenu> #include <QMenu>
#include <QDate> #include <QMessageBox>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogEditLabel::DialogEditLabel(const VAbstractPattern *doc, const VContainer *data, QWidget *parent) DialogEditLabel::DialogEditLabel(const VAbstractPattern *doc, const VContainer *data, QWidget *parent)
@ -77,12 +77,13 @@ DialogEditLabel::DialogEditLabel(const VAbstractPattern *doc, const VContainer *
connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate); connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate);
connect(ui->spinBoxFontSize, QOverload<int>::of(&QSpinBox::valueChanged), this, connect(ui->spinBoxFontSize, QOverload<int>::of(&QSpinBox::valueChanged), this,
&DialogEditLabel::SaveAdditionalFontSize); &DialogEditLabel::SaveAdditionalFontSize);
connect(ui->toolButtonTop, &QToolButton::clicked, this, [this](){DialogTool::MoveListRowTop(ui->listWidgetEdit);}); connect(ui->toolButtonTop, &QToolButton::clicked, this,
connect(ui->toolButtonUp, &QToolButton::clicked, this, [this](){DialogTool::MoveListRowUp(ui->listWidgetEdit);}); [this]() { DialogTool::MoveListRowTop(ui->listWidgetEdit); });
connect(ui->toolButtonUp, &QToolButton::clicked, this, [this]() { DialogTool::MoveListRowUp(ui->listWidgetEdit); });
connect(ui->toolButtonDown, &QToolButton::clicked, this, connect(ui->toolButtonDown, &QToolButton::clicked, this,
[this](){DialogTool::MoveListRowDown(ui->listWidgetEdit);}); [this]() { DialogTool::MoveListRowDown(ui->listWidgetEdit); });
connect(ui->toolButtonBottom, &QToolButton::clicked, this, connect(ui->toolButtonBottom, &QToolButton::clicked, this,
[this](){DialogTool::MoveListRowBottom(ui->listWidgetEdit);}); [this]() { DialogTool::MoveListRowBottom(ui->listWidgetEdit); });
InitPlaceholders(); InitPlaceholders();
InitPlaceholdersMenu(); InitPlaceholdersMenu();
@ -279,7 +280,8 @@ void DialogEditLabel::NewTemplate()
{ {
if (ui->listWidgetEdit->count() > 0) if (ui->listWidgetEdit->count() > 0)
{ {
const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Create new template"), const QMessageBox::StandardButton answer =
QMessageBox::question(this, tr("Create new template"),
tr("Creating new template will overwrite the current, do " tr("Creating new template will overwrite the current, do "
"you want to continue?"), "you want to continue?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
@ -311,7 +313,7 @@ void DialogEditLabel::ExportTemplate()
return; return;
} }
QFileInfo f( fileName ); QFileInfo f(fileName);
if (f.suffix().isEmpty() && f.suffix() != QLatin1String("xml")) if (f.suffix().isEmpty() && f.suffix() != QLatin1String("xml"))
{ {
fileName += QLatin1String(".xml"); fileName += QLatin1String(".xml");
@ -340,7 +342,8 @@ void DialogEditLabel::ImportTemplate()
{ {
if (ui->listWidgetEdit->count() > 0) if (ui->listWidgetEdit->count() > 0)
{ {
const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Import template"), const QMessageBox::StandardButton answer =
QMessageBox::question(this, tr("Import template"),
tr("Import template will overwrite the current, do " tr("Import template will overwrite the current, do "
"you want to continue?"), "you want to continue?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
@ -351,7 +354,7 @@ void DialogEditLabel::ImportTemplate()
} }
QString filter(tr("Label template") + QLatin1String(" (*.xml)")); QString filter(tr("Label template") + QLatin1String(" (*.xml)"));
//Use standard path to label templates // Use standard path to label templates
const QString path = const QString path =
VCommonSettings::PrepareLabelTemplates(VAbstractApplication::VApp()->Settings()->GetPathLabelTemplate()); VCommonSettings::PrepareLabelTemplates(VAbstractApplication::VApp()->Settings()->GetPathLabelTemplate());
const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr, const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr,
@ -453,7 +456,7 @@ void DialogEditLabel::SetupControls()
ui->toolButtonDown->setEnabled(true); ui->toolButtonDown->setEnabled(true);
ui->toolButtonBottom->setEnabled(true); ui->toolButtonBottom->setEnabled(true);
} }
else if (ui->listWidgetEdit->currentRow() == ui->listWidgetEdit->count()-1) else if (ui->listWidgetEdit->currentRow() == ui->listWidgetEdit->count() - 1)
{ {
ui->toolButtonTop->setEnabled(true); ui->toolButtonTop->setEnabled(true);
ui->toolButtonUp->setEnabled(true); ui->toolButtonUp->setEnabled(true);
@ -518,22 +521,22 @@ void DialogEditLabel::InitPlaceholders()
const QString pUnits = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true); const QString pUnits = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
m_placeholders.insert(pl_pUnits, qMakePair(tr("Pattern units"), pUnits)); m_placeholders.insert(pl_pUnits, qMakePair(tr("Pattern units"), pUnits));
m_placeholders.insert(pl_mSizeUnits, qMakePair(tr("Size units"), m_placeholders.insert(
UnitsToStr(VAbstractValApplication::VApp()->DimensionSizeUnits(), pl_mSizeUnits,
true))); qMakePair(tr("Size units"), UnitsToStr(VAbstractValApplication::VApp()->DimensionSizeUnits(), true)));
m_placeholders.insert(pl_areaUnits, qMakePair(tr("Area units"), pUnits + QStringLiteral("²"))); m_placeholders.insert(pl_areaUnits, qMakePair(tr("Area units"), pUnits + QStringLiteral("²")));
if (VAbstractValApplication::VApp()->GetMeasurementsType() == MeasurementsType::Individual) if (VAbstractValApplication::VApp()->GetMeasurementsType() == MeasurementsType::Individual)
{ {
m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), m_placeholders.insert(pl_customer,
VAbstractValApplication::VApp()->GetCustomerName())); qMakePair(tr("Customer name"), VAbstractValApplication::VApp()->GetCustomerName()));
const QString birthDate = locale.toString(VAbstractValApplication::VApp()->GetCustomerBirthDate(), const QString birthDate =
m_doc->GetLabelDateFormat()); locale.toString(VAbstractValApplication::VApp()->GetCustomerBirthDate(), m_doc->GetLabelDateFormat());
m_placeholders.insert(pl_birthDate, qMakePair(tr("Customer birth date"), birthDate)); m_placeholders.insert(pl_birthDate, qMakePair(tr("Customer birth date"), birthDate));
m_placeholders.insert(pl_email, qMakePair(tr("Customer email"), m_placeholders.insert(pl_email,
VAbstractValApplication::VApp()->CustomerEmail())); qMakePair(tr("Customer email"), VAbstractValApplication::VApp()->CustomerEmail()));
} }
else else
{ {
@ -571,41 +574,41 @@ void DialogEditLabel::InitPlaceholders()
{ {
QString label = VAbstractValApplication::VApp()->GetDimensionHeightLabel(); QString label = VAbstractValApplication::VApp()->GetDimensionHeightLabel();
m_placeholders.insert(pl_heightLabel, qMakePair(tr("Height label", "dimension"), m_placeholders.insert(pl_heightLabel,
not label.isEmpty() ? label : heightValue)); qMakePair(tr("Height label", "dimension"), not label.isEmpty() ? label : heightValue));
m_placeholders.insert(pl_dimensionX, qMakePair(tr("Dimension X label", "dimension"), m_placeholders.insert(
not label.isEmpty() ? label : heightValue)); pl_dimensionX, qMakePair(tr("Dimension X label", "dimension"), not label.isEmpty() ? label : heightValue));
label = VAbstractValApplication::VApp()->GetDimensionSizeLabel(); label = VAbstractValApplication::VApp()->GetDimensionSizeLabel();
m_placeholders.insert(pl_sizeLabel, qMakePair(tr("Size label", "dimension"), m_placeholders.insert(pl_sizeLabel,
not label.isEmpty() ? label : sizeValue)); qMakePair(tr("Size label", "dimension"), not label.isEmpty() ? label : sizeValue));
m_placeholders.insert(pl_dimensionY, qMakePair(tr("Dimension Y label", "dimension"), m_placeholders.insert(pl_dimensionY,
not label.isEmpty() ? label : sizeValue)); qMakePair(tr("Dimension Y label", "dimension"), not label.isEmpty() ? label : sizeValue));
label = VAbstractValApplication::VApp()->GetDimensionHipLabel(); label = VAbstractValApplication::VApp()->GetDimensionHipLabel();
m_placeholders.insert(pl_hipLabel, qMakePair(tr("Hip label", "dimension"), m_placeholders.insert(pl_hipLabel,
not label.isEmpty() ? label : hipValue)); qMakePair(tr("Hip label", "dimension"), not label.isEmpty() ? label : hipValue));
m_placeholders.insert(pl_dimensionZ, qMakePair(tr("Dimension Z label", "dimension"), m_placeholders.insert(pl_dimensionZ,
not label.isEmpty() ? label : hipValue)); qMakePair(tr("Dimension Z label", "dimension"), not label.isEmpty() ? label : hipValue));
label = VAbstractValApplication::VApp()->GetDimensionWaistLabel(); label = VAbstractValApplication::VApp()->GetDimensionWaistLabel();
m_placeholders.insert(pl_waistLabel, qMakePair(tr("Waist label", "dimension"), m_placeholders.insert(pl_waistLabel,
not label.isEmpty() ? label : waistValue)); qMakePair(tr("Waist label", "dimension"), not label.isEmpty() ? label : waistValue));
m_placeholders.insert(pl_dimensionW, qMakePair(tr("Dimension W label", "dimension"), m_placeholders.insert(
not label.isEmpty() ? label : waistValue)); pl_dimensionW, qMakePair(tr("Dimension W label", "dimension"), not label.isEmpty() ? label : waistValue));
} }
m_placeholders.insert(
m_placeholders.insert(pl_mExt, pl_mExt, qMakePair(tr("Measurments extension"),
qMakePair(tr("Measurments extension"),
VAbstractValApplication::VApp()->GetMeasurementsType() == MeasurementsType::Multisize VAbstractValApplication::VApp()->GetMeasurementsType() == MeasurementsType::Multisize
? QStringLiteral("vst") : QStringLiteral("vit"))); ? QStringLiteral("vst")
: QStringLiteral("vit")));
const QString userMaterialStr = tr("User material"); const QString userMaterialStr = tr("User material");
const QMap<int, QString> materials = m_doc->GetPatternMaterials(); const QMap<int, QString> materials = m_doc->GetPatternMaterials();
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i) for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
{ {
const QString number = QString::number(i+1); const QString number = QString::number(i + 1);
QString materialDescription; QString materialDescription;
QString value; QString value;
@ -623,7 +626,7 @@ void DialogEditLabel::InitPlaceholders()
} }
{ {
const QMap<QString, QSharedPointer<VMeasurement> > measurements = m_data->DataMeasurements(); const QMap<QString, QSharedPointer<VMeasurement>> measurements = m_data->DataMeasurements();
auto i = measurements.constBegin(); auto i = measurements.constBegin();
while (i != measurements.constEnd()) while (i != measurements.constEnd())
{ {
@ -642,7 +645,7 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert(pl_currentArea, qMakePair(tr("Piece full area"), QString())); m_placeholders.insert(pl_currentArea, qMakePair(tr("Piece full area"), QString()));
m_placeholders.insert(pl_currentSeamLineArea, qMakePair(tr("Piece seam line area"), QString())); m_placeholders.insert(pl_currentSeamLineArea, qMakePair(tr("Piece seam line area"), QString()));
for (int i=0; i < measurements.size(); ++i) for (int i = 0; i < measurements.size(); ++i)
{ {
const VFinalMeasurement &m = measurements.at(i); const VFinalMeasurement &m = measurements.at(i);
@ -651,15 +654,18 @@ void DialogEditLabel::InitPlaceholders()
QScopedPointer<Calculator> cal(new Calculator()); QScopedPointer<Calculator> cal(new Calculator());
const qreal result = cal->EvalFormula(completeData.DataVariables(), m.formula); const qreal result = cal->EvalFormula(completeData.DataVariables(), m.formula);
m_placeholders.insert(pl_finalMeasurement + m.name, qMakePair(tr("Final measurement: %1").arg(m.name), m_placeholders.insert(pl_finalMeasurement + m.name,
QString::number(result))); qMakePair(tr("Final measurement: %1").arg(m.name), QString::number(result)));
} }
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
const QString errorMsg = QObject::tr("Failed to prepare final measurement placeholder. Parser error at " const QString errorMsg = QObject::tr("Failed to prepare final measurement placeholder. Parser error at "
"line %1: %2.").arg(i+1).arg(e.GetMsg()); "line %1: %2.")
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : .arg(i + 1)
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; .arg(e.GetMsg());
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }
} }
@ -688,10 +694,11 @@ auto DialogEditLabel::ReplacePlaceholders(QString line) const -> QString
auto TestDimension = [per, this, line](const QString &placeholder, const QString &errorMsg) auto TestDimension = [per, this, line](const QString &placeholder, const QString &errorMsg)
{ {
if (line.contains(per+placeholder+per) && m_placeholders.value(placeholder).second == QChar('0')) if (line.contains(per + placeholder + per) && m_placeholders.value(placeholder).second == QChar('0'))
{ {
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
}; };
@ -708,7 +715,7 @@ auto DialogEditLabel::ReplacePlaceholders(QString line) const -> QString
auto i = m_placeholders.constBegin(); auto i = m_placeholders.constBegin();
while (i != m_placeholders.constEnd()) while (i != m_placeholders.constEnd())
{ {
line.replace(per+i.key()+per, i.value().second); line.replace(per + i.key() + per, i.value().second);
++i; ++i;
} }
return line; return line;
@ -720,7 +727,7 @@ auto DialogEditLabel::GetTemplate() const -> QVector<VLabelTemplateLine>
QVector<VLabelTemplateLine> lines; QVector<VLabelTemplateLine> lines;
lines.reserve(ui->listWidgetEdit->count()); lines.reserve(ui->listWidgetEdit->count());
for (int i=0; i<ui->listWidgetEdit->count(); ++i) for (int i = 0; i < ui->listWidgetEdit->count(); ++i)
{ {
const QListWidgetItem *lineItem = ui->listWidgetEdit->item(i); const QListWidgetItem *lineItem = ui->listWidgetEdit->item(i);
if (lineItem) if (lineItem)
@ -775,7 +782,7 @@ void DialogEditLabel::SetTemplate(const QVector<VLabelTemplateLine> &lines)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::SetPiece(const VPiece &piece) void DialogEditLabel::SetPiece(const VPiece &piece)
{ {
const VPieceLabelData& pieceData = piece.GetPieceLabelData(); const VPieceLabelData &pieceData = piece.GetPieceLabelData();
m_placeholders[pl_pLetter].second = pieceData.GetLetter(); m_placeholders[pl_pLetter].second = pieceData.GetLetter();
m_placeholders[pl_pAnnotation].second = pieceData.GetAnnotation(); m_placeholders[pl_pAnnotation].second = pieceData.GetAnnotation();
m_placeholders[pl_pOrientation].second = pieceData.GetOrientation(); m_placeholders[pl_pOrientation].second = pieceData.GetOrientation();
@ -803,8 +810,9 @@ void DialogEditLabel::SetPiece(const VPiece &piece)
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg()); const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
try try
@ -816,8 +824,9 @@ void DialogEditLabel::SetPiece(const VPiece &piece)
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg()); const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }

View File

@ -70,7 +70,6 @@
#include "nodeDetails/vtoolplacelabel.h" #include "nodeDetails/vtoolplacelabel.h"
#include <QFuture> #include <QFuture>
#include <QtConcurrent/QtConcurrentRun>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsView> #include <QGraphicsView>
#include <QKeyEvent> #include <QKeyEvent>
@ -78,6 +77,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QTimer> #include <QTimer>
#include <QUuid> #include <QUuid>
#include <QtConcurrent/QtConcurrentRun>
#include <QtMath> #include <QtMath>
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@ -118,8 +118,7 @@ const QString VToolSeamAllowance::AttrPiecePriority = QStringLiteral("priority")
namespace namespace
{ {
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> auto FixLabelPins(T itemData, const QMap<quint32, quint32> &mappedPins) -> T
auto FixLabelPins(T itemData, const QMap<quint32, quint32> &mappedPins) -> T
{ {
itemData.SetCenterPin(mappedPins.value(itemData.CenterPin(), NULL_ID)); itemData.SetCenterPin(mappedPins.value(itemData.CenterPin(), NULL_ID));
itemData.SetTopLeftPin(mappedPins.value(itemData.TopLeftPin(), NULL_ID)); itemData.SetTopLeftPin(mappedPins.value(itemData.TopLeftPin(), NULL_ID));
@ -128,8 +127,7 @@ auto FixLabelPins(T itemData, const QMap<quint32, quint32> &mappedPins) -> T
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> auto FixGrainlinePins(T itemData, const QMap<quint32, quint32> &mappedPins) -> T
auto FixGrainlinePins(T itemData, const QMap<quint32, quint32> &mappedPins) -> T
{ {
itemData.SetCenterPin(mappedPins.value(itemData.CenterPin(), NULL_ID)); itemData.SetCenterPin(mappedPins.value(itemData.CenterPin(), NULL_ID));
itemData.SetTopPin(mappedPins.value(itemData.TopPin(), NULL_ID)); itemData.SetTopPin(mappedPins.value(itemData.TopPin(), NULL_ID));
@ -141,7 +139,7 @@ auto FixGrainlinePins(T itemData, const QMap<quint32, quint32> &mappedPins) -> T
auto DuplicatePins(const QVector<quint32> &pins, const VToolSeamAllowanceInitData &initData) -> QMap<quint32, quint32> auto DuplicatePins(const QVector<quint32> &pins, const VToolSeamAllowanceInitData &initData) -> QMap<quint32, quint32>
{ {
QMap<quint32, quint32> newPins; QMap<quint32, quint32> newPins;
for(auto p : pins) for (auto p : pins)
{ {
QSharedPointer<VPointF> pin = initData.data->GeometricObject<VPointF>(p); QSharedPointer<VPointF> pin = initData.data->GeometricObject<VPointF>(p);
@ -190,13 +188,11 @@ void UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog, auto VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VMainGraphicsScene *scene,
VAbstractPattern *doc,
VContainer *data) -> VToolSeamAllowance * VContainer *data) -> VToolSeamAllowance *
{ {
SCASSERT(not dialog.isNull()); SCASSERT(not dialog.isNull());
const QPointer<DialogSeamAllowance> dialogTool = qobject_cast<DialogSeamAllowance*>(dialog); const QPointer<DialogSeamAllowance> dialogTool = qobject_cast<DialogSeamAllowance *>(dialog);
SCASSERT(not dialogTool.isNull()) SCASSERT(not dialogTool.isNull())
VToolSeamAllowanceInitData initData; VToolSeamAllowanceInitData initData;
@ -222,8 +218,9 @@ auto VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog,
{ {
const QString errorMsg = QObject::tr("Piece '%1'. Unable to load default piece label template.\n%2\n%3") const QString errorMsg = QObject::tr("Piece '%1'. Unable to load default piece label template.\n%2\n%3")
.arg(initData.detail.GetName(), e.ErrorMessage(), e.DetailedInformation()); .arg(initData.detail.GetName(), e.ErrorMessage(), e.DetailedInformation());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }
@ -282,18 +279,17 @@ auto VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initData) -> VToolSe
VMainGraphicsView::NewSceneRect(initData.scene, VAbstractValApplication::VApp()->getSceneView(), piece); VMainGraphicsView::NewSceneRect(initData.scene, VAbstractValApplication::VApp()->getSceneView(), piece);
VAbstractPattern::AddTool(initData.id, piece); VAbstractPattern::AddTool(initData.id, piece);
} }
//Very important to delete it. Only this tool need this special variable. // Very important to delete it. Only this tool need this special variable.
initData.data->RemoveVariable(currentSeamAllowance); initData.data->RemoveVariable(currentSeamAllowance);
return piece; return piece;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VToolSeamAllowance::Duplicate(const QPointer<DialogTool> &dialog, auto VToolSeamAllowance::Duplicate(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc)
VMainGraphicsScene *scene, -> VToolSeamAllowance *
VAbstractPattern *doc) -> VToolSeamAllowance *
{ {
SCASSERT(not dialog.isNull()); SCASSERT(not dialog.isNull());
const QPointer<DialogDuplicateDetail> dialogTool = qobject_cast<DialogDuplicateDetail*>(dialog); const QPointer<DialogDuplicateDetail> dialogTool = qobject_cast<DialogDuplicateDetail *>(dialog);
SCASSERT(not dialogTool.isNull()) SCASSERT(not dialogTool.isNull())
VToolSeamAllowanceInitData initData; VToolSeamAllowanceInitData initData;
@ -327,8 +323,8 @@ auto VToolSeamAllowance::Duplicate(VToolSeamAllowanceInitData &initData) -> VToo
QMap<quint32, quint32> replacements; QMap<quint32, quint32> replacements;
dupDetail.GetPath().SetNodes(DuplicateNodes(initData.detail.GetPath(), initData, replacements)); dupDetail.GetPath().SetNodes(DuplicateNodes(initData.detail.GetPath(), initData, replacements));
dupDetail.SetCustomSARecords(DuplicateCustomSARecords(initData.detail.GetCustomSARecords(), initData, dupDetail.SetCustomSARecords(
replacements)); DuplicateCustomSARecords(initData.detail.GetCustomSARecords(), initData, replacements));
dupDetail.SetInternalPaths(DuplicateInternalPaths(initData.detail.GetInternalPaths(), initData)); dupDetail.SetInternalPaths(DuplicateInternalPaths(initData.detail.GetInternalPaths(), initData));
dupDetail.SetPlaceLabels(DuplicatePlaceLabels(initData.detail.GetPlaceLabels(), initData)); dupDetail.SetPlaceLabels(DuplicatePlaceLabels(initData.detail.GetPlaceLabels(), initData));
dupDetail.SetUUID(QUuid::createUuid()); dupDetail.SetUUID(QUuid::createUuid());
@ -350,10 +346,10 @@ void VToolSeamAllowance::RemoveWithConfirm(bool ask)
{ {
DeleteToolWithConfirm(ask); DeleteToolWithConfirm(ask);
} }
catch(const VExceptionToolWasDeleted &e) catch (const VExceptionToolWasDeleted &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return;//Leave this method immediately!!! return; // Leave this method immediately!!!
} }
} }
@ -391,7 +387,7 @@ void VToolSeamAllowance::InsertNodes(const QVector<VPieceNode> &nodes, quint32 p
newDet.GetPath().Append(node); newDet.GetPath().Append(node);
// Seam allowance tool already initializated and can't init the node // Seam allowance tool already initializated and can't init the node
auto *saTool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(pieceId)); auto *saTool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(pieceId));
SCASSERT(saTool != nullptr); SCASSERT(saTool != nullptr);
InitNode(node, scene, saTool); InitNode(node, scene, saTool);
@ -409,28 +405,28 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl
doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, VDomDocument::AttrId, id);
doc->SetAttribute(domElement, AttrName, piece.GetName()); doc->SetAttribute(domElement, AttrName, piece.GetName());
doc->SetAttributeOrRemoveIf<QString>(domElement, AttrShortName, piece.GetShortName(), doc->SetAttributeOrRemoveIf<QString>(domElement, AttrShortName, piece.GetShortName(),
[](const QString &name) noexcept {return name.isEmpty();}); [](const QString &name) noexcept { return name.isEmpty(); });
doc->SetAttribute(domElement, AttrUUID, piece.GetUUID().toString()); doc->SetAttribute(domElement, AttrUUID, piece.GetUUID().toString());
doc->SetAttributeOrRemoveIf<QString>(domElement, AttrGradationLabel, piece.GetGradationLabel(), doc->SetAttributeOrRemoveIf<QString>(domElement, AttrGradationLabel, piece.GetGradationLabel(),
[](const QString &label) noexcept {return label.isEmpty();}); [](const QString &label) noexcept { return label.isEmpty(); });
doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion)); doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
doc->SetAttribute(domElement, AttrMx, VAbstractValApplication::VApp()->fromPixel(piece.GetMx())); doc->SetAttribute(domElement, AttrMx, VAbstractValApplication::VApp()->fromPixel(piece.GetMx()));
doc->SetAttribute(domElement, AttrMy, VAbstractValApplication::VApp()->fromPixel(piece.GetMy())); doc->SetAttribute(domElement, AttrMy, VAbstractValApplication::VApp()->fromPixel(piece.GetMy()));
doc->SetAttributeOrRemoveIf<bool>(domElement, AttrInLayout, piece.IsInLayout(), doc->SetAttributeOrRemoveIf<bool>(domElement, AttrInLayout, piece.IsInLayout(),
[](bool inLayout) noexcept {return inLayout;}); [](bool inLayout) noexcept { return inLayout; });
doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping()); doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping());
doc->SetAttribute(domElement, AttrForceFlipping, piece.IsForceFlipping()); doc->SetAttribute(domElement, AttrForceFlipping, piece.IsForceFlipping());
doc->SetAttribute(domElement, AttrSewLineOnDrawing, piece.IsSewLineOnDrawing()); doc->SetAttribute(domElement, AttrSewLineOnDrawing, piece.IsSewLineOnDrawing());
doc->SetAttributeOrRemoveIf<bool>(domElement, AttrSeamAllowance, piece.IsSeamAllowance(), doc->SetAttributeOrRemoveIf<bool>(domElement, AttrSeamAllowance, piece.IsSeamAllowance(),
[](bool seamAllowance) noexcept {return not seamAllowance;}); [](bool seamAllowance) noexcept { return not seamAllowance; });
doc->SetAttribute(domElement, AttrHideMainPath, piece.IsHideMainPath()); doc->SetAttribute(domElement, AttrHideMainPath, piece.IsHideMainPath());
doc->SetAttributeOrRemoveIf<bool>(domElement, AttrSeamAllowanceBuiltIn, piece.IsSeamAllowanceBuiltIn(), doc->SetAttributeOrRemoveIf<bool>(domElement, AttrSeamAllowanceBuiltIn, piece.IsSeamAllowanceBuiltIn(),
[](bool builtin) noexcept {return not builtin;}); [](bool builtin) noexcept { return not builtin; });
doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth()); doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth());
doc->SetAttributeOrRemoveIf<bool>(domElement, AttrUnited, piece.IsUnited(), doc->SetAttributeOrRemoveIf<bool>(domElement, AttrUnited, piece.IsUnited(),
[](bool united) noexcept {return not united;}); [](bool united) noexcept { return not united; });
doc->SetAttributeOrRemoveIf<uint>(domElement, AttrPiecePriority, piece.GetPriority(), doc->SetAttributeOrRemoveIf<uint>(domElement, AttrPiecePriority, piece.GetPriority(),
[](uint priority) noexcept {return priority == 0;}); [](uint priority) noexcept { return priority == 0; });
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -495,7 +491,7 @@ void VToolSeamAllowance::AddPlaceLabels(VAbstractPattern *doc, QDomElement &domE
void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece) void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
{ {
QDomElement domData = doc->createElement(VAbstractPattern::TagData); QDomElement domData = doc->createElement(VAbstractPattern::TagData);
const VPieceLabelData& data = piece.GetPieceLabelData(); const VPieceLabelData &data = piece.GetPieceLabelData();
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
doc->SetAttribute(domData, VAbstractPattern::AttrAnnotation, data.GetAnnotation()); doc->SetAttribute(domData, VAbstractPattern::AttrAnnotation, data.GetAnnotation());
doc->SetAttribute(domData, VAbstractPattern::AttrOrientation, data.GetOrientation()); doc->SetAttribute(domData, VAbstractPattern::AttrOrientation, data.GetOrientation());
@ -512,11 +508,11 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement
doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttribute(domData, AttrFont, data.GetFontSize());
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, data.CenterPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, data.CenterPin(),
[](quint32 pin) noexcept {return pin == NULL_ID;}); [](quint32 pin) noexcept { return pin == NULL_ID; });
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrTopLeftPin, data.TopLeftPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrTopLeftPin, data.TopLeftPin(),
[](quint32 leftPin) noexcept {return leftPin == NULL_ID;}); [](quint32 leftPin) noexcept { return leftPin == NULL_ID; });
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrBottomRightPin, data.BottomRightPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrBottomRightPin, data.BottomRightPin(),
[](quint32 rightPin) noexcept {return rightPin == NULL_ID;}); [](quint32 rightPin) noexcept { return rightPin == NULL_ID; });
doc->SetLabelTemplate(domData, data.GetLabelTemplate()); doc->SetLabelTemplate(domData, data.GetLabelTemplate());
domElement.appendChild(domData); domElement.appendChild(domData);
@ -526,7 +522,7 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement
void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece) void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
{ {
QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo); QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo);
const VPatternLabelData& geom = piece.GetPatternLabelData(); const VPatternLabelData &geom = piece.GetPatternLabelData();
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible()); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible());
doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMx, geom.GetPos().x());
doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y());
@ -535,11 +531,11 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE
doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, AttrFont, geom.GetFontSize());
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation());
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, geom.CenterPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, geom.CenterPin(),
[](quint32 pin) noexcept {return pin <= NULL_ID;}); [](quint32 pin) noexcept { return pin <= NULL_ID; });
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrTopLeftPin, geom.TopLeftPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrTopLeftPin, geom.TopLeftPin(),
[](quint32 pin) noexcept {return pin <= NULL_ID;}); [](quint32 pin) noexcept { return pin <= NULL_ID; });
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrBottomRightPin, geom.BottomRightPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrBottomRightPin, geom.BottomRightPin(),
[](quint32 pin) noexcept {return pin <= NULL_ID;}); [](quint32 pin) noexcept { return pin <= NULL_ID; });
domElement.appendChild(domData); domElement.appendChild(domData);
} }
@ -549,7 +545,7 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
{ {
// grainline // grainline
QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline); QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline);
const VGrainlineData& glGeom = piece.GetGrainlineGeometry(); const VGrainlineData &glGeom = piece.GetGrainlineGeometry();
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible()); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible());
doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x());
doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y());
@ -557,11 +553,11 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation());
doc->SetAttribute(domData, VAbstractPattern::AttrArrows, static_cast<int>(glGeom.GetArrowType())); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, static_cast<int>(glGeom.GetArrowType()));
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, glGeom.CenterPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, glGeom.CenterPin(),
[](quint32 pin) noexcept {return pin <= NULL_ID;}); [](quint32 pin) noexcept { return pin <= NULL_ID; });
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrTopPin, glGeom.TopPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrTopPin, glGeom.TopPin(),
[](quint32 pin) noexcept {return pin <= NULL_ID;}); [](quint32 pin) noexcept { return pin <= NULL_ID; });
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrBottomPin, glGeom.BottomPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrBottomPin, glGeom.BottomPin(),
[](quint32 pin) noexcept {return pin <= NULL_ID;}); [](quint32 pin) noexcept { return pin <= NULL_ID; });
domElement.appendChild(domData); domElement.appendChild(domData);
} }
@ -649,7 +645,10 @@ void VToolSeamAllowance::ReinitInternals(const VPiece &detail, VMainGraphicsScen
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VToolSeamAllowance::getTagName() const -> QString { return VAbstractPattern::TagDetail; } auto VToolSeamAllowance::getTagName() const -> QString
{
return VAbstractPattern::TagDetail;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ShowVisualization(bool show) void VToolSeamAllowance::ShowVisualization(bool show)
@ -667,7 +666,7 @@ void VToolSeamAllowance::GroupVisibility(quint32 object, bool visible)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::FullUpdateFromFile() void VToolSeamAllowance::FullUpdateFromFile()
{ {
const bool updateChildren = false;// Chilren have their own signals. Avoid double refresh. const bool updateChildren = false; // Chilren have their own signals. Avoid double refresh.
RefreshGeometry(updateChildren); RefreshGeometry(updateChildren);
} }
@ -757,7 +756,7 @@ void VToolSeamAllowance::Highlight(quint32 id)
void VToolSeamAllowance::UpdateDetailLabel() void VToolSeamAllowance::UpdateDetailLabel()
{ {
const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPiece detail = VAbstractTool::data.GetPiece(m_id);
const VPieceLabelData& labelData = detail.GetPieceLabelData(); const VPieceLabelData &labelData = detail.GetPieceLabelData();
const QVector<quint32> &pins = detail.GetPins(); const QVector<quint32> &pins = detail.GetPins();
if (labelData.IsVisible()) if (labelData.IsVisible())
@ -784,7 +783,7 @@ void VToolSeamAllowance::UpdateDetailLabel()
void VToolSeamAllowance::UpdatePatternInfo() void VToolSeamAllowance::UpdatePatternInfo()
{ {
const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPiece detail = VAbstractTool::data.GetPiece(m_id);
const VPatternLabelData& geom = detail.GetPatternLabelData(); const VPatternLabelData &geom = detail.GetPatternLabelData();
const QVector<quint32> &pins = detail.GetPins(); const QVector<quint32> &pins = detail.GetPins();
if (geom.IsVisible()) if (geom.IsVisible())
@ -818,7 +817,7 @@ void VToolSeamAllowance::UpdatePassmarks()
void VToolSeamAllowance::UpdateGrainline() void VToolSeamAllowance::UpdateGrainline()
{ {
const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPiece detail = VAbstractTool::data.GetPiece(m_id);
const VGrainlineData& geom = detail.GetGrainlineGeometry(); const VGrainlineData &geom = detail.GetGrainlineGeometry();
const QVector<quint32> &pins = detail.GetPins(); const QVector<quint32> &pins = detail.GetPins();
if (geom.IsVisible()) if (geom.IsVisible())
@ -841,10 +840,10 @@ void VToolSeamAllowance::UpdateGrainline()
if (m_geometryIsReady && not IsGrainlinePositionValid()) if (m_geometryIsReady && not IsGrainlinePositionValid())
{ {
const QString errorMsg = QObject::tr("Piece '%1'. Grainline is not valid.") const QString errorMsg = QObject::tr("Piece '%1'. Grainline is not valid.").arg(detail.GetName());
.arg(detail.GetName()); VAbstractApplication::VApp()->IsPedantic()
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : ? throw VException(errorMsg)
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }
else else
@ -857,7 +856,7 @@ void VToolSeamAllowance::UpdateGrainline()
/** /**
* @brief SaveMoveDetail saves the move detail operation to the undo stack * @brief SaveMoveDetail saves the move detail operation to the undo stack
*/ */
void VToolSeamAllowance::SaveMoveDetail(const QPointF& ptPos) void VToolSeamAllowance::SaveMoveDetail(const QPointF &ptPos)
{ {
VPiece oldDet = VAbstractTool::data.GetPiece(m_id); VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
@ -909,7 +908,6 @@ void VToolSeamAllowance::SaveRotationDetail(qreal dRot)
VAbstractApplication::VApp()->getUndoStack()->push(rotateCommand); VAbstractApplication::VApp()->getUndoStack()->push(rotateCommand);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief SaveMovePattern saves the pattern label position * @brief SaveMovePattern saves the pattern label position
@ -964,16 +962,15 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot)
VAbstractApplication::VApp()->getUndoStack()->push(rotateCommand); VAbstractApplication::VApp()->getUndoStack()->push(rotateCommand);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::SaveMoveGrainline(const QPointF& ptPos) void VToolSeamAllowance::SaveMoveGrainline(const QPointF &ptPos)
{ {
VPiece oldDet = VAbstractTool::data.GetPiece(m_id); VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
newDet.GetGrainlineGeometry().SetPos(ptPos); newDet.GetGrainlineGeometry().SetPos(ptPos);
qDebug() << "******* new grainline pos" << ptPos; qDebug() << "******* new grainline pos" << ptPos;
auto* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id); auto *moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
moveCommand->setText(tr("move grainline")); moveCommand->setText(tr("move grainline"));
VAbstractApplication::VApp()->getUndoStack()->push(moveCommand); VAbstractApplication::VApp()->getUndoStack()->push(moveCommand);
} }
@ -988,13 +985,13 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength)
newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos()); newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos());
newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength)); newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength));
auto* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id); auto *resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
resizeCommand->setText(tr("resize grainline")); resizeCommand->setText(tr("resize grainline"));
VAbstractApplication::VApp()->getUndoStack()->push(resizeCommand); VAbstractApplication::VApp()->getUndoStack()->push(resizeCommand);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF &ptPos)
{ {
VPiece oldDet = VAbstractTool::data.GetPiece(m_id); VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
@ -1076,14 +1073,14 @@ void VToolSeamAllowance::AddToFile()
// nodes // nodes
AddNodes(doc, domElement, piece); AddNodes(doc, domElement, piece);
//custom seam allowance // custom seam allowance
AddCSARecords(doc, domElement, piece.GetCustomSARecords()); AddCSARecords(doc, domElement, piece.GetCustomSARecords());
AddInternalPaths(doc, domElement, piece.GetInternalPaths()); AddInternalPaths(doc, domElement, piece.GetInternalPaths());
AddPins(doc, domElement, piece.GetPins()); AddPins(doc, domElement, piece.GetPins());
AddPlaceLabels(doc, domElement, piece.GetPlaceLabels()); AddPlaceLabels(doc, domElement, piece.GetPlaceLabels());
VAbstractApplication::VApp()->getUndoStack()->push(new AddPiece(domElement, doc, VAbstractTool::data, VAbstractApplication::VApp()->getUndoStack()->push(
m_sceneDetails, m_drawName)); new AddPiece(domElement, doc, VAbstractTool::data, m_sceneDetails, m_drawName));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1095,8 +1092,7 @@ void VToolSeamAllowance::RefreshDataInFile()
// Refresh only parts that we possibly need to update // Refresh only parts that we possibly need to update
{ {
// TODO. Delete if minimal supported version is 0.4.0 // TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 4, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 4, 0), "Time to refactor the code.");
"Time to refactor the code.");
const uint version = VAbstractPattern::GetParametrUInt(domElement, AttrVersion, QChar('1')); const uint version = VAbstractPattern::GetParametrUInt(domElement, AttrVersion, QChar('1'));
if (version == 1) if (version == 1)
@ -1133,8 +1129,8 @@ auto VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change, co
// value - this is new position. // value - this is new position.
const QPointF newPos = value.toPointF(); const QPointF newPos = value.toPointF();
VAbstractApplication::VApp()->getUndoStack()->push(new MovePiece(doc, newPos.x(), newPos.y(), m_id, VAbstractApplication::VApp()->getUndoStack()->push(
scene())); new MovePiece(doc, newPos.x(), newPos.y(), m_id, scene()));
const QList<QGraphicsView *> viewList = scene()->views(); const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty()) if (not viewList.isEmpty())
@ -1172,7 +1168,7 @@ void VToolSeamAllowance::mousePressEvent(QGraphicsSceneMouseEvent *event)
QGraphicsPathItem::mousePressEvent(event); QGraphicsPathItem::mousePressEvent(event);
// Somehow clicking on notselectable object do not clean previous selections. // Somehow clicking on notselectable object do not clean previous selections.
if (not (flags() & ItemIsSelectable) && scene()) if (not(flags() & ItemIsSelectable) && scene())
{ {
scene()->clearSelection(); scene()->clearSelection();
} }
@ -1187,7 +1183,8 @@ void VToolSeamAllowance::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (selectionType == SelectionType::ByMouseRelease) if (selectionType == SelectionType::ByMouseRelease)
{ {
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event event
->accept(); // Special for not selectable item first need to call standard mousePressEvent then accept event
} }
else else
{ {
@ -1307,12 +1304,12 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
DeleteFromMenu(); DeleteFromMenu();
} }
catch(const VExceptionToolWasDeleted &e) catch (const VExceptionToolWasDeleted &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return;//Leave this method immediately!!! return; // Leave this method immediately!!!
} }
//Leave this method immediately after call!!! // Leave this method immediately after call!!!
} }
} }
@ -1339,14 +1336,14 @@ void VToolSeamAllowance::keyReleaseEvent(QKeyEvent *event)
} }
DeleteToolWithConfirm(false); DeleteToolWithConfirm(false);
} }
catch(const VExceptionToolWasDeleted &e) catch (const VExceptionToolWasDeleted &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
if (not toolList.isEmpty()) if (not toolList.isEmpty())
{ {
VAbstractApplication::VApp()->getUndoStack()->endMacro(); VAbstractApplication::VApp()->getUndoStack()->endMacro();
} }
return;//Leave this method immediately!!! return; // Leave this method immediately!!!
} }
} }
break; break;
@ -1354,7 +1351,7 @@ void VToolSeamAllowance::keyReleaseEvent(QKeyEvent *event)
break; break;
} }
QGraphicsPathItem::keyReleaseEvent ( event ); QGraphicsPathItem::keyReleaseEvent(event);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1387,7 +1384,7 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
VToolSeamAllowance::AllowHover(true); VToolSeamAllowance::AllowHover(true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setFlag(QGraphicsItem::ItemIsFocusable, true); // For keyboard input focus
VToolSeamAllowance::ToolCreation(initData.typeCreation); VToolSeamAllowance::ToolCreation(initData.typeCreation);
setAcceptHoverEvents(m_acceptHoverEvents); setAcceptHoverEvents(m_acceptHoverEvents);
@ -1410,11 +1407,11 @@ void VToolSeamAllowance::UpdateExcludeState()
const VPieceNode &node = path.at(i); const VPieceNode &node = path.at(i);
if (node.GetTypeTool() == Tool::NodePoint) if (node.GetTypeTool() == Tool::NodePoint)
{ {
auto *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId())); auto *tool = qobject_cast<VNodePoint *>(VAbstractPattern::getTool(node.GetId()));
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
tool->SetExluded(node.IsExcluded()); tool->SetExluded(node.IsExcluded());
tool->setVisible(not node.IsExcluded());//Hide excluded point tool->setVisible(not node.IsExcluded()); // Hide excluded point
} }
} }
} }
@ -1429,12 +1426,12 @@ void VToolSeamAllowance::UpdateInternalPaths()
{ {
try try
{ {
if (auto *tool = qobject_cast<VToolPiecePath*>(VAbstractPattern::getTool(path))) if (auto *tool = qobject_cast<VToolPiecePath *>(VAbstractPattern::getTool(path)))
{ {
tool->RefreshGeometry(); tool->RefreshGeometry();
} }
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
// ignore // ignore
} }
@ -1448,25 +1445,26 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren)
const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPiece detail = VAbstractTool::data.GetPiece(m_id);
QFuture<QPainterPath > futurePath = QtConcurrent::run([this, detail](){return detail.MainPathPath(getData());}); QFuture<QPainterPath> futurePath = QtConcurrent::run([this, detail]() { return detail.MainPathPath(getData()); });
QFuture<QPainterPath > futurePassmarks = QFuture<QPainterPath> futurePassmarks =
QtConcurrent::run([this, detail](){return detail.PassmarksPath(getData());}); QtConcurrent::run([this, detail]() { return detail.PassmarksPath(getData()); });
QFuture<QVector<VLayoutPoint> > futureSeamAllowance; QFuture<QVector<VLayoutPoint>> futureSeamAllowance;
QFuture<bool> futureSeamAllowanceValid; QFuture<bool> futureSeamAllowanceValid;
if (detail.IsSeamAllowance()) if (detail.IsSeamAllowance())
{ {
futureSeamAllowance = QtConcurrent::run([this, detail](){return detail.SeamAllowancePoints(getData());}); futureSeamAllowance = QtConcurrent::run([this, detail]() { return detail.SeamAllowancePoints(getData()); });
futureSeamAllowanceValid = QtConcurrent::run([this, detail](){return detail.IsSeamAllowanceValid(getData());}); futureSeamAllowanceValid =
QtConcurrent::run([this, detail]() { return detail.IsSeamAllowanceValid(getData()); });
} }
this->setPos(detail.GetMx(), detail.GetMy()); this->setPos(detail.GetMx(), detail.GetMy());
QPainterPath path; QPainterPath path;
if (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() || not detail.IsHideMainPath() if (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() || not detail.IsHideMainPath() ||
|| not detail.IsSeamAllowance() || detail.IsSeamAllowanceBuiltIn()) not detail.IsSeamAllowance() || detail.IsSeamAllowanceBuiltIn())
{ {
m_mainPath = QPainterPath(); m_mainPath = QPainterPath();
m_seamAllowance->setBrush(QBrush(Qt::Dense7Pattern)); m_seamAllowance->setBrush(QBrush(Qt::Dense7Pattern));
@ -1488,10 +1486,10 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren)
{ {
if (not futureSeamAllowanceValid.result()) if (not futureSeamAllowanceValid.result())
{ {
const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.") const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.").arg(detail.GetName());
.arg(detail.GetName()); VAbstractApplication::VApp()->IsPedantic()
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : ? throw VException(errorMsg)
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
path.addPath(detail.SeamAllowancePath(futureSeamAllowance.result())); path.addPath(detail.SeamAllowancePath(futureSeamAllowance.result()));
path.setFillRule(Qt::OddEvenFill); path.setFillRule(Qt::OddEvenFill);
@ -1508,7 +1506,8 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren)
if (VAbstractApplication::VApp()->IsAppInGUIMode()) if (VAbstractApplication::VApp()->IsAppInGUIMode())
{ {
QTimer::singleShot(V_MSECONDS(100), Qt::CoarseTimer, this, [this, updateChildren]() QTimer::singleShot(V_MSECONDS(100), Qt::CoarseTimer, this,
[this, updateChildren]()
{ {
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
UpdateDetailLabel(); UpdateDetailLabel();
@ -1546,7 +1545,7 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren)
void VToolSeamAllowance::SaveDialogChange(const QString &undoText) void VToolSeamAllowance::SaveDialogChange(const QString &undoText)
{ {
SCASSERT(not m_dialog.isNull()); SCASSERT(not m_dialog.isNull());
auto *dialogTool = qobject_cast<DialogSeamAllowance*>(m_dialog.data()); auto *dialogTool = qobject_cast<DialogSeamAllowance *>(m_dialog.data());
SCASSERT(dialogTool != nullptr); SCASSERT(dialogTool != nullptr);
const VPiece newDet = dialogTool->GetPiece(); const VPiece newDet = dialogTool->GetPiece();
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
@ -1562,7 +1561,7 @@ void VToolSeamAllowance::SaveDialogChange(const QString &undoText)
if (groupChange) if (groupChange)
{ {
VAbstractApplication::VApp()->getUndoStack()->beginMacro(undoText.isEmpty() ? saveCommand->text(): undoText); VAbstractApplication::VApp()->getUndoStack()->beginMacro(undoText.isEmpty() ? saveCommand->text() : undoText);
for (auto command : undocommands) for (auto command : undocommands)
{ {
@ -1583,8 +1582,8 @@ void VToolSeamAllowance::SaveDialogChange(const QString &undoText)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ShowOptions() void VToolSeamAllowance::ShowOptions()
{ {
QPointer<DialogSeamAllowance> dialog = new DialogSeamAllowance(getData(), doc, m_id, QPointer<DialogSeamAllowance> dialog =
VAbstractValApplication::VApp()->getMainWindow()); new DialogSeamAllowance(getData(), doc, m_id, VAbstractValApplication::VApp()->getMainWindow());
dialog->EnableApply(true); dialog->EnableApply(true);
m_dialog = dialog; m_dialog = dialog;
m_dialog->setModal(true); m_dialog->setModal(true);
@ -1605,17 +1604,15 @@ void VToolSeamAllowance::ToggleInLayout(bool checked)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleForbidFlipping(bool checked) void VToolSeamAllowance::ToggleForbidFlipping(bool checked)
{ {
VAbstractApplication::VApp()->getUndoStack()->push( VAbstractApplication::VApp()->getUndoStack()->push(new TogglePieceForceForbidFlipping(
new TogglePieceForceForbidFlipping(m_id, checked, ForceForbidFlippingType::ForbidFlipping, m_id, checked, ForceForbidFlippingType::ForbidFlipping, &(VAbstractTool::data), doc));
&(VAbstractTool::data), doc));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleForceFlipping(bool checked) void VToolSeamAllowance::ToggleForceFlipping(bool checked)
{ {
VAbstractApplication::VApp()->getUndoStack()->push( VAbstractApplication::VApp()->getUndoStack()->push(new TogglePieceForceForbidFlipping(
new TogglePieceForceForbidFlipping(m_id, checked, ForceForbidFlippingType::ForceFlipping, m_id, checked, ForceForbidFlippingType::ForceFlipping, &(VAbstractTool::data), doc));
&(VAbstractTool::data), doc));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1630,7 +1627,7 @@ void VToolSeamAllowance::ToggleExcludeState(quint32 id)
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
for (int i = 0; i< oldDet.GetPath().CountNodes(); ++i) for (int i = 0; i < oldDet.GetPath().CountNodes(); ++i)
{ {
VPieceNode node = oldDet.GetPath().at(i); VPieceNode node = oldDet.GetPath().at(i);
if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint) if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint)
@ -1650,7 +1647,7 @@ void VToolSeamAllowance::ToggleTurnPointState(quint32 id)
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
for (int i = 0; i< oldDet.GetPath().CountNodes(); ++i) for (int i = 0; i < oldDet.GetPath().CountNodes(); ++i)
{ {
VPieceNode node = oldDet.GetPath().at(i); VPieceNode node = oldDet.GetPath().at(i);
if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint) if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint)
@ -1670,7 +1667,7 @@ void VToolSeamAllowance::ToggleNodePointAngleType(quint32 id, PieceNodeAngle typ
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
for (int i = 0; i< oldDet.GetPath().CountNodes(); ++i) for (int i = 0; i < oldDet.GetPath().CountNodes(); ++i)
{ {
VPieceNode node = oldDet.GetPath().at(i); VPieceNode node = oldDet.GetPath().at(i);
if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint) if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint)
@ -1690,7 +1687,7 @@ void VToolSeamAllowance::ToggleNodePointPassmark(quint32 id, bool toggle)
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
for (int i = 0; i< oldDet.GetPath().CountNodes(); ++i) for (int i = 0; i < oldDet.GetPath().CountNodes(); ++i)
{ {
VPieceNode node = oldDet.GetPath().at(i); VPieceNode node = oldDet.GetPath().at(i);
if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint) if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint)
@ -1710,7 +1707,7 @@ void VToolSeamAllowance::TogglePassmarkAngleType(quint32 id, PassmarkAngleType t
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
for (int i = 0; i< oldDet.GetPath().CountNodes(); ++i) for (int i = 0; i < oldDet.GetPath().CountNodes(); ++i)
{ {
VPieceNode node = oldDet.GetPath().at(i); VPieceNode node = oldDet.GetPath().at(i);
if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint) if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint)
@ -1730,7 +1727,7 @@ void VToolSeamAllowance::TogglePassmarkLineType(quint32 id, PassmarkLineType typ
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
for (int i = 0; i< oldDet.GetPath().CountNodes(); ++i) for (int i = 0; i < oldDet.GetPath().CountNodes(); ++i)
{ {
VPieceNode node = oldDet.GetPath().at(i); VPieceNode node = oldDet.GetPath().at(i);
if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint) if (node.GetId() == id && node.GetTypeTool() == Tool::NodePoint)
@ -1766,19 +1763,17 @@ void VToolSeamAllowance::ResetPieceLabelTemplate()
{ {
const QString errorMsg = QObject::tr("Piece '%1'. Unable to load default piece label template.\n%2\n%3") const QString errorMsg = QObject::tr("Piece '%1'. Unable to load default piece label template.\n%2\n%3")
.arg(newDet.GetName(), e.ErrorMessage(), e.DetailedInformation()); .arg(newDet.GetName(), e.ErrorMessage(), e.DetailedInformation());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData, auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData, const QVector<quint32> &pins,
const QVector<quint32> &pins, qreal &rotationAngle, qreal &labelWidth, qreal &labelHeight, QPointF &pos)
qreal &rotationAngle, -> VPieceItem::MoveTypes
qreal &labelWidth,
qreal &labelHeight,
QPointF &pos) -> VPieceItem::MoveTypes
{ {
VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications; VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications;
@ -1786,13 +1781,13 @@ auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData,
{ {
if (not qmu::QmuTokenParser::IsSingle(labelData.GetRotation())) if (not qmu::QmuTokenParser::IsSingle(labelData.GetRotation()))
{ {
restrictions &= ~ VPieceItem::IsRotatable; restrictions &= ~VPieceItem::IsRotatable;
} }
Calculator cal1; Calculator cal1;
rotationAngle = cal1.EvalFormula(VAbstractTool::data.DataVariables(), labelData.GetRotation()); rotationAngle = cal1.EvalFormula(VAbstractTool::data.DataVariables(), labelData.GetRotation());
} }
catch(qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return VPieceItem::Error; return VPieceItem::Error;
@ -1801,27 +1796,27 @@ auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData,
const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 topLeftPin = labelData.TopLeftPin();
const quint32 bottomRightPin = labelData.BottomRightPin(); const quint32 bottomRightPin = labelData.BottomRightPin();
if (topLeftPin != NULL_ID && pins.contains(topLeftPin) && bottomRightPin != NULL_ID if (topLeftPin != NULL_ID && pins.contains(topLeftPin) && bottomRightPin != NULL_ID &&
&& pins.contains(bottomRightPin)) pins.contains(bottomRightPin))
{ {
try try
{ {
const auto topLeftPinPoint = VAbstractTool::data.GeometricObject<VPointF>(topLeftPin); const auto topLeftPinPoint = VAbstractTool::data.GeometricObject<VPointF>(topLeftPin);
const auto bottomRightPinPoint = VAbstractTool::data.GeometricObject<VPointF>(bottomRightPin); const auto bottomRightPinPoint = VAbstractTool::data.GeometricObject<VPointF>(bottomRightPin);
const QRectF labelRect = QRectF(static_cast<QPointF>(*topLeftPinPoint), const QRectF labelRect =
static_cast<QPointF>(*bottomRightPinPoint)); QRectF(static_cast<QPointF>(*topLeftPinPoint), static_cast<QPointF>(*bottomRightPinPoint));
labelWidth = FromPixel(qAbs(labelRect.width()), *VDataTool::data.GetPatternUnit()); labelWidth = FromPixel(qAbs(labelRect.width()), *VDataTool::data.GetPatternUnit());
labelHeight = FromPixel(qAbs(labelRect.height()), *VDataTool::data.GetPatternUnit()); labelHeight = FromPixel(qAbs(labelRect.height()), *VDataTool::data.GetPatternUnit());
pos = labelRect.topLeft(); pos = labelRect.topLeft();
restrictions &= ~ VPieceItem::IsMovable; restrictions &= ~VPieceItem::IsMovable;
restrictions &= ~ VPieceItem::IsResizable; restrictions &= ~VPieceItem::IsResizable;
return restrictions; return restrictions;
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
// do nothing. // do nothing.
} }
@ -1841,10 +1836,10 @@ auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData,
if (not widthIsSingle || not heightIsSingle) if (not widthIsSingle || not heightIsSingle)
{ {
restrictions &= ~ VPieceItem::IsResizable; restrictions &= ~VPieceItem::IsResizable;
} }
} }
catch(qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return VPieceItem::Error; return VPieceItem::Error;
@ -1861,9 +1856,9 @@ auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData,
const qreal lHeight = ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()); const qreal lHeight = ToPixel(labelHeight, *VDataTool::data.GetPatternUnit());
pos = static_cast<QPointF>(*centerPinPoint) - QRectF(0, 0, lWidth, lHeight).center(); pos = static_cast<QPointF>(*centerPinPoint) - QRectF(0, 0, lWidth, lHeight).center();
restrictions &= ~ VPieceItem::IsMovable; restrictions &= ~VPieceItem::IsMovable;
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
pos = labelData.GetPos(); pos = labelData.GetPos();
} }
@ -1877,11 +1872,8 @@ auto VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData &labelData,
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData &geom, auto VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData &geom, const QVector<quint32> &pins, qreal &length,
const QVector<quint32> &pins, qreal &rotationAngle, QPointF &pos) -> VPieceItem::MoveTypes
qreal &length,
qreal &rotationAngle,
QPointF &pos) -> VPieceItem::MoveTypes
{ {
const quint32 topPin = geom.TopPin(); const quint32 topPin = geom.TopPin();
const quint32 bottomPin = geom.BottomPin(); const quint32 bottomPin = geom.BottomPin();
@ -1906,7 +1898,7 @@ auto VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData &geom,
return VPieceItem::NotMovable; return VPieceItem::NotMovable;
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
// do nothing. // do nothing.
} }
@ -1917,7 +1909,7 @@ auto VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData &geom,
{ {
if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation())) if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation()))
{ {
restrictions &= ~ VPieceItem::IsRotatable; restrictions &= ~VPieceItem::IsRotatable;
} }
Calculator cal1; Calculator cal1;
@ -1925,13 +1917,13 @@ auto VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData &geom,
if (not qmu::QmuTokenParser::IsSingle(geom.GetLength())) if (not qmu::QmuTokenParser::IsSingle(geom.GetLength()))
{ {
restrictions &= ~ VPieceItem::IsResizable; restrictions &= ~VPieceItem::IsResizable;
} }
Calculator cal2; Calculator cal2;
length = cal2.EvalFormula(VAbstractTool::data.DataVariables(), geom.GetLength()); length = cal2.EvalFormula(VAbstractTool::data.DataVariables(), geom.GetLength());
} }
catch(qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return VPieceItem::Error; return VPieceItem::Error;
@ -1945,17 +1937,17 @@ auto VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData &geom,
const auto centerPinPoint = VAbstractTool::data.GeometricObject<VPointF>(centerPin); const auto centerPinPoint = VAbstractTool::data.GeometricObject<VPointF>(centerPin);
const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit()); const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit());
QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), centerPinPoint->x() + cLength / 2.0,
centerPinPoint->x() + cLength / 2.0, centerPinPoint->y()); centerPinPoint->y());
grainline.setAngle(rotationAngle); grainline.setAngle(rotationAngle);
grainline = QLineF(grainline.p2(), grainline.p1()); grainline = QLineF(grainline.p2(), grainline.p1());
grainline.setLength(cLength); grainline.setLength(cLength);
pos = grainline.p2(); pos = grainline.p2();
restrictions &= ~ VPieceItem::IsMovable; restrictions &= ~VPieceItem::IsMovable;
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
pos = geom.GetPos(); pos = geom.GetPos();
} }
@ -1990,7 +1982,7 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
{ {
case (Tool::NodePoint): case (Tool::NodePoint):
{ {
auto *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId())); auto *tool = qobject_cast<VNodePoint *>(VAbstractPattern::getTool(node.GetId()));
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
if (tool->parent() != parent) if (tool->parent() != parent)
@ -2014,15 +2006,15 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem, Qt::UniqueConnection); connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem, Qt::UniqueConnection);
connect(tool, &VNodePoint::TogglePassmarkAngleType, parent, connect(tool, &VNodePoint::TogglePassmarkAngleType, parent,
&VToolSeamAllowance::TogglePassmarkAngleType, Qt::UniqueConnection); &VToolSeamAllowance::TogglePassmarkAngleType, Qt::UniqueConnection);
connect(tool, &VNodePoint::TogglePassmarkLineType, parent, connect(tool, &VNodePoint::TogglePassmarkLineType, parent, &VToolSeamAllowance::TogglePassmarkLineType,
&VToolSeamAllowance::TogglePassmarkLineType, Qt::UniqueConnection); Qt::UniqueConnection);
connect(tool, &VNodePoint::ResetPieceLabelTemplate, parent, connect(tool, &VNodePoint::ResetPieceLabelTemplate, parent,
&VToolSeamAllowance::ResetPieceLabelTemplate, Qt::UniqueConnection); &VToolSeamAllowance::ResetPieceLabelTemplate, Qt::UniqueConnection);
tool->setParentItem(parent); tool->setParentItem(parent);
tool->SetParentType(ParentType::Item); tool->SetParentType(ParentType::Item);
tool->SetExluded(node.IsExcluded()); tool->SetExluded(node.IsExcluded());
} }
tool->setVisible(not node.IsExcluded());//Hide excluded point tool->setVisible(not node.IsExcluded()); // Hide excluded point
break; break;
} }
case (Tool::NodeArc): case (Tool::NodeArc):
@ -2032,7 +2024,7 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
// Do nothing // Do nothing
break; break;
default: default:
qDebug()<<"Get wrong tool type. Ignore."; qDebug() << "Get wrong tool type. Ignore.";
break; break;
} }
} }
@ -2053,7 +2045,7 @@ void VToolSeamAllowance::InitInternalPaths(const VPiece &detail)
const QVector<quint32> paths = detail.GetInternalPaths(); const QVector<quint32> paths = detail.GetInternalPaths();
for (auto path : paths) for (auto path : paths)
{ {
auto *tool = qobject_cast<VToolPiecePath*>(VAbstractPattern::getTool(path)); auto *tool = qobject_cast<VToolPiecePath *>(VAbstractPattern::getTool(path));
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
if (tool->parent() != this) if (tool->parent() != this)
@ -2114,8 +2106,8 @@ auto VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, co
qreal labelWidth = 0; qreal labelWidth = 0;
qreal labelHeight = 0; qreal labelHeight = 0;
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, pins, labelAngle, labelWidth, labelHeight, const VTextGraphicsItem::MoveTypes type =
pos); FindLabelGeometry(labelData, pins, labelAngle, labelWidth, labelHeight, pos);
if (type & VGrainlineItem::Error) if (type & VGrainlineItem::Error)
{ {
labelItem->hide(); labelItem->hide();
@ -2139,14 +2131,14 @@ auto VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, co
auto VToolSeamAllowance::SelectedTools() const -> QList<VToolSeamAllowance *> auto VToolSeamAllowance::SelectedTools() const -> QList<VToolSeamAllowance *>
{ {
QList<VToolSeamAllowance *> tools; QList<VToolSeamAllowance *> tools;
if(m_sceneDetails) if (m_sceneDetails)
{ {
const QList<QGraphicsItem *> list = m_sceneDetails->selectedItems(); const QList<QGraphicsItem *> list = m_sceneDetails->selectedItems();
if (not list.isEmpty()) if (not list.isEmpty())
{ {
tools.reserve(list.size()); tools.reserve(list.size());
for(auto *item : list) for (auto *item : list)
{ {
auto *tool = qgraphicsitem_cast<VToolSeamAllowance *>(item); auto *tool = qgraphicsitem_cast<VToolSeamAllowance *>(item);
if (tool != nullptr && tool->getId() != m_id) if (tool != nullptr && tool->getId() != m_id)
@ -2182,8 +2174,8 @@ void VToolSeamAllowance::AddPointRecords(VAbstractPattern *doc, QDomElement &dom
QDomElement pinsElement = doc->createElement(tag); QDomElement pinsElement = doc->createElement(tag);
for (auto record : records) for (auto record : records)
{ {
pinsElement.appendChild(doc->CreateElementWithText(VToolSeamAllowance::TagRecord, pinsElement.appendChild(
QString().setNum(record))); doc->CreateElementWithText(VToolSeamAllowance::TagRecord, QString().setNum(record)));
} }
domElement.appendChild(pinsElement); domElement.appendChild(pinsElement);
} }
@ -2236,7 +2228,7 @@ auto VToolSeamAllowance::DuplicateNode(const VPieceNode &node, const VToolSeamAl
VNodeSplinePath::Create(initNodeData); VNodeSplinePath::Create(initNodeData);
break; break;
default: default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO; qDebug() << "May be wrong tool type!!! Ignoring." << Q_FUNC_INFO;
break; break;
} }
return initNodeData.id; return initNodeData.id;
@ -2278,7 +2270,7 @@ auto VToolSeamAllowance::DuplicateCustomSARecords(const QVector<CustomSARecord>
{ {
QVector<CustomSARecord> newRecords; QVector<CustomSARecord> newRecords;
newRecords.reserve(records.size()); newRecords.reserve(records.size());
for(auto record : records) for (auto record : records)
{ {
record.path = DuplicatePiecePath(record.path, initData); record.path = DuplicatePiecePath(record.path, initData);
record.startPoint = replacements.value(record.startPoint, NULL_ID); record.startPoint = replacements.value(record.startPoint, NULL_ID);
@ -2294,7 +2286,7 @@ auto VToolSeamAllowance::DuplicateInternalPaths(const QVector<quint32> &iPaths,
{ {
QVector<quint32> newPaths; QVector<quint32> newPaths;
newPaths.reserve(iPaths.size()); newPaths.reserve(iPaths.size());
for(auto iPath : iPaths) for (auto iPath : iPaths)
{ {
newPaths.append(DuplicatePiecePath(iPath, initData)); newPaths.append(DuplicatePiecePath(iPath, initData));
} }
@ -2307,7 +2299,7 @@ auto VToolSeamAllowance::DuplicatePlaceLabels(const QVector<quint32> &placeLabel
{ {
QVector<quint32> newPlaceLabels; QVector<quint32> newPlaceLabels;
newPlaceLabels.reserve(placeLabels.size()); newPlaceLabels.reserve(placeLabels.size());
for(auto placeLabel : placeLabels) for (auto placeLabel : placeLabels)
{ {
QSharedPointer<VPlaceLabelItem> label = initData.data->GeometricObject<VPlaceLabelItem>(placeLabel); QSharedPointer<VPlaceLabelItem> label = initData.data->GeometricObject<VPlaceLabelItem>(placeLabel);
auto *tool = qobject_cast<VAbstractNode *>(VAbstractPattern::getTool(placeLabel)); auto *tool = qobject_cast<VAbstractNode *>(VAbstractPattern::getTool(placeLabel));
@ -2341,7 +2333,7 @@ auto VToolSeamAllowance::DuplicateNodes(const VPiecePath &path, const VToolSeamA
{ {
QVector<VPieceNode> nodes; QVector<VPieceNode> nodes;
nodes.reserve(path.CountNodes()); nodes.reserve(path.CountNodes());
for (int i = 0; i< path.CountNodes(); ++i) for (int i = 0; i < path.CountNodes(); ++i)
{ {
VPieceNode nodeD = path.at(i); VPieceNode nodeD = path.at(i);
const quint32 oldId = nodeD.GetId(); const quint32 oldId = nodeD.GetId();