Skip to content

Commit 6849406

Browse files
committed
Merge atlas branch
2 parents f1c9955 + e54e917 commit 6849406

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2807
-209
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/** \ingroup MapComposer
2+
* Class used to render an Atlas, iterating over geometry features.
3+
* prepareForFeature() modifies the atlas map's extent to zoom on the given feature.
4+
* This class is used for printing, exporting to PDF and images.
5+
* */
6+
class QgsAtlasComposition : public QObject
7+
{
8+
%TypeHeaderCode
9+
#include <qgsatlascomposition.h>
10+
%End
11+
12+
public:
13+
QgsAtlasComposition( QgsComposition* composition );
14+
~QgsAtlasComposition();
15+
16+
/** Is the atlas generation enabled ? */
17+
bool enabled() const;
18+
void setEnabled( bool e );
19+
20+
QgsComposerMap* composerMap() const;
21+
void setComposerMap( QgsComposerMap* map );
22+
23+
bool hideCoverage() const;
24+
void setHideCoverage( bool hide );
25+
26+
bool fixedScale() const;
27+
void setFixedScale( bool fixed );
28+
29+
float margin() const;
30+
void setMargin( float margin );
31+
32+
QString filenamePattern() const;
33+
void setFilenamePattern( const QString& pattern );
34+
35+
QgsVectorLayer* coverageLayer() const;
36+
void setCoverageLayer( QgsVectorLayer* lmap );
37+
38+
bool singleFile() const;
39+
void setSingleFile( bool single );
40+
41+
/** Begins the rendering. */
42+
void beginRender();
43+
/** Ends the rendering. Restores original extent */
44+
void endRender();
45+
46+
/** Returns the number of features in the coverage layer */
47+
size_t numFeatures() const;
48+
49+
/** Prepare the atlas map for the given feature. Sets the extent and context variables */
50+
void prepareForFeature( size_t i );
51+
52+
/** Returns the current filename. Must be called after prepareForFeature( i ) */
53+
const QString& currentFilename() const;
54+
55+
void writeXML( QDomElement& elem, QDomDocument& doc ) const;
56+
void readXML( const QDomElement& elem, const QDomDocument& doc );
57+
58+
QgsComposition* composition();
59+
60+
signals:
61+
/** emitted when one of the parameters changes */
62+
void parameterChanged();
63+
};

python/core/composer/qgscomposerlabel.sip

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class QgsComposerLabel : QgsComposerItem
2626
@note this function was added in version 1.2*/
2727
QString displayText() const;
2828

