예제 #1
0
 def populateFieldTable(self):
     if self.collectedDataDict:
         importingFields = self.collectedDataDict[0].keys()
         self.fieldTable.clear()
         self.fieldTable.setRowCount(len(importingFields))
         predefinedFields = ['EOMETRY','ODKUUID']
         for row,field in enumerate(importingFields):
             enabledItem = QTableWidgetItem()
             enabledItem.setFlags(enabledItem.flags() | Qt.ItemIsUserCheckable)
             enabledItem.setText("")
             self.fieldTable.setItem(row,0,enabledItem)
             ODKfieldItem = QTableWidgetItem()
             ODKfieldItem.setText(field)
             self.fieldTable.setItem(row,1,ODKfieldItem)
             self.fieldTable.setRowHeight(row,30)
             QGISfieldItem = QTableWidgetItem()
             if slugify(field) in self.fieldMapping:
                 QGISfieldItem.setText(self.fieldMapping[slugify(field)])
                 enabledItem.setCheckState(Qt.Checked)
             else:
                 QGISfieldItem.setText("")
                 enabledItem.setCheckState(Qt.Unchecked)
             self.fieldTable.setItem(row,2,QGISfieldItem)
             if field[-7:] in predefinedFields: #prevent predefined fields user editing
                 if field[-7:] == 'ODKUUID':
                     ODKfieldItem.setText('ODKUUID')
                 enabledItem.setCheckState(Qt.Checked)
                 enabledItem.setFlags(enabledItem.flags() & Qt.ItemIsEditable)
                 ODKfieldItem.setFlags(ODKfieldItem.flags() & Qt.ItemIsEditable)
                 QGISfieldItem.setFlags(QGISfieldItem.flags() & Qt.ItemIsEditable)
예제 #2
0
 def checkSyncroAction(self):
     if self.syncroCheckBox.isChecked():
         self.layerComboBox.setEnabled(True)
         try:
             self.layerComboBox.currentIndexChanged.disconnect(
                 self.layerComboBoxChanged)
         except:
             pass
         self.layerComboBox.clear()
         for layer in self.iface.legendInterface().layers():
             if layer.type() == QgsMapLayer.VectorLayer:
                 self.layerComboBox.addItem(layer.name(), layer.id())
         if self.iface.legendInterface().currentLayer():
             current_idx = self.layerComboBox.findData(
                 self.iface.legendInterface().currentLayer().id())
             if current_idx != -1:
                 self.layerComboBox.setCurrentIndex(current_idx)
         self.layerComboBox.currentIndexChanged.connect(
             self.layerComboBoxChanged)
         self.layerComboBoxChanged()
     else:
         self.layerComboBox.setEnabled(False)
         self.fieldMapping = {}
         for field in self.module.dlg.treeView.getFieldMappingDict().values(
         ):
             if field != '':
                 self.fieldMapping[slugify(field)] = field
         self.processingLayer = None
         self.populateFieldTable()
예제 #3
0
 def layerComboBoxChanged(self):
     '''
     if another layer is selected the currentlayerfields is updated 
     '''
     currentLayer = self.getCurrentLayer()
     currentLayerFields = {}
     for field in currentLayer.pendingFields():
         currentLayerFields[slugify(field.name())]=field.name() #dict with key slugified to simplify name match
     self.fieldMapping = currentLayerFields
     self.populateFieldTable()
예제 #4
0
    def populateFieldTable(self):
        if self.collectedDataDict:
            importingFields = self.collectedDataDict[0].keys()
            self.fieldTable.clear()
            self.fieldTable.setRowCount(len(importingFields))
            predefinedFields = ['EOMETRY','UUID']
            for row,field in enumerate(importingFields):
                enabledItem = QTableWidgetItem()
                enabledItem.setFlags(enabledItem.flags() | Qt.ItemIsUserCheckable)
                enabledItem.setText("")
                self.fieldTable.setItem(row,0,enabledItem)
                ODKfieldItem = QTableWidgetItem()
                ODKfieldItem.setText(field)
                self.fieldTable.setItem(row,1,ODKfieldItem)
                self.fieldTable.setRowHeight(row,30)
                QGISfieldItem = QTableWidgetItem()
                
                # try to guess field mapping
                QGISfieldItem.setText("")
                enabledItem.setCheckState(Qt.Unchecked)
                for fieldOrigin, FieldDest in self.fieldMapping.iteritems():
                    if fieldOrigin in slugify(field):
                        QGISfieldItem.setText(FieldDest)
                        enabledItem.setCheckState(Qt.Checked)
                        break

                '''
                if slugify(field) in self.fieldMapping:
                    QGISfieldItem.setText(self.fieldMapping[slugify(field)])
                    enabledItem.setCheckState(Qt.Checked)
                else:
                    QGISfieldItem.setText("")
                    enabledItem.setCheckState(Qt.Unchecked)
                '''

                self.fieldTable.setItem(row,2,QGISfieldItem)
                for predef in predefinedFields:
                    if predef in field.upper(): #prevent predefined fields user editing
                        if predef == 'UUID':
                            ODKfieldItem.setText(field)
                            QGISfieldItem.setText('ODKUUID')
                        elif predef == 'EOMETRY':
                            ODKfieldItem.setText('GEOMETRY')
                            QGISfieldItem.setText('GEOMETRY')
                        enabledItem.setCheckState(Qt.Checked)
                        enabledItem.setFlags(enabledItem.flags() & Qt.ItemIsEditable)
                        ODKfieldItem.setFlags(ODKfieldItem.flags() & Qt.ItemIsEditable)
                        QGISfieldItem.setFlags(QGISfieldItem.flags() & Qt.ItemIsEditable)