QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
16 #include <QHBoxLayout>
31 QHBoxLayout *layout =
new QHBoxLayout(
this );
32 layout->setContentsMargins( 0, 0, 0, 0 );
33 layout->setSpacing( 6 );
36 layout->addWidget( mScaleComboBox );
38 mCurrentScaleButton =
new QToolButton(
this );
39 mCurrentScaleButton->setToolTip( tr(
"Set to current canvas scale" ) );
42 mMenu =
new QMenu(
this );
43 mCurrentScaleButton->setMenu( mMenu );
44 mCurrentScaleButton->setPopupMode( QToolButton::MenuButtonPopup );
45 connect( mMenu, &QMenu::aboutToShow,
this, &QgsScaleWidget::menuAboutToShow );
47 layout->addWidget( mCurrentScaleButton );
48 mCurrentScaleButton->hide();
57 mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
63 mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
68 return mScaleComboBox->
isNull();
99 void QgsScaleWidget::menuAboutToShow()
106 connect( canvasScaleAction, &QAction::triggered,
this, [
this,
scale] {
setScale(
scale ); } );
107 mMenu->addAction( canvasScaleAction );
112 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
115 QList< QgsLayoutItemMap * > maps;
116 layout->layoutItems( maps );
121 mMenu->addSeparator();
125 QMenu *layoutMenu =
new QMenu( layout->name(), mMenu );
128 scale = map->scale();
129 QAction *mapScaleAction =
new QAction( tr(
"%1 (1:%2)" ).arg( map->displayName(),
qgsDoubleToString(
scale, 0 ) ), mMenu );
130 connect( mapScaleAction, &QAction::triggered,
this, [
this,
scale] {
setScale(
scale ); } );
131 layoutMenu->addAction( mapScaleAction );
133 mMenu->addMenu( layoutMenu );
Manages storage of a set of layouts.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
Map canvas is a class for displaying all GIS data types on a canvas.
static QgsProject * instance()
Returns the QgsProject singleton instance.
double scale() const
Returns the last reported scale of the canvas.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
void setNull()
Sets the combo box to the null value.
bool allowNull() const
Returns true if the combobox can be set to a NULL value.
void setAllowNull(bool allowNull)
Sets whether the scale combobox can be set to a NULL value.
bool isNull() const
Returns true if the combo box is currently set to a "null" value.
Layout graphical items for displaying a map.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
void setScale(double scale)
Set the selected scale from a double.
void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.