def testScaleSafe(self): """ test scaleSafe method """ view = QgsComposerView() view.fitInView(QRectF(0, 0, 10, 10)) scale = view.transform().m11() view.scaleSafe(2) self.assertAlmostEqual(view.transform().m11(), 2) view.scaleSafe(4) self.assertAlmostEqual(view.transform().m11(), 8) # try to zoom in heaps view.scaleSafe(99999999) # assume we have hit the limit scale = view.transform().m11() view.scaleSafe(2) self.assertAlmostEqual(view.transform().m11(), scale) view.setTransform(QTransform.fromScale(1, 1)) self.assertAlmostEqual(view.transform().m11(), 1) # test zooming out view.scaleSafe(0.5) self.assertAlmostEqual(view.transform().m11(), 0.5) view.scaleSafe(0.1) self.assertAlmostEqual(view.transform().m11(), 0.05) # try zooming out heaps view.scaleSafe(0.000000001) # assume we have hit the limit scale = view.transform().m11() view.scaleSafe(0.5) self.assertAlmostEqual(view.transform().m11(), scale)
def showComposer(self): """Show the composition in a composer view so the user can tweak it if they want to. Args: None Returns: None Raises: None """ myView = QgsComposerView(self.iface.mainWindow()) myView.show()
def __init__(self, parent, comp, basePMCheck, model): ''' Constructor ''' QMainWindow.__init__(self, parent) self.basePMCheck = basePMCheck # self.ui = Ui_Previewself.grbPageProperty() # self.ui.setupUi(self) self.resize(1000, 700) self.setWindowTitle("Preview Dialog") self.view = QgsComposerView(self) viewLayout = QGridLayout() viewLayout.setSpacing(0) viewLayout.setMargin(0) mHorizontalRuler = QgsComposerRuler(QgsComposerRuler.Horizontal) mVerticalRuler = QgsComposerRuler(QgsComposerRuler.Vertical) mRulerLayoutFix = QWidget() mRulerLayoutFix.setAttribute(Qt.WA_NoMousePropagation) mRulerLayoutFix.setBackgroundRole(QPalette.Window) mRulerLayoutFix.setFixedSize(mVerticalRuler.rulerSize(), mHorizontalRuler.rulerSize()) viewLayout.addWidget(mRulerLayoutFix, 0, 0) viewLayout.addWidget(mHorizontalRuler, 0, 1) viewLayout.addWidget(mVerticalRuler, 1, 0) self.view.setContentsMargins(0, 0, 0, 0) self.view.setHorizontalRuler(mHorizontalRuler) self.view.setVerticalRuler(mVerticalRuler) viewLayout.addWidget(self.view, 1, 1) # self.scene = comp self.view.setZoomLevel(1.0) self.view.setComposition(comp) self.scene = self.view.composition() layout = QVBoxLayout() hLayout = QHBoxLayout() hLayout.addLayout(viewLayout) self.mapItem = self.scene.getComposerMapById(0) self.view.scale(2.8, 2.8) self.view.setPreviewModeEnabled(True) self.toolBarAction = self.addToolBar("composer action") self.actionMapRefresh = QAction(self) self.actionMapRefresh.setObjectName("actionMapRefresh") icon3 = QIcon("Resource/Refresh.png") self.actionMapRefresh.setIcon(icon3) self.actionMapRefresh.setToolTip("Refresh") # self.textItemAction.setCheckable(True) self.connect(self.actionMapRefresh, SIGNAL("triggered()"), self.actionMapRefresh_triggered) self.toolBarAction.addAction(self.actionMapRefresh) # # self.templeteCreateAction = QAction(self) # # self.templeteCreateAction.setObjectName("createTempleteAction") # # icon4 = QIcon("Resource\\templetepointer.png") # # self.templeteCreateAction.setIcon(icon4) # # self.templeteCreateAction.setToolTip("Create Templete") # # self.templeteCreateAction.setCheckable(True) # # self.connect(self.templeteCreateAction, SIGNAL("triggered()"), self.createTempleteAction) # # self.toolBar.addAction(self.templeteCreateAction) # layout.insertWidget(0, self.toolBar) # self.scene.selectedItemChanged.connect(self.selectedItemDisplay) self.view.selectedItemChanged.connect(self.selectedItemDisplay) self.view.cursorPosChanged.connect(self.cursorPosChangedEvent) # self.connect(self.view, SIGNAL("selectedItemChanged(QgsComposerItem)"),self, SLOT("selectedItemDisplay(QgsComposerItem)")) # self.scene.composerLabelAdded.connect(self.composerLabelAddedEvent) self.view.itemRemoved.connect(self.deleteItem) # self.connect( self.view, SIGNAL( "actionFinished()" ), self.setSelectionTool) #listen out for position updates from the QgsComposerView self.propertyWidget = QWidget(self) hLayout.addWidget(self.propertyWidget) self.propertyWidget.setObjectName("propertyWidget") self.propertyWidget.resize(222, 302) self.vLayout_3 = QVBoxLayout(self.propertyWidget) self.vLayout_3.setObjectName("vLayout_3") self.groupBox = QGroupBox(self.propertyWidget) self.groupBox.setObjectName("groupBox") self.horizontalLayout_2 = QHBoxLayout(self.groupBox) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.frame = QFrame(self.groupBox) self.frame.setFrameShape(QFrame.StyledPanel) self.frame.setFrameShadow(QFrame.Raised) self.frame.setObjectName("frame") self.verticalLayout = QVBoxLayout(self.frame) self.verticalLayout.setObjectName("verticalLayout") self.label = QLabel(self.frame) self.label.setObjectName("label") self.verticalLayout.addWidget(self.label) self.labelText = QPlainTextEdit(self.frame) self.labelText.setObjectName("labelText") self.verticalLayout.addWidget(self.labelText) self.btnLabelFont = QPushButton(self.frame) self.btnLabelFont.setObjectName("btnLabelFont") self.verticalLayout.addWidget(self.btnLabelFont) self.btnLabelColor = QPushButton(self.frame) self.btnLabelColor.setObjectName("btnLabelColor") self.verticalLayout.addWidget(self.btnLabelColor) self.frame_2 = QFrame(self.frame) self.frame_2.setFrameShape(QFrame.StyledPanel) self.frame_2.setFrameShadow(QFrame.Raised) self.frame_2.setObjectName("frame_2") self.horizontalLayout = QHBoxLayout(self.frame_2) self.horizontalLayout.setObjectName("horizontalLayout") self.label_2 = QLabel(self.frame_2) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.spinLabelRotation = QSpinBox(self.frame_2) self.spinLabelRotation.setObjectName("spinLabelRotation") self.spinLabelRotation.setMinimum(-360) self.spinLabelRotation.setMaximum(360) self.horizontalLayout.addWidget(self.spinLabelRotation) self.verticalLayout.addWidget(self.frame_2) self.chbBackgroundEnable = QCheckBox(self.frame) self.chbBackgroundEnable.setChecked(True) self.chbBackgroundEnable.setObjectName("chbBackgroundEnable") self.verticalLayout.addWidget(self.chbBackgroundEnable) self.horizontalLayout_2.addWidget(self.frame) self.vLayout_3.addWidget(self.groupBox) self.resolutionFrame = QFrame(self.frame) self.resolutionFrame.setFrameShape(QFrame.StyledPanel) self.resolutionFrame.setFrameShadow(QFrame.Raised) self.resolutionFrame.setObjectName("resolutionFrame") self.horizontalLayout4 = QHBoxLayout(self.resolutionFrame) self.horizontalLayout4.setObjectName("horizontalLayout4") self.label_resolution = QLabel(self.resolutionFrame) self.label_resolution.setObjectName("label_resolution") self.label_resolution.setText("Print Resolution (dpi):") self.horizontalLayout4.addWidget(self.label_resolution) self.spinResolution = QSpinBox(self.resolutionFrame) self.spinResolution.setObjectName("spinResolution") self.spinResolution.setMinimum(0) self.spinResolution.setMaximum(1000) self.spinResolution.setValue(300) self.horizontalLayout4.addWidget(self.spinResolution) # self.verticalLayout.addWidget(self.frame_2) self.vLayout_3.addWidget(self.resolutionFrame) self.gbTable = GroupBox(self.propertyWidget) self.gbTable.Caption = "Table" self.vLayout_3.addWidget(self.gbTable) self.mTableView = QTableView(self.gbTable) self.gbTable.Add = self.mTableView hHeder = self.mTableView.horizontalHeader() hHeder.setVisible(False) vHeder = self.mTableView.verticalHeader() vHeder.setVisible(False) # self.mTableView.setFixedHeight(70) # self.mTableView.setFixedWidth(comp.paperWidth() - 40) # self.stdItemModel = QStandardItemModel() # self. self.spaceItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.vLayout_3.addItem(self.spaceItem) self.groupBox.setTitle("Label Property") self.label.setText("Label Text:") self.btnLabelFont.setText("Label Font") self.btnLabelColor.setText("Label Color") self.label_2.setText("Label Rotation:") self.chbBackgroundEnable.setText("Background Enable") self.groupBox.setEnabled(False) self.connect(self.btnLabelFont, SIGNAL("clicked()"), self.btnLabelFontClick) self.connect(self.btnLabelColor, SIGNAL("clicked()"), self.btnLabelColorClick) self.connect(self.chbBackgroundEnable, SIGNAL("clicked()"), self.chbBackgroundEnableClick) self.labelText.textChanged.connect(self.labelTextChanged) self.spinLabelRotation.valueChanged.connect( self.spinLabelRotationValueChanged) layout.addLayout(hLayout) # self.btnBack = QPushButton() self.btnBack.setText("back") footerLayout = QHBoxLayout() footerLayout.addWidget(self.btnBack) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") footerLayout.addWidget(self.buttonBox) layout.addLayout(footerLayout) self.setLayout(layout) deleteItemKey = QShortcut(QKeySequence(Qt.Key_Delete), self) deleteItemKey.activated.connect(self.deleteItem) # self.btnBack.clicked.connect(self.back) self.connect(self.buttonBox, SIGNAL("accepted()"), self.acceptMethod) self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject) self.btnCancel = self.buttonBox.button(QDialogButtonBox.Cancel) self.view.setCurrentTool(QgsComposerView.Select) self.btnLabelColor.setVisible(False) # self.btnBack.setVisible(False) self.chbBackgroundEnable.setVisible(False) # self.view.emit(SIGNAL("actionFinished")) # if self.scene.plotStyle() != QgsComposition.Preview: # self.scene.setPlotStyle(QgsComposition.Preview) # self.mapItem.setPreviewMode(QgsComposerMap.Render) # self.mapItem.updateCachedImage() # self.mapItem.setSelected(True) self.mComposition = comp self.composerMapItem = self.mComposition.composerMapItems()[0] self.composerMapItem.setUpdatesEnabled(True) self.mStdModel = model self.mTableView.setModel(self.mStdModel) self.mTableView.setSpan(0, 0, 1, 6) self.mTableView.setSpan(1, 0, 1, 2) self.mTableView.setSpan(2, 0, 2, 1) self.mTableView.setSpan(4, 0, 1, 2) self.mTableView.setSpan(5, 0, 1, 2) self.mTableView.setSpan(6, 0, 1, 2) self.mTableView.setSpan(0, 6, 1, 8) self.mTableView.setSpan(1, 7, 1, 4) self.mTableView.setSpan(1, 11, 1, 3) self.mTableView.setSpan(2, 7, 1, 4) self.mTableView.setSpan(2, 11, 1, 3)
def show_composer(self): """Show the composition in a composer view so the user can tweak it. """ view = QgsComposerView(self.iface.mainWindow()) view.show()