Skip to content

Commit

Permalink
Show warning instead of error on plugin layers
Browse files Browse the repository at this point in the history
Fix #62
Fix #61
  • Loading branch information
m-kuhn committed Mar 10, 2018
1 parent 000ef55 commit 39cfc70
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 26 deletions.
18 changes: 16 additions & 2 deletions qfieldsync/core/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def is_configured(self):
def is_file(self):
if os.path.isfile(self.layer.source()):
return True
elif not self._has_data_provider():
return False
elif os.path.isfile(QgsDataSourceURI(self.layer.dataProvider().dataSourceUri()).database()):
return True
else:
Expand Down Expand Up @@ -127,20 +129,25 @@ def is_supported(self):
# ecw raster
elif self.layer.source().endswith('ecw'):
return False
elif not self._has_data_provider():
return False
else:
return True

@property
def warning(self):
if self.layer.source().endswith('jp2', 'jpx'):
if self.layer.source().endswith('jp2') or self.layer.source().endswith('jpx'):
return QCoreApplication.translate('DataSourceWarning',
'JPEG2000 layers are not supported by QField.<br>You can rasterize '
'them as basemap.'
)
if self.layer.source().endswith('ecw'):
elif self.layer.source().endswith('ecw'):
return QCoreApplication.translate('DataSourceWarning',
'ECW layers are not supported by QField.<br>You can rasterize them '
'as basemap.')
elif not self._has_data_provider():
return QCoreApplication.translate('DataSourceWarning', 'Plugin layers are not supported by QField.<br>'
'Use the basemap functionality or the XYZ provider.')
return None

def copy(self, target_path, keep_existent=False):
Expand Down Expand Up @@ -201,3 +208,10 @@ def _change_data_source(self, new_data_source):
# reload layer definition
self.layer.readLayerXML(map_layer_element)
self.layer.reload()

def _has_data_provider(self):
return hasattr(self.layer, 'dataProvider') # Plugin layers do not have a dataProvider (See #62)

@property
def name(self):
return self.layer.name()
17 changes: 17 additions & 0 deletions qfieldsync/dialogs/project_configuration_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ def __init__(self, iface, parent=None):
self.setupUi(self)

self.singleLayerRadioButton.toggled.connect(self.baseMapTypeChanged)
self.unsupportedLayersList = list()

self.reloadProject()

def reloadProject(self):
"""
Load all layers from the map layer registry into the table.
"""
self.unsupportedLayersList = list()
self.layersTable.setRowCount(0)
self.layersTable.setSortingEnabled(False)
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
layer_source = LayerSource(layer)
if not layer_source.is_supported:
self.unsupportedLayersList.append(layer_source)
count = self.layersTable.rowCount()
self.layersTable.insertRow(count)
item = QTableWidgetItem(layer.name())
Expand Down Expand Up @@ -107,6 +111,19 @@ def reloadProject(self):
self.tileSize.setText(str(self.__project_configuration.base_map_tile_size))
self.onlyOfflineCopyFeaturesInAoi.setChecked(self.__project_configuration.offline_copy_only_aoi)

if self.unsupportedLayersList:
self.unsupportedLayers.setVisible(True)

unsupportedLayersText = '<b>{}</b><br>'.format(self.tr('Warning'))
unsupportedLayersText += self.tr("There are unsupported layers in your project. They will not be available on QField.")

unsupportedLayersText += '<ul>'
for layer in self.unsupportedLayersList:
unsupportedLayersText += '<li>' + '<b>' + layer.name + ':</b> ' + layer.warning
unsupportedLayersText += '<ul>'

self.unsupportedLayers.setText(unsupportedLayersText)

