QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
26#include "moc_qgscolorramplegendnodewidget.cpp"
27
29 : QgsPanelWidget( parent )
30{
31 setupUi( this );
32
33 mDirectionComboBox->addItem( tr( "Maximum on Top" ), QgsColorRampLegendNodeSettings::MinimumToMaximum );
34 mDirectionComboBox->addItem( tr( "Minimum on Top" ), QgsColorRampLegendNodeSettings::MaximumToMinimum );
35
36 mOrientationComboBox->addItem( tr( "Vertical" ), Qt::Vertical );
37 mOrientationComboBox->addItem( tr( "Horizontal" ), Qt::Horizontal );
38
39 if ( capabilities.testFlag( Capability::DefaultMinimum ) )
40 {
41 mMinLabelLineEdit->setPlaceholderText( tr( "Default" ) );
42 }
43 else
44 {
45 mMinLabelLineEdit->setShowClearButton( false );
46 }
47 if ( capabilities.testFlag( Capability::DefaultMinimum ) )
48 {
49 mMaxLabelLineEdit->setPlaceholderText( tr( "Default" ) );
50 }
51 else
52 {
53 mMaxLabelLineEdit->setShowClearButton( false );
54 }
55
56 mFontButton->setShowNullFormat( true );
57 mFontButton->setNoFormatString( tr( "Default" ) );
58
59 connect( mUseContinuousLegendCheckBox, &QCheckBox::stateChanged, this, [this]( bool checked ) {
60 mLayoutGroup->setEnabled( checked );
61 mLabelsGroup->setEnabled( checked );
62 onChanged();
63 } );
64
65 connect( mMinLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
66 connect( mMaxLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
67 connect( mPrefixLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
68 connect( mSuffixLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
69 connect( mDirectionComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onChanged );
70 connect( mOrientationComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onOrientationChanged );
71 connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsColorRampLegendNodeWidget::changeNumberFormat );
72 connect( mFontButton, &QgsFontButton::changed, this, &QgsColorRampLegendNodeWidget::onChanged );
73
74 if ( !capabilities.testFlag( Capability::Prefix ) )
75 {
76 mPrefixLineEdit->hide();
77 mPrefixLabel->hide();
78 }
79 if ( !capabilities.testFlag( Capability::Suffix ) )
80 {
81 mSuffixLineEdit->hide();
82 mSuffixLabel->hide();
83 }
84 if ( !capabilities.testFlag( Capability::NumberFormat ) )
85 {
86 mNumberFormatPushButton->hide();
87 mNumberFormatLabel->hide();
88 }
89}
90
92{
94 settings.setUseContinuousLegend( mUseContinuousLegendCheckBox->isChecked() );
95 settings.setDirection( static_cast<QgsColorRampLegendNodeSettings::Direction>( mDirectionComboBox->currentData().toInt() ) );
96 settings.setOrientation( static_cast<Qt::Orientation>( mOrientationComboBox->currentData().toInt() ) );
97 settings.setMinimumLabel( mMinLabelLineEdit->text() );
98 settings.setMaximumLabel( mMaxLabelLineEdit->text() );
99 settings.setPrefix( mPrefixLineEdit->text() );
100 settings.setSuffix( mSuffixLineEdit->text() );
101 settings.setNumericFormat( mSettings.numericFormat()->clone() );
102 settings.setTextFormat( mFontButton->textFormat() );
103 return settings;
104}
105
107{
108 mBlockSignals = true;
109
110 mSettings = settings;
111 mUseContinuousLegendCheckBox->setChecked( settings.useContinuousLegend() );
112 mMinLabelLineEdit->setText( settings.minimumLabel() );
113 mMaxLabelLineEdit->setText( settings.maximumLabel() );
114 mPrefixLineEdit->setText( settings.prefix() );
115 mSuffixLineEdit->setText( settings.suffix() );
116 mDirectionComboBox->setCurrentIndex( mDirectionComboBox->findData( settings.direction() ) );
117 mOrientationComboBox->setCurrentIndex( mOrientationComboBox->findData( settings.orientation() ) );
118 mFontButton->setTextFormat( settings.textFormat() );
119 onOrientationChanged();
120 mBlockSignals = false;
121}
122
124{
125 mUseContinuousLegendCheckBox->setVisible( visible );
126}
127
128void QgsColorRampLegendNodeWidget::changeNumberFormat()
129{
131 widget->setPanelTitle( tr( "Number Format" ) );
132 widget->setFormat( mSettings.numericFormat() );
133 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
134 mSettings.setNumericFormat( widget->format() );
135 onChanged();
136 } );
137 openPanel( widget );
138 return;
139}
140
141void QgsColorRampLegendNodeWidget::onOrientationChanged()
142{
143 switch ( static_cast<Qt::Orientation>( mOrientationComboBox->currentData().toInt() ) )
144 {
145 case Qt::Vertical:
146 mDirectionComboBox->setItemText( 0, tr( "Maximum on Top" ) );
147 mDirectionComboBox->setItemText( 1, tr( "Minimum on Top" ) );
148 break;
149
150 case Qt::Horizontal:
151 mDirectionComboBox->setItemText( 0, tr( "Maximum on Right" ) );
152 mDirectionComboBox->setItemText( 1, tr( "Minimum on Right" ) );
153 break;
154 }
155
156 onChanged();
157}
158
159void QgsColorRampLegendNodeWidget::onChanged()
160{
161 if ( mBlockSignals )
162 return;
163
164 emit widgetChanged();
165}
166
167//
168// QgsColorRampLegendNodeDialog
169//
170
172 : QDialog( parent )
173{
174 QVBoxLayout *vLayout = new QVBoxLayout();
175 mWidget = new QgsColorRampLegendNodeWidget( nullptr, capabilities );
176 vLayout->addWidget( mWidget );
177 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
178 connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
179 connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
180 connect( mButtonBox, &QDialogButtonBox::helpRequested, this, [] {
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
192{
193 return mWidget->settings();
194}
195
197{
198 return mButtonBox;
199}
200
202{
203 mWidget->setUseContinuousRampCheckBoxVisibility( visible );
204}
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:38
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.