Quantum GIS API Documentation  1.7.4
src/gui/qgscomposerview.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                          qgscomposerview.cpp
00003                          -------------------
00004     begin                : January 2005
00005     copyright            : (C) 2005 by Radim Blazek
00006     email                : blazek@itc.it
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <QMainWindow>
00019 #include <QMouseEvent>
00020 #include <QKeyEvent>
00021 
00022 #include "qgscomposerview.h"
00023 #include "qgscomposerarrow.h"
00024 #include "qgscomposerlabel.h"
00025 #include "qgscomposerlegend.h"
00026 #include "qgscomposermap.h"
00027 #include "qgscomposeritemgroup.h"
00028 #include "qgscomposerpicture.h"
00029 #include "qgscomposerscalebar.h"
00030 #include "qgscomposershape.h"
00031 #include "qgscomposerattributetable.h"
00032 
00033 QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f ) :
00034     QGraphicsView( parent ), mShiftKeyPressed( false ), mRubberBandItem( 0 ), mRubberBandLineItem( 0 ), mMoveContentItem( 0 ), mPaintingEnabled( true )
00035 {
00036   setResizeAnchor( QGraphicsView::AnchorViewCenter );
00037   setMouseTracking( true );
00038   viewport()->setMouseTracking( true );
00039 }
00040 
00041 void QgsComposerView::mousePressEvent( QMouseEvent* e )
00042 {
00043   if ( !composition() )
00044   {
00045     return;
00046   }
00047 
00048   QPointF scenePoint = mapToScene( e->pos() );
00049   QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint );
00050 
00051   //lock/unlock position of item with right click
00052   if ( e->button() == Qt::RightButton )
00053   {
00054     QgsComposerItem* selectedItem = composition()->composerItemAt( scenePoint );
00055     if ( selectedItem )
00056     {
00057       bool lock = selectedItem->positionLock() ? false : true;
00058       selectedItem->setPositionLock( lock );
00059       selectedItem->update();
00060       //make sure the new cursor is correct
00061       QPointF itemPoint = selectedItem->mapFromScene( scenePoint );
00062       selectedItem->updateCursor( itemPoint );
00063     }
00064     return;
00065   }
00066 
00067   switch ( mCurrentTool )
00068   {
00069       //select/deselect items and pass mouse event further
00070     case Select:
00071     {
00072       if ( !mShiftKeyPressed ) //keep selection if shift key pressed
00073       {
00074         composition()->clearSelection();
00075       }
00076 
00077       //select topmost item at position of event
00078       QgsComposerItem* selectedItem = composition()->composerItemAt( scenePoint );
00079       if ( !selectedItem )
00080       {
00081         break;
00082       }
00083 
00084       selectedItem->setSelected( true );
00085       QGraphicsView::mousePressEvent( e );
00086       emit selectedItemChanged( selectedItem );
00087       break;
00088     }
00089 
00090     case MoveItemContent:
00091     {
00092       //store item as member if it is selected and cursor is over item
00093       QgsComposerItem* item = dynamic_cast<QgsComposerItem *>( itemAt( e->pos() ) );
00094       if ( item )
00095       {
00096         mMoveContentStartPos = scenePoint;
00097       }
00098       mMoveContentItem = item;
00099       break;
00100     }
00101 
00102     case AddArrow:
00103     {
00104       mRubberBandStartPos = QPointF( snappedScenePoint.x(), snappedScenePoint.y() );
00105       mRubberBandLineItem = new QGraphicsLineItem( snappedScenePoint.x(), snappedScenePoint.y(), snappedScenePoint.x(), snappedScenePoint.y() );
00106       mRubberBandLineItem->setZValue( 100 );
00107       scene()->addItem( mRubberBandLineItem );
00108       scene()->update();
00109       break;
00110     }
00111 
00112     //create rubber band for map and ellipse items
00113     case AddMap:
00114     case AddShape:
00115     {
00116       QTransform t;
00117       mRubberBandItem = new QGraphicsRectItem( 0, 0, 0, 0 );
00118       mRubberBandStartPos = QPointF( snappedScenePoint.x(), snappedScenePoint.y() );
00119       t.translate( snappedScenePoint.x(), snappedScenePoint.y() );
00120       mRubberBandItem->setTransform( t );
00121       mRubberBandItem->setZValue( 100 );
00122       scene()->addItem( mRubberBandItem );
00123       scene()->update();
00124     }
00125     break;
00126 
00127     case AddLabel:
00128     {
00129       QgsComposerLabel* newLabelItem = new QgsComposerLabel( composition() );
00130       newLabelItem->setText( tr( "Quantum GIS" ) );
00131       newLabelItem->adjustSizeToText();
00132       newLabelItem->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
00133       addComposerLabel( newLabelItem );
00134       emit actionFinished();
00135     }
00136     break;
00137 
00138     case AddScalebar:
00139     {
00140       QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar( composition() );
00141       newScaleBar->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 20, 20 ) );
00142       addComposerScaleBar( newScaleBar );
00143       emit actionFinished();
00144     }
00145     break;
00146 
00147     case AddLegend:
00148     {
00149       QgsComposerLegend* newLegend = new QgsComposerLegend( composition() );
00150       newLegend->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
00151       addComposerLegend( newLegend );
00152       emit actionFinished();
00153       break;
00154     }
00155     case AddPicture:
00156     {
00157       QgsComposerPicture* newPicture = new QgsComposerPicture( composition() );
00158       newPicture->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
00159       addComposerPicture( newPicture );
00160       emit actionFinished();
00161       break;
00162     }
00163     case AddTable:
00164     {
00165       QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( composition() );
00166       newTable->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
00167       addComposerTable( newTable );
00168       emit actionFinished();
00169       break;
00170     }
00171 
00172     default:
00173       break;
00174   }
00175 }
00176 
00177 void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
00178 {
00179   if ( !composition() )
00180   {
00181     return;
00182   }
00183 
00184   QPointF scenePoint = mapToScene( e->pos() );
00185 
00186   switch ( mCurrentTool )
00187   {
00188     case Select:
00189     {
00190       QGraphicsView::mouseReleaseEvent( e );
00191       break;
00192     }
00193 
00194     case MoveItemContent:
00195     {
00196       if ( mMoveContentItem )
00197       {
00198         //update map preview if composer map
00199         QgsComposerMap* composerMap = dynamic_cast<QgsComposerMap *>( mMoveContentItem );
00200         if ( composerMap )
00201         {
00202           composerMap->setOffset( 0, 0 );
00203         }
00204 
00205         double moveX = scenePoint.x() - mMoveContentStartPos.x();
00206         double moveY = scenePoint.y() - mMoveContentStartPos.y();
00207 
00208         composition()->beginCommand( mMoveContentItem, tr( "Move item content" ) );
00209         mMoveContentItem->moveContent( -moveX, -moveY );
00210         composition()->endCommand();
00211         mMoveContentItem = 0;
00212       }
00213       break;
00214     }
00215     case AddArrow:
00216     {
00217       QPointF scenePoint = mapToScene( e->pos() );
00218       QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint );
00219       QgsComposerArrow* composerArrow = new QgsComposerArrow( mRubberBandStartPos, QPointF( snappedScenePoint.x(), snappedScenePoint.y() ), composition() );
00220       addComposerArrow( composerArrow );
00221       scene()->removeItem( mRubberBandLineItem );
00222       delete mRubberBandLineItem;
00223       mRubberBandLineItem = 0;
00224       emit actionFinished();
00225       break;
00226     }
00227 
00228     case AddShape:
00229     {
00230       if ( !mRubberBandItem || mRubberBandItem->rect().width() < 0.1 || mRubberBandItem->rect().width() < 0.1 )
00231       {
00232         scene()->removeItem( mRubberBandItem );
00233         delete mRubberBandItem;
00234         mRubberBandItem = 0;
00235         return;
00236       }
00237 
00238       QgsComposerShape* composerShape = new QgsComposerShape( mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height(), composition() );
00239       addComposerShape( composerShape );
00240       scene()->removeItem( mRubberBandItem );
00241       delete mRubberBandItem;
00242       mRubberBandItem = 0;
00243       emit actionFinished();
00244       break;
00245     }
00246 
00247     case AddMap:
00248     {
00249       if ( !mRubberBandItem || mRubberBandItem->rect().width() < 0.1 || mRubberBandItem->rect().width() < 0.1 )
00250       {
00251         if ( mRubberBandItem )
00252         {
00253           scene()->removeItem( mRubberBandItem );
00254           delete mRubberBandItem;
00255           mRubberBandItem = 0;
00256         }
00257         return;
00258       }
00259 
00260       QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
00261       addComposerMap( composerMap );
00262       scene()->removeItem( mRubberBandItem );
00263       delete mRubberBandItem;
00264       mRubberBandItem = 0;
00265       emit actionFinished();
00266     }
00267     break;
00268 
00269     default:
00270       break;
00271   }
00272 }
00273 
00274 void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
00275 {
00276   if ( !composition() )
00277   {
00278     return;
00279   }
00280 
00281   if ( e->buttons() == Qt::NoButton )
00282   {
00283     if ( mCurrentTool == Select )
00284     {
00285       QGraphicsView::mouseMoveEvent( e );
00286     }
00287   }
00288   else
00289   {
00290     QPointF scenePoint = mapToScene( e->pos() );
00291 
00292     switch ( mCurrentTool )
00293     {
00294       case Select:
00295         QGraphicsView::mouseMoveEvent( e );
00296         break;
00297 
00298       case AddArrow:
00299       {
00300         if ( mRubberBandLineItem )
00301         {
00302           mRubberBandLineItem->setLine( mRubberBandStartPos.x(), mRubberBandStartPos.y(),  scenePoint.x(),  scenePoint.y() );
00303         }
00304         break;
00305       }
00306 
00307       case AddMap:
00308       case AddShape:
00309         //adjust rubber band item
00310       {
00311         double x = 0;
00312         double y = 0;
00313         double width = 0;
00314         double height = 0;
00315 
00316         double dx = scenePoint.x() - mRubberBandStartPos.x();
00317         double dy = scenePoint.y() - mRubberBandStartPos.y();
00318 
00319         if ( dx < 0 )
00320         {
00321           x = scenePoint.x();
00322           width = -dx;
00323         }
00324         else
00325         {
00326           x = mRubberBandStartPos.x();
00327           width = dx;
00328         }
00329 
00330         if ( dy < 0 )
00331         {
00332           y = scenePoint.y();
00333           height = -dy;
00334         }
00335         else
00336         {
00337           y = mRubberBandStartPos.y();
00338           height = dy;
00339         }
00340 
00341         if ( mRubberBandItem )
00342         {
00343           mRubberBandItem->setRect( 0, 0, width, height );
00344           QTransform t;
00345           t.translate( x, y );
00346           mRubberBandItem->setTransform( t );
00347         }
00348         break;
00349       }
00350 
00351       case MoveItemContent:
00352       {
00353         //update map preview if composer map
00354         QgsComposerMap* composerMap = dynamic_cast<QgsComposerMap *>( mMoveContentItem );
00355         if ( composerMap )
00356         {
00357           composerMap->setOffset( scenePoint.x() - mMoveContentStartPos.x(), scenePoint.y() - mMoveContentStartPos.y() );
00358           composerMap->update();
00359         }
00360         break;
00361       }
00362       default:
00363         break;
00364     }
00365   }
00366 }
00367 
00368 void QgsComposerView::mouseDoubleClickEvent( QMouseEvent* e )
00369 {
00370   e->ignore();
00371 }
00372 
00373 void QgsComposerView::keyPressEvent( QKeyEvent * e )
00374 {
00375   if ( e->key() == Qt::Key_Shift )
00376   {
00377     mShiftKeyPressed = true;
00378   }
00379 
00380   if ( !composition() )
00381   {
00382     return;
00383   }
00384 
00385   QList<QgsComposerItem*> composerItemList = composition()->selectedComposerItems();
00386   QList<QgsComposerItem*>::iterator itemIt = composerItemList.begin();
00387 
00388   //delete selected items
00389   if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace )
00390   {
00391     for ( ; itemIt != composerItemList.end(); ++itemIt )
00392     {
00393       QgsComposerMap* map = dynamic_cast<QgsComposerMap *>( *itemIt );
00394       if ( !map || !map->isDrawing() ) //don't delete a composer map while it draws
00395       {
00396         composition()->removeItem( *itemIt );
00397         QgsComposerItemGroup* itemGroup = dynamic_cast<QgsComposerItemGroup*>( *itemIt );
00398         if ( itemGroup && composition() )
00399         {
00400           //add add/remove item command for every item in the group
00401           QUndoCommand* parentCommand = new QUndoCommand( tr( "Remove item group" ) );
00402 
00403           QSet<QgsComposerItem*> groupedItems = itemGroup->items();
00404           QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
00405           for ( ; it != groupedItems.end(); ++it )
00406           {
00407             QgsAddRemoveItemCommand* subcommand = new QgsAddRemoveItemCommand( QgsAddRemoveItemCommand::Removed, *it, composition(), "", parentCommand );
00408             connectAddRemoveCommandSignals( subcommand );
00409             emit itemRemoved( *it );
00410           }
00411 
00412           composition()->undoStack()->push( parentCommand );
00413           delete itemGroup;
00414           emit itemRemoved( itemGroup );
00415         }
00416         else
00417         {
00418           emit itemRemoved( *itemIt );
00419           pushAddRemoveCommand( *itemIt, tr( "Item deleted" ), QgsAddRemoveItemCommand::Removed );
00420         }
00421       }
00422     }
00423   }
00424 
00425   else if ( e->key() == Qt::Key_Left )
00426   {
00427     for ( ; itemIt != composerItemList.end(); ++itemIt )
00428     {
00429       ( *itemIt )->move( -1.0, 0.0 );
00430     }
00431   }
00432   else if ( e->key() == Qt::Key_Right )
00433   {
00434     for ( ; itemIt != composerItemList.end(); ++itemIt )
00435     {
00436       ( *itemIt )->move( 1.0, 0.0 );
00437     }
00438   }
00439   else if ( e->key() == Qt::Key_Down )
00440   {
00441     for ( ; itemIt != composerItemList.end(); ++itemIt )
00442     {
00443       ( *itemIt )->move( 0.0, 1.0 );
00444     }
00445   }
00446   else if ( e->key() == Qt::Key_Up )
00447   {
00448     for ( ; itemIt != composerItemList.end(); ++itemIt )
00449     {
00450       ( *itemIt )->move( 0.0, -1.0 );
00451     }
00452   }
00453 }
00454 
00455 void QgsComposerView::keyReleaseEvent( QKeyEvent * e )
00456 {
00457   if ( e->key() == Qt::Key_Shift )
00458   {
00459     mShiftKeyPressed = false;
00460   }
00461 }
00462 
00463 void QgsComposerView::wheelEvent( QWheelEvent* event )
00464 {
00465   QPointF scenePoint = mapToScene( event->pos() );
00466 
00467   //select topmost item at position of event
00468   QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
00469   if ( theItem )
00470   {
00471     if ( theItem->isSelected() )
00472     {
00473       QPointF itemPoint = theItem->mapFromScene( scenePoint );
00474       theItem->beginCommand( tr( "Zoom item content" ) );
00475       theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
00476       theItem->endCommand();
00477     }
00478   }
00479 }
00480 
00481 void QgsComposerView::paintEvent( QPaintEvent* event )
00482 {
00483   if ( mPaintingEnabled )
00484   {
00485     QGraphicsView::paintEvent( event );
00486     event->accept();
00487   }
00488   else
00489   {
00490     event->ignore();
00491   }
00492 }
00493 
00494 void QgsComposerView::setComposition( QgsComposition* c )
00495 {
00496   setScene( c );
00497 }
00498 
00499 QgsComposition* QgsComposerView::composition()
00500 {
00501   if ( scene() )
00502   {
00503     QgsComposition* c = dynamic_cast<QgsComposition *>( scene() );
00504     if ( c )
00505     {
00506       return c;
00507     }
00508   }
00509   return 0;
00510 }
00511 
00512 void QgsComposerView::addComposerArrow( QgsComposerArrow* arrow )
00513 {
00514   composition()->addItem( arrow );
00515   emit composerArrowAdded( arrow );
00516   scene()->clearSelection();
00517   arrow->setSelected( true );
00518   emit selectedItemChanged( arrow );
00519   pushAddRemoveCommand( arrow, tr( "Arrow added" ) );
00520 }
00521 
00522 void QgsComposerView::addComposerLabel( QgsComposerLabel* label )
00523 {
00524   composition()->addItem( label );
00525   emit composerLabelAdded( label );
00526   scene()->clearSelection();
00527   label->setSelected( true );
00528   emit selectedItemChanged( label );
00529   pushAddRemoveCommand( label, tr( "Label added" ) );
00530 }
00531 
00532 void QgsComposerView::addComposerMap( QgsComposerMap* map )
00533 {
00534   scene()->addItem( map );
00535   //set default preview mode to cache. Must be done here between adding composer map to scene and emiting signal
00536   map->setPreviewMode( QgsComposerMap::Cache );
00537   map->cache();
00538   emit composerMapAdded( map );
00539   scene()->clearSelection();
00540   map->setSelected( true );
00541   emit selectedItemChanged( map );
00542   pushAddRemoveCommand( map, tr( "Map added" ) );
00543 }
00544 
00545 void QgsComposerView::addComposerScaleBar( QgsComposerScaleBar* scaleBar )
00546 {
00547   //take first available map
00548   QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
00549   if ( mapItemList.size() > 0 )
00550   {
00551     scaleBar->setComposerMap( mapItemList.at( 0 ) );
00552   }
00553   scaleBar->applyDefaultSize(); //4 segments, 1/5 of composer map width
00554   scene()->addItem( scaleBar );
00555   emit composerScaleBarAdded( scaleBar );
00556   scene()->clearSelection();
00557   scaleBar->setSelected( true );
00558   emit selectedItemChanged( scaleBar );
00559   pushAddRemoveCommand( scaleBar, tr( "Scale bar added" ) );
00560 }
00561 
00562 void QgsComposerView::addComposerLegend( QgsComposerLegend* legend )
00563 {
00564   //take first available map
00565   QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
00566   if ( mapItemList.size() > 0 )
00567   {
00568     legend->setComposerMap( mapItemList.at( 0 ) );
00569   }
00570   scene()->addItem( legend );
00571   emit composerLegendAdded( legend );
00572   scene()->clearSelection();
00573   legend->setSelected( true );
00574   emit selectedItemChanged( legend );
00575   pushAddRemoveCommand( legend, tr( "Legend added" ) );
00576 }
00577 
00578 void QgsComposerView::addComposerPicture( QgsComposerPicture* picture )
00579 {
00580   scene()->addItem( picture );
00581   emit composerPictureAdded( picture );
00582   scene()->clearSelection();
00583   picture->setSelected( true );
00584   emit selectedItemChanged( picture );
00585   pushAddRemoveCommand( picture, tr( "Picture added" ) );
00586 }
00587 
00588 void QgsComposerView::addComposerShape( QgsComposerShape* shape )
00589 {
00590   scene()->addItem( shape );
00591   emit composerShapeAdded( shape );
00592   scene()->clearSelection();
00593   shape->setSelected( true );
00594   emit selectedItemChanged( shape );
00595   pushAddRemoveCommand( shape, tr( "Shape added" ) );
00596 }
00597 
00598 void QgsComposerView::addComposerTable( QgsComposerAttributeTable* table )
00599 {
00600   scene()->addItem( table );
00601   emit composerTableAdded( table );
00602   scene()->clearSelection();
00603   table->setSelected( true );
00604   emit selectedItemChanged( table );
00605   pushAddRemoveCommand( table, tr( "Table added" ) );
00606 }
00607 
00608 void QgsComposerView::groupItems()
00609 {
00610   if ( !composition() )
00611   {
00612     return;
00613   }
00614 
00615   QList<QgsComposerItem*> selectionList = composition()->selectedComposerItems();
00616   if ( selectionList.size() < 2 )
00617   {
00618     return; //not enough items for a group
00619   }
00620   QgsComposerItemGroup* itemGroup = new QgsComposerItemGroup( composition() );
00621 
00622   QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
00623   for ( ; itemIter != selectionList.end(); ++itemIter )
00624   {
00625     itemGroup->addItem( *itemIter );
00626   }
00627 
00628   composition()->addItem( itemGroup );
00629   itemGroup->setSelected( true );
00630   emit selectedItemChanged( itemGroup );
00631 }
00632 
00633 void QgsComposerView::ungroupItems()
00634 {
00635   if ( !composition() )
00636   {
00637     return;
00638   }
00639 
00640   QList<QgsComposerItem*> selectionList = composition()->selectedComposerItems();
00641   QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
00642   for ( ; itemIter != selectionList.end(); ++itemIter )
00643   {
00644     QgsComposerItemGroup* itemGroup = dynamic_cast<QgsComposerItemGroup *>( *itemIter );
00645     if ( itemGroup )
00646     {
00647       itemGroup->removeItems();
00648       composition()->removeItem( *itemIter );
00649       delete( *itemIter );
00650       emit itemRemoved( *itemIter );
00651     }
00652   }
00653 }
00654 
00655 void QgsComposerView::sendItemAddedSignal( QgsComposerItem* item )
00656 {
00657   //cast and send proper signal
00658   item->setSelected( true );
00659   QgsComposerArrow* arrow = dynamic_cast<QgsComposerArrow*>( item );
00660   if ( arrow )
00661   {
00662     emit composerArrowAdded( arrow );
00663     emit selectedItemChanged( arrow );
00664     return;
00665   }
00666   QgsComposerLabel* label = dynamic_cast<QgsComposerLabel*>( item );
00667   if ( label )
00668   {
00669     emit composerLabelAdded( label );
00670     emit selectedItemChanged( label );
00671     return;
00672   }
00673   QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item );
00674   if ( map )
00675   {
00676     emit composerMapAdded( map );
00677     emit selectedItemChanged( map );
00678     return;
00679   }
00680   QgsComposerScaleBar* scalebar = dynamic_cast<QgsComposerScaleBar*>( item );
00681   if ( scalebar )
00682   {
00683     emit composerScaleBarAdded( scalebar );
00684     emit selectedItemChanged( scalebar );
00685     return;
00686   }
00687   QgsComposerLegend* legend = dynamic_cast<QgsComposerLegend*>( item );
00688   if ( legend )
00689   {
00690     emit composerLegendAdded( legend );
00691     emit selectedItemChanged( legend );
00692     return;
00693   }
00694   QgsComposerPicture* picture = dynamic_cast<QgsComposerPicture*>( item );
00695   if ( picture )
00696   {
00697     emit composerPictureAdded( picture );
00698     emit selectedItemChanged( picture );
00699     return;
00700   }
00701   QgsComposerShape* shape = dynamic_cast<QgsComposerShape*>( item );
00702   if ( shape )
00703   {
00704     emit composerShapeAdded( shape );
00705     emit selectedItemChanged( shape );
00706     return;
00707   }
00708   QgsComposerAttributeTable* table = dynamic_cast<QgsComposerAttributeTable*>( item );
00709   if ( table )
00710   {
00711     emit composerTableAdded( table );
00712     emit selectedItemChanged( table );
00713     return;
00714   }
00715 }
00716 
00717 QMainWindow* QgsComposerView::composerWindow()
00718 {
00719   QMainWindow* composerObject = 0;
00720   QObject* currentObject = parent();
00721   if ( !currentObject )
00722   {
00723     return qobject_cast<QMainWindow *>( currentObject );
00724   }
00725 
00726   while ( true )
00727   {
00728     composerObject = qobject_cast<QMainWindow*>( currentObject );
00729     if ( composerObject || currentObject->parent() == 0 )
00730     {
00731       return composerObject;
00732     }
00733     currentObject = currentObject->parent();
00734   }
00735 
00736   return 0;
00737 }
00738 
00739 void QgsComposerView::connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c )
00740 {
00741   if ( !c )
00742   {
00743     return;
00744   }
00745   QObject::connect( c, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SIGNAL( itemRemoved( QgsComposerItem* ) ) );
00746   QObject::connect( c, SIGNAL( itemAdded( QgsComposerItem* ) ), this, SLOT( sendItemAddedSignal( QgsComposerItem* ) ) );
00747 }
00748 
00749 void QgsComposerView::pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state )
00750 {
00751   if ( !composition() )
00752   {
00753     return;
00754   }
00755 
00756   QgsAddRemoveItemCommand* c = new QgsAddRemoveItemCommand( state, item, composition(), text );
00757   connectAddRemoveCommandSignals( c );
00758   composition()->undoStack()->push( c );
00759 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines