Skip to content

Commit

Permalink
If the same item is reselected in a layout, don't create a new
Browse files Browse the repository at this point in the history
properties widget for it

Because if we do annoying things happen, like loss of focused
widget and scroll bar position
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent b2414d8 commit ea453be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions python/gui/layout/qgslayoutitemwidget.sip
Expand Up @@ -75,6 +75,12 @@ class QgsLayoutItemBaseWidget: QgsPanelWidget
Constructor for QgsLayoutItemBaseWidget, linked with the specified ``layoutObject``.
%End

QgsLayoutObject *layoutObject();
%Docstring
Returns the layout object associated with this widget.
:rtype: QgsLayoutObject
%End

protected:

void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property );
Expand Down
16 changes: 14 additions & 2 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -620,6 +620,18 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa
return;
}

if ( auto widget = qobject_cast< QgsLayoutItemBaseWidget * >( mItemPropertiesStack->mainPanel() ) )
{
if ( widget->layoutObject() == item )
{
// already showing properties for this item - we don't want to create a new panel
if ( bringPanelToFront )
mItemDock->setUserVisible( true );

return;
}
}

std::unique_ptr< QgsLayoutItemBaseWidget > widget( QgsGui::layoutItemGuiRegistry()->createItemWidget( item ) );
if ( ! widget )
{
Expand Down Expand Up @@ -1069,8 +1081,8 @@ void QgsLayoutDesignerDialog::createLayoutPropertiesWidget()
}

// update layout based widgets
QgsLayoutPropertiesWidget *oldCompositionWidget = qobject_cast<QgsLayoutPropertiesWidget *>( mGeneralPropertiesStack->takeMainPanel() );
delete oldCompositionWidget;
QgsLayoutPropertiesWidget *oldLayoutWidget = qobject_cast<QgsLayoutPropertiesWidget *>( mGeneralPropertiesStack->takeMainPanel() );
delete oldLayoutWidget;
QgsLayoutGuideWidget *oldGuideWidget = qobject_cast<QgsLayoutGuideWidget *>( mGuideStack->takeMainPanel() );
delete oldGuideWidget;

Expand Down
9 changes: 7 additions & 2 deletions src/gui/layout/qgslayoutitemwidget.cpp
Expand Up @@ -129,10 +129,16 @@ QgsVectorLayer *QgsLayoutConfigObject::coverageLayer() const
QgsLayoutItemBaseWidget::QgsLayoutItemBaseWidget( QWidget *parent, QgsLayoutObject *layoutObject )
: QgsPanelWidget( parent )
, mConfigObject( new QgsLayoutConfigObject( this, layoutObject ) )
, mObject( layoutObject )
{

}

QgsLayoutObject *QgsLayoutItemBaseWidget::layoutObject()
{
return mObject;
}

void QgsLayoutItemBaseWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property )
{
mConfigObject->initializeDataDefinedButton( button, property );
Expand Down Expand Up @@ -165,7 +171,7 @@ void QgsLayoutItemPropertiesWidget::updateVariables()
{
QgsExpressionContext context = mItem->createExpressionContext();
mVariableEditor->setContext( &context );
int editableIndex = context.indexOfScope( tr( "Composer Item" ) );
int editableIndex = context.indexOfScope( tr( "Layout Item" ) );
if ( editableIndex >= 0 )
mVariableEditor->setEditableScopeIndex( editableIndex );
}
Expand Down Expand Up @@ -212,7 +218,6 @@ QgsLayoutItemPropertiesWidget::QgsLayoutItemPropertiesWidget( QWidget *parent, Q
mStrokeUnitsComboBox->linkToWidget( mStrokeWidthSpinBox );
mStrokeUnitsComboBox->setConverter( &mItem->layout()->context().measurementConverter() );


//make button exclusive
QButtonGroup *buttonGroup = new QButtonGroup( this );
buttonGroup->addButton( mUpperLeftCheckBox );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/layout/qgslayoutitemwidget.h
Expand Up @@ -121,6 +121,11 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
*/
QgsLayoutItemBaseWidget( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );

/**
* Returns the layout object associated with this widget.
*/
QgsLayoutObject *layoutObject();

protected:

/**
Expand All @@ -147,6 +152,8 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
private:

QgsLayoutConfigObject *mConfigObject = nullptr;

QgsLayoutObject *mObject = nullptr;
};


Expand Down

0 comments on commit ea453be

Please sign in to comment.