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

View file

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

View file

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