31 mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) );
32 mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) );
40 if ( mMouseHandles->scene() )
41 mMouseHandles->scene()->removeItem( mMouseHandles );
48 if ( mMouseHandles->shouldBlockEvent( event ) )
54 if ( mMouseHandles->isVisible() )
57 QgsGraphicsViewMouseHandles::MouseAction mouseAction = mMouseHandles->mouseActionForScenePos( event->
modelPoint() );
59 if ( mouseAction != QgsGraphicsViewMouseHandles::MoveItem
60 && mouseAction != QgsGraphicsViewMouseHandles::NoAction
61 && mouseAction != QgsGraphicsViewMouseHandles::SelectItem )
69 if ( event->button() != Qt::LeftButton )
76 QgsModelComponentGraphicItem *selectedItem =
nullptr;
85 mMousePressStartPos =
event->pos();
86 mRubberBand->start( event->
modelPoint(), Qt::KeyboardModifiers() );
90 if ( ( event->modifiers() & Qt::ShiftModifier ) && ( selectedItem->isSelected() ) )
93 selectedItem->setSelected(
false );
96 const QList<QgsModelComponentGraphicItem *> selectedItems =
scene()->selectedComponentItems();
97 if ( !selectedItems.isEmpty() )
108 if ( ( !selectedItem->isSelected() ) &&
109 !( event->modifiers() & Qt::ShiftModifier ) )
111 scene()->setSelectedItem( selectedItem );
115 selectedItem->setSelected(
true );
120 if ( !( event->modifiers() & Qt::ShiftModifier ) )
124 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
125 for ( QGraphicsItem *item : items )
127 if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast< QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
130 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
132 button->modelPressEvent( event );
148 mRubberBand->update( event->
modelPoint(), Qt::KeyboardModifiers() );
154 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
155 for ( QGraphicsItem *item : items )
157 if ( mHoverEnteredItems.contains( item ) )
159 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
161 component->modelHoverMoveEvent( event );
166 mHoverEnteredItems.append( item );
167 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
169 component->modelHoverEnterEvent( event );
171 else if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast<QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
174 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
175 button->modelHoverEnterEvent( event );
179 const QList< QGraphicsItem * > prevHovered = mHoverEnteredItems;
180 for ( QGraphicsItem *item : prevHovered )
182 if ( ! items.contains( item ) )
184 mHoverEnteredItems.removeAll( item );
185 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
187 component->modelHoverLeaveEvent( event );
189 else if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast<QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
192 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
193 button->modelHoverLeaveEvent( event );
208 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
209 for ( QGraphicsItem *item : items )
211 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
213 scene()->setSelectedItem( component );
214 component->modelDoubleClickEvent( event );
223 if ( event->button() != Qt::LeftButton && mMouseHandles->shouldBlockEvent( event ) )
229 if ( !mIsSelecting || event->button() != Qt::LeftButton )
235 mIsSelecting =
false;
236 bool wasClick = !
isClickAndDrag( mMousePressStartPos, event->pos() );
240 QRectF rect = mRubberBand->finish( event->
modelPoint() );
242 bool subtractingSelection =
false;
243 if ( event->modifiers() & Qt::ShiftModifier )
247 else if ( event->modifiers() & Qt::ControlModifier )
250 subtractingSelection =
true;
259 Qt::ItemSelectionMode selectionMode = Qt::IntersectsItemShape;
260 if ( event->modifiers() & Qt::AltModifier )
263 selectionMode = Qt::ContainsItemShape;
267 QList<QGraphicsItem *> itemList;
269 itemList =
scene()->items( rect.center(), selectionMode );
271 itemList =
scene()->items( rect, selectionMode );
272 for ( QGraphicsItem *item : std::as_const( itemList ) )
274 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
276 if ( subtractingSelection )
278 componentItem->setSelected(
false );
282 componentItem->setSelected(
true );
293 const QList<QgsModelComponentGraphicItem *> selectedItemList =
scene()->selectedComponentItems();
294 if ( !selectedItemList.isEmpty() )
302 mMouseHandles->selectionChanged();
307 if ( mMouseHandles->shouldBlockEvent( event ) )
320 if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
334 mRubberBand->finish();
335 mIsSelecting =
false;
342 return !mIsSelecting;
347 return mMouseHandles;
354 mMouseHandles->deleteLater();
357 mMouseHandles =
new QgsModelViewMouseHandles(
view() );
358 mMouseHandles->hide();
359 mMouseHandles->setZValue( QgsModelGraphicsScene::MouseHandles );
360 scene->addItem( mMouseHandles );
365 mHoverEnteredItems.clear();
A QgsModelViewMouseEvent is the result of a user interaction with the mouse on a QgsModelGraphicsView...
QPointF modelPoint() const
Returns the event point location in model coordinates.
QgsModelViewRectangularRubberBand is rectangular rubber band for use within QgsModelGraphicsView widg...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.