示例#1
0
def main():
    import sys

    app = QApplication(sys.argv)

    app.setApplicationName("style")
    app.setOrganizationName("QtProject")
    app.setOrganizationDomain("www.qt-project.org")

    widget = StyleWidget()
    widget.showFullScreen()

    sys.exit(app.exec_())
示例#2
0
    def __init__(self, dialog, parent=None):
        PropertyPage.__init__(self, PAGE_VECTOR, dialog, parent)
        Ui_VectorPropertiesWidget.setupUi(self, self)

        self.layer = None

        # initialize vector style widgets
        self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
        self.heightWidget.setObjectName("heightWidget")
        self.verticalLayout_zCoordinate.addWidget(self.heightWidget)

        self.labelHeightWidget = StyleWidget(StyleWidget.LABEL_HEIGHT)
        self.labelHeightWidget.setObjectName("labelHeightWidget")
        self.labelHeightWidget.setEnabled(False)
        self.verticalLayout_Label.addWidget(self.labelHeightWidget)

        self.styleWidgetCount = 0
        self.styleWidgets = []
        for i in range(self.STYLE_MAX_COUNT):
            objName = "styleWidget" + str(i)

            widget = StyleWidget()
            widget.setVisible(False)
            widget.setObjectName(objName)
            self.styleWidgets.append(widget)
            self.verticalLayout_Styles.addWidget(widget)

            # assign the widget to property page attribute
            setattr(self, objName, widget)

        widgets = [self.comboBox_ObjectType, self.heightWidget
                   ] + self.styleWidgets
        widgets += [
            self.radioButton_AllFeatures,
            self.radioButton_IntersectingFeatures, self.checkBox_Clip
        ]
        widgets += [
            self.checkBox_ExportAttrs, self.comboBox_Label,
            self.labelHeightWidget
        ]
        self.registerPropertyWidgets(widgets)

        self.comboBox_ObjectType.currentIndexChanged.connect(
            self.setupStyleWidgets)
        self.heightWidget.comboBox.currentIndexChanged.connect(
            self.altitudeModeChanged)
        self.checkBox_ExportAttrs.toggled.connect(self.exportAttrsToggled)
  def __init__(self, dialog, parent=None):
    PropertyPage.__init__(self, PAGE_VECTOR, dialog, parent)
    Ui_VectorPropertiesWidget.setupUi(self, self)

    self.layer = None

    # initialize vector style widgets
    self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
    self.heightWidget.setObjectName("heightWidget")
    self.verticalLayout_zCoordinate.addWidget(self.heightWidget)

    self.colorWidget = StyleWidget(StyleWidget.COLOR)
    self.colorWidget.setObjectName("colorWidget")
    self.verticalLayout_Styles.addWidget(self.colorWidget)

    self.transparencyWidget = StyleWidget(StyleWidget.TRANSPARENCY)
    self.transparencyWidget.setObjectName("transparencyWidget")
    self.verticalLayout_Styles.addWidget(self.transparencyWidget)

    self.labelHeightWidget = StyleWidget(StyleWidget.LABEL_HEIGHT)
    self.labelHeightWidget.setObjectName("labelHeightWidget")
    self.labelHeightWidget.setEnabled(False)
    self.verticalLayout_Label.addWidget(self.labelHeightWidget)

    self.styleWidgetCount = 0
    self.styleWidgets = []
    for i in range(self.STYLE_MAX_COUNT):
      objName = "styleWidget" + str(i)

      widget = StyleWidget()
      widget.setVisible(False)
      widget.setObjectName(objName)
      self.styleWidgets.append(widget)
      self.verticalLayout_Styles.addWidget(widget)

      # assign the widget to property page attribute
      setattr(self, objName, widget)

    widgets = [self.comboBox_ObjectType, self.heightWidget, self.colorWidget, self.transparencyWidget] + self.styleWidgets
    widgets += [self.radioButton_AllFeatures, self.radioButton_IntersectingFeatures, self.checkBox_Clip]
    widgets += [self.checkBox_ExportAttrs, self.comboBox_Label, self.labelHeightWidget]
    self.registerPropertyWidgets(widgets)

    self.comboBox_ObjectType.currentIndexChanged.connect(self.setupStyleWidgets)
    self.checkBox_ExportAttrs.toggled.connect(self.exportAttrsToggled)
    for radioButton in [self.radioButton_AllFeatures, self.radioButton_IntersectingFeatures]:
      radioButton.toggled.connect(self.featuresToExportChanged)
