Skip to content

Commit

Permalink
Change type of PostedEvent::target to EventReceiver*
Browse files Browse the repository at this point in the history
Change type of PostedEvent::target from Object* to EventReceiver*.
Events shall operate on EventReceiver instances.
Objects shall introduce management of parents and children only.
Thus have PostedEvents target EventReceiver instances.

Change-Id: I1afc731f38fc38db9dcfb2dbec45bebe9adb9459
Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/135488
Tested-by: Continuous Integration <[email protected]>
Reviewed-by: Miłosz Kosobucki <[email protected]>
Reviewed-by: Paul Lemire <[email protected]>
  • Loading branch information
marcothaller committed Dec 20, 2023
1 parent 8cdc640 commit f36a3ef
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/KDFoundation/core_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ CoreApplication::~CoreApplication()
ms_application = nullptr;
}

void CoreApplication::postEvent(Object *target, std::unique_ptr<Event> &&event)
void CoreApplication::postEvent(EventReceiver *target, std::unique_ptr<Event> &&event)
{
assert(target != nullptr);
assert(event->type() != Event::Type::Invalid);
m_eventQueue.push(target, std::forward<std::unique_ptr<Event>>(event));
m_platformEventLoop->wakeUp();
}

void CoreApplication::sendEvent(Object *target, Event *event)
void CoreApplication::sendEvent(EventReceiver *target, Event *event)
{
SPDLOG_LOGGER_TRACE(m_logger, "{}()", __FUNCTION__);
m_postman->deliverEvent(target, event);
Expand Down Expand Up @@ -142,5 +142,5 @@ void CoreApplication::event(EventReceiver *target, Event *event)
event->setAccepted(true);
}

Object::event(target, event);
EventReceiver::event(target, event);
}
4 changes: 2 additions & 2 deletions src/KDFoundation/core_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class KDFOUNDATION_API CoreApplication : public Object

Postman *postman() { return m_postman.get(); }

void postEvent(Object *target, std::unique_ptr<Event> &&event);
void postEvent(EventReceiver *target, std::unique_ptr<Event> &&event);
EventQueue::size_type eventQueueSize() const { return m_eventQueue.size(); }

void sendEvent(Object *target, Event *event);
void sendEvent(EventReceiver *target, Event *event);

void processEvents(int timeout = 0);

Expand Down
7 changes: 4 additions & 3 deletions src/KDFoundation/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once

#include "KDFoundation/event_receiver.h"
#include <KDFoundation/kdfoundation_global.h>

#include <cstdint>
Expand Down Expand Up @@ -81,18 +82,18 @@ class Object;
class KDFOUNDATION_API PostedEvent : public Event
{
public:
PostedEvent(Object *target, std::unique_ptr<Event> &&wrappedEvent)
PostedEvent(EventReceiver *target, std::unique_ptr<Event> &&wrappedEvent)
: Event(Event::Type::PostedEvent)
, m_target{ target }
, m_wrappedEvent{ std::move(wrappedEvent) }
{
}

Object *target() const { return m_target; }
EventReceiver *target() const { return m_target; }
Event *wrappedEvent() const { return m_wrappedEvent.get(); }

private:
Object *m_target;
EventReceiver *m_target;
std::unique_ptr<Event> m_wrappedEvent;
};

Expand Down
2 changes: 1 addition & 1 deletion src/KDFoundation/event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KDFOUNDATION_API EventQueue
m_events.push(std::move(event));
}

void push(Object *target, std::unique_ptr<Event> &&event)
void push(EventReceiver *target, std::unique_ptr<Event> &&event)
{
auto ev = std::make_unique<PostedEvent>(target, std::forward<std::unique_ptr<Event>>(event));
push(std::move(ev));
Expand Down
2 changes: 1 addition & 1 deletion src/KDFoundation/postman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using namespace KDFoundation;

void Postman::deliverEvent(Object *target, Event *event)
void Postman::deliverEvent(EventReceiver *target, Event *event)
{
// Give the registered event filters first chance to handle the event
for (const auto &filter : m_filters) {
Expand Down
3 changes: 2 additions & 1 deletion src/KDFoundation/postman.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once

#include "KDFoundation/event_receiver.h"
#include <KDFoundation/kdfoundation_global.h>

#include <vector>
Expand All @@ -23,7 +24,7 @@ class Object;
class KDFOUNDATION_API Postman
{
public:
void deliverEvent(Object *target, Event *event);
void deliverEvent(EventReceiver *target, Event *event);

void addFilter(Object *filter);
void removeFilter(Object *filter);
Expand Down

0 comments on commit f36a3ef

Please sign in to comment.