29+
/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions */
30+
void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions = QMap<QString, QVariant>() );
31+
2932
QFont font() const;
3033
void setFont( const QFont& f );
3134
/** Accessor for the vertical alignment of the label

python/core/composer/qgscomposition.sip

+32-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* them in a list in ascending z-Order. This list can be changed to lower/raise items one position
55
* or to bring them to front/back.
66
* */
7-
class QgsComposition: QGraphicsScene
7+
class QgsComposition : QGraphicsScene
88
{
99
%TypeHeaderCode
1010
#include <qgscomposition.h>
1111
%End
12+
1213
public:
1314

1415
/** \brief Plot type */
@@ -67,20 +68,27 @@ class QgsComposition: QGraphicsScene
6768
/**Returns pointer to undo/redo command storage*/
6869
QUndoStack* undoStack();
6970

70-
/**Returns the topmose composer item. Ignores mPaperItem*/
71+
/**Returns the topmost composer item. Ignores mPaperItem*/
7172
QgsComposerItem* composerItemAt( const QPointF & position );
7273

74+
/** Returns the page number (0-bsaed) given a coordinate */
75+
int pageNumberAt( const QPointF& position ) const;
76+
77+
/** Returns on which page number (0-based) is displayed an item */
78+
int itemPageNumber( const QgsComposerItem* ) const;
79+
7380
QList<QgsComposerItem*> selectedComposerItems();
7481

7582
/**Returns pointers to all composer maps in the scene*/
76-
//todo: needs a new mapping for QList<const T*> ?
77-
// QList<const QgsComposerMap*> composerMapItems() const;
83+
%If (QLISTCONSTPTR_CONVERSION)
84+
QList<const QgsComposerMap*> composerMapItems() const;
85+
%End
7886

7987
/**Return composer items of a specific type*/
8088
// template<class T> void composerItems( QList<T*>& itemList );
8189

8290
/**Returns the composer map with specified id
83-
@return id or 0 pointer if the composer map item does not exist*/
91+
@return QgsComposerMap or 0 pointer if the composer map item does not exist*/
8492
const QgsComposerMap* getComposerMapById( int id ) const;
8593

8694
/*Returns the composer html with specified id (a string as named in the
@@ -111,7 +119,7 @@ class QgsComposition: QGraphicsScene
111119
/**Returns pointer to map renderer of qgis map canvas*/
112120
QgsMapRenderer* mapRenderer();
113121

114-
QgsComposition::PlotStyle plotStyle();
122+
QgsComposition::PlotStyle plotStyle() const;
115123
void setPlotStyle( QgsComposition::PlotStyle style );
116124

117125
/**Returns the pixel font size for a font that has point size set.
@@ -140,8 +148,13 @@ class QgsComposition: QGraphicsScene
140148
@param doc xml document
141149
@param mapsToRestore for reading from project file: set preview move 'rectangle' to all maps and save the preview states to show composer maps on demand
142150
@param addUndoCommands insert AddItem commands if true (e.g. for copy/paste)
143-
@param pos item position. Optional, take position from xml if 0*/
144-
//void addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, QMap< QgsComposerMap*, int >* mapsToRestore, bool addUndoCommands = false, QPointF* pos = 0 );
151+
@param pos item position. Optional, take position from xml if 0
152+
@note not available in python bindings
153+
*/
154+
/*
155+
void addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, QMap< QgsComposerMap*, int >* mapsToRestore = 0,
156+
bool addUndoCommands = false, QPointF* pos = 0 );
157+
*/
145158

146159
/**Adds item to z list. Usually called from constructor of QgsComposerItem*/
147160
void addItemToZList( QgsComposerItem* item );
@@ -192,7 +205,7 @@ class QgsComposition: QGraphicsScene
192205
/**Removes multi frame (but does not delete it)*/
193206
void removeMultiFrame( QgsComposerMultiFrame* multiFrame );
194207
/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
195-
//void addComposerArrow( QgsComposerArrow* arrow );
208+
void addComposerArrow( QgsComposerArrow* arrow );
196209
/**Adds label to the graphics scene and advices composer to create a widget for it (through signal)*/
197210
void addComposerLabel( QgsComposerLabel* label );
198211
/**Adds map to the graphics scene and advices composer to create a widget for it (through signal)*/
@@ -219,10 +232,19 @@ class QgsComposition: QGraphicsScene
219232

220233
//printing
221234

222-
void exportAsPDF( const QString& file );
235+
/** Prepare the printer for printing */
236+
void beginPrint( QPrinter& printer );
237+
/** Prepare the printer for printing in a PDF */
238+
void beginPrintAsPDF( QPrinter& printer, const QString& file );
239+
/** Print on a preconfigured printer */
240+
void doPrint( QPrinter& printer, QPainter& painter );
223241

242+
/** Convenience function that prepares the printer and prints */
224243
void print( QPrinter &printer );
225244

245+
/** Convenience function that prepares the printer for printing in PDF and prints */
246+
void exportAsPDF( const QString& file );
247+
226248
//! print composer page to image
227249
//! If the image does not fit into memory, a null image is returned
228250
QImage printPageAsRaster( int page );

python/core/core.sip

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
%Include composer/qgscomposershape.sip
9999
%Include composer/qgscomposertable.sip
100100
%Include composer/qgscomposition.sip
101+
%Include composer/qgsatlascomposition.sip
101102
%Include composer/qgsdoubleboxscalebarstyle.sip
102103
%Include composer/qgslegendmodel.sip
103104
%Include composer/qgsnumericscalebarstyle.sip

python/core/qgsexpression.sip

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ class QgsExpression
4343
//! Return the number used for $rownum special column
4444
int currentRowNumber();
4545

46+
//! Assign a special column
47+
static void setSpecialColumn( const QString& name, QVariant value );
48+
//! Unset a special column
49+
static void unsetSpecialColumn( const QString& name );
50+
//! Return the value of the given special column or a null QVariant if undefined
51+
static QVariant specialColumn( const QString& name );
52+
4653
void setScale( double scale );
4754

4855
int scale();
@@ -64,7 +71,6 @@ class QgsExpression
6471
static QString replaceExpressionText( QString action, QgsFeature &feat,
6572
QgsVectorLayer* layer,
6673
const QMap<QString, QVariant> *substitutionMap = 0 );
67-
6874
//
6975

7076
enum UnaryOperator
@@ -141,6 +147,11 @@ class QgsExpression
141147
*/
142148
static int functionCount();
143149

150+
/**
151+
* Returns a list of special Column definitions
152+
*/
153+
static QList<QgsExpression::FunctionDef> specialColumns();
154+
144155
//! return quoted column reference (in double quotes)
145156
static QString quotedColumnRef( QString name );
146157
//! return quoted string (in single quotes)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h3>$feature function</h3>
2+
In atlas generation, returns the current feature number that is iterated over on the coverage layer.
3+
4+
<h4>Syntax</h4>
5+
<pre>$feature</pre>
6+
7+
<h4>Arguments</h4>
8+
None
9+
10+
<h4>Example</h4>
11+
<pre>$feature &rarr; 2</pre>
12+
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h3>$numfeatures function</h3>
2+
In atlas generation, returns the total number of features within the coverage layer.
3+
4+
<h4>Syntax</h4>
5+
<pre>$numfeatures</pre>
6+
7+
<h4>Arguments</h4>
8+
None
9+
10+
<h4>Example</h4>
11+
<pre>$numfeatures &rarr; 42</pre>
12+
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h3>$numpages function</h3>
2+
Returns the total number of pages in the composition.
3+
4+
<h4>Syntax</h4>
5+
<pre>$numpages</pre>
6+
7+
<h4>Arguments</h4>
8+
None
9+
10+
<h4>Example</h4>
11+
<pre>$numpages &rarr; 42</pre>
12+

resources/function_help/$page-en_US

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h3>$page function</h3>
2+
Returns the current page number within a composition.
3+
4+
<h4>Syntax</h4>
5+
<pre>$page</pre>
6+
7+
<h4>Arguments</h4>
8+
None
9+
10+
<h4>Example</h4>
11+
<pre>$page &rarr; 2</pre>
12+

src/app/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ SET(QGIS_APP_SRCS
126126
composer/qgscomposerlegendlayersdialog.cpp
127127
composer/qgscomposerlegendwidget.cpp
128128
composer/qgscompositionwidget.cpp
129+
composer/qgsatlascompositionwidget.cpp
129130
composer/qgsitempositiondialog.cpp
130131

131132
legend/qgslegendgroup.cpp
@@ -268,6 +269,7 @@ SET (QGIS_APP_MOC_HDRS
268269
composer/qgscomposertablewidget.h
269270
composer/qgscomposershapewidget.h
270271
composer/qgscompositionwidget.h
272+
composer/qgsatlascompositionwidget.h
271273
composer/qgsitempositiondialog.h
272274

273275
legend/qgslegend.h

0 commit comments

Comments
 (0)