def setModel(self, model: QAbstractTableModel):
     super().setModel(model)
     for row in range(model.rowCount()):
         for col in range(model.columnCount()):
             span = model.span(model.index(row, col))
             if span.height() > 1 or span.width() > 1:
                 self.setSpan(row, col, span.height(), span.width())
    def __init__(self, *args, model: QAbstractTableModel = None, selected_columns: List[int] = None, **kwargs):
        super().__init__(*args, **kwargs)

        for i in range(self.layoutBins.count()):
            w = self.layoutBins.itemAt(i).widget()
            if w is not None and not isinstance(w, QLabel):
                w.hide()

        if model is not None:
            for col in range(model.columnCount()):
                text = model.headerData(col, Qt.Horizontal, Qt.DisplayRole)
                color = model.headerData(col, Qt.Horizontal, ColorMarkRole)
                item = ColumnListWidgetItem(text, column=col)
                if color is not None:
                    item.setBackground(color)

                if selected_columns is not None and col in selected_columns:
                    self.lstUsedColumns.addItem(item)
                else:
                    self.lstColumns.addItem(item)

        colors = QSettings().value('NetworkView/pie_colors',
                                   [c.name() for c in generate_colors(8)],
                                   type=str)
        self.set_colors(colors)

        self.btUseSelectedColumns.clicked.connect(lambda: self.move_selected_columns(MOVE_COLUMNS_SELECT))
        self.btRemoveSelectedColumns.clicked.connect(lambda: self.move_selected_columns(MOVE_COLUMNS_UNSELECT))
Exemple #3
0
    def __init__(self,
                 *args,
                 model: QAbstractTableModel,
                 column_id: int,
                 func: 'SizeMappingFunc' = None,
                 **kwargs):
        super().__init__(*args, **kwargs)

        self._model = model
        self._column_id = column_id
        self._func = func

        self.setupUi(self)
        self.setWindowFlags(Qt.Tool | Qt.CustomizeWindowHint
                            | Qt.WindowCloseButtonHint)
        self.setFixedSize(self.geometry().size())

        self.spinMaxValue.valueChanged.connect(
            lambda x: self.on_range_changed('max-value', x))
        self.spinMinValue.valueChanged.connect(
            lambda x: self.on_range_changed('min-value', x))
        self.spinMaxSize.valueChanged.connect(
            lambda x: self.on_range_changed('max-size', x))
        self.spinMinSize.valueChanged.connect(
            lambda x: self.on_range_changed('min-size', x))
        self.btAddHandle.clicked.connect(self.on_add_handle)
        self.btRemoveHandle.clicked.connect(self.on_remove_handle)

        self.gvMapping.setRenderHints(QPainter.Antialiasing
                                      | QPainter.TextAntialiasing)
        self.gvMapping.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.gvMapping.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.cbMode.addItems(["Linear", "Log"])
        self.cbMode.activated[int].connect(self.on_mode_changed)
        self._current_mode = MODE_LINEAR
        self.cbMode.setCurrentIndex(MODE_LINEAR)

        self.lstColumns.selectionModel().currentChanged.connect(
            self.on_column_changed)

        for col in range(model.columnCount()):
            text = model.headerData(col, Qt.Horizontal, Qt.DisplayRole)
            item = ColumnListWidgetItem(text, column=col)
            self.lstColumns.addItem(item)
    def __init__(self, *args, model: QAbstractTableModel = None, column_id: int = None, mapping: dict = None, **kwargs):
        self._model = model
        self._column_id = column_id

        super().__init__(*args, **kwargs)

        self.lstUsedColumns.setItemDelegate(ItemDelegate())
        self.lstColors.setItemDelegate(ItemDelegate())

        data = self._model.headerData(self._column_id, Qt.Horizontal, role=ColumnDataRole)
        if data is not None and not isinstance(data, pd.Series):
            data = pd.Series(data)
        self._data = data

        if model is not None and column_id is not None:
            for i in range(model.columnCount()):
                index = model.index(0, i)
                text = model.headerData(i, Qt.Horizontal, Qt.DisplayRole)
                color = model.headerData(i, Qt.Horizontal, ColorMarkRole)
                item = ColumnListWidgetItem(text, column=index.column())
                if color is not None:
                    item.setBackground(color)

                if index.column() != column_id:
                    self.lstColumns.addItem(item)

        self.lstUsedColumns.setSelectionMode(QAbstractItemView.ContiguousSelection)
        self.lstColumns.setSelectionMode(QAbstractItemView.SingleSelection)
        self.populate_bins(mapping)

        colors = QSettings().value('NetworkView/node_colors',
                                   [c.name() for c in generate_colors(8)],
                                   type=str)
        self.set_colors(colors)

        self.btUseSelectedColumns.clicked.connect(self.on_use_selected_column)
        self.btRemoveSelectedColumns.clicked.connect(self.on_unuse_selected_column)