Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Aug 25, 2014
1 parent 29afed6 commit 7b84ccc9b1d6bf897eae3c0f062c63278b00fc21
@@ -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();

};
@@ -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
@@ -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 )
@@ -552,6 +555,8 @@ void QgsComposerItem::setPositionLock( const bool lock )
{
mComposition->itemsModel()->updateItemLockStatus( this );
}
update();
emit lockChanged();
}

double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const
@@ -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)
@@ -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;

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

0 comments on commit 7b84ccc

Please sign in to comment.
You can’t perform that action at this time.