QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsscalemethodwidget.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsscalemethodwidget.cpp
3
------------------------
4
begin : March 2025
5
copyright : (C) 2025 by Nyall Dawson
6
email : nyall.dawson@gmail.com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsscalemethodwidget.h
"
19
20
#include "
qgsapplication.h
"
21
22
#include <QComboBox>
23
#include <QHBoxLayout>
24
#include <QLabel>
25
#include <QString>
26
27
#include "moc_qgsscalemethodwidget.cpp"
28
29
using namespace
Qt::StringLiterals;
30
31
QgsScaleMethodWidget::QgsScaleMethodWidget
( QWidget *parent )
32
: QWidget( parent )
33
{
34
mCombo =
new
QComboBox();
35
mCombo->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
36
37
mCombo->addItem( tr(
"Average Top, Middle and Bottom Scales"
), QVariant::fromValue(
Qgis::ScaleCalculationMethod::HorizontalAverage
) );
38
mCombo->addItem( tr(
"Calculate along Top of Map"
), QVariant::fromValue(
Qgis::ScaleCalculationMethod::HorizontalTop
) );
39
mCombo->addItem( tr(
"Calculate along Middle of Map"
), QVariant::fromValue(
Qgis::ScaleCalculationMethod::HorizontalMiddle
) );
40
mCombo->addItem( tr(
"Calculate along Bottom of Map"
), QVariant::fromValue(
Qgis::ScaleCalculationMethod::HorizontalBottom
) );
41
mCombo->addItem( tr(
"Always Calculate at Equator"
), QVariant::fromValue(
Qgis::ScaleCalculationMethod::AtEquator
) );
42
43
QHBoxLayout *hLayout =
new
QHBoxLayout();
44
hLayout->setContentsMargins( 0, 0, 0, 0 );
45
hLayout->addWidget( mCombo, 1 );
46
47
// bit of fiddlyness here -- we want the initial spacing to only be visible
48
// when the warning label is shown, so it's embedded inside mWarningLabel
49
// instead of outside it
50
mWarningLabelContainer =
new
QWidget();
51
QHBoxLayout *warningLayout =
new
QHBoxLayout();
52
warningLayout->setContentsMargins( 0, 0, 0, 0 );
53
mWarningLabel =
new
QLabel();
54
const
QIcon icon =
QgsApplication::getThemeIcon
( u
"mIconWarning.svg"
_s );
55
const
int
size =
static_cast<
int
>
( std::max( 24.0, mCombo->minimumSize().height() * 0.5 ) );
56
mWarningLabel->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
57
const
int
labelMargin =
static_cast<
int
>
( std::round( mCombo->fontMetrics().horizontalAdvance(
'X'
) ) );
58
warningLayout->insertSpacing( 0, labelMargin / 2 );
59
warningLayout->insertWidget( 1, mWarningLabel );
60
mWarningLabelContainer->setLayout( warningLayout );
61
hLayout->addWidget( mWarningLabelContainer );
62
mWarningLabelContainer->hide();
63
64
setLayout( hLayout );
65
66
setFocusPolicy( Qt::FocusPolicy::StrongFocus );
67
setFocusProxy( mCombo );
68
69
connect( mCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this
, &
QgsScaleMethodWidget::methodChanged
);
70
connect( mCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this
, &QgsScaleMethodWidget::updateWarning );
71
}
72
73
Qgis::ScaleCalculationMethod
QgsScaleMethodWidget::scaleMethod
()
const
74
{
75
return
mCombo->currentData().value<
Qgis::ScaleCalculationMethod
>();
76
}
77
78
void
QgsScaleMethodWidget::setScaleMethod
(
Qgis::ScaleCalculationMethod
method )
79
{
80
mCombo->setCurrentIndex( mCombo->findData( QVariant::fromValue( method ) ) );
81
updateWarning();
82
}
83
84
void
QgsScaleMethodWidget::updateWarning()
85
{
86
switch
(
scaleMethod
() )
87
{
88
case
Qgis::ScaleCalculationMethod::HorizontalTop
:
89
case
Qgis::ScaleCalculationMethod::HorizontalMiddle
:
90
case
Qgis::ScaleCalculationMethod::HorizontalBottom
:
91
case
Qgis::ScaleCalculationMethod::HorizontalAverage
:
92
mWarningLabelContainer->hide();
93
break
;
94
95
case
Qgis::ScaleCalculationMethod::AtEquator
:
96
{
97
mWarningLabelContainer->show();
98
const
QString warning = u
"<p>%1</p><p>%2</p>"
_s.arg(
99
tr(
100
"This method will calculate misleading scales when the map extent is not close to the "
101
"equator, however it ensures that the scale remains constant and does not "
102
"change as the map is panned."
103
),
104
tr(
"This setting is valid for maps in a geographic (latitude/longitude) CRS only."
)
105
);
106
mWarningLabel->setToolTip( warning );
107
108
break
;
109
}
110
}
111
}
Qgis::ScaleCalculationMethod
ScaleCalculationMethod
Scale calculation logic.
Definition
qgis.h:5865
Qgis::ScaleCalculationMethod::HorizontalTop
@ HorizontalTop
Calculate horizontally, across top of map.
Definition
qgis.h:5866
Qgis::ScaleCalculationMethod::HorizontalMiddle
@ HorizontalMiddle
Calculate horizontally, across midle of map.
Definition
qgis.h:5867
Qgis::ScaleCalculationMethod::AtEquator
@ AtEquator
Always calculate the scale at the equator, regardless of the actual visible map extent....
Definition
qgis.h:5870
Qgis::ScaleCalculationMethod::HorizontalAverage
@ HorizontalAverage
Calculate horizontally, using the average of the top, middle and bottom scales.
Definition
qgis.h:5869
Qgis::ScaleCalculationMethod::HorizontalBottom
@ HorizontalBottom
Calculate horizontally, across bottom of map.
Definition
qgis.h:5868
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition
qgsapplication.cpp:904
QgsScaleMethodWidget::QgsScaleMethodWidget
QgsScaleMethodWidget(QWidget *parent=nullptr)
Constructor for QgsScaleMethodWidget, with the specified parent widget.
Definition
qgsscalemethodwidget.cpp:31
QgsScaleMethodWidget::setScaleMethod
void setScaleMethod(Qgis::ScaleCalculationMethod method)
Sets the selected blend mode.
Definition
qgsscalemethodwidget.cpp:78
QgsScaleMethodWidget::methodChanged
void methodChanged()
Emitted when the selected method is changed.
QgsScaleMethodWidget::scaleMethod
Qgis::ScaleCalculationMethod scaleMethod
Definition
qgsscalemethodwidget.h:39
qgsapplication.h
qgsscalemethodwidget.h
Generated on
for QGIS API Documentation by
1.17.0