Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lizmap/definitions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class InputType(Enum):
SpinBox = 'SpinBox' # QSpinbox
Text = 'Text' # QLineEdit
MultiLine = 'MultiLine' # QPlainTextEdit or QgsCodeEditorHTML
Scale = 'Scale' # QgsScaleWidget


class BaseDefinitions:
Expand Down
90 changes: 90 additions & 0 deletions lizmap/definitions/portfolio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Definitions for portfolio."""

from lizmap.definitions.base import BaseDefinitions, InputType
from lizmap.toolbelt.i18n import tr


def represent_templates(data: Dict) -> str:
"""Generate HTMl string for the tooltip instead of JSON representation."""
html = '<ul>'

for template in data:
layout = template.get('layout')
theme = template.get('theme')
html += f'<li>{layout} - {theme}</li>\n'

html += '</ul>\n'
return html


@unique
class GeometryType(Enum):
Point = {
'data': 'point',
'label': tr('Point'),
}
Line = {
'data': 'line',
'label': tr('Line'),
}
Polygon = {
'data': 'polygon',
'label': tr('Polygon'),
}


class PortfolioDefinitions(BaseDefinitions):

def __init__(self):
super().__init__()
self._layer_config['title'] = {
'type': InputType.Text,
'header': tr('Title'),
'default': '',
'tooltip': tr('The title of the portfolio, when displayed in the portfolio dock'),
}
self._layer_config['description'] = {
'type': InputType.HtmlWysiwyg,
'header': tr('Description'),
'default': '',
'tooltip': tr('The description of the portfolio. HTML is supported.'),
}
self._layer_config['geometry'] = {
'type': InputType.List,
'header': tr('Geometry'),
'items': GeometryType,
'default': GeometryType.Point,
'tooltip': tr('The geometry type of the portfolio.')
}
self._layer_config['margin'] = {
'type': InputType.SpinBox,
'header': tr('Margin'),
'default': 10,
'tooltip': tr('The margin around line or polygon geometry.')
}
self._layer_config['scale'] = {
'type': InputType.Scale,
'header': tr('Scale'),
'default': 5000,
'tooltip': tr('The scale of the portfolio for point geometry.')
}
self._layer_config['templates'] = {
'type': InputType.Collection,
'header': tr('Templates'),
'tooltip': tr('Textual representations of templates'),
'items': [
'layout',
'theme',
],
'represent_value': represent_templates,
}

@staticmethod
def primary_keys() -> tuple:
return tuple()

def key(self) -> str:
return 'portfolioLayers'

def help_path(self) -> str:
return 'publish/lizmap_plugin/portfolio.html'
16 changes: 15 additions & 1 deletion lizmap/forms/base_edition_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
QMessageBox,
QPlainTextEdit,
)
from qgis.utils import iface

from lizmap.definitions.base import InputType
from lizmap.definitions.definitions import LwcVersions, ServerComboData
Expand Down Expand Up @@ -123,9 +124,18 @@ def setup_ui(self):
widget.setSuffix(unit)

default = layer_config.get('default')
if unit:
if unit: # TO FIX replaced by default
widget.setValue(default)

if layer_config['type'] == InputType.Scale:
if widget is not None:
widget.setShowCurrentScaleButton(True)
widget.setMapCanvas(iface.mapCanvas())
widget.setAllowNull(False)
default = layer_config.get('default')
if default:
widget.setScale(default)

if layer_config['type'] == InputType.Color:
if widget is not None:
if layer_config['default'] == '':
Expand Down Expand Up @@ -386,6 +396,8 @@ def load_form(self, data: OrderedDict) -> None:
definition['widget'].setCurrentIndex(index)
elif definition['type'] == InputType.SpinBox:
definition['widget'].setValue(value)
elif definition['type'] == InputType.Scale:
widget.setScale(value)
elif definition['type'] == InputType.Text:
definition['widget'].setText(value)
elif definition['type'] == InputType.Json:
Expand Down Expand Up @@ -443,6 +455,8 @@ def save_form(self) -> OrderedDict:
value = definition['widget'].currentData()
elif definition['type'] == InputType.SpinBox:
value = definition['widget'].value()
elif definition['type'] == InputType.Scale:
value = definition['widget'].scale()
elif definition['type'] == InputType.Text:
value = definition['widget'].text().strip(' \t')
elif definition['type'] == InputType.MultiLine:
Expand Down
63 changes: 63 additions & 0 deletions lizmap/forms/portfolio_edition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Dialog for portfolio edition."""

