Exemplo n.º 1
1
 def setEditorData(self, editor, index):
     """ load data from model to editor """
     m = index.model()
     if index.column() == 1:
         txt = m.data(index, Qt.DisplayRole)
         editor.setEditText(txt)
     else:
         # use default
         QItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 2
0
 def __init__(self, min, max, *args):
     """
     min and max are the limits that the spin box can scroll to/accept.
     """
     QItemDelegate.__init__(self, *args)
     self.min = min
     self.max = max
Exemplo n.º 3
0
 def __init__(self, parent):
     QItemDelegate.__init__(self, parent)
     self.margin_left = 5
     self.margin_top = 7
     self.height = 10
     self.icon_size = 17
     self.width = 300
Exemplo n.º 4
0
 def __init__(self, parent, itemsDict, column):
     """
     Constructor
     """
     QItemDelegate.__init__(self, parent)
     self.itemsDict = itemsDict
     self.column = column
Exemplo n.º 5
0
 def setModelData(self, editor, model, index):
     """ save data from editor back to model """
     if index.column() == self.column:
         model.setData(index, editor.currentText())
     else:
         # use default
         QItemDelegate.setModelData(self, editor, model, index)
Exemplo n.º 6
0
 def __init__(self, parent, itemsDict, column):
     """
     Constructor
     """
     QItemDelegate.__init__(self, parent)
     self.itemsDict = itemsDict
     self.column = column
Exemplo n.º 7
0
 def setModelData(self,editor,model,index):
     """Save value changes"""
     if index.column() == 1:
         value, ok = editor.itemData(editor.currentIndex()).toInt()
         model.setData(index,QVariant(value),Qt.EditRole)
     else:
         QItemDelegate.setModelData(self,editor,model,index)
Exemplo n.º 8
0
 def setModelData(self, editor, model, index):
     """ save data from editor back to model """
     if index.column() == self.column:
         model.setData(index, editor.currentText())
     else:
         # use default
         QItemDelegate.setModelData(self, editor, model, index)
Exemplo n.º 9
0
 def updateEditorGeometry(self, editor, option, index):
     ''' PyQt API Method -- See the PyQt documentation for a description '''
     if type(editor) == QComboBox:
         editor.setGeometry(option.rect)
         editor.showPopup()
     else:
         QItemDelegate.updateEditorGeometry(self, editor, option, index)
Exemplo n.º 10
0
    def __init__(self, columns=(), parent=None):
        """ Construtor.

        @param columns sequence of column numbers for LCD widgets
        @param parent ancestor object
        """
        QItemDelegate.__init__(self, parent)
        self.columns = columns
Exemplo n.º 11
0
    def __init__(self, owner):
        """
        Checkbox delegate

        @param value: 
        @type value:
        """
        QItemDelegate.__init__(self, owner)
Exemplo n.º 12
0
 def setModelData(self, editor, model, index):
     if index.column() == 0:
         #print "cleaning"
         value = cleanXMLtag(editor.text())
         #print value
         model.setData(index, value)
     else:
         QItemDelegate.setModelData(self, editor, model, index)
Exemplo n.º 13
0
 def __init__(self, distObjects, parent=None):
     """Init TracepointModel
     """
     QAbstractTableModel.__init__(self, parent)
     QItemDelegate.__init__(self, parent)
     self.tracepoints = []
     self.distObjects = distObjects
     self.connector = distObjects.gdb_connector
Exemplo n.º 14
0
 def setModelData(self, editor, model, index):
     """ save data from editor back to model """
     if index.column() == 1:
         model.setData(index, editor.currentText())
     else:
         # use default
         QItemDelegate.setModelData(self, editor, model, index)
         if index.column() == 0:
             self.emit(SIGNAL("columnNameChanged()"))
Exemplo n.º 15
0
 def setEditorData(self, editor, index):
     """ load data from model to editor """
     m = index.model()
     if index.column() == 1:
         txt = m.data(index, Qt.DisplayRole)
         editor.setEditText(txt)
     else:
         # use default
         QItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 16
