Skip to content
Permalink
Browse files

When selecting a different item, but the item is the same

type of item, just update the existing panel to show the new
item's properties

This means that flicking between selecting items of the same
type will not create a new properties widget, so scroll
bar positions, focused widgets, etc are all maintained.

Makes using layouts less annoying.
  • Loading branch information
nyalldawson committed Oct 10, 2017
1 parent 29dfcc0 commit e836fc49b1048ffcfaf1fef799c158dba2fd70c3
@@ -81,6 +81,17 @@ class QgsLayoutItemBaseWidget: QgsPanelWidget
:rtype: QgsLayoutObject
%End

bool setItem( QgsLayoutItem *item );
%Docstring
Sets the current ``item`` to show in the widget. If true is returned, ``item``
was an acceptable type for display in this widget and the widget has been
updated to match ``item``'s properties.

If false is returned, then the widget could not be successfully updated
to show the properties of ``item``.
:rtype: bool
%End

protected:

void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property );
@@ -100,6 +111,19 @@ class QgsLayoutItemBaseWidget: QgsPanelWidget
:rtype: QgsVectorLayer
%End

virtual bool setNewItem( QgsLayoutItem *item );
%Docstring
Attempts to update the widget to show the properties
for the specified ``item``.

Subclasses can override this if they support changing items in place.

Implementations must return true if the item was accepted and
the widget was updated.
:rtype: bool
%End



};

@@ -127,6 +151,8 @@ class QgsLayoutItemPropertiesWidget: QWidget

void showFrameGroup( bool showGroup );

void setItem( QgsLayoutItem *item );

protected slots:
void initializeDataDefinedButtons();
%Docstring
@@ -630,6 +630,17 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa

return;
}
else
{
// try to reuse
if ( widget->setItem( item ) )
{
if ( bringPanelToFront )
mItemDock->setUserVisible( true );

return;
}
}
}

std::unique_ptr< QgsLayoutItemBaseWidget > widget( QgsGui::layoutItemGuiRegistry()->createItemWidget( item ) );
@@ -68,8 +68,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
mMapRotationSpinBox->setClearValue( 0 );

//add widget for general composer item properties
QgsLayoutItemPropertiesWidget *itemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, item );
mainLayout->addWidget( itemPropertiesWidget );
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, item );
mainLayout->addWidget( mItemPropertiesWidget );

mScaleLineEdit->setValidator( new QDoubleValidator( mScaleLineEdit ) );

@@ -141,6 +141,17 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
blockAllSignals( false );
}

bool QgsLayoutMapWidget::setNewItem( QgsLayoutItem *item )
{
if ( item->type() != QgsLayoutItemRegistry::LayoutMap )
return false;

mMapItem = qobject_cast< QgsLayoutItemMap * >( item );
mItemPropertiesWidget->setItem( mMapItem );

return true;
}

void QgsLayoutMapWidget::populateDataDefinedButtons()
{
updateDataDefinedButton( mScaleDDBtn );
@@ -89,6 +89,7 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM
void blockOverviewItemsSignals( bool block );

protected:
bool setNewItem( QgsLayoutItem *item ) override;

void addPageToToolbox( QWidget *widget, const QString &name );

@@ -124,6 +125,7 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM

private:
QgsLayoutItemMap *mMapItem = nullptr;
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;

//! Sets extent of composer map from line edits
void updateComposerExtentFromGui();
@@ -139,6 +139,17 @@ QgsLayoutObject *QgsLayoutItemBaseWidget::layoutObject()
return mObject;
}

bool QgsLayoutItemBaseWidget::setItem( QgsLayoutItem *item )
{
if ( setNewItem( item ) )
{
mObject = item;
return true;
}

return false;
}

void QgsLayoutItemBaseWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property )
{
mConfigObject->initializeDataDefinedButton( button, property );
@@ -154,6 +165,11 @@ QgsVectorLayer *QgsLayoutItemBaseWidget::coverageLayer() const
return mConfigObject->coverageLayer();
}

bool QgsLayoutItemBaseWidget::setNewItem( QgsLayoutItem * )
{
return false;
}

