QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsmeshvariablestrokewidthwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshvariablestrokewidthtwidget.cpp
3 -------------------------------------
4 begin : April 2020
5 copyright : (C) 2020 by Vincent Cloarec
6 email : vcloarec at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsmeshvariablestrokewidthwidget.cpp"
18
19#include <QDialog>
20#include <QDialogButtonBox>
21#include <QPointer>
22
23#include "qgssettings.h"
24
26 const QgsInterpolatedLineWidth &variableStrokeWidth,
27 double defaultMinimumvalue,
28 double defaultMaximumValue,
29 QWidget *parent
30)
31 : QgsPanelWidget( parent ), mDefaultMinimumValue( defaultMinimumvalue ), mDefaultMaximumValue( defaultMaximumValue )
32{
33 setupUi( this );
34
35 mValueMinimumSpinBox->setSpecialValueText( QString() );
36 mValueMinimumSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
37 mValueMaximumSpinBox->setSpecialValueText( QString() );
38 mValueMaximumSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
39
40 setPanelTitle( tr( "Variable Stroke Width" ) );
41
43
44 connect( mDefaultMinMaxButton, &QPushButton::clicked, this, &QgsMeshVariableStrokeWidthWidget::defaultMinMax );
45
46 connect( mValueMinimumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
47 connect( mValueMaximumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
48 connect( mWidthMinimumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
49 connect( mWidthMaximumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
50 connect( mIgnoreOutOfRangecheckBox, &QCheckBox::toggled, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
51 connect( mUseAbsoluteValueCheckBox, &QCheckBox::toggled, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
52}
53
55{
56 whileBlocking( mValueMinimumSpinBox )->setValue( variableStrokeWidth.minimumValue() );
57 whileBlocking( mValueMaximumSpinBox )->setValue( variableStrokeWidth.maximumValue() );
58 whileBlocking( mWidthMinimumSpinBox )->setValue( variableStrokeWidth.minimumWidth() );
59 whileBlocking( mWidthMaximumSpinBox )->setValue( variableStrokeWidth.maximumWidth() );
60 whileBlocking( mIgnoreOutOfRangecheckBox )->setChecked( variableStrokeWidth.ignoreOutOfRange() );
61 whileBlocking( mUseAbsoluteValueCheckBox )->setChecked( variableStrokeWidth.useAbsoluteValue() );
62}
63
64void QgsMeshVariableStrokeWidthButton::setDefaultMinMaxValue( double minimum, double maximum )
65{
66 mMinimumDefaultValue = minimum;
67 mMaximumDefaultValue = maximum;
68}
69
71{
72 QgsInterpolatedLineWidth strokeWidth;
73 strokeWidth.setMinimumValue( lineEditValue( mValueMinimumSpinBox ) );
74 strokeWidth.setMaximumValue( lineEditValue( mValueMaximumSpinBox ) );
75 strokeWidth.setMinimumWidth( mWidthMinimumSpinBox->value() );
76 strokeWidth.setMaximumWidth( mWidthMaximumSpinBox->value() );
77 strokeWidth.setIgnoreOutOfRange( mIgnoreOutOfRangecheckBox->isChecked() );
78 strokeWidth.setUseAbsoluteValue( mUseAbsoluteValueCheckBox->isChecked() );
79 return strokeWidth;
80}
81
82void QgsMeshVariableStrokeWidthWidget::defaultMinMax()
83{
84 whileBlocking( mValueMinimumSpinBox )->setValue( mDefaultMinimumValue );
85 whileBlocking( mValueMaximumSpinBox )->setValue( mDefaultMaximumValue );
86 emit widgetChanged();
87}
88
90 : QPushButton( parent )
91{
92 updateText();
93 connect( this, &QPushButton::clicked, this, &QgsMeshVariableStrokeWidthButton::openWidget );
94}
95
100
102{
103 mVariableStrokeWidth = variableStrokeWidth;
104 updateText();
105}
106
107void QgsMeshVariableStrokeWidthButton::openWidget()
108{
110 QgsMeshVariableStrokeWidthWidget *widget = new QgsMeshVariableStrokeWidthWidget( mVariableStrokeWidth, mMinimumDefaultValue, mMaximumDefaultValue, panel );
111
112 if ( panel && panel->dockMode() )
113 {
114 connect( widget, &QgsMeshVariableStrokeWidthWidget::widgetChanged, this, [this, widget] {
115 // Update strokeWidth toward button
117 this->emit widgetChanged();
118 } );
119
120 panel->openPanel( widget );
121 return;
122 }
123 else
124 {
125 // Show the dialog version if not in a panel
126 QDialog *dlg = new QDialog( this );
127 const QString key = QStringLiteral( "/UI/paneldialog/%1" ).arg( widget->panelTitle() );
128 QgsSettings settings;
129 dlg->restoreGeometry( settings.value( key ).toByteArray() );
130 dlg->setWindowTitle( widget->panelTitle() );
131 dlg->setLayout( new QVBoxLayout() );
132 dlg->layout()->addWidget( widget );
133 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
134 connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept );
135 connect( buttonBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject );
136 dlg->layout()->addWidget( buttonBox );
137
138 if ( dlg->exec() == QDialog::Accepted )
139 {
141 emit widgetChanged();
142 }
143 settings.setValue( key, dlg->saveGeometry() );
144 }
145}
146
147void QgsMeshVariableStrokeWidthButton::updateText()
148{
149 setText( QString( "%1 - %2" ).arg( QLocale().toString( mVariableStrokeWidth.minimumWidth(), 'g', 3 ), QLocale().toString( mVariableStrokeWidth.maximumWidth(), 'g', 3 ) ) );
150}
151
152double QgsMeshVariableStrokeWidthWidget::lineEditValue( const QgsDoubleSpinBox *lineEdit ) const
153{
154 if ( lineEdit->value() == lineEdit->clearValue() )
155 {
156 return std::numeric_limits<double>::quiet_NaN();
157 }
158
159 return lineEdit->value();
160}
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
@ MinimumValue
Reset value to minimum()
Represents a width than can vary depending on values.
void setUseAbsoluteValue(bool useAbsoluteValue)
Sets whether absolute value are used as input.
double minimumValue() const
Returns the minimum value used to defined the variable width.
void setIgnoreOutOfRange(bool ignoreOutOfRange)
Sets whether the variable width ignores out of range value.
void setMaximumValue(double maximumValue)
Sets the maximum value used to defined the variable width.
bool useAbsoluteValue() const
Returns whether absolute value are used as input.
void setMinimumValue(double minimumValue)
Sets the minimum value used to defined the variable width.
double maximumWidth() const
Returns the maximum width used to defined the variable width.
void setMaximumWidth(double maximumWidth)
Sets the maximum width used to defined the variable width.
double maximumValue() const
Returns the maximum value used to defined the variable width.
void setMinimumWidth(double minimumWidth)
Sets the minimum width used to defined the variable width.
bool ignoreOutOfRange() const
Returns whether the variable width ignores out of range value.
double minimumWidth() const
Returns the minimum width used to defined the variable width.
void setDefaultMinMaxValue(double minimum, double maximum)
Sets the default min/max values that will be reload if needed.
QgsMeshVariableStrokeWidthButton(QWidget *parent=nullptr)
Constructor.
void setVariableStrokeWidth(const QgsInterpolatedLineWidth &variableStrokeWidth)
Sets the variable stroke width.
QgsInterpolatedLineWidth variableStrokeWidth() const
Returns the variable stroke width.
A widget to set parameters of variable stroke width.
QgsMeshVariableStrokeWidthWidget(const QgsInterpolatedLineWidth &variableStrokeWidth, double defaultMinimumvalue, double defaultMaximumValue, QWidget *parent=nullptr)
Constructor.
QgsInterpolatedLineWidth variableStrokeWidth() const
Returns the variable stroke width.
void setVariableStrokeWidth(const QgsInterpolatedLineWidth &variableStrokeWidth)
Sets the variable stroke width.
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 ...
QString panelTitle()
The title of the panel.
void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
bool dockMode()
Returns the dock mode state.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5928