18#include "moc_qgslayoutpolylinewidget.cpp"
26#include <QButtonGroup>
31 , mPolyline( polyline )
36 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowStrokeWidthChanged );
37 connect( mArrowHeadWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowHeadWidthChanged );
40 connect( mRadioStartArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startArrowHeadToggled );
41 connect( mRadioStartNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startNoMarkerToggled );
42 connect( mRadioStartSVG, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startSvgMarkerToggled );
43 connect( mRadioEndArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endArrowHeadToggled );
44 connect( mRadioEndNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endNoMarkerToggled );
45 connect( mRadioEndSvg, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endSvgMarkerToggled );
46 connect( mStartMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged );
47 connect( mEndMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged );
48 connect( mStartMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked );
49 connect( mEndMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked );
51 QButtonGroup *startMarkerGroup =
new QButtonGroup(
this );
52 startMarkerGroup->addButton( mRadioStartNoMarker );
53 startMarkerGroup->addButton( mRadioStartArrow );
54 startMarkerGroup->addButton( mRadioStartSVG );
55 startMarkerGroup->setExclusive(
true );
56 QButtonGroup *endMarkerGroup =
new QButtonGroup(
this );
57 endMarkerGroup->addButton( mRadioEndNoMarker );
58 endMarkerGroup->addButton( mRadioEndArrow );
59 endMarkerGroup->addButton( mRadioEndSvg );
60 endMarkerGroup->setExclusive(
true );
63 enableStartSvgInputElements(
false );
64 enableEndSvgInputElements(
false );
66 mArrowHeadStrokeColorButton->setColorDialogTitle( tr(
"Select Arrow Head Stroke Color" ) );
67 mArrowHeadStrokeColorButton->setAllowOpacity(
true );
68 mArrowHeadStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
69 mArrowHeadStrokeColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
70 mArrowHeadStrokeColorButton->setShowNoColor(
true );
71 mArrowHeadFillColorButton->setColorDialogTitle( tr(
"Select Arrow Head Fill Color" ) );
72 mArrowHeadFillColorButton->setAllowOpacity(
true );
73 mArrowHeadFillColorButton->setContext( QStringLiteral(
"composer" ) );
74 mArrowHeadFillColorButton->setNoColorString( tr(
"Transparent Fill" ) );
75 mArrowHeadFillColorButton->setShowNoColor(
true );
82 mainLayout->addWidget( mItemPropertiesWidget );
90 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
92 setGuiElementValues();
94 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
96 if ( mPolyline->layout() )
104 if ( mItemPropertiesWidget )
118 mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item );
119 mItemPropertiesWidget->
setItem( mPolyline );
124 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
127 setGuiElementValues();
133void QgsLayoutPolylineWidget::setGuiElementValues()
138 whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
140 whileBlocking( mArrowHeadFillColorButton )->setColor( mPolyline->arrowHeadFillColor() );
141 whileBlocking( mArrowHeadStrokeColorButton )->setColor( mPolyline->arrowHeadStrokeColor() );
142 whileBlocking( mStrokeWidthSpinBox )->setValue( mPolyline->arrowHeadStrokeWidth() );
143 whileBlocking( mArrowHeadWidthSpinBox )->setValue( mPolyline->arrowHeadWidth() );
145 mRadioStartNoMarker->blockSignals(
true );
146 mRadioStartArrow->blockSignals(
true );
147 mRadioStartSVG->blockSignals(
true );
148 mRadioEndArrow->blockSignals(
true );
149 mRadioEndNoMarker->blockSignals(
true );
150 mRadioEndSvg->blockSignals(
true );
151 switch ( mPolyline->startMarker() )
154 mRadioStartNoMarker->setChecked(
true );
157 mRadioStartArrow->setChecked(
true );
160 mRadioStartSVG->setChecked(
true );
161 enableStartSvgInputElements(
true );
164 switch ( mPolyline->endMarker() )
167 mRadioEndNoMarker->setChecked(
true );
170 mRadioEndArrow->setChecked(
true );
173 mRadioEndSvg->setChecked(
true );
174 enableEndSvgInputElements(
true );
177 mRadioStartNoMarker->blockSignals(
false );
178 mRadioStartArrow->blockSignals(
false );
179 mRadioStartSVG->blockSignals(
false );
180 mRadioEndArrow->blockSignals(
false );
181 mRadioEndNoMarker->blockSignals(
false );
182 mRadioEndSvg->blockSignals(
false );
184 mStartMarkerLineEdit->setText( mPolyline->startSvgMarkerPath() );
185 mEndMarkerLineEdit->setText( mPolyline->endSvgMarkerPath() );
188void QgsLayoutPolylineWidget::symbolChanged()
194 mPolyline->setSymbol( mLineStyleButton->clonedSymbol<
QgsLineSymbol>() );
195 mPolyline->layout()->undoStack()->endCommand();
198void QgsLayoutPolylineWidget::arrowStrokeWidthChanged(
double d )
204 mPolyline->setArrowHeadStrokeWidth( d );
205 mPolyline->endCommand();
208void QgsLayoutPolylineWidget::arrowHeadWidthChanged(
double d )
214 mPolyline->setArrowHeadWidth( d );
215 mPolyline->endCommand();
219void QgsLayoutPolylineWidget::arrowHeadFillColorChanged(
const QColor &newColor )
225 mPolyline->setArrowHeadFillColor( newColor );
226 mPolyline->endCommand();
230void QgsLayoutPolylineWidget::arrowHeadStrokeColorChanged(
const QColor &newColor )
236 mPolyline->setArrowHeadStrokeColor( newColor );
237 mPolyline->endCommand();
241void QgsLayoutPolylineWidget::startArrowHeadToggled(
bool toggled )
243 if ( !mPolyline || !toggled )
246 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
248 mPolyline->endCommand();
251void QgsLayoutPolylineWidget::endArrowHeadToggled(
bool toggled )
253 if ( !mPolyline || !toggled )
256 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
258 mPolyline->endCommand();
261void QgsLayoutPolylineWidget::startNoMarkerToggled(
bool toggled )
263 if ( !mPolyline || !toggled )
266 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
268 mPolyline->endCommand();
271void QgsLayoutPolylineWidget::endNoMarkerToggled(
bool toggled )
273 if ( !mPolyline || !toggled )
276 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
278 mPolyline->endCommand();
281void QgsLayoutPolylineWidget::startSvgMarkerToggled(
bool toggled )
283 enableStartSvgInputElements( toggled );
284 if ( !mPolyline || !toggled )
287 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
289 mPolyline->endCommand();
292void QgsLayoutPolylineWidget::endSvgMarkerToggled(
bool toggled )
294 enableEndSvgInputElements( toggled );
295 if ( !mPolyline || !toggled )
298 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
300 mPolyline->endCommand();
303void QgsLayoutPolylineWidget::enableStartSvgInputElements(
bool enable )
305 mStartMarkerLineEdit->setEnabled( enable );
306 mStartMarkerToolButton->setEnabled( enable );
309void QgsLayoutPolylineWidget::enableEndSvgInputElements(
bool enable )
311 mEndMarkerLineEdit->setEnabled( enable );
312 mEndMarkerToolButton->setEnabled( enable );
315void QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged(
const QString &text )
320 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
321 const QFileInfo fi( text );
322 if ( fi.exists() && fi.isFile() )
324 mPolyline->setStartSvgMarkerPath( text );
328 mPolyline->setStartSvgMarkerPath( QString() );
330 mPolyline->endCommand();
333void QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged(
const QString &text )
338 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
339 const QFileInfo fi( text );
340 if ( fi.exists() && fi.isFile() )
342 mPolyline->setEndSvgMarkerPath( text );
346 mPolyline->setEndSvgMarkerPath( QString() );
348 mPolyline->endCommand();
351void QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked()
356 if ( !mStartMarkerLineEdit->text().isEmpty() )
358 const QFileInfo fi( mStartMarkerLineEdit->text() );
359 openDir = fi.dir().absolutePath();
362 if ( openDir.isEmpty() )
364 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
367 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"Start marker svg file" ), openDir );
368 if ( !svgFileName.isNull() )
370 const QFileInfo fileInfo( svgFileName );
371 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
372 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
373 mStartMarkerLineEdit->setText( svgFileName );
374 mPolyline->endCommand();
378void QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked()
383 if ( !mEndMarkerLineEdit->text().isEmpty() )
385 const QFileInfo fi( mEndMarkerLineEdit->text() );
386 openDir = fi.dir().absolutePath();
389 if ( openDir.isEmpty() )
391 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
394 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"End marker svg file" ), openDir );
395 if ( !svgFileName.isNull() )
397 const QFileInfo fileInfo( svgFileName );
398 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
399 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
400 mEndMarkerLineEdit->setText( svgFileName );
401 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.