Revision control

Copy as Markdown

{{>licenseInfo}}
#ifndef {{prefix}}_HTTP_FILE_ELEMENT_H
#define {{prefix}}_HTTP_FILE_ELEMENT_H
#include <QtCore/qjsonvalue.h>
#include <QtCore/qmetatype.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
{{#cppNamespaceDeclarations}}
namespace {{this}} {
{{/cppNamespaceDeclarations}}
// NOTE: Normally, {{prefix}}HttpFileElementShared would be forward-declared and
// defined in the cpp file with QT_DECLARE/DEFINE_QESDP_SPECIALIZATION_DTOR(),
// but since those macros are internal, we define it here instead.
// The class enables implicit sharing via QExplicitlySharedDataPointer.
class {{prefix}}HttpFileElementShared : public QSharedData
{
public:
explicit {{prefix}}HttpFileElementShared(const QString &localFilename)
: m_localFilename(localFilename) {}
~{{prefix}}HttpFileElementShared();
QString m_variableName;
const QString m_localFilename;
QString m_mimeType;
bool m_temporary = false;
};
class {{prefix}}HttpFileElement {
public:
{{prefix}}HttpFileElement();
explicit {{prefix}}HttpFileElement(const QString &localFilename);
{{prefix}}HttpFileElement(const {{prefix}}HttpFileElement &other);
{{prefix}}HttpFileElement({{prefix}}HttpFileElement &&other) noexcept : d(std::move(other.d)) {}
{{prefix}}HttpFileElement &operator=(const {{prefix}}HttpFileElement &other);
{{prefix}}HttpFileElement &operator=({{prefix}}HttpFileElement &&other) noexcept
{
if (this != &other)
d = std::move(other.d);
return *this;
}
~{{prefix}}HttpFileElement();
void setMimeType(const QString &mime);
void setVariableName(const QString &name);
void setTemporary(bool temp);
QString mimeType() const;
QString filename() const;
QString variableName() const;
bool isTemporary() const;
QString requestFilename() const;
bool isSet() const;
bool fromStringValue(const QString &instr);
bool fromJsonValue(const QJsonValue &jval);
bool saveToLocalFile(const QByteArray &bytes);
QString asJson() const;
QJsonValue asJsonValue() const;
QByteArray loadFromLocalFile() const;
private:
QExplicitlySharedDataPointer<{{prefix}}HttpFileElementShared> d;
};
{{#cppNamespaceDeclarations}}
} // namespace {{this}}
{{/cppNamespaceDeclarations}}
Q_DECLARE_METATYPE({{#cppNamespaceDeclarations}}{{this}}::{{/cppNamespaceDeclarations}}{{prefix}}HttpFileElement)
#endif // {{prefix}}_HTTP_FILE_ELEMENT_H