class PlotConfigPanel(QFrame): """A panel to interact with PlotConfig instances.""" plot_marker_styles = ["", ".", ",", "o", "*", "s", "+", "x", "p", "h", "H", "D", "d"] plot_line_styles = ["", "-", "--", "-.", ":"] def __init__(self, plot_config): QFrame.__init__(self) self.plot_config = plot_config self.connect(plot_config.signal_handler, SIGNAL('plotConfigChanged(PlotConfig)'), self._fetchValues) layout = QFormLayout() layout.setRowWrapPolicy(QFormLayout.WrapLongRows) self.chk_visible = QCheckBox() layout.addRow("Visible:", self.chk_visible) self.connect(self.chk_visible, SIGNAL('stateChanged(int)'), self._setVisibleState) self.plot_linestyle = QComboBox() self.plot_linestyle.addItems(self.plot_line_styles) self.connect(self.plot_linestyle, SIGNAL("currentIndexChanged(QString)"), self._setLineStyle) layout.addRow("Line style:", self.plot_linestyle) self.plot_marker_style = QComboBox() self.plot_marker_style.addItems(self.plot_marker_styles) self.connect(self.plot_marker_style, SIGNAL("currentIndexChanged(QString)"), self._setMarker) layout.addRow("Marker style:", self.plot_marker_style) self.alpha_spinner = QDoubleSpinBox(self) self.alpha_spinner.setMinimum(0.0) self.alpha_spinner.setMaximum(1.0) self.alpha_spinner.setDecimals(3) self.alpha_spinner.setSingleStep(0.01) self.connect(self.alpha_spinner, SIGNAL('valueChanged(double)'), self._setAlpha) layout.addRow("Blend factor:", self.alpha_spinner) self.color_picker = ColorPicker(plot_config) layout.addRow("Color:", self.color_picker) self.setLayout(layout) self._fetchValues(plot_config) def _fetchValues(self, plot_config): """Fetch values from a PlotConfig and insert into the panel.""" self.plot_config = plot_config #block signals to avoid updating the incoming plot_config state = self.plot_linestyle.blockSignals(True) linestyle_index = self.plot_line_styles.index(self.plot_config.linestyle) self.plot_linestyle.setCurrentIndex(linestyle_index) self.plot_linestyle.blockSignals(state) state = self.plot_marker_style.blockSignals(True) marker_index = self.plot_marker_styles.index(self.plot_config.marker) self.plot_marker_style.setCurrentIndex(marker_index) self.plot_marker_style.blockSignals(state) state = self.alpha_spinner.blockSignals(True) self.alpha_spinner.setValue(self.plot_config.alpha) self.alpha_spinner.blockSignals(state) state = self.chk_visible.blockSignals(True) self.chk_visible.setChecked(self.plot_config.is_visible) self.chk_visible.blockSignals(state) self.color_picker.update() #------------------------------------------- # update plot config from widgets #------------------------------------------- def _setLineStyle(self, linestyle): self.plot_config.linestyle = linestyle def _setMarker(self, marker): self.plot_config.marker = marker def _setAlpha(self, alpha): self.plot_config.alpha = alpha def _setVisibleState(self, state): self.plot_config.is_visible = state == 2
class QgsAnnotationWidget(QWidget): def __init__(self, parent, item): QWidget.__init__(self, parent) self.gridLayout_2 = QGridLayout(self) self.gridLayout_2.setObjectName(("gridLayout_2")) self.mMapPositionFixedCheckBox = QCheckBox(self) self.mMapPositionFixedCheckBox.setObjectName( ("mMapPositionFixedCheckBox")) self.gridLayout_2.addWidget(self.mMapPositionFixedCheckBox, 0, 0, 1, 1) self.gridLayout = QGridLayout() self.gridLayout.setObjectName(("gridLayout")) self.mFrameColorButton = QgsColorButton(self) self.mFrameColorButton.setText(("")) self.mFrameColorButton.setObjectName(("mFrameColorButton")) self.gridLayout.addWidget(self.mFrameColorButton, 3, 1, 1, 1) self.mFrameColorButton.colorChanged.connect( self.on_mFrameColorButton_colorChanged) self.mBackgroundColorLabel = QLabel(self) self.mBackgroundColorLabel.setObjectName(("mBackgroundColorLabel")) self.gridLayout.addWidget(self.mBackgroundColorLabel, 2, 0, 1, 1) self.mMapMarkerLabel = QLabel(self) self.mMapMarkerLabel.setObjectName(("mMapMarkerLabel")) self.gridLayout.addWidget(self.mMapMarkerLabel, 0, 0, 1, 1) self.mBackgroundColorButton = QgsColorButton(self) self.mBackgroundColorButton.setText(("")) self.mBackgroundColorButton.setObjectName(("mBackgroundColorButton")) self.gridLayout.addWidget(self.mBackgroundColorButton, 2, 1, 1, 1) self.mBackgroundColorButton.colorChanged.connect( self.on_mBackgroundColorButton_colorChanged) self.mMapMarkerButton = QPushButton(self) self.mMapMarkerButton.setText(("")) self.mMapMarkerButton.setObjectName(("mMapMarkerButton")) self.gridLayout.addWidget(self.mMapMarkerButton, 0, 1, 1, 1) self.mMapMarkerButton.clicked.connect(self.on_mMapMarkerButton_clicked) self.mFrameWidthLabel = QLabel(self) self.mFrameWidthLabel.setObjectName(("mFrameWidthLabel")) self.gridLayout.addWidget(self.mFrameWidthLabel, 1, 0, 1, 1) self.mFrameWidthSpinBox = QDoubleSpinBox(self) self.mFrameWidthSpinBox.setObjectName(("mFrameWidthSpinBox")) self.gridLayout.addWidget(self.mFrameWidthSpinBox, 1, 1, 1, 1) self.mFrameColorLabel = QLabel(self) self.mFrameColorLabel.setObjectName(("mFrameColorLabel")) self.gridLayout.addWidget(self.mFrameColorLabel, 3, 0, 1, 1) self.gridLayout_2.addLayout(self.gridLayout, 1, 0, 1, 1) self.mMapMarkerLabel.setBuddy(self.mMapMarkerButton) self.mFrameWidthLabel.setBuddy(self.mFrameWidthSpinBox) self.setWindowTitle("QgsAnnotationWidgetBase") self.mMapPositionFixedCheckBox.setText("Fixed map position") self.mBackgroundColorLabel.setText("Background color") self.mMapMarkerLabel.setText("Map marker") self.mFrameWidthLabel.setText("Frame width") self.mFrameColorLabel.setText("Frame color") self.setLayout(self.gridLayout_2) self.mItem = item if (self.mItem != None): self.blockAllSignals(True) if (self.mItem.mapPositionFixed()): self.mMapPositionFixedCheckBox.setCheckState(Qt.Checked) else: self.mMapPositionFixedCheckBox.setCheckState(Qt.Unchecked) self.mFrameWidthSpinBox.setValue(self.mItem.frameBorderWidth()) self.mFrameColorButton.setColor(self.mItem.frameColor()) self.mFrameColorButton.setColorDialogTitle("Select frame color") self.mFrameColorButton.setColorDialogOptions( QColorDialog.ShowAlphaChannel) self.mBackgroundColorButton.setColor( self.mItem.frameBackgroundColor()) self.mBackgroundColorButton.setColorDialogTitle( "Select background color") self.mBackgroundColorButton.setColorDialogOptions( QColorDialog.ShowAlphaChannel) self.symbol = self.mItem.markerSymbol() if (self.symbol != None): self.mMarkerSymbol = self.symbol.clone() self.updateCenterIcon() self.blockAllSignals(False) def apply(self): if (self.mItem != None): self.mItem.setMapPositionFixed( self.mMapPositionFixedCheckBox.checkState() == Qt.Checked) self.mItem.setFrameBorderWidth(self.mFrameWidthSpinBox.value()) self.mItem.setFrameColor(self.mFrameColorButton.color()) self.mItem.setFrameBackgroundColor( self.mBackgroundColorButton.color()) self.mItem.setMarkerSymbol(self.mMarkerSymbol) self.mMarkerSymbol = None #//item takes ownership self.mItem.update() def blockAllSignals(self, block): self.mMapPositionFixedCheckBox.blockSignals(block) self.mMapMarkerButton.blockSignals(block) self.mFrameWidthSpinBox.blockSignals(block) self.mFrameColorButton.blockSignals(block) def on_mMapMarkerButton_clicked(self): if (self.mMarkerSymbol == None): return markerSymbol = self.mMarkerSymbol.clone() dlg = QgsSymbolV2SelectorDialog(markerSymbol, QgsStyleV2.defaultStyle(), None, self) if (dlg.exec_() != QDialog.Rejected): self.mMarkerSymbol = markerSymbol self.updateCenterIcon() def on_mFrameColorButton_colorChanged(self, color): if (self.mItem == None): return self.mItem.setFrameColor(color) def updateCenterIcon(self): if (self.mMarkerSymbol == None): return icon = QgsSymbolLayerV2Utils.symbolPreviewIcon( self.mMarkerSymbol, self.mMapMarkerButton.iconSize()) self.mMapMarkerButton.setIcon(icon) def on_mBackgroundColorButton_colorChanged(self, color): if (self.mItem == None): return self.mItem.setFrameBackgroundColor(color)