Skip to content

Commit 822d6f7

Browse files
committed
Move actions which apply to selected items only to QgsLayoutView
Selections are a gui concept, so these actions belong to the gui class instead of cluterring QgsLayout
1 parent fdba8f1 commit 822d6f7

File tree

9 files changed

+273
-254
lines changed

9 files changed

+273
-254
lines changed

python/core/layout/qgslayout.sip

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,6 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
9898
not correctly emit signals to allow the layout's model to update.
9999
%End
100100

101-
void lockSelectedItems();
102-
%Docstring
103-
Locks any selected items, preventing them from being interacted with
104-
by mouse interactions.
105-
.. seealso:: unlockAllItems()
106-
%End
107-
108-
void unlockAllItems();
109-
%Docstring
110-
Unlocks all locked items in the layout.
111-
.. seealso:: lockSelectedItems()
112-
%End
113-
114101
bool raiseItem( QgsLayoutItem *item, bool deferUpdate = false );
115102
%Docstring
116103
Raises an ``item`` up the z-order.
@@ -122,6 +109,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
122109
updating the scene for each one.
123110

124111
.. seealso:: lowerItem()
112+
.. seealso:: updateZValues()
125113
:rtype: bool
126114
%End
127115

@@ -136,6 +124,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
136124
updating the scene for each one.
137125

138126
.. seealso:: raiseItem()
127+
.. seealso:: updateZValues()
139128
:rtype: bool
140129
%End
141130

@@ -150,6 +139,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
150139
updating the scene for each one.
151140

152141
.. seealso:: moveItemToBottom()
142+
.. seealso:: updateZValues()
153143
:rtype: bool
154144
%End
155145

@@ -163,39 +153,15 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
163153
updating the scene for each one.
164154

165155
.. seealso:: moveItemToTop()
156+
.. seealso:: updateZValues()
166157
:rtype: bool
167158
%End
168159

169-
void raiseSelectedItems();
170-
%Docstring
171-
Raises the selected items up the z-order.
172-
.. seealso:: lowerSelectedItems()
173-
.. seealso:: moveSelectedItemsToTop()
174-
.. seealso:: moveSelectedItemsToBottom()
175-
%End
176-
177-
void lowerSelectedItems();
178-
%Docstring
179-
Lowers the selected items down the z-order.
180-
.. seealso:: raiseSelectedItems()
181-
.. seealso:: moveSelectedItemsToTop()
182-
.. seealso:: moveSelectedItemsToBottom()
183-
%End
184-
185-
void moveSelectedItemsToTop();
186-
%Docstring
187-
Raises the selected items to the top of the z-order.
188-
.. seealso:: raiseSelectedItems()
189-
.. seealso:: lowerSelectedItems()
190-
.. seealso:: moveSelectedItemsToBottom()
191-
%End
192-
193-
void moveSelectedItemsToBottom();
160+
void updateZValues( const bool addUndoCommands = true );
194161
%Docstring
195-
Lowers the selected items to the bottom of the z-order.
196-
.. seealso:: raiseSelectedItems()
197-
.. seealso:: lowerSelectedItems()
198-
.. seealso:: moveSelectedItemsToTop()
162+
Resets the z-values of items based on their position in the internal
163+
z order list. This should be called after any stacking changes
164+
which deferred z-order updates.
199165
%End
200166

201167
QgsLayoutItem *itemByUuid( const QString &uuid );

python/gui/layout/qgslayoutview.sip

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,51 @@ class QgsLayoutView: QGraphicsView
210210
.. seealso:: selectNextItemAbove()
211211
.. seealso:: selectAll()
212212
.. seealso:: deselectAll()
213+
%End
214+
215+
void raiseSelectedItems();
216+
%Docstring
217+
Raises the selected items up the z-order.
218+
.. seealso:: lowerSelectedItems()
219+
.. seealso:: moveSelectedItemsToTop()
220+
.. seealso:: moveSelectedItemsToBottom()
221+
%End
222+
223+
void lowerSelectedItems();
224+
%Docstring
225+
Lowers the selected items down the z-order.
226+
.. seealso:: raiseSelectedItems()
227+
.. seealso:: moveSelectedItemsToTop()
228+
.. seealso:: moveSelectedItemsToBottom()
229+
%End
230+
231+
void moveSelectedItemsToTop();
232+
%Docstring
233+
Raises the selected items to the top of the z-order.
234+
.. seealso:: raiseSelectedItems()
235+
.. seealso:: lowerSelectedItems()
236+
.. seealso:: moveSelectedItemsToBottom()
237+
%End
238+
239+
void moveSelectedItemsToBottom();
240+
%Docstring
241+
Lowers the selected items to the bottom of the z-order.
242+
.. seealso:: raiseSelectedItems()
243+
.. seealso:: lowerSelectedItems()
244+
.. seealso:: moveSelectedItemsToTop()
245+
%End
246+
247+
void lockSelectedItems();
248+
%Docstring
249+
Locks any selected items, preventing them from being interacted with
250+
by mouse interactions.
251+
.. seealso:: unlockAllItems()
252+
%End
253+
254+
void unlockAllItems();
255+
%Docstring
256+
Unlocks all locked items in the layout.
257+
.. seealso:: lockSelectedItems()
213258
%End
214259

215260
void viewChanged();

src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,18 +542,12 @@ void QgsLayoutDesignerDialog::snapToItems( bool enabled )
542542

