-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsdecorationscalebardialog.cpp
113 lines (96 loc) · 4.08 KB
/
qgsdecorationscalebardialog.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
/***************************************************************************
* Copyright (C) 2003 by Tim Sutton *
* *
* This is a plugin generated from the QGIS plugin template *
* *
* 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 "qgsdecorationscalebardialog.h"
#include "qgsdecorationscalebar.h"
#include "qgslogger.h"
#include "qgshelp.h"
#include "qgssettings.h"
#include <QColorDialog>
#include <QDialogButtonBox>
#include <QPushButton>
QgsDecorationScaleBarDialog::QgsDecorationScaleBarDialog( QgsDecorationScaleBar &deco, int units, QWidget *parent )
: QDialog( parent )
, mDeco( deco )
{
setupUi( this );
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/DecorationScaleBar/geometry" ) ).toByteArray() );
QPushButton *applyButton = buttonBox->button( QDialogButtonBox::Apply );
connect( applyButton, SIGNAL( clicked() ), this, SLOT( apply() ) );
// set the map units in the spin box
spnSize->setShowClearButton( false );
switch ( units )
{
case 0:
spnSize->setSuffix( tr( " meters/km" ) );
break;
case 1:
spnSize->setSuffix( tr( " feet/miles" ) );
break;
case 2:
spnSize->setSuffix( tr( " degrees" ) );
break;
default:
QgsDebugMsg( QString( "Error: not picked up map units - actual value = %1" ).arg( units ) );
}
spnSize->setValue( mDeco.mPreferredSize );
chkSnapping->setChecked( mDeco.mSnapping );
// placement
cboPlacement->addItem( tr( "Top left" ), QgsDecorationItem::TopLeft );
cboPlacement->addItem( tr( "Top right" ), QgsDecorationItem::TopRight );
cboPlacement->addItem( tr( "Bottom left" ), QgsDecorationItem::BottomLeft );
cboPlacement->addItem( tr( "Bottom right" ), QgsDecorationItem::BottomRight );
cboPlacement->setCurrentIndex( cboPlacement->findData( mDeco.placement() ) );
spnHorizontal->setValue( mDeco.mMarginHorizontal );
spnVertical->setValue( mDeco.mMarginVertical );
wgtUnitSelection->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPercentage << QgsUnitTypes::RenderPixels );
wgtUnitSelection->setUnit( mDeco.mMarginUnit );
grpEnable->setChecked( mDeco.enabled() );
// style
cboStyle->clear();
cboStyle->addItems( mDeco.mStyleLabels );
cboStyle->setCurrentIndex( mDeco.mStyleIndex );
pbnChangeColor->setColor( mDeco.mColor );
pbnChangeColor->setContext( QStringLiteral( "gui" ) );
pbnChangeColor->setColorDialogTitle( tr( "Select scalebar color" ) );
}
QgsDecorationScaleBarDialog::~QgsDecorationScaleBarDialog()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/DecorationScaleBar/geometry" ), saveGeometry() );
}
void QgsDecorationScaleBarDialog::on_buttonBox_helpRequested()
{
QgsHelp::openHelp( QStringLiteral( "introduction/general_tools.html#scale-bar" ) );
}
void QgsDecorationScaleBarDialog::apply()
{
mDeco.setPlacement( static_cast< QgsDecorationItem::Placement>( cboPlacement->currentData().toInt() ) );
mDeco.mMarginUnit = wgtUnitSelection->unit();
mDeco.mMarginHorizontal = spnHorizontal->value();
mDeco.mMarginVertical = spnVertical->value();
mDeco.mPreferredSize = spnSize->value();
mDeco.mSnapping = chkSnapping->isChecked();
mDeco.setEnabled( grpEnable->isChecked() );
mDeco.mStyleIndex = cboStyle->currentIndex();
mDeco.mColor = pbnChangeColor->color();
mDeco.update();
}
void QgsDecorationScaleBarDialog::on_buttonBox_accepted()
{
apply();
accept();
}
void QgsDecorationScaleBarDialog::on_buttonBox_rejected()
{
reject();
}