gui: PreviewGenerator*: Wrap PreviewResult in QSharedPointer
Dieser Commit ist enthalten in:
Ursprung
3e03fed1a2
Commit
ee18142e36
@ -9,7 +9,7 @@
|
||||
class PreviewGenerator
|
||||
{
|
||||
public:
|
||||
virtual PreviewResult *generate(RenderConfig config, QString documentPath, unsigned int page) = 0;
|
||||
virtual QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page) = 0;
|
||||
virtual ~PreviewGenerator()
|
||||
{
|
||||
}
|
||||
|
@ -10,16 +10,15 @@ void PreviewGeneratorMapFunctor::setRenderConfig(RenderConfig config)
|
||||
this->renderConfig = config;
|
||||
}
|
||||
|
||||
QSharedPointer<PreviewResult> PreviewGeneratorMapFunctor::operator()(const QSharedPointer<PreviewResult> &renderResult)
|
||||
QByteArray PreviewGeneratorMapFunctor::operator()(const RenderTarget &renderTarget)
|
||||
{
|
||||
QFileInfo info{renderResult->getDocumentPath()};
|
||||
QFileInfo info{renderTarget.path};
|
||||
PreviewGenerator *previewGenerator = PreviewGenerator::get(info);
|
||||
if(previewGenerator == nullptr)
|
||||
{
|
||||
return QSharedPointer<PreviewResult>();
|
||||
return QByteArray{};
|
||||
}
|
||||
auto preview =
|
||||
previewGenerator->generate(this->renderConfig, renderResult->getDocumentPath(), renderResult->getPage());
|
||||
auto preview = previewGenerator->generate(this->renderConfig, renderTarget.path, renderTarget.page);
|
||||
|
||||
return QSharedPointer<PreviewResult>(preview);
|
||||
return preview->serialize();
|
||||
}
|
||||
|
@ -2,8 +2,9 @@
|
||||
#define PREVIEWGENERATORMAPFUNCTOR_H
|
||||
|
||||
#include "renderconfig.h"
|
||||
#include "previewgenerator.h"
|
||||
#include "rendertarget.h"
|
||||
|
||||
#include "previewgenerator.h"
|
||||
class PreviewGeneratorMapFunctor
|
||||
{
|
||||
|
||||
@ -16,13 +17,13 @@ class PreviewGeneratorMapFunctor
|
||||
RenderConfig renderConfig;
|
||||
|
||||
public:
|
||||
typedef QSharedPointer<PreviewResult> result_type;
|
||||
typedef QByteArray result_type;
|
||||
|
||||
PreviewGeneratorMapFunctor();
|
||||
|
||||
void setRenderConfig(RenderConfig config);
|
||||
|
||||
QSharedPointer<PreviewResult> operator()(const QSharedPointer<PreviewResult> &renderResult);
|
||||
QByteArray operator()(const RenderTarget &renderTarget);
|
||||
};
|
||||
|
||||
#endif // PREVIEWGENERATORMAPFUNCTOR_H
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QPainter>
|
||||
|
||||
#include "previewgeneratorpdf.h"
|
||||
|
||||
static QMutex cacheMutex;
|
||||
@ -24,18 +23,18 @@ Poppler::Document *PreviewGeneratorPdf::document(QString path)
|
||||
return result;
|
||||
}
|
||||
|
||||
PreviewResult *PreviewGeneratorPdf::generate(RenderConfig config, QString documentPath, unsigned int page)
|
||||
QSharedPointer<PreviewResult> PreviewGeneratorPdf::generate(RenderConfig config, QString documentPath,
|
||||
unsigned int page)
|
||||
{
|
||||
PreviewResultPdf *result = new PreviewResultPdf(documentPath, page);
|
||||
|
||||
Poppler::Document *doc = document(documentPath);
|
||||
if(doc == nullptr)
|
||||
{
|
||||
return result;
|
||||
return QSharedPointer<PreviewResult>(result);
|
||||
}
|
||||
if(doc->isLocked())
|
||||
{
|
||||
return result;
|
||||
return QSharedPointer<PreviewResult>(result);
|
||||
}
|
||||
int p = (int)page - 1;
|
||||
if(p < 0)
|
||||
@ -55,5 +54,5 @@ PreviewResult *PreviewGeneratorPdf::generate(RenderConfig config, QString docume
|
||||
}
|
||||
}
|
||||
result->previewImage = img;
|
||||
return result;
|
||||
return QSharedPointer<PreviewResult>(result);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class PreviewGeneratorPdf : public PreviewGenerator
|
||||
public:
|
||||
using PreviewGenerator::PreviewGenerator;
|
||||
|
||||
PreviewResult *generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||
QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||
|
||||
~PreviewGeneratorPdf()
|
||||
{
|
||||
|
@ -3,13 +3,14 @@
|
||||
#include "previewgeneratorplaintext.h"
|
||||
#include "previewresultplaintext.h"
|
||||
|
||||
PreviewResult *PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath, unsigned int page)
|
||||
QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath,
|
||||
unsigned int page)
|
||||
{
|
||||
PreviewResultPlainText *result = new PreviewResultPlainText(documentPath, page);
|
||||
QFile file(documentPath);
|
||||
if(!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
return result;
|
||||
return QSharedPointer<PreviewResultPlainText>(result);
|
||||
}
|
||||
QTextStream in(&file);
|
||||
|
||||
@ -77,5 +78,5 @@ PreviewResult *PreviewGeneratorPlainText::generate(RenderConfig config, QString
|
||||
header += "<hr>";
|
||||
|
||||
result->setText(header + resulText.replace("\n", "<br>"));
|
||||
return result;
|
||||
return QSharedPointer<PreviewResultPlainText>(result);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ class PreviewGeneratorPlainText : public PreviewGenerator
|
||||
{
|
||||
public:
|
||||
using PreviewGenerator::PreviewGenerator;
|
||||
PreviewResult *generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||
QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||
};
|
||||
|
||||
#endif // PREVIEWGENERATORPLAINTEXT_H
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren