Skip to content

Commit

Permalink
Use symbol button for overview frame symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 8bc57f7 commit aa2b73d
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 101 deletions.
1 change: 1 addition & 0 deletions python/core/layout/qgslayoutitem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoAtlasMargin,
UndoMapRotation,
UndoZoomContent,
UndoOverviewStyle,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
Expand Down
109 changes: 31 additions & 78 deletions src/app/layout/qgslayoutmapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 1 addition & 7 deletions src/app/layout/qgslayoutmapwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -162,8 +158,6 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM

void loadOverviewEntries();

void updateOverviewFrameSymbolMarker( const QgsLayoutItemMapOverview *overview );

void storeCurrentLayerSet();

};
Expand Down
11 changes: 11 additions & 0 deletions src/app/layout/qgslayoutpolygonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ QgsLayoutPolygonWidget::QgsLayoutPolygonWidget( QgsLayoutItemPolygon *polygon )
if ( mPolygon )
{
connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
}

setGuiElementValues();
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/app/layout/qgslayoutpolylinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ QgsLayoutPolylineWidget::QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polylin
if ( mPolyline )
{
connect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues );
mLineStyleButton->registerExpressionContextGenerator( mPolyline );
}
setGuiElementValues();

Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/app/layout/qgslayoutshapewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down
Loading

0 comments on commit aa2b73d

Please sign in to comment.