Cancel watched jobs before application close to prevent crashes.

This commit is contained in:
Roman Telezhynskyi 2024-05-06 18:56:30 +03:00
parent a21a3eac85
commit bf2b110b69
6 changed files with 78 additions and 14 deletions

View File

@ -548,6 +548,12 @@ VPSheet::VPSheet(const VPLayoutPtr &layout, QObject *parent)
SetSheetMargins(settings->GetLayoutSheetMargins()); SetSheetMargins(settings->GetLayoutSheetMargins());
SetSheetSize(QSizeF(settings->GetLayoutSheetPaperWidth(), settings->GetLayoutSheetPaperHeight())); SetSheetSize(QSizeF(settings->GetLayoutSheetPaperWidth(), settings->GetLayoutSheetPaperHeight()));
connect(qApp, &QCoreApplication::aboutToQuit, m_validityWatcher,
[this]()
{
m_validityWatcher->cancel();
m_validityWatcher->waitForFinished();
});
connect(m_validityWatcher, &QFutureWatcher<QHash<QString, VPiecePositionValidity>>::finished, this, connect(m_validityWatcher, &QFutureWatcher<QHash<QString, VPiecePositionValidity>>::finished, this,
&VPSheet::UpdatePiecesValidity); &VPSheet::UpdatePiecesValidity);
} }
@ -844,6 +850,11 @@ void VPSheet::CheckPiecesPositionValidity() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSheet::UpdatePiecesValidity() void VPSheet::UpdatePiecesValidity()
{ {
if (m_validityWatcher->isCanceled())
{
return;
}
QHash<QString, VPiecePositionValidity> const newValidations = m_validityWatcher->future().result(); QHash<QString, VPiecePositionValidity> const newValidations = m_validityWatcher->future().result();
QList<VPPiecePtr> const pieces = GetPieces(); QList<VPPiecePtr> const pieces = GetPieces();

View File

@ -187,7 +187,7 @@
<node type="NodeSpline" reverse="1" nodeType="Contour" idObject="122" mx="0" my="0"/> <node type="NodeSpline" reverse="1" nodeType="Contour" idObject="122" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="123" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="123" mx="0" my="0"/>
</detail> </detail>
<detail closed="0" id="303" name="Деталь" supplement="1" width="7" mx="10.0402" my="-26.0133"> <detail closed="0" id="303" name="Деталь 1" supplement="1" width="7" mx="10.0402" my="-26.0133">
<node type="NodePoint" nodeType="Contour" idObject="296" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="296" mx="0" my="0"/>
<node type="NodeSplinePath" nodeType="Contour" idObject="297" mx="0" my="0"/> <node type="NodeSplinePath" nodeType="Contour" idObject="297" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="298" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="298" mx="0" my="0"/>
@ -196,9 +196,9 @@
<node type="NodePoint" nodeType="Contour" idObject="301" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="301" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="302" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="302" mx="0" my="0"/>
</detail> </detail>
<detail closed="0" id="312" name="Деталь" forbidFlipping="1" supplement="1" width="7" mx="0" my="0"> <detail closed="0" id="312" name="Деталь 2" forbidFlipping="1" supplement="1" width="7" mx="0" my="0">
<data rotation="0" letter="" fontSize="12" visible="true" mx="0" width="0" my="0" height="0"/> <data rotation="0" letter="" fontSize="12" visible="true" mx="0" width="1" my="0" height="1"/>
<patternInfo rotation="0" fontSize="12" visible="true" mx="0" width="0" my="0" height="0"/> <patternInfo rotation="0" fontSize="12" visible="true" mx="0" width="1" my="0" height="1"/>
<grainline arrows="0" rotation="" visible="false" mx="0" my="0" length=""/> <grainline arrows="0" rotation="" visible="false" mx="0" my="0" length=""/>
<node type="NodePoint" nodeType="Contour" idObject="304" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="304" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="305" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="305" mx="0" my="0"/>
@ -209,9 +209,9 @@
<node type="NodePoint" nodeType="Contour" idObject="310" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="310" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="311" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="311" mx="0" my="0"/>
</detail> </detail>
<detail closed="1" id="320" name="Деталь" forbidFlipping="1" supplement="1" width="7" mx="-41.9497" my="-160.593"> <detail closed="1" id="320" name="Деталь 3" forbidFlipping="1" supplement="1" width="7" mx="-41.9497" my="-160.593">
<data rotation="0" letter="" fontSize="12" visible="true" mx="0" width="0" my="0" height="0"/> <data rotation="0" letter="" fontSize="12" visible="true" mx="0" width="1" my="0" height="1"/>
<patternInfo rotation="0" fontSize="12" visible="true" mx="0" width="0" my="0" height="0"/> <patternInfo rotation="0" fontSize="12" visible="true" mx="0" width="1" my="0" height="1"/>
<grainline arrows="0" rotation="" visible="false" mx="0" my="0" length=""/> <grainline arrows="0" rotation="" visible="false" mx="0" my="0" length=""/>
<node type="NodePoint" nodeType="Contour" idObject="313" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="313" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="314" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="314" mx="0" my="0"/>
@ -221,7 +221,7 @@
<node type="NodePoint" nodeType="Contour" idObject="318" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="318" mx="0" my="0"/>
<node type="NodeSplinePath" reverse="1" nodeType="Contour" idObject="319" mx="0" my="0"/> <node type="NodeSplinePath" reverse="1" nodeType="Contour" idObject="319" mx="0" my="0"/>
</detail> </detail>
<detail closed="1" id="329" name="Деталь" supplement="1" width="7" mx="52.483" my="-2.73825"> <detail closed="1" id="329" name="Деталь 4" supplement="1" width="7" mx="52.483" my="-2.73825">
<node type="NodePoint" nodeType="Contour" idObject="321" mx="3" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="321" mx="3" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="322" mx="3" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="322" mx="3" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="323" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="323" mx="0" my="0"/>
@ -304,7 +304,7 @@
<point type="modeling" inUse="true" id="338" idObject="130" mx="1.32292" my="2.64583"/> <point type="modeling" inUse="true" id="338" idObject="130" mx="1.32292" my="2.64583"/>
</modeling> </modeling>
<details> <details>
<detail closed="1" id="339" name="Деталь" supplement="1" width="7" mx="-151.4" my="6.83743"> <detail closed="1" id="339" name="Деталь 5" supplement="1" width="7" mx="-151.4" my="6.83743">
<node type="NodePoint" nodeType="Contour" idObject="330" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="330" mx="0" my="0"/>
<node type="NodeSpline" reverse="0" nodeType="Contour" idObject="331" mx="0" my="0"/> <node type="NodeSpline" reverse="0" nodeType="Contour" idObject="331" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="332" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="332" mx="0" my="0"/>
@ -378,9 +378,9 @@
<spline type="modelingPath" inUse="true" id="284" idObject="263"/> <spline type="modelingPath" inUse="true" id="284" idObject="263"/>
</modeling> </modeling>
<details> <details>
<detail closed="1" id="285" name="Деталь" forbidFlipping="1" supplement="1" width="7" mx="-49.2726" my="-53.1166"> <detail closed="1" id="285" name="Деталь 6" forbidFlipping="1" supplement="1" width="7" mx="-49.2726" my="-53.1166">
<data rotation="0" letter="" fontSize="12" visible="true" mx="0" width="0" my="0" height="0"/> <data rotation="0" letter="" fontSize="12" visible="true" mx="0" width="1" my="0" height="1"/>
<patternInfo rotation="0" fontSize="12" visible="true" mx="0" width="0" my="0" height="0"/> <patternInfo rotation="0" fontSize="12" visible="true" mx="0" width="1" my="0" height="1"/>
<grainline arrows="0" rotation="90" visible="false" mx="0" my="0" length="0"/> <grainline arrows="0" rotation="90" visible="false" mx="0" my="0" length="0"/>
<node type="NodePoint" nodeType="Contour" idObject="276" mx="0" my="0"/> <node type="NodePoint" nodeType="Contour" idObject="276" mx="0" my="0"/>
<node type="NodeSpline" reverse="0" nodeType="Contour" idObject="277" mx="0" my="0"/> <node type="NodeSpline" reverse="0" nodeType="Contour" idObject="277" mx="0" my="0"/>

View File

@ -883,10 +883,24 @@ void MApplication::RepopulateMeasurementsDatabase(const QString &path)
Q_UNUSED(path) Q_UNUSED(path)
if (m_knownMeasurementsDatabase != nullptr) if (m_knownMeasurementsDatabase != nullptr)
{ {
connect(qApp, &QCoreApplication::aboutToQuit, m_knownMeasurementsRepopulateWatcher,
[this]()
{
m_knownMeasurementsRepopulateWatcher->cancel();
m_knownMeasurementsRepopulateWatcher->waitForFinished();
});
QObject::connect(m_knownMeasurementsRepopulateWatcher, &QFutureWatcher<void>::finished, this, QObject::connect(m_knownMeasurementsRepopulateWatcher, &QFutureWatcher<void>::finished, this,
&MApplication::SyncKnownMeasurements); &MApplication::SyncKnownMeasurements);
m_knownMeasurementsRepopulateWatcher->setFuture( m_knownMeasurementsRepopulateWatcher->setFuture(QtConcurrent::run(
QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); })); [this]()
{
if (m_knownMeasurementsRepopulateWatcher->isCanceled())
{
return;
}
m_knownMeasurementsDatabase->PopulateMeasurementsDatabase();
}));
} }
} }

