26#include <QButtonGroup>
29#include "moc_qgslayoutpolylinewidget.cpp"
33 , mPolyline( polyline )
38 connect( mStrokeWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowStrokeWidthChanged );
39 connect( mArrowHeadWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowHeadWidthChanged );
42 connect( mRadioStartArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startArrowHeadToggled );
43 connect( mRadioStartNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startNoMarkerToggled );
44 connect( mRadioStartSVG, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startSvgMarkerToggled );
45 connect( mRadioEndArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endArrowHeadToggled );
46 connect( mRadioEndNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endNoMarkerToggled );
47 connect( mRadioEndSvg, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endSvgMarkerToggled );
48 connect( mStartMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged );
49 connect( mEndMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged );
50 connect( mStartMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked );
51 connect( mEndMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked );
53 QButtonGroup *startMarkerGroup =
new QButtonGroup(
this );
54 startMarkerGroup->addButton( mRadioStartNoMarker );
55 startMarkerGroup->addButton( mRadioStartArrow );
56 startMarkerGroup->addButton( mRadioStartSVG );
57 startMarkerGroup->setExclusive(
true );
58 QButtonGroup *endMarkerGroup =
new QButtonGroup(
this );
59 endMarkerGroup->addButton( mRadioEndNoMarker );
60 endMarkerGroup->addButton( mRadioEndArrow );
61 endMarkerGroup->addButton( mRadioEndSvg );
62 endMarkerGroup->setExclusive(
true );
65 enableStartSvgInputElements(
false );
66 enableEndSvgInputElements(
false );
68 mArrowHeadStrokeColorButton->setColorDialogTitle( tr(
"Select Arrow Head Stroke Color" ) );
69 mArrowHeadStrokeColorButton->setAllowOpacity(
true );
70 mArrowHeadStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
71 mArrowHeadStrokeColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
72 mArrowHeadStrokeColorButton->setShowNoColor(
true );
73 mArrowHeadFillColorButton->setColorDialogTitle( tr(
"Select Arrow Head Fill Color" ) );
74 mArrowHeadFillColorButton->setAllowOpacity(
true );
75 mArrowHeadFillColorButton->setContext( QStringLiteral(
"composer" ) );
76 mArrowHeadFillColorButton->setNoColorString( tr(
"Transparent Fill" ) );
77 mArrowHeadFillColorButton->setShowNoColor(
true );
82 mItemPropertiesWidget->showBackgroundGroup(
false );
83 mItemPropertiesWidget->showFrameGroup(
false );
84 mainLayout->addWidget( mItemPropertiesWidget );
92 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
94 setGuiElementValues();
96 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
98 if ( mPolyline->layout() )
106 if ( mItemPropertiesWidget )
107 mItemPropertiesWidget->setMasterLayout( masterLayout );
120 mPolyline = qobject_cast<QgsLayoutItemPolyline *>( item );
121 mItemPropertiesWidget->setItem( mPolyline );
126 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
129 setGuiElementValues();
135void QgsLayoutPolylineWidget::setGuiElementValues()
140 whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
142 whileBlocking( mArrowHeadFillColorButton )->setColor( mPolyline->arrowHeadFillColor() );
143 whileBlocking( mArrowHeadStrokeColorButton )->setColor( mPolyline->arrowHeadStrokeColor() );
144 whileBlocking( mStrokeWidthSpinBox )->setValue( mPolyline->arrowHeadStrokeWidth() );
145 whileBlocking( mArrowHeadWidthSpinBox )->setValue( mPolyline->arrowHeadWidth() );
147 mRadioStartNoMarker->blockSignals(
true );
148 mRadioStartArrow->blockSignals(
true );
149 mRadioStartSVG->blockSignals(
true );
150 mRadioEndArrow->blockSignals(
true );
151 mRadioEndNoMarker->blockSignals(
true );
152 mRadioEndSvg->blockSignals(
true );
153 switch ( mPolyline->startMarker() )
156 mRadioStartNoMarker->setChecked(
true );
159 mRadioStartArrow->setChecked(
true );
162 mRadioStartSVG->setChecked(
true );
163 enableStartSvgInputElements(
true );
166 switch ( mPolyline->endMarker() )
169 mRadioEndNoMarker->setChecked(
true );
172 mRadioEndArrow->setChecked(
true );
175 mRadioEndSvg->setChecked(
true );
176 enableEndSvgInputElements(
true );
179 mRadioStartNoMarker->blockSignals(
false );
180 mRadioStartArrow->blockSignals(
false );
181 mRadioStartSVG->blockSignals(
false );
182 mRadioEndArrow->blockSignals(
false );
183 mRadioEndNoMarker->blockSignals(
false );
184 mRadioEndSvg->blockSignals(
false );
186 mStartMarkerLineEdit->setText( mPolyline->startSvgMarkerPath() );
187 mEndMarkerLineEdit->setText( mPolyline->endSvgMarkerPath() );
190void QgsLayoutPolylineWidget::symbolChanged()
196 mPolyline->setSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
197 mPolyline->layout()->undoStack()->endCommand();
200void QgsLayoutPolylineWidget::arrowStrokeWidthChanged(
double d )
206 mPolyline->setArrowHeadStrokeWidth( d );
207 mPolyline->endCommand();
210void QgsLayoutPolylineWidget::arrowHeadWidthChanged(
double d )
216 mPolyline->setArrowHeadWidth( d );
217 mPolyline->endCommand();
221void QgsLayoutPolylineWidget::arrowHeadFillColorChanged(
const QColor &newColor )
227 mPolyline->setArrowHeadFillColor( newColor );
228 mPolyline->endCommand();
232void QgsLayoutPolylineWidget::arrowHeadStrokeColorChanged(
const QColor &newColor )
238 mPolyline->setArrowHeadStrokeColor( newColor );
239 mPolyline->endCommand();
243void QgsLayoutPolylineWidget::startArrowHeadToggled(
bool toggled )
245 if ( !mPolyline || !toggled )
248 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
250 mPolyline->endCommand();
253void QgsLayoutPolylineWidget::endArrowHeadToggled(
bool toggled )
255 if ( !mPolyline || !toggled )
258 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
260 mPolyline->endCommand();
263void QgsLayoutPolylineWidget::startNoMarkerToggled(
bool toggled )
265 if ( !mPolyline || !toggled )
268 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
270 mPolyline->endCommand();
273void QgsLayoutPolylineWidget::endNoMarkerToggled(
bool toggled )
275 if ( !mPolyline || !toggled )
278 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
280 mPolyline->endCommand();
283void QgsLayoutPolylineWidget::startSvgMarkerToggled(
bool toggled )
285 enableStartSvgInputElements( toggled );
286 if ( !mPolyline || !toggled )
289 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
291 mPolyline->endCommand();
294void QgsLayoutPolylineWidget::endSvgMarkerToggled(
bool toggled )
296 enableEndSvgInputElements( toggled );
297 if ( !mPolyline || !toggled )
300 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
302 mPolyline->endCommand();
305void QgsLayoutPolylineWidget::enableStartSvgInputElements(
bool enable )
307 mStartMarkerLineEdit->setEnabled( enable );
308 mStartMarkerToolButton->setEnabled( enable );
311void QgsLayoutPolylineWidget::enableEndSvgInputElements(
bool enable )
313 mEndMarkerLineEdit->setEnabled( enable );
314 mEndMarkerToolButton->setEnabled( enable );
317void QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged(
const QString &text )
322 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
323 const QFileInfo fi( text );
324 if ( fi.exists() && fi.isFile() )
326 mPolyline->setStartSvgMarkerPath( text );
330 mPolyline->setStartSvgMarkerPath( QString() );
332 mPolyline->endCommand();
335void QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged(
const QString &text )
340 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
341 const QFileInfo fi( text );
342 if ( fi.exists() && fi.isFile() )
344 mPolyline->setEndSvgMarkerPath( text );
348 mPolyline->setEndSvgMarkerPath( QString() );
350 mPolyline->endCommand();
353void QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked()
358 if ( !mStartMarkerLineEdit->text().isEmpty() )
360 const QFileInfo fi( mStartMarkerLineEdit->text() );
361 openDir = fi.dir().absolutePath();
364 if ( openDir.isEmpty() )
366 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
369 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"Start marker svg file" ), openDir );
370 if ( !svgFileName.isNull() )
372 const QFileInfo fileInfo( svgFileName );
373 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
374 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
375 mStartMarkerLineEdit->setText( svgFileName );
376 mPolyline->endCommand();
380void QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked()
385 if ( !mEndMarkerLineEdit->text().isEmpty() )
387 const QFileInfo fi( mEndMarkerLineEdit->text() );
388 openDir = fi.dir().absolutePath();
391 if ( openDir.isEmpty() )
393 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
396 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"End marker svg file" ), openDir );
397 if ( !svgFileName.isNull() )
399 const QFileInfo fileInfo( svgFileName );
400 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
401 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
402 mEndMarkerLineEdit->setText( svgFileName );
403 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.