Skip to content
Permalink
Browse files

Make composer history track lock/unlock state

Move unlock/lock functions from QgsComposerView to QgsComposition
Add keyboard shortcuts to lock item/unlock all
  • Loading branch information
nyalldawson authored and mhugent committed Sep 15, 2013
1 parent 51297d5 commit 082d49729edba2b98a4b003379b701c7879fb2af
@@ -1689,17 +1689,17 @@ void QgsComposer::on_mActionUngroupItems_triggered()

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

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

@@ -1149,6 +1149,43 @@ void QgsComposition::alignSelectedItemsBottom()
mUndoStack.push( parentCommand );
}

void QgsComposition::lockSelectedItems()
{
QUndoCommand* parentCommand = new QUndoCommand( tr( "Items locked" ) );
QList<QgsComposerItem*> selectionList = selectedComposerItems();
QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
for ( ; itemIter != selectionList.end(); ++itemIter )
{
QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *itemIter, "", parentCommand );
subcommand->savePreviousState();
( *itemIter )->setPositionLock( true );
subcommand->saveAfterState();
}

clearSelection();
mUndoStack.push( parentCommand );
}

void QgsComposition::unlockAllItems()
{
//unlock all items in composer
QUndoCommand* parentCommand = new QUndoCommand( tr( "Items unlocked" ) );
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
if ( mypItem )
{
QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( mypItem, "", parentCommand );
subcommand->savePreviousState();
mypItem->setPositionLock( false );
subcommand->saveAfterState();
}
}
mUndoStack.push( parentCommand );
}

void QgsComposition::updateZValues()
{
int counter = 1;
@@ -260,6 +260,12 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void alignSelectedItemsVCenter();
void alignSelectedItemsBottom();

//functions to lock and unlock items
/**Lock the selected items*/
void lockSelectedItems();
/**Unlock all items*/
void unlockAllItems();

/**Sorts the zList. The only time where this function needs to be called is from QgsComposer
after reading all the items from xml file*/
void sortZList();
@@ -851,43 +851,6 @@ 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;
@@ -89,12 +89,6 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Ungroups the selected items*/
void ungroupItems();

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

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

/**Cuts or copies the selected items*/
void copyItems( ClipboardMode mode );

@@ -580,6 +580,9 @@
<property name="text">
<string>Lock Selected Items</string>
</property>
<property name="shortcut">
<string>Ctrl+L</string>
</property>
</action>
<action name="mActionUnlockAll">
<property name="icon">
@@ -592,6 +595,9 @@
<property name="toolTip">
<string>Unlock All Items</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+L</string>
</property>
</action>
<action name="mActionPasteInPlace">
<property name="text">

0 comments on commit 082d497

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