summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2025-09-20 17:33:08 +0200
committerNikita Kostovsky <nikita@kostovsky.me>2025-09-20 17:33:08 +0200
commitffac2767127fe0bdb990187bbf9ec640e06933a6 (patch)
tree65990a5ea86d91a6ba14fcc4a2cf83458a91310f
parente7019763076cbbe3d52c2a03133c3ded5558f017 (diff)
introduce 'goodies' namespaceHEADmaster
-rw-r--r--g_object.cpp30
-rw-r--r--g_object.h3
-rw-r--r--g_property.h5
-rw-r--r--keyvalue.cpp8
-rw-r--r--keyvalue.h11
5 files changed, 35 insertions, 22 deletions
diff --git a/g_object.cpp b/g_object.cpp
index 09cbc27..bf7f6b0 100644
--- a/g_object.cpp
+++ b/g_object.cpp
@@ -5,32 +5,32 @@
#include <QLineF>
#include <QPointF>
-G_Object::G_Object(QObject* parent)
+goodies::G_Object::G_Object(QObject* parent)
: QObject(parent)
{
}
-G_Object::G_Object(const QJsonObject& json, QObject* parent)
+goodies::G_Object::G_Object(const QJsonObject& json, QObject* parent)
: QObject(parent)
{
// use G_Object static offset, not virtual
constructFromJson(json);
}
-G_Object::G_Object(const QJsonValue& json, QObject* parent)
+goodies::G_Object::G_Object(const QJsonValue& json, QObject* parent)
: QObject(parent)
{
constructFromJson(json.toObject());
}
-G_Object::G_Object(const G_Object& other, QObject* parent)
+goodies::G_Object::G_Object(const goodies::G_Object& other, QObject* parent)
: QObject(parent)
{
// NOTE: always G_Object's assignment operator will be called, not derived
*this = other;
}
-G_Object& G_Object::operator=(const G_Object& other)
+goodies::G_Object& goodies::G_Object::operator=(const goodies::G_Object& other)
{
// use G_Object static offset, not virtual
for (int i = staticMetaObject.propertyOffset();
@@ -48,26 +48,26 @@ G_Object& G_Object::operator=(const G_Object& other)
return *this;
}
-G_Object& G_Object::operator=(const QJsonObject& json)
+goodies::G_Object& goodies::G_Object::operator=(const QJsonObject& json)
{
constructFromJson(json);
return *this;
}
-G_Object& G_Object::operator=(const QJsonValue& json)
+goodies::G_Object& goodies::G_Object::operator=(const QJsonValue& json)
{
constructFromJson(json.toObject());
return *this;
}
-G_Object::operator const QJsonValue() const
+goodies::G_Object::operator const QJsonValue() const
{
return this->operator const QJsonObject();
}
-bool G_Object::operator==(const G_Object& other) const
+bool goodies::G_Object::operator==(const goodies::G_Object& other) const
{
for (int i = staticMetaObject.propertyOffset();
i < metaObject()->propertyCount();
@@ -84,7 +84,7 @@ bool G_Object::operator==(const G_Object& other) const
return true;
}
-bool G_Object::constructFromJson(const QJsonObject& json)
+bool goodies::G_Object::constructFromJson(const QJsonObject& json)
{
auto offset = staticMetaObject.propertyOffset();
auto properiesCount = metaObject()->propertyCount();
@@ -120,8 +120,8 @@ bool G_Object::constructFromJson(const QJsonObject& json)
{
qDebug() << Q_FUNC_INFO << "cannot convert" << key
<< "property from type"
- << QMetaType::typeName(variantValue.userType())
- << "to type" << QMetaType::typeName(type);
+ << QMetaType(variantValue.userType()).name() << "to type"
+ << QMetaType(type).name();
return false;
}
@@ -132,7 +132,7 @@ bool G_Object::constructFromJson(const QJsonObject& json)
return true;
}
-G_Object::operator const QJsonObject() const
+goodies::G_Object::operator const QJsonObject() const
{
QJsonObject result;
@@ -154,7 +154,7 @@ G_Object::operator const QJsonObject() const
if (!converted)
{
- qDebug() << "G_Object::operator const QJsonObject() const:"
+ qDebug() << "goodies::G_Object::operator const QJsonObject() const:"
<< "cannot convert" << key << "property from type"
<< QMetaType::typeName(value.userType()) << "to type"
<< QMetaType::typeName(type);
@@ -166,7 +166,7 @@ G_Object::operator const QJsonObject() const
return result;
}
-QDebug operator<<(QDebug d, const G_Object& o)
+QDebug goodies::operator<<(QDebug d, const goodies::G_Object& o)
{
d << o.metaObject()->className() << ":\n";
diff --git a/g_object.h b/g_object.h
index 725fbc1..d5e51a6 100644
--- a/g_object.h
+++ b/g_object.h
@@ -109,6 +109,8 @@ public: \
JSON_VALUE_CONSTRUCTOR(base_class, derived_class) \
COPY_CONSTRUCTOR(base_class, derived_class)
+namespace goodies
+{
class G_Object : public QObject
{
Q_OBJECT
@@ -136,3 +138,4 @@ protected:
};
QDebug operator<<(QDebug d, const G_Object& o);
+} // namespace goodies
diff --git a/g_property.h b/g_property.h
index fa743cd..af29c50 100644
--- a/g_property.h
+++ b/g_property.h
@@ -159,7 +159,8 @@ public Q_SLOTS: \
public: \
virtual type get_##name() const \
{ \
- return static_cast<type>( \
+ qDebug() << "read" << #name; \
+ const auto result = static_cast<type>( \
GlobalSettings::instance() \
->value( \
QString(this->staticMetaObject.className()) + "/" + #name, \
@@ -167,6 +168,8 @@ public: \
) \
.value<type>() \
); \
+ qDebug() << #name << "result:" << result; \
+ return result; \
}
#define INI_PROPERTY_GET_CAST(type, name, defaultValue) \
diff --git a/keyvalue.cpp b/keyvalue.cpp
index 1dcaa92..fe0da27 100644
--- a/keyvalue.cpp
+++ b/keyvalue.cpp
@@ -1,7 +1,11 @@
#include "keyvalue.h"
-KeyValue::KeyValue(const QVariant& key, const QVariant& value, QObject* parent)
- : G_Object(parent)
+goodies::KeyValue::KeyValue(
+ const QVariant& key,
+ const QVariant& value,
+ QObject* parent
+)
+ : goodies::G_Object(parent)
, INIT_FIELD(key)
, INIT_FIELD(value)
{
diff --git a/keyvalue.h b/keyvalue.h
index b5b7b79..f8eb5c7 100644
--- a/keyvalue.h
+++ b/keyvalue.h
@@ -4,6 +4,8 @@
#include "g_object.h"
#include "g_property.h"
+namespace goodies
+{
class Q_DECL_EXPORT KeyValue : public G_Object
{
Q_OBJECT
@@ -18,9 +20,10 @@ public:
QObject* parent = nullptr
);
- G_OBJECT(G_Object, KeyValue)
- ASSIGN_OPERATOR(G_Object, KeyValue)
+ G_OBJECT(goodies::G_Object, KeyValue)
+ ASSIGN_OPERATOR(goodies::G_Object, KeyValue)
};
+} // namespace goodies
-Q_DECLARE_METATYPE(KeyValue)
-Q_DECLARE_METATYPE(QVector<KeyValue>)
+Q_DECLARE_METATYPE(goodies::KeyValue)
+Q_DECLARE_METATYPE(QVector<goodies::KeyValue>)