Skip to content
Permalink
Browse files

If the same item is reselected in a layout, don't create a new

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 Oct 10, 2017
1 parent b2414d8 commit ea453beb73692738b58daa516425742d24f83040
@@ -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 );
@@ -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 )
{
@@ -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;

@@ -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 );
@@ -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 );
}
@@ -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 );
@@ -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:

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

QgsLayoutConfigObject *mConfigObject = nullptr;

QgsLayoutObject *mObject = nullptr;
};


0 comments on commit ea453be

Please sign in to comment.
You can’t perform that action at this time.