def test03_SaveRestoreBasemapsFromProject(self): """Test saving and restoring enabled basemaps from project""" self.assertEqual(WRITER_REGISTRY.getBasemapsFromProject(), []) WRITER_REGISTRY.saveBasemapsToProject(['a', 'b c d']) self.assertEqual(WRITER_REGISTRY.getBasemapsFromProject(), ['a', 'b c d']) # no existing settings QgsProject.instance().removeEntry("qgis2web", "/") self.assertEqual(WRITER_REGISTRY.getBasemapsFromProject(), [])
def test06_SaveRestoreWriterFromProject(self): """Test saving and restoring writer state to project""" writer = LeafletWriter() writer.params = getDefaultParams() # change some parameters writer.params['Appearance']['Add layers list'] = 'Collapsed' writer.params['Data export']['Minify GeoJSON files'] = False writer.params['Data export']['Precision'] = '4' WRITER_REGISTRY.saveWriterToProject(writer) new_writer = WRITER_REGISTRY.createWriterFromProject() self.assertTrue( isinstance(new_writer, LeafletWriter)) self.assertEqual(new_writer.params,writer.params)
def test06_SaveRestoreWriterFromProject(self): """Test saving and restoring writer state to project""" writer = LeafletWriter() writer.params = getDefaultParams() # change some parameters writer.params['Appearance']['Add layers list'] = 'Collapsed' writer.params['Data export']['Minify GeoJSON files'] = False writer.params['Data export']['Precision'] = '4' WRITER_REGISTRY.saveWriterToProject(writer) new_writer = WRITER_REGISTRY.createWriterFromProject() self.assertTrue(isinstance(new_writer, LeafletWriter)) self.assertEqual(new_writer.params, writer.params)
def test05_SaveRestoreParamsFromProject(self): """Test saving and restoring parameters from project""" # no settings in project, should match defaults QgsProject.instance().removeEntry("qgis2web", "/") params = WRITER_REGISTRY.readParamsFromProject() self.maxDiff = 1000000000 self.assertEqual(params, getDefaultParams()) # change some parameters (one of each type) params['Appearance']['Add layers list'] = 'Collapsed' params['Data export']['Minify GeoJSON files'] = False # no ints in config yet! # params['Test']['test int'] = 5 params['Data export']['Precision'] = '4' # no strings in config yet! # params['Test']['test string'] ='test' WRITER_REGISTRY.saveParamsToProject(params) restored_params = WRITER_REGISTRY.readParamsFromProject() self.assertEqual(restored_params, params)
def test05_SaveRestoreParamsFromProject(self): """Test saving and restoring parameters from project""" # no settings in project, should match defaults QgsProject.instance().removeEntry("qgis2web", "/") params = WRITER_REGISTRY.readParamsFromProject() self.maxDiff = 1000000000 self.assertEqual(params, getDefaultParams() ) # change some parameters (one of each type) params['Appearance']['Add layers list'] = 'Collapsed' params['Data export']['Minify GeoJSON files'] = False # no ints in config yet! # params['Test']['test int'] = 5 params['Data export']['Precision'] = '4' # no strings in config yet! # params['Test']['test string'] ='test' WRITER_REGISTRY.saveParamsToProject(params) restored_params = WRITER_REGISTRY.readParamsFromProject() self.assertEqual(restored_params,params)
def test02_SaveRestoreWriterTypeFromProject(self): """Test saving and restoring writer type from project""" WRITER_REGISTRY.saveTypeToProject(OpenLayersWriter.type()) self.assertEqual(WRITER_REGISTRY.getWriterFactoryFromProject(), OpenLayersWriter) WRITER_REGISTRY.saveTypeToProject(LeafletWriter.type()) self.assertEqual(WRITER_REGISTRY.getWriterFactoryFromProject(), LeafletWriter) # no existing settings QgsProject.instance().removeEntry("qgis2web", "/") self.assertEqual(WRITER_REGISTRY.getWriterFactoryFromProject(), OpenLayersWriter)
def test02_SaveRestoreWriterTypeFromProject(self): """Test saving and restoring writer type from project""" WRITER_REGISTRY.saveTypeToProject(OpenLayersWriter.type()) self.assertEqual( WRITER_REGISTRY.getWriterFactoryFromProject(), OpenLayersWriter) WRITER_REGISTRY.saveTypeToProject(LeafletWriter.type()) self.assertEqual( WRITER_REGISTRY.getWriterFactoryFromProject(), LeafletWriter) # no existing settings QgsProject.instance().removeEntry("qgis2web", "/") self.assertEqual( WRITER_REGISTRY.getWriterFactoryFromProject(), OpenLayersWriter)
def __init__(self, iface, parent=None): super(MainDialog, self).__init__(parent) QDialog.__init__(self) self.setupUi(self) self.iface = iface self.previewUrl = None self.layer_search_combo = None self.layer_filter_select = None self.exporter_combo = None self.feedback = FeedbackDialog(self) self.feedback.setModal(True) stgs = QSettings() self.restoreGeometry( stgs.value("qgis2web/MainDialogGeometry", QByteArray(), type=QByteArray)) self.verticalLayout_2.addStretch() self.horizontalLayout_6.addStretch() if stgs.value("qgis2web/previewOnStartup", Qt.Checked) == Qt.Checked: self.previewOnStartup.setCheckState(Qt.Checked) else: self.previewOnStartup.setCheckState(Qt.Unchecked) if stgs.value("qgis2web/closeFeedbackOnSuccess", Qt.Checked) == Qt.Checked: self.closeFeedbackOnSuccess.setCheckState(Qt.Checked) else: self.closeFeedbackOnSuccess.setCheckState(Qt.Unchecked) self.previewFeatureLimit.setText( stgs.value("qgis2web/previewFeatureLimit", "1000")) self.appearanceParams.setSelectionMode( QAbstractItemView.SingleSelection) self.preview = None if webkit_available: widget = QWebView() self.preview = widget try: # if os.environ["TRAVIS"]: self.preview.setPage(WebPage()) except Exception: print("Failed to set custom webpage") webview = self.preview.page() webview.setNetworkAccessManager(QgsNetworkAccessManager.instance()) self.preview.settings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True) self.preview.settings().setAttribute( QWebSettings.DnsPrefetchEnabled, True) else: widget = QTextBrowser() widget.setText( self.tr('Preview is not available since QtWebKit ' 'dependency is missing on your system')) self.right_layout.insertWidget(0, widget) self.populateConfigParams(self) self.populate_layers_and_groups(self) self.populateLayerSearch() self.populateAttrFilter() writer = WRITER_REGISTRY.createWriterFromProject() self.setStateToWriter(writer) self.exporter = EXPORTER_REGISTRY.createFromProject() self.exporter_combo.setCurrentIndex( self.exporter_combo.findText(self.exporter.name())) self.exporter_combo.currentIndexChanged.connect( self.exporterTypeChanged) self.toggleOptions() if webkit_available: if self.previewOnStartup.checkState() == Qt.Checked: self.autoUpdatePreview() self.buttonPreview.clicked.connect(self.previewMap) else: self.buttonPreview.setDisabled(True) QgsProject.instance().cleared.connect(self.reject) self.layersTree.model().dataChanged.connect(self.populateLayerSearch) self.layersTree.model().dataChanged.connect(self.populateAttrFilter) self.ol3.clicked.connect(self.changeFormat) self.leaflet.clicked.connect(self.changeFormat) self.mapbox.clicked.connect(self.changeFormat) self.buttonExport.clicked.connect(self.saveMap) helpText = os.path.join(os.path.dirname(os.path.realpath(__file__)), "helpFile.md") self.helpField.setSource(QUrl.fromLocalFile(helpText)) if webkit_available: self.devConsole = QWebInspector(self.preview) self.devConsole.setFixedHeight(0) self.devConsole.setObjectName("devConsole") self.devConsole.setPage(self.preview.page()) self.devConsole.hide() self.right_layout.insertWidget(1, self.devConsole) self.filter = devToggleFilter() self.filter.devToggle.connect(self.showHideDevConsole) self.installEventFilter(self.filter) self.setModal(False)
def saveParameters(self): """ Saves current dialog state to project """ WRITER_REGISTRY.saveWriterToProject(self.createWriter()) EXPORTER_REGISTRY.writeToProject(self.exporter)
def test04_SanitiseKey(self): """Test sanitising param key for storage""" self.assertEqual(WRITER_REGISTRY.sanitiseKey('a'), 'a') self.assertEqual(WRITER_REGISTRY.sanitiseKey('a b'), 'ab')
def test01_RegistryHasExporters(self): """test that writer registry is populated with writers""" self.assertTrue(OpenLayersWriter in WRITER_REGISTRY.getWriters())
def __init__(self, iface): QDialog.__init__(self) self.setupUi(self) self.iface = iface self.previewUrl = None self.layer_search_combo = None self.exporter_combo = None self.feedback = FeedbackDialog(self) self.feedback.setModal(True) stgs = QSettings() self.restoreGeometry(stgs.value("qgis2web/MainDialogGeometry", QByteArray(), type=QByteArray)) if stgs.value("qgis2web/previewOnStartup", Qt.Checked) == Qt.Checked: self.previewOnStartup.setCheckState(Qt.Checked) else: self.previewOnStartup.setCheckState(Qt.Unchecked) if (stgs.value("qgis2web/closeFeedbackOnSuccess", Qt.Checked) == Qt.Checked): self.closeFeedbackOnSuccess.setCheckState(Qt.Checked) else: self.closeFeedbackOnSuccess.setCheckState(Qt.Unchecked) self.previewFeatureLimit.setText( stgs.value("qgis2web/previewFeatureLimit", "1000")) self.paramsTreeOL.setSelectionMode(QAbstractItemView.SingleSelection) self.preview = None if webkit_available: widget = QWebView() self.preview = widget try: # if os.environ["TRAVIS"]: self.preview.setPage(WebPage()) except: print("Failed to set custom webpage") webview = self.preview.page() webview.setNetworkAccessManager(QgsNetworkAccessManager.instance()) self.preview.settings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True) else: widget = QTextBrowser() widget.setText(self.tr('Preview is not available since QtWebKit ' 'dependency is missing on your system')) self.right_layout.insertWidget(0, widget) self.populateConfigParams(self) self.populate_layers_and_groups(self) self.populateLayerSearch() writer = WRITER_REGISTRY.createWriterFromProject() self.setStateToWriter(writer) self.exporter = EXPORTER_REGISTRY.createFromProject() self.exporter_combo.setCurrentIndex( self.exporter_combo.findText(self.exporter.name())) self.exporter_combo.currentIndexChanged.connect( self.exporterTypeChanged) self.toggleOptions() if webkit_available: if self.previewOnStartup.checkState() == Qt.Checked: self.autoUpdatePreview() self.buttonPreview.clicked.connect(self.previewMap) else: self.buttonPreview.setDisabled(True) self.layersTree.model().dataChanged.connect(self.populateLayerSearch) self.ol3.clicked.connect(self.changeFormat) self.leaflet.clicked.connect(self.changeFormat) self.buttonExport.clicked.connect(self.saveMap) helpText = os.path.join(os.path.dirname(os.path.realpath(__file__)), "helpFile.md") self.helpField.setSource(QUrl.fromLocalFile(helpText)) if webkit_available: self.devConsole = QWebInspector(self.verticalLayoutWidget_2) self.devConsole.setFixedHeight(0) self.devConsole.setObjectName("devConsole") self.devConsole.setPage(self.preview.page()) self.devConsole.hide() self.right_layout.insertWidget(1, self.devConsole) self.filter = devToggleFilter() self.filter.devToggle.connect(self.showHideDevConsole) self.installEventFilter(self.filter) self.setModal(False)
def test04_SanitiseKey(self): """Test sanitising param key for storage""" self.assertEqual(WRITER_REGISTRY.sanitiseKey('a'),'a') self.assertEqual(WRITER_REGISTRY.sanitiseKey('a b'),'ab')