Fix crash while synchronize measurements.

This commit is contained in:
Roman Telezhynskyi 2020-10-30 12:52:39 +02:00
parent 64f70a58cf
commit 1b5705388c
3 changed files with 20 additions and 11 deletions

View File

@ -38,6 +38,7 @@
- Elide a variable description in the formula wizard.
- Fix removing a pin in the Seam Allowance tool dialog.
- Fix label size for case with two pins.
- Fix crash while synchronize measurements.
# Version 0.6.1 October 23, 2018
- [#885] Regression. Broken support for multi size measurements.

View File

@ -136,7 +136,11 @@ MainWindow::MainWindow(QWidget *parent)
isDockGroupsVisible(true),
drawMode(true), recentFileActs(),
separatorAct(nullptr),
leftGoToStage(nullptr), rightGoToStage(nullptr), autoSaveTimer(nullptr), guiEnabled(true),
leftGoToStage(nullptr),
rightGoToStage(nullptr),
autoSaveTimer(nullptr),
measurementsSyncTimer(new QTimer(this)),
guiEnabled(true),
gradationHeights(nullptr),
gradationSizes(nullptr),
gradationHeightsLabel(nullptr),
@ -209,18 +213,22 @@ MainWindow::MainWindow(QWidget *parent)
ui->dockWidgetLayoutPages->setVisible(false);
connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::MeasurementsChanged);
connect(qApp, &QApplication::focusChanged, this, [this](QWidget *old, QWidget *now)
measurementsSyncTimer->setTimerType(Qt::VeryCoarseTimer);
connect(measurementsSyncTimer, &QTimer::timeout, this, [this]()
{
if (old == nullptr && isAncestorOf(now) == true)
{// focus IN
if (isActiveWindow())
{
static bool asking = false;
if (not asking && mChanges && not mChangesAsked)
{
asking = true;
mChangesAsked = true;
const auto answer = QMessageBox::question(this, tr("Measurements"),
tr("Measurements were changed. Do you want to sync measurements now?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
measurementsSyncTimer->stop();
const auto answer =
QMessageBox::question(this, tr("Measurements"),
tr("Measurements were changed. Do you want to sync measurements now?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
if (answer == QMessageBox::Yes)
{
SyncMeasurements();
@ -228,10 +236,6 @@ MainWindow::MainWindow(QWidget *parent)
asking = false;
}
}
// In case we will need it
// else if (isAncestorOf(old) == true && now == nullptr)
// focus OUT
});
#if defined(Q_OS_MAC)
@ -1771,6 +1775,7 @@ void MainWindow::MeasurementsChanged(const QString &path)
{
mChanges = true;
mChangesAsked = false;
measurementsSyncTimer->start(1500);
}
else
{
@ -1780,6 +1785,7 @@ void MainWindow::MeasurementsChanged(const QString &path)
{
mChanges = true;
mChangesAsked = false;
measurementsSyncTimer->start(1500);
break;
}
else
@ -1812,6 +1818,7 @@ void MainWindow::SyncMeasurements()
doc->LiteParseTree(Document::LiteParse);
mChanges = false;
mChangesAsked = true;
measurementsSyncTimer->stop();
UpdateWindowTitle();
ui->actionSyncMeasurements->setEnabled(mChanges);
}

View File

@ -264,6 +264,7 @@ private:
QLabel *leftGoToStage;
QLabel *rightGoToStage;
QTimer *autoSaveTimer;
QTimer *measurementsSyncTimer;
bool guiEnabled;
QPointer<QComboBox> gradationHeights;
QPointer<QComboBox> gradationSizes;