-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsannotationwidget.cpp
136 lines (115 loc) · 5.68 KB
/
qgsannotationwidget.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
/***************************************************************************
qgsannotationwidget.cpp
------------------------
begin : February 25, 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco dot hugentobler at hugis dot 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 "qgsannotationwidget.h"
#include "qgsmapcanvasannotationitem.h"
#include "qgsannotation.h"
#include "qgsstyle.h"
#include "qgssymbollayerutils.h"
#include "qgssymbol.h"
#include "qgssymbolselectordialog.h"
#include "qgisapp.h"
#include "qgsfillsymbol.h"
#include "qgsmarkersymbol.h"
#include "qgsdoublespinbox.h"
#include "qgssettingsentryimpl.h"
#include "qgssettingstree.h"
#include <QColorDialog>
const QgsSettingsEntryBool *QgsAnnotationWidget::settingLiveUpdate = new QgsSettingsEntryBool( QStringLiteral( "live-update" ), QgsSettingsTree::sTreeAnnotations, false, QObject::tr( "Whether the annotations are dynamically updated while they are edited" ) );
QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWidget *parent, Qt::WindowFlags f )
: QWidget( parent, f )
, mItem( item )
{
setupUi( this );
mLayerComboBox->setAllowEmptyLayer( true );
mMapMarkerButton->setSymbolType( Qgis::SymbolType::Marker );
mFrameStyleButton->setSymbolType( Qgis::SymbolType::Fill );
if ( mItem && mItem->annotation() )
{
QgsAnnotation *annotation = mItem->annotation();
blockAllSignals( true );
if ( annotation->hasFixedMapPosition() )
{
mMapPositionFixedCheckBox->setCheckState( Qt::Checked );
}
else
{
mMapPositionFixedCheckBox->setCheckState( Qt::Unchecked );
}
whileBlocking( mSpinTopMargin )->setValue( annotation->contentsMargin().top() );
whileBlocking( mSpinLeftMargin )->setValue( annotation->contentsMargin().left() );
whileBlocking( mSpinRightMargin )->setValue( annotation->contentsMargin().right() );
whileBlocking( mSpinBottomMargin )->setValue( annotation->contentsMargin().bottom() );
mLayerComboBox->setLayer( annotation->mapLayer() );
const QgsMarkerSymbol *symbol = annotation->markerSymbol();
if ( symbol )
{
mMapMarkerButton->setSymbol( symbol->clone() );
}
const QgsFillSymbol *fill = annotation->fillSymbol();
if ( fill )
{
mFrameStyleButton->setSymbol( fill->clone() );
}
blockAllSignals( false );
}
mMapMarkerButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mMapMarkerButton->setMessageBar( QgisApp::instance()->messageBar() );
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mFrameStyleButton->setMessageBar( QgisApp::instance()->messageBar() );
connect( mFrameStyleButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::frameStyleChanged );
// connect to the changed signal
connect( mFrameStyleButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::changed );
connect( mMapMarkerButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::changed );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsAnnotationWidget::changed );
connect( mSpinTopMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mSpinLeftMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mSpinRightMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mSpinBottomMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mMapPositionFixedCheckBox, &QCheckBox::stateChanged, this, &QgsAnnotationWidget::changed );
}
QColor QgsAnnotationWidget::backgroundColor()
{
return mFrameStyleButton->symbol() ? mFrameStyleButton->symbol()->color() : QColor();
}
void QgsAnnotationWidget::frameStyleChanged()
{
emit backgroundColorChanged( backgroundColor() );
}
void QgsAnnotationWidget::apply()
{
if ( mItem )
{
QgsAnnotation *annotation = mItem->annotation();
if ( annotation )
{
annotation->setHasFixedMapPosition( mMapPositionFixedCheckBox->checkState() == Qt::Checked );
annotation->setFillSymbol( mFrameStyleButton->clonedSymbol<QgsFillSymbol>() );
annotation->setMarkerSymbol( mMapMarkerButton->clonedSymbol<QgsMarkerSymbol>() );
annotation->setMapLayer( mLayerComboBox->currentLayer() );
annotation->setContentsMargin( QgsMargins( mSpinLeftMargin->value(),
mSpinTopMargin->value(),
mSpinRightMargin->value(),
mSpinBottomMargin->value() ) );
}
mItem->update();
}
}
void QgsAnnotationWidget::blockAllSignals( bool block )
{
mMapPositionFixedCheckBox->blockSignals( block );
mMapMarkerButton->blockSignals( block );
mLayerComboBox->blockSignals( block );
}