Пример #1
1
 def createEditor( self, parent, option, index ):
     if index.column() == CANTIDAD:
         spinbox = QSpinBox( parent )
         spinbox.setRange( 0, index.model().lines[index.row()].maxquantity )
         spinbox.setSingleStep( 1 )
         return spinbox
     else:
         QStyledItemDelegate.createEditor( self, parent, option, index )
Пример #2
0
    def setEditorData(self, editor, index):
        """Specifies how the given editor should be filled out with the
        data from the model.
        """

        if not index.isValid():
            return

        # if BaseDNs
        if index.column() == 5:

            # List of strings from the model
            d = index.data().toPyObject()
            # Empty the editor (clear old list)
            editor.clear()
            # Fill it out with new data
            for tmpBase in d:
                # The editor is the items parent, so it gets added to
                # the list
                QListWidgetItem(tmpBase, editor)
                # Can also do this
                #editor.addItem(QListWidgetItem(tmpBase))
            return

        # NOTE: If a QComboBox just set the index it should display
        # (the strings displayed is in the .ui-file) this means the
        # strings in the *.ui file HAS TO BE IN THE CORRECT ORDER.

        # If QComboBoxes has currentIndex just give it the data.
        if editor.property("currentIndex").isValid():
            editor.setProperty("currentIndex", index.data())
            return

        # else (default)
        QStyledItemDelegate.setEditorData(self, editor, index)
Пример #3
0
    def setModelData(self, editor, model, index):
        """ Specifies how the model should be filled out with data from
        the editor
        """

        # if the baseDNs
        if index.column() == 5:

            returnList = []

            # Get the basedn-list from the editor
            for i in xrange(editor.count()):
                returnList.append(
                    editor.item(i).data(Qt.DisplayRole).toPyObject())

            # now that we have constructed the list, give it to the model
            model.setData(index, QVariant(returnList))
            return

        # if a combobox, get the index and give it to the model
        value = editor.property("currentIndex")
        if value.isValid():
            model.setData(index, value)
            return

        # else - default
        QStyledItemDelegate.setModelData(self, editor, model, index)
Пример #4
0
 def paint( self, painter, option, index ):
     " Hides the dotted outline "
     itemOption = QStyleOptionViewItem( option )
     if itemOption.state & QStyle.State_HasFocus != 0:
         itemOption.state = itemOption.state & ~QStyle.State_HasFocus
     QStyledItemDelegate.paint( self, painter, itemOption, index )
     return
Пример #5
0
 def paint(self, painter, option, index):
     # pylint: disable=missing-docstring
     painter.save()
     painter.setPen(QColor(212, 212, 212))
     painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
     painter.restore()
     QStyledItemDelegate.paint(self, painter, option, index)
