def _add_results(self, preselect: int = -1, row_number: int = 0): ''' adds results to the map canvas and to the result list of the dialog ''' provider = self.preview_layer.layer.dataProvider() for i, result in enumerate(self.results): feature = QgsFeature() coords = result['geometry']['coordinates'] geom = QgsGeometry.fromPointXY(QgsPointXY(coords[0], coords[1])) feature.setGeometry(geom) feature.setAttributes([ i + 1, result['properties']['text'], ]) provider.addFeature(feature) properties = result['properties'] radio = QRadioButton(properties['text']) preview = QLabel() preview.setMaximumWidth(20) preview.setMinimumWidth(20) self.results_contents.addWidget(preview, i + row_number, 0) self.results_contents.addWidget(radio, i + row_number, 1) if self.show_score: score = QLabel(f'Score {properties["score"]}') self.results_contents.addWidget(score, i + row_number, 2) img_path = os.path.join(ICON_PATH, f'marker_{i+1}.png') if os.path.exists(img_path): pixmap = QPixmap(img_path) preview.setPixmap( pixmap.scaled(preview.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) # results clicked in the dialog are highlighted on the map radio.toggled.connect( lambda c, i=i, f=feature: self._toggle_result(i, f)) if i == preselect: radio.setChecked(True) self.preview_layer.layer.commitChanges() extent = self.preview_layer.layer.extent() if not extent.isEmpty(): transform = QgsCoordinateTransform( self.preview_layer.layer.crs(), self.canvas.mapSettings().destinationCrs(), QgsProject.instance()) self.canvas.setExtent(transform.transform(extent)) self.canvas.zoomByFactor(1.5) self.canvas.refresh()
def initGui(self): self.setWindowTitle('New remote') layout = QVBoxLayout() buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close) horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) nameLabel = QLabel('Name') nameLabel.setMinimumWidth(120) nameLabel.setMaximumWidth(120) self.nameBox = QLineEdit() if self.name is not None: self.nameBox.setText(self.name) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) layout.addLayout(horizontalLayout) horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) urlLabel = QLabel('URL') urlLabel.setMinimumWidth(120) urlLabel.setMaximumWidth(120) self.urlBox = QLineEdit() if self.url is not None: self.urlBox.setText(self.url) horizontalLayout.addWidget(urlLabel) horizontalLayout.addWidget(self.urlBox) layout.addLayout(horizontalLayout) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.resize(400, 200)
def initGui(self): self.setWindowTitle('New connection') layout = QVBoxLayout() buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close) horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) nameLabel = QLabel('Name') nameLabel.setMinimumWidth(120) nameLabel.setMaximumWidth(120) self.nameBox = QLineEdit() if self.name is not None: self.nameBox.setText(self.name) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) layout.addLayout(horizontalLayout) horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) urlLabel = QLabel('URL') urlLabel.setMinimumWidth(120) urlLabel.setMaximumWidth(120) self.urlBox = QLineEdit() if self.url is not None: self.urlBox.setText(self.url) horizontalLayout.addWidget(urlLabel) horizontalLayout.addWidget(self.urlBox) layout.addLayout(horizontalLayout) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.resize(400, 200)
def __init__(self, parent, confHandler): """ :type confHandler: configHandler.ConfigHandler """ QDialog.__init__(self, parent) self.confHandler = confHandler self.doSave = False self.setWindowTitle(self.tr('Output Optionen')) main_widget = QWidget(self) # Build up gui # Project title hbox1 = QHBoxLayout() projectNameLabel = QLabel(self.tr('Projektname')) projectNameLabel.setMinimumWidth(100) self.projectField = QLineEdit() self.projectField.setMinimumWidth(400) self.projectField.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) hbox1.addWidget(projectNameLabel) hbox1.addWidget(self.projectField) # Save path hbox2 = QHBoxLayout() saveLabel = QLabel(self.tr('Speicherpfad')) saveLabel.setMinimumWidth(100) self.pathField = QComboBox() self.pathField.setMinimumWidth(400) self.pathField.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) openButton = QPushButton() openButton.setMaximumSize(QSize(27, 27)) icon = QIcon() iconPath = os.path.join(os.path.dirname(__file__), 'icons', 'icon_open.png') icon.addPixmap(QPixmap(iconPath), QIcon.Normal, QIcon.Off) openButton.setIcon(icon) openButton.setIconSize(QSize(24, 24)) openButton.clicked.connect(self.onOpenDialog) hbox2.addWidget(saveLabel) hbox2.addWidget(self.pathField) hbox2.addWidget(openButton) # Create checkboxes questionLabel = QLabel( self.tr('Welche Produkte sollen erzeugt werden?')) self.checkBoxShortReport = QCheckBox(self.tr('Kurzbericht')) self.checkBoxReport = QCheckBox(self.tr('Technischer Bericht')) self.checkBoxPlot = QCheckBox(self.tr('Diagramm')) self.checkBoxGeodata = QCheckBox( self.tr('Shape-Daten der Stuetzen und Seillinie')) self.checkBoxKML = QCheckBox( self.tr('KML-Daten der Stuetzen und Seillinie')) self.checkBoxCoords = QCheckBox( self.tr('Koordinaten-Tabellen der Stuetzen und Seillinie')) # Set tick correctly self.checkBoxShortReport.setChecked( self.confHandler.outputOptions['shortReport']) self.checkBoxReport.setChecked( self.confHandler.outputOptions['report']) self.checkBoxPlot.setChecked(self.confHandler.outputOptions['plot']) self.checkBoxGeodata.setChecked( self.confHandler.outputOptions['geodata']) self.checkBoxKML.setChecked(self.confHandler.outputOptions['kml']) self.checkBoxCoords.setChecked( self.confHandler.outputOptions['coords']) # Create Ok/Cancel Button and connect signal buttonBox = QDialogButtonBox(main_widget) buttonBox.setStandardButtons(QDialogButtonBox.Save | QDialogButtonBox.Cancel) buttonBox.button(QDialogButtonBox.Save).setText(self.tr("Speichern")) buttonBox.button(QDialogButtonBox.Cancel).setText(self.tr("Abbrechen")) buttonBox.button(QDialogButtonBox.Cancel).clicked.connect( self.onCancel) buttonBox.button(QDialogButtonBox.Save).clicked.connect(self.onSave) # Layout container = QVBoxLayout(main_widget) container.addLayout(hbox1) container.addLayout(hbox2) container.addWidget(QLabel('')) container.addWidget(questionLabel) container.addWidget(self.checkBoxShortReport) container.addWidget(self.checkBoxReport) container.addWidget(self.checkBoxPlot) container.addWidget(self.checkBoxGeodata) container.addWidget(self.checkBoxKML) container.addWidget(self.checkBoxCoords) container.addWidget(buttonBox) container.setAlignment(Qt.AlignLeft) self.setLayout(container) self.fillInData()