def __init__(self, results, onlySymbology, geodataServer, metadataServer,
              parent):
     super(PublishReportDialog, self).__init__(parent)
     self.results = results
     self.setupUi(self)
     self.tableWidget.horizontalHeader().setSectionResizeMode(
         QHeaderView.Stretch)
     if geodataServer is not None:
         url = geodataServer.url
         self.labelUrlMapServer.setText('<a href="%s">%s</a>' % (url, url))
     else:
         self.labelUrlMapServer.setText("----")
     if metadataServer is not None:
         url = metadataServer.url
         self.labelUrlMetadataServer.setText('<a href="%s">%s</a>' %
                                             (url, url))
     else:
         self.labelUrlMetadataServer.setText("----")
     publishData = geodataServer is not None
     self.labelPublishMapData.setText(
         "ON" if publishData and not onlySymbology else "OFF")
     self.labelPublishSymbology.setText("ON" if publishData else "OFF")
     self.labelPublishMetadata.setText(
         "ON" if metadataServer is not None else "OFF")
     self.tableWidget.setRowCount(len(results))
     for i, name in enumerate(results.keys()):
         warnings, errors = results[name]
         item = QTableWidgetItem(name)
         item.setFlags(item.flags() ^ Qt.ItemIsEditable)
         self.tableWidget.setItem(i, 0, item)
         if geodataServer is not None:
             dataPublished = geodataServer.layerExists(name)
             stylePublished = geodataServer.styleExists(name)
         else:
             dataPublished = False
             stylePublished = False
         item = QTableWidgetItem("Yes" if dataPublished else "No")
         item.setFlags(item.flags() ^ Qt.ItemIsEditable)
         self.tableWidget.setItem(i, 1, item)
         item = QTableWidgetItem("Yes" if stylePublished else "No")
         item.setFlags(item.flags() ^ Qt.ItemIsEditable)
         self.tableWidget.setItem(i, 2, item)
         metadataPublished = metadataServer is not None
         item = QTableWidgetItem(
             self.tr("Yes") if metadataPublished else self.tr("No"))
         item.setFlags(item.flags() ^ Qt.ItemIsEditable)
         self.tableWidget.setItem(i, 3, item)
         txt = self.tr("warnings(%i), errors(%i)") % (len(warnings),
                                                      len(errors))
         widget = QWidget()
         button = QPushButton()
         button.setText(txt)
         button.clicked.connect(partial(self.openDetails, name))
         layout = QHBoxLayout(widget)
         layout.addWidget(button)
         layout.setAlignment(Qt.AlignCenter)
         layout.setContentsMargins(0, 0, 0, 0)
         widget.setLayout(layout)
         self.tableWidget.setCellWidget(i, 4, widget)
 def populateLayerFields(self):
     if self.currentLayer.type() == self.currentLayer.VectorLayer:
         fields = [f.name() for f in self.currentLayer.fields()]
         self.tabLayerInfo.setTabEnabled(1, True)
         self.tableFields.setRowCount(len(fields))
         for i, field in enumerate(fields):
             item = QTableWidgetItem()
             item.setFlags(item.flags() ^ Qt.ItemIsEditable)
             check = Qt.Checked if self.fieldsToPublish[
                 self.currentLayer][field] else Qt.Unchecked
             item.setCheckState(check)
             self.tableFields.setItem(i, 0, item)
             item = QTableWidgetItem(field)
             item.setFlags(item.flags() ^ Qt.ItemIsEditable)
             self.tableFields.setItem(i, 1, item)
     else:
         self.tabLayerInfo.setTabEnabled(1, False)