Пример #6
0
    def paint(self, painter, option, index):
        if option.state & QStyle.State_Selected:
            modelIndex = index.row()
            if modelIndex != self.currentIndex:
                model = index.model()
                self.currentIndex = modelIndex
                model.wantsUpdate()

        layer = index.data().toPyObject()
        if isinstance(layer, Layer):
            pic = QPixmap( option.rect.width(), option.rect.height() )
            w = self._w
            w.layer = layer
            w.setGeometry( option.rect )
            w.setPalette( option.palette )
            
            # Manually set alternating background colors for the rows
            if index.row() % 2 == 0:
                itemBackgroundColor = self.parent().palette().color(QPalette.Base)
            else:
                itemBackgroundColor = self.parent().palette().color(QPalette.AlternateBase)
            pallete = w.palette()
            pallete.setColor( QPalette.Window, itemBackgroundColor )
            w.setPalette(pallete)
            w.render(pic)            
            painter.drawPixmap( option.rect, pic )
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
    def paint(self, painter, option, index):
        # noinspection PyArgumentList
        style = QApplication.instance().style()

        if index.data(CheckableItemDelegate.CheckTypeRole):
            # Size and spacing in current style
            is_radio = index.data(CheckableItemDelegate.CheckTypeRole) == CheckableItemDelegate.RadioCheckType
            if is_radio:
                button_width = style.pixelMetric(QStyle.PM_ExclusiveIndicatorWidth, option)
                spacing = style.pixelMetric(QStyle.PM_RadioButtonLabelSpacing, option)
            else:
                button_width = style.pixelMetric(QStyle.PM_IndicatorWidth, option)
                spacing = style.pixelMetric(QStyle.PM_CheckBoxLabelSpacing, option)

            # Draw default appearance shifted to right
            myOption = option
            left = myOption.rect.left()
            myOption.rect.setLeft(left + spacing + button_width)
            QStyledItemDelegate.paint(self, painter, myOption, index)

            # Draw check button to open space (where expand indicator would be)
            myOption.rect.setLeft(left)
            myOption.rect.setWidth(button_width)

            if index.data(CheckableItemDelegate.CheckedRole):
                myOption.state |= QStyle.State_On
            else:
                myOption.state |= QStyle.State_Off

            if is_radio:
                style.drawPrimitive(QStyle.PE_IndicatorRadioButton, myOption, painter)
            else:
                style.drawPrimitive(QStyle.PE_IndicatorCheckBox, myOption, painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
Пример #8
0
    def paint(self, painter, option, index):
        painter.save()
        palette = QApplication.palette()
        if index.isValid():
            color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else  QColor(Qt.white)
            painter.fillRect(option.rect, color)
            if (option.state and QStyle.State_Active):
                textColor = QPalette.HighlightedText if option.state & QStyle.State_Selected else QPalette.WindowText
            else:
                textColor = QPalette.WindowText
            
            col = index.column()
            val = index.model().data(index).toFloat()[0]
            if col == 1:
                text = '%.2f %%  ' % (val*100)
            else:
                text = '%d  ' % (val)
            
            QApplication.style().drawItemText(painter, option.rect, Qt.AlignRight | Qt.AlignVCenter,
                                              option.palette, True, text,
                                              textColor)
        else:
            QStyledItemDelegate.paint(painter, option, index)

        painter.restore()
Пример #9
0
    def paint(self, painter, option, index):
        # if item selected, override default theme
        # Keeps verdict color for cells and use a bold font
        if option.state & QStyle.State_Selected:
            option.state &= ~QStyle.State_Selected
            option.font.setBold(True)

        QStyledItemDelegate.paint(self, painter, option, index)

        item = index.model().get_item(index)
        if item and item.downloading:
            # Draw progress bar
            progressBarOption = QStyleOptionProgressBarV2()
            progressBarHeight = option.rect.height() / 4
            progressBarOption.rect = QRect(
                option.rect.x(),
                option.rect.y() + (option.rect.height() - progressBarHeight),
                option.rect.width(),
                progressBarHeight,
            )
            progressBarOption.minimum = 0
            progressBarOption.maximum = 100
            progressBarOption.textAlignment = Qt.AlignCenter

            progressBarOption.progress = item.progress

            QApplication.style().drawControl(QStyle.CE_ProgressBar, progressBarOption, painter)
Пример #10
0
 def __init__(self, layersView, listModel, parent = None):
     QStyledItemDelegate.__init__(self, parent=parent)
     self.currentIndex = -1
     self._view = layersView
     self._w = LayerItemWidget()
     self._listModel = listModel
     self._listModel.rowsAboutToBeRemoved.connect(self.handleRemovedRows)
Пример #11
0
	def __init__(self, qnotero):
	
		"""
		Constructor
		
		Arguments:
		qnotero -- a Qnotero instance
		"""
	
		QStyledItemDelegate.__init__(self, qnotero)		
		self.qnotero = qnotero
		self.boldFont = QFont()
		self.boldFont.setBold(True)
		self.regularFont = QFont()
		self.italicFont = QFont()
		self.italicFont.setItalic(True)
		self.tagFont = QFont()
		self.tagFont.setBold(True)
		self.tagFont.setPointSize(self.boldFont.pointSize() - 2)
		
		self.dy = QFontMetrics(self.boldFont) \
			.size(Qt.TextSingleLine, "Dummy").height() \
			*self.qnotero.theme.lineHeight()		
		
		
		self.margin = 0.5*self.dy
		self._margin = 0.1*self.dy		
		self.height = 5*self.dy+self._margin
		self.noPdfPixmap = self.qnotero.theme.pixmap("nopdf")
		self.pdfPixmap = self.qnotero.theme.pixmap("pdf")
		self.aboutPixmap = self.qnotero.theme.pixmap("about")
		self.notePixmap = self.qnotero.theme.pixmap("note")
		self.pixmapSize = self.pdfPixmap.height()+0.5*self.dy		
		self.roundness = self.qnotero.theme.roundness()		
Пример #12
0
    def setModelData( self, editor, model, index ):

        if index.column() == DESCRIPCION:
            modelo = self.proxymodel
            if modelo.rowCount() > 0:
                fila = editor.currentIndex()
                model.setData( index, [
                                           modelo.index( fila, 0 ).data().toInt()[0],
                                           modelo.index( fila, 1 ).data().toString(),
                                           modelo.index( fila, 2 ).data().toInt()[0],
                                           modelo.index( fila, 3 ).data().toString()
                    ] )
                self.removeFromFilter( modelo.index( fila, 1 ).data().toString() )
                self.proxymodel.setFilterRegExp( self.filter() )
        elif index.column() == BANCO:
            modelo = self.bancosmodel
            if modelo.rowCount() == 0 :
                model.setData( index, [-1, ""] )
            else:
                fila = editor.currentIndex()
                model.setData( index, [
                                               modelo.index( fila, 0 ).data().toInt()[0],
                                               modelo.index( fila, 1 ).data().toString()
                        ] )
        else:
            QStyledItemDelegate.setModelData( self, editor, model, index )
Пример #13
0
    def paint(self, painter, option, index):
        script = index.data(Qt.DisplayRole).toPyObject()

        if script.flags & Script.Modified:
            option = QStyleOptionViewItemV4(option)
            option.palette.setColor(QPalette.Text, QColor(Qt.red))
            option.palette.setColor(QPalette.Highlight, QColor(Qt.darkRed))
        QStyledItemDelegate.paint(self, painter, option, index)
Пример #14
0
    def __init__(self, controller, model, parent=None):
        """
        Constructor.
        """

        QStyledItemDelegate.__init__(self, parent)
        self._controller = controller
        self._model = model
Пример #15
0
 def createEditor(self, parent, option, index):
     if index.column() == NUMAJUSTE:
         spinbox = QSpinBox(parent)
         spinbox.setRange(-1000, 1000)
         spinbox.setSingleStep(1)
         return spinbox
     else:
         QStyledItemDelegate.createEditor(self, parent, option, index)
Пример #16
0
 def __init__(self, base):
     QStyledItemDelegate.__init__(self)
     self.favorite_icon = base.load_image('mark-favorite.png', True)
     self.verified_icon = base.load_image('mark-verified.png', True)
     self.protected_icon = base.load_image('mark-protected.png', True)
     self.repeated_icon = base.load_image('mark-repeated.png', True)
     self.reposted_icon = base.load_image('mark-reposted.png', True)
     self.avatar = None
Пример #17
0
    def __init__(self, layersView, parent = None):
        QStyledItemDelegate.__init__(self, parent)
        self.currentIndex = -1
        self._view = layersView
        self._layerPainter = LayerPainter()

        #whether to draw all layers expanded
        self.expandAll = True
Пример #18
0
 def createEditor(self, parent, option, index):
     layer = index.data().toPyObject()
     if isinstance(layer, Layer):
         editor = LayerEditor(parent)
         self._editors[layer] = editor
         return editor
     else:
         QStyledItemDelegate.createEditor(self, parent, option, index)
Пример #19
0
 def __init__( self, query, showTable = False ):
     QStyledItemDelegate.__init__( self )
     self.accounts = QSqlQueryModel()
     self.accounts.setQuery( query )
     self.proxymodel = QSortFilterProxyModel()
     self.proxymodel.setFilterKeyColumn( 0 )
     self.proxymodel.setSourceModel( self.accounts )
     self.showTable = showTable
     self.filtrados = []
Пример #20
0
    def initStyleOption(self, option, index):
        QStyledItemDelegate.initStyleOption(self, option, index)

        order = toSortOrder(index.data(SortOrderRole))

        if order == Qt.AscendingOrder:
            option.text = option.text + " (Ascending)"
        else:
            option.text = option.text + " (Descending)"
Пример #21
0
 def setEditorData( self, editor, index ):
     """
     Aca se definen los datos iniciales que tendra el control, 
     justo antes de mostrarlo
     """
     if index.column() in ( NOMBRE, TELEFONO, RUC, EMAIL ):
         text = index.model().data( index, Qt.DisplayRole )
         editor.setText( text.toString() )
     else:
         QStyledItemDelegate.setEditorData( self, editor, index )
Пример #22
0
 def setEditorData( self, editor, index ):
     """
     En esta funcion se inicializan los datos a mostrarse en el editor
     se ejecuta justo en el momento en el que se muestra el editor
     """
     if index.column() == ABONO:
         valortemp = index.model().data( index, Qt.EditRole )
         editor.setValue( valortemp )
     else:
         QStyledItemDelegate.setEditorData( self, editor, index )
Пример #23
0
 def setEditorData( self, editor, index ):
     data = index.data()
     if index.column() in ( BANCO, DESCRIPCION ):
         i = editor.findText( data if type( data ) != QVariant else data.toString() )
         if i == -1:
             i = 0
         editor.setCurrentIndex( i )
     elif index.column() == MONTO:
         editor.setValue( index.model().data( index, Qt.EditRole ) if index.model().data( index, Qt.EditRole ) != "" else 0 )
     else:
         QStyledItemDelegate.setEditorData( self, editor, index )
Пример #24
0
 def createEditor(self, parent, option, index):
     layer = index.data().toPyObject()
     if isinstance(layer, Layer):
         editor = LayerItemWidget(parent=parent)
         editor.setAutoFillBackground(True)
         editor.setPalette( option.palette )
         editor.setBackgroundRole(QPalette.Highlight)
         editor.layer = layer
         return editor
     else:
         QStyledItemDelegate.createEditor(self, parent, option, index)
Пример #25
0
 def setModelData(self, editor, model, index):
     if index.column() == TEU:
         model.setData(index, QVariant(editor.value()))
     elif index.column() in (OWNER, COUNTRY):
         model.setData(index, QVariant(editor.currentText()))
     elif index.column() == NAME:
         model.setData(index, QVariant(editor.text()))
     elif index.column() == DESCRIPTION:
         model.setData(index, QVariant(editor.toSimpleHtml()))
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Пример #26
0
    def __init__(self, layersView, listModel, parent = None):
        QStyledItemDelegate.__init__(self, parent)
        self.currentIndex = -1
        self._view = layersView
        self._editors = {}
        self._listModel = listModel

        #whether to draw all layers expanded
        self.expandAll = True

        self._listModel.rowsAboutToBeRemoved.connect(self.handleRemovedRows)
Пример #27
0
	def __init__(self,
				parent=None,
				style=None,
				highlightColor=None,
				hoverColor=None,
				backgroundColor=None,
				highlightBackgroundColor=None,
				hoverBackgroundColor=None):
		"""
		Initializes the class.

		:param parent: Widget parent.
		:type parent: QObject
		:param style: Style.
		:type style: Style
		"""

		LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__))

		QStyledItemDelegate.__init__(self, parent)

		# --- Setting class attributes. ---
		self.__indent = 5

		self.__label = QLabel()
		self.__label.setIndent(self.__indent)
		self.__label.setTextFormat(Qt.RichText)

		self.__defaultStyle = Style(default=\
								"""
								QLabel, QLabel link {
									background-color: rgb(32, 32, 32);
									color: rgb(192, 192, 192);
								}
								""",
								hover=\
								"""
								QLabel, QLabel link {
									background-color: rgb(64, 64, 64);
									color: rgb(192, 192, 192);
								}
								""",
								highlight=\
								"""
								QLabel, QLabel link {
									background-color: rgb(128, 128, 128);
									color: rgb(224, 224, 224);
								}
								""")

		self.__style = self.__defaultStyle
		self.style = style or self.__style
