19 #include "qgsprocessingmodelalgorithm.h"
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;
78 QList<QgsModelComponentGraphicItem *> selectedItems =
scene()->selectedComponentItems();
87 mMousePressStartPos =
event->pos();
88 mRubberBand->start( event->
modelPoint(),
nullptr );
92 if ( ( event->modifiers() & Qt::ShiftModifier ) && ( selectedItem->isSelected() ) )
95 selectedItem->setSelected(
false );
98 const QList<QgsModelComponentGraphicItem *> selectedItems =
scene()->selectedComponentItems();
99 if ( !selectedItems.isEmpty() )
110 if ( ( !selectedItem->isSelected() ) &&
111 !( event->modifiers() & Qt::ShiftModifier ) )
113 scene()->setSelectedItem( selectedItem );
117 selectedItem->setSelected(
true );
122 if ( !( event->modifiers() & Qt::ShiftModifier ) )
126 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
127 for ( QGraphicsItem *item : items )
129 if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast< QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
132 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
134 button->modelPressEvent( event );
150 mRubberBand->update( event->
modelPoint(),
nullptr );
156 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
157 for ( QGraphicsItem *item : items )
159 if ( mHoverEnteredItems.contains( item ) )
161 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
163 component->modelHoverMoveEvent( event );
168 mHoverEnteredItems.append( item );
169 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
171 component->modelHoverEnterEvent( event );
173 else if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast<QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
176 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
177 button->modelHoverEnterEvent( event );
181 const QList< QGraphicsItem * > prevHovered = mHoverEnteredItems;
182 for ( QGraphicsItem *item : prevHovered )
184 if ( ! items.contains( item ) )
186 mHoverEnteredItems.removeAll( item );
187 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
189 component->modelHoverLeaveEvent( event );
191 else if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast<QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
194 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
195 button->modelHoverLeaveEvent( event );
210 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
211 for ( QGraphicsItem *item : items )
213 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
215 scene()->setSelectedItem( component );
216 component->modelDoubleClickEvent( event );
225 if ( event->button() != Qt::LeftButton && mMouseHandles->shouldBlockEvent( event ) )
231 if ( !mIsSelecting || event->button() != Qt::LeftButton )
237 mIsSelecting =
false;
238 bool wasClick = !
isClickAndDrag( mMousePressStartPos, event->pos() );
242 QRectF rect = mRubberBand->finish( event->
modelPoint() );
244 bool subtractingSelection =
false;
245 if ( event->modifiers() & Qt::ShiftModifier )
249 else if ( event->modifiers() & Qt::ControlModifier )
252 subtractingSelection =
true;
261 Qt::ItemSelectionMode selectionMode = Qt::IntersectsItemShape;
262 if ( event->modifiers() & Qt::AltModifier )
265 selectionMode = Qt::ContainsItemShape;
269 QList<QGraphicsItem *> itemList;
271 itemList =
scene()->items( rect.center(), selectionMode );
273 itemList =
scene()->items( rect, selectionMode );
274 for ( QGraphicsItem *item : qgis::as_const( itemList ) )
276 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
278 if ( subtractingSelection )
280 componentItem->setSelected(
false );
284 componentItem->setSelected(
true );
295 const QList<QgsModelComponentGraphicItem *> selectedItemList =
scene()->selectedComponentItems();
296 if ( !selectedItemList.isEmpty() )
304 mMouseHandles->selectionChanged();
309 if ( mMouseHandles->shouldBlockEvent( event ) )
322 if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
336 mRubberBand->finish();
337 mIsSelecting =
false;
344 return !mIsSelecting;
349 return mMouseHandles;
356 mMouseHandles->deleteLater();
359 mMouseHandles =
new QgsModelViewMouseHandles(
view() );
360 mMouseHandles->hide();
361 mMouseHandles->setZValue( QgsModelGraphicsScene::MouseHandles );
362 scene->addItem( mMouseHandles );
367 mHoverEnteredItems.clear();