Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgscomposition.cpp 00003 ------------------- 00004 begin : January 2005 00005 copyright : (C) 2005 by Radim Blazek 00006 email : blazek@itc.it 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include "qgscomposition.h" 00018 #include "qgscomposeritem.h" 00019 #include "qgscomposermap.h" 00020 #include "qgspaperitem.h" 00021 #include "qgslogger.h" 00022 #include <QDomDocument> 00023 #include <QDomElement> 00024 #include <QGraphicsRectItem> 00025 #include <QSettings> 00026 00027 QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ): 00028 QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSnapToGrid( false ), 00029 mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 ) 00030 { 00031 setBackgroundBrush( Qt::gray ); 00032 00033 //set paper item 00034 mPaperItem = new QgsPaperItem( 0, 0, 297, 210, this ); //default size A4 00035 mPaperItem->setBrush( Qt::white ); 00036 addItem( mPaperItem ); 00037 mPaperItem->setZValue( 0 ); 00038 mPrintResolution = 300; //hardcoded default 00039 loadGridAppearanceSettings(); 00040 } 00041 00042 QgsComposition::QgsComposition(): 00043 QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), 00044 mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 ) 00045 { 00046 loadGridAppearanceSettings(); 00047 } 00048 00049 QgsComposition::~QgsComposition() 00050 { 00051 delete mPaperItem; 00052 00053 // make sure that all composer items are removed before 00054 // this class is deconstructed - to avoid segfaults 00055 // when composer items access in destructor composition that isn't valid anymore 00056 clear(); 00057 } 00058 00059 void QgsComposition::setPaperSize( double width, double height ) 00060 { 00061 if ( mPaperItem ) 00062 { 00063 mPaperItem->setRect( QRectF( 0, 0, width, height ) ); 00064 emit paperSizeChanged(); 00065 } 00066 } 00067 00068 double QgsComposition::paperHeight() const 00069 { 00070 return mPaperItem->rect().height(); 00071 } 00072 00073 double QgsComposition::paperWidth() const 00074 { 00075 return mPaperItem->rect().width(); 00076 } 00077 00078 QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position ) 00079 { 00080 QList<QGraphicsItem *> itemList = items( position ); 00081 QList<QGraphicsItem *>::iterator itemIt = itemList.begin(); 00082 00083 for ( ; itemIt != itemList.end(); ++itemIt ) 00084 { 00085 QgsComposerItem* composerItem = dynamic_cast<QgsComposerItem *>( *itemIt ); 00086 if ( composerItem && composerItem != mPaperItem ) 00087 { 00088 return composerItem; 00089 } 00090 } 00091 return 0; 00092 } 00093 00094 QList<QgsComposerItem*> QgsComposition::selectedComposerItems() 00095 { 00096 QList<QgsComposerItem*> composerItemList; 00097 00098 QList<QGraphicsItem *> graphicsItemList = selectedItems(); 00099 QList<QGraphicsItem *>::iterator itemIter = graphicsItemList.begin(); 00100 00101 for ( ; itemIter != graphicsItemList.end(); ++itemIter ) 00102 { 00103 QgsComposerItem* composerItem = dynamic_cast<QgsComposerItem *>( *itemIter ); 00104 if ( composerItem ) 00105 { 00106 composerItemList.push_back( composerItem ); 00107 } 00108 } 00109 00110 return composerItemList; 00111 } 00112 00113 QList<const QgsComposerMap*> QgsComposition::composerMapItems() const 00114 { 00115 QList<const QgsComposerMap*> resultList; 00116 00117 QList<QGraphicsItem *> itemList = items(); 00118 QList<QGraphicsItem *>::iterator itemIt = itemList.begin(); 00119 for ( ; itemIt != itemList.end(); ++itemIt ) 00120 { 00121 const QgsComposerMap* composerMap = dynamic_cast<const QgsComposerMap *>( *itemIt ); 00122 if ( composerMap ) 00123 { 00124 resultList.push_back( composerMap ); 00125 } 00126 } 00127 00128 return resultList; 00129 } 00130 00131 const QgsComposerMap* QgsComposition::getComposerMapById( int id ) const 00132 { 00133 QList<const QgsComposerMap*> resultList; 00134 00135 QList<QGraphicsItem *> itemList = items(); 00136 QList<QGraphicsItem *>::iterator itemIt = itemList.begin(); 00137 for ( ; itemIt != itemList.end(); ++itemIt ) 00138 { 00139 const QgsComposerMap* composerMap = dynamic_cast<const QgsComposerMap *>( *itemIt ); 00140 if ( composerMap ) 00141 { 00142 if ( composerMap->id() == id ) 00143 { 00144 return composerMap; 00145 } 00146 } 00147 } 00148 00149 return 0; 00150 } 00151 00152 int QgsComposition::pixelFontSize( double pointSize ) const 00153 { 00154 //in QgsComposition, one unit = one mm 00155 double sizeMillimeters = pointSize * 0.3527; 00156 return ( sizeMillimeters + 0.5 ); //round to nearest mm 00157 } 00158 00159 double QgsComposition::pointFontSize( int pixelSize ) const 00160 { 00161 double sizePoint = pixelSize / 0.3527; 00162 return sizePoint; 00163 } 00164 00165 bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc ) 00166 { 00167 if ( composerElem.isNull() ) 00168 { 00169 return false; 00170 } 00171 00172 QDomElement compositionElem = doc.createElement( "Composition" ); 00173 if ( mPaperItem ) 00174 { 00175 compositionElem.setAttribute( "paperWidth", mPaperItem->rect().width() ); 00176 compositionElem.setAttribute( "paperHeight", mPaperItem->rect().height() ); 00177 } 00178 00179 //snapping 00180 if ( mSnapToGrid ) 00181 { 00182 compositionElem.setAttribute( "snapping", "1" ); 00183 } 00184 else 00185 { 00186 compositionElem.setAttribute( "snapping", "0" ); 00187 } 00188 compositionElem.setAttribute( "snapGridResolution", mSnapGridResolution ); 00189 compositionElem.setAttribute( "snapGridOffsetX", mSnapGridOffsetX ); 00190 compositionElem.setAttribute( "snapGridOffsetY", mSnapGridOffsetY ); 00191 00192 compositionElem.setAttribute( "printResolution", mPrintResolution ); 00193 compositionElem.setAttribute( "printAsRaster", mPrintAsRaster ); 00194 00195 composerElem.appendChild( compositionElem ); 00196 00197 return true; 00198 } 00199 00200 bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocument& doc ) 00201 { 00202 if ( compositionElem.isNull() ) 00203 { 00204 return false; 00205 } 00206 00207 //create paper item 00208 bool widthConversionOk, heightConversionOk; 00209 double paperWidth = compositionElem.attribute( "paperWidth" ).toDouble( &widthConversionOk ); 00210 double paperHeight = compositionElem.attribute( "paperHeight" ).toDouble( &heightConversionOk ); 00211 00212 if ( widthConversionOk && heightConversionOk ) 00213 { 00214 delete mPaperItem; 00215 mPaperItem = new QgsPaperItem( 0, 0, paperWidth, paperHeight, this ); 00216 mPaperItem->setBrush( Qt::white ); 00217 addItem( mPaperItem ); 00218 mPaperItem->setZValue( 0 ); 00219 } 00220 00221 //snapping 00222 if ( compositionElem.attribute( "snapping" ) == "0" ) 00223 { 00224 mSnapToGrid = false; 00225 } 00226 else 00227 { 00228 mSnapToGrid = true; 00229 } 00230 mSnapGridResolution = compositionElem.attribute( "snapGridResolution" ).toDouble(); 00231 mSnapGridOffsetX = compositionElem.attribute( "snapGridOffsetX" ).toDouble(); 00232 mSnapGridOffsetY = compositionElem.attribute( "snapGridOffsetY" ).toDouble(); 00233 mPrintAsRaster = compositionElem.attribute( "printAsRaster" ).toInt(); 00234 00235 mPrintResolution = compositionElem.attribute( "printResolution", "300" ).toInt(); 00236 00237 if ( mPaperItem ) 00238 { 00239 mPaperItem->update(); 00240 } 00241 00242 return true; 00243 } 00244 00245 void QgsComposition::addItemToZList( QgsComposerItem* item ) 00246 { 00247 if ( !item ) 00248 { 00249 return; 00250 } 00251 mItemZList.push_back( item ); 00252 QgsDebugMsg( QString::number( mItemZList.size() ) ); 00253 item->setZValue( mItemZList.size() ); 00254 } 00255 00256 void QgsComposition::removeItemFromZList( QgsComposerItem* item ) 00257 { 00258 if ( !item ) 00259 { 00260 return; 00261 } 00262 mItemZList.removeAll( item ); 00263 } 00264 00265 void QgsComposition::raiseSelectedItems() 00266 { 00267 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00268 QList<QgsComposerItem*>::iterator it = selectedItems.begin(); 00269 for ( ; it != selectedItems.end(); ++it ) 00270 { 00271 raiseItem( *it ); 00272 } 00273 00274 //update all positions 00275 updateZValues(); 00276 update(); 00277 } 00278 00279 void QgsComposition::raiseItem( QgsComposerItem* item ) 00280 { 00281 //search item 00282 QMutableLinkedListIterator<QgsComposerItem*> it( mItemZList ); 00283 if ( it.findNext( item ) ) 00284 { 00285 if ( it.hasNext() ) 00286 { 00287 it.remove(); 00288 it.next(); 00289 it.insert( item ); 00290 } 00291 } 00292 } 00293 00294 void QgsComposition::lowerSelectedItems() 00295 { 00296 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00297 QList<QgsComposerItem*>::iterator it = selectedItems.begin(); 00298 for ( ; it != selectedItems.end(); ++it ) 00299 { 00300 lowerItem( *it ); 00301 } 00302 00303 //update all positions 00304 updateZValues(); 00305 update(); 00306 } 00307 00308 void QgsComposition::lowerItem( QgsComposerItem* item ) 00309 { 00310 //search item 00311 QMutableLinkedListIterator<QgsComposerItem*> it( mItemZList ); 00312 if ( it.findNext( item ) ) 00313 { 00314 it.previous(); 00315 if ( it.hasPrevious() ) 00316 { 00317 it.remove(); 00318 it.previous(); 00319 it.insert( item ); 00320 } 00321 } 00322 } 00323 00324 void QgsComposition::moveSelectedItemsToTop() 00325 { 00326 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00327 QList<QgsComposerItem*>::iterator it = selectedItems.begin(); 00328 00329 for ( ; it != selectedItems.end(); ++it ) 00330 { 00331 moveItemToTop( *it ); 00332 } 00333 00334 //update all positions 00335 updateZValues(); 00336 update(); 00337 } 00338 00339 void QgsComposition::moveItemToTop( QgsComposerItem* item ) 00340 { 00341 //search item 00342 QMutableLinkedListIterator<QgsComposerItem*> it( mItemZList ); 00343 if ( it.findNext( item ) ) 00344 { 00345 it.remove(); 00346 } 00347 mItemZList.push_back( item ); 00348 } 00349 00350 void QgsComposition::moveSelectedItemsToBottom() 00351 { 00352 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00353 QList<QgsComposerItem*>::iterator it = selectedItems.begin(); 00354 for ( ; it != selectedItems.end(); ++it ) 00355 { 00356 moveItemToBottom( *it ); 00357 } 00358 00359 //update all positions 00360 updateZValues(); 00361 update(); 00362 } 00363 00364 void QgsComposition::moveItemToBottom( QgsComposerItem* item ) 00365 { 00366 //search item 00367 QMutableLinkedListIterator<QgsComposerItem*> it( mItemZList ); 00368 if ( it.findNext( item ) ) 00369 { 00370 it.remove(); 00371 } 00372 mItemZList.push_front( item ); 00373 } 00374 00375 void QgsComposition::alignSelectedItemsLeft() 00376 { 00377 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00378 if ( selectedItems.size() < 2 ) 00379 { 00380 return; 00381 } 00382 00383 QRectF selectedItemBBox; 00384 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 ) 00385 { 00386 return; 00387 } 00388 00389 double minXCoordinate = selectedItemBBox.left(); 00390 00391 //align items left to minimum x coordinate 00392 QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items left" ) ); 00393 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin(); 00394 for ( ; align_it != selectedItems.end(); ++align_it ) 00395 { 00396 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand ); 00397 subcommand->savePreviousState(); 00398 QTransform itemTransform = ( *align_it )->transform(); 00399 itemTransform.translate( minXCoordinate - itemTransform.dx(), 0 ); 00400 ( *align_it )->setTransform( itemTransform ); 00401 subcommand->saveAfterState(); 00402 } 00403 mUndoStack.push( parentCommand ); 00404 } 00405 00406 void QgsComposition::alignSelectedItemsHCenter() 00407 { 00408 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00409 if ( selectedItems.size() < 2 ) 00410 { 00411 return; 00412 } 00413 00414 QRectF selectedItemBBox; 00415 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 ) 00416 { 00417 return; 00418 } 00419 00420 double averageXCoord = ( selectedItemBBox.left() + selectedItemBBox.right() ) / 2.0; 00421 00422 //place items 00423 QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items hcenter" ) ); 00424 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin(); 00425 for ( ; align_it != selectedItems.end(); ++align_it ) 00426 { 00427 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand ); 00428 subcommand->savePreviousState(); 00429 QTransform itemTransform = ( *align_it )->transform(); 00430 itemTransform.translate( averageXCoord - itemTransform.dx() - ( *align_it )->rect().width() / 2.0, 0 ); 00431 ( *align_it )->setTransform( itemTransform ); 00432 subcommand->saveAfterState(); 00433 } 00434 mUndoStack.push( parentCommand ); 00435 } 00436 00437 void QgsComposition::alignSelectedItemsRight() 00438 { 00439 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00440 if ( selectedItems.size() < 2 ) 00441 { 00442 return; 00443 } 00444 00445 QRectF selectedItemBBox; 00446 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 ) 00447 { 00448 return; 00449 } 00450 00451 double maxXCoordinate = selectedItemBBox.right(); 00452 00453 //align items right to maximum x coordinate 00454 QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items right" ) ); 00455 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin(); 00456 for ( ; align_it != selectedItems.end(); ++align_it ) 00457 { 00458 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand ); 00459 subcommand->savePreviousState(); 00460 QTransform itemTransform = ( *align_it )->transform(); 00461 itemTransform.translate( maxXCoordinate - itemTransform.dx() - ( *align_it )->rect().width(), 0 ); 00462 ( *align_it )->setTransform( itemTransform ); 00463 subcommand->saveAfterState(); 00464 } 00465 mUndoStack.push( parentCommand ); 00466 } 00467 00468 void QgsComposition::alignSelectedItemsTop() 00469 { 00470 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00471 if ( selectedItems.size() < 2 ) 00472 { 00473 return; 00474 } 00475 00476 QRectF selectedItemBBox; 00477 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 ) 00478 { 00479 return; 00480 } 00481 00482 double minYCoordinate = selectedItemBBox.top(); 00483 00484 QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items top" ) ); 00485 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin(); 00486 for ( ; align_it != selectedItems.end(); ++align_it ) 00487 { 00488 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand ); 00489 subcommand->savePreviousState(); 00490 QTransform itemTransform = ( *align_it )->transform(); 00491 itemTransform.translate( 0, minYCoordinate - itemTransform.dy() ); 00492 ( *align_it )->setTransform( itemTransform ); 00493 subcommand->saveAfterState(); 00494 } 00495 mUndoStack.push( parentCommand ); 00496 } 00497 00498 void QgsComposition::alignSelectedItemsVCenter() 00499 { 00500 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00501 if ( selectedItems.size() < 2 ) 00502 { 00503 return; 00504 } 00505 00506 QRectF selectedItemBBox; 00507 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 ) 00508 { 00509 return; 00510 } 00511 00512 double averageYCoord = ( selectedItemBBox.top() + selectedItemBBox.bottom() ) / 2.0; 00513 QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items vcenter" ) ); 00514 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin(); 00515 for ( ; align_it != selectedItems.end(); ++align_it ) 00516 { 00517 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand ); 00518 subcommand->savePreviousState(); 00519 QTransform itemTransform = ( *align_it )->transform(); 00520 itemTransform.translate( 0, averageYCoord - itemTransform.dy() - ( *align_it )->rect().height() / 2 ); 00521 ( *align_it )->setTransform( itemTransform ); 00522 subcommand->saveAfterState(); 00523 } 00524 mUndoStack.push( parentCommand ); 00525 } 00526 00527 void QgsComposition::alignSelectedItemsBottom() 00528 { 00529 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00530 if ( selectedItems.size() < 2 ) 00531 { 00532 return; 00533 } 00534 00535 QRectF selectedItemBBox; 00536 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 ) 00537 { 00538 return; 00539 } 00540 00541 double maxYCoord = selectedItemBBox.bottom(); 00542 QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items bottom" ) ); 00543 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin(); 00544 for ( ; align_it != selectedItems.end(); ++align_it ) 00545 { 00546 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand ); 00547 subcommand->savePreviousState(); 00548 QTransform itemTransform = ( *align_it )->transform(); 00549 itemTransform.translate( 0, maxYCoord - itemTransform.dy() - ( *align_it )->rect().height() ); 00550 ( *align_it )->setTransform( itemTransform ); 00551 subcommand->saveAfterState(); 00552 } 00553 mUndoStack.push( parentCommand ); 00554 } 00555 00556 void QgsComposition::updateZValues() 00557 { 00558 int counter = 1; 00559 QLinkedList<QgsComposerItem*>::iterator it = mItemZList.begin(); 00560 QgsComposerItem* currentItem = 0; 00561 00562 QUndoCommand* parentCommand = new QUndoCommand( tr( "Item z-order changed" ) ); 00563 for ( ; it != mItemZList.end(); ++it ) 00564 { 00565 currentItem = *it; 00566 if ( currentItem ) 00567 { 00568 QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *it, "", parentCommand ); 00569 subcommand->savePreviousState(); 00570 currentItem->setZValue( counter ); 00571 subcommand->saveAfterState(); 00572 } 00573 ++counter; 00574 } 00575 mUndoStack.push( parentCommand ); 00576 } 00577 00578 void QgsComposition::sortZList() 00579 { 00580 if ( mItemZList.size() < 2 ) 00581 { 00582 return; 00583 } 00584 00585 QLinkedList<QgsComposerItem*>::const_iterator lIt = mItemZList.constBegin(); 00586 QLinkedList<QgsComposerItem*> sortedList; 00587 00588 for ( ; lIt != mItemZList.constEnd(); ++lIt ) 00589 { 00590 QLinkedList<QgsComposerItem*>::iterator insertIt = sortedList.begin(); 00591 for ( ; insertIt != sortedList.end(); ++insertIt ) 00592 { 00593 if (( *lIt )->zValue() < ( *insertIt )->zValue() ) 00594 { 00595 break; 00596 } 00597 } 00598 sortedList.insert( insertIt, ( *lIt ) ); 00599 } 00600 00601 mItemZList = sortedList; 00602 } 00603 00604 QPointF QgsComposition::snapPointToGrid( const QPointF& scenePoint ) const 00605 { 00606 if ( !mSnapToGrid || mSnapGridResolution <= 0 ) 00607 { 00608 return scenePoint; 00609 } 00610 00611 //snap x coordinate //todo: add support for x- and y- offset 00612 int xRatio = ( int )(( scenePoint.x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 ); 00613 int yRatio = ( int )(( scenePoint.y() - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 ); 00614 00615 return QPointF( xRatio * mSnapGridResolution + mSnapGridOffsetX, yRatio * mSnapGridResolution + mSnapGridOffsetY ); 00616 } 00617 00618 int QgsComposition::boundingRectOfSelectedItems( QRectF& bRect ) 00619 { 00620 QList<QgsComposerItem*> selectedItems = selectedComposerItems(); 00621 if ( selectedItems.size() < 1 ) 00622 { 00623 return 1; 00624 } 00625 00626 //set the box to the first item 00627 QgsComposerItem* currentItem = selectedItems.at( 0 ); 00628 double minX = currentItem->transform().dx(); 00629 double minY = currentItem->transform().dy(); 00630 double maxX = minX + currentItem->rect().width(); 00631 double maxY = minY + currentItem->rect().height(); 00632 00633 double currentMinX, currentMinY, currentMaxX, currentMaxY; 00634 00635 for ( int i = 1; i < selectedItems.size(); ++i ) 00636 { 00637 currentItem = selectedItems.at( i ); 00638 currentMinX = currentItem->transform().dx(); 00639 currentMinY = currentItem->transform().dy(); 00640 currentMaxX = currentMinX + currentItem->rect().width(); 00641 currentMaxY = currentMinY + currentItem->rect().height(); 00642 00643 if ( currentMinX < minX ) 00644 minX = currentMinX; 00645 if ( currentMaxX > maxX ) 00646 maxX = currentMaxX; 00647 if ( currentMinY < minY ) 00648 minY = currentMinY; 00649 if ( currentMaxY > maxY ) 00650 maxY = currentMaxY; 00651 } 00652 00653 bRect.setTopLeft( QPointF( minX, minY ) ); 00654 bRect.setBottomRight( QPointF( maxX, maxY ) ); 00655 return 0; 00656 } 00657 00658 void QgsComposition::setSnapToGridEnabled( bool b ) 00659 { 00660 mSnapToGrid = b; 00661 if ( mPaperItem ) 00662 { 00663 mPaperItem->update(); 00664 } 00665 } 00666 00667 void QgsComposition::setSnapGridResolution( double r ) 00668 { 00669 mSnapGridResolution = r; 00670 if ( mPaperItem ) 00671 { 00672 mPaperItem->update(); 00673 } 00674 } 00675 00676 void QgsComposition::setSnapGridOffsetX( double offset ) 00677 { 00678 mSnapGridOffsetX = offset; 00679 if ( mPaperItem ) 00680 { 00681 mPaperItem->update(); 00682 } 00683 } 00684 00685 void QgsComposition::setSnapGridOffsetY( double offset ) 00686 { 00687 mSnapGridOffsetY = offset; 00688 if ( mPaperItem ) 00689 { 00690 mPaperItem->update(); 00691 } 00692 } 00693 00694 void QgsComposition::setGridPen( const QPen& p ) 00695 { 00696 mGridPen = p; 00697 if ( mPaperItem ) 00698 { 00699 mPaperItem->update(); 00700 } 00701 saveGridAppearanceSettings(); 00702 } 00703 00704 void QgsComposition::setGridStyle( GridStyle s ) 00705 { 00706 mGridStyle = s; 00707 if ( mPaperItem ) 00708 { 00709 mPaperItem->update(); 00710 } 00711 saveGridAppearanceSettings(); 00712 } 00713 00714 void QgsComposition::loadGridAppearanceSettings() 00715 { 00716 //read grid style, grid color and pen width from settings 00717 QSettings s; 00718 00719 QString gridStyleString; 00720 int red, green, blue; 00721 double penWidth; 00722 00723 gridStyleString = s.value( "/qgis/composerGridStyle", "Dots" ).toString(); 00724 penWidth = s.value( "/qgis/composerGridWidth", 0.5 ).toDouble(); 00725 red = s.value( "/qgis/composerGridRed", 0 ).toInt(); 00726 green = s.value( "/qgis/composerGridGreen", 0 ).toInt(); 00727 blue = s.value( "/qgis/composerGridBlue", 0 ).toInt(); 00728 00729 mGridPen.setColor( QColor( red, green, blue ) ); 00730 mGridPen.setWidthF( penWidth ); 00731 00732 if ( gridStyleString == "Dots" ) 00733 { 00734 mGridStyle = Dots; 00735 } 00736 else if ( gridStyleString == "Crosses" ) 00737 { 00738 mGridStyle = Crosses; 00739 } 00740 else 00741 { 00742 mGridStyle = Solid; 00743 } 00744 } 00745 00746 void QgsComposition::saveGridAppearanceSettings() 00747 { 00748 //store grid appearance settings 00749 QSettings s; 00750 s.setValue( "/qgis/composerGridWidth", mGridPen.widthF() ); 00751 s.setValue( "/qgis/composerGridRed", mGridPen.color().red() ); 00752 s.setValue( "/qgis/composerGridGreen", mGridPen.color().green() ); 00753 s.setValue( "/qgis/composerGridBlue", mGridPen.color().blue() ); 00754 00755 if ( mGridStyle == Solid ) 00756 { 00757 s.setValue( "/qgis/composerGridStyle", "Solid" ); 00758 } 00759 else if ( mGridStyle == Dots ) 00760 { 00761 s.setValue( "/qgis/composerGridStyle", "Dots" ); 00762 } 00763 else if ( mGridStyle == Crosses ) 00764 { 00765 s.setValue( "/qgis/composerGridStyle", "Crosses" ); 00766 } 00767 } 00768 00769 void QgsComposition::beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c ) 00770 { 00771 delete mActiveCommand; 00772 if ( !item ) 00773 { 00774 mActiveCommand = 0; 00775 return; 00776 } 00777 00778 if ( c == QgsComposerMergeCommand::Unknown ) 00779 { 00780 mActiveCommand = new QgsComposerItemCommand( item, commandText ); 00781 } 00782 else 00783 { 00784 mActiveCommand = new QgsComposerMergeCommand( c, item, commandText ); 00785 } 00786 mActiveCommand->savePreviousState(); 00787 } 00788 00789 void QgsComposition::endCommand() 00790 { 00791 if ( mActiveCommand ) 00792 { 00793 mActiveCommand->saveAfterState(); 00794 if ( mActiveCommand->containsChange() ) //protect against empty commands 00795 { 00796 mUndoStack.push( mActiveCommand ); 00797 } 00798 else 00799 { 00800 delete mActiveCommand; 00801 } 00802 mActiveCommand = 0; 00803 } 00804 } 00805 00806 void QgsComposition::cancelCommand() 00807 { 00808 delete mActiveCommand; 00809 mActiveCommand = 0; 00810 }