Beispiel #1
0
def max_value(values, context, parent, node):
    """
    <h3>function max_value</h3>
    <div class="description">Returns the maximum value from a layer for a given column.</div>
    <h4>Syntax</h4>
    <div class="syntax">
    <code><span class="functionname">max_value</span>(<span class="argument">string</span>, <span class="argument">string</span>)</code>
    <h4>Arguments</h4>
    <div class="arguments">
    <table>
    <tr><td class="argument">string</td><td>A string (case sensitive) representing a layer in the current workspace.</td></tr>
    <tr><td class="argument">string</td><td>A string (case sensitive) representing a field within this layer.</td></tr>
    </table>
    </div>
    <h4>Examples</h4>
    <div class="examples">
    <ul>
    <li><code>max_value('Trees', 'pk')</code> &rarr; <code>Maximum primary key ('pk') value in layer 'Trees'.</code></li>
    </ul>
    </div>
    """
    layer = values[0]
    try:
        layer = utils.layer_by_name(layer)
    except IndexError:
        parent.setEvalErrorString("Can't find layer {}".format(layer))
        return

    field = values[1]
    index = layer.fields().indexOf(field)
    if index == -1:
        return None
    return layer.maximumValue(index)
Beispiel #2
0
    def set_project(self, project, node):
        """
        Set the project for the widget. Updates the selection query for the current widget..
        """
        self.connectionCombo.blockSignals(False)
        super(InfoNode, self).set_project(project, node)
        # uri = QgsDataSourceURI(self.layer.dataProvider().dataSourceUri())

        infoblock = self.project.info_query(node.key, node.layer.name())
        caption = infoblock.get("caption", node.text())
        query = infoblock.get("query", "")
        connection = infoblock.get("connection", "from_layer")

        if connection == "from_layer":
            self.thislayer_radio.setChecked(True)
        else:
            layername = connection['layer']
            layer = utils.layer_by_name(layername)
            self.fromlayer_radio.setChecked(True)
            self.connectionCombo.setLayer(layer)

        self.caption_edit.setText(caption)
        self.Editor.setText(query)
        self.attributesLabel.setText("")
        self.previewGrid.setModel(None)
        self.resultsLabel.setText("")

        if not self.update_panel_status():
            pass
Beispiel #3
0
    def set_project(self, project, node):
        """
        Set the project for the widget. Updates the selection query for the current widget..
        """
        self.connectionCombo.blockSignals(False)
        super(InfoNode, self).set_project(project, node)
        self.layer = self.treenode.layer
        # uri = QgsDataSourceURI(self.layer.dataProvider().dataSourceUri())
        if not self.update_panel_status():
            pass

        infoblock = self.project.info_query(node.key, node.layer.name())
        caption = infoblock.get("caption", node.text())
        query = infoblock.get("query", "")
        connection = infoblock.get("connection", "from_layer")

        if connection == "from_layer":
            self.thislayer_radio.setChecked(True)
        else:
            layername = connection['layer']
            layer = utils.layer_by_name(layername)
            self.fromlayer_radio.setChecked(True)
            self.connectionCombo.setLayer(layer)

        self.caption_edit.setText(caption)
        self.Editor.setText(query)
Beispiel #4
0
 def get_layer() -> str:
     connection = infoblockdef.get('connection', "from_layer")
     if isinstance(connection, dict):
         return layer_by_name(connection['layer'])
     elif connection == "from_layer":
         return layer
     else:
         raise NotImplementedError("{} is not a supported connection type".format(connection))
Beispiel #5
0
 def get_layer():
     connection = infoblockdef['connection']
     if isinstance(connection, dict):
         return layer_by_name(connection['layer'])
     elif connection == "from_layer":
         return layer
     else:
         raise NotImplementedError("{} is not a supported connection type".format(connection))
Beispiel #6
0
 def define_filter(self):
     layer = self.layerCombo.currentText()
     if not layer:
         return
     layer = layer_by_name(layer)
     dlg = QgsExpressionBuilderDialog(layer, "List filter", self)
     text = self.filterText.toPlainText()
     dlg.setExpressionText(text)
     if dlg.exec_():
         self.filterText.setPlainText(dlg.expressionText())
Beispiel #7
0
 def define_filter(self):
     layer = self.layerCombo.currentText()
     if not layer:
         return
     layer = layer_by_name(layer)
     dlg = QgsExpressionBuilderDialog(layer, "List filter", self)
     text = self.filterText.toPlainText()
     dlg.setExpressionText(text)
     if dlg.exec_():
         self.filterText.setPlainText(dlg.expressionText())
 def get_work_layer(self):
     settings = self.project.settings
     layername = settings['gpspointlayer']
     self.w_layer = utils.layer_by_name(layername[0])
     field_nat = settings['gpspointattr']
     self.w_layer_nat_field = field_nat[0]
     try:
         field_time = settings['gpspointtime']
         self.w_layer_time_field = field_time[0]
     except (KeyError):
         logger.info('No time field in project.config')
         self.w_layer_time_field = None
Beispiel #9
0
def max_value(values, feature, parent):
    """
    Return the max value from a layer for the given column

    Usage:
    max_value('Trees', 'pk')
    """
    layer = values[0]
    try:
        layer = utils.layer_by_name(layer)
    except IndexError:
        parent.setEvalErrorString("Can't find layer {}".format(layer))
        return

    field = values[1]
    index = layer.fields().indexOf(field)
    if index == -1:
        return None
    return layer.maximumValue(index)
Beispiel #10
0
def max_value(values, feature, parent):
    """
    Return the max value from a layer for the given column

    Usage:
    max_value('Trees', 'pk')
    """
    layer = values[0]
    try:
        layer = utils.layer_by_name(layer)
    except IndexError:
        parent.setEvalErrorString("Can't find layer {}".format(layer))
        return

    field = values[1]
    index = layer.fieldNameIndex(field)
    if index == -1:
        return None
    return layer.maximumValue(index)
Beispiel #11
0
    def set_project(self, project, node):
        self.connectionCombo.blockSignals(False)
        super(InfoNode, self).set_project(project, node)
        self.layer = self.treenode.layer
        # uri = QgsDataSourceURI(self.layer.dataProvider().dataSourceUri())
        if not self.update_panel_status():
            pass

        infoblock = self.project.info_query(node.key, node.layer.name())
        caption = infoblock.get("caption", node.text())
        query = infoblock.get("query", "")
        connection = infoblock.get("connection", "from_layer")

        if connection == "from_layer":
            self.thislayer_radio.setChecked(True)
        else:
            layername = connection['layer']
            layer = utils.layer_by_name(layername)
            self.fromlayer_radio.setChecked(True)
            self.connectionCombo.setLayer(layer)

        self.caption_edit.setText(caption)
        self.Editor.setText(query)