Skip to content

Commit

Permalink
[composer] Locked items can't be selected by clicking them in the can…
Browse files Browse the repository at this point in the history
…vas.
  • Loading branch information
nyalldawson committed Jul 30, 2014
1 parent 7b347c7 commit 0aeb357
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
17 changes: 12 additions & 5 deletions python/core/composer/qgscomposition.sip
Expand Up @@ -181,13 +181,20 @@ class QgsComposition : QGraphicsScene
/**Returns pointer to undo/redo command storage*/
QUndoStack* undoStack();

/**Returns the topmost composer item. Ignores mPaperItem*/
QgsComposerItem* composerItemAt( const QPointF & position ) const;
/**Returns the topmost composer item at a specified position. Ignores paper items.
* @param position point to search for item at
* @param ignoreLocked set to true to ignore locked items
* @returns composer item at position
*/
QgsComposerItem* composerItemAt( const QPointF & position, const bool ignoreLocked = false ) const;

/**Returns the highest composer item at a specified position which is below a specified item. Ignores mPaperItem
@note Added in QGIS 2.1
/**Returns the topmost composer item at a specified position which is below a specified item. Ignores paper items.
* @param position point to search for item at
* @param belowItem item to search below
* @param ignoreLocked set to true to ignore locked items
* @returns composer item at position which is below specified item
*/
QgsComposerItem* composerItemAt( const QPointF & position, const QgsComposerItem* belowItem ) const;
QgsComposerItem* composerItemAt( const QPointF & position, const QgsComposerItem* belowItem, const bool ignoreLocked = false ) const;

/** Returns the page number (0-bsaed) given a coordinate */
int pageNumberAt( const QPointF& position ) const;
Expand Down
8 changes: 4 additions & 4 deletions src/core/composer/qgscomposition.cpp 100755 → 100644
Expand Up @@ -444,12 +444,12 @@ void QgsComposition::setStatusMessage( const QString & message )
emit statusMsgChanged( message );
}

QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position ) const
QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position , const bool ignoreLocked ) const
{
return composerItemAt( position, 0 );
return composerItemAt( position, 0, ignoreLocked );
}

QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position, const QgsComposerItem* belowItem ) const
QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position, const QgsComposerItem* belowItem, const bool ignoreLocked ) const
{
//get a list of items which intersect the specified position, in descending z order
QList<QGraphicsItem*> itemList;
Expand All @@ -465,7 +465,7 @@ QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position, const
{
// If we are not checking for a an item below a specified item, or if we've
// already found that item, then we've found our target
if ( ! belowItem || foundBelowItem )
if (( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !composerItem->positionLock() ) )
{
return composerItem;
}
Expand Down
17 changes: 12 additions & 5 deletions src/core/composer/qgscomposition.h
Expand Up @@ -241,13 +241,20 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Returns pointer to undo/redo command storage*/
QUndoStack* undoStack() { return mUndoStack; }

/**Returns the topmost composer item. Ignores mPaperItem*/
QgsComposerItem* composerItemAt( const QPointF & position ) const;
/**Returns the topmost composer item at a specified position. Ignores paper items.
* @param position point to search for item at
* @param ignoreLocked set to true to ignore locked items
* @returns composer item at position
*/
QgsComposerItem* composerItemAt( const QPointF & position, const bool ignoreLocked = false ) const;

/**Returns the highest composer item at a specified position which is below a specified item. Ignores mPaperItem
@note Added in QGIS 2.1
/**Returns the topmost composer item at a specified position which is below a specified item. Ignores paper items.
* @param position point to search for item at
* @param belowItem item to search below
* @param ignoreLocked set to true to ignore locked items
* @returns composer item at position which is below specified item
*/
QgsComposerItem* composerItemAt( const QPointF & position, const QgsComposerItem* belowItem ) const;
QgsComposerItem* composerItemAt( const QPointF & position, const QgsComposerItem* belowItem, const bool ignoreLocked = false ) const;

/** Returns the page number (0-based) given a coordinate */
int pageNumberAt( const QPointF& position ) const;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -208,19 +208,19 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
if ( previousSelectedItem )
{
//select highest item just below previously selected item at position of event
selectedItem = composition()->composerItemAt( scenePoint, previousSelectedItem );
selectedItem = composition()->composerItemAt( scenePoint, previousSelectedItem, true );

//if we didn't find a lower item we'll use the top-most as fall-back
//this duplicates mapinfo/illustrator/etc behaviour where ctrl-clicks are "cyclic"
if ( !selectedItem )
{
selectedItem = composition()->composerItemAt( scenePoint );
selectedItem = composition()->composerItemAt( scenePoint, true );
}
}
else
{
//select topmost item at position of event
selectedItem = composition()->composerItemAt( scenePoint );
selectedItem = composition()->composerItemAt( scenePoint, true );
}

if ( !selectedItem )
Expand Down Expand Up @@ -1506,7 +1506,7 @@ void QgsComposerView::wheelEvent( QWheelEvent* event )

QPointF scenePoint = mapToScene( event->pos() );
//select topmost item at position of event
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint, true );
if ( theItem )
{
if ( theItem->isSelected() )
Expand Down

0 comments on commit 0aeb357

Please sign in to comment.