Beispiel #1
0
class SnappingDock(DockWidget):
    def __init__(self, iface, parent=None):
        super(SnappingDock, self).__init__(parent)
        self._iface = iface

        self.setWindowTitle(u'Snapping Panel')
        self.setObjectName(u'snappingDock')

        self._listWidget = QListWidget(self)
        self._listWidget.setSelectionMode(QAbstractItemView.NoSelection)
        self._listWidget.setDropIndicatorShown(False)

        self._dockLayout = QVBoxLayout(self)
        self._dockLayout.setObjectName(u'dockLayout')
        self._dockLayout.addWidget(self._listWidget)

        self._dockContents = QWidget(self)
        self._dockContents.setObjectName(u'dockContents')
        self._dockContents.setLayout(self._dockLayout)
        self.setWidget(self._dockContents)

        # Keep up-to-date with layers added and removed
        QgsMapLayerRegistry.instance().layersAdded.connect(self._layersAdded)
        QgsMapLayerRegistry.instance().layersRemoved.connect(
            self._layersRemoved)

    def refresh(self):
        self._listWidget.clear()
        layers = QgsMapLayerRegistry.instance().mapLayers()
        layerIds = layers.keys()
        sorted(layerIds)
        for layerId in layerIds:
            self.addLayer(layers[layerId])

    def addLayer(self, layer):
        if (layer is None or not layer.isValid()
                or layer.type() != QgsMapLayer.VectorLayer):
            return
        newItem = QListWidgetItem()
        newItem.setData(Qt.UserRole, layer.id())
        # newItem.setSizeHint(layerWidget.minimumSizeHint())
        self._listWidget.addItem(newItem)
        self._listWidget.setItemWidget(newItem,
                                       LayerSnappingWidget(layer, self))

    def removeLayer(self, layerId):
        for idx in range(0, self._listWidget.count() - 1):
            if self._listWidget.item(idx).data() == layerId:
                self._listWidget.takeItem(idx)
                return

    def _layersAdded(self, layers):
        for layer in layers:
            self.addLayer(layer)

    def _layersRemoved(self, layerIds):
        for idx in range(self._listWidget.count() - 1, 0):
            if self._listWidget.item(idx).data() in layerIds:
                self._listWidget.takeItem(idx)
Beispiel #2
0
class SnappingDock(DockWidget):

    def __init__(self, iface, parent=None):
        super(SnappingDock, self).__init__(parent)
        self._iface = iface

        self.setWindowTitle(u'Snapping Panel')
        self.setObjectName(u'snappingDock')

        self._listWidget = QListWidget(self)
        self._listWidget.setSelectionMode(QAbstractItemView.NoSelection)
        self._listWidget.setDropIndicatorShown(False)

        self._dockLayout = QVBoxLayout(self)
        self._dockLayout.setObjectName(u'dockLayout')
        self._dockLayout.addWidget(self._listWidget)

        self._dockContents = QWidget(self)
        self._dockContents.setObjectName(u'dockContents')
        self._dockContents.setLayout(self._dockLayout)
        self.setWidget(self._dockContents)

        # Keep up-to-date with layers added and removed
        QgsMapLayerRegistry.instance().layersAdded.connect(self._layersAdded)
        QgsMapLayerRegistry.instance().layersRemoved.connect(self._layersRemoved)

    def refresh(self):
        self._listWidget.clear()
        layers = QgsMapLayerRegistry.instance().mapLayers()
        layerIds = layers.keys()
        sorted(layerIds)
        for layerId in layerIds:
            self.addLayer(layers[layerId])

    def addLayer(self, layer):
        if (layer is None or not layer.isValid() or layer.type() != QgsMapLayer.VectorLayer):
            return
        newItem = QListWidgetItem()
        newItem.setData(Qt.UserRole, layer.id())
        # newItem.setSizeHint(layerWidget.minimumSizeHint())
        self._listWidget.addItem(newItem)
        self._listWidget.setItemWidget(newItem, LayerSnappingWidget(layer, self))

    def removeLayer(self, layerId):
        for idx in range(0, self._listWidget.count() - 1):
            if self._listWidget.item(idx).data() == layerId:
                self._listWidget.takeItem(idx)
                return

    def _layersAdded(self, layers):
        for layer in layers:
            self.addLayer(layer)

    def _layersRemoved(self, layerIds):
        for idx in range(self._listWidget.count() - 1, 0):
            if self._listWidget.item(idx).data() in layerIds:
                self._listWidget.takeItem(idx)
Beispiel #3
0
    grade2 = QTreeWidgetItem(treeWidget, grade1)
    grade2.setText(0, "Grade2")
    treeWidget.show()

    #********************* 3. QTableWidget ********************/
    # 创建表格部件,同时指定行数和列数
    tableWidget = QTableWidget(3, 2)
    # 创建表格项目,并插入到指定单元
    tableWidgetItem = QTableWidgetItem("qt")
    tableWidget.setItem(1, 1, tableWidgetItem)
    # 创建表格项目,并将它们作为标头
    headerV = QTableWidgetItem("first")
    tableWidget.setVerticalHeaderItem(0, headerV)
    headerH = QTableWidgetItem("ID")
    tableWidget.setHorizontalHeaderItem(0, headerH)
    tableWidget.show()

    #/************ 4.  为listWidget启用拖放 *************/
    # 设置选择模式为单选
    listWidget.setSelectionMode(QAbstractItemView.SingleSelection)
    # 启用拖动
    listWidget.setDragEnabled(True)
    # 设置接受拖放
    listWidget.viewport().setAcceptDrops(True)
    # 设置显示将要被放置的位置
    listWidget.setDropIndicatorShown(True)
    # 设置拖放模式为移动项目,如果不设置,默认为复制项目
    listWidget.setDragDropMode(QAbstractItemView.InternalMove)

    app.exec_()