Skip to content

Commit

Permalink
Fix $CURRENT_DATE replacement in QgsComposerLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier committed Sep 26, 2012
1 parent e70b152 commit cc452d1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -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 ) );
Expand Down

0 comments on commit cc452d1

Please sign in to comment.