Skip to content

Commit

Permalink
another UI rework and related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jul 3, 2023
1 parent ebc2df7 commit e68fb9f
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 106 deletions.
10 changes: 8 additions & 2 deletions Mergin/attachment_fields_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from qgis.PyQt.QtGui import QStandardItemModel, QStandardItem
from qgis.PyQt.QtCore import Qt
from qgis.core import QgsProject, QgsMapLayer
from qgis.PyQt.QtCore import Qt, QSize
from qgis.core import QgsProject, QgsMapLayer, QgsSymbolLayerUtils, QgsIconUtils


class AttachmentFieldsModel(QStandardItemModel):
Expand Down Expand Up @@ -29,6 +29,12 @@ def __init__(self, parent=None):
continue

item_layer = QStandardItem(f"{layer.name()}")
if layer.renderer().type() == "singleSymbol":
icon = QgsSymbolLayerUtils.symbolPreviewIcon(layer.renderer().symbol(), QSize(16, 16))
item_layer.setIcon(icon)
else:
item_layer.setIcon(QgsIconUtils.iconForLayer(layer))

item_field = QStandardItem(f"{field.name()}")
item_field.setData(layer_id, AttachmentFieldsModel.LAYER_ID)
item_field.setData(field.name(), AttachmentFieldsModel.FIELD_NAME)
Expand Down
29 changes: 21 additions & 8 deletions Mergin/project_settings_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from qgis.gui import QgsOptionsWidgetFactory, QgsOptionsPageWidget
from .attachment_fields_model import AttachmentFieldsModel
from .utils import icon_path, mergin_project_local_path
from .utils import icon_path, mergin_project_local_path, prefix_for_relative_path, resolve_target_dir

ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_project_config.ui")
ProjectConfigUiWidget, _ = uic.loadUiType(ui_file)
Expand Down Expand Up @@ -108,35 +108,40 @@ def expression_changed(self, expression):
return
index = self.attachment_fields.selectionModel().selectedIndexes()[0]
layer = None
field_name = None
if index.isValid():
item = self.attachments_model.item(index.row(), 1)
item.setData(self.edit_photo_expression.expression(), AttachmentFieldsModel.EXPRESSION)
layer = QgsProject.instance().mapLayer(item.data(AttachmentFieldsModel.LAYER_ID))
field_name = item.data(AttachmentFieldsModel.FIELD_NAME)

self.update_preview(expression, layer)
self.update_preview(expression, layer, field_name)

def update_expression_edit(self, current, previous):
item = self.attachments_model.item(current.row(), 1)
exp = item.data(AttachmentFieldsModel.EXPRESSION)
field_name = item.data(AttachmentFieldsModel.FIELD_NAME)
layer = QgsProject.instance().mapLayer(item.data(AttachmentFieldsModel.LAYER_ID))
if layer and layer.isValid():
self.edit_photo_expression.setLayer(layer)

self.edit_photo_expression.blockSignals(True)
self.edit_photo_expression.setExpression(exp if exp else "")
self.edit_photo_expression.blockSignals(False)
self.update_preview(exp, layer)
self.update_preview(exp, layer, field_name)

def update_preview(self, expression, layer):
def update_preview(self, expression, layer, field_name):
if expression == "":
self.label_preview.setText("")
return

context = None
if layer and layer.isValid():
context = layer.createExpressionContext()
f = QgsFeature()
layer.getFeatures(QgsFeatureRequest().setLimit(1)).nextFeature(f)
context.setFeature(f)
if f.isValid():
context.setFeature(f)
else:
context = QgsExpressionContext()
context.appendScope(QgsExpressionContextUtils.globalScope())
Expand All @@ -153,13 +158,21 @@ def update_preview(self, expression, layer):
self.label_preview.setText(f"<i>{exp.evalErrorString()}</i>")
return

