|
65 | 65 | #include <QSizeGrip>
|
66 | 66 | #include "qgslogger.h"
|
67 | 67 |
|
68 |
| -QgsComposer::QgsComposer( QgisApp *qgis, const QString& id ): QMainWindow(), mId( id ) |
| 68 | +QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title ) |
69 | 69 | {
|
70 | 70 | setupUi( this );
|
71 |
| - setAttribute( Qt::WA_DeleteOnClose ); |
| 71 | + setWindowTitle( mTitle ); |
72 | 72 | setupTheme();
|
| 73 | + QObject::connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( close() ) ); |
73 | 74 |
|
74 | 75 | QToolButton* orderingToolButton = new QToolButton( this );
|
75 | 76 | orderingToolButton->setPopupMode( QToolButton::InstantPopup );
|
@@ -107,8 +108,6 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& id ): QMainWindow(), mId
|
107 | 108 | toggleActionGroup->addAction( mActionSelectMoveItem );
|
108 | 109 | toggleActionGroup->setExclusive( true );
|
109 | 110 |
|
110 |
| - setWindowTitle( mId ); |
111 |
| - |
112 | 111 | mActionAddNewMap->setCheckable( true );
|
113 | 112 | mActionAddNewLabel->setCheckable( true );
|
114 | 113 | mActionAddNewLegend->setCheckable( true );
|
@@ -185,6 +184,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& id ): QMainWindow(), mId
|
185 | 184 | connectSlots();
|
186 | 185 |
|
187 | 186 | mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
|
| 187 | + mComposition->setParent(mView); |
188 | 188 | mView->setComposition( mComposition );
|
189 | 189 |
|
190 | 190 | QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mCompositionOptionsFrame, mComposition );
|
@@ -297,31 +297,12 @@ void QgsComposer::open( void )
|
297 | 297 |
|
298 | 298 | void QgsComposer::activate()
|
299 | 299 | {
|
| 300 | + show(); |
300 | 301 | raise();
|
301 | 302 | setWindowState( windowState() & ~Qt::WindowMinimized );
|
302 | 303 | activateWindow();
|
303 | 304 | }
|
304 | 305 |
|
305 |
| -void QgsComposer::closeEvent( QCloseEvent *event ) |
306 |
| -{ |
307 |
| - 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 ) |
308 |
| - { |
309 |
| - mQgis->checkOutComposer( this ); |
310 |
| - event->accept(); |
311 |
| - } |
312 |
| - else |
313 |
| - { |
314 |
| - event->ignore(); |
315 |
| - } |
316 |
| -#if 0 |
317 |
| - QMainWindow::closeEvent( event ); |
318 |
| - if ( event->isAccepted() ) |
319 |
| - { |
320 |
| - QgisApp::instance()->removeWindow( mWindowAction ); |
321 |
| - } |
322 |
| -#endif //0 |
323 |
| -} |
324 |
| - |
325 | 306 | #ifdef Q_WS_MAC
|
326 | 307 | void QgsComposer::changeEvent( QEvent* event )
|
327 | 308 | {
|
@@ -351,6 +332,12 @@ void QgsComposer::showEvent( QShowEvent *event )
|
351 | 332 | }
|
352 | 333 | #endif
|
353 | 334 |
|
| 335 | +void QgsComposer::setTitle( const QString& title ) |
| 336 | +{ |
| 337 | + mTitle = title; |
| 338 | + setWindowTitle( mTitle ); |
| 339 | +} |
| 340 | + |
354 | 341 | void QgsComposer::showCompositionOptions( QWidget *w )
|
355 | 342 | {
|
356 | 343 | QWidget* currentWidget = mItemStackedWidget->currentWidget();
|
@@ -1024,7 +1011,7 @@ void QgsComposer::writeXML( QDomDocument& doc )
|
1024 | 1011 | void QgsComposer::writeXML( QDomNode& parentNode, QDomDocument& doc )
|
1025 | 1012 | {
|
1026 | 1013 | QDomElement composerElem = doc.createElement( "Composer" );
|
1027 |
| - composerElem.setAttribute( "id", mId ); |
| 1014 | + composerElem.setAttribute( "title", mTitle ); |
1028 | 1015 | parentNode.appendChild( composerElem );
|
1029 | 1016 |
|
1030 | 1017 | //store composer items:
|
@@ -1055,14 +1042,16 @@ void QgsComposer::readXML( const QDomDocument& doc )
|
1055 | 1042 |
|
1056 | 1043 | void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument& doc )
|
1057 | 1044 | {
|
1058 |
| - mId = composerElem.attribute( "id", "" ); |
1059 |
| - setWindowTitle( mId ); |
1060 |
| - |
1061 | 1045 | // Create action to select this window
|
1062 | 1046 | delete mWindowAction;
|
1063 | 1047 | mWindowAction = new QAction( windowTitle(), this );
|
1064 | 1048 | connect( mWindowAction, SIGNAL( triggered() ), this, SLOT( activate() ) );
|
1065 | 1049 |
|
| 1050 | + if ( composerElem.hasAttribute( "title" ) ) |
| 1051 | + { |
| 1052 | + setTitle( composerElem.attribute( "title", tr( "Composer" ) ) ); |
| 1053 | + } |
| 1054 | + |
1066 | 1055 | //delete composer view and composition
|
1067 | 1056 | delete mView;
|
1068 | 1057 | mView = 0;
|
@@ -1187,148 +1176,6 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
|
1187 | 1176 | setSelectionTool();
|
1188 | 1177 | }
|
1189 | 1178 |
|
1190 |
| -#if 0 |
1191 |
| -void QgsComposer::readXML( const QDomDocument& doc ) |
1192 |
| -{ |
1193 |
| - //look for Composer element |
1194 |
| - QDomNodeList nl = doc.elementsByTagName( "Composer" ); |
1195 |
| - if ( nl.size() < 1 ) |
1196 |
| - { |
1197 |
| - return; //nothing to do... |
1198 |
| - } |
1199 |
| - QDomElement composerElem = nl.at( 0 ).toElement(); |
1200 |
| - mId = composerElem.attribute( "id", "" ); |
1201 |
| - |
1202 |
| - //look for Composition element |
1203 |
| - QDomNodeList cnl = composerElem.elementsByTagName( "Composition" ); |
1204 |
| - if ( cnl.size() < 1 ) |
1205 |
| - { |
1206 |
| - return; //nothing to do |
1207 |
| - } |
1208 |
| - |
1209 |
| - |
1210 |
| - //delete composer view and composition |
1211 |
| - delete mView; |
1212 |
| - mView = 0; |
1213 |
| - //delete every child of mViewFrame |
1214 |
| - QObjectList viewFrameChildren = mViewFrame->children(); |
1215 |
| - QObjectList::iterator it = viewFrameChildren.begin(); |
1216 |
| - for ( ; it != viewFrameChildren.end(); ++it ) |
1217 |
| - { |
1218 |
| - delete( *it ); |
1219 |
| - } |
1220 |
| - //delete composition widget |
1221 |
| - QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mCompositionOptionsFrame->children().at( 0 ) ); |
1222 |
| - delete oldCompositionWidget; |
1223 |
| - delete mCompositionOptionsLayout; |
1224 |
| - mCompositionOptionsLayout = 0; |
1225 |
| - |
1226 |
| - QDomElement compositionElem = cnl.at( 0 ).toElement(); |
1227 |
| - |
1228 |
| - //todo: move in function because duplicated code with constructor |
1229 |
| - mView = new QgsComposerView( mViewFrame ); |
1230 |
| - connectSlots(); |
1231 |
| - |
1232 |
| - mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() ); |
1233 |
| - mComposition->readXML( compositionElem, doc ); |
1234 |
| - |
1235 |
| - QGridLayout *l = new QGridLayout( mViewFrame ); |
1236 |
| - l->setMargin( 0 ); |
1237 |
| - l->addWidget( mView, 0, 0 ); |
1238 |
| - |
1239 |
| - //create compositionwidget |
1240 |
| - QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mCompositionOptionsFrame, mComposition ); |
1241 |
| - QObject::connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) ); |
1242 |
| - compositionWidget->show(); |
1243 |
| - |
1244 |
| - mCompositionOptionsLayout = new QGridLayout( mCompositionOptionsFrame ); |
1245 |
| - mCompositionOptionsLayout->setMargin( 0 ); |
1246 |
| - mCompositionOptionsLayout->addWidget( compositionWidget ); |
1247 |
| - |
1248 |
| - //read and restore all the items |
1249 |
| - |
1250 |
| - //composer labels |
1251 |
| - QDomNodeList composerLabelList = composerElem.elementsByTagName( "ComposerLabel" ); |
1252 |
| - for ( int i = 0; i < composerLabelList.size(); ++i ) |
1253 |
| - { |
1254 |
| - QDomElement currentComposerLabelElem = composerLabelList.at( i ).toElement(); |
1255 |
| - QgsComposerLabel* newLabel = new QgsComposerLabel( mComposition ); |
1256 |
| - newLabel->readXML( currentComposerLabelElem, doc ); |
1257 |
| - addComposerLabel( newLabel ); |
1258 |
| - mComposition->addItem( newLabel ); |
1259 |
| - mComposition->update(); |
1260 |
| - mComposition->clearSelection(); |
1261 |
| - newLabel->setSelected( true ); |
1262 |
| - showItemOptions( newLabel ); |
1263 |
| - } |
1264 |
| - |
1265 |
| - //composer maps |
1266 |
| - QDomNodeList composerMapList = composerElem.elementsByTagName( "ComposerMap" ); |
1267 |
| - for ( int i = 0; i < composerMapList.size(); ++i ) |
1268 |
| - { |
1269 |
| - QDomElement currentComposerMapElem = composerMapList.at( i ).toElement(); |
1270 |
| - QgsComposerMap* newMap = new QgsComposerMap( mComposition ); |
1271 |
| - newMap->readXML( currentComposerMapElem, doc ); |
1272 |
| - addComposerMap( newMap ); |
1273 |
| - mComposition->addItem( newMap ); |
1274 |
| - mComposition->update(); |
1275 |
| - mComposition->clearSelection(); |
1276 |
| - newMap->setSelected( true ); |
1277 |
| - showItemOptions( newMap ); |
1278 |
| - } |
1279 |
| - |
1280 |
| - //composer scalebars |
1281 |
| - QDomNodeList composerScaleBarList = composerElem.elementsByTagName( "ComposerScaleBar" ); |
1282 |
| - for ( int i = 0; i < composerScaleBarList.size(); ++i ) |
1283 |
| - { |
1284 |
| - QDomElement currentScaleBarElem = composerScaleBarList.at( i ).toElement(); |
1285 |
| - QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar( mComposition ); |
1286 |
| - newScaleBar->readXML( currentScaleBarElem, doc ); |
1287 |
| - addComposerScaleBar( newScaleBar ); |
1288 |
| - mComposition->addItem( newScaleBar ); |
1289 |
| - mComposition->update(); |
1290 |
| - mComposition->clearSelection(); |
1291 |
| - newScaleBar->setSelected( true ); |
1292 |
| - showItemOptions( newScaleBar ); |
1293 |
| - } |
1294 |
| - |
1295 |
| - //composer legends |
1296 |
| - QDomNodeList composerLegendList = composerElem.elementsByTagName( "ComposerLegend" ); |
1297 |
| - for ( int i = 0; i < composerLegendList.size(); ++i ) |
1298 |
| - { |
1299 |
| - QDomElement currentLegendElem = composerLegendList.at( i ).toElement(); |
1300 |
| - QgsComposerLegend* newLegend = new QgsComposerLegend( mComposition ); |
1301 |
| - newLegend->readXML( currentLegendElem, doc ); |
1302 |
| - addComposerLegend( newLegend ); |
1303 |
| - mComposition->addItem( newLegend ); |
1304 |
| - mComposition->update(); |
1305 |
| - mComposition->clearSelection(); |
1306 |
| - newLegend->setSelected( true ); |
1307 |
| - showItemOptions( newLegend ); |
1308 |
| - } |
1309 |
| - |
1310 |
| - //composer pictures |
1311 |
| - QDomNodeList composerPictureList = composerElem.elementsByTagName( "ComposerPicture" ); |
1312 |
| - for ( int i = 0; i < composerPictureList.size(); ++i ) |
1313 |
| - { |
1314 |
| - QDomElement currentPictureElem = composerPictureList.at( i ).toElement(); |
1315 |
| - QgsComposerPicture* newPicture = new QgsComposerPicture( mComposition ); |
1316 |
| - newPicture->readXML( currentPictureElem, doc ); |
1317 |
| - addComposerPicture( newPicture ); |
1318 |
| - mComposition->addItem( newPicture ); |
1319 |
| - mComposition->update(); |
1320 |
| - mComposition->clearSelection(); |
1321 |
| - newPicture->setSelected( true ); |
1322 |
| - showItemOptions( newPicture ); |
1323 |
| - } |
1324 |
| - |
1325 |
| - mComposition->sortZList(); |
1326 |
| - mView->setComposition( mComposition ); |
1327 |
| - |
1328 |
| - setSelectionTool(); |
1329 |
| -} |
1330 |
| -#endif //0 |
1331 |
| - |
1332 | 1179 | void QgsComposer::addComposerMap( QgsComposerMap* map )
|
1333 | 1180 | {
|
1334 | 1181 | if ( !map )
|
|
0 commit comments