[QGIS Commit] r10956 - trunk/qgis/src/core/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Jun 19 01:00:10 EDT 2009
Author: mhugent
Date: 2009-06-19 01:00:09 -0400 (Fri, 19 Jun 2009)
New Revision: 10956
Modified:
trunk/qgis/src/core/composer/qgscomposerlabel.cpp
Log:
[FEATURE] possibility to display current date in composer label by typing (d 'June' yyyy) or similar
Modified: trunk/qgis/src/core/composer/qgscomposerlabel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlabel.cpp 2009-06-19 03:17:23 UTC (rev 10955)
+++ trunk/qgis/src/core/composer/qgscomposerlabel.cpp 2009-06-19 05:00:09 UTC (rev 10956)
@@ -16,6 +16,7 @@
***************************************************************************/
#include "qgscomposerlabel.h"
+#include <QDate>
#include <QDomElement>
#include <QPainter>
@@ -58,7 +59,26 @@
void QgsComposerLabel::setText( const QString& text )
{
+ //replace '$CURRENT_DATE<(FORMAT)>' with the current date
+ //e.g. $CURRENT_DATE(d 'June' yyyy)
mText = text;
+ int currentDatePos = mText.indexOf("$CURRENT_DATE");
+ if(currentDatePos != -1)
+ {
+ //check if there is a bracket just after $CURRENT_DATE
+ QString formatText;
+ int openingBracketPos = mText.indexOf("(", currentDatePos);
+ int closingBracketPos = mText.indexOf(")", openingBracket + 1);
+ if(openingBracketPos != -1 && closingBracketPos != -1 && (closingBracketPos - openingBracketPos) > 1 )
+ {
+ formatText = mText.mid(openingBracketPos + 1, closingBracketPos - openingBracketPos - 1);
+ mText.replace(currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString(formatText));
+ }
+ else //no bracket
+ {
+ mText.replace("$CURRENT_DATE", QDate::currentDate().toString());
+ }
+ }
}
void QgsComposerLabel::setFont( const QFont& f )
More information about the QGIS-commit
mailing list