QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
18#include "qgssettings.h"
19
20#include <QDialog>
21#include <QDialogButtonBox>
22#include <QPointer>
23#include <QString>
24
25#include "moc_qgsmeshvariablestrokewidthwidget.cpp"
26
27using namespace Qt::StringLiterals;
28
31 double defaultMinimumvalue,
32 double defaultMaximumValue,
33 QWidget *parent
34)
35 : QgsPanelWidget( parent ), mDefaultMinimumValue( defaultMinimumvalue ), mDefaultMaximumValue( defaultMaximumValue )
36{
37 setupUi( this );
38
39 mValueMinimumSpinBox->setSpecialValueText( QString() );
40 mValueMinimumSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
41 mValueMaximumSpinBox->setSpecialValueText( QString() );
42 mValueMaximumSpinBox->setClearValueMode( QgsDoubleSpinBox::ClearValueMode::MinimumValue );
43
44 setPanelTitle( tr( "Variable Stroke Width" ) );
45
47
48 connect( mDefaultMinMaxButton, &QPushButton::clicked, this, &QgsMeshVariableStrokeWidthWidget::defaultMinMax );
49
50 connect( mValueMinimumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
51 connect( mValueMaximumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
52 connect( mWidthMinimumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
53 connect( mWidthMaximumSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
54 connect( mIgnoreOutOfRangecheckBox, &QCheckBox::toggled, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
55 connect( mUseAbsoluteValueCheckBox, &QCheckBox::toggled, this, &QgsMeshVariableStrokeWidthWidget::widgetChanged );
56}
57
59{
60 whileBlocking( mValueMinimumSpinBox )->setValue( variableStrokeWidth.minimumValue() );
61 whileBlocking( mValueMaximumSpinBox )->setValue( variableStrokeWidth.maximumValue() );
62 whileBlocking( mWidthMinimumSpinBox )->setValue( variableStrokeWidth.minimumWidth() );
63 whileBlocking( mWidthMaximumSpinBox )->setValue( variableStrokeWidth.maximumWidth() );
64 whileBlocking( mIgnoreOutOfRangecheckBox )->setChecked( variableStrokeWidth.ignoreOutOfRange() );
65 whileBlocking( mUseAbsoluteValueCheckBox )->setChecked( variableStrokeWidth.useAbsoluteValue() );
66}
67
68void QgsMeshVariableStrokeWidthButton::setDefaultMinMaxValue( double minimum, double maximum )
69{
70 mMinimumDefaultValue = minimum;
71 mMaximumDefaultValue = maximum;
72}
73
75{
76 QgsInterpolatedLineWidth strokeWidth;
77 strokeWidth.setMinimumValue( lineEditValue( mValueMinimumSpinBox ) );
78 strokeWidth.setMaximumValue( lineEditValue( mValueMaximumSpinBox ) );
79 strokeWidth.setMinimumWidth( mWidthMinimumSpinBox->value() );
80 strokeWidth.setMaximumWidth( mWidthMaximumSpinBox->value() );
81 strokeWidth.setIgnoreOutOfRange( mIgnoreOutOfRangecheckBox->isChecked() );
82 strokeWidth.setUseAbsoluteValue( mUseAbsoluteValueCheckBox->isChecked() );
83 return strokeWidth;
84}
85
86void QgsMeshVariableStrokeWidthWidget::defaultMinMax()
87{
88 whileBlocking( mValueMinimumSpinBox )->setValue( mDefaultMinimumValue );
89 whileBlocking( mValueMaximumSpinBox )->setValue( mDefaultMaximumValue );
90 emit widgetChanged();
91}
92
94 : QPushButton( parent )
95{
96 updateText();
97 connect( this, &QPushButton::clicked, this, &QgsMeshVariableStrokeWidthButton::openWidget );
98}
99
104
110
111void QgsMeshVariableStrokeWidthButton::openWidget()
112{
114 QgsMeshVariableStrokeWidthWidget *widget = new QgsMeshVariableStrokeWidthWidget( mVariableStrokeWidth, mMinimumDefaultValue, mMaximumDefaultValue, panel );
115
116 if ( panel && panel->dockMode() )
117 {
118 connect( widget, &QgsMeshVariableStrokeWidthWidget::widgetChanged, this, [this, widget] {
119 // Update strokeWidth toward button
121 this->emit widgetChanged();
122 } );
123
124 panel->openPanel( widget );
125 return;
126 }
127 else
128 {
129 // Show the dialog version if not in a panel
130 QDialog *dlg = new QDialog( this );
131 const QString key = u"/UI/paneldialog/%1"_s.arg( widget->panelTitle() );
132 QgsSettings settings;
133 dlg->restoreGeometry( settings.value( key ).toByteArray() );
134 dlg->setWindowTitle( widget->panelTitle() );
135 dlg->setLayout( new QVBoxLayout() );
136 dlg->layout()->addWidget( widget );
137 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
138 connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept );
139 connect( buttonBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject );
140 dlg->layout()->addWidget( buttonBox );
141
142 if ( dlg->exec() == QDialog::Accepted )
143 {
145 emit widgetChanged();
146 }
147 settings.setValue( key, dlg->saveGeometry() );
148 }
149}
150
151void QgsMeshVariableStrokeWidthButton::updateText()
152{
153 setText( QString( "%1 - %2" ).arg( QLocale().toString( mVariableStrokeWidth.minimumWidth(), 'g', 3 ), QLocale().toString( mVariableStrokeWidth.maximumWidth(), 'g', 3 ) ) );
154}
155
156double QgsMeshVariableStrokeWidthWidget::lineEditValue( const QgsDoubleSpinBox *lineEdit ) const
157{
158 if ( lineEdit->value() == lineEdit->clearValue() )
159 {
160 return std::numeric_limits<double>::quiet_NaN();
161 }
162
163 return lineEdit->value();
164}
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 that can vary depending on values.
void setUseAbsoluteValue(bool useAbsoluteValue)
Sets whether absolute value are used as input.
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.
void setMinimumValue(double minimumValue)
Sets the minimum value used to defined the variable width.
void setMaximumWidth(double maximumWidth)
Sets the maximum width used to defined the variable width.
void setMinimumWidth(double minimumWidth)
Sets 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 an inline panel.
QString panelTitle() const
The title of the 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 ...
bool dockMode() const
Returns the dock mode state.
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.
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.
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:6828