Skip to content
Permalink
Browse files

[FEATURE] possibility to display current date in composer label by ty…

…ping (d 'June' yyyy) or similar

git-svn-id: http://svn.osgeo.org/qgis/trunk@10956 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jun 19, 2009
1 parent b9d460b commit 730ad812c876f61ea93e7cc5269ed739c08e5bcd
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/core/composer/qgscomposerlabel.cpp
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgscomposerlabel.h"
#include <QDate>
#include <QDomElement>
#include <QPainter>

@@ -58,7 +59,26 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*

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 )

0 comments on commit 730ad81

Please sign in to comment.
You can’t perform that action at this time.