Skip to content

Commit 2b784a3

Browse files
committedMar 29, 2013
composer legend minor fixes
1 parent bfada31 commit 2b784a3

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed
 

‎src/app/composer/qgscomposerlegendwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
123123

124124
if ( legend )
125125
{
126-
legend->model()->setHorizontalHeaderLabels( QStringList() << tr( "Item" ) << tr( "Style" ) );
126+
legend->model()->setHorizontalHeaderLabels( QStringList() << tr( "Item" ) << tr( "Title style" ) );
127127
mItemTreeView->setModel( legend->model() );
128128
}
129129

‎src/core/composer/qgscomposerlegend.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
4343
, mSplitLayer( false )
4444
, mEqualColumnWidth( false )
4545
{
46-
setStyleMargin( QgsComposerLegendStyle::Group, 2 );
47-
setStyleMargin( QgsComposerLegendStyle::Subgroup, 2 );
48-
setStyleMargin( QgsComposerLegendStyle::Symbol, 2 );
49-
setStyleMargin( QgsComposerLegendStyle::SymbolLabel, 2 );
46+
setStyleMargin( QgsComposerLegendStyle::Group, QgsComposerLegendStyle::Top, 2 );
47+
setStyleMargin( QgsComposerLegendStyle::Subgroup, QgsComposerLegendStyle::Top, 2 );
48+
setStyleMargin( QgsComposerLegendStyle::Symbol, QgsComposerLegendStyle::Top, 2 );
49+
setStyleMargin( QgsComposerLegendStyle::SymbolLabel, QgsComposerLegendStyle::Top, 2 );
5050
rstyle( QgsComposerLegendStyle::Title ).rfont().setPointSizeF( 16.0 );
5151
rstyle( QgsComposerLegendStyle::Group ).rfont().setPointSizeF( 14.0 );
5252
rstyle( QgsComposerLegendStyle::Subgroup ).rfont().setPointSizeF( 12.0 );
@@ -795,36 +795,41 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
795795
QString titleFontString = itemElem.attribute( "titleFont" );
796796
if ( !titleFontString.isEmpty() )
797797
{
798-
//mTitleFont.fromString( titleFontString );
799798
rstyle( QgsComposerLegendStyle::Title ).rfont().fromString( titleFontString );
800799
}
801800
//group font
802801
QString groupFontString = itemElem.attribute( "groupFont" );
803802
if ( !groupFontString.isEmpty() )
804803
{
805-
//mGroupFont.fromString( groupFontString );
806804
rstyle( QgsComposerLegendStyle::Group ).rfont().fromString( groupFontString );
807805
}
808806

809807
//layer font
810808
QString layerFontString = itemElem.attribute( "layerFont" );
811809
if ( !layerFontString.isEmpty() )
812810
{
813-
//mLayerFont.fromString( layerFontString );
814811
rstyle( QgsComposerLegendStyle::Subgroup ).rfont().fromString( layerFontString );
815812
}
816813
//item font
817814
QString itemFontString = itemElem.attribute( "itemFont" );
818815
if ( !itemFontString.isEmpty() )
819816
{
820-
//mItemFont.fromString( itemFontString );
821817
rstyle( QgsComposerLegendStyle::SymbolLabel ).rfont().fromString( itemFontString );
822818
}
823819

824-
rstyle( QgsComposerLegendStyle::Group ).setMargin( itemElem.attribute( "groupSpace", "3.0" ).toDouble() );
825-
rstyle( QgsComposerLegendStyle::Subgroup ).setMargin( itemElem.attribute( "layerSpace", "3.0" ).toDouble() );
826-
rstyle( QgsComposerLegendStyle::Symbol ).setMargin( itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
827-
rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
820+
if ( !itemElem.attribute( "groupSpace" ).isEmpty() )
821+
{
822+
rstyle( QgsComposerLegendStyle::Group ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "groupSpace", "3.0" ).toDouble() );
823+
}
824+
if ( !itemElem.attribute( "layerSpace" ).isEmpty() )
825+
{
826+
rstyle( QgsComposerLegendStyle::Subgroup ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "layerSpace", "3.0" ).toDouble() );
827+
}
828+
if ( !itemElem.attribute( "symbolSpace" ).isEmpty() )
829+
{
830+
rstyle( QgsComposerLegendStyle::Symbol ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
831+
rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
832+
}
828833
// <<<<<<< < 2.0 projects backward compatibility
829834

830835
emit itemChanged();

‎src/core/composer/qgscomposerlegendstyle.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ QgsComposerLegendStyle::~QgsComposerLegendStyle()
3131
{
3232
}
3333

34-
void QgsComposerLegendStyle::setMargin( double margin )
35-
{
34+
void QgsComposerLegendStyle::setMargin( double margin )
35+
{
3636
mMarginMap[Top] = margin;
3737
mMarginMap[Bottom] = margin;
3838
mMarginMap[Left] = margin;
@@ -47,32 +47,32 @@ void QgsComposerLegendStyle::writeXML( QString name, QDomElement& elem, QDomDocu
4747

4848
styleElem.setAttribute( "name", name );
4949

50-
styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
51-
styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
52-
styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
53-
styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );
50+
if ( mMarginMap[Top] != 0 ) styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
51+
if ( mMarginMap[Bottom] != 0 ) styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
52+
if ( mMarginMap[Left] != 0 ) styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
53+
if ( mMarginMap[Right] != 0 ) styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );
5454

5555
styleElem.setAttribute( "font", mFont.toString() );
5656

5757
elem.appendChild( styleElem );
5858
}
5959

60-
void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
60+
void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
6161
{
6262
Q_UNUSED( doc );
6363
if ( elem.isNull() ) return;
6464

6565
mFont.fromString( elem.attribute( "font" ) );
6666

67-
mMarginMap[Top] = elem.attribute( "marginTop" ).toDouble();
68-
mMarginMap[Bottom] = elem.attribute( "marginBottom" ).toDouble();
69-
mMarginMap[Left] = elem.attribute( "marginLeft" ).toDouble();
70-
mMarginMap[Right] = elem.attribute( "marginRight" ).toDouble();
67+
mMarginMap[Top] = elem.attribute( "marginTop", "0" ).toDouble();
68+
mMarginMap[Bottom] = elem.attribute( "marginBottom", "0" ).toDouble();
69+
mMarginMap[Left] = elem.attribute( "marginLeft", "0" ).toDouble();
70+
mMarginMap[Right] = elem.attribute( "marginRight", "0" ).toDouble();
7171
}
7272

73-
QString QgsComposerLegendStyle::styleName ( Style s )
73+
QString QgsComposerLegendStyle::styleName( Style s )
7474
{
75-
switch ( s )
75+
switch ( s )
7676
{
7777
case Undefined:
7878
return "";
@@ -92,7 +92,7 @@ QString QgsComposerLegendStyle::styleName ( Style s )
9292
return "";
9393
}
9494

95-
QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName ( QString styleName )
95+
QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName( QString styleName )
9696
{
9797
if ( styleName == "hidden" ) return Hidden;
9898
else if ( styleName == "title" ) return Title;
@@ -103,24 +103,24 @@ QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName ( QString st
103103
return Undefined;
104104
}
105105

106-
QString QgsComposerLegendStyle::styleLabel ( Style s )
106+
QString QgsComposerLegendStyle::styleLabel( Style s )
107107
{
108-
switch ( s )
108+
switch ( s )
109109
{
110110
case Undefined:
111-
return QObject::tr("Undefined");
111+
return QObject::tr( "Undefined" );
112112
case Hidden:
113-
return QObject::tr("Hidden");
113+
return QObject::tr( "Hidden" );
114114
case Title:
115-
return QObject::tr("Title");
115+
return QObject::tr( "Title" );
116116
case Group:
117-
return QObject::tr("Group");
117+
return QObject::tr( "Group" );
118118
case Subgroup:
119-
return QObject::tr("Subgroup");
119+
return QObject::tr( "Subgroup" );
120120
case Symbol:
121-
return QObject::tr("Symbol");
121+
return QObject::tr( "Symbol" );
122122
case SymbolLabel:
123-
return QObject::tr("Symbol label");
123+
return QObject::tr( "Symbol label" );
124124
}
125125
return "";
126126
}

0 commit comments

Comments
 (0)
Please sign in to comment.