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->setOpaqueColorString( tr(
"Opaque Stroke" ) );
76 mArrowHeadStrokeColorButton->setShowNoColor(
true );
77 mArrowHeadFillColorButton->setColorDialogTitle( tr(
"Select Arrow Head Fill Color" ) );
78 mArrowHeadFillColorButton->setAllowOpacity(
true );
79 mArrowHeadFillColorButton->setContext( u
"composer"_s );
80 mArrowHeadFillColorButton->setNoColorString( tr(
"Transparent Fill" ) );
81 mArrowHeadFillColorButton->setOpaqueColorString( tr(
"Opaque Fill" ) );
82 mArrowHeadFillColorButton->setShowNoColor(
true );
87 mItemPropertiesWidget->showBackgroundGroup(
false );
88 mItemPropertiesWidget->showFrameGroup(
false );
89 mainLayout->addWidget( mItemPropertiesWidget );
97 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
99 setGuiElementValues();
101 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
103 if ( mPolyline->layout() )
111 if ( mItemPropertiesWidget )
112 mItemPropertiesWidget->setMasterLayout( masterLayout );
125 mPolyline = qobject_cast<QgsLayoutItemPolyline *>( item );
126 mItemPropertiesWidget->setItem( mPolyline );
131 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
134 setGuiElementValues();
140void QgsLayoutPolylineWidget::setGuiElementValues()
145 whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
147 whileBlocking( mArrowHeadFillColorButton )->setColor( mPolyline->arrowHeadFillColor() );
148 whileBlocking( mArrowHeadStrokeColorButton )->setColor( mPolyline->arrowHeadStrokeColor() );
149 whileBlocking( mStrokeWidthSpinBox )->setValue( mPolyline->arrowHeadStrokeWidth() );
150 whileBlocking( mArrowHeadWidthSpinBox )->setValue( mPolyline->arrowHeadWidth() );
152 mRadioStartNoMarker->blockSignals(
true );
153 mRadioStartArrow->blockSignals(
true );
154 mRadioStartSVG->blockSignals(
true );
155 mRadioEndArrow->blockSignals(
true );
156 mRadioEndNoMarker->blockSignals(
true );
157 mRadioEndSvg->blockSignals(
true );
158 switch ( mPolyline->startMarker() )
161 mRadioStartNoMarker->setChecked(
true );
164 mRadioStartArrow->setChecked(
true );
167 mRadioStartSVG->setChecked(
true );
168 enableStartSvgInputElements(
true );
171 switch ( mPolyline->endMarker() )
174 mRadioEndNoMarker->setChecked(
true );
177 mRadioEndArrow->setChecked(
true );
180 mRadioEndSvg->setChecked(
true );
181 enableEndSvgInputElements(
true );
184 mRadioStartNoMarker->blockSignals(
false );
185 mRadioStartArrow->blockSignals(
false );
186 mRadioStartSVG->blockSignals(
false );
187 mRadioEndArrow->blockSignals(
false );
188 mRadioEndNoMarker->blockSignals(
false );
189 mRadioEndSvg->blockSignals(
false );
191 mStartMarkerLineEdit->setText( mPolyline->startSvgMarkerPath() );
192 mEndMarkerLineEdit->setText( mPolyline->endSvgMarkerPath() );
195void QgsLayoutPolylineWidget::symbolChanged()
201 mPolyline->setSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
202 mPolyline->layout()->undoStack()->endCommand();
205void QgsLayoutPolylineWidget::arrowStrokeWidthChanged(
double d )
211 mPolyline->setArrowHeadStrokeWidth( d );
212 mPolyline->endCommand();
215void QgsLayoutPolylineWidget::arrowHeadWidthChanged(
double d )
221 mPolyline->setArrowHeadWidth( d );
222 mPolyline->endCommand();
226void QgsLayoutPolylineWidget::arrowHeadFillColorChanged(
const QColor &newColor )
232 mPolyline->setArrowHeadFillColor( newColor );
233 mPolyline->endCommand();
237void QgsLayoutPolylineWidget::arrowHeadStrokeColorChanged(
const QColor &newColor )
243 mPolyline->setArrowHeadStrokeColor( newColor );
244 mPolyline->endCommand();
248void QgsLayoutPolylineWidget::startArrowHeadToggled(
bool toggled )
250 if ( !mPolyline || !toggled )
253 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
255 mPolyline->endCommand();
258void QgsLayoutPolylineWidget::endArrowHeadToggled(
bool toggled )
260 if ( !mPolyline || !toggled )
263 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
265 mPolyline->endCommand();
268void QgsLayoutPolylineWidget::startNoMarkerToggled(
bool toggled )
270 if ( !mPolyline || !toggled )
273 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
275 mPolyline->endCommand();
278void QgsLayoutPolylineWidget::endNoMarkerToggled(
bool toggled )
280 if ( !mPolyline || !toggled )
283 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
285 mPolyline->endCommand();
288void QgsLayoutPolylineWidget::startSvgMarkerToggled(
bool toggled )
290 enableStartSvgInputElements( toggled );
291 if ( !mPolyline || !toggled )
294 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
296 mPolyline->endCommand();
299void QgsLayoutPolylineWidget::endSvgMarkerToggled(
bool toggled )
301 enableEndSvgInputElements( toggled );
302 if ( !mPolyline || !toggled )
305 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
307 mPolyline->endCommand();
310void QgsLayoutPolylineWidget::enableStartSvgInputElements(
bool enable )
312 mStartMarkerLineEdit->setEnabled( enable );
313 mStartMarkerToolButton->setEnabled( enable );
316void QgsLayoutPolylineWidget::enableEndSvgInputElements(
bool enable )
318 mEndMarkerLineEdit->setEnabled( enable );
319 mEndMarkerToolButton->setEnabled( enable );
322void QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged(
const QString &text )
327 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
328 const QFileInfo fi( text );
329 if ( fi.exists() && fi.isFile() )
331 mPolyline->setStartSvgMarkerPath( text );
335 mPolyline->setStartSvgMarkerPath( QString() );
337 mPolyline->endCommand();
340void QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged(
const QString &text )
345 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
346 const QFileInfo fi( text );
347 if ( fi.exists() && fi.isFile() )
349 mPolyline->setEndSvgMarkerPath( text );
353 mPolyline->setEndSvgMarkerPath( QString() );
355 mPolyline->endCommand();
358void QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked()
363 if ( !mStartMarkerLineEdit->text().isEmpty() )
365 const QFileInfo fi( mStartMarkerLineEdit->text() );
366 openDir = fi.dir().absolutePath();
369 if ( openDir.isEmpty() )
371 openDir = s.
value( u
"/UI/lastComposerMarkerDir"_s, QDir::homePath() ).toString();
374 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"Start marker svg file" ), openDir );
375 if ( !svgFileName.isNull() )
377 const QFileInfo fileInfo( svgFileName );
378 s.
setValue( u
"/UI/lastComposerMarkerDir"_s, fileInfo.absolutePath() );
379 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
380 mStartMarkerLineEdit->setText( svgFileName );
381 mPolyline->endCommand();
385void QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked()
390 if ( !mEndMarkerLineEdit->text().isEmpty() )
392 const QFileInfo fi( mEndMarkerLineEdit->text() );
393 openDir = fi.dir().absolutePath();
396 if ( openDir.isEmpty() )
398 openDir = s.
value( u
"/UI/lastComposerMarkerDir"_s, QDir::homePath() ).toString();
401 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"End marker svg file" ), openDir );
402 if ( !svgFileName.isNull() )
404 const QFileInfo fileInfo( svgFileName );
405 s.
setValue( u
"/UI/lastComposerMarkerDir"_s, fileInfo.absolutePath() );
406 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
407 mEndMarkerLineEdit->setText( svgFileName );
408 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.