From c536c406280e111e16e469914032a34f73015fcc Mon Sep 17 00:00:00 2001
From: Roman Telezhynskyi <kroluku@gmail.com>
Date: Mon, 1 Jul 2019 12:47:06 +0300
Subject: [PATCH] Refactor AboutToQuit.

--HG--
branch : develop
---
 src/app/tape/mapplication.cpp           | 9 +++++++++
 src/app/tape/mapplication.h             | 3 +++
 src/app/valentina/core/vapplication.cpp | 9 +++++++++
 src/app/valentina/core/vapplication.h   | 3 +++
 src/libs/vmisc/testvapplication.h       | 6 ++++++
 src/libs/vmisc/vabstractapplication.cpp | 8 +-------
 src/libs/vmisc/vabstractapplication.h   | 3 +++
 7 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp
index ca3e5f9aa..9f11396e3 100644
--- a/src/app/tape/mapplication.cpp
+++ b/src/app/tape/mapplication.cpp
@@ -486,6 +486,15 @@ bool MApplication::event(QEvent *e)
     return VAbstractApplication::event(e);
 }
 
+//---------------------------------------------------------------------------------------------------------------------
+void MApplication::AboutToQuit()
+{
+    // If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
+    // instance. Solution is to call sync() before quit.
+    // Connect this slot with VApplication::aboutToQuit.
+    Settings()->sync();
+}
+
 //---------------------------------------------------------------------------------------------------------------------
 void MApplication::OpenSettings()
 {
diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h
index 1bcf38702..9afb435f8 100644
--- a/src/app/tape/mapplication.h
+++ b/src/app/tape/mapplication.h
@@ -85,6 +85,9 @@ protected:
     virtual void InitTrVars() override;
     virtual bool event(QEvent *e) override;
 
+protected slots:
+    virtual void AboutToQuit() override;
+
 private slots:
     void NewLocalSocketConnection();
 
diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp
index 803953893..073a316cb 100644
--- a/src/app/valentina/core/vapplication.cpp
+++ b/src/app/valentina/core/vapplication.cpp
@@ -709,6 +709,15 @@ bool VApplication::event(QEvent *e)
     return VAbstractApplication::event(e);
 }
 
+//---------------------------------------------------------------------------------------------------------------------
+void VApplication::AboutToQuit()
+{
+    // If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
+    // instance. Solution is to call sync() before quit.
+    // Connect this slot with VApplication::aboutToQuit.
+    Settings()->sync();
+}
+
 //---------------------------------------------------------------------------------------------------------------------
 /**
  * @brief OpenSettings get acsses to application settings.
diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h
index b7bd61c23..423c2dc98 100644
--- a/src/app/valentina/core/vapplication.h
+++ b/src/app/valentina/core/vapplication.h
@@ -82,6 +82,9 @@ protected:
     virtual void       InitTrVars() override;
     virtual bool	   event(QEvent *e) override;
 
+protected slots:
+    virtual void AboutToQuit() override;
+
 private:
     Q_DISABLE_COPY(VApplication)
     VTranslateVars     *trVars;
diff --git a/src/libs/vmisc/testvapplication.h b/src/libs/vmisc/testvapplication.h
index 59f6455a2..b8b81c89e 100644
--- a/src/libs/vmisc/testvapplication.h
+++ b/src/libs/vmisc/testvapplication.h
@@ -41,6 +41,7 @@ class VTestSettings;
 
 class TestVApplication : public VAbstractApplication
 {
+    Q_OBJECT
 public:
     TestVApplication(int &argc, char ** argv)
         : VAbstractApplication(argc, argv),
@@ -77,6 +78,11 @@ public:
     {
         m_trVars = trVars;
     }
+
+protected slots:
+    virtual void AboutToQuit() override
+    {}
+
 private:
     Q_DISABLE_COPY(TestVApplication)
     VTranslateVars *m_trVars;
diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp
index 26d68b1c1..7a54caed2 100644
--- a/src/libs/vmisc/vabstractapplication.cpp
+++ b/src/libs/vmisc/vabstractapplication.cpp
@@ -100,13 +100,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
     setAttribute(Qt::AA_UseHighDpiPixmaps);
 #endif
 
-    connect(this, &QApplication::aboutToQuit, this, [this]()
-    {
-        // If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
-        // instance. Solution is to call sync() before quit.
-        // Connect this slot with VApplication::aboutToQuit.
-        Settings()->sync();
-    });
+    connect(this, &QApplication::aboutToQuit, this, &VAbstractApplication::AboutToQuit);
 }
 
 //---------------------------------------------------------------------------------------------------------------------
diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h
index eb39ed56b..4de9f0990 100644
--- a/src/libs/vmisc/vabstractapplication.h
+++ b/src/libs/vmisc/vabstractapplication.h
@@ -146,6 +146,9 @@ protected:
 
     virtual void InitTrVars()=0;
 
+protected slots:
+    virtual void AboutToQuit()=0;
+
 private:
     Q_DISABLE_COPY(VAbstractApplication)
     Unit               _patternUnit;