mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Use symbol buttons for grid symbols
This commit is contained in:
parent
cef5dbc073
commit
b7e352613e
@ -73,6 +73,8 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
|
||||
UndoMapGridFrameFill2Color,
|
||||
UndoMapAnnotationDistance,
|
||||
UndoMapGridAnnotationFontColor,
|
||||
UndoMapGridLineSymbol,
|
||||
UndoMapGridMarkerSymbol,
|
||||
};
|
||||
|
||||
explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
|
||||
|
@ -33,8 +33,6 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
|
||||
, mMapGrid( mapGrid )
|
||||
{
|
||||
setupUi( this );
|
||||
connect( mGridLineStyleButton, &QPushButton::clicked, this, &QgsLayoutMapGridWidget::mGridLineStyleButton_clicked );
|
||||
connect( mGridMarkerStyleButton, &QPushButton::clicked, this, &QgsLayoutMapGridWidget::mGridMarkerStyleButton_clicked );
|
||||
connect( mIntervalXSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished );
|
||||
connect( mIntervalYSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsLayoutMapGridWidget::mIntervalYSpinBox_editingFinished );
|
||||
connect( mOffsetXSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mOffsetXSpinBox_valueChanged );
|
||||
@ -139,6 +137,9 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
|
||||
mGridFrameFill2ColorButton->setNoColorString( tr( "Transparent fill" ) );
|
||||
mGridFrameFill2ColorButton->setShowNoColor( true );
|
||||
|
||||
mGridLineStyleButton->setSymbolType( QgsSymbol::Line );
|
||||
mGridMarkerStyleButton->setSymbolType( QgsSymbol::Marker );
|
||||
|
||||
//set initial state of frame style controls
|
||||
toggleFrameControls( false, false, false );
|
||||
|
||||
@ -146,6 +147,8 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
|
||||
|
||||
blockAllSignals( false );
|
||||
connect( mAnnotationFontButton, &QgsFontButton::changed, this, &QgsLayoutMapGridWidget::annotationFontChanged );
|
||||
connect( mGridLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapGridWidget::lineSymbolChanged );
|
||||
connect( mGridMarkerStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapGridWidget::markerSymbolChanged );
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::populateDataDefinedButtons()
|
||||
@ -153,65 +156,6 @@ void QgsLayoutMapGridWidget::populateDataDefinedButtons()
|
||||
// none for now
|
||||
}
|
||||
|
||||
|
||||
void QgsLayoutMapGridWidget::updateGridLineStyleFromWidget()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
|
||||
mMapGrid->setLineSymbol( dynamic_cast< QgsLineSymbol * >( w->symbol()->clone() ) );
|
||||
mMap->update();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::cleanUpGridLineStyleSelector( QgsPanelWidget *container )
|
||||
{
|
||||
QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
|
||||
if ( !w )
|
||||
return;
|
||||
|
||||
delete w->symbol();
|
||||
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateGridLineSymbolMarker();
|
||||
mMap->endCommand();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::updateGridMarkerStyleFromWidget()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
|
||||
mMapGrid->setMarkerSymbol( dynamic_cast< QgsMarkerSymbol * >( w->symbol()->clone() ) );
|
||||
mMap->update();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::cleanUpGridMarkerStyleSelector( QgsPanelWidget *container )
|
||||
{
|
||||
QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
|
||||
if ( !w )
|
||||
return;
|
||||
|
||||
delete w->symbol();
|
||||
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateGridMarkerSymbolMarker();
|
||||
mMap->endCommand();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::setGuiElementValues()
|
||||
{
|
||||
updateGuiElements();
|
||||
@ -256,6 +200,7 @@ void QgsLayoutMapGridWidget::blockAllSignals( bool block )
|
||||
mFrameDivisionsRightComboBox->blockSignals( block );
|
||||
mFrameDivisionsTopComboBox->blockSignals( block );
|
||||
mFrameDivisionsBottomComboBox->blockSignals( block );
|
||||
mGridMarkerStyleButton->blockSignals( block );
|
||||
|
||||
//grid annotation
|
||||
mDrawAnnotationGroupBox->blockSignals( block );
|
||||
@ -493,6 +438,9 @@ void QgsLayoutMapGridWidget::setGridItems()
|
||||
return;
|
||||
}
|
||||
|
||||
mGridMarkerStyleButton->registerExpressionContextGenerator( mMapGrid );
|
||||
mGridLineStyleButton->registerExpressionContextGenerator( mMapGrid );
|
||||
|
||||
mIntervalXSpinBox->setValue( mMapGrid->intervalX() );
|
||||
mIntervalYSpinBox->setValue( mMapGrid->intervalY() );
|
||||
mOffsetXSpinBox->setValue( mMapGrid->offsetX() );
|
||||
@ -595,9 +543,9 @@ void QgsLayoutMapGridWidget::setGridItems()
|
||||
initFrameDisplayBox( mFrameDivisionsBottomComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Bottom ) );
|
||||
|
||||
//line style
|
||||
updateGridLineSymbolMarker();
|
||||
mGridLineStyleButton->setSymbol( mMapGrid->lineSymbol()->clone() );
|
||||
//marker style
|
||||
updateGridMarkerSymbolMarker();
|
||||
mGridMarkerStyleButton->setSymbol( mMapGrid->markerSymbol()->clone() );
|
||||
|
||||
mGridBlendComboBox->setBlendMode( mMapGrid->blendMode() );
|
||||
|
||||
@ -646,80 +594,6 @@ void QgsLayoutMapGridWidget::setGridItems()
|
||||
mMapGridCRSButton->setText( crsButtonText );
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::updateGridLineSymbolMarker()
|
||||
{
|
||||
if ( mMapGrid )
|
||||
{
|
||||
QgsLineSymbol *nonConstSymbol = const_cast<QgsLineSymbol *>( mMapGrid->lineSymbol() ); //bad
|
||||
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( nonConstSymbol, mGridLineStyleButton->iconSize() );
|
||||
mGridLineStyleButton->setIcon( icon );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::updateGridMarkerSymbolMarker()
|
||||
{
|
||||
if ( mMapGrid )
|
||||
{
|
||||
QgsMarkerSymbol *nonConstSymbol = const_cast<QgsMarkerSymbol *>( mMapGrid->markerSymbol() ); //bad
|
||||
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( nonConstSymbol, mGridMarkerStyleButton->iconSize() );
|
||||
mGridMarkerStyleButton->setIcon( icon );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::mGridLineStyleButton_clicked()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0 //TODO
|
||||
// use the atlas coverage layer, if any
|
||||
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
|
||||
#endif
|
||||
QgsVectorLayer *coverageLayer = nullptr;
|
||||
|
||||
QgsLineSymbol *newSymbol = static_cast<QgsLineSymbol *>( mMapGrid->lineSymbol()->clone() );
|
||||
QgsExpressionContext context = mMap->createExpressionContext();
|
||||
|
||||
QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
|
||||
QgsSymbolWidgetContext symbolContext;
|
||||
symbolContext.setExpressionContext( &context );
|
||||
d->setContext( symbolContext );
|
||||
|
||||
connect( d, &QgsPanelWidget::widgetChanged, this, &QgsLayoutMapGridWidget::updateGridLineStyleFromWidget );
|
||||
connect( d, &QgsPanelWidget::panelAccepted, this, &QgsLayoutMapGridWidget::cleanUpGridLineStyleSelector );
|
||||
openPanel( d );
|
||||
mMap->beginCommand( tr( "Grid line style changed" ) );
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::mGridMarkerStyleButton_clicked()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0 //TODO
|
||||
// use the atlas coverage layer, if any
|
||||
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
|
||||
#endif
|
||||
QgsVectorLayer *coverageLayer = nullptr;
|
||||
|
||||
QgsMarkerSymbol *newSymbol = static_cast<QgsMarkerSymbol *>( mMapGrid->markerSymbol()->clone() );
|
||||
QgsExpressionContext context = mMap->createExpressionContext();
|
||||
|
||||
QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
|
||||
QgsSymbolWidgetContext symbolContext;
|
||||
symbolContext.setExpressionContext( &context );
|
||||
d->setContext( symbolContext );
|
||||
|
||||
connect( d, &QgsPanelWidget::widgetChanged, this, &QgsLayoutMapGridWidget::updateGridMarkerStyleFromWidget );
|
||||
connect( d, &QgsPanelWidget::panelAccepted, this, &QgsLayoutMapGridWidget::cleanUpGridMarkerStyleSelector );
|
||||
openPanel( d );
|
||||
mMap->beginCommand( tr( "Grid markers style changed" ) );
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
@ -1221,6 +1095,32 @@ void QgsLayoutMapGridWidget::annotationFontChanged()
|
||||
mMap->endCommand();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::lineSymbolChanged()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mMap->beginCommand( tr( "Change Grid Line Style" ), QgsLayoutItem::UndoMapGridLineSymbol );
|
||||
mMapGrid->setLineSymbol( mGridLineStyleButton->clonedSymbol<QgsLineSymbol>() );
|
||||
mMap->endCommand();
|
||||
mMap->update();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::markerSymbolChanged()
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mMap->beginCommand( tr( "Change Grid Marker Style" ), QgsLayoutItem::UndoMapGridMarkerSymbol );
|
||||
mMapGrid->setMarkerSymbol( mGridMarkerStyleButton->clonedSymbol<QgsMarkerSymbol>() );
|
||||
mMap->endCommand();
|
||||
mMap->update();
|
||||
}
|
||||
|
||||
void QgsLayoutMapGridWidget::mAnnotationFontColorButton_colorChanged( const QColor &color )
|
||||
{
|
||||
if ( !mMapGrid || !mMap )
|
||||
|
@ -36,8 +36,6 @@ class QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLay
|
||||
public slots:
|
||||
|
||||
void setGridItems();
|
||||
void mGridLineStyleButton_clicked();
|
||||
void mGridMarkerStyleButton_clicked();
|
||||
void mIntervalXSpinBox_editingFinished();
|
||||
void mIntervalYSpinBox_editingFinished();
|
||||
void mOffsetXSpinBox_valueChanged( double value );
|
||||
@ -103,12 +101,9 @@ class QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLay
|
||||
|
||||
//! Sets the GUI elements to the values of mPicture
|
||||
void setGuiElementValues();
|
||||
|
||||
void updateGridLineStyleFromWidget();
|
||||
void cleanUpGridLineStyleSelector( QgsPanelWidget *container );
|
||||
void updateGridMarkerStyleFromWidget();
|
||||
void cleanUpGridMarkerStyleSelector( QgsPanelWidget *container );
|
||||
void annotationFontChanged();
|
||||
void lineSymbolChanged();
|
||||
void markerSymbolChanged();
|
||||
|
||||
private:
|
||||
QgsLayoutItemMap *mMap = nullptr;
|
||||
@ -132,9 +127,6 @@ class QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLay
|
||||
void initAnnotationPositionBox( QComboBox *c, QgsLayoutItemMapGrid::AnnotationPosition pos );
|
||||
void initAnnotationDirectionBox( QComboBox *c, QgsLayoutItemMapGrid::AnnotationDirection dir );
|
||||
|
||||
void updateGridLineSymbolMarker();
|
||||
void updateGridMarkerSymbolMarker();
|
||||
|
||||
//! Enables/disables grid frame related controls
|
||||
void toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled );
|
||||
|
||||
|
@ -106,6 +106,8 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
|
||||
UndoMapGridFrameFill2Color, //!< Map grid frame fill color 2
|
||||
UndoMapAnnotationDistance, //!< Map frame annotation distance
|
||||
UndoMapGridAnnotationFontColor, //!< Map frame annotation color
|
||||
UndoMapGridLineSymbol, //!< Grid line symbol
|
||||
UndoMapGridMarkerSymbol, //!< Grid marker symbol
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>389</width>
|
||||
<height>1419</height>
|
||||
<height>1417</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -249,13 +249,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="mGridLineStyleButton">
|
||||
<property name="text">
|
||||
<string>change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="mMarkerStyleLabel">
|
||||
<property name="text">
|
||||
@ -266,13 +259,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QPushButton" name="mGridMarkerStyleButton">
|
||||
<property name="text">
|
||||
<string>change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="mGridBlendLabel">
|
||||
<property name="text">
|
||||
@ -283,6 +269,32 @@
|
||||
<item row="8" column="1">
|
||||
<widget class="QgsBlendModeComboBox" name="mGridBlendComboBox"/>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QgsSymbolButton" name="mGridLineStyleButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QgsSymbolButton" name="mGridMarkerStyleButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -780,6 +792,11 @@
|
||||
<extends>QComboBox</extends>
|
||||
<header>qgsblendmodecombobox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsSymbolButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>qgssymbolbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>scrollArea</tabstop>
|
||||
|
Loading…
x
Reference in New Issue
Block a user