-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from suricactus/lock_geom
FEATURE add option to lock geometries
- Loading branch information
Showing
8 changed files
with
337 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
QFieldSyncDialog | ||
A QGIS plugin | ||
Sync your projects to QField on android | ||
------------------- | ||
begin : 2020-06-15 | ||
git sha : $Format:%H$ | ||
copyright : (C) 2020 by OPENGIS.ch | ||
email : info@opengis.ch | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
import os | ||
|
||
from qgis.core import Qgis, QgsProject, QgsMapLayer | ||
from qgis.gui import QgsMapLayerConfigWidget, QgsMapLayerConfigWidgetFactory | ||
|
||
from qgis.PyQt.uic import loadUiType | ||
|
||
from qfieldsync.core.layer import LayerSource | ||
from qfieldsync.gui.photo_naming_widget import PhotoNamingTableWidget | ||
from qfieldsync.gui.utils import set_available_actions | ||
|
||
WidgetUi, _ = loadUiType(os.path.join(os.path.dirname(__file__), '../ui/map_layer_config_widget.ui')) | ||
|
||
|
||
class MapLayerConfigWidgetFactory(QgsMapLayerConfigWidgetFactory): | ||
def __init__(self, title, icon): | ||
super(MapLayerConfigWidgetFactory, self).__init__(title, icon) | ||
|
||
|
||
def createWidget(self, layer, canvas, dock_widget, parent): | ||
return MapLayerConfigWidget(layer, canvas, parent) | ||
|
||
|
||
def supportsLayer(self, layer): | ||
return LayerSource(layer).is_supported | ||
|
||
|
||
def supportLayerPropertiesDialog(self): | ||
return True | ||
|
||
|
||
class MapLayerConfigWidget(QgsMapLayerConfigWidget, WidgetUi): | ||
def __init__(self, layer, canvas, parent): | ||
super(MapLayerConfigWidget, self).__init__(layer, canvas, parent) | ||
self.setupUi(self) | ||
self.layer_source = LayerSource(layer) | ||
self.project = QgsProject.instance() | ||
|
||
set_available_actions(self.layerActionComboBox, self.layer_source) | ||
|
||
self.isGeometryLockedCheckBox.setEnabled(self.layer_source.can_lock_geometry) | ||
self.isGeometryLockedCheckBox.setChecked(self.layer_source.is_geometry_locked) | ||
self.photoNamingTable = PhotoNamingTableWidget() | ||
self.photoNamingTable.addLayerFields(self.layer_source) | ||
self.photoNamingTable.setLayerColumnHidden(True) | ||
|
||
# insert the table as a second row only for vector layers | ||
if Qgis.QGIS_VERSION_INT >= 31300 and layer.type() == QgsMapLayer.VectorLayer: | ||
self.layout().insertRow(1, self.tr('Photo Naming'), self.photoNamingTable) | ||
self.photoNamingTable.setEnabled(self.photoNamingTable.rowCount() > 0) | ||
|
||
|
||
def apply(self): | ||
old_layer_action = self.layer_source.action | ||
old_is_geometry_locked = self.layer_source.is_geometry_locked | ||
|
||
self.layer_source.action = self.layerActionComboBox.itemData(self.layerActionComboBox.currentIndex()) | ||
self.layer_source.is_geometry_locked = self.isGeometryLockedCheckBox.isChecked() | ||
self.photoNamingTable.syncLayerSourceValues() | ||
|
||
# apply always the photo_namings (to store default values on first apply as well) | ||
if (self.layer_source.action != old_layer_action or | ||
self.layer_source.is_geometry_locked != old_is_geometry_locked or | ||
self.photoNamingTable.rowCount() > 0 | ||
): | ||
self.layer_source.apply() | ||
self.project.setDirty(True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
QFieldSyncDialog | ||
A QGIS plugin | ||
Sync your projects to QField on android | ||
------------------- | ||
begin : 2020-06-15 | ||
git sha : $Format:%H$ | ||
copyright : (C) 2020 by OPENGIS.ch | ||
email : info@opengis.ch | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
|
||
from qgis.core import QgsMapLayer | ||
from qgis.gui import QgsFieldExpressionWidget | ||
|
||
from qgis.PyQt.QtCore import Qt | ||
from qgis.PyQt.QtWidgets import QTableWidget, QTableWidgetItem, QAbstractScrollArea | ||
|
||
|
||
class PhotoNamingTableWidget(QTableWidget): | ||
def __init__(self): | ||
super(PhotoNamingTableWidget, self).__init__() | ||
|
||
self.setColumnCount(3) | ||
self.setHorizontalHeaderLabels([self.tr('Layer'), self.tr('Field'), self.tr('Naming Expression')]) | ||
self.horizontalHeaderItem(2).setToolTip(self.tr('Enter expression for a file path with the extension .jpg')) | ||
self.horizontalHeader().setStretchLastSection(True) | ||
self.setRowCount(0) | ||
self.resizeColumnsToContents() | ||
self.setMinimumHeight(100) | ||
self.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) | ||
|
||
|
||
def addLayerFields(self, layer_source): | ||
layer = layer_source.layer | ||
|
||
if layer.type() != QgsMapLayer.VectorLayer: | ||
return | ||
|
||
for i, field in enumerate(layer.fields()): | ||
row = self.rowCount() | ||
ews = layer.editorWidgetSetup(i) | ||
|
||
if ews.type() == 'ExternalResource': | ||
# for later: if ews.config().get('DocumentViewer', QgsExternalResourceWidget.NoContent) == QgsExternalResourceWidget.Image: | ||
self.insertRow(row) | ||
item = QTableWidgetItem(layer.name()) | ||
item.setData(Qt.UserRole, layer_source) | ||
self.setItem(row, 0, item) | ||
item = QTableWidgetItem(field.name()) | ||
self.setItem(row, 1, item) | ||
ew = QgsFieldExpressionWidget() | ||
ew.setLayer(layer) | ||
expression = layer_source.photo_naming(field.name()) | ||
ew.setExpression(expression) | ||
self.setCellWidget(row, 2, ew) | ||
|
||
self.resizeColumnsToContents() | ||
|
||
|
||
def setLayerColumnHidden(self, is_hidden): | ||
self.setColumnHidden(0, is_hidden) | ||
|
||
|
||
def syncLayerSourceValues(self, should_apply=False): | ||
for i in range(self.rowCount()): | ||
layer_source = self.item(i, 0).data(Qt.UserRole) | ||
field_name = self.item(i, 1).text() | ||
new_expression = self.cellWidget(i, 2).currentText() | ||
layer_source.set_photo_naming(field_name, new_expression) | ||
|
||
if should_apply: | ||
layer_source.apply() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
QFieldSyncDialog | ||
A QGIS plugin | ||
Sync your projects to QField on android | ||
------------------- | ||
begin : 2020-06-15 | ||
git sha : $Format:%H$ | ||
copyright : (C) 2020 by OPENGIS.ch | ||
email : info@opengis.ch | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
|
||
def set_available_actions(combobox, layer_source): | ||
"""Sets available actions on a checkbox and selects the current one. | ||
Args: | ||
combobox (QComboBox): target combobox | ||
layer_source (LayerSource): target layer | ||
""" | ||
for action, description in layer_source.available_actions: | ||
combobox.addItem(description) | ||
combobox.setItemData(combobox.count() - 1, action) | ||
|
||
if layer_source.action == action: | ||
combobox.setCurrentIndex(combobox.count() - 1) |
Oops, something went wrong.