@@ -47,8 +47,9 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
47
47
double penWidth = pen ().widthF ();
48
48
QRectF painterRect ( penWidth + mMargin , penWidth + mMargin , rect ().width () - 2 * penWidth - 2 * mMargin ,
49
49
rect ().height () - 2 * penWidth - 2 * mMargin );
50
- // painter->drawText( painterRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, mText );
51
- drawText ( painter, painterRect, mText , mFont );
50
+
51
+
52
+ drawText ( painter, painterRect, displayText (), mFont );
52
53
53
54
drawFrame ( painter );
54
55
if ( isSelected () )
@@ -59,6 +60,9 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
59
60
60
61
void QgsComposerLabel::setText ( const QString& text )
61
62
{
63
+ mText = text;
64
+
65
+ #if 0
62
66
//replace '$CURRENT_DATE<(FORMAT)>' with the current date
63
67
//e.g. $CURRENT_DATE(d 'June' yyyy)
64
68
mText = text;
@@ -79,6 +83,35 @@ void QgsComposerLabel::setText( const QString& text )
79
83
mText.replace( "$CURRENT_DATE", QDate::currentDate().toString() );
80
84
}
81
85
}
86
+ #endif // 0
87
+ }
88
+
89
+ QString QgsComposerLabel::displayText () const
90
+ {
91
+ QString displayText = mText ;
92
+ replaceDateText (displayText);
93
+ return displayText;
94
+ }
95
+
96
+ void QgsComposerLabel::replaceDateText (QString& text) const
97
+ {
98
+ int currentDatePos = text.indexOf ( " $CURRENT_DATE" );
99
+ if ( currentDatePos != -1 )
100
+ {
101
+ // check if there is a bracket just after $CURRENT_DATE
102
+ QString formatText;
103
+ int openingBracketPos = text.indexOf ( " (" , currentDatePos );
104
+ int closingBracketPos = text.indexOf ( " )" , openingBracketPos + 1 );
105
+ if ( openingBracketPos != -1 && closingBracketPos != -1 && ( closingBracketPos - openingBracketPos ) > 1 )
106
+ {
107
+ formatText = text.mid ( openingBracketPos + 1 , closingBracketPos - openingBracketPos - 1 );
108
+ text.replace ( currentDatePos, closingBracketPos - currentDatePos + 1 , QDate::currentDate ().toString ( formatText ) );
109
+ }
110
+ else // no bracket
111
+ {
112
+ text.replace ( " $CURRENT_DATE" , QDate::currentDate ().toString () );
113
+ }
114
+ }
82
115
}
83
116
84
117
void QgsComposerLabel::setFont ( const QFont& f )
@@ -88,7 +121,7 @@ void QgsComposerLabel::setFont( const QFont& f )
88
121
89
122
void QgsComposerLabel::adjustSizeToText ()
90
123
{
91
- double textWidth = textWidthMillimeters ( mFont , mText );
124
+ double textWidth = textWidthMillimeters ( mFont , displayText () );
92
125
double fontAscent = fontAscentMillimeters ( mFont );
93
126
94
127
setSceneRect ( QRectF ( transform ().dx (), transform ().dy (), textWidth + 2 * mMargin + 2 * pen ().widthF () + 1 , \
0 commit comments