Skip to content
Permalink
Browse files

Use symbol button for overview frame symbol

  • Loading branch information
nyalldawson committed Oct 21, 2017
1 parent 8bc57f7 commit aa2b73d425a3223336ad1233c37a503efb78be3f
@@ -67,6 +67,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoAtlasMargin,
UndoMapRotation,
UndoZoomContent,
UndoOverviewStyle,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
@@ -43,7 +43,6 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged );
connect( mDrawCanvasItemsCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mDrawCanvasItemsCheckBox_stateChanged );
connect( mOverviewFrameStyleButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mOverviewFrameStyleButton_clicked );
connect( mOverviewBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged );
connect( mOverviewInvertCheckbox, &QCheckBox::toggled, this, &QgsLayoutMapWidget::mOverviewInvertCheckbox_toggled );
connect( mOverviewCenterCheckbox, &QCheckBox::toggled, this, &QgsLayoutMapWidget::mOverviewCenterCheckbox_toggled );
@@ -90,6 +89,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
mCrsSelector->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
mCrsSelector->setNotSetText( tr( "Use project CRS" ) );

mOverviewFrameStyleButton->setSymbolType( QgsSymbol::Fill );

// follow preset combo
mFollowVisibilityPresetCombo->setModel( new QStringListModel( mFollowVisibilityPresetCombo ) );
connect( mFollowVisibilityPresetCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapWidget::followVisibilityPresetSelected );
@@ -104,6 +105,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
mLayerListFromPresetButton->setToolTip( tr( "Set layer list from a map theme" ) );
connect( menuKeepLayers, &QMenu::aboutToShow, this, &QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu );

mOverviewFrameMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );

if ( item )
{
connect( item, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
@@ -120,12 +123,12 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
}
#endif
mOverviewFrameMapComboBox->setCurrentLayout( item->layout() );
mOverviewFrameMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );

connect( mOverviewFrameMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutMapWidget::overviewMapChanged );
mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
}

connect( mOverviewFrameMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutMapWidget::overviewMapChanged );
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsLayoutMapWidget::mapCrsChanged );
connect( mOverviewFrameStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapWidget::overviewSymbolChanged );

registerDataDefinedButton( mScaleDDBtn, QgsLayoutObject::MapScale );
registerDataDefinedButton( mMapRotationDDBtn, QgsLayoutObject::MapRotation );
@@ -151,9 +154,20 @@ bool QgsLayoutMapWidget::setNewItem( QgsLayoutItem *item )
if ( item->type() != QgsLayoutItemRegistry::LayoutMap )
return false;

if ( mMapItem )
{
disconnect( mMapItem, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
}

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

if ( mMapItem )
{
connect( mMapItem, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
mOverviewFrameStyleButton->registerExpressionContextGenerator( mMapItem );
}

updateGuiElements();

return true;
@@ -274,40 +288,6 @@ void QgsLayoutMapWidget::onMapThemesChanged()
}
}

void QgsLayoutMapWidget::updateOverviewFrameStyleFromWidget()
{
QgsLayoutItemMapOverview *overview = currentOverview();
if ( !overview )
{
return;
}

QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
overview->setFrameSymbol( dynamic_cast< QgsFillSymbol * >( w->symbol()->clone() ) );
mMapItem->update();
}

void QgsLayoutMapWidget::cleanUpOverviewFrameStyleSelector( QgsPanelWidget *container )
{
Q_UNUSED( container );
QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
if ( !w )
return;

delete w->symbol();

QgsLayoutItemMapOverview *overview = currentOverview();
if ( !overview )
{
return;
}

updateOverviewFrameSymbolMarker( overview );
#if 0 //TODO
mMapItem->endCommand();
#endif
}