self.label_preview.setText(f"<i>{val}</i>")
config = layer.fields().field(field_name).editorWidgetSetup().config()
target_dir = resolve_target_dir(layer, config)
prefix = prefix_for_relative_path(
config.get("RelativeStorage", 0), QgsProject.instance().homePath(), target_dir
)
if prefix:
self.label_preview.setText(f"<i>{prefix.removeprefix(QgsProject.instance().homePath())}/{val}.jpg</i>")
else:
self.label_preview.setText(f"<i>{val}.jpg</i>")

def apply(self):
QgsProject.instance().writeEntry("Mergin", "PhotoQuality", self.cmb_photo_quality.currentData())
QgsProject.instance().writeEntry("Mergin", "Snapping", self.cmb_snapping_mode.currentData())
for i in range(self.model.rowCount()):
index = self.model.index(i, 1)
for i in range(self.attachments_model.rowCount()):
index = self.attachments_model.index(i, 1)
if index.isValid():
item = self.attachments_model.itemFromIndex(index)
layer_id = item.data(AttachmentFieldsModel.LAYER_ID)
Expand Down
201 changes: 105 additions & 96 deletions Mergin/ui/ui_project_config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<height>615</height>
<width>638</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Create Mergin Project</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="selective_sync_group">
<property name="title">
<string>Selective sync</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is configuration for selective sync for Input in Mergin Maps project. With selective sync enabled Mergin Maps Input will not download photos from other surveyors to make synchronisation faster. Check out more in the &lt;a href=&quot;https://merginmaps.com/docs/manage/selective_sync/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;documentation&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="edit_sync_dir">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>175</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Select sync directory</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QToolButton" name="btn_get_sync_dir">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_sync_dir">
<property name="text">
<string> Only apply for folder </string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="chk_sync_enabled">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Enable selective sync for Input</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="photo_quality_groupbox">
<property name="title">
Expand Down Expand Up @@ -114,19 +49,6 @@
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="snapping_group_box">
<property name="title">
Expand Down Expand Up @@ -162,40 +84,46 @@
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Photo attachment</string>
<string>Photo attachments configuration</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" rowspan="5">
<item row="4" column="2">
<widget class="QLabel" name="label_preview">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="8">
<widget class="QTreeView" name="attachment_fields">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="4" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_preview">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QgsExpressionLineEdit" name="edit_photo_expression" native="true"/>
</item>
<item row="2" column="1" colspan="2">
<item row="1" column="1" colspan="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;strong&gt;Photo name format&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Set up custom photo names format based on an expression. Make sure that the name is unique for each photo.&lt;/p&gt;&lt;p&gt;Pro tip: use variables like &lt;code&gt;@mergin_username&lt;/code&gt;, &lt;code&gt;@layer_name&lt;/code&gt; or layer fields in combination with &lt;code&gt;now()&lt;/code&gt; (to get the current time) in order to generate unique photo names.&lt;/p&gt;&lt;p&gt;For further details, please refer to &lt;a href=&quot;https://merginmaps.com/docs/layer/settingup_forms_photo/#customising-photo-name-format-with-expressions&quot;&gt;our documentation&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -205,7 +133,7 @@
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<item row="2" column="1" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -218,9 +146,90 @@
</property>
</spacer>
</item>
<item row="3" column="1" colspan="2">
<widget class="QgsExpressionLineEdit" name="edit_photo_expression" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="selective_sync_group">
<property name="title">
<string>Selective sync</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is configuration for selective sync for Input in Mergin Maps project. With selective sync enabled Mergin Maps Input will not download photos from other surveyors to make synchronisation faster. Check out more in the &lt;a href=&quot;https://merginmaps.com/docs/manage/selective_sync/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;documentation&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="edit_sync_dir">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>175</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Select sync directory</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QToolButton" name="btn_get_sync_dir">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_sync_dir">
<property name="text">
<string> Only apply for folder </string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="chk_sync_enabled">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Enable selective sync for Input</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
Loading

0 comments on commit e68fb9f

Please sign in to comment.