17#include "moc_qgsmodelviewtoolselect.cpp"
32 mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) );
33 mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) );
41 if ( mMouseHandles->scene() )
42 mMouseHandles->scene()->removeItem( mMouseHandles );
49 if ( mMouseHandles->shouldBlockEvent( event ) )
55 if ( mMouseHandles->isVisible() )
58 QgsGraphicsViewMouseHandles::MouseAction mouseAction = mMouseHandles->mouseActionForScenePos( event->
modelPoint() );
60 if ( mouseAction != QgsGraphicsViewMouseHandles::MoveItem
61 && mouseAction != QgsGraphicsViewMouseHandles::NoAction
62 && mouseAction != QgsGraphicsViewMouseHandles::SelectItem )
70 if ( event->button() != Qt::LeftButton )
77 QgsModelComponentGraphicItem *selectedItem =
nullptr;
86 mMousePressStartPos =
event->pos();
87 mRubberBand->start( event->
modelPoint(), Qt::KeyboardModifiers() );
91 if ( ( event->modifiers() & Qt::ShiftModifier ) && ( selectedItem->isSelected() ) )
94 selectedItem->setSelected(
false );
97 const QList<QgsModelComponentGraphicItem *> selectedItems =
scene()->selectedComponentItems();
98 if ( !selectedItems.isEmpty() )
109 if ( ( !selectedItem->isSelected() ) &&
110 !( event->modifiers() & Qt::ShiftModifier ) )
112 scene()->setSelectedItem( selectedItem );
116 selectedItem->setSelected(
true );
121 if ( !( event->modifiers() & Qt::ShiftModifier ) )
125 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
126 for ( QGraphicsItem *item : items )
128 if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast< QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
131 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
133 button->modelPressEvent( event );
149 mRubberBand->update( event->
modelPoint(), Qt::KeyboardModifiers() );
155 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
156 for ( QGraphicsItem *item : items )
158 if ( mHoverEnteredItems.contains( item ) )
160 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
162 component->modelHoverMoveEvent( event );
167 mHoverEnteredItems.append( item );
168 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
170 component->modelHoverEnterEvent( event );
172 else if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast<QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
175 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
176 button->modelHoverEnterEvent( event );
180 const QList< QGraphicsItem * > prevHovered = mHoverEnteredItems;
181 for ( QGraphicsItem *item : prevHovered )
183 if ( ! items.contains( item ) )
185 mHoverEnteredItems.removeAll( item );
186 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
188 component->modelHoverLeaveEvent( event );
190 else if ( QgsModelDesignerFlatButtonGraphicItem *button =
dynamic_cast<QgsModelDesignerFlatButtonGraphicItem *
>( item ) )
193 if ( mMouseHandles->sceneBoundingRect().contains( event->
modelPoint() ) )
194 button->modelHoverLeaveEvent( event );
209 QList< QGraphicsItem * > items =
scene()->items( event->
modelPoint() );
210 for ( QGraphicsItem *item : items )
212 if ( QgsModelComponentGraphicItem *component =
dynamic_cast< QgsModelComponentGraphicItem *
>( item ) )
214 scene()->setSelectedItem( component );
215 component->modelDoubleClickEvent( event );
224 if ( event->button() != Qt::LeftButton && mMouseHandles->shouldBlockEvent( event ) )
230 if ( !mIsSelecting || event->button() != Qt::LeftButton )
236 mIsSelecting =
false;
237 bool wasClick = !
isClickAndDrag( mMousePressStartPos, event->pos() );
241 QRectF rect = mRubberBand->finish( event->
modelPoint() );
243 bool subtractingSelection =
false;
244 if ( event->modifiers() & Qt::ShiftModifier )
248 else if ( event->modifiers() & Qt::ControlModifier )
251 subtractingSelection =
true;
260 Qt::ItemSelectionMode selectionMode = Qt::IntersectsItemShape;
261 if ( event->modifiers() & Qt::AltModifier )
264 selectionMode = Qt::ContainsItemShape;
268 QList<QGraphicsItem *> itemList;
270 itemList =
scene()->items( rect.center(), selectionMode );
272 itemList =
scene()->items( rect, selectionMode );
273 for ( QGraphicsItem *item : std::as_const( itemList ) )
275 if ( QgsModelComponentGraphicItem *componentItem =
dynamic_cast<QgsModelComponentGraphicItem *
>( item ) )
277 if ( subtractingSelection )
279 componentItem->setSelected(
false );
283 componentItem->setSelected(
true );
294 const QList<QgsModelComponentGraphicItem *> selectedItemList =
scene()->selectedComponentItems();
295 if ( !selectedItemList.isEmpty() )
303 mMouseHandles->selectionChanged();
308 if ( mMouseHandles->shouldBlockEvent( event ) )
321 if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
335 mRubberBand->finish();
336 mIsSelecting =
false;
343 return !mIsSelecting;
348 return mMouseHandles;
355 mMouseHandles->deleteLater();
358 mMouseHandles =
new QgsModelViewMouseHandles(
view() );
359 mMouseHandles->hide();
360 mMouseHandles->setZValue( QgsModelGraphicsScene::MouseHandles );
361 scene->addItem( mMouseHandles );
366 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.