Skip to content

Commit 639ecd1

Browse files
committed
Correctly handle item focusing in layout designer
1 parent e172356 commit 639ecd1

File tree

8 files changed

+46
-14
lines changed

8 files changed

+46
-14
lines changed

python/gui/layout/qgslayoutview.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ class QgsLayoutView: QGraphicsView
229229
.. seealso:: pushStatusMessage()
230230
%End
231231

232+
void itemFocused( QgsLayoutItem *item );
233+
%Docstring
234+
Emitted when an ``item`` is "focused" in the view, i.e. it becomes the active
235+
item and should have its properties displayed in any designer windows.
236+
%End
237+
232238
protected:
233239
virtual void mousePressEvent( QMouseEvent *event );
234240

python/gui/layout/qgslayoutviewtool.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ class QgsLayoutViewTool : QObject
159159
Emitted when the tool is deactivated.
160160
%End
161161

162+
void itemFocused( QgsLayoutItem *item );
163+
%Docstring
164+
Emitted when an ``item`` is "focused" by the tool, i.e. it should become the active
165+
item and should have its properties displayed in any designer windows.
166+
%End
167+
162168
protected:
163169

164170
void setFlags( const QgsLayoutViewTool::Flags flags );

src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
249249
connect( mHorizontalRuler, &QgsLayoutRuler::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );
250250
connect( mVerticalRuler, &QgsLayoutRuler::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );
251251

252+
connect( mView, &QgsLayoutView::itemFocused, this, [ = ]( QgsLayoutItem * item )
253+
{
254+
showItemOptions( item, false );
255+
} );
256+
252257
// Panel and toolbar submenus
253258
mToolbarMenu->addAction( mLayoutToolbar->toggleViewAction() );
254259
mToolbarMenu->addAction( mNavigationToolbar->toggleViewAction() );
@@ -372,7 +377,7 @@ void QgsLayoutDesignerDialog::setIconSizes( int size )
372377
}
373378
}
374379

375-
void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item )
380+
void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPanelToFront )
376381
{
377382
if ( !item )
378383
{
@@ -394,7 +399,8 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item )
394399
} );
395400

396401
mItemPropertiesStack->setMainPanel( widget.release() );
397-
mItemDock->setUserVisible( true );
402+
if ( bringPanelToFront )
403+
mItemDock->setUserVisible( true );
398404

399405
}
400406

src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
9696

9797
/**
9898
* Shows the configuration widget for the specified layout \a item.
99+
*
100+
* If \a bringPanelToFront is true, then the item properties panel will be automatically
101+
* shown and raised to the top of the interface.
99102
*/
100-
void showItemOptions( QgsLayoutItem *item );
103+
void showItemOptions( QgsLayoutItem *item, bool bringPanelToFront = true );
101104

102105
public slots:
103106

src/gui/layout/qgslayoutview.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
6868
setScene( layout );
6969

7070
connect( layout->pageCollection(), &QgsLayoutPageCollection::changed, this, &QgsLayoutView::viewChanged );
71+
connect( layout, &QgsLayout::selectedItemChanged, this, &QgsLayoutView::itemFocused );
72+
7173
viewChanged();
7274

7375
mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
@@ -113,6 +115,7 @@ void QgsLayoutView::setTool( QgsLayoutViewTool *tool )
113115
if ( mTool )
114116
{
115117
mTool->deactivate();
118+
disconnect( mTool, &QgsLayoutViewTool::itemFocused, this, &QgsLayoutView::itemFocused );
116119
}
117120

118121
mSnapMarker->hide();
@@ -125,6 +128,7 @@ void QgsLayoutView::setTool( QgsLayoutViewTool *tool )
125128
// to respond to whatever the current tool is
126129
tool->activate();
127130
mTool = tool;
131+
connect( mTool, &QgsLayoutViewTool::itemFocused, this, &QgsLayoutView::itemFocused );
128132

129133
emit toolSet( mTool );
130134
}

src/gui/layout/qgslayoutview.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
268268
*/
269269
void statusMessage( const QString &message );
270270

271+
/**
272+
* Emitted when an \a item is "focused" in the view, i.e. it becomes the active
273+
* item and should have its properties displayed in any designer windows.
274+
*/
275+
void itemFocused( QgsLayoutItem *item );
276+
271277
protected:
272278
void mousePressEvent( QMouseEvent *event ) override;
273279
void mouseReleaseEvent( QMouseEvent *event ) override;

src/gui/layout/qgslayoutviewtool.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QKeyEvent;
2828
class QgsLayoutView;
2929
class QgsLayoutViewMouseEvent;
3030
class QgsLayout;
31+
class QgsLayoutItem;
3132

3233
#ifdef SIP_RUN
3334
% ModuleHeaderCode
@@ -178,6 +179,12 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
178179
*/
179180
void deactivated();
180181

182+
/**
183+
* Emitted when an \a item is "focused" by the tool, i.e. it should become the active
184+
* item and should have its properties displayed in any designer windows.
185+
*/
186+
void itemFocused( QgsLayoutItem *item );
187+
181188
protected:
182189

183190
/**

src/gui/layout/qgslayoutviewtoolselect.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,17 @@ void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event )
112112
selectedItem->setSelected( false );
113113

114114
//Check if we have any remaining selected items, and if so, update the item panel
115-
QList<QgsLayoutItem *> selectedItems = layout()->selectedLayoutItems();
115+
const QList<QgsLayoutItem *> selectedItems = layout()->selectedLayoutItems();
116116
if ( !selectedItems.isEmpty() )
117117
{
118-
#if 0 //TODO
119-
emit selectedItemChanged( selectedItems.at( 0 ) );
120-
#endif
118+
emit itemFocused( selectedItems.at( 0 ) );
121119
}
122120
}
123121
else
124122
{
125123
selectedItem->setSelected( true );
126124
event->ignore();
127-
#if 0 //TODO
128-
emit selectedItemChanged( selectedItem );
129-
#endif
125+
emit itemFocused( selectedItem );
130126
}
131127
}
132128

@@ -216,14 +212,12 @@ void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event
216212
}
217213
}
218214

219-
#if 0 //TODO
220215
//update item panel
221-
QList<QgsComposerItem *> selectedItemList = composition()->selectedComposerItems();
216+
const QList<QgsLayoutItem *> selectedItemList = layout()->selectedLayoutItems();
222217
if ( !selectedItemList.isEmpty() )
223218
{
224-
emit selectedItemChanged( selectedItemList[0] );
219+
emit itemFocused( selectedItemList.at( 0 ) );
225220
}
226-
#endif
227221
}
228222

229223
void QgsLayoutViewToolSelect::wheelEvent( QWheelEvent *event )

0 commit comments

Comments
 (0)