Skip to content

Commit

Permalink
Merge pull request #45756 from DelazJ/labelLegendGroupBox
Browse files Browse the repository at this point in the history
Remove the unnecessary checkbox for the Label legend group box
  • Loading branch information
m-kuhn committed Oct 31, 2021
2 parents 9322dc6 + 547dee8 commit 469d387
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
29 changes: 10 additions & 19 deletions src/gui/vector/qgsvectorlayerlegendwidget.cpp
Expand Up @@ -60,11 +60,9 @@ QgsVectorLayerLegendWidget::QgsVectorLayerLegendWidget( QWidget *parent )
mTextOnSymbolGroupBox->setLayout( groupLayout );
mTextOnSymbolGroupBox->setCollapsed( false );

mShowLabelLegendCheckBox = new QCheckBox( tr( "Show label legend" ) );
connect( mShowLabelLegendCheckBox, &QCheckBox::toggled, this, &QgsVectorLayerLegendWidget::enableLabelLegendGroupBox );
mLabelLegendGroupBox = new QgsCollapsibleGroupBox;
mLabelLegendGroupBox->setVisible( false );
mLabelLegendGroupBox->setTitle( tr( "Label legend" ) );
mLabelLegendGroupBox->setCheckable( true );
mLabelLegendGroupBox->setTitle( tr( "Show Label Legend" ) );

mLabelLegendTreeWidget = new QTreeWidget;
connect( mLabelLegendTreeWidget, &QTreeWidget::itemDoubleClicked, this, &QgsVectorLayerLegendWidget::labelLegendTreeWidgetItemDoubleClicked );
Expand All @@ -80,27 +78,19 @@ QgsVectorLayerLegendWidget::QgsVectorLayerLegendWidget( QWidget *parent )
mImageSourceLineEdit->setSource( mLayer->legendPlaceholderImage() );
}

QHBoxLayout *placeholderLayout = new QHBoxLayout;
placeholderLayout->addWidget( mPlaceholderImageLabel );
placeholderLayout->addWidget( mImageSourceLineEdit );

QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mPlaceholderImageLabel );
layout->addWidget( mImageSourceLineEdit );
layout->addWidget( mShowLabelLegendCheckBox );
layout->addLayout( placeholderLayout );
layout->addWidget( mLabelLegendGroupBox );
layout->addWidget( mTextOnSymbolGroupBox );

setLayout( layout );
}

void QgsVectorLayerLegendWidget::enableLabelLegendGroupBox( bool enable )
{
mLabelLegendGroupBox->setVisible( enable );
if ( enable )
{
populateLabelLegendTreeWidget();
}
}

void QgsVectorLayerLegendWidget::labelLegendTreeWidgetItemDoubleClicked( QTreeWidgetItem *item, int column )
{
const Qt::ItemFlags flags = item->flags();
Expand Down Expand Up @@ -128,7 +118,8 @@ void QgsVectorLayerLegendWidget::setLayer( QgsVectorLayer *layer )
if ( !legend )
return;

mShowLabelLegendCheckBox->setChecked( legend->showLabelLegend() );
mLabelLegendGroupBox->setChecked( legend->showLabelLegend() );
populateLabelLegendTreeWidget();
mTextOnSymbolGroupBox->setChecked( legend->textOnSymbolEnabled() );
mTextOnSymbolFormatButton->setTextFormat( legend->textOnSymbolTextFormat() );
populateLegendTreeView( legend->textOnSymbolContent() );
Expand All @@ -142,7 +133,7 @@ void QgsVectorLayerLegendWidget::populateLabelLegendTreeWidget()
{
mLabelLegendTreeWidget->clear();
mLabelLegendTreeWidget->setColumnCount( 2 );
QTreeWidgetItem *headerItem = new QTreeWidgetItem( QStringList() << tr( "Description" ) << tr( "LegendText" ) );
QTreeWidgetItem *headerItem = new QTreeWidgetItem( QStringList() << tr( "Description" ) << tr( "Legend Text" ) );
mLabelLegendTreeWidget->setHeaderItem( headerItem );

const QgsAbstractVectorLayerLabeling *labeling = mLayer->labeling();
Expand Down Expand Up @@ -227,7 +218,7 @@ void QgsVectorLayerLegendWidget::applyToLayer()
}
legend->setTextOnSymbolContent( content );

const bool showLabelLegend = mShowLabelLegendCheckBox->isChecked();
const bool showLabelLegend = mLabelLegendGroupBox->isChecked();
legend->setShowLabelLegend( showLabelLegend );
if ( showLabelLegend )
{
Expand Down
3 changes: 0 additions & 3 deletions src/gui/vector/qgsvectorlayerlegendwidget.h
Expand Up @@ -24,7 +24,6 @@
#include "qgstextformat.h"
#include "qgis_gui.h"

class QCheckBox;
class QgsImageSourceLineEdit;
class QLabel;
class QPushButton;
Expand Down Expand Up @@ -60,7 +59,6 @@ class GUI_EXPORT QgsVectorLayerLegendWidget : public QWidget

private slots:
void labelsFromExpression();
void enableLabelLegendGroupBox( bool enable );
void labelLegendTreeWidgetItemDoubleClicked( QTreeWidgetItem *item, int column );

private:
Expand All @@ -74,7 +72,6 @@ class GUI_EXPORT QgsVectorLayerLegendWidget : public QWidget
QPushButton *mTextOnSymbolFromExpressionButton = nullptr;
QgsCollapsibleGroupBox *mTextOnSymbolGroupBox = nullptr;
QLabel *mTextOnSymbolLabel = nullptr;
QCheckBox *mShowLabelLegendCheckBox = nullptr;
QgsCollapsibleGroupBox *mLabelLegendGroupBox = nullptr;
QTreeWidget *mLabelLegendTreeWidget = nullptr;
QLabel *mPlaceholderImageLabel = nullptr;
Expand Down
46 changes: 34 additions & 12 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -1385,8 +1385,28 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Legend">
<layout class="QGridLayout" name="gridLayout_15">
<item row="2" column="0">
<layout class="QVBoxLayout" name="verticalLayout_151">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mLegendPlaceholderLabel">
<property name="text">
<string>Legend placeholder image</string>
</property>
</widget>
</item>
<item>
<widget class="QgsImageSourceLineEdit" name="mLegendPlaceholderWidget" native="true"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
Expand All @@ -1398,22 +1418,24 @@ p, li { white-space: pre-wrap; }
<string>Embedded Widgets in Legend</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QgsLayerTreeEmbeddedConfigWidget" name="mLegendConfigEmbeddedWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QgsImageSourceLineEdit" name="mLegendPlaceholderWidget" native="true"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mLegendPlaceholderLabel">
<property name="text">
<string>Legend placeholder image</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Server">
Expand Down
12 changes: 12 additions & 0 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -2059,6 +2059,18 @@
<string>Embedded Widgets in Legend</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QgsLayerTreeEmbeddedConfigWidget" name="mLegendConfigEmbeddedWidget" native="true"/>
</item>
Expand Down

0 comments on commit 469d387

Please sign in to comment.