19#include "moc_qgsmodelviewmousehandles.cpp"
27#include <QGraphicsSceneHoverEvent>
35QgsModelViewMouseHandles::QgsModelViewMouseHandles( QgsModelGraphicsView *view )
36 : QgsGraphicsViewMouseHandles( view )
40 connect( modelScene(), &QGraphicsScene::selectionChanged,
this, &QgsModelViewMouseHandles::selectionChanged );
44QgsModelGraphicsScene *QgsModelViewMouseHandles::modelScene()
const
46 return qobject_cast< QgsModelGraphicsScene * >( mView->scene() );
49void QgsModelViewMouseHandles::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
51 paintInternal( painter, !( modelScene()->flags() & QgsModelGraphicsScene::FlagHideControls ),
52 true,
false, option, widget );
55void QgsModelViewMouseHandles::selectionChanged()
58 const QList<QGraphicsItem *> itemList = mView->items();
59 for ( QGraphicsItem *graphicsItem : itemList )
61 QgsModelComponentGraphicItem *item =
dynamic_cast<QgsModelComponentGraphicItem *
>( graphicsItem );
65 if ( item->isSelected() )
67 connect( item, &QgsModelComponentGraphicItem::sizePositionChanged,
this, &QgsModelViewMouseHandles::selectedItemSizeChanged );
71 disconnect( item, &QgsModelComponentGraphicItem::sizePositionChanged,
this, &QgsModelViewMouseHandles::selectedItemSizeChanged );
79void QgsModelViewMouseHandles::setViewportCursor( Qt::CursorShape cursor )
84 if ( qobject_cast< QgsModelViewTool *>( mView->tool() ) )
86 mView->viewport()->setCursor( cursor );
90QList<QGraphicsItem *> QgsModelViewMouseHandles::sceneItemsAtPoint( QPointF scenePoint )
92 return modelScene()->items( scenePoint );
95QList<QGraphicsItem *> QgsModelViewMouseHandles::selectedSceneItems(
bool )
const
97 QList<QGraphicsItem *> res;
98 const QList<QgsModelComponentGraphicItem *> componentItems = modelScene()->selectedComponentItems();
99 res.reserve( componentItems.size() );
100 for ( QgsModelComponentGraphicItem *item : componentItems )
105QRectF QgsModelViewMouseHandles::itemRect( QGraphicsItem *item )
const
107 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
108 return componentItem->itemRect();
113QRectF QgsModelViewMouseHandles::storedItemRect( QGraphicsItem *item )
const
115 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
116 return componentItem->itemRect(
true );
121void QgsModelViewMouseHandles::moveItem( QGraphicsItem *item,
double deltaX,
double deltaY )
123 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
125 componentItem->moveComponentBy( deltaX, deltaY );
129void QgsModelViewMouseHandles::previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY )
131 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
133 componentItem->previewItemMove( deltaX, deltaY );
137void QgsModelViewMouseHandles::setItemRect( QGraphicsItem *item, QRectF rect )
139 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
141 componentItem->finalizePreviewedItemRectChange( rect );
145QRectF QgsModelViewMouseHandles::previewSetItemRect( QGraphicsItem *item, QRectF rect )
147 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
149 return componentItem->previewItemRectChange( rect );
154void QgsModelViewMouseHandles::startMacroCommand(
const QString &text )
156 mView->startMacroCommand( text );
159void QgsModelViewMouseHandles::endMacroCommand()
161 mView->endMacroCommand();
164QPointF QgsModelViewMouseHandles::snapPoint( QPointF originalPoint, QgsGraphicsViewMouseHandles::SnapGuideMode mode,
bool snapHorizontal,
bool snapVertical )
166 bool snapped =
false;
168 QPointF snappedPoint;
173 snappedPoint = mView->snapper()->snapPoint( originalPoint, mView->transform().m11(), snapped, snapHorizontal, snapVertical );
177 return snapped ? snappedPoint : originalPoint;