gui: PreviewResult*: Wrap result in shared pointer immediatly

This commit is contained in:
Albert S. 2022-11-13 17:37:35 +01:00
rodič abce4cfcd9
revize 9686ef30c7
2 změnil soubory, kde provedl 5 přidání a 4 odebrání

Zobrazit soubor

@ -30,7 +30,7 @@ QByteArray PreviewResultPdf::serialize() const
QSharedPointer<PreviewResultPdf> PreviewResultPdf::deserialize(QByteArray &ba) QSharedPointer<PreviewResultPdf> PreviewResultPdf::deserialize(QByteArray &ba)
{ {
PreviewResultPdf *result = new PreviewResultPdf(); QSharedPointer<PreviewResultPdf> result(new PreviewResultPdf());
PreviewResultType type; PreviewResultType type;
QDataStream stream{&ba, QIODevice::ReadOnly}; QDataStream stream{&ba, QIODevice::ReadOnly};
@ -40,5 +40,5 @@ QSharedPointer<PreviewResultPdf> PreviewResultPdf::deserialize(QByteArray &ba)
throw std::runtime_error("Invalid byte array: Not a pdf preview"); throw std::runtime_error("Invalid byte array: Not a pdf preview");
} }
stream >> result->documentPath >> result->page >> result->previewImage; stream >> result->documentPath >> result->page >> result->previewImage;
return QSharedPointer<PreviewResultPdf>(result); return result;
} }

Zobrazit soubor

@ -40,7 +40,8 @@ QByteArray PreviewResultPlainText::serialize() const
QSharedPointer<PreviewResultPlainText> PreviewResultPlainText::deserialize(QByteArray &ba) QSharedPointer<PreviewResultPlainText> PreviewResultPlainText::deserialize(QByteArray &ba)
{ {
PreviewResultPlainText *result = new PreviewResultPlainText(); QSharedPointer<PreviewResultPlainText> result(new PreviewResultPlainText());
PreviewResultType type; PreviewResultType type;
QDataStream stream{&ba, QIODevice::ReadOnly}; QDataStream stream{&ba, QIODevice::ReadOnly};
@ -50,5 +51,5 @@ QSharedPointer<PreviewResultPlainText> PreviewResultPlainText::deserialize(QByte
throw std::runtime_error("Invalid byte array: Not a pdf preview"); throw std::runtime_error("Invalid byte array: Not a pdf preview");
} }
stream >> result->documentPath >> result->page >> result->text; stream >> result->documentPath >> result->page >> result->text;
return QSharedPointer<PreviewResultPlainText>(result); return result;
} }