Skip to content

Commit

Permalink
[composer] Don't draw handles around locked items (fix #11059)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 25, 2014
1 parent 29afed6 commit 7b84ccc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 40 deletions.
14 changes: 11 additions & 3 deletions python/core/composer/qgscomposeritem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem

virtual void hoverMoveEvent( QGraphicsSceneHoverEvent * event );

/**Draw selection boxes around item*/
/**Draws additional graphics on selected items. The base implementation has
* no effect.
*/
virtual void drawSelectionBoxes( QPainter* p );

/**Draw black frame around item*/
Expand All @@ -629,8 +631,10 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
double rectHandlerBorderTolerance() const;

/**Returns the size of the lock symbol depending on the composer zoom level and the item size
@note: this function was introduced in version 1.2*/
double lockSymbolSize() const;
* @note: this function was introduced in version 1.2
* @deprecated will be removed in QGIS 3.0
*/
double lockSymbolSize() const /Deprecated/;

/**Returns the zoom factor of the graphics view.
@return the factor or -1 in case of error (e.g. graphic view does not exist)
Expand Down Expand Up @@ -706,5 +710,9 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
* @note: this function was introduced in version 2.2
*/
void frameChanged();
/**Emitted if the item's lock status changes
* @note: this function was introduced in version 2.5
*/
void lockChanged();

};
6 changes: 5 additions & 1 deletion python/core/composer/qgscomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ class QgsComposition : QGraphicsScene
/** Returns on which page number (0-based) is displayed an item */
int itemPageNumber( const QgsComposerItem* ) const;

QList<QgsComposerItem*> selectedComposerItems();
/**Returns list of selected composer items
* @param includeLockedItems set to true to include locked items in list
* @returns list of selected items
*/
QList<QgsComposerItem*> selectedComposerItems( const bool includeLockedItems = true );

%If (QLISTCONSTPTR_CONVERSION)
/**Returns pointers to all composer maps in the scene
Expand Down
41 changes: 23 additions & 18 deletions src/core/composer/qgscomposeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,32 +497,35 @@ void QgsComposerItem::cancelCommand()

void QgsComposerItem::drawSelectionBoxes( QPainter* p )
{

if ( !mComposition )
Q_UNUSED( p );
if ( !mComposition || mComposition->plotStyle() != QgsComposition::Preview )
{
return;
}

if ( mComposition->plotStyle() == QgsComposition::Preview )
if ( !isSelected() )
{
double sizeLockSymbol = lockSymbolSize();
return;
}

if ( mItemPositionLocked )
{
//draw lock symbol at upper left edge. Use QImage to be independent of the graphic system
QString lockIconPath = QgsApplication::activeThemePath() + "/mIconLock.png";
if ( !QFile::exists( lockIconPath ) )
{
lockIconPath = QgsApplication::defaultThemePath() + "/mIconLock.png";
}
//logic for drawing additional graphics on selected items here (if required)

QImage lockImage( lockIconPath );
if ( !lockImage.isNull() )
{
p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
}
}
//draw dotted border around locked, selected items
if ( positionLock() )
{
p->save();
p->setCompositionMode( QPainter::CompositionMode_Difference );

// use a grey dashed pen - in difference mode this should always be visible
QPen selectedItemPen = QPen( QColor( 144, 144, 144, 255 ) );
selectedItemPen.setStyle( Qt::DotLine );
selectedItemPen.setWidth( 0 );
p->setPen( selectedItemPen );
p->setBrush( Qt::NoBrush );
p->drawPolygon( rect() );
p->restore();
}

}

void QgsComposerItem::drawFrame( QPainter* p )
Expand Down Expand Up @@ -552,6 +555,8 @@ void QgsComposerItem::setPositionLock( const bool lock )
{
mComposition->itemsModel()->updateItemLockStatus( this );
}
update();
emit lockChanged();
}

double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const
Expand Down
14 changes: 11 additions & 3 deletions src/core/composer/qgscomposeritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
@note: this member was added in version 2.4*/
int mCurrentExportLayer;

/**Draw selection boxes around item*/
/**Draws additional graphics on selected items. The base implementation has
* no effect.
*/
virtual void drawSelectionBoxes( QPainter* p );

/**Draw black frame around item*/
Expand All @@ -637,8 +639,10 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
double rectHandlerBorderTolerance() const;

/**Returns the size of the lock symbol depending on the composer zoom level and the item size
@note: this function was introduced in version 1.2*/
double lockSymbolSize() const;
* @note: this function was introduced in version 1.2
* @deprecated will be removed in QGIS 3.0
*/
Q_DECL_DEPRECATED double lockSymbolSize() const;

/**Returns the zoom factor of the graphics view.
@return the factor or -1 in case of error (e.g. graphic view does not exist)
Expand Down Expand Up @@ -714,6 +718,10 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
* @note: this function was introduced in version 2.2
*/
void frameChanged();
/**Emitted if the item's lock status changes
* @note: this function was introduced in version 2.5
*/
void lockChanged();

