@@ -21,7 +21,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// Helper for lazy initialisation of objects.
|
// Helper for lazy initialization of objects.
|
||||||
// Usage:
|
// Usage:
|
||||||
// Lazy<Foo> my_lazy_object([]() { return new Foo; });
|
// Lazy<Foo> my_lazy_object([]() { return new Foo; });
|
||||||
|
|
||||||
@@ -48,19 +48,18 @@ class Lazy {
|
|||||||
// Returns true if the object is not yet initialised.
|
// Returns true if the object is not yet initialised.
|
||||||
explicit operator bool() const { return ptr_; }
|
explicit operator bool() const { return ptr_; }
|
||||||
|
|
||||||
// Deletes the underlying object and will re-run the initialisation function
|
// Deletes the underlying object and will re-run the initialisation function if the object is requested again.
|
||||||
// if the object is requested again.
|
void reset() { ptr_.reset(); }
|
||||||
void reset() { ptr_.reset(nullptr); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CheckInitialised() const {
|
void CheckInitialised() const {
|
||||||
if (!ptr_) {
|
if (!ptr_) {
|
||||||
ptr_.reset(init_());
|
ptr_.reset(init_(), [](T*obj) { obj->deleteLater(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::function<T*()> init_;
|
const std::function<T*()> init_;
|
||||||
mutable std::unique_ptr<T> ptr_;
|
mutable std::shared_ptr<T> ptr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LAZY_H
|
#endif // LAZY_H
|
||||||
|
|||||||
@@ -1087,6 +1087,9 @@ void MainWindow::SaveSettings() {
|
|||||||
|
|
||||||
void MainWindow::Exit() {
|
void MainWindow::Exit() {
|
||||||
|
|
||||||
|
// Make sure Settings dialog is destroyed first.
|
||||||
|
settings_dialog_.reset();
|
||||||
|
|
||||||
++exit_count_;
|
++exit_count_;
|
||||||
|
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user