LibrePCB Developers Documentation
GraphicsExport Class Referencefinal

Asynchronously exports graphics to a QPainter. More...

#include <graphicsexport.h>

Inherits QObject.

+ Collaboration diagram for GraphicsExport:

Classes

struct  Result
 
struct  RunArgs
 

Public Types

typedef std::pair< std::shared_ptr< GraphicsPagePainter >, std::shared_ptr< GraphicsExportSettings > > Page
 
typedef QList< PagePages
 

Signals

void previewReady (int index, const QSize &pageSize, const QRectF margins, std::shared_ptr< QPicture > picture)
 
void savingFile (const librepcb::FilePath &filePath)
 
void progress (int percent, int completed, int total)
 
void succeeded ()
 
void failed (const QString &error)
 
void imageCopiedToClipboard (const QImage &image, QClipboard::Mode mode)
 

Public Member Functions

 GraphicsExport (QObject *parent=nullptr) noexcept
 
 GraphicsExport (const GraphicsExport &other)=delete
 
 ~GraphicsExport () noexcept
 
void setDocumentName (const QString &name) noexcept
 Set the document name used for printing, PDF and SVG export. More...
 
void startPreview (const Pages &pages) noexcept
 Start creating previews asynchronously. More...
 
void startExport (const Pages &pages, const FilePath &filePath) noexcept
 Start exporting to a file or clipboard asynchronously. More...
 
void startPrint (const Pages &pages, const QString &printerName, QPrinter::DuplexMode duplex, int copies) noexcept
 Start printing to a printer asynchronously. More...
 
Result waitForFinished () noexcept
 Wait (block) until the preview/export/print is finished. More...
 
void cancel () noexcept
 Cancel the current job. More...
 
GraphicsExportoperator= (const GraphicsExport &rhs)=delete
 

Static Public Member Functions

static QStringList getSupportedExtensions () noexcept
 Get all supported file extensions for startExport() More...
 
static QStringList getSupportedImageExtensions () noexcept
 Get all supported image file extensions for startExport() More...
 

Private Member Functions

Result run (RunArgs args) noexcept
 

Static Private Member Functions

static QTransform getSourceTransformation (const GraphicsExportSettings &settings) noexcept
 
static QRectF calcSourceRect (const GraphicsPagePainter &page, const GraphicsExportSettings &settings) noexcept
 
static QPageLayout::Orientation getOrientation (const QSizeF &size) noexcept
 

Private Attributes

QString mCreator
 
QString mDocumentName
 
QFuture< ResultmFuture
 
bool mAbort
 

Detailed Description

Asynchronously exports graphics to a QPainter.

Used for graphics printing, PDF export, SVG export etc. without blocking the main thread.

Member Typedef Documentation

◆ Page

typedef std::pair<std::shared_ptr<GraphicsPagePainter>, std::shared_ptr<GraphicsExportSettings> > Page

◆ Pages

typedef QList<Page> Pages

Constructor & Destructor Documentation

◆ GraphicsExport() [1/2]

GraphicsExport ( QObject *  parent = nullptr)
noexcept

◆ GraphicsExport() [2/2]

GraphicsExport ( const GraphicsExport other)
delete

◆ ~GraphicsExport()

~GraphicsExport ( )
noexcept
+ Here is the call graph for this function:

Member Function Documentation

◆ setDocumentName()

void setDocumentName ( const QString &  name)
inlinenoexcept

Set the document name used for printing, PDF and SVG export.

Parameters
nameDocument name.
+ Here is the caller graph for this function:

◆ startPreview()

void startPreview ( const Pages pages)
noexcept

Start creating previews asynchronously.

The signal previewReady() will be emitted from a worker thread for each processed page.

Parameters
pagesThe pages to create the preview of.
+ Here is the call graph for this function:

◆ startExport()

void startExport ( const Pages pages,
const FilePath filePath 
)
noexcept

Start exporting to a file or clipboard asynchronously.

The supported file type will be determined automatically by the file extension. Supported file types are pdf, svg and all supported file extensions of QImage. See also getSupportedExtensions().

The signals::savingFile() will be emitted from a worker thread for each file created.

Parameters
pagesThe pages to export.
filePathExport file path. If invalid, pixmaps will be copied into the clipboard. If multiple pages are exported, the page number will automatically be appended to the filename.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startPrint()

void startPrint ( const Pages pages,
const QString &  printerName,
QPrinter::DuplexMode  duplex,
int  copies 
)
noexcept

Start printing to a printer asynchronously.

Parameters
pagesThe pages to export.
printerNameName of the printer to use.
duplexThe duplex mode to use.
copiesNumber of copies to print.
+ Here is the call graph for this function:

◆ waitForFinished()

GraphicsExport::Result waitForFinished ( )
noexcept

Wait (block) until the preview/export/print is finished.

Returns
Result of the export.
+ Here is the caller graph for this function:

◆ cancel()

void cancel ( )
noexcept

Cancel the current job.

+ Here is the caller graph for this function:

◆ operator=()

GraphicsExport & operator= ( const GraphicsExport rhs)
delete

◆ getSupportedExtensions()

QStringList getSupportedExtensions ( )
staticnoexcept

Get all supported file extensions for startExport()

Returns
File extensions (e.g. "pdf", "svg", "png").
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSupportedImageExtensions()

QStringList getSupportedImageExtensions ( )
staticnoexcept

Get all supported image file extensions for startExport()

Returns
File extensions (e.g. "svg", "bmp", "png").
+ Here is the caller graph for this function:

◆ previewReady

void previewReady ( int  index,
const QSize &  pageSize,
const QRectF  margins,
std::shared_ptr< QPicture >  picture 
)
signal
+ Here is the caller graph for this function:

◆ savingFile

void savingFile ( const librepcb::FilePath filePath)
signal

◆ progress

void progress ( int  percent,
int  completed,
int  total 
)
signal

◆ succeeded

void succeeded ( )
signal
+ Here is the caller graph for this function:

◆ failed

void failed ( const QString &  error)
signal

◆ imageCopiedToClipboard

void imageCopiedToClipboard ( const QImage &  image,
QClipboard::Mode  mode 
)
signal
+ Here is the caller graph for this function:

◆ run()

GraphicsExport::Result run ( RunArgs  args)
privatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSourceTransformation()

QTransform getSourceTransformation ( const GraphicsExportSettings settings)
staticprivatenoexcept

◆ calcSourceRect()

QRectF calcSourceRect ( const GraphicsPagePainter page,
const GraphicsExportSettings settings 
)
staticprivatenoexcept

◆ getOrientation()

QPageLayout::Orientation getOrientation ( const QSizeF &  size)
staticprivatenoexcept

Member Data Documentation

◆ mCreator

QString mCreator
private

◆ mDocumentName

QString mDocumentName
private

◆ mFuture

QFuture<Result> mFuture
private

◆ mAbort

bool mAbort
private

The documentation for this class was generated from the following files: