Skip to content
Permalink
Browse files

Fix $CURRENT_DATE replacement in QgsComposerLabel

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Sep 26, 2012
1 parent e70b152 commit cc452d1ffc9e9e115c7818e3a63f2161fe7058cd
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/core/composer/qgscomposerlabel.cpp
@@ -84,14 +84,18 @@ QString QgsComposerLabel::displayText() const

void QgsComposerLabel::replaceDateText( QString& text ) const
{
int currentDatePos = text.indexOf( "$CURRENT_DATE" );
QString constant = "$CURRENT_DATE";
int currentDatePos = text.indexOf( constant );
if ( currentDatePos != -1 )
{
//check if there is a bracket just after $CURRENT_DATE
QString formatText;
int openingBracketPos = text.indexOf( "(", currentDatePos );
int closingBracketPos = text.indexOf( ")", openingBracketPos + 1 );
if ( openingBracketPos != -1 && closingBracketPos != -1 && ( closingBracketPos - openingBracketPos ) > 1 )
if ( openingBracketPos != -1 &&
closingBracketPos != -1 &&
( closingBracketPos - openingBracketPos ) > 1 &&
openingBracketPos == currentDatePos + constant.size() )
{
formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );

0 comments on commit cc452d1

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