Skip to content

Commit 730ad81

Browse files
author
mhugent
committedJun 19, 2009
[FEATURE] possibility to display current date in composer label by typing (d 'June' yyyy) or similar
git-svn-id: http://svn.osgeo.org/qgis/trunk@10956 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b9d460b commit 730ad81

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎src/core/composer/qgscomposerlabel.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgscomposerlabel.h"
19+
#include <QDate>
1920
#include <QDomElement>
2021
#include <QPainter>
2122

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

5960
void QgsComposerLabel::setText( const QString& text )
6061
{
62+
//replace '$CURRENT_DATE<(FORMAT)>' with the current date
63+
//e.g. $CURRENT_DATE(d 'June' yyyy)
6164
mText = text;
65+
int currentDatePos = mText.indexOf("$CURRENT_DATE");
66+
if(currentDatePos != -1)
67+
{
68+
//check if there is a bracket just after $CURRENT_DATE
69+
QString formatText;
70+
int openingBracketPos = mText.indexOf("(", currentDatePos);
71+
int closingBracketPos = mText.indexOf(")", openingBracket + 1);
72+
if(openingBracketPos != -1 && closingBracketPos != -1 && (closingBracketPos - openingBracketPos) > 1 )
73+
{
74+
formatText = mText.mid(openingBracketPos + 1, closingBracketPos - openingBracketPos - 1);
75+
mText.replace(currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString(formatText));
76+
}
77+
else //no bracket
78+
{
79+
mText.replace("$CURRENT_DATE", QDate::currentDate().toString());
80+
}
81+
}
6282
}
6383

6484
void QgsComposerLabel::setFont( const QFont& f )

0 commit comments

Comments
 (0)
Please sign in to comment.