QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerlegendstyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlegendstyle.cpp
3  ---------------------
4  begin : March 2013
5  copyright : (C) 2013 by Radim Blazek
6  email : radim.blazek@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposerlegendstyle.h"
19 #include "qgscomposition.h"
20 #include <QFont>
21 #include <QMap>
22 #include <QString>
23 #include <QDomElement>
24 #include <QDomDocument>
25 #include <QDomNode>
26 
28 {
29  //get default composer font from settings
30  QSettings settings;
31  QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
32  if ( !defaultFontString.isEmpty() )
33  {
34  mFont.setFamily( defaultFontString );
35  }
36 }
37 
39 {
40 }
41 
42 void QgsComposerLegendStyle::setMargin( double margin )
43 {
48 }
49 
50 void QgsComposerLegendStyle::writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const
51 {
52  if ( elem.isNull() ) return;
53 
54  QDomElement styleElem = doc.createElement( "style" );
55 
56  styleElem.setAttribute( "name", name );
57 
58  if ( mMarginMap[Top] != 0 ) styleElem.setAttribute( "marginTop", QString::number( mMarginMap[Top] ) );
59  if ( mMarginMap[Bottom] != 0 ) styleElem.setAttribute( "marginBottom", QString::number( mMarginMap[Bottom] ) );
60  if ( mMarginMap[Left] != 0 ) styleElem.setAttribute( "marginLeft", QString::number( mMarginMap[Left] ) );
61  if ( mMarginMap[Right] != 0 ) styleElem.setAttribute( "marginRight", QString::number( mMarginMap[Right] ) );
62 
63  styleElem.setAttribute( "font", mFont.toString() );
64 
65  elem.appendChild( styleElem );
66 }
67 
68 void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
69 {
70  Q_UNUSED( doc );
71  if ( elem.isNull() ) return;
72 
73  mFont.fromString( elem.attribute( "font" ) );
74 
75  mMarginMap[Top] = elem.attribute( "marginTop", "0" ).toDouble();
76  mMarginMap[Bottom] = elem.attribute( "marginBottom", "0" ).toDouble();
77  mMarginMap[Left] = elem.attribute( "marginLeft", "0" ).toDouble();
78  mMarginMap[Right] = elem.attribute( "marginRight", "0" ).toDouble();
79 }
80 
82 {
83  switch ( s )
84  {
85  case Undefined:
86  return "";
87  case Hidden:
88  return "hidden";
89  case Title:
90  return "title";
91  case Group:
92  return "group";
93  case Subgroup:
94  return "subgroup";
95  case Symbol:
96  return "symbol";
97  case SymbolLabel:
98  return "symbolLabel";
99  }
100  return "";
101 }
102 
104 {
105  if ( styleName == "hidden" ) return Hidden;
106  else if ( styleName == "title" ) return Title;
107  else if ( styleName == "group" ) return Group;
108  else if ( styleName == "subgroup" ) return Subgroup;
109  else if ( styleName == "symbol" ) return Symbol;
110  else if ( styleName == "symbolLabel" ) return SymbolLabel;
111  return Undefined;
112 }
113 
115 {
116  switch ( s )
117  {
118  case Undefined:
119  return QObject::tr( "Undefined" );
120  case Hidden:
121  return QObject::tr( "Hidden" );
122  case Title:
123  return QObject::tr( "Title" );
124  case Group:
125  return QObject::tr( "Group" );
126  case Subgroup:
127  return QObject::tr( "Subgroup" );
128  case Symbol:
129  return QObject::tr( "Symbol" );
130  case SymbolLabel:
131  return QObject::tr( "Symbol label" );
132  }
133  return "";
134 }
QMap< Side, double > mMarginMap
void readXML(const QDomElement &elem, const QDomDocument &doc)
void setMargin(Side side, double margin)
static QString styleName(Style s)
Get name for style, used in project file.
static QString styleLabel(Style s)
Get style label, translated, used in UI.
static Style styleFromName(QString styleName)
Get style from name, used in project file.
void writeXML(QString name, QDomElement &elem, QDomDocument &doc) const
#define tr(sourceText)