FOSSredder 0.5.0
Loading...
Searching...
No Matches
CloseWorkflow.cpp
Go to the documentation of this file.
1
5
7
8#include <QCloseEvent>
9
10namespace ui::window {
11
12bool CloseWorkflow::allowImmediateClose(QCloseEvent* event) {
13 if (!allowImmediateClose_)
14 return false;
15 allowImmediateClose_ = false;
16 if (event)
17 event->accept();
18 return true;
19}
20
21void CloseWorkflow::requestClose(QCloseEvent* event,
22 const std::function<void()>& requestSave) {
23 if (!event)
24 return;
25 if (pendingCloseAfterSave_) {
26 event->ignore();
27 return;
28 }
29
30 pendingCloseAfterSave_ = true;
31 event->ignore();
32 try {
33 if (requestSave)
34 requestSave();
35 } catch (...) {
36 pendingCloseAfterSave_ = false;
37 allowImmediateClose_ = true;
38 }
39}
40
42 const QString& operation, const QString& saveOperation,
43 const std::function<void()>& closeWindow) {
44 if (!pendingCloseAfterSave_ || operation != saveOperation)
45 return false;
46
47 pendingCloseAfterSave_ = false;
48 allowImmediateClose_ = true;
49 if (closeWindow)
50 closeWindow();
51 return true;
52}
53
54bool CloseWorkflow::handleStorageOperationFailed(const QString& operation,
55 const QString& saveOperation) {
56 if (!pendingCloseAfterSave_ || operation != saveOperation)
57 return false;
58
59 pendingCloseAfterSave_ = false;
60 allowImmediateClose_ = true;
61 return true;
62}
63
64} // namespace ui::window
Declarations for the UI CloseWorkflow component.
void requestClose(QCloseEvent *event, const std::function< void()> &requestSave)
Defers closing and invokes the supplied save request.
bool allowImmediateClose(QCloseEvent *event)
Accepts a close event when a deferred close is already authorized.
bool handleStorageOperationSucceeded(const QString &operation, const QString &saveOperation, const std::function< void()> &closeWindow)
Completes a deferred close after the matching save succeeded.
bool handleStorageOperationFailed(const QString &operation, const QString &saveOperation)
Cancels a deferred close after the matching save failed.