Пример #28
0
 def __init__(self, layersView, listModel, parent = None):
     QStyledItemDelegate.__init__(self, parent=parent)
     self.currentIndex = -1
     self._view = layersView
     self._w = LayerItemWidget()
     self._listModel = listModel
     self._listModel.rowsAboutToBeRemoved.connect(self.handleRemovedRows)
     
     # We keep a dict of all open editors for easy access.
     # Note that the LayerWidget uses persistent editors.
     # (This is for convenience of testing.)
     # This is also why we don't need to override the paint() method here.
     self._editors = {}
Пример #29
0
    def setModelData( self, editor, model, index ):

        if index.column() in ( NCUENTA, CODCUENTA ):
            if editor.currentIndex() != -1:
                proxyindex = self.proxymodel.index( editor.currentIndex() , 0 )
                sourceindex = self.proxymodel.mapToSource( proxyindex )

                model.setData( index, [
                                       self.accounts.index( sourceindex.row(), 0 ).data().toInt()[0],
                                       self.accounts.index( sourceindex.row(), 1 ).data(),
                                       self.accounts.index( sourceindex.row(), 2 ).data()
                                       ] )
        else:
            QStyledItemDelegate.setModelData( self, editor, model, index )
Пример #30
0
    def setModelData( self, editor, model, index ):

        if index.column() in ( NCUENTA, CODCUENTA ):
            if self.proxymodel.rowCount() > 0:
                fila = editor.currentIndex()
                modelo = self.proxymodel
                model.setData( index, [
                                       modelo.index( fila , 0 ).data(),
                                       modelo.index( fila, 1 ).data(),
                                       modelo.index( fila, 2 ).data()
                                       ] )
                self.filtrados.append( modelo.index( fila , 0 ).data().toString() )
                self.proxymodel.setFilterRegExp( self.filter() )
        else:
            QStyledItemDelegate.setModelData( self, editor, model, index )
