26 #include <QGraphicsSceneHoverEvent>
34 QgsModelViewMouseHandles::QgsModelViewMouseHandles( QgsModelGraphicsView *view )
35 : QgsGraphicsViewMouseHandles( view )
39 connect( modelScene(), &QGraphicsScene::selectionChanged,
this, &QgsModelViewMouseHandles::selectionChanged );
43 QgsModelGraphicsScene *QgsModelViewMouseHandles::modelScene()
const
45 return qobject_cast< QgsModelGraphicsScene * >( mView->scene() );
48 void QgsModelViewMouseHandles::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
50 paintInternal( painter, !( modelScene()->flags() & QgsModelGraphicsScene::FlagHideControls ),
51 true,
false, option, widget );
54 void QgsModelViewMouseHandles::selectionChanged()
57 const QList<QGraphicsItem *> itemList = mView->items();
58 for ( QGraphicsItem *graphicsItem : itemList )
60 QgsModelComponentGraphicItem *item =
dynamic_cast<QgsModelComponentGraphicItem *
>( graphicsItem );
64 if ( item->isSelected() )
66 connect( item, &QgsModelComponentGraphicItem::sizePositionChanged,
this, &QgsModelViewMouseHandles::selectedItemSizeChanged );
70 disconnect( item, &QgsModelComponentGraphicItem::sizePositionChanged,
this, &QgsModelViewMouseHandles::selectedItemSizeChanged );
78 void QgsModelViewMouseHandles::setViewportCursor( Qt::CursorShape cursor )
83 if ( qobject_cast< QgsModelViewTool *>( mView->tool() ) )
85 mView->viewport()->setCursor( cursor );
89 QList<QGraphicsItem *> QgsModelViewMouseHandles::sceneItemsAtPoint( QPointF scenePoint )
91 return modelScene()->items( scenePoint );
94 QList<QGraphicsItem *> QgsModelViewMouseHandles::selectedSceneItems(
bool )
const
96 QList<QGraphicsItem *> res;
97 const QList<QgsModelComponentGraphicItem *> componentItems = modelScene()->selectedComponentItems();
98 res.reserve( componentItems.size() );
99 for ( QgsModelComponentGraphicItem *item : componentItems )
104 QRectF QgsModelViewMouseHandles::itemRect( QGraphicsItem *item )
const
106 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
107 return componentItem->itemRect();
112 QRectF QgsModelViewMouseHandles::storedItemRect( QGraphicsItem *item )
const
114 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
115 return componentItem->itemRect(
true );
120 void QgsModelViewMouseHandles::moveItem( QGraphicsItem *item,
double deltaX,
double deltaY )
122 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
124 componentItem->moveComponentBy( deltaX, deltaY );
128 void QgsModelViewMouseHandles::previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY )
130 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
132 componentItem->previewItemMove( deltaX, deltaY );
136 void QgsModelViewMouseHandles::setItemRect( QGraphicsItem *item, QRectF rect )
138 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
140 componentItem->finalizePreviewedItemRectChange( rect );
144 QRectF QgsModelViewMouseHandles::previewSetItemRect( QGraphicsItem *item, QRectF rect )
146 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
148 return componentItem->previewItemRectChange( rect );
153 void QgsModelViewMouseHandles::startMacroCommand(
const QString &text )
155 mView->startMacroCommand( text );
158 void QgsModelViewMouseHandles::endMacroCommand()
160 mView->endMacroCommand();
163 QPointF QgsModelViewMouseHandles::snapPoint( QPointF originalPoint, QgsGraphicsViewMouseHandles::SnapGuideMode mode,
bool snapHorizontal,
bool snapVertical )
165 bool snapped =
false;
167 QPointF snappedPoint;
172 snappedPoint = mView->snapper()->snapPoint( originalPoint, mView->transform().m11(), snapped, snapHorizontal, snapVertical );
176 return snapped ? snappedPoint : originalPoint;