0
 def setEditorData(self, editor, index):
     text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
     if index.column() in (MOD1, MOD2, MOD3, KEY):
         i = editor.findText(text)
         if i == -1:
             i = 0
         editor.setCurrentIndex(i)
     else:
         QItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 17
0
 def paint(self, painter, option, index):
     if index.row() != 0:
         topLeft = option.rect.topLeft()
         topRight = option.rect.topRight()
         bottomLeft = option.rect.bottomLeft()
         bottomRight = option.rect.bottomRight()
         painter.drawLine(topLeft,topRight)
         #painter.drawLine(bottomLeft,bottomRight)
     QItemDelegate.paint(self, painter, option, index)
Exemplo n.º 18
0
 def createEditor (self, parent, option, index):
     try:
         content = index.model().data(index, Qt.EditRole)
         if content == None:
             return None
     except:
         return None
     column = index.column()
     row = index.row()
     parentNode = index.model().data(index.parent(), Qt.EditRole)
     self.currentIndex = index
     
     q_type = QVariant.nameToType(index.model().data(index.sibling(0,7), Qt.DisplayRole))
     if column == 1 and parentNode:  # combobox for field mapping
         currentLayer = self.iface.legendInterface().currentLayer()
         editorQWidget = QComboBox(parent)
         fieldItems = []
         for field in self.iface.legendInterface().currentLayer().pendingFields():
             fieldItems.append(field.name())
         if not content in fieldItems:
             fieldItems.append(content)
         editorQWidget.addItems(fieldItems)
         editorQWidget.setCurrentIndex(editorQWidget.findText(content))
         return editorQWidget
     if column == 3 and parentNode: # combobox for odk types
         editorQWidget = QComboBox(parent)
         #QVariantType = indexQModelIndex.model().item(row,7).data()
         if content in ['text','note','image','barcode','audio','video']:
             combobox_items = ['text','note','image','barcode','audio','video','select one']
         elif content in ['date', 'datetime']:
             combobox_items = ['date', 'time', 'datetime']
         elif content in ['geopoint','geoshape','geotrace']:
             combobox_items = ['geopoint','geoshape','geotrace']
         elif content in ['select one']:
             combobox_items = ['select one', QVariantToODKtype(q_type)]
         elif content in ['select type']:
             combobox_items = ['text','decimal','integer','date','time','datetime','geopoint','geoshape','geotrace','image','barcode','audio','video','select one']
         else:
             combobox_items = [content,'select one']
         editorQWidget.addItems(combobox_items)
         editorQWidget.setCurrentIndex(editorQWidget.findText(content))
         editorQWidget.currentIndexChanged.connect(self.changeAppearanceAccordingly)
         return editorQWidget
     elif column == 9 and parentNode: # qdialog for value/label map
         content = QgisODKChoices.getChoices(content, q_type, title = parentNode)
         index.model().setData(index,content, Qt.DisplayRole)
         QItemDelegate.createEditor(self, parent, option, index)
     elif column == 10 and parentNode: # combobox for appearance
         contentType = index.model().data(index.sibling(0,3), Qt.DisplayRole)
         if contentType == '' or not contentType in appearanceDef.keys():
             return
         editorQWidget = QComboBox(parent)
         editorQWidget.addItems(appearanceDef[contentType])
         #editorQWidget.setCurrentIndex(0)
         return editorQWidget
     else:
         return QItemDelegate.createEditor(self, parent, option, index)
    def __init__(self, parent_view):
        """
        @param parent_view (QAbstractItemView): parent view for this item editor
        """
        QItemDelegate.__init__(self, parent_view)
        self.parent_view = parent_view

        # List of database connection names. Used for populating the editor for a db_connection_hook
        self.known_db_connection_names = []
Exemplo n.º 20
0
    def __init__(self, parent_view):
        '''
        @param parent_view (QAbstractItemView): parent view for this item editor
        '''
        QItemDelegate.__init__(self, parent_view)
        self.parent_view = parent_view

        # List of database connection names. Used for populating the editor for a db_connection_hook
        self.known_db_connection_names = []
Exemplo n.º 21
0
 def setModelData(self, editor, model, index):
     """ save data from editor back to model """
     if index.column() == 1:
         model.setData(index, editor.currentText())
     else:
         # use default
         QItemDelegate.setModelData(self, editor, model, index)
         if index.column() == 0:
             self.emit(SIGNAL("columnNameChanged()"))
