mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
Add some shortcuts to zoom to layout/layout width in status bar combobox
This commit is contained in:
parent
e27a32d41c
commit
02d0a046f8
@ -55,11 +55,6 @@ class QgsLayoutDesignerInterface: QObject
|
|||||||
Closes the layout designer.
|
Closes the layout designer.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual void zoomFull() = 0;
|
|
||||||
%Docstring
|
|
||||||
Zooms to full extent of layout.
|
|
||||||
%End
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -86,6 +86,14 @@ class QgsLayoutView: QGraphicsView
|
|||||||
.. seealso:: zoomIn()
|
.. seealso:: zoomIn()
|
||||||
.. seealso:: zoomOut()
|
.. seealso:: zoomOut()
|
||||||
.. seealso:: zoomActual()
|
.. seealso:: zoomActual()
|
||||||
|
%End
|
||||||
|
|
||||||
|
void zoomWidth();
|
||||||
|
%Docstring
|
||||||
|
Zooms the view to the full width of the layout.
|
||||||
|
.. seealso:: zoomIn()
|
||||||
|
.. seealso:: zoomOut()
|
||||||
|
.. seealso:: zoomActual()
|
||||||
%End
|
%End
|
||||||
|
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
//add some nice zoom levels for zoom comboboxes
|
//add some nice zoom levels for zoom comboboxes
|
||||||
QList<double> QgsLayoutDesignerDialog::sStatusZoomLevelsList { 0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0};
|
QList<double> QgsLayoutDesignerDialog::sStatusZoomLevelsList { 0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0};
|
||||||
|
#define FIT_LAYOUT -101
|
||||||
|
#define FIT_LAYOUT_WIDTH -102
|
||||||
|
|
||||||
QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
|
QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
|
||||||
: QgsLayoutDesignerInterface( dialog )
|
: QgsLayoutDesignerInterface( dialog )
|
||||||
@ -56,11 +58,6 @@ void QgsAppLayoutDesignerInterface::close()
|
|||||||
mDesigner->close();
|
mDesigner->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsAppLayoutDesignerInterface::zoomFull()
|
|
||||||
{
|
|
||||||
mDesigner->zoomFull();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFlags flags )
|
QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFlags flags )
|
||||||
: QMainWindow( parent, flags )
|
: QMainWindow( parent, flags )
|
||||||
@ -145,9 +142,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
|
|||||||
|
|
||||||
Q_FOREACH ( double level, sStatusZoomLevelsList )
|
Q_FOREACH ( double level, sStatusZoomLevelsList )
|
||||||
{
|
{
|
||||||
mStatusZoomCombo->insertItem( 0, tr( "%1%" ).arg( level * 100.0, 0, 'f', 1 ) );
|
mStatusZoomCombo->insertItem( 0, tr( "%1%" ).arg( level * 100.0, 0, 'f', 1 ), level );
|
||||||
}
|
}
|
||||||
connect( mStatusZoomCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutDesignerDialog::statusZoomCombo_currentIndexChanged );
|
mStatusZoomCombo->insertItem( 0, tr( "Fit Layout" ), FIT_LAYOUT );
|
||||||
|
mStatusZoomCombo->insertItem( 0, tr( "Fit Layout Width" ), FIT_LAYOUT_WIDTH );
|
||||||
|
connect( mStatusZoomCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsLayoutDesignerDialog::statusZoomCombo_currentIndexChanged );
|
||||||
connect( mStatusZoomCombo->lineEdit(), &QLineEdit::returnPressed, this, &QgsLayoutDesignerDialog::statusZoomCombo_zoomEntered );
|
connect( mStatusZoomCombo->lineEdit(), &QLineEdit::returnPressed, this, &QgsLayoutDesignerDialog::statusZoomCombo_zoomEntered );
|
||||||
|
|
||||||
mStatusBar->addPermanentWidget( mStatusZoomCombo );
|
mStatusBar->addPermanentWidget( mStatusZoomCombo );
|
||||||
@ -192,7 +191,7 @@ void QgsLayoutDesignerDialog::open()
|
|||||||
{
|
{
|
||||||
show();
|
show();
|
||||||
activate();
|
activate();
|
||||||
zoomFull(); // zoomFull() does not work properly until we have called show()
|
mView->zoomFull(); // zoomFull() does not work properly until we have called show()
|
||||||
|
|
||||||
#if 0 // TODO
|
#if 0 // TODO
|
||||||
|
|
||||||
@ -219,14 +218,6 @@ void QgsLayoutDesignerDialog::activate()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayoutDesignerDialog::zoomFull()
|
|
||||||
{
|
|
||||||
if ( mView )
|
|
||||||
{
|
|
||||||
mView->fitInView( mLayout->sceneRect(), Qt::KeepAspectRatio );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
|
void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
|
||||||
{
|
{
|
||||||
emit aboutToClose();
|
emit aboutToClose();
|
||||||
@ -253,12 +244,24 @@ void QgsLayoutDesignerDialog::itemTypeAdded( int type )
|
|||||||
|
|
||||||
void QgsLayoutDesignerDialog::statusZoomCombo_currentIndexChanged( int index )
|
void QgsLayoutDesignerDialog::statusZoomCombo_currentIndexChanged( int index )
|
||||||
{
|
{
|
||||||
double selectedZoom = sStatusZoomLevelsList.at( sStatusZoomLevelsList.count() - index - 1 );
|
QVariant data = mStatusZoomCombo->itemData( index );
|
||||||
if ( mView )
|
if ( data.toInt() == FIT_LAYOUT )
|
||||||
{
|
{
|
||||||
mView->setZoomLevel( selectedZoom );
|
mView->zoomFull();
|
||||||
//update zoom combobox text for correct format (one decimal place, trailing % sign)
|
}
|
||||||
whileBlocking( mStatusZoomCombo )->lineEdit()->setText( tr( "%1%" ).arg( selectedZoom * 100.0, 0, 'f', 1 ) );
|
else if ( data.toInt() == FIT_LAYOUT_WIDTH )
|
||||||
|
{
|
||||||
|
mView->zoomWidth();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double selectedZoom = data.toDouble();
|
||||||
|
if ( mView )
|
||||||
|
{
|
||||||
|
mView->setZoomLevel( selectedZoom );
|
||||||
|
//update zoom combobox text for correct format (one decimal place, trailing % sign)
|
||||||
|
whileBlocking( mStatusZoomCombo )->lineEdit()->setText( tr( "%1%" ).arg( selectedZoom * 100.0, 0, 'f', 1 ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void close() override;
|
void close() override;
|
||||||
void zoomFull() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -99,11 +98,6 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
|
|||||||
*/
|
*/
|
||||||
void activate();
|
void activate();
|
||||||
|
|
||||||
/**
|
|
||||||
* Zooms to show full layout.
|
|
||||||
*/
|
|
||||||
void zoomFull();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,11 +68,6 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject
|
|||||||
*/
|
*/
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Zooms to full extent of layout.
|
|
||||||
*/
|
|
||||||
virtual void zoomFull() = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSLAYOUTDESIGNERINTERFACE_H
|
#endif // QGSLAYOUTDESIGNERINTERFACE_H
|
||||||
|
@ -95,6 +95,7 @@ void QgsLayoutView::scaleSafe( double scale )
|
|||||||
scale *= currentScale;
|
scale *= currentScale;
|
||||||
scale = qBound( MIN_VIEW_SCALE, scale, MAX_VIEW_SCALE );
|
scale = qBound( MIN_VIEW_SCALE, scale, MAX_VIEW_SCALE );
|
||||||
setTransform( QTransform::fromScale( scale, scale ) );
|
setTransform( QTransform::fromScale( scale, scale ) );
|
||||||
|
emit zoomLevelChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayoutView::setZoomLevel( double level )
|
void QgsLayoutView::setZoomLevel( double level )
|
||||||
@ -113,6 +114,28 @@ void QgsLayoutView::setZoomLevel( double level )
|
|||||||
void QgsLayoutView::zoomFull()
|
void QgsLayoutView::zoomFull()
|
||||||
{
|
{
|
||||||
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
|
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
|
||||||
|
emit zoomLevelChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsLayoutView::zoomWidth()
|
||||||
|
{
|
||||||
|
//get current visible part of scene
|
||||||
|
QRect viewportRect( 0, 0, viewport()->width(), viewport()->height() );
|
||||||
|
QRectF visibleRect = mapToScene( viewportRect ).boundingRect();
|
||||||
|
|
||||||
|
double verticalCenter = ( visibleRect.top() + visibleRect.bottom() ) / 2.0;
|
||||||
|
// expand out visible rect to include left/right edges of scene
|
||||||
|
// centered on current visible vertical center
|
||||||
|
// note that we can't have a 0 height rect - fitInView doesn't handle that
|
||||||
|
// so we just set a very small height instead.
|
||||||
|
const double tinyHeight = 0.01;
|
||||||
|
QRectF targetRect( scene()->sceneRect().left(),
|
||||||
|
verticalCenter - tinyHeight,
|
||||||
|
scene()->sceneRect().width(),
|
||||||
|
tinyHeight * 2 );
|
||||||
|
|
||||||
|
fitInView( targetRect, Qt::KeepAspectRatio );
|
||||||
|
emit zoomLevelChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayoutView::zoomIn()
|
void QgsLayoutView::zoomIn()
|
||||||
|
@ -109,6 +109,14 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
|
|||||||
*/
|
*/
|
||||||
void zoomFull();
|
void zoomFull();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zooms the view to the full width of the layout.
|
||||||
|
* \see zoomIn()
|
||||||
|
* \see zoomOut()
|
||||||
|
* \see zoomActual()
|
||||||
|
*/
|
||||||
|
void zoomWidth();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zooms in to the view by a preset amount.
|
* Zooms in to the view by a preset amount.
|
||||||
* \see zoomFull()
|
* \see zoomFull()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user