Skip to content

Commit

Permalink
Correctly handle item focusing in layout designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent e172356 commit 639ecd1
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 14 deletions.
6 changes: 6 additions & 0 deletions python/gui/layout/qgslayoutview.sip
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ class QgsLayoutView: QGraphicsView
.. seealso:: pushStatusMessage()
%End

void itemFocused( QgsLayoutItem *item );
%Docstring
Emitted when an ``item`` is "focused" in the view, i.e. it becomes the active
item and should have its properties displayed in any designer windows.
%End

protected:
virtual void mousePressEvent( QMouseEvent *event );

Expand Down
6 changes: 6 additions & 0 deletions python/gui/layout/qgslayoutviewtool.sip
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ class QgsLayoutViewTool : QObject
Emitted when the tool is deactivated.
%End

void itemFocused( QgsLayoutItem *item );
%Docstring
Emitted when an ``item`` is "focused" by the tool, i.e. it should become the active
item and should have its properties displayed in any designer windows.
%End

protected:

void setFlags( const QgsLayoutViewTool::Flags flags );
Expand Down
10 changes: 8 additions & 2 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mHorizontalRuler, &QgsLayoutRuler::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );
connect( mVerticalRuler, &QgsLayoutRuler::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );

connect( mView, &QgsLayoutView::itemFocused, this, [ = ]( QgsLayoutItem * item )
{
showItemOptions( item, false );
} );

// Panel and toolbar submenus
mToolbarMenu->addAction( mLayoutToolbar->toggleViewAction() );
mToolbarMenu->addAction( mNavigationToolbar->toggleViewAction() );
Expand Down Expand Up @@ -372,7 +377,7 @@ void QgsLayoutDesignerDialog::setIconSizes( int size )
}
}

void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item )
void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPanelToFront )
{
if ( !item )
{
Expand All @@ -394,7 +399,8 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item )
} );

mItemPropertiesStack->setMainPanel( widget.release() );
mItemDock->setUserVisible( true );
if ( bringPanelToFront )
mItemDock->setUserVisible( true );

}

Expand Down
5 changes: 4 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

/**
* Shows the configuration widget for the specified layout \a item.
*
* If \a bringPanelToFront is true, then the item properties panel will be automatically
* shown and raised to the top of the interface.
*/
void showItemOptions( QgsLayoutItem *item );
void showItemOptions( QgsLayoutItem *item, bool bringPanelToFront = true );

public slots:

Expand Down
4 changes: 4 additions & 0 deletions src/gui/layout/qgslayoutview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
setScene( layout );

connect( layout->pageCollection(), &QgsLayoutPageCollection::changed, this, &QgsLayoutView::viewChanged );
connect( layout, &QgsLayout::selectedItemChanged, this, &QgsLayoutView::itemFocused );

viewChanged();

mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
Expand Down Expand Up @@ -113,6 +115,7 @@ void QgsLayoutView::setTool( QgsLayoutViewTool *tool )
if ( mTool )
{
mTool->deactivate();
disconnect( mTool, &QgsLayoutViewTool::itemFocused, this, &QgsLayoutView::itemFocused );
}

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

emit toolSet( mTool );
}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/layout/qgslayoutview.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
void statusMessage( const QString &message );

/**
* Emitted when an \a item is "focused" in the view, i.e. it becomes the active
* item and should have its properties displayed in any designer windows.
*/
void itemFocused( QgsLayoutItem *item );

protected:
void mousePressEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override;
Expand Down
7 changes: 7 additions & 0 deletions src/gui/layout/qgslayoutviewtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class QKeyEvent;
class QgsLayoutView;
class QgsLayoutViewMouseEvent;
class QgsLayout;
class QgsLayoutItem;

#ifdef SIP_RUN
% ModuleHeaderCode
Expand Down Expand Up @@ -178,6 +179,12 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
*/
void deactivated();

/**
* Emitted when an \a item is "focused" by the tool, i.e. it should become the active
* item and should have its properties displayed in any designer windows.
*/
void itemFocused( QgsLayoutItem *item );

protected:

/**
Expand Down
16 changes: 5 additions & 11 deletions src/gui/layout/qgslayoutviewtoolselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,17 @@ void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event )
selectedItem->setSelected( false );

//Check if we have any remaining selected items, and if so, update the item panel
QList<QgsLayoutItem *> selectedItems = layout()->selectedLayoutItems();
const QList<QgsLayoutItem *> selectedItems = layout()->selectedLayoutItems();
if ( !selectedItems.isEmpty() )
{
#if 0 //TODO
emit selectedItemChanged( selectedItems.at( 0 ) );
#endif
emit itemFocused( selectedItems.at( 0 ) );
}
}
else
{
selectedItem->setSelected( true );
event->ignore();
#if 0 //TODO
emit selectedItemChanged( selectedItem );
#endif
emit itemFocused( selectedItem );
}
}

Expand Down Expand Up @@ -216,14 +212,12 @@ void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event
}
}

#if 0 //TODO
//update item panel
QList<QgsComposerItem *> selectedItemList = composition()->selectedComposerItems();
const QList<QgsLayoutItem *> selectedItemList = layout()->selectedLayoutItems();
if ( !selectedItemList.isEmpty() )
{
emit selectedItemChanged( selectedItemList[0] );
emit itemFocused( selectedItemList.at( 0 ) );
}
#endif
}

void QgsLayoutViewToolSelect::wheelEvent( QWheelEvent *event )
Expand Down

0 comments on commit 639ecd1

Please sign in to comment.