Skip to content
Permalink
Browse files

[FEATURE] Add "Lock Selected Items" and "Unlock All" to composer layo…

…ut menu and toolbar
  • Loading branch information
nyalldawson authored and mhugent committed Sep 9, 2013
1 parent d6da4de commit c705034977207b01e764e829ec6578945dc7b3f6
@@ -245,6 +245,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
layoutMenu->addAction( mActionLowerItems );
layoutMenu->addAction( mActionMoveItemsToTop );
layoutMenu->addAction( mActionMoveItemsToBottom );
layoutMenu->addAction( mActionLockItems );
layoutMenu->addAction( mActionUnlockAll );

#ifdef Q_WS_MAC
// this doesn't work on Mac anymore: menuBar()->addMenu( mQgis->windowMenu() );
@@ -1645,6 +1647,22 @@ void QgsComposer::on_mActionUngroupItems_triggered()
}
}

void QgsComposer::on_mActionLockItems_triggered()
{
if ( mView )
{
mView->lockItems();
}
}

void QgsComposer::on_mActionUnlockAll_triggered()
{
if ( mView )
{
mView->unlockAllItems();
}
}

void QgsComposer::on_mActionRaiseItems_triggered()
{
if ( mComposition )
@@ -210,6 +210,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Ungroup selected item group
void on_mActionUngroupItems_triggered();

//! Lock selected items
void on_mActionLockItems_triggered();

//! Unlock all items
void on_mActionUnlockAll_triggered();

//! Move selected items one position up
void on_mActionRaiseItems_triggered();

@@ -265,11 +265,11 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
QString positionLock = itemElem.attribute( "positionLock" );
if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 )
{
mItemPositionLocked = true;
setPositionLock( true );
}
else
{
mItemPositionLocked = false;
setPositionLock( false );
}

//position
@@ -802,6 +802,11 @@ void QgsComposerItem::drawFrame( QPainter* p )
}
}

void QgsComposerItem::setPositionLock( bool lock )
{
mItemPositionLocked = lock;
}

void QgsComposerItem::move( double dx, double dy )
{
QTransform t = transform();
@@ -281,7 +281,7 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem

/**Locks / unlocks the item position for mouse drags
@note this method was added in version 1.2*/
void setPositionLock( bool lock ) {mItemPositionLocked = lock;}
void setPositionLock( bool lock );

/**Returns position lock for mouse drags (true means locked)
@note this method was added in version 1.2*/
@@ -751,6 +751,43 @@ void QgsComposerView::ungroupItems()
}
}

void QgsComposerView::lockItems()
{
if ( !composition() )
{
return;
}

QList<QgsComposerItem*> selectionList = composition()->selectedComposerItems();
QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
for ( ; itemIter != selectionList.end(); ++itemIter )
{
( *itemIter )->setPositionLock( true );
}

composition()->clearSelection();
}

void QgsComposerView::unlockAllItems()
{
if ( !composition() )
{
return;
}

//unlock all items in composer
QList<QGraphicsItem *> itemList = composition()->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
if ( mypItem )
{
mypItem->setPositionLock( false );
}
}
}

QMainWindow* QgsComposerView::composerWindow()
{
QMainWindow* composerObject = 0;
@@ -76,6 +76,12 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Ungroups the selected items*/
void ungroupItems();

/**Lock the selected items*/
void lockItems();

/**Unlock all items*/
void unlockAllItems();

QgsComposerView::Tool currentTool() const {return mCurrentTool;}
void setCurrentTool( QgsComposerView::Tool t ) {mCurrentTool = t;}

@@ -100,6 +100,8 @@
<addaction name="mActionMoveItemContent"/>
<addaction name="mActionGroupItems"/>
<addaction name="mActionUngroupItems"/>
<addaction name="mActionLockItems"/>
<addaction name="mActionUnlockAll"/>
</widget>
<widget class="QToolBar" name="mItemToolbar">
<property name="windowTitle">
@@ -570,6 +572,27 @@
<string>New from template</string>
</property>
</action>
<action name="mActionLockItems">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/locked.svg</normaloff>:/images/themes/default/locked.svg</iconset>
</property>
<property name="text">
<string>Lock Selected Items</string>
</property>
</action>
<action name="mActionUnlockAll">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/unlocked.svg</normaloff>:/images/themes/default/unlocked.svg</iconset>
</property>
<property name="text">
<string>Unlock All</string>
</property>
<property name="toolTip">
<string>Unlock All Items</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit c705034

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