gui: PreviewGenerator*: Wrap PreviewResult in QSharedPointer
Αυτή η υποβολή περιλαμβάνεται σε:
γονέας
3e03fed1a2
υποβολή
ee18142e36
@ -9,7 +9,7 @@
|
|||||||
class PreviewGenerator
|
class PreviewGenerator
|
||||||
{
|
{
|
||||||
public:
|
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()
|
virtual ~PreviewGenerator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -10,16 +10,15 @@ void PreviewGeneratorMapFunctor::setRenderConfig(RenderConfig config)
|
|||||||
this->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);
|
PreviewGenerator *previewGenerator = PreviewGenerator::get(info);
|
||||||
if(previewGenerator == nullptr)
|
if(previewGenerator == nullptr)
|
||||||
{
|
{
|
||||||
return QSharedPointer<PreviewResult>();
|
return QByteArray{};
|
||||||
}
|
}
|
||||||
auto preview =
|
auto preview = previewGenerator->generate(this->renderConfig, renderTarget.path, renderTarget.page);
|
||||||
previewGenerator->generate(this->renderConfig, renderResult->getDocumentPath(), renderResult->getPage());
|
|
||||||
|
|
||||||
return QSharedPointer<PreviewResult>(preview);
|
return preview->serialize();
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
#define PREVIEWGENERATORMAPFUNCTOR_H
|
#define PREVIEWGENERATORMAPFUNCTOR_H
|
||||||
|
|
||||||
#include "renderconfig.h"
|
#include "renderconfig.h"
|
||||||
#include "previewgenerator.h"
|
#include "rendertarget.h"
|
||||||
|
|
||||||
|
#include "previewgenerator.h"
|
||||||
class PreviewGeneratorMapFunctor
|
class PreviewGeneratorMapFunctor
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -16,13 +17,13 @@ class PreviewGeneratorMapFunctor
|
|||||||
RenderConfig renderConfig;
|
RenderConfig renderConfig;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef QSharedPointer<PreviewResult> result_type;
|
typedef QByteArray result_type;
|
||||||
|
|
||||||
PreviewGeneratorMapFunctor();
|
PreviewGeneratorMapFunctor();
|
||||||
|
|
||||||
void setRenderConfig(RenderConfig config);
|
void setRenderConfig(RenderConfig config);
|
||||||
|
|
||||||
QSharedPointer<PreviewResult> operator()(const QSharedPointer<PreviewResult> &renderResult);
|
QByteArray operator()(const RenderTarget &renderTarget);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PREVIEWGENERATORMAPFUNCTOR_H
|
#endif // PREVIEWGENERATORMAPFUNCTOR_H
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "previewgeneratorpdf.h"
|
#include "previewgeneratorpdf.h"
|
||||||
|
|
||||||
static QMutex cacheMutex;
|
static QMutex cacheMutex;
|
||||||
@ -24,18 +23,18 @@ Poppler::Document *PreviewGeneratorPdf::document(QString path)
|
|||||||
return result;
|
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);
|
PreviewResultPdf *result = new PreviewResultPdf(documentPath, page);
|
||||||
|
|
||||||
Poppler::Document *doc = document(documentPath);
|
Poppler::Document *doc = document(documentPath);
|
||||||
if(doc == nullptr)
|
if(doc == nullptr)
|
||||||
{
|
{
|
||||||
return result;
|
return QSharedPointer<PreviewResult>(result);
|
||||||
}
|
}
|
||||||
if(doc->isLocked())
|
if(doc->isLocked())
|
||||||
{
|
{
|
||||||
return result;
|
return QSharedPointer<PreviewResult>(result);
|
||||||
}
|
}
|
||||||
int p = (int)page - 1;
|
int p = (int)page - 1;
|
||||||
if(p < 0)
|
if(p < 0)
|
||||||
@ -55,5 +54,5 @@ PreviewResult *PreviewGeneratorPdf::generate(RenderConfig config, QString docume
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
result->previewImage = img;
|
result->previewImage = img;
|
||||||
return result;
|
return QSharedPointer<PreviewResult>(result);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class PreviewGeneratorPdf : public PreviewGenerator
|
|||||||
public:
|
public:
|
||||||
using PreviewGenerator::PreviewGenerator;
|
using PreviewGenerator::PreviewGenerator;
|
||||||
|
|
||||||
PreviewResult *generate(RenderConfig config, QString documentPath, unsigned int page);
|
QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||||
|
|
||||||
~PreviewGeneratorPdf()
|
~PreviewGeneratorPdf()
|
||||||
{
|
{
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
#include "previewgeneratorplaintext.h"
|
#include "previewgeneratorplaintext.h"
|
||||||
#include "previewresultplaintext.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);
|
PreviewResultPlainText *result = new PreviewResultPlainText(documentPath, page);
|
||||||
QFile file(documentPath);
|
QFile file(documentPath);
|
||||||
if(!file.open(QFile::ReadOnly | QFile::Text))
|
if(!file.open(QFile::ReadOnly | QFile::Text))
|
||||||
{
|
{
|
||||||
return result;
|
return QSharedPointer<PreviewResultPlainText>(result);
|
||||||
}
|
}
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
|
|
||||||
@ -77,5 +78,5 @@ PreviewResult *PreviewGeneratorPlainText::generate(RenderConfig config, QString
|
|||||||
header += "<hr>";
|
header += "<hr>";
|
||||||
|
|
||||||
result->setText(header + resulText.replace("\n", "<br>"));
|
result->setText(header + resulText.replace("\n", "<br>"));
|
||||||
return result;
|
return QSharedPointer<PreviewResultPlainText>(result);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ class PreviewGeneratorPlainText : public PreviewGenerator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using PreviewGenerator::PreviewGenerator;
|
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
|
#endif // PREVIEWGENERATORPLAINTEXT_H
|
||||||
|
Φόρτωση…
Αναφορά σε νέο ζήτημα
Block a user