mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
re-apply: Cleaner qobject2qvariant().
This commit is contained in:
parent
c570a13a1f
commit
21204971ff
@ -41,7 +41,7 @@ QObjectHelper::~QObjectHelper()
|
||||
delete d;
|
||||
}
|
||||
|
||||
QVariantMap QObjectHelper::qobject2qvariant( const QObject* object,
|
||||
QVariantMap QObjectHelper::qobject2qvariant(const QObject* object, Flags flags,
|
||||
const QStringList& ignoredProperties)
|
||||
{
|
||||
QVariantMap result;
|
||||
@ -55,11 +55,20 @@ QVariantMap QObjectHelper::qobject2qvariant( const QObject* object,
|
||||
continue;
|
||||
|
||||
QVariant value = object->property(name);
|
||||
if (value.isNull() && !flags.testFlag(Flag_StoreNullVariants))
|
||||
continue;
|
||||
if (!value.isValid() && !flags.testFlag(Flag_StoreInvalidVariants))
|
||||
continue;
|
||||
result[QLatin1String(name)] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantMap QObjectHelper::qobject2qvariant(const QObject *object, const QStringList &ignoredProperties)
|
||||
{
|
||||
return qobject2qvariant(object, Flag_All, ignoredProperties);
|
||||
}
|
||||
|
||||
void QObjectHelper::qvariant2qobject(const QVariantMap& variant, QObject* object)
|
||||
{
|
||||
const QMetaObject *metaobject = object->metaObject();
|
||||
|
@ -120,14 +120,24 @@ namespace QJson {
|
||||
QObjectHelper();
|
||||
~QObjectHelper();
|
||||
|
||||
enum Flag {
|
||||
Flag_None,
|
||||
Flag_StoreNullVariants,
|
||||
Flag_StoreInvalidVariants,
|
||||
Flag_All = Flag_StoreNullVariants | Flag_StoreInvalidVariants
|
||||
};
|
||||
Q_DECLARE_FLAGS(Flags, Flag)
|
||||
|
||||
/**
|
||||
* This method converts a QObject instance into a QVariantMap.
|
||||
*
|
||||
* @param object The QObject instance to be converted.
|
||||
* @param ignoredProperties Properties that won't be converted.
|
||||
*/
|
||||
static QVariantMap qobject2qvariant( const QObject* object,
|
||||
static QVariantMap qobject2qvariant(const QObject* object, Flags flags = Flag_All,
|
||||
const QStringList& ignoredProperties = QStringList(QString(QLatin1String("objectName"))));
|
||||
static QVariantMap qobject2qvariant(const QObject* object,
|
||||
const QStringList& ignoredProperties);
|
||||
|
||||
/**
|
||||
* This method converts a QVariantMap instance into a QObject
|
||||
|
Loading…
Reference in New Issue
Block a user