diff --git a/python/core/layout/qgslayoutitem.sip b/python/core/layout/qgslayoutitem.sip index 7ab8cee13bd..0c3bd726eda 100644 --- a/python/core/layout/qgslayoutitem.sip +++ b/python/core/layout/qgslayoutitem.sip @@ -67,6 +67,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt UndoAtlasMargin, UndoMapRotation, UndoZoomContent, + UndoOverviewStyle, }; explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true ); diff --git a/src/app/layout/qgslayoutmapwidget.cpp b/src/app/layout/qgslayoutmapwidget.cpp index 620cafc4f0f..c099b90480b 100644 --- a/src/app/layout/qgslayoutmapwidget.cpp +++ b/src/app/layout/qgslayoutmapwidget.cpp @@ -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( &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( &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( sender() ); - overview->setFrameSymbol( dynamic_cast< QgsFillSymbol * >( w->symbol()->clone() ) ); - mMapItem->update(); -} - -void QgsLayoutMapWidget::cleanUpOverviewFrameStyleSelector( QgsPanelWidget *container ) -{ - Q_UNUSED( container ); - QgsSymbolSelectorWidget *w = qobject_cast( 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() ); + 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( 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( 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 ); diff --git a/src/app/layout/qgslayoutmapwidget.h b/src/app/layout/qgslayoutmapwidget.h index 7875ab2822d..003180bd195 100644 --- a/src/app/layout/qgslayoutmapwidget.h +++ b/src/app/layout/qgslayoutmapwidget.h @@ -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(); }; diff --git a/src/app/layout/qgslayoutpolygonwidget.cpp b/src/app/layout/qgslayoutpolygonwidget.cpp index 5f9521ab045..a89cc77052c 100644 --- a/src/app/layout/qgslayoutpolygonwidget.cpp +++ b/src/app/layout/qgslayoutpolygonwidget.cpp @@ -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; diff --git a/src/app/layout/qgslayoutpolylinewidget.cpp b/src/app/layout/qgslayoutpolylinewidget.cpp index 587ba9c1051..d47492a6f71 100644 --- a/src/app/layout/qgslayoutpolylinewidget.cpp +++ b/src/app/layout/qgslayoutpolylinewidget.cpp @@ -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; diff --git a/src/app/layout/qgslayoutshapewidget.cpp b/src/app/layout/qgslayoutshapewidget.cpp index 56aa8aaa0c2..ca5a9ae3dd6 100644 --- a/src/app/layout/qgslayoutshapewidget.cpp +++ b/src/app/layout/qgslayoutshapewidget.cpp @@ -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; diff --git a/src/core/layout/qgslayoutitem.h b/src/core/layout/qgslayoutitem.h index 325bd3a4f17..3ac98f2aa44 100644 --- a/src/core/layout/qgslayoutitem.h +++ b/src/core/layout/qgslayoutitem.h @@ -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 }; /** diff --git a/src/ui/layout/qgslayoutmapwidgetbase.ui b/src/ui/layout/qgslayoutmapwidgetbase.ui index c3cc8d27517..876024e209c 100644 --- a/src/ui/layout/qgslayoutmapwidgetbase.ui +++ b/src/ui/layout/qgslayoutmapwidgetbase.ui @@ -63,9 +63,9 @@ 0 - 0 + -1556 627 - 2272 + 2265 @@ -735,13 +735,6 @@ - - - - Change... - - - @@ -766,6 +759,19 @@ + + + + + 0 + 0 + + + + Change... + + + @@ -780,6 +786,12 @@ + + QgsScrollArea + QScrollArea +
qgsscrollarea.h
+ 1 +
QgsPropertyOverrideButton QToolButton @@ -807,9 +819,9 @@
qgsblendmodecombobox.h
- QgsScrollArea - QScrollArea -
qgsscrollarea.h
+ QgsProjectionSelectionWidget + QWidget +
qgsprojectionselectionwidget.h
1
@@ -818,10 +830,9 @@
qgslayoutitemcombobox.h
- QgsProjectionSelectionWidget - QWidget -
qgsprojectionselectionwidget.h
- 1 + QgsSymbolButton + QToolButton +
qgssymbolbutton.h
@@ -907,6 +918,8 @@ + +