26#include <QButtonGroup>
30#include "moc_qgslayoutpolylinewidget.cpp"
32using namespace Qt::StringLiterals;
36 , mPolyline( polyline )
41 connect( mStrokeWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowStrokeWidthChanged );
42 connect( mArrowHeadWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowHeadWidthChanged );
45 connect( mRadioStartArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startArrowHeadToggled );
46 connect( mRadioStartNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startNoMarkerToggled );
47 connect( mRadioStartSVG, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startSvgMarkerToggled );
48 connect( mRadioEndArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endArrowHeadToggled );
49 connect( mRadioEndNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endNoMarkerToggled );
50 connect( mRadioEndSvg, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endSvgMarkerToggled );
51 connect( mStartMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged );
52 connect( mEndMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged );
53 connect( mStartMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked );
54 connect( mEndMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked );
56 QButtonGroup *startMarkerGroup =
new QButtonGroup(
this );
57 startMarkerGroup->addButton( mRadioStartNoMarker );
58 startMarkerGroup->addButton( mRadioStartArrow );
59 startMarkerGroup->addButton( mRadioStartSVG );
60 startMarkerGroup->setExclusive(
true );
61 QButtonGroup *endMarkerGroup =
new QButtonGroup(
this );
62 endMarkerGroup->addButton( mRadioEndNoMarker );
63 endMarkerGroup->addButton( mRadioEndArrow );
64 endMarkerGroup->addButton( mRadioEndSvg );
65 endMarkerGroup->setExclusive(
true );
68 enableStartSvgInputElements(
false );
69 enableEndSvgInputElements(
false );
71 mArrowHeadStrokeColorButton->setColorDialogTitle( tr(
"Select Arrow Head Stroke Color" ) );
72 mArrowHeadStrokeColorButton->setAllowOpacity(
true );
73 mArrowHeadStrokeColorButton->setContext( u
"composer"_s );
74 mArrowHeadStrokeColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
75 mArrowHeadStrokeColorButton->setShowNoColor(
true );
76 mArrowHeadFillColorButton->setColorDialogTitle( tr(
"Select Arrow Head Fill Color" ) );
77 mArrowHeadFillColorButton->setAllowOpacity(
true );
78 mArrowHeadFillColorButton->setContext( u
"composer"_s );
79 mArrowHeadFillColorButton->setNoColorString( tr(
"Transparent Fill" ) );
80 mArrowHeadFillColorButton->setShowNoColor(
true );
85 mItemPropertiesWidget->showBackgroundGroup(
false );
86 mItemPropertiesWidget->showFrameGroup(
false );
87 mainLayout->addWidget( mItemPropertiesWidget );
95 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
97 setGuiElementValues();
99 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
101 if ( mPolyline->layout() )
109 if ( mItemPropertiesWidget )
110 mItemPropertiesWidget->setMasterLayout( masterLayout );
123 mPolyline = qobject_cast<QgsLayoutItemPolyline *>( item );
124 mItemPropertiesWidget->setItem( mPolyline );
129 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
132 setGuiElementValues();
138void QgsLayoutPolylineWidget::setGuiElementValues()
143 whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
145 whileBlocking( mArrowHeadFillColorButton )->setColor( mPolyline->arrowHeadFillColor() );
146 whileBlocking( mArrowHeadStrokeColorButton )->setColor( mPolyline->arrowHeadStrokeColor() );
147 whileBlocking( mStrokeWidthSpinBox )->setValue( mPolyline->arrowHeadStrokeWidth() );
148 whileBlocking( mArrowHeadWidthSpinBox )->setValue( mPolyline->arrowHeadWidth() );
150 mRadioStartNoMarker->blockSignals(
true );
151 mRadioStartArrow->blockSignals(
true );
152 mRadioStartSVG->blockSignals(
true );
153 mRadioEndArrow->blockSignals(
true );
154 mRadioEndNoMarker->blockSignals(
true );
155 mRadioEndSvg->blockSignals(
true );
156 switch ( mPolyline->startMarker() )
159 mRadioStartNoMarker->setChecked(
true );
162 mRadioStartArrow->setChecked(
true );
165 mRadioStartSVG->setChecked(
true );
166 enableStartSvgInputElements(
true );
169 switch ( mPolyline->endMarker() )
172 mRadioEndNoMarker->setChecked(
true );
175 mRadioEndArrow->setChecked(
true );
178 mRadioEndSvg->setChecked(
true );
179 enableEndSvgInputElements(
true );
182 mRadioStartNoMarker->blockSignals(
false );
183 mRadioStartArrow->blockSignals(
false );
184 mRadioStartSVG->blockSignals(
false );
185 mRadioEndArrow->blockSignals(
false );
186 mRadioEndNoMarker->blockSignals(
false );
187 mRadioEndSvg->blockSignals(
false );
189 mStartMarkerLineEdit->setText( mPolyline->startSvgMarkerPath() );
190 mEndMarkerLineEdit->setText( mPolyline->endSvgMarkerPath() );
193void QgsLayoutPolylineWidget::symbolChanged()
199 mPolyline->setSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
200 mPolyline->layout()->undoStack()->endCommand();
203void QgsLayoutPolylineWidget::arrowStrokeWidthChanged(
double d )
209 mPolyline->setArrowHeadStrokeWidth( d );
210 mPolyline->endCommand();
213void QgsLayoutPolylineWidget::arrowHeadWidthChanged(
double d )
219 mPolyline->setArrowHeadWidth( d );
220 mPolyline->endCommand();
224void QgsLayoutPolylineWidget::arrowHeadFillColorChanged(
const QColor &newColor )
230 mPolyline->setArrowHeadFillColor( newColor );
231 mPolyline->endCommand();
235void QgsLayoutPolylineWidget::arrowHeadStrokeColorChanged(
const QColor &newColor )
241 mPolyline->setArrowHeadStrokeColor( newColor );
242 mPolyline->endCommand();
246void QgsLayoutPolylineWidget::startArrowHeadToggled(
bool toggled )
248 if ( !mPolyline || !toggled )
251 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
253 mPolyline->endCommand();
256void QgsLayoutPolylineWidget::endArrowHeadToggled(
bool toggled )
258 if ( !mPolyline || !toggled )
261 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
263 mPolyline->endCommand();
266void QgsLayoutPolylineWidget::startNoMarkerToggled(
bool toggled )
268 if ( !mPolyline || !toggled )
271 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
273 mPolyline->endCommand();
276void QgsLayoutPolylineWidget::endNoMarkerToggled(
bool toggled )
278 if ( !mPolyline || !toggled )
281 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
283 mPolyline->endCommand();
286void QgsLayoutPolylineWidget::startSvgMarkerToggled(
bool toggled )
288 enableStartSvgInputElements( toggled );
289 if ( !mPolyline || !toggled )
292 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
294 mPolyline->endCommand();
297void QgsLayoutPolylineWidget::endSvgMarkerToggled(
bool toggled )
299 enableEndSvgInputElements( toggled );
300 if ( !mPolyline || !toggled )
303 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
305 mPolyline->endCommand();
308void QgsLayoutPolylineWidget::enableStartSvgInputElements(
bool enable )
310 mStartMarkerLineEdit->setEnabled( enable );
311 mStartMarkerToolButton->setEnabled( enable );
314void QgsLayoutPolylineWidget::enableEndSvgInputElements(
bool enable )
316 mEndMarkerLineEdit->setEnabled( enable );
317 mEndMarkerToolButton->setEnabled( enable );
320void QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged(
const QString &text )
325 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
326 const QFileInfo fi( text );
327 if ( fi.exists() && fi.isFile() )
329 mPolyline->setStartSvgMarkerPath( text );
333 mPolyline->setStartSvgMarkerPath( QString() );
335 mPolyline->endCommand();
338void QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged(
const QString &text )
343 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
344 const QFileInfo fi( text );
345 if ( fi.exists() && fi.isFile() )
347 mPolyline->setEndSvgMarkerPath( text );
351 mPolyline->setEndSvgMarkerPath( QString() );
353 mPolyline->endCommand();
356void QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked()
361 if ( !mStartMarkerLineEdit->text().isEmpty() )
363 const QFileInfo fi( mStartMarkerLineEdit->text() );
364 openDir = fi.dir().absolutePath();
367 if ( openDir.isEmpty() )
369 openDir = s.
value( u
"/UI/lastComposerMarkerDir"_s, QDir::homePath() ).toString();
372 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"Start marker svg file" ), openDir );
373 if ( !svgFileName.isNull() )
375 const QFileInfo fileInfo( svgFileName );
376 s.
setValue( u
"/UI/lastComposerMarkerDir"_s, fileInfo.absolutePath() );
377 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
378 mStartMarkerLineEdit->setText( svgFileName );
379 mPolyline->endCommand();
383void QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked()
388 if ( !mEndMarkerLineEdit->text().isEmpty() )
390 const QFileInfo fi( mEndMarkerLineEdit->text() );
391 openDir = fi.dir().absolutePath();
394 if ( openDir.isEmpty() )
396 openDir = s.
value( u
"/UI/lastComposerMarkerDir"_s, QDir::homePath() ).toString();
399 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"End marker svg file" ), openDir );
400 if ( !svgFileName.isNull() )
402 const QFileInfo fileInfo( svgFileName );
403 s.
setValue( u
"/UI/lastComposerMarkerDir"_s, fileInfo.absolutePath() );
404 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
405 mEndMarkerLineEdit->setText( svgFileName );
406 mPolyline->endCommand();
Layout item for node based polyline shapes.
@ ArrowHead
Show arrow marker.
@ SvgMarker
Show SVG marker.
@ NoMarker
Don't show marker.
@ LayoutPolyline
Polyline shape item.
Base class for graphical items within a QgsLayout.
@ UndoArrowHeadStrokeColor
Arrow head stroke color.
@ UndoArrowHeadFillColor
Arrow head fill color.
@ UndoArrowHeadWidth
Arrow head width.
@ UndoArrowStrokeWidth
Arrow stroke width.
@ UndoShapeStyle
Shape symbol style.
int type() const override
Returns a unique graphics item type identifier.
void changed()
Emitted when the object's properties change.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
Interface for master layout type objects, such as print layouts and reports.
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.