diff --git a/.hgignore b/.hgignore index 2e058acbc..828b54ff8 100644 --- a/.hgignore +++ b/.hgignore @@ -25,3 +25,6 @@ latex/ # Ignore file Qt translation. *.qm + +# Ignore Mercurial .orig files +*.orig diff --git a/Valentina.pro b/Valentina.pro index f13d13f7b..9c5f07496 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -78,24 +78,24 @@ CONFIG(debug, debug|release){ -isystem "/usr/include/qt5/QtCore" -isystem "$${UI_DIR}" -isystem "$${MOC_DIR}" \ -isystem "$${RCC_DIR}" \ -O0 -Wall -Wextra -pedantic -Weffc++ -Woverloaded-virtual -Wctor-dtor-privacy \ - -Wnon-virtual-dtor -Wold-style-cast -Wconversion -Winit-self \ + -Wnon-virtual-dtor -Wold-style-cast -Wconversion -Winit-self -Wstack-protector \ -Wunreachable-code -Wcast-align -Wcast-qual -Wdisabled-optimization -Wfloat-equal \ - -Wformat -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k \ + -Wformat=2 -Wimport \ -Winvalid-pch -Wunsafe-loop-optimizations -Wlong-long -Wmissing-format-attribute \ - -Wmissing-include-dirs -Wpacked -Wredundant-decls \ - -Wswitch-default -Wswitch-enum -Wuninitialized -Wunused-parameter -Wvariadic-macros \ - -Wlogical-op -Wnoexcept \ + -Wmissing-include-dirs -Wpacked -Wredundant-decls -Winline \ + -Wswitch-default -Wswitch-enum -Wuninitialized -Wvariadic-macros \ + -Wlogical-op -Wnoexcept -Wmissing-noreturn -Wpointer-arith\ -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -gdwarf-3 } } else { *-g++{#Don't use additional GCC keys on Windows system. - QMAKE_CXXFLAGS += -Og -Wall -Wextra -pedantic + QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic } } }else{ # Release *-g++{ - QMAKE_CXXFLAGS += -O1 + QMAKE_CXXFLAGS += -O2 } DEFINES += QT_NO_DEBUG_OUTPUT @@ -131,6 +131,10 @@ INSTALL_TRANSLATIONS += share/translations/valentina_ru.qm \ share/translations/valentina_he_IL.qm \ share/translations/valentina_fr.qm +INSTALL_STANDARD_MEASHUREMENTS += share/tables/standard/GOST_man_ru.vst + +INSTALL_INDIVIDUAL_MEASHUREMENTS += share/tables/individual/indivindual_ru.vit + unix { #VARIABLES isEmpty(PREFIX) { @@ -147,10 +151,16 @@ pixmaps.path = $$DATADIR/pixmaps/ pixmaps.files += dist/$${TARGET}.png translations.path = $$DATADIR/$${TARGET}/translations/ translations.files = $$INSTALL_TRANSLATIONS +standard.path = $$DATADIR/$${TARGET}/tables/standard/ +standard.files = $$INSTALL_STANDARD_MEASHUREMENTS +individual.path = $$DATADIR/$${TARGET}/tables/individual/ +individual.files = $$INSTALL_INDIVIDUAL_MEASHUREMENTS INSTALLS += target \ desktop \ pixmaps \ - translations + translations \ + standard \ + individual } !isEmpty(TRANSLATIONS): { @@ -187,3 +197,19 @@ for(DIR, INSTALL_TRANSLATIONS) { } copyToDestdir($$tr_path, $$shell_path($$OUT_PWD/$$DESTDIR/translations)) + +for(DIR, INSTALL_STANDARD_MEASHUREMENTS) { + #add these absolute paths to a variable which + #ends up as 'mkcommands = path1 path2 path3 ...' + st_path += $$PWD/$$DIR +} + +copyToDestdir($$st_path, $$shell_path($$OUT_PWD/$$DESTDIR/tables/standard)) + +for(DIR, INSTALL_INDIVIDUAL_MEASHUREMENTS) { + #add these absolute paths to a variable which + #ends up as 'mkcommands = path1 path2 path3 ...' + ind_path += $$PWD/$$DIR +} + +copyToDestdir($$ind_path, $$shell_path($$OUT_PWD/$$DESTDIR/tables/individual)) diff --git a/share/resources/icon.qrc b/share/resources/icon.qrc index 504b28697..64d48ee8e 100644 --- a/share/resources/icon.qrc +++ b/share/resources/icon.qrc @@ -50,5 +50,7 @@ icon/flags/he_IL.png icon/flags/ru.png icon/flags/uk.png + icon/Graduation.png + icon/individual.png diff --git a/share/resources/icon/Graduation.png b/share/resources/icon/Graduation.png new file mode 100644 index 000000000..461bc95d1 Binary files /dev/null and b/share/resources/icon/Graduation.png differ diff --git a/share/resources/icon/individual.png b/share/resources/icon/individual.png new file mode 100644 index 000000000..9081d75c2 Binary files /dev/null and b/share/resources/icon/individual.png differ diff --git a/share/resources/schema.qrc b/share/resources/schema.qrc index ddc4b4e88..9209df5ca 100644 --- a/share/resources/schema.qrc +++ b/share/resources/schema.qrc @@ -1,5 +1,7 @@ schema/pattern.xsd + schema/individual_measurements.xsd + schema/standard_measurements.xsd diff --git a/share/resources/schema/individual_measurements.xsd b/share/resources/schema/individual_measurements.xsd new file mode 100644 index 000000000..55cd7f9a3 --- /dev/null +++ b/share/resources/schema/individual_measurements.xsd @@ -0,0 +1,893 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/share/resources/schema/pattern.xsd b/share/resources/schema/pattern.xsd index 8c8394d6a..1f1b0c00c 100644 --- a/share/resources/schema/pattern.xsd +++ b/share/resources/schema/pattern.xsd @@ -4,19 +4,26 @@ - - - + + + + + + + + + + - + - + @@ -32,51 +39,51 @@ - + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - + + + - - - + + + - + - + @@ -86,21 +93,21 @@ - + - + - - + + @@ -113,31 +120,31 @@ - - - + + + - + - + - - + + - + - - + + - + @@ -149,9 +156,9 @@ - - - + + + @@ -159,10 +166,10 @@ - + - - + + @@ -178,20 +185,20 @@ - - - + + + - - + + - + - + @@ -204,4 +211,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/share/resources/schema/standard_measurements.xsd b/share/resources/schema/standard_measurements.xsd new file mode 100644 index 000000000..4ac6eb0d5 --- /dev/null +++ b/share/resources/schema/standard_measurements.xsd @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/share/tables/individual/indivindual_ru.vit b/share/tables/individual/indivindual_ru.vit new file mode 100644 index 000000000..b7329e774 --- /dev/null +++ b/share/tables/individual/indivindual_ru.vit @@ -0,0 +1,108 @@ + + + ru + + + + 1900-01-01 + male + username@example.com + + + mm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/share/tables/standard/GOST_man_ru.vst b/share/tables/standard/GOST_man_ru.vst new file mode 100644 index 000000000..ca4a1c00a --- /dev/null +++ b/share/tables/standard/GOST_man_ru.vst @@ -0,0 +1,87 @@ + + + Типовые фигуры мужчин 1-й полнотной группы, обхват груди 100 см + mm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/container/calculator.h b/src/container/calculator.h index 6618e310a..00b0fe7ef 100644 --- a/src/container/calculator.h +++ b/src/container/calculator.h @@ -42,8 +42,8 @@ public: * @brief Calculator class constructor. * @param data pointer to a variable container. */ - explicit Calculator(const VContainer *data):errorMsg(0), token(QString()), tok(0), token_type(0), prog(QString()), - index(0), data(data), debugFormula(QString()){} + explicit Calculator(const VContainer *data):errorMsg(nullptr), token(QString()), tok(0), token_type(0), + prog(QString()), index(0), data(data), debugFormula(QString()){} /** * @brief eval calculate formula. * @param prog string of formula. diff --git a/src/container/container.pri b/src/container/container.pri index 5fe8d435f..fcd3ba862 100644 --- a/src/container/container.pri +++ b/src/container/container.pri @@ -1,11 +1,11 @@ SOURCES += \ - src/container/vincrementtablerow.cpp \ src/container/vcontainer.cpp \ src/container/calculator.cpp \ - src/container/vstandardtablerow.cpp + src/container/vmeasurement.cpp \ + src/container/vincrement.cpp HEADERS += \ - src/container/vincrementtablerow.h \ src/container/vcontainer.h \ src/container/calculator.h \ - src/container/vstandardtablerow.h + src/container/vmeasurement.h \ + src/container/vincrement.h diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index ddac8b87a..b108b3b81 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -30,18 +30,16 @@ #include #include +#include "../widgets/vapplication.h" -qint64 VContainer::_id = 0; +quint32 VContainer::_id = 0; VContainer::VContainer() - :base(QHash()), gObjects(QHash()), - standardTable(QHash()), incrementTable(QHash()), + :_size(50), sizeName("Сг"), _height(176), heightName("P"), gObjects(QHash()), + measurements(QHash()), increments(QHash()), lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), - lengthArcs(QHash()), details(QHash()) + lengthArcs(QHash()), details(QHash()) { - SetSize(500); - SetGrowth(1760); - CreateManTableIGroup (); } VContainer &VContainer::operator =(const VContainer &data) @@ -51,10 +49,10 @@ VContainer &VContainer::operator =(const VContainer &data) } VContainer::VContainer(const VContainer &data) - :base(QHash()), gObjects(QHash()), - standardTable(QHash()), incrementTable(QHash()), + :_size(50), sizeName("Сг"), _height(176), heightName("P"), gObjects(QHash()), + measurements(QHash()), increments(QHash()), lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), - lengthArcs(QHash()), details(QHash()) + lengthArcs(QHash()), details(QHash()) { setData(data); } @@ -67,44 +65,40 @@ VContainer::~VContainer() void VContainer::setData(const VContainer &data) { - base = *data.DataBase(); + _size = data.size(); + sizeName = data.SizeName(); + _height = data.height(); + heightName = data.HeightName(); qDeleteAll(gObjects); gObjects.clear(); - const QHash *obj = data.DataGObjects(); + const QHash *obj = data.DataGObjects(); Q_CHECK_PTR(obj); - QHashIterator i(*obj); + QHashIterator i(*obj); while (i.hasNext()) { i.next(); switch (i.value()->getType()) { case (GObject::Arc): - { CopyGObject(data, i.key()); break; - } case (GObject::Point): - { CopyGObject(data, i.key()); break; - } case (GObject::Spline): - { CopyGObject(data, i.key()); break; - } case (GObject::SplinePath): - { CopyGObject(data, i.key()); break; - } default: - qWarning()<<"Don't know how copy this type."; + qDebug()<<"Don't know how copy this type."; + break; } } - standardTable = *data.DataStandardTable(); - incrementTable = *data.DataIncrementTable(); + measurements = *data.DataMeasurements(); + increments = *data.DataIncrements(); lengthLines = *data.DataLengthLines(); lineAngles = *data.DataLineAngles(); lengthSplines = *data.DataLengthSplines(); @@ -112,7 +106,7 @@ void VContainer::setData(const VContainer &data) details = *data.DataDetails(); } -const VGObject *VContainer::GetGObject(qint64 id)const +const VGObject *VContainer::GetGObject(quint32 id)const { return GetObject(gObjects, id); } @@ -143,16 +137,16 @@ val VContainer::GetVariable(const QHash &obj, key id) const } } -const VStandardTableRow VContainer::GetStandardTableCell(const QString &name) const +const VMeasurement VContainer::GetMeasurement(const QString &name) const { Q_ASSERT(name.isEmpty()==false); - return GetVariable(standardTable, name); + return GetVariable(measurements, name); } -const VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const +const VIncrement VContainer::GetIncrement(const QString& name) const { Q_ASSERT(name.isEmpty()==false); - return GetVariable(incrementTable, name); + return GetVariable(increments, name); } qreal VContainer::GetLine(const QString &name) const @@ -179,35 +173,35 @@ qreal VContainer::GetLineAngle(const QString &name) const return GetVariable(lineAngles, name); } -const VDetail VContainer::GetDetail(qint64 id) const +const VDetail VContainer::GetDetail(quint32 id) const { return GetVariable(details, id); } -qint64 VContainer::AddGObject(VGObject *obj) +quint32 VContainer::AddGObject(VGObject *obj) { return AddObject(gObjects, obj); } -qint64 VContainer::AddDetail(VDetail detail) +quint32 VContainer::AddDetail(VDetail detail) { - qint64 id = getNextId(); + quint32 id = getNextId(); details[id] = detail; return id; } -void VContainer::AddIncrementTableRow(const QString &name, VIncrementTableRow row) +void VContainer::AddIncrement(const QString &name, VIncrement incr) { - incrementTable[name] = row; + increments[name] = incr; } -qint64 VContainer::getNextId() +quint32 VContainer::getNextId() { _id++; return _id; } -void VContainer::UpdateId(qint64 newId) +void VContainer::UpdateId(quint32 newId) { if (newId > _id) { @@ -216,7 +210,7 @@ void VContainer::UpdateId(qint64 newId) } template -void VContainer::UpdateObject(QHash &obj, const qint64 &id, val point) +void VContainer::UpdateObject(QHash &obj, const quint32 &id, val point) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_CHECK_PTR(point); @@ -236,10 +230,10 @@ void VContainer::AddLengthSpline(const QString &name, const qreal &value) lengthSplines[name] = value; } -void VContainer::AddLengthArc(const qint64 &id) +void VContainer::AddLengthArc(const quint32 &id) { const VArc * arc = GeometricObject(id); - lengthArcs[arc->name()] = toMM(arc->GetLength()); + lengthArcs[arc->name()] = qApp->fromPixel(arc->GetLength()); } void VContainer::AddLineAngle(const QString &name, const qreal &value) @@ -248,33 +242,42 @@ void VContainer::AddLineAngle(const QString &name, const qreal &value) lineAngles[name] = value; } -qreal VContainer::GetValueStandardTableCell(const QString& name) const +qreal VContainer::GetValueStandardTableRow(const QString& name) const { - VStandardTableRow cell = GetStandardTableCell(name); - qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; - qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth(); - return value; + const VMeasurement m = GetMeasurement(name); + if (qApp->patternType() == Pattern::Individual) + { + return m.GetValue(); + } + else + { + return m.GetValue(size(), height()); + } } qreal VContainer::GetValueIncrementTableRow(const QString& name) const { - VIncrementTableRow cell = GetIncrementTableRow(name); - qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; - qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth(); - return value; + const VIncrement icr = GetIncrement(name); + if (qApp->patternType() == Pattern::Individual) + { + return icr.GetValue(); + } + else + { + return icr.GetValue(size(), height()); + } } void VContainer::Clear() { _id = 0; - standardTable.clear(); - incrementTable.clear(); + measurements.clear(); + increments.clear(); lengthLines.clear(); lengthArcs.clear(); lineAngles.clear(); details.clear(); + lengthSplines.clear(); ClearGObjects(); } @@ -291,11 +294,11 @@ void VContainer::ClearCalculationGObjects() { if (gObjects.size()>0) { - QHashIterator i(gObjects); + QHashIterator i(gObjects); while (i.hasNext()) { i.next(); - if (i.value()->getMode() == Draw::Calculation) + if (i.value()->getMode() == Valentina::Calculation) { delete i.value(); gObjects.remove(i.key()); @@ -306,18 +309,22 @@ void VContainer::ClearCalculationGObjects() qreal VContainer::FindVar(const QString &name, bool *ok)const { - if (base.contains(name)) + if (sizeName == name) { *ok = true; - return base.value(name); + return _size; } - - if (standardTable.contains(name)) + if (heightName == name) { *ok = true; - return GetValueStandardTableCell(name); + return _height; } - if (incrementTable.contains(name)) + if (measurements.contains(name)) + { + *ok = true; + return GetValueStandardTableRow(name); + } + if (increments.contains(name)) { *ok = true; return GetValueIncrementTableRow(name); @@ -346,27 +353,27 @@ qreal VContainer::FindVar(const QString &name, bool *ok)const return 0; } -void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId) +void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPointId) { QString nameLine = GetNameLine(firstPointId, secondPointId); const VPointF *first = GeometricObject(firstPointId); const VPointF *second = GeometricObject(secondPointId); - AddLengthLine(nameLine, toMM(QLineF(first->toQPointF(), second->toQPointF()).length())); + AddLengthLine(nameLine, qApp->fromPixel(QLineF(first->toQPointF(), second->toQPointF()).length())); nameLine = GetNameLineAngle(firstPointId, secondPointId); AddLineAngle(nameLine, QLineF(first->toQPointF(), second->toQPointF()).angle()); } template -qint64 VContainer::AddObject(QHash &obj, val value) +quint32 VContainer::AddObject(QHash &obj, val value) { Q_CHECK_PTR(value); - qint64 id = getNextId(); + quint32 id = getNextId(); value->setId(id); obj[id] = value; return id; } -QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const +QString VContainer::GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const { const VPointF *first = GeometricObject(firstPoint); const VPointF *second = GeometricObject(secondPoint); @@ -374,7 +381,7 @@ QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPo return QString("Line_%1_%2").arg(first->name(), second->name()); } -QString VContainer::GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint) const +QString VContainer::GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const { const VPointF *first = GeometricObject(firstPoint); const VPointF *second = GeometricObject(secondPoint); @@ -382,12 +389,12 @@ QString VContainer::GetNameLineAngle(const qint64 &firstPoint, const qint64 &sec return QString("AngleLine_%1_%2").arg(first->name(), second->name()); } -void VContainer::UpdateGObject(qint64 id, VGObject* obj) +void VContainer::UpdateGObject(quint32 id, VGObject* obj) { UpdateObject(gObjects, id, obj); } -void VContainer::UpdateDetail(qint64 id, const VDetail &detail) +void VContainer::UpdateDetail(quint32 id, const VDetail &detail) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); details[id] = detail; @@ -399,65 +406,3 @@ void VContainer::AddLengthLine(const QString &name, const qreal &value) Q_ASSERT(name.isEmpty() == false); lengthLines[name] = value; } - -void VContainer::CreateManTableIGroup () -{ - AddStandardTableCell("Pkor", VStandardTableRow(84, 0, 3)); - AddStandardTableCell("Vtos", VStandardTableRow(1450, 2, 51)); - AddStandardTableCell("Vtosh", VStandardTableRow(1506, 2, 54)); - AddStandardTableCell("Vpt", VStandardTableRow(1438, 3, 52)); - AddStandardTableCell("Vst", VStandardTableRow(1257, -1, 49)); - AddStandardTableCell("Vlt", VStandardTableRow(1102, 0, 43)); - AddStandardTableCell("Vk", VStandardTableRow(503, 0, 22)); - AddStandardTableCell("Vsht", VStandardTableRow(1522, 2, 54)); - AddStandardTableCell("Vzy", VStandardTableRow(1328, 0, 49)); - AddStandardTableCell("Vlop", VStandardTableRow(1320, 0, 49)); - AddStandardTableCell("Vps", VStandardTableRow(811, -1, 36)); - AddStandardTableCell("Ssh", VStandardTableRow(202, 4, 1)); - AddStandardTableCell("SgI", VStandardTableRow(517, 18, 2)); - AddStandardTableCell("SgII", VStandardTableRow(522, 19, 1)); - AddStandardTableCell("SgIII", VStandardTableRow(500, 20, 0)); - AddStandardTableCell("SbI", VStandardTableRow(482, 12, 6)); - AddStandardTableCell("Obed", VStandardTableRow(566, 18, 6)); - AddStandardTableCell("Ok", VStandardTableRow(386, 8, 8)); - AddStandardTableCell("Oi", VStandardTableRow(380, 8, 6)); - AddStandardTableCell("Osch", VStandardTableRow(234, 4, 4)); - AddStandardTableCell("Dsb", VStandardTableRow(1120, 0, 44)); - AddStandardTableCell("Dsp", VStandardTableRow(1110, 0, 43)); - AddStandardTableCell("Dn", VStandardTableRow(826, -3, 37)); - AddStandardTableCell("Dps", VStandardTableRow(316, 4, 7)); - AddStandardTableCell("Dpob", VStandardTableRow(783, 14, 15)); - AddStandardTableCell("Ds", VStandardTableRow(260, 1, 6)); - AddStandardTableCell("Op", VStandardTableRow(316, 12, 0)); - AddStandardTableCell("Ozap", VStandardTableRow(180, 4, 0)); - AddStandardTableCell("Pkis", VStandardTableRow(250, 4, 0)); - AddStandardTableCell("SHp", VStandardTableRow(160, 1, 4)); - AddStandardTableCell("Dlych", VStandardTableRow(500, 2, 15)); - AddStandardTableCell("Dzap", VStandardTableRow(768, 2, 24)); - AddStandardTableCell("DIIIp", VStandardTableRow(970, 2, 29)); - AddStandardTableCell("Vprp", VStandardTableRow(214, 3, 3)); - AddStandardTableCell("Vg", VStandardTableRow(262, 8, 3)); - AddStandardTableCell("Dtp", VStandardTableRow(460, 7, 9)); - AddStandardTableCell("Dp", VStandardTableRow(355, 5, 5)); - AddStandardTableCell("Vprz", VStandardTableRow(208, 3, 5)); - AddStandardTableCell("Dts", VStandardTableRow(438, 2, 10)); - AddStandardTableCell("DtsI", VStandardTableRow(469, 2, 10)); - AddStandardTableCell("Dvcht", VStandardTableRow(929, 9, 19)); - AddStandardTableCell("SHg", VStandardTableRow(370, 14, 4)); - AddStandardTableCell("Cg", VStandardTableRow(224, 6, 0)); - AddStandardTableCell("SHs", VStandardTableRow(416, 10, 2)); - AddStandardTableCell("dpzr", VStandardTableRow(121, 6, 0)); - AddStandardTableCell("Ogol", VStandardTableRow(576, 4, 4)); - AddStandardTableCell("Ssh1", VStandardTableRow(205, 5, 0)); - - //TODO Posible duplicate. Need check. - //AddStandardTableCell("St", VStandardTableRow(410, 20, 0)); - AddStandardTableCell("St", VStandardTableRow(390, 20, 0)); - - AddStandardTableCell("Drzap", VStandardTableRow(594, 3, 19)); - AddStandardTableCell("DbII", VStandardTableRow(1020, 0, 44)); - - //TODO Posible duplicate. Need check. - //AddStandardTableCell("Sb", VStandardTableRow(504, 15, 4)); - AddStandardTableCell("Sb", VStandardTableRow(492, 15, 5)); -} diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index 87508a6b8..6ccf5c1e1 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -29,8 +29,8 @@ #ifndef VCONTAINER_H #define VCONTAINER_H -#include "vstandardtablerow.h" -#include "vincrementtablerow.h" +#include "vmeasurement.h" +#include "vincrement.h" #include "../geometry/varc.h" #include "../geometry/vsplinepath.h" #include "../geometry/vdetail.h" @@ -62,10 +62,9 @@ public: VContainer(const VContainer &data); ~VContainer(); template - void CopyGObject(const VContainer &data, const qint64 &id) + void CopyGObject(const VContainer &data, const quint32 &id) { T *obj = new T(*data.GeometricObject(id)); - Q_CHECK_PTR(obj); UpdateGObject(id, obj); } /** @@ -74,9 +73,9 @@ public: */ void setData(const VContainer &data); template - const T GeometricObject(qint64 id) const + const T GeometricObject(const quint32 &id) const { - VGObject *gObj = 0; + VGObject *gObj = nullptr; if (gObjects.contains(id)) { gObj = gObjects.value(id); @@ -84,10 +83,21 @@ public: else { throw VExceptionBadId(tr("Can't find object"), id); + return nullptr; } - T obj = dynamic_cast(gObj); - Q_CHECK_PTR(obj); - return obj; + + try + { + T obj = dynamic_cast(gObj); + Q_CHECK_PTR(obj); + return obj; + } + catch (const std::bad_alloc &) + { + throw VExceptionBadId(tr("Can't cast object"), id); + return nullptr; + } + return nullptr; } /** @@ -95,19 +105,19 @@ public: * @param id id of point * @return point */ - const VGObject *GetGObject(qint64 id) const; + const VGObject *GetGObject(quint32 id) const; /** - * @brief GetStandardTableCell return standard table row by name - * @param name name of standard table row - * @return row of standard table + * @brief GetMeasurement return measurement by name + * @param name short measurement name + * @return measurement */ - const VStandardTableRow GetStandardTableCell(const QString& name) const; + const VMeasurement GetMeasurement(const QString& name) const; /** - * @brief GetIncrementTableRow return increment table row by name + * @brief GetIncrement return increment table row by name * @param name name of increment table row - * @return row of increment table + * @return increment */ - const VIncrementTableRow GetIncrementTableRow(const QString& name) const; + const VIncrement GetIncrement(const QString& name) const; /** * @brief GetLine return length of line by name * @param name name of line @@ -137,37 +147,36 @@ public: * @param id id of detail * @return detail */ - const VDetail GetDetail(qint64 id) const; + const VDetail GetDetail(quint32 id) const; /** * @brief getId return current id * @return current id */ - static qint64 getId() {return _id;} + static quint32 getId() {return _id;} /** * @brief AddPoint add new point to container * @param point new point * @return return id of new point in container */ - qint64 AddGObject(VGObject *obj); + quint32 AddGObject(VGObject *obj); /** * @brief AddDetail add new detail to container * @param detail new detail * @return return id of new detail in container */ - qint64 AddDetail(VDetail detail); + quint32 AddDetail(VDetail detail); /** - * @brief AddStandardTableCell add new row of standard table - * @param name name of row of standard table - * @param cell row of standard table + * @brief AddMeasurement add new measurement + * @param name short measurement name + * @param row measurement */ - inline void AddStandardTableCell(const QString& name, const VStandardTableRow &cell) - {standardTable[name] = cell;} + void AddMeasurement(const QString& name, const VMeasurement &m); /** - * @brief AddIncrementTableRow add new row of increment table + * @brief AddIncrement add new row of increment table * @param name name of new row of increment table * @param row new row of increment table */ - void AddIncrementTableRow(const QString& name, VIncrementTableRow row); + void AddIncrement(const QString& name, VIncrement incr); /** * @brief AddLengthLine add length of line to container * @param name name of line @@ -184,7 +193,7 @@ public: * @brief AddLengthArc add length of arc to container * @param id id of arc */ - void AddLengthArc(const qint64 &id); + void AddLengthArc(const quint32 &id); /** * @brief AddLineAngle add angle of line to container * @param name name of line angle @@ -197,7 +206,7 @@ public: * @param secondPointId id of second point of line * @param mode mode of line */ - void AddLine(const qint64 &firstPointId, const qint64 &secondPointId); + void AddLine(const quint32 &firstPointId, const quint32 &secondPointId); /** * @brief GetNameLine return name of line * @param firstPoint id of first point of line @@ -205,7 +214,7 @@ public: * @return name of line */ // cppcheck-suppress functionStatic - QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const; + QString GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const; /** * @brief GetNameLineAngle return name of line angle * @param firstPoint id of first point of line @@ -213,39 +222,37 @@ public: * @return name of angle of line */ // cppcheck-suppress functionStatic - QString GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint) const; + QString GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const; /** * @brief UpdatePoint update point by id * @param id id of existing point * @param point point */ - void UpdateGObject(qint64 id, VGObject* obj); + void UpdateGObject(quint32 id, VGObject* obj); /** * @brief UpdateDetail update detail by id * @param id id of existing detail * @param detail detail */ - void UpdateDetail(qint64 id, const VDetail &detail); + void UpdateDetail(quint32 id, const VDetail &detail); /** - * @brief UpdateStandardTableCell update standard table row by name - * @param name name of row - * @param cell row of standard table + * @brief UpdateMeasurement update measurement by name + * @param name short measurement name + * @param m measurement */ - inline void UpdateStandardTableCell(const QString& name, VStandardTableRow cell) - {standardTable[name] = cell;} + void UpdateMeasurement(const QString& name, VMeasurement m); /** - * @brief UpdateIncrementTableRow update increment table row by name + * @brief UpdateIncrement update increment table row by name * @param name name of row * @param row row */ - inline void UpdateIncrementTableRow(const QString& name, VIncrementTableRow row) - {incrementTable[name] = row;} + void UpdateIncrement(const QString& name, VIncrement incr); /** - * @brief GetValueStandardTableCell return value of standard table row by name - * @param name name of row - * @return value in mm + * @brief GetValueStandardTableRow return value of measurement by name + * @param name name of measurement + * @return value in measurement units */ - qreal GetValueStandardTableCell(const QString& name) const; + qreal GetValueStandardTableRow(const QString& name) const; /** * @brief GetValueIncrementTableRow return value of increment table row by name * @param name name of row @@ -264,44 +271,49 @@ public: /** * @brief ClearIncrementTable clear increment table */ - inline void ClearIncrementTable() {incrementTable.clear();} + void ClearIncrementTable(); + void ClearMeasurements(); /** * @brief ClearLengthLines clear length lines */ - inline void ClearLengthLines() {lengthLines.clear();} + void ClearLengthLines(); /** * @brief ClearLengthSplines clear length splines */ - inline void ClearLengthSplines() {lengthSplines.clear();} + void ClearLengthSplines(); /** * @brief ClearLengthArcs clear length arcs */ - inline void ClearLengthArcs() {lengthArcs.clear();} + void ClearLengthArcs(); /** * @brief ClearLineAngles clear angles of lines */ - inline void ClearLineAngles() {lineAngles.clear();} - inline void ClearDetails() {details.clear();} + void ClearLineAngles(); + void ClearDetails(); /** * @brief SetSize set value of size - * @param size value of size in mm + * @param size value of size */ - inline void SetSize(qint32 size) {base["Сг"] = size;} + void SetSize(qreal size); + void SetSizeName(const QString &name); /** * @brief SetGrowth set value of growth - * @param growth value of growth in mm + * @param growth value of growth */ - inline void SetGrowth(qint32 growth) {base["Р"] = growth;} + void SetHeight(qreal height); + void SetHeightName(const QString &name); /** * @brief size return size * @return size in mm */ - inline qint32 size() const {return base.value("Сг");} + qreal size() const; + QString SizeName()const; /** - * @brief growth return growth - * @return growth in mm + * @brief height return height + * @return height in pattern units */ - inline qint32 growth() const {return base.value("Р");} + qreal height() const; + QString HeightName()const; /** * @brief FindVar return value of variable by name * @param name name of variable @@ -314,92 +326,83 @@ public: * @param name name of row * @return true if contains */ - inline bool IncrementTableContains(const QString& name) {return incrementTable.contains(name);} + bool IncrementTableContains(const QString& name); /** * @brief getNextId generate next unique id * @return next unique id */ - static qint64 getNextId(); + static quint32 getNextId(); /** * @brief RemoveIncrementTableRow remove row by name from increment table * @param name name of existing row */ - inline void RemoveIncrementTableRow(const QString& name) {incrementTable.remove(name);} + void RemoveIncrementTableRow(const QString& name); /** * @brief data container with datagObjects return container of gObjects * @return pointer on container of gObjects */ - inline const QHash *DataGObjects() const {return &gObjects;} + const QHash *DataGObjects() const; /** - * @brief data container with dataBase return container of data - * @return pointer on container of base data + * @brief DataMeasurements container with measurements. + * @return pointer to measurements. */ - inline const QHash *DataBase() const {return &base;} + const QHash *DataMeasurements() const; /** - * @brief data container with dataStandardTable return container of standard table - * @return pointer on container of standard table - */ - inline const QHash *DataStandardTable() const {return &standardTable;} - /** - * @brief data container with dataIncrementTable return container of increment table + * @brief data container with dataIncrements return container of increment table * @return pointer on container of increment table */ - inline const QHash *DataIncrementTable() const {return &incrementTable;} + const QHash *DataIncrements() const; /** * @brief data container with dataLengthLines return container of lines lengths * @return pointer on container of lines lengths */ - inline const QHash *DataLengthLines() const {return &lengthLines;} + const QHash *DataLengthLines() const; /** * @brief data container with dataLengthSplines return container of splines lengths * @return pointer on container of splines lengths */ - inline const QHash *DataLengthSplines() const {return &lengthSplines;} + const QHash *DataLengthSplines() const; /** * @brief data container with dataLengthArcs return container of arcs length * @return pointer on container of arcs length */ - inline const QHash *DataLengthArcs() const {return &lengthArcs;} + const QHash *DataLengthArcs() const; /** * @brief data container with dataLineAngles return container of angles of line * @return pointer on container of angles of line */ - inline const QHash *DataLineAngles() const {return &lineAngles;} + const QHash *DataLineAngles() const; /** * @brief data container with dataDetails return container of details * @return pointer on container of details */ - inline const QHash *DataDetails() const {return &details;} + const QHash *DataDetails() const; /** * @brief UpdateId update id. If new id bigger when current save new like current. * @param newId id */ - static void UpdateId(qint64 newId); - /** - * @brief CreateManTableIGroup generate man standard table of measurements - */ - void CreateManTableIGroup (); + static void UpdateId(quint32 newId); private: /** * @brief _id current id. New object will have value +1. For empty class equal 0. */ - static qint64 _id; - /** - * @brief base container of base data (size and growth) - */ - QHash base; + static quint32 _id; + qreal _size; + QString sizeName; + qreal _height; + QString heightName; /** * @brief gObjects graphicals objects of pattern. */ - QHash gObjects; + QHash gObjects; /** - * @brief standardTable container of standard table rows + * @brief measurements container of measurements. */ - QHash standardTable; + QHash measurements; /** - * @brief incrementTable + * @brief increments */ - QHash incrementTable; + QHash increments; /** * @brief lengthLines container of lines lengths */ @@ -419,7 +422,7 @@ private: /** * @brief details container of details */ - QHash details; + QHash details; template /** * @brief GetObject return object from container @@ -445,7 +448,7 @@ private: * @param id id of existing object * @param point object */ - void UpdateObject(QHash &obj, const qint64 &id, val point); + void UpdateObject(QHash &obj, const quint32 &id, val point); template /** * @brief AddObject add object to container @@ -453,7 +456,147 @@ private: * @param value object * @return id of object in container */ - static qint64 AddObject(QHash &obj, val value); + static quint32 AddObject(QHash &obj, val value); }; +inline void VContainer::AddMeasurement(const QString &name, const VMeasurement &m) +{ + measurements[name] = m; +} + +inline void VContainer::UpdateMeasurement(const QString &name, VMeasurement m) +{ + measurements[name] = m; +} + +inline void VContainer::UpdateIncrement(const QString &name, VIncrement incr) +{ + increments[name] = incr; +} + +inline void VContainer::ClearIncrementTable() +{ + increments.clear(); +} + +inline void VContainer::ClearMeasurements() +{ + measurements.clear(); +} + +inline void VContainer::ClearLengthLines() +{ + lengthLines.clear(); +} + +inline void VContainer::ClearLengthSplines() +{ + lengthSplines.clear(); +} + +inline void VContainer::ClearLengthArcs() +{ + lengthArcs.clear(); +} + +inline void VContainer::ClearLineAngles() +{ + lineAngles.clear(); +} + +inline void VContainer::ClearDetails() +{ + details.clear(); +} + +inline void VContainer::SetSize(qreal size) +{ + _size = size; +} + +inline void VContainer::SetSizeName(const QString &name) +{ + sizeName = name; +} + +inline void VContainer::SetHeight(qreal height) +{ + _height = height; +} + +inline void VContainer::SetHeightName(const QString &name) +{ + heightName = name; +} + +inline qreal VContainer::size() const +{ + return _size; +} + +inline QString VContainer::SizeName() const +{ + return sizeName; +} + +inline qreal VContainer::height() const +{ + return _height; +} + +inline QString VContainer::HeightName() const +{ + return heightName; +} + +inline bool VContainer::IncrementTableContains(const QString &name) +{ + return increments.contains(name); +} + +inline void VContainer::RemoveIncrementTableRow(const QString &name) +{ + increments.remove(name); +} + +inline const QHash *VContainer::DataGObjects() const +{ + return &gObjects; +} + +inline const QHash *VContainer::DataMeasurements() const +{ + return &measurements; +} + +inline const QHash *VContainer::DataIncrements() const +{ + return &increments; +} + +inline const QHash *VContainer::DataLengthLines() const +{ + return &lengthLines; +} + +inline const QHash *VContainer::DataLengthSplines() const +{ + return &lengthSplines; +} + +inline const QHash *VContainer::DataLengthArcs() const +{ + return &lengthArcs; +} + +inline const QHash *VContainer::DataLineAngles() const +{ + return &lineAngles; +} + +inline const QHash *VContainer::DataDetails() const +{ + return &details; +} + #endif // VCONTAINER_H diff --git a/src/container/vincrementtablerow.cpp b/src/container/vincrement.cpp similarity index 68% rename from src/container/vincrementtablerow.cpp rename to src/container/vincrement.cpp index 7b7b00655..bcabed46c 100644 --- a/src/container/vincrementtablerow.cpp +++ b/src/container/vincrement.cpp @@ -26,10 +26,22 @@ ** *************************************************************************/ -#include "vincrementtablerow.h" +#include "vincrement.h" -VIncrementTableRow::VIncrementTableRow() - :id(0), base(0), ksize(0), kgrowth(0), description(QString()){} +VIncrement::VIncrement() + :id(0), base(0), ksize(50.0), kheight(176.0), description(QString()){} -VIncrementTableRow::VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth, QString description) - :id(id), base(base), ksize(ksize), kgrowth(kgrowth), description(description){} +VIncrement::VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description) + :id(id), base(base), ksize(ksize), kheight(kheight), description(description){} + +qreal VIncrement::GetValue() const +{ + return base; +} + +qreal VIncrement::GetValue(const qreal &size, const qreal &height) const +{ + const qreal k_size = ( size - 50.0 ) / 2.0; + const qreal k_height = ( height - 176.0 ) / 6.0; + return base + k_size * ksize + k_height * kheight; +} diff --git a/src/container/vincrementtablerow.h b/src/container/vincrement.h similarity index 65% rename from src/container/vincrementtablerow.h rename to src/container/vincrement.h index 493967569..943dc6683 100644 --- a/src/container/vincrementtablerow.h +++ b/src/container/vincrement.h @@ -32,15 +32,15 @@ #include /** - * @brief The VIncrementTableRow class keep data row of increment table + * @brief The VIncrement class keep data row of increment table */ -class VIncrementTableRow +class VIncrement { public: /** * @brief VIncrementTableRow create enpty row */ - VIncrementTableRow(); + VIncrement(); /** * @brief VIncrementTableRow create row * @param id id @@ -49,63 +49,64 @@ public: * @param kgrowth increment in growths * @param description description of increment */ - VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth, - QString description = QString()); + VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description = QString()); /** * @brief getId return id of row * @return id */ - inline qint64 getId() const {return id;} + quint32 getId() const; /** * @brief setId set id of row * @param value id */ - inline void setId(const qint64 &value) {id = value;} + void setId(const quint32 &value); /** * @brief getBase return value in base size and growth * @return value */ - inline qreal getBase() const {return base;} + qreal getBase() const; /** * @brief setBase set value in base size and growth * @param value base value */ - inline void setBase(const qreal &value) {base = value;} + void setBase(const qreal &value); /** * @brief getKsize return increment in sizes * @return increment */ - inline qreal getKsize() const {return ksize;} + qreal getKsize() const; /** * @brief setKsize set increment in sizes * @param value value of increment */ - inline void setKsize(const qreal &value) {ksize = value;} + void setKsize(const qreal &value); /** - * @brief getKgrowth return increment in growths + * @brief getKheight return increment in growths * @return increment */ - inline qreal getKgrowth() const {return kgrowth;} + qreal getKheight() const; /** - * @brief setKgrowth set increment in growths + * @brief setKheight set increment in growths * @param value value of increment */ - inline void setKgrowth(const qreal &value) {kgrowth = value;} + void setKheight(const qreal &value); /** * @brief getDescription return description * @return description */ - inline QString getDescription() const {return description;} + QString getDescription() const; /** * @brief setDescription set description for row * @param value description */ - inline void setDescription(const QString &value) {description = value;} + void setDescription(const QString &value); + qreal GetValue() const; + qreal GetValue(const qreal &size, const qreal &height) const; private: /** * @brief id identificator */ - qint64 id; + quint32 id; /** * @brief base value in base size and growth */ @@ -117,11 +118,61 @@ private: /** * @brief kgrowth increment in growths */ - qreal kgrowth; + qreal kheight; /** * @brief description description of increment */ QString description; }; +inline quint32 VIncrement::getId() const +{ + return id; +} + +inline void VIncrement::setId(const quint32 &value) +{ + id = value; +} + +inline qreal VIncrement::getBase() const +{ + return base; +} + +inline void VIncrement::setBase(const qreal &value) +{ + base = value; +} + +inline qreal VIncrement::getKsize() const +{ + return ksize; +} + +inline void VIncrement::setKsize(const qreal &value) +{ + ksize = value; +} + +inline qreal VIncrement::getKheight() const +{ + return kheight; +} + +inline void VIncrement::setKheight(const qreal &value) +{ + kheight = value; +} + +inline QString VIncrement::getDescription() const +{ + return description; +} + +inline void VIncrement::setDescription(const QString &value) +{ + description = value; +} + #endif // VINCREMENTTABLEROW_H diff --git a/src/container/vmeasurement.cpp b/src/container/vmeasurement.cpp new file mode 100644 index 000000000..3aa743ce6 --- /dev/null +++ b/src/container/vmeasurement.cpp @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vstandardtablecell.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vmeasurement.h" + +VMeasurement::VMeasurement() + :base(0), ksize(50.0), kheight(176.0), gui_text(QString()), number(QString()), virtualM(false), + _tagName(QString()) +{ + +} + +VMeasurement::VMeasurement(const qreal &base, const qreal &ksize, const qreal &kgrowth, + const QString &gui_text, const QString &number, const QString &tagName) + :base(base), ksize(ksize), kheight(kgrowth), gui_text(gui_text), number(number), virtualM(false), + _tagName(tagName) +{ + +} + +VMeasurement::VMeasurement(const qreal &base, const QString &gui_text, const QString &number, const QString &tagName) + :base(base), ksize(50.0), kheight(176.0), gui_text(gui_text), number(number), virtualM(false), + _tagName(tagName) +{ + +} + +qreal VMeasurement::GetValue() const +{ + return base; +} + +qreal VMeasurement::GetValue(const qreal &size, const qreal &height) const +{ + const qreal k_size = ( size - 50.0 ) / 2.0; + const qreal k_height = ( height - 176.0 ) / 6.0; + return base + k_size * ksize + k_height * kheight; +} + + + + diff --git a/src/container/vstandardtablerow.h b/src/container/vmeasurement.h similarity index 55% rename from src/container/vstandardtablerow.h rename to src/container/vmeasurement.h index 7f6298392..4dab3e8f4 100644 --- a/src/container/vstandardtablerow.h +++ b/src/container/vmeasurement.h @@ -32,15 +32,15 @@ #include /** - * @brief The VStandardTableRow class keep data row of standard table + * @brief The VMeasurement class keep data row of standard table */ -class VStandardTableRow +class VMeasurement { public: /** * @brief VStandardTableRow create empty row */ - VStandardTableRow(); + VMeasurement(); /** * @brief VStandardTableRow create row * @param base value in base size and growth @@ -48,34 +48,45 @@ public: * @param kgrowth increment in growths * @param description description of increment */ - VStandardTableRow(const qint32 &base, const qreal &ksize, const qreal &kgrowth, - const QString &description = QString()); - ~VStandardTableRow(){} + VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight, + const QString &gui_text = QString(), const QString &number = QString(), + const QString &TagName = QString()); + VMeasurement(const qreal &base, const QString &gui_text = QString(), + const QString &number = QString(), const QString &TagName = QString()); + ~VMeasurement(){} /** * @brief GetBase return value in base size and growth * @return value */ - inline qint32 GetBase() const {return base;} + qreal GetBase() const; + void setBase(const qreal &value); /** * @brief GetKsize return increment in sizes * @return increment */ - inline qreal GetKsize() const {return ksize;} + qreal GetKsize() const; /** * @brief GetKgrowth return increment in growths * @return increment */ - inline qreal GetKgrowth() const {return kgrowth;} + qreal GetKheight() const; /** * @brief GetDescription return description * @return description */ - inline QString GetDescription() const {return description;} + QString GetDescription() const; + QString GetNumber() const; + qreal GetValue() const; + qreal GetValue(const qreal &size, const qreal &height) const; + QString TagName() const; + void setTagName(const QString &TagName); + bool Virtual() const; + void setVirtual(bool value); private: /** * @brief base value in base size and growth */ - qint32 base; + qreal base; /** * @brief ksize increment in sizes */ @@ -83,11 +94,64 @@ private: /** * @brief kgrowth increment in growths */ - qreal kgrowth; + qreal kheight; /** * @brief description description measurement */ - QString description; + QString gui_text; + QString number; + bool virtualM; + QString _tagName; }; +inline qreal VMeasurement::GetBase() const +{ + return base; +} + +inline void VMeasurement::setBase(const qreal &value) +{ + base = value; +} + +inline qreal VMeasurement::GetKsize() const +{ + return ksize; +} + +inline qreal VMeasurement::GetKheight() const +{ + return kheight; +} + +inline QString VMeasurement::GetDescription() const +{ + return gui_text; +} + +inline QString VMeasurement::GetNumber() const +{ + return number; +} + +inline QString VMeasurement::TagName() const +{ + return _tagName; +} + +inline void VMeasurement::setTagName(const QString &tagName) +{ + _tagName = tagName; +} + +inline bool VMeasurement::Virtual() const +{ + return virtualM; +} + +inline void VMeasurement::setVirtual(bool value) +{ + virtualM = value; +} + #endif // VSTANDARDTABLEROW_H diff --git a/src/dialogs/configdialog.cpp b/src/dialogs/app/configdialog.cpp similarity index 88% rename from src/dialogs/configdialog.cpp rename to src/dialogs/app/configdialog.cpp index 1cfdb228b..a5e1a1244 100644 --- a/src/dialogs/configdialog.cpp +++ b/src/dialogs/app/configdialog.cpp @@ -29,10 +29,9 @@ #include "configdialog.h" ConfigDialog::ConfigDialog(QWidget *parent) : - QDialog(parent), contentsWidget(0), pagesWidget(0), configurationPage(0), patternPage(0) + QDialog(parent), contentsWidget(nullptr), pagesWidget(nullptr), configurationPage(nullptr), patternPage(nullptr) { contentsWidget = new QListWidget; - Q_CHECK_PTR(contentsWidget); contentsWidget->setViewMode(QListView::IconMode); contentsWidget->setIconSize(QSize(96, 84)); contentsWidget->setMovement(QListView::Static); @@ -41,20 +40,14 @@ ConfigDialog::ConfigDialog(QWidget *parent) : contentsWidget->setSpacing(12); pagesWidget = new QStackedWidget; - Q_CHECK_PTR(pagesWidget); configurationPage = new ConfigurationPage(); - Q_CHECK_PTR(configurationPage); pagesWidget->addWidget(configurationPage); patternPage = new PatternPage(); - Q_CHECK_PTR(patternPage); pagesWidget->addWidget(patternPage); QPushButton *applyButton = new QPushButton(tr("Apply")); - Q_CHECK_PTR(applyButton); QPushButton *canselButton = new QPushButton(tr("&Cancel")); - Q_CHECK_PTR(canselButton); QPushButton *okButton = new QPushButton(tr("&Ok")); - Q_CHECK_PTR(okButton); createIcons(); contentsWidget->setCurrentRow(0); @@ -64,19 +57,16 @@ ConfigDialog::ConfigDialog(QWidget *parent) : connect(okButton, &QPushButton::clicked, this, &ConfigDialog::Ok); QHBoxLayout *horizontalLayout = new QHBoxLayout; - Q_CHECK_PTR(horizontalLayout); horizontalLayout->addWidget(contentsWidget); horizontalLayout->addWidget(pagesWidget, 1); QHBoxLayout *buttonsLayout = new QHBoxLayout; - Q_CHECK_PTR(buttonsLayout); buttonsLayout->addStretch(1); buttonsLayout->addWidget(applyButton); buttonsLayout->addWidget(canselButton); buttonsLayout->addWidget(okButton); QVBoxLayout *mainLayout = new QVBoxLayout; - Q_CHECK_PTR(mainLayout); mainLayout->addLayout(horizontalLayout); mainLayout->addStretch(1); mainLayout->addSpacing(12); @@ -107,14 +97,12 @@ void ConfigDialog::closeEvent(QCloseEvent *event) void ConfigDialog::createIcons() { QListWidgetItem *configButton = new QListWidgetItem(contentsWidget); - Q_CHECK_PTR(configButton); configButton->setIcon(QIcon("://icon/config.png")); configButton->setText(tr("Configuration")); configButton->setTextAlignment(Qt::AlignHCenter); configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); QListWidgetItem *patternButton = new QListWidgetItem(contentsWidget); - Q_CHECK_PTR(patternButton); patternButton->setIcon(QIcon("://icon/pattern_config.png")); patternButton->setText(tr("Pattern")); patternButton->setTextAlignment(Qt::AlignHCenter); @@ -125,12 +113,12 @@ void ConfigDialog::createIcons() void ConfigDialog::Apply() { - switch(contentsWidget->currentRow()) + switch (contentsWidget->currentRow()) { - case(0): + case (0): configurationPage->Apply(); break; - case(1): + case (1): patternPage->Apply(); break; default: diff --git a/src/dialogs/configdialog.h b/src/dialogs/app/configdialog.h similarity index 97% rename from src/dialogs/configdialog.h rename to src/dialogs/app/configdialog.h index 9acc653aa..d1bfef44f 100644 --- a/src/dialogs/configdialog.h +++ b/src/dialogs/app/configdialog.h @@ -40,7 +40,7 @@ class ConfigDialog : public QDialog { Q_OBJECT public: - explicit ConfigDialog(QWidget *parent = 0); + explicit ConfigDialog(QWidget *parent = nullptr); public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); protected: diff --git a/src/dialogs/app/dialoghistory.cpp b/src/dialogs/app/dialoghistory.cpp new file mode 100644 index 000000000..5c21887d8 --- /dev/null +++ b/src/dialogs/app/dialoghistory.cpp @@ -0,0 +1,437 @@ +/************************************************************************ + ** + ** @file dialoghistory.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialoghistory.h" +#include "ui_dialoghistory.h" +#include "../../geometry/varc.h" +#include "../../geometry/vspline.h" +#include "../../geometry/vsplinepath.h" +#include "../../tools/vabstracttool.h" +#include "../../tools/drawTools/vtoolcutspline.h" +#include "../../tools/drawTools/vtoolcutsplinepath.h" +#include "../../tools/drawTools/vtoolcutarc.h" +#include +#include + +DialogHistory::DialogHistory(VContainer *data, VPattern *doc, QWidget *parent) + :DialogTool(data, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), + cursorToolRecordRow(0) +{ + ui->setupUi(this); + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogHistory::DialogAccepted); + FillTable(); + InitialTable(); + connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked); + connect(this, &DialogHistory::ShowHistoryTool, doc, &VPattern::ShowHistoryTool); + connect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor); + connect(doc, &VPattern::patternChanged, this, &DialogHistory::UpdateHistory); + connect(doc, &VPattern::ChangedActivDraw, this, &DialogHistory::UpdateHistory); + ShowPoint(); +} + +DialogHistory::~DialogHistory() +{ + delete ui; +} + +void DialogHistory::DialogAccepted() +{ + QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); + quint32 id = qvariant_cast(item->data(Qt::UserRole)); + emit ShowHistoryTool(id, Qt::green, false); + emit DialogClosed(QDialog::Accepted); +} + +void DialogHistory::cellClicked(int row, int column) +{ + if (column == 0) + { + QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); + item->setIcon(QIcon()); + + item = ui->tableWidget->item(row, 0); + cursorRow = row; + item->setIcon(QIcon("://icon/32x32/put_after.png")); + quint32 id = qvariant_cast(item->data(Qt::UserRole)); + disconnect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor); + doc->setCursor(id); + connect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor); + } + else + { + QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); + quint32 id = qvariant_cast(item->data(Qt::UserRole)); + emit ShowHistoryTool(id, Qt::green, false); + + cursorToolRecordRow = row; + item = ui->tableWidget->item(cursorToolRecordRow, 0); + id = qvariant_cast(item->data(Qt::UserRole)); + emit ShowHistoryTool(id, Qt::green, true); + } +} + +void DialogHistory::ChangedCursor(quint32 id) +{ + for (qint32 i = 0; i< ui->tableWidget->rowCount(); ++i) + { + QTableWidgetItem *item = ui->tableWidget->item(i, 0); + quint32 rId = qvariant_cast(item->data(Qt::UserRole)); + if (rId == id) + { + QTableWidgetItem *oldCursorItem = ui->tableWidget->item(cursorRow, 0); + oldCursorItem->setIcon(QIcon()); + cursorRow = i; + item->setIcon(QIcon("://icon/32x32/put_after.png")); + } + } +} + +void DialogHistory::UpdateHistory() +{ + FillTable(); + InitialTable(); +} + +void DialogHistory::FillTable() +{ + ui->tableWidget->clear(); + const QVector *history = doc->getHistory(); + Q_CHECK_PTR(history); + qint32 currentRow = -1; + qint32 count = 0; + ui->tableWidget->setRowCount(history->size()); + for (qint32 i = 0; i< history->size(); ++i) + { + const VToolRecord tool = history->at(i); + if (tool.getNameDraw() != doc->GetNameActivDraw()) + { + continue; + } + const QString historyRecord = Record(tool); + if (historyRecord.isEmpty() ==false) + { + currentRow++; + + { + QTableWidgetItem *item = new QTableWidgetItem(QString()); + item->setTextAlignment(Qt::AlignHCenter); + item->setData(Qt::UserRole, tool.getId()); + ui->tableWidget->setItem(currentRow, 0, item); + } + + QTableWidgetItem *item = new QTableWidgetItem(historyRecord); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setFlags(item->flags() ^ Qt::ItemIsEditable); + ui->tableWidget->setItem(currentRow, 1, item); + ++count; + } + } + ui->tableWidget->setRowCount(count); + if (history->size()>0) + { + cursorRow = currentRow; + QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); + Q_CHECK_PTR(item); + item->setIcon(QIcon("://icon/32x32/put_after.png")); + } + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); +} + +QString DialogHistory::Record(const VToolRecord &tool) +{ + const QDomElement domElement = doc->elementById(QString().setNum(tool.getId())); + if (domElement.isElement() == false) + { + qDebug()<<"Can't find element by id"<GeometricObject(tool.getId())->name(); + return QString(tr("%1 - Base point")).arg(name); + } + case Valentina::EndLineTool: + { + const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); + const QString basePointIdName = data->GeometricObject(basePointId)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%1_%2 - Line from point %1 to point %2")).arg(basePointIdName, toolIdName); + } + case Valentina::LineTool: + { + const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString firstPointIdName = data->GeometricObject(firstPointId)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + return QString(tr("%1_%2 - Line from point %1 to point %2")).arg(firstPointIdName, secondPointIdName); + } + case Valentina::AlongLineTool: + { + const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString basePointIdName = data->GeometricObject(basePointId)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%3 - Point along line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName); + } + case Valentina::ShoulderPointTool: + { + const QString name = data->GeometricObject(tool.getId())->name(); + return QString(tr("%1 - Point of shoulder")).arg(name); + } + case Valentina::NormalTool: + { + const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString basePointIdName = data->GeometricObject(basePointId)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%3 - normal to line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName); + } + case Valentina::BisectorTool: + { + const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const quint32 thirdPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrThirdPoint, "0"); + const QString firstPointIdName = data->GeometricObject(firstPointId)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + const QString thirdPointIdName = data->GeometricObject(thirdPointId)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%4 - bisector of angle %1_%2_%3")).arg(firstPointIdName, secondPointIdName, + thirdPointIdName, toolIdName); + } + case Valentina::LineIntersectTool: + { + const quint32 p1Line1 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line1, "0"); + const quint32 p2Line1 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line1, "0"); + const quint32 p1Line2 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line2, "0"); + const quint32 p2Line2 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line2, "0"); + const QString p1Line1Name = data->GeometricObject(p1Line1)->name(); + const QString p2Line1Name = data->GeometricObject(p2Line1)->name(); + const QString p1Line2Name = data->GeometricObject(p1Line2)->name(); + const QString p2Line2Name = data->GeometricObject(p2Line2)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%5 - intersection of lines %1_%2 and %3_%4")).arg(p1Line1Name, p2Line1Name, + p1Line2Name, p2Line2Name, + toolIdName); + } + case Valentina::SplineTool: + { + const VSpline *spl = data->GeometricObject(tool.getId()); + Q_CHECK_PTR(spl); + const QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); + const QString splP4Name = data->GeometricObject(spl->GetP4().id())->name(); + return QString(tr("Curve %1_%2")).arg(splP1Name, splP4Name); + } + case Valentina::ArcTool: + { + const VArc *arc = data->GeometricObject(tool.getId()); + Q_CHECK_PTR(arc); + const QString arcCenterName = data->GeometricObject(arc->GetCenter().id())->name(); + return QString(tr("Arc with center in point %1")).arg(arcCenterName); + } + case Valentina::SplinePathTool: + { + const VSplinePath *splPath = data->GeometricObject(tool.getId()); + Q_CHECK_PTR(splPath); + const QVector points = splPath->GetSplinePath(); + QString record; + if (points.size() != 0 ) + { + const QString pName = data->GeometricObject(points.at(0).P().id())->name(); + record = QString(tr("Curve point %1")).arg(pName); + if (points.size() > 1) + { + const QString pName = data->GeometricObject(points.last().P().id())->name(); + record.append(QString("_%1").arg(pName)); + } + } + else + { + qDebug()<<"Not enough points in splinepath"<GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0"); + const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString firstPointIdName = data->GeometricObject(firstPointId)->name(); + const QString centerName = data->GeometricObject(center)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")).arg( + centerName, firstPointIdName, secondPointIdName, toolIdName); + } + case Valentina::Height: + { + const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); + const quint32 p1LineId = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0"); + const quint32 p2LineId = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0"); + const QString basePointIdName = data->GeometricObject(basePointId)->name(); + const QString p1LineIdName = data->GeometricObject(p1LineId)->name(); + const QString p2LineIdName = data->GeometricObject(p2LineId)->name(); + return QString(tr("Point of perpendicular from point %1 to line %2_%3")).arg(basePointIdName, + p1LineIdName, + p2LineIdName); + } + case Valentina::Triangle: + { + const quint32 axisP1Id = doc->GetParametrUInt(domElement, VAbstractTool::AttrAxisP1, "0"); + const quint32 axisP2Id = doc->GetParametrUInt(domElement, VAbstractTool::AttrAxisP2, "0"); + const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString axisP1IdName = data->GeometricObject(axisP1Id)->name(); + const QString axisP2IdName = data->GeometricObject(axisP2Id)->name(); + const QString firstPointIdName = data->GeometricObject(firstPointId)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + return QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg(axisP1IdName, axisP2IdName, + firstPointIdName, secondPointIdName); + } + case Valentina::PointOfIntersection: + { + const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString firstPointIdName = data->GeometricObject(firstPointId)->name(); + const QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%1 - point of intersection %2 and %3")).arg(toolIdName, firstPointIdName, + secondPointIdName); + } + case Valentina::CutArcTool: + { + const quint32 arcId = doc->GetParametrUInt(domElement, VToolCutArc::AttrArc, "0"); + const VArc *arc = data->GeometricObject(arcId); + Q_CHECK_PTR(arc); + const QString arcCenterName = data->GeometricObject(arc->GetCenter().id())->name(); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + return QString(tr("%1 - cut arc with center %2")).arg(toolIdName, arcCenterName); + } + case Valentina::CutSplineTool: + { + const quint32 splineId = doc->GetParametrUInt(domElement, VToolCutSpline::AttrSpline, "0"); + const VSpline *spl = data->GeometricObject(splineId); + Q_CHECK_PTR(spl); + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + const QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); + const QString splP4Name = data->GeometricObject(spl->GetP4().id())->name(); + return QString(tr("%1 - cut curve %2_%3")).arg(toolIdName, splP1Name, splP4Name); + } + case Valentina::CutSplinePathTool: + { + const quint32 splinePathId = doc->GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, "0"); + const VSplinePath *splPath = data->GeometricObject(splinePathId); + Q_CHECK_PTR(splPath); + const QVector points = splPath->GetSplinePath(); + QString record; + if (points.size() != 0 ) + { + const QString toolIdName = data->GeometricObject(tool.getId())->name(); + const QString pName = data->GeometricObject(points.at(0).P().id())->name(); + record = QString(tr("%1 - cut curve path %2")).arg(toolIdName, pName); + if (points.size() > 1) + { + const QString pName = data->GeometricObject(points.last().P().id())->name(); + const QString name = QString("_%1").arg(pName); + record.append(name); + } + } + else + { + qDebug()<<"Not enough points in splinepath"<tableWidget->setSortingEnabled(false); + ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(" ")); + ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Tool"))); +} + +void DialogHistory::ShowPoint() +{ + QVector *history = doc->getHistory(); + if (history->size()>0) + { + QTableWidgetItem *item = ui->tableWidget->item(0, 1); + item->setSelected(true); + cursorToolRecordRow = 0; + item = ui->tableWidget->item(0, 0); + quint32 id = qvariant_cast(item->data(Qt::UserRole)); + emit ShowHistoryTool(id, Qt::green, true); + } +} + +void DialogHistory::closeEvent(QCloseEvent *event) +{ + QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); + quint32 id = qvariant_cast(item->data(Qt::UserRole)); + emit ShowHistoryTool(id, Qt::green, false); + DialogTool::closeEvent(event); +} diff --git a/src/dialogs/dialoghistory.h b/src/dialogs/app/dialoghistory.h similarity index 91% rename from src/dialogs/dialoghistory.h rename to src/dialogs/app/dialoghistory.h index 120fff0ee..9b1337df4 100644 --- a/src/dialogs/dialoghistory.h +++ b/src/dialogs/app/dialoghistory.h @@ -29,8 +29,8 @@ #ifndef DIALOGHISTORY_H #define DIALOGHISTORY_H -#include "dialogtool.h" -#include "../xml/vdomdocument.h" +#include "../tools/dialogtool.h" +#include "../../xml/vpattern.h" namespace Ui { @@ -50,7 +50,7 @@ public: * @param doc dom document container * @param parent parent widget */ - DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent = 0); + DialogHistory(VContainer *data, VPattern *doc, QWidget *parent = nullptr); virtual ~DialogHistory(); public slots: /** @@ -67,7 +67,7 @@ public slots: * @brief ChangedCursor changed cursor of input. Cursor show after what record we will insert new object * @param id id of object */ - void ChangedCursor(qint64 id); + void ChangedCursor(quint32 id); /** * @brief UpdateHistory update history table */ @@ -79,7 +79,7 @@ signals: * @param color new color of tool * @param enable true enable selection, false disable selection */ - void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); + void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable); protected: /** * @brief closeEvent handle when windows is closing @@ -95,7 +95,7 @@ private: /** * @brief doc dom document container */ - VDomDocument *doc; + VPattern *doc; /** * @brief cursorRow save number of row where is cursor */ diff --git a/src/dialogs/dialoghistory.ui b/src/dialogs/app/dialoghistory.ui similarity index 100% rename from src/dialogs/dialoghistory.ui rename to src/dialogs/app/dialoghistory.ui diff --git a/src/dialogs/app/dialogincrements.cpp b/src/dialogs/app/dialogincrements.cpp new file mode 100644 index 000000000..1012c1d26 --- /dev/null +++ b/src/dialogs/app/dialogincrements.cpp @@ -0,0 +1,749 @@ +/************************************************************************ + ** + ** @file dialogincrements.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogincrements.h" +#include "ui_dialogincrements.h" +#include "../../widgets/doubledelegate.h" +#include "../../widgets/textdelegate.h" +#include "../../exception/vexception.h" +#include "../../xml/vstandardmeasurements.h" + +#include +#include + +DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent) + :DialogTool(data, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0), m(nullptr) +{ + ui->setupUi(this); + + if (qApp->patternType() == Pattern::Individual) + { + const QString filePath = doc->MPath(); + try + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); + m = new VIndividualMeasurements(data); + m->setContent(filePath); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + emit DialogClosed(QDialog::Rejected); + return; + } + } + + //Same regex in each shema files. Don't forget synchronize. + TextDelegate *textDelegate = new TextDelegate("^([^0-9-*/^+=\\s\\(\\)%:;!]){1,1}([^-*/^+=\\s\\(\\)%:;!]){0,}$", + ui->tableWidgetIncrement); + ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name + DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); + ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value + ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate);// in sizes + ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate);// in heights + + FillMeasurements(); + FillIncrements(); + FillLengthLines(); + FillLengthSplines(); + FillLengthArcs(); + + if (qApp->patternType() == Pattern::Standard) + { + ui->pagePersonalInformation->setVisible(false); + } + else + { + QRegExpValidator *reg = new QRegExpValidator(QRegExp("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")); + ui->lineEditMail->setValidator(reg); + + ui->tableWidgetMeasurements->setColumnHidden( 1, true );// calculated value + ui->tableWidgetMeasurements->setColumnHidden( 3, true );// in sizes + ui->tableWidgetMeasurements->setColumnHidden( 4, true );// in heights + + ui->tableWidgetIncrement->setColumnHidden( 1, true );// calculated value + ui->tableWidgetIncrement->setColumnHidden( 3, true );// in sizes + ui->tableWidgetIncrement->setColumnHidden( 4, true );// in heights + + ui->tableWidgetMeasurements->setItemDelegateForColumn(2, doubleDelegate);// base value + + connect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged); + + ui->lineEditGivenName->setText(m->GivenName()); + ui->lineEditFamilyName->setText(m->FamilyName()); + + ui->comboBoxSex->addItem(tr("male"),QVariant(m->GenderToStr(VIndividualMeasurements::Male))); + ui->comboBoxSex->addItem(tr("female"),QVariant(m->GenderToStr(VIndividualMeasurements::Female))); + qint32 index = ui->comboBoxSex->findData(m->GenderToStr(m->Sex())); + if (index != -1) + { + ui->comboBoxSex->setCurrentIndex(index); + } + + ui->dateEditBirthDate->setDate(m->BirthDate()); + ui->lineEditMail->setText(m->Mail()); + + connect(ui->lineEditGivenName, &QLineEdit::editingFinished, this, &DialogIncrements::SaveGivenName); + connect(ui->lineEditFamilyName, &QLineEdit::editingFinished, this, &DialogIncrements::SaveFamilyName); + connect(ui->lineEditMail, &QLineEdit::editingFinished, this, &DialogIncrements::SaveEmail); + connect(ui->comboBoxSex, static_cast(&QComboBox::currentIndexChanged), this, + &DialogIncrements::SaveSex); + connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &DialogIncrements::SaveBirthDate); + } + + ui->toolBoxMeasurements->setCurrentIndex(1); + + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); + connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); + connect(ui->toolButtonRemove, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonRemove); + + connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VPattern::FullUpdateTree); + connect(this, &DialogIncrements::haveLiteChange, this->doc, &VPattern::haveLiteChange); + connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); + + ui->tabWidget->setCurrentIndex(0); + + connect(ui->toolButtonOpenMeasurements, &QToolButton::clicked, this, &DialogIncrements::OpenTable); +} + +void DialogIncrements::FillMeasurements() +{ + const QHash *table = data->DataMeasurements(); + QHashIterator i(*table); + QMap map; + //Sorting QHash by id + while (i.hasNext()) + { + i.next(); + map.insert(i.key(), i.value()); + } + qint32 currentRow = -1; + QMapIterator iMap(map); + ui->tableWidgetMeasurements->setRowCount ( table->size() ); + while (iMap.hasNext()) + { + iMap.next(); + VMeasurement m = iMap.value(); + currentRow++; + + QTableWidgetItem *item = new QTableWidgetItem(QString(iMap.key())); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setToolTip(m.GetDescription()); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetMeasurements->setItem(currentRow, 0, item); + + if (qApp->patternType() == Pattern::Standard) + { + QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(data->GetValueStandardTableRow(iMap.key()))); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetMeasurements->setItem(currentRow, 1, item); + } + + item = new QTableWidgetItem(QString().setNum(m.GetBase())); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetMeasurements->setItem(currentRow, 2, item); + + if (qApp->patternType() == Pattern::Standard) + { + QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(m.GetKsize())); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetMeasurements->setItem(currentRow, 3, item); + + item = new QTableWidgetItem(QString().setNum(m.GetKheight())); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetMeasurements->setItem(currentRow, 4, item); + } + + item = new QTableWidgetItem(m.GetNumber()); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetMeasurements->setItem(currentRow, 5, item); + } + ui->tableWidgetMeasurements->verticalHeader()->setDefaultSectionSize(20); + ui->tableWidgetMeasurements->resizeColumnsToContents(); + ui->tableWidgetMeasurements->resizeRowsToContents(); +} + +void DialogIncrements::FillIncrements() +{ + const QHash *increments = data->DataIncrements(); + QHashIterator i(*increments); + QMap map; + //Sorting QHash by id + while (i.hasNext()) + { + i.next(); + VIncrement incr = i.value(); + map.insert(incr.getId(), i.key()); + } + + qint32 currentRow = -1; + QMapIterator iMap(map); + while (iMap.hasNext()) + { + iMap.next(); + VIncrement incr = increments->value(iMap.value()); + currentRow++; + ui->tableWidgetIncrement->setRowCount ( increments->size() ); + + QTableWidgetItem *item = new QTableWidgetItem(iMap.value()); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, incr.getId()); + ui->tableWidgetIncrement->setItem(currentRow, 0, item); + + if (qApp->patternType() == Pattern::Standard) + { + item = new QTableWidgetItem(QString().setNum(data->GetValueIncrementTableRow(iMap.value()))); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetIncrement->setItem(currentRow, 1, item); + } + + item = new QTableWidgetItem(QString().setNum(incr.getBase())); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 2, item); + + if (qApp->patternType() == Pattern::Standard) + { + item = new QTableWidgetItem(QString().setNum(incr.getKsize())); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 3, item); + + item = new QTableWidgetItem(QString().setNum(incr.getKheight())); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 4, item); + } + + item = new QTableWidgetItem(incr.getDescription()); + item->setTextAlignment(Qt::AlignLeft); + ui->tableWidgetIncrement->setItem(currentRow, 5, item); + } + if (ui->tableWidgetIncrement->rowCount()>0) + { + ui->toolButtonRemove->setEnabled(true); + } + ui->tableWidgetIncrement->resizeColumnsToContents(); + ui->tableWidgetIncrement->resizeRowsToContents(); + ui->tableWidgetIncrement->setCurrentCell( row, column ); +} + +void DialogIncrements::FillLengthLines() +{ + const QHash *linesTable = data->DataLengthLines(); + QHashIterator iHash(*linesTable); + QMap map; + //Sorting QHash by name + while (iHash.hasNext()) + { + iHash.next(); + map.insert(iHash.key(), iHash.value()); + } + + qint32 currentRow = -1; + QMapIterator i(map); + while (i.hasNext()) + { + i.next(); + qreal length = i.value(); + currentRow++; + ui->tableWidgetLines->setRowCount ( linesTable->size() ); + + QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + ui->tableWidgetLines->setItem(currentRow, 0, item); + + item = new QTableWidgetItem(QString().setNum(length)); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetLines->setItem(currentRow, 1, item); + } + ui->tableWidgetLines->resizeColumnsToContents(); + ui->tableWidgetLines->resizeRowsToContents(); + ui->tableWidgetLines->verticalHeader()->setDefaultSectionSize(20); +} + +void DialogIncrements::FillLengthSplines() +{ + const QHash *splinesTable = data->DataLengthSplines(); + QHashIterator iHash(*splinesTable); + QMap map; + //Sorting QHash by name + while (iHash.hasNext()) + { + iHash.next(); + map.insert(iHash.key(), iHash.value()); + } + + qint32 currentRow = -1; + QMapIterator i(map); + while (i.hasNext()) + { + i.next(); + qreal length = i.value(); + currentRow++; + ui->tableWidgetSplines->setRowCount ( splinesTable->size() ); + + QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); + item->setTextAlignment(Qt::AlignLeft); + item->setFont(QFont("Times", 12, QFont::Bold)); + ui->tableWidgetSplines->setItem(currentRow, 0, item); + + item = new QTableWidgetItem(QString().setNum(length)); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetSplines->setItem(currentRow, 1, item); + } + ui->tableWidgetSplines->resizeColumnsToContents(); + ui->tableWidgetSplines->resizeRowsToContents(); + ui->tableWidgetSplines->verticalHeader()->setDefaultSectionSize(20); +} + +void DialogIncrements::FillLengthArcs() +{ + const QHash *arcsTable = data->DataLengthArcs(); + QHashIterator iHash(*arcsTable); + QMap map; + //Sorting QHash by name + while (iHash.hasNext()) + { + iHash.next(); + map.insert(iHash.key(), iHash.value()); + } + + qint32 currentRow = -1; + QMapIterator i(map); + while (i.hasNext()) + { + i.next(); + qreal length = i.value(); + currentRow++; + ui->tableWidgetArcs->setRowCount ( arcsTable->size() ); + + QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + ui->tableWidgetArcs->setItem(currentRow, 0, item); + + item = new QTableWidgetItem(QString().setNum(length)); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetArcs->setItem(currentRow, 1, item); + } + ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20); + ui->tableWidgetArcs->resizeColumnsToContents(); + ui->tableWidgetArcs->resizeRowsToContents(); +} + +void DialogIncrements::FullUpdateFromFile() +{ + disconnect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged); + ui->tableWidgetMeasurements->clearContents(); + FillMeasurements(); + connect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged); + + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->clearContents(); + FillIncrements(); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); + + ui->tableWidgetLines->clearContents(); + FillLengthLines(); + + ui->tableWidgetSplines->clearContents(); + FillLengthSplines(); + + ui->tableWidgetArcs->clearContents(); + FillLengthArcs(); +} + +void DialogIncrements::SaveGivenName() +{ + m->setGivenName(ui->lineEditGivenName->text()); + if (m->SaveDocument(doc->MPath()) == false) + { + qDebug()<<"Can't save GivenName"; + } +} + +void DialogIncrements::SaveFamilyName() +{ + + m->setFamilyName(ui->lineEditFamilyName->text()); + if (m->SaveDocument(doc->MPath()) == false) + { + qDebug()<<"Can't save FamilyName"; + } +} + +void DialogIncrements::SaveEmail() +{ + m->setMail(ui->lineEditMail->text()); + if (m->SaveDocument(doc->MPath()) == false) + { + qDebug()<<"Can't save Email"; + } +} + +void DialogIncrements::SaveSex(int index) +{ + m->setSex(m->StrToGender(ui->comboBoxSex->itemData(index).toString())); + if (m->SaveDocument(doc->MPath()) == false) + { + qDebug()<<"Can't save Sex"; + } +} + +void DialogIncrements::SaveBirthDate(const QDate & date) +{ + m->setBirthDate(date); + if (m->SaveDocument(doc->MPath()) == false) + { + qDebug()<<"Can't save BirthDate"; + } +} + +void DialogIncrements::OpenTable() +{ + QString text = tr("Measurements use different units than pattern. This pattern required measurements in %1") + .arg(doc->UnitsToStr(qApp->patternUnit())); + if (qApp->patternType() == Pattern::Individual) + { + const QString filter(tr("Individual measurements (*.vit)")); + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); + if (filePath.isEmpty()) + { + return; + } + + VIndividualMeasurements *m1 = nullptr; + try + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); + + m1 = new VIndividualMeasurements(data); + m1->setContent(filePath); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + delete m1; + emit DialogClosed(QDialog::Rejected); + return; + } + Valentina::Units mUnit = m1->Unit(); + if (qApp->patternUnit() != mUnit) + { + QMessageBox::critical(this, tr("Wrong units."), text); + delete m1; + return; + } + delete m; + m = m1; + data->ClearMeasurements(); + m->Measurements(); + emit FullUpdateTree(); + + doc->SetPath(filePath); + emit haveLiteChange(); + } + else + { + const QString filter(tr("Standard measurements (*.vst)")); + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); + if (filePath.isEmpty()) + { + return; + } + + VStandardMeasurements *m1 = nullptr; + try + { + VDomDocument::ValidateXML("://schema/standard_measurements.xsd", filePath); + + m1 = new VStandardMeasurements(data); + m1->setContent(filePath); + Valentina::Units mUnit = m1->Unit(); + if (qApp->patternUnit() != mUnit) + { + QMessageBox::critical(this, tr("Wrong units."), text); + delete m1; + return; + } + m1->SetSize(); + m1->SetHeight(); + data->ClearMeasurements(); + m1->Measurements(); + delete m1; + emit FullUpdateTree(); + + doc->SetPath(filePath); + emit haveLiteChange(); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + delete m1; + emit DialogClosed(QDialog::Rejected); + return; + } + } +} + +void DialogIncrements::clickedToolButtonAdd() +{ + ui->tableWidgetIncrement->setFocus(Qt::OtherFocusReason); + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::IncrementChanged); + qint32 currentRow = ui->tableWidgetIncrement->rowCount(); + ui->tableWidgetIncrement->insertRow( currentRow ); + + qint32 num = 1; + QString name; + do + { + name = QString(tr("Name_%1")).arg(num); + num++; + } while (data->IncrementTableContains(name)); + + const quint32 id = data->getNextId(); + const QString description(tr("Description")); + VIncrement incr = VIncrement(id, 0, 0, 0, description); + data->AddIncrement(name, incr); + + AddIncrementToFile(id, name, 0, 0, 0, description); + + QTableWidgetItem *item = new QTableWidgetItem(name); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, id); + ui->tableWidgetIncrement->setItem(currentRow, 0, item); + ui->tableWidgetIncrement->setCurrentCell(currentRow, 0, QItemSelectionModel::ClearAndSelect); + + item = new QTableWidgetItem("0");// calculated value + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetIncrement->setItem(currentRow, 1, item); + + item = new QTableWidgetItem("0");// base value + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 2, item); + + item = new QTableWidgetItem("0");// in sizes + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 3, item); + + item = new QTableWidgetItem("0"); // in heights + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 4, item); + + item = new QTableWidgetItem(description); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 5, item); + + ui->toolButtonRemove->setEnabled(true); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::IncrementChanged); + emit haveLiteChange(); +} + +void DialogIncrements::clickedToolButtonRemove() +{ + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::IncrementChanged); + QTableWidgetItem *item = ui->tableWidgetIncrement->currentItem(); + qint32 row = item->row(); + QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); + data->RemoveIncrementTableRow(itemName->text()); + quint32 id = qvariant_cast(item->data(Qt::UserRole)); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + QDomNodeList list = doc->elementsByTagName(VPattern::TagIncrements); + list.at(0).removeChild(domElement); + } + ui->tableWidgetIncrement->removeRow(row); + if (ui->tableWidgetIncrement->rowCount() == 0) + { + ui->toolButtonRemove->setEnabled(false); + } + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::IncrementChanged); + emit haveLiteChange(); +} + +void DialogIncrements::AddIncrementToFile(const quint32 &id, const QString &name, const qreal &base, const qreal &ksize, + const qreal &kheight, const QString &description) +{ + QDomElement element = doc->createElement(VPattern::TagIncrement); + + doc->SetAttribute(element, VDomDocument::AttrId, id); + doc->SetAttribute(element, VPattern::IncrementName, name); + doc->SetAttribute(element, VPattern::IncrementBase, base); + doc->SetAttribute(element, VPattern::IncrementKsize, ksize); + doc->SetAttribute(element, VPattern::IncrementKgrowth, kheight); + doc->SetAttribute(element, VPattern::IncrementDescription, description); + + QDomNodeList list = doc->elementsByTagName(VPattern::TagIncrements); + list.at(0).appendChild(element); +} + +void DialogIncrements::IncrementChanged ( qint32 row, qint32 column ) +{ + + const QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); + const QTableWidgetItem *item = ui->tableWidgetIncrement->item(row, column); + const quint32 id = qvariant_cast(itemName->data(Qt::UserRole)); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement() == false) + { + qDebug()<<"Cant't find increment with id = "<row = row; + switch (column) + { + case 0: // VPattern::IncrementName + doc->SetAttribute(domElement, VPattern::IncrementName, item->text()); + data->ClearIncrementTable(); + this->column = 2; + emit FullUpdateTree(); + break; + case 2: // VPattern::IncrementBase + doc->SetAttribute(domElement, VPattern::IncrementBase, item->text()); + this->column = 3; + emit FullUpdateTree(); + break; + case 3: // VPattern::IncrementKsize + doc->SetAttribute(domElement, VPattern::IncrementKsize, item->text()); + this->column = 4; + emit FullUpdateTree(); + break; + case 4: // VPattern::IncrementKgrowth + doc->SetAttribute(domElement, VPattern::IncrementKgrowth, item->text()); + this->column = 5; + emit FullUpdateTree(); + break; + case 5: // VPattern::IncrementDescription + { + doc->SetAttribute(domElement, VPattern::IncrementDescription, item->text()); + VIncrement incr = data->GetIncrement(itemName->text()); + incr.setDescription(item->text()); + data->UpdateIncrement(itemName->text(), incr); + ui->tableWidgetIncrement->resizeColumnsToContents(); + ui->tableWidgetIncrement->resizeRowsToContents(); + this->column = 0; + ui->tableWidgetIncrement->setCurrentCell( row, this->column ); + break; + } + default: + break; + } + emit haveLiteChange(); +} + +void DialogIncrements::MeasurementChanged(qint32 row, qint32 column) +{ + switch (column) + { + case 2:// value column + { + const QTableWidgetItem *itemName = ui->tableWidgetMeasurements->item(row, 0); + QTableWidgetItem *item = ui->tableWidgetMeasurements->item(row, 2); + + VMeasurement measur = data->GetMeasurement(itemName->text()); + const QString tag = measur.TagName(); + QDomNodeList list = m->elementsByTagName(tag); + QDomElement domElement = list.at(0).toElement(); + if (domElement.isElement() == false) + { + qDebug()<<"Cant't find measurement "<SetAttribute(domElement, VIndividualMeasurements::AttrValue, item->text()); + if (m->SaveDocument(doc->MPath()) == false) + { + qDebug()<<"Can't save measurement"; + } + bool ok = false; + const qreal base = item->text().replace(",", ".").toDouble(&ok); + if (ok == false) + { + measur.setBase(0); + item->setText("0"); + qDebug()<<"Can't convert toDouble measurement value"<ClearMeasurements(); + m->Measurements(); + emit FullUpdateTree(); + break; + } + default: + break; + } +} + +void DialogIncrements::closeEvent(QCloseEvent *event) +{ + emit DialogClosed(QDialog::Accepted); + event->accept(); +} + +DialogIncrements::~DialogIncrements() +{ + delete ui; + delete m; +} diff --git a/src/dialogs/dialogincrements.h b/src/dialogs/app/dialogincrements.h similarity index 78% rename from src/dialogs/dialogincrements.h rename to src/dialogs/app/dialogincrements.h index 156e0c78f..c988f5b1e 100644 --- a/src/dialogs/dialogincrements.h +++ b/src/dialogs/app/dialogincrements.h @@ -29,8 +29,9 @@ #ifndef DIALOGINCREMENTS_H #define DIALOGINCREMENTS_H -#include "dialogtool.h" -#include "../xml/vdomdocument.h" +#include "../tools/dialogtool.h" +#include "../../xml/vpattern.h" +#include "../../xml/vindividualmeasurements.h" namespace Ui { @@ -50,7 +51,7 @@ public: * @param doc dom document container * @param parent parent widget */ - DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); + DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr); ~DialogIncrements(); public slots: /** @@ -66,11 +67,18 @@ public slots: * @param row number of row * @param column number of column */ - void cellChanged ( qint32 row, qint32 column ); + void IncrementChanged ( qint32 row, qint32 column ); + void MeasurementChanged ( qint32 row, qint32 column ); /** * @brief FullUpdateFromFile update information in tables form file */ void FullUpdateFromFile(); + void SaveGivenName(); + void SaveFamilyName(); + void SaveEmail(); + void SaveSex(int index); + void SaveBirthDate(const QDate & date); + void OpenTable(); signals: /** * @brief FullUpdateTree signal update data for dom document @@ -95,7 +103,7 @@ private: /** * @brief doc dom document container */ - VDomDocument *doc; + VPattern *doc; /** * @brief row save number of row current selected cell */ @@ -104,14 +112,15 @@ private: * @brief column save number of column current selected cell */ qint32 column; + VIndividualMeasurements *m; /** - * @brief FillStandardTable fill data for standard table + * @brief FillMeasurements load measurements data */ - void FillStandardTable(); + void FillMeasurements(); /** * @brief FillIncrementTable fill data for increment table */ - void FillIncrementTable(); + void FillIncrements(); /** * @brief FillLengthLines fill data for table of lines lengths */ @@ -130,11 +139,11 @@ private: * @param name name * @param base base value * @param ksize increment in sizes - * @param kgrowth increment in growths + * @param kheight increment in heights * @param description description of increment */ - void AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, - QString description); + void AddIncrementToFile(const quint32 &id, const QString &name, const qreal &base, + const qreal &ksize, const qreal &kheight, const QString &description); }; #endif // DIALOGINCREMENTS_H diff --git a/src/dialogs/app/dialogincrements.ui b/src/dialogs/app/dialogincrements.ui new file mode 100644 index 000000000..f3a0d3c19 --- /dev/null +++ b/src/dialogs/app/dialogincrements.ui @@ -0,0 +1,605 @@ + + + DialogIncrements + + + + 0 + 0 + 979 + 574 + + + + + 800 + 0 + + + + Increments + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + + 1 + 0 + + + + QTabWidget::North + + + 1 + + + + + 0 + 0 + + + + Measurements + + + + + + 6 + + + + + + 0 + 0 + + + + Load another measurements table + + + + + + + + 0 + 0 + + + + ... + + + + + + + + + + + + + + + 0 + 1 + + + + + 0 + 0 + + + + 1 + + + + true + + + + 0 + 0 + 939 + 411 + + + + Personal information + + + + + + + + + 0 + 0 + + + + + 84 + 0 + + + + Given name + + + + + + + + + + + + 6 + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + Family name + + + + + + + + + + + + + + + 0 + 0 + + + + + 84 + 0 + + + + Birth date + + + + + + + yyyy-MM-dd + + + + + + + + + + + + 0 + 0 + + + + + 84 + 0 + + + + Sex + + + + + + + + 0 + 0 + + + + + + + + + + + + + 0 + 0 + + + + + 84 + 0 + + + + Mail + + + + + + + + + + + + + + 0 + 0 + 939 + 411 + + + + Measurements + + + + + + true + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + false + + + 95 + + + 25 + + + false + + + true + + + false + + + 45 + + + 8 + + + + Name + + + + + The calculated value + + + + + Base value + + + + + In sizes + + + + + In heights + + + + + Description + + + + + + + + + + + + + Increments + + + + + + true + + + QAbstractItemView::SingleSelection + + + false + + + true + + + false + + + 95 + + + 17 + + + false + + + true + + + false + + + false + + + 20 + + + false + + + + Name + + + + + The calculated value + + + + + Base value + + + + + In sizes + + + + + In heights + + + + + Description + + + + + + + + ... + + + + + + + + + + + + false + + + ... + + + + + + + + + + + + + Lines + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + 137 + + + false + + + false + + + + Line + + + + + Length + + + + + + + + + Curves + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + 137 + + + false + + + false + + + + Curve + + + + + Length + + + + + + + + + Arcs + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + 137 + + + false + + + false + + + + Arc + + + + + Length + + + + + + + + + + + + tableWidgetMeasurements + tableWidgetIncrement + toolButtonAdd + toolButtonRemove + tableWidgetLines + tableWidgetSplines + tableWidgetArcs + + + + + + diff --git a/src/dialogs/app/dialogindividualmeasurements.cpp b/src/dialogs/app/dialogindividualmeasurements.cpp new file mode 100644 index 000000000..ef332c049 --- /dev/null +++ b/src/dialogs/app/dialogindividualmeasurements.cpp @@ -0,0 +1,287 @@ +/************************************************************************ + ** + ** @file dialogindividualmeasurements.cpp + ** @author Roman Telezhinsky + ** @date 22 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogindividualmeasurements.h" +#include "ui_dialogindividualmeasurements.h" +#include +#include "../../xml/vindividualmeasurements.h" +#include +#include +#include +#include "../../widgets/vapplication.h" + +DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName, + QWidget *parent) : + QDialog(parent), ui(new Ui::DialogIndividualMeasurements), _name(patternPieceName), _tablePath(QString()), + data(data) +{ + ui->setupUi(this); + + { + const QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + Q_CHECK_PTR(bOk); + connect(bOk, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogAccepted); + } + { + const QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + Q_CHECK_PTR(bCansel); + connect(bCansel, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogRejected); + } + + ui->lineEditName->setText(_name); + + LoadIndividualTables(); + InitUnits(); + + CheckState(); + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogIndividualMeasurements::CheckState); + connect(ui->buttonGroupPath, static_cast(&QButtonGroup::buttonClicked), this, + &DialogIndividualMeasurements::CheckState); + connect(ui->toolButtonOpenExist, &QToolButton::clicked, this, &DialogIndividualMeasurements::OpenTable); + connect(ui->toolButtonOpenNew, &QToolButton::clicked, this, &DialogIndividualMeasurements::NewTable); +} + +DialogIndividualMeasurements::~DialogIndividualMeasurements() +{ + delete ui; +} + +void DialogIndividualMeasurements::DialogAccepted() +{ + _name = ui->lineEditName->text(); + if (ui->radioButtonExistM->isChecked()) + { + _tablePath = ui->lineEditPathExistM->text(); + } + else + { + _tablePath = ui->lineEditPathNewM->text(); + QFile table(_tablePath); + if (table.exists()) + { + table.remove(); + } + + const qint32 index = ui->comboBoxLang->currentIndex(); + QString path = ui->comboBoxLang->itemData(index).toString(); + QFile iMeasur(path); + if ( iMeasur.copy(_tablePath) == false ) + { + QMessageBox::warning(this, tr("Could not create measurements file"), tr("Please try again or change file")); + DialogRejected(); + } + } + try + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", _tablePath); + VIndividualMeasurements m(data); + m.setContent(_tablePath); + const qint32 index = ui->comboBoxUnits->currentIndex(); + Valentina::Units unit = VDomDocument::StrToUnits(ui->comboBoxUnits->itemData(index).toString()); + m.setUnit(unit); + qApp->setPatternUnit( m.Unit()); + QFile iMeasur(_tablePath); + if (iMeasur.open(QIODevice::WriteOnly| QIODevice::Truncate)) + { + const int indent = 4; + QTextStream out(&iMeasur); + out.setCodec("UTF-8"); + m.save(out, indent); + iMeasur.close(); + } + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + qDebug()<<"File error."<lineEditName->text().isEmpty() == false) + { + flagName = true; + } + + bool flagPath = false; + if (ui->radioButtonExistM->isChecked()) + { + ui->lineEditPathExistM->setEnabled(true); + ui->toolButtonOpenExist->setEnabled(true); + + ui->lineEditPathNewM->setEnabled(false); + ui->toolButtonOpenNew->setEnabled(false); + ui->comboBoxLang->setEnabled(false); + ui->comboBoxUnits->setEnabled(false); + + if (ui->lineEditPathExistM->text().isEmpty() == false) + { + flagPath = true; + } + } + else + { + ui->lineEditPathNewM->setEnabled(true); + ui->toolButtonOpenNew->setEnabled(true); + ui->comboBoxLang->setEnabled(true); + ui->comboBoxUnits->setEnabled(true); + + ui->toolButtonOpenExist->setEnabled(false); + ui->lineEditPathExistM->setEnabled(false); + + if (ui->lineEditPathNewM->text().isEmpty() == false) + { + flagPath = true; + } + } + + bool flagLang = false; + { + const QComboBox *box = ui->comboBoxLang; + Q_CHECK_PTR(box); + if (box->count() > 0 && box->currentIndex() != -1) + { + flagLang = true; + } + } + + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + Q_CHECK_PTR(bOk); + bOk->setEnabled(flagName && flagPath && flagLang); +} + +void DialogIndividualMeasurements::LoadIndividualTables() +{ + QStringList filters; + filters << "*.vit"; + QDir tablesDir(qApp->pathToTables()); + tablesDir.setNameFilters(filters); + tablesDir.setCurrent(qApp->pathToTables()); + + const QStringList allFiles = tablesDir.entryList(QDir::NoDotAndDotDot | QDir::Files); + if (allFiles.isEmpty() == true) + { + ui->comboBoxLang->clear(); + CheckState(); + return; + } + + for (int i = 0; i < allFiles.size(); ++i) + { + QFileInfo fi(allFiles.at(i)); + try + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", fi.absoluteFilePath()); + VIndividualMeasurements m(data); + m.setContent(fi.absoluteFilePath()); + const QString lang = QLocale(m.Language()).nativeLanguageName(); + ui->comboBoxLang->addItem(lang, QVariant(fi.absoluteFilePath())); + } + catch(VException &e) + { + qDebug()<<"File error."<comboBoxLang->findData(checkedLocale); + if (index != -1) + { + ui->comboBoxLang->setCurrentIndex(index); + } +} + +void DialogIndividualMeasurements::OpenTable() +{ + const QString filter(tr("Individual measurements (*.vit)")); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); + if (fileName.isEmpty()) + { + return; + } + + try + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", fileName); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + fileName.clear(); + } + ui->lineEditPathExistM->setText(fileName); + ui->lineEditPathExistM->setToolTip(fileName); + CheckState(); +} + +void DialogIndividualMeasurements::NewTable() +{ + QString dir = QDir::homePath()+"/measurements.vit"; + QString name = QFileDialog::getSaveFileName(this, tr("Where save measurements?"), dir, + tr("Individual measurements (*.vit)")); + + if (name.isEmpty()) + { + return; + } + + // what if the users did not specify a suffix...? + QFileInfo f( name ); + if (f.suffix().isEmpty() && f.suffix() != "vit") + { + name += ".vit"; + } + ui->lineEditPathNewM->setText(name); + ui->lineEditPathNewM->setToolTip(name); + CheckState(); +} + +void DialogIndividualMeasurements::InitUnits() +{ + ui->comboBoxUnits->addItem(tr("centimeter"), QVariant(VDomDocument::UnitsToStr(Valentina::Cm))); + ui->comboBoxUnits->addItem(tr("inch"), QVariant(VDomDocument::UnitsToStr(Valentina::Inch))); +} diff --git a/src/dialogs/app/dialogindividualmeasurements.h b/src/dialogs/app/dialogindividualmeasurements.h new file mode 100644 index 000000000..338391b5c --- /dev/null +++ b/src/dialogs/app/dialogindividualmeasurements.h @@ -0,0 +1,74 @@ +/************************************************************************ + ** + ** @file dialogindividualmeasurements.h + ** @author Roman Telezhinsky + ** @date 22 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGINDIVIDUALMEASUREMENTS_H +#define DIALOGINDIVIDUALMEASUREMENTS_H + +#include +#include "../../container/vcontainer.h" + +namespace Ui +{ + class DialogIndividualMeasurements; +} + +class DialogIndividualMeasurements : public QDialog +{ + Q_OBJECT +public: + DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName, QWidget *parent = nullptr); + ~DialogIndividualMeasurements(); + QString name() const; + QString tablePath() const; +public slots: + void OpenTable(); + void NewTable(); + void CheckState(); + void DialogAccepted(); + void DialogRejected(); +private: + Q_DISABLE_COPY(DialogIndividualMeasurements) + Ui::DialogIndividualMeasurements *ui; + QString _name; + QString _tablePath; + VContainer *data; + void LoadIndividualTables(); + void InitUnits(); +}; + +inline QString DialogIndividualMeasurements::name() const +{ + return _name; +} + +inline QString DialogIndividualMeasurements::tablePath() const +{ + return _tablePath; +} + +#endif // DIALOGINDIVIDUALMEASUREMENTS_H diff --git a/src/dialogs/app/dialogindividualmeasurements.ui b/src/dialogs/app/dialogindividualmeasurements.ui new file mode 100644 index 000000000..522a6a3de --- /dev/null +++ b/src/dialogs/app/dialogindividualmeasurements.ui @@ -0,0 +1,216 @@ + + + DialogIndividualMeasurements + + + + 0 + 0 + 397 + 280 + + + + Dialog + + + + + + + + Pattern piece name + + + + + + + + + + + + + + Exist measurements + + + false + + + buttonGroupPath + + + + + + + + + Path: + + + + + + + true + + + + + + + ... + + + + + + + + + + + + + + + + + + New measurements + + + true + + + buttonGroupPath + + + + + + + + + Language: + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + + + + Units: + + + + + + + + + + + + + + Path: + + + + + + + true + + + + + + + ... + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogIndividualMeasurements + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogIndividualMeasurements + reject() + + + 316 + 260 + + + 286 + 274 + + + + + + + + diff --git a/src/dialogs/app/dialogmeasurements.cpp b/src/dialogs/app/dialogmeasurements.cpp new file mode 100644 index 000000000..55e2e954b --- /dev/null +++ b/src/dialogs/app/dialogmeasurements.cpp @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @file dialogpatterntype.cpp + ** @author Roman Telezhinsky + ** @date 21 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogmeasurements.h" +#include "ui_dialogmeasurements.h" + +DialogMeasurements::DialogMeasurements(QWidget *parent) : + QDialog(parent), ui(new Ui::DialogMeasurements), result(Measurements::Individual) +{ + ui->setupUi(this); + connect(ui->toolButtonStandard, &QToolButton::clicked, this, &DialogMeasurements::StandardMeasurements); + connect(ui->toolButtonIndividual, &QToolButton::clicked, this, &DialogMeasurements::IndividualMeasurements); +} + +DialogMeasurements::~DialogMeasurements() +{ + delete ui; +} + +Measurements::Type DialogMeasurements::type() const +{ + return result; +} + +void DialogMeasurements::StandardMeasurements() +{ + result = Measurements::Standard; + accept(); +} + +void DialogMeasurements::IndividualMeasurements() +{ + result = Measurements::Individual; + accept(); +} diff --git a/src/exception/vexceptionuniqueid.cpp b/src/dialogs/app/dialogmeasurements.h similarity index 58% rename from src/exception/vexceptionuniqueid.cpp rename to src/dialogs/app/dialogmeasurements.h index 9232d0ca7..23ef5a64e 100644 --- a/src/exception/vexceptionuniqueid.cpp +++ b/src/dialogs/app/dialogmeasurements.h @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vexceptionuniqueid.cpp + ** @file dialogpatterntype.h ** @author Roman Telezhinsky - ** @date November 15, 2013 + ** @date 21 2, 2014 ** ** @brief ** @copyright @@ -26,28 +26,39 @@ ** *************************************************************************/ -#include "vexceptionuniqueid.h" +#ifndef DIALOGMEASUREMENTS_H +#define DIALOGMEASUREMENTS_H -#include +#include -VExceptionUniqueId::VExceptionUniqueId(const QString &what, const QDomElement &domElement) - :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1) +namespace Ui { - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - QTextStream stream(&tagText); - domElement.save(stream, 4); - tagName = domElement.tagName(); - lineNumber = domElement.lineNumber(); + class DialogMeasurements; } -QString VExceptionUniqueId::ErrorMessage() const +namespace Measurements { - QString error = QString("ExceptionUniqueId: %1").arg(what); - return error; + /** + * @brief The Type enum pattern measurements. + */ + enum Type { Standard, Individual }; + Q_DECLARE_FLAGS(Types, Type) } +Q_DECLARE_OPERATORS_FOR_FLAGS( Measurements::Types ) -QString VExceptionUniqueId::DetailedInformation() const +class DialogMeasurements : public QDialog { - QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText); - return detail; -} + Q_OBJECT +public: + explicit DialogMeasurements(QWidget *parent = nullptr); + ~DialogMeasurements(); + Measurements::Type type() const; +private: + Q_DISABLE_COPY(DialogMeasurements) + Ui::DialogMeasurements *ui; + Measurements::Type result; + void StandardMeasurements(); + void IndividualMeasurements(); +}; + +#endif // DIALOGMEASUREMENTS_H diff --git a/src/dialogs/app/dialogmeasurements.ui b/src/dialogs/app/dialogmeasurements.ui new file mode 100644 index 000000000..93ebb16e5 --- /dev/null +++ b/src/dialogs/app/dialogmeasurements.ui @@ -0,0 +1,139 @@ + + + DialogMeasurements + + + + 0 + 0 + 385 + 244 + + + + Measurements + + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-size:18pt;">Please, choose pattern type.</span></p></body></html> + + + Qt::AlignCenter + + + + + + + 13 + + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Graduation + + + + :/icon/Graduation.png:/icon/Graduation.png + + + + 160 + 120 + + + + + + + + Use for creation pattern standard measurement table + + + true + + + + + + + + + 6 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Individual + + + + :/icon/individual.png:/icon/individual.png + + + + 160 + 120 + + + + + + + + Use for creation pattern individual measurements + + + true + + + + + + + + + + + toolButtonIndividual + toolButtonStandard + + + + + + diff --git a/src/dialogs/dialogpatternproperties.cpp b/src/dialogs/app/dialogpatternproperties.cpp similarity index 96% rename from src/dialogs/dialogpatternproperties.cpp rename to src/dialogs/app/dialogpatternproperties.cpp index 82527f731..6d7f922aa 100644 --- a/src/dialogs/dialogpatternproperties.cpp +++ b/src/dialogs/app/dialogpatternproperties.cpp @@ -30,7 +30,7 @@ #include "ui_dialogpatternproperties.h" #include -DialogPatternProperties::DialogPatternProperties(VDomDocument *doc, QWidget *parent) : +DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) : QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc) { ui->setupUi(this); @@ -39,7 +39,7 @@ DialogPatternProperties::DialogPatternProperties(VDomDocument *doc, QWidget *par QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()); -#ifdef Q_OS_WIN32 +#ifdef Q_OS_WIN QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); #else QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); @@ -57,7 +57,7 @@ DialogPatternProperties::DialogPatternProperties(VDomDocument *doc, QWidget *par Q_CHECK_PTR(bCansel); connect(bCansel, &QPushButton::clicked, this, &DialogPatternProperties::close); - connect(this, &DialogPatternProperties::haveChange, this->doc, &VDomDocument::haveLiteChange); + connect(this, &DialogPatternProperties::haveChange, this->doc, &VPattern::haveLiteChange); } DialogPatternProperties::~DialogPatternProperties() diff --git a/src/dialogs/dialogpatternproperties.h b/src/dialogs/app/dialogpatternproperties.h similarity index 90% rename from src/dialogs/dialogpatternproperties.h rename to src/dialogs/app/dialogpatternproperties.h index d65c834d8..3c4fae0c5 100644 --- a/src/dialogs/dialogpatternproperties.h +++ b/src/dialogs/app/dialogpatternproperties.h @@ -30,17 +30,18 @@ #define DIALOGPATTERNPROPERTIES_H #include -#include "../xml/vdomdocument.h" +#include "../../xml/vpattern.h" -namespace Ui { -class DialogPatternProperties; +namespace Ui +{ + class DialogPatternProperties; } class DialogPatternProperties : public QDialog { Q_OBJECT public: - DialogPatternProperties(VDomDocument *doc, QWidget *parent = 0); + DialogPatternProperties(VPattern *doc, QWidget *parent = nullptr); virtual ~DialogPatternProperties(); signals: void haveChange(); @@ -49,7 +50,7 @@ public slots: private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; - VDomDocument *doc; + VPattern *doc; void Write(const QString &tagName, const QString &text) const; }; diff --git a/src/dialogs/dialogpatternproperties.ui b/src/dialogs/app/dialogpatternproperties.ui similarity index 100% rename from src/dialogs/dialogpatternproperties.ui rename to src/dialogs/app/dialogpatternproperties.ui diff --git a/src/dialogs/app/dialogstandardmeasurements.cpp b/src/dialogs/app/dialogstandardmeasurements.cpp new file mode 100644 index 000000000..604681017 --- /dev/null +++ b/src/dialogs/app/dialogstandardmeasurements.cpp @@ -0,0 +1,160 @@ +/************************************************************************ + ** + ** @file dialogstandardmeasurements.cpp + ** @author Roman Telezhinsky + ** @date 21 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogstandardmeasurements.h" +#include "ui_dialogstandardmeasurements.h" +#include +#include "../../xml/vstandardmeasurements.h" +#include "../../widgets/vapplication.h" + +DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, const QString &patternPieceName, + QWidget *parent) : + QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(patternPieceName), _tablePath(QString()) +{ + ui->setupUi(this); + + { + const QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + Q_CHECK_PTR(bOk); + connect(bOk, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogAccepted); + } + { + const QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + Q_CHECK_PTR(bCansel); + connect(bCansel, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogRejected); + } + + ui->lineEditName->setText(_name); + + LoadStandardTables(); + + CheckState(); + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogStandardMeasurements::CheckState); +} + +DialogStandardMeasurements::~DialogStandardMeasurements() +{ + delete ui; +} + +QString DialogStandardMeasurements::name() const +{ + return _name; +} + +QString DialogStandardMeasurements::tablePath() const +{ + return _tablePath; +} + +void DialogStandardMeasurements::DialogAccepted() +{ + _name = ui->lineEditName->text(); + const qint32 index = ui->comboBoxTables->currentIndex(); + _tablePath = ui->comboBoxTables->itemData(index).toString(); + + try + { + VDomDocument::ValidateXML("://schema/standard_measurements.xsd", _tablePath); + VStandardMeasurements m(data); + m.setContent(_tablePath); + qApp->setPatternUnit(m.Unit()); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + qDebug()<<"File error."<lineEditName->text().isEmpty() == false) + { + flagName = true; + } + + bool flagTable = false; + { + const QComboBox *box = ui->comboBoxTables; + Q_CHECK_PTR(box); + if (box->count() > 0 && box->currentIndex() != -1) + { + flagTable = true; + } + } + + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + Q_CHECK_PTR(bOk); + bOk->setEnabled(flagTable && flagName); +} + +void DialogStandardMeasurements::LoadStandardTables() +{ + QStringList filters; + filters << "*.vst"; + QDir tablesDir(qApp->pathToTables()); + tablesDir.setNameFilters(filters); + tablesDir.setCurrent(qApp->pathToTables()); + + const QStringList allFiles = tablesDir.entryList(QDir::NoDotAndDotDot | QDir::Files); + if (allFiles.isEmpty() == true) + { + ui->comboBoxTables->clear(); + CheckState(); + return; + } + + for (int i = 0; i < allFiles.size(); ++i) + { + QFileInfo fi(allFiles.at(i)); + try + { + VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath()); + VStandardMeasurements m(data); + m.setContent(fi.absoluteFilePath()); + ui->comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath())); + } + catch(VException &e) + { + qDebug()<<"File error."< + ** @date 21 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGSTANDARDMEASUREMENTS_H +#define DIALOGSTANDARDMEASUREMENTS_H + +#include +#include "../../container/vcontainer.h" + +namespace Ui +{ + class DialogStandardMeasurements; +} + +class DialogStandardMeasurements : public QDialog +{ + Q_OBJECT +public: + DialogStandardMeasurements(VContainer *data, const QString &patternPieceName, QWidget *parent = nullptr); + ~DialogStandardMeasurements(); + QString name() const; + QString tablePath() const; +public slots: + void DialogAccepted(); + void DialogRejected(); + void CheckState(); +private: + Q_DISABLE_COPY(DialogStandardMeasurements) + Ui::DialogStandardMeasurements *ui; + VContainer *data; + QString _name; + QString _tablePath; + void LoadStandardTables(); +}; + +#endif // DIALOGSTANDARDMEASUREMENTS_H diff --git a/src/dialogs/app/dialogstandardmeasurements.ui b/src/dialogs/app/dialogstandardmeasurements.ui new file mode 100644 index 000000000..92fce6de8 --- /dev/null +++ b/src/dialogs/app/dialogstandardmeasurements.ui @@ -0,0 +1,127 @@ + + + DialogStandardMeasurements + + + + 0 + 0 + 452 + 115 + + + + Standard table + + + + + + + + + 0 + 0 + + + + + 206 + 0 + + + + Pattern piece name + + + 0 + + + + + + + + 0 + 0 + + + + + + + + + + + + + 0 + 0 + + + + Standard measurements table + + + + + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogStandardMeasurements + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogStandardMeasurements + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/dialogs/pages.cpp b/src/dialogs/app/pages.cpp similarity index 90% rename from src/dialogs/pages.cpp rename to src/dialogs/app/pages.cpp index eecaf4e58..68b27a7c9 100644 --- a/src/dialogs/pages.cpp +++ b/src/dialogs/app/pages.cpp @@ -27,7 +27,8 @@ *************************************************************************/ #include "pages.h" -#include "../options.h" +#include "../../options.h" +#include "../../widgets/vapplication.h" ConfigurationPage::ConfigurationPage(QWidget *parent): QWidget(parent), autoSaveCheck(0), autoTime(0), langCombo(0), osOptionCheck(0), langChanged(false) @@ -71,18 +72,14 @@ QGroupBox *ConfigurationPage::SaveGroup() QApplication::applicationName()); QGroupBox *saveGroup = new QGroupBox(tr("Save")); - Q_CHECK_PTR(saveGroup); autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern")); - Q_CHECK_PTR(autoSaveCheck); bool autoSaveValue = settings.value("configuration/autosave/state", 1).toBool(); autoSaveCheck->setChecked(autoSaveValue); QLabel *intervalLabel = new QLabel(tr("Interval:")); - Q_CHECK_PTR(intervalLabel); autoTime = new QSpinBox(); - Q_CHECK_PTR(autoTime); bool ok = true; qint32 autoTimeValue = settings.value("configuration/autosave/time", 5).toInt(&ok); if (ok == false) @@ -94,13 +91,11 @@ QGroupBox *ConfigurationPage::SaveGroup() autoTime->setSuffix(tr("min")); QHBoxLayout *autosaveLayout = new QHBoxLayout; - Q_CHECK_PTR(autosaveLayout); autosaveLayout->addWidget(autoSaveCheck); autosaveLayout->addWidget(intervalLabel); autosaveLayout->addWidget(autoTime); QVBoxLayout *saveLayout = new QVBoxLayout; - Q_CHECK_PTR(saveLayout); saveLayout->addLayout(autosaveLayout); saveGroup->setLayout(saveLayout); return saveGroup; @@ -112,21 +107,15 @@ QGroupBox *ConfigurationPage::LangGroup() QApplication::applicationName()); QGroupBox *langGroup = new QGroupBox(tr("Language")); - Q_CHECK_PTR(langGroup); - QLabel *guiLabel = new QLabel(tr("GUI language")); - Q_CHECK_PTR(guiLabel); - langCombo = new QComboBox; - Q_CHECK_PTR(langCombo); // format systems language QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString(); - QString m_langPath = QApplication::applicationDirPath(); - m_langPath.append(translationsPath); + QString m_langPath = qApp->translationsPath(); QDir dir(m_langPath); QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); @@ -158,26 +147,21 @@ QGroupBox *ConfigurationPage::LangGroup() &ConfigurationPage::LangChenged); QHBoxLayout *guiLangLayout = new QHBoxLayout; - Q_CHECK_PTR(guiLangLayout); guiLangLayout->addWidget(guiLabel); guiLangLayout->addWidget(langCombo); QLabel *separatorLabel = new QLabel(tr("Decimal separator parts")); - Q_CHECK_PTR(separatorLabel); osOptionCheck = new QCheckBox(tr("With OS options (.)")); - Q_CHECK_PTR(osOptionCheck); //bool osOptionValue = settings.value("configuration/osSeparator", 1).toBool(); //osOptionCheck->setChecked(osOptionValue); osOptionCheck->setEnabled(false); QHBoxLayout *separatorLayout = new QHBoxLayout; - Q_CHECK_PTR(separatorLayout); separatorLayout->addWidget(separatorLabel); separatorLayout->addWidget(osOptionCheck); QVBoxLayout *langLayout = new QVBoxLayout; - Q_CHECK_PTR(langLayout); langLayout->addLayout(guiLangLayout); langLayout->addLayout(separatorLayout); langGroup->setLayout(langLayout); @@ -215,14 +199,10 @@ QGroupBox *PatternPage::UserGroup() QApplication::applicationName()); QGroupBox *userGroup = new QGroupBox(tr("User")); - Q_CHECK_PTR(userGroup); - QLabel *nameLabel = new QLabel(tr("User name")); - Q_CHECK_PTR(nameLabel); userName = new QLineEdit; - Q_CHECK_PTR(userName); -#ifdef Q_OS_WIN32 +#ifdef Q_OS_WIN QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); #else QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); @@ -230,12 +210,10 @@ QGroupBox *PatternPage::UserGroup() userName->setText(user); QHBoxLayout *nameLayout = new QHBoxLayout; - Q_CHECK_PTR(nameLayout); nameLayout->addWidget(nameLabel); nameLayout->addWidget(userName); QVBoxLayout *userLayout = new QVBoxLayout; - Q_CHECK_PTR(userLayout); userLayout->addLayout(nameLayout); userGroup->setLayout(userLayout); return userGroup; @@ -247,20 +225,16 @@ QGroupBox *PatternPage::GraphOutputGroup() // QApplication::applicationName()); QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output")); - Q_CHECK_PTR(graphOutputGroup); graphOutputCheck = new QCheckBox(tr("Use antialiasing")); - Q_CHECK_PTR(graphOutputCheck); //bool graphOutputValue = settings.value("pattern/graphicalOutput", 1).toBool(); //graphOutputCheck->setChecked(graphOutputValue); graphOutputCheck->setEnabled(false); QHBoxLayout *graphLayout = new QHBoxLayout; - Q_CHECK_PTR(graphLayout); graphLayout->addWidget(graphOutputCheck); QVBoxLayout *graphOutputLayout = new QVBoxLayout; - Q_CHECK_PTR(graphOutputLayout); graphOutputLayout->addLayout(graphLayout); graphOutputGroup->setLayout(graphOutputLayout); return graphOutputGroup; @@ -272,13 +246,8 @@ QGroupBox *PatternPage::UndoneGroup() // QApplication::applicationName()); QGroupBox *undoneGroup = new QGroupBox(tr("Undone")); - Q_CHECK_PTR(undoneGroup); - QLabel *undoneLabel = new QLabel(tr("Count steps")); - Q_CHECK_PTR(undoneLabel); - undoneCount = new QSpinBox; - Q_CHECK_PTR(undoneCount); // bool ok = true; // qint32 count = settings.value("pattern/undone", 100).toInt(&ok); // if (ok == false) @@ -289,12 +258,10 @@ QGroupBox *PatternPage::UndoneGroup() undoneCount->setEnabled(false); QHBoxLayout *countLayout = new QHBoxLayout; - Q_CHECK_PTR(countLayout); countLayout->addWidget(undoneLabel); countLayout->addWidget(undoneCount); QVBoxLayout *undoneLayout = new QVBoxLayout; - Q_CHECK_PTR(undoneLayout); undoneLayout->addLayout(countLayout); undoneGroup->setLayout(undoneLayout); return undoneGroup; diff --git a/src/dialogs/pages.h b/src/dialogs/app/pages.h similarity index 95% rename from src/dialogs/pages.h rename to src/dialogs/app/pages.h index dc52a36f4..ef8e96e1c 100644 --- a/src/dialogs/pages.h +++ b/src/dialogs/app/pages.h @@ -35,7 +35,7 @@ class ConfigurationPage : public QWidget { Q_OBJECT public: - ConfigurationPage(QWidget *parent = 0); + ConfigurationPage(QWidget *parent = nullptr); void Apply(); public slots: void LangChenged(); @@ -54,7 +54,7 @@ class PatternPage : public QWidget { Q_OBJECT public: - PatternPage(QWidget *parent = 0); + PatternPage(QWidget *parent = nullptr); void Apply(); private: Q_DISABLE_COPY(PatternPage) diff --git a/src/dialogs/dialoghistory.cpp b/src/dialogs/dialoghistory.cpp deleted file mode 100644 index 2a6794364..000000000 --- a/src/dialogs/dialoghistory.cpp +++ /dev/null @@ -1,483 +0,0 @@ -/************************************************************************ - ** - ** @file dialoghistory.cpp - ** @author Roman Telezhinsky - ** @date November 15, 2013 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "dialoghistory.h" -#include "ui_dialoghistory.h" -#include "../geometry/varc.h" -#include "../geometry/vspline.h" -#include "../geometry/vsplinepath.h" -#include "../tools/vabstracttool.h" -#include "../tools/drawTools/vtoolcutspline.h" -#include "../tools/drawTools/vtoolcutsplinepath.h" -#include "../tools/drawTools/vtoolcutarc.h" -#include -#include - -DialogHistory::DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), - cursorToolRecordRow(0) -{ - ui->setupUi(this); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogHistory::DialogAccepted); - FillTable(); - InitialTable(); - connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked); - connect(this, &DialogHistory::ShowHistoryTool, doc, &VDomDocument::ShowHistoryTool); - connect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor); - connect(doc, &VDomDocument::patternChanged, this, &DialogHistory::UpdateHistory); - connect(doc, &VDomDocument::ChangedActivDraw, this, &DialogHistory::UpdateHistory); - ShowPoint(); -} - -DialogHistory::~DialogHistory() -{ - delete ui; -} - -void DialogHistory::DialogAccepted() -{ - QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); - qint64 id = qvariant_cast(item->data(Qt::UserRole)); - emit ShowHistoryTool(id, Qt::green, false); - emit DialogClosed(QDialog::Accepted); -} - -void DialogHistory::cellClicked(int row, int column) -{ - if (column == 0) - { - QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); - item->setIcon(QIcon()); - - item = ui->tableWidget->item(row, 0); - cursorRow = row; - item->setIcon(QIcon("://icon/32x32/put_after.png")); - qint64 id = qvariant_cast(item->data(Qt::UserRole)); - disconnect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor); - doc->setCursor(id); - connect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor); - } - else - { - QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); - qint64 id = qvariant_cast(item->data(Qt::UserRole)); - emit ShowHistoryTool(id, Qt::green, false); - - cursorToolRecordRow = row; - item = ui->tableWidget->item(cursorToolRecordRow, 0); - id = qvariant_cast(item->data(Qt::UserRole)); - emit ShowHistoryTool(id, Qt::green, true); - } -} - -void DialogHistory::ChangedCursor(qint64 id) -{ - for (qint32 i = 0; i< ui->tableWidget->rowCount(); ++i) - { - QTableWidgetItem *item = ui->tableWidget->item(i, 0); - qint64 rId = qvariant_cast(item->data(Qt::UserRole)); - if (rId == id) - { - QTableWidgetItem *oldCursorItem = ui->tableWidget->item(cursorRow, 0); - oldCursorItem->setIcon(QIcon()); - cursorRow = i; - item->setIcon(QIcon("://icon/32x32/put_after.png")); - } - } -} - -void DialogHistory::UpdateHistory() -{ - FillTable(); - InitialTable(); -} - -void DialogHistory::FillTable() -{ - ui->tableWidget->clear(); - QVector *history = doc->getHistory(); - qint32 currentRow = -1; - qint32 count = 0; - ui->tableWidget->setRowCount(history->size()); - for (qint32 i = 0; i< history->size(); ++i) - { - VToolRecord tool = history->at(i); - if (tool.getNameDraw() != doc->GetNameActivDraw()) - { - continue; - } - currentRow++; - - QTableWidgetItem *item = new QTableWidgetItem(QString()); - item->setTextAlignment(Qt::AlignHCenter); - item->setData(Qt::UserRole, tool.getId()); - ui->tableWidget->setItem(currentRow, 0, item); - - QString historyRecord = Record(tool); - item = new QTableWidgetItem(historyRecord); - item->setFont(QFont("Times", 12, QFont::Bold)); - item->setFlags(item->flags() ^ Qt::ItemIsEditable); - ui->tableWidget->setItem(currentRow, 1, item); - ++count; - } - ui->tableWidget->setRowCount(count); - if (history->size()>0) - { - cursorRow = currentRow; - QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); - item->setIcon(QIcon("://icon/32x32/put_after.png")); - } - ui->tableWidget->resizeColumnsToContents(); - ui->tableWidget->resizeRowsToContents(); - ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); -} - -QString DialogHistory::Record(const VToolRecord &tool) -{ - QString record = QString(); - qint64 basePointId = 0; - qint64 secondPointId = 0; - qint64 firstPointId = 0; - qint64 thirdPointId = 0; - qint64 p1Line1 = 0; - qint64 p2Line1 = 0; - qint64 p1Line2 = 0; - qint64 p2Line2 = 0; - qint64 center = 0; - QDomElement domElement; - switch ( tool.getTypeTool() ) - { - case Tool::ArrowTool: - break; - case Tool::SinglePointTool: - { - QString name = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%1 - Base point")).arg(name); - break; - } - case Tool::EndLineTool: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0"); - } - QString basePointIdName = data->GeometricObject(basePointId)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(basePointIdName, toolIdName); - break; - } - case Tool::LineTool: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - } - QString firstPointIdName = data->GeometricObject(firstPointId)->name(); - QString secondPointIdName = data->GeometricObject(secondPointId)->name(); - record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(firstPointIdName, secondPointIdName); - break; - } - case Tool::AlongLineTool: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - } - QString basePointIdName = data->GeometricObject(basePointId)->name(); - QString secondPointIdName = data->GeometricObject(secondPointId)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%3 - Point along line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName); - break; - } - case Tool::ShoulderPointTool: - { - QString name = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%1 - Point of shoulder")).arg(name); - break; - } - case Tool::NormalTool: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - } - QString basePointIdName = data->GeometricObject(basePointId)->name(); - QString secondPointIdName = data->GeometricObject(secondPointId)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%3 - normal to line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName); - break; - } - case Tool::BisectorTool: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - thirdPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrThirdPoint, "0"); - } - QString firstPointIdName = data->GeometricObject(firstPointId)->name(); - QString basePointIdName = data->GeometricObject(basePointId)->name(); - QString thirdPointIdName = data->GeometricObject(thirdPointId)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%4 - bisector of angle %1_%2_%3")).arg(firstPointIdName, basePointIdName, - thirdPointIdName, toolIdName); - break; - } - case Tool::LineIntersectTool: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - p1Line1 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP1Line1, "0"); - p2Line1 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP2Line1, "0"); - p1Line2 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP1Line2, "0"); - p2Line2 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP2Line2, "0"); - } - QString p1Line1Name = data->GeometricObject(p1Line1)->name(); - QString p2Line1Name = data->GeometricObject(p2Line1)->name(); - QString p1Line2Name = data->GeometricObject(p1Line2)->name(); - QString p2Line2Name = data->GeometricObject(p2Line2)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%5 - intersection of lines %1_%2 and %3_%4")).arg(p1Line1Name, p2Line1Name, - p1Line2Name, p2Line2Name, - toolIdName); - break; - } - case Tool::SplineTool: - { - const VSpline *spl = data->GeometricObject(tool.getId()); - QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); - QString splP4Name = data->GeometricObject(spl->GetP4().id())->name(); - record = QString(tr("Curve %1_%2")).arg(splP1Name, splP4Name); - } - break; - case Tool::ArcTool: - { - const VArc *arc = data->GeometricObject(tool.getId()); - QString arcCenterName = data->GeometricObject(arc->GetCenter().id())->name(); - record = QString(tr("Arc with center in point %1")).arg(arcCenterName); - } - break; - case Tool::SplinePathTool: - { - const VSplinePath *splPath = data->GeometricObject(tool.getId()); - QVector points = splPath->GetSplinePath(); - if (points.size() != 0 ) - { - QString pName = data->GeometricObject(points[0].P().id())->name(); - record = QString(tr("Curve point %1")).arg(pName); - for (qint32 i = 1; i< points.size(); ++i) - { - pName = data->GeometricObject(points[i].P().id())->name(); - QString name = QString("_%1").arg(pName); - record.append(name); - } - } - } - break; - case Tool::PointOfContact: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - center = doc->GetParametrLongLong(domElement, VAbstractTool::AttrCenter, "0"); - firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - } - QString firstPointIdName = data->GeometricObject(firstPointId)->name(); - QString centerName = data->GeometricObject(center)->name(); - QString secondPointIdName = data->GeometricObject(secondPointId)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")).arg( - centerName, firstPointIdName, secondPointIdName, toolIdName); - break; - } - case Tool::Height: - { - qint64 p1LineId = 0; - qint64 p2LineId = 0; - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0"); - p1LineId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP1Line, "0"); - p2LineId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP2Line, "0"); - } - QString basePointIdName = data->GeometricObject(basePointId)->name(); - QString p1LineIdName = data->GeometricObject(p1LineId)->name(); - QString p2LineIdName = data->GeometricObject(p2LineId)->name(); - record = QString(tr("Point of perpendicular from point %1 to line %2_%3")).arg( basePointIdName, - p1LineIdName, p2LineIdName); - break; - } - case Tool::Triangle: - { - qint64 axisP1Id = 0; - qint64 axisP2Id = 0; - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - axisP1Id = doc->GetParametrLongLong(domElement, VAbstractTool::AttrAxisP1, "0"); - axisP2Id = doc->GetParametrLongLong(domElement, VAbstractTool::AttrAxisP2, "0"); - firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - } - QString axisP1IdName = data->GeometricObject(axisP1Id)->name(); - QString axisP2IdName = data->GeometricObject(axisP2Id)->name(); - QString firstPointIdName = data->GeometricObject(firstPointId)->name(); - QString secondPointIdName = data->GeometricObject(secondPointId)->name(); - record = QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg( axisP1IdName, axisP2IdName, - firstPointIdName, secondPointIdName); - break; - } - case Tool::PointOfIntersection: - { - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - } - QString firstPointIdName = data->GeometricObject(firstPointId)->name(); - QString secondPointIdName = data->GeometricObject(secondPointId)->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%1 - point of intersection %2 and %3")).arg(toolIdName, firstPointIdName, - secondPointIdName); - } - break; - case Tool::CutArcTool: - { - qint64 arcId = 0; - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - arcId = doc->GetParametrLongLong(domElement, VToolCutArc::AttrArc, "0"); - } - const VArc *arc = data->GeometricObject(arcId); - QString arcCenterName = data->GeometricObject(arc->GetCenter().id())->name(); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - record = QString(tr("%1 - cut arc with center %2")).arg(toolIdName, arcCenterName); - } - break; - case Tool::CutSplineTool: - { - qint64 splineId = 0; - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - splineId = doc->GetParametrLongLong(domElement, VToolCutSpline::AttrSpline, "0"); - } - const VSpline *spl = data->GeometricObject(splineId); - QString toolIdName = data->GeometricObject(tool.getId())->name(); - QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); - QString splP4Name = data->GeometricObject(spl->GetP4().id())->name(); - record = QString(tr("%1 - cut curve %2_%3")).arg(toolIdName, splP1Name, splP4Name); - } - break; - case Tool::CutSplinePathTool: - { - qint64 splinePathId = 0; - domElement = doc->elementById(QString().setNum(tool.getId())); - if (domElement.isElement()) - { - splinePathId = doc->GetParametrLongLong(domElement, VToolCutSplinePath::AttrSplinePath, "0"); - } - const VSplinePath *splPath = data->GeometricObject(splinePathId); - QVector points = splPath->GetSplinePath(); - if (points.size() != 0 ) - { - QString toolIdName = data->GeometricObject(tool.getId())->name(); - QString pName = data->GeometricObject(points[0].P().id())->name(); - record = QString(tr("%1 - cut curve path %2")).arg(toolIdName, pName); - for (qint32 i = 1; i< points.size(); ++i) - { - pName = data->GeometricObject(points[i].P().id())->name(); - QString name = QString("_%1").arg(pName); - record.append(name); - } - } - } - break; - //Because "history" not only show history of pattern, but help restore current data for each pattern's piece, we - //need add record about details and nodes, but don't show them. - case Tool::Detail: - break; - case Tool::UnionDetails: - break; - case Tool::NodeArc: - break; - case Tool::NodePoint: - break; - case Tool::NodeSpline: - break; - case Tool::NodeSplinePath: - break; - default: - qWarning()<tableWidget->setSortingEnabled(false); - ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(" ")); - ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Tool"))); -} - -void DialogHistory::ShowPoint() -{ - QVector *history = doc->getHistory(); - if (history->size()>0) - { - QTableWidgetItem *item = ui->tableWidget->item(0, 1); - item->setSelected(true); - cursorToolRecordRow = 0; - item = ui->tableWidget->item(0, 0); - qint64 id = qvariant_cast(item->data(Qt::UserRole)); - emit ShowHistoryTool(id, Qt::green, true); - } -} - -void DialogHistory::closeEvent(QCloseEvent *event) -{ - QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); - qint64 id = qvariant_cast(item->data(Qt::UserRole)); - emit ShowHistoryTool(id, Qt::green, false); - DialogTool::closeEvent(event); -} diff --git a/src/dialogs/dialogincrements.cpp b/src/dialogs/dialogincrements.cpp deleted file mode 100644 index f33dda500..000000000 --- a/src/dialogs/dialogincrements.cpp +++ /dev/null @@ -1,521 +0,0 @@ -/************************************************************************ - ** - ** @file dialogincrements.cpp - ** @author Roman Telezhinsky - ** @date November 15, 2013 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "dialogincrements.h" -#include "ui_dialogincrements.h" -#include "../widgets/doubledelegate.h" -#include "../widgets/textdelegate.h" -#include "../exception/vexception.h" - -#include - -DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0) -{ - ui->setupUi(this); - TextDelegate *textDelegate = new TextDelegate(ui->tableWidgetIncrement); - Q_CHECK_PTR(textDelegate); - ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate); - DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); - Q_CHECK_PTR(doubleDelegate); - ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate); - ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate); - ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate); - - FillStandardTable(); - FillIncrementTable(); - FillLengthLines(); - FillLengthSplines(); - FillLengthArcs(); - - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); - connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); - connect(ui->toolButtonRemove, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonRemove); - - connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); - connect(this, &DialogIncrements::haveLiteChange, this->doc, &VDomDocument::haveLiteChange); - connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); - - ui->tabWidget->setCurrentIndex(0); -} - -void DialogIncrements::FillStandardTable() -{ - const QHash *standardTable = data->DataStandardTable(); - qint32 currentRow = -1; - QHashIterator i(*standardTable); - ui->tableWidgetStandard->setRowCount ( standardTable->size() ); - while (i.hasNext()) - { - i.next(); - VStandardTableRow cell = i.value(); - currentRow++; - - QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); - item->setTextAlignment(Qt::AlignHCenter); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->tableWidgetStandard->setItem(currentRow, 0, item); - - item = new QTableWidgetItem(QString().setNum(data->GetValueStandardTableCell(i.key()))); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetStandard->setItem(currentRow, 1, item); - - item = new QTableWidgetItem(QString().setNum(cell.GetBase())); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetStandard->setItem(currentRow, 2, item); - - item = new QTableWidgetItem(QString().setNum(cell.GetKsize())); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetStandard->setItem(currentRow, 3, item); - - item = new QTableWidgetItem(QString().setNum(cell.GetKgrowth())); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetStandard->setItem(currentRow, 4, item); - - item = new QTableWidgetItem(cell.GetDescription()); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetStandard->setItem(currentRow, 5, item); - } - ui->tableWidgetStandard->resizeColumnsToContents(); - ui->tableWidgetStandard->resizeRowsToContents(); - ui->tableWidgetStandard->verticalHeader()->setDefaultSectionSize(20); -} - -void DialogIncrements::FillIncrementTable() -{ - const QHash *incrementTable = data->DataIncrementTable(); - QHashIterator i(*incrementTable); - QMap map; - //Sorting QHash by id - while (i.hasNext()) - { - i.next(); - VIncrementTableRow cell = i.value(); - map.insert(cell.getId(), i.key()); - } - - qint32 currentRow = -1; - QMapIterator iMap(map); - while (iMap.hasNext()) - { - iMap.next(); - VIncrementTableRow cell = incrementTable->value(iMap.value()); - currentRow++; - ui->tableWidgetIncrement->setRowCount ( incrementTable->size() ); - - QTableWidgetItem *item = new QTableWidgetItem(iMap.value()); - item->setTextAlignment(Qt::AlignHCenter); - item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, cell.getId()); - ui->tableWidgetIncrement->setItem(currentRow, 0, item); - - item = new QTableWidgetItem(QString().setNum(data->GetValueIncrementTableRow(iMap.value()))); - item->setTextAlignment(Qt::AlignHCenter); - // set the item non-editable (view only), and non-selectable - Qt::ItemFlags flags = item->flags(); - flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag - item->setFlags(flags); - ui->tableWidgetIncrement->setItem(currentRow, 1, item); - - item = new QTableWidgetItem(QString().setNum(cell.getBase())); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 2, item); - - item = new QTableWidgetItem(QString().setNum(cell.getKsize())); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 3, item); - - item = new QTableWidgetItem(QString().setNum(cell.getKgrowth())); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 4, item); - - item = new QTableWidgetItem(cell.getDescription()); - item->setTextAlignment(Qt::AlignLeft); - ui->tableWidgetIncrement->setItem(currentRow, 5, item); - } - if (ui->tableWidgetIncrement->rowCount()>0) - { - ui->toolButtonRemove->setEnabled(true); - } - ui->tableWidgetIncrement->resizeColumnsToContents(); - ui->tableWidgetIncrement->resizeRowsToContents(); - ui->tableWidgetIncrement->setCurrentCell( row, column ); -} - -void DialogIncrements::FillLengthLines() -{ - const QHash *linesTable = data->DataLengthLines(); - QHashIterator iHash(*linesTable); - QMap map; - //Sorting QHash by name - while (iHash.hasNext()) - { - iHash.next(); - map.insert(iHash.key(), iHash.value()); - } - - qint32 currentRow = -1; - QMapIterator i(map); - while (i.hasNext()) - { - i.next(); - qreal length = i.value(); - currentRow++; - ui->tableWidgetLines->setRowCount ( linesTable->size() ); - - QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); - item->setTextAlignment(Qt::AlignHCenter); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->tableWidgetLines->setItem(currentRow, 0, item); - - item = new QTableWidgetItem(QString().setNum(length)); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetLines->setItem(currentRow, 1, item); - } - ui->tableWidgetLines->resizeColumnsToContents(); - ui->tableWidgetLines->resizeRowsToContents(); - ui->tableWidgetLines->verticalHeader()->setDefaultSectionSize(20); -} - -void DialogIncrements::FillLengthSplines() -{ - const QHash *splinesTable = data->DataLengthSplines(); - QHashIterator iHash(*splinesTable); - QMap map; - //Sorting QHash by name - while (iHash.hasNext()) - { - iHash.next(); - map.insert(iHash.key(), iHash.value()); - } - - qint32 currentRow = -1; - QMapIterator i(map); - while (i.hasNext()) - { - i.next(); - qreal length = i.value(); - currentRow++; - ui->tableWidgetSplines->setRowCount ( splinesTable->size() ); - - QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); - item->setTextAlignment(Qt::AlignLeft); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->tableWidgetSplines->setItem(currentRow, 0, item); - - item = new QTableWidgetItem(QString().setNum(length)); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetSplines->setItem(currentRow, 1, item); - } - ui->tableWidgetSplines->resizeColumnsToContents(); - ui->tableWidgetSplines->resizeRowsToContents(); - ui->tableWidgetSplines->verticalHeader()->setDefaultSectionSize(20); -} - -void DialogIncrements::FillLengthArcs() -{ - const QHash *arcsTable = data->DataLengthArcs(); - QHashIterator iHash(*arcsTable); - QMap map; - //Sorting QHash by name - while (iHash.hasNext()) - { - iHash.next(); - map.insert(iHash.key(), iHash.value()); - } - - qint32 currentRow = -1; - QMapIterator i(map); - while (i.hasNext()) - { - i.next(); - qreal length = i.value(); - currentRow++; - ui->tableWidgetArcs->setRowCount ( arcsTable->size() ); - - QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); - item->setTextAlignment(Qt::AlignHCenter); - item->setFont(QFont("Times", 12, QFont::Bold)); - ui->tableWidgetArcs->setItem(currentRow, 0, item); - - item = new QTableWidgetItem(QString().setNum(length)); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetArcs->setItem(currentRow, 1, item); - } - ui->tableWidgetArcs->resizeColumnsToContents(); - ui->tableWidgetArcs->resizeRowsToContents(); - ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20); -} - -void DialogIncrements::FullUpdateFromFile() -{ - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::cellChanged); - - ui->tableWidgetStandard->clearContents(); - FillStandardTable(); - - ui->tableWidgetIncrement->clearContents(); - FillIncrementTable(); - - ui->tableWidgetLines->clearContents(); - FillLengthLines(); - - ui->tableWidgetSplines->clearContents(); - FillLengthSplines(); - - ui->tableWidgetArcs->clearContents(); - FillLengthArcs(); - - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::cellChanged); -} - -void DialogIncrements::clickedToolButtonAdd() -{ - ui->tableWidgetIncrement->setFocus(Qt::OtherFocusReason); - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::cellChanged); - qint32 currentRow = ui->tableWidgetIncrement->rowCount(); - ui->tableWidgetIncrement->insertRow( currentRow ); - - qint32 num = 1; - QString name; - do - { - name = QString(tr("Name_%1")).arg(num); - num++; - } while (data->IncrementTableContains(name)); - - qint64 id = data->getNextId(); - qreal base = 0; - qreal ksize = 0; - qreal kgrowth = 0; - QString description = QString(tr("Description")); - VIncrementTableRow incrementRow = VIncrementTableRow(id, base, ksize, kgrowth, description); - data->AddIncrementTableRow(name, incrementRow); - - AddIncrementToFile(id, name, base, ksize, kgrowth, description); - - QTableWidgetItem *item = new QTableWidgetItem(name); - item->setTextAlignment(Qt::AlignHCenter); - item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, id); - ui->tableWidgetIncrement->setItem(currentRow, 0, item); - ui->tableWidgetIncrement->setCurrentCell(currentRow, 0, QItemSelectionModel::ClearAndSelect); - - item = new QTableWidgetItem("0"); - item->setTextAlignment(Qt::AlignHCenter); - // set the item non-editable (view only), and non-selectable - Qt::ItemFlags flags = item->flags(); - flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag - item->setFlags(flags); - ui->tableWidgetIncrement->setItem(currentRow, 1, item); - - item = new QTableWidgetItem("0"); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 2, item); - - item = new QTableWidgetItem("0"); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 3, item); - - item = new QTableWidgetItem("0"); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 4, item); - - item = new QTableWidgetItem(tr("Description")); - item->setTextAlignment(Qt::AlignHCenter); - ui->tableWidgetIncrement->setItem(currentRow, 5, item); - - ui->toolButtonRemove->setEnabled(true); - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::cellChanged); - emit haveLiteChange(); -} - -void DialogIncrements::clickedToolButtonRemove() -{ - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::cellChanged); - QTableWidgetItem *item = ui->tableWidgetIncrement->currentItem(); - qint32 row = item->row(); - QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); - data->RemoveIncrementTableRow(itemName->text()); - qint64 id = qvariant_cast(item->data(Qt::UserRole)); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - QDomNodeList list = doc->elementsByTagName("increments"); - list.at(0).removeChild(domElement); - } - ui->tableWidgetIncrement->removeRow(row); - if (ui->tableWidgetIncrement->rowCount() == 0) - { - ui->toolButtonRemove->setEnabled(false); - } - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::cellChanged); - emit haveLiteChange(); -} - -void DialogIncrements::AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, - QString description) -{ - QDomNodeList list = doc->elementsByTagName("increments"); - QDomElement element = doc->createElement("increment"); - - QDomAttr drawAttr = doc->createAttribute("id"); - drawAttr.setValue(QString().setNum(id)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("name"); - drawAttr.setValue(name); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("base"); - drawAttr.setValue(QString().setNum(base)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("ksize"); - drawAttr.setValue(QString().setNum(ksize)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("kgrowth"); - drawAttr.setValue(QString().setNum(kgrowth)); - element.setAttributeNode(drawAttr); - - drawAttr = doc->createAttribute("description"); - drawAttr.setValue(description); - element.setAttributeNode(drawAttr); - - list.at(0).appendChild(element); -} - -void DialogIncrements::cellChanged ( qint32 row, qint32 column ) -{ - QTableWidgetItem *item = 0; - QTableWidgetItem *itemName = 0; - qint64 id; - QDomElement domElement; - this->row = row; - switch (column) - { - case 0: - item = ui->tableWidgetIncrement->item(row, 0); - id = qvariant_cast(item->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("name", item->text()); - data->ClearIncrementTable(); - this->column = 2; - emit FullUpdateTree(); - emit haveLiteChange(); - } - break; - case 2: - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - bool ok = false; - qreal value = item->text().replace(",", ".").toDouble(&ok); - if (ok) - { - domElement.setAttribute("base", value); - this->column = 3; - emit FullUpdateTree(); - emit haveLiteChange(); - } - else - { - throw VException(tr("Can't convert toDouble value.")); - } - } - break; - case 3: - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("ksize", item->text().replace(",", ".").toDouble()); - this->column = 4; - emit FullUpdateTree(); - emit haveLiteChange(); - } - break; - case 4: - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("kgrowth", item->text().replace(",", ".").toDouble()); - this->column = 5; - emit FullUpdateTree(); - emit haveLiteChange(); - } - break; - case 5: - itemName = ui->tableWidgetIncrement->item(row, 0); - item = ui->tableWidgetIncrement->item(row, column); - id = qvariant_cast(itemName->data(Qt::UserRole)); - domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - domElement.setAttribute("description", item->text()); - VIncrementTableRow incr = data->GetIncrementTableRow(itemName->text()); - incr.setDescription(item->text()); - data->UpdateIncrementTableRow(itemName->text(), incr); - ui->tableWidgetIncrement->resizeColumnsToContents(); - ui->tableWidgetIncrement->resizeRowsToContents(); - ui->tableWidgetIncrement->setCurrentCell( row, 0 ); - emit haveLiteChange(); - } - break; - default: - break; - } -} - -void DialogIncrements::closeEvent(QCloseEvent *event) -{ - emit DialogClosed(QDialog::Accepted); - event->accept(); -} - -DialogIncrements::~DialogIncrements() -{ - delete ui; -} diff --git a/src/dialogs/dialogincrements.ui b/src/dialogs/dialogincrements.ui deleted file mode 100644 index a6ad81fab..000000000 --- a/src/dialogs/dialogincrements.ui +++ /dev/null @@ -1,369 +0,0 @@ - - - DialogIncrements - - - - 0 - 0 - 897 - 422 - - - - - 800 - 0 - - - - Increments - - - - :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - - - - - - - - - - 1 - 0 - - - - QTabWidget::North - - - 1 - - - - Sizes table - - - - - - true - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - false - - - 95 - - - 25 - - - false - - - true - - - false - - - 45 - - - 8 - - - - Name - - - - - The calculated value - - - - - Base value - - - - - In sizes - - - - - In growths - - - - - Description - - - - - - - - - Increments - - - - - - true - - - QAbstractItemView::SingleSelection - - - false - - - true - - - false - - - 95 - - - 17 - - - false - - - true - - - false - - - false - - - 20 - - - false - - - - Name - - - - - The calculated value - - - - - Base value - - - - - In sizes - - - - - In growths - - - - - Description - - - - - - - - ... - - - - - - - - - - - - false - - - ... - - - - - - - - - - - - - Lines - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - 137 - - - false - - - false - - - - Line - - - - - Length - - - - - - - - - Curves - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - 137 - - - false - - - false - - - - Curve - - - - - Length - - - - - - - - - Arcs - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - 137 - - - false - - - false - - - - Arc - - - - - Length - - - - - - - - - - - - tabWidget - tableWidgetStandard - tableWidgetIncrement - toolButtonAdd - toolButtonRemove - tableWidgetLines - tableWidgetSplines - tableWidgetArcs - - - - - - diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h index 42bc0aa48..325c096a1 100644 --- a/src/dialogs/dialogs.h +++ b/src/dialogs/dialogs.h @@ -29,29 +29,33 @@ #ifndef DIALOGS_H #define DIALOGS_H -#include "dialogalongline.h" -#include "dialogarc.h" -#include "dialogbisector.h" -#include "dialogdetail.h" -#include "dialogendline.h" -#include "dialoghistory.h" -#include "dialogincrements.h" -#include "dialogline.h" -#include "dialoglineintersect.h" -#include "dialognormal.h" -#include "dialogpointofcontact.h" -#include "dialogshoulderpoint.h" -#include "dialogsinglepoint.h" -#include "dialogspline.h" -#include "dialogsplinepath.h" -#include "dialogheight.h" -#include "dialogcutarc.h" -#include "dialogcutspline.h" -#include "dialogcutsplinepath.h" -#include "dialoguniondetails.h" -#include "dialogtriangle.h" -#include "dialogpointofintersection.h" -#include "configdialog.h" -#include "dialogpatternproperties.h" +#include "tools/dialogalongline.h" +#include "tools/dialogarc.h" +#include "tools/dialogbisector.h" +#include "tools/dialogdetail.h" +#include "tools/dialogendline.h" +#include "tools/dialogline.h" +#include "tools/dialoglineintersect.h" +#include "tools/dialognormal.h" +#include "tools/dialogpointofcontact.h" +#include "tools/dialogshoulderpoint.h" +#include "tools/dialogsinglepoint.h" +#include "tools/dialogspline.h" +#include "tools/dialogsplinepath.h" +#include "tools/dialogheight.h" +#include "tools/dialogcutarc.h" +#include "tools/dialogcutspline.h" +#include "tools/dialogcutsplinepath.h" +#include "tools/dialoguniondetails.h" +#include "tools/dialogtriangle.h" +#include "tools/dialogpointofintersection.h" + +#include "app/dialoghistory.h" +#include "app/dialogincrements.h" +#include "app/configdialog.h" +#include "app/dialogpatternproperties.h" +#include "app/dialogmeasurements.h" +#include "app/dialogindividualmeasurements.h" +#include "app/dialogstandardmeasurements.h" #endif // DIALOGS_H diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index 8796a0c47..99388667c 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -1,81 +1,90 @@ HEADERS += \ - src/dialogs/dialogtriangle.h \ - src/dialogs/dialogtool.h \ - src/dialogs/dialogsplinepath.h \ - src/dialogs/dialogspline.h \ - src/dialogs/dialogsinglepoint.h \ - src/dialogs/dialogshoulderpoint.h \ src/dialogs/dialogs.h \ - src/dialogs/dialogpointofintersection.h \ - src/dialogs/dialogpointofcontact.h \ - src/dialogs/dialognormal.h \ - src/dialogs/dialoglineintersect.h \ - src/dialogs/dialogline.h \ - src/dialogs/dialogincrements.h \ - src/dialogs/dialoghistory.h \ - src/dialogs/dialogheight.h \ - src/dialogs/dialogendline.h \ - src/dialogs/dialogdetail.h \ - src/dialogs/dialogbisector.h \ - src/dialogs/dialogarc.h \ - src/dialogs/dialogalongline.h \ - src/dialogs/dialogcutspline.h \ - src/dialogs/dialogcutsplinepath.h \ - src/dialogs/dialoguniondetails.h \ - src/dialogs/dialogcutarc.h \ - src/dialogs/configdialog.h \ - src/dialogs/pages.h \ - src/dialogs/dialogpatternproperties.h + src/dialogs/tools/dialogtriangle.h \ + src/dialogs/tools/dialogtool.h \ + src/dialogs/tools/dialogsplinepath.h \ + src/dialogs/tools/dialogspline.h \ + src/dialogs/tools/dialogsinglepoint.h \ + src/dialogs/tools/dialogshoulderpoint.h \ + src/dialogs/tools/dialogpointofintersection.h \ + src/dialogs/tools/dialogpointofcontact.h \ + src/dialogs/tools/dialognormal.h \ + src/dialogs/tools/dialoglineintersect.h \ + src/dialogs/tools/dialogline.h \ + src/dialogs/tools/dialogheight.h \ + src/dialogs/tools/dialogendline.h \ + src/dialogs/tools/dialogdetail.h \ + src/dialogs/tools/dialogbisector.h \ + src/dialogs/tools/dialogarc.h \ + src/dialogs/tools/dialogalongline.h \ + src/dialogs/tools/dialogcutspline.h \ + src/dialogs/tools/dialogcutsplinepath.h \ + src/dialogs/tools/dialoguniondetails.h \ + src/dialogs/tools/dialogcutarc.h \ + src/dialogs/app/dialogincrements.h \ + src/dialogs/app/dialoghistory.h \ + src/dialogs/app/configdialog.h \ + src/dialogs/app/pages.h \ + src/dialogs/app/dialogpatternproperties.h \ + src/dialogs/app/dialogmeasurements.h \ + src/dialogs/app/dialogstandardmeasurements.h \ + src/dialogs/app/dialogindividualmeasurements.h SOURCES += \ - src/dialogs/dialogtriangle.cpp \ - src/dialogs/dialogtool.cpp \ - src/dialogs/dialogsplinepath.cpp \ - src/dialogs/dialogspline.cpp \ - src/dialogs/dialogsinglepoint.cpp \ - src/dialogs/dialogshoulderpoint.cpp \ - src/dialogs/dialogpointofintersection.cpp \ - src/dialogs/dialogpointofcontact.cpp \ - src/dialogs/dialognormal.cpp \ - src/dialogs/dialoglineintersect.cpp \ - src/dialogs/dialogline.cpp \ - src/dialogs/dialogincrements.cpp \ - src/dialogs/dialoghistory.cpp \ - src/dialogs/dialogheight.cpp \ - src/dialogs/dialogendline.cpp \ - src/dialogs/dialogdetail.cpp \ - src/dialogs/dialogbisector.cpp \ - src/dialogs/dialogarc.cpp \ - src/dialogs/dialogalongline.cpp \ - src/dialogs/dialogcutspline.cpp \ - src/dialogs/dialogcutsplinepath.cpp \ - src/dialogs/dialoguniondetails.cpp \ - src/dialogs/dialogcutarc.cpp \ - src/dialogs/configdialog.cpp \ - src/dialogs/pages.cpp \ - src/dialogs/dialogpatternproperties.cpp + src/dialogs/tools/dialogtriangle.cpp \ + src/dialogs/tools/dialogtool.cpp \ + src/dialogs/tools/dialogsplinepath.cpp \ + src/dialogs/tools/dialogspline.cpp \ + src/dialogs/tools/dialogsinglepoint.cpp \ + src/dialogs/tools/dialogshoulderpoint.cpp \ + src/dialogs/tools/dialogpointofintersection.cpp \ + src/dialogs/tools/dialogpointofcontact.cpp \ + src/dialogs/tools/dialognormal.cpp \ + src/dialogs/tools/dialoglineintersect.cpp \ + src/dialogs/tools/dialogline.cpp \ + src/dialogs/tools/dialogheight.cpp \ + src/dialogs/tools/dialogendline.cpp \ + src/dialogs/tools/dialogdetail.cpp \ + src/dialogs/tools/dialogbisector.cpp \ + src/dialogs/tools/dialogarc.cpp \ + src/dialogs/tools/dialogalongline.cpp \ + src/dialogs/tools/dialogcutspline.cpp \ + src/dialogs/tools/dialogcutsplinepath.cpp \ + src/dialogs/tools/dialoguniondetails.cpp \ + src/dialogs/tools/dialogcutarc.cpp \ + src/dialogs/app/dialogincrements.cpp \ + src/dialogs/app/dialoghistory.cpp \ + src/dialogs/app/configdialog.cpp \ + src/dialogs/app/pages.cpp \ + src/dialogs/app/dialogpatternproperties.cpp \ + src/dialogs/app/dialogmeasurements.cpp \ + src/dialogs/app/dialogstandardmeasurements.cpp \ + src/dialogs/app/dialogindividualmeasurements.cpp FORMS += \ - src/dialogs/dialogtriangle.ui \ - src/dialogs/dialogsplinepath.ui \ - src/dialogs/dialogspline.ui \ - src/dialogs/dialogsinglepoint.ui \ - src/dialogs/dialogshoulderpoint.ui \ - src/dialogs/dialogpointofintersection.ui \ - src/dialogs/dialogpointofcontact.ui \ - src/dialogs/dialognormal.ui \ - src/dialogs/dialoglineintersect.ui \ - src/dialogs/dialogline.ui \ - src/dialogs/dialogincrements.ui \ - src/dialogs/dialoghistory.ui \ - src/dialogs/dialogheight.ui \ - src/dialogs/dialogendline.ui \ - src/dialogs/dialogdetail.ui \ - src/dialogs/dialogbisector.ui \ - src/dialogs/dialogarc.ui \ - src/dialogs/dialogalongline.ui \ - src/dialogs/dialogcutspline.ui \ - src/dialogs/dialogcutsplinepath.ui \ - src/dialogs/dialoguniondetails.ui \ - src/dialogs/dialogcutarc.ui \ - src/dialogs/dialogpatternproperties.ui + src/dialogs/tools/dialogtriangle.ui \ + src/dialogs/tools/dialogsplinepath.ui \ + src/dialogs/tools/dialogspline.ui \ + src/dialogs/tools/dialogsinglepoint.ui \ + src/dialogs/tools/dialogshoulderpoint.ui \ + src/dialogs/tools/dialogpointofintersection.ui \ + src/dialogs/tools/dialogpointofcontact.ui \ + src/dialogs/tools/dialognormal.ui \ + src/dialogs/tools/dialoglineintersect.ui \ + src/dialogs/tools/dialogline.ui \ + src/dialogs/tools/dialogheight.ui \ + src/dialogs/tools/dialogendline.ui \ + src/dialogs/tools/dialogdetail.ui \ + src/dialogs/tools/dialogbisector.ui \ + src/dialogs/tools/dialogarc.ui \ + src/dialogs/tools/dialogalongline.ui \ + src/dialogs/tools/dialogcutspline.ui \ + src/dialogs/tools/dialogcutsplinepath.ui \ + src/dialogs/tools/dialoguniondetails.ui \ + src/dialogs/tools/dialogcutarc.ui \ + src/dialogs/app/dialogincrements.ui \ + src/dialogs/app/dialoghistory.ui \ + src/dialogs/app/dialogpatternproperties.ui \ + src/dialogs/app/dialogmeasurements.ui \ + src/dialogs/app/dialogstandardmeasurements.ui \ + src/dialogs/app/dialogindividualmeasurements.ui diff --git a/src/dialogs/dialogalongline.cpp b/src/dialogs/tools/dialogalongline.cpp similarity index 59% rename from src/dialogs/dialogalongline.cpp rename to src/dialogs/tools/dialogalongline.cpp index f7d1f21ee..d9c7b7532 100644 --- a/src/dialogs/dialogalongline.cpp +++ b/src/dialogs/tools/dialogalongline.cpp @@ -36,44 +36,27 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0) { ui->setupUi(this); - listWidget = ui->listWidget; labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; - labelEditNamePoint = ui->labelEditNamePoint; + flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogAlongLine::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogAlongLine::DialogRejected); + InitOkCansel(ui); + FillComboBoxTypeLine(ui->comboBoxLineType); ui->comboBoxLineType->setCurrentIndex(0); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); + labelEditNamePoint = ui->labelEditNamePoint; connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere); - connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogAlongLine::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogAlongLine::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogAlongLine::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogAlongLine::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogAlongLine::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogAlongLine::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogAlongLine::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogAlongLine::LengthCurves); - connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged); + InitVariables(ui); + connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal); } DialogAlongLine::~DialogAlongLine() @@ -81,34 +64,27 @@ DialogAlongLine::~DialogAlongLine() delete ui; } -void DialogAlongLine::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogAlongLine::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { - const VPointF *point = data->GeometricObject(id); if (number == 0) { - qint32 index = ui->comboBoxFirstPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxFirstPoint->setCurrentIndex(index); + if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) + { number++; - emit ToolTip(tr("Select second point of line")); return; } } if (number == 1) { - qint32 index = ui->comboBoxSecondPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxSecondPoint->setCurrentIndex(index); - number = 0; - emit ToolTip(""); - } - if (isInitialized == false) + if (ChoosedPoint(id, ui->comboBoxSecondPoint, "")) { - this->show(); + number = 0; + if (isInitialized == false) + { + this->show(); + } } } } @@ -124,12 +100,12 @@ void DialogAlongLine::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogAlongLine::setSecondPointId(const qint64 &value, const qint64 &id) +void DialogAlongLine::setSecondPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -void DialogAlongLine::setFirstPointId(const qint64 &value, const qint64 &id) +void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } diff --git a/src/dialogs/dialogalongline.h b/src/dialogs/tools/dialogalongline.h similarity index 75% rename from src/dialogs/dialogalongline.h rename to src/dialogs/tools/dialogalongline.h index 33acbc715..5aa093457 100644 --- a/src/dialogs/dialogalongline.h +++ b/src/dialogs/tools/dialogalongline.h @@ -43,18 +43,18 @@ class DialogAlongLine : public DialogTool { Q_OBJECT public: - /** - * @brief DialogAlongLine create dialog - * @param data container with data - * @param parent parent widget - */ - DialogAlongLine(const VContainer *data, QWidget *parent = 0); - ~DialogAlongLine(); + /** + * @brief DialogAlongLine create dialog + * @param data container with data + * @param parent parent widget + */ + DialogAlongLine(const VContainer *data, QWidget *parent = nullptr); + ~DialogAlongLine(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -64,7 +64,7 @@ public: * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type @@ -74,7 +74,7 @@ public: * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula @@ -84,31 +84,31 @@ public: * @brief getFirstPointId return id first point of line * @return id */ - inline qint64 getFirstPointId() const {return firstPointId;} + quint32 getFirstPointId() const; /** * @brief setFirstPointId set id first point of line * @param value id * @param id id of current point */ - void setFirstPointId(const qint64 &value, const qint64 &id); + void setFirstPointId(const quint32 &value, const quint32 &id); /** * @brief getSecondPointId return id second point of line * @return id */ - inline qint64 getSecondPointId() const {return secondPointId;} + quint32 getSecondPointId() const; /** * @brief setSecondPointId set id second point of line * @param value id * @param id id of current point */ - void setSecondPointId(const qint64 &value, const qint64 &id); + void setSecondPointId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -138,11 +138,36 @@ private: /** * @brief firstPointId id first point of line */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second point of line */ - qint64 secondPointId; + quint32 secondPointId; }; +inline QString DialogAlongLine::getPointName() const +{ + return pointName; +} + +inline QString DialogAlongLine::getTypeLine() const +{ + return typeLine; +} + +inline QString DialogAlongLine::getFormula() const +{ + return formula; +} + +inline quint32 DialogAlongLine::getFirstPointId() const +{ + return firstPointId; +} + +inline quint32 DialogAlongLine::getSecondPointId() const +{ + return secondPointId; +} + #endif // DIALOGALONGLINE_H diff --git a/src/dialogs/dialogalongline.ui b/src/dialogs/tools/dialogalongline.ui similarity index 100% rename from src/dialogs/dialogalongline.ui rename to src/dialogs/tools/dialogalongline.ui diff --git a/src/dialogs/dialogarc.cpp b/src/dialogs/tools/dialogarc.cpp similarity index 77% rename from src/dialogs/dialogarc.cpp rename to src/dialogs/tools/dialogarc.cpp index 5056dc055..97be1a470 100644 --- a/src/dialogs/dialogarc.cpp +++ b/src/dialogs/tools/dialogarc.cpp @@ -34,7 +34,7 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), - timerRadius(0), timerF1(0), timerF2(0), center(0), radius(QString()), f1(QString()), f2(QString()) + timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()), f2(QString()) { ui->setupUi(this); @@ -47,38 +47,17 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogArc::DialogAccepted); - - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogArc::DialogRejected); + InitOkCansel(ui); FillComboBoxPoints(ui->comboBoxBasePoint); CheckState(); - listWidget = ui->listWidget; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; + InitVariables(ui); connect(ui->toolButtonPutHereRadius, &QPushButton::clicked, this, &DialogArc::PutRadius); connect(ui->toolButtonPutHereF1, &QPushButton::clicked, this, &DialogArc::PutF1); connect(ui->toolButtonPutHereF2, &QPushButton::clicked, this, &DialogArc::PutF2); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogArc::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogArc::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogArc::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogArc::LengthLines); - connect(ui->radioButtonLineAngles, &QRadioButton::clicked, this, &DialogArc::LineAngles); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogArc::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogArc::LengthCurves); connect(ui->toolButtonEqualRadius, &QPushButton::clicked, this, &DialogArc::EvalRadius); connect(ui->toolButtonEqualF1, &QPushButton::clicked, this, &DialogArc::EvalF1); @@ -94,7 +73,7 @@ DialogArc::~DialogArc() delete ui; } -void DialogArc::SetCenter(const qint64 &value) +void DialogArc::SetCenter(const quint32 &value) { center = value; ChangeCurrentData(ui->comboBoxBasePoint, center); @@ -118,9 +97,9 @@ void DialogArc::SetRadius(const QString &value) ui->lineEditRadius->setText(radius); } -void DialogArc::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogArc::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); diff --git a/src/dialogs/dialogarc.h b/src/dialogs/tools/dialogarc.h similarity index 73% rename from src/dialogs/dialogarc.h rename to src/dialogs/tools/dialogarc.h index d472ad928..0611c9b94 100644 --- a/src/dialogs/dialogarc.h +++ b/src/dialogs/tools/dialogarc.h @@ -43,164 +43,184 @@ class DialogArc : public DialogTool { Q_OBJECT public: - /** - * @brief DialogArc create dialog - * @param data container with data - * @param parent parent widget - */ - DialogArc(const VContainer *data, QWidget *parent = 0); - ~DialogArc(); + /** + * @brief DialogArc create dialog + * @param data container with data + * @param parent parent widget + */ + DialogArc(const VContainer *data, QWidget *parent = nullptr); + ~DialogArc(); /** * @brief GetCenter return id of center point * @return id id */ - inline qint64 GetCenter() const {return center;} + quint32 GetCenter() const; /** * @brief SetCenter set id of center point * @param value id */ - void SetCenter(const qint64 &value); + void SetCenter(const quint32 &value); /** * @brief GetRadius return formula of radius * @return formula */ - inline QString GetRadius() const {return radius;} + QString GetRadius() const; /** * @brief SetRadius set formula of radius * @param value formula */ - void SetRadius(const QString &value); + void SetRadius(const QString &value); /** * @brief GetF1 return formula first angle of arc * @return formula */ - inline QString GetF1() const {return f1;} + QString GetF1() const; /** * @brief SetF1 set formula first angle of arc * @param value formula */ - void SetF1(const QString &value); + void SetF1(const QString &value); /** * @brief GetF2 return formula second angle of arc * @return formula */ - inline QString GetF2() const {return f2;} + QString GetF2() const; /** * @brief SetF2 set formula second angle of arc * @param value formula */ - void SetF2(const QString &value); + void SetF2(const QString &value); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ - virtual void DialogAccepted(); + virtual void DialogAccepted(); /** * @brief ValChenged show description angles of lines * @param row number of row */ - virtual void ValChenged(int row); + virtual void ValChenged(int row); /** * @brief PutRadius put variable into formula of radius */ - void PutRadius(); + void PutRadius(); /** * @brief PutF1 put variable into formula of first angle */ - void PutF1(); + void PutF1(); /** * @brief PutF2 put variable into formula of second angle */ - void PutF2(); + void PutF2(); /** * @brief LineAngles show variable angles of lines */ - void LineAngles(); + void LineAngles(); /** * @brief RadiusChanged after change formula of radius calculate value and show result */ - void RadiusChanged(); + void RadiusChanged(); /** * @brief F1Changed after change formula of first angle calculate value and show result */ - void F1Changed(); + void F1Changed(); /** * @brief F2Changed after change formula of second angle calculate value and show result */ - void F2Changed(); + void F2Changed(); protected: /** * @brief CheckState if all is right enable button ok */ - virtual void CheckState(); + virtual void CheckState(); private: Q_DISABLE_COPY(DialogArc) /** * @brief ui keeps information about user interface */ - Ui::DialogArc *ui; + Ui::DialogArc *ui; /** * @brief flagRadius true if value of radius is correct */ - bool flagRadius; + bool flagRadius; /** * @brief flagF1 true if value of first angle is correct */ - bool flagF1; + bool flagF1; /** * @brief flagF2 true if value of second angle is correct */ - bool flagF2; + bool flagF2; /** * @brief timerRadius timer of check formula of radius */ - QTimer *timerRadius; + QTimer *timerRadius; /** * @brief timerF1 timer of check formula of first angle */ - QTimer *timerF1; + QTimer *timerF1; /** * @brief timerF2 timer of check formula of second angle */ - QTimer *timerF2; + QTimer *timerF2; /** * @brief center id of center point */ - qint64 center; + quint32 center; /** * @brief radius formula of radius */ - QString radius; + QString radius; /** * @brief f1 formula of first angle */ - QString f1; + QString f1; /** * @brief f2 formula of second angle */ - QString f2; + QString f2; /** * @brief EvalRadius calculate value of radius */ - void EvalRadius(); + void EvalRadius(); /** * @brief EvalF1 calculate value of first angle */ - void EvalF1(); + void EvalF1(); /** * @brief EvalF2 calculate value of second angle */ - void EvalF2(); + void EvalF2(); /** * @brief ShowLineAngles show varibles angles of lines */ - void ShowLineAngles(); + void ShowLineAngles(); }; +inline quint32 DialogArc::GetCenter() const +{ + return center; +} + +inline QString DialogArc::GetRadius() const +{ + return radius; +} + +inline QString DialogArc::GetF1() const +{ + return f1; +} + +inline QString DialogArc::GetF2() const +{ + return f2; +} + #endif // DIALOGARC_H diff --git a/src/dialogs/dialogarc.ui b/src/dialogs/tools/dialogarc.ui similarity index 100% rename from src/dialogs/dialogarc.ui rename to src/dialogs/tools/dialogarc.ui diff --git a/src/dialogs/dialogbisector.cpp b/src/dialogs/tools/dialogbisector.cpp similarity index 71% rename from src/dialogs/dialogbisector.cpp rename to src/dialogs/tools/dialogbisector.cpp index 50500f263..e0003192a 100644 --- a/src/dialogs/dialogbisector.cpp +++ b/src/dialogs/tools/dialogbisector.cpp @@ -36,25 +36,15 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0) { ui->setupUi(this); - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + InitOkCansel(ui); flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogBisector::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogBisector::DialogRejected); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); @@ -62,16 +52,8 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) FillComboBoxTypeLine(ui->comboBoxLineType); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogBisector::PutHere); - connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogBisector::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogBisector::ValChenged); + connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogBisector::PutVal); - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogBisector::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogBisector::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogBisector::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogBisector::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogBisector::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogBisector::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogBisector::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogBisector::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogBisector::FormulaChanged); @@ -82,9 +64,9 @@ DialogBisector::~DialogBisector() delete ui; } -void DialogBisector::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogBisector::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) @@ -144,17 +126,17 @@ void DialogBisector::setFormula(const QString &value) ui->lineEditFormula->setText(formula); } -void DialogBisector::setFirstPointId(const qint64 &value, const qint64 &id) +void DialogBisector::setFirstPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } -void DialogBisector::setSecondPointId(const qint64 &value, const qint64 &id) +void DialogBisector::setSecondPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -void DialogBisector::setThirdPointId(const qint64 &value, const qint64 &id) +void DialogBisector::setThirdPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxThirdPoint, thirdPointId, value, id); } diff --git a/src/dialogs/dialogbisector.h b/src/dialogs/tools/dialogbisector.h similarity index 69% rename from src/dialogs/dialogbisector.h rename to src/dialogs/tools/dialogbisector.h index ec4168754..6b928f807 100644 --- a/src/dialogs/dialogbisector.h +++ b/src/dialogs/tools/dialogbisector.h @@ -43,87 +43,87 @@ class DialogBisector : public DialogTool { Q_OBJECT public: - /** - * @brief DialogBisector create dialog - * @param data container with data - * @param parent parent widget - */ - DialogBisector(const VContainer *data, QWidget *parent = 0); - ~DialogBisector(); + /** + * @brief DialogBisector create dialog + * @param data container with data + * @param parent parent widget + */ + DialogBisector(const VContainer *data, QWidget *parent = nullptr); + ~DialogBisector(); /** * @brief getPointName return name of point * @return name */ - QString getPointName() const {return pointName;} + QString getPointName() const {return pointName;} /** * @brief setPointName set name of point * @param value name */ - void setPointName(const QString &value); + void setPointName(const QString &value); /** * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type */ - void setTypeLine(const QString &value); + void setTypeLine(const QString &value); /** * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula */ - void setFormula(const QString &value); + void setFormula(const QString &value); /** * @brief getFirstPointId return id of first point * @return id */ - inline qint64 getFirstPointId() const {return firstPointId;} + quint32 getFirstPointId() const; /** * @brief setFirstPointId set id of first point * @param value id * @param id don't show this id in list */ - void setFirstPointId(const qint64 &value, const qint64 &id); + void setFirstPointId(const quint32 &value, const quint32 &id); /** * @brief getSecondPointId return id of second point * @return id */ - inline qint64 getSecondPointId() const {return secondPointId;} + quint32 getSecondPointId() const; /** * @brief setSecondPointId set id of second point * @param value id * @param id don't show this id in list */ - void setSecondPointId(const qint64 &value, const qint64 &id); + void setSecondPointId(const quint32 &value, const quint32 &id); /** * @brief getThirdPointId return id of third point * @return id */ - inline qint64 getThirdPointId() const {return thirdPointId;} + quint32 getThirdPointId() const; /** * @brief setThirdPointId set id of third point * @param value id * @param id don't show this id in list */ - void setThirdPointId(const qint64 &value, const qint64 &id); + void setThirdPointId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ - virtual void DialogAccepted(); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogBisector) /** @@ -149,15 +149,40 @@ private: /** * @brief firstPointId id of first point */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id of second point */ - qint64 secondPointId; + quint32 secondPointId; /** * @brief thirdPointId id of third point */ - qint64 thirdPointId; + quint32 thirdPointId; }; +inline QString DialogBisector::getTypeLine() const +{ + return typeLine; +} + +inline QString DialogBisector::getFormula() const +{ + return formula; +} + +inline quint32 DialogBisector::getFirstPointId() const +{ + return firstPointId; +} + +inline quint32 DialogBisector::getSecondPointId() const +{ + return secondPointId; +} + +inline quint32 DialogBisector::getThirdPointId() const +{ + return thirdPointId; +} + #endif // DIALOGBISECTOR_H diff --git a/src/dialogs/dialogbisector.ui b/src/dialogs/tools/dialogbisector.ui similarity index 100% rename from src/dialogs/dialogbisector.ui rename to src/dialogs/tools/dialogbisector.ui diff --git a/src/dialogs/dialogcutarc.cpp b/src/dialogs/tools/dialogcutarc.cpp similarity index 65% rename from src/dialogs/dialogcutarc.cpp rename to src/dialogs/tools/dialogcutarc.cpp index 71d9c919a..2206bec4d 100644 --- a/src/dialogs/dialogcutarc.cpp +++ b/src/dialogs/tools/dialogcutarc.cpp @@ -33,39 +33,22 @@ DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : DialogTool(data, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), arcId(0) { ui->setupUi(this); - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + + InitOkCansel(ui); flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogCutArc::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogCutArc::DialogRejected); FillComboBoxArcs(ui->comboBoxArc); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutArc::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogCutArc::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCutArc::ValChenged); - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogCutArc::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogCutArc::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogCutArc::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogCutArc::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogCutArc::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogCutArc::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutArc::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogCutArc::FormulaChanged); @@ -76,9 +59,9 @@ DialogCutArc::~DialogCutArc() delete ui; } -void DialogCutArc::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogCutArc::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Arc) + if (type == Valentina::Arc) { const VArc *arc = data->GeometricObject(id); ChangeCurrentText(ui->comboBoxArc, arc->name()); @@ -95,7 +78,7 @@ void DialogCutArc::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogCutArc::setArcId(const qint64 &value, const qint64 &id) +void DialogCutArc::setArcId(const quint32 &value, const quint32 &id) { setCurrentArcId(ui->comboBoxArc, arcId, value, id, ComboMode::CutArc); } diff --git a/src/dialogs/dialogcutarc.h b/src/dialogs/tools/dialogcutarc.h similarity index 91% rename from src/dialogs/dialogcutarc.h rename to src/dialogs/tools/dialogcutarc.h index 0baf2dcbc..c2af664e9 100644 --- a/src/dialogs/dialogcutarc.h +++ b/src/dialogs/tools/dialogcutarc.h @@ -48,7 +48,7 @@ public: * @param data container with data * @param parent parent widget */ - DialogCutArc(const VContainer *data, QWidget *parent = 0); + DialogCutArc(const VContainer *data, QWidget *parent = nullptr); ~DialogCutArc(); /** * @brief getPointName return name point on arc @@ -74,20 +74,20 @@ public: * @brief getArcId return id of arc * @return id */ - qint64 getArcId() const {return arcId;} + quint32 getArcId() const {return arcId;} /** * @brief setArcId set id of arc * @param value id * @param id don't show this id in list */ - void setArcId(const qint64 &value, const qint64 &id); + void setArcId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -109,7 +109,7 @@ private: /** * @brief arcId keep id of arc */ - qint64 arcId; + quint32 arcId; }; #endif // DIALOGCUTARC_H diff --git a/src/dialogs/dialogcutarc.ui b/src/dialogs/tools/dialogcutarc.ui similarity index 100% rename from src/dialogs/dialogcutarc.ui rename to src/dialogs/tools/dialogcutarc.ui diff --git a/src/dialogs/dialogcutspline.cpp b/src/dialogs/tools/dialogcutspline.cpp similarity index 65% rename from src/dialogs/dialogcutspline.cpp rename to src/dialogs/tools/dialogcutspline.cpp index 988faea7e..ce959b199 100644 --- a/src/dialogs/dialogcutspline.cpp +++ b/src/dialogs/tools/dialogcutspline.cpp @@ -33,39 +33,21 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), splineId(0) { ui->setupUi(this); - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + InitOkCansel(ui); + flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogCutSpline::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogCutSpline::DialogRejected); FillComboBoxSplines(ui->comboBoxSpline); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSpline::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogCutSpline::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCutSpline::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogCutSpline::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogCutSpline::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogCutSpline::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogCutSpline::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogCutSpline::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogCutSpline::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutSpline::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogCutSpline::FormulaChanged); @@ -88,14 +70,14 @@ void DialogCutSpline::setFormula(const QString &value) ui->lineEditFormula->setText(formula); } -void DialogCutSpline::setSplineId(const qint64 &value, const qint64 &id) +void DialogCutSpline::setSplineId(const quint32 &value, const quint32 &id) { setCurrentSplineId(ui->comboBoxSpline, splineId, value, id, ComboMode::CutSpline); } -void DialogCutSpline::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogCutSpline::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Spline) + if (type == Valentina::Spline) { const VSpline *spl = data->GeometricObject(id); ChangeCurrentText(ui->comboBoxSpline, spl->name()); diff --git a/src/dialogs/dialogcutspline.h b/src/dialogs/tools/dialogcutspline.h similarity index 76% rename from src/dialogs/dialogcutspline.h rename to src/dialogs/tools/dialogcutspline.h index 17d6f6bae..88d4c634b 100644 --- a/src/dialogs/dialogcutspline.h +++ b/src/dialogs/tools/dialogcutspline.h @@ -48,50 +48,50 @@ public: * @param data container with data * @param parent parent widget */ - DialogCutSpline(const VContainer *data, QWidget *parent = 0); + DialogCutSpline(const VContainer *data, QWidget *parent = nullptr); ~DialogCutSpline(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name */ - void setPointName(const QString &value); + void setPointName(const QString &value); /** * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula */ - void setFormula(const QString &value); + void setFormula(const QString &value); /** * @brief getSplineId return id base point of line * @return id */ - inline qint64 getSplineId() const {return splineId;} + quint32 getSplineId() const; /** * @brief setSplineId set id spline * @param value id * @param id don't show this id in list */ - void setSplineId(const qint64 &value, const qint64 &id); + void setSplineId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ - virtual void DialogAccepted(); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogCutSpline) /** @@ -101,15 +101,30 @@ private: /** * @brief pointName name of created point */ - QString pointName; + QString pointName; /** * @brief formula string with formula */ - QString formula; + QString formula; /** * @brief splineId keep id of spline */ - qint64 splineId; + quint32 splineId; }; +inline QString DialogCutSpline::getPointName() const +{ + return pointName; +} + +inline QString DialogCutSpline::getFormula() const +{ + return formula; +} + +inline quint32 DialogCutSpline::getSplineId() const +{ + return splineId; +} + #endif // DIALOGCUTSPLINE_H diff --git a/src/dialogs/dialogcutspline.ui b/src/dialogs/tools/dialogcutspline.ui similarity index 100% rename from src/dialogs/dialogcutspline.ui rename to src/dialogs/tools/dialogcutspline.ui diff --git a/src/dialogs/dialogcutsplinepath.cpp b/src/dialogs/tools/dialogcutsplinepath.cpp similarity index 65% rename from src/dialogs/dialogcutsplinepath.cpp rename to src/dialogs/tools/dialogcutsplinepath.cpp index 561b47f5c..003383392 100644 --- a/src/dialogs/dialogcutsplinepath.cpp +++ b/src/dialogs/tools/dialogcutsplinepath.cpp @@ -34,39 +34,21 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent splinePathId(0) { ui->setupUi(this); - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + + InitOkCansel(ui); flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogCutSplinePath::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogCutSplinePath::DialogRejected); FillComboBoxSplinesPath(ui->comboBoxSplinePath); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSplinePath::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogCutSplinePath::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCutSplinePath::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogCutSplinePath::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogCutSplinePath::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogCutSplinePath::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogCutSplinePath::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogCutSplinePath::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogCutSplinePath::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutSplinePath::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged); @@ -89,14 +71,14 @@ void DialogCutSplinePath::setFormula(const QString &value) ui->lineEditFormula->setText(formula); } -void DialogCutSplinePath::setSplinePathId(const qint64 &value, const qint64 &id) +void DialogCutSplinePath::setSplinePathId(const quint32 &value, const quint32 &id) { setCurrentSplinePathId(ui->comboBoxSplinePath, splinePathId, value, id, ComboMode::CutSpline); } -void DialogCutSplinePath::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogCutSplinePath::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::SplinePath) + if (type == Valentina::SplinePath) { const VSplinePath *splPath = data->GeometricObject(id); ChangeCurrentText(ui->comboBoxSplinePath, splPath->name()); diff --git a/src/dialogs/dialogcutsplinepath.h b/src/dialogs/tools/dialogcutsplinepath.h similarity index 79% rename from src/dialogs/dialogcutsplinepath.h rename to src/dialogs/tools/dialogcutsplinepath.h index b4dadc0b1..622d1f73d 100644 --- a/src/dialogs/dialogcutsplinepath.h +++ b/src/dialogs/tools/dialogcutsplinepath.h @@ -48,50 +48,50 @@ public: * @param data container with data * @param parent parent widget */ - DialogCutSplinePath(const VContainer *data, QWidget *parent = 0); + DialogCutSplinePath(const VContainer *data, QWidget *parent = nullptr); ~DialogCutSplinePath(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name */ - void setPointName(const QString &value); + void setPointName(const QString &value); /** * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula */ - void setFormula(const QString &value); + void setFormula(const QString &value); /** * @brief getSplineId return id base point of line * @return id */ - inline qint64 getSplinePathId() const {return splinePathId;} + quint32 getSplinePathId() const; /** * @brief setSplineId set id spline * @param value id * @param id don't show this id in list */ - void setSplinePathId(const qint64 &value, const qint64 &id); + void setSplinePathId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ - virtual void DialogAccepted(); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogCutSplinePath) /** @@ -101,15 +101,30 @@ private: /** * @brief pointName name of created point */ - QString pointName; + QString pointName; /** * @brief formula string with formula */ - QString formula; + QString formula; /** * @brief splinePathId keep id of splinePath */ - qint64 splinePathId; + quint32 splinePathId; }; +inline QString DialogCutSplinePath::getPointName() const +{ + return pointName; +} + +inline QString DialogCutSplinePath::getFormula() const +{ + return formula; +} + +inline quint32 DialogCutSplinePath::getSplinePathId() const +{ + return splinePathId; +} + #endif // DIALOGCUTSPLINEPATH_H diff --git a/src/dialogs/dialogcutsplinepath.ui b/src/dialogs/tools/dialogcutsplinepath.ui similarity index 100% rename from src/dialogs/dialogcutsplinepath.ui rename to src/dialogs/tools/dialogcutsplinepath.ui diff --git a/src/dialogs/dialogdetail.cpp b/src/dialogs/tools/dialogdetail.cpp similarity index 81% rename from src/dialogs/dialogdetail.cpp rename to src/dialogs/tools/dialogdetail.cpp index a465d7764..b877cca27 100644 --- a/src/dialogs/dialogdetail.cpp +++ b/src/dialogs/tools/dialogdetail.cpp @@ -36,8 +36,13 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) { ui.setupUi(this); labelEditNamePoint = ui.labelEditNameDetail; + bOk = ui.buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogDetail::DialogAccepted); + Q_CHECK_PTR(bOk); + connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); + QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); + Q_CHECK_PTR(bCansel); + connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); flagName = true;//We have default name of detail. QPalette palette = labelEditNamePoint->palette(); @@ -45,9 +50,6 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) labelEditNamePoint->setPalette(palette); CheckState(); - QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogDetail::DialogRejected); - connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogDetail::ObjectChanged); connect(ui.spinBoxBiasX, static_cast(&QSpinBox::valueChanged), this, &DialogDetail::BiasXChanged); @@ -60,26 +62,26 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem); } -void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogDetail::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type != Scene::Line && type != Scene::Detail) + if (type != Valentina::Line && type != Valentina::Detail) { switch (type) { - case (Scene::Arc): - NewItem(id, Tool::NodeArc, NodeDetail::Contour); + case (Valentina::Arc): + NewItem(id, Valentina::NodeArc, NodeDetail::Contour); break; - case (Scene::Point): - NewItem(id, Tool::NodePoint, NodeDetail::Contour); + case (Valentina::Point): + NewItem(id, Valentina::NodePoint, NodeDetail::Contour); break; - case (Scene::Spline): - NewItem(id, Tool::NodeSpline, NodeDetail::Contour); + case (Valentina::Spline): + NewItem(id, Valentina::NodeSpline, NodeDetail::Contour); break; - case (Scene::SplinePath): - NewItem(id, Tool::NodeSplinePath, NodeDetail::Contour); + case (Valentina::SplinePath): + NewItem(id, Valentina::NodeSplinePath, NodeDetail::Contour); break; default: - qWarning()<setEnabled(true); @@ -103,38 +105,38 @@ void DialogDetail::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogDetail::NewItem(qint64 id, const Tool::Tools &typeTool, const NodeDetail::NodeDetails &typeNode, qreal mx, +void DialogDetail::NewItem(quint32 id, const Valentina::Tools &typeTool, const NodeDetail::NodeDetails &typeNode, qreal mx, qreal my) { QString name; switch (typeTool) { - case (Tool::NodePoint): + case (Valentina::NodePoint): { const VPointF *point = data->GeometricObject(id); name = point->name(); break; } - case (Tool::NodeArc): + case (Valentina::NodeArc): { const VArc *arc = data->GeometricObject(id); name = arc->name(); break; } - case (Tool::NodeSpline): + case (Valentina::NodeSpline): { const VSpline *spl = data->GeometricObject(id); name = spl->name(); break; } - case (Tool::NodeSplinePath): + case (Valentina::NodeSplinePath): { const VSplinePath *splPath = data->GeometricObject(id); name = splPath->name(); break; } default: - qWarning()<(&QSpinBox::valueChanged), this, &DialogDetail::BiasYChanged); - ui.spinBoxBiasX->setValue(static_cast(toMM(node.getMx()))); - ui.spinBoxBiasY->setValue(static_cast(toMM(node.getMy()))); + ui.spinBoxBiasX->setValue(static_cast(qApp->fromPixel(node.getMx()))); + ui.spinBoxBiasY->setValue(static_cast(qApp->fromPixel(node.getMy()))); connect(ui.spinBoxBiasX, static_cast(&QSpinBox::valueChanged), this, &DialogDetail::BiasXChanged); connect(ui.spinBoxBiasY, static_cast(&QSpinBox::valueChanged), @@ -182,7 +184,7 @@ void DialogDetail::BiasXChanged(qreal d) QListWidgetItem *item = ui.listWidget->item( row ); Q_CHECK_PTR(item); VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); - node.setMx(toPixel(d)); + node.setMx(qApp->toPixel(d)); item->setData(Qt::UserRole, QVariant::fromValue(node)); } @@ -192,7 +194,7 @@ void DialogDetail::BiasYChanged(qreal d) QListWidgetItem *item = ui.listWidget->item( row ); Q_CHECK_PTR(item); VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); - node.setMy(toPixel(d)); + node.setMy(qApp->toPixel(d)); item->setData(Qt::UserRole, QVariant::fromValue(node)); } @@ -216,8 +218,8 @@ void DialogDetail::ObjectChanged(int row) } QListWidgetItem *item = ui.listWidget->item( row ); VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); - ui.spinBoxBiasX->setValue(static_cast(toMM(node.getMx()))); - ui.spinBoxBiasY->setValue(static_cast(toMM(node.getMy()))); + ui.spinBoxBiasX->setValue(static_cast(qApp->fromPixel(node.getMx()))); + ui.spinBoxBiasY->setValue(static_cast(qApp->fromPixel(node.getMy()))); } void DialogDetail::DeleteItem() diff --git a/src/dialogs/dialogdetail.h b/src/dialogs/tools/dialogdetail.h similarity index 92% rename from src/dialogs/dialogdetail.h rename to src/dialogs/tools/dialogdetail.h index c02c41940..38dbe5a3b 100644 --- a/src/dialogs/dialogdetail.h +++ b/src/dialogs/tools/dialogdetail.h @@ -44,12 +44,12 @@ public: * @param data container with data * @param parent parent widget */ - DialogDetail(const VContainer *data, QWidget *parent = 0); + DialogDetail(const VContainer *data, QWidget *parent = nullptr); /** * @brief getDetails return detail * @return detail */ - inline VDetail getDetails() const {return details;} + VDetail getDetails() const; /** * @brief setDetails set detail * @param value detail @@ -61,7 +61,7 @@ public slots: * @param id id of objects (points, arcs, splines, spline paths) * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -121,8 +121,13 @@ private: * @param mx offset respect to x * @param my offset respect to y */ - void NewItem(qint64 id, const Tool::Tools &typeTool, const NodeDetail::NodeDetails &typeNode, + void NewItem(quint32 id, const Valentina::Tools &typeTool, const NodeDetail::NodeDetails &typeNode, qreal mx = 0, qreal my = 0); }; +inline VDetail DialogDetail::getDetails() const +{ + return details; +} + #endif // DIALOGDETAIL_H diff --git a/src/dialogs/dialogdetail.ui b/src/dialogs/tools/dialogdetail.ui similarity index 100% rename from src/dialogs/dialogdetail.ui rename to src/dialogs/tools/dialogdetail.ui diff --git a/src/dialogs/dialogendline.cpp b/src/dialogs/tools/dialogendline.cpp similarity index 58% rename from src/dialogs/dialogendline.cpp rename to src/dialogs/tools/dialogendline.cpp index ba0834eb4..806a7f43d 100644 --- a/src/dialogs/dialogendline.cpp +++ b/src/dialogs/tools/dialogendline.cpp @@ -36,66 +36,32 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) formula(QString()), angle(0), basePointId(0) { ui->setupUi(this); - spinBoxAngle = ui->doubleSpinBoxAngle; - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + + InitOkCansel(ui); flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogEndLine::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogEndLine::DialogRejected); FillComboBoxPoints(ui->comboBoxBasePoint); - FillComboBoxTypeLine(ui->comboBoxLineType); - connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, - &DialogEndLine::ArrowDown); - connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, - &DialogEndLine::ArrowUp); - connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, - &DialogEndLine::ArrowLeft); - connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, - &DialogEndLine::ArrowRight); - connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, - &DialogEndLine::ArrowLeftUp); - connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, - &DialogEndLine::ArrowLeftDown); - connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, - &DialogEndLine::ArrowRightUp); - connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, - &DialogEndLine::ArrowRightDown); + InitArrow(ui); + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEndLine::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogEndLine::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogEndLine::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogEndLine::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogEndLine::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogEndLine::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogEndLine::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEndLine::FormulaChanged); } -void DialogEndLine::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogEndLine::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); ChangeCurrentText(ui->comboBoxBasePoint, point->name()); @@ -128,7 +94,7 @@ void DialogEndLine::setAngle(const qreal &value) ui->doubleSpinBoxAngle->setValue(angle); } -void DialogEndLine::setBasePointId(const qint64 &value, const qint64 &id) +void DialogEndLine::setBasePointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id); } diff --git a/src/dialogs/dialogendline.h b/src/dialogs/tools/dialogendline.h similarity index 77% rename from src/dialogs/dialogendline.h rename to src/dialogs/tools/dialogendline.h index 34cadbaf5..97015d833 100644 --- a/src/dialogs/dialogendline.h +++ b/src/dialogs/tools/dialogendline.h @@ -43,18 +43,18 @@ class DialogEndLine : public DialogTool { Q_OBJECT public: - /** - * @brief DialogEndLine create dialog - * @param data container with data - * @param parent parent widget - */ - DialogEndLine(const VContainer *data, QWidget *parent = 0); - ~DialogEndLine(); + /** + * @brief DialogEndLine create dialog + * @param data container with data + * @param parent parent widget + */ + DialogEndLine(const VContainer *data, QWidget *parent = nullptr); + ~DialogEndLine(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -64,7 +64,7 @@ public: * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type @@ -74,7 +74,7 @@ public: * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula @@ -84,7 +84,7 @@ public: * @brief getAngle return angle of line * @return angle in degree */ - inline qreal getAngle() const {return angle;} + qreal getAngle() const; /** * @brief setAngle set angle of line * @param value angle in degree @@ -94,20 +94,20 @@ public: * @brief getBasePointId return id base point of line * @return id */ - inline qint64 getBasePointId() const {return basePointId;} + quint32 getBasePointId() const; /** * @brief setBasePointId set id base point of line * @param value id * @param id don't show this id in list */ - void setBasePointId(const qint64 &value, const qint64 &id); + void setBasePointId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -137,7 +137,32 @@ private: /** * @brief basePointId id base point of line */ - qint64 basePointId; + quint32 basePointId; }; +inline QString DialogEndLine::getPointName() const +{ + return pointName; +} + +inline QString DialogEndLine::getTypeLine() const +{ + return typeLine; +} + +inline QString DialogEndLine::getFormula() const +{ + return formula; +} + +inline qreal DialogEndLine::getAngle() const +{ + return angle; +} + +inline quint32 DialogEndLine::getBasePointId() const +{ + return basePointId; +} + #endif // DIALOGENDLINE_H diff --git a/src/dialogs/dialogendline.ui b/src/dialogs/tools/dialogendline.ui similarity index 100% rename from src/dialogs/dialogendline.ui rename to src/dialogs/tools/dialogendline.ui diff --git a/src/dialogs/dialogheight.cpp b/src/dialogs/tools/dialogheight.cpp similarity index 86% rename from src/dialogs/dialogheight.cpp rename to src/dialogs/tools/dialogheight.cpp index 184cf725d..249e45fa7 100644 --- a/src/dialogs/dialogheight.cpp +++ b/src/dialogs/tools/dialogheight.cpp @@ -37,12 +37,9 @@ DialogHeight::DialogHeight(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogHeight::DialogAccepted); + InitOkCansel(ui); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogHeight::DialogRejected); FillComboBoxPoints(ui->comboBoxBasePoint); FillComboBoxPoints(ui->comboBoxP1Line); @@ -68,27 +65,27 @@ void DialogHeight::setTypeLine(const QString &value) SetupTypeLine(ui->comboBoxLineType, value); } -void DialogHeight::setBasePointId(const qint64 &value, const qint64 &id) +void DialogHeight::setBasePointId(const quint32 &value, const quint32 &id) { basePointId = value; setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id); } -void DialogHeight::setP1LineId(const qint64 &value, const qint64 &id) +void DialogHeight::setP1LineId(const quint32 &value, const quint32 &id) { p1LineId = value; setCurrentPointId(ui->comboBoxP1Line, p1LineId, value, id); } -void DialogHeight::setP2LineId(const qint64 &value, const qint64 &id) +void DialogHeight::setP2LineId(const quint32 &value, const quint32 &id) { p2LineId = value; setCurrentPointId(ui->comboBoxP2Line, p2LineId, value, id); } -void DialogHeight::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogHeight::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); switch (number) diff --git a/src/dialogs/dialogheight.h b/src/dialogs/tools/dialogheight.h similarity index 74% rename from src/dialogs/dialogheight.h rename to src/dialogs/tools/dialogheight.h index 4074ba80e..79df86f24 100644 --- a/src/dialogs/dialogheight.h +++ b/src/dialogs/tools/dialogheight.h @@ -43,18 +43,18 @@ class DialogHeight : public DialogTool { Q_OBJECT public: - /** - * @brief DialogHeight create dialog - * @param data container with data - * @param parent parent widget - */ - DialogHeight(const VContainer *data, QWidget *parent = 0); - ~DialogHeight(); + /** + * @brief DialogHeight create dialog + * @param data container with data + * @param parent parent widget + */ + DialogHeight(const VContainer *data, QWidget *parent = nullptr); + ~DialogHeight(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -64,7 +64,7 @@ public: * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type @@ -74,42 +74,42 @@ public: * @brief getBasePointId return id base point of height * @return id */ - inline qint64 getBasePointId() const {return basePointId;} + quint32 getBasePointId() const; /** * @brief setBasePointId set id base point of height * @param value id * @param id don't show this id in list */ - void setBasePointId(const qint64 &value, const qint64 &id); + void setBasePointId(const quint32 &value, const quint32 &id); /** * @brief getP1LineId return id first point of line * @return id id */ - inline qint64 getP1LineId() const {return p1LineId;} + quint32 getP1LineId() const; /** * @brief setP1LineId set id first point of line * @param value id * @param id don't show this id in list */ - void setP1LineId(const qint64 &value, const qint64 &id); + void setP1LineId(const quint32 &value, const quint32 &id); /** * @brief getP2LineId return id second point of line * @return id */ - inline qint64 getP2LineId() const{return p2LineId;} + quint32 getP2LineId() const; /** * @brief setP2LineId set id second point of line * @param value id * @param id don't show this id in list */ - void setP2LineId(const qint64 &value, const qint64 &id); + void setP2LineId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -135,15 +135,40 @@ private: /** * @brief basePointId id base point of height */ - qint64 basePointId; + quint32 basePointId; /** * @brief p1LineId id first point of line */ - qint64 p1LineId; + quint32 p1LineId; /** * @brief p2LineId id second point of line */ - qint64 p2LineId; + quint32 p2LineId; }; +inline QString DialogHeight::getPointName() const +{ + return pointName; +} + +inline QString DialogHeight::getTypeLine() const +{ + return typeLine; +} + +inline quint32 DialogHeight::getBasePointId() const +{ + return basePointId; +} + +inline quint32 DialogHeight::getP1LineId() const +{ + return p1LineId; +} + +inline quint32 DialogHeight::getP2LineId() const +{ + return p2LineId; +} + #endif // DIALOGHEIGHT_H diff --git a/src/dialogs/dialogheight.ui b/src/dialogs/tools/dialogheight.ui similarity index 100% rename from src/dialogs/dialogheight.ui rename to src/dialogs/tools/dialogheight.ui diff --git a/src/dialogs/dialogline.cpp b/src/dialogs/tools/dialogline.cpp similarity index 84% rename from src/dialogs/dialogline.cpp rename to src/dialogs/tools/dialogline.cpp index ccbb31eb8..e5a580c88 100644 --- a/src/dialogs/dialogline.cpp +++ b/src/dialogs/tools/dialogline.cpp @@ -35,10 +35,7 @@ DialogLine::DialogLine(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0), typeLine(QString()) { ui->setupUi(this); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogLine::DialogAccepted); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogLine::DialogRejected); + InitOkCansel(ui); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); @@ -52,7 +49,7 @@ DialogLine::~DialogLine() delete ui; } -void DialogLine::setSecondPoint(const qint64 &value) +void DialogLine::setSecondPoint(const quint32 &value) { secondPoint = value; const VPointF *point = data->GeometricObject(value); @@ -69,7 +66,7 @@ void DialogLine::setTypeLine(const QString &value) SetupTypeLine(ui->comboBoxLineType, value); } -void DialogLine::setFirstPoint(const qint64 &value) +void DialogLine::setFirstPoint(const quint32 &value) { firstPoint = value; const VPointF *point = data->GeometricObject(value); @@ -84,16 +81,16 @@ void DialogLine::setFirstPoint(const qint64 &value) void DialogLine::DialogAccepted() { qint32 index = ui->comboBoxFirstPoint->currentIndex(); - firstPoint = qvariant_cast(ui->comboBoxFirstPoint->itemData(index)); + firstPoint = qvariant_cast(ui->comboBoxFirstPoint->itemData(index)); index = ui->comboBoxSecondPoint->currentIndex(); - secondPoint = qvariant_cast(ui->comboBoxSecondPoint->itemData(index)); + secondPoint = qvariant_cast(ui->comboBoxSecondPoint->itemData(index)); typeLine = GetTypeLine(ui->comboBoxLineType); DialogClosed(QDialog::Accepted); } -void DialogLine::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogLine::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) diff --git a/src/dialogs/dialogline.h b/src/dialogs/tools/dialogline.h similarity index 72% rename from src/dialogs/dialogline.h rename to src/dialogs/tools/dialogline.h index 1ec7d59a3..82e8c4fa1 100644 --- a/src/dialogs/dialogline.h +++ b/src/dialogs/tools/dialogline.h @@ -43,76 +43,91 @@ class DialogLine : public DialogTool { Q_OBJECT public: - /** - * @brief DialogLine create dialog - * @param data container with data - * @param parent parent widget - */ - DialogLine(const VContainer *data, QWidget *parent = 0); - ~DialogLine(); + /** + * @brief DialogLine create dialog + * @param data container with data + * @param parent parent widget + */ + DialogLine(const VContainer *data, QWidget *parent = nullptr); + ~DialogLine(); /** * @brief getFirstPoint return id first point * @return id */ - inline qint64 getFirstPoint() const {return firstPoint;} + quint32 getFirstPoint() const; /** * @brief setFirstPoint set id first point * @param value id */ - void setFirstPoint(const qint64 &value); + void setFirstPoint(const quint32 &value); /** * @brief getSecondPoint return id second point * @return id */ - inline qint64 getSecondPoint() const {return secondPoint;} + quint32 getSecondPoint() const; /** * @brief setSecondPoint set id second point * @param value id */ - void setSecondPoint(const qint64 &value); + void setSecondPoint(const quint32 &value); /** * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type */ - void setTypeLine(const QString &value); + void setTypeLine(const QString &value); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ - virtual void DialogAccepted(); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogLine) /** * @brief ui keeps information about user interface */ - Ui::DialogLine *ui; + Ui::DialogLine *ui; /** * @brief number number of handled objects */ - qint32 number; + qint32 number; /** * @brief firstPoint id first point */ - qint64 firstPoint; + quint32 firstPoint; /** * @brief secondPoint id second point */ - qint64 secondPoint; + quint32 secondPoint; /** * @brief typeLine type of line */ - QString typeLine; + QString typeLine; }; +inline quint32 DialogLine::getFirstPoint() const +{ + return firstPoint; +} + +inline quint32 DialogLine::getSecondPoint() const +{ + return secondPoint; +} + +inline QString DialogLine::getTypeLine() const +{ + return typeLine; +} + #endif // DIALOGLINE_H diff --git a/src/dialogs/dialogline.ui b/src/dialogs/tools/dialogline.ui similarity index 100% rename from src/dialogs/dialogline.ui rename to src/dialogs/tools/dialogline.ui diff --git a/src/dialogs/dialoglineintersect.cpp b/src/dialogs/tools/dialoglineintersect.cpp similarity index 87% rename from src/dialogs/dialoglineintersect.cpp rename to src/dialogs/tools/dialoglineintersect.cpp index 4950225f2..22f7d0b05 100644 --- a/src/dialogs/dialoglineintersect.cpp +++ b/src/dialogs/tools/dialoglineintersect.cpp @@ -37,12 +37,9 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent { ui->setupUi(this); number = 0; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogLineIntersect::DialogAccepted); + InitOkCansel(ui); labelEditNamePoint = ui->labelEditNamePoint; flagName = false; - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogLineIntersect::DialogRejected); FillComboBoxPoints(ui->comboBoxP1Line1); FillComboBoxPoints(ui->comboBoxP2Line1); @@ -57,9 +54,9 @@ DialogLineIntersect::~DialogLineIntersect() delete ui; } -void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogLineIntersect::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) @@ -142,28 +139,28 @@ void DialogLineIntersect::DialogAccepted() void DialogLineIntersect::P1Line1Changed( int index) { - p1Line1 = qvariant_cast(ui->comboBoxP1Line1->itemData(index)); + p1Line1 = qvariant_cast(ui->comboBoxP1Line1->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } void DialogLineIntersect::P2Line1Changed(int index) { - p2Line1 = qvariant_cast(ui->comboBoxP2Line1->itemData(index)); + p2Line1 = qvariant_cast(ui->comboBoxP2Line1->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } void DialogLineIntersect::P1Line2Changed(int index) { - p1Line2 = qvariant_cast(ui->comboBoxP1Line2->itemData(index)); + p1Line2 = qvariant_cast(ui->comboBoxP1Line2->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } void DialogLineIntersect::P2Line2Changed(int index) { - p2Line2 = qvariant_cast(ui->comboBoxP2Line2->itemData(index)); + p2Line2 = qvariant_cast(ui->comboBoxP2Line2->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } @@ -195,25 +192,25 @@ bool DialogLineIntersect::CheckIntersecion() } } -void DialogLineIntersect::setP2Line2(const qint64 &value) +void DialogLineIntersect::setP2Line2(const quint32 &value) { p2Line2 = value; ChangeCurrentData(ui->comboBoxP2Line2, value); } -void DialogLineIntersect::setP1Line2(const qint64 &value) +void DialogLineIntersect::setP1Line2(const quint32 &value) { p1Line2 = value; ChangeCurrentData(ui->comboBoxP1Line2, value); } -void DialogLineIntersect::setP2Line1(const qint64 &value) +void DialogLineIntersect::setP2Line1(const quint32 &value) { p2Line1 = value; ChangeCurrentData(ui->comboBoxP2Line1, value); } -void DialogLineIntersect::setP1Line1(const qint64 &value) +void DialogLineIntersect::setP1Line1(const quint32 &value) { p1Line1 = value; ChangeCurrentData(ui->comboBoxP1Line1, value); diff --git a/src/dialogs/dialoglineintersect.h b/src/dialogs/tools/dialoglineintersect.h similarity index 77% rename from src/dialogs/dialoglineintersect.h rename to src/dialogs/tools/dialoglineintersect.h index 49871348c..c74e0b555 100644 --- a/src/dialogs/dialoglineintersect.h +++ b/src/dialogs/tools/dialoglineintersect.h @@ -43,58 +43,58 @@ class DialogLineIntersect : public DialogTool { Q_OBJECT public: - /** - * @brief DialogLineIntersect create dialog - * @param data container with data - * @param parent parent widget - */ - DialogLineIntersect(const VContainer *data, QWidget *parent = 0); - ~DialogLineIntersect(); + /** + * @brief DialogLineIntersect create dialog + * @param data container with data + * @param parent parent widget + */ + DialogLineIntersect(const VContainer *data, QWidget *parent = nullptr); + ~DialogLineIntersect(); /** * @brief getP1Line1 return id first point of first line * @return id */ - inline qint64 getP1Line1() const {return p1Line1;} + quint32 getP1Line1() const; /** * @brief setP1Line1 set id first point of first line * @param value id */ - void setP1Line1(const qint64 &value); + void setP1Line1(const quint32 &value); /** * @brief getP2Line1 return id second point of first line * @return id */ - inline qint64 getP2Line1() const {return p2Line1;} + quint32 getP2Line1() const; /** * @brief setP2Line1 set id second point of first line * @param value id */ - void setP2Line1(const qint64 &value); + void setP2Line1(const quint32 &value); /** * @brief getP1Line2 return id first point of second line * @return id */ - inline qint64 getP1Line2() const {return p1Line2;} + quint32 getP1Line2() const; /** * @brief setP1Line2 set id first point of second line * @param value id */ - void setP1Line2(const qint64 &value); + void setP1Line2(const quint32 &value); /** * @brief getP2Line2 return id second point of second line * @return id */ - inline qint64 getP2Line2() const {return p2Line2;} + quint32 getP2Line2() const; /** * @brief setP2Line2 set id second point of second line * @param value id */ - void setP2Line2(const qint64 &value); + void setP2Line2(const quint32 &value); /** * @brief getPointName return name of point * @return */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value @@ -106,7 +106,7 @@ public slots: * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -148,19 +148,19 @@ private: /** * @brief p1Line1 id first point of first line */ - qint64 p1Line1; + quint32 p1Line1; /** * @brief p2Line1 id second point of first line */ - qint64 p2Line1; + quint32 p2Line1; /** * @brief p1Line2 id first point of second line */ - qint64 p1Line2; + quint32 p1Line2; /** * @brief p2Line2 id second point of second line */ - qint64 p2Line2; + quint32 p2Line2; /** * @brief flagPoint keep state of point */ @@ -176,4 +176,29 @@ private: bool CheckIntersecion(); }; +inline quint32 DialogLineIntersect::getP1Line1() const +{ + return p1Line1; +} + +inline quint32 DialogLineIntersect::getP2Line1() const +{ + return p2Line1; +} + +inline quint32 DialogLineIntersect::getP1Line2() const +{ + return p1Line2; +} + +inline quint32 DialogLineIntersect::getP2Line2() const +{ + return p2Line2; +} + +inline QString DialogLineIntersect::getPointName() const +{ + return pointName; +} + #endif // DIALOGLINEINTERSECT_H diff --git a/src/dialogs/dialoglineintersect.ui b/src/dialogs/tools/dialoglineintersect.ui similarity index 100% rename from src/dialogs/dialoglineintersect.ui rename to src/dialogs/tools/dialoglineintersect.ui diff --git a/src/dialogs/dialognormal.cpp b/src/dialogs/tools/dialognormal.cpp similarity index 53% rename from src/dialogs/dialognormal.cpp rename to src/dialogs/tools/dialognormal.cpp index 70e9c1aed..298e36885 100644 --- a/src/dialogs/dialognormal.cpp +++ b/src/dialogs/tools/dialognormal.cpp @@ -36,58 +36,25 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) typeLine(QString()), formula(QString()), angle(0), firstPointId(0), secondPointId(0) { ui->setupUi(this); - spinBoxAngle = ui->doubleSpinBoxAngle; - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + InitOkCansel(ui); + flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogNormal::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogNormal::DialogRejected); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); FillComboBoxTypeLine(ui->comboBoxLineType); - connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, - &DialogNormal::ArrowDown); - connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, - &DialogNormal::ArrowUp); - connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, - &DialogNormal::ArrowLeft); - connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, - &DialogNormal::ArrowRight); - connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, - &DialogNormal::ArrowLeftUp); - connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, - &DialogNormal::ArrowLeftDown); - connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, - &DialogNormal::ArrowRightUp); - connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, - &DialogNormal::ArrowRightDown); + InitArrow(ui); + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogNormal::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogNormal::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogNormal::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogNormal::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogNormal::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogNormal::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogNormal::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogNormal::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogNormal::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogNormal::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogNormal::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogNormal::FormulaChanged); @@ -98,34 +65,27 @@ DialogNormal::~DialogNormal() delete ui; } -void DialogNormal::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogNormal::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { - const VPointF *point = data->GeometricObject(id); if (number == 0) { - qint32 index = ui->comboBoxFirstPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxFirstPoint->setCurrentIndex(index); + if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) + { number++; - emit ToolTip(tr("Select second point of line")); return; } } if (number == 1) { - qint32 index = ui->comboBoxSecondPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxSecondPoint->setCurrentIndex(index); - number = 0; - emit ToolTip(""); - } - if (isInitialized == false) + if (ChoosedPoint(id, ui->comboBoxSecondPoint, "")) { - this->show(); + number = 0; + if (isInitialized == false) + { + this->show(); + } } } } @@ -142,12 +102,12 @@ void DialogNormal::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogNormal::setSecondPointId(const qint64 &value, const qint64 &id) +void DialogNormal::setSecondPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -void DialogNormal::setFirstPointId(const qint64 &value, const qint64 &id) +void DialogNormal::setFirstPointId(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } diff --git a/src/dialogs/dialognormal.h b/src/dialogs/tools/dialognormal.h similarity index 75% rename from src/dialogs/dialognormal.h rename to src/dialogs/tools/dialognormal.h index 556a8b9a2..51a2f1c20 100644 --- a/src/dialogs/dialognormal.h +++ b/src/dialogs/tools/dialognormal.h @@ -43,18 +43,18 @@ class DialogNormal : public DialogTool { Q_OBJECT public: - /** - * @brief DialogNormal create dialog - * @param data container with data - * @param parent parent widget - */ - DialogNormal(const VContainer *data, QWidget *parent = 0); - ~DialogNormal(); + /** + * @brief DialogNormal create dialog + * @param data container with data + * @param parent parent widget + */ + DialogNormal(const VContainer *data, QWidget *parent = nullptr); + ~DialogNormal(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const{return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -64,7 +64,7 @@ public: * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type @@ -74,7 +74,7 @@ public: * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula @@ -84,7 +84,7 @@ public: * @brief getAngle return aditional angle of normal * @return angle in degree */ - inline qreal getAngle() const {return angle;} + qreal getAngle() const; /** * @brief setAngle set aditional angle of normal * @param value angle in degree @@ -94,31 +94,31 @@ public: * @brief getFirstPointId return id of first point * @return id */ - inline qint64 getFirstPointId() const {return firstPointId;} + quint32 getFirstPointId() const; /** * @brief setFirstPointId set id of first point * @param value id * @param id don't show this id in list */ - void setFirstPointId(const qint64 &value, const qint64 &id); + void setFirstPointId(const quint32 &value, const quint32 &id); /** * @brief getSecondPointId return id of second point * @return id */ - inline qint64 getSecondPointId() const {return secondPointId;} + quint32 getSecondPointId() const; /** * @brief setSecondPointId set id of second point * @param value id * @param id don't show this id in list */ - void setSecondPointId(const qint64 &value, const qint64 &id); + void setSecondPointId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -152,11 +152,41 @@ private: /** * @brief firstPointId id first point of line */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second point of line */ - qint64 secondPointId; + quint32 secondPointId; }; +inline QString DialogNormal::getPointName() const +{ + return pointName; +} + +inline QString DialogNormal::getTypeLine() const +{ + return typeLine; +} + +inline QString DialogNormal::getFormula() const +{ + return formula; +} + +inline qreal DialogNormal::getAngle() const +{ + return angle; +} + +inline quint32 DialogNormal::getFirstPointId() const +{ + return firstPointId; +} + +inline quint32 DialogNormal::getSecondPointId() const +{ + return secondPointId; +} + #endif // DIALOGNORMAL_H diff --git a/src/dialogs/dialognormal.ui b/src/dialogs/tools/dialognormal.ui similarity index 100% rename from src/dialogs/dialognormal.ui rename to src/dialogs/tools/dialognormal.ui diff --git a/src/dialogs/dialogpointofcontact.cpp b/src/dialogs/tools/dialogpointofcontact.cpp similarity index 86% rename from src/dialogs/dialogpointofcontact.cpp rename to src/dialogs/tools/dialogpointofcontact.cpp index 2f8374a2a..8d9881e7f 100644 --- a/src/dialogs/dialogpointofcontact.cpp +++ b/src/dialogs/tools/dialogpointofcontact.cpp @@ -47,13 +47,17 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare lineEditFormula = ui.lineEditFormula; labelEditFormula = ui.labelEditFormula; labelEditNamePoint = ui.labelEditNamePoint; - flagFormula = false; + bOk = ui.buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogPointOfContact::DialogAccepted); + Q_CHECK_PTR(bOk); + connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); + QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); + Q_CHECK_PTR(bCansel); + connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); + + flagFormula = false; flagName = false; CheckState(); - QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogPointOfContact::DialogRejected); FillComboBoxPoints(ui.comboBoxCenter); FillComboBoxPoints(ui.comboBoxFirstPoint); @@ -63,9 +67,17 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare connect(ui.listWidget, &QListWidget::itemDoubleClicked, this, &DialogPointOfContact::PutVal); connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogPointOfContact::ValChenged); - ShowVariable(data->DataBase()); - connect(ui.radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogPointOfContact::SizeGrowth); - connect(ui.radioButtonStandardTable, &QRadioButton::clicked, this, &DialogPointOfContact::StandardTable); + if (qApp->patternType() == Pattern::Standard) + { + SizeHeight(); + connect(ui.radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogTool::SizeHeight); + } + else + { + radioButtonSizeGrowth->setVisible(false); + Measurements(); + } + connect(ui.radioButtonStandardTable, &QRadioButton::clicked, this, &DialogPointOfContact::Measurements); connect(ui.radioButtonIncrements, &QRadioButton::clicked, this, &DialogPointOfContact::Increments); connect(ui.radioButtonLengthLine, &QRadioButton::clicked, this, &DialogPointOfContact::LengthLines); connect(ui.radioButtonLengthArc, &QRadioButton::clicked, this, &DialogPointOfContact::LengthArcs); @@ -75,9 +87,9 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare connect(ui.lineEditFormula, &QLineEdit::textChanged, this, &DialogPointOfContact::FormulaChanged); } -void DialogPointOfContact::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogPointOfContact::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) @@ -129,17 +141,17 @@ void DialogPointOfContact::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogPointOfContact::setSecondPoint(const qint64 &value, const qint64 &id) +void DialogPointOfContact::setSecondPoint(const quint32 &value, const quint32 &id) { setCurrentPointId(ui.comboBoxSecondPoint, secondPoint, value, id); } -void DialogPointOfContact::setFirstPoint(const qint64 &value, const qint64 &id) +void DialogPointOfContact::setFirstPoint(const quint32 &value, const quint32 &id) { setCurrentPointId(ui.comboBoxFirstPoint, firstPoint, value, id); } -void DialogPointOfContact::setCenter(const qint64 &value, const qint64 &id) +void DialogPointOfContact::setCenter(const quint32 &value, const quint32 &id) { setCurrentPointId(ui.comboBoxCenter, center, value, id); center = value; diff --git a/src/dialogs/dialogpointofcontact.h b/src/dialogs/tools/dialogpointofcontact.h similarity index 74% rename from src/dialogs/dialogpointofcontact.h rename to src/dialogs/tools/dialogpointofcontact.h index d5a610c30..9c8949ed7 100644 --- a/src/dialogs/dialogpointofcontact.h +++ b/src/dialogs/tools/dialogpointofcontact.h @@ -39,17 +39,17 @@ class DialogPointOfContact : public DialogTool { Q_OBJECT public: - /** - * @brief DialogPointOfContact create dialog - * @param data container with data - * @param parent parent widget - */ - DialogPointOfContact(const VContainer *data, QWidget *parent = 0); + /** + * @brief DialogPointOfContact create dialog + * @param data container with data + * @param parent parent widget + */ + DialogPointOfContact(const VContainer *data, QWidget *parent = nullptr); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -59,7 +59,7 @@ public: * @brief getRadius return formula radius of arc * @return formula */ - inline QString getRadius() const {return radius;} + QString getRadius() const; /** * @brief setRadius set formula radius of arc * @param value formula @@ -69,42 +69,42 @@ public: * @brief GetCenter return id of center point * @return id */ - inline qint64 getCenter() const {return center;} + quint32 getCenter() const; /** * @brief SetCenter set id of center point * @param value id * @param id don't show this id in list. */ - void setCenter(const qint64 &value, const qint64 &id); + void setCenter(const quint32 &value, const quint32 &id); /** * @brief getFirstPoint return id first point * @return id */ - inline qint64 getFirstPoint() const {return firstPoint;} + quint32 getFirstPoint() const; /** * @brief setFirstPoint set id first point * @param value id * @param id don't show this id in list. */ - void setFirstPoint(const qint64 &value, const qint64 &id); + void setFirstPoint(const quint32 &value, const quint32 &id); /** * @brief getSecondPoint return id second point * @return id */ - inline qint64 getSecondPoint() const {return secondPoint;} + quint32 getSecondPoint() const; /** * @brief setSecondPoint set id second point * @param value id * @param id don't show this id in list. */ - void setSecondPoint(const qint64 &value, const qint64 &id); + void setSecondPoint(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -130,15 +130,40 @@ private: /** * @brief center id center point of arc */ - qint64 center; + quint32 center; /** * @brief firstPoint id first point of line */ - qint64 firstPoint; + quint32 firstPoint; /** * @brief secondPoint id second point of line */ - qint64 secondPoint; + quint32 secondPoint; }; +inline QString DialogPointOfContact::getPointName() const +{ + return pointName; +} + +inline QString DialogPointOfContact::getRadius() const +{ + return radius; +} + +inline quint32 DialogPointOfContact::getCenter() const +{ + return center; +} + +inline quint32 DialogPointOfContact::getFirstPoint() const +{ + return firstPoint; +} + +inline quint32 DialogPointOfContact::getSecondPoint() const +{ + return secondPoint; +} + #endif // DIALOGPOINTOFCONTACT_H diff --git a/src/dialogs/dialogpointofcontact.ui b/src/dialogs/tools/dialogpointofcontact.ui similarity index 100% rename from src/dialogs/dialogpointofcontact.ui rename to src/dialogs/tools/dialogpointofcontact.ui diff --git a/src/dialogs/dialogpointofintersection.cpp b/src/dialogs/tools/dialogpointofintersection.cpp similarity index 85% rename from src/dialogs/dialogpointofintersection.cpp rename to src/dialogs/tools/dialogpointofintersection.cpp index 0ec306a6e..7a2646422 100644 --- a/src/dialogs/dialogpointofintersection.cpp +++ b/src/dialogs/tools/dialogpointofintersection.cpp @@ -37,12 +37,9 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, QWi { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogPointOfIntersection::DialogAccepted); + InitOkCansel(ui); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogPointOfIntersection::DialogRejected); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); @@ -55,15 +52,15 @@ DialogPointOfIntersection::~DialogPointOfIntersection() delete ui; } -void DialogPointOfIntersection::setSecondPointId(const qint64 &value, const qint64 &id) +void DialogPointOfIntersection::setSecondPointId(const quint32 &value, const quint32 &id) { secondPointId = value; setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -void DialogPointOfIntersection::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogPointOfIntersection::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) @@ -102,7 +99,7 @@ void DialogPointOfIntersection::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogPointOfIntersection::setFirstPointId(const qint64 &value, const qint64 &id) +void DialogPointOfIntersection::setFirstPointId(const quint32 &value, const quint32 &id) { firstPointId = value; setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); diff --git a/src/dialogs/dialogpointofintersection.h b/src/dialogs/tools/dialogpointofintersection.h similarity index 76% rename from src/dialogs/dialogpointofintersection.h rename to src/dialogs/tools/dialogpointofintersection.h index 4a184a544..b0f41e510 100644 --- a/src/dialogs/dialogpointofintersection.h +++ b/src/dialogs/tools/dialogpointofintersection.h @@ -43,18 +43,18 @@ class DialogPointOfIntersection : public DialogTool { Q_OBJECT public: - /** - * @brief DialogPointOfIntersection create dialog - * @param data container with data - * @param parent parent widget - */ - DialogPointOfIntersection(const VContainer *data, QWidget *parent = 0); - ~DialogPointOfIntersection(); + /** + * @brief DialogPointOfIntersection create dialog + * @param data container with data + * @param parent parent widget + */ + DialogPointOfIntersection(const VContainer *data, QWidget *parent = nullptr); + ~DialogPointOfIntersection(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -64,31 +64,31 @@ public: * @brief getFirstPointId return id of first point * @return id */ - inline qint64 getFirstPointId() const {return firstPointId;} + quint32 getFirstPointId() const; /** * @brief setFirstPointId set id of first point * @param value id * @param id don't show this id in list. */ - void setFirstPointId(const qint64 &value, const qint64 &id); + void setFirstPointId(const quint32 &value, const quint32 &id); /** * @brief getSecondPointId return id of second point * @return id */ - inline qint64 getSecondPointId() const {return secondPointId;} + quint32 getSecondPointId() const; /** * @brief setSecondPointId set id of second point * @param value id * @param id don't show this id in list. */ - void setSecondPointId(const qint64 &value, const qint64 &id); + void setSecondPointId(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -110,11 +110,26 @@ private: /** * @brief firstPointId id first point of line */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second point of line */ - qint64 secondPointId; + quint32 secondPointId; }; +inline QString DialogPointOfIntersection::getPointName() const +{ + return pointName; +} + +inline quint32 DialogPointOfIntersection::getFirstPointId() const +{ + return firstPointId; +} + +inline quint32 DialogPointOfIntersection::getSecondPointId() const +{ + return secondPointId; +} + #endif // DIALOGPOINTOFINTERSECTION_H diff --git a/src/dialogs/dialogpointofintersection.ui b/src/dialogs/tools/dialogpointofintersection.ui similarity index 100% rename from src/dialogs/dialogpointofintersection.ui rename to src/dialogs/tools/dialogpointofintersection.ui diff --git a/src/dialogs/dialogshoulderpoint.cpp b/src/dialogs/tools/dialogshoulderpoint.cpp similarity index 72% rename from src/dialogs/dialogshoulderpoint.cpp rename to src/dialogs/tools/dialogshoulderpoint.cpp index ddf25d596..2a679c2b4 100644 --- a/src/dialogs/dialogshoulderpoint.cpp +++ b/src/dialogs/tools/dialogshoulderpoint.cpp @@ -37,42 +37,24 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent { ui->setupUi(this); number = 0; - listWidget = ui->listWidget; + InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - labelDescription = ui->labelDescription; - radioButtonSizeGrowth = ui->radioButtonSizeGrowth; - radioButtonStandardTable = ui->radioButtonStandardTable; - radioButtonIncrements = ui->radioButtonIncrements; - radioButtonLengthLine = ui->radioButtonLengthLine; - radioButtonLengthArc = ui->radioButtonLengthArc; - radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + InitOkCansel(ui); + flagFormula = false; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogShoulderPoint::DialogAccepted); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogShoulderPoint::DialogRejected); - FillComboBoxTypeLine(ui->comboBoxLineType); + FillComboBoxTypeLine(ui->comboBoxLineType); FillComboBoxPoints(ui->comboBoxP1Line); FillComboBoxPoints(ui->comboBoxP2Line); FillComboBoxPoints(ui->comboBoxPShoulder); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogShoulderPoint::PutHere); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogShoulderPoint::PutVal); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogShoulderPoint::ValChenged); - - ShowVariable(data->DataBase()); - connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogShoulderPoint::SizeGrowth); - connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogShoulderPoint::StandardTable); - connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogShoulderPoint::Increments); - connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogShoulderPoint::LengthLines); - connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogShoulderPoint::LengthArcs); - connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogShoulderPoint::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogShoulderPoint::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogShoulderPoint::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogShoulderPoint::FormulaChanged); @@ -83,9 +65,9 @@ DialogShoulderPoint::~DialogShoulderPoint() delete ui; } -void DialogShoulderPoint::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogShoulderPoint::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) @@ -138,17 +120,17 @@ void DialogShoulderPoint::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -void DialogShoulderPoint::setPShoulder(const qint64 &value, const qint64 &id) +void DialogShoulderPoint::setPShoulder(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxPShoulder, pShoulder, value, id); } -void DialogShoulderPoint::setP2Line(const qint64 &value, const qint64 &id) +void DialogShoulderPoint::setP2Line(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxP2Line, p2Line, value, id); } -void DialogShoulderPoint::setP1Line(const qint64 &value, const qint64 &id) +void DialogShoulderPoint::setP1Line(const quint32 &value, const quint32 &id) { setCurrentPointId(ui->comboBoxP1Line, p1Line, value, id); } diff --git a/src/dialogs/dialogshoulderpoint.h b/src/dialogs/tools/dialogshoulderpoint.h similarity index 74% rename from src/dialogs/dialogshoulderpoint.h rename to src/dialogs/tools/dialogshoulderpoint.h index 790aba904..2fc36dcc5 100644 --- a/src/dialogs/dialogshoulderpoint.h +++ b/src/dialogs/tools/dialogshoulderpoint.h @@ -43,18 +43,18 @@ class DialogShoulderPoint : public DialogTool { Q_OBJECT public: - /** - * @brief DialogShoulderPoint create dialog - * @param data container with data - * @param parent parent widget - */ - DialogShoulderPoint(const VContainer *data, QWidget *parent = 0); - ~DialogShoulderPoint(); + /** + * @brief DialogShoulderPoint create dialog + * @param data container with data + * @param parent parent widget + */ + DialogShoulderPoint(const VContainer *data, QWidget *parent = nullptr); + ~DialogShoulderPoint(); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -64,7 +64,7 @@ public: * @brief getTypeLine return type of line * @return type */ - inline QString getTypeLine() const {return typeLine;} + QString getTypeLine() const; /** * @brief setTypeLine set type of line * @param value type @@ -74,7 +74,7 @@ public: * @brief getFormula return string of formula * @return formula */ - inline QString getFormula() const {return formula;} + QString getFormula() const; /** * @brief setFormula set string of formula * @param value formula @@ -84,42 +84,42 @@ public: * @brief getP1Line return id first point of line * @return id */ - inline qint64 getP1Line() const {return p1Line;} + quint32 getP1Line() const; /** * @brief setP1Line set id first point of line * @param value id * @param id don't show this id in list */ - void setP1Line(const qint64 &value, const qint64 &id); + void setP1Line(const quint32 &value, const quint32 &id); /** * @brief getP2Line return id second point of line * @return id */ - inline qint64 getP2Line() const {return p2Line;} + quint32 getP2Line() const; /** * @brief setP2Line set id second point of line * @param value id * @param id don't show this id in list */ - void setP2Line(const qint64 &value, const qint64 &id); + void setP2Line(const quint32 &value, const quint32 &id); /** * @brief getPShoulder return id shoulder point * @return id */ - inline qint64 getPShoulder() const {return pShoulder;} + quint32 getPShoulder() const; /** * @brief setPShoulder set id shoulder point * @param value id * @param id don't show this id in list */ - void setPShoulder(const qint64 &value, const qint64 &id); + void setPShoulder(const quint32 &value, const quint32 &id); public slots: /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -149,15 +149,45 @@ private: /** * @brief p1Line id first point of line */ - qint64 p1Line; + quint32 p1Line; /** * @brief p2Line id second point of line */ - qint64 p2Line; + quint32 p2Line; /** * @brief pShoulder id shoulder point */ - qint64 pShoulder; + quint32 pShoulder; }; +inline QString DialogShoulderPoint::getPointName() const +{ + return pointName; +} + +inline QString DialogShoulderPoint::getTypeLine() const +{ + return typeLine; +} + +inline QString DialogShoulderPoint::getFormula() const +{ + return formula; +} + +inline quint32 DialogShoulderPoint::getP1Line() const +{ + return p1Line; +} + +inline quint32 DialogShoulderPoint::getP2Line() const +{ + return p2Line; +} + +inline quint32 DialogShoulderPoint::getPShoulder() const +{ + return pShoulder; +} + #endif // DIALOGSHOULDERPOINT_H diff --git a/src/dialogs/dialogshoulderpoint.ui b/src/dialogs/tools/dialogshoulderpoint.ui similarity index 100% rename from src/dialogs/dialogshoulderpoint.ui rename to src/dialogs/tools/dialogshoulderpoint.ui diff --git a/src/dialogs/dialogsinglepoint.cpp b/src/dialogs/tools/dialogsinglepoint.cpp similarity index 72% rename from src/dialogs/dialogsinglepoint.cpp rename to src/dialogs/tools/dialogsinglepoint.cpp index af69ba8b5..f4f07b064 100644 --- a/src/dialogs/dialogsinglepoint.cpp +++ b/src/dialogs/tools/dialogsinglepoint.cpp @@ -36,15 +36,14 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) point(QPointF()) { ui->setupUi(this); - ui->doubleSpinBoxX->setRange(0, toMM(SceneSize)); - ui->doubleSpinBoxY->setRange(0, toMM(SceneSize)); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + ui->doubleSpinBoxX->setRange(0, qApp->fromPixel(SceneSize)); + ui->doubleSpinBoxY->setRange(0, qApp->fromPixel(SceneSize)); labelEditNamePoint = ui->labelEditName; + InitOkCansel(ui); + flagName = false; CheckState(); - connect(bOk, &QPushButton::clicked, this, &DialogSinglePoint::DialogAccepted); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogSinglePoint::DialogRejected); + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NamePointChanged); } @@ -52,20 +51,20 @@ void DialogSinglePoint::mousePress(const QPointF &scenePos) { if (isInitialized == false) { - ui->doubleSpinBoxX->setValue(toMM(scenePos.x())); - ui->doubleSpinBoxY->setValue(toMM(scenePos.y())); + ui->doubleSpinBoxX->setValue(qApp->fromPixel(scenePos.x())); + ui->doubleSpinBoxY->setValue(qApp->fromPixel(scenePos.y())); this->show(); } else { - ui->doubleSpinBoxX->setValue(toMM(scenePos.x())); - ui->doubleSpinBoxY->setValue(toMM(scenePos.y())); + ui->doubleSpinBoxX->setValue(qApp->fromPixel(scenePos.x())); + ui->doubleSpinBoxY->setValue(qApp->fromPixel(scenePos.y())); } } void DialogSinglePoint::DialogAccepted() { - point = QPointF(toPixel(ui->doubleSpinBoxX->value()), toPixel(ui->doubleSpinBoxY->value())); + point = QPointF(qApp->toPixel(ui->doubleSpinBoxX->value()), qApp->toPixel(ui->doubleSpinBoxY->value())); name = ui->lineEditName->text(); emit DialogClosed(QDialog::Accepted); } @@ -76,8 +75,8 @@ void DialogSinglePoint::setData(const QString &name, const QPointF &point) this->point = point; isInitialized = true; ui->lineEditName->setText(name); - ui->doubleSpinBoxX->setValue(toMM(point.x())); - ui->doubleSpinBoxY->setValue(toMM(point.y())); + ui->doubleSpinBoxX->setValue(qApp->fromPixel(point.x())); + ui->doubleSpinBoxY->setValue(qApp->fromPixel(point.y())); } DialogSinglePoint::~DialogSinglePoint() diff --git a/src/dialogs/dialogsinglepoint.h b/src/dialogs/tools/dialogsinglepoint.h similarity index 84% rename from src/dialogs/dialogsinglepoint.h rename to src/dialogs/tools/dialogsinglepoint.h index ac667adc5..a4f994043 100644 --- a/src/dialogs/dialogsinglepoint.h +++ b/src/dialogs/tools/dialogsinglepoint.h @@ -43,12 +43,13 @@ class DialogSinglePoint : public DialogTool { Q_OBJECT public: - /** - * @brief DialogSinglePoint create dialog - * @param data container with data - * @param parent parent widget - */ - DialogSinglePoint(const VContainer *data, QWidget *parent = 0); + /** + * @brief DialogSinglePoint create dialog + * @param data container with data + * @param parent parent widget + */ + DialogSinglePoint(const VContainer *data, QWidget *parent = nullptr); + ~DialogSinglePoint(); /** * @brief setData set name and point * @param name name of point @@ -59,13 +60,12 @@ public: * @brief getName return name * @return name */ - inline QString getName()const {return name;} + QString getName()const; /** * @brief getPoint return point * @return point */ - inline QPointF getPoint()const {return point;} - ~DialogSinglePoint(); + QPointF getPoint()const; public slots: /** * @brief mousePress get mouse position @@ -92,4 +92,14 @@ private: QPointF point; }; +inline QString DialogSinglePoint::getName() const +{ + return name; +} + +inline QPointF DialogSinglePoint::getPoint() const +{ + return point; +} + #endif // DIALOGSINGLEPOINT_H diff --git a/src/dialogs/dialogsinglepoint.ui b/src/dialogs/tools/dialogsinglepoint.ui similarity index 100% rename from src/dialogs/dialogsinglepoint.ui rename to src/dialogs/tools/dialogsinglepoint.ui diff --git a/src/dialogs/dialogspline.cpp b/src/dialogs/tools/dialogspline.cpp similarity index 86% rename from src/dialogs/dialogspline.cpp rename to src/dialogs/tools/dialogspline.cpp index 88b1a8f19..411868d5b 100644 --- a/src/dialogs/dialogspline.cpp +++ b/src/dialogs/tools/dialogspline.cpp @@ -36,11 +36,7 @@ DialogSpline::DialogSpline(const VContainer *data, QWidget *parent) kAsm1(1), kAsm2(1), kCurve(1) { ui->setupUi(this); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogSpline::DialogAccepted); - - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogSpline::DialogRejected); + InitOkCansel(ui); FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); @@ -51,14 +47,14 @@ DialogSpline::~DialogSpline() delete ui; } -qint64 DialogSpline::getP1() const +quint32 DialogSpline::getP1() const { return p1; } -void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogSpline::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); if (number == 0) @@ -81,7 +77,7 @@ void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type) number = 0; emit ToolTip(""); index = ui->comboBoxP1->currentIndex(); - qint64 p1Id = qvariant_cast(ui->comboBoxP1->itemData(index)); + quint32 p1Id = qvariant_cast(ui->comboBoxP1->itemData(index)); QPointF p1 = data->GeometricObject(p1Id)->toQPointF(); QPointF p4 = data->GeometricObject(id)->toQPointF(); @@ -139,19 +135,19 @@ void DialogSpline::setAngle1(const qreal &value) ui->spinBoxAngle1->setValue(static_cast(value)); } -void DialogSpline::setP4(const qint64 &value) +void DialogSpline::setP4(const quint32 &value) { p4 = value; ChangeCurrentData(ui->comboBoxP4, value); } -void DialogSpline::setP1(const qint64 &value) +void DialogSpline::setP1(const quint32 &value) { p1 = value; ChangeCurrentData(ui->comboBoxP1, value); } -qint64 DialogSpline::getP4() const +quint32 DialogSpline::getP4() const { return p4; } diff --git a/src/dialogs/dialogspline.h b/src/dialogs/tools/dialogspline.h similarity index 80% rename from src/dialogs/dialogspline.h rename to src/dialogs/tools/dialogspline.h index f78b94bd5..c88ec7bb8 100644 --- a/src/dialogs/dialogspline.h +++ b/src/dialogs/tools/dialogspline.h @@ -43,38 +43,38 @@ class DialogSpline : public DialogTool { Q_OBJECT public: - /** - * @brief DialogSpline create dialog - * @param data container with data - * @param parent parent widget - */ - DialogSpline(const VContainer *data, QWidget *parent = 0); - ~DialogSpline(); + /** + * @brief DialogSpline create dialog + * @param data container with data + * @param parent parent widget + */ + DialogSpline(const VContainer *data, QWidget *parent = nullptr); + ~DialogSpline(); /** * @brief getP1 return id first point of spline * @return id */ - qint64 getP1() const; + quint32 getP1() const; /** * @brief setP1 set id first point of spline * @param value id */ - void setP1(const qint64 &value); + void setP1(const quint32 &value); /** * @brief getP4 return id fourth point of spline * @return id */ - qint64 getP4() const; + quint32 getP4() const; /** * @brief setP4 set id fourth point of spline * @param value id */ - void setP4(const qint64 &value); + void setP4(const quint32 &value); /** * @brief getAngle1 return first angle of spline * @return angle in degree */ - inline qreal getAngle1() const {return angle1;} + qreal getAngle1() const; /** * @brief setAngle1 set first angle of spline * @param value angle in degree @@ -84,7 +84,7 @@ public: * @brief getAngle2 return second angle of spline * @return angle in degree */ - inline qreal getAngle2() const {return angle2;} + qreal getAngle2() const; /** * @brief setAngle2 set second angle of spline * @param value angle in degree @@ -94,7 +94,7 @@ public: * @brief getKAsm1 return first coefficient asymmetry * @return value. Can be >= 0. */ - inline qreal getKAsm1() const {return kAsm1;} + qreal getKAsm1() const; /** * @brief setKAsm1 set first coefficient asymmetry * @param value value. Can be >= 0. @@ -104,7 +104,7 @@ public: * @brief getKAsm2 return second coefficient asymmetry * @return value. Can be >= 0. */ - inline qreal getKAsm2() const {return kAsm2;} + qreal getKAsm2() const; /** * @brief setKAsm2 set second coefficient asymmetry * @param value value. Can be >= 0. @@ -114,7 +114,7 @@ public: * @brief getKCurve return coefficient curve * @return value. Can be >= 0. */ - inline qreal getKCurve() const {return kCurve;} + qreal getKCurve() const; /** * @brief setKCurve set coefficient curve * @param value value. Can be >= 0. @@ -126,7 +126,7 @@ public slots: * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -144,11 +144,11 @@ private: /** * @brief p1 id first point of spline */ - qint64 p1; + quint32 p1; /** * @brief p4 id fourth point of spline */ - qint64 p4; + quint32 p4; /** * @brief angle1 first angle of spline in degree */ @@ -171,4 +171,29 @@ private: qreal kCurve; }; +inline qreal DialogSpline::getAngle1() const +{ + return angle1; +} + +inline qreal DialogSpline::getAngle2() const +{ + return angle2; +} + +inline qreal DialogSpline::getKAsm1() const +{ + return kAsm1; +} + +inline qreal DialogSpline::getKAsm2() const +{ + return kAsm2; +} + +inline qreal DialogSpline::getKCurve() const +{ + return kCurve; +} + #endif // DIALOGSPLINE_H diff --git a/src/dialogs/dialogspline.ui b/src/dialogs/tools/dialogspline.ui similarity index 100% rename from src/dialogs/dialogspline.ui rename to src/dialogs/tools/dialogspline.ui diff --git a/src/dialogs/dialogsplinepath.cpp b/src/dialogs/tools/dialogsplinepath.cpp similarity index 92% rename from src/dialogs/dialogsplinepath.cpp rename to src/dialogs/tools/dialogsplinepath.cpp index 058dc5a9a..ed7d10dbf 100644 --- a/src/dialogs/dialogsplinepath.cpp +++ b/src/dialogs/tools/dialogsplinepath.cpp @@ -28,7 +28,7 @@ #include "dialogsplinepath.h" #include "ui_dialogsplinepath.h" -#include "../geometry/vsplinepoint.h" +#include "../../geometry/vsplinepoint.h" #include @@ -36,13 +36,9 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) { ui->setupUi(this); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogSplinePath::DialogAccepted); + InitOkCansel(ui); bOk->setEnabled(false); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogSplinePath::DialogRejected); - FillComboBoxPoints(ui->comboBoxPoint); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogSplinePath::PointChanged); @@ -76,9 +72,9 @@ void DialogSplinePath::SetPath(const VSplinePath &value) } -void DialogSplinePath::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogSplinePath::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { NewItem(id, 1, 0, 1, 180); emit ToolTip(tr("Select point of curve path")); @@ -113,7 +109,7 @@ void DialogSplinePath::PointChanged(int row) void DialogSplinePath::currentPointChanged(int index) { - qint64 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); + quint32 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); @@ -164,7 +160,7 @@ void DialogSplinePath::KAsm2Changed(qreal d) item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) +void DialogSplinePath::NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) { const VPointF *point = data->GeometricObject(id); QListWidgetItem *item = new QListWidgetItem(point->name()); @@ -182,7 +178,7 @@ void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2 EnableFields(); } -void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) +void DialogSplinePath::DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) { disconnect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogSplinePath::currentPointChanged); diff --git a/src/dialogs/dialogsplinepath.h b/src/dialogs/tools/dialogsplinepath.h similarity index 84% rename from src/dialogs/dialogsplinepath.h rename to src/dialogs/tools/dialogsplinepath.h index c88713f55..287d316cb 100644 --- a/src/dialogs/dialogsplinepath.h +++ b/src/dialogs/tools/dialogsplinepath.h @@ -30,7 +30,7 @@ #define DIALOGSPLINEPATH_H #include "dialogtool.h" -#include "../geometry/vsplinepath.h" +#include "../../geometry/vsplinepath.h" namespace Ui { @@ -44,18 +44,18 @@ class DialogSplinePath : public DialogTool { Q_OBJECT public: - /** - * @brief DialogSplinePath create dialog - * @param data container with data - * @param parent parent widget - */ - DialogSplinePath(const VContainer *data, QWidget *parent = 0); - ~DialogSplinePath(); + /** + * @brief DialogSplinePath create dialog + * @param data container with data + * @param parent parent widget + */ + DialogSplinePath(const VContainer *data, QWidget *parent = nullptr); + ~DialogSplinePath(); /** * @brief GetPath return spline path * @return path */ - inline VSplinePath GetPath() const {return path;} + VSplinePath GetPath() const; /** * @brief SetPath set spline path * @param value path @@ -67,7 +67,7 @@ public slots: * @param id id of point or detail * @param type don't show this id in list */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -120,7 +120,7 @@ private: * @param kAsm2 second coefficient asymmetry * @param angle2 second angle in degree */ - void NewItem(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); + void NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); /** * @brief dataPoint show data of point in fields * @param id id @@ -129,11 +129,16 @@ private: * @param kAsm2 second coefficient asymmetry * @param angle2 second angle of spline */ - void DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); + void DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); /** * @brief EnableFields enable or disable fields */ void EnableFields(); }; +inline VSplinePath DialogSplinePath::GetPath() const +{ + return path; +} + #endif // DIALOGSPLINEPATH_H diff --git a/src/dialogs/dialogsplinepath.ui b/src/dialogs/tools/dialogsplinepath.ui similarity index 100% rename from src/dialogs/dialogsplinepath.ui rename to src/dialogs/tools/dialogsplinepath.ui diff --git a/src/dialogs/dialogtool.cpp b/src/dialogs/tools/dialogtool.cpp similarity index 78% rename from src/dialogs/dialogtool.cpp rename to src/dialogs/tools/dialogtool.cpp index 18f1cfdf5..320dea50a 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/tools/dialogtool.cpp @@ -27,18 +27,19 @@ *************************************************************************/ #include "dialogtool.h" -#include "../container/calculator.h" -#include "../geometry/vgobject.h" -#include "../tools/vabstracttool.h" +#include "../../container/calculator.h" +#include "../../geometry/vgobject.h" +#include "../../tools/vabstracttool.h" #include DialogTool::DialogTool(const VContainer *data, QWidget *parent) - :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), - spinBoxAngle(0), lineEditFormula(0), listWidget(0), labelResultCalculation(0), labelDescription(0), - labelEditNamePoint(0), labelEditFormula(0), radioButtonSizeGrowth(0), radioButtonStandardTable(0), - radioButtonIncrements(0), radioButtonLengthLine(0), radioButtonLengthArc(0), radioButtonLengthCurve(0), - lineStyles(QStringList()) + :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr), + bOk(nullptr), spinBoxAngle(nullptr), lineEditFormula(nullptr), listWidget(nullptr), + labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), + labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), + radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), + radioButtonLengthCurve(nullptr), lineStyles(QStringList()) { Q_CHECK_PTR(data); timerFormula = new QTimer(this); @@ -70,19 +71,19 @@ void DialogTool::showEvent(QShowEvent *event) isInitialized = true;//first show windows are held } -void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const +void DialogTool::FillComboBoxPoints(QComboBox *box, const quint32 &id) const { Q_CHECK_PTR(box); - const QHash *objs = data->DataGObjects(); - QHashIterator i(*objs); - QMap list; + const QHash *objs = data->DataGObjects(); + QHashIterator i(*objs); + QMap list; while (i.hasNext()) { i.next(); if (i.key() != id) { VGObject *obj = i.value(); - if (obj->getType() == GObject::Point && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Point && obj->getMode() == Valentina::Calculation) { const VPointF *point = data->GeometricObject(i.key()); list[point->name()] = i.key(); @@ -92,12 +93,12 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const FillList(box, list); } -void DialogTool::FillComboBoxArcs(QComboBox *box, const qint64 &id, ComboMode::ComboBoxCutArc cut) const +void DialogTool::FillComboBoxArcs(QComboBox *box, const quint32 &id, ComboMode::ComboBoxCutArc cut) const { Q_CHECK_PTR(box); - const QHash *objs = data->DataGObjects(); - QHashIterator i(*objs); - QMap list; + const QHash *objs = data->DataGObjects(); + QHashIterator i(*objs); + QMap list; while (i.hasNext()) { i.next(); @@ -106,7 +107,7 @@ void DialogTool::FillComboBoxArcs(QComboBox *box, const qint64 &id, ComboMode::C if (i.key() != id + 1 && i.key() != id + 2) { VGObject *obj = i.value(); - if (obj->getType() == GObject::Arc && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Arc && obj->getMode() == Valentina::Calculation) { const VArc *arc = data->GeometricObject(i.key()); list[arc->name()] = i.key(); @@ -118,7 +119,7 @@ void DialogTool::FillComboBoxArcs(QComboBox *box, const qint64 &id, ComboMode::C if (i.key() != id) { VGObject *obj = i.value(); - if (obj->getType() == GObject::Arc && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Arc && obj->getMode() == Valentina::Calculation) { const VArc *arc = data->GeometricObject(i.key()); list[arc->name()] = i.key(); @@ -129,12 +130,12 @@ void DialogTool::FillComboBoxArcs(QComboBox *box, const qint64 &id, ComboMode::C FillList(box, list); } -void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode::ComboBoxCutSpline cut) const +void DialogTool::FillComboBoxSplines(QComboBox *box, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { Q_CHECK_PTR(box); - const QHash *objs = data->DataGObjects(); - QHashIterator i(*objs); - QMap list; + const QHash *objs = data->DataGObjects(); + QHashIterator i(*objs); + QMap list; while (i.hasNext()) { i.next(); @@ -143,7 +144,7 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode if (i.key() != id + 1 && i.key() != id + 2) { VGObject *obj = i.value(); - if (obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Spline && obj->getMode() == Valentina::Calculation) { const VSpline *spl = data->GeometricObject(i.key()); list[spl->name()] = i.key(); @@ -155,7 +156,7 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode if (i.key() != id) { VGObject *obj = i.value(); - if (obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Spline && obj->getMode() == Valentina::Calculation) { const VSpline *spl = data->GeometricObject(i.key()); list[spl->name()] = i.key(); @@ -166,12 +167,12 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode FillList(box, list); } -void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, ComboMode::ComboBoxCutSpline cut) const +void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { Q_CHECK_PTR(box); - const QHash *objs = data->DataGObjects(); - QHashIterator i(*objs); - QMap list; + const QHash *objs = data->DataGObjects(); + QHashIterator i(*objs); + QMap list; while (i.hasNext()) { i.next(); @@ -180,7 +181,7 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, Combo if (i.key() != id + 1 && i.key() != id + 2) { VGObject *obj = i.value(); - if (obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::SplinePath && obj->getMode() == Valentina::Calculation) { const VSplinePath *splPath = data->GeometricObject(i.key()); list[splPath->name()] = i.key(); @@ -192,7 +193,7 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, Combo if (i.key() != id) { VGObject *obj = i.value(); - if (obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::SplinePath && obj->getMode() == Valentina::Calculation) { const VSplinePath *splPath = data->GeometricObject(i.key()); list[splPath->name()] = i.key(); @@ -212,7 +213,7 @@ void DialogTool::FillComboBoxTypeLine(QComboBox *box) const QString DialogTool::GetTypeLine(const QComboBox *box) const { - switch(lineStyles.indexOf(box->currentText())) + switch (lineStyles.indexOf(box->currentText())) { case 0: //No line return VAbstractTool::TypeLineNone; @@ -257,11 +258,11 @@ void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value) } else { - qWarning()<findData(value); if (index != -1) @@ -275,6 +276,7 @@ void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) Q_CHECK_PTR(lineEdit); Q_CHECK_PTR(listWidget); QListWidgetItem *item = listWidget->currentItem(); + Q_CHECK_PTR(item); int pos = lineEdit->cursorPosition(); lineEdit->setText(lineEdit->text().insert(lineEdit->cursorPosition(), item->text())); lineEdit->setFocus(); @@ -333,7 +335,7 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) labelEditFormula->setPalette(palette); } -void DialogTool::setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, const qint64 &id) const +void DialogTool::setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const { Q_CHECK_PTR(box); FillComboBoxPoints(box, id); @@ -341,7 +343,7 @@ void DialogTool::setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 ChangeCurrentData(box, value); } -void DialogTool::setCurrentSplineId(QComboBox *box, qint64 &splineId, const qint64 &value, const qint64 &id, +void DialogTool::setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { Q_CHECK_PTR(box); @@ -350,7 +352,7 @@ void DialogTool::setCurrentSplineId(QComboBox *box, qint64 &splineId, const qint ChangeCurrentData(box, value); } -void DialogTool::setCurrentArcId(QComboBox *box, qint64 &arcId, const qint64 &value, const qint64 &id, +void DialogTool::setCurrentArcId(QComboBox *box, quint32 &arcId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutArc cut) const { Q_CHECK_PTR(box); @@ -359,8 +361,8 @@ void DialogTool::setCurrentArcId(QComboBox *box, qint64 &arcId, const qint64 &va ChangeCurrentData(box, value); } -void DialogTool::setCurrentSplinePathId(QComboBox *box, qint64 &splinePathId, const qint64 &value, - const qint64 &id, ComboMode::ComboBoxCutSpline cut) const +void DialogTool::setCurrentSplinePathId(QComboBox *box, quint32 &splinePathId, const quint32 &value, + const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { Q_CHECK_PTR(box); FillComboBoxSplinesPath(box, id, cut); @@ -368,14 +370,14 @@ void DialogTool::setCurrentSplinePathId(QComboBox *box, qint64 &splinePathId, co ChangeCurrentData(box, value); } -qint64 DialogTool::getCurrentObjectId(QComboBox *box) const +quint32 DialogTool::getCurrentObjectId(QComboBox *box) const { Q_CHECK_PTR(box); qint32 index = box->currentIndex(); Q_ASSERT(index != -1); if (index != -1) { - return qvariant_cast(box->itemData(index)); + return qvariant_cast(box->itemData(index)); } else { @@ -383,12 +385,27 @@ qint64 DialogTool::getCurrentObjectId(QComboBox *box) const } } -void DialogTool::FillList(QComboBox *box, const QMap &list) const +bool DialogTool::ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip) +{ + Q_CHECK_PTR(box); + const VPointF *point = data->GeometricObject(id); + Q_CHECK_PTR(point); + const qint32 index = box->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + box->setCurrentIndex(index); + emit ToolTip(toolTip); + return true; + } + return false; +} + +void DialogTool::FillList(QComboBox *box, const QMap &list) const { Q_CHECK_PTR(box); box->clear(); - QMapIterator iter(list); + QMapIterator iter(list); while (iter.hasNext()) { iter.next(); @@ -402,7 +419,7 @@ void DialogTool::CheckState() bOk->setEnabled(flagFormula && flagName); } -void DialogTool::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogTool::ChoosedObject(quint32 id, const Valentina::Scenes &type) { Q_UNUSED(id); Q_UNUSED(type); @@ -507,14 +524,29 @@ void DialogTool::EvalFormula() Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); } -void DialogTool::SizeGrowth() +void DialogTool::SizeHeight() { - ShowVariable(data->DataBase()); + Q_CHECK_PTR(listWidget); + disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->clear(); + + { + QListWidgetItem *item = new QListWidgetItem(data->HeightName()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + } + + QListWidgetItem *item = new QListWidgetItem(data->SizeName()); + item->setFont(QFont("Times", 12, QFont::Bold)); + listWidget->addItem(item); + + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->setCurrentRow (0); } -void DialogTool::StandardTable() +void DialogTool::Measurements() { - ShowVariable(data->DataStandardTable()); + ShowVariable(data->DataMeasurements()); } void DialogTool::LengthLines() @@ -534,7 +566,7 @@ void DialogTool::LengthCurves() void DialogTool::Increments() { - ShowVariable(data->DataIncrementTable()); + ShowVariable(data->DataIncrements()); } void DialogTool::PutHere() @@ -570,12 +602,12 @@ void DialogTool::ValChenged(int row) QListWidgetItem *item = listWidget->item( row ); if (radioButtonSizeGrowth->isChecked()) { - if (item->text()=="Р") + if (item->text()==data->HeightName()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg(tr("Height")); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->height()).arg(tr("Height")); labelDescription->setText(desc); } - if (item->text()=="Сг") + if (item->text()==data->SizeName()) { QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg(tr("Size")); labelDescription->setText(desc); @@ -584,17 +616,17 @@ void DialogTool::ValChenged(int row) } if (radioButtonStandardTable->isChecked()) { - VStandardTableRow stable = data->GetStandardTableCell(item->text()); - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandardTableCell(item->text())) + VMeasurement stable = data->GetMeasurement(item->text()); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandardTableRow(item->text())) .arg(stable.GetDescription()); labelDescription->setText(desc); return; } if (radioButtonIncrements->isChecked()) { - VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); + VIncrement incr = data->GetIncrement(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) - .arg(itable.getDescription()); + .arg(incr.getDescription()); labelDescription->setText(desc); return; } @@ -632,15 +664,15 @@ void DialogTool::UpdateList() if (radioButtonSizeGrowth->isChecked()) { - ShowVariable(data->DataBase()); + SizeHeight(); } if (radioButtonStandardTable->isChecked()) { - ShowVariable(data->DataStandardTable()); + ShowVariable(data->DataMeasurements()); } if (radioButtonIncrements->isChecked()) { - ShowVariable(data->DataIncrementTable()); + ShowVariable(data->DataIncrements()); } if (radioButtonLengthLine->isChecked()) { diff --git a/src/dialogs/dialogtool.h b/src/dialogs/tools/dialogtool.h similarity index 75% rename from src/dialogs/dialogtool.h rename to src/dialogs/tools/dialogtool.h index ef8346c0d..eb5111c04 100644 --- a/src/dialogs/dialogtool.h +++ b/src/dialogs/tools/dialogtool.h @@ -35,7 +35,9 @@ #include #include #include -#include "../container/vcontainer.h" +#include +#include "../../container/vcontainer.h" +#include "../../widgets/vapplication.h" namespace ComboMode { @@ -63,7 +65,7 @@ public: * @param data container with data * @param parent parent widget */ - DialogTool(const VContainer *data, QWidget *parent = 0); + DialogTool(const VContainer *data, QWidget *parent = nullptr); virtual ~DialogTool() {} signals: /** @@ -82,7 +84,7 @@ public slots: * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief NamePointChanged check name of point */ @@ -136,13 +138,13 @@ public slots: */ void EvalFormula(); /** - * @brief SizeGrowth show in list base variables + * @brief SizeHeight show in list base variables */ - void SizeGrowth(); + void SizeHeight(); /** - * @brief StandardTable show in list standard table variables + * @brief Measurements show in list measurements */ - void StandardTable(); + void Measurements(); /** * @brief LengthLines show in list lengths of lines variables */ @@ -274,8 +276,8 @@ protected: * @param box comboBox * @param id don't show this id in list */ - void FillComboBoxPoints(QComboBox *box, const qint64 &id = 0)const; - void FillComboBoxArcs(QComboBox *box, const qint64 &id = 0, + void FillComboBoxPoints(QComboBox *box, const quint32 &id = 0)const; + void FillComboBoxArcs(QComboBox *box, const quint32 &id = 0, ComboMode::ComboBoxCutArc cut = ComboMode::NoCutArc)const; /** * @brief FillComboBoxSplines fill comboBox list of splines @@ -283,7 +285,7 @@ protected: * @param id don't show id in list * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ - void FillComboBoxSplines(QComboBox *box, const qint64 &id = 0, + void FillComboBoxSplines(QComboBox *box, const quint32 &id = 0, ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline)const; /** * @brief FillComboBoxSplinesPath @@ -291,7 +293,7 @@ protected: * @param id don't show id in list * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ - void FillComboBoxSplinesPath(QComboBox *box, const qint64 &id = 0, + void FillComboBoxSplinesPath(QComboBox *box, const quint32 &id = 0, ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline)const; /** * @brief FillComboBoxTypeLine fill comboBox list of type lines @@ -331,7 +333,7 @@ protected: * @param box combobox * @param value id of item */ - void ChangeCurrentData(QComboBox *box, const qint64 &value) const; + void ChangeCurrentData(QComboBox *box, const quint32 &value) const; /** * @brief PutValHere put variable into line edit from list * @param lineEdit lineEdit @@ -360,7 +362,7 @@ protected: * @param value point id * @param id don't show this id in list */ - void setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, const qint64 &id) const; + void setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const; /** * @brief setCurrentSplineId set current spline id in combobox * @param box combobox @@ -369,7 +371,7 @@ protected: * @param id don't show this id in list * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ - void setCurrentSplineId(QComboBox *box, qint64 &splineId, const qint64 &value, const qint64 &id, + void setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline) const; /** * @brief setCurrentArcId @@ -379,7 +381,7 @@ protected: * @param id don't show this id in list * @param cut if set to ComboMode::CutArc don't show id+1 and id+2 */ - void setCurrentArcId(QComboBox *box, qint64 &arcId, const qint64 &value, const qint64 &id, + void setCurrentArcId(QComboBox *box, quint32 &arcId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutArc cut = ComboMode::NoCutArc) const; /** * @brief setCurrentSplinePathId set current splinePath id in combobox @@ -389,21 +391,78 @@ protected: * @param id don't show this id in list * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ - void setCurrentSplinePathId(QComboBox *box, qint64 &splinePathId, const qint64 &value, const qint64 &id, + void setCurrentSplinePathId(QComboBox *box, quint32 &splinePathId, const quint32 &value, + const quint32 &id, ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline) const; /** * @brief getCurrentPointId return current point id in combobox * @param box combobox * @return id or -1 if combobox is empty */ - qint64 getCurrentObjectId(QComboBox *box) const; + quint32 getCurrentObjectId(QComboBox *box) const; + bool ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip); + template + void InitArrow(T *ui) + { + Q_CHECK_PTR(ui); + spinBoxAngle = ui->doubleSpinBoxAngle; + connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogTool::ArrowDown); + connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, &DialogTool::ArrowUp); + connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, &DialogTool::ArrowLeft); + connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, &DialogTool::ArrowRight); + connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, &DialogTool::ArrowLeftUp); + connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, &DialogTool::ArrowLeftDown); + connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, &DialogTool::ArrowRightUp); + connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, &DialogTool::ArrowRightDown); + } + template + void InitVariables(T *ui) + { + listWidget = ui->listWidget; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandardTable = ui->radioButtonStandardTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; + + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + + if (qApp->patternType() == Pattern::Standard) + { + SizeHeight(); + connect(radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogTool::SizeHeight); + } + else + { + radioButtonSizeGrowth->setVisible(false); + Measurements(); + } + connect(radioButtonStandardTable, &QRadioButton::clicked, this, &DialogTool::Measurements); + connect(radioButtonIncrements, &QRadioButton::clicked, this, &DialogTool::Increments); + connect(radioButtonLengthLine, &QRadioButton::clicked, this, &DialogTool::LengthLines); + connect(radioButtonLengthArc, &QRadioButton::clicked, this, &DialogTool::LengthArcs); + connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves); + } + template + void InitOkCansel(T *ui) + { + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + Q_CHECK_PTR(bOk); + connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); + + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + Q_CHECK_PTR(bCansel); + connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); + } private: /** * @brief FillList fill combobox list * @param box combobox * @param list list with ids and names */ - void FillList(QComboBox *box, const QMap &list)const; + void FillList(QComboBox *box, const QMap &list)const; }; #endif // DIALOGTOOL_H diff --git a/src/dialogs/dialogtriangle.cpp b/src/dialogs/tools/dialogtriangle.cpp similarity index 85% rename from src/dialogs/dialogtriangle.cpp rename to src/dialogs/tools/dialogtriangle.cpp index e4c1f63aa..d58a3094d 100644 --- a/src/dialogs/dialogtriangle.cpp +++ b/src/dialogs/tools/dialogtriangle.cpp @@ -37,12 +37,9 @@ DialogTriangle::DialogTriangle(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogTriangle::DialogAccepted); + InitOkCansel(ui); flagName = false; CheckState(); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogTriangle::DialogRejected); FillComboBoxPoints(ui->comboBoxAxisP1); FillComboBoxPoints(ui->comboBoxAxisP2); @@ -57,9 +54,9 @@ DialogTriangle::~DialogTriangle() delete ui; } -void DialogTriangle::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogTriangle::ChoosedObject(quint32 id, const Valentina::Scenes &type) { - if (type == Scene::Point) + if (type == Valentina::Point) { const VPointF *point = data->GeometricObject(id); switch (number) @@ -110,25 +107,25 @@ void DialogTriangle::setPointName(const QString &value) ui->lineEditNamePoint->setText(pointName); } -void DialogTriangle::setSecondPointId(const qint64 &value, const qint64 &id) +void DialogTriangle::setSecondPointId(const quint32 &value, const quint32 &id) { secondPointId = value; setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -void DialogTriangle::setFirstPointId(const qint64 &value, const qint64 &id) +void DialogTriangle::setFirstPointId(const quint32 &value, const quint32 &id) { firstPointId = value; setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } -void DialogTriangle::setAxisP2Id(const qint64 &value, const qint64 &id) +void DialogTriangle::setAxisP2Id(const quint32 &value, const quint32 &id) { axisP2Id = value; setCurrentPointId(ui->comboBoxAxisP2, axisP2Id, value, id); } -void DialogTriangle::setAxisP1Id(const qint64 &value, const qint64 &id) +void DialogTriangle::setAxisP1Id(const quint32 &value, const quint32 &id) { axisP1Id = value; setCurrentPointId(ui->comboBoxAxisP1, axisP1Id, value, id); diff --git a/src/dialogs/dialogtriangle.h b/src/dialogs/tools/dialogtriangle.h similarity index 72% rename from src/dialogs/dialogtriangle.h rename to src/dialogs/tools/dialogtriangle.h index 0335aa9c4..d1d132857 100644 --- a/src/dialogs/dialogtriangle.h +++ b/src/dialogs/tools/dialogtriangle.h @@ -43,62 +43,62 @@ class DialogTriangle : public DialogTool { Q_OBJECT public: - /** - * @brief DialogTriangle create dialog - * @param data container with data - * @param parent parent widget - */ - DialogTriangle(const VContainer *data, QWidget *parent = 0); - ~DialogTriangle(); + /** + * @brief DialogTriangle create dialog + * @param data container with data + * @param parent parent widget + */ + DialogTriangle(const VContainer *data, QWidget *parent = nullptr); + ~DialogTriangle(); /** * @brief getAxisP1Id return id first point of axis * @return id */ - inline qint64 getAxisP1Id() const {return axisP1Id;} + quint32 getAxisP1Id() const; /** * @brief setAxisP1Id set id first point of axis * @param value id * @param id don't show this point in list */ - void setAxisP1Id(const qint64 &value, const qint64 &id); + void setAxisP1Id(const quint32 &value, const quint32 &id); /** * @brief getAxisP2Id return id second point of axis * @return id */ - inline qint64 getAxisP2Id() const {return axisP2Id;} + quint32 getAxisP2Id() const; /** * @brief setAxisP2Id set id second point of axis * @param value id * @param id don't show this point in list */ - void setAxisP2Id(const qint64 &value, const qint64 &id); + void setAxisP2Id(const quint32 &value, const quint32 &id); /** * @brief getFirstPointId return id of first point * @return id */ - inline qint64 getFirstPointId() const {return firstPointId;} + quint32 getFirstPointId() const; /** * @brief setFirstPointId set id of first point * @param value id * @param id don't show this point in list */ - void setFirstPointId(const qint64 &value, const qint64 &id); + void setFirstPointId(const quint32 &value, const quint32 &id); /** * @brief getSecondPointId return id of second point * @return id */ - inline qint64 getSecondPointId() const {return secondPointId;} + quint32 getSecondPointId() const; /** * @brief setSecondPointId set id of second point * @param value id * @param id don't show this point in list */ - void setSecondPointId(const qint64 &value, const qint64 &id); + void setSecondPointId(const quint32 &value, const quint32 &id); /** * @brief getPointName return name of point * @return name */ - inline QString getPointName() const {return pointName;} + QString getPointName() const; /** * @brief setPointName set name of point * @param value name @@ -110,7 +110,7 @@ public slots: * @param id id of point or detail * @param type type of object */ - virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -132,19 +132,44 @@ private: /** * @brief axisP1Id id first point of axis */ - qint64 axisP1Id; + quint32 axisP1Id; /** * @brief axisP2Id id second point of axis */ - qint64 axisP2Id; + quint32 axisP2Id; /** * @brief firstPointId id first point of line */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second point of line */ - qint64 secondPointId; + quint32 secondPointId; }; +inline quint32 DialogTriangle::getAxisP1Id() const +{ + return axisP1Id; +} + +inline quint32 DialogTriangle::getAxisP2Id() const +{ + return axisP2Id; +} + +inline quint32 DialogTriangle::getFirstPointId() const +{ + return firstPointId; +} + +inline quint32 DialogTriangle::getSecondPointId() const +{ + return secondPointId; +} + +inline QString DialogTriangle::getPointName() const +{ + return pointName; +} + #endif // DIALOGTRIANGLE_H diff --git a/src/dialogs/dialogtriangle.ui b/src/dialogs/tools/dialogtriangle.ui similarity index 100% rename from src/dialogs/dialogtriangle.ui rename to src/dialogs/tools/dialogtriangle.ui diff --git a/src/dialogs/dialoguniondetails.cpp b/src/dialogs/tools/dialoguniondetails.cpp similarity index 83% rename from src/dialogs/dialoguniondetails.cpp rename to src/dialogs/tools/dialoguniondetails.cpp index 9dac1278d..4eb9e10ad 100644 --- a/src/dialogs/dialoguniondetails.cpp +++ b/src/dialogs/tools/dialoguniondetails.cpp @@ -34,10 +34,7 @@ DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) numberP(0), p1(0), p2(0) { ui->setupUi(this); - bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - connect(bOk, &QPushButton::clicked, this, &DialogUnionDetails::DialogAccepted); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - connect(bCansel, &QPushButton::clicked, this, &DialogUnionDetails::DialogRejected); + InitOkCansel(ui); } DialogUnionDetails::~DialogUnionDetails() @@ -45,7 +42,7 @@ DialogUnionDetails::~DialogUnionDetails() delete ui; } -void DialogUnionDetails::ChoosedObject(qint64 id, const Scene::Scenes &type) +void DialogUnionDetails::ChoosedObject(quint32 id, const Valentina::Scenes &type) { if (numberD == 0) { @@ -62,7 +59,7 @@ void DialogUnionDetails::DialogAccepted() emit DialogClosed(QDialog::Accepted); } -bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) const +bool DialogUnionDetails::CheckObject(const quint32 &id, const quint32 &idDetail) const { if (idDetail == 0) { @@ -72,11 +69,12 @@ bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) c return det.Containes(id); } -void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index) +void DialogUnionDetails::ChoosedDetail(const quint32 &id, const Valentina::Scenes &type, quint32 &idDetail, + ptrdiff_t &index) { if (idDetail == 0) { - if (type == Scene::Detail) + if (type == Valentina::Detail) { idDetail = id; emit ToolTip(tr("Select first point")); @@ -87,7 +85,7 @@ void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &ty { return; } - if (type == Scene::Point) + if (type == Valentina::Point) { if (numberP == 0) { diff --git a/src/dialogs/dialoguniondetails.h b/src/dialogs/tools/dialoguniondetails.h similarity index 80% rename from src/dialogs/dialoguniondetails.h rename to src/dialogs/tools/dialoguniondetails.h index ad94b45f4..5d8e4a225 100644 --- a/src/dialogs/dialoguniondetails.h +++ b/src/dialogs/tools/dialoguniondetails.h @@ -48,35 +48,35 @@ public: * @param data container with data * @param parent parent widget */ - DialogUnionDetails(const VContainer *data, QWidget *parent = 0); + DialogUnionDetails(const VContainer *data, QWidget *parent = nullptr); ~DialogUnionDetails(); /** * @brief getD1 return id first detail * @return id */ - inline qint64 getD1() const {return d1;} + quint32 getD1() const; /** * @brief getD2 return id second detail * @return id */ - inline qint64 getD2() const {return d2;} + quint32 getD2() const; /** * @brief getIndexD1 return index edge first detail * @return index */ - inline ptrdiff_t getIndexD1() const {return indexD1;} + ptrdiff_t getIndexD1() const; /** * @brief getIndexD2 return index edge second detail * @return index */ - inline ptrdiff_t getIndexD2() const {return indexD2;} + ptrdiff_t getIndexD2() const; public slots: /** * @brief ChoosedObject gets id and type of selected object. Save correct data and ignore wrong. * @param id id of point or detail * @param type type of object */ - void ChoosedObject(qint64 id, const Scene::Scenes &type); + void ChoosedObject(quint32 id, const Valentina::Scenes &type); /** * @brief DialogAccepted save data and emit signal about closed dialog. */ @@ -98,11 +98,11 @@ private: /** * @brief d1 id first detail */ - qint64 d1; + quint32 d1; /** * @brief d2 id second detail */ - qint64 d2; + quint32 d2; /** * @brief numberD number of detail, what we already have */ @@ -114,18 +114,18 @@ private: /** * @brief p1 id first point of detail */ - qint64 p1; + quint32 p1; /** * @brief p2 id second point of detail */ - qint64 p2; + quint32 p2; /** * @brief CheckObject check if detail contain this id * @param id id of item * @param idDetail detail id * @return true if contain */ - bool CheckObject(const qint64 &id, const qint64 &idDetail) const; + bool CheckObject(const quint32 &id, const quint32 &idDetail) const; /** * @brief ChoosedDetail help save information about detail and points on detail * @param id id selected object @@ -133,7 +133,27 @@ private: * @param idDetail id detail * @param index index of edge */ - void ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index); + void ChoosedDetail(const quint32 &id, const Valentina::Scenes &type, quint32 &idDetail, ptrdiff_t &index); }; +inline quint32 DialogUnionDetails::getD1() const +{ + return d1; +} + +inline quint32 DialogUnionDetails::getD2() const +{ + return d2; +} + +inline ptrdiff_t DialogUnionDetails::getIndexD1() const +{ + return indexD1; +} + +inline ptrdiff_t DialogUnionDetails::getIndexD2() const +{ + return indexD2; +} + #endif // DIALOGUNIONDETAILS_H diff --git a/src/dialogs/dialoguniondetails.ui b/src/dialogs/tools/dialoguniondetails.ui similarity index 100% rename from src/dialogs/dialoguniondetails.ui rename to src/dialogs/tools/dialoguniondetails.ui diff --git a/src/exception/exception.pri b/src/exception/exception.pri index 3e0166be0..a743115fc 100644 --- a/src/exception/exception.pri +++ b/src/exception/exception.pri @@ -1,17 +1,15 @@ HEADERS += \ - src/exception/vexceptionwrongparameterid.h \ - src/exception/vexceptionuniqueid.h \ src/exception/vexceptionobjecterror.h \ src/exception/vexceptionemptyparameter.h \ src/exception/vexceptionconversionerror.h \ src/exception/vexceptionbadid.h \ - src/exception/vexception.h + src/exception/vexception.h \ + src/exception/vexceptionwrongid.h SOURCES += \ - src/exception/vexceptionwrongparameterid.cpp \ - src/exception/vexceptionuniqueid.cpp \ src/exception/vexceptionobjecterror.cpp \ src/exception/vexceptionemptyparameter.cpp \ src/exception/vexceptionconversionerror.cpp \ src/exception/vexceptionbadid.cpp \ - src/exception/vexception.cpp + src/exception/vexception.cpp \ + src/exception/vexceptionwrongid.cpp diff --git a/src/exception/vexception.cpp b/src/exception/vexception.cpp index 9d76e95be..4221c65f9 100644 --- a/src/exception/vexception.cpp +++ b/src/exception/vexception.cpp @@ -31,11 +31,16 @@ #include #include -VException::VException(const QString &what):QException(), what(what) +VException::VException(const QString &what):QException(), what(what), moreInfo(QString()) { Q_ASSERT_X(what.isEmpty() == false, Q_FUNC_INFO, "Error message is empty"); } +VException::VException(const VException &e):what(e.What()), moreInfo(e.MoreInformation()) +{ + +} + QString VException::ErrorMessage() const { QString error = QString("Exception: %1").arg(what); @@ -45,20 +50,40 @@ QString VException::ErrorMessage() const void VException::CriticalMessageBox(const QString &situation, QWidget * parent) const { QMessageBox msgBox(parent); - msgBox.setWindowTitle("Critical error!"); + msgBox.setWindowTitle(tr("Critical error!")); msgBox.setText(situation); msgBox.setInformativeText(ErrorMessage()); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); - if (DetailedInformation().isEmpty() == false) + if (moreInfo.isEmpty() == false) { msgBox.setDetailedText(DetailedInformation()); } msgBox.setIcon(QMessageBox::Critical); QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); - Q_CHECK_PTR(horizontalSpacer); QGridLayout* layout = static_cast(msgBox.layout()); Q_CHECK_PTR(layout); layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); msgBox.exec(); } + +void VException::AddMoreInformation(const QString &info) +{ + if (info.isEmpty()) + { + return; + } + moreInfo = QString("%1\n%2").arg(moreInfo, info); +} + +QString VException::MoreInfo(const QString &detInfo) const +{ + if (moreInfo.isEmpty() == false) + { + return QString("%1\n%2").arg(moreInfo, detInfo); + } + else + { + return detInfo; + } +} diff --git a/src/exception/vexception.h b/src/exception/vexception.h index 6eea96e64..1d75437da 100644 --- a/src/exception/vexception.h +++ b/src/exception/vexception.h @@ -39,6 +39,7 @@ */ class VException : public QException { + Q_DECLARE_TR_FUNCTIONS(VException) public: /** * @brief VException constructor exception @@ -49,42 +50,82 @@ public: * @brief VException copy constructor * @param e exception */ - VException(const VException &e):what(e.What()){} + VException(const VException &e); virtual ~VException() noexcept (true){} /** * @brief raise method raise for exception */ - inline void raise() const { throw *this; } + void raise() const; /** * @brief clone clone exception * @return new exception */ - inline VException *clone() const { return new VException(*this); } + VException *clone() const; /** * @brief ErrorMessage return main error message * @return error message */ - virtual QString ErrorMessage() const; + virtual QString ErrorMessage() const; /** * @brief DetailedInformation return detailed information about error * @return detailed information */ - virtual QString DetailedInformation() const { return QString(); } + virtual QString DetailedInformation() const; /** * @brief What return string with error * @return string with error */ - inline QString What() const {return what;} + QString What() const; /** * @brief CriticalMessageBox show Critical Message Box. * @param situation main text message box. */ - virtual void CriticalMessageBox(const QString &situation, QWidget *parent = 0) const; + virtual void CriticalMessageBox(const QString &situation, QWidget *parent = nullptr) const; + /** + * @brief AddMoreInformation add more information for error + * @param info information + */ + void AddMoreInformation(const QString &info); + /** + * @brief MoreInformation return more information for error + * @return information + */ + QString MoreInformation() const; protected: /** * @brief what string with error */ - QString what; + QString what; + /** + * @brief moreInfo more information about error + */ + QString moreInfo; + QString MoreInfo(const QString &detInfo) const; }; +inline void VException::raise() const +{ + throw *this; +} + +inline VException *VException::clone() const +{ + return new VException(*this); +} + +inline QString VException::DetailedInformation() const +{ + return moreInfo; +} + +inline QString VException::What() const +{ + return what; +} + +inline QString VException::MoreInformation() const +{ + return moreInfo; +} + #endif // VEXCEPTION_H diff --git a/src/exception/vexceptionbadid.h b/src/exception/vexceptionbadid.h index 91a407c0c..beee3cdf0 100644 --- a/src/exception/vexceptionbadid.h +++ b/src/exception/vexceptionbadid.h @@ -42,7 +42,7 @@ public: * @param what string with error * @param id id */ - VExceptionBadId(const QString &what, const qint64 &id) + VExceptionBadId(const QString &what, const quint32 &id) :VException(what), id(id), key(QString()){} /** * @brief VExceptionBadId exception bad id @@ -67,21 +67,31 @@ public: * @brief BadId return bad id * @return id */ - inline qint64 BadId() const {return id; } + quint32 BadId() const; /** * @brief BadKey return bad key * @return key */ - inline QString BadKey() const {return key; } + QString BadKey() const; protected: /** * @brief id id */ - qint64 id; + quint32 id; /** * @brief key key */ QString key; }; +inline quint32 VExceptionBadId::BadId() const +{ + return id; +} + +inline QString VExceptionBadId::BadKey() const +{ + return key; +} + #endif // VEXCEPTIONBADID_H diff --git a/src/exception/vexceptionconversionerror.cpp b/src/exception/vexceptionconversionerror.cpp index cfc0634c5..bc216ba43 100644 --- a/src/exception/vexceptionconversionerror.cpp +++ b/src/exception/vexceptionconversionerror.cpp @@ -34,6 +34,12 @@ VExceptionConversionError::VExceptionConversionError(const QString &what, const Q_ASSERT_X(str.isEmpty() == false, Q_FUNC_INFO, "Error converting string is empty"); } +VExceptionConversionError::VExceptionConversionError(const VExceptionConversionError &e) + :VException(e), str(e.String()) +{ + +} + QString VExceptionConversionError::ErrorMessage() const { QString error = QString("ExceptionConversionError: %1 %2").arg(what, str); diff --git a/src/exception/vexceptionconversionerror.h b/src/exception/vexceptionconversionerror.h index 9f725b28f..fbf5d4ac2 100644 --- a/src/exception/vexceptionconversionerror.h +++ b/src/exception/vexceptionconversionerror.h @@ -47,8 +47,7 @@ public: * @brief VExceptionConversionError copy constructor * @param e exception */ - VExceptionConversionError(const VExceptionConversionError &e) - :VException(e), str(e.String()){} + VExceptionConversionError(const VExceptionConversionError &e); virtual ~VExceptionConversionError() noexcept (true) {} /** * @brief ErrorMessage return main error message @@ -59,7 +58,7 @@ public: * @brief String return string, where happend error * @return string */ - inline QString String() const {return str;} + QString String() const; protected: /** * @brief str string, where happend error @@ -67,4 +66,9 @@ protected: QString str; }; +inline QString VExceptionConversionError::String() const +{ + return str; +} + #endif // VEXCEPTIONCONVERSIONERROR_H diff --git a/src/exception/vexceptionemptyparameter.cpp b/src/exception/vexceptionemptyparameter.cpp index c3fdf6b7a..ed767abc9 100644 --- a/src/exception/vexceptionemptyparameter.cpp +++ b/src/exception/vexceptionemptyparameter.cpp @@ -42,6 +42,12 @@ VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QS lineNumber = domElement.lineNumber(); } +VExceptionEmptyParameter::VExceptionEmptyParameter(const VExceptionEmptyParameter &e) + :VException(e), name(e.Name()), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()) +{ + +} + QString VExceptionEmptyParameter::ErrorMessage() const { QString error = QString("ExceptionEmptyParameter: %1 %2").arg(what, name); @@ -50,6 +56,5 @@ QString VExceptionEmptyParameter::ErrorMessage() const QString VExceptionEmptyParameter::DetailedInformation() const { - QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText); - return detail; + return MoreInfo(QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText)); } diff --git a/src/exception/vexceptionemptyparameter.h b/src/exception/vexceptionemptyparameter.h index b514683a9..8f9f5525a 100644 --- a/src/exception/vexceptionemptyparameter.h +++ b/src/exception/vexceptionemptyparameter.h @@ -50,9 +50,7 @@ public: * @brief VExceptionEmptyParameter copy constructor * @param e exception */ - VExceptionEmptyParameter(const VExceptionEmptyParameter &e) - :VException(e), name(e.Name()), tagText(e.TagText()), tagName(e.TagName()), - lineNumber(e.LineNumber()){} + VExceptionEmptyParameter(const VExceptionEmptyParameter &e); virtual ~VExceptionEmptyParameter() noexcept (true) {} /** * @brief ErrorMessage return main error message @@ -68,22 +66,22 @@ public: * @brief Name return name of attribute where error * @return name */ - inline QString Name() const {return name;} + QString Name() const; /** * @brief TagText return tag text * @return tag text */ - inline QString TagText() const {return tagText;} + QString TagText() const; /** * @brief TagName return tag name * @return tag name */ - inline QString TagName() const {return tagName;} + QString TagName() const; /** * @brief LineNumber return line number of tag * @return line number */ - inline qint32 LineNumber() const {return lineNumber;} + qint32 LineNumber() const; protected: /** * @brief name name attribute @@ -103,4 +101,24 @@ protected: qint32 lineNumber; }; +inline QString VExceptionEmptyParameter::Name() const +{ + return name; +} + +inline QString VExceptionEmptyParameter::TagText() const +{ + return tagText; +} + +inline QString VExceptionEmptyParameter::TagName() const +{ + return tagName; +} + +inline qint32 VExceptionEmptyParameter::LineNumber() const +{ + return lineNumber; +} + #endif // VEXCEPTIONEMPTYPARAMETER_H diff --git a/src/exception/vexceptionobjecterror.cpp b/src/exception/vexceptionobjecterror.cpp index 7b77be4a3..4273a745b 100644 --- a/src/exception/vexceptionobjecterror.cpp +++ b/src/exception/vexceptionobjecterror.cpp @@ -30,7 +30,7 @@ #include VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement) - :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()) + :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1) { Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QTextStream stream(&tagText); @@ -39,6 +39,12 @@ VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElem lineNumber = domElement.lineNumber(); } +VExceptionObjectError::VExceptionObjectError(const VExceptionObjectError &e) + :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()) +{ + +} + QString VExceptionObjectError::ErrorMessage() const { QString error = QString("ExceptionObjectError: %1").arg(what); @@ -47,24 +53,5 @@ QString VExceptionObjectError::ErrorMessage() const QString VExceptionObjectError::DetailedInformation() const { - QString detail; - if (moreInfo.isEmpty() == false) - { - QString i = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText); - detail = QString("%1\n%2").arg(moreInfo, i); - } - else - { - detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText); - } - return detail; -} - -void VExceptionObjectError::AddMoreInformation(const QString &info) -{ - if (info.isEmpty()) - { - qWarning()<<"Error additional information is empty."<moreInfo.append(info); + return MoreInfo(QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText)); } diff --git a/src/exception/vexceptionobjecterror.h b/src/exception/vexceptionobjecterror.h index 71e90329b..864a78e13 100644 --- a/src/exception/vexceptionobjecterror.h +++ b/src/exception/vexceptionobjecterror.h @@ -39,20 +39,18 @@ class VExceptionObjectError : public VException { public: - /** - * @brief VExceptionObjectError exception object error - * @param what string with error - * @param domElement dom element - */ - VExceptionObjectError(const QString &what, const QDomElement &domElement); - /** - * @brief VExceptionObjectError copy constructor - * @param e exception - */ - VExceptionObjectError(const VExceptionObjectError &e) - :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()), - moreInfo(e.MoreInformation()){} - virtual ~VExceptionObjectError() noexcept (true) {} + /** + * @brief VExceptionObjectError exception object error + * @param what string with error + * @param domElement dom element + */ + VExceptionObjectError(const QString &what, const QDomElement &domElement); + /** + * @brief VExceptionObjectError copy constructor + * @param e exception + */ + VExceptionObjectError(const VExceptionObjectError &e); + virtual ~VExceptionObjectError() noexcept (true) {} /** * @brief ErrorMessage return main error message * @return main error message @@ -67,27 +65,17 @@ public: * @brief TagText return tag text * @return tag text */ - inline QString TagText() const {return tagText;} + QString TagText() const; /** * @brief TagName return tag name * @return tag name */ - inline QString TagName() const {return tagName;} + QString TagName() const; /** * @brief LineNumber return line number in file * @return line number */ - inline qint32 LineNumber() const {return lineNumber;} - /** - * @brief AddMoreInformation add more information for error - * @param info information - */ - void AddMoreInformation(const QString &info); - /** - * @brief MoreInformation return more information for error - * @return information - */ - inline QString MoreInformation() const {return moreInfo;} + qint32 LineNumber() const; protected: /** * @brief tagText tag text @@ -101,10 +89,21 @@ protected: * @brief lineNumber line number */ qint32 lineNumber; - /** - * @brief moreInfo more information about error - */ - QString moreInfo; }; +inline QString VExceptionObjectError::TagText() const +{ + return tagText; +} + +inline QString VExceptionObjectError::TagName() const +{ + return tagName; +} + +inline qint32 VExceptionObjectError::LineNumber() const +{ + return lineNumber; +} + #endif // VEXCEPTIONOBJECTERROR_H diff --git a/src/exception/vexceptionwrongparameterid.cpp b/src/exception/vexceptionwrongid.cpp similarity index 73% rename from src/exception/vexceptionwrongparameterid.cpp rename to src/exception/vexceptionwrongid.cpp index 14f5ab8ef..76471d0c7 100644 --- a/src/exception/vexceptionwrongparameterid.cpp +++ b/src/exception/vexceptionwrongid.cpp @@ -26,10 +26,10 @@ ** *************************************************************************/ -#include "vexceptionwrongparameterid.h" +#include "vexceptionwrongid.h" #include -VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement) +VExceptionWrongId::VExceptionWrongId(const QString &what, const QDomElement &domElement) :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1) { Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); @@ -39,14 +39,19 @@ VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, cons lineNumber = domElement.lineNumber(); } -QString VExceptionWrongParameterId::ErrorMessage() const +VExceptionWrongId::VExceptionWrongId(const VExceptionWrongId &e) + :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()) { - QString error = QString("ExceptionWrongParameterId: %1").arg(what); + +} + +QString VExceptionWrongId::ErrorMessage() const +{ + QString error = QString("ExceptionWrongId: %1").arg(what); return error; } -QString VExceptionWrongParameterId::DetailedInformation() const +QString VExceptionWrongId::DetailedInformation() const { - QString detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText); - return detail; + return MoreInfo(QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText)); } diff --git a/src/exception/vexceptionuniqueid.h b/src/exception/vexceptionwrongid.h similarity index 65% rename from src/exception/vexceptionuniqueid.h rename to src/exception/vexceptionwrongid.h index 7e8abd569..22be31c60 100644 --- a/src/exception/vexceptionuniqueid.h +++ b/src/exception/vexceptionwrongid.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vexceptionuniqueid.h + ** @file vexceptionwrongparameterid.h ** @author Roman Telezhinsky ** @date November 15, 2013 ** @@ -26,32 +26,31 @@ ** *************************************************************************/ -#ifndef VEXCEPTIONUNIQUEID_H -#define VEXCEPTIONUNIQUEID_H +#ifndef VEXCEPTIONWRONGID_H +#define VEXCEPTIONWRONGID_H #include "vexception.h" #include /** - * @brief The VExceptionUniqueId class for exception unique id + * @brief The VExceptionWrongId class for exception wrong id */ -class VExceptionUniqueId : public VException +class VExceptionWrongId : public VException { public: - /** - * @brief VExceptionUniqueId exception unique id - * @param what string with error - * @param domElement dom element - */ - VExceptionUniqueId(const QString &what, const QDomElement &domElement); - /** - * @brief VExceptionUniqueId copy constructor - * @param e exception - */ - VExceptionUniqueId(const VExceptionUniqueId &e) - :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){} - virtual ~VExceptionUniqueId() noexcept (true){} + /** + * @brief VExceptionWrongId exception wrong parameter id + * @param what string with error + * @param domElement som element + */ + VExceptionWrongId(const QString &what, const QDomElement &domElement); + /** + * @brief VExceptionWrongId copy constructor + * @param e exception + */ + VExceptionWrongId(const VExceptionWrongId &e); + virtual ~VExceptionWrongId() noexcept (true){} /** * @brief ErrorMessage return main error message * @return main error message @@ -66,17 +65,17 @@ public: * @brief TagText return tag text * @return tag text */ - inline QString TagText() const {return tagText;} + QString TagText() const; /** * @brief TagName return tag name * @return tag name */ - inline QString TagName() const {return tagName;} + QString TagName() const; /** * @brief LineNumber return line number in file * @return line number */ - inline qint32 LineNumber() const {return lineNumber;} + qint32 LineNumber() const; protected: /** * @brief tagText tag text @@ -92,4 +91,19 @@ protected: qint32 lineNumber; }; -#endif // VEXCEPTIONUNIQUEID_H +inline QString VExceptionWrongId::TagText() const +{ + return tagText; +} + +inline QString VExceptionWrongId::TagName() const +{ + return tagName; +} + +inline qint32 VExceptionWrongId::LineNumber() const +{ + return lineNumber; +} + +#endif // VEXCEPTIONWRONGID_H diff --git a/src/exception/vexceptionwrongparameterid.h b/src/exception/vexceptionwrongparameterid.h deleted file mode 100644 index bc10495c8..000000000 --- a/src/exception/vexceptionwrongparameterid.h +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************************************ - ** - ** @file vexceptionwrongparameterid.h - ** @author Roman Telezhinsky - ** @date November 15, 2013 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#ifndef VEXCEPTIONWRONGPARAMETERID_H -#define VEXCEPTIONWRONGPARAMETERID_H - -#include "vexception.h" - -#include - -/** - * @brief The VExceptionWrongParameterId class for exception wrong parameter id - */ -class VExceptionWrongParameterId : public VException -{ -public: - /** - * @brief VExceptionWrongParameterId exception wrong parameter id - * @param what string with error - * @param domElement som element - */ - VExceptionWrongParameterId(const QString &what, const QDomElement &domElement); - /** - * @brief VExceptionWrongParameterId copy constructor - * @param e exception - */ - VExceptionWrongParameterId(const VExceptionWrongParameterId &e) - :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){} - virtual ~VExceptionWrongParameterId() noexcept (true){} - /** - * @brief ErrorMessage return main error message - * @return main error message - */ - virtual QString ErrorMessage() const; - /** - * @brief DetailedInformation return detailed information about error - * @return detailed information - */ - virtual QString DetailedInformation() const; - /** - * @brief TagText return tag text - * @return tag text - */ - inline QString TagText() const {return tagText;} - /** - * @brief TagName return tag name - * @return tag name - */ - inline QString TagName() const {return tagName;} - /** - * @brief LineNumber return line number in file - * @return line number - */ - inline qint32 LineNumber() const {return lineNumber;} -protected: - /** - * @brief tagText tag text - */ - QString tagText; - /** - * @brief tagName tag name - */ - QString tagName; - /** - * @brief lineNumber line number - */ - qint32 lineNumber; -}; - -#endif // VEXCEPTIONWRONGPARAMETERID_H diff --git a/src/geometry/varc.cpp b/src/geometry/varc.cpp index af91b0396..bf3813f1c 100644 --- a/src/geometry/varc.cpp +++ b/src/geometry/varc.cpp @@ -39,7 +39,7 @@ VArc::VArc () } VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, - QString formulaF2, qint64 idObject, Draw::Draws mode) + QString formulaF2, quint32 idObject, Valentina::Draws mode) : VGObject(GObject::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius), center(center) { @@ -102,7 +102,7 @@ QPainterPath VArc::GetPath() const } else { - qWarning()<<"points.count() < 2"< list = listNodePoint(); if (list.size() < 3) { - qWarning()<<"Not enough points."; + qDebug()<<"Not enough points."; return false; } ptrdiff_t i = indexOfNode(list, p1); @@ -147,11 +147,11 @@ bool VDetail::OnEdge(const qint64 &p1, const qint64 &p2) const } } -ptrdiff_t VDetail::Edge(const qint64 &p1, const qint64 &p2) const +ptrdiff_t VDetail::Edge(const quint32 &p1, const quint32 &p2) const { if (OnEdge(p1, p2) == false) { - qWarning()<<"Points don't on edge."; + qDebug()<<"Points don't on edge."; return -1; } @@ -171,16 +171,16 @@ ptrdiff_t VDetail::Edge(const qint64 &p1, const qint64 &p2) const } } -void VDetail::NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2) const +void VDetail::NodeOnEdge(const quint32 &index, VNodeDetail &p1, VNodeDetail &p2) const { QVector list = listNodePoint(); - if (index < 0 || index > list.size()) + if (index > static_cast(list.size())) { - qWarning()<<"Wrong edge index index ="< &nodes); - /** - * @brief VDetail copy constructor. - * @param detail detail. - */ - VDetail(const VDetail &detail); - /** - * @brief operator = assignment operator. - * @param detail detail. - * @return new detail. - */ - VDetail &operator=(const VDetail &detail); + /** + * @brief VDetail default contructor. Create empty detail. + */ + VDetail(); + /** + * @brief VDetail constructor. + * @param name detail name. + * @param nodes list of nodes. + */ + VDetail(const QString &name, const QVector &nodes); + /** + * @brief VDetail copy constructor. + * @param detail detail. + */ + VDetail(const VDetail &detail); + /** + * @brief operator = assignment operator. + * @param detail detail. + * @return new detail. + */ + VDetail &operator=(const VDetail &detail); /** * @brief append append in the end of list node. * @param node new node. */ - inline void append(const VNodeDetail &node) {nodes.append(node);} + void append(const VNodeDetail &node); /** * @brief Clear detail full clear. */ @@ -97,13 +97,13 @@ public: * @brief CountNode return count nodes. * @return count. */ - inline qint32 CountNode() const {return nodes.size();} + qint32 CountNode() const; /** * @brief Containes check if detail containe this id. * @param id object id. * @return true if containe. */ - bool Containes(const qint64 &id)const; + bool Containes(const quint32 &id)const; /** * @brief operator [] find node by index in list. * @param indx index node in list. @@ -120,88 +120,88 @@ public: * @brief getName return detail name. * @return name. */ - inline QString getName() const {return name;} + QString getName() const; /** * @brief setName set detail name. * @param value new name. */ - inline void setName(const QString &value) {name = value;} + void setName(const QString &value); /** * @brief getMx return bias for X axis. * @return x bias. */ - inline qreal getMx() const {return mx;} + qreal getMx() const; /** * @brief setMx set bias for X axis. * @param value new x bias. */ - inline void setMx(const qreal &value) {mx = value;} + void setMx(const qreal &value); /** * @brief getMy get bias for y axis. * @return y axis. */ - inline qreal getMy() const {return my;} + qreal getMy() const; /** * @brief setMy set bias for y axis. * @param value new y bias. */ - inline void setMy(const qreal &value) {my = value;} + void setMy(const qreal &value); /** * @brief getSeamAllowance keep status for seam allowance detail. * @return true - need seam allowance, false - no need seam allowance. */ - inline bool getSeamAllowance() const {return seamAllowance;} + bool getSeamAllowance() const; /** * @brief setSeamAllowance set status for seam allowance detail. * @param value true - need seam allowance, false - no need seam allowance. */ - inline void setSeamAllowance(bool value) {seamAllowance = value;} + void setSeamAllowance(bool value); /** * @brief getClosed keep close status for detail equdistant. * @return true - close equdistant, false - don't close equdistant. */ - inline bool getClosed() const {return closed;} + bool getClosed() const; /** * @brief setClosed set close status for detail equdistant. * @param value true - close equdistant, false - don't close equdistant. */ - inline void setClosed(bool value) {closed = value;} + void setClosed(bool value); /** * @brief getWidth return value detail seam allowance. * @return value in mm. */ - inline qreal getWidth() const {return width;} + qreal getWidth() const; /** * @brief setWidth set value detail seam allowance. * @param value width in mm. */ - inline void setWidth(const qreal &value) {width = value;} + void setWidth(const qreal &value); /** * @brief getNodes return list of nodes. * @return list of nodes. */ - inline QVector getNodes() const {return nodes;} + QVector getNodes() const; /** * @brief setNodes set list of nodes * @param value list of nodes */ - inline void setNodes(const QVector &value) {nodes = value;} + void setNodes(const QVector &value); /** * @brief indexOfNode return index in list node using id object. * @param id object (arc, point, spline, splinePath) id. * @return index in list or -1 id can't find. */ - ptrdiff_t indexOfNode(const qint64 &id) const; + ptrdiff_t indexOfNode(const quint32 &id) const; /** * @brief id return id detail in list data. * @return id. */ - qint64 id() const; + quint32 id() const; /** * @brief setId set id detail in list data. * @param id detail id. */ - void setId(const qint64 &id); + void setId(const quint32 &id); /** * @brief OnEdge checks if two poins located on the edge. Edge is line between two points. If between two points * located arcs or splines ignore this. @@ -209,7 +209,7 @@ public: * @param p2 id second point. * @return true - on edge, false - no. */ - bool OnEdge(const qint64 &p1, const qint64 &p2)const; + bool OnEdge(const quint32 &p1, const quint32 &p2)const; /** * @brief Edge return edge index in detail. Edge is line between two points. If between two points * located arcs or splines ignore this. @@ -217,32 +217,32 @@ public: * @param p2 id second point. * @return edge index or -1 if points don't located on edge */ - ptrdiff_t Edge(const qint64 &p1, const qint64 &p2)const; + ptrdiff_t Edge(const quint32 &p1, const quint32 &p2)const; /** * @brief NodeOnEdge return nodes located on edge with index. * @param index index of edge. * @param p1 first node. * @param p2 second node. */ - void NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2)const; + void NodeOnEdge(const quint32 &index, VNodeDetail &p1, VNodeDetail &p2)const; /** * @brief RemoveEdge return detail without edge with index. * @param index idex of edge. * @return */ - VDetail RemoveEdge(const ptrdiff_t &index) const; + VDetail RemoveEdge(const quint32 &index) const; /** * @brief Missing find missing ids in detail. When we deleted object in detail and return this detail need * understand, what nodes need make invisible. * @param det changed detail. * @return list with missing detail. */ - QList Missing(const VDetail &det) const; + QList Missing(const VDetail &det) const; private: /** * @brief _id id detail. */ - qint64 _id; + quint32 _id; /** * @brief nodes list detail nodes. */ @@ -282,7 +282,87 @@ private: * @param id object (arc, point, spline, splinePath) id. * @return index in list or -1 id can't find. */ - static ptrdiff_t indexOfNode(const QVector &list, const qint64 &id); + static ptrdiff_t indexOfNode(const QVector &list, const quint32 &id); }; +inline void VDetail::append(const VNodeDetail &node) +{ + nodes.append(node); +} + +inline qint32 VDetail::CountNode() const +{ + return nodes.size(); +} + +inline QString VDetail::getName() const +{ + return name; +} + +inline void VDetail::setName(const QString &value) +{ + name = value; +} + +inline qreal VDetail::getMx() const +{ + return mx; +} + +inline void VDetail::setMx(const qreal &value) +{ + mx = value; +} + +inline qreal VDetail::getMy() const +{ + return my; +} + +inline void VDetail::setMy(const qreal &value) +{ + my = value; +} + +inline bool VDetail::getSeamAllowance() const +{ + return seamAllowance; +} + +inline void VDetail::setSeamAllowance(bool value) +{ + seamAllowance = value; +} + +inline bool VDetail::getClosed() const +{ + return closed; +} + +inline void VDetail::setClosed(bool value) +{ + closed = value; +} + +inline qreal VDetail::getWidth() const +{ + return width; +} + +inline void VDetail::setWidth(const qreal &value) +{ + width = value; +} + +inline QVector VDetail::getNodes() const +{ + return nodes; +} + +inline void VDetail::setNodes(const QVector &value) +{ + nodes = value; +} + #endif // VDETAIL_H diff --git a/src/geometry/vequidistant.cpp b/src/geometry/vequidistant.cpp index a0c7048e5..7550e31e0 100644 --- a/src/geometry/vequidistant.cpp +++ b/src/geometry/vequidistant.cpp @@ -27,8 +27,9 @@ *************************************************************************/ #include "vequidistant.h" +#include "../widgets/vapplication.h" -QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer *data) const +QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer *data) const { Q_CHECK_PTR(data); VDetail detail = data->GetDetail(idDetail); @@ -38,7 +39,7 @@ QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer { switch (detail.at(i).getTypeTool()) { - case (Tool::NodePoint): + case (Valentina::NodePoint): { const VPointF *point = data->GeometricObject(detail.at(i).getId()); points.append(point->toQPointF()); @@ -51,7 +52,7 @@ QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer } } break; - case (Tool::NodeArc): + case (Valentina::NodeArc): { const VArc *arc = data->GeometricObject(detail.at(i).getId()); qreal len1 = GetLengthContour(points, arc->GetPoints()); @@ -75,7 +76,7 @@ QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer } } break; - case (Tool::NodeSpline): + case (Valentina::NodeSpline): { const VSpline *spline = data->GeometricObject(detail.at(i).getId()); qreal len1 = GetLengthContour(points, spline->GetPoints()); @@ -99,7 +100,7 @@ QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer } } break; - case (Tool::NodeSplinePath): + case (Valentina::NodeSplinePath): { const VSplinePath *splinePath = data->GeometricObject(detail.at(i).getId()); qreal len1 = GetLengthContour(points, splinePath->GetPathPoints()); @@ -124,7 +125,7 @@ QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer } break; default: - qWarning()<<"Get wrong tool type. Ignore."<toPixel(detail.getWidth())); } else { - ekv = Equidistant(pointsEkv, Detail::OpenEquidistant, toPixel(detail.getWidth())); + ekv = Equidistant(pointsEkv, Detail::OpenEquidistant, qApp->toPixel(detail.getWidth())); } path.addPath(ekv); path.setFillRule(Qt::WindingFill); @@ -157,7 +158,7 @@ QPainterPath VEquidistant::ContourPath(const qint64 &idDetail, const VContainer return path; } -qreal VEquidistant::GetLengthContour(const QVector &contour, const QVector &newPoints) const +qreal VEquidistant::GetLengthContour(const QVector &contour, const QVector &newPoints) { qreal length = 0; QVector points; @@ -170,7 +171,7 @@ qreal VEquidistant::GetLengthContour(const QVector &contour, const QVec return length; } -QVector VEquidistant::biasPoints(const QVector &points, const qreal &mx, const qreal &my) const +QVector VEquidistant::biasPoints(const QVector &points, const qreal &mx, const qreal &my) { QVector p; for (qint32 i = 0; i < points.size(); ++i) @@ -183,12 +184,12 @@ QVector VEquidistant::biasPoints(const QVector &points, const return p; } -QVector VEquidistant::CorrectEquidistantPoints(const QVector &points) const +QVector VEquidistant::CorrectEquidistantPoints(const QVector &points) { QVector correctPoints; if (points.size()<4)//Better don't check if only three points. We can destroy equidistant. { - qWarning()<<"Only three points."; + qDebug()<<"Only three points."; return points; } //Clear equivalent points @@ -229,7 +230,7 @@ QVector VEquidistant::CorrectEquidistantPoints(const QVector & } QPainterPath VEquidistant::Equidistant(QVector points, const Detail::Equidistant &eqv, - const qreal &width) const + const qreal &width) { QPainterPath ekv; QVector ekvPoints; @@ -295,7 +296,7 @@ QPainterPath VEquidistant::Equidistant(QVector points, const Detail::Eq return ekv; } -QVector VEquidistant::CheckLoops(const QVector &points) const +QVector VEquidistant::CheckLoops(const QVector &points) { QVector ekvPoints; /*If we got less than 4 points no need seek loops.*/ @@ -353,7 +354,7 @@ QVector VEquidistant::CheckLoops(const QVector &points) const return ekvPoints; } -QVector VEquidistant::GetReversePoint(const QVector &points) const +QVector VEquidistant::GetReversePoint(const QVector &points) { Q_ASSERT(points.size() > 0); QVector reversePoints; @@ -364,13 +365,13 @@ QVector VEquidistant::GetReversePoint(const QVector &points) c return reversePoints; } -QVector VEquidistant::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width) const +QVector VEquidistant::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width) { Q_ASSERT(width > 0); QVector points; if (line1.p2() != line2.p2()) { - qWarning()<<"Last point of two lines must be equal."; + qDebug()<<"Last point of two lines must be equal."; } QPointF CrosPoint; QLineF bigLine1 = ParallelLine(line1, width ); @@ -385,7 +386,7 @@ QVector VEquidistant::EkvPoint(const QLineF &line1, const QLineF &line2 case (QLineF::UnboundedIntersection): { QLineF line( line1.p2(), CrosPoint ); - if (line.length() > width + toPixel(8)) + if (line.length() > width + qApp->toPixel(8)) { QLineF lineL = QLineF(bigLine1.p2(), CrosPoint); lineL.setLength(width); @@ -413,7 +414,7 @@ QVector VEquidistant::EkvPoint(const QLineF &line1, const QLineF &line2 return points; } -QLineF VEquidistant::ParallelLine(const QLineF &line, qreal width) const +QLineF VEquidistant::ParallelLine(const QLineF &line, qreal width) { Q_ASSERT(width > 0); QLineF paralel = QLineF (SingleParallelPoint(line, 90, width), SingleParallelPoint(QLineF(line.p2(), line.p1()), @@ -421,7 +422,7 @@ QLineF VEquidistant::ParallelLine(const QLineF &line, qreal width) const return paralel; } -QPointF VEquidistant::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width) const +QPointF VEquidistant::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width) { Q_ASSERT(width > 0); QLineF pLine = line; diff --git a/src/geometry/vequidistant.h b/src/geometry/vequidistant.h index a35ab3a83..13830858b 100644 --- a/src/geometry/vequidistant.h +++ b/src/geometry/vequidistant.h @@ -44,7 +44,7 @@ public: * @param data container with objects (points, arcs, splines). * @return return painter path of contour detail. */ - QPainterPath ContourPath(const qint64 &idDetail, const VContainer *data) const; + QPainterPath ContourPath(const quint32 &idDetail, const VContainer *data) const; private: /** * @brief GetLengthContour return length of contour. @@ -52,7 +52,7 @@ private: * @param newPoints point whos we try to add to contour. * @return length length of contour. */ - qreal GetLengthContour(const QVector &contour, const QVector &newPoints) const; + static qreal GetLengthContour(const QVector &contour, const QVector &newPoints); /** * @brief biasPoints bias point. * @param points vector of points. @@ -60,13 +60,13 @@ private: * @param my offset respect to y. * @return new vector biased points. */ - QVector biasPoints(const QVector &points, const qreal &mx, const qreal &my) const; + static QVector biasPoints(const QVector &points, const qreal &mx, const qreal &my); /** * @brief CorrectEquidistantPoints clear equivalent points and remove point on line from equdistant. * @param points list of points equdistant. * @return corrected list. */ - QVector CorrectEquidistantPoints(const QVector &points) const; + static QVector CorrectEquidistantPoints(const QVector &points); /** * @brief Equidistant create equidistant painter path for detail. * @param points vector of points. @@ -74,19 +74,19 @@ private: * @param width width of equidistant. * @return return painter path of equidistant. */ - QPainterPath Equidistant(QVector points, const Detail::Equidistant &eqv, const qreal &width) const; + static QPainterPath Equidistant(QVector points, const Detail::Equidistant &eqv, const qreal &width); /** * @brief CheckLoops seek and delete loops in equidistant. * @param points vector of points of equidistant. * @return vector of points of equidistant. */ - QVector CheckLoops(const QVector &points) const; + static QVector CheckLoops(const QVector &points); /** * @brief GetReversePoint return revers container of points. * @param points container with points. * @return reverced points. */ - QVector GetReversePoint(const QVector &points) const; + static QVector GetReversePoint(const QVector &points); /** * @brief EkvPoint return vector of points of equidistant two lines. Last point of two lines must be equal. * @param line1 first line. @@ -94,14 +94,14 @@ private: * @param width width of equidistant. * @return vector of points. */ - QVector EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width) const; + static QVector EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width); /** * @brief ParallelLine create parallel line. * @param line starting line. * @param width width to parallel line. * @return parallel line. */ - QLineF ParallelLine(const QLineF &line, qreal width ) const; + static QLineF ParallelLine(const QLineF &line, qreal width ); /** * @brief SingleParallelPoint return point of parallel line. * @param line starting line. @@ -109,7 +109,7 @@ private: * @param width width to parallel line. * @return point of parallel line. */ - QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width) const; + static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width); }; #endif // VEQUIDISTANT_H diff --git a/src/geometry/vgobject.cpp b/src/geometry/vgobject.cpp index 94d025598..cd051d540 100644 --- a/src/geometry/vgobject.cpp +++ b/src/geometry/vgobject.cpp @@ -29,11 +29,11 @@ #include "vgobject.h" VGObject::VGObject() - :_id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Draw::Calculation) + :_id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Valentina::Calculation) { } -VGObject::VGObject(const GObject::Type &type, const qint64 &idObject, const Draw::Draws &mode) +VGObject::VGObject(const GObject::Type &type, const quint32 &idObject, const Valentina::Draws &mode) :_id(0), type(type), idObject(idObject), _name(QString()), mode(mode) { } @@ -53,12 +53,12 @@ VGObject &VGObject::operator=(const VGObject &obj) return *this; } -qint64 VGObject::getIdObject() const +quint32 VGObject::getIdObject() const { return idObject; } -void VGObject::setIdObject(const qint64 &value) +void VGObject::setIdObject(const quint32 &value) { idObject = value; } @@ -73,12 +73,12 @@ void VGObject::setName(const QString &name) _name = name; } -Draw::Draws VGObject::getMode() const +Valentina::Draws VGObject::getMode() const { return mode; } -void VGObject::setMode(const Draw::Draws &value) +void VGObject::setMode(const Valentina::Draws &value) { mode = value; } @@ -88,12 +88,12 @@ GObject::Type VGObject::getType() const return type; } -qint64 VGObject::id() const +quint32 VGObject::id() const { return _id; } -void VGObject::setId(const qint64 &id) +void VGObject::setId(const quint32 &id) { _id = id; } diff --git a/src/geometry/vgobject.h b/src/geometry/vgobject.h index 917cef7a9..773e6ce2e 100644 --- a/src/geometry/vgobject.h +++ b/src/geometry/vgobject.h @@ -61,7 +61,8 @@ public: * @param idObject id parent object. * @param mode mode creation. Used in modeling mode. */ - VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation); + VGObject(const GObject::Type &type, const quint32 &idObject = 0, + const Valentina::Draws &mode = Valentina::Calculation); /** * @brief VGObject copy constructor. * @param obj object. @@ -78,12 +79,12 @@ public: * @brief getIdObject return parent id. * @return parent id or 0 if object don't have parent. */ - qint64 getIdObject() const; + quint32 getIdObject() const; /** * @brief setIdObject set parent id. * @param value parent id. */ - void setIdObject(const qint64 &value); + void setIdObject(const quint32 &value); /** * @brief name return name graphical object. * @return name @@ -98,12 +99,12 @@ public: * @brief getMode return mode creation. * @return mode. */ - Draw::Draws getMode() const; + Valentina::Draws getMode() const; /** * @brief setMode set mode creation. * @param value mode. */ - void setMode(const Draw::Draws &value); + void setMode(const Valentina::Draws &value); /** * @brief getType return object type. * @return type. @@ -113,17 +114,17 @@ public: * @brief id return id object. * @return id */ - qint64 id() const; + quint32 id() const; /** * @brief setId set id object. * @param id id. */ - virtual void setId(const qint64 &id); + virtual void setId(const quint32 &id); protected: /** * @brief _id id in container. Ned for arcs, spline and spline paths. */ - qint64 _id; + quint32 _id; /** * @brief type type of graphical object */ @@ -131,7 +132,7 @@ protected: /** * @brief idObject id of parent object. Only for modeling. All another return 0. */ - qint64 idObject; + quint32 idObject; /** * @brief _name object name */ @@ -139,7 +140,7 @@ protected: /** * @brief mode object created in calculation or drawing mode */ - Draw::Draws mode; + Valentina::Draws mode; }; #endif // VGOBJECT_H diff --git a/src/geometry/vnodedetail.cpp b/src/geometry/vnodedetail.cpp index 45bc99e92..ca8183fad 100644 --- a/src/geometry/vnodedetail.cpp +++ b/src/geometry/vnodedetail.cpp @@ -29,9 +29,9 @@ #include "vnodedetail.h" VNodeDetail::VNodeDetail() - :id(0), typeTool(Tool::NodePoint), typeNode(NodeDetail::Contour), mx(0), my(0){} + :id(0), typeTool(Valentina::NodePoint), typeNode(NodeDetail::Contour), mx(0), my(0){} -VNodeDetail::VNodeDetail(qint64 id, Tool::Tools typeTool, NodeDetail::NodeDetails typeNode, qreal mx, qreal my) +VNodeDetail::VNodeDetail(quint32 id, Valentina::Tools typeTool, NodeDetail::NodeDetails typeNode, qreal mx, qreal my) :id(id), typeTool(typeTool), typeNode(typeNode), mx(mx), my(my){} VNodeDetail::VNodeDetail(const VNodeDetail &node) diff --git a/src/geometry/vnodedetail.h b/src/geometry/vnodedetail.h index 3acff0c40..2a16dac7d 100644 --- a/src/geometry/vnodedetail.h +++ b/src/geometry/vnodedetail.h @@ -48,90 +48,90 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(NodeDetail::NodeDetails) class VNodeDetail { public: - /** - * @brief VNodeDetail default constructor. - */ - VNodeDetail(); - /** - * @brief VNodeDetail constructor. - * @param id object id - * @param typeTool type tool - * @param typeNode type node - * @param mx object bias x axis - * @param my object bias y axis - */ - VNodeDetail(qint64 id, Tool::Tools typeTool, NodeDetail::NodeDetails typeNode, qreal mx = 0, - qreal my = 0); - /** - * @brief VNodeDetail copy constructor - * @param node node - */ - VNodeDetail(const VNodeDetail &node); - /** - * @brief operator = assignment operator - * @param node node - * @return node - */ - VNodeDetail &operator=(const VNodeDetail &node); + /** + * @brief VNodeDetail default constructor. + */ + VNodeDetail(); + /** + * @brief VNodeDetail constructor. + * @param id object id + * @param typeTool type tool + * @param typeNode type node + * @param mx object bias x axis + * @param my object bias y axis + */ + VNodeDetail(quint32 id, Valentina::Tools typeTool, NodeDetail::NodeDetails typeNode, qreal mx = 0, + qreal my = 0); + /** + * @brief VNodeDetail copy constructor + * @param node node + */ + VNodeDetail(const VNodeDetail &node); + /** + * @brief operator = assignment operator + * @param node node + * @return node + */ + VNodeDetail &operator=(const VNodeDetail &node); /** * @brief getId return object id. * @return id. */ - inline qint64 getId() const {return id;} + quint32 getId() const; /** * @brief setId set object id. * @param value object id. */ - inline void setId(const qint64 &value) {id = value;} + void setId(const quint32 &value); /** * @brief getTypeTool return tool type. * @return tool type. */ - inline Tool::Tools getTypeTool() const {return typeTool;} + Valentina::Tools getTypeTool() const; /** * @brief setTypeTool set tool type. * @param value tool type. */ - inline void setTypeTool(const Tool::Tools &value) {typeTool = value;} + void setTypeTool(const Valentina::Tools &value); /** * @brief getTypeNode return node type. * @return node type. */ - inline NodeDetail::NodeDetails getTypeNode() const {return typeNode;} + NodeDetail::NodeDetails getTypeNode() const; /** * @brief setTypeNode set node type. * @param value node type. */ - inline void setTypeNode(const NodeDetail::NodeDetails &value) {typeNode = value;} + void setTypeNode(const NodeDetail::NodeDetails &value); /** * @brief getMx return object bias x axis. * @return bias x axis. */ - inline qreal getMx() const {return mx;} + qreal getMx() const; /** * @brief setMx set object bias x axis. * @param value bias x axis. */ - inline void setMx(const qreal &value) {mx = value;} + void setMx(const qreal &value); /** * @brief getMy return object bias y axis. * @return bias y axis. */ - inline qreal getMy() const {return my;} + qreal getMy() const; /** * @brief setMy set object bias y axis. * @param value bias y axis. */ - inline void setMy(const qreal &value) {my = value;} + void setMy(const qreal &value); private: /** * @brief id object id. */ - qint64 id; + quint32 id; /** * @brief typeTool type of tool */ - Tool::Tools typeTool; + Valentina::Tools typeTool; /** * @brief typeNode node type. */ @@ -139,13 +139,63 @@ private: /** * @brief mx bias x axis. */ - qreal mx; + qreal mx; /** * @brief my bias y axis. */ - qreal my; + qreal my; }; +inline quint32 VNodeDetail::getId() const +{ + return id; +} + +inline void VNodeDetail::setId(const quint32 &value) +{ + id = value; +} + +inline Valentina::Tools VNodeDetail::getTypeTool() const +{ + return typeTool; +} + +inline void VNodeDetail::setTypeTool(const Valentina::Tools &value) +{ + typeTool = value; +} + +inline NodeDetail::NodeDetails VNodeDetail::getTypeNode() const +{ + return typeNode; +} + +inline void VNodeDetail::setTypeNode(const NodeDetail::NodeDetails &value) +{ + typeNode = value; +} + +inline qreal VNodeDetail::getMx() const +{ + return mx; +} + +inline void VNodeDetail::setMx(const qreal &value) +{ + mx = value; +} + +inline qreal VNodeDetail::getMy() const +{ + return my; +} + +inline void VNodeDetail::setMy(const qreal &value) +{ + my = value; +} + Q_DECLARE_METATYPE(VNodeDetail) #endif // VNODEDETAIL_H diff --git a/src/geometry/vpointf.cpp b/src/geometry/vpointf.cpp index 33783552f..97646ca9c 100644 --- a/src/geometry/vpointf.cpp +++ b/src/geometry/vpointf.cpp @@ -28,12 +28,27 @@ #include "vpointf.h" -VPointF::VPointF(qreal x, qreal y, QString name, qreal mx, qreal my, qint64 idObject, Draw::Draws mode) +VPointF::VPointF(qreal x, qreal y, QString name, qreal mx, qreal my, quint32 idObject, Valentina::Draws mode) :VGObject(GObject::Point, idObject, mode), _mx(mx), _my(my), _x(x), _y(y) { this->_name = name; } +VPointF::VPointF() :VGObject(GObject::Point, 0, Valentina::Calculation), _mx(0), _my(0), _x(0), _y(0) +{ + +} + +VPointF::VPointF(const VPointF &point) :VGObject(point), _mx(point.mx()), _my(point.my()), _x(point.x()), _y(point.y()) +{ + +} + +VPointF::VPointF(const QPointF &point) :VGObject(VPointF()), _mx(0), _my(0), _x(point.x()), _y(point.y()) +{ + +} + VPointF &VPointF::operator =(const VPointF &point) { VGObject::operator=(point); diff --git a/src/geometry/vpointf.h b/src/geometry/vpointf.h index 63da46ba7..a88c8c99e 100644 --- a/src/geometry/vpointf.h +++ b/src/geometry/vpointf.h @@ -43,16 +43,13 @@ public: /** * @brief VPointF creat empty point */ - inline VPointF () - :VGObject(GObject::Point, 0, Draw::Calculation), _mx(0), _my(0), _x(0), _y(0){} + VPointF (); /** * @brief VPointF copy constructor * @param point */ - inline VPointF (const VPointF &point ) - :VGObject(point), _mx(point.mx()), _my(point.my()), _x(point.x()), _y(point.y()){} - inline VPointF (const QPointF &point ) - :VGObject(VPointF()), _mx(0), _my(0), _x(point.x()), _y(point.y()){} + VPointF (const VPointF &point ); + VPointF (const QPointF &point ); /** * @brief VPointF create new point * @param x x coordinate @@ -60,61 +57,62 @@ public: * @param mx offset name respect to x * @param my offset name respect to y */ - VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my, qint64 idObject = 0, - Draw::Draws mode = Draw::Calculation); + VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my, quint32 idObject = 0, + Valentina::Draws mode = Valentina::Calculation); + ~VPointF(){} /** * @brief operator = assignment operator * @param point point * @return point */ - VPointF &operator=(const VPointF &point); - ~VPointF(){} + VPointF &operator=(const VPointF &point); + /** * @brief mx return offset name respect to x * @return offset */ - inline qreal mx() const {return _mx;} + qreal mx() const; /** * @brief my return offset name respect to y * @return offset */ - inline qreal my() const {return _my;} + qreal my() const; /** * @brief setMx set offset name respect to x * @param mx offset */ - inline void setMx(qreal mx) {_mx = mx;} + void setMx(qreal mx); /** * @brief setMy set offset name respect to y * @param my offset */ - inline void setMy(qreal my) {_my = my;} + void setMy(qreal my); /** * @brief toQPointF convert to QPointF * @return QPointF point */ - inline QPointF toQPointF()const {return QPointF(_x, _y);} + QPointF toQPointF()const; /** * @brief x return x coordinate * @return value */ - inline qreal x() const {return _x;} + qreal x() const; /** * @brief setX set x coordinate * @param value x coordinate */ - inline void setX(const qreal &value){_x = value;} + void setX(const qreal &value); /** * @brief y return y coordinate * @return value */ - inline qreal y() const {return _y;} + qreal y() const; /** * @brief setY set y coordinate * @param value y coordinate */ - inline void setY(const qreal &value){_y = value;} - virtual QString name() const{return _name;} + void setY(const qreal &value); + virtual QString name() const; private: /** * @brief _mx offset name respect to x @@ -134,4 +132,54 @@ private: qreal _y; }; +inline qreal VPointF::mx() const +{ + return _mx; +} + +inline qreal VPointF::my() const +{ + return _my; +} + +inline void VPointF::setMx(qreal mx) +{ + _mx = mx; +} + +inline void VPointF::setMy(qreal my) +{ + _my = my; +} + +inline QPointF VPointF::toQPointF() const +{ + return QPointF(_x, _y); +} + +inline qreal VPointF::x() const +{ + return _x; +} + +inline void VPointF::setX(const qreal &value) +{ + _x = value; +} + +inline qreal VPointF::y() const +{ + return _y; +} + +inline void VPointF::setY(const qreal &value) +{ + _y = value; +} + +inline QString VPointF::name() const +{ + return _name; +} + #endif // VPOINTF_H diff --git a/src/geometry/vspline.cpp b/src/geometry/vspline.cpp index ecde28308..a3457a45b 100644 --- a/src/geometry/vspline.cpp +++ b/src/geometry/vspline.cpp @@ -40,7 +40,7 @@ VSpline::VSpline ( const VSpline & spline ) kCurve(spline.GetKcurve()){} VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve, - qint64 idObject, Draw::Draws mode) + quint32 idObject, Valentina::Draws mode) :VGObject(GObject::Spline, idObject, mode), p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve) { @@ -67,7 +67,7 @@ VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm this->p3 = p4p3.p2(); } -VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, qint64 idObject, Draw::Draws mode) +VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject, Valentina::Draws mode) :VGObject(GObject::Spline, idObject, mode), p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1) { @@ -134,7 +134,7 @@ qreal VSpline::LengthT(qreal t) const { if (t < 0 || t > 1) { - qWarning()<<"Wrong value t."; + qDebug()<<"Wrong value t."; return 0; } QLineF seg1_2 ( GetP1 ().toQPointF(), GetP2 () ); @@ -282,36 +282,36 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, // Calculate all the mid-points of the line segments //---------------------- - double x12 = (x1 + x2) / 2; - double y12 = (y1 + y2) / 2; - double x23 = (x2 + x3) / 2; - double y23 = (y2 + y3) / 2; - double x34 = (x3 + x4) / 2; - double y34 = (y3 + y4) / 2; - double x123 = (x12 + x23) / 2; - double y123 = (y12 + y23) / 2; - double x234 = (x23 + x34) / 2; - double y234 = (y23 + y34) / 2; - double x1234 = (x123 + x234) / 2; - double y1234 = (y123 + y234) / 2; + const double x12 = (x1 + x2) / 2; + const double y12 = (y1 + y2) / 2; + const double x23 = (x2 + x3) / 2; + const double y23 = (y2 + y3) / 2; + const double x34 = (x3 + x4) / 2; + const double y34 = (y3 + y4) / 2; + const double x123 = (x12 + x23) / 2; + const double y123 = (y12 + y23) / 2; + const double x234 = (x23 + x34) / 2; + const double y234 = (y23 + y34) / 2; + const double x1234 = (x123 + x234) / 2; + const double y1234 = (y123 + y234) / 2; // Try to approximate the full cubic curve by a single straight line //------------------ - double dx = x4-x1; - double dy = y4-y1; + const double dx = x4-x1; + const double dy = y4-y1; double d2 = fabs((x2 - x4) * dy - (y2 - y4) * dx); double d3 = fabs((x3 - x4) * dy - (y3 - y4) * dx); - double da1, da2, k; switch ((static_cast(d2 > curve_collinearity_epsilon) << 1) + static_cast(d3 > curve_collinearity_epsilon)) { case 0: + { // All collinear OR p1==p4 //---------------------- - k = dx*dx + dy*dy; + double k = dx*dx + dy*dy; if (k < 0.000000001) { d2 = CalcSqDistance(x1, y1, x2, y2); @@ -320,12 +320,16 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, else { k = 1 / k; - da1 = x2 - x1; - da2 = y2 - y1; - d2 = k * (da1*dx + da2*dy); - da1 = x3 - x1; - da2 = y3 - y1; - d3 = k * (da1*dx + da2*dy); + { + const double da1 = x2 - x1; + const double da2 = y2 - y1; + d2 = k * (da1*dx + da2*dy); + } + { + const double da1 = x3 - x1; + const double da2 = y3 - y1; + d3 = k * (da1*dx + da2*dy); + } // cppcheck-suppress incorrectLogicOperator if (d2 > 0 && d2 < 1 && d3 > 0 && d3 < 1) { @@ -363,10 +367,8 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, { if (d2 < m_distance_tolerance_square) { - px.append(x2); py.append(y2); - //m_points.add(point_d(x2, y2)); return; } } @@ -374,31 +376,29 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, { if (d3 < m_distance_tolerance_square) { - px.append(x3); py.append(y3); - //m_points.add(point_d(x3, y3)); return; } } break; + } case 1: + { // p1,p2,p4 are collinear, p3 is significant //---------------------- if (d3 * d3 <= m_distance_tolerance_square * (dx*dx + dy*dy)) { if (m_angle_tolerance < curve_angle_tolerance_epsilon) { - px.append(x23); py.append(y23); - //m_points.add(point_d(x23, y23)); return; } // Angle Condition //---------------------- - da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2)); + double da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2)); if (da1 >= M_PI) { da1 = 2*M_PI - da1; @@ -406,14 +406,11 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, if (da1 < m_angle_tolerance) { - px.append(x2); py.append(y2); px.append(x3); py.append(y3); - //m_points.add(point_d(x2, y2)); - //m_points.add(point_d(x3, y3)); return; } @@ -421,33 +418,30 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, { if (da1 > m_cusp_limit) { - px.append(x3); py.append(y3); - //m_points.add(point_d(x3, y3)); return; } } } break; - + } case 2: + { // p1,p3,p4 are collinear, p2 is significant //---------------------- if (d2 * d2 <= m_distance_tolerance_square * (dx*dx + dy*dy)) { if (m_angle_tolerance < curve_angle_tolerance_epsilon) { - px.append(x23); py.append(y23); - //m_points.add(point_d(x23, y23)); return; } // Angle Condition //---------------------- - da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1)); + double da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1)); if (da1 >= M_PI) { da1 = 2*M_PI - da1; @@ -455,14 +449,11 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, if (da1 < m_angle_tolerance) { - px.append(x2); py.append(y2); px.append(x3); py.append(y3); - //m_points.add(point_d(x2, y2)); - //m_points.add(point_d(x3, y3)); return; } @@ -472,15 +463,14 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, { px.append(x2); py.append(y2); - - //m_points.add(point_d(x2, y2)); return; } } } break; - + } case 3: + { // Regular case //----------------- if ((d2 + d3)*(d2 + d3) <= m_distance_tolerance_square * (dx*dx + dy*dy)) @@ -490,18 +480,16 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, //---------------------- if (m_angle_tolerance < curve_angle_tolerance_epsilon) { - px.append(x23); py.append(y23); - //m_points.add(point_d(x23, y23)); return; } // Angle & Cusp Condition //---------------------- - k = atan2(y3 - y2, x3 - x2); - da1 = fabs(k - atan2(y2 - y1, x2 - x1)); - da2 = fabs(atan2(y4 - y3, x4 - x3) - k); + const double k = atan2(y3 - y2, x3 - x2); + double da1 = fabs(k - atan2(y2 - y1, x2 - x1)); + double da2 = fabs(atan2(y4 - y3, x4 - x3) - k); if (da1 >= M_PI) { da1 = 2*M_PI - da1; @@ -518,7 +506,6 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, px.append(x23); py.append(y23); - //m_points.add(point_d(x23, y23)); return; } @@ -540,6 +527,7 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, } } break; + } default: break; } @@ -576,7 +564,7 @@ QPainterPath VSpline::GetPath() const } else { - qWarning()<<"points.count() < 2"<()), kCurve(kCurve), maxCountPoints(0) { } diff --git a/src/geometry/vsplinepath.h b/src/geometry/vsplinepath.h index 890689abf..1b780f42a 100644 --- a/src/geometry/vsplinepath.h +++ b/src/geometry/vsplinepath.h @@ -53,18 +53,18 @@ class VSplinePath :public VGObject { Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: - /** - * @brief VSplinePath constructor. - * @param kCurve coefficient of curvature spline path. - * @param idObject parent id. - * @param mode mode creation spline path. - */ - VSplinePath(qreal kCurve = 1, qint64 idObject = 0, Draw::Draws mode = Draw::Calculation); - /** - * @brief VSplinePath copy constructor. - * @param splPath spline path. - */ - VSplinePath(const VSplinePath& splPath); + /** + * @brief VSplinePath constructor. + * @param kCurve coefficient of curvature spline path. + * @param idObject parent id. + * @param mode mode creation spline path. + */ + VSplinePath(qreal kCurve = 1, quint32 idObject = 0, Valentina::Draws mode = Valentina::Calculation); + /** + * @brief VSplinePath copy constructor. + * @param splPath spline path. + */ + VSplinePath(const VSplinePath& splPath); /** * @brief append add point in the end of list points. * @param point new point. @@ -79,7 +79,7 @@ public: * @brief CountPoint return count point. * @return count. */ - inline qint32 CountPoint() const {return path.size();} + qint32 CountPoint() const; /** * @brief GetSpline return spline by index. * @param index index spline in spline path. @@ -90,7 +90,7 @@ public: * @brief GetPath return QPainterPath which reprezent spline path. * @return path. */ - QPainterPath GetPath() const; + QPainterPath GetPath() const; /** * @brief GetPathPoints return list of points what located on path. * @return list. @@ -100,7 +100,7 @@ public: * @brief GetSplinePath return list with spline points. * @return list. */ - inline QVector GetSplinePath() const {return path;} + QVector GetSplinePath() const; /** * @brief GetLength return length of spline path. * @return length. @@ -123,22 +123,22 @@ public: /** * @brief Clear clear list of points. */ - inline void Clear() {path.clear();} + void Clear(); /** * @brief getKCurve return coefficient of curvature spline path. * @return coefficient of curvature spline. */ - inline qreal getKCurve() const {return kCurve;} + qreal getKCurve() const; /** * @brief setKCurve set coefficient of curvature spline path. * @param value coefficient of curvature spline path. */ - inline void setKCurve(const qreal &value) {kCurve = value;} + void setKCurve(const qreal &value); /** * @brief GetPoint pointer to list spline point. * @return list. */ - inline const QVector *GetPoint() const {return &path;} + const QVector *GetPoint() const; /** * @brief operator = assignment operator. * @param path spline path. @@ -212,4 +212,34 @@ protected: qint32 maxCountPoints; }; +inline qint32 VSplinePath::CountPoint() const +{ + return path.size(); +} + +inline QVector VSplinePath::GetSplinePath() const +{ + return path; +} + +inline void VSplinePath::Clear() +{ + path.clear(); +} + +inline qreal VSplinePath::getKCurve() const +{ + return kCurve; +} + +inline void VSplinePath::setKCurve(const qreal &value) +{ + kCurve = value; +} + +inline const QVector *VSplinePath::GetPoint() const +{ + return &path; +} + #endif // VSPLINEPATH_H diff --git a/src/geometry/vsplinepoint.cpp b/src/geometry/vsplinepoint.cpp index 469b0d1dc..ed1396541 100644 --- a/src/geometry/vsplinepoint.cpp +++ b/src/geometry/vsplinepoint.cpp @@ -36,7 +36,7 @@ VSplinePoint::VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAs { if (qFuzzyCompare(qAbs(angle1-angle2), 180) == false) { - qWarning()<<"angle1 and angle2 are not equal."; + qDebug()<<"angle1 and angle2 are not equal."; } SetAngle2(angle2); } diff --git a/src/geometry/vsplinepoint.h b/src/geometry/vsplinepoint.h index 30517c406..dbe57a5db 100644 --- a/src/geometry/vsplinepoint.h +++ b/src/geometry/vsplinepoint.h @@ -39,73 +39,73 @@ class VSplinePoint { public: - /** - * @brief VSplinePoint default constructor. - */ - VSplinePoint(); - /** - * @brief VSplinePoint constructor. - * @param pSpline spline point. - * @param angle second angle control line. - * @param factor coefficient of length second control line. - */ - VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); - /** - * @brief VSplinePoint copy constructor - * @param point point - */ - VSplinePoint(const VSplinePoint &point); - ~VSplinePoint() {} + /** + * @brief VSplinePoint default constructor. + */ + VSplinePoint(); + /** + * @brief VSplinePoint constructor. + * @param pSpline spline point. + * @param angle second angle control line. + * @param factor coefficient of length second control line. + */ + VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); + /** + * @brief VSplinePoint copy constructor + * @param point point + */ + VSplinePoint(const VSplinePoint &point); + ~VSplinePoint() {} /** * @brief P return point. * @return point. */ - inline VPointF P() const {return pSpline;} + VPointF P() const; /** * @brief SetP set point. * @param value point. */ - inline void SetP(const VPointF &value) {pSpline = value;} + void SetP(const VPointF &value); /** * @brief Angle1 return first angle of spline. * @return angle. */ - inline qreal Angle1() const {return angle1;} + qreal Angle1() const; /** * @brief SetAngle1 set first angle of spline. * @param value angle. */ - void SetAngle1(const qreal &value); + void SetAngle1(const qreal &value); /** * @brief SetAngle2 set second angle of spline. * @param value angle. */ - void SetAngle2(const qreal &value); + void SetAngle2(const qreal &value); /** * @brief Angle2 return second angle of spline. * @return angle. */ - inline qreal Angle2() const {return angle2;} + qreal Angle2() const; /** * @brief KAsm1 return coefficient of length first control line. * @return coefficient. */ - inline qreal KAsm1() const {return kAsm1;} + qreal KAsm1() const; /** * @brief SetKAsm1 set coefficient of length first control line. * @param value coefficient. */ - inline void SetKAsm1(const qreal &value) {kAsm1 = value;} + void SetKAsm1(const qreal &value); /** * @brief KAsm2 return coefficient of length second control line. * @return coefficient. */ - inline qreal KAsm2() const {return kAsm2;} + qreal KAsm2() const; /** * @brief SetKAsm2 set coefficient of length second control line. * @param value coefficient. */ - inline void SetKAsm2(const qreal &value) {kAsm2 = value;} + void SetKAsm2(const qreal &value); protected: /** * @brief pSpline point. @@ -129,6 +129,46 @@ protected: qreal kAsm2; }; +inline VPointF VSplinePoint::P() const +{ + return pSpline; +} + +inline void VSplinePoint::SetP(const VPointF &value) +{ + pSpline = value; +} + +inline qreal VSplinePoint::Angle1() const +{ + return angle1; +} + +inline qreal VSplinePoint::Angle2() const +{ + return angle2; +} + +inline qreal VSplinePoint::KAsm1() const +{ + return kAsm1; +} + +inline void VSplinePoint::SetKAsm1(const qreal &value) +{ + kAsm1 = value; +} + +inline qreal VSplinePoint::KAsm2() const +{ + return kAsm2; +} + +inline void VSplinePoint::SetKAsm2(const qreal &value) +{ + kAsm2 = value; +} + Q_DECLARE_METATYPE(VSplinePoint) #endif // VSPLINEPOINT_H diff --git a/src/main.cpp b/src/main.cpp index f64c4174b..de0214e9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,42 +30,87 @@ #include "widgets/vapplication.h" #include #include +#include +#include #include "tablewindow.h" -#include "options.h" -#ifdef Q_OS_WIN32 - const QString translationsPath = QString("/translations"); -#else - #ifdef QT_DEBUG - const QString translationsPath = QString("/translations"); - #else - const QString translationsPath = QString("/usr/share/valentina/translations"); - #endif -#endif - -void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { - QByteArray localMsg = msg.toLocal8Bit(); - switch (type) + // Why on earth didn't Qt want to make failed signal/slot connections qWarning? + if ((type == QtDebugMsg) && msg.contains("::connect")) { - case QtDebugMsg: - fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - break; - case QtWarningMsg: - fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - break; - case QtCriticalMsg: - fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - break; - case QtFatalMsg: - fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); + type = QtWarningMsg; + } + + // this is another one that doesn't make sense as just a debug message. pretty serious + // sign of a problem + // http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue) + if ((type == QtDebugMsg) && msg.contains("QPainter::begin") && msg.contains("Paint device returned engine")) + { + type = QtWarningMsg; + } + + // This qWarning about "Cowardly refusing to send clipboard message to hung application..." + // is something that can easily happen if you are debugging and the application is paused. + // As it is so common, not worth popping up a dialog. + if ((type == QtWarningMsg) && QString(msg).contains("QClipboard::event") + && QString(msg).contains("Cowardly refusing")) + { + type = QtDebugMsg; + } + + // only the GUI thread should display message boxes. If you are + // writing a multithreaded application and the error happens on + // a non-GUI thread, you'll have to queue the message to the GUI + QCoreApplication *instance = QCoreApplication::instance(); + const bool isGuiThread = instance && (QThread::currentThread() == instance->thread()); + + if (isGuiThread) + { + QByteArray localMsg = msg.toLocal8Bit(); + QMessageBox messageBox; + switch (type) { + case QtDebugMsg: + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + return; + case QtWarningMsg: + messageBox.setIcon(QMessageBox::Warning); + messageBox.setInformativeText(msg); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + break; + case QtCriticalMsg: + messageBox.setIcon(QMessageBox::Critical); + messageBox.setInformativeText(msg); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + break; + case QtFatalMsg: + messageBox.setIcon(QMessageBox::Critical); + messageBox.setInformativeText(msg); + messageBox.setStandardButtons(QMessageBox::Cancel); + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + break; + default: + break; + } + + const int ret = messageBox.exec(); + if (ret == QMessageBox::Cancel) + { abort(); - default: - break; + } + } + else + { + if (type != QtDebugMsg) + { + abort(); // be NOISY unless overridden! + } } } @@ -76,8 +121,15 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(schema); Q_INIT_RESOURCE(theme); - qInstallMessageHandler(myMessageOutput); VApplication app(argc, argv); +#ifdef QT_DEBUG + // Because our "noisy" message handler uses the GUI subsystem for message + // boxes, we can't install it until after the QApplication is constructed. But it + // is good to be the very next thing to run, to start catching warnings ASAP. + { + qInstallMessageHandler(noisyFailureMsgHandler); + } +#endif app.setApplicationDisplayName("Valentina"); app.setApplicationName("Valentina"); app.setOrganizationName("ValentinaTeam"); @@ -94,13 +146,13 @@ int main(int argc, char *argv[]) app.installTranslator(&qtTranslator); QTranslator appTranslator; -#ifdef Q_OS_WIN32 - appTranslator.load("valentina_" + checkedLocale, "."+translationsPath); +#ifdef Q_OS_WIN + appTranslator.load("valentina_" + checkedLocale, qApp->translationsPath()); #else #ifdef QT_DEBUG - appTranslator.load("valentina_" + checkedLocale, "."+translationsPath); + appTranslator.load("valentina_" + checkedLocale, qApp->translationsPath()); #else - appTranslator.load("valentina_" + checkedLocale, translationsPath); + appTranslator.load("valentina_" + checkedLocale, qApp->translationsPath()); #endif #endif app.installTranslator(&appTranslator); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4bdadaddb..82bf6651b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -33,9 +33,9 @@ #include "exception/vexceptionobjecterror.h" #include "exception/vexceptionconversionerror.h" #include "exception/vexceptionemptyparameter.h" -#include "exception/vexceptionwrongparameterid.h" -#include "exception/vexceptionuniqueid.h" +#include "exception/vexceptionwrongid.h" #include "version.h" +#include "xml/vstandardmeasurements.h" #include #include @@ -44,48 +44,20 @@ #include #include #include -#include -#include #include -#include - -//This class need for validation pattern file using XSD shema -class MessageHandler : public QAbstractMessageHandler -{ -public: - MessageHandler() : QAbstractMessageHandler(0), m_messageType(QtMsgType()), m_description(QString()), - m_sourceLocation(QSourceLocation()){} - inline QString statusMessage() const {return m_description;} - inline qint64 line() const {return m_sourceLocation.line();} - inline qint64 column() const {return m_sourceLocation.column();} -protected: - virtual void handleMessage(QtMsgType type, const QString &description, - const QUrl &identifier, const QSourceLocation &sourceLocation) - { - Q_UNUSED(type); - Q_UNUSED(identifier); - - m_messageType = type; - m_description = description; - m_sourceLocation = sourceLocation; - } -private: - QtMsgType m_messageType; - QString m_description; - QSourceLocation m_sourceLocation; -}; MainWindow::MainWindow(QWidget *parent) - :QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0), - sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0), - dialogTool(0), dialogHistory(0), comboBoxDraws(0), curFile(QString()), mode(Draw::Calculation), - currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{0,0,0,0,0}, separatorAct(0), - autoSaveTimer(0) + :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Valentina::ArrowTool), + currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), + view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), + comboBoxDraws(nullptr), curFile(QString()), mode(Valentina::Calculation), currentDrawIndex(0), + currentToolBoxIndex(0), drawMode(true), recentFileActs{0, 0, 0, 0, 0}, separatorAct(nullptr), + autoSaveTimer(nullptr) { CreateActions(); CreateMenus(); - ToolBarOption(); ToolBarDraws(); + InitToolButtons(); sceneDraw = new VMainGraphicsScene(); currentScene = sceneDraw; @@ -106,31 +78,10 @@ MainWindow::MainWindow(QWidget *parent) helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working.")); ui->statusBar->addWidget(helpLabel); - connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine); - connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); - connect(ui->toolButtonAlongLine, &QToolButton::clicked, this, &MainWindow::ToolAlongLine); - connect(ui->toolButtonShoulderPoint, &QToolButton::clicked, this, &MainWindow::ToolShoulderPoint); - connect(ui->toolButtonNormal, &QToolButton::clicked, this, &MainWindow::ToolNormal); - connect(ui->toolButtonBisector, &QToolButton::clicked, this, &MainWindow::ToolBisector); - connect(ui->toolButtonLineIntersect, &QToolButton::clicked, this, &MainWindow::ToolLineIntersect); - connect(ui->toolButtonSpline, &QToolButton::clicked, this, &MainWindow::ToolSpline); - connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc); - connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath); - connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact); - connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail); - connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); - connect(ui->toolButtonTriangle, &QToolButton::clicked, this, &MainWindow::ToolTriangle); - connect(ui->toolButtonPointOfIntersection, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersection); - connect(ui->toolButtonSplineCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSpline); - connect(ui->toolButtonSplinePathCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSplinePath); - connect(ui->toolButtonUnionDetails, &QToolButton::clicked, this, &MainWindow::ToolUnionDetails); - connect(ui->toolButtonArcCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutArc); - pattern = new VContainer(); - doc = new VDomDocument(pattern, comboBoxDraws, &mode); - doc->CreateEmptyFile(); - connect(doc, &VDomDocument::patternChanged, this, &MainWindow::PatternWasModified); + doc = new VPattern(pattern, comboBoxDraws, &mode); + connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); InitAutoSave(); @@ -143,61 +94,83 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::ActionNewDraw() { - QString nameDraw; - bool bOk; - qint32 index; - QString nDraw = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1); - QInputDialog *dlg = new QInputDialog(this); - dlg->setInputMode( QInputDialog::TextInput ); - dlg->setLabelText(tr("Pattern piece:")); - dlg->setTextEchoMode(QLineEdit::Normal); - dlg->setWindowTitle(tr("Enter a label for the pattern piece.")); - dlg->resize(300, 100); - dlg->setTextValue(nDraw); - while (1) + QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1); + if (comboBoxDraws->count() == 0) { - bOk = dlg->exec(); - nameDraw = dlg->textValue(); - if (bOk == false || nameDraw.isEmpty()) + QString path; + DialogMeasurements measurements(this); + measurements.exec(); + if (measurements.type() == Measurements::Standard) { - delete dlg; - return; - } - index = comboBoxDraws->findText(nameDraw); - if (index != -1) - {//we already have this name - qCritical()<setPatternType(Pattern::Standard); + DialogStandardMeasurements stMeasurements(pattern, patternPieceName, this); + if (stMeasurements.exec() == QDialog::Accepted) + { + patternPieceName = stMeasurements.name(); + path = stMeasurements.tablePath(); + VStandardMeasurements m(pattern); + m.setContent(path); + m.SetSize(); + m.SetHeight(); + m.Measurements(); + } + else + { + return; + } } else { - break; + qApp->setPatternType(Pattern::Individual); + DialogIndividualMeasurements indMeasurements(pattern, patternPieceName, this); + if (indMeasurements.exec() == QDialog::Accepted) + { + patternPieceName = indMeasurements.name(); + path = indMeasurements.tablePath(); + VIndividualMeasurements m(pattern); + m.setContent(path); + m.Measurements(); + } + else + { + return; + } + } + doc->CreateEmptyFile(path); + } + else + { + patternPieceName = PatternPieceName(patternPieceName); + if (patternPieceName.isEmpty()) + { + return; } } - delete dlg; - bOk = doc->appendDraw(nameDraw); - if (bOk == false) + if (doc->appendDraw(patternPieceName) == false) { - qCritical()<(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); - comboBoxDraws->addItem(nameDraw); + comboBoxDraws->addItem(patternPieceName); pattern->ClearGObjects(); //Create single point - qint64 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10)); - VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui); + const quint32 id = pattern->AddGObject(new VPointF(qApp->toPixel((10+comboBoxDraws->count()*5)), qApp->toPixel(10), "А", 5, + 10)); + VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Valentina::FromGui); sceneDraw->addItem(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); - QHash* tools = doc->getTools(); + QHash* tools = doc->getTools(); + Q_CHECK_PTR(tools); tools->insert(id, spoint); - VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); + VDrawTool::AddRecord(id, Valentina::SinglePointTool, doc); SetEnableTool(true); SetEnableWidgets(true); - index = comboBoxDraws->findText(nameDraw); + const qint32 index = comboBoxDraws->findText(patternPieceName); if ( index != -1 ) { // -1 for not found comboBoxDraws->setCurrentIndex(index); @@ -209,50 +182,24 @@ void MainWindow::ActionNewDraw() void MainWindow::OptionDraw() { - QString nameDraw; - qint32 index; - QString nDraw = doc->GetNameActivDraw(); - QInputDialog *dlg = new QInputDialog(this); - dlg->setInputMode( QInputDialog::TextInput ); - dlg->setLabelText(tr("Pattern piece:")); - dlg->setTextEchoMode(QLineEdit::Normal); - dlg->setWindowTitle(tr("Enter a new label for the pattern piece.")); - dlg->resize(300, 100); - dlg->setTextValue(nDraw); - while (1) + const QString activDraw = doc->GetNameActivDraw(); + const QString nameDraw = PatternPieceName(activDraw); + if (nameDraw.isEmpty()) { - bool bOk = dlg->exec(); - nameDraw = dlg->textValue(); - if (bOk == false || nameDraw.isEmpty()) - { - delete dlg; - return; - } - index = comboBoxDraws->findText(nameDraw); - if (index != -1) - {//we already have this name - qCritical()<findText(doc->GetNameActivDraw()); if (doc->SetNameDraw(nameDraw)) { - comboBoxDraws->setItemText(index, nameDraw); + comboBoxDraws->setItemText(comboBoxDraws->findText(activDraw), nameDraw); } else { QMessageBox::warning(this, tr("Error saving change!!!"), tr("Can't save new label of pattern piece")); } - } template -void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip, +void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot) { if (checked) @@ -264,11 +211,10 @@ void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &curso view->setCursor(cur); helpLabel->setText(toolTip); dialogTool = new Dialog(pattern, this); - Q_CHECK_PTR(dialogTool); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChoosedObject); connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); - connect(doc, &VDomDocument::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); + connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); } else { @@ -293,7 +239,7 @@ void MainWindow::ClosedDialog(int result) void MainWindow::ToolEndLine(bool checked) { - SetToolButton(checked, Tool::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogEndLine); } @@ -304,7 +250,7 @@ void MainWindow::ClosedDialogEndLine(int result) void MainWindow::ToolLine(bool checked) { - SetToolButton(checked, Tool::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), + SetToolButton(checked, Valentina::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), &MainWindow::ClosedDialogLine); } @@ -315,7 +261,7 @@ void MainWindow::ClosedDialogLine(int result) void MainWindow::ToolAlongLine(bool checked) { - SetToolButton(checked, Tool::AlongLineTool, ":/cursor/alongline_cursor.png", tr("Select point"), + SetToolButton(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogAlongLine); } @@ -326,7 +272,7 @@ void MainWindow::ClosedDialogAlongLine(int result) void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButton(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + SetToolButton(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint); } @@ -337,7 +283,7 @@ void MainWindow::ClosedDialogShoulderPoint(int result) void MainWindow::ToolNormal(bool checked) { - SetToolButton(checked, Tool::NormalTool, ":/cursor/normal_cursor.png", + SetToolButton(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogNormal); } @@ -348,7 +294,7 @@ void MainWindow::ClosedDialogNormal(int result) void MainWindow::ToolBisector(bool checked) { - SetToolButton(checked, Tool::BisectorTool, ":/cursor/bisector_cursor.png", + SetToolButton(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", tr("Select first point of angle"), &MainWindow::ClosedDialogBisector); } @@ -359,7 +305,7 @@ void MainWindow::ClosedDialogBisector(int result) void MainWindow::ToolLineIntersect(bool checked) { - SetToolButton(checked, Tool::LineIntersectTool, ":/cursor/intersect_cursor.png", + SetToolButton(checked, Valentina::LineIntersectTool, ":/cursor/intersect_cursor.png", tr("Select first point of first line"), &MainWindow::ClosedDialogLineIntersect); } @@ -370,7 +316,7 @@ void MainWindow::ClosedDialogLineIntersect(int result) void MainWindow::ToolSpline(bool checked) { - SetToolButton(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", + SetToolButton(checked, Valentina::SplineTool, ":/cursor/spline_cursor.png", tr("Select first point curve"), &MainWindow::ClosedDialogSpline); } @@ -381,7 +327,7 @@ void MainWindow::ClosedDialogSpline(int result) void MainWindow::ToolCutSpline(bool checked) { - SetToolButton(checked, Tool::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", + SetToolButton(checked, Valentina::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", tr("Select simple curve"), &MainWindow::ClosedDialogCutSpline); } @@ -392,7 +338,7 @@ void MainWindow::ClosedDialogCutSpline(int result) void MainWindow::ToolArc(bool checked) { - SetToolButton(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", + SetToolButton(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png", tr("Select point of center of arc"), &MainWindow::ClosedDialogArc); } @@ -403,7 +349,7 @@ void MainWindow::ClosedDialogArc(int result) void MainWindow::ToolSplinePath(bool checked) { - SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", + SetToolButton(checked, Valentina::SplinePathTool, ":/cursor/splinepath_cursor.png", tr("Select point of curve path"), &MainWindow::ClosedDialogSplinePath); } @@ -414,7 +360,7 @@ void MainWindow::ClosedDialogSplinePath(int result) void MainWindow::ToolCutSplinePath(bool checked) { - SetToolButton(checked, Tool::CutSplinePathTool, ":/cursor/splinepath_cut_point_cursor.png", + SetToolButton(checked, Valentina::CutSplinePathTool, ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), &MainWindow::ClosedDialogCutSplinePath); } @@ -425,7 +371,7 @@ void MainWindow::ClosedDialogCutSplinePath(int result) void MainWindow::ToolPointOfContact(bool checked) { - SetToolButton(checked, Tool::PointOfContact, ":/cursor/pointcontact_cursor.png", + SetToolButton(checked, Valentina::PointOfContact, ":/cursor/pointcontact_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogPointOfContact); } @@ -436,7 +382,7 @@ void MainWindow::ClosedDialogPointOfContact(int result) void MainWindow::ToolDetail(bool checked) { - SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", + SetToolButton(checked, Valentina::DetailTool, "://cursor/new_detail_cursor.png", tr("Select points, arcs, curves clockwise."), &MainWindow::ClosedDialogDetail); } @@ -452,7 +398,7 @@ void MainWindow::ClosedDialogDetail(int result) void MainWindow::ToolHeight(bool checked) { - SetToolButton(checked, Tool::Height, ":/cursor/height_cursor.png", tr("Select base point"), + SetToolButton(checked, Valentina::Height, ":/cursor/height_cursor.png", tr("Select base point"), &MainWindow::ClosedDialogHeight); } @@ -463,7 +409,7 @@ void MainWindow::ClosedDialogHeight(int result) void MainWindow::ToolTriangle(bool checked) { - SetToolButton(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", + SetToolButton(checked, Valentina::Triangle, ":/cursor/triangle_cursor.png", tr("Select first point of axis"), &MainWindow::ClosedDialogTriangle); } @@ -474,7 +420,7 @@ void MainWindow::ClosedDialogTriangle(int result) void MainWindow::ToolPointOfIntersection(bool checked) { - SetToolButton(checked, Tool::PointOfIntersection, ":/cursor/pointofintersect_cursor.png", + SetToolButton(checked, Valentina::PointOfIntersection, ":/cursor/pointofintersect_cursor.png", tr("Select point vertically"), &MainWindow::ClosedDialogPointOfIntersection); } @@ -485,10 +431,10 @@ void MainWindow::ClosedDialogPointOfIntersection(int result) void MainWindow::ToolUnionDetails(bool checked) { - SetToolButton(checked, Tool::UnionDetails, ":/cursor/union_cursor.png", tr("Select detail"), + SetToolButton(checked, Valentina::UnionDetails, ":/cursor/union_cursor.png", tr("Select detail"), &MainWindow::ClosedDialogUnionDetails); //Must disconnect this signal here. - disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); + disconnect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); } void MainWindow::ClosedDialogUnionDetails(int result) @@ -499,7 +445,7 @@ void MainWindow::ClosedDialogUnionDetails(int result) void MainWindow::ToolCutArc(bool checked) { - SetToolButton(checked, Tool::CutArcTool, ":/cursor/arc_cut_cursor.png", tr("Select arc"), + SetToolButton(checked, Valentina::CutArcTool, ":/cursor/arc_cut_cursor.png", tr("Select arc"), &MainWindow::ClosedDialogCutArc); } @@ -585,47 +531,43 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::ToolBarOption() { - QLabel * labelGrowth = new QLabel; - labelGrowth->setText(tr("Height: ")); - ui->toolBarOption->addWidget(labelGrowth); + if (qApp->patternType() == Pattern::Standard) + { + ui->toolBarOption->addWidget(new QLabel(tr("Height: "))); - QStringList list; - list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" - <<"182"<<"188"; - QComboBox *comboBoxGrow = new QComboBox; - comboBoxGrow->clear(); - comboBoxGrow->addItems(list); - comboBoxGrow->setCurrentIndex(14); - ui->toolBarOption->addWidget(comboBoxGrow); - connect(comboBoxGrow, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::ChangedHeight); + QStringList list; + list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" + <<"182"<<"188"; + QComboBox *comboBoxHeight = new QComboBox; + comboBoxHeight->addItems(list); + comboBoxHeight->setCurrentIndex(14);//176 + ui->toolBarOption->addWidget(comboBoxHeight); + connect(comboBoxHeight, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedHeight); - QLabel * labelSize = new QLabel; - labelSize->setText(tr(" Size: ")); - ui->toolBarOption->addWidget(labelSize); + ui->toolBarOption->addWidget(new QLabel(tr(" Size: "))); - list.clear(); - list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"<<"56"; - QComboBox *comboBoxSize = new QComboBox; - comboBoxSize->clear(); - comboBoxSize->addItems(list); - comboBoxSize->setCurrentIndex(14); - ui->toolBarOption->addWidget(comboBoxSize); - connect(comboBoxSize, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::ChangedSize); + list.clear(); + list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54" + <<"56"; + QComboBox *comboBoxSize = new QComboBox; + comboBoxSize->addItems(list); + comboBoxSize->setCurrentIndex(14);//50 + ui->toolBarOption->addWidget(comboBoxSize); + connect(comboBoxSize, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedSize); - ui->toolBarOption->addSeparator(); + ui->toolBarOption->addSeparator(); + } - mouseCoordinate = new QLabel; - mouseCoordinate ->setText("0, 0"); + mouseCoordinate = new QLabel("0, 0"); ui->toolBarOption->addWidget(mouseCoordinate); } void MainWindow::ToolBarDraws() { - QLabel * labelNameDraw = new QLabel; - labelNameDraw ->setText(tr("Pattern Piece: ")); - ui->toolBarDraws->addWidget(labelNameDraw); + QLabel *labelPtternPieceName = new QLabel(tr("Pattern Piece: ")); + ui->toolBarDraws->addWidget(labelPtternPieceName); comboBoxDraws = new QComboBox; ui->toolBarDraws->addWidget(comboBoxDraws); @@ -648,6 +590,29 @@ void MainWindow::ToolBarDraws() ui->actionLayout->setEnabled(false); } +void MainWindow::InitToolButtons() +{ + connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine); + connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); + connect(ui->toolButtonAlongLine, &QToolButton::clicked, this, &MainWindow::ToolAlongLine); + connect(ui->toolButtonShoulderPoint, &QToolButton::clicked, this, &MainWindow::ToolShoulderPoint); + connect(ui->toolButtonNormal, &QToolButton::clicked, this, &MainWindow::ToolNormal); + connect(ui->toolButtonBisector, &QToolButton::clicked, this, &MainWindow::ToolBisector); + connect(ui->toolButtonLineIntersect, &QToolButton::clicked, this, &MainWindow::ToolLineIntersect); + connect(ui->toolButtonSpline, &QToolButton::clicked, this, &MainWindow::ToolSpline); + connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc); + connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath); + connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact); + connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail); + connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); + connect(ui->toolButtonTriangle, &QToolButton::clicked, this, &MainWindow::ToolTriangle); + connect(ui->toolButtonPointOfIntersection, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersection); + connect(ui->toolButtonSplineCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSpline); + connect(ui->toolButtonSplinePathCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSplinePath); + connect(ui->toolButtonUnionDetails, &QToolButton::clicked, this, &MainWindow::ToolUnionDetails); + connect(ui->toolButtonArcCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutArc); +} + void MainWindow::currentDrawChanged( int index ) { if (index != -1) @@ -657,7 +622,7 @@ void MainWindow::currentDrawChanged( int index ) if (drawMode) { ArrowTool(); - qint64 id = doc->SPointActiveDraw(); + quint32 id = doc->SPointActiveDraw(); if (id != 0) { const VPointF *p = pattern->GeometricObject(id); @@ -669,121 +634,123 @@ void MainWindow::currentDrawChanged( int index ) void MainWindow::mouseMove(const QPointF &scenePos) { - QString string = QString("%1, %2") - .arg(static_cast(toMM(scenePos.x()))) - .arg(static_cast(toMM(scenePos.y()))); - mouseCoordinate->setText(string); + QString string = QString("%1, %2").arg(static_cast(qApp->fromPixel(scenePos.x()))) + .arg(static_cast(qApp->fromPixel(scenePos.y()))); + if (mouseCoordinate != nullptr) + { + mouseCoordinate->setText(string); + } } void MainWindow::CancelTool() { delete dialogTool; - dialogTool = 0; + dialogTool = nullptr; switch ( tool ) { - case Tool::ArrowTool: + case Valentina::ArrowTool: ui->actionArrowTool->setChecked(false); helpLabel->setText(""); break; - case Tool::SinglePointTool: + case Valentina::SinglePointTool: Q_UNREACHABLE(); //Nothing to do here because we can't create this tool from main window. break; - case Tool::EndLineTool: + case Valentina::EndLineTool: ui->toolButtonEndLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::LineTool: + case Valentina::LineTool: ui->toolButtonLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearFocus(); break; - case Tool::AlongLineTool: + case Valentina::AlongLineTool: ui->toolButtonAlongLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::ShoulderPointTool: + case Valentina::ShoulderPointTool: ui->toolButtonShoulderPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::NormalTool: + case Valentina::NormalTool: ui->toolButtonNormal->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::BisectorTool: + case Valentina::BisectorTool: ui->toolButtonBisector->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::LineIntersectTool: + case Valentina::LineIntersectTool: ui->toolButtonLineIntersect->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::SplineTool: + case Valentina::SplineTool: ui->toolButtonSpline->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::ArcTool: + case Valentina::ArcTool: ui->toolButtonArc->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::SplinePathTool: + case Valentina::SplinePathTool: ui->toolButtonSplinePath->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::PointOfContact: + case Valentina::PointOfContact: ui->toolButtonPointOfContact->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::Detail: + case Valentina::DetailTool: ui->toolButtonNewDetail->setChecked(false); break; - case Tool::Height: + case Valentina::Height: ui->toolButtonHeight->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::Triangle: + case Valentina::Triangle: ui->toolButtonTriangle->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::PointOfIntersection: + case Valentina::PointOfIntersection: ui->toolButtonPointOfIntersection->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutSplineTool: + case Valentina::CutSplineTool: ui->toolButtonSplineCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutSplinePathTool: + case Valentina::CutSplinePathTool: ui->toolButtonSplinePathCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::UnionDetails: + case Valentina::UnionDetails: ui->toolButtonUnionDetails->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutArcTool: + case Valentina::CutArcTool: ui->toolButtonArcCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; default: - qWarning()<<"Got wrong tool type. Ignored."; + qDebug()<<"Got wrong tool type. Ignored."; break; } } @@ -792,7 +759,7 @@ void MainWindow::ArrowTool() { CancelTool(); ui->actionArrowTool->setChecked(true); - tool = Tool::ArrowTool; + tool = Valentina::ArrowTool; QCursor cur(Qt::ArrowCursor); view->setCursor(cur); helpLabel->setText(""); @@ -850,7 +817,7 @@ void MainWindow::ActionDraw(bool checked) connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); RestoreCurrentScene(); - mode = Draw::Calculation; + mode = Valentina::Calculation; comboBoxDraws->setEnabled(true); comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace drawMode = true; @@ -888,7 +855,7 @@ void MainWindow::ActionDetails(bool checked) comboBoxDraws->setEnabled(false); - mode = Draw::Modeling; + mode = Valentina::Modeling; SetEnableTool(true); currentToolBoxIndex = ui->toolBox->currentIndex(); ui->toolBox->setCurrentIndex(4); @@ -996,6 +963,12 @@ void MainWindow::Clear() ui->actionSave->setEnabled(false); ui->actionPattern_properties->setEnabled(false); SetEnableTool(false); + qApp->setPatternUnit(Valentina::Cm); + qApp->setPatternType(Pattern::Individual); + ui->toolBarOption->clear(); +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif } void MainWindow::NewPattern() @@ -1021,7 +994,7 @@ void MainWindow::ChangedSize(const QString & text) void MainWindow::ChangedHeight(const QString &text) { qint32 growth = text.toInt(); - pattern->SetGrowth(growth*10); + pattern->SetHeight(growth*10); doc->FullUpdateTree(); } @@ -1044,7 +1017,6 @@ void MainWindow::ActionTable(bool checked) if (checked) { dialogTable = new DialogIncrements(pattern, doc, this); - Q_CHECK_PTR(dialogTable); connect(dialogTable, &DialogIncrements::DialogClosed, this, &MainWindow::ClosedActionTable); dialogTable->show(); } @@ -1059,7 +1031,7 @@ void MainWindow::ClosedActionTable() { ui->actionTable->setChecked(false); delete dialogTable; - dialogTable = 0; + dialogTable = nullptr; } void MainWindow::ActionHistory(bool checked) @@ -1068,8 +1040,7 @@ void MainWindow::ActionHistory(bool checked) { dialogHistory = new DialogHistory(pattern, doc, this); dialogHistory->setWindowFlags(Qt::Window); - connect(dialogHistory, &DialogHistory::DialogClosed, this, - &MainWindow::ClosedActionHistory); + connect(dialogHistory, &DialogHistory::DialogClosed, this, &MainWindow::ClosedActionHistory); dialogHistory->show(); } else @@ -1084,8 +1055,8 @@ void MainWindow::ActionLayout(bool checked) Q_UNUSED(checked); hide(); QVector listDetails; - const QHash *details = pattern->DataDetails(); - QHashIterator idetail(*details); + const QHash *details = pattern->DataDetails(); + QHashIterator idetail(*details); while (idetail.hasNext()) { idetail.next(); @@ -1106,7 +1077,7 @@ void MainWindow::SetEnableTool(bool enable) { bool drawTools = false; bool modelingTools = false; - if (mode == Draw::Calculation) + if (mode == Valentina::Calculation) { drawTools = enable; } @@ -1146,113 +1117,12 @@ void MainWindow::MinimumScrollBar() verScrollBar->setValue(verScrollBar->minimum()); } -bool MainWindow::ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, - qint64 &errorColumn) const -{ - errorLine = -1; - errorColumn = -1; - QFile pattern(fileName); - if (pattern.open(QIODevice::ReadOnly) == false) - { - errorMsg = QString(tr("Can't open pattern file %1:\n%2.").arg(fileName).arg(pattern.errorString())); - return false; - } - QFile fileSchema(schema); - if (fileSchema.open(QIODevice::ReadOnly) == false) - { - errorMsg = QString(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); - return false; - } - - MessageHandler messageHandler; - QXmlSchema sch; - sch.setMessageHandler(&messageHandler); - sch.load(&fileSchema, QUrl::fromLocalFile(fileSchema.fileName())); - - bool errorOccurred = false; - if (sch.isValid() == false) - { - errorOccurred = true; - } - else - { - QXmlSchemaValidator validator(sch); - if (validator.validate(&pattern, QUrl::fromLocalFile(pattern.fileName())) == false) - { - errorOccurred = true; - } - } - - if (errorOccurred) - { - errorMsg = messageHandler.statusMessage(); - errorLine = messageHandler.line(); - errorColumn = messageHandler.column(); - return false; - } - else - { - return true; - } -} - bool MainWindow::SavePattern(const QString &fileName) { - try - { - doc->TestUniqueId(); - } - catch (const VExceptionUniqueId &e) - { - e.CriticalMessageBox(tr("Error no unique id."), this); - return false; - } - if (fileName.isEmpty()) - { - qWarning()<save(out, Indent); - tempFile.close(); - } - //Replace temp file our - bool result = false; - QFile patternFile(fileName); - // We need here temporary file because we need restore pattern after error of copying temp file. - QTemporaryFile tempOfPattern; - if (tempOfPattern.open()) - { - patternFile.copy(tempOfPattern.fileName()); - } - if ( patternFile.exists() == false || patternFile.remove() ) - { - if ( tempFile.copy(patternFile.fileName()) == false ) - { - qWarning()<SaveDocument(fileName); if (result) { - tempFile.remove(); if (tempInfo.suffix() != "autosave") { setCurrentFile(fileName); @@ -1269,7 +1139,7 @@ void MainWindow::AutoSavePattern() QString autofile = curFile +".autosave"; if (SavePattern(autofile) == false) { - qWarning()<menuFile->insertAction(ui->actionExit, recentFileActs[i]); } separatorAct = new QAction(this); - Q_CHECK_PTR(separatorAct); separatorAct->setSeparator(true); ui->menuFile->insertAction(ui->actionExit, separatorAct); UpdateRecentFileActions(); @@ -1404,7 +1277,6 @@ void MainWindow::CreateActions() for (int i = 0; i < MaxRecentFiles; ++i) { recentFileActs[i] = new QAction(this); - Q_CHECK_PTR(recentFileActs[i]); recentFileActs[i]->setVisible(false); connect(recentFileActs[i], &QAction::triggered, this, &MainWindow::OpenRecentFile); } @@ -1414,7 +1286,7 @@ void MainWindow::InitAutoSave() { //Autosaving file each 5 minutes delete autoSaveTimer; - autoSaveTimer = 0; + autoSaveTimer = nullptr; QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()); @@ -1429,13 +1301,40 @@ void MainWindow::InitAutoSave() } autoSaveTimer = new QTimer(this); - Q_CHECK_PTR(autoSaveTimer); autoSaveTimer->setTimerType(Qt::VeryCoarseTimer); connect(autoSaveTimer, &QTimer::timeout, this, &MainWindow::AutoSavePattern); autoSaveTimer->start(autoTime*60000); } } +QString MainWindow::PatternPieceName(const QString &text) +{ + QInputDialog *dlg = new QInputDialog(this); + dlg->setInputMode( QInputDialog::TextInput ); + dlg->setLabelText(tr("Pattern piece:")); + dlg->setTextEchoMode(QLineEdit::Normal); + dlg->setWindowTitle(tr("Enter a new label for the pattern piece.")); + dlg->resize(300, 100); + dlg->setTextValue(text); + QString nameDraw; + while (1) + { + const bool bOk = dlg->exec(); + nameDraw = dlg->textValue(); + if (bOk == false || nameDraw.isEmpty()) + { + delete dlg; + return QString(); + } + if (comboBoxDraws->findText(nameDraw) == -1) + { + break; + } + } + delete dlg; + return nameDraw; +} + MainWindow::~MainWindow() { CancelTool(); @@ -1449,123 +1348,165 @@ MainWindow::~MainWindow() void MainWindow::LoadPattern(const QString &fileName) { - QFile file(fileName); - QString errorMsg; - qint64 errorLine = 0; - qint64 errorColumn = 0; - if (file.open(QIODevice::ReadOnly)) + try { - if (ValidatePattern("://schema/pattern.xsd", fileName, errorMsg, errorLine, errorColumn)) + VDomDocument::ValidateXML("://schema/pattern.xsd", fileName); + doc->setContent(fileName); + + qApp->setPatternUnit(doc->MUnit()); + qApp->setPatternType(doc->MType()); + QString path = doc->MPath(); + + path = CheckPathToMeasurements(path, qApp->patternType()); + if(path.isEmpty()) { - qint32 errorLine = 0; - qint32 errorColumn = 0; - if (doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)) + Clear(); + return; + } + + QString text = tr("Measurements use different units than pattern. This pattern required measurements in %1") + .arg(doc->UnitsToStr(qApp->patternUnit())); + if (qApp->patternType() == Pattern::Standard) + { + VStandardMeasurements m(pattern); + m.setContent(path); + Valentina::Units mUnit = m.Unit(); + if (qApp->patternUnit() != mUnit) { - disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - try - { - #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); - #endif - doc->Parse(Document::FullParse, sceneDraw, sceneDetails); - #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); - #endif - ui->actionPattern_properties->setEnabled(true); - } - catch (const VExceptionObjectError &e) - { - e.CriticalMessageBox(tr("Error parsing file."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionConversionError &e) - { - e.CriticalMessageBox(tr("Error can't convert value."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionEmptyParameter &e) - { - e.CriticalMessageBox(tr("Error empty parameter."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionWrongParameterId &e) - { - e.CriticalMessageBox(tr("Error wrong id."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionUniqueId &e) - { - e.CriticalMessageBox(tr("Error no unique id."), this); - file.close(); - Clear(); - return; - } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - QString nameDraw = doc->GetNameActivDraw(); - qint32 index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) - { // -1 for not found - comboBoxDraws->setCurrentIndex(index); - } - if (comboBoxDraws->count() > 0) - { - SetEnableTool(true); - } - else - { - SetEnableTool(false); - } - SetEnableWidgets(true); + QMessageBox::critical(this, tr("Wrong units."), text); + Clear(); + return; } - else + m.SetSize(); + m.SetHeight(); + ToolBarOption(); + } + else + { + VIndividualMeasurements m(pattern); + m.setContent(path); + Valentina::Units mUnit = m.Unit(); + if (qApp->patternUnit() != mUnit) { - QMessageBox msgBox(this); - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Parsing pattern file error.")); - msgBox.setInformativeText(errorMsg); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - QString error = QString(tr("Error in line %1 column %2")).arg(errorLine).arg(errorColumn); - msgBox.setDetailedText(error); - msgBox.exec(); - file.close(); + QMessageBox::critical(this, tr("Wrong units."), text); Clear(); return; } } - else - { - QMessageBox msgBox(this); - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Validation file error.")); - msgBox.setInformativeText(errorMsg); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - QString error = QString(tr("Error in line %1 column %2")).arg(errorLine).arg(errorColumn); - msgBox.setDetailedText(error); - msgBox.exec(); - file.close(); - Clear(); - return; - } - file.close(); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + Clear(); + return; + } + + disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + try + { + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + + doc->Parse(Document::FullParse, sceneDraw, sceneDetails); + + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + ui->actionPattern_properties->setEnabled(true); + } + catch (const VExceptionObjectError &e) + { + e.CriticalMessageBox(tr("Error parsing file."), this); + Clear(); + return; + } + catch (const VExceptionConversionError &e) + { + e.CriticalMessageBox(tr("Error can't convert value."), this); + Clear(); + return; + } + catch (const VExceptionEmptyParameter &e) + { + e.CriticalMessageBox(tr("Error empty parameter."), this); + Clear(); + return; + } + catch (const VExceptionWrongId &e) + { + e.CriticalMessageBox(tr("Error wrong id."), this); + Clear(); + return; + } + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + QString nameDraw = doc->GetNameActivDraw(); + qint32 index = comboBoxDraws->findText(nameDraw); + if ( index != -1 ) + { // -1 for not found + comboBoxDraws->setCurrentIndex(index); + } + if (comboBoxDraws->count() > 0) + { + SetEnableTool(true); } else { - QMessageBox::warning(this, tr("Valentina"), tr("Cannot read file %1:\n%2.") - .arg(fileName) - .arg(file.errorString())); + SetEnableTool(false); } + SetEnableWidgets(true); + setCurrentFile(fileName); helpLabel->setText(tr("File loaded")); } + +QString MainWindow::CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType) +{ + QFile table(path); + if (table.exists() == false) + { + QString text = tr("The measurements file

%1

%3").arg(path) + .arg(tr("could not be found. Do you want to update the file location")); + QMessageBox::StandardButton res = QMessageBox::question(this, "Loading measurements file", text, + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + if(res == QMessageBox::No) + { + return QString(); + } + else + { + QString filter; + if (patternType == Pattern::Standard) + { + filter = tr("Standard measurements (*.vst)"); + } + else + { + filter = tr("Individual measurements (*.vit)"); + } + QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); + + if(mPath.isEmpty()) + { + return mPath; + } + else + { + if (patternType == Pattern::Standard) + { + VDomDocument::ValidateXML("://schema/standard_measurements.xsd", mPath); + } + else + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", mPath); + } + doc->SetPath(mPath); + return mPath; + } + } + } + return path; +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 75c4f7f81..8df7c3985 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -55,7 +55,7 @@ public: * @brief MainWindow constructor. * @param parent parent widget. */ - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); /** * @brief LoadPattern open pattern file. @@ -403,11 +403,11 @@ private: /** * @brief doc dom document container */ - VDomDocument *doc; + VPattern *doc; /** * @brief tool current tool */ - Tool::Tools tool; + Valentina::Tools tool; /** * @brief currentScene pointer to current scene. */ @@ -450,7 +450,7 @@ private: /** * @brief mode keep current draw mode. */ - Draw::Draws mode; + Valentina::Draws mode; /** * @brief currentDrawIndex save current selected pattern peace. */ @@ -475,6 +475,7 @@ private: * @brief ToolBarDraws enable draw toolbar. */ void ToolBarDraws(); + void InitToolButtons(); /** * @brief CanselTool cansel tool. */ @@ -510,23 +511,12 @@ private: * @param toolTip first tooltipe. * @param closeDialogSlot function what handle after close dialog. */ - void SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip, + void SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot); /** * @brief MinimumScrollBar set scroll bar to minimum. */ void MinimumScrollBar(); - /** - * @brief ValidatePattern validate pattern file by xsd schema. - * @param schema path to schema file. - * @param fileName name of pattern file. - * @param errorMsg error message. - * @param errorLine number error line. - * @param errorColumn number error column. - * @return true if validation successful. - */ - bool ValidatePattern(const QString &schema, const QString &curFile, QString &errorMsg, qint64 &errorLine, - qint64 &errorColumn) const; template /** * @brief ClosedDialog handle close dialog @@ -572,6 +562,8 @@ private: void CreateMenus(); void CreateActions(); void InitAutoSave(); + QString PatternPieceName(const QString &text); + QString CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType); }; #endif // MAINWINDOW_H diff --git a/src/options.h b/src/options.h index 1d4176d0c..6ed030062 100644 --- a/src/options.h +++ b/src/options.h @@ -31,38 +31,20 @@ #include #include +#include #define SceneSize 50000 -#define PrintDPI 96.0 - -inline double toPixel(double mm) -{ - return (mm / 25.4) * PrintDPI; -} - -inline double toMM(double pix) -{ - return (pix / PrintDPI) * 25.4; -} - -#define widthMainLine 1.2 //mm -#define widthHairLine widthMainLine/3 - extern const QString translationsPath; -namespace Scene +namespace Valentina { /** * @brief The Scene enum */ enum Scene { Point, Line, Spline, Arc, SplinePath, Detail }; Q_DECLARE_FLAGS(Scenes, Scene) -} -Q_DECLARE_OPERATORS_FOR_FLAGS( Scene::Scenes ) -namespace Tool -{ /** * @brief The Tool enum */ @@ -84,7 +66,7 @@ namespace Tool SplinePathTool, CutSplinePathTool, PointOfContact, - Detail, + DetailTool, NodePoint, NodeArc, NodeSpline, @@ -101,18 +83,34 @@ namespace Tool */ enum Source { FromGui, FromFile, FromTool }; Q_DECLARE_FLAGS(Sources, Source) -} -Q_DECLARE_OPERATORS_FOR_FLAGS( Tool::Tools ) -Q_DECLARE_OPERATORS_FOR_FLAGS( Tool::Sources ) -namespace Draw -{ /** * @brief The Draw enum */ enum Draw { Calculation, Modeling }; Q_DECLARE_FLAGS(Draws, Draw) + + /** + * @brief The Unit enum + */ + enum Unit { Mm, Cm, Inch }; + Q_DECLARE_FLAGS(Units, Unit) } -Q_DECLARE_OPERATORS_FOR_FLAGS(Draw::Draws) +Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Scenes ) +Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Tools ) +Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Sources ) +Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Draws ) +Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Units ) +Q_DECLARE_METATYPE(Valentina::Unit) + +namespace Pattern +{ + /** + * @brief The Scene enum + */ + enum Measurement { Standard, Individual }; + Q_DECLARE_FLAGS(Measurements, Measurement) +} +Q_DECLARE_OPERATORS_FOR_FLAGS( Pattern::Measurements ) #endif // OPTIONS_H diff --git a/src/stable.h b/src/stable.h index 09cd50c93..d220aab6a 100644 --- a/src/stable.h +++ b/src/stable.h @@ -47,7 +47,6 @@ were in use. */ #include #include #include -#include "options.h" #endif #endif // STABLE_H diff --git a/src/tablewindow.cpp b/src/tablewindow.cpp index 4f14159b7..ff2bff51b 100644 --- a/src/tablewindow.cpp +++ b/src/tablewindow.cpp @@ -31,12 +31,12 @@ #include "widgets/vtablegraphicsview.h" #include #include -#include "options.h" +#include "widgets/vapplication.h" TableWindow::TableWindow(QWidget *parent) - :QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow), - listDetails(QVector()), outItems(false), collidingItems(false), tableScene(0), - paper(0), shadowPaper(0), listOutItems(0), listCollidingItems(QList()), + :QMainWindow(parent), numberDetal(nullptr), colission(nullptr), ui(new Ui::TableWindow), + listDetails(QVector()), outItems(false), collidingItems(false), tableScene(nullptr), + paper(nullptr), shadowPaper(nullptr), listOutItems(nullptr), listCollidingItems(QList()), indexDetail(0), sceneRect(QRectF()), fileName(QString()), description(QString()) { ui->setupUi(this); @@ -45,8 +45,8 @@ TableWindow::TableWindow(QWidget *parent) ui->statusBar->addWidget(numberDetal); ui->statusBar->addWidget(colission); outItems = collidingItems = false; - //sceneRect = QRectF(0, 0, toPixel(203), toPixel(287)); - sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171)); + //sceneRect = QRectF(0, 0, qApp->toPixel(203), qApp->toPixel(287)); + sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171)); tableScene = new QGraphicsScene(sceneRect); QBrush brush; brush.setStyle( Qt::SolidPattern ); @@ -81,7 +81,7 @@ void TableWindow::AddPaper() shadowPaper->setBrush(QBrush(Qt::black)); tableScene->addItem(shadowPaper); paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2)); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); + paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); paper->setBrush(QBrush(Qt::white)); tableScene->addItem(paper); qDebug()<rect().size().toSize(); @@ -168,7 +168,7 @@ void TableWindow::StopTable() delete listOutItems; listDetails.clear(); //sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9); - sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171)); + sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171)); emit closed(); } @@ -216,6 +216,7 @@ void TableWindow::saveScene() tableScene->setBackgroundBrush( *brush ); tableScene->clearSelection(); // Selections would also render to the file, so need delete them shadowPaper->setVisible(false); + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); QFileInfo fi( name ); QStringList suffix; suffix << "svg" << "png" << "pdf" << "eps" << "ps"; @@ -226,30 +227,23 @@ void TableWindow::saveScene() SvgFile(name); paper->setVisible(true); break; - case 1: //png - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); + case 1: //png PngFile(name); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); break; case 2: //pdf - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); - PdfFile(name); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); + PdfFile(name); break; case 3: //eps - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); EpsFile(name); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); break; case 4: //ps - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); PsFile(name); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); break; default: - qWarning() << "Bad file suffix"<setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); brush->setColor( QColor( Qt::gray ) ); brush->setStyle( Qt::SolidPattern ); tableScene->setBackgroundBrush( *brush ); @@ -323,7 +317,7 @@ void TableWindow::itemColliding(QList list, int number) { VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(i) ); Q_CHECK_PTR(bitem); - bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); listCollidingItems.removeAt(i); } } @@ -332,7 +326,7 @@ void TableWindow::itemColliding(QList list, int number) { VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(0) ); Q_CHECK_PTR(bitem); - bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); listCollidingItems.clear(); collidingItems = true; } @@ -378,13 +372,13 @@ void TableWindow::GetNextDetail() void TableWindow::AddLength() { QRectF rect = tableScene->sceneRect(); - rect.setHeight(rect.height()+toPixel(279)); + rect.setHeight(rect.height()+qApp->toPixel(279)); tableScene->setSceneRect(rect); rect = shadowPaper->rect(); - rect.setHeight(rect.height()+toPixel(279)); + rect.setHeight(rect.height()+qApp->toPixel(279)); shadowPaper->setRect(rect); rect = paper->rect(); - rect.setHeight(rect.height()+toPixel(279)); + rect.setHeight(rect.height()+qApp->toPixel(279)); paper->setRect(rect); ui->actionRemove->setEnabled(true); emit LengthChanged(); @@ -395,13 +389,13 @@ void TableWindow::RemoveLength() if (sceneRect.height() <= tableScene->sceneRect().height() - 100) { QRectF rect = tableScene->sceneRect(); - rect.setHeight(rect.height()-toPixel(279)); + rect.setHeight(rect.height()-qApp->toPixel(279)); tableScene->setSceneRect(rect); rect = shadowPaper->rect(); - rect.setHeight(rect.height()-toPixel(279)); + rect.setHeight(rect.height()-qApp->toPixel(279)); shadowPaper->setRect(rect); rect = paper->rect(); - rect.setHeight(rect.height()-toPixel(279)); + rect.setHeight(rect.height()-qApp->toPixel(279)); paper->setRect(rect); if (fabs(sceneRect.height() - tableScene->sceneRect().height()) < 0.01) { @@ -437,12 +431,12 @@ void TableWindow::SvgFile(const QString &name) const generator.setViewBox(paper->rect()); generator.setTitle("Valentina pattern"); generator.setDescription(description); - generator.setResolution(PrintDPI); + generator.setResolution(static_cast(qApp->PrintDPI)); QPainter painter; painter.begin(&generator); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, toPixel(widthHairLine), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); tableScene->render(&painter); painter.end(); @@ -459,7 +453,7 @@ void TableWindow::PngFile(const QString &name) const QPainter painter(&image); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, toPixel(widthMainLine), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); tableScene->render(&painter); image.save(name); @@ -473,8 +467,8 @@ void TableWindow::PdfFile(const QString &name) const QRectF r = paper->rect(); qreal x=0, y=0, w=0, h=0; r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents - printer.setResolution(PrintDPI); - printer.setPaperSize ( QSizeF(toMM(w), toMM(h)), QPrinter::Millimeter ); + printer.setResolution(static_cast(qApp->PrintDPI)); + printer.setPaperSize ( QSizeF(qApp->fromPixel(w), qApp->fromPixel(h)), QPrinter::Millimeter ); QPainter painter; if (painter.begin( &printer ) == false) { // failed to open file @@ -483,7 +477,7 @@ void TableWindow::PdfFile(const QString &name) const } painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, toPixel(widthMainLine), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); tableScene->render(&painter); painter.end(); @@ -499,8 +493,8 @@ void TableWindow::EpsFile(const QString &name) const QStringList params; params << "-eps" << tmp.fileName() << name; - PdfToPs(name, params); - } + PdfToPs(params); + } } void TableWindow::PsFile(const QString &name) const @@ -513,13 +507,12 @@ void TableWindow::PsFile(const QString &name) const QStringList params; params << tmp.fileName() << name; - PdfToPs(name, params); + PdfToPs(params); } } -//TODO delete parametr name and use last parameter in string list instead. -void TableWindow::PdfToPs(const QString &name, const QStringList ¶ms) const -{ +void TableWindow::PdfToPs(const QStringList ¶ms) const +{ #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); #endif @@ -534,10 +527,10 @@ void TableWindow::PdfToPs(const QString &name, const QStringList ¶ms) const QApplication::restoreOverrideCursor(); #endif - QFile f(name); - if (!f.exists()) + QFile f(params.last()); + if (f.exists() == false) { - QString msg = QString(tr("Creating file '%1' failed! %2")).arg(name).arg(proc.errorString()); + QString msg = QString(tr("Creating file '%1' failed! %2")).arg(params.last()).arg(proc.errorString()); QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default); msgBox.exec(); } diff --git a/src/tablewindow.h b/src/tablewindow.h index 00e6a6a0c..2db91a8ff 100644 --- a/src/tablewindow.h +++ b/src/tablewindow.h @@ -57,7 +57,7 @@ public: * @brief TableWindow constructor. * @param parent parent widget. */ - explicit TableWindow(QWidget *parent = 0); + explicit TableWindow(QWidget *parent = nullptr); ~TableWindow(); public slots: /** @@ -225,11 +225,10 @@ private: void PsFile(const QString &name)const; /** * @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format. - * @param name name output file. * @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when * need create eps file. */ - void PdfToPs(const QString &name, const QStringList ¶ms)const; + void PdfToPs(const QStringList ¶ms)const; }; #endif // TABLEWINDOW_H diff --git a/src/tools/drawTools/vabstractspline.cpp b/src/tools/drawTools/vabstractspline.cpp new file mode 100644 index 000000000..9d77cdf54 --- /dev/null +++ b/src/tools/drawTools/vabstractspline.cpp @@ -0,0 +1,116 @@ +/************************************************************************ + ** + ** @file vabstractspline.cpp + ** @author Roman Telezhinsky + ** @date 4 3, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vabstractspline.h" + +const QString VAbstractSpline::TagName = QStringLiteral("spline"); + +VAbstractSpline::VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()) +{ + ignoreFullUpdate = true; +} + +void VAbstractSpline::FullUpdateFromFile() +{ + RefreshGeometry(); +} + +void VAbstractSpline::ChangedActivDraw(const QString &newName) +{ + bool selectable = false; + if (nameActivDraw == newName) + { + selectable = true; + currentColor = Qt::black; + } + else + { + selectable = false; + currentColor = Qt::gray; + } + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); + this->setAcceptHoverEvents (selectable); + emit setEnabledPoint(selectable); + VDrawTool::ChangedActivDraw(newName); +} + +void VAbstractSpline::ShowTool(quint32 id, Qt::GlobalColor color, bool enable) +{ + ShowItem(this, id, color, enable); +} + +void VAbstractSpline::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VAbstractSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor)); +} + +void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); +} + +QVariant VAbstractSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == QGraphicsItem::ItemSelectedChange) + { + if (value == true) + { + // do stuff if selected + this->setFocus(); + } + else + { + // do stuff if not selected + } + } + + return QGraphicsItem::itemChange(change, value); +} + +void VAbstractSpline::keyReleaseEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Delete: + DeleteTool(this); + break; + default: + break; + } + QGraphicsItem::keyReleaseEvent ( event ); +} diff --git a/src/tools/drawTools/vabstractspline.h b/src/tools/drawTools/vabstractspline.h new file mode 100644 index 000000000..46261a5c3 --- /dev/null +++ b/src/tools/drawTools/vabstractspline.h @@ -0,0 +1,112 @@ +/************************************************************************ + ** + ** @file vabstractspline.h + ** @author Roman Telezhinsky + ** @date 4 3, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VABSTRACTSPLINE_H +#define VABSTRACTSPLINE_H + +#include "vdrawtool.h" +#include +#include "../../widgets/vcontrolpointspline.h" + +class VAbstractSpline:public VDrawTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); + static const QString TagName; +public slots: + /** + * @brief FullUpdateFromFile update tool data form file. + */ + virtual void FullUpdateFromFile (); +signals: + /** + * @brief RefreshLine refresh control line. + * @param indexSpline position spline in spline list. + * @param position position point in spline. + * @param controlPoint new position control point. + * @param splinePoint new position spline point. + */ + void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, + const QPointF &controlPoint, const QPointF &splinePoint); + /** + * @brief setEnabledPoint disable control points. + * @param enable enable or diasable points. + */ + void setEnabledPoint(bool enable); +protected: + /** + * @brief controlPoints list pointers of control points. + */ + QVector controlPoints; + /** + * @brief RefreshGeometry refresh item on scene. + */ + virtual void RefreshGeometry ()=0; + /** + * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. + * @param newName new name active pattern peace. + */ + virtual void ChangedActivDraw ( const QString &newName ); + /** + * @brief ShowTool highlight tool. + * @param id object id in container + * @param color highlight color. + * @param enable enable or disable highlight. + */ + virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); + /** + * @brief SetFactor set current scale factor of scene. + * @param factor scene scale factor. + */ + virtual void SetFactor(qreal factor); + /** + * @brief hoverMoveEvent handle hover move events. + * @param event hover move event. + */ + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + /** + * @brief hoverLeaveEvent handle hover leave events. + * @param event hover leave event. + */ + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + /** + * @brief itemChange hadle item change. + * @param change change. + * @param value value. + * @return value. + */ + virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + /** + * @brief keyReleaseEvent handle key release events. + * @param event key release event. + */ + virtual void keyReleaseEvent(QKeyEvent * event); +}; + +#endif // VABSTRACTSPLINE_H diff --git a/src/tools/drawTools/vdrawtool.cpp b/src/tools/drawTools/vdrawtool.cpp index e4ad8d170..69e864c3b 100644 --- a/src/tools/drawTools/vdrawtool.cpp +++ b/src/tools/drawTools/vdrawtool.cpp @@ -30,13 +30,13 @@ qreal VDrawTool::factor = 1; -VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id) +VDrawTool::VDrawTool(VPattern *doc, VContainer *data, quint32 id) :VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false), - nameActivDraw(doc->GetNameActivDraw()), dialog(0) + nameActivDraw(doc->GetNameActivDraw()), dialog(nullptr) { - connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw); - connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); - connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool); + connect(this->doc, &VPattern::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw); + connect(this->doc, &VPattern::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); + connect(this->doc, &VPattern::ShowTool, this, &VDrawTool::ShowTool); } VDrawTool::~VDrawTool() @@ -44,7 +44,7 @@ VDrawTool::~VDrawTool() delete dialog; } -void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +void VDrawTool::ShowTool(quint32 id, Qt::GlobalColor color, bool enable) { Q_UNUSED(id); Q_UNUSED(color); @@ -85,7 +85,7 @@ void VDrawTool::FullUpdateFromGui(int result) } } delete dialog; - dialog = 0; + dialog = nullptr; } void VDrawTool::SetFactor(qreal factor) @@ -99,10 +99,10 @@ void VDrawTool::SetFactor(qreal factor) void VDrawTool::AddToCalculation(const QDomElement &domElement) { QDomElement calcElement; - bool ok = doc->GetActivCalculationElement(calcElement); + bool ok = doc->GetActivNodeElement(VPattern::TagCalculation, calcElement); if (ok) { - qint64 id = doc->getCursor(); + quint32 id = doc->getCursor(); if (id <= 0) { calcElement.appendChild(domElement); diff --git a/src/tools/drawTools/vdrawtool.h b/src/tools/drawTools/vdrawtool.h index f85b9cab4..d6e86c05d 100644 --- a/src/tools/drawTools/vdrawtool.h +++ b/src/tools/drawTools/vdrawtool.h @@ -33,7 +33,7 @@ #include #include -#include "../../dialogs/dialogtool.h" +#include "../../dialogs/tools/dialogtool.h" /** * @brief The VDrawTool abstract class for all draw tool. @@ -49,7 +49,7 @@ public: * @param id object id in container. * @param parent parent object. */ - VDrawTool(VDomDocument *doc, VContainer *data, qint64 id); + VDrawTool(VPattern *doc, VContainer *data, quint32 id); virtual ~VDrawTool(); /** * @brief setDialog set dialog when user want change tool option. @@ -67,7 +67,7 @@ public slots: * @param color highlight color. * @param enable enable or disable highlight. */ - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. name new active pattern peace. @@ -134,7 +134,7 @@ protected: { QMenu menu; QAction *actionOption = menu.addAction(tr("Options")); - QAction *actionRemove = 0; + QAction *actionRemove = nullptr; if (showRemove) { actionRemove = menu.addAction(tr("Delete")); @@ -159,7 +159,7 @@ protected: connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGui); if (ignoreFullUpdate == false) { - connect(doc, &VDomDocument::FullUpdateFromFile, dialog, &DialogTool::UpdateList); + connect(doc, &VPattern::FullUpdateFromFile, dialog, &DialogTool::UpdateList); } tool->setDialog(); @@ -183,7 +183,7 @@ protected: * @param color highlight color. * @param enable enable or disable highlight. */ - void ShowItem(Item *item, qint64 id, Qt::GlobalColor color, bool enable) + void ShowItem(Item *item, quint32 id, Qt::GlobalColor color, bool enable) { Q_CHECK_PTR(item); if (id == item->id) @@ -196,7 +196,7 @@ protected: { currentColor = color; } - item->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); } } private: diff --git a/src/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index 1b75c1ed7..ac8e65204 100644 --- a/src/tools/drawTools/vtoolalongline.cpp +++ b/src/tools/drawTools/vtoolalongline.cpp @@ -28,18 +28,18 @@ #include "vtoolalongline.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogalongline.h" +#include "../../dialogs/tools/dialogalongline.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); -VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, - const qint64 &firstPointId, const qint64 &secondPointId, - const QString &typeLine, const Tool::Sources &typeCreation, +VToolAlongLine::VToolAlongLine(VPattern *doc, VContainer *data, quint32 id, const QString &formula, + const quint32 &firstPointId, const quint32 &secondPointId, + const QString &typeLine, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId) { - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -56,8 +56,8 @@ void VToolAlongLine::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshGeometry(); } @@ -84,16 +84,16 @@ void VToolAlongLine::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrFirstPoint, basePointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrFirstPoint, basePointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } @@ -104,13 +104,13 @@ void VToolAlongLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrFirstPoint, basePointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrFirstPoint, basePointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } } @@ -125,11 +125,11 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogAlongLine *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrFirstPoint, dialogTool->getFirstPointId()); - SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId()); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrFirstPoint, dialogTool->getFirstPointId()); + doc->SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId()); } void VToolAlongLine::setDialog() @@ -145,24 +145,24 @@ void VToolAlongLine::setDialog() dialogTool->setPointName(p->name()); } -void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogAlongLine *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString formula = dialogTool->getFormula(); - qint64 firstPointId = dialogTool->getFirstPointId(); - qint64 secondPointId = dialogTool->getSecondPointId(); + quint32 firstPointId = dialogTool->getFirstPointId(); + quint32 secondPointId = dialogTool->getSecondPointId(); QString typeLine = dialogTool->getTypeLine(); QString pointName = dialogTool->getPointName(); Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *firstPoint = data->GeometricObject(firstPointId); const VPointF *secondPoint = data->GeometricObject(secondPointId); @@ -172,9 +172,9 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS qreal result = cal.eval(formula, &errorMsg); if (errorMsg.isEmpty()) { - line.setLength(toPixel(result)); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + line.setLength(qApp->toPixel(result)); + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject( new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); data->AddLine(firstPointId, id); @@ -190,7 +190,7 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::AlongLineTool, doc); + VDrawTool::AddRecord(id, Valentina::AlongLineTool, doc); if (parse == Document::FullParse) { VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, diff --git a/src/tools/drawTools/vtoolalongline.h b/src/tools/drawTools/vtoolalongline.h index 21c9f7bbd..89924d36e 100644 --- a/src/tools/drawTools/vtoolalongline.h +++ b/src/tools/drawTools/vtoolalongline.h @@ -50,9 +50,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, - const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolAlongLine(VPattern *doc, VContainer *data, quint32 id, const QString &formula, + const quint32 &firstPointId, const quint32 &secondPointId, const QString &typeLine, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,10 +81,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, - const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, const QString &formula, + const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** @@ -127,7 +127,7 @@ private: /** * @brief secondPointId id second point of line. */ - qint64 secondPointId; + quint32 secondPointId; }; #endif // VTOOLALONGLINE_H diff --git a/src/tools/drawTools/vtoolarc.cpp b/src/tools/drawTools/vtoolarc.cpp index 7f63bfa8d..e45eb80e7 100644 --- a/src/tools/drawTools/vtoolarc.cpp +++ b/src/tools/drawTools/vtoolarc.cpp @@ -28,12 +28,12 @@ #include "vtoolarc.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogarc.h" +#include "../../dialogs/tools/dialogarc.h" const QString VToolArc::TagName = QStringLiteral("arc"); const QString VToolArc::ToolType = QStringLiteral("simple"); -VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, +VToolArc::VToolArc(VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VDrawTool(doc, data, id), QGraphicsPathItem(parent) { @@ -42,12 +42,12 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::S path.addPath(arc->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, toPixel(widthHairLine)/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -69,22 +69,22 @@ void VToolArc::setDialog() dialogTool->SetRadius(arc->GetFormulaRadius()); } -void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogArc *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - qint64 center = dialogTool->GetCenter(); + quint32 center = dialogTool->GetCenter(); QString radius = dialogTool->GetRadius(); QString f1 = dialogTool->GetF1(); QString f2 = dialogTool->GetF2(); - Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Tool::FromGui); + Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, - const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolArc::Create(const quint32 _id, const quint32 ¢er, const QString &radius, const QString &f1, + const QString &f2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; @@ -93,7 +93,7 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad qreal result = cal.eval(radius, &errorMsg); if (errorMsg.isEmpty()) { - calcRadius = toPixel(result); + calcRadius = qApp->toPixel(result); } errorMsg.clear(); @@ -112,9 +112,8 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad VPointF c = *data->GeometricObject(center); VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 ); - Q_CHECK_PTR(arc); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(arc); } @@ -127,7 +126,7 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad } } data->AddLengthArc(id); - VDrawTool::AddRecord(id, Tool::ArcTool, doc); + VDrawTool::AddRecord(id, Valentina::ArcTool, doc); if (parse == Document::FullParse) { VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); @@ -156,13 +155,13 @@ void VToolArc::ChangedActivDraw(const QString &newName) selectable = false; currentColor = Qt::gray; } - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); this->setAcceptHoverEvents (selectable); VDrawTool::ChangedActivDraw(newName); } -void VToolArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +void VToolArc::ShowTool(quint32 id, Qt::GlobalColor color, bool enable) { ShowItem(this, id, color, enable); } @@ -183,12 +182,12 @@ void VToolArc::AddToFile() const VArc *arc = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); - SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); - SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); - SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); + doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); + doc->SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); + doc->SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); AddToCalculation(domElement); } @@ -199,10 +198,10 @@ void VToolArc::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); - SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); - SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); - SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); + doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); + doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); + doc->SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); + doc->SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); } } @@ -210,7 +209,7 @@ void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Arc); + emit ChoosedTool(id, Valentina::Arc); } QGraphicsItem::mouseReleaseEvent(event); } @@ -219,14 +218,14 @@ void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VToolArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor)); } //cppcheck-suppress unusedFunction void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); } void VToolArc::RemoveReferens() @@ -271,15 +270,15 @@ void VToolArc::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogArc *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetCenter())); - SetAttribute(domElement, AttrRadius, dialogTool->GetRadius()); - SetAttribute(domElement, AttrAngle1, dialogTool->GetF1()); - SetAttribute(domElement, AttrAngle2, dialogTool->GetF2()); + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetCenter())); + doc->SetAttribute(domElement, AttrRadius, dialogTool->GetRadius()); + doc->SetAttribute(domElement, AttrAngle1, dialogTool->GetF1()); + doc->SetAttribute(domElement, AttrAngle2, dialogTool->GetF2()); } void VToolArc::RefreshGeometry() { - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); const VArc *arc = VAbstractTool::data.GeometricObject(id); QPainterPath path; path.addPath(arc->GetPath()); diff --git a/src/tools/drawTools/vtoolarc.h b/src/tools/drawTools/vtoolarc.h index 1455db910..8dd66a768 100644 --- a/src/tools/drawTools/vtoolarc.h +++ b/src/tools/drawTools/vtoolarc.h @@ -48,8 +48,8 @@ public: * @param typeCreation way we create this tool. * @param parent parent object */ - VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0); + VToolArc(VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -61,7 +61,7 @@ public: * @param doc dom document container * @param data container with variables */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool form GUI. * @param _id tool id, 0 if tool doesn't exist yet. @@ -75,9 +75,9 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, - const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const quint32 ¢er, const QString &radius, const QString &f1, + const QString &f2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString TagName; static const QString ToolType; public slots: @@ -96,7 +96,7 @@ public slots: * @param color highlight color. * @param enable enable or disable highlight. */ - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. diff --git a/src/tools/drawTools/vtoolbisector.cpp b/src/tools/drawTools/vtoolbisector.cpp index 44b28bac6..34bf702b6 100644 --- a/src/tools/drawTools/vtoolbisector.cpp +++ b/src/tools/drawTools/vtoolbisector.cpp @@ -28,20 +28,19 @@ #include "vtoolbisector.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogbisector.h" +#include "../../dialogs/tools/dialogbisector.h" const QString VToolBisector::ToolType = QStringLiteral("bisector"); -VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qint64 &thirdPointId, const Tool::Sources &typeCreation, - QGraphicsItem *parent) +VToolBisector::VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, + const quint32 &thirdPointId, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), thirdPointId(0) { this->firstPointId = firstPointId; this->thirdPointId = thirdPointId; - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -84,27 +83,27 @@ void VToolBisector::setDialog() dialogTool->setPointName(p->name()); } -void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogBisector *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString formula = dialogTool->getFormula(); - qint64 firstPointId = dialogTool->getFirstPointId(); - qint64 secondPointId = dialogTool->getSecondPointId(); - qint64 thirdPointId = dialogTool->getThirdPointId(); + quint32 firstPointId = dialogTool->getFirstPointId(); + quint32 secondPointId = dialogTool->getSecondPointId(); + quint32 thirdPointId = dialogTool->getThirdPointId(); QString typeLine = dialogTool->getTypeLine(); QString pointName = dialogTool->getPointName(); Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolBisector::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine, +void VToolBisector::Create(const quint32 _id, const QString &formula, const quint32 &firstPointId, + const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *firstPoint = data->GeometricObject(firstPointId); const VPointF *secondPoint = data->GeometricObject(secondPointId); @@ -116,9 +115,9 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 if (errorMsg.isEmpty()) { QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), - thirdPoint->toQPointF(), toPixel(result)); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + thirdPoint->toQPointF(), qApp->toPixel(result)); + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); data->AddLine(firstPointId, id); @@ -132,7 +131,7 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::BisectorTool, doc); + VDrawTool::AddRecord(id, Valentina::BisectorTool, doc); if (parse == Document::FullParse) { VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, @@ -155,9 +154,9 @@ void VToolBisector::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - basePointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); - thirdPointId = domElement.attribute(AttrThirdPoint, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + basePointId = domElement.attribute(AttrSecondPoint, "").toUInt(); + thirdPointId = domElement.attribute(AttrThirdPoint, "").toUInt(); } RefreshGeometry(); } @@ -183,17 +182,17 @@ void VToolBisector::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, basePointId); - SetAttribute(domElement, AttrThirdPoint, thirdPointId); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, basePointId); + doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); AddToCalculation(domElement); } @@ -204,14 +203,14 @@ void VToolBisector::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, basePointId); - SetAttribute(domElement, AttrThirdPoint, thirdPointId); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, basePointId); + doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); } } @@ -227,10 +226,10 @@ void VToolBisector::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogBisector *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); - SetAttribute(domElement, AttrThirdPoint, QString().setNum(dialogTool->getThirdPointId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); + doc->SetAttribute(domElement, AttrThirdPoint, QString().setNum(dialogTool->getThirdPointId())); } diff --git a/src/tools/drawTools/vtoolbisector.h b/src/tools/drawTools/vtoolbisector.h index f019bd35e..84aeac0f8 100644 --- a/src/tools/drawTools/vtoolbisector.h +++ b/src/tools/drawTools/vtoolbisector.h @@ -50,10 +50,10 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, - const qint64 &thirdPointId, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0); + VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, + const quint32 &thirdPointId, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr); /** * @brief FindPoint find bisector point. * @param firstPoint first point of angle. @@ -75,7 +75,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -93,11 +93,11 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine, + static void Create(const quint32 _id, const QString &formula, const quint32 &firstPointId, + const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** @@ -140,11 +140,11 @@ private: /** * @brief firstPointId id first point of angle. */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief thirdPointId id third point of angle. */ - qint64 thirdPointId; + quint32 thirdPointId; }; #endif // VTOOLBISECTOR_H diff --git a/src/tools/drawTools/vtoolcutarc.cpp b/src/tools/drawTools/vtoolcutarc.cpp index 05588967a..c363d4723 100644 --- a/src/tools/drawTools/vtoolcutarc.cpp +++ b/src/tools/drawTools/vtoolcutarc.cpp @@ -28,14 +28,14 @@ #include "vtoolcutarc.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogcutarc.h" +#include "../../dialogs/tools/dialogcutarc.h" const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); const QString VToolCutArc::AttrArc = QStringLiteral("arc"); -VToolCutArc::VToolCutArc(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, - const qint64 &arcId, const qint64 &arc1id, const qint64 &arc2id, - const Tool::Sources &typeCreation, QGraphicsItem * parent) +VToolCutArc::VToolCutArc(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &arcId, const quint32 &arc1id, const quint32 &arc2id, + const Valentina::Sources &typeCreation, QGraphicsItem * parent) :VToolPoint(doc, data, id, parent), formula(formula), arcId(arcId), firstArc(), secondArc(), arc1id(arc1id), arc2id(arc2id) { @@ -44,18 +44,16 @@ VToolCutArc::VToolCutArc(VDomDocument *doc, VContainer *data, const qint64 &id, Q_ASSERT_X(arc2id > 0, Q_FUNC_INFO, "arc2id <= 0"); firstArc = new VSimpleArc(arc1id, ¤tColor, &factor); - Q_CHECK_PTR(firstArc); RefreshArc(firstArc, arc1id, SimpleArc::ForthPoint); firstArc->setParentItem(this); connect(firstArc, &VSimpleArc::Choosed, this, &VToolCutArc::ArcChoosed); secondArc = new VSimpleArc(arc2id, ¤tColor, &factor); - Q_CHECK_PTR(secondArc); RefreshArc(secondArc, arc2id, SimpleArc::FirstPoint); secondArc->setParentItem(this); connect(secondArc, &VSimpleArc::Choosed, this, &VToolCutArc::ArcChoosed); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -76,7 +74,7 @@ void VToolCutArc::setDialog() dialogTool->setPointName(point->name()); } -void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); @@ -84,13 +82,13 @@ void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocu Q_CHECK_PTR(dialogTool); QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); - qint64 arcId = dialogTool->getArcId(); - Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); + quint32 arcId = dialogTool->getArcId(); + Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolCutArc::Create(const qint64 _id, const QString &pointName, const QString &formula, const qint64 &arcId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolCutArc::Create(const quint32 _id, const QString &pointName, const QString &formula, const quint32 &arcId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VArc *arc = data->GeometricObject(arcId); Calculator cal(data); @@ -100,40 +98,34 @@ void VToolCutArc::Create(const qint64 _id, const QString &pointName, const QStri { VArc arc1; VArc arc2; - QPointF point = arc->CutArc(toPixel(result), arc1, arc2); + QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2); - qint64 id = _id; - qint64 arc1id = 0; - qint64 arc2id = 0; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + quint32 arc1id = 0; + quint32 arc2id = 0; + if (typeCreation == Valentina::FromGui) { VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); - Q_CHECK_PTR(p); id = data->AddGObject(p); VArc * ar1 = new VArc(arc1); - Q_CHECK_PTR(ar1); arc1id = data->AddGObject(ar1); VArc * ar2 = new VArc(arc2); - Q_CHECK_PTR(ar2); arc2id = data->AddGObject(ar2); } else { VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); - Q_CHECK_PTR(p); data->UpdateGObject(id, p); arc1id = id + 1; arc2id = id + 2; VArc * ar1 = new VArc(arc1); - Q_CHECK_PTR(ar1); data->UpdateGObject(arc1id, ar1); VArc * ar2 = new VArc(arc2); - Q_CHECK_PTR(ar2); data->UpdateGObject(arc2id, ar2); if (parse != Document::FullParse) @@ -144,7 +136,7 @@ void VToolCutArc::Create(const qint64 _id, const QString &pointName, const QStri data->AddLengthArc(arc1id); data->AddLengthArc(arc2id); - VDrawTool::AddRecord(id, Tool::CutArcTool, doc); + VDrawTool::AddRecord(id, Valentina::CutArcTool, doc); if (parse == Document::FullParse) { VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation); @@ -165,14 +157,14 @@ void VToolCutArc::FullUpdateFromFile() if (domElement.isElement()) { formula = domElement.attribute(AttrLength, ""); - arcId = domElement.attribute(AttrArc, "").toLongLong(); + arcId = domElement.attribute(AttrArc, "").toUInt(); } RefreshGeometry(); } -void VToolCutArc::ArcChoosed(qint64 id) +void VToolCutArc::ArcChoosed(quint32 id) { - emit ChoosedTool(id, Scene::Arc); + emit ChoosedTool(id, Valentina::Arc); } void VToolCutArc::ChangedActivDraw(const QString &newName) @@ -193,8 +185,8 @@ void VToolCutArc::ChangedActivDraw(const QString &newName) secondArc->setFlag(QGraphicsItem::ItemIsSelectable, false); secondArc->setAcceptHoverEvents(false); } - firstArc->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); - secondArc->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + firstArc->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + secondArc->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); VToolPoint::ChangedActivDraw(newName); } @@ -213,14 +205,14 @@ void VToolCutArc::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrArc, arcId); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrArc, arcId); AddToCalculation(domElement); } @@ -231,11 +223,11 @@ void VToolCutArc::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrArc, arcId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrArc, arcId); } } @@ -251,12 +243,12 @@ void VToolCutArc::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogCutArc *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId())); } -void VToolCutArc::RefreshArc(VSimpleArc *sArc, qint64 arcid, SimpleArc::Translation tr) +void VToolCutArc::RefreshArc(VSimpleArc *sArc, quint32 arcid, SimpleArc::Translation tr) { const VArc *arc = VAbstractTool::data.GeometricObject(arcid); QPainterPath path; diff --git a/src/tools/drawTools/vtoolcutarc.h b/src/tools/drawTools/vtoolcutarc.h index 9d10bcf0a..5d44d47b6 100644 --- a/src/tools/drawTools/vtoolcutarc.h +++ b/src/tools/drawTools/vtoolcutarc.h @@ -51,9 +51,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolCutArc(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, - const qint64 &arcId, const qint64 &arc1id, const qint64 &arc2id, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolCutArc(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &arcId, const quint32 &arc1id, const quint32 &arc2id, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -65,7 +65,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -80,9 +80,9 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const QString &formula, const qint64 &arcId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const QString &formula, const quint32 &arcId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; static const QString AttrArc; public slots: @@ -94,7 +94,7 @@ public slots: * @brief ArcChoosed send signal about selection from cutted arc. * @param id object id in container. */ - void ArcChoosed(qint64 id); + void ArcChoosed(quint32 id); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. @@ -136,7 +136,7 @@ private: /** * @brief arcId keep id of arc */ - qint64 arcId; + quint32 arcId; /** * @brief firstArc first arc after cutting. */ @@ -148,18 +148,18 @@ private: /** * @brief arc1id id first arc after cutting. */ - const qint64 arc1id; + const quint32 arc1id; /** * @brief arc2id id second arc after cutting. */ - const qint64 arc2id; + const quint32 arc2id; /** * @brief RefreshArc refresh arc on scene. * @param sArc arc. * @param arcid arc id. * @param tr arc type. */ - void RefreshArc(VSimpleArc *sArc, qint64 arcid, SimpleArc::Translation tr); + void RefreshArc(VSimpleArc *sArc, quint32 arcid, SimpleArc::Translation tr); }; #endif // VTOOLCUTARC_H diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index b97a97e41..9c0e88a96 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -28,14 +28,14 @@ #include "vtoolcutspline.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogcutspline.h" +#include "../../dialogs/tools/dialogcutspline.h" const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline"); const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); -VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, - const qint64 &splineId, const qint64 &spl1id, const qint64 &spl2id, - const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolCutSpline::VToolCutSpline(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id, + const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), formula(formula), splineId(splineId), firstSpline(), secondSpline(), spl1id(spl1id), spl2id(spl2id) { @@ -44,18 +44,16 @@ VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 Q_ASSERT_X(spl2id > 0, Q_FUNC_INFO, "spl2id <= 0"); firstSpline = new VSimpleSpline(spl1id, ¤tColor, &factor); - Q_CHECK_PTR(firstSpline); RefreshSpline(firstSpline, spl1id, SimpleSpline::ForthPoint); firstSpline->setParentItem(this); connect(firstSpline, &VSimpleSpline::Choosed, this, &VToolCutSpline::SplineChoosed); secondSpline = new VSimpleSpline(spl2id, ¤tColor, &factor); - Q_CHECK_PTR(secondSpline); RefreshSpline(secondSpline, spl2id, SimpleSpline::FirstPoint); secondSpline->setParentItem(this); connect(secondSpline, &VSimpleSpline::Choosed, this, &VToolCutSpline::SplineChoosed); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -77,21 +75,21 @@ void VToolCutSpline::setDialog() } void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) + VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogCutSpline *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); - qint64 splineId = dialogTool->getSplineId(); - Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); + quint32 splineId = dialogTool->getSplineId(); + Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolCutSpline::Create(const qint64 _id, const QString &pointName, - const QString &formula, const qint64 &splineId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolCutSpline::Create(const quint32 _id, const QString &pointName, + const QString &formula, const quint32 &splineId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VSpline *spl = data->GeometricObject(splineId); Calculator cal(data); @@ -100,52 +98,46 @@ void VToolCutSpline::Create(const qint64 _id, const QString &pointName, if (errorMsg.isEmpty()) { QPointF spl1p2, spl1p3, spl2p2, spl2p3; - QPointF point = spl->CutSpline(toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3); + QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3); - qint64 id = _id; - qint64 spl1id = 0; - qint64 spl2id = 0; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + quint32 spl1id = 0; + quint32 spl2id = 0; + if (typeCreation == Valentina::FromGui) { VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); - Q_CHECK_PTR(p != 0); id = data->AddGObject(p); VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); - Q_CHECK_PTR(spline1); spl1id = data->AddGObject(spline1); - data->AddLengthSpline(spline1->name(), toMM(spline1->GetLength())); + data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength())); VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve()); - Q_CHECK_PTR(spline2); spl2id = data->AddGObject(spline2); - data->AddLengthSpline(spline2->name(), toMM(spline2->GetLength())); + data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength())); } else { VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); - Q_CHECK_PTR(p); data->UpdateGObject(id, p); spl1id = id + 1; spl2id = id + 2; VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); - Q_CHECK_PTR(spline1); data->UpdateGObject(spl1id, spline1); - data->AddLengthSpline(spline1->name(), toMM(spline1->GetLength())); + data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength())); VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve()); - Q_CHECK_PTR(spline2); data->UpdateGObject(spl2id, spline2); - data->AddLengthSpline(spline2->name(), toMM(spline2->GetLength())); + data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength())); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::CutSplineTool, doc); + VDrawTool::AddRecord(id, Valentina::CutSplineTool, doc); if (parse == Document::FullParse) { VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation); @@ -166,36 +158,31 @@ void VToolCutSpline::FullUpdateFromFile() if (domElement.isElement()) { formula = domElement.attribute(AttrLength, ""); - splineId = domElement.attribute(AttrSpline, "").toLongLong(); + splineId = domElement.attribute(AttrSpline, "").toUInt(); } RefreshGeometry(); } -void VToolCutSpline::SplineChoosed(qint64 id) +void VToolCutSpline::SplineChoosed(quint32 id) { - emit ChoosedTool(id, Scene::Spline); + emit ChoosedTool(id, Valentina::Spline); } void VToolCutSpline::ChangedActivDraw(const QString &newName) { + bool flag = true; if (nameActivDraw == newName) { currentColor = Qt::black; - firstSpline->setFlag(QGraphicsItem::ItemIsSelectable, true); - firstSpline->setAcceptHoverEvents(true); - secondSpline->setFlag(QGraphicsItem::ItemIsSelectable, true); - secondSpline->setAcceptHoverEvents(true); + flag = true; } else { currentColor = Qt::gray; - firstSpline->setFlag(QGraphicsItem::ItemIsSelectable, false); - firstSpline->setAcceptHoverEvents(false); - secondSpline->setFlag(QGraphicsItem::ItemIsSelectable, false); - secondSpline->setAcceptHoverEvents(false); + flag = false; } - firstSpline->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); - secondSpline->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + firstSpline->ChangedActivDraw(flag); + secondSpline->ChangedActivDraw(flag); VToolPoint::ChangedActivDraw(newName); } @@ -214,14 +201,14 @@ void VToolCutSpline::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrSpline, splineId); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrSpline, splineId); AddToCalculation(domElement); } @@ -232,11 +219,11 @@ void VToolCutSpline::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrSpline, splineId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrSpline, splineId); } } @@ -257,12 +244,12 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogCutSpline *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId())); } -void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr) +void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, quint32 splid, SimpleSpline::Translation tr) { const VSpline *spl = VAbstractTool::data.GeometricObject(splid); QPainterPath path; diff --git a/src/tools/drawTools/vtoolcutspline.h b/src/tools/drawTools/vtoolcutspline.h index bdf971598..5ed16027d 100644 --- a/src/tools/drawTools/vtoolcutspline.h +++ b/src/tools/drawTools/vtoolcutspline.h @@ -49,9 +49,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, - const qint64 &splineId, const qint64 &spl1id, const qint64 &spl2id, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolCutSpline(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -63,7 +63,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -78,10 +78,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, - const QString &formula, const qint64 &splineId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, + const QString &formula, const quint32 &splineId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; static const QString AttrSpline; public slots: @@ -93,7 +93,7 @@ public slots: * @brief SplineChoosed send signal about selection from spline. * @param id object id in container. */ - void SplineChoosed(qint64 id); + void SplineChoosed(quint32 id); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. @@ -139,7 +139,7 @@ private: /** * @brief splineId keep id of spline. */ - qint64 splineId; + quint32 splineId; /** * @brief firstSpline first spline after cutting. */ @@ -151,18 +151,18 @@ private: /** * @brief spl1id id first spline after cutting. */ - const qint64 spl1id; + const quint32 spl1id; /** * @brief spl2id id second spline after cutting. */ - const qint64 spl2id; + const quint32 spl2id; /** * @brief RefreshSpline refresh spline on scene. * @param spline spline. * @param splid spline id. * @param tr spline type. */ - void RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr); + void RefreshSpline(VSimpleSpline *spline, quint32 splid, SimpleSpline::Translation tr); }; #endif // VTOOLCUTSPLINE_H diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index 5a26815c2..da87b2d83 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -28,15 +28,15 @@ #include "vtoolcutsplinepath.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogcutsplinepath.h" +#include "../../dialogs/tools/dialogcutsplinepath.h" const QString VToolCutSplinePath::ToolType = QStringLiteral("cutSplinePath"); const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); -VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &formula, const qint64 &splinePathId, - const qint64 &splPath1id, const qint64 &splPath2id, - const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolCutSplinePath::VToolCutSplinePath(VPattern *doc, VContainer *data, const quint32 &id, + const QString &formula, const quint32 &splinePathId, + const quint32 &splPath1id, const quint32 &splPath2id, + const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), formula(formula), splinePathId(splinePathId), firstSpline(), secondSpline(), splPath1id (splPath1id), splPath2id(splPath2id) { @@ -45,18 +45,16 @@ VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, cons Q_ASSERT_X(splPath2id > 0, Q_FUNC_INFO, "spl2id <= 0"); firstSpline = new VSimpleSpline(splPath1id, ¤tColor, &factor); - Q_CHECK_PTR(firstSpline); RefreshSpline(firstSpline, splPath1id, SimpleSpline::ForthPoint); firstSpline->setParentItem(this); connect(firstSpline, &VSimpleSpline::Choosed, this, &VToolCutSplinePath::SplineChoosed); secondSpline = new VSimpleSpline(splPath2id, ¤tColor, &factor); - Q_CHECK_PTR(secondSpline); RefreshSpline(secondSpline, splPath2id, SimpleSpline::FirstPoint); secondSpline->setParentItem(this); connect(secondSpline, &VSimpleSpline::Choosed, this, &VToolCutSplinePath::SplineChoosed); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -77,53 +75,56 @@ void VToolCutSplinePath::setDialog() dialogTool->setPointName(point->name()); } -void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogCutSplinePath *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); - qint64 splinePathId = dialogTool->getSplinePathId(); - Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); + quint32 splinePathId = dialogTool->getSplinePathId(); + Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, const QString &formula, - const qint64 &splinePathId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, const QString &formula, + const quint32 &splinePathId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VSplinePath *splPath = data->GeometricObject(splinePathId); + Q_CHECK_PTR(splPath); Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); if (errorMsg.isEmpty()) { + quint32 id = _id; QPointF spl1p2, spl1p3, spl2p2, spl2p3; qint32 p1 = 0, p2 = 0; - QPointF point = splPath->CutSplinePath(toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); - qint64 id = _id; - qint64 splPath1id = 0; - qint64 splPath2id = 0; - if (typeCreation == Tool::FromGui) + const QPointF point = splPath->CutSplinePath(qApp->toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); + VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); + if (typeCreation == Valentina::FromGui) { - VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); - Q_CHECK_PTR(p); id = data->AddGObject(p); - splPath1id = id + 1; - splPath2id = id + 2; + } + else + { + data->UpdateGObject(id, p); + } - VSplinePoint splP1 = splPath->at(p1); - VSplinePoint splP2 = splPath->at(p2); - VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve()); - VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve()); + quint32 splPath1id = id + 1; + quint32 splPath2id = id + 2; + VSplinePoint splP1 = splPath->at(p1); + VSplinePoint splP2 = splPath->at(p2); + const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve()); + const VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve()); - VSplinePath *splPath1 = new VSplinePath(); - Q_CHECK_PTR(splPath1); - VSplinePath *splPath2 = new VSplinePath(); - Q_CHECK_PTR(splPath2); + VSplinePath *splPath1 = new VSplinePath(); + VSplinePath *splPath2 = new VSplinePath(); + if (typeCreation == Valentina::FromGui) + { for (qint32 i = 0; i < splPath->CountPoint(); i++) { if (i <= p1 && i < p2) @@ -132,8 +133,8 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), spl1.GetAngle1())); - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), - spl1.GetAngle2()+180, spl1.GetAngle2()); + const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), + spl1.GetAngle2()+180, spl1.GetAngle2()); splPath1->append(cutPoint); continue; } @@ -143,8 +144,8 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { if (i == p2) { - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180, spl2.GetKasm1(), - spl2.GetAngle1()); + const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180, + spl2.GetKasm1(), spl2.GetAngle1()); splPath2->append(cutPoint); splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), spl2.GetAngle2()+180)); @@ -158,29 +159,13 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons splPath2->setMaxCountPoints(splPath->CountPoint()); splPath1id = data->AddGObject(splPath1); - data->AddLengthSpline(splPath1->name(), toMM(splPath1->GetLength())); + data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength())); splPath2id = data->AddGObject(splPath2); - data->AddLengthSpline(splPath2->name(), toMM(splPath2->GetLength())); + data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength())); } else { - VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); - Q_CHECK_PTR(p); - data->UpdateGObject(id, p); - - splPath1id = id + 1; - splPath2id = id + 2; - - VSplinePoint splP1 = splPath->at(p1); - VSplinePoint splP2 = splPath->at(p2); - VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve()); - VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve()); - - VSplinePath *splPath1 = new VSplinePath(); - Q_CHECK_PTR(splPath1); - VSplinePath *splPath2 = new VSplinePath(); - Q_CHECK_PTR(splPath2); for (qint32 i = 0; i < splPath->CountPoint(); i++) { if (i <= p1 && i < p2) @@ -189,8 +174,8 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), spl1.GetAngle1())); - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), - spl2.GetKasm1(), spl1.GetAngle2()+180); + const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), + spl2.GetKasm1(), spl1.GetAngle2()+180); splPath1->append(cutPoint); continue; } @@ -200,8 +185,8 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons { if (i == p2) { - VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180, spl2.GetKasm1(), - spl2.GetAngle1()); + const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180, + spl2.GetKasm1(), spl2.GetAngle1()); splPath2->append(cutPoint); splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), spl2.GetAngle2()+180)); @@ -215,17 +200,17 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons splPath2->setMaxCountPoints(splPath->CountPoint()); data->UpdateGObject(splPath1id, splPath1); - data->AddLengthSpline(splPath1->name(), toMM(splPath1->GetLength())); + data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength())); data->UpdateGObject(splPath2id, splPath2); - data->AddLengthSpline(splPath2->name(), toMM(splPath2->GetLength())); + data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength())); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::CutSplinePathTool, doc); + VDrawTool::AddRecord(id, Valentina::CutSplinePathTool, doc); if (parse == Document::FullParse) { VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, splPath1id, @@ -247,36 +232,31 @@ void VToolCutSplinePath::FullUpdateFromFile() if (domElement.isElement()) { formula = domElement.attribute(AttrLength, ""); - splinePathId = domElement.attribute(AttrSplinePath, "").toLongLong(); + splinePathId = domElement.attribute(AttrSplinePath, "").toUInt(); } RefreshGeometry(); } -void VToolCutSplinePath::SplineChoosed(qint64 id) +void VToolCutSplinePath::SplineChoosed(quint32 id) { - emit ChoosedTool(id, Scene::SplinePath); + emit ChoosedTool(id, Valentina::SplinePath); } void VToolCutSplinePath::ChangedActivDraw(const QString &newName) { + bool flag = true; if (nameActivDraw == newName) { currentColor = Qt::black; - firstSpline->setFlag(QGraphicsItem::ItemIsSelectable, true); - firstSpline->setAcceptHoverEvents(true); - secondSpline->setFlag(QGraphicsItem::ItemIsSelectable, true); - secondSpline->setAcceptHoverEvents(true); + flag = true; } else { currentColor = Qt::gray; - firstSpline->setFlag(QGraphicsItem::ItemIsSelectable, false); - firstSpline->setAcceptHoverEvents(false); - secondSpline->setFlag(QGraphicsItem::ItemIsSelectable, false); - secondSpline->setAcceptHoverEvents(false); + flag = false; } - firstSpline->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); - secondSpline->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + firstSpline->ChangedActivDraw(flag); + secondSpline->ChangedActivDraw(flag); VToolPoint::ChangedActivDraw(newName); } @@ -295,14 +275,14 @@ void VToolCutSplinePath::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrSplinePath, splinePathId); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrSplinePath, splinePathId); AddToCalculation(domElement); } @@ -313,11 +293,11 @@ void VToolCutSplinePath::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrSplinePath, splinePathId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrSplinePath, splinePathId); } } @@ -338,12 +318,12 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogCutSplinePath *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId())); } -void VToolCutSplinePath::RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr) +void VToolCutSplinePath::RefreshSpline(VSimpleSpline *spline, quint32 splPathid, SimpleSpline::Translation tr) { const VSplinePath *splPath = VAbstractTool::data.GeometricObject(splPathid); QPainterPath path; diff --git a/src/tools/drawTools/vtoolcutsplinepath.h b/src/tools/drawTools/vtoolcutsplinepath.h index 7a13d2e5e..08b319439 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.h +++ b/src/tools/drawTools/vtoolcutsplinepath.h @@ -52,9 +52,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolCutSplinePath(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, - const qint64 &splinePathId, const qint64 &splPath1id, const qint64 &splPath2id, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolCutSplinePath(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &splinePathId, const quint32 &splPath1id, const quint32 &splPath2id, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -66,7 +66,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,10 +81,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const QString &formula, - const qint64 &splinePathId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const QString &formula, + const quint32 &splinePathId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); static const QString ToolType; static const QString AttrSplinePath; public slots: @@ -96,7 +96,7 @@ public slots: * @brief SplineChoosed send signal about selection splinePath. * @param id object id in container. */ - void SplineChoosed(qint64 id); + void SplineChoosed(quint32 id); /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @param newName new name active pattern peace. @@ -142,7 +142,7 @@ private: /** * @brief splineId keep id of spline. */ - qint64 splinePathId; + quint32 splinePathId; /** * @brief firstSpline first splinePath after cutting. */ @@ -154,18 +154,18 @@ private: /** * @brief splPath1id id first splinePath after cutting. */ - const qint64 splPath1id; + const quint32 splPath1id; /** * @brief splPath2id id second splinePath after cutting. */ - const qint64 splPath2id; + const quint32 splPath2id; /** * @brief RefreshSpline refresh splinePath on scene. * @param spline splinePath. * @param splPathid splinePath id. * @param tr splineType type. */ - void RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr); + void RefreshSpline(VSimpleSpline *spline, quint32 splPathid, SimpleSpline::Translation tr); }; #endif // VTOOLCUTSPLINEPATH_H diff --git a/src/tools/drawTools/vtoolendline.cpp b/src/tools/drawTools/vtoolendline.cpp index efe9c6a9b..98603c373 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -29,17 +29,17 @@ #include "vtoolendline.h" #include "../../widgets/vmaingraphicsscene.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogendline.h" +#include "../../dialogs/tools/dialogendline.h" const QString VToolEndLine::ToolType = QStringLiteral("endLine"); -VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &basePointId, - const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolEndLine::VToolEndLine(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const qreal &angle, const quint32 &basePointId, + const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent) { - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -62,7 +62,7 @@ void VToolEndLine::setDialog() dialogTool->setPointName(p->name()); } -void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); @@ -72,15 +72,15 @@ void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDoc QString typeLine = dialogTool->getTypeLine(); QString formula = dialogTool->getFormula(); qreal angle = dialogTool->getAngle(); - qint64 basePointId = dialogTool->getBasePointId(); + quint32 basePointId = dialogTool->getBasePointId(); Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, - Tool::FromGui); + Valentina::FromGui); } -void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &basePointId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qreal &angle, const quint32 &basePointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *basePoint = data->GeometricObject(basePointId); QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); @@ -89,10 +89,10 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr qreal result = cal.eval(formula, &errorMsg); if (errorMsg.isEmpty()) { - line.setLength(toPixel(result)); + line.setLength(qApp->toPixel(result)); line.setAngle(angle); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); data->AddLine(basePointId, id); @@ -106,7 +106,7 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::EndLineTool, doc); + VDrawTool::AddRecord(id, Valentina::EndLineTool, doc); if (parse == Document::FullParse) { VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, @@ -127,7 +127,7 @@ void VToolEndLine::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); + basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); angle = domElement.attribute(AttrAngle, "").toInt(); } RefreshGeometry(); @@ -148,16 +148,16 @@ void VToolEndLine::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrAngle, angle); - SetAttribute(domElement, AttrBasePoint, basePointId); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrAngle, angle); + doc->SetAttribute(domElement, AttrBasePoint, basePointId); AddToCalculation(domElement); } @@ -168,13 +168,13 @@ void VToolEndLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrAngle, angle); - SetAttribute(domElement, AttrBasePoint, basePointId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrAngle, angle); + doc->SetAttribute(domElement, AttrBasePoint, basePointId); } } @@ -183,9 +183,9 @@ void VToolEndLine::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogEndLine *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); - SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); + doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); } diff --git a/src/tools/drawTools/vtoolendline.h b/src/tools/drawTools/vtoolendline.h index a8b3c4992..f386e360e 100644 --- a/src/tools/drawTools/vtoolendline.h +++ b/src/tools/drawTools/vtoolendline.h @@ -50,9 +50,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &basePointId, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolEndLine(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const qreal &angle, const quint32 &basePointId, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,10 +81,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &basePointId, const qreal &mx, - const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qreal &angle, const quint32 &basePointId, const qreal &mx, + const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** diff --git a/src/tools/drawTools/vtoolheight.cpp b/src/tools/drawTools/vtoolheight.cpp index 089218d64..5a0640718 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -27,17 +27,17 @@ *************************************************************************/ #include "vtoolheight.h" -#include "../../dialogs/dialogheight.h" +#include "../../dialogs/tools/dialogheight.h" const QString VToolHeight::ToolType = QStringLiteral("height"); -VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, - const Tool::Sources &typeCreation, QGraphicsItem * parent) +VToolHeight::VToolHeight(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, + const Valentina::Sources &typeCreation, QGraphicsItem * parent) :VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), p1LineId(p1LineId), p2LineId(p2LineId) { ignoreFullUpdate = true; - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -60,34 +60,34 @@ void VToolHeight::setDialog() dialogTool->setPointName(p->name()); } -void VToolHeight::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolHeight::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogHeight *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogTool, &DialogHeight::UpdateList); + disconnect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogHeight::UpdateList); QString pointName = dialogTool->getPointName(); QString typeLine = dialogTool->getTypeLine(); - qint64 basePointId = dialogTool->getBasePointId(); - qint64 p1LineId = dialogTool->getP1LineId(); - qint64 p2LineId = dialogTool->getP2LineId(); + quint32 basePointId = dialogTool->getBasePointId(); + quint32 p1LineId = dialogTool->getP1LineId(); + quint32 p2LineId = dialogTool->getP2LineId(); Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolHeight::Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolHeight::Create(const quint32 _id, const QString &pointName, const QString &typeLine, + const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *basePoint = data->GeometricObject(basePointId); const VPointF *p1Line = data->GeometricObject(p1LineId); const VPointF *p2Line = data->GeometricObject(p2LineId); QPointF pHeight = FindPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()), basePoint->toQPointF()); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(pHeight.x(), pHeight.y(), pointName, mx, my)); data->AddLine(basePointId, id); @@ -105,7 +105,7 @@ void VToolHeight::Create(const qint64 _id, const QString &pointName, const QStri doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::Height, doc); + VDrawTool::AddRecord(id, Valentina::Height, doc); if (parse == Document::FullParse) { VToolHeight *point = new VToolHeight(doc, data, id, typeLine, basePointId, p1LineId, p2LineId, @@ -131,9 +131,9 @@ void VToolHeight::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); - p1LineId = domElement.attribute(AttrP1Line, "").toLongLong(); - p2LineId = domElement.attribute(AttrP2Line, "").toLongLong(); + basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); + p1LineId = domElement.attribute(AttrP1Line, "").toUInt(); + p2LineId = domElement.attribute(AttrP2Line, "").toUInt(); } RefreshGeometry(); @@ -154,16 +154,16 @@ void VToolHeight::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrBasePoint, basePointId); - SetAttribute(domElement, AttrP1Line, p1LineId); - SetAttribute(domElement, AttrP2Line, p2LineId); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrBasePoint, basePointId); + doc->SetAttribute(domElement, AttrP1Line, p1LineId); + doc->SetAttribute(domElement, AttrP2Line, p2LineId); AddToCalculation(domElement); @@ -175,13 +175,13 @@ void VToolHeight::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrBasePoint, basePointId); - SetAttribute(domElement, AttrP1Line, p1LineId); - SetAttribute(domElement, AttrP2Line, p2LineId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrBasePoint, basePointId); + doc->SetAttribute(domElement, AttrP1Line, p1LineId); + doc->SetAttribute(domElement, AttrP2Line, p2LineId); } } @@ -190,9 +190,9 @@ void VToolHeight::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogHeight *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); - SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); - SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1LineId())); - SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2LineId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); + doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1LineId())); + doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2LineId())); } diff --git a/src/tools/drawTools/vtoolheight.h b/src/tools/drawTools/vtoolheight.h index 085407efb..ce1105806 100644 --- a/src/tools/drawTools/vtoolheight.h +++ b/src/tools/drawTools/vtoolheight.h @@ -50,9 +50,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolHeight(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,10 +81,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, + const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); /** * @brief FindPoint find projection base point onto line. * @param line line @@ -125,11 +125,11 @@ private: /** * @brief p1LineId id first point of line. */ - qint64 p1LineId; + quint32 p1LineId; /** * @brief p2LineId id second point of line. */ - qint64 p2LineId; + quint32 p2LineId; }; #endif // VTOOLHEIGHT_H diff --git a/src/tools/drawTools/vtoolline.cpp b/src/tools/drawTools/vtoolline.cpp index e4723dc35..e62d9f09f 100644 --- a/src/tools/drawTools/vtoolline.cpp +++ b/src/tools/drawTools/vtoolline.cpp @@ -27,12 +27,12 @@ *************************************************************************/ #include "vtoolline.h" -#include "../../dialogs/dialogline.h" +#include "../../dialogs/tools/dialogline.h" const QString VToolLine::TagName = QStringLiteral("line"); -VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, - const QString &typeLine, const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolLine::VToolLine(VPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, + const QString &typeLine, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint) { this->typeLine = typeLine; @@ -45,9 +45,9 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); - this->setPen(QPen(Qt::black, toPixel(widthHairLine)/factor, LineStyle())); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -67,26 +67,26 @@ void VToolLine::setDialog() dialogTool->setTypeLine(typeLine); } -void VToolLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogLine *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - qint64 firstPoint = dialogTool->getFirstPoint(); - qint64 secondPoint = dialogTool->getSecondPoint(); + quint32 firstPoint = dialogTool->getFirstPoint(); + quint32 secondPoint = dialogTool->getSecondPoint(); QString typeLine = dialogTool->getTypeLine(); - Create(0, firstPoint, secondPoint, typeLine, scene, doc, data, Document::FullParse, Tool::FromGui); + Create(0, firstPoint, secondPoint, typeLine, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, const QString &typeLine, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint, + const QString &typeLine, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { Q_CHECK_PTR(scene); Q_CHECK_PTR(doc); Q_CHECK_PTR(data); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->getNextId(); data->AddLine(firstPoint, secondPoint); @@ -100,11 +100,10 @@ void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::LineTool, doc); + VDrawTool::AddRecord(id, Valentina::LineTool, doc); if (parse == Document::FullParse) { VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, typeCreation); - Q_CHECK_PTR(line); scene->addItem(line); connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, line, &VToolLine::SetFactor); @@ -119,7 +118,7 @@ void VToolLine::FullUpdateFromFile() RefreshGeometry(); } -void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +void VToolLine::ShowTool(quint32 id, Qt::GlobalColor color, bool enable) { ShowItem(this, id, color, enable); } @@ -143,7 +142,7 @@ void VToolLine::ChangedActivDraw(const QString &newName) selectable = false; currentColor = Qt::gray; } - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor, LineStyle())); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); this->setAcceptHoverEvents (selectable); VDrawTool::ChangedActivDraw(newName); } @@ -156,10 +155,10 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VToolLine::AddToFile() { QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrFirstPoint, firstPoint); - SetAttribute(domElement, AttrSecondPoint, secondPoint); - SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); + doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); AddToCalculation(domElement); } @@ -169,22 +168,22 @@ void VToolLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrFirstPoint, firstPoint); - SetAttribute(domElement, AttrSecondPoint, secondPoint); - SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); + doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); } } void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine)/factor, LineStyle())); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, LineStyle())); } void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor, LineStyle())); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); } void VToolLine::RemoveReferens() @@ -229,9 +228,9 @@ void VToolLine::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogLine *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); + doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); } void VToolLine::RefreshGeometry() @@ -239,12 +238,12 @@ void VToolLine::RefreshGeometry() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - firstPoint = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - secondPoint = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); + firstPoint = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + secondPoint = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); typeLine = doc->GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); } const VPointF *first = VAbstractTool::data.GeometricObject(firstPoint); const VPointF *second = VAbstractTool::data.GeometricObject(secondPoint); this->setLine(QLineF(first->toQPointF(), second->toQPointF())); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor, LineStyle())); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); } diff --git a/src/tools/drawTools/vtoolline.h b/src/tools/drawTools/vtoolline.h index 169cc77f0..be951fb59 100644 --- a/src/tools/drawTools/vtoolline.h +++ b/src/tools/drawTools/vtoolline.h @@ -31,7 +31,7 @@ #include "vdrawtool.h" #include -#include "../../dialogs/dialogline.h" +#include "../../dialogs/tools/dialogline.h" /** * @brief The VToolLine class tool for creation line. @@ -51,9 +51,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, - qint64 secondPoint, const QString &typeLine, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0); + VToolLine(VPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, + quint32 secondPoint, const QString &typeLine, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -65,7 +65,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -78,9 +78,9 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, const QString &typeLine, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint, + const QString &typeLine, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString TagName; public slots: /** @@ -98,7 +98,7 @@ public slots: * @param color highlight color. * @param enable enable or disable highlight. */ - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -152,11 +152,11 @@ private: /** * @brief firstPoint id first line point. */ - qint64 firstPoint; + quint32 firstPoint; /** * @brief secondPoint id second line point. */ - qint64 secondPoint; + quint32 secondPoint; /** * @brief RefreshGeometry refresh item on scene. */ diff --git a/src/tools/drawTools/vtoollineintersect.cpp b/src/tools/drawTools/vtoollineintersect.cpp index a947d08ef..9598a3873 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -27,19 +27,19 @@ *************************************************************************/ #include "vtoollineintersect.h" -#include "../../dialogs/dialoglineintersect.h" +#include "../../dialogs/tools/dialoglineintersect.h" const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect"); -VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, - const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, const Tool::Sources &typeCreation, +VToolLineIntersect::VToolLineIntersect(VPattern *doc, VContainer *data, const quint32 &id, + const quint32 &p1Line1, const quint32 &p2Line1, const quint32 &p1Line2, + const quint32 &p2Line2, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), p2Line2(p2Line2) { ignoreFullUpdate = true; - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -62,25 +62,25 @@ void VToolLineIntersect::setDialog() dialogTool->setPointName(p->name()); } -void VToolLineIntersect::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolLineIntersect::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogLineIntersect *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - qint64 p1Line1Id = dialogTool->getP1Line1(); - qint64 p2Line1Id = dialogTool->getP2Line1(); - qint64 p1Line2Id = dialogTool->getP1Line2(); - qint64 p2Line2Id = dialogTool->getP2Line2(); + quint32 p1Line1Id = dialogTool->getP1Line1(); + quint32 p2Line1Id = dialogTool->getP2Line1(); + quint32 p1Line2Id = dialogTool->getP1Line2(); + quint32 p2Line2Id = dialogTool->getP2Line2(); QString pointName = dialogTool->getPointName(); Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, - const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, +void VToolLineIntersect::Create(const quint32 _id, const quint32 &p1Line1Id, const quint32 &p2Line1Id, + const quint32 &p1Line2Id, const quint32 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation) + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation) { const VPointF *p1Line1 = data->GeometricObject(p1Line1Id); const VPointF *p2Line1 = data->GeometricObject(p2Line1Id); @@ -93,8 +93,8 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) { - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); data->AddLine(p1Line1Id, id); @@ -114,7 +114,7 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::LineIntersectTool, doc); + VDrawTool::AddRecord(id, Valentina::LineIntersectTool, doc); if (parse == Document::FullParse) { VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, @@ -136,10 +136,10 @@ void VToolLineIntersect::FullUpdateFromFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - p1Line1 = domElement.attribute(AttrP1Line1, "").toLongLong(); - p2Line1 = domElement.attribute(AttrP2Line1, "").toLongLong(); - p1Line2 = domElement.attribute(AttrP1Line2, "").toLongLong(); - p2Line2 = domElement.attribute(AttrP2Line2, "").toLongLong(); + p1Line1 = domElement.attribute(AttrP1Line1, "").toUInt(); + p2Line1 = domElement.attribute(AttrP2Line1, "").toUInt(); + p1Line2 = domElement.attribute(AttrP1Line2, "").toUInt(); + p2Line2 = domElement.attribute(AttrP2Line2, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } @@ -165,16 +165,16 @@ void VToolLineIntersect::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrP1Line1, p1Line1); - SetAttribute(domElement, AttrP2Line1, p2Line1); - SetAttribute(domElement, AttrP1Line2, p1Line2); - SetAttribute(domElement, AttrP2Line2, p2Line2); + doc->SetAttribute(domElement, AttrP1Line1, p1Line1); + doc->SetAttribute(domElement, AttrP2Line1, p2Line1); + doc->SetAttribute(domElement, AttrP1Line2, p1Line2); + doc->SetAttribute(domElement, AttrP2Line2, p2Line2); AddToCalculation(domElement); } @@ -185,13 +185,13 @@ void VToolLineIntersect::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrP1Line1, p1Line1); - SetAttribute(domElement, AttrP2Line1, p2Line1); - SetAttribute(domElement, AttrP1Line2, p1Line2); - SetAttribute(domElement, AttrP2Line2, p2Line2); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrP1Line1, p1Line1); + doc->SetAttribute(domElement, AttrP2Line1, p2Line1); + doc->SetAttribute(domElement, AttrP1Line2, p1Line2); + doc->SetAttribute(domElement, AttrP2Line2, p2Line2); } } @@ -208,9 +208,9 @@ void VToolLineIntersect::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogLineIntersect *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrP1Line1, QString().setNum(dialogTool->getP1Line1())); - SetAttribute(domElement, AttrP2Line1, QString().setNum(dialogTool->getP2Line1())); - SetAttribute(domElement, AttrP1Line2, QString().setNum(dialogTool->getP1Line2())); - SetAttribute(domElement, AttrP2Line2, QString().setNum(dialogTool->getP2Line2())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrP1Line1, QString().setNum(dialogTool->getP1Line1())); + doc->SetAttribute(domElement, AttrP2Line1, QString().setNum(dialogTool->getP2Line1())); + doc->SetAttribute(domElement, AttrP1Line2, QString().setNum(dialogTool->getP1Line2())); + doc->SetAttribute(domElement, AttrP2Line2, QString().setNum(dialogTool->getP2Line2())); } diff --git a/src/tools/drawTools/vtoollineintersect.h b/src/tools/drawTools/vtoollineintersect.h index f39dc0b6e..521458048 100644 --- a/src/tools/drawTools/vtoollineintersect.h +++ b/src/tools/drawTools/vtoollineintersect.h @@ -50,9 +50,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &p1Line1, - const qint64 &p2Line1, const qint64 &p1Line2, const qint64 &p2Line2, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolLineIntersect(VPattern *doc, VContainer *data, const quint32 &id, const quint32 &p1Line1, + const quint32 &p2Line1, const quint32 &p1Line2, const quint32 &p2Line2, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,10 +81,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, const qint64 &p1Line2Id, - const qint64 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const quint32 &p1Line1Id, const quint32 &p2Line1Id, const quint32 &p1Line2Id, + const quint32 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** @@ -127,19 +127,19 @@ private: /** * @brief p1Line1 id first point first line. */ - qint64 p1Line1; + quint32 p1Line1; /** * @brief p2Line1 id second point first line. */ - qint64 p2Line1; + quint32 p2Line1; /** * @brief p1Line2 id first point second line. */ - qint64 p1Line2; + quint32 p1Line2; /** * @brief p2Line2 id second point second line. */ - qint64 p2Line2; + quint32 p2Line2; }; #endif // VTOOLLINEINTERSECT_H diff --git a/src/tools/drawTools/vtoollinepoint.cpp b/src/tools/drawTools/vtoollinepoint.cpp index e277335b5..7c7bde930 100644 --- a/src/tools/drawTools/vtoollinepoint.cpp +++ b/src/tools/drawTools/vtoollinepoint.cpp @@ -28,18 +28,18 @@ #include "vtoollinepoint.h" -VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &basePointId, +VToolLinePoint::VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &id, + const QString &typeLine, const QString &formula, const quint32 &basePointId, const qreal &angle, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), formula(formula), angle(angle), basePointId(basePointId), - mainLine(0) + mainLine(nullptr) { this->typeLine = typeLine; Q_ASSERT_X(basePointId > 0, Q_FUNC_INFO, "basePointId <= 0"); QPointF point1 = data->GeometricObject(basePointId)->toQPointF(); QPointF point2 = data->GeometricObject(id)->toQPointF(); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); - mainLine->setPen(QPen(Qt::black, toPixel(widthHairLine)/factor, LineStyle())); + mainLine->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -53,13 +53,13 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName) { currentColor = Qt::gray; } - mainLine->setPen(QPen(currentColor, toPixel(widthHairLine)/factor, LineStyle())); + mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); VToolPoint::ChangedActivDraw(newName); } void VToolLinePoint::RefreshGeometry() { - mainLine->setPen(QPen(currentColor, toPixel(widthHairLine)/factor, LineStyle())); + mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle())); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); QPointF point = VDrawTool::data.GeometricObject(id)->toQPointF(); QPointF basePoint = VDrawTool::data.GeometricObject(basePointId)->toQPointF(); diff --git a/src/tools/drawTools/vtoollinepoint.h b/src/tools/drawTools/vtoollinepoint.h index 2ba9bd9ab..52628620a 100644 --- a/src/tools/drawTools/vtoollinepoint.h +++ b/src/tools/drawTools/vtoollinepoint.h @@ -49,9 +49,9 @@ public: * @param angle line angle. * @param parent parent object. */ - VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qint64 &basePointId, const qreal &angle, - QGraphicsItem * parent = 0); + VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const quint32 &basePointId, const qreal &angle, + QGraphicsItem * parent = nullptr); public slots: /** * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. @@ -75,7 +75,7 @@ protected: /** * @brief basePointId id base line point. */ - qint64 basePointId; + quint32 basePointId; /** * @brief mainLine line item. */ diff --git a/src/tools/drawTools/vtoolnormal.cpp b/src/tools/drawTools/vtoolnormal.cpp index 38b84591e..83b00e6af 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -28,18 +28,18 @@ #include "vtoolnormal.h" #include "../../container/calculator.h" -#include "../../dialogs/dialognormal.h" +#include "../../dialogs/tools/dialognormal.h" const QString VToolNormal::ToolType = QStringLiteral("normal"); -VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolNormal::VToolNormal(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const qreal &angle, const quint32 &firstPointId, + const quint32 &secondPointId, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), secondPointId(secondPointId) { - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -63,26 +63,26 @@ void VToolNormal::setDialog() dialogTool->setPointName(p->name()); } -void VToolNormal::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolNormal::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogNormal *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString formula = dialogTool->getFormula(); - qint64 firstPointId = dialogTool->getFirstPointId(); - qint64 secondPointId = dialogTool->getSecondPointId(); + quint32 firstPointId = dialogTool->getFirstPointId(); + quint32 secondPointId = dialogTool->getSecondPointId(); QString typeLine = dialogTool->getTypeLine(); QString pointName = dialogTool->getPointName(); qreal angle = dialogTool->getAngle(); Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const QString &typeLine, const QString &pointName, +void VToolNormal::Create(const quint32 _id, const QString &formula, const quint32 &firstPointId, + const quint32 &secondPointId, const QString &typeLine, const QString &pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation) + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation) { const VPointF *firstPoint = data->GeometricObject(firstPointId); const VPointF *secondPoint = data->GeometricObject(secondPointId); @@ -92,9 +92,9 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 if (errorMsg.isEmpty()) { QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), - toPixel(result), angle); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + qApp->toPixel(result), angle); + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); data->AddLine(firstPointId, id); @@ -108,7 +108,7 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::NormalTool, doc); + VDrawTool::AddRecord(id, Valentina::NormalTool, doc); if (parse == Document::FullParse) { VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, @@ -140,8 +140,8 @@ void VToolNormal::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); angle = domElement.attribute(AttrAngle, "").toDouble(); } RefreshGeometry(); @@ -168,17 +168,17 @@ void VToolNormal::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrAngle, angle); - SetAttribute(domElement, AttrFirstPoint, basePointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrAngle, angle); + doc->SetAttribute(domElement, AttrFirstPoint, basePointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } @@ -189,14 +189,14 @@ void VToolNormal::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrAngle, angle); - SetAttribute(domElement, AttrFirstPoint, basePointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrAngle, angle); + doc->SetAttribute(domElement, AttrFirstPoint, basePointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } } @@ -211,10 +211,10 @@ void VToolNormal::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogNormal *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); + doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } diff --git a/src/tools/drawTools/vtoolnormal.h b/src/tools/drawTools/vtoolnormal.h index 018374b8d..da1d0170b 100644 --- a/src/tools/drawTools/vtoolnormal.h +++ b/src/tools/drawTools/vtoolnormal.h @@ -51,10 +51,10 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0); + VToolNormal(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const qreal &angle, const quint32 &firstPointId, + const quint32 &secondPointId, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -66,7 +66,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -84,11 +84,11 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const QString &typeLine, const QString &pointName, + static void Create(const quint32 _id, const QString &formula, const quint32 &firstPointId, + const quint32 &secondPointId, const QString &typeLine, const QString &pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); /** * @brief FindPoint return normal point. * @param firstPoint first line point. @@ -141,7 +141,7 @@ private: /** * @brief secondPointId id second line point. */ - qint64 secondPointId; + quint32 secondPointId; }; #endif // VTOOLNORMAL_H diff --git a/src/tools/drawTools/vtoolpoint.cpp b/src/tools/drawTools/vtoolpoint.cpp index 7d618cd14..f4ae47e14 100644 --- a/src/tools/drawTools/vtoolpoint.cpp +++ b/src/tools/drawTools/vtoolpoint.cpp @@ -30,15 +30,31 @@ const QString VToolPoint::TagName = QStringLiteral("point"); -VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem *parent):VDrawTool(doc, data, id), - QGraphicsEllipseItem(parent), radius(toPixel(2)), namePoint(0), lineName(0) +#define DefRadius 2.0//mm + +VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent):VDrawTool(doc, data, id), + QGraphicsEllipseItem(parent), radius(DefRadius), namePoint(0), lineName(0) { + switch(qApp->patternUnit()) + { + case Valentina::Mm: + radius = qApp->toPixel(DefRadius); + break; + case Valentina::Cm: + radius = qApp->toPixel(DefRadius/10.0); + break; + case Valentina::Inch: + radius = qApp->toPixel(DefRadius/25.4); + break; + default: + radius = qApp->toPixel(DefRadius); + break; + } + namePoint = new VGraphicsSimpleTextItem(this); - Q_CHECK_PTR(namePoint); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu); namePoint->setBrush(Qt::black); lineName = new QGraphicsLineItem(this); - Q_CHECK_PTR(lineName); lineName->setPen(QPen(Qt::black)); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); this->setBrush(QBrush(Qt::NoBrush)); @@ -51,7 +67,6 @@ VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphics void VToolPoint::NameChangePosition(const QPointF &pos) { VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); - Q_CHECK_PTR(point); QPointF p = pos - this->pos(); point->setMx(p.x()); point->setMy(p.y()); @@ -65,8 +80,8 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my) QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrMx, toMM(mx)); - SetAttribute(domElement, AttrMy, toMM(my)); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(mx)); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(my)); emit toolhaveChange(); } } @@ -84,7 +99,7 @@ void VToolPoint::ChangedActivDraw(const QString &newName) selectable = false; currentColor = Qt::gray; } - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); this->setAcceptHoverEvents (selectable); namePoint->setFlag(QGraphicsItem::ItemIsMovable, selectable); @@ -92,11 +107,11 @@ void VToolPoint::ChangedActivDraw(const QString &newName) namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, selectable); namePoint->setBrush(QBrush(currentColor)); namePoint->setAcceptHoverEvents(selectable); - lineName->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + lineName->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); VDrawTool::ChangedActivDraw(newName); } -void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +void VToolPoint::ShowTool(quint32 id, Qt::GlobalColor color, bool enable) { ShowItem(this, id, color, enable); } @@ -116,7 +131,7 @@ void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Point); + emit ChoosedTool(id, Valentina::Point); } QGraphicsItem::mouseReleaseEvent(event); } @@ -124,31 +139,29 @@ void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor)); } void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); } void VToolPoint::RefreshPointGeometry(const VPointF &point) { - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); this->setPos(point.toQPointF()); - disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VToolPoint::NameChangePosition); + disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); QFont font = namePoint->font(); font.setPointSize(static_cast(namePoint->FontSize()/factor)); namePoint->setFont(font); namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VToolPoint::NameChangePosition); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); RefreshLine(); } @@ -161,13 +174,13 @@ void VToolPoint::RefreshLine() lineName->setLine(QLineF(p1, pRec - scenePos())); if (currentColor == Qt::gray) { - lineName->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + lineName->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); } else { - lineName->setPen(QPen(Qt::black, toPixel(widthHairLine)/factor)); + lineName->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); } - if (QLineF(p1, pRec - scenePos()).length() <= toPixel(4)) + if (QLineF(p1, pRec - scenePos()).length() <= qApp->toPixel(4)) { lineName->setVisible(false); } diff --git a/src/tools/drawTools/vtoolpoint.h b/src/tools/drawTools/vtoolpoint.h index 23c4ae4f2..4622d6bc9 100644 --- a/src/tools/drawTools/vtoolpoint.h +++ b/src/tools/drawTools/vtoolpoint.h @@ -46,7 +46,7 @@ public: * @param id object id in container. * @param parent parent object. */ - VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); + VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); virtual ~VToolPoint(){} static const QString TagName; public slots: @@ -66,7 +66,7 @@ public slots: * @param color highlight color. * @param enable enable or disable highlight. */ - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. diff --git a/src/tools/drawTools/vtoolpointofcontact.cpp b/src/tools/drawTools/vtoolpointofcontact.cpp index 3516678a3..b1221b45e 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -28,18 +28,18 @@ #include "vtoolpointofcontact.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogpointofcontact.h" +#include "../../dialogs/tools/dialogpointofcontact.h" const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); -VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &radius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, - const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolPointOfContact::VToolPointOfContact(VPattern *doc, VContainer *data, const quint32 &id, + const QString &radius, const quint32 ¢er, + const quint32 &firstPointId, const quint32 &secondPointId, + const Valentina::Sources &typeCreation, QGraphicsItem *parent) : VToolPoint(doc, data, id, parent), arcRadius(radius), center(center), firstPointId(firstPointId), secondPointId(secondPointId) { - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -88,25 +88,25 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e return pArc; } -void VToolPointOfContact::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolPointOfContact::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogPointOfContact *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString radius = dialogTool->getRadius(); - qint64 center = dialogTool->getCenter(); - qint64 firstPointId = dialogTool->getFirstPoint(); - qint64 secondPointId = dialogTool->getSecondPoint(); + quint32 center = dialogTool->getCenter(); + quint32 firstPointId = dialogTool->getFirstPoint(); + quint32 secondPointId = dialogTool->getSecondPoint(); QString pointName = dialogTool->getPointName(); Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, +void VToolPointOfContact::Create(const quint32 _id, const QString &radius, const quint32 ¢er, + const quint32 &firstPointId, const quint32 &secondPointId, const QString &pointName, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *centerP = data->GeometricObject(center); const VPointF *firstP = data->GeometricObject(firstPointId); @@ -117,10 +117,10 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const qreal result = cal.eval(radius, &errorMsg); if (errorMsg.isEmpty()) { - QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP->toQPointF(), + QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(), firstP->toQPointF(), secondP->toQPointF()); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); data->AddLine(firstPointId, id); @@ -138,7 +138,7 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::PointOfContact, doc); + VDrawTool::AddRecord(id, Valentina::PointOfContact, doc); if (parse == Document::FullParse) { VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center, @@ -160,9 +160,9 @@ void VToolPointOfContact::FullUpdateFromFile() if (domElement.isElement()) { arcRadius = domElement.attribute(AttrRadius, ""); - center = domElement.attribute(AttrCenter, "").toLongLong(); - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + center = domElement.attribute(AttrCenter, "").toUInt(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } @@ -188,16 +188,16 @@ void VToolPointOfContact::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrRadius, arcRadius); - SetAttribute(domElement, AttrCenter, center); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrRadius, arcRadius); + doc->SetAttribute(domElement, AttrCenter, center); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } @@ -208,13 +208,13 @@ void VToolPointOfContact::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrRadius, arcRadius); - SetAttribute(domElement, AttrCenter, center); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrRadius, arcRadius); + doc->SetAttribute(domElement, AttrCenter, center); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } } @@ -230,9 +230,9 @@ void VToolPointOfContact::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogPointOfContact *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrRadius, dialogTool->getRadius()); - SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->getCenter())); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrRadius, dialogTool->getRadius()); + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->getCenter())); + doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); + doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); } diff --git a/src/tools/drawTools/vtoolpointofcontact.h b/src/tools/drawTools/vtoolpointofcontact.h index 0855537c8..0199dbdba 100644 --- a/src/tools/drawTools/vtoolpointofcontact.h +++ b/src/tools/drawTools/vtoolpointofcontact.h @@ -49,10 +49,10 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &arcRadius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolPointOfContact(VPattern *doc, VContainer *data, const quint32 &id, + const QString &arcRadius, const quint32 ¢er, + const quint32 &firstPointId, const quint32 &secondPointId, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -74,7 +74,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -91,10 +91,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &arcRadius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &arcRadius, const quint32 ¢er, + const quint32 &firstPointId, const quint32 &secondPointId, const QString &pointName, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** @@ -141,15 +141,15 @@ private: /** * @brief center id center arc point. */ - qint64 center; + quint32 center; /** * @brief firstPointId id first line point. */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second line point. */ - qint64 secondPointId; + quint32 secondPointId; }; #endif // VTOOLPOINTOFCONTACT_H diff --git a/src/tools/drawTools/vtoolpointofintersection.cpp b/src/tools/drawTools/vtoolpointofintersection.cpp index c9e84e23e..c66fc0c04 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -27,17 +27,17 @@ *************************************************************************/ #include "vtoolpointofintersection.h" -#include "../../dialogs/dialogpointofintersection.h" +#include "../../dialogs/tools/dialogpointofintersection.h" const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfIntersection"); -VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, - const qint64 &firstPointId, const qint64 &secondPointId, - const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolPointOfIntersection::VToolPointOfIntersection(VPattern *doc, VContainer *data, const quint32 &id, + const quint32 &firstPointId, const quint32 &secondPointId, + const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId) { ignoreFullUpdate = true; - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -58,29 +58,29 @@ void VToolPointOfIntersection::setDialog() dialogTool->setPointName(p->name()); } -void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogPointOfIntersection *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - qint64 firstPointId = dialogTool->getFirstPointId(); - qint64 secondPointId = dialogTool->getSecondPointId(); + quint32 firstPointId = dialogTool->getFirstPointId(); + quint32 secondPointId = dialogTool->getSecondPointId(); QString pointName = dialogTool->getPointName(); - Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); + Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolPointOfIntersection::Create(const qint64 _id, const QString &pointName, const qint64 &firstPointId, - const qint64 &secondPointId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolPointOfIntersection::Create(const quint32 _id, const QString &pointName, const quint32 &firstPointId, + const quint32 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *firstPoint = data->GeometricObject(firstPointId); const VPointF *secondPoint = data->GeometricObject(secondPointId); QPointF point(firstPoint->x(), secondPoint->y()); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(point.x(), point.y(), pointName, mx, my)); } @@ -92,7 +92,7 @@ void VToolPointOfIntersection::Create(const qint64 _id, const QString &pointName doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::PointOfIntersection, doc); + VDrawTool::AddRecord(id, Valentina::PointOfIntersection, doc); if (parse == Document::FullParse) { VToolPointOfIntersection *point = new VToolPointOfIntersection(doc, data, id, firstPointId, @@ -111,8 +111,8 @@ void VToolPointOfIntersection::FullUpdateFromFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } @@ -138,14 +138,14 @@ void VToolPointOfIntersection::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } @@ -156,11 +156,11 @@ void VToolPointOfIntersection::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } } @@ -169,7 +169,7 @@ void VToolPointOfIntersection::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogPointOfIntersection *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } diff --git a/src/tools/drawTools/vtoolpointofintersection.h b/src/tools/drawTools/vtoolpointofintersection.h index 33e2905c6..89fc26709 100644 --- a/src/tools/drawTools/vtoolpointofintersection.h +++ b/src/tools/drawTools/vtoolpointofintersection.h @@ -48,9 +48,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, - const qint64 &firstPointId, const qint64 &secondPointId, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolPointOfIntersection(VPattern *doc, VContainer *data, const quint32 &id, + const quint32 &firstPointId, const quint32 &secondPointId, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -62,7 +62,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -77,10 +77,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const qint64 &firstPointId, - const qint64 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const quint32 &firstPointId, + const quint32 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** @@ -119,11 +119,11 @@ private: /** * @brief firstPointId id first line point. */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second line point. */ - qint64 secondPointId; + quint32 secondPointId; }; #endif // VTOOLPOINTOFINTERSECTION_H diff --git a/src/tools/drawTools/vtoolshoulderpoint.cpp b/src/tools/drawTools/vtoolshoulderpoint.cpp index 9de69427e..4aa522f9c 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -28,17 +28,17 @@ #include "vtoolshoulderpoint.h" #include "../../container/calculator.h" -#include "../../dialogs/dialogshoulderpoint.h" +#include "../../dialogs/tools/dialogshoulderpoint.h" const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder"); -VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, const Tool::Sources &typeCreation, +VToolShoulderPoint::VToolShoulderPoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const quint32 &p1Line, const quint32 &p2Line, + const quint32 &pShoulder, const Valentina::Sources &typeCreation, QGraphicsItem * parent) :VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder) { - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -70,7 +70,7 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li qreal dist = line.length(); if (dist>toolLength) { - qWarning()<<"Correction of length in shoulder point tool. Parameter length too small."; + qDebug()<<"Correction of length in shoulder point tool. Parameter length too small."; toolLength = dist; } if (qFuzzyCompare(dist, toolLength)) @@ -89,26 +89,26 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li } } -void VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogShoulderPoint *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); QString formula = dialogTool->getFormula(); - qint64 p1Line = dialogTool->getP1Line(); - qint64 p2Line = dialogTool->getP2Line(); - qint64 pShoulder = dialogTool->getPShoulder(); + quint32 p1Line = dialogTool->getP1Line(); + quint32 p2Line = dialogTool->getP2Line(); + quint32 pShoulder = dialogTool->getPShoulder(); QString typeLine = dialogTool->getTypeLine(); QString pointName = dialogTool->getPointName(); Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, const QString &typeLine, +void VToolShoulderPoint::Create(const quint32 _id, const QString &formula, const quint32 &p1Line, + const quint32 &p2Line, const quint32 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *firstPoint = data->GeometricObject(p1Line); const VPointF *secondPoint = data->GeometricObject(p2Line); @@ -120,9 +120,9 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const if (errorMsg.isEmpty()) { QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), - shoulderPoint->toQPointF(), toPixel(result)); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + shoulderPoint->toQPointF(), qApp->toPixel(result)); + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); data->AddLine(p1Line, id); @@ -138,7 +138,7 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::ShoulderPointTool, doc); + VDrawTool::AddRecord(id, Valentina::ShoulderPointTool, doc); if (parse == Document::FullParse) { VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, @@ -162,9 +162,9 @@ void VToolShoulderPoint::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrP1Line, "").toLongLong(); - p2Line = domElement.attribute(AttrP2Line, "").toLongLong(); - pShoulder = domElement.attribute(AttrPShoulder, "").toLongLong(); + basePointId = domElement.attribute(AttrP1Line, "").toUInt(); + p2Line = domElement.attribute(AttrP2Line, "").toUInt(); + pShoulder = domElement.attribute(AttrPShoulder, "").toUInt(); } RefreshGeometry(); } @@ -190,17 +190,17 @@ void VToolShoulderPoint::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrP1Line, basePointId); - SetAttribute(domElement, AttrP2Line, p2Line); - SetAttribute(domElement, AttrPShoulder, pShoulder); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrP1Line, basePointId); + doc->SetAttribute(domElement, AttrP2Line, p2Line); + doc->SetAttribute(domElement, AttrPShoulder, pShoulder); AddToCalculation(domElement); } @@ -211,14 +211,14 @@ void VToolShoulderPoint::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrName, toMM(point->mx())); - SetAttribute(domElement, AttrName, toMM(point->my())); - SetAttribute(domElement, AttrTypeLine, typeLine); - SetAttribute(domElement, AttrLength, formula); - SetAttribute(domElement, AttrP1Line, basePointId); - SetAttribute(domElement, AttrP2Line, p2Line); - SetAttribute(domElement, AttrPShoulder, pShoulder); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrTypeLine, typeLine); + doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrP1Line, basePointId); + doc->SetAttribute(domElement, AttrP2Line, p2Line); + doc->SetAttribute(domElement, AttrPShoulder, pShoulder); } } @@ -234,10 +234,10 @@ void VToolShoulderPoint::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogShoulderPoint *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); - SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1Line())); - SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2Line())); - SetAttribute(domElement, AttrPShoulder, QString().setNum(dialogTool->getPShoulder())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); + doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); + doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1Line())); + doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2Line())); + doc->SetAttribute(domElement, AttrPShoulder, QString().setNum(dialogTool->getPShoulder())); } diff --git a/src/tools/drawTools/vtoolshoulderpoint.h b/src/tools/drawTools/vtoolshoulderpoint.h index fec464fc2..8885dc8d6 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.h +++ b/src/tools/drawTools/vtoolshoulderpoint.h @@ -51,10 +51,10 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qint64 &p1Line, const qint64 &p2Line, - const qint64 &pShoulder, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0); + VToolShoulderPoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formula, const quint32 &p1Line, const quint32 &p2Line, + const quint32 &pShoulder, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -76,7 +76,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -94,10 +94,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, - const qint64 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, - const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &formula, const quint32 &p1Line, const quint32 &p2Line, + const quint32 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, + const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; public slots: /** @@ -140,11 +140,11 @@ private: /** * @brief p2Line id second line point. */ - qint64 p2Line; + quint32 p2Line; /** * @brief pShoulder id shoulder line point. */ - qint64 pShoulder; + quint32 pShoulder; }; #endif // VTOOLSHOULDERPOINT_H diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index 22518d374..f88570791 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -27,22 +27,23 @@ *************************************************************************/ #include "vtoolsinglepoint.h" -#include "../../dialogs/dialogsinglepoint.h" +#include "../../dialogs/tools/dialogsinglepoint.h" const QString VToolSinglePoint::ToolType = QStringLiteral("single"); -VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, +VToolSinglePoint::VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, QGraphicsItem * parent ) :VToolPoint(doc, data, id, parent) { baseColor = Qt::red; currentColor = baseColor; + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); ignoreFullUpdate = true; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, false); setColorLabel(Qt::black); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -66,13 +67,13 @@ void VToolSinglePoint::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrX, toMM(point->x())); - SetAttribute(domElement, AttrY, toMM(point->y())); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrX, qApp->fromPixel(point->x())); + doc->SetAttribute(domElement, AttrY, qApp->fromPixel(point->y())); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); AddToCalculation(domElement); } @@ -83,11 +84,11 @@ void VToolSinglePoint::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrX, QString().setNum(toMM(point->x()))); - SetAttribute(domElement, AttrY, QString().setNum(toMM(point->y()))); - SetAttribute(domElement, AttrMx, QString().setNum(toMM(point->mx()))); - SetAttribute(domElement, AttrMy, QString().setNum(toMM(point->my()))); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(point->x()))); + doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(point->y()))); + doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(point->mx()))); + doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(point->my()))); } } @@ -113,8 +114,8 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrX, QString().setNum(toMM(newPos.x()))); - SetAttribute(domElement, AttrY, QString().setNum(toMM(newPos.y()))); + doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(newPos.x()))); + doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(newPos.y()))); QList list = this->scene()->views(); VAbstractTool::NewSceneRect(this->scene(), list[0]); @@ -142,15 +143,15 @@ void VToolSinglePoint::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialogTool); QPointF p = dialogTool->getPoint(); QString name = dialogTool->getName(); - SetAttribute(domElement, AttrName, name); - SetAttribute(domElement, AttrX, QString().setNum(toMM(p.x()))); - SetAttribute(domElement, AttrY, QString().setNum(toMM(p.y()))); + doc->SetAttribute(domElement, AttrName, name); + doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(p.x()))); + doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(p.y()))); } void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) { namePoint->setBrush(color); - lineName->setPen(QPen(color, toPixel(widthHairLine)/factor)); + lineName->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); } void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) diff --git a/src/tools/drawTools/vtoolsinglepoint.h b/src/tools/drawTools/vtoolsinglepoint.h index 625a2b231..90fbfbd67 100644 --- a/src/tools/drawTools/vtoolsinglepoint.h +++ b/src/tools/drawTools/vtoolsinglepoint.h @@ -47,8 +47,8 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0 ); + VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr ); /** * @brief setDialog set dialog when user want change tool option. */ diff --git a/src/tools/drawTools/vtoolspline.cpp b/src/tools/drawTools/vtoolspline.cpp index 93987b272..ce1a7f6e1 100644 --- a/src/tools/drawTools/vtoolspline.cpp +++ b/src/tools/drawTools/vtoolspline.cpp @@ -28,23 +28,19 @@ #include "vtoolspline.h" #include "../../geometry/vspline.h" -#include "../../dialogs/dialogspline.h" +#include "../../dialogs/tools/dialogspline.h" -const QString VToolSpline::TagName = QStringLiteral("spline"); const QString VToolSpline::ToolType = QStringLiteral("simple"); -VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, - QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()) +VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, + QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) { - ignoreFullUpdate = true; - const VSpline *spl = data->GeometricObject(id); QPainterPath path; path.addPath(spl->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, toPixel(widthHairLine)/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); @@ -65,7 +61,7 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const T connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint2); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -90,48 +86,47 @@ void VToolSpline::setDialog() dialogTool->setKCurve(spl->GetKcurve()); } -void VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogSpline *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - qint64 p1 = dialogTool->getP1(); - qint64 p4 = dialogTool->getP4(); + quint32 p1 = dialogTool->getP1(); + quint32 p4 = dialogTool->getP4(); qreal kAsm1 = dialogTool->getKAsm1(); qreal kAsm2 = dialogTool->getKAsm2(); qreal angle1 = dialogTool->getAngle1(); qreal angle2 = dialogTool->getAngle2(); qreal kCurve = dialogTool->getKCurve(); Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, doc, data, Document::FullParse, - Tool::FromGui); + Valentina::FromGui); } -void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, +void VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { VPointF point1 = *data->GeometricObject(p1); VPointF point4 = *data->GeometricObject(p4); VSpline *spline = new VSpline(point1, point4, angle1, angle2, kAsm1, kAsm2, kCurve); - Q_CHECK_PTR(spline); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(spline); - data->AddLengthSpline(spline->name(), toMM(spline->GetLength())); + data->AddLengthSpline(spline->name(), qApp->fromPixel(spline->GetLength())); } else { data->UpdateGObject(id, spline); - data->AddLengthSpline(spline->name(), toMM(spline->GetLength())); + data->AddLengthSpline(spline->name(), qApp->fromPixel(spline->GetLength())); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::SplineTool, doc); + VDrawTool::AddRecord(id, Valentina::SplineTool, doc); if (parse == Document::FullParse) { VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation); @@ -144,11 +139,6 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c } } -void VToolSpline::FullUpdateFromFile() -{ - RefreshGeometry(); -} - void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, const QPointF &pos) { @@ -166,11 +156,11 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrAngle1, QString().setNum(spl.GetAngle1())); - SetAttribute(domElement, AttrAngle2, QString().setNum(spl.GetAngle2())); - SetAttribute(domElement, AttrKAsm1, QString().setNum(spl.GetKasm1())); - SetAttribute(domElement, AttrKAsm2, QString().setNum(spl.GetKasm2())); - SetAttribute(domElement, AttrKCurve, QString().setNum(spl.GetKcurve())); + doc->SetAttribute(domElement, AttrAngle1, QString().setNum(spl.GetAngle1())); + doc->SetAttribute(domElement, AttrAngle2, QString().setNum(spl.GetAngle2())); + doc->SetAttribute(domElement, AttrKAsm1, QString().setNum(spl.GetKasm1())); + doc->SetAttribute(domElement, AttrKAsm2, QString().setNum(spl.GetKasm2())); + doc->SetAttribute(domElement, AttrKCurve, QString().setNum(spl.GetKcurve())); emit FullUpdateTree(); emit toolhaveChange(); } @@ -186,15 +176,15 @@ void VToolSpline::AddToFile() const VSpline *spl = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); - SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); - SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); - SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); - SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); - SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); - SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); + doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); + doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); + doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); + doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); + doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); + doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); AddToCalculation(domElement); } @@ -205,13 +195,13 @@ void VToolSpline::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); - SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); - SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); - SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); - SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); - SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); - SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); + doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); + doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); + doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); + doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); + doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); + doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); + doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); } } @@ -219,23 +209,11 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Spline); + emit ChoosedTool(id, Valentina::Spline); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine)/factor)); -} - -void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); -} - void VToolSpline::RemoveReferens() { const VSpline *spl = VAbstractTool::data.GeometricObject(id); @@ -243,37 +221,6 @@ void VToolSpline::RemoveReferens() doc->DecrementReferens(spl->GetP4().id()); } -QVariant VToolSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) -{ - if (change == QGraphicsItem::ItemSelectedChange) - { - if (value == true) - { - // do stuff if selected - this->setFocus(); - } - else - { - // do stuff if not selected - } - } - - return QGraphicsItem::itemChange(change, value); -} - -void VToolSpline::keyReleaseEvent(QKeyEvent *event) -{ - switch (event->key()) - { - case Qt::Key_Delete: - DeleteTool(this); - break; - default: - break; - } - QGraphicsItem::keyReleaseEvent ( event ); -} - void VToolSpline::SaveDialog(QDomElement &domElement) { Q_CHECK_PTR(dialog); @@ -298,18 +245,18 @@ void VToolSpline::SaveDialog(QDomElement &domElement) spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogTool->getKCurve()); - SetAttribute(domElement, AttrPoint1, spl.GetP1().id()); - SetAttribute(domElement, AttrPoint4, spl.GetP4().id()); - SetAttribute(domElement, AttrAngle1, spl.GetAngle1()); - SetAttribute(domElement, AttrAngle2, spl.GetAngle2()); - SetAttribute(domElement, AttrKAsm1, spl.GetKasm1()); - SetAttribute(domElement, AttrKAsm2, spl.GetKasm2()); - SetAttribute(domElement, AttrKCurve, spl.GetKcurve()); + doc->SetAttribute(domElement, AttrPoint1, spl.GetP1().id()); + doc->SetAttribute(domElement, AttrPoint4, spl.GetP4().id()); + doc->SetAttribute(domElement, AttrAngle1, spl.GetAngle1()); + doc->SetAttribute(domElement, AttrAngle2, spl.GetAngle2()); + doc->SetAttribute(domElement, AttrKAsm1, spl.GetKasm1()); + doc->SetAttribute(domElement, AttrKAsm2, spl.GetKasm2()); + doc->SetAttribute(domElement, AttrKCurve, spl.GetKcurve()); } void VToolSpline::RefreshGeometry() { - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); const VSpline *spl = VAbstractTool::data.GeometricObject(id); QPainterPath path; path.addPath(spl->GetPath()); @@ -333,35 +280,3 @@ void VToolSpline::RefreshGeometry() connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); } - - -void VToolSpline::ChangedActivDraw(const QString &newName) -{ - bool selectable = false; - if (nameActivDraw == newName) - { - selectable = true; - currentColor = Qt::black; - } - else - { - selectable = false; - currentColor = Qt::gray; - } - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); - this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); - this->setAcceptHoverEvents (selectable); - emit setEnabledPoint(selectable); - VDrawTool::ChangedActivDraw(newName); -} - -void VToolSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) -{ - ShowItem(this, id, color, enable); -} - -void VToolSpline::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} diff --git a/src/tools/drawTools/vtoolspline.h b/src/tools/drawTools/vtoolspline.h index fc8350083..1f42f5060 100644 --- a/src/tools/drawTools/vtoolspline.h +++ b/src/tools/drawTools/vtoolspline.h @@ -29,15 +29,13 @@ #ifndef VTOOLSPLINE_H #define VTOOLSPLINE_H -#include "vdrawtool.h" -#include -#include "../../widgets/vcontrolpointspline.h" +#include "vabstractspline.h" #include "../../geometry/vsplinepath.h" /** * @brief The VToolSpline class tool for creation spline. I mean bezier curve. */ -class VToolSpline:public VDrawTool, public QGraphicsPathItem +class VToolSpline:public VAbstractSpline { Q_OBJECT public: @@ -49,8 +47,8 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0 ); + VToolSpline (VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr ); /** * @brief setDialog set dialog when user want change tool option. */ @@ -62,7 +60,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -79,32 +77,12 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, + static void Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); - static const QString TagName; + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; -signals: - /** - * @brief RefreshLine refresh control line. - * @param indexSpline position spline in spline list. - * @param position position point in spline. - * @param controlPoint new position control point. - * @param splinePoint new position spline point. - */ - void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, - const QPointF &controlPoint, const QPointF &splinePoint ); - /** - * @brief setEnabledPoint disable control points. - * @param enable enable or diasable points. - */ - void setEnabledPoint ( bool enable ); public slots: - /** - * @brief FullUpdateFromFile update tool data form file. - */ - virtual void FullUpdateFromFile (); /** * @brief ControlPointChangePosition handle change position control point. * @param indexSpline position spline in spline list. @@ -113,23 +91,6 @@ public slots: */ void ControlPointChangePosition (const qint32 &indexSpline, const SplinePoint::Position &position, const QPointF &pos); - /** - * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. - * @param newName new name active pattern peace. - */ - virtual void ChangedActivDraw ( const QString &newName ); - /** - * @brief ShowTool highlight tool. - * @param id object id in container - * @param color highlight color. - * @param enable enable or disable highlight. - */ - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - /** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ - virtual void SetFactor(qreal factor); protected: /** * @brief contextMenuEvent handle context menu events. @@ -149,41 +110,15 @@ protected: * @param event context menu event. */ virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - /** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. - */ - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - /** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); /** * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); - /** - * @brief itemChange hadle item change. - * @param change change. - * @param value value. - * @return value. - */ - virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); - /** - * @brief keyReleaseEvent handle key release events. - * @param event key release event. - */ - virtual void keyReleaseEvent(QKeyEvent * event); /** * @brief SaveDialog save options into file after change in dialog. */ virtual void SaveDialog(QDomElement &domElement); private: - /** - * @brief controlPoints list pointers of control points. - */ - QVector controlPoints; /** * @brief RefreshGeometry refresh item on scene. */ diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index 924a9091c..523c5e087 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -27,22 +27,19 @@ *************************************************************************/ #include "vtoolsplinepath.h" -#include "../../dialogs/dialogsplinepath.h" +#include "../../dialogs/tools/dialogsplinepath.h" -const QString VToolSplinePath::TagName = QStringLiteral("spline"); const QString VToolSplinePath::ToolType = QStringLiteral("path"); -VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, - QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()) +VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, + QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) { - ignoreFullUpdate = true; const VSplinePath *splPath = data->GeometricObject(id); QPainterPath path; path.addPath(splPath->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, toPixel(widthHairLine)/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); @@ -65,7 +62,7 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint); } - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -84,40 +81,39 @@ void VToolSplinePath::setDialog() dialogTool->SetPath(*splPath); } -void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogSplinePath *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); VSplinePath *path = new VSplinePath(dialogTool->GetPath()); - Q_CHECK_PTR(path); for (qint32 i = 0; i < path->CountPoint(); ++i) { doc->IncrementReferens((*path)[i].P().id()); } - Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui); + Create(0, path, scene, doc, data, Document::FullParse, Valentina::FromGui); } -void VToolSplinePath::Create(const qint64 _id, VSplinePath *path, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation) +void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation) { - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(path); - data->AddLengthSpline(path->name(), toMM(path->GetLength())); + data->AddLengthSpline(path->name(), qApp->fromPixel(path->GetLength())); } else { data->UpdateGObject(id, path); - data->AddLengthSpline(path->name(), toMM(path->GetLength())); + data->AddLengthSpline(path->name(), qApp->fromPixel(path->GetLength())); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::SplinePathTool, doc); + VDrawTool::AddRecord(id, Valentina::SplinePathTool, doc); if (parse == Document::FullParse) { VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); @@ -128,11 +124,6 @@ void VToolSplinePath::Create(const qint64 _id, VSplinePath *path, VMainGraphicsS } } -void VToolSplinePath::FullUpdateFromFile() -{ - RefreshGeometry(); -} - void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, const QPointF &pos) { @@ -151,7 +142,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); + doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); emit FullUpdateTree(); emit toolhaveChange(); @@ -171,6 +162,30 @@ void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPa splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p); } +void VToolSplinePath::RefreshSplinePath(VSplinePath &splPath) +{ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { + VSpline spl = splPath.GetSpline(i); + qint32 j = i*2; + disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, + &VToolSplinePath::ControlPointChangePosition); + disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, + &VToolSplinePath::ControlPointChangePosition); + controlPoints[j-2]->setPos(spl.GetP2()); + controlPoints[j-1]->setPos(spl.GetP3()); + connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, + &VToolSplinePath::ControlPointChangePosition); + connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, + &VToolSplinePath::ControlPointChangePosition); + + spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(), + splPath.getKCurve()); + CorectControlPoints(spl, splPath, i); + CorectControlPoints(spl, splPath, i); + } +} + void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path) { QDomNodeList nodeList = node.childNodes(); @@ -181,45 +196,14 @@ void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path) if (domElement.isNull() == false) { VSplinePoint p = path[i]; - SetAttribute(domElement, AttrPSpline, p.P().id()); - SetAttribute(domElement, AttrKAsm1, p.KAsm1()); - SetAttribute(domElement, AttrKAsm2, p.KAsm2()); - SetAttribute(domElement, AttrAngle, p.Angle2()); + doc->SetAttribute(domElement, AttrPSpline, p.P().id()); + doc->SetAttribute(domElement, AttrKAsm1, p.KAsm1()); + doc->SetAttribute(domElement, AttrKAsm2, p.KAsm2()); + doc->SetAttribute(domElement, AttrAngle, p.Angle2()); } } } -void VToolSplinePath::ChangedActivDraw(const QString &newName) -{ - bool selectable = false; - if (nameActivDraw == newName) - { - selectable = true; - currentColor = Qt::black; - } - else - { - selectable = false; - currentColor = Qt::gray; - } - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); - this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); - this->setAcceptHoverEvents (selectable); - emit setEnabledPoint(selectable); - VDrawTool::ChangedActivDraw(newName); -} - -void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) -{ - ShowItem(this, id, color, enable); -} - -void VToolSplinePath::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { ContextMenu(this, event); @@ -230,9 +214,9 @@ void VToolSplinePath::AddToFile() VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrKCurve, splPath.getKCurve()); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrKCurve, splPath.getKCurve()); for (qint32 i = 0; i < splPath.CountPoint(); ++i) { @@ -244,45 +228,26 @@ void VToolSplinePath::AddToFile() void VToolSplinePath::RefreshDataInFile() { - VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - for (qint32 i = 1; i<=splPath.Count(); ++i) + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement() == false) { - VSpline spl = splPath.GetSpline(i); - qint32 j = i*2; - disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - controlPoints[j-2]->setPos(spl.GetP2()); - controlPoints[j-1]->setPos(spl.GetP3()); - connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - - spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(), - splPath.getKCurve()); - CorectControlPoints(spl, splPath, i); - CorectControlPoints(spl, splPath, i); - - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); - UpdatePathPoint(domElement, splPath); - } - + qDebug()<<"Can't find element with id="<(id); + RefreshSplinePath(splPath); + doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); + UpdatePathPoint(domElement, splPath); } void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint) { QDomElement pathPoint = doc->createElement(AttrPathPoint); - SetAttribute(pathPoint, AttrPSpline, splPoint.P().id()); - SetAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1()); - SetAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2()); - SetAttribute(pathPoint, AttrAngle, splPoint.Angle2()); + doc->SetAttribute(pathPoint, AttrPSpline, splPoint.P().id()); + doc->SetAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1()); + doc->SetAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2()); + doc->SetAttribute(pathPoint, AttrAngle, splPoint.Angle2()); domElement.appendChild(pathPoint); } @@ -291,23 +256,11 @@ void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::SplinePath); + emit ChoosedTool(id, Valentina::SplinePath); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine)/factor)); -} - -void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); -} - void VToolSplinePath::RemoveReferens() { VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); @@ -317,37 +270,6 @@ void VToolSplinePath::RemoveReferens() } } -QVariant VToolSplinePath::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) -{ - if (change == QGraphicsItem::ItemSelectedChange) - { - if (value == true) - { - // do stuff if selected - this->setFocus(); - } - else - { - // do stuff if not selected - } - } - - return QGraphicsItem::itemChange(change, value); -} - -void VToolSplinePath::keyReleaseEvent(QKeyEvent *event) -{ - switch (event->key()) - { - case Qt::Key_Delete: - DeleteTool(this); - break; - default: - break; - } - QGraphicsItem::keyReleaseEvent ( event ); -} - void VToolSplinePath::SaveDialog(QDomElement &domElement) { Q_CHECK_PTR(dialog); @@ -355,34 +277,14 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialogTool); VSplinePath splPath = dialogTool->GetPath(); - for (qint32 i = 1; i<=splPath.Count(); ++i) - { - VSpline spl = splPath.GetSpline(i); - qint32 j = i*2; - disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - controlPoints[j-2]->setPos(spl.GetP2()); - controlPoints[j-1]->setPos(spl.GetP3()); - connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - - spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(), - splPath.getKCurve()); - CorectControlPoints(spl, splPath, i); - CorectControlPoints(spl, splPath, i); - } - - SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); + RefreshSplinePath(splPath); + doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); } void VToolSplinePath::RefreshGeometry() { - this->setPen(QPen(currentColor, toPixel(widthHairLine)/factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); const VSplinePath *splPath = VAbstractTool::data.GeometricObject(id); QPainterPath path; path.addPath(splPath->GetPath()); diff --git a/src/tools/drawTools/vtoolsplinepath.h b/src/tools/drawTools/vtoolsplinepath.h index a905f4cf8..4e7ca8358 100644 --- a/src/tools/drawTools/vtoolsplinepath.h +++ b/src/tools/drawTools/vtoolsplinepath.h @@ -29,14 +29,12 @@ #ifndef VTOOLSPLINEPATH_H #define VTOOLSPLINEPATH_H -#include "vdrawtool.h" -#include -#include "../../widgets/vcontrolpointspline.h" +#include "vabstractspline.h" /** * @brief The VToolSplinePath class tool for creation spline path. */ -class VToolSplinePath:public VDrawTool, public QGraphicsPathItem +class VToolSplinePath:public VAbstractSpline { Q_OBJECT public: @@ -48,8 +46,8 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, - QGraphicsItem * parent = 0); + VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Valentina::Sources &typeCreation, + QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -61,7 +59,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -72,10 +70,9 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, VSplinePath *path, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); - static const QString TagName; + static void Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); static const QString ToolType; signals: /** @@ -93,10 +90,6 @@ signals: */ void setEnabledPoint(bool enable); public slots: - /** - * @brief FullUpdateFromFile update tool data form file. - */ - virtual void FullUpdateFromFile(); /** * @brief ControlPointChangePosition handle change position control point. * @param indexSpline position spline in spline list. @@ -105,23 +98,6 @@ public slots: */ void ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, const QPointF &pos); - /** - * @brief ChangedActivDraw disable or enable context menu after change active pattern peace. - * @param newName new name active pattern peace. - */ - virtual void ChangedActivDraw(const QString &newName); - /** - * @brief ShowTool highlight tool. - * @param id object id in container - * @param color highlight color. - * @param enable enable or disable highlight. - */ - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - /** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ - virtual void SetFactor(qreal factor); protected: /** * @brief contextMenuEvent handle context menu events. @@ -141,41 +117,15 @@ protected: * @param event mouse release event. */ virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - /** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. - */ - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - /** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); /** * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(); - /** - * @brief itemChange handle item change. - * @param change change. - * @param value value. - * @return value. - */ - virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); - /** - * @brief keyReleaseEvent handle key release events. - * @param event key release event. - */ - virtual void keyReleaseEvent(QKeyEvent * event); /** * @brief SaveDialog save options into file after change in dialog. */ virtual void SaveDialog(QDomElement &domElement); private: - /** - * @brief controlPoints list pointers of control points. - */ - QVector controlPoints; /** * @brief RefreshGeometry refresh item on scene. */ @@ -199,6 +149,7 @@ private: * @param indexSpline index spline in spline path. */ void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline); + void RefreshSplinePath(VSplinePath &splPath); }; #endif // VTOOLSPLINEPATH_H diff --git a/src/tools/drawTools/vtooltriangle.cpp b/src/tools/drawTools/vtooltriangle.cpp index b980b8d8d..4bfbb486e 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -27,18 +27,18 @@ *************************************************************************/ #include "vtooltriangle.h" -#include "../../dialogs/dialogtriangle.h" +#include "../../dialogs/tools/dialogtriangle.h" const QString VToolTriangle::ToolType = QStringLiteral("triangle"); -VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, - const qint64 &axisP1Id, const qint64 &axisP2Id, const qint64 &firstPointId, - const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) +VToolTriangle::VToolTriangle(VPattern *doc, VContainer *data, const quint32 &id, + const quint32 &axisP1Id, const quint32 &axisP2Id, const quint32 &firstPointId, + const quint32 &secondPointId, const Valentina::Sources &typeCreation, QGraphicsItem *parent) :VToolPoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId), secondPointId(secondPointId) { ignoreFullUpdate = true; - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -62,24 +62,24 @@ void VToolTriangle::setDialog() } void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data) + VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogTriangle *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - qint64 axisP1Id = dialogTool->getAxisP1Id(); - qint64 axisP2Id = dialogTool->getAxisP2Id(); - qint64 firstPointId = dialogTool->getFirstPointId(); - qint64 secondPointId = dialogTool->getSecondPointId(); + quint32 axisP1Id = dialogTool->getAxisP1Id(); + quint32 axisP2Id = dialogTool->getAxisP2Id(); + quint32 firstPointId = dialogTool->getFirstPointId(); + quint32 secondPointId = dialogTool->getSecondPointId(); QString pointName = dialogTool->getPointName(); Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui); + Document::FullParse, Valentina::FromGui); } -void VToolTriangle::Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id, - const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolTriangle::Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id, + const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *axisP1 = data->GeometricObject(axisP1Id); const VPointF *axisP2 = data->GeometricObject(axisP2Id); @@ -88,8 +88,8 @@ void VToolTriangle::Create(const qint64 _id, const QString &pointName, const qin QPointF point = FindPoint(axisP1->toQPointF(), axisP2->toQPointF(), firstPoint->toQPointF(), secondPoint->toQPointF()); - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->AddGObject(new VPointF(point.x(), point.y(), pointName, mx, my)); } @@ -101,7 +101,7 @@ void VToolTriangle::Create(const qint64 _id, const QString &pointName, const qin doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::Triangle, doc); + VDrawTool::AddRecord(id, Valentina::Triangle, doc); if (parse == Document::FullParse) { VToolTriangle *point = new VToolTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId, @@ -152,7 +152,7 @@ QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, c if (c*c < a*a + b*b) { //Still don't know why this code handled. Need to think about that. - qWarning()<elementById(QString().setNum(id)); if (domElement.isElement()) { - axisP1Id = domElement.attribute(AttrAxisP1, "").toLongLong(); - axisP2Id = domElement.attribute(AttrAxisP2, "").toLongLong(); - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + axisP1Id = domElement.attribute(AttrAxisP1, "").toUInt(); + axisP2Id = domElement.attribute(AttrAxisP2, "").toUInt(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } @@ -194,16 +194,16 @@ void VToolTriangle::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - SetAttribute(domElement, AttrAxisP1, axisP1Id); - SetAttribute(domElement, AttrAxisP2, axisP2Id); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrAxisP1, axisP1Id); + doc->SetAttribute(domElement, AttrAxisP2, axisP2Id); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } @@ -214,13 +214,13 @@ void VToolTriangle::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrName, point->name()); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); - SetAttribute(domElement, AttrAxisP1, axisP1Id); - SetAttribute(domElement, AttrAxisP2, axisP2Id); - SetAttribute(domElement, AttrFirstPoint, firstPointId); - SetAttribute(domElement, AttrSecondPoint, secondPointId); + doc->SetAttribute(domElement, AttrName, point->name()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); + doc->SetAttribute(domElement, AttrAxisP1, axisP1Id); + doc->SetAttribute(domElement, AttrAxisP2, axisP2Id); + doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); + doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } } @@ -229,9 +229,9 @@ void VToolTriangle::SaveDialog(QDomElement &domElement) Q_CHECK_PTR(dialog); DialogTriangle *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); - SetAttribute(domElement, AttrName, dialogTool->getPointName()); - SetAttribute(domElement, AttrAxisP1, QString().setNum(dialogTool->getAxisP1Id())); - SetAttribute(domElement, AttrAxisP2, QString().setNum(dialogTool->getAxisP2Id())); - SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); - SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); + doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); + doc->SetAttribute(domElement, AttrAxisP1, QString().setNum(dialogTool->getAxisP1Id())); + doc->SetAttribute(domElement, AttrAxisP2, QString().setNum(dialogTool->getAxisP2Id())); + doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); + doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } diff --git a/src/tools/drawTools/vtooltriangle.h b/src/tools/drawTools/vtooltriangle.h index ba2f76bf4..7495e3b3c 100644 --- a/src/tools/drawTools/vtooltriangle.h +++ b/src/tools/drawTools/vtooltriangle.h @@ -50,9 +50,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &axisP1Id, - const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + VToolTriangle(VPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id, + const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId, + const Valentina::Sources &typeCreation, QGraphicsItem * parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,10 +81,10 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id, const qint64 &axisP2Id, - const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id, const quint32 &axisP2Id, + const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation); /** * @brief FindPoint find point intersection two foots right triangle. * @param axisP1 first axis point. @@ -133,19 +133,19 @@ private: /** * @brief axisP1Id id first axis point. */ - qint64 axisP1Id; + quint32 axisP1Id; /** * @brief axisP2Id id second axis point. */ - qint64 axisP2Id; + quint32 axisP2Id; /** * @brief firstPointId id first triangle point, what lies on the hypotenuse. */ - qint64 firstPointId; + quint32 firstPointId; /** * @brief secondPointId id second triangle point, what lies on the hypotenuse. */ - qint64 secondPointId; + quint32 secondPointId; }; #endif // VTOOLTRIANGLE_H diff --git a/src/tools/nodeDetails/vabstractnode.cpp b/src/tools/nodeDetails/vabstractnode.cpp index 4a9464eb2..52285c2c8 100644 --- a/src/tools/nodeDetails/vabstractnode.cpp +++ b/src/tools/nodeDetails/vabstractnode.cpp @@ -32,8 +32,8 @@ const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool"); -VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode, - const qint64 &idTool, QObject *parent) +VAbstractNode::VAbstractNode(VPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode, + const quint32 &idTool, QObject *parent) : VAbstractTool(doc, data, id, parent), idNode(idNode), idTool(idTool) { _referens = 0; @@ -58,17 +58,17 @@ void VAbstractNode::DeleteNode() } else { - qWarning()<<"parent isn't element"< +#include "../../widgets/vapplication.h" const QString VNodeArc::TagName = QStringLiteral("arc"); const QString VNodeArc::ToolType = QStringLiteral("modeling"); -VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Tool::Sources &typeCreation, - const qint64 &idTool, QObject *qoParent, QGraphicsItem *parent) +VNodeArc::VNodeArc(VPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Valentina::Sources &typeCreation, + const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent) :VAbstractNode(doc, data, id, idArc, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); - this->setPen(QPen(baseColor, toPixel(widthHairLine))); + this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine()))); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -50,14 +51,13 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, } } -void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, - const Tool::Sources &typeCreation, const qint64 &idTool, QObject *parent) +void VNodeArc::Create(VPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document::Documents &parse, + const Valentina::Sources &typeCreation, const quint32 &idTool, QObject *parent) { - VAbstractTool::AddRecord(id, Tool::NodeArc, doc); + VAbstractTool::AddRecord(id, Valentina::NodeArc, doc); if (parse == Document::FullParse) { VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent); - Q_CHECK_PTR(arc); doc->AddTool(id, arc); if (idTool != 0) { @@ -93,12 +93,12 @@ void VNodeArc::AddToFile() { QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrIdObject, idNode); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } AddToModeling(domElement); @@ -109,10 +109,10 @@ void VNodeArc::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrIdObject, idNode); + doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } } } @@ -121,7 +121,7 @@ void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Arc); + emit ChoosedTool(id, Valentina::Arc); } QGraphicsItem::mouseReleaseEvent(event); } @@ -129,13 +129,13 @@ void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodeArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); } void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); } void VNodeArc::RefreshGeometry() diff --git a/src/tools/nodeDetails/vnodearc.h b/src/tools/nodeDetails/vnodearc.h index 2a5093f69..e548a2e5e 100644 --- a/src/tools/nodeDetails/vnodearc.h +++ b/src/tools/nodeDetails/vnodearc.h @@ -48,9 +48,8 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, - QGraphicsItem * parent = 0); + VNodeArc(VPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Valentina::Sources &typeCreation, + const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr); /** * @brief Create help create tool. * @param doc dom document container. @@ -60,8 +59,8 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, - const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *parent = 0); + static void Create(VPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document::Documents &parse, + const Valentina::Sources &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr); static const QString TagName; static const QString ToolType; /** diff --git a/src/tools/nodeDetails/vnodepoint.cpp b/src/tools/nodeDetails/vnodepoint.cpp index e1f4ee241..0b2a0204c 100644 --- a/src/tools/nodeDetails/vnodepoint.cpp +++ b/src/tools/nodeDetails/vnodepoint.cpp @@ -29,26 +29,27 @@ #include "vnodepoint.h" #include +#include "../../widgets/vapplication.h" const QString VNodePoint::TagName = QStringLiteral("point"); const QString VNodePoint::ToolType = QStringLiteral("modeling"); -VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent, +VNodePoint::VNodePoint(VPattern *doc, VContainer *data, quint32 id, quint32 idPoint, + const Valentina::Sources &typeCreation, const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent) - :VAbstractNode(doc, data, id, idPoint, idTool, qoParent), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), - namePoint(0), lineName(0) + :VAbstractNode(doc, data, id, idPoint, idTool, qoParent), QGraphicsEllipseItem(parent), radius(qApp->toPixel(1.5)), + namePoint(nullptr), lineName(nullptr) { namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VNodePoint::NameChangePosition); - this->setPen(QPen(Qt::black, toPixel(widthHairLine))); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -58,17 +59,16 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id } } -void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool, +void VNodePoint::Create(VPattern *doc, VContainer *data, quint32 id, quint32 idPoint, + const Document::Documents &parse, const Valentina::Sources &typeCreation, const quint32 &idTool, QObject *parent) { - VAbstractTool::AddRecord(id, Tool::NodePoint, doc); + VAbstractTool::AddRecord(id, Valentina::NodePoint, doc); if (parse == Document::FullParse) { //TODO Need create garbage collector and remove all nodes, what we don't use. //Better check garbage before each saving file. Check only modeling tags. VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool, parent); - Q_CHECK_PTR(point); doc->AddTool(id, point); if (idTool != 0) { @@ -105,14 +105,14 @@ void VNodePoint::AddToFile() const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrIdObject, idNode); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, idNode); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } AddToModeling(domElement); @@ -124,12 +124,12 @@ void VNodePoint::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrIdObject, idNode); - SetAttribute(domElement, AttrMx, toMM(point->mx())); - SetAttribute(domElement, AttrMy, toMM(point->my())); + doc->SetAttribute(domElement, AttrIdObject, idNode); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } } } @@ -138,7 +138,7 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Point); + emit ChoosedTool(id, Valentina::Point); } QGraphicsItem::mouseReleaseEvent(event); } @@ -146,13 +146,13 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); } void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); } @@ -172,8 +172,8 @@ void VNodePoint::UpdateNamePosition(qreal mx, qreal my) QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrMx, QString().setNum(toMM(mx))); - SetAttribute(domElement, AttrMy, QString().setNum(toMM(my))); + doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx))); + doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my))); emit toolhaveChange(); } } @@ -201,7 +201,7 @@ void VNodePoint::RefreshLine() LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - if (QLineF(p1, pRec - scenePos()).length() <= toPixel(4)) + if (QLineF(p1, pRec - scenePos()).length() <= qApp->toPixel(4)) { lineName->setVisible(false); } diff --git a/src/tools/nodeDetails/vnodepoint.h b/src/tools/nodeDetails/vnodepoint.h index 9e366c5af..af513d3b5 100644 --- a/src/tools/nodeDetails/vnodepoint.h +++ b/src/tools/nodeDetails/vnodepoint.h @@ -48,9 +48,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, - QGraphicsItem * parent = 0 ); + VNodePoint(VPattern *doc, VContainer *data, quint32 id, quint32 idPoint, + const Valentina::Sources &typeCreation, const quint32 &idTool = 0, QObject *qoParent = nullptr, + QGraphicsItem * parent = nullptr ); /** * @brief Create help create tool. * @param doc dom document container. @@ -60,9 +60,9 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0, - QObject *parent = 0); + static void Create(VPattern *doc, VContainer *data, quint32 id, quint32 idPoint, + const Document::Documents &parse, const Valentina::Sources &typeCreation, const quint32 &idTool = 0, + QObject *parent = nullptr); static const QString TagName; static const QString ToolType; /** diff --git a/src/tools/nodeDetails/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index 6cb4d68a8..a9ad3124e 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -29,19 +29,20 @@ #include "vnodespline.h" #include +#include "../../widgets/vapplication.h" const QString VNodeSpline::TagName = QStringLiteral("spline"); const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline"); -VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent, +VNodeSpline::VNodeSpline(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Valentina::Sources &typeCreation, const quint32 &idTool, QObject *qoParent, QGraphicsItem * parent) :VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); - this->setPen(QPen(baseColor, toPixel(widthHairLine))); + this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine()))); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -51,12 +52,12 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 } } -VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation, - const qint64 &idTool, QObject *parent) +VNodeSpline *VNodeSpline::Create(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Document::Documents &parse, const Valentina::Sources &typeCreation, + const quint32 &idTool, QObject *parent) { - VAbstractTool::AddRecord(id, Tool::NodeSpline, doc); - VNodeSpline *spl = 0; + VAbstractTool::AddRecord(id, Valentina::NodeSpline, doc); + VNodeSpline *spl = nullptr; if (parse == Document::FullParse) { spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent); @@ -96,12 +97,12 @@ void VNodeSpline::AddToFile() { QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrIdObject, idNode); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } AddToModeling(domElement); @@ -112,10 +113,10 @@ void VNodeSpline::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); + doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } } } @@ -124,7 +125,7 @@ void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Spline); + emit ChoosedTool(id, Valentina::Spline); } QGraphicsItem::mouseReleaseEvent(event); } @@ -132,13 +133,13 @@ void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodeSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); } void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); } void VNodeSpline::RefreshGeometry() diff --git a/src/tools/nodeDetails/vnodespline.h b/src/tools/nodeDetails/vnodespline.h index 20559a3c5..b7e680e40 100644 --- a/src/tools/nodeDetails/vnodespline.h +++ b/src/tools/nodeDetails/vnodespline.h @@ -48,9 +48,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, - QGraphicsItem * parent = 0); + VNodeSpline(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Valentina::Sources &typeCreation, const quint32 &idTool = 0, QObject *qoParent = nullptr, + QGraphicsItem * parent = nullptr); /** * @brief Create help create tool. * @param doc dom document container. @@ -61,9 +61,9 @@ public: * @param typeCreation way we create this tool. * @return */ - static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation, - const qint64 &idTool = 0, QObject *parent = 0); + static VNodeSpline *Create(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Document::Documents &parse, const Valentina::Sources &typeCreation, + const quint32 &idTool = 0, QObject *parent = nullptr); static const QString TagName; static const QString ToolType; /** diff --git a/src/tools/nodeDetails/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index ed21d0bb4..c8a01a065 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -29,19 +29,20 @@ #include "vnodesplinepath.h" #include +#include "../../widgets/vapplication.h" const QString VNodeSplinePath::TagName = QStringLiteral("spline"); const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath"); -VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent, +VNodeSplinePath::VNodeSplinePath(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Valentina::Sources &typeCreation, const quint32 &idTool, QObject *qoParent, QGraphicsItem * parent) :VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); - this->setPen(QPen(baseColor, toPixel(widthHairLine))); + this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine()))); - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -51,15 +52,14 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, } } -void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool, +void VNodeSplinePath::Create(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Document::Documents &parse, const Valentina::Sources &typeCreation, const quint32 &idTool, QObject *parent) { - VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc); + VAbstractTool::AddRecord(id, Valentina::NodeSplinePath, doc); if (parse == Document::FullParse) { VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent); - Q_CHECK_PTR(splPath); doc->AddTool(id, splPath); const VSplinePath *path = data->GeometricObject(id); const QVector *points = path->GetPoint(); @@ -100,12 +100,12 @@ void VNodeSplinePath::AddToFile() { QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrIdObject, idNode); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIdObject, idNode); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } AddToModeling(domElement); @@ -116,10 +116,10 @@ void VNodeSplinePath::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); + doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); if (idTool != 0) { - SetAttribute(domElement, AttrIdTool, idTool); + doc->SetAttribute(domElement, AttrIdTool, idTool); } } } @@ -128,7 +128,7 @@ void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::SplinePath); + emit ChoosedTool(id, Valentina::SplinePath); } QGraphicsItem::mouseReleaseEvent(event); } @@ -136,13 +136,13 @@ void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodeSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); } void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine))); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); } void VNodeSplinePath::RefreshGeometry() diff --git a/src/tools/nodeDetails/vnodesplinepath.h b/src/tools/nodeDetails/vnodesplinepath.h index 5429fee8c..8c0829543 100644 --- a/src/tools/nodeDetails/vnodesplinepath.h +++ b/src/tools/nodeDetails/vnodesplinepath.h @@ -48,9 +48,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, - QGraphicsItem * parent = 0); + VNodeSplinePath(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Valentina::Sources &typeCreation, const quint32 &idTool = 0, + QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr); /** * @brief Create help create tool. * @param doc dom document container. @@ -60,8 +60,8 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0, + static void Create(VPattern *doc, VContainer *data, quint32 id, quint32 idSpline, + const Document::Documents &parse, const Valentina::Sources &typeCreation, const quint32 &idTool = 0, QObject *parent = 0); static const QString TagName; static const QString ToolType; diff --git a/src/tools/tools.pri b/src/tools/tools.pri index 578923b13..6e5924a6a 100644 --- a/src/tools/tools.pri +++ b/src/tools/tools.pri @@ -31,7 +31,8 @@ HEADERS += \ src/tools/drawTools/vtoolcutspline.h \ src/tools/drawTools/vtoolcutsplinepath.h \ src/tools/vtooluniondetails.h \ - src/tools/drawTools/vtoolcutarc.h + src/tools/drawTools/vtoolcutarc.h \ + src/tools/drawTools/vabstractspline.h SOURCES += \ src/tools/vtooldetail.cpp \ @@ -63,4 +64,5 @@ SOURCES += \ src/tools/drawTools/vtoolcutspline.cpp \ src/tools/drawTools/vtoolcutsplinepath.cpp \ src/tools/vtooluniondetails.cpp \ - src/tools/drawTools/vtoolcutarc.cpp + src/tools/drawTools/vtoolcutarc.cpp \ + src/tools/drawTools/vabstractspline.cpp diff --git a/src/tools/vabstracttool.cpp b/src/tools/vabstracttool.cpp index 8bb711086..922ae62a4 100644 --- a/src/tools/vabstracttool.cpp +++ b/src/tools/vabstracttool.cpp @@ -28,7 +28,6 @@ #include "vabstracttool.h" -const QString VAbstractTool::AttrId = QStringLiteral("id"); const QString VAbstractTool::AttrType = QStringLiteral("type"); const QString VAbstractTool::AttrMx = QStringLiteral("mx"); const QString VAbstractTool::AttrMy = QStringLiteral("my"); @@ -62,20 +61,21 @@ const QString VAbstractTool::AttrPathPoint = QStringLiteral("pathPoint"); const QString VAbstractTool::AttrPSpline = QStringLiteral("pSpline"); const QString VAbstractTool::AttrAxisP1 = QStringLiteral("axisP1"); const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2"); -const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); -const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); + +const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); +const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); const QString VAbstractTool::TypeLineDashLine = QStringLiteral("dashLine"); const QString VAbstractTool::TypeLineDotLine = QStringLiteral("dotLine"); const QString VAbstractTool::TypeLineDashDotLine = QStringLiteral("dashDotLine"); const QString VAbstractTool::TypeLineDashDotDotLine = QStringLiteral("dashDotDotLine"); -VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) +VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent) :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine) { Q_CHECK_PTR(doc); - connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); - connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); - connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); + connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); + connect(this->doc, &VPattern::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); + connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VPattern::FullUpdateTree); emit toolhaveChange(); } @@ -241,17 +241,17 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool) } else { - qWarning()<<"parent isn't element"< /** @@ -40,15 +40,15 @@ class VAbstractTool: public VDataTool { Q_OBJECT public: - /** - * @brief VAbstractTool container. - * @param doc dom document container. - * @param data container with data. - * @param id object id in container. - * @param parent parent object. - */ - VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); - virtual ~VAbstractTool(){} + /** + * @brief VAbstractTool container. + * @param doc dom document container. + * @param data container with data. + * @param id object id in container. + * @param parent parent object. + */ + VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr); + virtual ~VAbstractTool(){} /** * @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view. * @param sc scene. @@ -93,7 +93,7 @@ public: * @brief getId return object id. * @return id. */ - inline qint64 getId() const {return id;} + quint32 getId() const; /** * @brief LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0. * @param line line @@ -102,7 +102,6 @@ public: * @param c c value */ static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); - static const QString AttrId; static const QString AttrType; static const QString AttrMx; static const QString AttrMy; @@ -153,7 +152,7 @@ public: * @param toolType tool type * @param doc dom document container */ - static void AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc); + static void AddRecord(const quint32 id, const Valentina::Tools &toolType, VPattern *doc); public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -169,7 +168,7 @@ signals: * @param id object id in container. * @param type type of scene object. */ - void ChoosedTool(qint64 id, Scene::Scenes type); + void ChoosedTool(quint32 id, Valentina::Scenes type); /** * @brief FullUpdateTree emit if need reparse pattern file. */ @@ -178,11 +177,11 @@ protected: /** * @brief doc dom document container */ - VDomDocument *doc; + VPattern *doc; /** * @brief id object id. */ - const qint64 id; + const quint32 id; /** * @brief baseColor base color for tool. */ @@ -207,7 +206,7 @@ protected: * @brief getData return pointer to data container. * @return container. */ - inline const VContainer *getData() const {return &data;} + const VContainer *getData() const; /** * @brief RemoveReferens decrement value of reference. */ @@ -227,26 +226,17 @@ protected: * @return pen style. */ Qt::PenStyle LineStyle(); - template - /** - * @brief SetAttribute set attribute in pattern file. Replace "," by ".". - * @param domElement element in xml tree. - * @param name name of attribute. - * @param value value of attribute. - */ - void SetAttribute(QDomElement &domElement, const QString &name, const T &value) - { - QString val = QString().setNum(value); - val = val.replace(",", "."); - domElement.setAttribute(name, val); - } private: Q_DISABLE_COPY(VAbstractTool) }; -template <> -inline void VAbstractTool::SetAttribute(QDomElement &domElement, const QString &name, const QString &value) +inline quint32 VAbstractTool::getId() const { - domElement.setAttribute(name, value); + return id; +} + +inline const VContainer *VAbstractTool::getData() const +{ + return &data; } #endif // VABSTRACTTOOL_H diff --git a/src/tools/vdatatool.h b/src/tools/vdatatool.h index 34fbdd5b7..69ef0a00f 100644 --- a/src/tools/vdatatool.h +++ b/src/tools/vdatatool.h @@ -39,13 +39,13 @@ class VDataTool : public QObject { Q_OBJECT public: - /** - * @brief VDataTool constructor. - * @param data container with variables - * @param parent parent object - */ - VDataTool(VContainer *data, QObject *parent = 0); - virtual ~VDataTool(){} + /** + * @brief VDataTool constructor. + * @param data container with variables + * @param parent parent object + */ + VDataTool(VContainer *data, QObject *parent = nullptr); + virtual ~VDataTool(){} /** * @brief operator = assignment operator. * @param tool tool @@ -56,21 +56,21 @@ public: * @brief getData return data container. * @return container. */ - inline VContainer getData() const { return data; } + VContainer getData() const; /** * @brief setData set data container. * @param value container. */ - inline void setData(const VContainer *value){data = *value;} + void setData(const VContainer *value); /** * @brief referens return count of referens. * @return count count of referens. */ - virtual inline qint64 referens() const {return _referens;} + virtual quint32 referens() const; /** * @brief incrementReferens increment referens. */ - virtual inline void incrementReferens(){++_referens;} + virtual void incrementReferens(); /** * @brief decrementReferens decrement referens. */ @@ -83,7 +83,27 @@ protected: /** * @brief _referens keep count tools what use this tool. If value more than 1 you can't delete tool. */ - qint64 _referens; + quint32 _referens; }; +inline VContainer VDataTool::getData() const +{ + return data; +} + +inline void VDataTool::setData(const VContainer *value) +{ + data = *value; +} + +inline quint32 VDataTool::referens() const +{ + return _referens; +} + +inline void VDataTool::incrementReferens() +{ + ++_referens; +} + #endif // VDATATOOL_H diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 6a0e26e1d..bb620c94e 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -32,37 +32,44 @@ const QString VToolDetail::TagName = QStringLiteral("detail"); const QString VToolDetail::TagNode = QStringLiteral("node"); + const QString VToolDetail::AttrSupplement = QStringLiteral("supplement"); const QString VToolDetail::AttrClosed = QStringLiteral("closed"); const QString VToolDetail::AttrWidth = QStringLiteral("width"); const QString VToolDetail::AttrIdObject = QStringLiteral("idObject"); const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); + const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour"); const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling"); -VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, const Tool::Sources &typeCreation, +const QString VToolDetail::NodeArc = QStringLiteral("NodeArc"); +const QString VToolDetail::NodePoint = QStringLiteral("NodePoint"); +const QString VToolDetail::NodeSpline = QStringLiteral("NodeSpline"); +const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath"); + +VToolDetail::VToolDetail(VPattern *doc, VContainer *data, const quint32 &id, const Valentina::Sources &typeCreation, VMainGraphicsScene *scene, QGraphicsItem *parent) - :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(0), sceneDetails(scene) + :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(nullptr), sceneDetails(scene) { VDetail detail = data->GetDetail(id); for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { switch (detail[i].getTypeTool()) { - case (Tool::NodePoint): + case (Valentina::NodePoint): InitTool(scene, detail[i]); break; - case (Tool::NodeArc): + case (Valentina::NodeArc): InitTool(scene, detail[i]); break; - case (Tool::NodeSpline): + case (Valentina::NodeSpline): InitTool(scene, detail[i]); break; - case (Tool::NodeSplinePath): + case (Valentina::NodeSplinePath): InitTool(scene, detail[i]); break; default: - qWarning()<<"Get wrong tool type. Ignore."; + qDebug()<<"Get wrong tool type. Ignore."; break; } doc->IncrementReferens(detail[i].getId()); @@ -73,7 +80,7 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, this->setPos(detail.getMx(), detail.getMy()); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); - if (typeCreation == Tool::FromGui || typeCreation == Tool::FromTool) + if (typeCreation == Valentina::FromGui || typeCreation == Valentina::FromTool) { AddToFile(); } @@ -93,7 +100,7 @@ void VToolDetail::setDialog() dialogTool->setDetails(detail); } -void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogDetail *dialogTool = qobject_cast(dialog); @@ -102,49 +109,49 @@ void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocu VDetail det; for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { - qint64 id = 0; + quint32 id = 0; switch (detail[i].getTypeTool()) { - case (Tool::NodePoint): + case (Valentina::NodePoint): { id = CreateNode(data, detail[i].getId()); - VNodePoint::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); + VNodePoint::Create(doc, data, id, detail[i].getId(), Document::FullParse, Valentina::FromGui); } break; - case (Tool::NodeArc): + case (Valentina::NodeArc): { id = CreateNode(data, detail[i].getId()); - VNodeArc::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); + VNodeArc::Create(doc, data, id, detail[i].getId(), Document::FullParse, Valentina::FromGui); } break; - case (Tool::NodeSpline): + case (Valentina::NodeSpline): { id = CreateNode(data, detail[i].getId()); - VNodeSpline::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); + VNodeSpline::Create(doc, data, id, detail[i].getId(), Document::FullParse, Valentina::FromGui); } break; - case (Tool::NodeSplinePath): + case (Valentina::NodeSplinePath): { id = CreateNode(data, detail[i].getId()); - VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); + VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Valentina::FromGui); } break; default: - qWarning()<<"May be wrong tool type!!! Ignoring."<AddDetail(newDetail); } @@ -156,13 +163,13 @@ void VToolDetail::Create(const qint64 &_id, const VDetail &newDetail, VMainGraph doc->UpdateToolData(id, data); } } - VAbstractTool::AddRecord(id, Tool::Detail, doc); + VAbstractTool::AddRecord(id, Valentina::DetailTool, doc); if (parse == Document::FullParse) { VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); scene->addItem(detail); connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - QHash* tools = doc->getTools(); + QHash* tools = doc->getTools(); tools->insert(id, detail); } } @@ -188,18 +195,18 @@ void VToolDetail::FullUpdateFromGui(int result) DialogDetail *dialogTool = qobject_cast(dialog); Q_CHECK_PTR(dialogTool); VDetail det = dialogTool->getDetails(); - SetAttribute(domElement, AttrName, det.getName()); - SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); - SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed())); - SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); + doc->SetAttribute(domElement, AttrName, det.getName()); + doc->SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); + doc->SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed())); + doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); RemoveAllChild(domElement); for (ptrdiff_t i = 0; i < det.CountNode(); ++i) { AddNode(domElement, det[i]); } VDetail detail = VAbstractTool::data.GetDetail(id); - QList list = detail.Missing(det); - QHash* tools = doc->getTools(); + QList list = detail.Missing(det); + QHash* tools = doc->getTools(); if (list.size()>0) { for (qint32 i = 0; i < list.size(); ++i) @@ -221,13 +228,13 @@ void VToolDetail::AddToFile() VDetail detail = VAbstractTool::data.GetDetail(id); QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrName, detail.getName()); - SetAttribute(domElement, AttrMx, toMM(detail.getMx())); - SetAttribute(domElement, AttrMy, toMM(detail.getMy())); - SetAttribute(domElement, AttrSupplement, detail.getSeamAllowance()); - SetAttribute(domElement, AttrClosed, detail.getClosed()); - SetAttribute(domElement, AttrWidth, detail.getWidth()); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrName, detail.getName()); + doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(detail.getMx())); + doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(detail.getMy())); + doc->SetAttribute(domElement, AttrSupplement, detail.getSeamAllowance()); + doc->SetAttribute(domElement, AttrClosed, detail.getClosed()); + doc->SetAttribute(domElement, AttrWidth, detail.getWidth()); for (ptrdiff_t i = 0; i < detail.CountNode(); ++i) { @@ -235,7 +242,7 @@ void VToolDetail::AddToFile() } QDomElement element; - bool ok = doc->GetActivDetailsElement(element); + bool ok = doc->GetActivNodeElement(VPattern::TagDetails, element); if (ok) { element.appendChild(domElement); @@ -248,10 +255,10 @@ void VToolDetail::RefreshDataInFile() if (domElement.isElement()) { VDetail det = VAbstractTool::data.GetDetail(id); - SetAttribute(domElement, AttrName, det.getName()); - SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); - SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed())); - SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); + doc->SetAttribute(domElement, AttrName, det.getName()); + doc->SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); + doc->SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed())); + doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); RemoveAllChild(domElement); for (ptrdiff_t i = 0; i < det.CountNode(); ++i) { @@ -270,8 +277,8 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrMx, QString().setNum(toMM(newPos.x()))); - SetAttribute(domElement, AttrMy, QString().setNum(toMM(newPos.y()))); + doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(newPos.x()))); + doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(newPos.y()))); QList list = this->scene()->views(); VAbstractTool::NewSceneRect(this->scene(), list[0]); @@ -313,7 +320,7 @@ void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::Detail); + emit ChoosedTool(id, Valentina::Detail); } QGraphicsItem::mouseReleaseEvent(event); } @@ -362,33 +369,33 @@ void VToolDetail::AddNode(QDomElement &domElement, const VNodeDetail &node) { QDomElement nod = doc->createElement(TagNode); - SetAttribute(nod, AttrIdObject, node.getId()); - SetAttribute(nod, AttrMx, toMM(node.getMx())); - SetAttribute(nod, AttrMy, toMM(node.getMy())); + doc->SetAttribute(nod, AttrIdObject, node.getId()); + doc->SetAttribute(nod, AttrMx, qApp->fromPixel(node.getMx())); + doc->SetAttribute(nod, AttrMy, qApp->fromPixel(node.getMy())); if (node.getTypeNode() == NodeDetail::Contour) { - SetAttribute(nod, AttrNodeType, NodeTypeContour); + doc->SetAttribute(nod, AttrNodeType, NodeTypeContour); } else { - SetAttribute(nod, AttrNodeType, NodeTypeModeling); + doc->SetAttribute(nod, AttrNodeType, NodeTypeModeling); } switch (node.getTypeTool()) { - case (Tool::NodeArc): - SetAttribute(nod, AttrType, QStringLiteral("NodeArc")); + case (Valentina::NodeArc): + doc->SetAttribute(nod, AttrType, NodeArc); break; - case (Tool::NodePoint): - SetAttribute(nod, AttrType, QStringLiteral("NodePoint")); + case (Valentina::NodePoint): + doc->SetAttribute(nod, AttrType, NodePoint); break; - case (Tool::NodeSpline): - SetAttribute(nod, AttrType, QStringLiteral("NodeSpline")); + case (Valentina::NodeSpline): + doc->SetAttribute(nod, AttrType, NodeSpline); break; - case (Tool::NodeSplinePath): - SetAttribute(nod, AttrType, QStringLiteral("NodeSplinePath")); + case (Valentina::NodeSplinePath): + doc->SetAttribute(nod, AttrType, NodeSplinePath); break; default: - qWarning()<<"May be wrong tool type!!! Ignoring."< //cppcheck-suppress unusedFunction void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) { - QHash* tools = doc->getTools(); + QHash* tools = doc->getTools(); Q_CHECK_PTR(tools); Tool *tool = qobject_cast(tools->value(node.getId())); Q_CHECK_PTR(tool); diff --git a/src/tools/vtooldetail.h b/src/tools/vtooldetail.h index 2ae074f72..2a6b44b14 100644 --- a/src/tools/vtooldetail.h +++ b/src/tools/vtooldetail.h @@ -31,7 +31,7 @@ #include "vabstracttool.h" #include -#include "../dialogs/dialogdetail.h" +#include "../dialogs/tools/dialogdetail.h" /** * @brief The VToolDetail class for working with detail. @@ -49,8 +49,8 @@ public: * @param scene pointer to scene. * @param parent parent object */ - VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, const Tool::Sources &typeCreation, - VMainGraphicsScene *scene, QGraphicsItem * parent = 0); + VToolDetail(VPattern *doc, VContainer *data, const quint32 &id, const Valentina::Sources &typeCreation, + VMainGraphicsScene *scene, QGraphicsItem * parent = nullptr); ~VToolDetail(); /** * @brief setDialog set dialog when user want change tool option. @@ -63,12 +63,11 @@ public: * @param id id parent object. * @return id for new object. */ - static qint64 CreateNode(VContainer *data, const qint64 &id) + static quint32 CreateNode(VContainer *data, const quint32 &id) { //We can't use exist object. Need create new. T *node = new T(*data->GeometricObject(id)); - Q_CHECK_PTR(node); - node->setMode(Draw::Modeling); + node->setMode(Valentina::Modeling); return data->AddGObject(node); } @@ -79,7 +78,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -90,9 +89,9 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); + static void Create(const quint32 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); static const QString TagName; static const QString TagNode; static const QString AttrSupplement; @@ -102,6 +101,10 @@ public: static const QString AttrNodeType; static const QString NodeTypeContour; static const QString NodeTypeModeling; + static const QString NodeArc; + static const QString NodePoint; + static const QString NodeSpline; + static const QString NodeSplinePath; /** * @brief Remove full delete detail. */ diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index a2952b075..6fa37d28a 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -41,12 +41,12 @@ const QString VToolUnionDetails::AttrNodeType = QStringLiteral("nodeType"); const QString VToolUnionDetails::NodeTypeContour = QStringLiteral("Contour"); const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling"); -VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, - const VDetail &d2, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, - const Tool::Sources &typeCreation, QObject *parent) +VToolUnionDetails::VToolUnionDetails(VPattern *doc, VContainer *data, const quint32 &id, const VDetail &d1, + const VDetail &d2, const quint32 &indexD1, const quint32 &indexD2, + const Valentina::Sources &typeCreation, QObject *parent) :VAbstractTool(doc, data, id, parent), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2) { - if (typeCreation == Tool::FromGui) + if (typeCreation == Valentina::FromGui) { AddToFile(); } @@ -56,14 +56,14 @@ VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const } } -void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContainer *data, VDetail &newDetail, - const VDetail &det, const ptrdiff_t &i, const qint64 &idTool, const qreal &dx, - const qreal &dy, const qint64 &pRotate, const qreal &angle) +void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer *data, VDetail &newDetail, + const VDetail &det, const ptrdiff_t &i, const quint32 &idTool, const qreal &dx, + const qreal &dy, const quint32 &pRotate, const qreal &angle) { - qint64 id = 0, idObject = 0; + quint32 id = 0, idObject = 0; switch (det.at(i).getTypeTool()) { - case (Tool::NodePoint): + case (Valentina::NodePoint): { if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) { @@ -72,20 +72,18 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai else { VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); - Q_CHECK_PTR(point); - point->setMode(Draw::Modeling); + point->setMode(Valentina::Modeling); BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); idObject = data->AddGObject(point); VPointF *point1 = new VPointF(*point); - Q_CHECK_PTR(point1); - point1->setMode(Draw::Modeling); + point1->setMode(Valentina::Modeling); id = data->AddGObject(point1); - VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Valentina::FromGui, idTool, tool); } } break; - case (Tool::NodeArc): + case (Valentina::NodeArc): { if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { @@ -99,32 +97,29 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai VPointF p2 = VPointF(arc->GetP2().x(), arc->GetP2().y(), "A", 0, 0); BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); VPointF *center = new VPointF(arc->GetCenter()); - Q_CHECK_PTR(center); BiasRotatePoint(center, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); QLineF l1(center->toQPointF(), p1.toQPointF()); QLineF l2(center->toQPointF(), p2.toQPointF()); - center->setMode(Draw::Modeling); - qint64 idCenter = data->AddGObject(center); + center->setMode(Valentina::Modeling); + quint32 idCenter = data->AddGObject(center); Q_UNUSED(idCenter); VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(), QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())); - Q_CHECK_PTR(arc1); - arc1->setMode(Draw::Modeling); + arc1->setMode(Valentina::Modeling); idObject = data->AddGObject(arc1); VArc *arc2 = new VArc(*arc1); - Q_CHECK_PTR(arc2); - arc2->setMode(Draw::Modeling); + arc2->setMode(Valentina::Modeling); id = data->AddGObject(arc2); - VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Valentina::FromGui, idTool, tool); } } break; - case (Tool::NodeSpline): + case (Valentina::NodeSpline): { if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { @@ -135,9 +130,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai const VSpline *spline = data->GeometricObject(det.at(i).getId()); VPointF *p1 = new VPointF(spline->GetP1()); - Q_CHECK_PTR(p1); BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - qint64 idP1 = data->AddGObject(p1); + quint32 idP1 = data->AddGObject(p1); VPointF p2 = VPointF(spline->GetP2()); BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); @@ -146,24 +140,21 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); VPointF *p4 = new VPointF(spline->GetP4()); - Q_CHECK_PTR(p4); BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - qint64 idP4 = data->AddGObject(p4); + quint32 idP4 = data->AddGObject(p4); VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0, - Draw::Modeling); - Q_CHECK_PTR(spl); + Valentina::Modeling); idObject = data->AddGObject(spl); VSpline *spl1 = new VSpline(*spl); - Q_CHECK_PTR(spl1); - spl1->setMode(Draw::Modeling); + spl1->setMode(Valentina::Modeling); id = data->AddGObject(spl1); - VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Valentina::FromGui, idTool, tool); } } break; - case (Tool::NodeSplinePath): + case (Valentina::NodeSplinePath): { if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { @@ -172,8 +163,7 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai else { VSplinePath *path = new VSplinePath(); - Q_CHECK_PTR(path); - path->setMode(Draw::Modeling); + path->setMode(Valentina::Modeling); const VSplinePath *splinePath = data->GeometricObject(det.at(i).getId()); qint32 k = splinePath->getMaxCountPoints(); for (qint32 i = 1; i <= splinePath->Count(); ++i) @@ -183,10 +173,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai splinePath->at(i).KAsm1(), splinePath->getKCurve()); VPointF *p1 = new VPointF(spline.GetP1()); - Q_CHECK_PTR(p1); BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - qint64 idP1 = data->AddGObject(p1); + quint32 idP1 = data->AddGObject(p1); --k; VPointF p2 = VPointF(spline.GetP2()); @@ -198,10 +187,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai angle); VPointF *p4 = new VPointF(spline.GetP4()); - Q_CHECK_PTR(p4); BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - qint64 idP4 = data->AddGObject(p4); + quint32 idP4 = data->AddGObject(p4); --k; VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve()); @@ -221,33 +209,31 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai idObject = data->AddGObject(path); VSplinePath *path1 = new VSplinePath(*path); - Q_CHECK_PTR(path1); - path1->setMode(Draw::Modeling); + path1->setMode(Valentina::Modeling); id = data->AddGObject(path1); - VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Valentina::FromGui, idTool, tool); } } break; default: - qWarning()<<"May be wrong tool type!!! Ignoring."<GeometricObject(det.at(i).getId())); - Q_CHECK_PTR(point); - point->setMode(Draw::Modeling); + point->setMode(Valentina::Modeling); BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); ++idCount; data->UpdateGObject(idDetail+idCount, point); @@ -256,7 +242,7 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c } } break; - case (Tool::NodeArc): + case (Valentina::NodeArc): { if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) { @@ -266,19 +252,17 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c VPointF p2 = VPointF(arc->GetP2()); BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); VPointF *center = new VPointF(arc->GetCenter()); - Q_CHECK_PTR(center); BiasRotatePoint(center, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); QLineF l1(center->toQPointF(), p1.toQPointF()); QLineF l2(center->toQPointF(), p2.toQPointF()); ++idCount; - center->setMode(Draw::Modeling); + center->setMode(Valentina::Modeling); data->UpdateGObject(idDetail+idCount, center); VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(), QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())); - Q_CHECK_PTR(arc1); - arc1->setMode(Draw::Modeling); + arc1->setMode(Valentina::Modeling); ++idCount; data->UpdateGObject(idDetail+idCount, arc1); @@ -286,14 +270,13 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c } } break; - case (Tool::NodeSpline): + case (Valentina::NodeSpline): { if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) { const VSpline *spline = data->GeometricObject(det.at(i).getId()); VPointF *p1 = new VPointF(spline->GetP1()); - Q_CHECK_PTR(p1); BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); ++idCount; data->UpdateGObject(idDetail+idCount, p1); @@ -305,15 +288,13 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); VPointF *p4 = new VPointF(spline->GetP4()); - Q_CHECK_PTR(p4); BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); ++idCount; data->UpdateGObject(idDetail+idCount, p4); VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0, - Draw::Modeling); + Valentina::Modeling); - Q_CHECK_PTR(spl); ++idCount; data->UpdateGObject(idDetail+idCount, spl); @@ -321,13 +302,12 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c } } break; - case (Tool::NodeSplinePath): + case (Valentina::NodeSplinePath): { if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) { VSplinePath *path = new VSplinePath(); - Q_CHECK_PTR(path); - path->setMode(Draw::Modeling); + path->setMode(Valentina::Modeling); const VSplinePath *splinePath = data->GeometricObject(det.at(i).getId()); Q_CHECK_PTR(splinePath); qint32 k = splinePath->getMaxCountPoints(); @@ -338,7 +318,6 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c splinePath->at(i).KAsm1(), splinePath->getKCurve()); VPointF *p1 = new VPointF(spline.GetP1()); - Q_CHECK_PTR(p1); BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); ++idCount; @@ -354,7 +333,6 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c angle); VPointF *p4 = new VPointF(spline.GetP4()); - Q_CHECK_PTR(p4); BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); ++idCount; @@ -386,7 +364,7 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c } break; default: - qWarning()<<"May be wrong tool type!!! Ignoring."<setY(line.p2().y()); } -void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) +void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); DialogUnionDetails *dialogTool = qobject_cast(dialog); @@ -412,17 +390,17 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VD ptrdiff_t indexD1 = dialogTool->getIndexD1(); ptrdiff_t indexD2 = dialogTool->getIndexD2(); Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, - Tool::FromGui); + Valentina::FromGui); } -void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, - const qint64 &d2id, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, const Tool::Sources &typeCreation) +void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, + const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document::Documents &parse, const Valentina::Sources &typeCreation) { VToolUnionDetails *unionDetails = 0; - qint64 id = _id; - if (typeCreation == Tool::FromGui) + quint32 id = _id; + if (typeCreation == Valentina::FromGui) { id = data->getNextId(); } @@ -433,12 +411,12 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai doc->UpdateToolData(id, data); } } - VAbstractTool::AddRecord(id, Tool::UnionDetails, doc); + VAbstractTool::AddRecord(id, Valentina::UnionDetails, doc); if (parse == Document::FullParse) { //Scene doesn't show this tool, so doc will destroy this object. unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc); - QHash* tools = doc->getTools(); + QHash* tools = doc->getTools(); tools->insert(id, unionDetails); for (ptrdiff_t i = 0; i < d1.CountNode(); ++i) { @@ -450,170 +428,135 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai } } + VNodeDetail det1p1; + VNodeDetail det1p2; + d1.NodeOnEdge(indexD1, det1p1, det1p2); + Q_UNUSED(det1p2); - if (typeCreation == Tool::FromGui) + VPointF point1; + VPointF point2; + PointsOnEdge(d1, indexD1, point1, point2, data); + + VPointF point3; + VPointF point4; + PointsOnEdge(d2, indexD2, point3, point4, data); + + const qreal dx = point1.x() - point4.x(); + const qreal dy = point1.y() - point4.y(); + + point3.setX(point3.x()+dx); + point3.setY(point3.y()+dy); + + point4.setX(point4.x()+dx); + point4.setY(point4.y()+dy); + + const qreal angle = QLineF(point4.toQPointF(), point3.toQPointF()).angleTo(QLineF(point1.toQPointF(), + point2.toQPointF())); + qint32 pointsD2 = 0; //Keeps count points second detail, what we already add. + + if (typeCreation == Valentina::FromGui) { - VDetail uD1 = d1.RemoveEdge(indexD1); - VDetail uD2 = d2.RemoveEdge(indexD2); qint32 j = 0, i = 0; - qint32 nD1 = uD1.CountNode(); - qint32 nD2 = uD2.CountNode(); - qint32 pointsD2 = 0; //Keeps count points second detail, what we already add. VDetail newDetail; - - VNodeDetail det1p1; - VNodeDetail det1p2; - d1.NodeOnEdge(indexD1, det1p1, det1p2); - const VPointF *point1 = data->GeometricObject(det1p1.getId()); - const VPointF *point2 = data->GeometricObject(det1p2.getId()); - - VNodeDetail det2p1; - VNodeDetail det2p2; - d2.NodeOnEdge(indexD2, det2p1, det2p2); - VPointF point3 = VPointF(*data->GeometricObject(det2p1.getId())); - VPointF point4 = VPointF(*data->GeometricObject(det2p2.getId())); - - qreal dx = point1->x() - point4.x(); - qreal dy = point1->y() - point4.y(); - - point3.setX(point3.x()+dx); - point3.setY(point3.y()+dy); - - point4.setX(point4.x()+dx); - point4.setY(point4.y()+dy); - - QLineF l1(point1->toQPointF(), point2->toQPointF()); - QLineF l2(point4.toQPointF(), point3.toQPointF()); - qreal angle = l2.angleTo(l1); - - ptrdiff_t iD1 = d1.indexOfNode(det1p1.getId()); - do { - AddToNewDetail(unionDetails, doc, data, newDetail, uD1, i, id); + AddToNewDetail(unionDetails, doc, data, newDetail, d1.RemoveEdge(indexD1), i, id); ++i; - if (i > iD1 && pointsD2 < nD2-2) + if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2) { do { - if (pointsD2 == 0) - { - VNodeDetail node1; - VNodeDetail node2; - d2.NodeOnEdge(indexD2, node1, node2); - ptrdiff_t k = uD2.indexOfNode(node2.getId()); - if (k == uD2.CountNode()-1) - { - j = 0; - } - else - { - j = uD2.indexOfNode(node2.getId())+1; - } - } - if (pointsD2 == nD2 -2) + FindJ(pointsD2, d2, indexD2, j); + if (pointsD2 == d2.RemoveEdge(indexD2).CountNode() -2) { break; } - if (j >= nD2) + if (j >= d2.RemoveEdge(indexD2).CountNode()) { j=0; } - AddToNewDetail(unionDetails, doc, data, newDetail, uD2, j, id, dx, dy, det1p1.getId(), angle); + AddToNewDetail(unionDetails, doc, data, newDetail, d2.RemoveEdge(indexD2), j, id, dx, dy, + det1p1.getId(), angle); ++pointsD2; ++j; - } while (pointsD2 < nD2); + } while (pointsD2 < d2.RemoveEdge(indexD2).CountNode()); } - } while(i* tools = doc->getTools(); + VToolDetail::Create(0, newDetail, scene, doc, data, parse, Valentina::FromTool); + QHash* tools = doc->getTools(); + Q_CHECK_PTR(tools); - VToolDetail *toolDet = qobject_cast(tools->value(d1id)); - toolDet->Remove(); + { + VToolDetail *toolDet = qobject_cast(tools->value(d1id)); + Q_CHECK_PTR(toolDet); + toolDet->Remove(); + } - toolDet = qobject_cast(tools->value(d2id)); + VToolDetail *toolDet = qobject_cast(tools->value(d2id)); + Q_CHECK_PTR(toolDet); toolDet->Remove(); } else { - VDetail uD1 = d1.RemoveEdge(indexD1); - VDetail uD2 = d2.RemoveEdge(indexD2); - qint64 idCount = 0; + quint32 idCount = 0; qint32 j = 0, i = 0; - qint32 nD1 = uD1.CountNode(); - qint32 nD2 = uD2.CountNode(); - qint32 pointsD2 = 0; //Keeps count points second detail, what we already add. - - VNodeDetail det1p1; - VNodeDetail det1p2; - d1.NodeOnEdge(indexD1, det1p1, det1p2); - const VPointF *point1 = data->GeometricObject(det1p1.getId()); - const VPointF *point2 = data->GeometricObject(det1p2.getId()); - - VNodeDetail det2p1; - VNodeDetail det2p2; - d2.NodeOnEdge(indexD2, det2p1, det2p2); - VPointF point3 = VPointF(*data->GeometricObject(det2p1.getId())); - VPointF point4 = VPointF(*data->GeometricObject(det2p2.getId())); - - qreal dx = point1->x() - point4.x(); - qreal dy = point1->y() - point4.y(); - - point3.setX(point3.x()+dx); - point3.setY(point3.y()+dy); - - point4.setX(point4.x()+dx); - point4.setY(point4.y()+dy); - - QLineF l1(point1->toQPointF(), point2->toQPointF()); - QLineF l2(point4.toQPointF(), point3.toQPointF()); - qreal angle = l2.angleTo(l1); - - ptrdiff_t iD1 = d1.indexOfNode(det1p1.getId()); - do { - UpdatePoints(id, data, uD1, i, idCount); + UpdatePoints(id, data, d1.RemoveEdge(indexD1), i, idCount); ++i; - if (i > iD1 && pointsD2 < nD2-2) + if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2) { do { - if (pointsD2 == 0) - { - VNodeDetail node1; - VNodeDetail node2; - d2.NodeOnEdge(indexD2, node1, node2); - ptrdiff_t k = uD2.indexOfNode(node2.getId()); - if (k == uD2.CountNode()-1) - { - j = 0; - } - else - { - j = uD2.indexOfNode(node2.getId())+1; - } - } - if (pointsD2 == nD2-2) + FindJ(pointsD2, d2, indexD2, j); + if (pointsD2 == d2.RemoveEdge(indexD2).CountNode()-2) { break; } - if (j >= nD2) + if (j >= d2.RemoveEdge(indexD2).CountNode()) { j=0; } - UpdatePoints(id, data, uD2, j, idCount, dx, dy, det1p1.getId(), angle); + UpdatePoints(id, data, d2.RemoveEdge(indexD2), j, idCount, dx, dy, det1p1.getId(), angle); ++pointsD2; ++j; - } while (pointsD2 < nD2); + } while (pointsD2 < d2.RemoveEdge(indexD2).CountNode()); } - } while (i VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement) +void VToolUnionDetails::PointsOnEdge(const VDetail &d, const qint32 &index, VPointF &p1, VPointF &p2, VContainer *data) +{ + VNodeDetail det2p1; + VNodeDetail det2p2; + d.NodeOnEdge(index, det2p1, det2p2); + p1 = VPointF(*data->GeometricObject(det2p1.getId())); + p2 = VPointF(*data->GeometricObject(det2p2.getId())); +} + +void VToolUnionDetails::FindJ(const qint32 &pointsD2, const VDetail &d2, const qint32 &indexD2, qint32 &j) +{ + if (pointsD2 == 0) + { + VNodeDetail node1; + VNodeDetail node2; + d2.NodeOnEdge(indexD2, node1, node2); + ptrdiff_t k = d2.RemoveEdge(indexD2).indexOfNode(node2.getId()); + if (k == d2.RemoveEdge(indexD2).CountNode()-1) + { + j = 0; + } + else + { + j = d2.RemoveEdge(indexD2).indexOfNode(node2.getId())+1; + } + } +} + +QVector VToolUnionDetails::GetDetailFromFile(VPattern *doc, const QDomElement &domElement) { QVector vector; QDomNodeList detailList = domElement.childNodes(); @@ -635,27 +578,27 @@ QVector VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const Q { if (element.tagName() == VToolUnionDetails::TagNode) { - qint64 id = doc->GetParametrLongLong(element, VToolDetail::AttrIdObject, "0"); - qreal mx = toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMx, "0.0")); - qreal my = toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMy, "0.0")); - Tool::Tools tool; + quint32 id = doc->GetParametrUInt(element, VToolDetail::AttrIdObject, "0"); + qreal mx = qApp->toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMx, "0.0")); + qreal my = qApp->toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMy, "0.0")); + Valentina::Tools tool; NodeDetail::NodeDetails nodeType = NodeDetail::Contour; QString t = doc->GetParametrString(element, "type", "NodePoint"); if (t == "NodePoint") { - tool = Tool::NodePoint; + tool = Valentina::NodePoint; } else if (t == "NodeArc") { - tool = Tool::NodeArc; + tool = Valentina::NodeArc; } else if (t == "NodeSpline") { - tool = Tool::NodeSpline; + tool = Valentina::NodeSpline; } else if (t == "NodeSplinePath") { - tool = Tool::NodeSplinePath; + tool = Valentina::NodeSplinePath; } d.append(VNodeDetail(id, tool, nodeType, mx, my)); } @@ -672,10 +615,10 @@ void VToolUnionDetails::AddToFile() { QDomElement domElement = doc->createElement(TagName); - SetAttribute(domElement, AttrId, id); - SetAttribute(domElement, AttrType, ToolType); - SetAttribute(domElement, AttrIndexD1, indexD1); - SetAttribute(domElement, AttrIndexD2, indexD2); + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrType, ToolType); + doc->SetAttribute(domElement, AttrIndexD1, indexD1); + doc->SetAttribute(domElement, AttrIndexD2, indexD2); AddDetail(domElement, d1); AddDetail(domElement, d2); @@ -688,8 +631,8 @@ void VToolUnionDetails::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - SetAttribute(domElement, AttrIndexD1, indexD1); - SetAttribute(domElement, AttrIndexD2, indexD2); + doc->SetAttribute(domElement, AttrIndexD1, indexD1); + doc->SetAttribute(domElement, AttrIndexD2, indexD2); QDomNode domNode = domElement.firstChild(); domNode = UpdateDetail(domNode, d1); @@ -713,33 +656,33 @@ void VToolUnionDetails::AddNode(QDomElement &domElement, const VNodeDetail &node { QDomElement nod = doc->createElement(TagNode); - SetAttribute(nod, AttrIdObject, node.getId()); - SetAttribute(nod, AttrMx, toMM(node.getMx())); - SetAttribute(nod, AttrMy, toMM(node.getMy())); + doc->SetAttribute(nod, AttrIdObject, node.getId()); + doc->SetAttribute(nod, AttrMx, qApp->fromPixel(node.getMx())); + doc->SetAttribute(nod, AttrMy, qApp->fromPixel(node.getMy())); if (node.getTypeNode() == NodeDetail::Contour) { - SetAttribute(nod, AttrNodeType, NodeTypeContour); + doc->SetAttribute(nod, AttrNodeType, NodeTypeContour); } else { - SetAttribute(nod, AttrNodeType, NodeTypeModeling); + doc->SetAttribute(nod, AttrNodeType, NodeTypeModeling); } switch (node.getTypeTool()) { - case (Tool::NodeArc): - SetAttribute(nod, AttrType, QStringLiteral("NodeArc")); + case (Valentina::NodeArc): + doc->SetAttribute(nod, AttrType, QStringLiteral("NodeArc")); break; - case (Tool::NodePoint): - SetAttribute(nod, AttrType, QStringLiteral("NodePoint")); + case (Valentina::NodePoint): + doc->SetAttribute(nod, AttrType, QStringLiteral("NodePoint")); break; - case (Tool::NodeSpline): - SetAttribute(nod, AttrType, QStringLiteral("NodeSpline")); + case (Valentina::NodeSpline): + doc->SetAttribute(nod, AttrType, QStringLiteral("NodeSpline")); break; - case (Tool::NodeSplinePath): - SetAttribute(nod, AttrType, QStringLiteral("NodeSplinePath")); + case (Valentina::NodeSplinePath): + doc->SetAttribute(nod, AttrType, QStringLiteral("NodeSplinePath")); break; default: - qWarning()<<"May be wrong tool type!!! Ignoring."<GetActivModelingElement(modelingElement); + bool ok = doc->GetActivNodeElement(VPattern::TagModeling, modelingElement); if (ok) { modelingElement.appendChild(domElement); diff --git a/src/tools/vtooluniondetails.h b/src/tools/vtooluniondetails.h index 98c4b3eac..43e3dd014 100644 --- a/src/tools/vtooluniondetails.h +++ b/src/tools/vtooluniondetails.h @@ -30,7 +30,7 @@ #define VTOOLUNIONDETAILS_H #include "vabstracttool.h" -#include "../dialogs/dialoguniondetails.h" +#include "../dialogs/tools/dialoguniondetails.h" /** * @brief The VToolUnionDetails class tool union details. @@ -51,9 +51,9 @@ public: * @param typeCreation way we create this tool. * @param parent parent object. */ - VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, const VDetail &d2, - const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, - const Tool::Sources &typeCreation, QObject *parent = 0); + VToolUnionDetails(VPattern *doc, VContainer *data, const quint32 &id, const VDetail &d1, const VDetail &d2, + const quint32 &indexD1, const quint32 &indexD2, const Valentina::Sources &typeCreation, + QObject *parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -80,17 +80,19 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, const qint64 &d2id, - const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation); + static void Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, + const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document::Documents &parse, + const Valentina::Sources &typeCreation); + static void PointsOnEdge(const VDetail &d, const qint32 &index, VPointF &p1, VPointF &p2, VContainer *data); + static void FindJ(const qint32 &pointsD2, const VDetail &d2, const qint32 &indexD2, qint32 &j); /** * @brief GetDetailFromFile parse detail from file. * @param doc dom document container. * @param domElement tag in xml tree. * @return detail stored in file. */ - static QVector GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement); + static QVector GetDetailFromFile(VPattern *doc, const QDomElement &domElement); static const QString TagName; static const QString ToolType; static const QString TagDetail; @@ -115,9 +117,9 @@ public: * @param pRotate point rotation. * @param angle angle rotation. */ - static void AddToNewDetail(QObject *tool, VDomDocument *doc, VContainer *data, VDetail &newDetail, - const VDetail &det, const ptrdiff_t &i, const qint64 &idTool, const qreal &dx = 0, - const qreal &dy = 0, const qint64 &pRotate = 0, const qreal &angle = 0); + static void AddToNewDetail(QObject *tool, VPattern *doc, VContainer *data, VDetail &newDetail, + const VDetail &det, const ptrdiff_t &i, const quint32 &idTool, const qreal &dx = 0, + const qreal &dy = 0, const quint32 &pRotate = 0, const qreal &angle = 0); /** * @brief UpdatePoints update data for united details. * @param idDetail id united detail. @@ -130,8 +132,8 @@ public: * @param pRotate point rotation. * @param angle angle rotation. */ - static void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i, - qint64 &idCount, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, + static void UpdatePoints(const quint32 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i, + quint32 &idCount, const qreal &dx = 0, const qreal &dy = 0, const quint32 &pRotate = 0, const qreal &angle = 0); /** * @brief BiasRotatePoint bias and rotate point. @@ -170,11 +172,11 @@ private: /** * @brief indexD1 index edge in first detail. */ - ptrdiff_t indexD1; + quint32 indexD1; /** * @brief indexD2 index edge in second detail. */ - ptrdiff_t indexD2; + quint32 indexD2; /** * @brief AddDetail add detail to xml file. * @param domElement tag in xml tree. diff --git a/src/widgets/doubledelegate.cpp b/src/widgets/doubledelegate.cpp index 1b2bccf23..596bbbd91 100644 --- a/src/widgets/doubledelegate.cpp +++ b/src/widgets/doubledelegate.cpp @@ -37,7 +37,6 @@ QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOption Q_UNUSED(option); Q_UNUSED(index); QDoubleSpinBox *editor = new QDoubleSpinBox(parent); - Q_CHECK_PTR(editor); editor->setMinimum(-10000.0); editor->setMaximum(10000.0); connect(editor, &QDoubleSpinBox::editingFinished, this, &DoubleSpinBoxDelegate::commitAndCloseEditor); diff --git a/src/widgets/doubledelegate.h b/src/widgets/doubledelegate.h index fde48b36b..f515b14cb 100644 --- a/src/widgets/doubledelegate.h +++ b/src/widgets/doubledelegate.h @@ -43,7 +43,7 @@ public: * @brief DoubleSpinBoxDelegate constructor. * @param parent parent object. */ - DoubleSpinBoxDelegate(QObject *parent = 0): QItemDelegate(parent), lastValue(-10001.0){} + DoubleSpinBoxDelegate(QObject *parent = nullptr): QItemDelegate(parent), lastValue(-10001.0){} /** * @brief createEditorReturns the widget used to edit the item specified by index for editing. The parent widget and * style option are used to control how the editor widget appears. diff --git a/src/widgets/textdelegate.cpp b/src/widgets/textdelegate.cpp index 54050cb06..9fd9e9c43 100644 --- a/src/widgets/textdelegate.cpp +++ b/src/widgets/textdelegate.cpp @@ -30,7 +30,8 @@ #include -TextDelegate::TextDelegate(QObject *parent): QItemDelegate(parent), lastText(QString("Name_")) +TextDelegate::TextDelegate(const QString ®ex, QObject *parent): QItemDelegate(parent), lastText(QString("Name_")), + regex(regex) { //Little hack. Help save lineedit text in const method. connect(this, &TextDelegate::SaveText, this, &TextDelegate::InitText); @@ -41,11 +42,8 @@ QWidget *TextDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem Q_UNUSED(option); Q_UNUSED(index); QLineEdit *editor = new QLineEdit(parent); - Q_CHECK_PTR(editor); - QRegExp re("^(([^+ -/()\\^*%:;\"\'=.,><0-9]){1,1}[^+ -/()\\^*%:;\"\'=><]([0-9]){0,}){0,}$"); - QRegExpValidator *v = new QRegExpValidator(re); - Q_CHECK_PTR(v); - editor->setValidator( v ); + //Same regex pattern in xsd file + editor->setValidator( new QRegExpValidator(QRegExp(regex)) ); connect(editor, &QLineEdit::editingFinished, this, &TextDelegate::commitAndCloseEditor); return editor; } @@ -69,7 +67,7 @@ void TextDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, cons QLineEdit *lineEdit = qobject_cast(editor); Q_CHECK_PTR(lineEdit); QString text = lineEdit->text(); - if(text.isEmpty()) + if (text.isEmpty()) { text = lastText; } @@ -94,7 +92,7 @@ void TextDelegate::commitAndCloseEditor() lastText = text; emit commitData(lineEdit); } - else if(text.isEmpty() == false) + else if (text.isEmpty() == false) { lineEdit->setText(lastText); emit commitData(lineEdit); diff --git a/src/widgets/textdelegate.h b/src/widgets/textdelegate.h index 5bdac8a6e..c904e2223 100644 --- a/src/widgets/textdelegate.h +++ b/src/widgets/textdelegate.h @@ -43,7 +43,7 @@ public: * @brief TextDelegate constructor. * @param parent parent widget. */ - explicit TextDelegate(QObject *parent = 0); + TextDelegate(const QString ®ex, QObject *parent = nullptr); /** * @brief createEditorReturns the widget used to edit the item specified by index for editing. The parent widget and * style option are used to control how the editor widget appears. @@ -96,6 +96,7 @@ private: * @brief lastValue last saved value. */ QString lastText; + QString regex; }; #endif // TEXTDELEGATE_H diff --git a/src/widgets/vapplication.cpp b/src/widgets/vapplication.cpp index 0a4d7eaca..45ecac5d6 100644 --- a/src/widgets/vapplication.cpp +++ b/src/widgets/vapplication.cpp @@ -31,91 +31,58 @@ #include "../exception/vexceptionbadid.h" #include "../exception/vexceptionconversionerror.h" #include "../exception/vexceptionemptyparameter.h" -#include "../exception/vexceptionwrongparameterid.h" +#include "../exception/vexceptionwrongid.h" #include #include +const qreal VApplication::PrintDPI = 96.0; + +#define DefWidth 1.2//mm + +VApplication::VApplication(int &argc, char **argv) + : QApplication(argc, argv), _patternUnit(Valentina::Cm), _patternType(Pattern::Individual), + _widthMainLine(DefWidth), _widthHairLine(DefWidth/3.0) +{ + InitLineWidth(); +} + // reimplemented from QApplication so we can throw exceptions in slots bool VApplication::notify(QObject *receiver, QEvent *event) { try { - return QApplication::notify(receiver, event); + return QApplication::notify(receiver, event); } catch (const VExceptionObjectError &e) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error parsing file. Program will be terminated.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(e.DetailedInformation()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); + e.CriticalMessageBox(tr("Error parsing file. Program will be terminated.")); abort(); } catch (const VExceptionBadId &e) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error bad id. Program will be terminated.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); + e.CriticalMessageBox(tr("Error bad id. Program will be terminated.")); abort(); } catch (const VExceptionConversionError &e) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error can't convert value. Program will be terminated.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); + e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated.")); abort(); } catch (const VExceptionEmptyParameter &e) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error empty parameter. Program will be terminated.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(e.DetailedInformation()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); + e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated.")); abort(); } - catch (const VExceptionWrongParameterId &e) + catch (const VExceptionWrongId &e) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error wrong id. Program will be terminated.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(e.DetailedInformation()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); + e.CriticalMessageBox(tr("Error wrong id. Program will be terminated.")); abort(); } catch (const VException &e) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Something's wrong!!")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); + e.CriticalMessageBox(tr("Something's wrong!!")); + return true; } catch (std::exception& e) { @@ -123,3 +90,111 @@ bool VApplication::notify(QObject *receiver, QEvent *event) } return false; } + +double VApplication::toPixel(double unit) const +{ + double result = 0; + switch (_patternUnit) + { + case Valentina::Mm: + result = (unit / 25.4) * PrintDPI; + break; + case Valentina::Cm: + result = ((unit * 10.0) / 25.4) * PrintDPI; + break; + case Valentina::Inch: + result = unit * PrintDPI; + break; + default: + break; + } + return result; +} + +double VApplication::fromPixel(double pix) const +{ + double result = 0; + switch (_patternUnit) + { + case Valentina::Mm: + result = (pix / PrintDPI) * 25.4; + break; + case Valentina::Cm: + result = ((pix / PrintDPI) * 25.4) / 10.0; + break; + case Valentina::Inch: + result = pix / PrintDPI; + break; + default: + break; + } + return result; +} +QString VApplication::pathToTables() const +{ + if (_patternType == Pattern::Individual) + { + #ifdef Q_OS_WIN + return QApplication::applicationDirPath() + QStringLiteral("/tables/individual"); + #else + #ifdef QT_DEBUG + return QApplication::applicationDirPath() + QStringLiteral("/tables/individual"); + #else + return QStringLiteral("/usr/share/valentina/tables/individual"); + #endif + #endif + } + else + { + #ifdef Q_OS_WIN + return QApplication::applicationDirPath() + QStringLiteral("/tables/standard"); + #else + #ifdef QT_DEBUG + return QApplication::applicationDirPath() + QStringLiteral("/tables/standard"); + #else + return QStringLiteral("/usr/share/valentina/tables/standard"); + #endif + #endif + } +} + +QString VApplication::translationsPath() const +{ +#ifdef Q_OS_WIN + return QApplication::applicationDirPath() + QStringLiteral("/translations"); +#else +#ifdef QT_DEBUG + return QApplication::applicationDirPath() + QStringLiteral("/translations"); + #else + return QStringLiteral("/usr/share/valentina/translations"); + #endif + #endif +} + + +void VApplication::InitLineWidth() +{ + switch(_patternUnit) + { + case Valentina::Mm: + _widthMainLine = DefWidth; + break; + case Valentina::Cm: + _widthMainLine = DefWidth/10.0; + break; + case Valentina::Inch: + _widthMainLine = DefWidth/25.4; + break; + default: + _widthMainLine = DefWidth; + break; + } + _widthHairLine = _widthMainLine/3.0; +} + + +void VApplication::setPatternUnit(const Valentina::Units &patternUnit) +{ + _patternUnit = patternUnit; + InitLineWidth(); +} diff --git a/src/widgets/vapplication.h b/src/widgets/vapplication.h index 2320d3fe1..c6a3ff14f 100644 --- a/src/widgets/vapplication.h +++ b/src/widgets/vapplication.h @@ -30,6 +30,14 @@ #define VAPPLICATION_H #include +#include "../options.h" + +class VApplication; + +#if defined(qApp) +#undef qApp +#endif +#define qApp (static_cast(QCoreApplication::instance())) /** * @brief The VApplication class reimplamentation QApplication class. @@ -43,7 +51,7 @@ public: * @param argc number arguments. * @param argv command line. */ - VApplication(int &argc, char ** argv): QApplication(argc, argv){} + VApplication(int &argc, char ** argv); virtual ~VApplication() {} /** * @brief notify Reimplemented from QApplication::notify(). @@ -51,7 +59,49 @@ public: * @param event event. * @return value that is returned from the receiver's event handler. */ - virtual bool notify(QObject * receiver, QEvent * event); + virtual bool notify(QObject * receiver, QEvent * event); + Valentina::Units patternUnit() const; + void setPatternUnit(const Valentina::Units &patternUnit); + Pattern::Measurements patternType() const; + void setPatternType(const Pattern::Measurements &patternType); + double toPixel(double unit) const; + double fromPixel(double pix) const; + static const qreal PrintDPI; + QString translationsPath() const; + QString pathToTables() const; + qreal widthMainLine() const; + qreal widthHairLine() const; +private: + Valentina::Units _patternUnit; + Pattern::Measurements _patternType; + qreal _widthMainLine; + qreal _widthHairLine; + void InitLineWidth(); }; +inline Valentina::Units VApplication::patternUnit() const +{ + return _patternUnit; +} + +inline Pattern::Measurements VApplication::patternType() const +{ + return _patternType; +} + +inline void VApplication::setPatternType(const Pattern::Measurements &patternType) +{ + _patternType = patternType; +} + +inline qreal VApplication::widthMainLine() const +{ + return _widthMainLine; +} + +inline qreal VApplication::widthHairLine() const +{ + return _widthHairLine; +} + #endif // VAPPLICATION_H diff --git a/src/widgets/vcontrolpointspline.cpp b/src/widgets/vcontrolpointspline.cpp index a918bb943..9f850ff44 100644 --- a/src/widgets/vcontrolpointspline.cpp +++ b/src/widgets/vcontrolpointspline.cpp @@ -30,17 +30,19 @@ #include "../tools/vabstracttool.h" #include +#include "../widgets/vapplication.h" VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint, QGraphicsItem *parent) - :QGraphicsEllipseItem(parent), radius(toPixel(1.5)), controlLine(0), indexSpline(indexSpline), position(position) + :QGraphicsEllipseItem(parent), radius(qApp->toPixel(1.5)), controlLine(nullptr), indexSpline(indexSpline), + position(position) { //create circle QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); - this->setPen(QPen(Qt::black, toPixel(widthHairLine))); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -51,20 +53,20 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePoint: QPointF p1, p2; VAbstractTool::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); controlLine = new QGraphicsLineItem(QLineF(splinePoint-controlPoint, p1), this); - controlLine->setPen(QPen(Qt::red, toPixel(widthHairLine))); + controlLine->setPen(QPen(Qt::red, qApp->toPixel(qApp->widthHairLine()))); controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } void VControlPointSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(Qt::black, toPixel(widthMainLine))); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); } void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(Qt::black, toPixel(widthHairLine))); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); } QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) @@ -93,14 +95,14 @@ void VControlPointSpline::setEnabledPoint(bool enable) { if (enable == true) { - this->setPen(QPen(Qt::black, toPixel(widthHairLine))); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setAcceptHoverEvents(true); } else { - this->setPen(QPen(Qt::gray, toPixel(widthHairLine))); + this->setPen(QPen(Qt::gray, qApp->toPixel(qApp->widthHairLine()))); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setFlag(QGraphicsItem::ItemIsMovable, false); this->setAcceptHoverEvents(false); diff --git a/src/widgets/vcontrolpointspline.h b/src/widgets/vcontrolpointspline.h index 60e8b5b54..550420bfb 100644 --- a/src/widgets/vcontrolpointspline.h +++ b/src/widgets/vcontrolpointspline.h @@ -50,7 +50,7 @@ public: */ VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint, - QGraphicsItem * parent = 0); + QGraphicsItem * parent = nullptr); signals: /** * @brief ControlPointChangePosition emit when control point change position. diff --git a/src/widgets/vgraphicssimpletextitem.h b/src/widgets/vgraphicssimpletextitem.h index f21454f4d..4c6967a60 100644 --- a/src/widgets/vgraphicssimpletextitem.h +++ b/src/widgets/vgraphicssimpletextitem.h @@ -42,13 +42,13 @@ public: * @brief VGraphicsSimpleTextItem default constructor. * @param parent parent object. */ - VGraphicsSimpleTextItem(QGraphicsItem * parent = 0); + VGraphicsSimpleTextItem(QGraphicsItem * parent = nullptr); /** * @brief VGraphicsSimpleTextItem constructor. * @param text text. * @param parent parent object. */ - VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = 0 ); + VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = nullptr ); /** * @brief FontSize return label font size. * @return font size. diff --git a/src/widgets/vitem.cpp b/src/widgets/vitem.cpp index 68dda487b..698a1e1f2 100644 --- a/src/widgets/vitem.cpp +++ b/src/widgets/vitem.cpp @@ -27,20 +27,31 @@ *************************************************************************/ #include "vitem.h" -#include "../options.h" #include #include +#include "../widgets/vapplication.h" VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent ) - :QGraphicsPathItem ( path, parent ), numInOutList(numInList), paper(0) + :QGraphicsPathItem ( path, parent ), numInOutList(numInList), paper(nullptr) { } +VItem::VItem():numInOutList(0), paper(nullptr) +{ + +} + +VItem::VItem(int numInList, QGraphicsItem *parent):QGraphicsPathItem (parent), numInOutList(numInList), + paper(nullptr) +{ + +} + void VItem::checkItemChange() { QRectF rect; - if (paper == 0) + if (paper == nullptr) { qDebug()<<"Don't set paper for detail!!!!"; rect = this->scene()->sceneRect(); @@ -52,19 +63,19 @@ void VItem::checkItemChange() QRectF myrect = sceneBoundingRect(); if ( rect.contains( myrect )==true ) { - setPen(QPen(Qt::black, toPixel(widthMainLine))); + setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); emit itemOut( numInOutList, false ); } else { - setPen(QPen(Qt::red, toPixel(widthMainLine))); + setPen(QPen(Qt::red, qApp->toPixel(qApp->widthMainLine()))); emit itemOut( numInOutList, true ); } QList list = QGraphicsItem::collidingItems (); if ( list.size() - 2 > 0 ) { list.append( this ); - setPen(QPen(Qt::red, toPixel(widthMainLine))); + setPen(QPen(Qt::red, qApp->toPixel(qApp->widthMainLine()))); emit itemColliding( list, 1 );//Detail intersect with other details. } else diff --git a/src/widgets/vitem.h b/src/widgets/vitem.h index cc2df7284..4822e0f4b 100644 --- a/src/widgets/vitem.h +++ b/src/widgets/vitem.h @@ -42,21 +42,20 @@ public: /** * @brief VItem default constructor. */ - VItem ():numInOutList(0), paper(0){} + VItem (); /** * @brief VItem constructor. * @param numInList index in list of details. * @param parent parent object. */ - VItem (int numInList, QGraphicsItem * parent = 0):QGraphicsPathItem (parent), numInOutList(numInList), - paper(0){} + VItem (int numInList, QGraphicsItem * parent = nullptr); /** * @brief VItem constructor. * @param path detail path. * @param numInList index in list of details. * @param parent parent object. */ - VItem ( const QPainterPath & path, int numInList, QGraphicsItem * parent = 0 ); + VItem ( const QPainterPath & path, int numInList, QGraphicsItem * parent = nullptr ); /** * @brief Rotate rotate detail on angle in degree. * @param angle angle in degree. @@ -81,7 +80,7 @@ public slots: * @brief SetIndexInList set detail index in list. * @param index index in list. */ - inline void SetIndexInList( qint32 index ) {numInOutList = index;} + void SetIndexInList( qint32 index ); protected: /** * @brief itemChange handle item change. @@ -118,4 +117,9 @@ signals: */ void itemColliding ( QList list, int number ); }; + +inline void VItem::SetIndexInList(qint32 index) +{ + numInOutList = index; +} #endif // VITEM_H diff --git a/src/widgets/vmaingraphicsscene.cpp b/src/widgets/vmaingraphicsscene.cpp index e2bd07775..047f86e16 100644 --- a/src/widgets/vmaingraphicsscene.cpp +++ b/src/widgets/vmaingraphicsscene.cpp @@ -62,7 +62,7 @@ void VMainGraphicsScene::setTransform(const QTransform &transform) _transform = transform; } -void VMainGraphicsScene::ChoosedItem(qint64 id, const Scene::Scenes &type) +void VMainGraphicsScene::ChoosedItem(quint32 id, const Valentina::Scenes &type) { emit ChoosedObject(id, type); } diff --git a/src/widgets/vmaingraphicsscene.h b/src/widgets/vmaingraphicsscene.h index d8f1cd9c2..87620d695 100644 --- a/src/widgets/vmaingraphicsscene.h +++ b/src/widgets/vmaingraphicsscene.h @@ -48,27 +48,27 @@ public: * @param sceneRect scene rect. * @param parent parent object. */ - VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0); + VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = nullptr); /** * @brief getHorScrollBar return scene horizontal scrollbar. * @return horizontal scrollbar. */ - inline qint32 getHorScrollBar() const {return horScrollBar;} + qint32 getHorScrollBar() const; /** * @brief setHorScrollBar set scene horizontal scrollbar. * @param value horizontal scrollbar. */ - inline void setHorScrollBar(const qint32 &value) {horScrollBar = value;} + void setHorScrollBar(const qint32 &value); /** * @brief getVerScrollBar return scene vertical scrollbar. * @return vertical scrollbar. */ - inline qint32 getVerScrollBar() const {return verScrollBar;} + qint32 getVerScrollBar() const; /** * @brief setVerScrollBar set scene vertical scrollbar. * @param value vertical scrollbar. */ - inline void setVerScrollBar(const qint32 &value) {verScrollBar = value;} + void setVerScrollBar(const qint32 &value); /** * @brief transform return view transformation. * @return view transformation. @@ -85,7 +85,7 @@ public slots: * @param id object id. * @param type object scene type. */ - void ChoosedItem(qint64 id, const Scene::Scenes &type); + void ChoosedItem(quint32 id, const Valentina::Scenes &type); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. scene scale factor. @@ -118,7 +118,7 @@ signals: * @param id object id. * @param type object scene type. */ - void ChoosedObject(qint64 id, Scene::Scenes type); + void ChoosedObject(quint32 id, Valentina::Scenes type); /** * @brief NewFactor send new scale factor. * @param factor scene scale factor. @@ -143,4 +143,24 @@ private: QTransform _transform; }; +inline qint32 VMainGraphicsScene::getHorScrollBar() const +{ + return horScrollBar; +} + +inline void VMainGraphicsScene::setHorScrollBar(const qint32 &value) +{ + horScrollBar = value; +} + +inline qint32 VMainGraphicsScene::getVerScrollBar() const +{ + return verScrollBar; +} + +inline void VMainGraphicsScene::setVerScrollBar(const qint32 &value) +{ + verScrollBar = value; +} + #endif // VMAINGRAPHICSSCENE_H diff --git a/src/widgets/vmaingraphicsview.cpp b/src/widgets/vmaingraphicsview.cpp index ada2d8c81..2b972be03 100644 --- a/src/widgets/vmaingraphicsview.cpp +++ b/src/widgets/vmaingraphicsview.cpp @@ -54,7 +54,6 @@ void VMainGraphicsView::wheelEvent(QWheelEvent *event) } QTimeLine *anim = new QTimeLine(300, this); - Q_CHECK_PTR(anim); anim->setUpdateInterval(20); if (QApplication::keyboardModifiers() == Qt::ControlModifier) diff --git a/src/widgets/vmaingraphicsview.h b/src/widgets/vmaingraphicsview.h index 175f35025..55cdfd648 100644 --- a/src/widgets/vmaingraphicsview.h +++ b/src/widgets/vmaingraphicsview.h @@ -42,7 +42,7 @@ public: * @brief VMainGraphicsView constructor. * @param parent parent object. */ - explicit VMainGraphicsView(QWidget *parent = 0); + explicit VMainGraphicsView(QWidget *parent = nullptr); signals: /** * @brief NewFactor send new scale factor. diff --git a/src/widgets/vsimplearc.cpp b/src/widgets/vsimplearc.cpp index b5ed1cb4b..a734fea9a 100644 --- a/src/widgets/vsimplearc.cpp +++ b/src/widgets/vsimplearc.cpp @@ -27,17 +27,18 @@ *************************************************************************/ #include "vsimplearc.h" +#include "../widgets/vapplication.h" -VSimpleArc::VSimpleArc(qint64 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent) +VSimpleArc::VSimpleArc(quint32 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent) :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor) { - if (factor == 0) + if (factor == nullptr) { - setPen(QPen(Qt::black, toPixel(widthHairLine))); + setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); } else { - setPen(QPen(Qt::black, toPixel(widthHairLine)/ *factor)); + setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/ *factor)); } setFlag(QGraphicsItem::ItemIsSelectable, true); setAcceptHoverEvents(true); @@ -55,25 +56,25 @@ void VSimpleArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VSimpleArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - if (factor == 0) + if (factor == nullptr) { - this->setPen(QPen(*currentColor, toPixel(widthMainLine))); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine()))); } else { - this->setPen(QPen(*currentColor, toPixel(widthMainLine)/ *factor)); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor)); } } void VSimpleArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - if (factor == 0) + if (factor == nullptr) { - this->setPen(QPen(*currentColor, toPixel(widthHairLine))); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine()))); } else { - this->setPen(QPen(*currentColor, toPixel(widthHairLine)/ *factor)); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); } } diff --git a/src/widgets/vsimplearc.h b/src/widgets/vsimplearc.h index 408d12f6e..914e93daf 100644 --- a/src/widgets/vsimplearc.h +++ b/src/widgets/vsimplearc.h @@ -55,13 +55,13 @@ public: * @param factor scale factor. * @param parent parent object. */ - VSimpleArc(qint64 id, Qt::GlobalColor *currentColor, qreal *factor = 0, QObject *parent = 0); + VSimpleArc(quint32 id, Qt::GlobalColor *currentColor, qreal *factor = nullptr, QObject *parent = nullptr); signals: /** * @brief Choosed send id when clicked. * @param id arc id. */ - void Choosed(qint64 id); + void Choosed(quint32 id); protected: /** * @brief mouseReleaseEvent handle mouse release events. @@ -83,7 +83,7 @@ private: /** * @brief id arc id. */ - qint64 id; + quint32 id; /** * @brief factor scale factor. */ diff --git a/src/widgets/vsimplespline.cpp b/src/widgets/vsimplespline.cpp index a86d37364..fb0d54e10 100644 --- a/src/widgets/vsimplespline.cpp +++ b/src/widgets/vsimplespline.cpp @@ -27,23 +27,30 @@ *************************************************************************/ #include "vsimplespline.h" -#include "../options.h" +#include "../widgets/vapplication.h" -VSimpleSpline::VSimpleSpline(qint64 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent) +VSimpleSpline::VSimpleSpline(quint32 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent) :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor) { - if (factor == 0) + if (factor == nullptr) { - setPen(QPen(Qt::black, toPixel(widthHairLine))); + setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); } else { - setPen(QPen(Qt::black, toPixel(widthHairLine)/ *factor)); + setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/ *factor)); } setFlag(QGraphicsItem::ItemIsSelectable, true); setAcceptHoverEvents(true); } +void VSimpleSpline::ChangedActivDraw(const bool &flag) +{ + setFlag(QGraphicsItem::ItemIsSelectable, flag); + setAcceptHoverEvents(flag); + setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); +} + void VSimpleSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) @@ -56,25 +63,25 @@ void VSimpleSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VSimpleSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - if (factor == 0) + if (factor == nullptr) { - this->setPen(QPen(*currentColor, toPixel(widthMainLine))); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine()))); } else { - this->setPen(QPen(*currentColor, toPixel(widthMainLine)/ *factor)); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor)); } } void VSimpleSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - if (factor == 0) + if (factor == nullptr) { - this->setPen(QPen(*currentColor, toPixel(widthHairLine))); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine()))); } else { - this->setPen(QPen(*currentColor, toPixel(widthHairLine)/ *factor)); + this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); } } diff --git a/src/widgets/vsimplespline.h b/src/widgets/vsimplespline.h index d6c8ae2cc..05f2bc816 100644 --- a/src/widgets/vsimplespline.h +++ b/src/widgets/vsimplespline.h @@ -55,13 +55,14 @@ public: * @param currentColor current color. * @param parent parent object. */ - VSimpleSpline(qint64 id, Qt::GlobalColor *currentColor, qreal *factor = 0, QObject *parent = 0); + VSimpleSpline(quint32 id, Qt::GlobalColor *currentColor, qreal *factor = nullptr, QObject *parent = 0); + void ChangedActivDraw(const bool &flag); signals: /** * @brief Choosed send id when clicked. * @param id spline id. */ - void Choosed(qint64 id); + void Choosed(quint32 id); protected: /** * @brief mouseReleaseEvent handle mouse release events. @@ -83,7 +84,7 @@ private: /** * @brief id spline id. */ - qint64 id; + quint32 id; /** * @brief factor scale factor. */ diff --git a/src/widgets/vsimplesplinepath.cpp b/src/widgets/vsimplesplinepath.cpp index b7dae6417..c247823a9 100644 --- a/src/widgets/vsimplesplinepath.cpp +++ b/src/widgets/vsimplesplinepath.cpp @@ -27,8 +27,9 @@ *************************************************************************/ #include "vsimplesplinepath.h" +#include "../widgets/vapplication.h" -VSimpleSplinePath::VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor) +VSimpleSplinePath::VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor) :VAbstractTool(doc, data, id), factor(factor) { } @@ -37,7 +38,7 @@ void VSimpleSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, Scene::SplinePath); + emit ChoosedTool(id, Valentina::SplinePath); } QGraphicsItem::mouseReleaseEvent(event); } @@ -45,11 +46,11 @@ void VSimpleSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VSimpleSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthMainLine)/ *factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor)); } void VSimpleSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, toPixel(widthHairLine)/ *factor)); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); } diff --git a/src/widgets/vsimplesplinepath.h b/src/widgets/vsimplesplinepath.h index 457f32bf5..6cb9df94b 100644 --- a/src/widgets/vsimplesplinepath.h +++ b/src/widgets/vsimplesplinepath.h @@ -47,7 +47,7 @@ public: * @param id spline path id. * @param factor scale factor. */ - VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor); + VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor); protected: /** * @brief mouseReleaseEvent handle mouse release events. diff --git a/src/widgets/vtablegraphicsview.h b/src/widgets/vtablegraphicsview.h index 6fbdafabe..abd79573a 100644 --- a/src/widgets/vtablegraphicsview.h +++ b/src/widgets/vtablegraphicsview.h @@ -42,7 +42,8 @@ public: * @brief The typeMove_e enum type items moves. */ enum typeMove_e { Left, Right, Up, Down }; - VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent = 0); + + VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent = nullptr); signals: /** * @brief itemChect emit after change selection state detail. @@ -57,7 +58,7 @@ public slots: /** * @brief rotateItems handle rotatation detail. */ - inline void rotateItems() {rotateIt();} + void rotateItems(); /** * @brief MirrorItem mirror detail. */ @@ -65,11 +66,11 @@ public slots: /** * @brief ZoomIn zoom in paper scale. */ - inline void ZoomIn() {scale(1.1, 1.1);} + void ZoomIn(); /** * @brief ZoomOut zoom out paper scale. */ - inline void ZoomOut() {scale(1/1.1, 1/1.1);} + void ZoomOut(); protected: /** * @brief wheelEvent handle wheel events. @@ -103,4 +104,19 @@ protected: }; +inline void VTableGraphicsView::rotateItems() +{ + rotateIt(); +} + +inline void VTableGraphicsView::ZoomIn() +{ + scale(1.1, 1.1); +} + +inline void VTableGraphicsView::ZoomOut() +{ + scale(1/1.1, 1/1.1); +} + #endif // VTABLEGRAPHICSVIEW_H diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 2af908437..402e4f2cb 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -27,35 +27,67 @@ *************************************************************************/ #include "vdomdocument.h" -#include "../exception/vexceptionwrongparameterid.h" #include "../exception/vexceptionconversionerror.h" #include "../exception/vexceptionemptyparameter.h" -#include "../exception/vexceptionuniqueid.h" -#include "../exception/vexceptionobjecterror.h" #include "../exception/vexceptionbadid.h" -#include "../tools/vtooldetail.h" -#include "../tools/vtooluniondetails.h" -#include "../tools/drawTools/drawtools.h" -#include "../tools/nodeDetails/nodedetails.h" -#include +#include +#include +#include +#include -VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent) - : QObject(parent), QDomDocument(), map(QHash()), nameActivDraw(QString()), data(data), - tools(QHash()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false){} +//This class need for validation pattern file using XSD shema +class MessageHandler : public QAbstractMessageHandler +{ +public: + MessageHandler() : QAbstractMessageHandler(), m_messageType(QtMsgType()), m_description(QString()), + m_sourceLocation(QSourceLocation()){} + QString statusMessage() const; + qint64 line() const; + qint64 column() const; +protected: + virtual void handleMessage(QtMsgType type, const QString &description, + const QUrl &identifier, const QSourceLocation &sourceLocation) + { + Q_UNUSED(type); + Q_UNUSED(identifier); -VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, - QObject *parent) - :QObject(parent), QDomDocument(name), map(QHash()), nameActivDraw(QString()), data(data), - tools(QHash()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false){} + m_messageType = type; + m_description = description; + m_sourceLocation = sourceLocation; + } +private: + QtMsgType m_messageType; + QString m_description; + QSourceLocation m_sourceLocation; +}; -VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode, QObject *parent) - :QObject(parent), QDomDocument(doctype), map(QHash()), nameActivDraw(QString()), data(data), - tools(QHash()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false){} +inline QString MessageHandler::statusMessage() const +{ + return m_description; +} + +inline qint64 MessageHandler::line() const +{ + return m_sourceLocation.line(); +} + +inline qint64 MessageHandler::column() const +{ + return m_sourceLocation.column(); +} + +const QString VDomDocument::AttrId = QStringLiteral("id"); +const QString VDomDocument::AttrUnit = QStringLiteral("unit"); +const QString VDomDocument::UnitMM = QStringLiteral("mm"); +const QString VDomDocument::UnitCM = QStringLiteral("cm"); +const QString VDomDocument::UnitINCH = QStringLiteral("inch"); + +VDomDocument::VDomDocument(VContainer *data) + : QDomDocument(), data(data), map(QHash()) +{ + +} QDomElement VDomDocument::elementById(const QString& id) { @@ -69,8 +101,7 @@ QDomElement VDomDocument::elementById(const QString& id) map.remove(id); } - bool res = this->find(this->documentElement(), id); - if (res) + if (this->find(this->documentElement(), id)) { return map[id]; } @@ -97,9 +128,9 @@ void VDomDocument::removeAllChilds(QDomElement &element) bool VDomDocument::find(const QDomElement &node, const QString& id) { - if (node.hasAttribute("id")) + if (node.hasAttribute(AttrId)) { - QString value = node.attribute("id"); + const QString value = node.attribute(AttrId); this->map[value] = node; if (value == id) { @@ -112,55 +143,7 @@ bool VDomDocument::find(const QDomElement &node, const QString& id) QDomNode n = node.childNodes().at(i); if (n.isElement()) { - bool res = this->find(n.toElement(), id); - if (res) - { - return true; - } - } - } - - return false; -} - -void VDomDocument::CreateEmptyFile() -{ - QDomElement patternElement = this->createElement("pattern"); - this->appendChild(patternElement); - - QDomComment info = this->createComment("Valentina pattern format."); - patternElement.appendChild(info); - QDomNode xmlNode = this->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); - this->insertBefore(xmlNode, this->firstChild()); - - QDomElement authorElement = this->createElement("author"); - patternElement.appendChild(authorElement); - - QDomElement descElement = this->createElement("description"); - patternElement.appendChild(descElement); - - QDomElement notesElement = this->createElement("notes"); - patternElement.appendChild(notesElement); - - QDomElement incrElement = this->createElement("increments"); - patternElement.appendChild(incrElement); -} - -bool VDomDocument::CheckNameDraw(const QString& name) const -{ - Q_ASSERT_X(name.isEmpty() == false, "CheckNameDraw", "name draw is empty"); - QDomNodeList elements = this->documentElement().elementsByTagName( "draw" ); - if (elements.size() == 0) - { - return false; - } - for ( qint32 i = 0; i < elements.count(); i++ ) - { - QDomElement elem = elements.at( i ).toElement(); - if (elem.isNull() == false) - { - QString fieldName = elem.attribute( "name" ); - if ( fieldName == name ) + if (this->find(n.toElement(), id)) { return true; } @@ -169,305 +152,32 @@ bool VDomDocument::CheckNameDraw(const QString& name) const return false; } -bool VDomDocument::appendDraw(const QString& name) -{ - Q_ASSERT_X(name.isEmpty() == false, "appendDraw", "name draw is empty"); - if (name.isEmpty()) - { - return false; - } - if (CheckNameDraw(name)== false) - { - QDomElement rootElement = this->documentElement(); - - QDomElement drawElement = this->createElement("draw"); - QDomAttr drawAttr = this->createAttribute("name"); - drawAttr.setValue(name); - drawElement.setAttributeNode(drawAttr); - - QDomElement calculationElement = this->createElement("calculation"); - QDomElement modelingElement = this->createElement("modeling"); - QDomElement pathsElement = this->createElement("details"); - drawElement.appendChild(calculationElement); - drawElement.appendChild(modelingElement); - drawElement.appendChild(pathsElement); - - rootElement.appendChild(drawElement); - - if (nameActivDraw.isEmpty()) - { - SetActivDraw(name); - } - else - { - ChangeActivDraw(name); - } - return true; - } - else - { - return false; - } - return false; -} - -void VDomDocument::ChangeActivDraw(const QString& name, const Document::Documents &parse) -{ - Q_ASSERT_X(name.isEmpty() == false, "ChangeActivDraw", "name draw is empty"); - if (CheckNameDraw(name) == true) - { - this->nameActivDraw = name; - if (parse == Document::FullParse) - { - emit ChangedActivDraw(name); - } - } -} - -bool VDomDocument::SetNameDraw(const QString& name) -{ - Q_ASSERT_X(name.isEmpty() == false, "SetNameDraw", "name draw is empty"); - QString oldName = nameActivDraw; - QDomElement element; - if (GetActivDrawElement(element)) - { - nameActivDraw = name; - element.setAttribute("name", nameActivDraw); - emit patternChanged(); - emit ChangedNameDraw(oldName, nameActivDraw); - return true; - } - else - { - qWarning()<<"Can't find activ draw"<nameActivDraw = name; -} - -bool VDomDocument::GetActivDrawElement(QDomElement &element) -{ - if (nameActivDraw.isEmpty() == false) - { - QDomNodeList elements = this->documentElement().elementsByTagName( "draw" ); - if (elements.size() == 0) - { - return false; - } - for ( qint32 i = 0; i < elements.count(); i++ ) - { - element = elements.at( i ).toElement(); - if (element.isNull() == false) - { - QString fieldName = element.attribute( "name" ); - if ( fieldName == nameActivDraw ) - { - return true; - } - } - } - } - return false; -} - -bool VDomDocument::GetActivCalculationElement(QDomElement &element) -{ - bool ok = GetActivNodeElement("calculation", element); - if (ok) - { - return true; - } - else - { - return false; - } -} - -bool VDomDocument::GetActivModelingElement(QDomElement &element) -{ - bool ok = GetActivNodeElement("modeling", element); - if (ok) - { - return true; - } - else - { - return false; - } -} - -bool VDomDocument::GetActivDetailsElement(QDomElement &element) -{ - bool ok = GetActivNodeElement("details", element); - if (ok) - { - return true; - } - else - { - return false; - } -} - -bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element) -{ - Q_ASSERT_X(name.isEmpty() == false, "GetActivNodeElement", "name draw is empty"); - QDomElement drawElement; - bool drawOk = this->GetActivDrawElement(drawElement); - if (drawOk == true) - { - QDomNodeList listElement = drawElement.elementsByTagName(name); - if (listElement.size() == 0 || listElement.size() > 1) - { - return false; - } - element = listElement.at( 0 ).toElement(); - if (element.isNull() == false) - { - return true; - } - else - { - return false; - } - } - else - { - return false; - } -} - -void VDomDocument::Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, - VMainGraphicsScene *sceneDetail) -{ - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); - if (parse == Document::FullParse) - { - TestUniqueId(); - data->Clear(); - data->CreateManTableIGroup(); - nameActivDraw.clear(); - sceneDraw->clear(); - sceneDetail->clear(); - comboBoxDraws->clear(); - tools.clear(); - cursor = 0; - } - data->ClearLengthLines(); - data->ClearLengthArcs(); - data->ClearLengthSplines(); - data->ClearLineAngles(); - data->ClearDetails(); - history.clear(); - QDomElement rootElement = this->documentElement(); - QDomNode domNode = rootElement.firstChild(); - while (domNode.isNull() == false) - { - if (domNode.isElement()) - { - QDomElement domElement = domNode.toElement(); - if (domElement.isNull() == false) - { - if (domElement.tagName()=="draw") - { - if (parse == Document::FullParse) - { - if (nameActivDraw.isEmpty()) - { - SetActivDraw(domElement.attribute("name")); - } - else - { - ChangeActivDraw(domElement.attribute("name")); - } - comboBoxDraws->addItem(domElement.attribute("name")); - } - else - { - ChangeActivDraw(domElement.attribute("name"), Document::LiteParse); - } - ParseDrawElement(sceneDraw, sceneDetail, domElement, parse); - } - if (domElement.tagName()=="increments") - { - ParseIncrementsElement(domElement); - } - } - } - domNode = domNode.nextSibling(); - } -} - -VDataTool *VDomDocument::getTool(const qint64 &id) -{ - if (tools.contains(id)) - { - return tools.value(id); - } - else - { - QString error = QString(tr("Can't find tool id = %1 in table.")).arg(id); - throw VException(error); - } - return 0; -} - -void VDomDocument::ParseIncrementsElement(const QDomNode &node) -{ - QDomNode domNode = node.firstChild(); - while (domNode.isNull() == false) - { - if (domNode.isElement()) - { - QDomElement domElement = domNode.toElement(); - if (domElement.isNull() == false) - { - if (domElement.tagName() == "increment") - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name", ""); - qreal base = GetParametrDouble(domElement, "base", "0"); - qreal ksize = GetParametrDouble(domElement, "ksize", "0"); - qreal kgrowth = GetParametrDouble(domElement, "kgrowth", "0"); - QString desc = GetParametrString(domElement, "description", "Description"); - data->UpdateId(id); - data->AddIncrementTableRow(name, VIncrementTableRow(id, base, ksize, kgrowth, desc)); - } - } - } - domNode = domNode.nextSibling(); - } -} - -qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const -{ - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - qint64 id = GetParametrLongLong(domElement, "id", "0"); - if (id <= 0) - { - throw VExceptionWrongParameterId(tr("Got wrong parameter id. Need only id > 0."), domElement); - } - return id; -} - -qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QString &name, - const QString &defValue) const +quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue) const { Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + bool ok = false; - QString parametr = GetParametrString(domElement, name, defValue); - qint64 id = parametr.toLongLong(&ok); - if (ok == false) + QString parametr; + quint32 id = 0; + + QString message = tr("Can't convert toUInt parameter"); + try { - throw VExceptionConversionError(tr("Can't convert toLongLong parameter"), name); + parametr = GetParametrString(domElement, name, defValue); + id = parametr.toUInt(&ok); + if (ok == false) + { + throw VExceptionConversionError(message, name); + } } + catch (const VExceptionEmptyParameter &e) + { + VExceptionConversionError excep(message, name); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + return id; } @@ -476,10 +186,17 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt { Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - QString parameter = domElement.attribute(name, defValue); + const QString parameter = domElement.attribute(name, defValue); if (parameter.isEmpty()) { - throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement); + if (defValue.isEmpty()) + { + throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement); + } + else + { + return defValue; + } } return parameter; } @@ -488,905 +205,42 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri { Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + bool ok = false; - QString parametr = GetParametrString(domElement, name, defValue); - qreal param = parametr.replace(",", ".").toDouble(&ok); - if (ok == false) + qreal param = 0; + + QString message = tr("Can't convert toDouble parameter"); + try { - qDebug()<<"defValue"< vector; - CollectId(this->documentElement(), vector); -} - -void VDomDocument::CollectId(const QDomElement &node, QVector &vector) const -{ - if (node.hasAttribute("id")) - { - qint64 id = GetParametrId(node); - if (vector.contains(id)) - { - throw VExceptionUniqueId(tr("This id is not unique."), node); - } - vector.append(id); - } - - for (qint32 i=0; iClearCalculationGObjects(); - ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Calculation); - } - if (domElement.tagName() == "modeling") - { - ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Modeling); - } - if (domElement.tagName() == "details") - { - ParseDetails(sceneDetail, domElement, parse); - } - } - } - domNode = domNode.nextSibling(); - } -} - -void VDomDocument::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, - const QDomNode& node, const Document::Documents &parse, const Draw::Draws &mode) -{ - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); - VMainGraphicsScene *scene = 0; - if (mode == Draw::Calculation) - { - scene = sceneDraw; - } - else - { - scene = sceneDetail; - } - QDomNodeList nodeList = node.childNodes(); - qint32 num = nodeList.size(); - for (qint32 i = 0; i < num; ++i) - { - QDomElement domElement = nodeList.at(i).toElement(); - if (domElement.isNull() == false) - { - if (domElement.tagName() == "point") - { - ParsePointElement(scene, domElement, parse, domElement.attribute("type", "")); - continue; - } - if (domElement.tagName() == "line") - { - ParseLineElement(scene, domElement, parse); - continue; - } - if (domElement.tagName() == "spline") - { - ParseSplineElement(scene, domElement, parse, domElement.attribute("type", "")); - continue; - } - if (domElement.tagName() == "arc") - { - ParseArcElement(scene, domElement, parse, domElement.attribute("type", "")); - continue; - } - if (domElement.tagName() == "tools") - { - ParseToolsElement(scene, domElement, parse, domElement.attribute("type", "")); - continue; - } - } - } -} - -void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse) -{ - Q_CHECK_PTR(sceneDetail); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - try - { - VDetail detail; - VDetail oldDetail; - qint64 id = GetParametrId(domElement); - detail.setName(GetParametrString(domElement, VAbstractTool::AttrName, "")); - detail.setMx(toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"))); - detail.setMy(toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "0.0"))); - detail.setSeamAllowance(GetParametrLongLong(domElement, VToolDetail::AttrSupplement, "1")); - detail.setWidth(GetParametrDouble(domElement, VToolDetail::AttrWidth, "10.0")); - detail.setClosed(GetParametrLongLong(domElement, VToolDetail::AttrClosed, "1")); - - QDomNodeList nodeList = domElement.childNodes(); - qint32 num = nodeList.size(); - for (qint32 i = 0; i < num; ++i) - { - QDomElement element = nodeList.at(i).toElement(); - if (element.isNull() == false) - { - if (element.tagName() == VToolDetail::TagNode) - { - qint64 id = GetParametrLongLong(element, VToolDetail::AttrIdObject, "0"); - qreal mx = toPixel(GetParametrDouble(element, VAbstractTool::AttrMx, "0.0")); - qreal my = toPixel(GetParametrDouble(element, VAbstractTool::AttrMy, "0.0")); - Tool::Tools tool; - NodeDetail::NodeDetails nodeType = NodeDetail::Contour; - QString t = GetParametrString(element, "type", "NodePoint"); - if (t == "NodePoint") - { - tool = Tool::NodePoint; -// const VPointF *point = data->GeometricObject(id); -// oldDetail.append(VNodeDetail(point.getIdObject(), tool, NodeDetail::Contour)); - } - else if (t == "NodeArc") - { - tool = Tool::NodeArc; -// VArc arc = data->GetArc(id); -// oldDetail.append(VNodeDetail(arc.getIdObject(), tool, NodeDetail::Contour)); - } - else if (t == "NodeSpline") - { - tool = Tool::NodeSpline; -// VSpline spl = data->GetSpline(id); -// oldDetail.append(VNodeDetail(spl.getIdObject(), tool, NodeDetail::Contour)); - } - else if (t == "NodeSplinePath") - { - tool = Tool::NodeSplinePath; -// VSplinePath splPath = data->GetSplinePath(id); -// oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, NodeDetail::Contour)); - } - detail.append(VNodeDetail(id, tool, nodeType, mx, my)); - } - } - } - VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating detail"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } -} - -void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse) -{ - Q_CHECK_PTR(sceneDetail); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - QDomNode domNode = domElement.firstChild(); - while (domNode.isNull() == false) - { - if (domNode.isElement()) - { - QDomElement domElement = domNode.toElement(); - if (domElement.isNull() == false) - { - if (domElement.tagName() == VToolDetail::TagName) - { - ParseDetailElement(sceneDetail, domElement, parse); - } - } - } - domNode = domNode.nextSibling(); - } -} - -void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type) -{ - Q_CHECK_PTR(scene); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty"); - - - QStringList points; - points << VToolSinglePoint::ToolType << VToolEndLine::ToolType << VToolAlongLine::ToolType - << VToolShoulderPoint::ToolType << VToolNormal::ToolType << VToolBisector::ToolType - << VToolLineIntersect::ToolType << VToolPointOfContact::ToolType << VNodePoint::ToolType - << VToolHeight::ToolType << VToolTriangle::ToolType << VToolPointOfIntersection::ToolType - << VToolCutSpline::ToolType << VToolCutSplinePath::ToolType << VToolCutArc::ToolType; - switch(points.indexOf(type)) { - case 0: //VToolSinglePoint::ToolType - { - VToolSinglePoint *spoint = 0; - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, "A"); - qreal x = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrX, "10.0")); - qreal y = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0")); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - - data->UpdateGObject(id, new VPointF(x, y, name, mx, my)); - VDrawTool::AddRecord(id, Tool::SinglePointTool, this); - if (parse != Document::FullParse) - { - UpdateToolData(id, data); - } - if (parse == Document::FullParse) - { - spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); - Q_CHECK_PTR(spoint); - scene->addItem(spoint); - connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); - tools[id] = spoint; - } - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating single point"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - scene->removeItem(spoint); - delete spoint; - throw excep; - } - break; - } - case 1: //VToolEndLine::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); - qint64 basePointId = GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0"); - qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); - - VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, - mx, my, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 2: //VToolAlongLine::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); - qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - - VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, scene, this, data, - parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 3: //VToolShoulderPoint::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); - qint64 p1Line = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line, "0"); - qint64 p2Line = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line, "0"); - qint64 pShoulder = GetParametrLongLong(domElement, VAbstractTool::AttrPShoulder, "0"); - - VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this, - data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 4: //VToolNormal::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); - qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); - - VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, - angle, mx, my, scene, this,data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 5: //VToolBisector::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); - qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - qint64 thirdPointId = GetParametrLongLong(domElement, VAbstractTool::AttrThirdPoint, "0"); - - VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, - typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 6: //VToolLineIntersect::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - qint64 p1Line1Id = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line1, "0"); - qint64 p2Line1Id = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line1, "0"); - qint64 p1Line2Id = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line2, "0"); - qint64 p2Line2Id = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line2, "0"); - - VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, - mx, my, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of lineintersection"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 7: //VToolPointOfContact::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "0"); - qint64 center = GetParametrLongLong(domElement, VAbstractTool::AttrCenter, "0"); - qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - - VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, - mx, my, scene, this,data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 8: //VNodePoint::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); - const VPointF *point = data->GeometricObject(idObject ); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - data->UpdateGObject(id, new VPointF(point->x(), point->y(), point->name(), - mx, my, idObject,Draw::Modeling)); - VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating modeling point"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 9: //VToolHeight::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - qint64 basePointId = GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0"); - qint64 p1LineId = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line, "0"); - qint64 p2LineId = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line, "0"); - - VToolHeight::Create(id, name, typeLine, basePointId, p1LineId, p2LineId, - mx, my, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating height"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 10: //VToolTriangle::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - qint64 axisP1Id = GetParametrLongLong(domElement, VAbstractTool::AttrAxisP1, "0"); - qint64 axisP2Id = GetParametrLongLong(domElement, VAbstractTool::AttrAxisP2, "0"); - qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - - VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, scene, this, data, - parse, Tool::FromFile); - return; - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating triangle"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 11: //VToolPointOfIntersection::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - - VToolPointOfIntersection::Create(id, name, firstPointId, secondPointId, - mx, my, scene, this, data, parse,Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating point of intersection"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 12: //VToolCutSpline::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); - qint64 splineId = GetParametrLongLong(domElement, VToolCutSpline::AttrSpline, "0"); - - VToolCutSpline::Create(id, name, formula, splineId, mx, my, scene, this, data, parse, Tool::FromFile); - return; - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating cut spline point"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 13: //VToolCutSplinePath::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); - qint64 splinePathId = GetParametrLongLong(domElement, VToolCutSplinePath::AttrSplinePath, "0"); - - VToolCutSplinePath::Create(id, name, formula, splinePathId, mx, my, - scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating cut spline path point"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 14: //VToolCutArc::ToolType - try - { - qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); - qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); - qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); - qint64 arcId = GetParametrLongLong(domElement, VToolCutArc::AttrArc, "0"); - - VToolCutArc::Create(id, name, formula, arcId, mx, my, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating cut arc point"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - default: - qWarning() << "Illegal point type in VDomDocument::ParsePointElement()."; - break; - } -} - -void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse) -{ - Q_CHECK_PTR(scene); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - try - { - qint64 id = GetParametrId(domElement); - qint64 firstPoint = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); - qint64 secondPoint = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); - QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); - - VToolLine::Create(id, firstPoint, secondPoint, typeLine, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating line"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } -} - -void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, const QString &type) -{ - Q_CHECK_PTR(scene); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - - QStringList splines; - splines << VToolSpline::ToolType << VToolSplinePath::ToolType << VNodeSpline::ToolType << VNodeSplinePath::ToolType; - switch(splines.indexOf(type)) { - case 0: //VToolSpline::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 point1 = GetParametrLongLong(domElement, VAbstractTool::AttrPoint1, "0"); - qint64 point4 = GetParametrLongLong(domElement, VAbstractTool::AttrPoint4, "0"); - qreal angle1 = GetParametrDouble(domElement, VAbstractTool::AttrAngle1, "270.0"); - qreal angle2 = GetParametrDouble(domElement, VAbstractTool::AttrAngle2, "90.0"); - qreal kAsm1 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm1, "1.0"); - qreal kAsm2 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm2, "1.0"); - qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); - - VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse,Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating simple curve"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 1: //VToolSplinePath::ToolType - try - { - qint64 id = GetParametrId(domElement); - qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); - VSplinePath *path = new VSplinePath(kCurve); - Q_CHECK_PTR(path); - - QDomNodeList nodeList = domElement.childNodes(); - qint32 num = nodeList.size(); - for (qint32 i = 0; i < num; ++i) - { - QDomElement element = nodeList.at(i).toElement(); - if (element.isNull() == false) - { - if (element.tagName() == VAbstractTool::AttrPathPoint) - { - qreal kAsm1 = GetParametrDouble(element, VAbstractTool::AttrKAsm1, "1.0"); - qreal angle = GetParametrDouble(element, VAbstractTool::AttrAngle, "0"); - qreal kAsm2 = GetParametrDouble(element, VAbstractTool::AttrKAsm2, "1.0"); - qint64 pSpline = GetParametrLongLong(element, VAbstractTool::AttrPSpline, "0"); - VPointF p = *data->GeometricObject(pSpline); - - QLineF line(0, 0, 100, 0); - line.setAngle(angle+180); - - VSplinePoint splPoint(p, kAsm1, line.angle(), kAsm2, angle); - path->append(splPoint); - if (parse == Document::FullParse) - { - IncrementReferens(pSpline); - } - } - } - } - - VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating curve path"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 2: //VNodeSpline::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); - VSpline *spl = new VSpline(*data->GeometricObject(idObject)); - Q_CHECK_PTR(spl); - spl->setIdObject(idObject); - spl->setMode(Draw::Modeling); - data->UpdateGObject(id, spl); - VNodeSpline::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating modeling simple curve"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 3: //VNodeSplinePath::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); - VSplinePath *path = new VSplinePath(*data->GeometricObject(idObject)); - Q_CHECK_PTR(path); - path->setIdObject(idObject); - path->setMode(Draw::Modeling); - data->UpdateGObject(id, path); - VNodeSplinePath::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating modeling curve path"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - default: - qWarning() << "Illegal spline type in VDomDocument::ParseSplineElement()."; - break; - } -} - -void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, const QString &type) -{ - Q_CHECK_PTR(scene); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - - QStringList arcs; - arcs << VToolArc::ToolType << VNodeArc::ToolType; - - switch(arcs.indexOf(type)) { - case 0: //VToolArc::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 center = GetParametrLongLong(domElement, VAbstractTool::AttrCenter, "0"); - QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "10"); - QString f1 = GetParametrString(domElement, VAbstractTool::AttrAngle1, "180"); - QString f2 = GetParametrString(domElement, VAbstractTool::AttrAngle2, "270"); - - VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - case 1: //VNodeArc::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); - VArc *arc = new VArc(*data->GeometricObject(idObject)); - Q_CHECK_PTR(arc); - arc->setIdObject(idObject); - arc->setMode(Draw::Modeling); - data->UpdateGObject(id, arc); - VNodeArc::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating modeling arc"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - default: - qWarning() << "Illegal arc type in VDomDocument::ParseArcElement()."; - break; - } -} - -void VDomDocument::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, const QString &type) -{ - Q_CHECK_PTR(scene); - Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - - QStringList tools; - tools << VToolUnionDetails::ToolType; - - switch(tools.indexOf(type)) { - case 0: //VToolUnionDetails::ToolType - try - { - qint64 id = GetParametrId(domElement); - qint64 indexD1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrIndexD1, "-1"); - qint64 indexD2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrIndexD2, "-1"); - - QVector vector = VToolUnionDetails::GetDetailFromFile(this, domElement); - - VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, indexD1, indexD2, scene, this, data, parse, - Tool::FromFile); - } - catch (const VExceptionBadId &e) - { - VExceptionObjectError excep(tr("Error creating or updating union details"), domElement); - excep.AddMoreInformation(e.ErrorMessage()); - throw excep; - } - break; - default: - qWarning() << "Illegal tools type in VDomDocument::ParseToolsElement()."; - break; - } -} - -void VDomDocument::FullUpdateTree() -{ - VMainGraphicsScene *scene = new VMainGraphicsScene(); - Q_CHECK_PTR(scene); - try - { - Parse(Document::LiteParse, scene, scene); - } - catch (const std::bad_alloc &) - { - delete scene; - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error parsing file.")); - msgBox.setInformativeText("std::bad_alloc"); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Warning); - msgBox.exec(); - return; - } - catch (...) - { - delete scene; - throw; - } - - delete scene; - setCurrentData(); - emit FullUpdateFromFile(); -} - -void VDomDocument::haveLiteChange() -{ - patternModified = true; - emit patternChanged(); -} - -void VDomDocument::ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable) -{ - emit ShowTool(id, color, enable); -} -bool VDomDocument::isPatternModified() const -{ - return patternModified; -} - -void VDomDocument::setPatternModified(bool value) -{ - patternModified = value; -} - -QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVal) -{ - QDomNodeList nodeList = this->elementsByTagName(tagName); + const QDomNodeList nodeList = this->elementsByTagName(tagName); if (nodeList.isEmpty()) { return defVal; } else { - QDomNode domNode = nodeList.at(0); + const QDomNode domNode = nodeList.at(0); if (domNode.isNull() == false && domNode.isElement()) { - QDomElement domElement = domNode.toElement(); + const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { return domElement.text(); @@ -1396,82 +250,193 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa return defVal; } - -void VDomDocument::setCursor(const qint64 &value) +void VDomDocument::ValidateXML(const QString &schema, const QString &fileName) { - cursor = value; - emit ChangedCursor(cursor); + QFile pattern(fileName); + if (pattern.open(QIODevice::ReadOnly) == false) + { + const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString())); + throw VException(errorMsg); + } + + QFile fileSchema(schema); + if (fileSchema.open(QIODevice::ReadOnly) == false) + { + pattern.close(); + const QString errorMsg(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); + throw VException(errorMsg); + } + + MessageHandler messageHandler; + QXmlSchema sch; + sch.setMessageHandler(&messageHandler); + sch.load(&fileSchema, QUrl::fromLocalFile(fileSchema.fileName())); + + bool errorOccurred = false; + if (sch.isValid() == false) + { + errorOccurred = true; + } + else + { + QXmlSchemaValidator validator(sch); + if (validator.validate(&pattern, QUrl::fromLocalFile(pattern.fileName())) == false) + { + errorOccurred = true; + } + } + + if (errorOccurred) + { + pattern.close(); + fileSchema.close(); + VException e(messageHandler.statusMessage()); + e.AddMoreInformation(tr("Validation error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column())); + throw e; + } + pattern.close(); + fileSchema.close(); } -void VDomDocument::setCurrentData() +void VDomDocument::setContent(const QString &fileName) { - if (*mode == Draw::Calculation) + QFile file(fileName); + if (file.open(QIODevice::ReadOnly) == false) { - QString nameDraw = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); - if (nameActivDraw != nameDraw) + const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(file.errorString())); + throw VException(errorMsg); + } + + QString errorMsg; + int errorLine = -1; + int errorColumn = -1; + if (QDomDocument::setContent(&file, &errorMsg, &errorLine, &errorColumn) == false) + { + file.close(); + VException e(errorMsg); + e.AddMoreInformation(tr("Parcing error in line %1 column %2").arg(errorLine).arg(errorColumn)); + throw e; + } +} + +Valentina::Units VDomDocument::StrToUnits(const QString &unit) +{ + QStringList units; + units << UnitMM << UnitCM << UnitINCH; + Valentina::Units result = Valentina::Cm; + switch (units.indexOf(unit)) + { + case 0:// mm + result = Valentina::Mm; + break; + case 1:// cm + result = Valentina::Cm; + break; + case 2:// inch + result = Valentina::Inch; + break; + default: + result = Valentina::Cm; + break; + } + return result; +} + +QString VDomDocument::UnitsToStr(const Valentina::Units &unit) +{ + QString result; + switch(unit) + { + case Valentina::Mm: + result = "mm"; + break; + case Valentina::Cm: + result = "cm"; + break; + case Valentina::Inch: + result = "inch"; + break; + default: + result = "cm"; + break; + } + return result; +} + +bool VDomDocument::SaveDocument(const QString &fileName) +{ + if (fileName.isEmpty()) + { + qDebug()<<"Got empty file name."; + return false; + } + //Writing in temporary file + QFileInfo tempInfo(fileName); + QString temp = tempInfo.absolutePath() + "/" + tempInfo.baseName() + ".tmp"; + QFile tempFile(temp); + if (tempFile.open(QIODevice::WriteOnly| QIODevice::Truncate)) + { + const int indent = 4; + QTextStream out(&tempFile); + out.setCodec("UTF-8"); + save(out, indent); + tempFile.close(); + } + //Replace temp file our + bool result = false; + QFile patternFile(fileName); + // We need here temporary file because we need restore document after error of copying temp file. + QTemporaryFile tempOfPattern; + if (tempOfPattern.open()) + { + patternFile.copy(tempOfPattern.fileName()); + } + if ( patternFile.exists() == false || patternFile.remove() ) + { + if ( tempFile.copy(patternFile.fileName()) == false ) { - nameActivDraw = nameDraw; - qint64 id = 0; - if (history.size() == 0) + qDebug()<<"Could not copy temp file to document file"<elementsByTagName(tag); + if (nodeList.isEmpty()) + { + qDebug()<<"Can't save tag "< 0) - { - VDataTool *vTool = tools.value(id); - data->setData(vTool->getData()); - } } } } - -void VDomDocument::AddTool(const qint64 &id, VDataTool *tool) -{ - Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(tool); - tools.insert(id, tool); -} - -void VDomDocument::UpdateToolData(const qint64 &id, VContainer *data) -{ - Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(data); - VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); - tool->VDataTool::setData(data); -} - -void VDomDocument::IncrementReferens(qint64 id) const -{ - Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); - tool->incrementReferens(); -} - -void VDomDocument::DecrementReferens(qint64 id) const -{ - Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - VDataTool *tool = tools.value(id); - if (tool != 0) - { - tool->decrementReferens(); - } -} diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index e808e614e..01d03d5da 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -30,23 +30,10 @@ #define VDOMDOCUMENT_H #include "../container/vcontainer.h" -#include "../widgets/vmaingraphicsscene.h" -#include "../tools/vdatatool.h" -#include "vtoolrecord.h" -#include #include #include - -namespace Document -{ - /** - * @brief The Document enum types parse. - */ - enum Document { LiteParse, FullParse}; - Q_DECLARE_FLAGS(Documents, Document) -} -Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents) +#include "../options.h" #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -54,38 +41,24 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents) #endif /** - * @brief The VDomDocument class working with pattern file. + * @brief The VDomDocument class extend QDomDocument class. */ -class VDomDocument : public QObject, public QDomDocument +class VDomDocument : public QDomDocument { - Q_OBJECT + Q_DECLARE_TR_FUNCTIONS(VDomDocument) public: - /** - * @brief VDomDocument constructor. - * @param data container with variables. - * @param comboBoxDraws combobox for pattern peaces names. - * @param mode draw mode. - */ - VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent = 0); - /** - * @brief VDomDocument constructor. - * @param name pattern peace name. - * @param data container with variables. - * @param comboBoxDraws combobox for pattern peaces names. - * @param mode draw mode. - */ - VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, - QObject *parent = 0); - /** - * @brief VDomDocument constructor. - * @param doc dom document container type. - * @param data container with variables. - * @param comboBoxDraws combobox for pattern peaces names. - * @param mode draw mode. - */ - VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode, QObject *parent = 0); - ~VDomDocument(){} + static const QString AttrId; + static const QString AttrUnit; + static const QString UnitMM; + static const QString UnitCM; + static const QString UnitINCH; + /** + * @brief VDomDocument constructor. + * @param data container with variables. + * @param parent parent object + */ + VDomDocument(VContainer *data); + virtual ~VDomDocument(){} /** * @brief elementById find element by id. * @param id value id attribute. @@ -97,136 +70,38 @@ public: * @param element tag. */ void removeAllChilds(QDomElement &element); + template /** - * @brief CreateEmptyFile create minimal empty file. + * @brief SetAttribute set attribute in pattern file. Replace "," by ".". + * @param domElement element in xml tree. + * @param name name of attribute. + * @param value value of attribute. */ - void CreateEmptyFile(); - /** - * @brief ChangeActivDraw set new pattern peace name. - * @param name new name. - * @param parse parser file mode. - */ - void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse); - /** - * @brief GetNameActivDraw return current pattern peace name. - * @return pattern peace name. - */ - inline QString GetNameActivDraw() const {return nameActivDraw;} - /** - * @brief GetActivDrawElement return draw tag for current pattern peace. - * @param element draw tag. - * @return true if found. - */ - bool GetActivDrawElement(QDomElement &element); - /** - * @brief GetActivCalculationElement return calculation tag for current pattern peace. - * @param element calculation tag. - * @return true if found. - */ - bool GetActivCalculationElement(QDomElement &element); - /** - * @brief GetActivModelingElement return modeling tag for current pattern peace. - * @param element modeling tag - * @return true if found. - */ - bool GetActivModelingElement(QDomElement &element); - /** - * @brief GetActivDetailsElement return details tag for current pattern peace. - * @param element details tag. - * @return true if found. - */ - bool GetActivDetailsElement(QDomElement &element); - /** - * @brief appendDraw add new pattern peace structure to the file. - * @param name pattern peace name. - * @return true if success. - */ - bool appendDraw(const QString& name); - /** - * @brief SetNameDraw change current pattern peace. - * @param name pattern peace name. - * @return true if success. - */ - bool SetNameDraw(const QString& name); - /** - * @brief Parse parse file. - * @param parse parser file mode. - * @param sceneDraw pointer to draw scene. - * @param sceneDetail pointer to details scene. - */ - void Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, - VMainGraphicsScene *sceneDetail); - /** - * @brief getTools return list of tools pointers. - * @return list. - */ - inline QHash* getTools() {return &tools;} - /** - * @brief getTool return tool from tool list. - * @param id tool id. - * @return tool. - */ - VDataTool* getTool(const qint64 &id); - /** - * @brief getHistory return list with list of history records. - * @return list of history records. - */ - inline QVector *getHistory() {return &history;} - /** - * @brief getCursor return cursor. - * @return cursor. - */ - inline qint64 getCursor() const {return cursor;} - /** - * @brief setCursor set cursor. - * @param value cursor. - */ - void setCursor(const qint64 &value); - /** - * @brief setCurrentData set current data set. - */ - void setCurrentData(); - /** - * @brief AddTool add tool to list tools. - * @param id tool id. - * @param tool tool. - */ - void AddTool(const qint64 &id, VDataTool *tool); - /** - * @brief UpdateToolData update tool in list tools. - * @param id tool id. - * @param data container with variables. - */ - void UpdateToolData(const qint64 &id, VContainer *data); - /** - * @brief IncrementReferens increment reference parent objects. - * @param id parent object id. - */ - void IncrementReferens(qint64 id) const; - /** - * @brief DecrementReferens decrement reference parent objects. - * @param id parent object id. - */ - void DecrementReferens(qint64 id) const; - /** - * @brief TestUniqueId test exist unique id in pattern file. Each id must be unique. - */ - void TestUniqueId() const; + void SetAttribute(QDomElement &domElement, const QString &name, const T &value) + { + QString val = QString().setNum(value); + val = val.replace(",", "."); + domElement.setAttribute(name, val); + } /** * @brief GetParametrLongLong return long long value of attribute. * @param domElement tag in xml tree. * @param name attribute name. * @return long long value. */ - qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name, + quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const; /** * @brief GetParametrString return string value of attribute. + * + * if attribute empty return default value. If default value empty too throw exception. * @param domElement tag in xml tree. * @param name attribute name. + * @throw VExceptionEmptyParameter when attribute is empty * @return attribute value. */ - QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue) const; + QString GetParametrString(const QDomElement& domElement, const QString &name, + const QString &defValue = QString()) const; /** * @brief GetParametrDouble return double value of attribute. * @param domElement tag in xml tree. @@ -234,100 +109,35 @@ public: * @return double value. */ qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; + QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; /** - * @brief SPointActiveDraw return id base point current pattern peace. - * @return id base point. + * @brief ValidateXML validate xml file by xsd schema. + * @param schema path to schema file. + * @param fileName name of xml file. + * @param errorMsg error message. + * @param errorLine number error line. + * @param errorColumn number error column. + * @return true if validation successful. */ - qint64 SPointActiveDraw(); - bool isPatternModified() const; - void setPatternModified(bool value); - QString UniqueTagText(const QString &tagName, const QString &defVal = QString()); -signals: + static void ValidateXML(const QString &schema, const QString &fileName); + void setContent(const QString &fileName); + static Valentina::Units StrToUnits(const QString &unit); + static QString UnitsToStr(const Valentina::Units &unit); + virtual bool SaveDocument(const QString &fileName); +protected: /** - * @brief ChangedActivDraw change active pattern peace. - * @param newName new pattern peace name. + * @brief data container with data. */ - void ChangedActivDraw(const QString &newName); - /** - * @brief ChangedNameDraw save new name active pattern peace. - * @param oldName old name. - * @param newName new name. - */ - void ChangedNameDraw(const QString &oldName, const QString &newName); - /** - * @brief FullUpdateFromFile update tool data form file. - */ - void FullUpdateFromFile(); - /** - * @brief patternChanged emit if we have unsaved change. - */ - void patternChanged(); - /** - * @brief ShowTool highlight tool. - * @param id tool id. - * @param color highlight color. - * @param enable enable or disable highlight. - */ - void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - /** - * @brief ChangedCursor change cursor position. - * @param id tool id. - */ - void ChangedCursor(qint64 id); -public slots: - /** - * @brief FullUpdateTree lite parse file. - */ - void FullUpdateTree(); - /** - * @brief haveLiteChange we have unsaved change. - */ - void haveLiteChange(); - /** - * @brief ShowHistoryTool hightlight tool. - * @param id tool id. - * @param color hightlight color. - * @param enable enable or diasable hightlight. - */ - void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); + VContainer *data; + void setTagText(const QString &tag, const QString &text); + private: Q_DISABLE_COPY(VDomDocument) /** * @brief map use for finding element by id. */ QHash map; - /** - * @brief nameActivDraw name current pattern peace. - */ - QString nameActivDraw; - /** - * @brief data container with data. - */ - VContainer *data; - /** - * @brief tools list with pointer on tools. - */ - QHash tools; - /** - * @brief history history records. - */ - QVector history; - /** - * @brief cursor cursor keep id tool after which we will add new tool in file. - */ - qint64 cursor; - /** - * @brief comboBoxDraws combobox with pattern peace names. - */ - QComboBox *comboBoxDraws; - /** - * @brief mode current draw mode. - */ - Draw::Draws *mode; - /** - * @brief fileModified true if exist change in file. - */ - bool patternModified; + /** * @brief find find element by id. * @param node node. @@ -335,126 +145,28 @@ private: * @return true if found. */ bool find(const QDomElement &node, const QString& id); - /** - * @brief CheckNameDraw check if exist pattern peace with this name. - * @param name pattern peace name. - * @return true if exist. - */ - bool CheckNameDraw(const QString& name) const; - /** - * @brief SetActivDraw set current pattern peace. - * @param name pattern peace name. - */ - void SetActivDraw(const QString& name); - /** - * @brief GetActivNodeElement find element in current pattern peace by name. - * @param name name tag. - * @param element element. - * @return true if found. - */ - bool GetActivNodeElement(const QString& name, QDomElement& element); - /** - * @brief ParseDrawElement parse draw tag. - * @param sceneDraw draw scene. - * @param sceneDetail details scene. - * @param node node. - * @param parse parser file mode. - */ - void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, - const QDomNode& node, const Document::Documents &parse); - /** - * @brief ParseDrawMode parse draw tag with draw mode. - * @param sceneDraw draw scene. - * @param sceneDetail details scene. - * @param node node. - * @param parse parser file mode. - * @param mode draw mode. - */ - void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, - const QDomNode& node, const Document::Documents &parse, const Draw::Draws &mode); - /** - * @brief ParseDetailElement parse detail tag. - * @param sceneDetail detail scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - */ - void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse); - /** - * @brief ParseDetails parse details tag. - * @param sceneDetail detail scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - */ - void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse); - /** - * @brief ParsePointElement parse point tag. - * @param scene scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - * @param type type of point. - * @param mode draw mode. - */ - void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString &type); - /** - * @brief ParseLineElement parse line tag. - * @param scene scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - * @param mode draw mode. - */ - void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse); - /** - * @brief ParseSplineElement parse spline tag. - * @param scene scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - * @param type type of spline. - * @param mode draw mode. - */ - void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type); - /** - * @brief ParseArcElement parse arc tag. - * @param scene scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - * @param type type of spline. - * @param mode draw mode. - */ - void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type); - /** - * @brief ParseToolsElement parse tools tag. - * @param scene scene. - * @param domElement tag in xml tree. - * @param parse parser file mode. - * @param type type of spline. - */ - void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type); - /** - * @brief ParseIncrementsElement parse increments tag. - * @param node tag in xml tree. - */ - void ParseIncrementsElement(const QDomNode& node); - /** - * @brief GetParametrId return value id attribute. - * @param domElement tag in xml tree. - * @return id value. - */ - qint64 GetParametrId(const QDomElement& domElement) const; - /** - * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique. - * @param node tag in xml tree. - * @param vector list with ids. - */ - void CollectId(const QDomElement &node, QVector &vector)const; }; +template <> +inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, const QString &value) +{ + domElement.setAttribute(name, value); +} + +template <> +inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, + const Pattern::Measurements &value) +{ + if (value == Pattern::Standard) + { + domElement.setAttribute(name, "standard"); + } + else + { + domElement.setAttribute(name, "individual"); + } +} + #ifdef Q_CC_GNU #pragma GCC diagnostic pop #endif diff --git a/src/xml/vindividualmeasurements.cpp b/src/xml/vindividualmeasurements.cpp new file mode 100644 index 000000000..0f9d62271 --- /dev/null +++ b/src/xml/vindividualmeasurements.cpp @@ -0,0 +1,303 @@ +/************************************************************************ + ** + ** @file vindividualmeasurements.cpp + ** @author Roman Telezhinsky + ** @date 8 3, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vindividualmeasurements.h" + +const QString VIndividualMeasurements::AttrIgnore = QStringLiteral("ignore"); +const QString VIndividualMeasurements::AttrName = QStringLiteral("name"); +const QString VIndividualMeasurements::AttrM_number = QStringLiteral("m_number"); +const QString VIndividualMeasurements::AttrGui_text = QStringLiteral("gui_text"); +const QString VIndividualMeasurements::AttrValue = QStringLiteral("value"); +const QString VIndividualMeasurements::AttrDescription = QStringLiteral("description"); + +const QString VIndividualMeasurements::TagLang = QStringLiteral("lang"); +const QString VIndividualMeasurements::TagFamily_name = QStringLiteral("family-name"); +const QString VIndividualMeasurements::TagGiven_name = QStringLiteral("given-name"); +const QString VIndividualMeasurements::TagBirth_date = QStringLiteral("birth-date"); +const QString VIndividualMeasurements::TagSex = QStringLiteral("sex"); +const QString VIndividualMeasurements::TagUnit = QStringLiteral("unit"); +const QString VIndividualMeasurements::TagEmail = QStringLiteral("email"); + +const QString VIndividualMeasurements::SexMale = QStringLiteral("male"); +const QString VIndividualMeasurements::SexFemale = QStringLiteral("female"); + +VIndividualMeasurements::VIndividualMeasurements(VContainer *data):VDomDocument(data) +{ +} + +Valentina::Units VIndividualMeasurements::Unit() const +{ + const QString unit = UniqueTagText(TagUnit, UnitCM); + return VDomDocument::StrToUnits(unit); +} + +void VIndividualMeasurements::setUnit(const Valentina::Units &unit) +{ + setTagText(TagUnit, UnitsToStr(unit)); +} + +void VIndividualMeasurements::Measurements() +{ + //head and neck + Measurement("head_girth"); + Measurement("mid_neck_girth"); + Measurement("neck_base_girth"); + Measurement("head_and_neck_length"); + //torso + Measurement("center_front_waist_length"); + Measurement("center_back_waist_length"); + Measurement("shoulder_length"); + Measurement("side_waist_length"); + Measurement("trunk_length"); + Measurement("shoulder_girth"); + Measurement("upper_chest_girth"); + Measurement("bust__girth"); + Measurement("under_bust_girth"); + Measurement("waist_girth"); + Measurement("high_hip_girth"); + Measurement("hip_girth"); + Measurement("upper_front_chest_width"); + Measurement("front_chest_width"); + Measurement("across_front_shoulder_width"); + Measurement("across_back_shoulder_width"); + Measurement("upper_back_width"); + Measurement("back_width"); + Measurement("bustpoint_to_bustpoint"); + Measurement("halter_bustpoint_to_bustpoint"); + Measurement("neck_to_bustpoint"); + Measurement("crotch_length"); + Measurement("rise_height"); + Measurement("shoulder_drop"); + Measurement("shoulder_slope_degrees"); + Measurement("front_shoulder_slope_length"); + Measurement("back_shoulder_slope_length"); + Measurement("front_shoulder_to_waist_length"); + Measurement("back_shoulder_to_waist_length"); + Measurement("front_neck_arc"); + Measurement("back_neck_arc"); + Measurement("front_upper-bust_arc"); + Measurement("back_upper-bust_arc"); + Measurement("front_waist_arc"); + Measurement("back_waist_arc"); + Measurement("front_upper-hip_arc"); + Measurement("back_upper-hip_arc"); + Measurement("front_hip_arc"); + Measurement("back_hip_arc"); + Measurement("chest_slope"); + Measurement("back_slope"); + Measurement("front_waist_slope"); + Measurement("back_waist_slope"); + Measurement("front-neck_to_upper-chest_height"); + Measurement("front-neck_to_bust_height"); + //arm + Measurement("armscye_girth"); + Measurement("elbow_girth"); + Measurement("upper-arm_girth"); + Measurement("wrist_girth"); + Measurement("scye_depth"); + Measurement("shoulder_and_arm_length"); + Measurement("underarm_length"); + Measurement("cervicale_to_wrist_length"); + Measurement("shoulder_to_elbow_length"); + Measurement("arm_length"); + //hand + Measurement("hand_width"); + Measurement("hand_length"); + Measurement("hand_girth"); + //leg + Measurement("thigh_girth"); + Measurement("mid_thigh_girth"); + Measurement("knee_girth"); + Measurement("calf_girth"); + Measurement("ankle_girth"); + Measurement("knee_height"); + Measurement("ankle_height"); + //foot + Measurement("foot_width"); + Measurement("foot_length"); + //heights + Measurement("height"); + Measurement("cervicale_height"); + Measurement("cervicale_to_knee_height"); + Measurement("waist_height"); + Measurement("high_hip_height"); + Measurement("hip_height"); + Measurement("waist_to_hip_height"); + Measurement("waist_to_knee_height"); + Measurement("crotch_height"); +} + +void VIndividualMeasurements::Measurement(const QString &tag) +{ + const QDomNodeList nodeList = this->elementsByTagName(tag); + if (nodeList.isEmpty()) + { + qDebug()<<"Measurement" << tag <<"doesn't exist"<AddMeasurement(name, VMeasurement(value/10.0, gui_text, description, tag)); + if (m_number.isEmpty()) + { + qDebug()<<"Can't find language-independent measurement name for "<< tag; + return; + } + else + { + VMeasurement m(value/10.0, gui_text, description, tag); + m.setVirtual(true); + data->AddMeasurement(m_number, m); + } + } + else//Cm or inch. + { + data->AddMeasurement(name, VMeasurement(value, gui_text, description, tag)); + if (m_number.isEmpty()) + { + qDebug()<<"Can't find language-independent measurement name for "<< tag; + return; + } + else + { + VMeasurement m(value, gui_text, description, tag); + m.setVirtual(true); + data->AddMeasurement(m_number, m); + } + } + } + } + } +} + +QString VIndividualMeasurements::Language() const +{ + return UniqueTagText(TagLang, "en"); +} + +QString VIndividualMeasurements::FamilyName() const +{ + return UniqueTagText(TagFamily_name, ""); +} + +void VIndividualMeasurements::setFamilyName(const QString &text) +{ + setTagText(TagFamily_name, text); +} + +QString VIndividualMeasurements::GivenName() const +{ + return UniqueTagText(TagGiven_name, ""); +} + +void VIndividualMeasurements::setGivenName(const QString &text) +{ + setTagText(TagGiven_name, text); +} + +QDate VIndividualMeasurements::BirthDate() const +{ + const QString date = UniqueTagText(TagBirth_date, "1900-01-01"); + return QDate::fromString(date, "yyyy-MM-dd"); +} + +void VIndividualMeasurements::setBirthDate(const QDate &date) +{ + setTagText(TagBirth_date, date.toString("yyyy-MM-dd")); +} + +VIndividualMeasurements::Genders VIndividualMeasurements::Sex() const +{ + return StrToGender(UniqueTagText(TagSex, "")); +} + +void VIndividualMeasurements::setSex(const VIndividualMeasurements::Genders &sex) +{ + setTagText(TagSex, GenderToStr(sex)); +} + +QString VIndividualMeasurements::Mail() const +{ + return UniqueTagText(TagEmail, ""); +} + +void VIndividualMeasurements::setMail(const QString &text) +{ + setTagText(TagEmail, text); +} + +QString VIndividualMeasurements::GenderToStr(const VIndividualMeasurements::Genders &sex) +{ + switch (sex) + { + case Male: + return SexMale; + case Female: + return SexFemale; + default: + return SexMale; + } +} + +VIndividualMeasurements::Genders VIndividualMeasurements::StrToGender(const QString &sex) +{ + QStringList genders; + genders << SexMale << SexFemale; + switch (genders.indexOf(sex)) + { + case 0: // SexMale + return Male; + case 1: // SexFemale + return Female; + default: + return Male; + } +} diff --git a/src/xml/vindividualmeasurements.h b/src/xml/vindividualmeasurements.h new file mode 100644 index 000000000..7af71045e --- /dev/null +++ b/src/xml/vindividualmeasurements.h @@ -0,0 +1,82 @@ +/************************************************************************ + ** + ** @file vindividualmeasurements.h + ** @author Roman Telezhinsky + ** @date 8 3, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VINDIVIDUALMEASUREMENTS_H +#define VINDIVIDUALMEASUREMENTS_H + +#include "vdomdocument.h" +#include + +class VIndividualMeasurements:public VDomDocument +{ +public: + enum Sex { Male, Female }; + Q_DECLARE_FLAGS(Genders, Sex) + + VIndividualMeasurements(VContainer *data); + Valentina::Units Unit() const; + void setUnit(const Valentina::Units &unit); + void Measurements(); + QString Language() const; + QString FamilyName() const; + void setFamilyName(const QString &text); + QString GivenName() const; + void setGivenName(const QString &text); + QDate BirthDate() const; + void setBirthDate(const QDate &date); + VIndividualMeasurements::Genders Sex() const; + void setSex(const VIndividualMeasurements::Genders &sex); + QString Mail() const; + void setMail(const QString &text); + static const QString AttrIgnore; + static const QString AttrName; + static const QString AttrM_number; + static const QString AttrGui_text; + static const QString AttrValue; + static const QString AttrDescription; + + static const QString TagLang; + static const QString TagFamily_name; + static const QString TagGiven_name; + static const QString TagBirth_date; + static const QString TagSex; + static const QString TagUnit; + static const QString TagEmail; + + static const QString SexMale; + static const QString SexFemale; + + static QString GenderToStr(const VIndividualMeasurements::Genders &sex); + static VIndividualMeasurements::Genders StrToGender(const QString &sex); +private: + void Measurement(const QString &tag); +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS( VIndividualMeasurements::Genders ) + +#endif // VINDIVIDUALMEASUREMENTS_H diff --git a/src/xml/vpattern.cpp b/src/xml/vpattern.cpp new file mode 100644 index 000000000..16e5b320d --- /dev/null +++ b/src/xml/vpattern.cpp @@ -0,0 +1,1455 @@ +/************************************************************************ + ** + ** @file vpattern.cpp + ** @author Roman Telezhinsky + ** @date 24 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vpattern.h" + +#include "../tools/vtooldetail.h" +#include "../tools/vtooluniondetails.h" +#include "../tools/drawTools/drawtools.h" +#include "../tools/nodeDetails/nodedetails.h" +#include "../exception/vexceptionobjecterror.h" +#include "../exception/vexceptionwrongid.h" +#include "../exception/vexceptionconversionerror.h" +#include "vstandardmeasurements.h" +#include "vindividualmeasurements.h" + +#include + +const QString VPattern::TagPattern = QStringLiteral("pattern"); +const QString VPattern::TagCalculation = QStringLiteral("calculation"); +const QString VPattern::TagModeling = QStringLiteral("modeling"); +const QString VPattern::TagDetails = QStringLiteral("details"); +const QString VPattern::TagAuthor = QStringLiteral("author"); +const QString VPattern::TagDescription = QStringLiteral("description"); +const QString VPattern::TagNotes = QStringLiteral("notes"); +const QString VPattern::TagMeasurements = QStringLiteral("measurements"); +const QString VPattern::TagIncrements = QStringLiteral("increments"); +const QString VPattern::TagIncrement = QStringLiteral("increment"); +const QString VPattern::TagDraw = QStringLiteral("draw"); +const QString VPattern::TagPoint = QStringLiteral("point"); +const QString VPattern::TagLine = QStringLiteral("line"); +const QString VPattern::TagSpline = QStringLiteral("spline"); +const QString VPattern::TagArc = QStringLiteral("arc"); +const QString VPattern::TagTools = QStringLiteral("tools"); + +const QString VPattern::AttrName = QStringLiteral("name"); +const QString VPattern::AttrType = QStringLiteral("type"); +const QString VPattern::AttrPath = QStringLiteral("path"); + +const QString VPattern::IncrementName = QStringLiteral("name"); +const QString VPattern::IncrementBase = QStringLiteral("base"); +const QString VPattern::IncrementKsize = QStringLiteral("ksize"); +const QString VPattern::IncrementKgrowth = QStringLiteral("kgrowth"); +const QString VPattern::IncrementDescription = QStringLiteral("description"); + +VPattern::VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent) + : QObject(parent), VDomDocument(data), nameActivDraw(QString()), tools(QHash()), + history(QVector()), cursor(0), comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false) +{ +} + +void VPattern::CreateEmptyFile(const QString &tablePath) +{ + if (tablePath.isEmpty()) + { + throw VException("Path to measurement table empty."); + } + QDomElement patternElement = this->createElement(TagPattern); + + patternElement.appendChild(createComment("Valentina pattern format.")); + patternElement.appendChild(createElement(TagAuthor)); + patternElement.appendChild(createElement(TagDescription)); + patternElement.appendChild(createElement(TagNotes)); + + QDomElement measurements = createElement(TagMeasurements); + SetAttribute(measurements, AttrUnit, UnitsToStr(qApp->patternUnit())); + SetAttribute(measurements, AttrType, qApp->patternType()); + SetAttribute(measurements, AttrPath, tablePath); + patternElement.appendChild(measurements); + + patternElement.appendChild(createElement(TagIncrements)); + + this->appendChild(patternElement); + insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild()); +} + +void VPattern::ChangeActivDraw(const QString &name, const Document::Documents &parse) +{ + Q_ASSERT_X(name.isEmpty() == false, "ChangeActivDraw", "name draw is empty"); + if (CheckNameDraw(name)) + { + this->nameActivDraw = name; + if (parse == Document::FullParse) + { + emit ChangedActivDraw(name); + } + } +} + +bool VPattern::GetActivDrawElement(QDomElement &element) +{ + if (nameActivDraw.isEmpty() == false) + { + const QDomNodeList elements = this->documentElement().elementsByTagName( TagDraw ); + if (elements.size() == 0) + { + return false; + } + for ( qint32 i = 0; i < elements.count(); i++ ) + { + element = elements.at( i ).toElement(); + if (element.isNull() == false) + { + const QString fieldName = element.attribute( AttrName ); + if ( fieldName == nameActivDraw ) + { + return true; + } + } + } + } + return false; +} + +bool VPattern::appendDraw(const QString &name) +{ + Q_ASSERT_X(name.isEmpty() == false, "appendDraw", "name draw is empty"); + if (name.isEmpty()) + { + return false; + } + if (CheckNameDraw(name) == false) + { + QDomElement rootElement = this->documentElement(); + + QDomElement drawElement = this->createElement(TagDraw); + SetAttribute(drawElement, AttrName, name); + + drawElement.appendChild(createElement(TagCalculation)); + drawElement.appendChild(createElement(TagModeling)); + drawElement.appendChild(createElement(TagDetails)); + + rootElement.appendChild(drawElement); + + if (nameActivDraw.isEmpty()) + { + SetActivDraw(name); + } + else + { + ChangeActivDraw(name); + } + return true; + } + return false; +} + +bool VPattern::SetNameDraw(const QString &name) +{ + Q_ASSERT_X(name.isEmpty() == false, "SetNameDraw", "name draw is empty"); + const QString oldName = nameActivDraw; + QDomElement element; + if (GetActivDrawElement(element)) + { + nameActivDraw = name; + element.setAttribute(AttrName, nameActivDraw); + emit patternChanged(); + emit ChangedNameDraw(oldName, nameActivDraw); + return true; + } + else + { + qDebug()<<"Can't find activ draw"<addItem(GetParametrString(domElement, AttrName)); + } + else + { + ChangeActivDraw(GetParametrString(domElement, AttrName), Document::LiteParse); + } + ParseDrawElement(sceneDraw, sceneDetail, domElement, parse); + break; + case 1: // TagIncrements + ParseIncrementsElement(domElement); + break; + case 2: // TagAuthor + break; + case 3: // TagDescription + break; + case 4: // TagNotes + break; + case 5: // TagMeasurements + break; + default: + qDebug()<<"Wrong tag name"<itemText(comboBoxDraws->currentIndex()); + if (nameActivDraw != nameDraw) + { + nameActivDraw = nameDraw; + quint32 id = 0; + if (history.size() == 0) + { + return; + } + for (qint32 i = 0; i < history.size(); ++i) + { + const VToolRecord tool = history.at(i); + if (tool.getNameDraw() == nameDraw) + { + id = tool.getId(); + } + } + if (id == 0) + { + const VToolRecord tool = history.at(history.size()-1); + id = tool.getId(); + if (id == 0) + { + return; + } + } + if (tools.size() > 0) + { + const VDataTool *vTool = tools.value(id); + data->setData(vTool->getData()); + } + } + } +} + +void VPattern::AddTool(const quint32 &id, VDataTool *tool) +{ + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + Q_CHECK_PTR(tool); + tools.insert(id, tool); +} + +void VPattern::UpdateToolData(const quint32 &id, VContainer *data) +{ + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + Q_CHECK_PTR(data); + VDataTool *tool = tools.value(id); + Q_CHECK_PTR(tool); + tool->VDataTool::setData(data); +} + +void VPattern::IncrementReferens(quint32 id) const +{ + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + VDataTool *tool = tools.value(id); + Q_CHECK_PTR(tool); + tool->incrementReferens(); +} + +void VPattern::DecrementReferens(quint32 id) const +{ + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + VDataTool *tool = tools.value(id); + Q_CHECK_PTR(tool); + tool->decrementReferens(); +} + +void VPattern::TestUniqueId() const +{ + QVector vector; + CollectId(documentElement(), vector); +} + +quint32 VPattern::SPointActiveDraw() +{ + QDomElement calcElement; + if (GetActivNodeElement(TagCalculation, calcElement)) + { + const QDomNode domNode = calcElement.firstChild(); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + if (domElement.tagName() == VToolPoint::TagName && + domElement.attribute(AttrType, "") == VToolSinglePoint::ToolType) + { + return GetParametrId(domElement); + } + } + } + } + return 0; +} + +bool VPattern::CheckNameDraw(const QString &name) const +{ + Q_ASSERT_X(name.isEmpty() == false, "CheckNameDraw", "name draw is empty"); + const QDomNodeList elements = this->documentElement().elementsByTagName( TagDraw ); + if (elements.size() == 0) + { + return false; + } + for ( qint32 i = 0; i < elements.count(); i++ ) + { + const QDomElement elem = elements.at( i ).toElement(); + if (elem.isNull() == false) + { + if ( GetParametrString(elem, AttrName) == name ) + { + return true; + } + } + } + return false; +} + +void VPattern::SetActivDraw(const QString &name) +{ + Q_ASSERT_X(name.isEmpty() == false, "SetActivDraw", "name draw is empty"); + this->nameActivDraw = name; +} + +bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element) +{ + Q_ASSERT_X(name.isEmpty() == false, "GetActivNodeElement", "name draw is empty"); + QDomElement drawElement; + if (GetActivDrawElement(drawElement)) + { + const QDomNodeList listElement = drawElement.elementsByTagName(name); + if (listElement.size() != 1) + { + return false; + } + element = listElement.at( 0 ).toElement(); + if (element.isNull() == false) + { + return true; + } + else + { + return false; + } + } + return false; +} + +QString VPattern::MPath() const +{ + QDomNodeList list = elementsByTagName(TagMeasurements); + QDomElement element = list.at(0).toElement(); + if (element.isElement()) + { + return GetParametrString(element, AttrPath); + } + else + { + return QString(); + } +} + +void VPattern::SetPath(const QString &path) +{ + if (path.isEmpty()) + { + qDebug()<<"Path to measurements is empty"<ClearCalculationGObjects(); + ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Valentina::Calculation); + break; + case 1: // TagModeling + ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Valentina::Modeling); + break; + case 2: // TagDetails + ParseDetails(sceneDetail, domElement, parse); + break; + default: + qDebug()<<"Wrong tag name"<toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"))); + detail.setMy(qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "0.0"))); + detail.setSeamAllowance(GetParametrUInt(domElement, VToolDetail::AttrSupplement, "1")); + detail.setWidth(GetParametrDouble(domElement, VToolDetail::AttrWidth, "10.0")); + detail.setClosed(GetParametrUInt(domElement, VToolDetail::AttrClosed, "1")); + + const QDomNodeList nodeList = domElement.childNodes(); + const qint32 num = nodeList.size(); + for (qint32 i = 0; i < num; ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (element.isNull() == false) + { + if (element.tagName() == VToolDetail::TagNode) + { + const quint32 id = GetParametrUInt(element, VToolDetail::AttrIdObject, "0"); + const qreal mx = qApp->toPixel(GetParametrDouble(element, VAbstractTool::AttrMx, "0.0")); + const qreal my = qApp->toPixel(GetParametrDouble(element, VAbstractTool::AttrMy, "0.0")); + const NodeDetail::NodeDetails nodeType = NodeDetail::Contour; + + const QString t = GetParametrString(element, AttrType, "NodePoint"); + Valentina::Tools tool; + QStringList types; + types << VToolDetail::NodePoint << VToolDetail::NodeArc << VToolDetail::NodeSpline << + VToolDetail::NodeSplinePath; + switch (types.indexOf(t)) + { + case 0: // VToolDetail::NodePoint + tool = Valentina::NodePoint; + break; + case 1: // VToolDetail::NodeArc + tool = Valentina::NodeArc; + break; + case 2: // VToolDetail::NodeSpline + tool = Valentina::NodeSpline; + break; + case 3: // VToolDetail::NodeSplinePath + tool = Valentina::NodeSplinePath; + break; + default: + qDebug()<<"Wrong node type."<toPixel(GetParametrDouble(domElement, VAbstractTool::AttrX, "10.0")); + const qreal y = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0")); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + + data->UpdateGObject(id, new VPointF(x, y, name, mx, my)); + VDrawTool::AddRecord(id, Valentina::SinglePointTool, this); + if (parse != Document::FullParse) + { + UpdateToolData(id, data); + } + if (parse == Document::FullParse) + { + spoint = new VToolSinglePoint(this, data, id, Valentina::FromFile); + scene->addItem(spoint); + connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); + tools[id] = spoint; + } + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating single point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + scene->removeItem(spoint); + delete spoint; + throw excep; + } + break; + } + case 1: //VToolEndLine::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); + const qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); + + VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, + mx, my, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 2: //VToolAlongLine::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + + VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, scene, this, + data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 3: //VToolShoulderPoint::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + const quint32 p1Line = GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0"); + const quint32 p2Line = GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0"); + const quint32 pShoulder = GetParametrUInt(domElement, VAbstractTool::AttrPShoulder, "0"); + + VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this, + data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 4: //VToolNormal::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); + + VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, scene, + this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 5: //VToolBisector::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const quint32 thirdPointId = GetParametrUInt(domElement, VAbstractTool::AttrThirdPoint, "0"); + + VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, + typeLine, name, mx, my, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 6: //VToolLineIntersect::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const quint32 p1Line1Id = GetParametrUInt(domElement, VAbstractTool::AttrP1Line1, "0"); + const quint32 p2Line1Id = GetParametrUInt(domElement, VAbstractTool::AttrP2Line1, "0"); + const quint32 p1Line2Id = GetParametrUInt(domElement, VAbstractTool::AttrP1Line2, "0"); + const quint32 p2Line2Id = GetParametrUInt(domElement, VAbstractTool::AttrP2Line2, "0"); + + VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, + mx, my, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of lineintersection"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 7: //VToolPointOfContact::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "0"); + const quint32 center = GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0"); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + + VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, scene, this, + data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 8: //VNodePoint::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0"); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0"); + const VPointF *point = data->GeometricObject(idObject ); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + data->UpdateGObject(id, new VPointF(point->x(), point->y(), point->name(), mx, my, idObject, + Valentina::Modeling)); + VNodePoint::Create(this, data, id, idObject, parse, Valentina::FromFile, idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating modeling point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 9: //VToolHeight::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); + const quint32 p1LineId = GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0"); + const quint32 p2LineId = GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0"); + + VToolHeight::Create(id, name, typeLine, basePointId, p1LineId, p2LineId, + mx, my, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating height"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 10: //VToolTriangle::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const quint32 axisP1Id = GetParametrUInt(domElement, VAbstractTool::AttrAxisP1, "0"); + const quint32 axisP2Id = GetParametrUInt(domElement, VAbstractTool::AttrAxisP2, "0"); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + + VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, scene, this, + data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating triangle"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 11: //VToolPointOfIntersection::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const quint32 firstPointId = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPointId = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + + VToolPointOfIntersection::Create(id, name, firstPointId, secondPointId, mx, my, scene, this, data, + parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of intersection"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 12: //VToolCutSpline::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); + const quint32 splineId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, "0"); + + VToolCutSpline::Create(id, name, formula, splineId, mx, my, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating cut spline point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 13: //VToolCutSplinePath::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); + const quint32 splinePathId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, "0"); + + VToolCutSplinePath::Create(id, name, formula, splinePathId, mx, my, + scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating cut spline path point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 14: //VToolCutArc::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + const qreal mx = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + const qreal my = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); + const quint32 arcId = GetParametrUInt(domElement, VToolCutArc::AttrArc, "0"); + + VToolCutArc::Create(id, name, formula, arcId, mx, my, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating cut arc point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + default: + qDebug() << "Illegal point type in VDomDocument::ParsePointElement()."; + break; + } +} + +void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, + const Document::Documents &parse) +{ + Q_CHECK_PTR(scene); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + try + { + const quint32 id = GetParametrId(domElement); + const quint32 firstPoint = GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); + const quint32 secondPoint = GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); + const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, + VAbstractTool::TypeLineLine); + + VToolLine::Create(id, firstPoint, secondPoint, typeLine, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating line"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + +void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement, + const Document::Documents &parse, const QString &type) +{ + Q_CHECK_PTR(scene); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); + + QStringList splines; + splines << VToolSpline::ToolType << VToolSplinePath::ToolType << VNodeSpline::ToolType << VNodeSplinePath::ToolType; + switch (splines.indexOf(type)) + { + case 0: //VToolSpline::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 point1 = GetParametrUInt(domElement, VAbstractTool::AttrPoint1, "0"); + const quint32 point4 = GetParametrUInt(domElement, VAbstractTool::AttrPoint4, "0"); + const qreal angle1 = GetParametrDouble(domElement, VAbstractTool::AttrAngle1, "270.0"); + const qreal angle2 = GetParametrDouble(domElement, VAbstractTool::AttrAngle2, "90.0"); + const qreal kAsm1 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm1, "1.0"); + const qreal kAsm2 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm2, "1.0"); + const qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); + + VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse, + Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating simple curve"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 1: //VToolSplinePath::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); + VSplinePath *path = new VSplinePath(kCurve); + + const QDomNodeList nodeList = domElement.childNodes(); + const qint32 num = nodeList.size(); + for (qint32 i = 0; i < num; ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (element.isNull() == false) + { + if (element.tagName() == VAbstractTool::AttrPathPoint) + { + const qreal kAsm1 = GetParametrDouble(element, VAbstractTool::AttrKAsm1, "1.0"); + const qreal angle = GetParametrDouble(element, VAbstractTool::AttrAngle, "0"); + const qreal kAsm2 = GetParametrDouble(element, VAbstractTool::AttrKAsm2, "1.0"); + const quint32 pSpline = GetParametrUInt(element, VAbstractTool::AttrPSpline, "0"); + const VPointF p = *data->GeometricObject(pSpline); + + QLineF line(0, 0, 100, 0); + line.setAngle(angle+180); + + VSplinePoint splPoint(p, kAsm1, line.angle(), kAsm2, angle); + path->append(splPoint); + if (parse == Document::FullParse) + { + IncrementReferens(pSpline); + } + } + } + } + + VToolSplinePath::Create(id, path, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating curve path"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 2: //VNodeSpline::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0"); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0"); + VSpline *spl = new VSpline(*data->GeometricObject(idObject)); + spl->setIdObject(idObject); + spl->setMode(Valentina::Modeling); + data->UpdateGObject(id, spl); + VNodeSpline::Create(this, data, id, idObject, parse, Valentina::FromFile, idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating modeling simple curve"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 3: //VNodeSplinePath::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0"); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0"); + VSplinePath *path = new VSplinePath(*data->GeometricObject(idObject)); + path->setIdObject(idObject); + path->setMode(Valentina::Modeling); + data->UpdateGObject(id, path); + VNodeSplinePath::Create(this, data, id, idObject, parse, Valentina::FromFile, idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating modeling curve path"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + default: + qDebug() << "Illegal spline type in VDomDocument::ParseSplineElement()."; + break; + } +} + +void VPattern::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement, + const Document::Documents &parse, const QString &type) +{ + Q_CHECK_PTR(scene); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); + + QStringList arcs; + arcs << VToolArc::ToolType << VNodeArc::ToolType; + + switch (arcs.indexOf(type)) + { + case 0: //VToolArc::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 center = GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0"); + const QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "10"); + const QString f1 = GetParametrString(domElement, VAbstractTool::AttrAngle1, "180"); + const QString f2 = GetParametrString(domElement, VAbstractTool::AttrAngle2, "270"); + + VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + case 1: //VNodeArc::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, "0"); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, "0"); + VArc *arc = new VArc(*data->GeometricObject(idObject)); + arc->setIdObject(idObject); + arc->setMode(Valentina::Modeling); + data->UpdateGObject(id, arc); + VNodeArc::Create(this, data, id, idObject, parse, Valentina::FromFile, idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating modeling arc"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + default: + qDebug() << "Illegal arc type in VDomDocument::ParseArcElement()."; + break; + } +} + +void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &domElement, + const Document::Documents &parse, const QString &type) +{ + Q_CHECK_PTR(scene); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); + + QStringList tools; + tools << VToolUnionDetails::ToolType; + + switch (tools.indexOf(type)) + { + case 0: //VToolUnionDetails::ToolType + try + { + const quint32 id = GetParametrId(domElement); + const quint32 indexD1 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD1, "-1"); + const quint32 indexD2 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD2, "-1"); + + const QVector vector = VToolUnionDetails::GetDetailFromFile(this, domElement); + + VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, indexD1, indexD2, scene, this, data, parse, + Valentina::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating union details"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + break; + default: + qDebug() << "Illegal tools type in VDomDocument::ParseToolsElement()."; + break; + } +} + +void VPattern::ParseIncrementsElement(const QDomNode &node) +{ + QDomNode domNode = node.firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + if (domElement.tagName() == TagIncrement) + { + const quint32 id = GetParametrId(domElement); + const QString name = GetParametrString(domElement, IncrementName, ""); + const qreal base = GetParametrDouble(domElement, IncrementBase, "0"); + const qreal ksize = GetParametrDouble(domElement, IncrementKsize, "0"); + const qreal kgrowth = GetParametrDouble(domElement, IncrementKgrowth, "0"); + const QString desc = GetParametrString(domElement, IncrementDescription, "Description"); + data->UpdateId(id); + data->AddIncrement(name, VIncrement(id, base, ksize, kgrowth, desc)); + } + } + } + domNode = domNode.nextSibling(); + } +} + +quint32 VPattern::GetParametrId(const QDomElement &domElement) const +{ + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + quint32 id = 0; + + QString message = tr("Got wrong parameter id. Need only id > 0."); + try + { + id = GetParametrUInt(domElement, VDomDocument::AttrId, "0"); + if (id <= 0) + { + throw VExceptionWrongId(message, domElement); + } + } + catch (const VExceptionConversionError &e) + { + VExceptionWrongId excep(message, domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + return id; +} + +void VPattern::CollectId(const QDomElement &node, QVector &vector) const +{ + if (node.hasAttribute(VDomDocument::AttrId)) + { + const quint32 id = GetParametrId(node); + if (vector.contains(id)) + { + throw VExceptionWrongId(tr("This id is not unique."), node); + } + vector.append(id); + } + + for (qint32 i=0; iClear(); + UpdateMeasurements(); + nameActivDraw.clear(); + sceneDraw->clear(); + sceneDetail->clear(); + comboBoxDraws->clear(); + tools.clear(); + cursor = 0; + } + data->ClearLengthLines(); + data->ClearLengthArcs(); + data->ClearLengthSplines(); + data->ClearLineAngles(); + data->ClearDetails(); + history.clear(); +} + +void VPattern::UpdateMeasurements() +{ + const QString path = MPath(); + if (MType() == Pattern::Standard) + { + VStandardMeasurements m(data); + m.setContent(path); + m.Measurements(); + } + else + { + VIndividualMeasurements m(data); + m.setContent(path); + m.Measurements(); + } +} diff --git a/src/xml/vpattern.h b/src/xml/vpattern.h new file mode 100644 index 000000000..6a95f56fc --- /dev/null +++ b/src/xml/vpattern.h @@ -0,0 +1,419 @@ +/************************************************************************ + ** + ** @file vpattern.h + ** @author Roman Telezhinsky + ** @date 24 2, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPATTERN_H +#define VPATTERN_H + +#include "vdomdocument.h" +#include "../widgets/vmaingraphicsscene.h" +#include "../tools/vdatatool.h" +#include "vtoolrecord.h" +#include + +namespace Document +{ + /** + * @brief The Document enum parse types. + */ + enum Document { LiteParse, FullParse}; + Q_DECLARE_FLAGS(Documents, Document) +} +Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents) + +/** + * @brief The VPattern class working with pattern file. + */ +class VPattern : public QObject, public VDomDocument +{ + Q_OBJECT +public: + VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent = nullptr); + /** + * @brief CreateEmptyFile create minimal empty file. + * @param tablePath + */ + void CreateEmptyFile(const QString &tablePath); + /** + * @brief ChangeActivDraw set new pattern peace name. + * @param name new name. + * @param parse parser file mode. + */ + void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse); + /** + * @brief GetNameActivDraw return current pattern peace name. + * @return pattern peace name. + */ + QString GetNameActivDraw() const; + /** + * @brief GetActivDrawElement return draw tag for current pattern peace. + * @param element draw tag. + * @return true if found. + */ + bool GetActivDrawElement(QDomElement &element); + /** + * @brief appendDraw add new pattern peace structure to the file. + * @param name pattern peace name. + * @return true if success. + */ + bool appendDraw(const QString& name); + /** + * @brief SetNameDraw change current pattern peace. + * @param name pattern peace name. + * @return true if success. + */ + bool SetNameDraw(const QString& name); + /** + * @brief Parse parse file. + * @param parse parser file mode. + * @param sceneDraw pointer to draw scene. + * @param sceneDetail pointer to details scene. + */ + void Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, + VMainGraphicsScene *sceneDetail); + /** + * @brief getTools return list of tools pointers. + * @return list. + */ + QHash* getTools(); + /** + * @brief getTool return tool from tool list. + * @param id tool id. + * @return tool. + */ + VDataTool* getTool(const quint32 &id); + /** + * @brief getHistory return list with list of history records. + * @return list of history records. + */ + QVector *getHistory(); + /** + * @brief getCursor return cursor. + * @return cursor. + */ + quint32 getCursor() const; + /** + * @brief setCursor set cursor. + * @param value cursor. + */ + void setCursor(const quint32 &value); + /** + * @brief setCurrentData set current data set. + */ + void setCurrentData(); + /** + * @brief AddTool add tool to list tools. + * @param id tool id. + * @param tool tool. + */ + void AddTool(const quint32 &id, VDataTool *tool); + /** + * @brief UpdateToolData update tool in list tools. + * @param id tool id. + * @param data container with variables. + */ + void UpdateToolData(const quint32 &id, VContainer *data); + /** + * @brief IncrementReferens increment reference parent objects. + * @param id parent object id. + */ + void IncrementReferens(quint32 id) const; + /** + * @brief DecrementReferens decrement reference parent objects. + * @param id parent object id. + */ + void DecrementReferens(quint32 id) const; + /** + * @brief TestUniqueId test exist unique id in pattern file. Each id must be unique. + */ + void TestUniqueId() const; + /** + * @brief SPointActiveDraw return id base point current pattern peace. + * @return id base point. + */ + quint32 SPointActiveDraw(); + bool isPatternModified() const; + void setPatternModified(bool value); + /** + * @brief GetActivNodeElement find element in current pattern piece by name. + * @param name name tag. + * @param element element. + * @return true if found. + */ + bool GetActivNodeElement(const QString& name, QDomElement& element); + QString MPath() const; + void SetPath(const QString &path); + Valentina::Units MUnit() const; + Pattern::Measurements MType() const; + static const QString TagPattern; + static const QString TagCalculation; + static const QString TagModeling; + static const QString TagDetails; + static const QString TagAuthor; + static const QString TagDescription; + static const QString TagNotes; + static const QString TagMeasurements; + static const QString TagIncrements; + static const QString TagIncrement; + static const QString TagDraw; + static const QString TagPoint; + static const QString TagLine; + static const QString TagSpline; + static const QString TagArc; + static const QString TagTools; + static const QString AttrName; + static const QString AttrType; + static const QString AttrPath; + static const QString IncrementName; + static const QString IncrementBase; + static const QString IncrementKsize; + static const QString IncrementKgrowth; + static const QString IncrementDescription; + virtual bool SaveDocument(const QString &fileName); +signals: + /** + * @brief ChangedActivDraw change active pattern peace. + * @param newName new pattern peace name. + */ + void ChangedActivDraw(const QString &newName); + /** + * @brief ChangedNameDraw save new name active pattern peace. + * @param oldName old name. + * @param newName new name. + */ + void ChangedNameDraw(const QString &oldName, const QString &newName); + /** + * @brief FullUpdateFromFile update tool data form file. + */ + void FullUpdateFromFile(); + /** + * @brief patternChanged emit if we have unsaved change. + */ + void patternChanged(); + /** + * @brief ShowTool highlight tool. + * @param id tool id. + * @param color highlight color. + * @param enable enable or disable highlight. + */ + void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); + /** + * @brief ChangedCursor change cursor position. + * @param id tool id. + */ + void ChangedCursor(quint32 id); +public slots: + /** + * @brief FullUpdateTree lite parse file. + */ + void FullUpdateTree(); + /** + * @brief haveLiteChange we have unsaved change. + */ + void haveLiteChange(); + /** + * @brief ShowHistoryTool hightlight tool. + * @param id tool id. + * @param color hightlight color. + * @param enable enable or diasable hightlight. + */ + void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable); +private: + Q_DISABLE_COPY(VPattern) + /** + * @brief nameActivDraw name current pattern peace. + */ + QString nameActivDraw; + /** + * @brief tools list with pointer on tools. + */ + QHash tools; + /** + * @brief history history records. + */ + QVector history; + /** + * @brief cursor cursor keep id tool after which we will add new tool in file. + */ + quint32 cursor; + QComboBox *comboBoxDraws; + /** + * @brief mode current draw mode. + */ + Valentina::Draws *mode; + /** + * @brief fileModified true if exist change in file. + */ + bool patternModified; + /** + * @brief CheckNameDraw check if exist pattern peace with this name. + * @param name pattern peace name. + * @return true if exist. + */ + bool CheckNameDraw(const QString& name) const; + /** + * @brief SetActivDraw set current pattern peace. + * @param name pattern peace name. + */ + void SetActivDraw(const QString& name); + + /** + * @brief ParseDrawElement parse draw tag. + * @param sceneDraw draw scene. + * @param sceneDetail details scene. + * @param node node. + * @param parse parser file mode. + */ + void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, + const QDomNode& node, const Document::Documents &parse); + /** + * @brief ParseDrawMode parse draw tag with draw mode. + * @param sceneDraw draw scene. + * @param sceneDetail details scene. + * @param node node. + * @param parse parser file mode. + * @param mode draw mode. + */ + void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, + const QDomNode& node, const Document::Documents &parse, const Valentina::Draws &mode); + /** + * @brief ParseDetailElement parse detail tag. + * @param sceneDetail detail scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + */ + void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, + const Document::Documents &parse); + /** + * @brief ParseDetails parse details tag. + * @param sceneDetail detail scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + */ + void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, + const Document::Documents &parse); + /** + * @brief ParsePointElement parse point tag. + * @param scene scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + * @param type type of point. + * @param mode draw mode. + */ + void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString &type); + /** + * @brief ParseLineElement parse line tag. + * @param scene scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + * @param mode draw mode. + */ + void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse); + /** + * @brief ParseSplineElement parse spline tag. + * @param scene scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + * @param type type of spline. + * @param mode draw mode. + */ + void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString& type); + /** + * @brief ParseArcElement parse arc tag. + * @param scene scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + * @param type type of spline. + * @param mode draw mode. + */ + void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString& type); + /** + * @brief ParseToolsElement parse tools tag. + * @param scene scene. + * @param domElement tag in xml tree. + * @param parse parser file mode. + * @param type type of spline. + */ + void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString& type); + /** + * @brief ParseIncrementsElement parse increments tag. + * @param node tag in xml tree. + */ + void ParseIncrementsElement(const QDomNode& node); + /** + * @brief GetParametrId return value id attribute. + * @param domElement tag in xml tree. + * @return id value. + */ + quint32 GetParametrId(const QDomElement& domElement) const; + /** + * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique. + * @param node tag in xml tree. + * @param vector list with ids. + */ + void CollectId(const QDomElement &node, QVector &vector)const; + void PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, + VMainGraphicsScene *sceneDetail); + void UpdateMeasurements(); +}; + +inline QString VPattern::GetNameActivDraw() const +{ + return nameActivDraw; +} + +inline QHash *VPattern::getTools() +{ + return &tools; +} + +inline QVector *VPattern::getHistory() +{ + return &history; +} + +inline quint32 VPattern::getCursor() const +{ + return cursor; +} + +inline bool VPattern::isPatternModified() const +{ + return patternModified; +} + +inline void VPattern::setPatternModified(bool value) +{ + patternModified = value; +} + +#endif // VPATTERN_H diff --git a/src/xml/vstandardmeasurements.cpp b/src/xml/vstandardmeasurements.cpp new file mode 100644 index 000000000..b61a373ef --- /dev/null +++ b/src/xml/vstandardmeasurements.cpp @@ -0,0 +1,172 @@ +/************************************************************************ + ** + ** @file vstandardmeasurements.cpp + ** @author Roman Telezhinsky + ** @date 8 3, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vstandardmeasurements.h" +#include + +const QString VStandardMeasurements::TagMeasurement = QStringLiteral("measurement"); +const QString VStandardMeasurements::TagDescription = QStringLiteral("description"); +const QString VStandardMeasurements::TagSize = QStringLiteral("size"); +const QString VStandardMeasurements::TagHeight = QStringLiteral("height"); +const QString VStandardMeasurements::AttrName = QStringLiteral("name"); +const QString VStandardMeasurements::AttrGui_text = QStringLiteral("gui_text"); +const QString VStandardMeasurements::AttrBase = QStringLiteral("base"); +const QString VStandardMeasurements::AttrSize_increace = QStringLiteral("size_increace"); +const QString VStandardMeasurements::AttrHeight_increase = QStringLiteral("height_increase"); +const QString VStandardMeasurements::AttrNumber = QStringLiteral("number"); + +VStandardMeasurements::VStandardMeasurements(VContainer *data):VDomDocument(data) +{ +} + +Valentina::Units VStandardMeasurements::Unit() +{ + const QString unit = UniqueTagText(AttrUnit, UnitCM); + return VDomDocument::StrToUnits(unit); +} + +QString VStandardMeasurements::Description() +{ + const QString desc = UniqueTagText(TagDescription, ""); + if (desc.isEmpty()) + { + qDebug()<<"Empty description in standard table."<elementsByTagName(TagMeasurement); + if (nodeList.isEmpty()) + { + qDebug()<<"Measurement list is empty"<AddMeasurement(name, VMeasurement(base/10.0, size_increace/10.0, height_increase/10.0, + gui_text, number)); + } + else// Cm or inch. + { + data->AddMeasurement(name, VMeasurement(base, size_increace, height_increase, + gui_text, number)); + } + } + } + } + } +} + +void VStandardMeasurements::SetSize() +{ + const QDomNodeList nodeList = this->elementsByTagName(TagSize); + if (nodeList.isEmpty()) + { + data->SetSize(50); + data->SetSizeName("Сг"); + } + else + { + const QDomNode domNode = nodeList.at(0); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString name = GetParametrString(domElement, AttrName, "Сг"); + const qreal base = GetParametrDouble(domElement, AttrBase, "50.0"); + if (Unit() == Valentina::Mm)// Convert to Cm. + { + data->SetSize(base/10.0); + data->SetSizeName(name); + } + else// Cm or inch. + { + data->SetSize(base); + data->SetSizeName(name); + } + } + } + } +} + +void VStandardMeasurements::SetHeight() +{ + const QDomNodeList nodeList = this->elementsByTagName(TagHeight); + if (nodeList.isEmpty()) + { + data->SetHeight(176); + data->SetHeightName("P"); + } + else + { + const QDomNode domNode = nodeList.at(0); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString name = GetParametrString(domElement, AttrName, "Р"); + const qreal base = GetParametrDouble(domElement, AttrBase, "176.0"); + if (Unit() == Valentina::Mm)// Convert to Cm. + { + data->SetHeight(base/10.0); + data->SetHeightName(name); + } + else// Cm or inch. + { + data->SetHeight(base); + data->SetHeightName(name); + } + } + } + } +} diff --git a/src/container/vstandardtablerow.cpp b/src/xml/vstandardmeasurements.h similarity index 59% rename from src/container/vstandardtablerow.cpp rename to src/xml/vstandardmeasurements.h index 0c2586cc9..2e23de685 100644 --- a/src/container/vstandardtablerow.cpp +++ b/src/xml/vstandardmeasurements.h @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vstandardtablecell.cpp + ** @file vstandardmeasurements.h ** @author Roman Telezhinsky - ** @date November 15, 2013 + ** @date 8 3, 2014 ** ** @brief ** @copyright @@ -26,11 +26,30 @@ ** *************************************************************************/ -#include "vstandardtablerow.h" +#ifndef VSTANDARDMEASUREMENTS_H +#define VSTANDARDMEASUREMENTS_H -VStandardTableRow::VStandardTableRow() - :base(0), ksize(0), kgrowth(0), description(QString()){} +#include "vdomdocument.h" -VStandardTableRow::VStandardTableRow(const qint32 &base, const qreal &ksize, const qreal &kgrowth, - const QString &description) - :base(base), ksize(ksize), kgrowth(kgrowth), description(description){} +class VStandardMeasurements:public VDomDocument +{ +public: + VStandardMeasurements(VContainer *data); + Valentina::Units Unit(); + QString Description(); + void Measurements(); + void SetSize(); + void SetHeight(); + static const QString TagMeasurement; + static const QString TagDescription; + static const QString TagSize; + static const QString TagHeight; + static const QString AttrName; + static const QString AttrGui_text; + static const QString AttrBase; + static const QString AttrSize_increace; + static const QString AttrHeight_increase; + static const QString AttrNumber; +}; + +#endif // VSTANDARDMEASUREMENTS_H diff --git a/src/xml/vtoolrecord.cpp b/src/xml/vtoolrecord.cpp index e5e69ac0a..ed6f0e756 100644 --- a/src/xml/vtoolrecord.cpp +++ b/src/xml/vtoolrecord.cpp @@ -29,7 +29,7 @@ #include "vtoolrecord.h" VToolRecord::VToolRecord() - :id(0), typeTool(Tool::ArrowTool), nameDraw(QString()){} + :id(0), typeTool(Valentina::ArrowTool), nameDraw(QString()){} -VToolRecord::VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw) +VToolRecord::VToolRecord(const quint32 &id, const Valentina::Tools &typeTool, const QString &nameDraw) :id(id), typeTool(typeTool), nameDraw(nameDraw){} diff --git a/src/xml/vtoolrecord.h b/src/xml/vtoolrecord.h index 0a622f8ae..edbe2aae6 100644 --- a/src/xml/vtoolrecord.h +++ b/src/xml/vtoolrecord.h @@ -39,60 +39,90 @@ class VToolRecord { public: - /** - * @brief VToolRecord default constructor. - */ - VToolRecord(); - /** - * @brief VToolRecord constructor. - * @param id tool id. - * @param typeTool tool type. - * @param nameDraw pattern peace name. - */ - VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw); + /** + * @brief VToolRecord default constructor. + */ + VToolRecord(); + /** + * @brief VToolRecord constructor. + * @param id tool id. + * @param typeTool tool type. + * @param nameDraw pattern peace name. + */ + VToolRecord(const quint32 &id, const Valentina::Tools &typeTool, const QString &nameDraw); /** * @brief getId return tool id. * @return id. */ - inline qint64 getId() const {return id;} + quint32 getId() const; /** * @brief setId set tool id. * @param value id. */ - inline void setId(const qint64 &value) {id = value;} + void setId(const quint32 &value); /** * @brief getTypeTool return tool type. * @return tool type. */ - inline Tool::Tools getTypeTool() const {return typeTool;} + Valentina::Tools getTypeTool() const; /** * @brief setTypeTool set tool type. * @param value tool type. */ - inline void setTypeTool(const Tool::Tools &value) {typeTool = value;} + void setTypeTool(const Valentina::Tools &value); /** * @brief getNameDraw return pattern peace name. * @return pattern peace name. */ - inline QString getNameDraw() const {return nameDraw;} + QString getNameDraw() const; /** * @brief setNameDraw set pattern peace name. * @param value pattern peace name. */ - inline void setNameDraw(const QString &value) {nameDraw = value;} + void setNameDraw(const QString &value); private: /** * @brief id tool id. */ - qint64 id; + quint32 id; /** * @brief typeTool tool type. */ - Tool::Tools typeTool; + Valentina::Tools typeTool; /** * @brief nameDraw pattern peace name. */ QString nameDraw; }; +inline quint32 VToolRecord::getId() const +{ + return id; +} + +inline void VToolRecord::setId(const quint32 &value) +{ + id = value; +} + +inline Valentina::Tools VToolRecord::getTypeTool() const +{ + return typeTool; +} + +inline void VToolRecord::setTypeTool(const Valentina::Tools &value) +{ + typeTool = value; +} + +inline QString VToolRecord::getNameDraw() const +{ + return nameDraw; +} + +inline void VToolRecord::setNameDraw(const QString &value) +{ + nameDraw = value; +} + #endif // VTOOLRECORD_H diff --git a/src/xml/xml.pri b/src/xml/xml.pri index 0214e42b5..fd858fb2b 100644 --- a/src/xml/xml.pri +++ b/src/xml/xml.pri @@ -1,7 +1,13 @@ HEADERS += \ src/xml/vtoolrecord.h \ - src/xml/vdomdocument.h + src/xml/vdomdocument.h \ + src/xml/vpattern.h \ + src/xml/vstandardmeasurements.h \ + src/xml/vindividualmeasurements.h SOURCES += \ src/xml/vtoolrecord.cpp \ - src/xml/vdomdocument.cpp + src/xml/vdomdocument.cpp \ + src/xml/vpattern.cpp \ + src/xml/vstandardmeasurements.cpp \ + src/xml/vindividualmeasurements.cpp