543543
void QgsLayoutDesignerDialog::unlockAllItems()
544544
{
545-
if ( mLayout )
546-
{
547-
mLayout->unlockAllItems();
548-
}
545+
mView->unlockAllItems();
549546
}
550547

551548
void QgsLayoutDesignerDialog::lockSelectedItems()
552549
{
553-
if ( mLayout )
554-
{
555-
mLayout->lockSelectedItems();
556-
}
550+
mView->lockSelectedItems();
557551
}
558552

559553
void QgsLayoutDesignerDialog::setPanelVisibility( bool hidden )
@@ -616,22 +610,22 @@ void QgsLayoutDesignerDialog::setPanelVisibility( bool hidden )
616610

617611
void QgsLayoutDesignerDialog::raiseSelectedItems()
618612
{
619-
mLayout->raiseSelectedItems();
613+
mView->raiseSelectedItems();
620614
}
621615

622616
void QgsLayoutDesignerDialog::lowerSelectedItems()
623617
{
624-
mLayout->lowerSelectedItems();
618+
mView->lowerSelectedItems();
625619
}
626620

627621
void QgsLayoutDesignerDialog::moveSelectedItemsToTop()
628622
{
629-
mLayout->moveSelectedItemsToTop();
623+
mView->moveSelectedItemsToTop();
630624
}
631625

632626
void QgsLayoutDesignerDialog::moveSelectedItemsToBottom()
633627
{
634-
mLayout->moveSelectedItemsToBottom();
628+
mView->moveSelectedItemsToBottom();
635629
}
636630

637631
void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )

src/core/layout/qgslayout.cpp

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -113,47 +113,6 @@ void QgsLayout::deselectAll()
113113
emit selectedItemChanged( nullptr );
114114
}
115115

116-
void QgsLayout::lockSelectedItems()
117-
{
118-
mUndoStack->beginMacro( tr( "Items locked" ) );
119-
const QList<QgsLayoutItem *> selectionList = selectedLayoutItems();
120-
for ( QgsLayoutItem *item : selectionList )
121-
{
122-
mUndoStack->beginCommand( item, QString() );
123-
item->setLocked( true );
124-
mUndoStack->endCommand();
125-
}
126-
127-
deselectAll();
128-
mUndoStack->endMacro();
129-
}
130-
131-
void QgsLayout::unlockAllItems()
132-
{
133-
//unlock all items in composer
134-
135-
mUndoStack->beginMacro( tr( "Items unlocked" ) );
136-
137-
//first, clear the selection
138-
deselectAll();
139-
140-
const QList<QGraphicsItem *> itemList = items();
141-
for ( QGraphicsItem *graphicItem : itemList )
142-
{
143-
QgsLayoutItem *item = dynamic_cast<QgsLayoutItem *>( graphicItem );
144-
if ( item && item->isLocked() )
145-
{
146-
mUndoStack->beginCommand( item, QString() );
147-
item->setLocked( false );
148-
//select unlocked items, same behavior as illustrator
149-
item->setSelected( true );
150-
emit selectedItemChanged( item );
151-
mUndoStack->endCommand();
152-
}
153-
}
154-
mUndoStack->endMacro();
155-
}
156-
157116
bool QgsLayout::raiseItem( QgsLayoutItem *item, bool deferUpdate )
158117
{
159118
//model handles reordering items
@@ -206,86 +165,6 @@ bool QgsLayout::moveItemToBottom( QgsLayoutItem *item, bool deferUpdate )
206165
return result;
207166
}
208167

209-
void QgsLayout::raiseSelectedItems()
210-
{
211-
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
212-
bool itemsRaised = false;
213-
for ( QgsLayoutItem *item : selectedItems )
214-
{
215-
itemsRaised = itemsRaised | raiseItem( item, true );
216-
}
217-
218-
if ( !itemsRaised )
219-
{
220-
//no change
221-
return;
222-
}
223-
224-
//update all positions
225-
updateZValues();
226-
update();
227-
}
228-
229-
void QgsLayout::lowerSelectedItems()
230-
{
231-
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
232-
bool itemsLowered = false;
233-
for ( QgsLayoutItem *item : selectedItems )
234-
{
235-
itemsLowered = itemsLowered | lowerItem( item, true );
236-
}
237-
238-
if ( !itemsLowered )
239-
{
240-
//no change
241-
return;
242-
}
243-
244-
//update all positions
245-
updateZValues();
246-
update();
247-
}
248-
249-
void QgsLayout::moveSelectedItemsToTop()
250-
{
251-
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
252-
bool itemsRaised = false;
253-
for ( QgsLayoutItem *item : selectedItems )
254-
{
255-
itemsRaised = itemsRaised | moveItemToTop( item, true );
256-
}
257-
258-
if ( !itemsRaised )
259-
{
260-
//no change
261-
return;
262-
}
263-
264-
//update all positions
265-
updateZValues();
266-
update();
267-
}
268-
269-
void QgsLayout::moveSelectedItemsToBottom()
270-
{
271-
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
272-
bool itemsLowered = false;
273-
for ( QgsLayoutItem *item : selectedItems )
274-
{
275-
itemsLowered = itemsLowered | moveItemToBottom( item, true );
276-
}
277-
278-
if ( !itemsLowered )
279-
{
280-
//no change
281-
return;
282-
}
283-
284-
//update all positions
285-
updateZValues();
286-
update();
287-
}
288-
289168
QgsLayoutItem *QgsLayout::itemByUuid( const QString &uuid )
290169
{
291170
QList<QgsLayoutItem *> itemList;

0 commit comments

Comments
 (0)