Exemplo n.º 22
0
    def __init__(self, parent, col_):
        """
        @param value: 
        @type value:

        @param value: 
        @type value:
        """
        QItemDelegate.__init__(self, parent)
        self.col_ = col_
Exemplo n.º 23
0
 def setEditorData(self,editor,index):
     """Set initial data for the editor"""
     if index.column() == 0:
         current = index.model().data(index,Qt.DisplayRole)
         editor.setText(current)
     elif index.column() == 1:
         current = index.model().data(index,Qt.DisplayRole)
         editor.setCurrentIndex(editor.findData(current))
     else:
         QItemDelegate.setEditorData(self,editor,index)
Exemplo n.º 24
0
class EditResDlg(QDialog):
    def __init__(self, images, scales, images_path, *args):
        QDialog.__init__(self, *args)
        cache = image_cache.cache
        self.ui = Ui_EditResDlg()
        self.ui.setupUi(self)
        icons = []
        for pth in images_path:
            ico = QIcon(
                QPixmap.fromImage(
                    cache.image(pth).scaled(QSize(64, 64),
                                            Qt.KeepAspectRatio)))
            icons.append(ico)
        self.model = ScaleModel(icons, images, scales)
        self.ui.pixelSizes.setModel(self.model)
        self.ui.pixelSizes.resizeColumnToContents(0)
        self.ui.pixelSizes.resizeColumnToContents(1)
        self.ui.pixelSizes.resizeColumnToContents(2)
        self.item_delegate = QItemDelegate()
        self.item_delegate.setItemEditorFactory(ScaleEditorFactory())
        self.ui.pixelSizes.setItemDelegate(self.item_delegate)
        self.ui.width.setValidator(QDoubleValidator(0, 1e300, 100, self))
        self.ui.height.setValidator(QDoubleValidator(0, 1e300, 100, self))
        # Find smallest scale
        minx = inf
        miny = inf
        for img in scales:
            sc = scales[img]
            if sc[0] > 0 and sc[0] < minx:
                minx = sc[0]
            if sc[1] > 0 and sc[1] < miny:
                miny = sc[1]
        if minx == inf:
            minx = 1e-6
        if miny == inf:
            miny = 1e-6
        # And set the default unit
        self.ui.unit.setCurrentIndex(self.model.findUnit(min(minx, miny)))

    def __del__(self):
        cleanQObject(self)

    @pyqtSignature("int")
    def on_unit_currentIndexChanged(self, idx):
        self.model.setUnit(self.ui.unit.currentText())

    @pyqtSignature("")
    def on_setAll_clicked(self):
        sel = self.ui.pixelSizes.selectionModel()
        w = float(self.ui.width.text())
        h = float(self.ui.height.text())
        if sel.hasSelection():
            self.model.setSubset(w, h, sel)
        else:
            self.model.setAll(w, h)
Exemplo n.º 25
0
 def paint(self, painter, option, index):
     option.palette.setColor(
         QPalette.Highlight,QColor(
             index.data(Qt.BackgroundRole)).darker(107))
     option.palette.setColor(
         QPalette.HighlightedText,QColor(
             index.data(Qt.ForegroundRole)).darker(115))
     QItemDelegate.paint(self, painter, option, index)
     if option.showDecorationSelected and \
             (option.state & QStyle.State_Selected):
         painter.drawRect(option.rect)
Exemplo n.º 26
0
 def paint(self, painter, option, index):
 
     if index.column() != 0:
         QItemDelegate.paint(self, painter, option, index)
         return
     
     painter.fillRect(option.rect, option.palette.brush(QPalette.Base))
     painter.setPen(QPen(option.palette.color(QPalette.Text)))
     painter.drawText(option.rect.adjusted(4, 4, -4, -4),
         Qt.TextShowMnemonic | Qt.AlignLeft | Qt.AlignVCenter,
         index.data().toString())
