2010-12-20 02:45:36 +00:00
|
|
|
#include "titleblocktemplaterenderer.h"
|
|
|
|
#include "titleblocktemplate.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor
|
|
|
|
@param parnet Parent QObject of this renderer
|
|
|
|
*/
|
|
|
|
TitleBlockTemplateRenderer::TitleBlockTemplateRenderer(QObject *parent) :
|
|
|
|
QObject(parent),
|
2018-12-28 18:39:54 +00:00
|
|
|
m_titleblock_template(nullptr),
|
|
|
|
m_use_cache(true),
|
|
|
|
m_last_known_titleblock_width(-1)
|
2010-12-20 02:45:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
TitleBlockTemplateRenderer::~TitleBlockTemplateRenderer() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return the titleblock template used for the rendering
|
|
|
|
*/
|
|
|
|
const TitleBlockTemplate *TitleBlockTemplateRenderer::titleBlockTemplate() const {
|
2018-12-28 18:39:54 +00:00
|
|
|
return(m_titleblock_template);
|
2010-12-20 02:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param titleblock_template TitleBlock template to render.
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateRenderer::setTitleBlockTemplate(const TitleBlockTemplate *titleblock_template) {
|
2018-12-28 18:39:54 +00:00
|
|
|
if (titleblock_template != m_titleblock_template) {
|
|
|
|
m_titleblock_template = titleblock_template;
|
2010-12-20 02:45:36 +00:00
|
|
|
invalidateRenderedTemplate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-28 18:39:54 +00:00
|
|
|
* @brief TitleBlockTemplateRenderer::setContext
|
|
|
|
* @param context : Context to use when rendering the titleblock
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void TitleBlockTemplateRenderer::setContext(const DiagramContext &context) {
|
2018-12-28 18:39:54 +00:00
|
|
|
m_context = context;
|
2010-12-20 02:45:36 +00:00
|
|
|
invalidateRenderedTemplate();
|
|
|
|
}
|
|
|
|
|
2018-12-28 18:39:54 +00:00
|
|
|
/**
|
|
|
|
* @brief TitleBlockTemplateRenderer::context
|
|
|
|
* @return the current diagram context use when render the titleblock
|
|
|
|
*/
|
|
|
|
DiagramContext TitleBlockTemplateRenderer::context() const {
|
|
|
|
return m_context;
|
|
|
|
}
|
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
/**
|
|
|
|
@return the height of the rendered template, or -1 if no template has been
|
|
|
|
set for this renderer.
|
|
|
|
@see TitleBlockTemplate::height()
|
|
|
|
*/
|
|
|
|
int TitleBlockTemplateRenderer::height() const {
|
2018-12-28 18:39:54 +00:00
|
|
|
if (!m_titleblock_template) return(-1);
|
|
|
|
return(m_titleblock_template -> height());
|
2010-12-20 02:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Render the titleblock.
|
|
|
|
@param provided_painter QPainter to use to render the titleblock.
|
|
|
|
@param titleblock_width The total width of the titleblock to render
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateRenderer::render(QPainter *provided_painter, int titleblock_width) {
|
2018-12-28 18:39:54 +00:00
|
|
|
if (!m_titleblock_template) return;
|
2010-12-20 02:45:36 +00:00
|
|
|
|
2018-12-28 18:39:54 +00:00
|
|
|
if (m_use_cache) {
|
2012-02-26 21:54:47 +00:00
|
|
|
// Do we really need to calculate all this again?
|
2018-12-28 18:39:54 +00:00
|
|
|
if (titleblock_width != m_last_known_titleblock_width || m_rendered_template.isNull()) {
|
2012-02-26 21:54:47 +00:00
|
|
|
renderToQPicture(titleblock_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
provided_painter -> save();
|
2018-12-28 18:39:54 +00:00
|
|
|
m_rendered_template.play(provided_painter);
|
2012-02-26 21:54:47 +00:00
|
|
|
provided_painter -> restore();
|
|
|
|
} else {
|
2018-12-28 18:39:54 +00:00
|
|
|
m_titleblock_template -> render(*provided_painter, m_context, titleblock_width);
|
2010-12-20 02:45:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 16:55:16 +00:00
|
|
|
|
|
|
|
void TitleBlockTemplateRenderer::renderDxf(QRectF &title_block_rect, int titleblock_width, QString &file_path, int color) {
|
2018-12-28 18:39:54 +00:00
|
|
|
if (!m_titleblock_template) return;
|
|
|
|
m_titleblock_template -> renderDxf(title_block_rect, m_context, titleblock_width, file_path, color);
|
2014-01-08 16:55:16 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
/**
|
|
|
|
Renders the titleblock to the internal QPicture
|
|
|
|
@param titleblock_width Width of the titleblock to render
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateRenderer::renderToQPicture(int titleblock_width) {
|
2018-12-28 18:39:54 +00:00
|
|
|
if (!m_titleblock_template) return;
|
2010-12-20 02:45:36 +00:00
|
|
|
|
|
|
|
// we render the template on our internal QPicture
|
2018-12-28 18:39:54 +00:00
|
|
|
QPainter painter(&m_rendered_template);
|
2010-12-20 02:45:36 +00:00
|
|
|
|
2018-12-28 18:39:54 +00:00
|
|
|
m_titleblock_template -> render(painter, m_context, titleblock_width);
|
2010-12-20 02:45:36 +00:00
|
|
|
|
|
|
|
// memorize the last known width
|
2018-12-28 18:39:54 +00:00
|
|
|
m_last_known_titleblock_width = titleblock_width;
|
2010-12-20 02:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Invalidates the previous rendering of the template by resetting the internal
|
|
|
|
QPicture.
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateRenderer::invalidateRenderedTemplate() {
|
2018-12-28 18:39:54 +00:00
|
|
|
m_rendered_template = QPicture();
|
2010-12-20 02:45:36 +00:00
|
|
|
}
|
2012-02-26 21:54:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@param use_cache true for this renderer to use its QPicture-based cache,
|
|
|
|
false otherwise.
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateRenderer::setUseCache(bool use_cache) {
|
2018-12-28 18:39:54 +00:00
|
|
|
m_use_cache = use_cache;
|
2012-02-26 21:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return true if this renderer uses its QPicture-based cache, false
|
|
|
|
otherwise.
|
|
|
|
*/
|
|
|
|
bool TitleBlockTemplateRenderer::useCache() const {
|
2018-12-28 18:39:54 +00:00
|
|
|
return(m_use_cache);
|
2012-02-26 21:54:47 +00:00
|
|
|
}
|
|
|
|
|