|
| 1 | +/*************************************************************************** |
| 2 | + qgslayoutpolylinewidget.cpp |
| 3 | + begin : March 2016 |
| 4 | + copyright : (C) 2016 Paul Blottiere, Oslandia |
| 5 | + email : paul dot blottiere at oslandia dot com |
| 6 | + ***************************************************************************/ |
| 7 | + |
| 8 | +/*************************************************************************** |
| 9 | + * * |
| 10 | + * This program is free software; you can redistribute it and/or modify * |
| 11 | + * it under the terms of the GNU General Public License as published by * |
| 12 | + * the Free Software Foundation; either version 2 of the License, or * |
| 13 | + * (at your option) any later version. * |
| 14 | + * * |
| 15 | + ***************************************************************************/ |
| 16 | + |
| 17 | +#include "qgslayoutpolylinewidget.h" |
| 18 | +#include "qgssymbolselectordialog.h" |
| 19 | +#include "qgsstyle.h" |
| 20 | +#include "qgssymbollayerutils.h" |
| 21 | +#include "qgslayoutitemregistry.h" |
| 22 | +#include "qgslayout.h" |
| 23 | + |
| 24 | +QgsLayoutPolylineWidget::QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polyline ) |
| 25 | + : QgsLayoutItemBaseWidget( nullptr, polyline ) |
| 26 | + , mPolyline( polyline ) |
| 27 | +{ |
| 28 | + setupUi( this ); |
| 29 | + setPanelTitle( tr( "Polyline properties" ) ); |
| 30 | + |
| 31 | + //add widget for general composer item properties |
| 32 | + mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polyline ); |
| 33 | + //shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget |
| 34 | + mItemPropertiesWidget->showBackgroundGroup( false ); |
| 35 | + mItemPropertiesWidget->showFrameGroup( false ); |
| 36 | + mainLayout->addWidget( mItemPropertiesWidget ); |
| 37 | + |
| 38 | + mLineStyleButton->setSymbolType( QgsSymbol::Line ); |
| 39 | + connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolylineWidget::symbolChanged ); |
| 40 | + |
| 41 | + if ( mPolyline ) |
| 42 | + { |
| 43 | + connect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues ); |
| 44 | + } |
| 45 | + setGuiElementValues(); |
| 46 | + |
| 47 | +#if 0 //TODO |
| 48 | + mShapeStyleButton->setLayer( atlasCoverageLayer() ); |
| 49 | +#endif |
| 50 | +} |
| 51 | + |
| 52 | +bool QgsLayoutPolylineWidget::setNewItem( QgsLayoutItem *item ) |
| 53 | +{ |
| 54 | + if ( item->type() != QgsLayoutItemRegistry::LayoutPolyline ) |
| 55 | + return false; |
| 56 | + |
| 57 | + mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item ); |
| 58 | + mItemPropertiesWidget->setItem( mPolyline ); |
| 59 | + |
| 60 | + setGuiElementValues(); |
| 61 | + |
| 62 | + return true; |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +void QgsLayoutPolylineWidget::setGuiElementValues() |
| 67 | +{ |
| 68 | + if ( !mPolyline ) |
| 69 | + return; |
| 70 | + |
| 71 | + whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() ); |
| 72 | +} |
| 73 | + |
| 74 | +void QgsLayoutPolylineWidget::symbolChanged() |
| 75 | +{ |
| 76 | + if ( !mPolyline ) |
| 77 | + return; |
| 78 | + |
| 79 | + mPolyline->layout()->undoStack()->beginCommand( mPolyline, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle ); |
| 80 | + mPolyline->setSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() ); |
| 81 | + mPolyline->layout()->undoStack()->endCommand(); |
| 82 | +} |
0 commit comments