Skip to content

Commit aaa2fcf

Browse files
nyalldawsonmhugent
authored andcommittedSep 21, 2013
[feature] CTRL-click in composer to select items below other items (fix #4358)
1 parent e447813 commit aaa2fcf

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed
 

‎src/core/composer/qgscomposition.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ int QgsComposition::numPages() const
170170

171171
QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
172172
{
173+
return composerItemAt( position, 0 );
174+
}
175+
176+
QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position, const QgsComposerItem* belowItem )
177+
{
178+
//get a list of items which intersect the specified position, in descending z order
173179
QList<QGraphicsItem*> itemList;
174180
if ( mSelectionTolerance <= 0.0 )
175181
{
176-
itemList = items( position );
182+
itemList = items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
177183
}
178184
else
179185
{
@@ -182,13 +188,27 @@ QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
182188
}
183189
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
184190

191+
bool foundBelowItem = false;
185192
for ( ; itemIt != itemList.end(); ++itemIt )
186193
{
187194
QgsComposerItem* composerItem = dynamic_cast<QgsComposerItem *>( *itemIt );
188195
QgsPaperItem* paperItem = dynamic_cast<QgsPaperItem*>( *itemIt );
189196
if ( composerItem && !paperItem )
190197
{
191-
return composerItem;
198+
// If we are not checking for a an item below a specified item, or if we've
199+
// already found that item, then we've found our target
200+
if ( ! belowItem || foundBelowItem )
201+
{
202+
return composerItem;
203+
}
204+
else
205+
{
206+
if ( composerItem == belowItem )
207+
{
208+
//Target item is next in list
209+
foundBelowItem = true;
210+
}
211+
}
192212
}
193213
}
194214
return 0;

‎src/core/composer/qgscomposition.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
131131
/**Returns the topmost composer item. Ignores mPaperItem*/
132132
QgsComposerItem* composerItemAt( const QPointF & position );
133133

134+
/**Returns the highest composer item at a specified position which is below a specified item. Ignores mPaperItem
135+
@note Added in QGIS 2.1
136+
*/
137+
QgsComposerItem* composerItemAt( const QPointF & position, const QgsComposerItem* belowItem );
138+
134139
/** Returns the page number (0-bsaed) given a coordinate */
135140
int pageNumberAt( const QPointF& position ) const;
136141

‎src/gui/qgscomposerview.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,43 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
8989
//select/deselect items and pass mouse event further
9090
case Select:
9191
{
92+
QgsComposerItem* selectedItem;
93+
QgsComposerItem* previousSelectedItem = 0;
94+
95+
if ( e->modifiers() & Qt::ControlModifier )
96+
{
97+
//CTRL modifier, so we are trying to select the next item below the current one
98+
//first, find currently selected item
99+
QList<QgsComposerItem*> selectedItems = composition()->selectedComposerItems();
100+
if ( selectedItems.size() > 0 )
101+
{
102+
previousSelectedItem = selectedItems.at( 0 );
103+
}
104+
}
105+
92106
if ( !( e->modifiers() & Qt::ShiftModifier ) ) //keep selection if shift key pressed
93107
{
94108
composition()->clearSelection();
95109
}
96110

97-
//select topmost item at position of event
98-
QgsComposerItem* selectedItem = composition()->composerItemAt( scenePoint );
111+
if ( previousSelectedItem )
112+
{
113+
//select highest item just below previously selected item at position of event
114+
selectedItem = composition()->composerItemAt( scenePoint, previousSelectedItem );
115+
116+
//if we didn't find a lower item we'll use the top-most as fall-back
117+
//this duplicates mapinfo/illustrator/etc behaviour where ctrl-clicks are "cyclic"
118+
if ( !selectedItem )
119+
{
120+
selectedItem = composition()->composerItemAt( scenePoint );
121+
}
122+
}
123+
else
124+
{
125+
//select topmost item at position of event
126+
selectedItem = composition()->composerItemAt( scenePoint );
127+
}
128+
99129
if ( !selectedItem )
100130
{
101131
break;

0 commit comments

Comments
 (0)
Please sign in to comment.