Navigation Menu

Skip to content

Commit

Permalink
When selecting a different item, but the item is the same
Browse files Browse the repository at this point in the history
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 Nov 7, 2017
1 parent 29dfcc0 commit e836fc4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 14 deletions.
26 changes: 26 additions & 0 deletions python/gui/layout/qgslayoutitemwidget.sip
Expand Up @@ -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 );
Expand All @@ -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



};

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

void showFrameGroup( bool showGroup );

void setItem( QgsLayoutItem *item );

protected slots:
void initializeDataDefinedButtons();
%Docstring
Expand Down
11 changes: 11 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -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 ) );
Expand Down
15 changes: 13 additions & 2 deletions src/app/layout/qgslayoutmapwidget.cpp
Expand Up @@ -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 ) );

Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgslayoutmapwidget.h
Expand Up @@ -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 );

Expand Down Expand Up @@ -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();
Expand Down
49 changes: 37 additions & 12 deletions src/gui/layout/qgslayoutitemwidget.cpp
Expand Up @@ -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 );
Expand All @@ -154,6 +165,11 @@ QgsVectorLayer *QgsLayoutItemBaseWidget::coverageLayer() const
return mConfigObject->coverageLayer();
}

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

#if 0 //TODO
QgsAtlasComposition *QgsLayoutItemBaseWidget::atlasComposition() const
{
Expand All @@ -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 );
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down
24 changes: 24 additions & 0 deletions src/gui/layout/qgslayoutitemwidget.h
Expand Up @@ -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:

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e836fc4

Please sign in to comment.