Skip to content

Commit

Permalink
composer legend minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Mar 29, 2013
1 parent bfada31 commit 2b784a3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -123,7 +123,7 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m

if ( legend )
{
legend->model()->setHorizontalHeaderLabels( QStringList() << tr( "Item" ) << tr( "Style" ) );
legend->model()->setHorizontalHeaderLabels( QStringList() << tr( "Item" ) << tr( "Title style" ) );
mItemTreeView->setModel( legend->model() );
}

Expand Down
29 changes: 17 additions & 12 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -43,10 +43,10 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
, mSplitLayer( false )
, mEqualColumnWidth( false )
{
setStyleMargin( QgsComposerLegendStyle::Group, 2 );
setStyleMargin( QgsComposerLegendStyle::Subgroup, 2 );
setStyleMargin( QgsComposerLegendStyle::Symbol, 2 );
setStyleMargin( QgsComposerLegendStyle::SymbolLabel, 2 );
setStyleMargin( QgsComposerLegendStyle::Group, QgsComposerLegendStyle::Top, 2 );
setStyleMargin( QgsComposerLegendStyle::Subgroup, QgsComposerLegendStyle::Top, 2 );
setStyleMargin( QgsComposerLegendStyle::Symbol, QgsComposerLegendStyle::Top, 2 );
setStyleMargin( QgsComposerLegendStyle::SymbolLabel, QgsComposerLegendStyle::Top, 2 );
rstyle( QgsComposerLegendStyle::Title ).rfont().setPointSizeF( 16.0 );
rstyle( QgsComposerLegendStyle::Group ).rfont().setPointSizeF( 14.0 );
rstyle( QgsComposerLegendStyle::Subgroup ).rfont().setPointSizeF( 12.0 );
Expand Down Expand Up @@ -795,36 +795,41 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
QString titleFontString = itemElem.attribute( "titleFont" );
if ( !titleFontString.isEmpty() )
{
//mTitleFont.fromString( titleFontString );
rstyle( QgsComposerLegendStyle::Title ).rfont().fromString( titleFontString );
}
//group font
QString groupFontString = itemElem.attribute( "groupFont" );
if ( !groupFontString.isEmpty() )
{
//mGroupFont.fromString( groupFontString );
rstyle( QgsComposerLegendStyle::Group ).rfont().fromString( groupFontString );
}

//layer font
QString layerFontString = itemElem.attribute( "layerFont" );
if ( !layerFontString.isEmpty() )
{
//mLayerFont.fromString( layerFontString );
rstyle( QgsComposerLegendStyle::Subgroup ).rfont().fromString( layerFontString );
}
//item font
QString itemFontString = itemElem.attribute( "itemFont" );
if ( !itemFontString.isEmpty() )
{
//mItemFont.fromString( itemFontString );
rstyle( QgsComposerLegendStyle::SymbolLabel ).rfont().fromString( itemFontString );
}

rstyle( QgsComposerLegendStyle::Group ).setMargin( itemElem.attribute( "groupSpace", "3.0" ).toDouble() );
rstyle( QgsComposerLegendStyle::Subgroup ).setMargin( itemElem.attribute( "layerSpace", "3.0" ).toDouble() );
rstyle( QgsComposerLegendStyle::Symbol ).setMargin( itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
if ( !itemElem.attribute( "groupSpace" ).isEmpty() )
{
rstyle( QgsComposerLegendStyle::Group ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "groupSpace", "3.0" ).toDouble() );
}
if ( !itemElem.attribute( "layerSpace" ).isEmpty() )
{
rstyle( QgsComposerLegendStyle::Subgroup ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "layerSpace", "3.0" ).toDouble() );
}
if ( !itemElem.attribute( "symbolSpace" ).isEmpty() )
{
rstyle( QgsComposerLegendStyle::Symbol ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
}
// <<<<<<< < 2.0 projects backward compatibility

emit itemChanged();
Expand Down
46 changes: 23 additions & 23 deletions src/core/composer/qgscomposerlegendstyle.cpp
Expand Up @@ -31,8 +31,8 @@ QgsComposerLegendStyle::~QgsComposerLegendStyle()
{
}

void QgsComposerLegendStyle::setMargin( double margin )
{
void QgsComposerLegendStyle::setMargin( double margin )
{
mMarginMap[Top] = margin;
mMarginMap[Bottom] = margin;
mMarginMap[Left] = margin;
Expand All @@ -47,32 +47,32 @@ void QgsComposerLegendStyle::writeXML( QString name, QDomElement& elem, QDomDocu

styleElem.setAttribute( "name", name );

styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );
if ( mMarginMap[Top] != 0 ) styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
if ( mMarginMap[Bottom] != 0 ) styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
if ( mMarginMap[Left] != 0 ) styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
if ( mMarginMap[Right] != 0 ) styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );

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

elem.appendChild( styleElem );
}

void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
{
Q_UNUSED( doc );
if ( elem.isNull() ) return;

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

mMarginMap[Top] = elem.attribute( "marginTop" ).toDouble();
mMarginMap[Bottom] = elem.attribute( "marginBottom" ).toDouble();
mMarginMap[Left] = elem.attribute( "marginLeft" ).toDouble();
mMarginMap[Right] = elem.attribute( "marginRight" ).toDouble();
mMarginMap[Top] = elem.attribute( "marginTop", "0" ).toDouble();
mMarginMap[Bottom] = elem.attribute( "marginBottom", "0" ).toDouble();
mMarginMap[Left] = elem.attribute( "marginLeft", "0" ).toDouble();
mMarginMap[Right] = elem.attribute( "marginRight", "0" ).toDouble();
}

QString QgsComposerLegendStyle::styleName ( Style s )
QString QgsComposerLegendStyle::styleName( Style s )
{
switch ( s )
switch ( s )
{
case Undefined:
return "";
Expand All @@ -92,7 +92,7 @@ QString QgsComposerLegendStyle::styleName ( Style s )
return "";
}

QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName ( QString styleName )
QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName( QString styleName )
{
if ( styleName == "hidden" ) return Hidden;
else if ( styleName == "title" ) return Title;
Expand All @@ -103,24 +103,24 @@ QgsComposerLegendStyle::Style QgsComposerLegendStyle::styleFromName ( QString st
return Undefined;
}

QString QgsComposerLegendStyle::styleLabel ( Style s )
QString QgsComposerLegendStyle::styleLabel( Style s )
{
switch ( s )
switch ( s )
{
case Undefined:
return QObject::tr("Undefined");
return QObject::tr( "Undefined" );
case Hidden:
return QObject::tr("Hidden");
return QObject::tr( "Hidden" );
case Title:
return QObject::tr("Title");
return QObject::tr( "Title" );
case Group:
return QObject::tr("Group");
return QObject::tr( "Group" );
case Subgroup:
return QObject::tr("Subgroup");
return QObject::tr( "Subgroup" );
case Symbol:
return QObject::tr("Symbol");
return QObject::tr( "Symbol" );
case SymbolLabel:
return QObject::tr("Symbol label");
return QObject::tr( "Symbol label" );
}
return "";
}

0 comments on commit 2b784a3

Please sign in to comment.