3 * @brief Base class for all the events
6 * Copyright (c) 2011-2019 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __COMMON_EVENT_H
21 #define __COMMON_EVENT_H
23 #include "libcommon.h"
27 #include <QSharedData>
28 #include <QExplicitlySharedDataPointer>
34 * Event class for all the eVaf events
35 * @code@include <Common/Event>@endcode
37 * The Event class is an event container for all the eVaf events.
39 class COMMON_EXPORT Event
: public QEvent
43 /// Event type for eVaf events
44 static QEvent::Type
const eVafEvent
;
47 * Creates the event object
48 * @param eventId The ID of the event
49 * @param intValue A 32-bit integer value
50 * @param dataObj Shared data object attached to the event
52 * Creates the event object with the given event ID value and attaches optional data to the event.
54 * The optional 32-bit integer value can be used to store information that fits into the value and
55 * is not reference-counted.
57 * The optional reference-counted shared data object is owned by the event and the reference counter
58 * is decreased by 1 when the event object is destroyed. If nobody else claimed the ownership, then
59 * the shared data object is destroyed too.
61 Event(uint eventId
, quint32 intValue
= 0, QSharedData
* dataObj
= nullptr)
69 * Returns the event ID value
71 inline uint
id() const { return mId
; }
74 * Returns the 32-bit integer value
76 inline quint32
value() const { return mValue
; }
79 * Returns the shared data object attached to the event
81 * The shared data object is valid only while in the event handler. Once the event loop
82 * is finished, the event and shared data attached to it are destroyed. To keep the shared
83 * data object, use QExplicitlySharedDataPointer<> to claim ownership.
85 inline QSharedData
* data() const { return mData
!= nullptr ? mData
.data() : nullptr; }
93 /// A 32-bit integer value associated to the event
96 /// Shared data object attached to the event
97 QExplicitlySharedDataPointer
<QSharedData
> mData
;
101 } // namespace eVaf::Common