Skip to content

Commit 2d252af

Browse files
Merge pull request #35 from Reim-developer/dev
Implement new chaining method for event listener # Change Log: commit 42bb627 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 21 22:12:57 2025 +0700 Removed unused `using` & unused class field member. commit 91e5bfe Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 21 22:12:26 2025 +0700 Removed unused include & defined `CoreClearBuilder` class. commit bf16534 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 21 22:11:55 2025 +0700 Removed unused initiation. Use `ObjectManager` instead commit 538e773 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 21 22:11:35 2025 +0700 Removed unused include & use new chaining methods with `BuilderCore` instead. commit 2a02f76 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 21 22:10:55 2025 +0700 Defined chain methods & removed unused include commit ab3a067 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 21 22:10:01 2025 +0700 Implmenent debugging information & new function `Finally_Setup_Listener` for setup button clicked event
2 parents 00fd1d6 + d8c78d5 commit 2d252af

6 files changed

Lines changed: 131 additions & 72 deletions

File tree

Source/Core/CoreClearCache.cc

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,87 @@
11
#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"
73

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;
108

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+
}
1823

1924
return this;
2025
}
2126

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);
2687
}

Source/Core/Include/CoreClearCache.hpp

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,60 @@
33
#include <QObject>
44
#include <QPushButton>
55
#include <QSettings>
6-
#include <functional>
76
#include "../../GUI/Include/TableView.hpp"
87
#include "../../Utils/Include/Namespace_Macro.hpp"
98
#include "../../Lib_Memory/Include/Memory.hpp"
9+
#include "../../Utils/Include/Meta_Macro.hpp"
10+
#include "../../Listener/Include/ListenerClearCache.hpp"
11+
#include "../../Utils/Include/Meta_Macro.hpp"
1012

1113
using std::function;
1214
using ZClipboard::Lib_Memory::MakePtr;
1315
using ZClipboard::Lib_Memory::PtrUnique;
1416
using ZClipboard::GUI::TableView;
17+
using ZClipboard::Listener::ClearCacheListener;
18+
using std::enable_if_t;
19+
using std::is_invocable_v;
1520

1621
CORE_NAMESPACE
1722