Exemplo n.º 27
0
 def paint(self, painter, option, index):
     option.palette.setColor(
         QPalette.Highlight,
         QColor(index.data(Qt.BackgroundRole)).darker(107))
     option.palette.setColor(
         QPalette.HighlightedText,
         QColor(index.data(Qt.ForegroundRole)).darker(115))
     QItemDelegate.paint(self, painter, option, index)
     if option.showDecorationSelected and \
             (option.state & QStyle.State_Selected):
         painter.drawRect(option.rect)
Exemplo n.º 28
0
 def setModelData(self, editor, model, index):
     """ save data from editor back to model """
     if index.column() == self.column:
         checkedItems = []
         for i in range(editor.count()):
             item = editor.item(i)
             if item.checkState() == Qt.Checked:
                 checkedItems.append(item.text())
         model.setData(index, '{%s}' % ','.join(checkedItems))
     else:
         # use default
         QItemDelegate.setModelData(self, editor, model, index)
Exemplo n.º 29
0
 def setModelData(self, editor, model, index):
     """ save data from editor back to model """
     if index.column() == self.column:
         checkedItems = []
         for i in range(editor.count()):
             item = editor.item(i)
             if item.checkState() == Qt.Checked:
                 checkedItems.append(item.text())
         model.setData(index, '{%s}' % ','.join(checkedItems))
     else:
         # use default
         QItemDelegate.setModelData(self, editor, model, index)
Exemplo n.º 30
0
 def paint (self, painter, option, index):
     if not (QStyle.State_Selected & option.state):
         r = QRect(option.rect)
         r.setX(0)
         # test if item/device is in use
         if index.data(Qt.UserRole).toBool():
             painter.setBrush(QColor(255, 0, 0, 32))
         else:
             painter.setBrush(QColor(0, 255, 0, 128))
         painter.setPen(Qt.lightGray)
         painter.drawRect(r)
     QItemDelegate.paint(self, painter, option, index)
Exemplo n.º 31
0
    def __init__(self, parent=None, editable=True, **kwargs):
        """:param parent: the parent object for the delegate
        :param editable: a boolean indicating if the field associated to the delegate
        is editable

        """
        QItemDelegate.__init__(self, parent)
        self.editable = editable
        self.kwargs = kwargs
        self._font_metrics = QtGui.QFontMetrics(QtGui.QApplication.font())
        self._height = self._font_metrics.lineSpacing() + 10
        self._width = self._font_metrics.averageCharWidth() * 20
Exemplo n.º 32
0
class EditResDlg(QDialog):
    def __init__(self, images, scales, images_path, *args):
        QDialog.__init__(self, *args)
        cache = image_cache.cache
        self.ui = Ui_EditResDlg()
        self.ui.setupUi(self)
        icons = []
        for pth in images_path:
            ico = QIcon(QPixmap.fromImage(cache.image(pth).scaled(QSize(64, 64), Qt.KeepAspectRatio)))
            icons.append(ico)
        self.model = ScaleModel(icons, images, scales)
        self.ui.pixelSizes.setModel(self.model)
        self.ui.pixelSizes.resizeColumnToContents(0)
        self.ui.pixelSizes.resizeColumnToContents(1)
        self.ui.pixelSizes.resizeColumnToContents(2)
        self.item_delegate = QItemDelegate()
        self.item_delegate.setItemEditorFactory(ScaleEditorFactory())
        self.ui.pixelSizes.setItemDelegate(self.item_delegate)
        self.ui.width.setValidator(QDoubleValidator(0, 1e300, 100, self))
        self.ui.height.setValidator(QDoubleValidator(0, 1e300, 100, self))
        # Find smallest scale
        minx = inf
        miny = inf
        for img in scales:
            sc = scales[img]
            if sc[0] > 0 and sc[0] < minx:
                minx = sc[0]
            if sc[1] > 0 and sc[1] < miny:
                miny = sc[1]
        if minx == inf:
            minx = 1e-6
        if miny == inf:
            miny = 1e-6
        # And set the default unit
        self.ui.unit.setCurrentIndex(self.model.findUnit(min(minx, miny)))

    def __del__(self):
        cleanQObject(self)

    @pyqtSignature("int")
    def on_unit_currentIndexChanged(self, idx):
        self.model.setUnit(self.ui.unit.currentText())

    @pyqtSignature("")
    def on_setAll_clicked(self):
        sel = self.ui.pixelSizes.selectionModel()
        w = float(self.ui.width.text())
        h = float(self.ui.height.text())
        if sel.hasSelection():
            self.model.setSubset(w, h, sel)
        else:
            self.model.setAll(w, h)