示例#4
0
  def __init__(self, dialog, parent=None):
    PropertyPage.__init__(self, PAGE_VECTOR, dialog, parent)
    Ui_VectorPropertiesWidget.setupUi(self, self)

    self.layer = None

    # initialize vector style widgets
    self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
    self.heightWidget.setObjectName("heightWidget")
    self.verticalLayout_zCoordinate.addWidget(self.heightWidget)
    self.colorWidget = StyleWidget(StyleWidget.COLOR)
    self.colorWidget.setObjectName("colorWidget")
    self.verticalLayout_Styles.addWidget(self.colorWidget)
    self.transparencyWidget = StyleWidget(StyleWidget.TRANSPARENCY)
    self.transparencyWidget.setObjectName("transparencyWidget")
    self.verticalLayout_Styles.addWidget(self.transparencyWidget)

    self.STYLE_MAX_COUNT = dialog.STYLE_MAX_COUNT
    self.styleWidgets = []
    for i in range(self.STYLE_MAX_COUNT):
      objName = "styleWidget" + str(i)

      widget = StyleWidget()
      widget.setVisible(False)
      widget.setObjectName(objName)
      self.styleWidgets.append(widget)
      self.verticalLayout_Styles.addWidget(widget)

      # assign the widget to property page attribute
      setattr(self, objName, widget)

    widgets = [self.comboBox_ObjectType, self.heightWidget, self.colorWidget, self.transparencyWidget] + self.styleWidgets
    widgets += [self.checkBox_ExportAttrs, self.comboBox_Label]
    self.setPropertyWidgets(widgets)

    self.comboBox_ObjectType.currentIndexChanged.connect(self.objectTypeSelectionChanged)
    self.checkBox_ExportAttrs.toggled.connect(self.exportAttrsToggled)