#if 0 //TODO
QgsAtlasComposition *QgsLayoutItemBaseWidget::atlasComposition() const
{
@@ -178,28 +194,26 @@ void QgsLayoutItemPropertiesWidget::updateVariables()

QgsLayoutItemPropertiesWidget::QgsLayoutItemPropertiesWidget( QWidget *parent, QgsLayoutItem *item )
: QWidget( parent )
, mItem( item )
, mConfigObject( new QgsLayoutConfigObject( this, item ) )
, mFreezeXPosSpin( false )
, mFreezeYPosSpin( false )
, mFreezeWidthSpin( false )
, mFreezeHeightSpin( false )
, mFreezePageSpin( false )
{

setupUi( this );

mItemRotationSpinBox->setClearValue( 0 );
mStrokeUnitsComboBox->linkToWidget( mStrokeWidthSpinBox );
mStrokeUnitsComboBox->setConverter( &mItem->layout()->context().measurementConverter() );
mStrokeUnitsComboBox->setConverter( &item->layout()->context().measurementConverter() );

mPosUnitsComboBox->linkToWidget( mXPosSpin );
mPosUnitsComboBox->linkToWidget( mYPosSpin );
mSizeUnitsComboBox->linkToWidget( mWidthSpin );
mSizeUnitsComboBox->linkToWidget( mHeightSpin );

mPosUnitsComboBox->setConverter( &mItem->layout()->context().measurementConverter() );
mSizeUnitsComboBox->setConverter( &mItem->layout()->context().measurementConverter() );
mPosUnitsComboBox->setConverter( &item->layout()->context().measurementConverter() );
mSizeUnitsComboBox->setConverter( &item->layout()->context().measurementConverter() );

mPosLockAspectRatio->setWidthSpinBox( mXPosSpin );
mPosLockAspectRatio->setHeightSpinBox( mYPosSpin );
@@ -249,25 +263,22 @@ QgsLayoutItemPropertiesWidget::QgsLayoutItemPropertiesWidget( QWidget *parent, Q

initializeDataDefinedButtons();

setValuesForGuiElements();

#if 0 //TODO
connect( mItem->composition(), &QgsComposition::paperSizeChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
#endif

connect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
setItem( item );

connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsLayoutItemPropertiesWidget::opacityChanged );

updateVariables();
connect( mVariableEditor, &QgsVariableEditorWidget::scopeChanged, this, &QgsLayoutItemPropertiesWidget::variablesChanged );
// listen out for variable edits
connect( QgsApplication::instance(), &QgsApplication::customVariablesChanged, this, &QgsLayoutItemPropertiesWidget::updateVariables );
connect( mItem->layout()->project(), &QgsProject::customVariablesChanged, this, &QgsLayoutItemPropertiesWidget::updateVariables );
connect( item->layout()->project(), &QgsProject::customVariablesChanged, this, &QgsLayoutItemPropertiesWidget::updateVariables );

if ( mItem->layout() )
connect( mItem->layout(), &QgsLayout::variablesChanged, this, &QgsLayoutItemPropertiesWidget::updateVariables );
if ( item->layout() )
connect( item->layout(), &QgsLayout::variablesChanged, this, &QgsLayoutItemPropertiesWidget::updateVariables );
}

void QgsLayoutItemPropertiesWidget::showBackgroundGroup( bool showGroup )
@@ -280,6 +291,20 @@ void QgsLayoutItemPropertiesWidget::showFrameGroup( bool showGroup )
mFrameGroupBox->setVisible( showGroup );
}

void QgsLayoutItemPropertiesWidget::setItem( QgsLayoutItem *item )
{
if ( mItem )
{
disconnect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
disconnect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
}
mItem = item;
connect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );

setValuesForGuiElements();
}

//slots

void QgsLayoutItemPropertiesWidget::mFrameColorButton_colorChanged( const QColor &newFrameColor )
@@ -126,6 +126,16 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
*/
QgsLayoutObject *layoutObject();

/**
* Sets the current \a item to show in the widget. If true is returned, \a item
* was an acceptable type for display in this widget and the widget has been
* updated to match \a item's properties.
*
* If false is returned, then the widget could not be successfully updated
* to show the properties of \a item.
*/
bool setItem( QgsLayoutItem *item );

protected:

/**
@@ -144,6 +154,18 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
*/
QgsVectorLayer *coverageLayer() const;

/**
* Attempts to update the widget to show the properties
* for the specified \a item.
*
* Subclasses can override this if they support changing items in place.
*
* Implementations must return true if the item was accepted and
* the widget was updated.
*/
virtual bool setNewItem( QgsLayoutItem *item );


#if 0 //TODO
//! Returns the atlas for the composition
QgsAtlasComposition *atlasComposition() const;
@@ -176,6 +198,8 @@ class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsL

void showFrameGroup( bool showGroup );

void setItem( QgsLayoutItem *item );

protected slots:
//! Initializes data defined buttons to current atlas coverage layer
void initializeDataDefinedButtons();

0 comments on commit e836fc4

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