Showing with 61 additions and 47 deletions.
  1. +4 −4 src/app/composer/qgscomposer.cpp
  2. +45 −0 src/core/composer/qgscomposition.cpp
  3. +6 −0 src/core/composer/qgscomposition.h
  4. +0 −37 src/gui/qgscomposerview.cpp
  5. +0 −6 src/gui/qgscomposerview.h
  6. +6 −0 src/ui/qgscomposerbase.ui
8 changes: 4 additions & 4 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
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
45 changes: 45 additions & 0 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,51 @@ 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" ) );

//first, clear the selection
clearSelection();

QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
if ( mypItem && mypItem->positionLock() )
{
QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( mypItem, "", parentCommand );
subcommand->savePreviousState();
mypItem->setPositionLock( false );
//select unlocked items, same behaviour as illustrator
mypItem->setSelected( true );
emit selectedItemChanged( mypItem );
subcommand->saveAfterState();
}
}
mUndoStack.push( parentCommand );
}

void QgsComposition::updateZValues()
{
int counter = 1;
Expand Down
6 changes: 6 additions & 0 deletions src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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