void QgsLayoutMapWidget::mapCrsChanged( const QgsCoordinateReferenceSystem &crs )
{
if ( !mMapItem )
@@ -343,6 +323,18 @@ void QgsLayoutMapWidget::mapCrsChanged( const QgsCoordinateReferenceSystem &crs
mMapItem->invalidateCache();
}

void QgsLayoutMapWidget::overviewSymbolChanged()
{
QgsLayoutItemMapOverview *overview = currentOverview();
if ( !overview )
return;

mMapItem->beginCommand( tr( "Change Overview Style" ), QgsLayoutItem::UndoOverviewStyle );
overview->setFrameSymbol( mOverviewFrameStyleButton->clonedSymbol<QgsFillSymbol>() );
mMapItem->endCommand();
mMapItem->update();
}

void QgsLayoutMapWidget::mAtlasCheckBox_toggled( bool checked )
{
if ( !mMapItem )
@@ -1505,22 +1497,11 @@ void QgsLayoutMapWidget::setOverviewItems( QgsLayoutItemMapOverview *overview )
//center overview
mOverviewCenterCheckbox->setChecked( overview->centered() );

//frame style
updateOverviewFrameSymbolMarker( overview );
mOverviewFrameStyleButton->setSymbol( overview->frameSymbol()->clone() );

blockOverviewItemsSignals( false );
}

void QgsLayoutMapWidget::updateOverviewFrameSymbolMarker( const QgsLayoutItemMapOverview *overview )
{
if ( overview )
{
QgsFillSymbol *nonConstSymbol = const_cast<QgsFillSymbol *>( overview->frameSymbol() ); //bad
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( nonConstSymbol, mOverviewFrameStyleButton->iconSize() );
mOverviewFrameStyleButton->setIcon( icon );
}
}

void QgsLayoutMapWidget::storeCurrentLayerSet()
{
if ( !mMapItem )
@@ -1626,34 +1607,6 @@ void QgsLayoutMapWidget::overviewMapChanged( QgsLayoutItem *item )
mMapItem->endCommand();
}

void QgsLayoutMapWidget::mOverviewFrameStyleButton_clicked()
{
QgsLayoutItemMapOverview *overview = currentOverview();
if ( !overview )
{
return;
}

QgsVectorLayer *coverageLayer = nullptr;
#if 0 //TODO
// use the atlas coverage layer, if any
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
#endif

QgsFillSymbol *newSymbol = static_cast<QgsFillSymbol *>( overview->frameSymbol()->clone() );
QgsExpressionContext context = mMapItem->createExpressionContext();

QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
d->setContext( symbolContext );

connect( d, &QgsPanelWidget::widgetChanged, this, &QgsLayoutMapWidget::updateOverviewFrameStyleFromWidget );
connect( d, &QgsPanelWidget::panelAccepted, this, &QgsLayoutMapWidget::cleanUpOverviewFrameStyleSelector );
openPanel( d );
mMapItem->beginCommand( tr( "Change Overview Style" ) );
}

void QgsLayoutMapWidget::mOverviewBlendModeComboBox_currentIndexChanged( int index )
{
Q_UNUSED( index );
@@ -47,7 +47,6 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM
void mKeepLayerStylesCheckBox_stateChanged( int state );
void mDrawCanvasItemsCheckBox_stateChanged( int state );
void overviewMapChanged( QgsLayoutItem *item );
void mOverviewFrameStyleButton_clicked();
void mOverviewBlendModeComboBox_currentIndexChanged( int index );
void mOverviewInvertCheckbox_toggled( bool state );
void mOverviewCenterCheckbox_toggled( bool state );
@@ -113,11 +112,8 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM

void onMapThemesChanged();

void updateOverviewFrameStyleFromWidget();
void cleanUpOverviewFrameStyleSelector( QgsPanelWidget *container );

void mapCrsChanged( const QgsCoordinateReferenceSystem &crs );

void overviewSymbolChanged();
private:
QgsLayoutItemMap *mMapItem = nullptr;
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
@@ -162,8 +158,6 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM

void loadOverviewEntries();

void updateOverviewFrameSymbolMarker( const QgsLayoutItemMapOverview *overview );

void storeCurrentLayerSet();

};
@@ -41,6 +41,7 @@ QgsLayoutPolygonWidget::QgsLayoutPolygonWidget( QgsLayoutItemPolygon *polygon )
if ( mPolygon )
{
connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
}

setGuiElementValues();
@@ -54,9 +55,19 @@ bool QgsLayoutPolygonWidget::setNewItem( QgsLayoutItem *item )
if ( item->type() != QgsLayoutItemRegistry::LayoutPolygon )
return false;

if ( mPolygon )
{
disconnect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
}

mPolygon = qobject_cast< QgsLayoutItemPolygon * >( item );
mItemPropertiesWidget->setItem( mPolygon );

if ( mPolygon )
{
connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
}
setGuiElementValues();

return true;
@@ -41,6 +41,7 @@ QgsLayoutPolylineWidget::QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polylin
if ( mPolyline )
{
connect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues );
mLineStyleButton->registerExpressionContextGenerator( mPolyline );
}
setGuiElementValues();

@@ -54,9 +55,20 @@ bool QgsLayoutPolylineWidget::setNewItem( QgsLayoutItem *item )
if ( item->type() != QgsLayoutItemRegistry::LayoutPolyline )
return false;

if ( mPolyline )
{
disconnect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues );
}

mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item );
mItemPropertiesWidget->setItem( mPolyline );

if ( mPolyline )
{
connect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues );
mLineStyleButton->registerExpressionContextGenerator( mPolyline );
}

setGuiElementValues();

return true;
@@ -70,9 +70,20 @@ bool QgsLayoutShapeWidget::setNewItem( QgsLayoutItem *item )
if ( item->type() != QgsLayoutItemRegistry::LayoutShape )
return false;

if ( mShape )
{
disconnect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues );
}

mShape = qobject_cast< QgsLayoutItemShape * >( item );
mItemPropertiesWidget->setItem( mShape );

if ( mShape )
{
connect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues );
mShapeStyleButton->registerExpressionContextGenerator( mShape );
}

setGuiElementValues();

return true;
@@ -100,6 +100,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
UndoAtlasMargin, //!< Map atlas margin changed
UndoMapRotation, //!< Map rotation changed
UndoZoomContent, //!< Item content zoomed
UndoOverviewStyle, //!< Map overview style
};

/**

0 comments on commit aa2b73d

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