[composer] Don't draw handles around locked items (fix #11059)

This commit is contained in:
Nyall Dawson 2014-08-25 22:58:27 +10:00
parent 29afed61e1
commit 7b84ccc9b1
8 changed files with 68 additions and 42 deletions

View File

@ -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*/
@ -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)
@ -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();
};

View File

@ -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

View File

@ -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();
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";
}
QImage lockImage( lockIconPath );
if ( !lockImage.isNull() )
{
p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
}
}
return;
}
//logic for drawing additional graphics on selected items here (if required)
//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 )
@ -552,6 +555,8 @@ void QgsComposerItem::setPositionLock( const bool lock )
{
mComposition->itemsModel()->updateItemLockStatus( this );
}
update();
emit lockChanged();
}
double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const

View File

@ -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*/
@ -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)
@ -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)

View File

@ -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;

View File

@ -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;
@ -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 );
}
}
}
@ -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
@ -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
@ -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
@ -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 )
{
@ -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 )
{
@ -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 )
{

View File

@ -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;
@ -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 );
}

View File

@ -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