Example #3
0
 def addCoord(self, lat, lon, label):
     '''Add a coordinate to the list.'''
     if self.numcoord >= self.maxResults:
         return
     self.resultsTable.insertRow(self.numcoord)
     self.llitems.append(LatLonItem(lat, lon, label))
     self.resultsTable.blockSignals(True)
     self.resultsTable.setItem(self.numcoord, 2, QTableWidgetItem(label))
     item = QTableWidgetItem(str(lat))
     item.setFlags(item.flags() & ~Qt.ItemIsEditable)
     self.resultsTable.setItem(self.numcoord, 0, item)
     item = QTableWidgetItem(str(lon))
     item.setFlags(item.flags() & ~Qt.ItemIsEditable)
     self.resultsTable.setItem(self.numcoord, 1, item)
     self.resultsTable.blockSignals(False)
     self.numcoord += 1
     if self.showAllCheckBox.checkState():
         self.showAllChange()
 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)
    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)
 def selectSource(self): 
     '''
     source feature selection procedure
     '''
     if self.layerHighlighted:
         self.resetSource()
     try:
         self.dock.tableWidget.itemChanged.disconnect(self.highLightCellOverride)
     except:
         pass
     #take first selected feature as source feature
     self.sourceFeat = self.selectedFeature
     #hightlight source feature with rubberband
     self.sourceEvid.setToGeometry(self.sourceFeat.geometry(),self.selectedLayer)
     #get current layer attributes labels list
     field_names = self.scanLayerFieldsNames(self.selectedLayer)
     field_types = self.scanLayerFieldsTypes(self.selectedLayer)
     self.sourceAttrsTab=[]
     self.dock.tableWidget.setRowCount(len(field_names))
     #loading attributes labels and values in QTableWidget
     for n in range(0,len(field_names)):
             item=QTableWidgetItem()
             item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Unchecked)
             item.setText("")
             #set first column as checkbox
             self.dock.tableWidget.setItem(n,0,item)
             #set second colunm as attribute label as qcombobox widget
             self.dock.tableWidget.setCellWidget(n,1,self.setComboField(field_names[n],field_types[n],self.canvas.currentLayer()))
             #set third column as attribute value
             item = QTableWidgetItem()
             item.setData(Qt.DisplayRole,self.sourceFeat.attributes()[n])
             self.dock.tableWidget.setItem(n,2,item)
     #resize table to contents
     self.dock.tableWidget.resizeColumnsToContents()
     self.dock.tableWidget.horizontalHeader().setStretchLastSection(True)
     #procedure to recover same field selection if current source feature has the same layer of the precedent one
     if self.selectedLayer.id() != self.activeLayer:
         self.sourceAttrs={}
         self.activeLayer = self.selectedLayer.id()
     else:
         for Attr in self.sourceAttrs:
             self.dock.tableWidget.item(Attr,0).setCheckState(Qt.Checked)
     #Enable button to apply or reset
     self.dock.ResetSource.setEnabled(True)
     self.dock.tableWidget.itemChanged.connect(self.highLightCellOverride)
     self.checkOnLayerChange(self.canvas.currentLayer())
Example #7
0
    def populate_function_table_1(self):
        """Populate the tblFunctions1 table with available functions."""
        hazards = deepcopy(hazard_all)
        exposures = exposure_all

        self.lblAvailableFunctions1.clear()
        self.tblFunctions1.clear()
        self.tblFunctions1.setColumnCount(len(hazards))
        self.tblFunctions1.setRowCount(len(exposures))
        for i in range(len(hazards)):
            hazard = hazards[i]
            item = QTableWidgetItem()
            item.setIcon(QIcon(get_image_path(hazard)))
            item.setText(hazard['name'].capitalize())
            item.setTextAlignment(Qt.AlignLeft)
            self.tblFunctions1.setHorizontalHeaderItem(i, item)
        for i in range(len(exposures)):
            exposure = exposures[i]
            item = QTableWidgetItem()
            item.setIcon(QIcon(get_image_path(exposure)))
            item.setText(exposure['name'].capitalize())
            self.tblFunctions1.setVerticalHeaderItem(i, item)
        developer_mode = setting('developer_mode', False, bool)
        for hazard in hazards:
            for exposure in exposures:
                item = QTableWidgetItem()
                if (exposure in hazard['disabled_exposures'] and not
                        developer_mode):
                    background_colour = unavailable_option_color
                    # Set it disable and un-selectable
                    item.setFlags(
                        item.flags() & ~
                        Qt.ItemIsEnabled & ~
                        Qt.ItemIsSelectable
                    )
                else:
                    background_colour = available_option_color
                item.setBackground(QBrush(background_colour))
                item.setFont(big_font)
                item.setTextAlignment(Qt.AlignCenter | Qt.AlignHCenter)
                item.setData(RoleHazard, hazard)
                item.setData(RoleExposure, exposure)
                self.tblFunctions1.setItem(
                    exposures.index(exposure), hazards.index(hazard), item)
        self.parent.pbnNext.setEnabled(False)