Пример #31
0
    def paint(self, painter, option, index):
        painter.save()
        if index.isValid():

            style = self.parent().style()
            styleOption = QStyleOptionViewItemV4(option)

            node = index.internalPointer()
            val = index.model().data(index).toPyObject()

            if node.typeInfo == 'CODE':
                if node.valueFormat == 'percent':
                    text = '%.2f %%  ' % (val * 100)
                elif node.valueFormat == 'integer':
                    text = '%d  ' % val
                else:
                    text = '%.2f  ' % val

                styleOption.text = text
                styleOption.displayAlignment = Qt.AlignRight

                style.drawControl(QStyle.CE_ItemViewItem, styleOption, painter)

            elif node.typeInfo == 'BAREME' and index.column() == 2:
                styleOption = QStyleOptionButton()
                styleOption.rect = option.rect
                styleOption.text = QString('Editer')
                styleOption.textVisible = True
                styleOption.state = styleOption.state | QStyle.State_Enabled
                style.drawControl(QStyle.CE_PushButton, styleOption, painter)
            else:
                QStyledItemDelegate.paint(self, painter, styleOption, index)

        else:
            QStyledItemDelegate.paint(painter, option, index)

        painter.restore()
Пример #32
0
    def createEditor(self, parent, option, index):
        # Create combobox editor for sort order column
        if index.column() == self._sort_cold_idx:
            combo = QComboBox(parent)
            for enum, txt in SORT_ORDER_NAME.iteritems():
                combo.addItem(txt, enum)

            return combo
        else:
            return QStyledItemDelegate.createEditor(
                self,
                parent,
                option,
                index
            )
