QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgscolorramplegendnodewidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorramplegendnodewidget.h
3 -----------------------
4 begin : December 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgscolorramplegendnodewidget.cpp"
20#include "qgshelp.h"
22#include "qgsnumericformat.h"
23#include <QDialogButtonBox>
24
26 : QgsPanelWidget( parent )
27{
28 setupUi( this );
29
30 mDirectionComboBox->addItem( tr( "Maximum on Top" ), QgsColorRampLegendNodeSettings::MinimumToMaximum );
31 mDirectionComboBox->addItem( tr( "Minimum on Top" ), QgsColorRampLegendNodeSettings::MaximumToMinimum );
32
33 mOrientationComboBox->addItem( tr( "Vertical" ), Qt::Vertical );
34 mOrientationComboBox->addItem( tr( "Horizontal" ), Qt::Horizontal );
35
36 if ( capabilities.testFlag( Capability::DefaultMinimum ) )
37 {
38 mMinLabelLineEdit->setPlaceholderText( tr( "Default" ) );
39 }
40 else
41 {
42 mMinLabelLineEdit->setShowClearButton( false );
43 }
44 if ( capabilities.testFlag( Capability::DefaultMinimum ) )
45 {
46 mMaxLabelLineEdit->setPlaceholderText( tr( "Default" ) );
47 }
48 else
49 {
50 mMaxLabelLineEdit->setShowClearButton( false );
51 }
52
53 mFontButton->setShowNullFormat( true );
54 mFontButton->setNoFormatString( tr( "Default" ) );
55
56 connect( mUseContinuousLegendCheckBox, &QCheckBox::stateChanged, this, [ = ]( bool checked )
57 {
58 mLayoutGroup->setEnabled( checked );
59 mLabelsGroup->setEnabled( checked );
60 onChanged();
61 } );
62
63 connect( mMinLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
64 connect( mMaxLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
65 connect( mPrefixLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
66 connect( mSuffixLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
67 connect( mDirectionComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onChanged );
68 connect( mOrientationComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onOrientationChanged );
69 connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsColorRampLegendNodeWidget::changeNumberFormat );
70 connect( mFontButton, &QgsFontButton::changed, this, &QgsColorRampLegendNodeWidget::onChanged );
71
72 if ( !capabilities.testFlag( Capability::Prefix ) )
73 {
74 mPrefixLineEdit->hide();
75 mPrefixLabel->hide();
76 }
77 if ( !capabilities.testFlag( Capability::Suffix ) )
78 {
79 mSuffixLineEdit->hide();
80 mSuffixLabel->hide();
81 }
82 if ( !capabilities.testFlag( Capability::NumberFormat ) )
83 {
84 mNumberFormatPushButton->hide();
85 mNumberFormatLabel->hide();
86 }
87}
88
90{
92 settings.setUseContinuousLegend( mUseContinuousLegendCheckBox->isChecked() );
93 settings.setDirection( static_cast< QgsColorRampLegendNodeSettings::Direction >( mDirectionComboBox->currentData().toInt() ) );
94 settings.setOrientation( static_cast< Qt::Orientation >( mOrientationComboBox->currentData().toInt() ) );
95 settings.setMinimumLabel( mMinLabelLineEdit->text() );
96 settings.setMaximumLabel( mMaxLabelLineEdit->text() );
97 settings.setPrefix( mPrefixLineEdit->text() );
98 settings.setSuffix( mSuffixLineEdit->text() );
100 settings.setTextFormat( mFontButton->textFormat() );
101 return settings;
102}
103
105{
106 mBlockSignals = true;
107
108 mSettings = settings;
109 mUseContinuousLegendCheckBox->setChecked( settings.useContinuousLegend() );
110 mMinLabelLineEdit->setText( settings.minimumLabel() );
111 mMaxLabelLineEdit->setText( settings.maximumLabel() );
112 mPrefixLineEdit->setText( settings.prefix() );
113 mSuffixLineEdit->setText( settings.suffix() );
114 mDirectionComboBox->setCurrentIndex( mDirectionComboBox->findData( settings.direction() ) );
115 mOrientationComboBox->setCurrentIndex( mOrientationComboBox->findData( settings.orientation() ) );
116 mFontButton->setTextFormat( settings.textFormat() );
117 onOrientationChanged();
118 mBlockSignals = false;
119}
120
122{
123 mUseContinuousLegendCheckBox->setVisible( visible );
124}
125
126void QgsColorRampLegendNodeWidget::changeNumberFormat()
127{
129 widget->setPanelTitle( tr( "Number Format" ) );
130 widget->setFormat( mSettings.numericFormat() );
131 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [ = ]
132 {
133 mSettings.setNumericFormat( widget->format() );
134 onChanged();
135 } );
136 openPanel( widget );
137 return;
138}
139
140void QgsColorRampLegendNodeWidget::onOrientationChanged()
141{
142 switch ( static_cast< Qt::Orientation >( mOrientationComboBox->currentData().toInt() ) )
143 {
144 case Qt::Vertical:
145 mDirectionComboBox->setItemText( 0, tr( "Maximum on Top" ) );
146 mDirectionComboBox->setItemText( 1, tr( "Minimum on Top" ) );
147 break;
148
149 case Qt::Horizontal:
150 mDirectionComboBox->setItemText( 0, tr( "Maximum on Right" ) );
151 mDirectionComboBox->setItemText( 1, tr( "Minimum on Right" ) );
152 break;
153 }
154
155 onChanged();
156}
157
158void QgsColorRampLegendNodeWidget::onChanged()
159{
160 if ( mBlockSignals )
161 return;
162
163 emit widgetChanged();
164}
165
166//
167// QgsColorRampLegendNodeDialog
168//
169
171 : QDialog( parent )
172{
173 QVBoxLayout *vLayout = new QVBoxLayout();
174 mWidget = new QgsColorRampLegendNodeWidget( nullptr, capabilities );
175 vLayout->addWidget( mWidget );
176 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
177 connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
178 connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
179 connect( mButtonBox, &QDialogButtonBox::helpRequested, this, [ = ]
180 {
181 QgsHelp::openHelp( QStringLiteral( "working_with_raster/raster_properties.html#raster-legend-settings" ) );
182 } );
183 connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );
184 vLayout->addWidget( mButtonBox );
185 setLayout( vLayout );
186 setWindowTitle( tr( "Legend Node Settings" ) );
187
188 mWidget->setSettings( settings );
189}
190
195
197{
198 return mButtonBox;
199}
200
void setUseContinuousRampCheckBoxVisibility(bool visible)
Sets visibility for the "Use Continuous Legend" checkbox in the legend settings dialog to visible.
QgsColorRampLegendNodeDialog(const QgsColorRampLegendNodeSettings &settings, QWidget *parent SIP_TRANSFERTHIS=nullptr, QgsColorRampLegendNodeWidget::Capabilities capabilities=QgsColorRampLegendNodeWidget::Capability::AllCapabilities)
Constructor for QgsColorRampLegendNodeDialog, initially showing the specified settings.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
QgsColorRampLegendNodeSettings settings() const
Returns the legend node settings as defined by the dialog.
Settings for a color ramp legend node.
void setDirection(QgsColorRampLegendNodeSettings::Direction direction)
Sets the direction of the ramp.
void setMaximumLabel(const QString &label)
Sets the label for the maximum value on the ramp.
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
bool useContinuousLegend() const
Returns true if a continuous gradient legend will be used.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
QString maximumLabel() const
Returns the label for the maximum value on the ramp.
QString suffix() const
Returns the suffix to show after legend text.
void setPrefix(const QString &prefix)
Sets the prefix to show before legend text.
void setUseContinuousLegend(bool useContinuousLegend)
Sets the flag to use a continuous gradient legend to useContinuousLegend.
void setOrientation(Qt::Orientation orientation)
Sets the ramp orientation (i.e.
@ MaximumToMinimum
Maximum value on bottom, minimum value on top.
@ MinimumToMaximum
Minimum value on bottom, maximum value on top.
void setSuffix(const QString &suffix)
Sets the suffix to show after legend text.
QString prefix() const
Returns the prefix to show before legend text.
Qt::Orientation orientation() const
Returns the ramp orientation (i.e.
QgsColorRampLegendNodeSettings::Direction direction() const
Returns the direction of the ramp.
QgsTextFormat textFormat() const
Returns the text format used to render text in the legend item.
void setMinimumLabel(const QString &label)
Sets the label for the minimum value on the ramp.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used to render text in the legend item.
QString minimumLabel() const
Returns the label for the minimum value on the ramp.
A widget for properties relating to a QgsColorRampLegendNode (QgsColorRampLegendNodeSettings).
QFlags< Capability > Capabilities
Capabilities to expose in the widget.
@ Suffix
Allow editing legend suffix.
@ DefaultMinimum
Allow resetting minimum label to default.
@ NumberFormat
Allow editing number format.
@ Prefix
Allow editing legend prefix.
QgsColorRampLegendNodeSettings settings() const
Returns the legend node settings as defined by the widget.
void setSettings(const QgsColorRampLegendNodeSettings &settings)
Sets the settings to show in the widget.
QgsColorRampLegendNodeWidget(QWidget *parent=nullptr, QgsColorRampLegendNodeWidget::Capabilities capabilities=QgsColorRampLegendNodeWidget::Capability::AllCapabilities)
Constructor for QgsColorRampLegendNodeWidget, with the specified parent widget.
void setUseContinuousRampCheckBoxVisibility(bool visible)
Sets visibility for the "Use Continuous Legend" checkbox to visible.
void changed()
Emitted when the widget's text format settings are changed.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
A widget which allows choice of numeric formats and the properties of them.
QgsNumericFormat * format() const
Returns a new format object representing the settings currently configured in the widget.
void changed()
Emitted whenever the format configured55 in the widget is changed.
void setFormat(const QgsNumericFormat *format)
Sets the format to show in the widget.
virtual QgsNumericFormat * clone() const =0
Clones the format, returning a new object.
Base class for any widget that can be shown as a inline panel.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
void widgetChanged()
Emitted when the widget state changes.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.