/** * @file Common/event.h * @brief Base class for all the events * @author Enar Vaikene * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #ifndef __COMMON_EVENT_H #define __COMMON_EVENT_H #include "libcommon.h" #include #include #include #include namespace eVaf { namespace Common { /** * Event class for all the eVaf events * @code@include @endcode * * The Event class is an event container for all the eVaf events. */ class COMMON_EXPORT Event : public QEvent { public: /// Event type for eVaf events static QEvent::Type const eVafEvent; /** * Creates the event object * @param eventId The ID of the event * @param intValue A 32-bit integer value * @param dataObj Shared data object attached to the event * * Creates the event object with the given event ID value and attaches optional data to the event. * * The optional 32-bit integer value can be used to store information that fits into the value and * is not reference-counted. * * The optional reference-counted shared data object is owned by the event and the reference counter * is decreased by 1 when the event object is destroyed. If nobody else claimed the ownership, then * the shared data object is destroyed too. */ Event(uint eventId, quint32 intValue = 0, QSharedData * dataObj = nullptr) : QEvent(eVafEvent) , mId(eventId) , mValue(intValue) , mData(dataObj) {} virtual ~Event(); /** * Returns the event ID value */ inline uint id() const { return mId; } /** * Returns the 32-bit integer value */ inline quint32 value() const { return mValue; } /** * Returns the shared data object attached to the event * * The shared data object is valid only while in the event handler. Once the event loop * is finished, the event and shared data attached to it are destroyed. To keep the shared * data object, use QExplicitlySharedDataPointer<> to claim ownership. */ inline QSharedData * data() const { return mData != nullptr ? mData.data() : nullptr; } private: /// Event ID value uint mId; /// A 32-bit integer value associated to the event quint32 mValue; /// Shared data object attached to the event QExplicitlySharedDataPointer mData; }; } // namespace eVaf::Common } // namespace eVaf #endif // event.h