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();
 
   99void 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 );
 
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 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.