20#include "moc_qgsscalewidget.cpp"
32 QHBoxLayout *layout =
new QHBoxLayout(
this );
33 layout->setContentsMargins( 0, 0, 0, 0 );
34 layout->setSpacing( 6 );
37 layout->addWidget( mScaleComboBox );
39 mCurrentScaleButton =
new QToolButton(
this );
40 mCurrentScaleButton->setToolTip( tr(
"Set to current canvas scale" ) );
43 mMenu =
new QMenu(
this );
44 mCurrentScaleButton->setMenu( mMenu );
45 mCurrentScaleButton->setPopupMode( QToolButton::MenuButtonPopup );
46 connect( mMenu, &QMenu::aboutToShow,
this, &QgsScaleWidget::menuAboutToShow );
48 layout->addWidget( mCurrentScaleButton );
49 mCurrentScaleButton->hide();
58 mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
64 mCurrentScaleButton->setVisible( mShowCurrentScaleButton && mCanvas );
69 return mScaleComboBox->
isNull();
105void QgsScaleWidget::menuAboutToShow()
111 connect( canvasScaleAction, &QAction::triggered,
this, [
this,
scale] {
setScale(
scale ); } );
112 mMenu->addAction( canvasScaleAction );
117 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
120 QList<QgsLayoutItemMap *> maps;
121 layout->layoutItems( maps );
126 mMenu->addSeparator();
130 QMenu *layoutMenu =
new QMenu( layout->name(), mMenu );
133 scale = map->scale();
134 QAction *mapScaleAction =
new QAction( tr(
"%1 (1:%2)" ).arg( map->displayName(),
qgsDoubleToString(
scale, 0 ) ), mMenu );
135 connect( mapScaleAction, &QAction::triggered,
this, [
this,
scale] {
setScale(
scale ); } );
136 layoutMenu->addAction( mapScaleAction );
138 mMenu->addMenu( layoutMenu );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Layout graphical items for displaying a map.
Manages storage of a set of layouts.
Map canvas is a class for displaying all GIS data types on a canvas.
double scale() const
Returns the last reported scale of the canvas.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
void setPredefinedScales(const QVector< double > &scales)
Sets the list of predefined scales to show in the combobox.
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.
bool allowNull() const
Returns true if the combobox can be set to a NULL value.
void setScale(double scale)
Set the selected scale from a double.
void setNull()
Sets the combo box to the null value.
void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.