Replaced the QET_TBT_USE_QPICTURE_BASED_CACHE compile-time option with a hardcoded runtime check.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1536 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-02-26 21:54:47 +00:00
parent 6199503954
commit 1e8e01c84c
4 changed files with 37 additions and 21 deletions

View File

@@ -163,13 +163,3 @@ unix {
} }
} }
} }
# From Qt 4.8, we disable the QPicture-based cache for titleblock rendering
# because it leads to bad rendering then crash.
contains(QT_VERSION, ^4\\.[0-7]\\..*) {
message("Detected Qt < 4.8: enabling QPicture-based cache for titleblock rendering.")
DEFINES += QET_TBT_USE_QPICTURE_BASED_CACHE
} else {
message("Detected Qt >= 4.8: disabling QPicture-based cache for titleblock rendering.")
}

View File

@@ -35,6 +35,11 @@ BorderTitleBlock::BorderTitleBlock(QObject *parent) :
titleblock_template_renderer = new TitleBlockTemplateRenderer(this); titleblock_template_renderer = new TitleBlockTemplateRenderer(this);
titleblock_template_renderer -> setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate()); titleblock_template_renderer -> setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate());
// disable the QPicture-based cache from Qt 4.8 to avoid rendering errors and crashes
if (!QRegExp("4\\.[0-7]\\.").exactMatch(qVersion())) {
titleblock_template_renderer -> setUseCache(false);
}
// dimensions par defaut du schema // dimensions par defaut du schema
importBorder(BorderProperties()); importBorder(BorderProperties());

View File

@@ -8,6 +8,7 @@
TitleBlockTemplateRenderer::TitleBlockTemplateRenderer(QObject *parent) : TitleBlockTemplateRenderer::TitleBlockTemplateRenderer(QObject *parent) :
QObject(parent), QObject(parent),
titleblock_template_(0), titleblock_template_(0),
use_cache_(true),
last_known_titleblock_width_(-1) last_known_titleblock_width_(-1)
{ {
} }
@@ -61,18 +62,18 @@ int TitleBlockTemplateRenderer::height() const {
void TitleBlockTemplateRenderer::render(QPainter *provided_painter, int titleblock_width) { void TitleBlockTemplateRenderer::render(QPainter *provided_painter, int titleblock_width) {
if (!titleblock_template_) return; if (!titleblock_template_) return;
#ifdef QET_TBT_USE_QPICTURE_BASED_CACHE if (use_cache_) {
// Do we really need to calculate all this again? // Do we really need to calculate all this again?
if (titleblock_width != last_known_titleblock_width_ || rendered_template_.isNull()) { if (titleblock_width != last_known_titleblock_width_ || rendered_template_.isNull()) {
renderToQPicture(titleblock_width); renderToQPicture(titleblock_width);
}
provided_painter -> save();
rendered_template_.play(provided_painter);
provided_painter -> restore();
} else {
titleblock_template_ -> render(*provided_painter, context_, titleblock_width);
} }
provided_painter -> save();
rendered_template_.play(provided_painter);
provided_painter -> restore();
#else
titleblock_template_ -> render(*provided_painter, context_, titleblock_width);
#endif
} }
/** /**
@@ -98,3 +99,20 @@ void TitleBlockTemplateRenderer::renderToQPicture(int titleblock_width) {
void TitleBlockTemplateRenderer::invalidateRenderedTemplate() { void TitleBlockTemplateRenderer::invalidateRenderedTemplate() {
rendered_template_ = QPicture(); rendered_template_ = QPicture();
} }
/**
@param use_cache true for this renderer to use its QPicture-based cache,
false otherwise.
*/
void TitleBlockTemplateRenderer::setUseCache(bool use_cache) {
use_cache_ = use_cache;
}
/**
@return true if this renderer uses its QPicture-based cache, false
otherwise.
*/
bool TitleBlockTemplateRenderer::useCache() const {
return(use_cache_);
}

View File

@@ -32,12 +32,15 @@ class TitleBlockTemplateRenderer : public QObject {
int height() const; int height() const;
void render(QPainter *, int); void render(QPainter *, int);
void invalidateRenderedTemplate(); void invalidateRenderedTemplate();
void setUseCache(bool);
bool useCache() const;
private: private:
void renderToQPicture(int); void renderToQPicture(int);
private: private:
const TitleBlockTemplate *titleblock_template_; const TitleBlockTemplate *titleblock_template_;
bool use_cache_;
QPicture rendered_template_; QPicture rendered_template_;
DiagramContext context_; DiagramContext context_;
int last_known_titleblock_width_; int last_known_titleblock_width_;