Пример #33
0
 def sizeHint(self, option, index):
     """
     This method is re-implemented because Description column is using HTML, it must return the exactly number of characters for
     presentation purpose rather than the number of HTML raw characters.
     """
     fm = option.fontMetrics
     if index.column() == TEU:
         return QSize(fm.width("9,999,999"), fm.height())
     if index.column() == DESCRIPTION:
         text = index.model().data(index).toString()
         document = QTextDocument()
         document.setDefaultFont(option.font)
         document.setHtml(text)
         return QSize(document.idealWidth() + 5, fm.height())
     return QStyledItemDelegate.sizeHint(self, option, index)
Пример #34
0
 def sizeHint(self, option, index):
     s = QStyledItemDelegate.sizeHint(self, option, index)
     # sizeHint is for some reason only called once, so set
     # size globally
     #if index.data(CheckableItemDelegate.CheckTypeRole):
     #    # Determine size of check buttons in current style
     #    #noinspection PyArgumentList
     #    button_height = QApplication.style().pixelMetric(QStyle.PM_ExclusiveIndicatorHeight, option)
     #    # Ensure that row is tall enough to draw check button
     #    print button_height
     #    s.setHeight(max(s.height(), button_height))
     radio_height = QApplication.style().pixelMetric(
         QStyle.PM_ExclusiveIndicatorHeight, option)
     check_height = QApplication.style().pixelMetric(
         QStyle.PM_IndicatorHeight, option)
     s.setHeight(max(s.height(), radio_height, check_height))
     return s
Пример #35
0
    def editorEvent(self, event, model, option, index):
        #print "editor event"
        if event.type() == QEvent.MouseButtonDblClick and model.isList(index):
            # read-only ?
            if model.flags(index) & Qt.ItemIsEditable: mode = 'w'
            else: mode = 'r'
            #print mode
            data = model.data(index, role=Qt.EditRole)
            fm = SimpleListDlg(datalist=data, mode = mode)
            fm.setModal(True)
            fm.exec_()
            if fm.values:
                #print fm.values
                vals = QVariant.fromList([QVariant(d) for d in fm.values])
                model.setData(index, vals)
            return True

        return QStyledItemDelegate.editorEvent(self, event, model, option, index)
Пример #36
0
    def setModelData(self, editor, model, index):
        """copy data from editor to model"""
        #if _DBG_VERBOSE: print "updating model data", editor.text(),
        #print "  sender", self.sender()
        #traceback.print_stack(file=sys.stdout)
        row, col = index.row(), index.column()
        if row == C_FIELD:
            #if _DBG_VERBOSE: print "skip"
            return QStyledItemDelegate.setModelData(self, editor, model, index)

        if not self._modified: return
        if isinstance(editor, QLineEdit):
            model.setData(index, QVariant(editor.text()))
            #if _DBG_VERBOSE: print "done"
        elif isinstance(editor, Qwt.QwtSlider):
            model.setData(index, QVariant(editor.value()))
            #if _DBG_VERBOSE: print "done"
        else:
            #if _DBG_VERBOSE: print "skip"
            pass