View File

@ -285,6 +285,12 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool
{ {
QEventLoop wait; QEventLoop wait;
QFutureWatcher<void> fw; QFutureWatcher<void> fw;
connect(qApp, &QCoreApplication::aboutToQuit, &fw,
[&fw]()
{
fw.cancel();
fw.waitForFinished();
});
QObject::connect(&fw, &QFutureWatcher<void>::finished, &wait, &QEventLoop::quit); QObject::connect(&fw, &QFutureWatcher<void>::finished, &wait, &QEventLoop::quit);
fw.setFuture( fw.setFuture(
QtConcurrent::run([&lGenerator, timer, nestingState]() QtConcurrent::run([&lGenerator, timer, nestingState]()

View File

@ -276,6 +276,12 @@ VDomDocument::VDomDocument(QObject *parent)
m_elementIdCache(), m_elementIdCache(),
m_watcher(new QFutureWatcher<QHash<quint32, QDomElement>>(this)) m_watcher(new QFutureWatcher<QHash<quint32, QDomElement>>(this))
{ {
connect(qApp, &QCoreApplication::aboutToQuit, m_watcher,
[this]()
{
m_watcher->cancel();
m_watcher->waitForFinished();
});
connect(m_watcher, &QFutureWatcher<QHash<quint32, QDomElement>>::finished, this, &VDomDocument::CacheRefreshed); connect(m_watcher, &QFutureWatcher<QHash<quint32, QDomElement>>::finished, this, &VDomDocument::CacheRefreshed);
} }
@ -724,6 +730,11 @@ auto VDomDocument::Compare(const QDomElement &element1, const QDomElement &eleme
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VDomDocument::CacheRefreshed() void VDomDocument::CacheRefreshed()
{ {
if (m_watcher->isCanceled())
{
return;
}
m_elementIdCache = m_watcher->future().result(); m_elementIdCache = m_watcher->future().result();
} }

View File

@ -1729,9 +1729,20 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
m_foldLineMark->setBrush(Qt::SolidPattern); m_foldLineMark->setBrush(Qt::SolidPattern);
connect(qApp, &QCoreApplication::aboutToQuit, m_patternUpdateInfoWatcher,
[this]()
{
m_patternUpdateInfoWatcher->cancel();
m_patternUpdateInfoWatcher->waitForFinished();
});
connect(m_patternUpdateInfoWatcher, &QFutureWatcher<void>::finished, this, connect(m_patternUpdateInfoWatcher, &QFutureWatcher<void>::finished, this,
[this]() [this]()
{ {
if (m_patternUpdateInfoWatcher->isCanceled())
{
return;
}
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
m_patternInfo->show(); m_patternInfo->show();
UpdateLabelItem(m_patternInfo, m_patternLabelPos, m_patternLabelAngle); UpdateLabelItem(m_patternInfo, m_patternLabelPos, m_patternLabelAngle);
@ -1742,9 +1753,20 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
UpdatePatternInfo(); UpdatePatternInfo();
} }
}); });
connect(qApp, &QCoreApplication::aboutToQuit, m_pieceUpdateInfoWatcher,
[this]()
{
m_pieceUpdateInfoWatcher->cancel();
m_pieceUpdateInfoWatcher->waitForFinished();
});
connect(m_pieceUpdateInfoWatcher, &QFutureWatcher<void>::finished, this, connect(m_pieceUpdateInfoWatcher, &QFutureWatcher<void>::finished, this,
[this]() [this]()
{ {
if (m_pieceUpdateInfoWatcher->isCanceled())
{
return;
}
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
m_dataLabel->show(); m_dataLabel->show();
UpdateLabelItem(m_dataLabel, m_pieceLabelPos, m_pieceLabelAngle); UpdateLabelItem(m_dataLabel, m_pieceLabelPos, m_pieceLabelAngle);