Exemplo n.º 33
0
    def __init__(self, data, options, parent=None):
        """
        Initializes STRTypeDelegate and QItemDelegate.
        :param spatial_unit: The current spatial unit.
        :param type: Object
        :param parent: The parent of the item delegate.
        :type parent: QWidget
        """
        QItemDelegate.__init__(self, parent)
        self.data = data
        self.options = options

        self._view = parent
Exemplo n.º 34
0
    def __init__(self, role, pixmap_on, pixmap_off, text_on, text_off, style_on, style_off, parent=None):
        QItemDelegate.__init__(self, parent)
        self.pixmap_on = pixmap_on
        self.pixmap_off = pixmap_off
        self.text_on = text_on
        self.text_off = text_off
        self.style_on = style_on
        self.style_off = style_off
        self.role = role

        self.icon = QIcon()
        self.icon.addPixmap(pixmap_on, QIcon.Normal, QIcon.On)
        self.icon.addPixmap(pixmap_off, QIcon.Normal, QIcon.Off)
Exemplo n.º 35
0
    def __init__ (self, parent, colId):
        """
        Contructs ItemComboDelegate item delegate
        
        @param parent: 
        @type parent:

        @param colId: 
        @type colId:
        """
        QItemDelegate.__init__(self, parent)
        self.owner = parent
        self.colId = colId
Exemplo n.º 36
0
    def __init__(self, str_type_id=0, parent=None):
        """
        Initializes STRTypeDelegate and QItemDelegate.
        :param str_type_id: The tenure type id.
        :type str_type_id: Integer
        :param parent: The parent of the item delegate.
        :type parent: QWidget
        """
        QItemDelegate.__init__(self, parent)
        self.str_type_id = str_type_id
        self.curr_profile = current_profile()

        self.social_tenure = self.curr_profile.social_tenure
Exemplo n.º 37
0
 def setEditorData(self, editor, index):
     model = index.model()
     horse = model.horseList[index.row()]
     if model.isColumn("name", index):
         editor.setText(horse.name)
     elif model.isColumn("rating", index):
         ratingIndex = model.getColumn("rating", index)
         editor.setValue(horse[ratingIndex])
     elif model.isColumn("adjust", index):
         adjustIndex = model.getColumn("adjust", index)
         editor.setValue(model.race.adjusts.getAdjust(model.race.adjusts[adjustIndex], horse))
     else:
         QItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 38
0
    def __init__(self, data, options, parent=None):
        """
        Initializes STRTypeDelegate and QItemDelegate.
        :param spatial_unit: The current spatial unit.
        :param type: Object
        :param parent: The parent of the item delegate.
        :type parent: QWidget
        """
        QItemDelegate.__init__(self, parent)
        self.data = data
        self.options = options

        self._view = parent
Exemplo n.º 39
0
    def __init__(self, spatial_unit, parent=None):
        """
        Initializes STRTypeDelegate and QItemDelegate.
        :param spatial_unit: The current spatial unit.
        :param type: Object
        :param parent: The parent of the item delegate.
        :type parent: QWidget
        """
        QItemDelegate.__init__(self, parent)

        self.curr_profile = current_profile()

        self.social_tenure = self.curr_profile.social_tenure
        self.spatial_unit = spatial_unit
Exemplo n.º 40
0
    def __init__(self, parent, width, height):
        QItemDelegate.__init__(self, parent)

        self.itemWidth = width
        self.itemHeight = height
        self.checkedIcon = None
        self.partiallyCheckedIcon = None
        self.uncheckedIcon = None
        self.pixmapUnckecked = QPixmap(self.itemWidth, self.itemHeight)
        self.drawPixmapForUnckecked()
        self.pixmapCkecked = QPixmap(self.itemWidth, self.itemHeight)
        self.drawPixmapForCkecked()
        self.pixmapPartiallyChecked = QPixmap(self.itemWidth, self.itemHeight)
        self.drawPixmapForPartiallyChecked()
