Plasma Engine  2.0
Loading...
Searching...
No Matches
GuiFoundationDLL.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Math/Color8UNorm.h>
5#include <Foundation/Strings/String.h>
6#include <Foundation/Types/Uuid.h>
7#include <QColor>
8#include <QDataStream>
9#include <QMetaType>
10#include <ToolsFoundation/ToolsFoundationDLL.h>
11
12// Configure the DLL Import/Export Define
13#if PL_ENABLED(PL_COMPILE_ENGINE_AS_DLL)
14# ifdef BUILDSYSTEM_BUILDING_GUIFOUNDATION_LIB
15# define PL_GUIFOUNDATION_DLL PL_DECL_EXPORT
16# else
17# define PL_GUIFOUNDATION_DLL PL_DECL_IMPORT
18# endif
19#else
20# define PL_GUIFOUNDATION_DLL
21#endif
22
23class QWidget;
24class QObject;
25
26
27Q_DECLARE_METATYPE(plUuid);
28
30class PL_GUIFOUNDATION_DLL plQtScopedUpdatesDisabled
31{
32public:
33 plQtScopedUpdatesDisabled(QWidget* pWidget1, QWidget* pWidget2 = nullptr, QWidget* pWidget3 = nullptr, QWidget* pWidget4 = nullptr,
34 QWidget* pWidget5 = nullptr, QWidget* pWidget6 = nullptr);
36
37private:
38 QWidget* m_pWidgets[6];
39};
40
41
43class PL_GUIFOUNDATION_DLL plQtScopedBlockSignals
44{
45public:
46 plQtScopedBlockSignals(QObject* pObject1, QObject* pObject2 = nullptr, QObject* pObject3 = nullptr, QObject* pObject4 = nullptr,
47 QObject* pObject5 = nullptr, QObject* pObject6 = nullptr);
49
50private:
51 QObject* m_pObjects[6];
52};
53
54PL_ALWAYS_INLINE QColor plToQtColor(const plColorGammaUB& c)
55{
56 return QColor(c.r, c.g, c.b, c.a);
57}
58
59PL_ALWAYS_INLINE plColorGammaUB qtToPlColor(const QColor& c)
60{
61 return plColorGammaUB(c.red(), c.green(), c.blue(), c.alpha());
62}
63
64PL_ALWAYS_INLINE plString qtToPlString(const QString& sString)
65{
66 QByteArray data = sString.toUtf8();
67 return plString(plStringView(data.data(), static_cast<plUInt32>(data.size())));
68}
69
70PL_ALWAYS_INLINE QString plMakeQString(plStringView sString)
71{
72 return QString::fromUtf8(sString.GetStartPointer(), sString.GetElementCount());
73}
74
75template <typename T>
76void operator>>(QDataStream& inout_stream, T*& rhs)
77{
78 void* p = nullptr;
79 uint len = sizeof(void*);
80 inout_stream.readRawData((char*)&p, len);
81 rhs = (T*)p;
82}
83
84
85template <typename T>
86void operator<<(QDataStream& inout_stream, T* rhs)
87{
88 inout_stream.writeRawData((const char*)&rhs, sizeof(void*));
89}
90
91template <typename T>
92void operator>>(QDataStream& inout_stream, plDynamicArray<T>& rhs)
93{
94 plUInt32 uiIndices = 0;
95 inout_stream >> uiIndices;
96 rhs.Clear();
97 rhs.Reserve(uiIndices);
98
99 for (int i = 0; i < uiIndices; ++i)
100 {
101 T obj = {};
102 inout_stream >> obj;
103 rhs.PushBack(obj);
104 }
105}
106
107template <typename T>
108void operator<<(QDataStream& inout_stream, plDynamicArray<T>& rhs)
109{
110 plUInt32 iIndices = rhs.GetCount();
111 inout_stream << iIndices;
112
113 for (plUInt32 i = 0; i < iIndices; ++i)
114 {
115 inout_stream << rhs[i];
116 }
117}
void PushBack(const T &value)
Pushes value at the end of the array.
Definition ArrayBase_inl.h:333
void Clear()
Clears the array.
Definition ArrayBase_inl.h:184
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
void Reserve(plUInt32 uiCapacity)
Expands the array so it can at least store the given capacity.
Definition DynamicArray_inl.h:179
Definition DynamicArray.h:81
Calls blockSignals(true) on all given QObjects, and the reverse in the destructor....
Definition GuiFoundationDLL.h:44
Calls setUpdatesEnabled(false) on all given QObjects, and the reverse in the destructor....
Definition GuiFoundationDLL.h:31
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
plUInt32 GetElementCount() const
Returns the number of bytes from the start position up to its end.
Definition StringView.h:93
const char * GetStartPointer() const
Returns the start of the view range.
Definition StringView.h:102
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11