Python qgis.PyQt.QtWidgets.QTableWidgetItem() Examples

The following are 16 code examples of qgis.PyQt.QtWidgets.QTableWidgetItem(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module qgis.PyQt.QtWidgets , or try the search function .
Example #1
Source File: multizoom.py    From qgis-latlontools-plugin with GNU General Public License v2.0 6 votes vote down vote up
def settingsChanged(self):
        self.initLabel()
        if self.numCol != self.settings.multiZoomNumCol + 3:
            # The number of columns have changed
            self.numCol = 3 + self.settings.multiZoomNumCol
            self.resultsTable.blockSignals(True)
            self.resultsTable.setColumnCount(self.numCol)
            self.resultsTable.setHorizontalHeaderLabels(LABELS[0:self.numCol])
            rowcnt = self.resultsTable.rowCount()
            for i in range(rowcnt):
                item = self.resultsTable.item(i, 0).data(Qt.UserRole)
                if self.numCol > 3:
                    for j in range(3, self.numCol):
                        self.resultsTable.setItem(i, j, QTableWidgetItem(item.data[j - 3]))

            self.resultsTable.clearSelection()
            self.resultsTable.blockSignals(False)
            self.geomChanged()
            self.updateDisplayedMarkers() 
Example #2
Source File: multizoom.py    From qgis-latlontools-plugin with GNU General Public License v2.0 6 votes vote down vote up
def addCoord(self, lat, lon, label='', data=[]):
        '''Add a coordinate to the list.'''
        rowcnt = self.resultsTable.rowCount()
        if rowcnt >= self.maxResults:
            return
        self.resultsTable.blockSignals(True)
        self.resultsTable.insertRow(rowcnt)
        item = QTableWidgetItem(str(lat))
        item.setData(Qt.UserRole, LatLonItem(lat, lon, label, data))
        item.setFlags(item.flags() & ~Qt.ItemIsEditable)
        self.resultsTable.setItem(rowcnt, 0, item)
        item = QTableWidgetItem(str(lon))
        item.setFlags(item.flags() & ~Qt.ItemIsEditable)
        self.resultsTable.setItem(rowcnt, 1, item)
        self.resultsTable.setItem(rowcnt, 2, QTableWidgetItem(label))
        if self.numCol > 3 and len(data) > 0:
            for i in range(min(self.numCol - 3, len(data))):
                self.resultsTable.setItem(rowcnt, i + 3, QTableWidgetItem(data[i]))

        self.resultsTable.blockSignals(False)
        return(rowcnt) 
Example #3
Source File: HydroSEDPlugin_dockwidget.py    From WMF with GNU General Public License v3.0 6 votes vote down vote up
def NewEntry(self, Dic, DicKey,TabElement, New = False):
        '''Actualiza la lista de las variables en una tabla'''
        #Busca si ese nombre ya se encuentra en la tabla
        try:
            #Si esta, remplaza esa posicion
            pos = self.TabNames.index(DicKey)
            suma = 0
        except:
            #Si no esta, lo pone al final.
            pos = self.NumRows
            self.TabNames.append(DicKey)
            suma = 1
        #for keyParam in Dic:
        if New:
            TabElement.setItem (pos, 0, QTableWidgetItem (Dic["nombre"]+'*'))
        else:
            TabElement.setItem (pos, 0, QTableWidgetItem (Dic["nombre"]))
        TabElement.setItem (pos, 1, QTableWidgetItem (Dic["tipo"]))
        TabElement.setItem (pos, 2, QTableWidgetItem (str (Dic["shape"])))
        TabElement.setItem (pos, 3, QTableWidgetItem (Dic["categoria"]))
        self.NumRows += suma 
Example #4
Source File: photo_naming_widget.py    From qfieldsync with GNU Lesser General Public License v3.0 6 votes vote down vote up
def addLayerFields(self, layer_source):
        layer = layer_source.layer

        if layer.type() != QgsMapLayer.VectorLayer:
            return

        for i, field in enumerate(layer.fields()):
            row = self.rowCount()
            ews = layer.editorWidgetSetup(i)

            if ews.type() == 'ExternalResource':
                # for later: if ews.config().get('DocumentViewer', QgsExternalResourceWidget.NoContent) == QgsExternalResourceWidget.Image:
                self.insertRow(row)
                item = QTableWidgetItem(layer.name())
                item.setData(Qt.UserRole, layer_source)
                self.setItem(row, 0, item)
                item = QTableWidgetItem(field.name())
                self.setItem(row, 1, item)
                ew = QgsFieldExpressionWidget()
                ew.setLayer(layer)
                expression = layer_source.photo_naming(field.name())
                ew.setExpression(expression)
                self.setCellWidget(row, 2, ew)

        self.resizeColumnsToContents() 
Example #5
Source File: viewServers.py    From DsgTools with GNU General Public License v2.0 6 votes vote down vote up
def populateTable(self):
        '''
        Populates the servers table
        '''
        currentConnections = self.getServers()
        self.tableWidget.setRowCount(len(currentConnections))
        for i, connection in enumerate(currentConnections):
            self.tableWidget.setItem(i, 0, QTableWidgetItem(connection))
            (host, port, user, password, isDefault) = self.getServerConfiguration(connection)
            self.tableWidget.setItem(i, 1, QTableWidgetItem(host))
            self.tableWidget.setItem(i, 2, QTableWidgetItem(port))
            self.tableWidget.setItem(i, 3, QTableWidgetItem(user))
            if not password or len(password) == 0:
                self.tableWidget.setItem(i, 4, QTableWidgetItem(self.tr('Not Saved')))
            else:
                self.tableWidget.setItem(i, 4, QTableWidgetItem(self.tr('Saved')))
            radio = QRadioButton(self.tableWidget)
            radio.setAutoExclusive(True)
            if isDefault:
                radio.setChecked(True)
            self.tableWidget.setCellWidget(i, 5, radio) 
Example #6
Source File: viewServers.py    From DsgTools with GNU General Public License v2.0 6 votes vote down vote up
def populateTable(self):
        """
        Populates the servers table
        """
        currentConnections = self.getServers()
        self.tableWidget.setRowCount(len(currentConnections))
        connParam = self.connectionParameters()
        for i, connection in enumerate(currentConnections):
            self.tableWidget.setItem(i, 0, QTableWidgetItem(connection))
            (host, port, user, password, isDefault) = self.getServerConfiguration(connection)
            self.tableWidget.setItem(i, 1, QTableWidgetItem(host))
            self.tableWidget.setItem(i, 2, QTableWidgetItem(port))
            self.tableWidget.setItem(i, 3, QTableWidgetItem(user))
            if not password or len(password) == 0:
                self.tableWidget.setItem(i, 4, QTableWidgetItem(self.tr('Not Saved')))
            else:
                self.tableWidget.setItem(i, 4, QTableWidgetItem(self.tr('Saved')))
            radio = QRadioButton(self.tableWidget)
            radio.setAutoExclusive(True)
            if (not connParam and isDefault) or (connParam and connParam['connection'] == connection):
                radio.setChecked(True)
            self.tableWidget.setCellWidget(i, 5, radio) 
Example #7
Source File: HydroSEDPlugin_dockwidget.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def EditedEntry(self, KeyEdited, TabElement, New_or_Edited = 'Edited'):
        '''Establece en la tabla visual si una entrada ha sido editada'''
        #Encuentra la pos
        pos = self.TabNames.index(KeyEdited)
        #Edita el nombre en la tabla 
        TabElement.setItem(pos, 0, QTableWidgetItem(KeyEdited+'*')) 
Example #8
Source File: HydroSEDPlugin_dockwidget.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def SavedEntry(self, TabElement):
        '''Busca los elementos de la tabla que terminen con * y se los quita, solo para
        que el usuario sepa que han sido guardados'''
        #Busca en cada entrada
        for i in range(self.NumRows):
            Nombre = TabElement.takeItem(i,0).text()
            if Nombre[-1] == '*':
                TabElement.setItem(i,0, QTableWidgetItem(Nombre[:-1]))
            else:
                TabElement.setItem(i,0, QTableWidgetItem(Nombre)) 
Example #9
Source File: searchDialog.py    From qgis-searchlayers-plugin with GNU General Public License v2.0 5 votes vote down vote up
def addFoundItem(self, layer, feature, attrname, value):
        '''We found an item so add it to the found list.'''
        self.resultsTable.insertRow(self.found)
        self.results.append([layer, feature])
        self.resultsTable.setItem(self.found, 0, QTableWidgetItem(value))
        self.resultsTable.setItem(self.found, 1, QTableWidgetItem(layer.name()))
        self.resultsTable.setItem(self.found, 2, QTableWidgetItem(attrname))
        self.resultsTable.setItem(self.found, 3, QTableWidgetItem(str(feature.id())))
        self.found += 1 
Example #10
Source File: geodesicMeasureTool.py    From qgis-shapetools-plugin with GNU General Public License v2.0 5 votes vote down vote up
def unitsChanged(self):
        label = "Distance [{}]".format(DISTANCE_LABELS[self.unitsComboBox.currentIndex()])
        item = QTableWidgetItem(label)
        self.tableWidget.setHorizontalHeaderItem(2, item)
        ptcnt = len(self.capturedPoints)
        if ptcnt >= 2:
            i = 0
            while i < ptcnt - 1:
                item = QTableWidgetItem('{:.4f}'.format(self.unitDistance(self.distances[i])))
                self.tableWidget.setItem(i, 2, item)
                i += 1
            self.formatTotal() 
Example #11
Source File: geodesicMeasureTool.py    From qgis-shapetools-plugin with GNU General Public License v2.0 5 votes vote down vote up
def insertParams(self, position, distance, startAngle, endAngle):
        if position > self.tableWidget.rowCount():
            self.tableWidget.insertRow(position - 1)
        item = QTableWidgetItem('{:.4f}'.format(self.unitDistance(distance)))
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
        self.tableWidget.setItem(position - 1, 2, item)
        item = QTableWidgetItem('{:.4f}'.format(startAngle))
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
        self.tableWidget.setItem(position - 1, 0, item)
        item = QTableWidgetItem('{:.4f}'.format(endAngle))
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
        self.tableWidget.setItem(position - 1, 1, item) 
Example #12
Source File: newDomainWidget.py    From DsgTools with GNU General Public License v2.0 5 votes vote down vote up
def addItemInTableWidget(self, codeText = '', valueText = ''):
        index = self.tableWidget.rowCount()
        self.tableWidget.insertRow(index)
        codeItem = QtGui.QTableWidgetItem(codeText)
        valueItem = QtGui.QTableWidgetItem(valueText)
        self.tableWidget.setItem(self.tableWidget.rowCount()-1, 0, codeItem)
        self.tableWidget.setItem(self.tableWidget.rowCount()-1, 1, valueItem)
        if index == 0:
            self.oldBackground = self.tableWidget.item(0,0).background() 
Example #13
Source File: datasourceInfoTable.py    From DsgTools with GNU General Public License v2.0 5 votes vote down vote up
def addItem(self, row, col, text):
        """
        Gets an item to be added to the table that may be set to not be editable.
        :param row: (int) row index to be added.
        :param col: (int) column index to be added.
        :param text: (str) name to be exposed on table cell.
        :return: (QTableWidgetItem) item added as to table cell.
        """
        item = QtWidgets.QTableWidgetItem()
        item.setText(text)
        item.setFlags(Qt.ItemIsEditable) # not editable
        self.tableWidget.setItem(row, col, item)
        return item 
Example #14
Source File: datasourceConversion.py    From DsgTools with GNU General Public License v2.0 5 votes vote down vote up
def fillOutDsInfoRow(self, row):
        """
        Fills out row with output info for each output column. In here, ouput SRC and EDGV are filled. 
        :param row: (int) row index to have its output columns populated.
        :return: (list-of-object) return a list containing (str) output EDGV version and (QPushButton) output SRC.
        """
        # clear current content, if any
        try:
            self.clearOutDsInforRow(row=row)
        except:
            pass
        # get only outDs widget
        outDs = self.getRowContents(row=row)[DatasourceConversion.OutDs]
        # widget dict keys are defined as group title, which is part of outDs current text
        if outDs:
            groupTitle = outDs.currentText().split(':')[0]
            crsIcon = QIcon(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'icons', 'CRS_qgis.svg'))
        else:
            return []
        if groupTitle in self.outDs:
            containerWidget = self.outDs[groupTitle]
            # only fills line if dictionary is a controlled widget
            # new push button for SRC
            outCrs = QtWidgets.QPushButton()
            outCrs.setIcon(crsIcon)
            # get new text item to add output datasource
            edgvOut = containerWidget.connectionWidget.getDatasourceEdgvVersion()
            edgvOut = edgvOut[5:] if 'EDGV' in edgvOut else edgvOut
            itemEdgvOut = QtWidgets.QTableWidgetItem()
            itemEdgvOut.setText(edgvOut)
            itemEdgvOut.setFlags(Qt.ItemIsEditable) # not editable
            # add both to table
            self.tableWidget.setCellWidget(row, DatasourceConversion.outCrs, outCrs)
            self.tableWidget.setItem(row, DatasourceConversion.OutEdgv, itemEdgvOut)
            return [edgvOut, outCrs]
        else:
            # if is not controlled, clear line
            return [] 
Example #15
Source File: datasourceConversion.py    From DsgTools with GNU General Public License v2.0 5 votes vote down vote up
def addItemToTable(self, col, row, text='', isEditable=True):
        """
        Adds an item to the mapping table into a given column and row.
        :param col: (int) column containing new item.
        :param row: (int) row containing new item.
        :param text: (str) name to be exposed on table cell.
        :param isEditable: (bool) boolean indicating whether cell content should be editable.
        :return: (QTableWidgetItem) item added.
        """
        newItem = self.getNewTableItem(text=text, isEditable=isEditable)
        self.tableWidget.setItem(row, col, newItem)
        return newItem 
Example #16
Source File: code_list.py    From DsgTools with GNU General Public License v2.0 5 votes vote down vote up
def populateFieldsTable(self):
        """
        Populates field map to codelist table.
        """
        fieldMap = self.currentFieldMap()
        self.tableWidget.setRowCount(len(fieldMap))
        for row, (code, value) in enumerate(fieldMap.items()):
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            self.tableWidget.setItem(row, 1, QTableWidgetItem(code))
        self.tableWidget.sortItems(1)