Exemplo n.º 41
0
 def paint(self,painter,option,index):
     if index.column() == 1:
         progress = int(index.model().data(index, Qt.DisplayRole))
         progressBarOption = QStyleOptionProgressBarV2()
         progressBarOption.state = QStyle.State_Enabled
         progressBarOption.direction = QApplication.layoutDirection()
         progressBarOption.rect = option.rect
         progressBarOption.fontMetrics = QApplication.fontMetrics()
         progressBarOption.textVisible = True
         progressBarOption.textAlignment = Qt.AlignCenter
         progressBarOption.minimum = 0
         row = index.row()
         maximum = index.model().record(row).value('size')
         if maximum == '未知':
             progressBarOption.maximum = 10000000
             progressBarOption.text = '0%'
             progressBarOption.progress = 0
         else:
             progressBarOption.maximum = int(maximum)
             progressBarOption.progress = progress
             ratio = int(progress*100/int(maximum))
             progressBarOption.text = '%s'%ratio+'%'
         QApplication.style().drawControl(QStyle.CE_ProgressBar,progressBarOption,painter)
     elif index.column() == 2:
         if index.model().data(index) != '未知':
             length = int(index.model().data(index, Qt.EditRole))
             lengthMB = length/(1024*1024)
             size = round(lengthMB, 1)
             text = '%s'%size+'M'
             QApplication.style().drawItemText(painter, option.rect, Qt.AlignLeft and Qt.AlignVCenter, QApplication.palette(), True, text)
         else:
             return QItemDelegate.paint(self,painter,option,index)
     elif index.column() == 3 :
         if index.model().data(index) not in ["已完成", "已取消", "等待", "已暂停", "出错"]:
             remainSeconds = float(index.model().data(index))
             hours = int(remainSeconds/3600)
             minutes = int((remainSeconds%3600)/60)
             seconds = round((remainSeconds)%3600%60, 1)
             if remainSeconds >= 3600:
                 remainTime = '%sh%sm%ss'%(hours, minutes, int(seconds))
             elif  remainSeconds < 3600 and remainSeconds >= 60:
                 remainTime = '%sm%ss'%(minutes, int(seconds))
             else:
                 remainTime = '%ss'%seconds
             text = remainTime
             QApplication.style().drawItemText(painter, option.rect, Qt.AlignLeft and Qt.AlignVCenter, QApplication.palette(), True, text)
         else:
             return QItemDelegate.paint(self,painter,option,index)
     else:
         return QItemDelegate.paint(self,painter,option,index)
Exemplo n.º 42
0
    def __init__(self, spatial_unit, parent=None):
        """
        Initializes STRTypeDelegate and QItemDelegate.
        :param spatial_unit: The current spatial unit.
        :param type: Object
        :param parent: The parent of the item delegate.
        :type parent: QWidget
        """
        QItemDelegate.__init__(self, parent)

        self.curr_profile = current_profile()

        self.social_tenure = self.curr_profile.social_tenure
        self.spatial_unit = spatial_unit
Exemplo n.º 43
0
 def setEditorData(self, editor, index):
     """
     Changes how model data are displayed in widget.
     :param editor: QWidget used for editing
     :param index: QModelIndex, index for model
     """
     if index.column() == ELEMENT:
         set_combobox_to_model_value(editor, index, self.element_codes)
     elif index.column() == HIERARCHY:
         set_combobox_to_model_value(editor, index, self.hierarchy_codes)
     elif index.column() == OFFSET:
         set_combobox_to_model_value(editor, index, self.offset_codes)
     else:
         QItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 44
0
 def __init__(self, parent, width, height):
     QItemDelegate.__init__(self, parent)
     
     self.itemWidth = width
     self.itemHeight = height
     self.checkedIcon = None
     self.partiallyCheckedIcon = None
     self.uncheckedIcon = None
     self.pixmapUnckecked = QPixmap(self.itemWidth, self.itemHeight)
     self.drawPixmapForUnckecked()
     self.pixmapCkecked = QPixmap(self.itemWidth, self.itemHeight)
     self.drawPixmapForCkecked()
     self.pixmapPartiallyChecked = QPixmap(self.itemWidth, self.itemHeight)
     self.drawPixmapForPartiallyChecked()
