18 #include <QApplication>
19 #include <QMainWindow>
20 #include <QMouseEvent>
24 #include <QGridLayout>
43 : QGraphicsView( parent )
44 , mRubberBandItem( 0 )
45 , mRubberBandLineItem( 0 )
46 , mMoveContentItem( 0 )
47 , mPaintingEnabled( true )
48 , mHorizontalRuler( 0 )
54 setResizeAnchor( QGraphicsView::AnchorViewCenter );
55 setMouseTracking(
true );
56 viewport()->setMouseTracking(
true );
57 setFrameShape( QFrame::NoFrame );
67 QPointF scenePoint = mapToScene( e->pos() );
71 if ( e->button() == Qt::RightButton )
78 selectedItem->update();
80 QPointF itemPoint = selectedItem->mapFromScene( scenePoint );
91 if ( !( e->modifiers() & Qt::ShiftModifier ) )
104 QGraphicsView::mousePressEvent( e );
124 mRubberBandLineItem =
new QGraphicsLineItem( snappedScenePoint.x(), snappedScenePoint.y(), snappedScenePoint.x(), snappedScenePoint.y() );
125 mRubberBandLineItem->setZValue( 100 );
126 scene()->addItem( mRubberBandLineItem );
141 t.translate( snappedScenePoint.x(), snappedScenePoint.y() );
155 newLabelItem->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
166 newScaleBar->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 20, 20 ) );
169 if ( mapItemList.size() > 0 )
184 newLegend->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
196 newPicture->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
206 newTable->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
265 QPointF scenePoint = mapToScene( e->pos() );
271 QGraphicsView::mouseReleaseEvent( e );
299 QPointF scenePoint = mapToScene( e->pos() );
380 if ( e->buttons() == Qt::NoButton )
384 QGraphicsView::mouseMoveEvent( e );
389 QPointF scenePoint = mapToScene( e->pos() );
394 QGraphicsView::mouseMoveEvent( e );
460 composerMap->update();
485 QList<QgsComposerItem*>::iterator itemIt = composerItemList.begin();
487 if ( e->matches( QKeySequence::Copy ) || e->matches( QKeySequence::Cut ) )
490 QDomElement documentElement = doc.createElement(
"ComposerItemClipboard" );
491 for ( ; itemIt != composerItemList.end(); ++itemIt )
497 QSet<QgsComposerItem*> groupedItems = itemGroup->
items();
498 QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
499 for ( ; it != groupedItems.end(); ++it )
501 ( *it )->writeXML( documentElement, doc );
504 ( *itemIt )->writeXML( documentElement, doc );
505 if ( e->matches( QKeySequence::Cut ) )
510 doc.appendChild( documentElement );
513 if ( e->matches( QKeySequence::Copy ) )
516 QDomNodeList composerItemsNodes = doc.elementsByTagName(
"ComposerItem" );
517 for (
int i = 0; i < composerItemsNodes.count(); ++i )
519 QDomNode composerItemNode = composerItemsNodes.at( i );
520 if ( composerItemNode.isElement() )
522 composerItemNode.toElement().removeAttribute(
"uuid" );
527 QMimeData *mimeData =
new QMimeData;
528 mimeData->setData(
"text/xml", doc.toByteArray() );
529 QClipboard *clipboard = QApplication::clipboard();
530 clipboard->setMimeData( mimeData );
534 if ( e->matches( QKeySequence::Paste ) || ( e->key() == Qt::Key_V && e->modifiers() & Qt::ControlModifier && e->modifiers() & Qt::ShiftModifier ) )
537 QClipboard *clipboard = QApplication::clipboard();
538 if ( doc.setContent( clipboard->mimeData()->data(
"text/xml" ) ) )
540 QDomElement docElem = doc.documentElement();
541 if ( docElem.tagName() ==
"ComposerItemClipboard" )
545 QPointF pt = mapToScene( mapFromGlobal( QCursor::pos() ) );
546 bool pasteInPlace = ( e->modifiers() & Qt::ShiftModifier );
554 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace )
556 for ( ; itemIt != composerItemList.end(); ++itemIt )
565 else if ( e->key() == Qt::Key_Left )
567 for ( ; itemIt != composerItemList.end(); ++itemIt )
570 ( *itemIt )->move( -1.0, 0.0 );
571 ( *itemIt )->endCommand();
574 else if ( e->key() == Qt::Key_Right )
576 for ( ; itemIt != composerItemList.end(); ++itemIt )
579 ( *itemIt )->move( 1.0, 0.0 );
580 ( *itemIt )->endCommand();
583 else if ( e->key() == Qt::Key_Down )
585 for ( ; itemIt != composerItemList.end(); ++itemIt )
588 ( *itemIt )->move( 0.0, 1.0 );
589 ( *itemIt )->endCommand();
592 else if ( e->key() == Qt::Key_Up )
594 for ( ; itemIt != composerItemList.end(); ++itemIt )
597 ( *itemIt )->move( 0.0, -1.0 );
598 ( *itemIt )->endCommand();
605 QPointF scenePoint = mapToScene( event->pos() );
611 if ( theItem->isSelected() )
613 QPointF itemPoint = theItem->mapFromScene( scenePoint );
615 theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
616 theItem->endCommand();
625 QGraphicsView::paintEvent( event );
648 QGraphicsView::resizeEvent( event );
654 QGraphicsView::scrollContentsBy( dx, dy );
692 if ( selectionList.size() < 2 )
698 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
699 for ( ; itemIter != selectionList.end(); ++itemIter )
701 itemGroup->
addItem( *itemIter );
717 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
718 for ( ; itemIter != selectionList.end(); ++itemIter )
733 QMainWindow* composerObject = 0;
734 QObject* currentObject = parent();
735 if ( !currentObject )
737 return qobject_cast<QMainWindow *>( currentObject );
742 composerObject = qobject_cast<QMainWindow*>( currentObject );
743 if ( composerObject || currentObject->parent() == 0 )
745 return composerObject;
747 currentObject = currentObject->parent();
void mouseDoubleClickEvent(QMouseEvent *e)
bool positionLock() const
Returns position lock for mouse drags (true means locked)
void setShapeType(QgsComposerShape::Shape s)
A scale bar item that can be added to a map composition.
QUndoStack * undoStack()
Returns pointer to undo/redo command storage.
QPointF mMoveContentStartPos
Start position of content move.
void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
QMainWindow * composerWindow()
Returns the composer main window.
QgsComposerRuler * mVerticalRuler
An item that draws an arrow between to points.
void mouseReleaseEvent(QMouseEvent *)
void removeItems()
Removes the items but does not delete them.
void setOffset(double xOffset, double yOffset)
Sets offset values to shift image (useful for live updates when moving item content) ...
QgsComposerView::Tool mCurrentTool
Current composer tool.
void updateRulers()
Update rulers with current scene rect.
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
void addComposerScaleBar(QgsComposerScaleBar *scaleBar)
Adds scale bar to the graphics scene and advices composer to create a widget for it (through signal) ...
A item that forms part of a map composition.
void updateMarker(const QPointF &pos)
QPointF snapPointToGrid(const QPointF &scenePoint) const
Snaps a scene coordinate point to grid.
void removeComposerItem(QgsComposerItem *item, bool createCommand=true)
Remove item from the graphics scene.
A container for grouping several QgsComposerItems.
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
void setComposition(QgsComposition *c)
void groupItems()
Add an item group containing the selected items.
void paintEvent(QPaintEvent *event)
QGraphicsLineItem * mRubberBandLineItem
Rubber band item for arrows.
void updateLegend()
Updates the model and all legend entries.
void beginMultiFrameCommand(QgsComposerMultiFrame *multiFrame, const QString &text)
void composerViewHide(QgsComposerView *)
Emitted before composerview is hidden.
void scrollContentsBy(int dx, int dy)
A composer class that displays svg files or raster format (jpg, png, ...)
void endMultiFrameCommand()
QSet< QgsComposerItem * > items()
QgsComposerItem * composerItemAt(const QPointF &position)
Returns the topmost composer item.
void addComposerShape(QgsComposerShape *shape)
Adds a composer shape to the graphics scene and advices composer to create a widget for it (through s...
virtual void moveContent(double dx, double dy)
Move Content of item.
void addShape(Tool currentTool)
Draw a shape on the canvas.
void hideEvent(QHideEvent *e)
void setSceneRect(const QRectF &rectangle)
Adapts mMaximumNumberOfFeatures depending on the rectangle height.
void endCommand()
Saves end state of item and pushes command to the undo history.
void resizeEvent(QResizeEvent *event)
void mousePressEvent(QMouseEvent *)
void selectedItemChanged(QgsComposerItem *selected)
Is emitted when selected item changed.
void setSceneTransform(const QTransform &transform)
void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
void beginCommand(const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Starts new composer undo command.
QPointF mRubberBandStartPos
Start of rubber band creation.
void wheelEvent(QWheelEvent *event)
Graphics scene for map printing.
Object representing map window.
Frame for html, table, text which can be divided onto several frames.
QgsComposerView(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
void addItemsFromXML(const QDomElement &elem, const QDomDocument &doc, QMap< QgsComposerMap *, int > *mapsToRestore=0, bool addUndoCommands=false, QPointF *pos=0, bool pasteInPlace=false)
Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
void setComposerMap(const QgsComposerMap *map)
void ungroupItems()
Ungroups the selected items.
void setPositionLock(bool lock)
Locks / unlocks the item position for mouse drags.
QgsComposerItem * mMoveContentItem
Item to move content.
A table class that displays a vector attribute table.
void addItem(QgsComposerItem *item)
Adds an item to the group.
A composer items that draws common shapes (ellipse, triangle, rectangle)
void keyPressEvent(QKeyEvent *e)
void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)
void setComposition(QgsComposition *c)
Sets composition (derived from QGraphicsScene)
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
void updateCursor(const QPointF &itemPos)
Update mouse cursor at (item) position.
void applyDefaultSize()
Apply default size (scale bar 1/5 of map item width)
void setText(const QString &text)
void showEvent(QShowEvent *e)
void pushAddRemoveCommand(QgsComposerItem *item, const QString &text, QgsAddRemoveItemCommand::State state=QgsAddRemoveItemCommand::Added)
Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo...
A label that can be placed onto a map composition.
void addComposerPicture(QgsComposerPicture *picture)
Adds picture to the graphics scene and advices composer to create a widget for it (through signal) ...
void addComposerTable(QgsComposerAttributeTable *table)
Adds a composer table to the graphics scene and advices composer to create a widget for it (through s...
QgsComposition * composition()
Returns the composition or 0 in case of error.
void mouseMoveEvent(QMouseEvent *)
void actionFinished()
Current action (e.g.
QList< QgsComposerItem * > selectedComposerItems()
QgsComposerRuler * mHorizontalRuler
A legend that can be placed onto a map composition.
void addComposerLabel(QgsComposerLabel *label)
Adds label to the graphics scene and advices composer to create a widget for it (through signal) ...
void addComposerArrow(QgsComposerArrow *arrow)
Adds an arrow item to the graphics scene and advices composer to create a widget for it (through sign...
QGraphicsRectItem * mRubberBandItem
Rubber band item.
void addComposerMap(QgsComposerMap *map, bool setDefaultPreviewStyle=true)
Adds map to the graphics scene and advices composer to create a widget for it (through signal) ...
void addComposerLegend(QgsComposerLegend *legend)
Adds legend to the graphics scene and advices composer to create a widget for it (through signal) ...
void adjustSizeToText()
resizes the widget such that the text fits to the item.
void beginCommand(QgsComposerItem *item, const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.
void composerViewShow(QgsComposerView *)
Emitted before composerview is shown.
void itemRemoved(QgsComposerItem *)
Is emitted when a composer item has been removed from the scene.