[qet] [1536] Replaced the QET_TBT_USE_QPICTURE_BASED_CACHE compile-time option with a hardcoded runtime check .

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1536
Author:   xavier
Date:     2012-02-26 22:54:47 +0100 (Sun, 26 Feb 2012)
Log Message:
-----------
Replaced the QET_TBT_USE_QPICTURE_BASED_CACHE compile-time option with a hardcoded runtime check.

Modified Paths:
--------------
    branches/0.3/qelectrotech.pro
    branches/0.3/sources/bordertitleblock.cpp
    branches/0.3/sources/titleblocktemplaterenderer.cpp
    branches/0.3/sources/titleblocktemplaterenderer.h

Modified: branches/0.3/qelectrotech.pro
===================================================================
--- branches/0.3/qelectrotech.pro	2012-02-26 21:00:56 UTC (rev 1535)
+++ branches/0.3/qelectrotech.pro	2012-02-26 21:54:47 UTC (rev 1536)
@@ -163,13 +163,3 @@
 		}
 	}
 }
-
-# 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.")
-}
-

Modified: branches/0.3/sources/bordertitleblock.cpp
===================================================================
--- branches/0.3/sources/bordertitleblock.cpp	2012-02-26 21:00:56 UTC (rev 1535)
+++ branches/0.3/sources/bordertitleblock.cpp	2012-02-26 21:54:47 UTC (rev 1536)
@@ -35,6 +35,11 @@
 	titleblock_template_renderer = new TitleBlockTemplateRenderer(this);
 	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
 	importBorder(BorderProperties());
 	

Modified: branches/0.3/sources/titleblocktemplaterenderer.cpp
===================================================================
--- branches/0.3/sources/titleblocktemplaterenderer.cpp	2012-02-26 21:00:56 UTC (rev 1535)
+++ branches/0.3/sources/titleblocktemplaterenderer.cpp	2012-02-26 21:54:47 UTC (rev 1536)
@@ -8,6 +8,7 @@
 TitleBlockTemplateRenderer::TitleBlockTemplateRenderer(QObject *parent) :
 	QObject(parent),
 	titleblock_template_(0),
+	use_cache_(true),
 	last_known_titleblock_width_(-1)
 {
 }
@@ -61,18 +62,18 @@
 void TitleBlockTemplateRenderer::render(QPainter *provided_painter, int titleblock_width) {
 	if (!titleblock_template_) return;
 	
-#ifdef QET_TBT_USE_QPICTURE_BASED_CACHE
-	// Do we really need to calculate all this again?
-	if (titleblock_width != last_known_titleblock_width_ || rendered_template_.isNull()) {
-		renderToQPicture(titleblock_width);
+	if (use_cache_) {
+		// Do we really need to calculate all this again?
+		if (titleblock_width != last_known_titleblock_width_ || rendered_template_.isNull()) {
+			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::invalidateRenderedTemplate() {
 	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_);
+}
+

Modified: branches/0.3/sources/titleblocktemplaterenderer.h
===================================================================
--- branches/0.3/sources/titleblocktemplaterenderer.h	2012-02-26 21:00:56 UTC (rev 1535)
+++ branches/0.3/sources/titleblocktemplaterenderer.h	2012-02-26 21:54:47 UTC (rev 1536)
@@ -32,12 +32,15 @@
 	int height() const;
 	void render(QPainter *, int);
 	void invalidateRenderedTemplate();
+	void setUseCache(bool);
+	bool useCache() const;
 	
 	private:
 	void renderToQPicture(int);
 	
 	private:
 	const TitleBlockTemplate *titleblock_template_;
+	bool use_cache_;
 	QPicture rendered_template_;
 	DiagramContext context_;
 	int last_known_titleblock_width_;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/