Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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/qgis@10956 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 19, 2009
1 parent 07cfdda commit c24efc4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

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

Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit c24efc4

Please sign in to comment.