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 );