-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgscomposershapewidget.cpp
201 lines (166 loc) · 6.13 KB
/
qgscomposershapewidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/***************************************************************************
qgscomposershapewidget.cpp
--------------------------
begin : November 2009
copyright : (C) 2009 by Marco Hugentobler
email : marco@hugis.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgscomposershapewidget.h"
#include "qgscomposershape.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposition.h"
#include "qgsstyle.h"
#include "qgssymbolselectordialog.h"
#include "qgssymbollayerutils.h"
#include <QColorDialog>
QgsComposerShapeWidget::QgsComposerShapeWidget( QgsComposerShape* composerShape ): QgsComposerItemBaseWidget( nullptr, composerShape ), mComposerShape( composerShape )
{
setupUi( this );
setPanelTitle( tr( "Shape properties" ) );
//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, composerShape );
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
itemPropertiesWidget->showBackgroundGroup( false );
itemPropertiesWidget->showFrameGroup( false );
mainLayout->addWidget( itemPropertiesWidget );
blockAllSignals( true );
//shape types
mShapeComboBox->addItem( tr( "Ellipse" ) );
mShapeComboBox->addItem( tr( "Rectangle" ) );
mShapeComboBox->addItem( tr( "Triangle" ) );
setGuiElementValues();
blockAllSignals( false );
if ( mComposerShape )
{
connect( mComposerShape, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
}
}
QgsComposerShapeWidget::~QgsComposerShapeWidget()
{
}
void QgsComposerShapeWidget::blockAllSignals( bool block )
{
mShapeComboBox->blockSignals( block );
mCornerRadiusSpinBox->blockSignals( block );
mShapeStyleButton->blockSignals( block );
}
void QgsComposerShapeWidget::setGuiElementValues()
{
if ( !mComposerShape )
{
return;
}
blockAllSignals( true );
updateShapeStyle();
mCornerRadiusSpinBox->setValue( mComposerShape->cornerRadius() );
if ( mComposerShape->shapeType() == QgsComposerShape::Ellipse )
{
mShapeComboBox->setCurrentIndex( mShapeComboBox->findText( tr( "Ellipse" ) ) );
mCornerRadiusSpinBox->setEnabled( false );
}
else if ( mComposerShape->shapeType() == QgsComposerShape::Rectangle )
{
mShapeComboBox->setCurrentIndex( mShapeComboBox->findText( tr( "Rectangle" ) ) );
mCornerRadiusSpinBox->setEnabled( true );
}
else if ( mComposerShape->shapeType() == QgsComposerShape::Triangle )
{
mShapeComboBox->setCurrentIndex( mShapeComboBox->findText( tr( "Triangle" ) ) );
mCornerRadiusSpinBox->setEnabled( false );
}
blockAllSignals( false );
}
void QgsComposerShapeWidget::on_mShapeStyleButton_clicked()
{
if ( !mComposerShape )
{
return;
}
// use the atlas coverage layer, if any
QgsVectorLayer* coverageLayer = atlasCoverageLayer();
QgsFillSymbol* newSymbol = mComposerShape->shapeStyleSymbol()->clone();
QgsExpressionContext context = mComposerShape->createExpressionContext();
QgsSymbolSelectorWidget* d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
d->setContext( symbolContext );
connect( d, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolFromWidget() ) );
connect( d, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
openPanel( d );
mComposerShape->beginCommand( tr( "Shape style changed" ) );
}
void QgsComposerShapeWidget::updateShapeStyle()
{
if ( mComposerShape )
{
mComposerShape->refreshSymbol();
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mComposerShape->shapeStyleSymbol(), mShapeStyleButton->iconSize() );
mShapeStyleButton->setIcon( icon );
}
}
void QgsComposerShapeWidget::on_mCornerRadiusSpinBox_valueChanged( double val )
{
if ( mComposerShape )
{
mComposerShape->beginCommand( tr( "Shape radius changed" ), QgsComposerMergeCommand::ShapeCornerRadius );
mComposerShape->setCornerRadius( val );
mComposerShape->update();
mComposerShape->endCommand();
}
}
void QgsComposerShapeWidget::on_mShapeComboBox_currentIndexChanged( const QString& text )
{
if ( !mComposerShape )
{
return;
}
mComposerShape->beginCommand( tr( "Shape type changed" ) );
if ( text == tr( "Ellipse" ) )
{
mComposerShape->setShapeType( QgsComposerShape::Ellipse );
}
else if ( text == tr( "Rectangle" ) )
{
mComposerShape->setShapeType( QgsComposerShape::Rectangle );
}
else if ( text == tr( "Triangle" ) )
{
mComposerShape->setShapeType( QgsComposerShape::Triangle );
}
toggleRadiusSpin( text );
mComposerShape->update();
mComposerShape->endCommand();
}
void QgsComposerShapeWidget::toggleRadiusSpin( const QString& shapeText )
{
if ( shapeText == tr( "Rectangle" ) )
{
mCornerRadiusSpinBox->setEnabled( true );
}
else
{
mCornerRadiusSpinBox->setEnabled( false );
}
}
void QgsComposerShapeWidget::updateSymbolFromWidget()
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
mComposerShape->setShapeStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
}
void QgsComposerShapeWidget::cleanUpSymbolSelector( QgsPanelWidget* container )
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( container );
if ( !w )
return;
delete w->symbol();
updateShapeStyle();
mComposerShape->endCommand();
}