65
65
#include < QSizeGrip>
66
66
#include " qgslogger.h"
67
67
68
- QgsComposer::QgsComposer ( QgisApp *qgis ): QMainWindow(), mFirstPaint( true )
68
+ QgsComposer::QgsComposer ( QgisApp *qgis, const QString& id ): QMainWindow(), mId( id )
69
69
{
70
70
setupUi ( this );
71
+ setAttribute ( Qt::WA_DeleteOnClose );
71
72
setupTheme ();
72
73
73
74
QToolButton* orderingToolButton = new QToolButton ( this );
@@ -106,7 +107,7 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow(), mFirstPaint( true )
106
107
toggleActionGroup->addAction ( mActionSelectMoveItem );
107
108
toggleActionGroup->setExclusive ( true );
108
109
109
- setWindowTitle ( tr ( " QGIS - print composer " ) );
110
+ setWindowTitle ( mId );
110
111
111
112
mActionAddNewMap ->setCheckable ( true );
112
113
mActionAddNewLabel ->setCheckable ( true );
@@ -116,17 +117,21 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow(), mFirstPaint( true )
116
117
mActionAddImage ->setCheckable ( true );
117
118
mActionMoveItemContent ->setCheckable ( true );
118
119
120
+ #ifdef Q_WS_MAC
119
121
QMenu *appMenu = menuBar ()->addMenu ( tr ( " QGIS" ) );
120
122
appMenu->addAction ( QgisApp::instance ()->actionAbout () );
121
123
appMenu->addAction ( QgisApp::instance ()->actionOptions () );
124
+ #endif
122
125
123
126
QMenu *fileMenu = menuBar ()->addMenu ( tr ( " File" ) );
124
- fileMenu->addAction ( tr ( " Close" ), this , SLOT ( close () ), tr ( " Ctrl+W" ) );
125
127
fileMenu->addAction ( mActionExportAsImage );
126
128
fileMenu->addAction ( mActionExportAsPDF );
127
129
fileMenu->addAction ( mActionExportAsSVG );
128
130
fileMenu->addSeparator ();
129
131
fileMenu->addAction ( mActionPrint );
132
+ fileMenu->addSeparator ();
133
+ fileMenu->addAction ( mActionQuit );
134
+ QObject::connect ( mActionQuit , SIGNAL ( triggered () ), this , SLOT ( close () ) );
130
135
131
136
QMenu *viewMenu = menuBar ()->addMenu ( tr ( " View" ) );
132
137
viewMenu->addAction ( mActionZoomIn );
@@ -159,14 +164,13 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow(), mFirstPaint( true )
159
164
#endif
160
165
#endif
161
166
167
+ mQgis = qgis;
168
+ mFirstTime = true ;
162
169
163
- // Create action to select this window and add it to Window menu
170
+ // Create action to select this window
164
171
mWindowAction = new QAction ( windowTitle (), this );
165
172
connect ( mWindowAction , SIGNAL ( triggered () ), this , SLOT ( activate () ) );
166
173
167
- mQgis = qgis;
168
- mFirstTime = true ;
169
-
170
174
QgsDebugMsg ( " entered." );
171
175
172
176
setMouseTracking ( true );
@@ -188,8 +192,6 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow(), mFirstPaint( true )
188
192
mCompositionOptionsLayout ->setMargin ( 0 );
189
193
mCompositionOptionsLayout ->addWidget ( compositionWidget );
190
194
191
- mPrinter = 0 ;
192
-
193
195
QGridLayout *l = new QGridLayout ( mViewFrame );
194
196
l->setMargin ( 0 );
195
197
l->addWidget ( mView , 0 , 0 );
@@ -206,10 +208,9 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow(), mFirstPaint( true )
206
208
207
209
mView ->setFocus ();
208
210
209
- // connect with signals from QgsProject to read/ write project files
211
+ // connect with signals from QgsProject to write project files
210
212
if ( QgsProject::instance () )
211
213
{
212
- connect ( QgsProject::instance (), SIGNAL ( readProject ( const QDomDocument& ) ), this , SLOT ( readXML ( const QDomDocument& ) ) );
213
214
connect ( QgsProject::instance (), SIGNAL ( writeProject ( QDomDocument& ) ), this , SLOT ( writeXML ( QDomDocument& ) ) );
214
215
}
215
216
}
@@ -229,6 +230,7 @@ void QgsComposer::setupTheme()
229
230
{
230
231
// now set all the icons - getThemeIcon will fall back to default theme if its
231
232
// missing from active theme
233
+ mActionQuit ->setIcon ( QgisApp::getThemeIcon ( " /mActionFileExit.png" ) );
232
234
mActionLoadFromTemplate ->setIcon ( QgisApp::getThemeIcon ( " /mActionFileOpen.png" ) );
233
235
mActionSaveAsTemplate ->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSaveAs.png" ) );
234
236
mActionExportAsImage ->setIcon ( QgisApp::getThemeIcon ( " /mActionSaveMapAsImage.png" ) );
@@ -290,36 +292,33 @@ void QgsComposer::open( void )
290
292
}
291
293
}
292
294
293
- void QgsComposer::paintEvent ( QPaintEvent* event )
294
- {
295
- QMainWindow::paintEvent ( event );
296
- #if 0 //MH: disabled for now as there are segfaults on some systems
297
- //The cached content of the composer maps need to be recreated it is the first paint event of the composer after reading from XML file.
298
- //Otherwise the resolution of the composer map is not suitable for screen
299
- if ( mFirstPaint )
300
- {
301
- QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
302
- for ( ; it != mItemWidgetMap.constEnd(); ++it )
303
- {
304
- QgsComposerMap* cm = qobject_cast<QgsComposerMap *>( it.key() );
305
- if ( cm )
306
- {
307
- mFirstPaint = false;
308
- cm->cache();
309
- cm->update();
310
- }
311
- }
312
- }
313
- #endif // 0
314
- }
315
-
316
295
void QgsComposer::activate ()
317
296
{
318
297
raise ();
319
298
setWindowState ( windowState () & ~Qt::WindowMinimized );
320
299
activateWindow ();
321
300
}
322
301
302
+ void QgsComposer::closeEvent ( QCloseEvent *event )
303
+ {
304
+ if ( QMessageBox::warning ( 0 , tr ( " Remove composer?" ), tr ( " Do you really want to remove the composer instance '%1'?" ).arg ( mId ), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) == QMessageBox::Ok )
305
+ {
306
+ mQgis ->checkOutComposer ( this );
307
+ event->accept ();
308
+ }
309
+ else
310
+ {
311
+ event->ignore ();
312
+ }
313
+ #if 0
314
+ QMainWindow::closeEvent( event );
315
+ if ( event->isAccepted() )
316
+ {
317
+ QgisApp::instance()->removeWindow( mWindowAction );
318
+ }
319
+ #endif // 0
320
+ }
321
+
323
322
#ifdef Q_WS_MAC
324
323
void QgsComposer::changeEvent ( QEvent* event )
325
324
{
@@ -338,15 +337,6 @@ void QgsComposer::changeEvent( QEvent* event )
338
337
}
339
338
}
340
339
341
- void QgsComposer::closeEvent ( QCloseEvent *event )
342
- {
343
- QMainWindow::closeEvent ( event );
344
- if ( event->isAccepted () )
345
- {
346
- QgisApp::instance ()->removeWindow ( mWindowAction );
347
- }
348
- }
349
-
350
340
void QgsComposer::showEvent ( QShowEvent *event )
351
341
{
352
342
QMainWindow::showEvent ( event );
@@ -1031,6 +1021,7 @@ void QgsComposer::writeXML( QDomDocument& doc )
1031
1021
void QgsComposer::writeXML ( QDomNode& parentNode, QDomDocument& doc )
1032
1022
{
1033
1023
QDomElement composerElem = doc.createElement ( " Composer" );
1024
+ composerElem.setAttribute ( " id" , mId );
1034
1025
parentNode.appendChild ( composerElem );
1035
1026
1036
1027
// store composer items:
@@ -1049,6 +1040,145 @@ void QgsComposer::writeXML( QDomNode& parentNode, QDomDocument& doc )
1049
1040
}
1050
1041
}
1051
1042
1043
+ void QgsComposer::readXML ( const QDomDocument& doc )
1044
+ {
1045
+ QDomNodeList composerNodeList = doc.elementsByTagName ( " Composer" );
1046
+ if ( composerNodeList.size () < 1 )
1047
+ {
1048
+ return ;
1049
+ }
1050
+ readXML ( composerNodeList.at ( 0 ).toElement (), doc );
1051
+ }
1052
+
1053
+ void QgsComposer::readXML ( const QDomElement& composerElem, const QDomDocument& doc )
1054
+ {
1055
+ mId = composerElem.attribute ( " id" , " " );
1056
+ setWindowTitle ( mId );
1057
+
1058
+ // Create action to select this window
1059
+ delete mWindowAction ;
1060
+ mWindowAction = new QAction ( windowTitle (), this );
1061
+ connect ( mWindowAction , SIGNAL ( triggered () ), this , SLOT ( activate () ) );
1062
+
1063
+ // delete composer view and composition
1064
+ delete mView ;
1065
+ mView = 0 ;
1066
+ // delete every child of mViewFrame
1067
+ QObjectList viewFrameChildren = mViewFrame ->children ();
1068
+ QObjectList::iterator it = viewFrameChildren.begin ();
1069
+ for ( ; it != viewFrameChildren.end (); ++it )
1070
+ {
1071
+ delete ( *it );
1072
+ }
1073
+ // delete composition widget
1074
+ QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mCompositionOptionsFrame ->children ().at ( 0 ) );
1075
+ delete oldCompositionWidget;
1076
+ delete mCompositionOptionsLayout ;
1077
+ mCompositionOptionsLayout = 0 ;
1078
+
1079
+ mView = new QgsComposerView ( mViewFrame );
1080
+ connectSlots ();
1081
+
1082
+ mComposition = new QgsComposition ( mQgis ->mapCanvas ()->mapRenderer () );
1083
+ mComposition ->readXML ( composerElem, doc );
1084
+
1085
+ QGridLayout *l = new QGridLayout ( mViewFrame );
1086
+ l->setMargin ( 0 );
1087
+ l->addWidget ( mView , 0 , 0 );
1088
+
1089
+ // create compositionwidget
1090
+ QgsCompositionWidget* compositionWidget = new QgsCompositionWidget ( mCompositionOptionsFrame , mComposition );
1091
+ QObject::connect ( mComposition , SIGNAL ( paperSizeChanged () ), compositionWidget, SLOT ( displayCompositionWidthHeight () ) );
1092
+ compositionWidget->show ();
1093
+
1094
+ mCompositionOptionsLayout = new QGridLayout ( mCompositionOptionsFrame );
1095
+ mCompositionOptionsLayout ->setMargin ( 0 );
1096
+ mCompositionOptionsLayout ->addWidget ( compositionWidget );
1097
+
1098
+ // read and restore all the items
1099
+
1100
+ // composer labels
1101
+ QDomNodeList composerLabelList = composerElem.elementsByTagName ( " ComposerLabel" );
1102
+ for ( int i = 0 ; i < composerLabelList.size (); ++i )
1103
+ {
1104
+ QDomElement currentComposerLabelElem = composerLabelList.at ( i ).toElement ();
1105
+ QgsComposerLabel* newLabel = new QgsComposerLabel ( mComposition );
1106
+ newLabel->readXML ( currentComposerLabelElem, doc );
1107
+ addComposerLabel ( newLabel );
1108
+ mComposition ->addItem ( newLabel );
1109
+ mComposition ->update ();
1110
+ mComposition ->clearSelection ();
1111
+ newLabel->setSelected ( true );
1112
+ showItemOptions ( newLabel );
1113
+ }
1114
+
1115
+ // composer maps
1116
+ QDomNodeList composerMapList = composerElem.elementsByTagName ( " ComposerMap" );
1117
+ for ( int i = 0 ; i < composerMapList.size (); ++i )
1118
+ {
1119
+ QDomElement currentComposerMapElem = composerMapList.at ( i ).toElement ();
1120
+ QgsComposerMap* newMap = new QgsComposerMap ( mComposition );
1121
+ newMap->readXML ( currentComposerMapElem, doc );
1122
+ addComposerMap ( newMap );
1123
+ mComposition ->addItem ( newMap );
1124
+ mComposition ->update ();
1125
+ mComposition ->clearSelection ();
1126
+ newMap->setSelected ( true );
1127
+ showItemOptions ( newMap );
1128
+ }
1129
+
1130
+ // composer scalebars
1131
+ QDomNodeList composerScaleBarList = composerElem.elementsByTagName ( " ComposerScaleBar" );
1132
+ for ( int i = 0 ; i < composerScaleBarList.size (); ++i )
1133
+ {
1134
+ QDomElement currentScaleBarElem = composerScaleBarList.at ( i ).toElement ();
1135
+ QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar ( mComposition );
1136
+ newScaleBar->readXML ( currentScaleBarElem, doc );
1137
+ addComposerScaleBar ( newScaleBar );
1138
+ mComposition ->addItem ( newScaleBar );
1139
+ mComposition ->update ();
1140
+ mComposition ->clearSelection ();
1141
+ newScaleBar->setSelected ( true );
1142
+ showItemOptions ( newScaleBar );
1143
+ }
1144
+
1145
+ // composer legends
1146
+ QDomNodeList composerLegendList = composerElem.elementsByTagName ( " ComposerLegend" );
1147
+ for ( int i = 0 ; i < composerLegendList.size (); ++i )
1148
+ {
1149
+ QDomElement currentLegendElem = composerLegendList.at ( i ).toElement ();
1150
+ QgsComposerLegend* newLegend = new QgsComposerLegend ( mComposition );
1151
+ newLegend->readXML ( currentLegendElem, doc );
1152
+ addComposerLegend ( newLegend );
1153
+ mComposition ->addItem ( newLegend );
1154
+ mComposition ->update ();
1155
+ mComposition ->clearSelection ();
1156
+ newLegend->setSelected ( true );
1157
+ showItemOptions ( newLegend );
1158
+ }
1159
+
1160
+ // composer pictures
1161
+ QDomNodeList composerPictureList = composerElem.elementsByTagName ( " ComposerPicture" );
1162
+ for ( int i = 0 ; i < composerPictureList.size (); ++i )
1163
+ {
1164
+ QDomElement currentPictureElem = composerPictureList.at ( i ).toElement ();
1165
+ QgsComposerPicture* newPicture = new QgsComposerPicture ( mComposition );
1166
+ newPicture->readXML ( currentPictureElem, doc );
1167
+ addComposerPicture ( newPicture );
1168
+ mComposition ->addItem ( newPicture );
1169
+ mComposition ->update ();
1170
+ mComposition ->clearSelection ();
1171
+ newPicture->setSelected ( true );
1172
+ showItemOptions ( newPicture );
1173
+ }
1174
+
1175
+ mComposition ->sortZList ();
1176
+ mView ->setComposition ( mComposition );
1177
+
1178
+ setSelectionTool ();
1179
+ }
1180
+
1181
+ #if 0
1052
1182
void QgsComposer::readXML( const QDomDocument& doc )
1053
1183
{
1054
1184
//look for Composer element
@@ -1058,6 +1188,7 @@ void QgsComposer::readXML( const QDomDocument& doc )
1058
1188
return; //nothing to do...
1059
1189
}
1060
1190
QDomElement composerElem = nl.at( 0 ).toElement();
1191
+ mId = composerElem.attribute( "id", "" );
1061
1192
1062
1193
//look for Composition element
1063
1194
QDomNodeList cnl = composerElem.elementsByTagName( "Composition" );
@@ -1187,6 +1318,7 @@ void QgsComposer::readXML( const QDomDocument& doc )
1187
1318
1188
1319
setSelectionTool();
1189
1320
}
1321
+ #endif // 0
1190
1322
1191
1323
void QgsComposer::addComposerMap ( QgsComposerMap* map )
1192
1324
{
0 commit comments