|
16 | 16 | #include "qgslayoutviewtoolselect.h"
|
17 | 17 | #include "qgslayoutviewmouseevent.h"
|
18 | 18 | #include "qgslayoutview.h"
|
| 19 | +#include "qgslayout.h" |
| 20 | +#include "qgslayoutitempage.h" |
19 | 21 |
|
20 | 22 | QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
|
21 | 23 | : QgsLayoutViewTool( view, tr( "Select" ) )
|
@@ -61,8 +63,68 @@ void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event
|
61 | 63 | }
|
62 | 64 |
|
63 | 65 | mIsSelecting = false;
|
| 66 | + if ( !isClickAndDrag( mMousePressStartPos, event->pos() ) ) |
| 67 | + { |
| 68 | + //just a click, do nothing |
| 69 | + return; |
| 70 | + } |
| 71 | + |
64 | 72 | QRectF rect = mRubberBand->finish( event->layoutPoint(), event->modifiers() );
|
65 |
| - Q_UNUSED( rect ); |
| 73 | + |
| 74 | + bool subtractingSelection = false; |
| 75 | + if ( event->modifiers() & Qt::ShiftModifier ) |
| 76 | + { |
| 77 | + //shift modifer means adding to selection, nothing required here |
| 78 | + } |
| 79 | + else if ( event->modifiers() & Qt::ControlModifier ) |
| 80 | + { |
| 81 | + //control modifier means subtract from current selection |
| 82 | + subtractingSelection = true; |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + //not adding to or removing from selection, so clear current selection |
| 87 | + layout()->deselectAll(); |
| 88 | + } |
| 89 | + |
| 90 | + //determine item selection mode, default to intersection |
| 91 | + Qt::ItemSelectionMode selectionMode = Qt::IntersectsItemShape; |
| 92 | + if ( event->modifiers() & Qt::AltModifier ) |
| 93 | + { |
| 94 | + //alt modifier switches to contains selection mode |
| 95 | + selectionMode = Qt::ContainsItemShape; |
| 96 | + } |
| 97 | + |
| 98 | + //find all items in rect |
| 99 | + const QList<QGraphicsItem *> itemList = layout()->items( rect, selectionMode ); |
| 100 | + for ( QGraphicsItem *item : itemList ) |
| 101 | + { |
| 102 | + QgsLayoutItem *layoutItem = dynamic_cast<QgsLayoutItem *>( item ); |
| 103 | + QgsLayoutItemPage *paperItem = dynamic_cast<QgsLayoutItemPage *>( item ); |
| 104 | + if ( layoutItem && !paperItem ) |
| 105 | + { |
| 106 | + if ( !layoutItem->isLocked() ) |
| 107 | + { |
| 108 | + if ( subtractingSelection ) |
| 109 | + { |
| 110 | + layoutItem->setSelected( false ); |
| 111 | + } |
| 112 | + else |
| 113 | + { |
| 114 | + layoutItem->setSelected( true ); |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | +#if 0 //TODO |
| 121 | + //update item panel |
| 122 | + QList<QgsComposerItem *> selectedItemList = composition()->selectedComposerItems(); |
| 123 | + if ( !selectedItemList.isEmpty() ) |
| 124 | + { |
| 125 | + emit selectedItemChanged( selectedItemList[0] ); |
| 126 | + } |
| 127 | +#endif |
66 | 128 | }
|
67 | 129 |
|
68 | 130 | void QgsLayoutViewToolSelect::deactivate()
|
|
0 commit comments