Exemplo n.º 45
0
    def __init__ (self, parent, col_ ):
        """
        Contructs ComboValueDelegate item delegate
        
        @param parent: 
        @type parent:

        @param items_: 
        @type items_:

        @param col_: 
        @type col_:
        """
        QItemDelegate.__init__(self, parent)
        self.parent = parent
Exemplo n.º 46
0
    def __init__ (self, parent, col_ ):
        """
        Contructs NameDelegate item delegate
        
        @param parent: 
        @type parent:

        @param items_: 
        @type items_:

        @param col_: 
        @type col_:
        """
        QItemDelegate.__init__(self, parent)
        self.col_ = col_
Exemplo n.º 47
0
 def setEditorData(self, editor, index):
     """ load data from model to editor """
     m = index.model()
     try:
         if index.column() == self.column:
             txt = m.data(index, Qt.DisplayRole)
             checkList = txt[1:-1].split(',')
             for i in range(editor.count()):
                 item = editor.item(i)
                 item.setCheckState(Qt.Checked if item.text() in checkList else Qt.Unchecked)
         else:
             # use default
             QItemDelegate.setEditorData(self, editor, index)
     except:
         pass
Exemplo n.º 48
0
    def __init__(self, parent):
        """
        Contructs Action item delegate
        
        @param parent: 
        @type parent:

        @param items_: 
        @type items_:

        @param col_: 
        @type col_:
        """
        QItemDelegate.__init__(self, parent)
        self.owner = parent
Exemplo n.º 49
0
    def paint(self, painter, option, index):
        """ Draw a button-style on root items """
        model = index.model()
        assert model


        if not model.parent(index).isValid():
            # this is a top-level item.
            buttonOption = QStyleOptionButton()

            buttonOption.state = option.state
            buttonOption.state &= ~QStyle.State_HasFocus

            buttonOption.rect = option.rect
            buttonOption.palette = option.palette
            buttonOption.features = QStyleOptionButton.None

            self.m_view.style().drawControl(QStyle.CE_PushButton, buttonOption, painter, self.m_view)

            branchOption = QStyleOption()
            i = 15  ### hardcoded in qcommonstyle.cpp
            r = option.rect
            branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i)
            branchOption.palette = option.palette
#            branchOption.state = QStyle.State_Children

            if self.m_view.isExpanded(index):
                branchOption.state |= QStyle.State_Open

            self.m_view.style().drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, painter, self.m_view)

            # draw text
            textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height())
            text = self.elidedText(option.fontMetrics, textrect.width(), Qt.ElideMiddle,
                              model.data(index, Qt.DisplayRole).toString())
            self.m_view.style().drawItemText(painter, textrect,Qt.AlignLeft|Qt.AlignVCenter,
                                             option.palette, self.m_view.isEnabled(), text)

            icon_variant = index.data(Qt.DecorationRole)
            icon = QIcon(icon_variant)
            self.m_view.style().drawItemPixmap(
                                               painter, option.rect,
                                               Qt.AlignLeft,
                                               icon.pixmap(icon.actualSize(QSize(20 ,20)))
                                               )

        else:
            QItemDelegate.paint(self, painter, option, index)
Exemplo n.º 50
0
 def paint(self, painter, option, index):
     data = index.model().data(index, Qt.UserRole)
     if data.isValid() and data.toPyObject() is not None:
         data = data.toPyObject()
         painter.save()
         rect = option.rect
         rect.adjust(+5, 0, -5, 0)
         pen = data
         painter.setPen(pen)
         middle = (rect.bottom() + rect.top()) / 2
         painter.drawLine(rect.left(), middle, rect.right(), middle)
         painter.restore()
     else:
         QItemDelegate.paint(self, painter, option, index)
         painter.drawLine(rect.left(), middle, rect.right(), middle)
         painter.restore()
