def addAttributes(self, attributes, vectorLayerDescriptor): for attribute in attributes: # : :type attribute: QgsField vectorLayerDescriptor.addAttribute(GeoCSVAttribute.createFromQgsField(attribute)) try: self.csvDataSourceHandler.updateCsvtFile(vectorLayerDescriptor.getAttributeTypes()) NotificationHandler.pushInfo(QApplication.translate('GeoCsvNewController', 'CSVT File created/updated.'), QApplication.translate('GeoCsvNewController', 'The CSVT file was successfully created/updated on disk.')) except: NotificationHandler.pushWarning(QApplication.translate('GeoCsvNewController', 'CSVT File Error'), QApplication.translate('GeoCsvNewController', 'An error occured while trying to update the CSVT file according to the new attribute types. Please update the csvt file manually.'))
def _onCharsetConvert(self): csvFilePath = self.newDialog.filePath.text() encoding = self.newDialog.charsetDropDown.currentText() try: GeoCsvDataSourceHandler.createBackupFile(csvFilePath) NotificationHandler.pushInfo(QApplication.translate('GeoCsvNewController', 'backup created'), QApplication.translate('GeoCsvNewController', 'Created backup on "{}"').format(csvFilePath)) GeoCsvDataSourceHandler.convertFileToUTF8(csvFilePath, encoding) NotificationHandler.pushSuccess(QApplication.translate('GeoCsvNewController', 'Converted'), QApplication.translate('GeoCsvNewController', 'Successfully converted to utf-8')) self._analyseCsv() except: self.newDialog.statusNotificationLabel.setText(QApplication.translate('GeoCsvNewController', 'error in converting'))
def deleteAttributes(self, attributeIds, vectorLayerDescriptor): try: for attributeId in attributeIds: vectorLayerDescriptor.deleteAttributeAtIndex(attributeId) except: QMessageBox.information(None, QApplication.translate('VectorLayerSaveConflictController', 'Error while updating attributes happend'), QApplication.translate('VectorLayerSaveConflictController', 'An error occured while trying to update the attributes list. Nothing has been stored on disk.')) else: try: self.csvDataSourceHandler.updateCsvtFile(vectorLayerDescriptor.getAttributeTypes()) NotificationHandler.pushInfo(QApplication.translate('GeoCsvNewController', 'CSVT File created/updated.'), QApplication.translate('GeoCsvNewController', 'The CSVT file was successfully created/updated on disk.')) except: QMessageBox.information(None, QApplication.translate('VectorLayerSaveConflictController', 'CSVT file could not be updated'), QApplication.translate('VectorLayerSaveConflictController', 'An error occured while trying to update the CSVT file according to the new attribute types. Please update the csvt file manually.'))
def createCsvVectorLayer(self, csvVectorLayers, qgsVectorLayer=None, customTitle=None): if self.newDialog.isVisible(): self.newDialog.reject() # enable help hyperlink self.newDialog.helpLabel.setOpenExternalLinks(True) self.dataSourceHandler = None self.vectorDescriptor = None self.csvtFileIsDirty = False if customTitle: self.newDialog.setWindowTitle(customTitle) if qgsVectorLayer: csvPath = qgsVectorLayer.customProperty('editablegeocsv_path') if csvPath: self.newDialog.filePath.setText(csvPath) self._updateAcceptButton() self._analyseCsv() self.newDialog.show() #wait for user input result = self.newDialog.exec_() #if user pressed ok if result == 1: if self.dataSourceHandler and self.vectorDescriptor: csvVectorLayer = GeoCsvVectorLayerFactory.createCsvVectorLayer(self.dataSourceHandler, self.vectorDescriptor, qgsVectorLayer) vectorLayerController = VectorLayerController(csvVectorLayer, self.dataSourceHandler) csvVectorLayer.initController(vectorLayerController) QgsMapLayerRegistry.instance().addMapLayer(csvVectorLayer.qgsVectorLayer) NotificationHandler.pushSuccess(QApplication.translate('GeoCsvNewController', 'GeoCSV Layer created'), QApplication.translate('GeoCsvNewController', 'The layer "{}" was created successfully.').format(csvVectorLayer.qgsVectorLayer.name())) csvVectorLayers.append(csvVectorLayer) if self.csvtFileIsDirty: try: self.dataSourceHandler.updateCsvtFile(self.vectorDescriptor.getAttributeTypes()) NotificationHandler.pushInfo(QApplication.translate('GeoCsvNewController', 'CSVT File created/updated.'), QApplication.translate('GeoCsvNewController', 'The CSVT file was successfully created/updated on disk.')) except FileIOException: NotificationHandler.pushWarning(QApplication.translate('GeoCsvNewController', 'CSVT File Error'), QApplication.translate('GeoCsvNewController', 'The csvt file couldn\'t be updated on disk.')) if not self.dataSourceHandler.hasPrj(): self.dataSourceHandler.updatePrjFile(csvVectorLayer.qgsVectorLayer.crs().toWkt()) NotificationHandler.pushInfo(QApplication.translate('GeoCsvNewController', 'PRJ File created.'), QApplication.translate('GeoCsvNewController', 'The PRJ file was successfully created on disk.'))