Example #8
0
    def populate_function_table_1(self):
        """Populate the tblFunctions1 table with available functions."""
        hazards = deepcopy(hazard_all)
        exposures = exposure_all

        self.lblAvailableFunctions1.clear()
        self.tblFunctions1.clear()
        self.tblFunctions1.setColumnCount(len(hazards))
        self.tblFunctions1.setRowCount(len(exposures))
        for i in range(len(hazards)):
            hazard = hazards[i]
            item = QTableWidgetItem()
            item.setIcon(QIcon(get_image_path(hazard)))
            item.setText(hazard['name'].capitalize())
            item.setTextAlignment(Qt.AlignLeft)
            self.tblFunctions1.setHorizontalHeaderItem(i, item)
        for i in range(len(exposures)):
            exposure = exposures[i]
            item = QTableWidgetItem()
            item.setIcon(QIcon(get_image_path(exposure)))
            item.setText(exposure['name'].capitalize())
            self.tblFunctions1.setVerticalHeaderItem(i, item)
        developer_mode = setting('developer_mode', False, bool)
        for hazard in hazards:
            for exposure in exposures:
                item = QTableWidgetItem()
                if (exposure in hazard['disabled_exposures'] and not
                        developer_mode):
                    background_colour = unavailable_option_color
                    # Set it disable and un-selectable
                    item.setFlags(
                        item.flags() & ~
                        Qt.ItemIsEnabled & ~
                        Qt.ItemIsSelectable
                    )
                else:
                    background_colour = available_option_color
                item.setBackground(QBrush(background_colour))
                item.setFont(big_font)
                item.setTextAlignment(Qt.AlignCenter | Qt.AlignHCenter)
                item.setData(RoleHazard, hazard)
                item.setData(RoleExposure, exposure)
                self.tblFunctions1.setItem(
                    exposures.index(exposure), hazards.index(hazard), item)
        self.parent.pbnNext.setEnabled(False)
    def restoreState(self,layer,table):
        if layer.id() in self.states.keys():
            table.blockSignals(True)
            #clear dock widget
            while table.rowCount()>0:
                table.removeRow(0)
            #add rows
            table.setRowCount(len(self.states[layer.id()]))
            for n in range(0, len(self.states[layer.id()])):
                row = self.states[layer.id()][n]
                #set first column as checkbox
                item=QTableWidgetItem()
                item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
                if row[0]:
                    item.setCheckState(Qt.Checked)
                else:
                    item.setCheckState(Qt.Unchecked)
                item.setText("")
                table.setItem(n,0,item)
                #set second column as combobox
                combo = QComboBox();
                combo.addItems(row[1])
                #print (row[1],row[2])
                combo.setCurrentIndex(row[2])
                table.setCellWidget(n,1,combo)
                #set third column as attribute value
                item = QTableWidgetItem(row[3])
                item.setData(Qt.DisplayRole,row[4])
                if row[5]:
                    item.setForeground(QBrush(QColor(0,0,0)))
                else:
                    item.setForeground(QBrush(QColor(130,130,130)))
                if row[6]:
                    item.setBackground(QBrush(QColor(183,213,225)))
                table.setItem(n,2,item)

            table.blockSignals(False)
            return True

        else:
            return None
    def set_pixel_table(self):
        # clear table
        self.PixelTable.clear()
        self.PixelTable.setRowCount(0)
        self.PixelTable.setColumnCount(0)
        if not self.thematic_file_classes:
            return

        with block_signals_to(self.PixelTable):
            header = ["", "class value", "select"]
            row_length = len(self.pixel_classes)
            # init table
            self.PixelTable.setRowCount(row_length)
            self.PixelTable.setColumnCount(3)
            self.PixelTable.horizontalHeader().setMinimumSectionSize(45)
            # hidden row labels
            self.PixelTable.verticalHeader().setVisible(False)
            # add Header
            self.PixelTable.setHorizontalHeaderLabels(header)
            # insert items
            for col_idx, header in enumerate(header):
                if header == "":
                    for row_idx, pixel in enumerate(self.pixel_classes):
                        item_table = QTableWidgetItem()
                        item_table.setFlags(item_table.flags()
                                            & ~Qt.ItemIsSelectable)
                        item_table.setBackground(
                            QColor(pixel["color"]["R"], pixel["color"]["G"],
                                   pixel["color"]["B"], pixel["color"]["A"]))
                        self.PixelTable.setItem(row_idx, col_idx, item_table)
                if header == "class value":
                    for row_idx, pixel in enumerate(self.pixel_classes):
                        item_table = QTableWidgetItem(str(pixel["value"]))
                        item_table.setFlags(item_table.flags()
                                            & ~Qt.ItemIsSelectable)
                        item_table.setFlags(item_table.flags()
                                            & ~Qt.ItemIsEditable)
                        item_table.setTextAlignment(Qt.AlignCenter
                                                    | Qt.AlignVCenter)
                        self.PixelTable.setItem(row_idx, col_idx, item_table)
                if header == "select":
                    for row_idx, pixel in enumerate(self.pixel_classes):
                        item_table = QTableWidgetItem()
                        item_table.setFlags(item_table.flags()
                                            | Qt.ItemIsUserCheckable)
                        item_table.setFlags(item_table.flags()
                                            | Qt.ItemIsEnabled)
                        item_table.setFlags(item_table.flags()
                                            & ~Qt.ItemIsSelectable)
                        item_table.setTextAlignment(Qt.AlignCenter
                                                    | Qt.AlignVCenter)
                        if pixel["select"]:
                            item_table.setCheckState(Qt.Checked)
                        else:
                            item_table.setCheckState(Qt.Unchecked)
                        self.PixelTable.setItem(row_idx, col_idx, item_table)

            # adjust size of Table
            self.PixelTable.resizeColumnsToContents()
            self.PixelTable.resizeRowsToContents()
            # adjust the editor block based on table content
            table_width = self.PixelTable.horizontalHeader().length() + 40
            self.TableBlock.setMaximumWidth(table_width)
            self.TableBlock.setMinimumWidth(table_width)