示例#5
0
class VectorPropertyPage(PropertyPage, Ui_VectorPropertiesWidget):

    STYLE_MAX_COUNT = 6

    def __init__(self, dialog, parent=None):
        PropertyPage.__init__(self, PAGE_VECTOR, dialog, parent)
        Ui_VectorPropertiesWidget.setupUi(self, self)

        self.layer = None

        # initialize vector style widgets
        self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
        self.heightWidget.setObjectName("heightWidget")
        self.verticalLayout_zCoordinate.addWidget(self.heightWidget)

        self.labelHeightWidget = StyleWidget(StyleWidget.LABEL_HEIGHT)
        self.labelHeightWidget.setObjectName("labelHeightWidget")
        self.labelHeightWidget.setEnabled(False)
        self.verticalLayout_Label.addWidget(self.labelHeightWidget)

        self.styleWidgetCount = 0
        self.styleWidgets = []
        for i in range(self.STYLE_MAX_COUNT):
            objName = "styleWidget" + str(i)

            widget = StyleWidget()
            widget.setVisible(False)
            widget.setObjectName(objName)
            self.styleWidgets.append(widget)
            self.verticalLayout_Styles.addWidget(widget)

            # assign the widget to property page attribute
            setattr(self, objName, widget)

        widgets = [self.comboBox_ObjectType, self.heightWidget
                   ] + self.styleWidgets
        widgets += [
            self.radioButton_AllFeatures,
            self.radioButton_IntersectingFeatures, self.checkBox_Clip
        ]
        widgets += [
            self.checkBox_ExportAttrs, self.comboBox_Label,
            self.labelHeightWidget
        ]
        self.registerPropertyWidgets(widgets)

        self.comboBox_ObjectType.currentIndexChanged.connect(
            self.setupStyleWidgets)
        self.heightWidget.comboBox.currentIndexChanged.connect(
            self.altitudeModeChanged)
        self.checkBox_ExportAttrs.toggled.connect(self.exportAttrsToggled)

    def setup(self, properties=None, layer=None):
        self.layer = layer

        self.setEnabled(
            self.dialog.currentItem.data(0, Qt.CheckStateRole) == Qt.Checked)
        for i in range(self.STYLE_MAX_COUNT):
            self.styleWidgets[i].hide()

        obj_types = self.dialog.objectTypeManager.objectTypeNames(
            layer.geometryType())

        # set up object type combo box
        self.comboBox_ObjectType.blockSignals(True)
        self.comboBox_ObjectType.clear()
        for index, obj_type in enumerate(obj_types):
            self.comboBox_ObjectType.addItem(obj_type, index)
        if properties:
            # restore object type selection
            self.comboBox_ObjectType.setCurrentIndex(
                properties.get("comboBox_ObjectType", 0))
        self.comboBox_ObjectType.blockSignals(False)

        # get MapTo3D object to calculate default values
        mapTo3d = self.dialog.mapTo3d()

        # set up height widget and label height widget
        self.heightWidget.setup(options={"layer": layer})
        if layer.geometryType() != QGis.Line:
            defaultLabelHeight = 5
            self.labelHeightWidget.setup(
                options={
                    "layer": layer,
                    "defaultValue": defaultLabelHeight / mapTo3d.multiplierZ
                })
        else:
            self.labelHeightWidget.hide()

        # point layer has no geometry clip option
        self.checkBox_Clip.setVisible(layer.geometryType() != QGis.Point)

        # set up style widgets for selected object type
        self.setupStyleWidgets()

        # set up label combo box
        hasPoint = (layer.geometryType() in (QGis.Point, QGis.Polygon))
        self.setLayoutVisible(self.formLayout_Label, hasPoint)
        self.comboBox_Label.clear()
        if hasPoint:
            self.comboBox_Label.addItem("(No label)")
            fields = self.layer.pendingFields()
            for i in range(fields.count()):
                self.comboBox_Label.addItem(fields[i].name(), i)

        # restore other properties for the layer
        self.setProperties(properties or self.defaultProperties)

    def setupStyleWidgets(self, index=None):
        index = self.comboBox_ObjectType.currentIndex()

        # notice 3D model is experimental
        is_experimental = self.comboBox_ObjectType.currentText() in [
            "JSON model", "COLLADA model"
        ]
        self.label_ObjectTypeMessage.setVisible(is_experimental)

        # get MapTo3D object to calculate default values
        mapTo3d = self.dialog.mapTo3d()

        # setup widgets
        self.dialog.objectTypeManager.setupWidgets(self, mapTo3d, self.layer,
                                                   self.layer.geometryType(),
                                                   index)

        # update enabled property of feature group box
        self.altitudeModeChanged()

    def itemChanged(self, item):
        self.setEnabled(item.data(0, Qt.CheckStateRole) == Qt.Checked)

    def altitudeModeChanged(self, index=None):
        geom_type = self.layer.geometryType()
        type_index = self.comboBox_ObjectType.currentIndex()
        only_clipped = False

        if (geom_type == QGis.Line and type_index
                == 4) or (geom_type == QGis.Polygon
                          and type_index == 1):  # Profile or Overlay
            if self.heightWidget.func.isCurrentItemRelativeHeight():
                only_clipped = True
                self.radioButton_IntersectingFeatures.setChecked(True)
                self.checkBox_Clip.setChecked(True)

        self.groupBox_Features.setEnabled(not only_clipped)

    def exportAttrsToggled(self, checked):
        self.setLayoutEnabled(self.formLayout_Label, checked)
        self.labelHeightWidget.setEnabled(checked)

    def properties(self):
        p = PropertyPage.properties(self)
        item = self.dialog.currentItem
        if item is not None:
            p["visible"] = item.data(0, Qt.CheckStateRole) == Qt.Checked
        return p

    def initStyleWidgets(self, color=True, transparency=True):
        self.styleWidgetCount = 0

        if color:
            self.addStyleWidget(StyleWidget.COLOR)

        if transparency:
            self.addStyleWidget(StyleWidget.TRANSPARENCY)

        for i in range(self.styleWidgetCount, self.STYLE_MAX_COUNT):
            self.styleWidgets[i].hide()

    def addStyleWidget(self, funcType=None, options=None):
        self.styleWidgets[self.styleWidgetCount].setup(funcType, options)
        self.styleWidgetCount += 1
