mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
[FEATURE] Zoom in/out and fit items to view actions for the modeler (#3939)
This commit is contained in:
parent
b3fddc79f6
commit
56d5a375a1
@ -32,8 +32,8 @@ import os
|
|||||||
|
|
||||||
from qgis.PyQt import uic
|
from qgis.PyQt import uic
|
||||||
from qgis.PyQt.QtCore import Qt, QRectF, QMimeData, QPoint, QPointF, QSettings, QByteArray, QSize, QSizeF, pyqtSignal
|
from qgis.PyQt.QtCore import Qt, QRectF, QMimeData, QPoint, QPointF, QSettings, QByteArray, QSize, QSizeF, pyqtSignal
|
||||||
from qgis.PyQt.QtWidgets import QGraphicsView, QTreeWidget, QMessageBox, QFileDialog, QTreeWidgetItem, QSizePolicy, QMainWindow
|
from qgis.PyQt.QtWidgets import QGraphicsView, QTreeWidget, QMessageBox, QFileDialog, QTreeWidgetItem, QSizePolicy, QMainWindow, QShortcut
|
||||||
from qgis.PyQt.QtGui import QIcon, QImage, QPainter
|
from qgis.PyQt.QtGui import QIcon, QImage, QPainter, QKeySequence
|
||||||
from qgis.PyQt.QtSvg import QSvgGenerator
|
from qgis.PyQt.QtSvg import QSvgGenerator
|
||||||
from qgis.PyQt.QtPrintSupport import QPrinter
|
from qgis.PyQt.QtPrintSupport import QPrinter
|
||||||
from qgis.core import QgsApplication
|
from qgis.core import QgsApplication
|
||||||
@ -209,11 +209,19 @@ class ModelerDialog(BASE, WIDGET):
|
|||||||
self.searchBox.textChanged.connect(self.fillAlgorithmTree)
|
self.searchBox.textChanged.connect(self.fillAlgorithmTree)
|
||||||
self.algorithmTree.doubleClicked.connect(self.addAlgorithm)
|
self.algorithmTree.doubleClicked.connect(self.addAlgorithm)
|
||||||
|
|
||||||
|
# Ctrl+= should also trigger a zoom in action
|
||||||
|
ctrlEquals = QShortcut(QKeySequence("Ctrl+="), self)
|
||||||
|
ctrlEquals.activated.connect(self.zoomIn)
|
||||||
|
|
||||||
iconSize = settings.value("iconsize", 24)
|
iconSize = settings.value("iconsize", 24)
|
||||||
self.mToolbar.setIconSize(QSize(iconSize, iconSize))
|
self.mToolbar.setIconSize(QSize(iconSize, iconSize))
|
||||||
self.mActionOpen.triggered.connect(self.openModel)
|
self.mActionOpen.triggered.connect(self.openModel)
|
||||||
self.mActionSave.triggered.connect(self.save)
|
self.mActionSave.triggered.connect(self.save)
|
||||||
self.mActionSaveAs.triggered.connect(self.saveAs)
|
self.mActionSaveAs.triggered.connect(self.saveAs)
|
||||||
|
self.mActionZoomIn.triggered.connect(self.zoomIn)
|
||||||
|
self.mActionZoomOut.triggered.connect(self.zoomOut)
|
||||||
|
self.mActionZoomActual.triggered.connect(self.zoomActual)
|
||||||
|
self.mActionZoomToItems.triggered.connect(self.zoomToItems)
|
||||||
self.mActionExportImage.triggered.connect(self.exportAsImage)
|
self.mActionExportImage.triggered.connect(self.exportAsImage)
|
||||||
self.mActionExportPdf.triggered.connect(self.exportAsPdf)
|
self.mActionExportPdf.triggered.connect(self.exportAsPdf)
|
||||||
self.mActionExportSvg.triggered.connect(self.exportAsSvg)
|
self.mActionExportSvg.triggered.connect(self.exportAsSvg)
|
||||||
@ -290,6 +298,39 @@ class ModelerDialog(BASE, WIDGET):
|
|||||||
def saveAs(self):
|
def saveAs(self):
|
||||||
self.saveModel(True)
|
self.saveModel(True)
|
||||||
|
|
||||||
|
def zoomIn(self):
|
||||||
|
self.view.setTransformationAnchor(QGraphicsView.NoAnchor)
|
||||||
|
point = self.view.mapToScene(QPoint(self.view.viewport().width() / 2, self.view.viewport().height() / 2))
|
||||||
|
|
||||||
|
settings = QSettings()
|
||||||
|
factor = settings.value('/qgis/zoom_favor', 2.0)
|
||||||
|
|
||||||
|
self.view.scale(factor, factor)
|
||||||
|
self.view.centerOn(point)
|
||||||
|
self.repaintModel()
|
||||||
|
|
||||||
|
def zoomOut(self):
|
||||||
|
self.view.setTransformationAnchor(QGraphicsView.NoAnchor)
|
||||||
|
point = self.view.mapToScene(QPoint(self.view.viewport().width() / 2, self.view.viewport().height() / 2))
|
||||||
|
|
||||||
|
settings = QSettings()
|
||||||
|
factor = settings.value('/qgis/zoom_favor', 2.0)
|
||||||
|
factor = 1 / factor
|
||||||
|
|
||||||
|
self.view.scale(factor, factor)
|
||||||
|
self.view.centerOn(point)
|
||||||
|
self.repaintModel()
|
||||||
|
|
||||||
|
def zoomActual(self):
|
||||||
|
point = self.view.mapToScene(QPoint(self.view.viewport().width() / 2, self.view.viewport().height() / 2))
|
||||||
|
self.view.resetTransform()
|
||||||
|
self.view.centerOn(point)
|
||||||
|
|
||||||
|
def zoomToItems(self):
|
||||||
|
totalRect = self.scene.itemsBoundingRect()
|
||||||
|
totalRect.adjust(-10, -10, 10, 10)
|
||||||
|
self.view.fitInView(totalRect, Qt.KeepAspectRatio)
|
||||||
|
|
||||||
def exportAsImage(self):
|
def exportAsImage(self):
|
||||||
self.repaintModel(controls=False)
|
self.repaintModel(controls=False)
|
||||||
filename, fileFilter = QFileDialog.getSaveFileName(self,
|
filename, fileFilter = QFileDialog.getSaveFileName(self,
|
||||||
|
@ -309,6 +309,11 @@
|
|||||||
<addaction name="mActionSave"/>
|
<addaction name="mActionSave"/>
|
||||||
<addaction name="mActionSaveAs"/>
|
<addaction name="mActionSaveAs"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="mActionZoomIn"/>
|
||||||
|
<addaction name="mActionZoomOut"/>
|
||||||
|
<addaction name="mActionZoomActual"/>
|
||||||
|
<addaction name="mActionZoomToItems"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="mActionExportImage"/>
|
<addaction name="mActionExportImage"/>
|
||||||
<addaction name="mActionExportPdf"/>
|
<addaction name="mActionExportPdf"/>
|
||||||
<addaction name="mActionExportSvg"/>
|
<addaction name="mActionExportSvg"/>
|
||||||
@ -363,6 +368,51 @@
|
|||||||
<string>Ctrl+Shift+S</string>
|
<string>Ctrl+Shift+S</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="mActionZoomActual">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../images/images.qrc">
|
||||||
|
<normaloff>:/images/themes/default/mActionZoomActual.svg</normaloff>:/images/themes/default/mActionZoomActual.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Zoom to &100%</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Zoom to &100%</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+1</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mActionZoomIn">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../images/images.qrc">
|
||||||
|
<normaloff>:/images/themes/default/mActionZoomIn.svg</normaloff>:/images/themes/default/mActionZoomIn.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Zoom in</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Zoom in</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl++</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mActionZoomOut">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../images/images.qrc">
|
||||||
|
<normaloff>:/images/themes/default/mActionZoomOut.svg</normaloff>:/images/themes/default/mActionZoomOut.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Zoom out</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Zoom out</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+-</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="mActionExportImage">
|
<action name="mActionExportImage">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../images/images.qrc">
|
<iconset resource="../../images/images.qrc">
|
||||||
@ -375,6 +425,21 @@
|
|||||||
<string>Export as image</string>
|
<string>Export as image</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="mActionZoomToItems">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../images/images.qrc">
|
||||||
|
<normaloff>:/images/themes/default/mActionZoomFullExtent.svg</normaloff>:/images/themes/default/mActionZoomFullExtent.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Zoom full</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Zoom full</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+0</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="mActionExportPdf">
|
<action name="mActionExportPdf">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../images/images.qrc">
|
<iconset resource="../../images/images.qrc">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user