25#include <QButtonGroup>
30 , mPolyline( polyline )
35 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowStrokeWidthChanged );
36 connect( mArrowHeadWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowHeadWidthChanged );
39 connect( mRadioStartArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startArrowHeadToggled );
40 connect( mRadioStartNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startNoMarkerToggled );
41 connect( mRadioStartSVG, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startSvgMarkerToggled );
42 connect( mRadioEndArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endArrowHeadToggled );
43 connect( mRadioEndNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endNoMarkerToggled );
44 connect( mRadioEndSvg, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endSvgMarkerToggled );
45 connect( mStartMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged );
46 connect( mEndMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged );
47 connect( mStartMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked );
48 connect( mEndMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked );
50 QButtonGroup *startMarkerGroup =
new QButtonGroup(
this );
51 startMarkerGroup->addButton( mRadioStartNoMarker );
52 startMarkerGroup->addButton( mRadioStartArrow );
53 startMarkerGroup->addButton( mRadioStartSVG );
54 startMarkerGroup->setExclusive(
true );
55 QButtonGroup *endMarkerGroup =
new QButtonGroup(
this );
56 endMarkerGroup->addButton( mRadioEndNoMarker );
57 endMarkerGroup->addButton( mRadioEndArrow );
58 endMarkerGroup->addButton( mRadioEndSvg );
59 endMarkerGroup->setExclusive(
true );
62 enableStartSvgInputElements(
false );
63 enableEndSvgInputElements(
false );
65 mArrowHeadStrokeColorButton->setColorDialogTitle( tr(
"Select Arrow Head Stroke Color" ) );
66 mArrowHeadStrokeColorButton->setAllowOpacity(
true );
67 mArrowHeadStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
68 mArrowHeadStrokeColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
69 mArrowHeadStrokeColorButton->setShowNoColor(
true );
70 mArrowHeadFillColorButton->setColorDialogTitle( tr(
"Select Arrow Head Fill Color" ) );
71 mArrowHeadFillColorButton->setAllowOpacity(
true );
72 mArrowHeadFillColorButton->setContext( QStringLiteral(
"composer" ) );
73 mArrowHeadFillColorButton->setNoColorString( tr(
"Transparent Fill" ) );
74 mArrowHeadFillColorButton->setShowNoColor(
true );
81 mainLayout->addWidget( mItemPropertiesWidget );
89 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
91 setGuiElementValues();
93 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
95 if ( mPolyline->layout() )
103 if ( mItemPropertiesWidget )
117 mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item );
118 mItemPropertiesWidget->
setItem( mPolyline );
123 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
126 setGuiElementValues();
132void QgsLayoutPolylineWidget::setGuiElementValues()
137 whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
139 whileBlocking( mArrowHeadFillColorButton )->setColor( mPolyline->arrowHeadFillColor() );
140 whileBlocking( mArrowHeadStrokeColorButton )->setColor( mPolyline->arrowHeadStrokeColor() );
141 whileBlocking( mStrokeWidthSpinBox )->setValue( mPolyline->arrowHeadStrokeWidth() );
142 whileBlocking( mArrowHeadWidthSpinBox )->setValue( mPolyline->arrowHeadWidth() );
144 mRadioStartNoMarker->blockSignals(
true );
145 mRadioStartArrow->blockSignals(
true );
146 mRadioStartSVG->blockSignals(
true );
147 mRadioEndArrow->blockSignals(
true );
148 mRadioEndNoMarker->blockSignals(
true );
149 mRadioEndSvg->blockSignals(
true );
150 switch ( mPolyline->startMarker() )
153 mRadioStartNoMarker->setChecked(
true );
156 mRadioStartArrow->setChecked(
true );
159 mRadioStartSVG->setChecked(
true );
160 enableStartSvgInputElements(
true );
163 switch ( mPolyline->endMarker() )
166 mRadioEndNoMarker->setChecked(
true );
169 mRadioEndArrow->setChecked(
true );
172 mRadioEndSvg->setChecked(
true );
173 enableEndSvgInputElements(
true );
176 mRadioStartNoMarker->blockSignals(
false );
177 mRadioStartArrow->blockSignals(
false );
178 mRadioStartSVG->blockSignals(
false );
179 mRadioEndArrow->blockSignals(
false );
180 mRadioEndNoMarker->blockSignals(
false );
181 mRadioEndSvg->blockSignals(
false );
183 mStartMarkerLineEdit->setText( mPolyline->startSvgMarkerPath() );
184 mEndMarkerLineEdit->setText( mPolyline->endSvgMarkerPath() );
187void QgsLayoutPolylineWidget::symbolChanged()
193 mPolyline->setSymbol( mLineStyleButton->clonedSymbol<
QgsLineSymbol>() );
194 mPolyline->layout()->undoStack()->endCommand();
197void QgsLayoutPolylineWidget::arrowStrokeWidthChanged(
double d )
203 mPolyline->setArrowHeadStrokeWidth( d );
204 mPolyline->endCommand();
207void QgsLayoutPolylineWidget::arrowHeadWidthChanged(
double d )
213 mPolyline->setArrowHeadWidth( d );
214 mPolyline->endCommand();
218void QgsLayoutPolylineWidget::arrowHeadFillColorChanged(
const QColor &newColor )
224 mPolyline->setArrowHeadFillColor( newColor );
225 mPolyline->endCommand();
229void QgsLayoutPolylineWidget::arrowHeadStrokeColorChanged(
const QColor &newColor )
235 mPolyline->setArrowHeadStrokeColor( newColor );
236 mPolyline->endCommand();
240void QgsLayoutPolylineWidget::startArrowHeadToggled(
bool toggled )
242 if ( !mPolyline || !toggled )
245 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
247 mPolyline->endCommand();
250void QgsLayoutPolylineWidget::endArrowHeadToggled(
bool toggled )
252 if ( !mPolyline || !toggled )
255 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
257 mPolyline->endCommand();
260void QgsLayoutPolylineWidget::startNoMarkerToggled(
bool toggled )
262 if ( !mPolyline || !toggled )
265 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
267 mPolyline->endCommand();
270void QgsLayoutPolylineWidget::endNoMarkerToggled(
bool toggled )
272 if ( !mPolyline || !toggled )
275 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
277 mPolyline->endCommand();
280void QgsLayoutPolylineWidget::startSvgMarkerToggled(
bool toggled )
282 enableStartSvgInputElements( toggled );
283 if ( !mPolyline || !toggled )
286 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
288 mPolyline->endCommand();
291void QgsLayoutPolylineWidget::endSvgMarkerToggled(
bool toggled )
293 enableEndSvgInputElements( toggled );
294 if ( !mPolyline || !toggled )
297 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
299 mPolyline->endCommand();
302void QgsLayoutPolylineWidget::enableStartSvgInputElements(
bool enable )
304 mStartMarkerLineEdit->setEnabled( enable );
305 mStartMarkerToolButton->setEnabled( enable );
308void QgsLayoutPolylineWidget::enableEndSvgInputElements(
bool enable )
310 mEndMarkerLineEdit->setEnabled( enable );
311 mEndMarkerToolButton->setEnabled( enable );
314void QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged(
const QString &text )
319 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
320 const QFileInfo fi( text );
321 if ( fi.exists() && fi.isFile() )
323 mPolyline->setStartSvgMarkerPath( text );
327 mPolyline->setStartSvgMarkerPath( QString() );
329 mPolyline->endCommand();
332void QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged(
const QString &text )
337 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
338 const QFileInfo fi( text );
339 if ( fi.exists() && fi.isFile() )
341 mPolyline->setEndSvgMarkerPath( text );
345 mPolyline->setEndSvgMarkerPath( QString() );
347 mPolyline->endCommand();
350void QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked()
355 if ( !mStartMarkerLineEdit->text().isEmpty() )
357 const QFileInfo fi( mStartMarkerLineEdit->text() );
358 openDir = fi.dir().absolutePath();
361 if ( openDir.isEmpty() )
363 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
366 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"Start marker svg file" ), openDir );
367 if ( !svgFileName.isNull() )
369 const QFileInfo fileInfo( svgFileName );
370 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
371 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
372 mStartMarkerLineEdit->setText( svgFileName );
373 mPolyline->endCommand();
377void QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked()
382 if ( !mEndMarkerLineEdit->text().isEmpty() )
384 const QFileInfo fi( mEndMarkerLineEdit->text() );
385 openDir = fi.dir().absolutePath();
388 if ( openDir.isEmpty() )
390 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
393 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"End marker svg file" ), openDir );
394 if ( !svgFileName.isNull() )
396 const QFileInfo fileInfo( svgFileName );
397 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
398 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
399 mEndMarkerLineEdit->setText( svgFileName );
400 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.
A line symbol type, for rendering LineString and MultiLineString geometries.
Interface for master layout type objects, such as print layouts and reports.
This class is a composition of two QSettings instances:
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.