Пример #37
0
 def createEditor(self, parent, option, index):
     node = index.internalPointer()
     if node.typeInfo == 'CODE':
         if node.valueFormat == 'percent':
             editor = QDoubleSpinBox(parent)
             editor.setSuffix('%')
         elif node.valueFormat == 'integer':
             editor = QSpinBox(parent)
         else:
             editor = QDoubleSpinBox(parent)
         editor.setMaximum(100000000)
     elif node.typeInfo == 'BAREME':
         editor = QPushButton(parent)
         editor.setText('Editer')
         value = node._value
         value.marToMoy()
         self.baremeDialog = BaremeDialog(value, self._parent)
         self.connect(editor, SIGNAL('clicked()'), self.runBaremeDialog)
         self.runBaremeDialog()
     else:
         editor = QStyledItemDelegate.createEditor(self, parent, option,
                                                   index)
     return editor
Пример #38
0
 def sizeHint(self, option, index):
     return QStyledItemDelegate.sizeHint(self, option, index)
Пример #39
0
 def updateEditorGeometry(self, editor, opt, index):
     #print "geometry:", opt.rect
     #opt.rect.adjust(0, 30, 100, 60)
     QStyledItemDelegate.updateEditorGeometry(self, editor, opt, index)
Пример #40
0
 def createEditor(self, parent, option, index):
     return QStyledItemDelegate.createEditor(self, parent, option, index)
Пример #41
0
 def __init__(self, viewWidget):
     QStyledItemDelegate.__init__(self)
     self.viewWidget = viewWidget
     self.counter = 0
Пример #42
0
 def sizeHint(self, option, index):
     size = QStyledItemDelegate.sizeHint(self, option, index)
     return QSize(size.width(), size.height() + 4)
Пример #43
0
 def setEditorData(self, editor, index):
     layer = index.data().toPyObject()
     if isinstance(layer, Layer):
         editor.layer = layer
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
Пример #44
0
 def setModelData(self, editor, model, index):
     layer = index.data().toPyObject()
     if isinstance(layer, Layer):
         model.setData(index, editor.layer)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Пример #45
0
 def __init__(self):
     QStyledItemDelegate.__init__(self)