示例#6
0
class VectorPropertyPage(PropertyPage, Ui_VectorPropertiesWidget):

  STYLE_MAX_COUNT = 6

  def __init__(self, dialog, parent=None):
    PropertyPage.__init__(self, PAGE_VECTOR, dialog, parent)
    Ui_VectorPropertiesWidget.setupUi(self, self)

    self.layer = None

    # initialize vector style widgets
    self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
    self.heightWidget.setObjectName("heightWidget")
    self.verticalLayout_zCoordinate.addWidget(self.heightWidget)

    self.labelHeightWidget = StyleWidget(StyleWidget.LABEL_HEIGHT)
    self.labelHeightWidget.setObjectName("labelHeightWidget")
    self.labelHeightWidget.setEnabled(False)
    self.verticalLayout_Label.addWidget(self.labelHeightWidget)

    self.styleWidgetCount = 0
    self.styleWidgets = []
    for i in range(self.STYLE_MAX_COUNT):
      objName = "styleWidget" + str(i)

      widget = StyleWidget()
      widget.setVisible(False)
      widget.setObjectName(objName)
      self.styleWidgets.append(widget)
      self.verticalLayout_Styles.addWidget(widget)

      # assign the widget to property page attribute
      setattr(self, objName, widget)

    widgets = [self.comboBox_ObjectType, self.heightWidget] + self.styleWidgets
    widgets += [self.radioButton_AllFeatures, self.radioButton_IntersectingFeatures, self.checkBox_Clip]
    widgets += [self.checkBox_ExportAttrs, self.comboBox_Label, self.labelHeightWidget]
    self.registerPropertyWidgets(widgets)

    self.comboBox_ObjectType.currentIndexChanged.connect(self.setupStyleWidgets)
    self.heightWidget.comboBox.currentIndexChanged.connect(self.altitudeModeChanged)
    self.checkBox_ExportAttrs.toggled.connect(self.exportAttrsToggled)

  def setup(self, properties=None, layer=None):
    self.layer = layer

    self.setEnabled(self.dialog.currentItem.data(0, Qt.CheckStateRole) == Qt.Checked)
    for i in range(self.STYLE_MAX_COUNT):
      self.styleWidgets[i].hide()

    obj_types = self.dialog.objectTypeManager.objectTypeNames(layer.geometryType())

    # set up object type combo box
    self.comboBox_ObjectType.blockSignals(True)
    self.comboBox_ObjectType.clear()
    for index, obj_type in enumerate(obj_types):
      self.comboBox_ObjectType.addItem(obj_type, index)
    if properties:
      # restore object type selection
      self.comboBox_ObjectType.setCurrentIndex(properties.get("comboBox_ObjectType", 0))
    self.comboBox_ObjectType.blockSignals(False)

    # get MapTo3D object to calculate default values
    mapTo3d = self.dialog.mapTo3d()

    # set up height widget and label height widget
    self.heightWidget.setup(options={"layer": layer})
    if layer.geometryType() != QGis.Line:
      defaultLabelHeight = 5
      self.labelHeightWidget.setup(options={"layer": layer, "defaultValue": defaultLabelHeight / mapTo3d.multiplierZ})
    else:
      self.labelHeightWidget.hide()

    # point layer has no geometry clip option
    self.checkBox_Clip.setVisible(layer.geometryType() != QGis.Point)

    # set up style widgets for selected object type
    self.setupStyleWidgets()

    # set up label combo box
    hasPoint = (layer.geometryType() in (QGis.Point, QGis.Polygon))
    self.setLayoutVisible(self.formLayout_Label, hasPoint)
    self.comboBox_Label.clear()
    if hasPoint:
      self.comboBox_Label.addItem("(No label)")
      fields = self.layer.pendingFields()
      for i in range(fields.count()):
        self.comboBox_Label.addItem(fields[i].name(), i)

    # restore other properties for the layer
    self.setProperties(properties or self.defaultProperties)

  def setupStyleWidgets(self, index=None):
    index = self.comboBox_ObjectType.currentIndex()

    # notice 3D model is experimental
    is_experimental = self.comboBox_ObjectType.currentText() in ["JSON model", "COLLADA model"]
    self.label_ObjectTypeMessage.setVisible(is_experimental)

    # get MapTo3D object to calculate default values
    mapTo3d = self.dialog.mapTo3d()

    # setup widgets
    self.dialog.objectTypeManager.setupWidgets(self, mapTo3d, self.layer, self.layer.geometryType(), index)

    # update enabled property of feature group box
    self.altitudeModeChanged()

  def itemChanged(self, item):
    self.setEnabled(item.data(0, Qt.CheckStateRole) == Qt.Checked)

  def altitudeModeChanged(self, index=None):
    geom_type = self.layer.geometryType()
    type_index = self.comboBox_ObjectType.currentIndex()
    only_clipped = False

    if (geom_type == QGis.Line and type_index == 4) or (geom_type == QGis.Polygon and type_index == 1):    # Profile or Overlay
      if self.heightWidget.func.isCurrentItemRelativeHeight():
        only_clipped = True
        self.radioButton_IntersectingFeatures.setChecked(True)
        self.checkBox_Clip.setChecked(True)

    self.groupBox_Features.setEnabled(not only_clipped)

  def exportAttrsToggled(self, checked):
    self.setLayoutEnabled(self.formLayout_Label, checked)
    self.labelHeightWidget.setEnabled(checked)

  def properties(self):
    p = PropertyPage.properties(self)
    item = self.dialog.currentItem
    if item is not None:
      p["visible"] = item.data(0, Qt.CheckStateRole) == Qt.Checked
    return p

  def initStyleWidgets(self, color=True, transparency=True):
    self.styleWidgetCount = 0

    if color:
      self.addStyleWidget(StyleWidget.COLOR)

    if transparency:
      self.addStyleWidget(StyleWidget.TRANSPARENCY)

    for i in range(self.styleWidgetCount, self.STYLE_MAX_COUNT):
      self.styleWidgets[i].hide()

  def addStyleWidget(self, funcType=None, options=None):
    self.styleWidgets[self.styleWidgetCount].setup(funcType, options)
    self.styleWidgetCount += 1
