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 ),
true,
false, option, widget );
54void 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 );
78void QgsModelViewMouseHandles::setViewportCursor( Qt::CursorShape cursor )
83 if ( qobject_cast<QgsModelViewTool *>( mView->tool() ) )
85 mView->viewport()->setCursor( cursor );
89QList<QGraphicsItem *> QgsModelViewMouseHandles::sceneItemsAtPoint( QPointF scenePoint )
91 return modelScene()->items( scenePoint );
94QList<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 )
104QRectF QgsModelViewMouseHandles::itemRect( QGraphicsItem *item )
const
106 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
107 return componentItem->itemRect();
112QRectF QgsModelViewMouseHandles::storedItemRect( QGraphicsItem *item )
const
114 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
115 return componentItem->itemRect(
true );
120void QgsModelViewMouseHandles::moveItem( QGraphicsItem *item,
double deltaX,
double deltaY )
122 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
124 componentItem->moveComponentBy( deltaX, deltaY );
128void QgsModelViewMouseHandles::previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY )
130 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
132 componentItem->previewItemMove( deltaX, deltaY );
136void QgsModelViewMouseHandles::setItemRect( QGraphicsItem *item, QRectF rect )
138 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
140 componentItem->finalizePreviewedItemRectChange( rect );
144QRectF QgsModelViewMouseHandles::previewSetItemRect( QGraphicsItem *item, QRectF rect )
146 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
148 return componentItem->previewItemRectChange( rect );
153void QgsModelViewMouseHandles::startMacroCommand(
const QString &text )
155 mView->startMacroCommand( text );
158void QgsModelViewMouseHandles::endMacroCommand()
160 mView->endMacroCommand();
163QPointF 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;