/
qgscomposer.h
346 lines (243 loc) · 10 KB
/
qgscomposer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/***************************************************************************
qgscomposer.h
-------------------
begin : January 2005
copyright : (C) 2005 by Radim Blazek
email : blazek@itc.it
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSCOMPOSER_H
#define QGSCOMPOSER_H
#include "ui_qgscomposerbase.h"
#include "qgscomposermap.h"
#include "qgscontexthelp.h"
#include <QPrinter>
#include <QDockWidget>
class QgisApp;
class QgsComposerArrow;
class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerPicture;
class QgsComposerPictureWidget;
class QgsComposerScaleBar;
class QgsComposerShape;
class QgsComposerAttributeTable;
class QgsComposerView;
class QgsComposition;
class QgsMapCanvas;
class QGridLayout;
class QDomNode;
class QDomDocument;
class QMoveEvent;
class QResizeEvent;
class QFile;
class QSizeGrip;
class QUndoView;
/** \ingroup MapComposer
* \brief A gui for composing a printable map.
*/
class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
{
Q_OBJECT
public:
QgsComposer( QgisApp *qgis, const QString& title );
~QgsComposer();
//! Set the pixmap / icons on the toolbar buttons
void setupTheme();
void setIconSizes( int size );
void setFontSize( int size );
//! Open and show, set defaults if first time
void open();
//! Zoom to full extent of the paper
void zoomFull();
//! Return pointer to map canvas
QgsMapCanvas *mapCanvas( void );
//! Return pointer to composer view
QgsComposerView *view( void );
//! Return current composition
//QgsComposition *composition(void);
//! Restore the window and toolbar state
void restoreWindowState();
QAction* windowAction() {return mWindowAction;}
const QString& title() const {return mTitle;}
void setTitle( const QString& title );
protected:
//! Move event
virtual void moveEvent( QMoveEvent * );
virtual void closeEvent( QCloseEvent * );
//! Resize event
virtual void resizeEvent( QResizeEvent * );
virtual void showEvent( QShowEvent* event );
#ifdef Q_WS_MAC
//! Change event (update window menu on ActivationChange)
virtual void changeEvent( QEvent * );
#endif
signals:
//! Is emitted every time the view zoom has changed
void zoomLevelChanged();
void composerAdded( QgsComposerView* v );
//!Composer deletes the old composerview when loading a template
void composerWillBeRemoved( QgsComposerView* v );
public slots:
//! Zoom to full extent of the paper
void on_mActionZoomAll_triggered();
//! Zoom in
void on_mActionZoomIn_triggered();
//! Zoom out
void on_mActionZoomOut_triggered();
//! Refresh view
void on_mActionRefreshView_triggered();
//! Print the composition
void on_mActionPrint_triggered();
//! Page Setup for composition
void on_mActionPageSetup_triggered();
//! Print as image
void on_mActionExportAsImage_triggered();
//! Print as SVG
void on_mActionExportAsSVG_triggered();
//! Print as PDF
void on_mActionExportAsPDF_triggered();
//! Select item
void on_mActionSelectMoveItem_triggered();
//! Add arrow
void on_mActionAddArrow_triggered();
//! Add new map
void on_mActionAddNewMap_triggered();
//! Add new legend
void on_mActionAddNewLegend_triggered();
//! Add new label
void on_mActionAddNewLabel_triggered();
//! Add new scalebar
void on_mActionAddNewScalebar_triggered();
//! Add new picture
void on_mActionAddImage_triggered();
void on_mActionAddRectangle_triggered();
void on_mActionAddTriangle_triggered();
void on_mActionAddEllipse_triggered();
//! Add attribute table
void on_mActionAddTable_triggered();
void on_mActionAddHtml_triggered();
//! Save composer as template
void on_mActionSaveAsTemplate_triggered();
void on_mActionLoadFromTemplate_triggered();
//! Set tool to move item content
void on_mActionMoveItemContent_triggered();
//! Group selected items
void on_mActionGroupItems_triggered();
//! Ungroup selected item group
void on_mActionUngroupItems_triggered();
//! Move selected items one position up
void on_mActionRaiseItems_triggered();
//!Move selected items one position down
void on_mActionLowerItems_triggered();
//!Move selected items to top
void on_mActionMoveItemsToTop_triggered();
//!Move selected items to bottom
void on_mActionMoveItemsToBottom_triggered();
//!Align selected composer items left
void on_mActionAlignLeft_triggered();
//!Align selected composere items horizontally centered
void on_mActionAlignHCenter_triggered();
//!Align selected composer items right
void on_mActionAlignRight_triggered();
//!Align selected composer items to top
void on_mActionAlignTop_triggered();
//!Align selected composer items vertically centered
void on_mActionAlignVCenter_triggered();
//!Align selected composer items to bottom
void on_mActionAlignBottom_triggered();
//!Undo last composer change
void on_mActionUndo_triggered();
//!Redo last composer change
void on_mActionRedo_triggered();
//! Save window state
void saveWindowState();
/**Add a composer arrow to the item/widget map and creates a configuration widget for it*/
void addComposerArrow( QgsComposerArrow* arrow );
/**Add a composer map to the item/widget map and creates a configuration widget for it*/
void addComposerMap( QgsComposerMap* map );
/**Adds a composer label to the item/widget map and creates a configuration widget for it*/
void addComposerLabel( QgsComposerLabel* label );
/**Adds a composer scale bar to the item/widget map and creates a configuration widget for it*/
void addComposerScaleBar( QgsComposerScaleBar* scalebar );
/**Adds a composer legend to the item/widget map and creates a configuration widget for it*/
void addComposerLegend( QgsComposerLegend* legend );
/**Adds a composer picture to the item/widget map and creates a configuration widget*/
void addComposerPicture( QgsComposerPicture* picture );
/**Adds a composer shape to the item/widget map and creates a configuration widget*/
void addComposerShape( QgsComposerShape* shape );
/**Adds a composer table to the item/widget map and creates a configuration widget*/
void addComposerTable( QgsComposerAttributeTable* table );
/**Adds composer html and creates a configuration widget*/
void addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame );
/**Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself*/
void deleteItem( QgsComposerItem* item );
/**Shows the configuration widget for a composer item*/
void showItemOptions( QgsComposerItem* i );
//XML, usually connected with QgsProject::readProject and QgsProject::writeProject
//! Stores state in Dom node
void writeXML( QDomDocument& doc );
//! Sets state from Dom document
void readXML( const QDomDocument& doc );
void readXML( const QDomElement& composerElem, const QDomDocument& doc, bool fromTemplate = false );
void setSelectionTool();
//! Raise, unminimize and activate this window
void activate();
void on_mButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
private:
/**Establishes the signal slot connection for the class*/
void connectSlots();
//! True if a composer map contains a WMS layer
bool containsWMSLayer() const;
//! Displays a warning because of possible min/max size in WMS
void showWMSPrintingWarning();
//! Changes elements that are not suitable for this project
void cleanupAfterTemplateRead();
//! Writes state under DOM element
void writeXML( QDomNode& parentNode, QDomDocument& doc );
//! Removes all the item from the graphics scene and deletes them
void deleteItemWidgets();
//! Restores composer map preview states.
//! Initially after reading from xml, states are set to rectangle to achieve faster project loading.
void restoreComposerMapStates();
//! Fills icons into composer picture widgets
//! To make loading from project faster, the previews are generated when the composer becomes visible.
void initialiseComposerPicturePreviews();
/**Composer title*/
QString mTitle;
//! Pointer to composer view
QgsComposerView *mView;
//! Current composition
QgsComposition *mComposition;
//! Pointer to QGIS application
QgisApp *mQgis;
//! The composer was opened first time (-> set defaults)
bool mFirstTime;
//! Layout
QGridLayout *mItemOptionsLayout;
//! Size grip
QSizeGrip *mSizeGrip;
//! To know which item to show if selection changes
QMap<QgsComposerItem*, QWidget*> mItemWidgetMap;
//! Window menu action to select this window
QAction *mWindowAction;
//! Page & Printer Setup
QPrinter mPrinter;
QUndoView* mUndoView;
//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
QMap< QgsComposerMap*, int > mMapsToRestore;
QList< QgsComposerPictureWidget* > mPicturePreviews;
QDockWidget* mItemDock;
QDockWidget* mUndoDock;
QDockWidget* mGeneralDock;
QMenu* mPanelMenu;
QMenu* mToolbarMenu;
};
#endif