from typing import TYPE_CHECKING

from qgis.core import QgsApplication
from qgis.PyQt.QtGui import QIcon

from lizmap.forms.base_edition_dialog import BaseEditionDialog
from lizmap.definitions.definitions import LwcVersions
from lizmap.definitions.portfolio import PortfolioDefinitions
from lizmap.toolbelt.i18n import tr
from lizmap.toolbelt.resources import load_ui

if TYPE_CHECKING:
from lizmap.dialogs.main import LizmapDialog


CLASS = load_ui('ui_form_portfolio.ui')


class PortfolioEditionDialog(BaseEditionDialog, CLASS):

def __init__(
self,
parent: Optional["LizmapDialog"] = None,
unicity: Optional[Dict[str, str]] = None,
lwc_version: Optional[LwcVersions] = None,
):
super().__init__(parent, unicity, lwc_version)
self.setupUi(self)
self.parent = parent
self.config = PortfolioDefinitions()
self.config.add_layer_widget('title', self.title)
self.config.add_layer_widget('description', self.text_description)
self.config.add_layer_widget('geometry', self.geometry)
self.config.add_layer_widget('margin', self.margin)
self.config.add_layer_widget('scale', self.scale)
self.config.add_layer_widget('templates', self.templates)

# noinspection PyCallByClass,PyArgumentList
self.add_template.setText('')
self.add_template.setIcon(QIcon(QgsApplication.iconPath('symbologyAdd.svg')))
self.add_template.setToolTip(tr('Add a new tempalte to the portfolio.'))
self.remove_template.setText('')
self.remove_template.setIcon(QIcon(QgsApplication.iconPath('symbologyRemove.svg')))
self.remove_template.setToolTip(tr('Remove the selected template from the portfolio.'))

# Set templates table
items = self.config.layer_config['templates']['items']
self.templates.setColumnCount(len(items))
for i, item in enumerate(items):
sub_definition = self.config.layer_config[item]
column = QTableWidgetItem(sub_definition['header'])
column.setToolTip(sub_definition['tooltip'])
self.templates.setHorizontalHeaderItem(i, column)
header = self.templates.horizontalHeader()
header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)

self.templates.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
self.templates.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
self.templates.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.templates.setAlternatingRowColors(True)
188 changes: 188 additions & 0 deletions lizmap/resources/ui/ui_form_portfolio.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>858</width>
<height>733</height>
</rect>
</property>
<property name="windowTitle">
<string>Portfolio</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>838</width>
<height>659</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_portfolio">
<property name="text">
<string>Map Portfolio printing: he user, after activating the portfolio module, can choose a portfolio, draws the geometry, customizes it (color, text), and launches the portfolio printing that will generate 1 PDF file by tuple (template, theme).</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="add_template">
<property name="text">
<string notr="true">+</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="remove_template">
<property name="text">
<string notr="true">-</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="margin"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_templates">
<property name="text">
<string>Templates</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_description">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_geometry">
<property name="text">
<string>Geometry</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="HtmlEditorWidget" name="text_description" native="true"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Margin</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="geometry"/>
</item>
<item row="5" column="1">
<widget class="QTableWidget" name="templates"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="title"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_title">
<property name="text">
<string>Title</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_scale">
<property name="text">
<string>Scale</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QgsScaleWidget" name="scale">
<property name="showCurrentScaleButton">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QLabel" name="error">
<property name="styleSheet">
<string notr="true">QLabel { color : red; }</string>
</property>
<property name="text">
<string notr="true">ERROR</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsScaleWidget</class>
<extends>QWidget</extends>
<header>qgis.gui</header>
</customwidget>
<customwidget>
<class>HtmlEditorWidget</class>
<extends>QWidget</extends>
<header>lizmap.widgets.html_editor</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Loading
Loading