nodeguy/src/cpp/include/nodegui/Extras/Utils/nutils.h
2021-10-27 10:46:12 +02:00

39 lines
1.3 KiB
C++

#pragma once
#include <napi.h>
#include <QPointer>
#include <QVariant>
#include "Extras/Export/export.h"
#include "core/FlexLayout/flexutils.h"
#include "deps/yoga/YGNode.h"
namespace extrautils {
DLL_EXPORT QVariant* convertToQVariant(Napi::Env& env, Napi::Value& value);
DLL_EXPORT bool isNapiValueInt(Napi::Env& env, Napi::Value& num);
DLL_EXPORT std::string getNapiObjectClassName(Napi::Object& object);
DLL_EXPORT void* configureQWidget(QWidget* widget, YGNodeRef node,
bool isLeafNode = false);
DLL_EXPORT void* configureQObject(QObject* object);
DLL_EXPORT void* configureComponent(void* component);
DLL_EXPORT uint64_t hashPointerTo53bit(const void* input);
template <typename T>
void safeDelete(QPointer<T>& component) {
if (!component.isNull() && component->QObject::parent() == nullptr) {
delete component;
}
}
} // namespace extrautils
class DLL_EXPORT NUtilsWrap : public Napi::ObjectWrap<NUtilsWrap> {
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
NUtilsWrap(const Napi::CallbackInfo& info);
static Napi::FunctionReference constructor;
};
namespace StaticNUtilsWrapMethods {
DLL_EXPORT Napi::Value isNapiExternal(const Napi::CallbackInfo& info);
} // namespace StaticNUtilsWrapMethods