示例#7
0
class VectorPropertyPage(PropertyPage, Ui_VectorPropertiesWidget):

  def __init__(self, dialog, parent=None):
    PropertyPage.__init__(self, PAGE_VECTOR, dialog, parent)
    Ui_VectorPropertiesWidget.setupUi(self, self)

    self.layer = None

    # initialize vector style widgets
    self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
    self.heightWidget.setObjectName("heightWidget")
    self.verticalLayout_zCoordinate.addWidget(self.heightWidget)
    self.colorWidget = StyleWidget(StyleWidget.COLOR)
    self.colorWidget.setObjectName("colorWidget")
    self.verticalLayout_Styles.addWidget(self.colorWidget)
    self.transparencyWidget = StyleWidget(StyleWidget.TRANSPARENCY)
    self.transparencyWidget.setObjectName("transparencyWidget")
    self.verticalLayout_Styles.addWidget(self.transparencyWidget)
    self.labelHeightWidget = StyleWidget(StyleWidget.LABEL_HEIGHT)
    self.labelHeightWidget.setObjectName("labelHeightWidget")
    self.verticalLayout_Label.addWidget(self.labelHeightWidget)
    self.labelHeightWidget.setEnabled(False)

    self.STYLE_MAX_COUNT = dialog.STYLE_MAX_COUNT
    self.styleWidgets = []
    for i in range(self.STYLE_MAX_COUNT):
      objName = "styleWidget" + str(i)

      widget = StyleWidget()
      widget.setVisible(False)
      widget.setObjectName(objName)
      self.styleWidgets.append(widget)
      self.verticalLayout_Styles.addWidget(widget)

      # assign the widget to property page attribute
      setattr(self, objName, widget)

    widgets = [self.comboBox_ObjectType, self.heightWidget, self.colorWidget, self.transparencyWidget] + self.styleWidgets
    widgets += [self.checkBox_ExportAttrs, self.comboBox_Label, self.labelHeightWidget]
    self.setPropertyWidgets(widgets)

    self.comboBox_ObjectType.currentIndexChanged.connect(self.objectTypeChanged)
    self.checkBox_ExportAttrs.toggled.connect(self.exportAttrsToggled)

  def setup(self, properties=None, layer=None):
    self.layer = layer

    self.setEnabled(self.dialog.currentItem.data(0, Qt.CheckStateRole) == Qt.Checked)
    for i in range(self.STYLE_MAX_COUNT):
      self.styleWidgets[i].hide()

    obj_types = self.dialog.objectTypeManager.objectTypeNames(layer.geometryType())

    # set up object type combo box
    self.comboBox_ObjectType.blockSignals(True)
    self.comboBox_ObjectType.clear()
    for index, obj_type in enumerate(obj_types):
      self.comboBox_ObjectType.addItem(obj_type, index)
    if properties:
      # restore object type selection
      self.comboBox_ObjectType.setCurrentIndex(properties.get("comboBox_ObjectType", 0))
    self.comboBox_ObjectType.blockSignals(False)

    # create MapTo3d object to calculate default values
    world = self.dialog.properties[ObjectTreeItem.ITEM_WORLD] or {}
    ve = float(world.get("lineEdit_zFactor", 1.5))
    vs = float(world.get("lineEdit_zShift", 0))
    mapTo3d = MapTo3D(self.dialog.iface.mapCanvas(), verticalExaggeration=ve, verticalShift=vs)

    # set up height widget and label height widget
    self.heightWidget.setup(layer=layer)
    if layer.geometryType() != QGis.Line:
      defaultLabelHeight = 5
      self.labelHeightWidget.setup(layer=layer, defaultValue=defaultLabelHeight/mapTo3d.multiplierZ)
    else:
      self.labelHeightWidget.hide()

    # set up style widgets for selected object type
    self.objectTypeChanged()

    # set up label combo box
    hasPoint = (layer.geometryType() in (QGis.Point, QGis.Polygon))
    self.setLayoutVisible(self.formLayout_Label, hasPoint)
    self.comboBox_Label.clear()
    if hasPoint:
      self.comboBox_Label.addItem("(No label)")
      fields = self.layer.pendingFields()
      for i in range(fields.count()):
        self.comboBox_Label.addItem(fields[i].name(), i)

    # restore other properties for the layer
    if properties:
      PropertyPage.setProperties(self, properties)
    else:
      PropertyPage.setProperties(self, self.defaultProperties)

  def objectTypeChanged(self, idx=None):
    # notice JSON model is experimental
    self.label_ObjectTypeMessage.setVisible(self.comboBox_ObjectType.currentText() == "JSON model")

    # create MapTo3d object to calculate default values
    world = self.dialog.properties[ObjectTreeItem.ITEM_WORLD] or {}
    ve = float(world.get("lineEdit_zFactor", 1.5))
    vs = float(world.get("lineEdit_zShift", 0))
    mapTo3d = MapTo3D(self.dialog.iface.mapCanvas(), verticalExaggeration=ve, verticalShift=vs)

    # setup widgets
    self.dialog.objectTypeManager.setupForm(self, mapTo3d, self.layer, self.layer.geometryType(), self.comboBox_ObjectType.currentIndex())

  def itemChanged(self, item):
    self.setEnabled(item.data(0, Qt.CheckStateRole) == Qt.Checked)

  def exportAttrsToggled(self, checked):
    self.setLayoutEnabled(self.formLayout_Label, checked)
    self.labelHeightWidget.setEnabled(checked)

  def properties(self):
    p = PropertyPage.properties(self)
    item = self.dialog.currentItem
    if item is not None:
      p["visible"] = item.data(0, Qt.CheckStateRole) == Qt.Checked
    return p
示例#8
0
from PyQt5 import QtWidgets

from stylewidget import StyleWidget

if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    w = StyleWidget()
    w.show()
    sys.exit(app.exec_())