QGIS API Documentation 3.99.0-Master (d270888f95f)
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
20#include "qgshelp.h"
21#include "qgsnumericformat.h"
23
24#include <QDialogButtonBox>
25#include <QString>
26
27#include "moc_qgscolorramplegendnodewidget.cpp"
28
29using namespace Qt::StringLiterals;
30
32 : QgsPanelWidget( parent )
33{
34 setupUi( this );
35
36 mDirectionComboBox->addItem( tr( "Maximum on Top" ), QgsColorRampLegendNodeSettings::MinimumToMaximum );
37 mDirectionComboBox->addItem( tr( "Minimum on Top" ), QgsColorRampLegendNodeSettings::MaximumToMinimum );
38
39 mOrientationComboBox->addItem( tr( "Vertical" ), Qt::Vertical );
40 mOrientationComboBox->addItem( tr( "Horizontal" ), Qt::Horizontal );
41
42 if ( capabilities.testFlag( Capability::DefaultMinimum ) )
43 {
44 mMinLabelLineEdit->setPlaceholderText( tr( "Default" ) );
45 }
46 else
47 {
48 mMinLabelLineEdit->setShowClearButton( false );
49 }
50 if ( capabilities.testFlag( Capability::DefaultMinimum ) )
51 {
52 mMaxLabelLineEdit->setPlaceholderText( tr( "Default" ) );
53 }
54 else
55 {
56 mMaxLabelLineEdit->setShowClearButton( false );
57 }
58
59 mFontButton->setShowNullFormat( true );
60 mFontButton->setNoFormatString( tr( "Default" ) );
61
62 connect( mUseContinuousLegendCheckBox, &QCheckBox::stateChanged, this, [this]( bool checked ) {
63 mLayoutGroup->setEnabled( checked );
64 mLabelsGroup->setEnabled( checked );
65 onChanged();
66 } );
67
68 connect( mMinLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
69 connect( mMaxLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
70 connect( mPrefixLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
71 connect( mSuffixLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
72 connect( mDirectionComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onChanged );
73 connect( mOrientationComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onOrientationChanged );
74 connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsColorRampLegendNodeWidget::changeNumberFormat );
75 connect( mFontButton, &QgsFontButton::changed, this, &QgsColorRampLegendNodeWidget::onChanged );
76
77 if ( !capabilities.testFlag( Capability::Prefix ) )
78 {
79 mPrefixLineEdit->hide();
80 mPrefixLabel->hide();
81 }
82 if ( !capabilities.testFlag( Capability::Suffix ) )
83 {
84 mSuffixLineEdit->hide();
85 mSuffixLabel->hide();
86 }
87 if ( !capabilities.testFlag( Capability::NumberFormat ) )
88 {
89 mNumberFormatPushButton->hide();
90 mNumberFormatLabel->hide();
91 }
92}
93
95{
97 settings.setUseContinuousLegend( mUseContinuousLegendCheckBox->isChecked() );
98 settings.setDirection( static_cast<QgsColorRampLegendNodeSettings::Direction>( mDirectionComboBox->currentData().toInt() ) );
99 settings.setOrientation( static_cast<Qt::Orientation>( mOrientationComboBox->currentData().toInt() ) );
100 settings.setMinimumLabel( mMinLabelLineEdit->text() );
101 settings.setMaximumLabel( mMaxLabelLineEdit->text() );
102 settings.setPrefix( mPrefixLineEdit->text() );
103 settings.setSuffix( mSuffixLineEdit->text() );
104 settings.setNumericFormat( mSettings.numericFormat()->clone() );
105 settings.setTextFormat( mFontButton->textFormat() );
106 return settings;
107}
108
110{
111 mBlockSignals = true;
112
113 mSettings = settings;
114 mUseContinuousLegendCheckBox->setChecked( settings.useContinuousLegend() );
115 mMinLabelLineEdit->setText( settings.minimumLabel() );
116 mMaxLabelLineEdit->setText( settings.maximumLabel() );
117 mPrefixLineEdit->setText( settings.prefix() );
118 mSuffixLineEdit->setText( settings.suffix() );
119 mDirectionComboBox->setCurrentIndex( mDirectionComboBox->findData( settings.direction() ) );
120 mOrientationComboBox->setCurrentIndex( mOrientationComboBox->findData( settings.orientation() ) );
121 mFontButton->setTextFormat( settings.textFormat() );
122 onOrientationChanged();
123 mBlockSignals = false;
124}
125
127{
128 mUseContinuousLegendCheckBox->setVisible( visible );
129}
130
131void QgsColorRampLegendNodeWidget::changeNumberFormat()
132{
134 widget->setPanelTitle( tr( "Number Format" ) );
135 widget->setFormat( mSettings.numericFormat() );
136 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
137 mSettings.setNumericFormat( widget->format() );
138 onChanged();
139 } );
140 openPanel( widget );
141 return;
142}
143
144void QgsColorRampLegendNodeWidget::onOrientationChanged()
145{
146 switch ( static_cast<Qt::Orientation>( mOrientationComboBox->currentData().toInt() ) )
147 {
148 case Qt::Vertical:
149 mDirectionComboBox->setItemText( 0, tr( "Maximum on Top" ) );
150 mDirectionComboBox->setItemText( 1, tr( "Minimum on Top" ) );
151 break;
152
153 case Qt::Horizontal:
154 mDirectionComboBox->setItemText( 0, tr( "Maximum on Right" ) );
155 mDirectionComboBox->setItemText( 1, tr( "Minimum on Right" ) );
156 break;
157 }
158
159 onChanged();
160}
161
162void QgsColorRampLegendNodeWidget::onChanged()
163{
164 if ( mBlockSignals )
165 return;
166
167 emit widgetChanged();
168}
169
170//
171// QgsColorRampLegendNodeDialog
172//
173
175 : QDialog( parent )
176{
177 QVBoxLayout *vLayout = new QVBoxLayout();
178 mWidget = new QgsColorRampLegendNodeWidget( nullptr, capabilities );
179 vLayout->addWidget( mWidget );
180 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
181 connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
182 connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
183 connect( mButtonBox, &QDialogButtonBox::helpRequested, this, [] {
184 QgsHelp::openHelp( u"working_with_raster/raster_properties.html#raster-legend-settings"_s );
185 } );
186 connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );
187 vLayout->addWidget( mButtonBox );
188 setLayout( vLayout );
189 setWindowTitle( tr( "Legend Node Settings" ) );
190
191 mWidget->setSettings( settings );
192}
193
195{
196 return mWidget->settings();
197}
198
200{
201 return mButtonBox;
202}
203
205{
206 mWidget->setUseContinuousRampCheckBoxVisibility( visible );
207}
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 setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
@ MaximumToMinimum
Maximum value on bottom, minimum value on top.
@ MinimumToMaximum
Minimum value on bottom, maximum value on top.
A widget for properties relating to a QgsColorRampLegendNode (QgsColorRampLegendNodeSettings).
QFlags< Capability > Capabilities
Capabilities to expose in the widget.
@ DefaultMinimum
Allow resetting minimum label to default.
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:41
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.
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.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
void widgetChanged()
Emitted when the widget state changes.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.