Пример #46
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
Пример #47
0
 def __init__(self, sortingModel, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.sortingModel = sortingModel
Пример #48
0
 def paint(self, painter, option, index):
     myoption = QStyleOptionViewItem(option)
     myoption.displayAlignment |= (Qt.AlignRight | Qt.AlignVCenter)
     QStyledItemDelegate.paint(self, painter, myoption, index)
Пример #49
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
Пример #50
0
 def paint(self, painter, option, index):
     delegate = self.delegates.get(index.column())
     if delegate is not None:
         delegate.paint(painter, option, index)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
Пример #51
0
 def setModelData(self, editor, model, index):
     delegate = self.delegates.get(index.column())
     if delegate is not None:
         delegate.setModelData(editor, model, index)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Пример #52
0
 def paint(self, painter, option, index):
     painter.save()
     painter.setPen(QColor(212, 212, 212))
     painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
     painter.restore()
     QStyledItemDelegate.paint(self, painter, option, index)
Пример #53
0
 def paint(self, painter, option, index):
     model = index.model()
     row, col = index.row(), index.column()
     QStyledItemDelegate.paint(self, painter, option, index)
Пример #54
0
 def sizeHint(self, option, index):
     " Returns the size hint in which the only height matters "
     origSize = QStyledItemDelegate.sizeHint(self, option, index)
     self.lastHeight = origSize.height() + self.delta
     origSize.setHeight(self.lastHeight)
     return origSize
Пример #55
0
    def __init__(self, iface, db, parent=None):
        QWidget.__init__(self, parent)
        self.iface = iface
        self.db = db
        self.filter = ""
        self.allowMultiColumnPk = isinstance(
            db, PGDatabase
        )  # at the moment only PostGIS allows a primary key to span multiple columns, spatialite doesn't
        self.setupUi(self)
        self.setWindowTitle(
            u"%s - %s [%s]" %
            (self.windowTitle(), db.connection().connectionName(),
             db.connection().typeNameString()))

        self.defaultLayerName = 'QueryLayer'

        if self.allowMultiColumnPk:
            self.uniqueColumnCheck.setText(
                self.trUtf8("Column(s) with unique values"))
        else:
            self.uniqueColumnCheck.setText(
                self.trUtf8("Column with unique values"))

        self.editSql.setFocus()
        self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.initCompleter()

        # allow to copy results
        copyAction = QAction("copy", self)
        self.viewResult.addAction(copyAction)
        copyAction.setShortcuts(QKeySequence.Copy)

        copyAction.triggered.connect(self.copySelectedResults)

        self.btnExecute.clicked.connect(self.executeSql)
        self.btnSetFilter.clicked.connect(self.setFilter)
        self.btnClear.clicked.connect(self.clearSql)

        self.presetStore.clicked.connect(self.storePreset)
        self.presetDelete.clicked.connect(self.deletePreset)
        self.presetCombo.activated[str].connect(self.loadPreset)
        self.presetCombo.activated[str].connect(self.presetName.setText)

        self.updatePresetsCombobox()

        self.geomCombo.setEditable(True)
        self.geomCombo.lineEdit().setReadOnly(True)

        self.uniqueCombo.setEditable(True)
        self.uniqueCombo.lineEdit().setReadOnly(True)
        self.uniqueModel = QStandardItemModel(self.uniqueCombo)
        self.uniqueCombo.setModel(self.uniqueModel)
        if self.allowMultiColumnPk:
            self.uniqueCombo.setItemDelegate(QStyledItemDelegate())
            self.uniqueModel.itemChanged.connect(
                self.uniqueChanged)  # react to the (un)checking of an item
            self.uniqueCombo.lineEdit().textChanged.connect(
                self.uniqueTextChanged
            )  # there are other events that change the displayed text and some of them can not be caught directly

        # hide the load query as layer if feature is not supported
        self._loadAsLayerAvailable = self.db.connector.hasCustomQuerySupport()
        self.loadAsLayerGroup.setVisible(self._loadAsLayerAvailable)
        if self._loadAsLayerAvailable:
            self.layerTypeWidget.hide()  # show if load as raster is supported
            self.loadLayerBtn.clicked.connect(self.loadSqlLayer)
            self.getColumnsBtn.clicked.connect(self.fillColumnCombos)
            self.loadAsLayerGroup.toggled.connect(self.loadAsLayerToggled)
            self.loadAsLayerToggled(False)

        self._createViewAvailable = self.db.connector.hasCreateSpatialViewSupport(
        )
        self.btnCreateView.setVisible(self._createViewAvailable)
        if self._createViewAvailable:
            self.btnCreateView.clicked.connect(self.createView)

        self.queryBuilderFirst = True
        self.queryBuilderBtn.setIcon(QIcon(":/db_manager/icons/sql.gif"))
        self.queryBuilderBtn.clicked.connect(self.displayQueryBuilder)

        self.presetName.textChanged.connect(self.nameChanged)
Пример #56
0
 def __init__(self, parent=None, items_pair=None):
     QStyledItemDelegate.__init__(self, parent)
     self._items_pair = items_pair
     if self._items_pair is None:
         self._items_pair = [[], []]
Пример #57
0
    def __init__(self, iface, layer, parent=None):
        QWidget.__init__(self, parent)
        self.iface = iface
        self.layer = layer

        uri = QgsDataSourceURI(layer.source())
        dbplugin = None
        db = None
        if layer.dataProvider().name() == 'postgres':
            dbplugin = createDbPlugin('postgis', 'postgres')
        elif layer.dataProvider().name() == 'spatialite':
            dbplugin = createDbPlugin('spatialite', 'spatialite')
        elif layer.dataProvider().name() == 'oracle':
            dbplugin = createDbPlugin('oracle', 'oracle')
        elif layer.dataProvider().name() == 'virtual':
            dbplugin = createDbPlugin('vlayers', 'virtual')
        elif layer.dataProvider().name() == 'ogr':
            dbplugin = createDbPlugin('gpkg', 'gpkg')
        if dbplugin:
            dbplugin.connectToUri(uri)
            db = dbplugin.db

        self.dbplugin = dbplugin
        self.db = db
        self.filter = ""
        self.allowMultiColumnPk = isinstance(db, PGDatabase) # at the moment only PostgreSQL allows a primary key to span multiple columns, spatialite doesn't
        self.aliasSubQuery = isinstance(db, PGDatabase) # only PostgreSQL requires subqueries to be aliases
        self.setupUi(self)
        self.setWindowTitle(
            u"%s - %s [%s]" % (self.windowTitle(), db.connection().connectionName(), db.connection().typeNameString()))

        self.defaultLayerName = 'QueryLayer'

        if self.allowMultiColumnPk:
            self.uniqueColumnCheck.setText(self.trUtf8("Column(s) with unique values"))
        else:
            self.uniqueColumnCheck.setText(self.trUtf8("Column with unique values"))

        self.editSql.setFocus()
        self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.editSql.setMarginVisible(True)
        self.initCompleter()

        # allow copying results
        copyAction = QAction("copy", self)
        self.viewResult.addAction(copyAction)
        copyAction.setShortcuts(QKeySequence.Copy)

        copyAction.triggered.connect(self.copySelectedResults)

        self.btnExecute.clicked.connect(self.executeSql)
        self.btnSetFilter.clicked.connect(self.setFilter)
        self.btnClear.clicked.connect(self.clearSql)

        self.presetStore.clicked.connect(self.storePreset)
        self.presetDelete.clicked.connect(self.deletePreset)
        self.presetCombo.activated[str].connect(self.loadPreset)
        self.presetCombo.activated[str].connect(self.presetName.setText)

        self.updatePresetsCombobox()

        self.geomCombo.setEditable(True)
        self.geomCombo.lineEdit().setReadOnly(True)

        self.uniqueCombo.setEditable(True)
        self.uniqueCombo.lineEdit().setReadOnly(True)
        self.uniqueModel = QStandardItemModel(self.uniqueCombo)
        self.uniqueCombo.setModel(self.uniqueModel)
        if self.allowMultiColumnPk:
            self.uniqueCombo.setItemDelegate(QStyledItemDelegate())
            self.uniqueModel.itemChanged.connect(self.uniqueChanged)                # react to the (un)checking of an item
            self.uniqueCombo.lineEdit().textChanged.connect(self.uniqueTextChanged) # there are other events that change the displayed text and some of them can not be caught directly

        self.layerTypeWidget.hide()  # show if load as raster is supported
        #self.loadLayerBtn.clicked.connect(self.loadSqlLayer)
        self.updateLayerBtn.clicked.connect(self.updateSqlLayer)
        self.getColumnsBtn.clicked.connect(self.fillColumnCombos)

        self.queryBuilderFirst = True
        self.queryBuilderBtn.setIcon(QIcon(":/db_manager/icons/sql.gif"))
        self.queryBuilderBtn.clicked.connect(self.displayQueryBuilder)

        self.presetName.textChanged.connect(self.nameChanged)

        # Update from layer
        # Fisrtly the SQL from QgsDataSourceURI table
        sql = uri.table()
        if uri.keyColumn() == '_uid_':
            match = re.search('^\(SELECT .+ AS _uid_,\* FROM \((.*)\) AS _subq_.+_\s*\)$', sql, re.S)
            if match:
                sql = match.group(1)
        else:
            match = re.search('^\((SELECT .+ FROM .+)\)$', sql, re.S)
            if match:
                sql = match.group(1)
        self.editSql.setText(sql)
        self.executeSql()

        # Then the columns
        self.geomCombo.setCurrentIndex(self.geomCombo.findText(uri.geometryColumn(), Qt.MatchExactly))
        if uri.keyColumn() != '_uid_':
            self.uniqueColumnCheck.setCheckState(Qt.Checked)
            if self.allowMultiColumnPk:
                itemsData = uri.keyColumn().split(',')
                for item in self.uniqueModel.findItems("*", Qt.MatchWildcard):
                    if item.data() in itemsData:
                        item.setCheckState(Qt.Checked)
            else:
                keyColumn = uri.keyColumn()
                if self.uniqueModel.findItems(keyColumn):
                    self.uniqueCombo.setEditText(keyColumn)

        # Finally layer name, filter and selectAtId
        self.layerNameEdit.setText(layer.name())
        self.filter = uri.sql()
        if uri.selectAtIdDisabled():
            self.avoidSelectById.setCheckState(Qt.Checked)
 def __init__(self, parent=None, *args):
     QStyledItemDelegate.__init__(self, parent, *args)
Пример #59
0
 def eventFilter(self, editor, event):
     if event.type() == QEvent.FocusOut and hasattr(editor, 'canFocusOut'):
         if not editor.canFocusOut:
             return False
     return QStyledItemDelegate.eventFilter(self, editor, event)
 def createEditor(self, parent, option, index):
     if index.model().get_item(index).waiting_evaluation:
         return AskVerdict(parent, self)
     else:
         return QStyledItemDelegate.createEditor(self, parent, option,
                                                 index)