def __init__(self, uri='', providerOptions=QgsDataProvider.ProviderOptions()): """ :param uri: <app>.<model>[?geofield=<name>] :param providerOptions: """ super().__init__(uri) self._is_valid = False self.setNativeTypes(( # TODO QgsVectorDataProvider.NativeType('Integer', 'integer', QVariant.Int, -1, -1, 0, 0), QgsVectorDataProvider.NativeType('Text', 'text', QVariant.String, -1, -1, -1, -1), )) self._uri = uri url = QUrl(uri) url_query = QUrlQuery(url) self._full_model_name = url.path() self._app_label, self._model_name = self._full_model_name.split('.') self._model = apps.get_model(self._app_label, self._model_name) # Django model self._meta = self._model._meta self._qgis_fields = QgsFields() self._django_fields = [] # Django fields represented by provider in the same order as QgsFields for django_field in self._meta.get_fields(): # TODO: more field types qgis_field = self._get_qgis_field_from_django_field(django_field) if qgis_field: self._qgis_fields.append(qgis_field) self._django_fields.append(django_field) self._geo_field_name = url_query.queryItemValue('geofield') self._geo_field = None # Django geometry field if self._geo_field_name: self._meta.get_field(self._geo_field_name) else: # If geometry field was not specified in uri, use the first one if any. for field in self._meta.get_fields(): if isinstance(field, models.GeometryField): self._geo_field = field self._geo_field_name = field.name break self._wkbType = QgsWkbTypes.NoGeometry if self._geo_field: for geo_field_class in wkb_types.keys(): if isinstance(self._geo_field, geo_field_class): self._wkbType = wkb_types[geo_field_class] break self._extent = QgsRectangle() self._crs = None if self._geo_field: self._crs = QgsCoordinateReferenceSystem.fromEpsgId(self._geo_field.srid) self._provider_options = providerOptions self._is_valid = True
def populateEncodings(self): # populate the combo with supported encodings self.cboEncoding.addItems(QgsVectorDataProvider.availableEncodings()) # set the last used encoding enc = self.inLayer.dataProvider().encoding() idx = self.cboEncoding.findText(enc) if idx < 0: self.cboEncoding.insertItem(0, enc) idx = 0 self.cboEncoding.setCurrentIndex(idx)
def populateEncodings(self): # populate the combo with supported encodings self.cboEncoding.addItems(QgsVectorDataProvider.availableEncodings()) # set the last used encoding enc = self.inLayer.dataProvider().encoding() idx = self.cboEncoding.findText(enc) if idx < 0: self.cboEncoding.insertItem(0, enc) idx = 0 self.cboEncoding.setCurrentIndex(idx)
def setupUi(self): ''' set up the ui, fill it with dynamic content and connect all interactive ui elements with actions ''' # connect buttons self.import_csv_button.clicked.connect(self.import_csv) self.export_csv_button.clicked.connect(self.export_csv) self.attribute_table_button.clicked.connect(self.show_attribute_table) self.request_start_button.clicked.connect(self.bkg_geocode) self.request_stop_button.clicked.connect(lambda: self.geocoding.kill()) self.request_stop_button.setVisible(False) self.help_button.clicked.connect(self.show_help) self.about_button.clicked.connect(self.show_about) # only vector layers as input self.layer_combo.setFilters(QgsMapLayerProxyModel.VectorLayer) self.layer_combo.layerChanged.connect(self.change_layer) # input layer encodings for encoding in QgsVectorDataProvider.availableEncodings(): self.encoding_combo.addItem(encoding) self.encoding_combo.currentTextChanged.connect(self.set_encoding) self.setup_crs() # initially set the first layer in the combobox as input self.change_layer(self.layer_combo.currentLayer()) # "Regionalschlüssel" filter self.rs_combo.addItem('Eingabehilfe Bundesländer') self.rs_combo.model().item(0).setEnabled(False) for name, rs in RS_PRESETS: self.rs_combo.addItem(name, rs) self.rs_combo.currentIndexChanged.connect( lambda: self.rs_edit.setText(self.rs_combo.currentData())) def rs_finished(): self.rs_combo.blockSignals(True) self.rs_combo.setCurrentIndex(0) self.rs_combo.blockSignals(False) self.rs_edit.editingFinished.connect(rs_finished) def set_rs(rs): valid = self.check_rs(rs) self.rs_error_label.setVisible(not valid and self.use_rs_check.isChecked()) self.rs_edit.textChanged.connect(set_rs) self.use_rs_check.toggled.connect(lambda: set_rs(self.rs_edit.text())) # spatial filter # only polygons can be used as a spatial filter self.spatial_filter_combo.setFilters( QgsMapLayerProxyModel.PolygonLayer) # connect map tools self.inspect_picker = FeaturePicker(self.inspect_picker_button, canvas=self.canvas) self.inspect_picker.feature_picked.connect(self.inspect_results) self.reverse_picker = FeatureDragger(self.reverse_picker_button, canvas=self.canvas) self.reverse_picker.feature_dragged.connect(self.inspect_neighbours) self.reverse_picker_button.setEnabled(False) self.inspect_picker_button.setEnabled(False) self.export_csv_button.setEnabled(False) self.attribute_table_button.setEnabled(False) # initialize the timer running when geocoding self.timer = QTimer(self) self.timer.timeout.connect(self.update_timer) self._dragged_feature = None # unregister layers from plugin when they are removed from QGIS # avoids errors when user is messing around in the QGIS UI QgsProject.instance().layersRemoved.connect(self.unregister_layers)
def __init__(self, parent=None): QDialog.__init__(self, parent) self.ui = Ui_QgsNewVectorLayerDialogBase() self.ui.setupUi(self) # self.ui.mAddAttributeButton.setIcon(QIcon("Resource/images/themes/default/mActionNewAttribute.svg")) # self.ui.mRemoveAttributeButton.setIcon(QIcon("Resource/images/themes/default/mActionDeleteAttribute.svg")) self.ui.mTypeBox.addItem("Text data", "String") self.ui.mTypeBox.addItem("Whole number", "Integer") self.ui.mTypeBox.addItem("Decimal number", "Real") self.ui.mTypeBox.addItem("Date", "Date") self.ui.mWidth.setValidator(QIntValidator(1, 255, self)) self.ui.mPrecision.setValidator(QIntValidator(0, 15, self)) self.ui.mPointRadioButton.setChecked(True) self.ui.mFileFormatComboBox.addItem("ESRI Shapefile", "ESRI Shapefile") # self.ui.mFileFormatComboBox.addItem("Comma Separated Value", "Comma Separated Value") # self.ui.mFileFormatComboBox.addItem("GML", "GML") # self.ui.mFileFormatComboBox.addItem("Mapinfo File", "Mapinfo File") #endif if (self.ui.mFileFormatComboBox.count() == 1): self.ui.mFileFormatComboBox.setVisible(False) self.ui.mFileFormatLabel.setVisible(False) self.ui.mFileFormatComboBox.setCurrentIndex(0) self.ui.mFileEncoding.addItems( QgsVectorDataProvider.availableEncodings()) # Use default encoding if none supplied # enc = QSettings().value( "/UI/encoding", "System" ).toString() # The specified decoding is added if not existing alread, and then set current. # This should select it. # int encindex = self.ui.mFileEncoding.findText( enc ) # if ( encindex < 0 ) # { # self.ui.mFileEncoding.insertItem( 0, enc ) # encindex = 0 # } # self.ui.mFileEncoding.setCurrentIndex( encindex ) self.ui.mAttributeView.addTopLevelItem( QTreeWidgetItem(QStringList(["id", "Integer", "10", ""]))) # defaultCrs = QgsCRSCache::instance().crsByOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() ) # defaultCrs.validate() if define._units == QGis.Meters: defaultCrs = define._xyCrs else: defaultCrs = define._latLonCrs self.ui.mCrsSelector.setCrs(defaultCrs) self.connect(self.ui.mNameEdit, SIGNAL("textChanged( QString )"), self.nameChanged) self.connect(self.ui.mAttributeView, SIGNAL("itemSelectionChanged()"), self.selectionChanged) self.ui.mAddAttributeButton.setEnabled(False) self.ui.mRemoveAttributeButton.setEnabled(False) self.ui.mAddAttributeButton.clicked.connect( self.mAddAttributeButtonClicked) self.ui.mRemoveAttributeButton.clicked.connect( self.mRemoveAttributeButtonClicked) self.ui.mTypeBox.currentIndexChanged.connect( self.mTypeBoxCrrentIndexChanged) self.ui.mFileFormatComboBox.currentIndexChanged.connect( self.mFileFormatComboBoxCurrentIndexChanged)