Exemplo n.º 51
0
 def __init__(self, images, scales, images_path, *args):
     QDialog.__init__(self, *args)
     cache = image_cache.cache
     self.ui = Ui_EditResDlg()
     self.ui.setupUi(self)
     icons = []
     for pth in images_path:
         ico = QIcon(QPixmap.fromImage(cache.image(pth).scaled(QSize(64, 64), Qt.KeepAspectRatio)))
         icons.append(ico)
     self.model = ScaleModel(icons, images, scales)
     self.ui.pixelSizes.setModel(self.model)
     self.ui.pixelSizes.resizeColumnToContents(0)
     self.ui.pixelSizes.resizeColumnToContents(1)
     self.ui.pixelSizes.resizeColumnToContents(2)
     self.item_delegate = QItemDelegate()
     self.item_delegate.setItemEditorFactory(ScaleEditorFactory())
     self.ui.pixelSizes.setItemDelegate(self.item_delegate)
     self.ui.width.setValidator(QDoubleValidator(0, 1e300, 100, self))
     self.ui.height.setValidator(QDoubleValidator(0, 1e300, 100, self))
     # Find smallest scale
     minx = inf
     miny = inf
     for img in scales:
         sc = scales[img]
         if sc[0] > 0 and sc[0] < minx:
             minx = sc[0]
         if sc[1] > 0 and sc[1] < miny:
             miny = sc[1]
     if minx == inf:
         minx = 1e-6
     if miny == inf:
         miny = 1e-6
     # And set the default unit
     self.ui.unit.setCurrentIndex(self.model.findUnit(min(minx, miny)))
Exemplo n.º 52
0
 def createEditor(self, parent, option, index):
     delegate = self.delegates.get(index.column())
     if delegate is not None:
         return delegate.createEditor(parent, option, index)
     else:
         return QItemDelegate.createEditor(self, parent, option,
                                           index)
Exemplo n.º 53
0
 def sizeHint(self, option, index):
     fm = option.fontMetrics
     if index.column() in (MOD1, MOD2, MOD3):
         if self.mod is None:
             w = 0
             for mod in self.modifiers:
                 cw = fm.width(mod)
                 if cw > w:
                     w = cw
                     self.mod = mod
         else:
             w = fm.width(self.mod)
         return QSize(w+20, fm.height())
     elif index.column() == KEY:
         if self.key is None:
             w = 0
             for key in self.keys:
                 cw = fm.width(key)
                 if cw > w:
                     w = cw
                     self.key = key
         else:
             w = fm.width(self.key)
         return QSize(w+20, fm.height())
     return QItemDelegate.sizeHint(self, option, index)
Exemplo n.º 54
0
 def createEditor (self, parent, option, index):
     column = index.column()
     row = index.row()
     self.index = index
     content = index.model().data(index, Qt.EditRole)
     if column == 2:
         content = index.model().data(index, Qt.EditRole)
         label = index.model().data(index.model().index(row,1), Qt.EditRole)
         checkrowIndex = index.model().index(row,0)
         checkrowIndex = index.model().data(index.model().index(row,0), Qt.CheckStateRole)
         self.editorQWidget = QComboBox(parent)
         self.editorQWidget.setEditable(True)
         self.editorQWidget.addItems(self.module.fieldMapping.values())
         self.editorQWidget.addItems(['GEOMETRY','ODKUUID'])
         if content in self.module.fieldMapping.values():
             self.editorQWidget.setCurrentIndex(self.editorQWidget.findData(content))
             #self.module.fieldTable.item(row,0).setCheckState(Qt.Checked)
         else:
             #self.editorQWidget.insertItem(0,label)
             self.editorQWidget.insertItem(0,'')
             #self.module.fieldTable.item(row,0).setCheckState(Qt.Unchecked)
             self.editorQWidget.setCurrentIndex(0)
         return self.editorQWidget
     else:
         return None
     return QItemDelegate.createEditor(self, parent, option, index)
Exemplo n.º 55
0
 def setModelData(self, editor, model, index):
     if isinstance(editor, QComboBox):
         model.setData(index, QVariant(editor.currentText()), Qt.EditRole)
     elif isinstance(editor, QTextEdit):
         model.setData(index, QVariant(editor.toPlainText()), Qt.EditRole)
     else:
         return QItemDelegate.setModelData(self, editor, model, index)