Example #11
0
    def update_layers(self):
        if self.tabWidget.currentIndex() != 2:
            return

        if self.layerSelection.currentIndex() == 3:  # by selection string
            self.selectionStringLineEdit.setEnabled(True)
        else:
            self.selectionStringLineEdit.setEnabled(False)

        if self.layerSelection.currentIndex() == 0:  # visible layers
            layers = self.activeRasterLayers(0)
        elif self.layerSelection.currentIndex() == 3:  # by selection string
            layers = self.activeRasterLayers(3)
        else:
            layers = self.activeRasterLayers(1)  # All layers

        self.selectionTable.blockSignals(True)
        self.selectionTable.clearContents()
        self.selectionTable.setRowCount(len(layers))
        self.selectionTable.horizontalHeader().resizeSection(0, 20)
        self.selectionTable.horizontalHeader().resizeSection(2, 20)

        j = 0
        for layer in layers:
            item = QTableWidgetItem()
            item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
            if self.layerSelection.currentIndex() != 2:
                item.setFlags(item.flags() & ~Qt.ItemIsEnabled)
                item.setCheckState(Qt.Checked)
            else:
                # manual selection
                if layer.id() in self.layersSelected:
                    item.setCheckState(Qt.Checked)
                else:
                    item.setCheckState(Qt.Unchecked)
            self.selectionTable.setItem(j, 0, item)
            item = QTableWidgetItem(layer.name())
            item.setData(Qt.UserRole, layer.id())
            self.selectionTable.setItem(j, 1, item)
            activeBands = self.activeBandsForRaster(layer)
            button = QToolButton()
            button.setIcon(QIcon(':/plugins/mutant/img/bands.jpg'))
            # button.setIconSize(QtCore.QSize(400, 400))
            button.setPopupMode(QToolButton.InstantPopup)
            group = QActionGroup(button)
            group.setExclusive(False)
            group.triggered.connect(self.bandSelected)
            if self.bandSelection.currentIndex(
            ) == 2 and layer.bandCount() > 1:
                menu = QMenu()
                menu.installEventFilter(self)

                for iband in range(1, layer.bandCount() + 1):
                    action = QAction(str(layer.bandName(iband)), group)
                    action.setData([layer.id(), iband, j, False])
                    action.setCheckable(True)
                    action.setChecked(iband in activeBands)
                    menu.addAction(action)
                if layer.bandCount() > 1:
                    action = QAction(str(self.tr("All")), group)
                    action.setData([layer.id(), -1, j, True])
                    action.setCheckable(False)
                    menu.addAction(action)
                    action = QAction(str(self.tr("None")), group)
                    action.setData([layer.id(), -1, j, False])
                    action.setCheckable(False)
                    menu.addAction(action)

                button.setMenu(menu)
            else:
                button.setEnabled(False)
            self.selectionTable.setCellWidget(j, 2, button)
            item = QTableWidgetItem(str(activeBands))
            item.setToolTip(str(activeBands))
            self.selectionTable.setItem(j, 3, item)
            j += 1

        self.selectionTable.blockSignals(False)
