Skip to content

Commit

Permalink
Make composer history track lock/unlock state
Browse files Browse the repository at this point in the history
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 17, 2013
1 parent 51297d5 commit 082d497
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -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();
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -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();
Expand Down
37 changes: 0 additions & 37 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/gui/qgscomposerview.h
Expand Up @@ -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 );

Expand Down
6 changes: 6 additions & 0 deletions src/ui/qgscomposerbase.ui
Expand Up @@ -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">
Expand All @@ -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">
Expand Down

0 comments on commit 082d497

Please sign in to comment.