private:
// id (not unique)
Expand Down
5 changes: 0 additions & 5 deletions src/core/composer/qgscomposermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ bool QgsComposerModel::setData( const QModelIndex & index, const QVariant & valu
case LockStatus:
//second column is item lock state
item->setPositionLock( value.toBool() );
if ( value.toBool() )
{
//deselect item when locking
item->setSelected( false );
}
emit dataChanged( index, index );
return true;

Expand Down
16 changes: 9 additions & 7 deletions src/core/composer/qgscomposermousehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void QgsComposerMouseHandles::drawHandles( QPainter* painter, double rectHandler
void QgsComposerMouseHandles::drawSelectedItemBounds( QPainter* painter )
{
//draw dotted border around selected items to give visual feedback which items are selected
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
if ( selectedItems.size() == 0 )
{
return;
Expand Down Expand Up @@ -206,12 +206,14 @@ void QgsComposerMouseHandles::selectionChanged()
QObject::connect( item, SIGNAL( sizeChanged() ), this, SLOT( selectedItemSizeChanged() ) );
QObject::connect( item, SIGNAL( itemRotationChanged( double ) ), this, SLOT( selectedItemRotationChanged() ) );
QObject::connect( item, SIGNAL( frameChanged( ) ), this, SLOT( selectedItemSizeChanged() ) );
QObject::connect( item, SIGNAL( lockChanged( ) ), this, SLOT( selectedItemSizeChanged() ) );
}
else
{
QObject::disconnect( item, SIGNAL( sizeChanged() ), this, 0 );
QObject::disconnect( item, SIGNAL( itemRotationChanged( double ) ), this, 0 );
QObject::disconnect( item, SIGNAL( frameChanged( ) ), this, 0 );
QObject::disconnect( item, SIGNAL( lockChanged( ) ), this, 0 );
}
}
}
Expand Down Expand Up @@ -243,7 +245,7 @@ void QgsComposerMouseHandles::updateHandles()
//recalculate size and position of handle item

//first check to see if any items are selected
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
if ( selectedItems.size() > 0 )
{
//one or more items are selected, get bounds of all selected items
Expand Down Expand Up @@ -282,7 +284,7 @@ void QgsComposerMouseHandles::updateHandles()
QRectF QgsComposerMouseHandles::selectionBounds() const
{
//calculate bounds of all currently selected items in mouse handle coordinate system
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();

//start with handle bounds of first selected item
Expand All @@ -300,7 +302,7 @@ QRectF QgsComposerMouseHandles::selectionBounds() const
bool QgsComposerMouseHandles::selectionRotation( double & rotation ) const
{
//check if all selected items have same rotation
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();

//start with rotation of first selected item
Expand Down Expand Up @@ -598,7 +600,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
QPointF mEndHandleMovePos = scenePos();

//move all selected items
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();
for ( ; itemIter != selectedItems.end(); ++itemIter )
{
Expand All @@ -621,7 +623,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
QUndoCommand* parentCommand = new QUndoCommand( tr( "Change item size" ) );

//resize all selected items
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();
for ( ; itemIter != selectedItems.end(); ++itemIter )
{
Expand Down Expand Up @@ -679,7 +681,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event

void QgsComposerMouseHandles::resetStatusBar()
{
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems( false );
int selectedCount = selectedItems.size();
if ( selectedCount > 1 )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ int QgsComposition::itemPageNumber( const QgsComposerItem* item ) const
return pageNumberAt( QPointF( item->pos().x(), item->pos().y() ) );
}

QList<QgsComposerItem*> QgsComposition::selectedComposerItems()
QList<QgsComposerItem*> QgsComposition::selectedComposerItems( const bool includeLockedItems )
{
QList<QgsComposerItem*> composerItemList;

Expand All @@ -521,7 +521,7 @@ QList<QgsComposerItem*> QgsComposition::selectedComposerItems()
for ( ; itemIter != graphicsItemList.end(); ++itemIter )
{
QgsComposerItem* composerItem = dynamic_cast<QgsComposerItem *>( *itemIter );
if ( composerItem )
if ( composerItem && ( includeLockedItems || !composerItem->positionLock() ) )
{
composerItemList.push_back( composerItem );
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/** Returns on which page number (0-based) is displayed an item */
int itemPageNumber( const QgsComposerItem* ) const;

QList<QgsComposerItem*> selectedComposerItems();
/**Returns list of selected composer items
* @param includeLockedItems set to true to include locked items in list
* @returns list of selected items
*/
QList<QgsComposerItem*> selectedComposerItems( const bool includeLockedItems = true );

/**Returns pointers to all composer maps in the scene
@note available in python bindings only with PyQt >= 4.8.4
Expand Down

0 comments on commit 7b84ccc

Please sign in to comment.