Example #12
0
def make_item(data, readonly=True):
    item = QTableWidgetItem(str(data))
    if readonly:
        item.setFlags(item.flags() ^ Qt.ItemIsEditable)
    return item
Example #13
0
 def addLayer(self, layer, headers, types, features):
     tab = QWidget()
     tab.layer = layer
     p1_vertical = QVBoxLayout(tab)
     p1_vertical.setContentsMargins(0,0,0,0)
     
     table = QTableWidget()
     table.itemSelectionChanged.connect(self.highlight_features)
     table.title = layer.name()
     table.crs = layer.crs()
     table.setColumnCount(len(headers))
     if len(features) > 0:
         table.setRowCount(len(features))
         nbrow = len(features)
         self.loadingWindow.show()
         self.loadingWindow.setLabelText(table.title)
         self.loadingWindow.activateWindow()
         self.loadingWindow.showNormal()
         
         # Table population
         m = 0
         for feature in features:
             n = 0
             for cell in feature.attributes():
                 item = QTableWidgetItem()
                 item.setData(Qt.DisplayRole, cell)
                 item.setFlags(item.flags() ^ Qt.ItemIsEditable)
                 item.feature = feature
                 table.setItem(m, n, item)
                 n += 1
             m += 1
             self.loadingWindow.setValue(int((float(m)/nbrow)*100))  
             QApplication.processEvents()
         
     else:
         table.setRowCount(0)  
                         
     table.setHorizontalHeaderLabels(headers)
     table.horizontalHeader().setSectionsMovable(True)
     
     table.types = types
     table.filter_op = []
     table.filters = []
     for i in range(0, len(headers)):
         table.filters.append('')
         table.filter_op.append(0)
     
     header = table.horizontalHeader()
     header.setContextMenuPolicy(Qt.CustomContextMenu)
     header.customContextMenuRequested.connect(partial(self.filterMenu, table))
         
     table.setSortingEnabled(True)
     
     p1_vertical.addWidget(table)
     
     # Status bar to display informations (ie: area)
     tab.sb = QStatusBar()
     p1_vertical.addWidget(tab.sb)
     
     title = table.title
     # We reduce the title's length to 20 characters
     if len(title)>20:
         title = title[:20]+'...'
     
     # We add the number of elements to the tab's title.
     title += ' ('+str(len(features))+')'
         
     self.tabWidget.addTab(tab, title) # Add the tab to the conatiner
     self.tabWidget.setTabToolTip(self.tabWidget.indexOf(tab), table.title) # Display a tooltip with the layer's full name