27 #include <QButtonGroup>
28 #include <QFileDialog>
32 , mPolyline( polyline )
37 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowStrokeWidthChanged );
38 connect( mArrowHeadWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPolylineWidget::arrowHeadWidthChanged );
41 connect( mRadioStartArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startArrowHeadToggled );
42 connect( mRadioStartNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startNoMarkerToggled );
43 connect( mRadioStartSVG, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::startSvgMarkerToggled );
44 connect( mRadioEndArrow, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endArrowHeadToggled );
45 connect( mRadioEndNoMarker, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endNoMarkerToggled );
46 connect( mRadioEndSvg, &QRadioButton::toggled,
this, &QgsLayoutPolylineWidget::endSvgMarkerToggled );
47 connect( mStartMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged );
48 connect( mEndMarkerLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged );
49 connect( mStartMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked );
50 connect( mEndMarkerToolButton, &QToolButton::clicked,
this, &QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked );
52 QButtonGroup *startMarkerGroup =
new QButtonGroup(
this );
53 startMarkerGroup->addButton( mRadioStartNoMarker );
54 startMarkerGroup->addButton( mRadioStartArrow );
55 startMarkerGroup->addButton( mRadioStartSVG );
56 startMarkerGroup->setExclusive(
true );
57 QButtonGroup *endMarkerGroup =
new QButtonGroup(
this );
58 endMarkerGroup->addButton( mRadioEndNoMarker );
59 endMarkerGroup->addButton( mRadioEndArrow );
60 endMarkerGroup->addButton( mRadioEndSvg );
61 endMarkerGroup->setExclusive(
true );
64 enableStartSvgInputElements(
false );
65 enableEndSvgInputElements(
false );
67 mArrowHeadStrokeColorButton->setColorDialogTitle( tr(
"Select Arrow Head Stroke Color" ) );
68 mArrowHeadStrokeColorButton->setAllowOpacity(
true );
69 mArrowHeadStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
70 mArrowHeadStrokeColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
71 mArrowHeadStrokeColorButton->setShowNoColor(
true );
72 mArrowHeadFillColorButton->setColorDialogTitle( tr(
"Select Arrow Head Fill Color" ) );
73 mArrowHeadFillColorButton->setAllowOpacity(
true );
74 mArrowHeadFillColorButton->setContext( QStringLiteral(
"composer" ) );
75 mArrowHeadFillColorButton->setNoColorString( tr(
"Transparent Fill" ) );
76 mArrowHeadFillColorButton->setShowNoColor(
true );
83 mainLayout->addWidget( mItemPropertiesWidget );
91 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
93 setGuiElementValues();
95 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
97 if ( mPolyline->layout() )
105 if ( mItemPropertiesWidget )
119 mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item );
120 mItemPropertiesWidget->
setItem( mPolyline );
125 mLineStyleButton->registerExpressionContextGenerator( mPolyline );
128 setGuiElementValues();
134 void QgsLayoutPolylineWidget::setGuiElementValues()
139 whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
141 whileBlocking( mArrowHeadFillColorButton )->setColor( mPolyline->arrowHeadFillColor() );
142 whileBlocking( mArrowHeadStrokeColorButton )->setColor( mPolyline->arrowHeadStrokeColor() );
143 whileBlocking( mStrokeWidthSpinBox )->setValue( mPolyline->arrowHeadStrokeWidth() );
144 whileBlocking( mArrowHeadWidthSpinBox )->setValue( mPolyline->arrowHeadWidth() );
146 mRadioStartNoMarker->blockSignals(
true );
147 mRadioStartArrow->blockSignals(
true );
148 mRadioStartSVG->blockSignals(
true );
149 mRadioEndArrow->blockSignals(
true );
150 mRadioEndNoMarker->blockSignals(
true );
151 mRadioEndSvg->blockSignals(
true );
152 switch ( mPolyline->startMarker() )
155 mRadioStartNoMarker->setChecked(
true );
158 mRadioStartArrow->setChecked(
true );
161 mRadioStartSVG->setChecked(
true );
162 enableStartSvgInputElements(
true );
165 switch ( mPolyline->endMarker() )
168 mRadioEndNoMarker->setChecked(
true );
171 mRadioEndArrow->setChecked(
true );
174 mRadioEndSvg->setChecked(
true );
175 enableEndSvgInputElements(
true );
178 mRadioStartNoMarker->blockSignals(
false );
179 mRadioStartArrow->blockSignals(
false );
180 mRadioStartSVG->blockSignals(
false );
181 mRadioEndArrow->blockSignals(
false );
182 mRadioEndNoMarker->blockSignals(
false );
183 mRadioEndSvg->blockSignals(
false );
185 mStartMarkerLineEdit->setText( mPolyline->startSvgMarkerPath() );
186 mEndMarkerLineEdit->setText( mPolyline->endSvgMarkerPath() );
189 void QgsLayoutPolylineWidget::symbolChanged()
195 mPolyline->setSymbol( mLineStyleButton->clonedSymbol<
QgsLineSymbol>() );
196 mPolyline->layout()->undoStack()->endCommand();
199 void QgsLayoutPolylineWidget::arrowStrokeWidthChanged(
double d )
205 mPolyline->setArrowHeadStrokeWidth( d );
206 mPolyline->endCommand();
209 void QgsLayoutPolylineWidget::arrowHeadWidthChanged(
double d )
215 mPolyline->setArrowHeadWidth( d );
216 mPolyline->endCommand();
220 void QgsLayoutPolylineWidget::arrowHeadFillColorChanged(
const QColor &newColor )
226 mPolyline->setArrowHeadFillColor( newColor );
227 mPolyline->endCommand();
231 void QgsLayoutPolylineWidget::arrowHeadStrokeColorChanged(
const QColor &newColor )
237 mPolyline->setArrowHeadStrokeColor( newColor );
238 mPolyline->endCommand();
242 void QgsLayoutPolylineWidget::startArrowHeadToggled(
bool toggled )
244 if ( !mPolyline || !toggled )
247 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
249 mPolyline->endCommand();
252 void QgsLayoutPolylineWidget::endArrowHeadToggled(
bool toggled )
254 if ( !mPolyline || !toggled )
257 mPolyline->beginCommand( tr(
"Set Arrow Marker" ) );
259 mPolyline->endCommand();
262 void QgsLayoutPolylineWidget::startNoMarkerToggled(
bool toggled )
264 if ( !mPolyline || !toggled )
267 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
269 mPolyline->endCommand();
272 void QgsLayoutPolylineWidget::endNoMarkerToggled(
bool toggled )
274 if ( !mPolyline || !toggled )
277 mPolyline->beginCommand( tr(
"Set Line Marker" ) );
279 mPolyline->endCommand();
282 void QgsLayoutPolylineWidget::startSvgMarkerToggled(
bool toggled )
284 enableStartSvgInputElements( toggled );
285 if ( !mPolyline || !toggled )
288 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
290 mPolyline->endCommand();
293 void QgsLayoutPolylineWidget::endSvgMarkerToggled(
bool toggled )
295 enableEndSvgInputElements( toggled );
296 if ( !mPolyline || !toggled )
299 mPolyline->beginCommand( tr(
"Set SVG Marker" ) );
301 mPolyline->endCommand();
304 void QgsLayoutPolylineWidget::enableStartSvgInputElements(
bool enable )
306 mStartMarkerLineEdit->setEnabled( enable );
307 mStartMarkerToolButton->setEnabled( enable );
310 void QgsLayoutPolylineWidget::enableEndSvgInputElements(
bool enable )
312 mEndMarkerLineEdit->setEnabled( enable );
313 mEndMarkerToolButton->setEnabled( enable );
316 void QgsLayoutPolylineWidget::mStartMarkerLineEdit_textChanged(
const QString &text )
321 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
322 const QFileInfo fi( text );
323 if ( fi.exists() && fi.isFile() )
325 mPolyline->setStartSvgMarkerPath( text );
329 mPolyline->setStartSvgMarkerPath( QString() );
331 mPolyline->endCommand();
334 void QgsLayoutPolylineWidget::mEndMarkerLineEdit_textChanged(
const QString &text )
339 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
340 const QFileInfo fi( text );
341 if ( fi.exists() && fi.isFile() )
343 mPolyline->setEndSvgMarkerPath( text );
347 mPolyline->setEndSvgMarkerPath( QString() );
349 mPolyline->endCommand();
352 void QgsLayoutPolylineWidget::mStartMarkerToolButton_clicked()
357 if ( !mStartMarkerLineEdit->text().isEmpty() )
359 const QFileInfo fi( mStartMarkerLineEdit->text() );
360 openDir = fi.dir().absolutePath();
363 if ( openDir.isEmpty() )
365 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
368 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"Start marker svg file" ), openDir );
369 if ( !svgFileName.isNull() )
371 const QFileInfo fileInfo( svgFileName );
372 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
373 mPolyline->beginCommand( tr(
"Change Start Marker File" ) );
374 mStartMarkerLineEdit->setText( svgFileName );
375 mPolyline->endCommand();
379 void QgsLayoutPolylineWidget::mEndMarkerToolButton_clicked()
384 if ( !mEndMarkerLineEdit->text().isEmpty() )
386 const QFileInfo fi( mEndMarkerLineEdit->text() );
387 openDir = fi.dir().absolutePath();
390 if ( openDir.isEmpty() )
392 openDir = s.
value( QStringLiteral(
"/UI/lastComposerMarkerDir" ), QDir::homePath() ).toString();
395 const QString svgFileName = QFileDialog::getOpenFileName(
this, tr(
"End marker svg file" ), openDir );
396 if ( !svgFileName.isNull() )
398 const QFileInfo fileInfo( svgFileName );
399 s.
setValue( QStringLiteral(
"/UI/lastComposerMarkerDir" ), fileInfo.absolutePath() );
400 mPolyline->beginCommand( tr(
"Change End Marker File" ) );
401 mEndMarkerLineEdit->setText( svgFileName );
402 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.