Skip to content

Commit fac2d7f

Browse files
committedOct 6, 2017
Allow selection tool to control selection
1 parent 6b700e2 commit fac2d7f

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed
 

‎src/gui/layout/qgslayoutviewtoolselect.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "qgslayoutviewtoolselect.h"
1717
#include "qgslayoutviewmouseevent.h"
1818
#include "qgslayoutview.h"
19+
#include "qgslayout.h"
20+
#include "qgslayoutitempage.h"
1921

2022
QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
2123
: QgsLayoutViewTool( view, tr( "Select" ) )
@@ -61,8 +63,68 @@ void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event
6163
}
6264

6365
mIsSelecting = false;
66+
if ( !isClickAndDrag( mMousePressStartPos, event->pos() ) )
67+
{
68+
//just a click, do nothing
69+
return;
70+
}
71+
6472
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
66128
}
67129

68130
void QgsLayoutViewToolSelect::deactivate()

0 commit comments

Comments
 (0)
Please sign in to comment.