18-
struct ParamImpl {
23+
struct CoreClearBuilderData {
1924
QPushButton *button;
25+
QSettings *settings;
26+
TableView *tableView;
2027
};
2128

22-
class ClearCoreBuilder {
23-
private:
24-
PtrUnique<ParamImpl> Impl;
29+
class CoreClearBuilder {
30+
private:
31+
using Self = CoreClearBuilder;
32+
using ImplData = CoreClearBuilderData;
33+
using Listener = ClearCacheListener;
34+
using Button = QPushButton;
35+
using Settings = QSettings;
36+
37+
private:
38+
PtrUnique<ImplData> Impl;
39+
PtrUnique<Listener> func_Builder;
40+
2541

26-
public:
27-
ClearCoreBuilder *StartBuild(QPushButton* button);
28-
void ThenAddListener(function<void()> func);
42+
private:
43+
inline Button *GetClearButton() noexcept;
44+
inline Settings *GetSettings() noexcept;
45+
inline TableView *GetTableView() noexcept;
46+
47+
public:
48+
Self *StartBuild();
49+
50+
CLASS_BUILD(T, V)
51+
Self *WithAndThen(T ImplData::*member, V&& value) {
52+
Impl.get()->*member = FORWARD(V, value);
53+
54+
return this;
55+
}
56+
57+
Self *WhenDone();
58+
void Finally_Setup_Listener();
59+
2960
};
3061

3162
END_NAMESPACE

Source/GUI/ClearButton.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "Include/ClearButton.hpp"
22
#include "../Utils/Include/Config.hpp"
3-
#include "../Listener/Include/ListenerClearCache.hpp"
43
#include "../Core/Include/CoreClearCache.hpp"
54
#include "Include/TableView.hpp"
65
#include "../Utils/Include/Utils.hpp"
76

87
using ZClipboard::Lib_Memory::PtrUnique;
98
using ZClipboard::GUI::ClearButton;
10-
using ZClipboard::Listener::ListenerCacheImpl;
9+
using ZClipboard::Core::CoreClearBuilderData;
1110
using ZClipboard::AppUtils::Utils;
1211

1312
#if defined (Z_DEBUG)
@@ -25,8 +24,6 @@ void ClearButton::SetupClearButton(ComponentsManager *toolkit, TableView *tableV
2524
}
2625

2726
void ClearButton::SetupEventListener(QPushButton *clearButton, TableView *tableView) {
28-
using Impl = ListenerCacheImpl;
29-
3027
#if defined (Z_DEBUG)
3128

3229
AssertContext{}.RequireNonNullPtr(clearButton);
@@ -35,15 +32,16 @@ void ClearButton::SetupEventListener(QPushButton *clearButton, TableView *tableV
3532

3633
#endif
3734

38-
const auto Function = BuilderFunc
39-
. StartBuild()
40-
-> WithAndThen(&Impl::button, clearButton)
41-
-> WithAndThen(&Impl::settings, settings.get())
42-
-> WithAndThen(&Impl::table, tableView)
43-
-> WhenDone()
44-
-> TryGetListener();
35+
if(!BuilderCore) {
36+
Utils::MakeSmartPtr<CoreClearBuilder>(BuilderCore);
37+
}
4538

39+
using ImplData = CoreClearBuilderData;
4640
BuilderCore
47-
. StartBuild(clearButton)
48-
-> ThenAddListener(Function);
41+
-> StartBuild()
42+
-> WithAndThen(&ImplData::button, clearButton)
43+
-> WithAndThen(&ImplData::settings, settings.get())
44+
-> WithAndThen(&ImplData::tableView, tableView)
45+
-> WhenDone()
46+
-> Finally_Setup_Listener();
4947
}

Source/GUI/Include/ClearButton.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <QSettings>
99
#include "../../Lib_Memory/Include/Memory.hpp"
1010
#include "../../Core/Include/CoreClearCache.hpp"
11-
#include "../../Listener/Include/ListenerClearCache.hpp"
1211
#include "../../Utils/Include/Namespace_Macro.hpp"
1312
#include "../Toolkit/Include/MainWindow_Components.hpp"
1413

@@ -19,16 +18,14 @@
1918

2019
using ZClipboard::GUI::TableView;
2120
using ZClipboard::Lib_Memory::PtrUnique;
22-
using ZClipboard::Core::ClearCoreBuilder;
23-
using ZClipboard::Listener::ClearCacheListener;
21+
using ZClipboard::Core::CoreClearBuilder;
2422
using ZClipboard::GUI::Toolkit::MainWindowComponentsManager;
2523

2624
GUI_NAMESPACE
2725

2826
class ClearButton {
2927
private:
30-
ClearCoreBuilder BuilderCore;
31-
ClearCacheListener BuilderFunc;
28+
PtrUnique<CoreClearBuilder> BuilderCore;
3229

3330
private:
3431
using ComponentsManager = MainWindowComponentsManager;
@@ -46,7 +43,6 @@ GUI_NAMESPACE
4643
private:
4744
void __LOGGING_ALL_OBJECTS__(QPushButton *clearButton) {
4845
LogContext{}.LogDebug(&BuilderCore);
49-
LogContext{}.LogDebug(&BuilderFunc);
5046
LogContext{}.LogDebug(&settings);
5147
LogContext{}.LogDebug(&clearButton);
5248
}

Source/GUI/Include/Window.hpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,20 @@
55
#include <QGridLayout>
66
#include <QWidget>
77
#include <QString>
8-
#include <QSystemTrayIcon>
9-
#include <QStringLiteral>
10-
#include <QMenu>
118
#include "LanguageManager.hpp"
12-
#include "SearchPanel.hpp"
13-
#include "ClearButton.hpp"
14-
#include "DisconnectButton.hpp"
15-
#include "GetConnectButton.hpp"
16-
#include "SettingButton.hpp"
17-
#include "../../Core/Include/CoreNotification.hpp"
189
#include <QSettings>
1910
#include "../../Lib_Memory/Include/Memory.hpp"
2011
#include "../../Utils/Include/Namespace_Macro.hpp"
2112
#include "../Hot_Reload/Include/HotReload_Language.hpp"
2213
#include "../Toolkit/Include/MainWindow_Components.hpp"
2314
#include "../../Lib_Memory/Include/MainWindow_ObjectManager.hpp"
2415
#include "../../Implements/GUI_Components/Include/Manager_MainWindow_Component_Impl.hpp"
25-
#include "TableView.hpp"
2616

2717
#if defined (Z_DEBUG)
2818
#include "../../Utils/Include/Logging.hpp"
2919
using ZClipboard::AppUtils::LogContext;
3020
#endif
3121

32-
using ZClipboard::Core::NotificationCore;
33-
using ZClipboard::GUI::DisconnectButton;
34-
using ZClipboard::GUI::TableView;
35-
using ZClipboard::GUI::ClearButton;
36-
using ZClipboard::GUI::ConnectButton;
37-
using ZClipboard::GUI::SearchArea;
38-
using ZClipboard::GUI::SettingButton;
39-
using ZClipboard::GUI::SystemTray;
4022
using ZClipboard::Lib_Memory::PtrUnique;
4123
using ZClipboard::GUI::Hot_Reload::HotReloadLanguage;
4224
using ZClipboard::GUI::Hot_Reload::HotReloadImpl;
@@ -88,9 +70,6 @@ GUI_NAMESPACE
8870
QWidget *centralWidget;
8971
QGridLayout *windowLayout;
9072

91-
PtrUnique<ConnectButton> getButton;
92-
SettingButton *settingButton;
93-
DisconnectButton *disconnectButton;
9473

9574
#if defined (Z_DEBUG)
9675
private:
@@ -99,9 +78,6 @@ GUI_NAMESPACE
9978
LogContext{}.LogDebug(&objectManager->GetMainWindowObjects()->tableView_Component);
10079
LogContext{}.LogDebug(&objectManager->GetMainWindowObjects()->searchArea_Component);
10180
LogContext{}.LogDebug(&objectManager->GetMainWindowObjects()->clearButton_Component);
102-
LogContext{}.LogDebug(&getButton);
103-
LogContext{}.LogDebug(&settingButton);
104-
LogContext{}.LogDebug(&disconnectButton);
10581
LogContext{}.LogDebug(&objectManager->GetMainWindowObjects()->systemTray_Component);
10682
LogContext{}.LogDebug(&hotReloadLanguage);
10783
}

Source/GUI/Window.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ void AppMainWindow::InitiationObject() {
5757

5858
Utils::MakeSmartPtr<ComponentsManager>(__TOOLKIT__);
5959
Utils::MakeSmartPtr<Object>(objectManager);
60-
Utils::MakeSmartPtr<ConnectButton>(getButton);
6160
Utils::MakeSmartPtr<GUI_Manager>(manager_GUI);
6261

6362
objectManager->InitiationObjects();
64-
settingButton = new SettingButton();
65-
disconnectButton = new DisconnectButton();
6663
}
6764

6865
void AppMainWindow::SetupApplicationGUI() {

0 commit comments

Comments
 (0)