Skip to content

Commit 3480ef2

Browse files
committed
[composer] Some tweaks to label display name, add display name for legends
1 parent a309a6c commit 3480ef2

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/core/composer/qgscomposerlabel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,14 @@ QString QgsComposerLabel::displayName() const
412412
return id();
413413
}
414414

415+
if ( mHtmlState )
416+
{
417+
return tr( "<HTML label>" );
418+
}
419+
415420
//if no id, default to portion of label text
416421
QString text = displayText();
417-
if ( text.isEmpty() || mHtmlState )
422+
if ( text.isEmpty() )
418423
{
419424
return tr( "<label>" );
420425
}

src/core/composer/qgscomposerlegend.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgscomposerlegenditem.h"
2222
#include "qgscomposermap.h"
2323
#include "qgscomposition.h"
24+
#include "qgscomposermodel.h"
2425
#include "qgslegendrenderer.h"
2526
#include "qgslogger.h"
2627
#include <QDomDocument>
@@ -101,7 +102,16 @@ void QgsComposerLegend::adjustBoxSize()
101102
}
102103
}
103104

104-
void QgsComposerLegend::setTitle( const QString& t ) { mSettings.setTitle( t ); }
105+
void QgsComposerLegend::setTitle( const QString& t )
106+
{
107+
mSettings.setTitle( t );
108+
109+
if ( mComposition && id().isEmpty() )
110+
{
111+
//notify the model that the display name has changed
112+
mComposition->itemsModel()->updateItemDisplayName( this );
113+
}
114+
}
105115
QString QgsComposerLegend::title() const { return mSettings.title(); }
106116

107117
Qt::AlignmentFlag QgsComposerLegend::titleAlignment() const { return mSettings.titleAlignment(); }
@@ -335,6 +345,29 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
335345
return true;
336346
}
337347

348+
QString QgsComposerLegend::displayName() const
349+
{
350+
if ( !id().isEmpty() )
351+
{
352+
return id();
353+
}
354+
355+
//if no id, default to portion of title text
356+
QString text = mSettings.title();
357+
if ( text.isEmpty() )
358+
{
359+
return tr( "<legend>" );
360+
}
361+
if ( text.length() > 25 )
362+
{
363+
return QString( tr( "%1..." ) ).arg( text.left( 25 ) );
364+
}
365+
else
366+
{
367+
return text;
368+
}
369+
}
370+
338371
void QgsComposerLegend::setComposerMap( const QgsComposerMap* map )
339372
{
340373
mComposerMap = map;

src/core/composer/qgscomposerlegend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
139139
*/
140140
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
141141

142+
//Overriden to show legend title
143+
virtual QString displayName() const;
144+
142145
public slots:
143146
/**Data changed*/
144147
void synchronizeWithModel();

0 commit comments

Comments
 (0)