Commit 9d318d33 authored by Martin Straka's avatar Martin Straka

Added QVarinat conversion into both classes

parent a64b9095
......@@ -207,3 +207,12 @@ void AttachmentData::_setIcon(const QString &_icon)
{
m_icon = _icon;
}
AttachmentData *AttachmentData::fromVariant(const QVariant &attachDataVariant)
{
if (!attachDataVariant.canConvert<QObject *>()) {
return Q_NULLPTR;
}
QObject *obj = qvariant_cast<QObject *>(attachDataVariant);
return qobject_cast<AttachmentData *>(obj);
}
......@@ -101,6 +101,20 @@ public:
QString _icon(void) const;
void _setIcon(const QString &_icon);
/*!
* @brief Converts QVariant obtained from QML into data pointer.
*
* @note Some weird stuff happens in QML when passing attachment data
* directly as constant reference. Wrong constructors are called
* and no data are passed. That's because we are using a QVariant.
* This function does not allocate a new data.
*
* @param[in] attachDataVariant QVariant holding the attachment data.
* @return Pointer to data if it could be acquired, Q_NULLPTR else.
*/
static
AttachmentData *fromVariant(const QVariant &attachDataVariant);
private:
int m_fileId; /*!< File identifier. */
......
......@@ -540,3 +540,12 @@ void MsgEnvelope::_setDmReadLocally(bool _dmReadLocally)
{
m_dmReadLocally = _dmReadLocally;
}
MsgEnvelope *MsgEnvelope::fromVariant(const QVariant &msgEnvelDataVariant)
{
if (!msgEnvelDataVariant.canConvert<QObject *>()) {
return Q_NULLPTR;
}
QObject *obj = qvariant_cast<QObject *>(msgEnvelDataVariant);
return qobject_cast<MsgEnvelope *>(obj);
}
......@@ -223,6 +223,20 @@ public:
bool _dmReadLocally(void) const;
void _setDmReadLocally(bool _dmReadLocally);
/*!
* @brief Converts QVariant obtained from QML into data pointer.
*
* @note Some weird stuff happens in QML when passing envelope data
* directly as constant reference. Wrong constructors are called
* and no data are passed. That's because we are using a QVariant.
* This function does not allocate a new data.
*
* @param[in] msgEnvelDataVariant QVariant holding the envelope data.
* @return Pointer to data if it could be acquired, Q_NULLPTR else.
*/
static
MsgEnvelope *fromVariant(const QVariant &msgEnvelDataVariant);
private:
qint64 m_dmID;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment