Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Zoom in/out and fit items to view actions for the modeler (#…
  • Loading branch information
nirvn committed Jan 3, 2017
1 parent b3fddc7 commit 56d5a37
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
45 changes: 43 additions & 2 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -32,8 +32,8 @@

from qgis.PyQt import uic
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.QtGui import QIcon, QImage, QPainter
from qgis.PyQt.QtWidgets import QGraphicsView, QTreeWidget, QMessageBox, QFileDialog, QTreeWidgetItem, QSizePolicy, QMainWindow, QShortcut
from qgis.PyQt.QtGui import QIcon, QImage, QPainter, QKeySequence
from qgis.PyQt.QtSvg import QSvgGenerator
from qgis.PyQt.QtPrintSupport import QPrinter
from qgis.core import QgsApplication
Expand Down Expand Up @@ -209,11 +209,19 @@ def _mimeDataAlgorithm(items):
self.searchBox.textChanged.connect(self.fillAlgorithmTree)
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)
self.mToolbar.setIconSize(QSize(iconSize, iconSize))
self.mActionOpen.triggered.connect(self.openModel)
self.mActionSave.triggered.connect(self.save)
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.mActionExportPdf.triggered.connect(self.exportAsPdf)
self.mActionExportSvg.triggered.connect(self.exportAsSvg)
Expand Down Expand Up @@ -290,6 +298,39 @@ def save(self):
def saveAs(self):
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):
self.repaintModel(controls=False)
filename, fileFilter = QFileDialog.getSaveFileName(self,
Expand Down
65 changes: 65 additions & 0 deletions python/plugins/processing/ui/DlgModeler.ui
Expand Up @@ -309,6 +309,11 @@
<addaction name="mActionSave"/>
<addaction name="mActionSaveAs"/>
<addaction name="separator"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActual"/>
<addaction name="mActionZoomToItems"/>
<addaction name="separator"/>
<addaction name="mActionExportImage"/>
<addaction name="mActionExportPdf"/>
<addaction name="mActionExportSvg"/>
Expand Down Expand Up @@ -363,6 +368,51 @@
<string>Ctrl+Shift+S</string>
</property>
</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 &amp;100%</string>
</property>
<property name="toolTip">
<string>Zoom to &amp;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">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand All @@ -375,6 +425,21 @@
<string>Export as image</string>
</property>
</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">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand Down

0 comments on commit 56d5a37

Please sign in to comment.