gui: PreviewResult: Add serialization() methods for IPC
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "previewresultpdf.h"
|
||||
|
||||
PreviewResultPdf::PreviewResultPdf(const PreviewResult &o)
|
||||
{
|
||||
this->documentPath = o.getDocumentPath();
|
||||
@@ -19,3 +18,27 @@ bool PreviewResultPdf::hasPreview()
|
||||
bool result = !this->previewImage.isNull();
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray PreviewResultPdf::serialize() const
|
||||
{
|
||||
QByteArray result;
|
||||
QDataStream stream{&result, QIODevice::WriteOnly};
|
||||
PreviewResultType type = PreviewResultType::PDF;
|
||||
stream << type << this->documentPath << this->page << this->previewImage;
|
||||
return result;
|
||||
}
|
||||
|
||||
QSharedPointer<PreviewResultPdf> PreviewResultPdf::deserialize(QByteArray &ba)
|
||||
{
|
||||
PreviewResultPdf *result = new PreviewResultPdf();
|
||||
PreviewResultType type;
|
||||
|
||||
QDataStream stream{&ba, QIODevice::ReadOnly};
|
||||
stream >> type;
|
||||
if(type != PreviewResultType::PDF)
|
||||
{
|
||||
throw std::runtime_error("Invalid byte array: Not a pdf preview");
|
||||
}
|
||||
stream >> result->documentPath >> result->page >> result->previewImage;
|
||||
return QSharedPointer<PreviewResultPdf>(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user