|
1 | 1 | #include "Include/CoreClearCache.hpp" |
2 | | -#include <QTimer> |
3 | | -#include <QFile> |
4 | | -#include <QtSql/QSqlDatabase> |
5 | | -#include <functional> |
6 | | -#include <QObject> |
| 2 | +#include "../Utils/Include/Utils.hpp" |
7 | 3 |
|
8 | | -using std::function; |
9 | | -using ZClipboard::Core::ClearCoreBuilder; |
| 4 | +using ZClipboard::Core::CoreClearBuilder; |
| 5 | +using ZClipboard::Core::CoreClearBuilderData; |
| 6 | +using ZClipboard::Listener::ListenerCacheImpl; |
| 7 | +using ZClipboard::AppUtils::Utils; |
10 | 8 |
|
11 | | -ClearCoreBuilder *ClearCoreBuilder::StartBuild(QPushButton *button) { |
12 | | - Impl = MakePtr<ParamImpl>(); |
13 | | - |
14 | | - this |
15 | | - -> Impl |
16 | | - -> button |
17 | | - = button; |
| 9 | +using Self = CoreClearBuilder; |
| 10 | +using ImplData = CoreClearBuilderData; |
| 11 | +using Button = QPushButton; |
| 12 | +using Settings = QSettings; |
| 13 | + |
| 14 | +#if defined(Z_DEBUG) |
| 15 | + #include "../Utils/Include/AssertNullPtr.hpp" |
| 16 | + #include "../Utils/Include/Logging.hpp" |
| 17 | +#endif |
| 18 | + |
| 19 | +Self *Self::StartBuild() { |
| 20 | + if(!Impl) { |
| 21 | + Impl = MakePtr<CoreClearBuilderData>(); |
| 22 | + } |
18 | 23 |
|
19 | 24 | return this; |
20 | 25 | } |
21 | 26 |
|
22 | | -void ClearCoreBuilder::ThenAddListener(function<void()> func) { |
23 | | - auto button = Impl->button; |
24 | | - |
25 | | - QObject::connect(button, &QPushButton::clicked, func); |
| 27 | +Self *Self::WhenDone() { |
| 28 | + if(!func_Builder) { |
| 29 | + Utils::MakeSmartPtr<Listener>(func_Builder); |
| 30 | + } |
| 31 | + |
| 32 | + return this; |
| 33 | +} |
| 34 | + |
| 35 | +inline Button *Self::GetClearButton() noexcept { |
| 36 | + return this |
| 37 | + -> Impl |
| 38 | + -> button; |
| 39 | +} |
| 40 | + |
| 41 | +inline Settings *Self::GetSettings() noexcept { |
| 42 | + return this |
| 43 | + -> Impl |
| 44 | + -> settings; |
| 45 | +} |
| 46 | + |
| 47 | +inline TableView *Self::GetTableView() noexcept { |
| 48 | + return this |
| 49 | + -> Impl |
| 50 | + -> tableView; |
| 51 | +} |
| 52 | + |
| 53 | +void Self::Finally_Setup_Listener() { |
| 54 | + auto clearButton = this->GetClearButton(); |
| 55 | + auto settings = this->GetSettings(); |
| 56 | + auto tableView = this->GetTableView(); |
| 57 | + |
| 58 | + using ImplData = ListenerCacheImpl; |
| 59 | + const auto Function = func_Builder |
| 60 | + -> StartBuild() |
| 61 | + -> WithAndThen(&ImplData::button, clearButton) |
| 62 | + -> WithAndThen(&ImplData::settings, settings) |
| 63 | + -> WithAndThen(&ImplData::table, tableView) |
| 64 | + -> WhenDone() |
| 65 | + -> TryGetListener(); |
| 66 | + |
| 67 | + |
| 68 | + #if defined(Z_DEBUG) |
| 69 | + using Assert = AssertContext; |
| 70 | + using Debug = LogContext; |
| 71 | + |
| 72 | + Assert{}.RequireNonNullPtr(Impl.get()); |
| 73 | + Assert{}.RequireNonNullPtr(Impl->button); |
| 74 | + Assert{}.RequireNonNullPtr(func_Builder.get()); |
| 75 | + Assert{}.RequireNonNullPtr(clearButton); |
| 76 | + Assert{}.RequireNonNullPtr(settings); |
| 77 | + Assert{}.RequireNonNullPtr(tableView); |
| 78 | + |
| 79 | + Debug{}.LogDebug(&Impl); |
| 80 | + Debug{}.LogDebug(&Impl->button); |
| 81 | + Debug{}.LogDebug(&Impl->tableView); |
| 82 | + Debug{}.LogDebug(&Impl->settings); |
| 83 | + Debug{}.LogDebug(&func_Builder); |
| 84 | + #endif |
| 85 | + |
| 86 | + QObject::connect(clearButton, &QPushButton::clicked, Function); |
26 | 87 | } |
0 commit comments