QElectroTech  0.70
titleblocktemplaterenderer.cpp
Go to the documentation of this file.
2 #include "titleblocktemplate.h"
3 
9  QObject(parent),
10  m_titleblock_template(nullptr),
11  m_use_cache(true),
12  m_last_known_titleblock_width(-1)
13 {
14 }
15 
20 }
21 
26  return(m_titleblock_template);
27 }
28 
33  if (titleblock_template != m_titleblock_template) {
34  m_titleblock_template = titleblock_template;
36  }
37 }
38 
46 }
47 
53  return m_context;
54 }
55 
62  if (!m_titleblock_template) return(-1);
63  return(m_titleblock_template -> height());
64 }
65 
71 void TitleBlockTemplateRenderer::render(QPainter *provided_painter, int titleblock_width) {
72  if (!m_titleblock_template) return;
73 
74  if (m_use_cache) {
75  // Do we really need to calculate all this again?
76  if (titleblock_width != m_last_known_titleblock_width || m_rendered_template.isNull()) {
77  renderToQPicture(titleblock_width);
78  }
79 
80  provided_painter -> save();
81  m_rendered_template.play(provided_painter);
82  provided_painter -> restore();
83  } else {
84  m_titleblock_template -> render(*provided_painter, m_context, titleblock_width);
85  }
86 }
87 
88 
89 void TitleBlockTemplateRenderer::renderDxf(QRectF &title_block_rect, int titleblock_width, QString &file_path, int color) {
90  if (!m_titleblock_template) return;
91  m_titleblock_template -> renderDxf(title_block_rect, m_context, titleblock_width, file_path, color);
92 }
93 
99  if (!m_titleblock_template) return;
100 
101  // we render the template on our internal QPicture
102  QPainter painter(&m_rendered_template);
103 
104  m_titleblock_template -> render(painter, m_context, titleblock_width);
105 
106  // memorize the last known width
107  m_last_known_titleblock_width = titleblock_width;
108 }
109 
115  m_rendered_template = QPicture();
116 }
117 
123  m_use_cache = use_cache;
124 }
125 
131  return(m_use_cache);
132 }
133 
const TitleBlockTemplate * titleBlockTemplate() const
const TitleBlockTemplate * m_titleblock_template
void setTitleBlockTemplate(const TitleBlockTemplate *)
void renderDxf(QRectF &, int, QString &, int)
void setContext(const DiagramContext &context)
TitleBlockTemplateRenderer::setContext.
DiagramContext context() const
TitleBlockTemplateRenderer::context.