def onAccepted(self):
"""
Update layer configuration in project
Expand Down
3 changes: 2 additions & 1 deletion qfieldsync/ui/package_dialog_ui4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/package_dialog.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -72,6 +72,7 @@ def setupUi(self, QFieldPackageDialogBase):
self.widget.setSizePolicy(sizePolicy)
self.widget.setObjectName(_fromUtf8("widget"))
self.gridLayout_6 = QtGui.QGridLayout(self.widget)
self.gridLayout_6.setMargin(0)
self.gridLayout_6.setObjectName(_fromUtf8("gridLayout_6"))
self.yMaxLabel = QtGui.QLineEdit(self.widget)
self.yMaxLabel.setEnabled(False)
Expand Down
3 changes: 1 addition & 2 deletions qfieldsync/ui/package_dialog_ui5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/package_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.7
# Created by: PyQt5 UI code generator 5.9.1
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -58,7 +58,6 @@ def setupUi(self, QFieldPackageDialogBase):
self.widget.setSizePolicy(sizePolicy)
self.widget.setObjectName("widget")
self.gridLayout_6 = QtWidgets.QGridLayout(self.widget)
self.gridLayout_6.setContentsMargins(0, 0, 0, 0)
self.gridLayout_6.setObjectName("gridLayout_6")
self.yMaxLabel = QtWidgets.QLineEdit(self.widget)
self.yMaxLabel.setEnabled(False)
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/ui/preferences_dialog_ui4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/preferences_dialog.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!

Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/ui/preferences_dialog_ui5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/preferences_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.7
# Created by: PyQt5 UI code generator 5.9.1
#
# WARNING! All changes made in this file will be lost!

Expand Down
19 changes: 15 additions & 4 deletions qfieldsync/ui/project_configuration_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>608</width>
<width>543</width>
<height>510</height>
</rect>
</property>
Expand Down Expand Up @@ -52,7 +52,7 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -213,8 +213,6 @@
</widget>
</item>
</layout>
<zorder>singleLayerRadioButton</zorder>
<zorder>createBaseMapGroupBox</zorder>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
Expand All @@ -232,6 +230,19 @@
</widget>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="unsupportedLayers">
<property name="text">
<string>Unsupported layers</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
17 changes: 12 additions & 5 deletions qfieldsync/ui/project_configuration_dialog_ui4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/project_configuration_dialog.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!

Expand All @@ -25,7 +25,7 @@ def _translate(context, text, disambig):
class Ui_QFieldProjectConfigurationBase(object):
def setupUi(self, QFieldProjectConfigurationBase):
QFieldProjectConfigurationBase.setObjectName(_fromUtf8("QFieldProjectConfigurationBase"))
QFieldProjectConfigurationBase.resize(608, 510)
QFieldProjectConfigurationBase.resize(543, 510)
self.gridLayout = QtGui.QGridLayout(QFieldProjectConfigurationBase)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.groupBox = QtGui.QGroupBox(QFieldProjectConfigurationBase)
Expand All @@ -48,12 +48,13 @@ def setupUi(self, QFieldProjectConfigurationBase):
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout.addWidget(self.buttonBox, 3, 0, 1, 1)
self.gridLayout.addWidget(self.buttonBox, 4, 0, 1, 1)
self.tabWidget = QtGui.QTabWidget(QFieldProjectConfigurationBase)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.tab = QtGui.QWidget()
self.tab.setObjectName(_fromUtf8("tab"))
self.gridLayout_4 = QtGui.QGridLayout(self.tab)
self.gridLayout_4.setMargin(0)
self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
self.createBaseMapGroupBox = QtGui.QGroupBox(self.tab)
self.createBaseMapGroupBox.setCheckable(True)
Expand Down Expand Up @@ -99,6 +100,7 @@ def setupUi(self, QFieldProjectConfigurationBase):
self.singleLayerPage.setSizePolicy(sizePolicy)
self.singleLayerPage.setObjectName(_fromUtf8("singleLayerPage"))
self.formLayout = QtGui.QFormLayout(self.singleLayerPage)
self.formLayout.setMargin(0)
self.formLayout.setObjectName(_fromUtf8("formLayout"))
self.label_2 = QtGui.QLabel(self.singleLayerPage)
self.label_2.setObjectName(_fromUtf8("label_2"))
Expand Down Expand Up @@ -127,18 +129,22 @@ def setupUi(self, QFieldProjectConfigurationBase):
self.buttonGroup.addButton(self.singleLayerRadioButton)
self.gridLayout_3.addWidget(self.singleLayerRadioButton, 0, 0, 1, 1)
self.gridLayout_4.addWidget(self.createBaseMapGroupBox, 0, 0, 1, 1)
self.singleLayerRadioButton.raise_()
self.createBaseMapGroupBox.raise_()
self.tabWidget.addTab(self.tab, _fromUtf8(""))
self.tab_2 = QtGui.QWidget()
self.tab_2.setObjectName(_fromUtf8("tab_2"))
self.gridLayout_5 = QtGui.QGridLayout(self.tab_2)
self.gridLayout_5.setMargin(0)
self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5"))
self.onlyOfflineCopyFeaturesInAoi = QtGui.QCheckBox(self.tab_2)
self.onlyOfflineCopyFeaturesInAoi.setObjectName(_fromUtf8("onlyOfflineCopyFeaturesInAoi"))
self.gridLayout_5.addWidget(self.onlyOfflineCopyFeaturesInAoi, 0, 0, 1, 1)
self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
self.gridLayout.addWidget(self.tabWidget, 1, 0, 1, 1)
self.unsupportedLayers = QtGui.QLabel(QFieldProjectConfigurationBase)
self.unsupportedLayers.setTextFormat(QtCore.Qt.RichText)
self.unsupportedLayers.setWordWrap(True)
self.unsupportedLayers.setObjectName(_fromUtf8("unsupportedLayers"))
self.gridLayout.addWidget(self.unsupportedLayers, 3, 0, 1, 1)

self.retranslateUi(QFieldProjectConfigurationBase)
self.tabWidget.setCurrentIndex(0)
Expand Down Expand Up @@ -168,5 +174,6 @@ def retranslateUi(self, QFieldProjectConfigurationBase):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("QFieldProjectConfigurationBase", "Base map", None))
self.onlyOfflineCopyFeaturesInAoi.setText(_translate("QFieldProjectConfigurationBase", "Only copy features in area of interest", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("QFieldProjectConfigurationBase", "Offline editing", None))
self.unsupportedLayers.setText(_translate("QFieldProjectConfigurationBase", "Unsupported layers", None))

from qgis.gui import QgsMapLayerComboBox
17 changes: 9 additions & 8 deletions qfieldsync/ui/project_configuration_dialog_ui5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/project_configuration_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.7
# Created by: PyQt5 UI code generator 5.9.1
#
# WARNING! All changes made in this file will be lost!

Expand All @@ -11,7 +11,7 @@
class Ui_QFieldProjectConfigurationBase(object):
def setupUi(self, QFieldProjectConfigurationBase):
QFieldProjectConfigurationBase.setObjectName("QFieldProjectConfigurationBase")
QFieldProjectConfigurationBase.resize(608, 510)
QFieldProjectConfigurationBase.resize(543, 510)
self.gridLayout = QtWidgets.QGridLayout(QFieldProjectConfigurationBase)
self.gridLayout.setObjectName("gridLayout")
self.groupBox = QtWidgets.QGroupBox(QFieldProjectConfigurationBase)
Expand All @@ -34,13 +34,12 @@ def setupUi(self, QFieldProjectConfigurationBase):
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 3, 0, 1, 1)
self.gridLayout.addWidget(self.buttonBox, 4, 0, 1, 1)
self.tabWidget = QtWidgets.QTabWidget(QFieldProjectConfigurationBase)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.gridLayout_4 = QtWidgets.QGridLayout(self.tab)
self.gridLayout_4.setContentsMargins(0, 0, 0, 0)
self.gridLayout_4.setObjectName("gridLayout_4")
self.createBaseMapGroupBox = QtWidgets.QGroupBox(self.tab)
self.createBaseMapGroupBox.setCheckable(True)
Expand Down Expand Up @@ -86,7 +85,6 @@ def setupUi(self, QFieldProjectConfigurationBase):
self.singleLayerPage.setSizePolicy(sizePolicy)
self.singleLayerPage.setObjectName("singleLayerPage")
self.formLayout = QtWidgets.QFormLayout(self.singleLayerPage)
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.formLayout.setObjectName("formLayout")
self.label_2 = QtWidgets.QLabel(self.singleLayerPage)
self.label_2.setObjectName("label_2")
Expand Down Expand Up @@ -115,19 +113,21 @@ def setupUi(self, QFieldProjectConfigurationBase):
self.buttonGroup.addButton(self.singleLayerRadioButton)
self.gridLayout_3.addWidget(self.singleLayerRadioButton, 0, 0, 1, 1)
self.gridLayout_4.addWidget(self.createBaseMapGroupBox, 0, 0, 1, 1)
self.singleLayerRadioButton.raise_()
self.createBaseMapGroupBox.raise_()
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.gridLayout_5 = QtWidgets.QGridLayout(self.tab_2)
self.gridLayout_5.setContentsMargins(0, 0, 0, 0)
self.gridLayout_5.setObjectName("gridLayout_5")
self.onlyOfflineCopyFeaturesInAoi = QtWidgets.QCheckBox(self.tab_2)
self.onlyOfflineCopyFeaturesInAoi.setObjectName("onlyOfflineCopyFeaturesInAoi")
self.gridLayout_5.addWidget(self.onlyOfflineCopyFeaturesInAoi, 0, 0, 1, 1)
self.tabWidget.addTab(self.tab_2, "")
self.gridLayout.addWidget(self.tabWidget, 1, 0, 1, 1)
self.unsupportedLayers = QtWidgets.QLabel(QFieldProjectConfigurationBase)
self.unsupportedLayers.setTextFormat(QtCore.Qt.RichText)
self.unsupportedLayers.setWordWrap(True)
self.unsupportedLayers.setObjectName("unsupportedLayers")
self.gridLayout.addWidget(self.unsupportedLayers, 3, 0, 1, 1)

self.retranslateUi(QFieldProjectConfigurationBase)
self.tabWidget.setCurrentIndex(0)
Expand Down Expand Up @@ -158,5 +158,6 @@ def retranslateUi(self, QFieldProjectConfigurationBase):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("QFieldProjectConfigurationBase", "Base map"))
self.onlyOfflineCopyFeaturesInAoi.setText(_translate("QFieldProjectConfigurationBase", "Only copy features in area of interest"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("QFieldProjectConfigurationBase", "Offline editing"))
self.unsupportedLayers.setText(_translate("QFieldProjectConfigurationBase", "Unsupported layers"))

from qgis.gui import QgsMapLayerComboBox
2 changes: 1 addition & 1 deletion qfieldsync/ui/synchronize_dialog_ui4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/synchronize_dialog.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!

Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/ui/synchronize_dialog_ui5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/synchronize_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.7
# Created by: PyQt5 UI code generator 5.9.1
#
# WARNING! All changes made in this file will be lost!

Expand Down

0 comments on commit 39cfc70

Please sign in to comment.