QGIS API Documentation  2.0.1-Dufour
 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 : [email protected]
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 <QFont>
20 #include <QMap>
21 #include <QString>
22 #include <QDomElement>
23 #include <QDomDocument>
24 #include <QDomNode>
25 
27 {
28 }
29 
31 {
32 }
33 
34 void QgsComposerLegendStyle::setMargin( double margin )
35 {
40 }
41 
42 void QgsComposerLegendStyle::writeXML( QString name, QDomElement& elem, QDomDocument & doc ) const
43 {
44  if ( elem.isNull() ) return;
45 
46  QDomElement styleElem = doc.createElement( "style" );
47 
48  styleElem.setAttribute( "name", name );
49 
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] ) );
54 
55  styleElem.setAttribute( "font", mFont.toString() );
56 
57  elem.appendChild( styleElem );
58 }
59 
60 void QgsComposerLegendStyle::readXML( const QDomElement& elem, const QDomDocument& doc )
61 {
62  Q_UNUSED( doc );
63  if ( elem.isNull() ) return;
64 
65  mFont.fromString( elem.attribute( "font" ) );
66 
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();
71 }
72 
74 {
75  switch ( s )
76  {
77  case Undefined:
78  return "";
79  case Hidden:
80  return "hidden";
81  case Title:
82  return "title";
83  case Group:
84  return "group";
85  case Subgroup:
86  return "subgroup";
87  case Symbol:
88  return "symbol";
89  case SymbolLabel:
90  return "symbolLabel";
91  }
92  return "";
93 }
94 
96 {
97  if ( styleName == "hidden" ) return Hidden;
98  else if ( styleName == "title" ) return Title;
99  else if ( styleName == "group" ) return Group;
100  else if ( styleName == "subgroup" ) return Subgroup;
101  else if ( styleName == "symbol" ) return Symbol;
102  else if ( styleName == "symbolLabel" ) return SymbolLabel;
103  return Undefined;
104 }
105 
107 {
108  switch ( s )
109  {
110  case Undefined:
111  return QObject::tr( "Undefined" );
112  case Hidden:
113  return QObject::tr( "Hidden" );
114  case Title:
115  return QObject::tr( "Title" );
116  case Group:
117  return QObject::tr( "Group" );
118  case Subgroup:
119  return QObject::tr( "Subgroup" );
120  case Symbol:
121  return QObject::tr( "Symbol" );
122  case SymbolLabel:
123  return QObject::tr( "Symbol label" );
124  }
125  return "";
126 }