コード例 #1
0
ファイル: MergeModel.py プロジェクト: mdavis199/MergeWizard
 def lessThan(self, left: QModelIndex, right: QModelIndex):
     # This sorts the plugins alpabetically, leaves the mods order unchanged
     depth = Id.depth(left)
     if depth == Id.Depth.D0:
         return left.row() < right.row()
     return (
         self.sourceModel().data(left.siblingAtColumn(Column.Name)).lower()
         < self.sourceModel().data(right.siblingAtColumn(Column.Name)).lower()
     )
コード例 #2
0
 def data(self, idx: QModelIndex, role: int = Qt.DisplayRole):
     if role == Qt.DisplayRole:
         if self.isIconOnlyColumn(idx.column()):
             return None
         if idx.column() == Column.Priority:
             sourceIdx = self.sourceModel().index(idx.row(), idx.column())
             if self.sourceModel().data(sourceIdx) == -1:
                 return None
     elif role == Qt.DecorationRole:
         if not self.isIconOnlyColumn(idx.column()):
             return None
         v = super().data(idx, Role.Cell)
         if idx.column() == Column.IsSelectedAsMaster:
             return QIcon(Icon.SELECTED_AS_MASTER) if v else None
         if idx.column() == Column.IsSelected:
             return QIcon(Icon.SELECTED) if v else None
         if idx.column() == Column.IsMissing:
             return QIcon(Icon.MISSING) if v else None
         if idx.column() == Column.IsInactive:
             return QIcon(Icon.INACTIVE) if v else None
         if idx.column() == Column.IsMaster:
             return QIcon(Icon.MASTER) if v else None
         if idx.column() == Column.IsMerge:
             return QIcon(Icon.MERGE) if v else None
         if idx.column() == Column.IsMerged:
             return QIcon(Icon.MERGED) if v else None
         return None
     elif role == Qt.ForegroundRole:
         missing = super().data(idx.siblingAtColumn(Column.IsMissing),
                                Role.Cell)
         inactive = super().data(idx.siblingAtColumn(Column.IsInactive),
                                 Role.Cell)
         if missing or inactive:
             return QColor(Qt.lightGray).darker()
     elif role == Qt.FontRole:
         if super().data(idx.siblingAtColumn(Column.IsMissing), Role.Cell):
             font = QFont()
             font.setItalic(True)
             return font
     elif role == Qt.TextAlignmentRole:
         if idx.column() in [
                 Column.PluginOrder,
                 Column.MasterOrder,
                 Column.Priority,
         ]:
             return Qt.AlignCenter
     elif role == Qt.CheckStateRole and self._displayCheckbox:
         if idx.column() == Column.PluginName:
             return Qt.Checked if super().data(
                 idx.siblingAtColumn(Column.IsSelected),
                 Role.Cell) else Qt.Unchecked
     return super().data(idx, role)
コード例 #3
0
    def _openItem(self, packItem: QModelIndex):
        try:
            currTab: Tab = self.tabWidget.currentWidget()
            state = currTab.attrsTreeView.header().saveState()
        except AttributeError:
            # if there is no curr widget, there is no current header state, it
            state = None

        self.packItem = QPersistentModelIndex(packItem.siblingAtColumn(0))
        self.descrLabel.setText("")

        self.packItemObj = self.packItem.data(OBJECT_ROLE)
        self.updateMediaWidget()
        self.pathLine.setText(getTreeItemPath(self.packItem))
        self.objTypeLine.setText(getTypeName(type(self.packItemObj)))

        icon = self.packItem.data(Qt.DecorationRole)
        if icon:
            self.setWindowIcon(icon)
        self.setWindowTitle(self.packItem.data(Qt.DisplayRole))
        self.attrsTreeView.newPackItem(self.packItem)
        self.attrsTreeView.selectionModel().currentChanged.connect(
            self.showDetailInfoItemDoc)
        self.currItemChanged.emit(QModelIndex(self.packItem))

        self.forwardAct.setEnabled(
            True) if self.nextItems else self.forwardAct.setDisabled(True)
        self.backAct.setEnabled(
            True) if self.prevItems else self.backAct.setDisabled(True)
        if state:
            self.attrsTreeView.header().restoreState(state)
コード例 #4
0
 def onViewDoubleClicked(self, idx: QModelIndex):
     idx = self.infoModel().mapToSource(idx)
     if Id.depth(idx) == Id.Depth.D2:
         if idx.parent().row() == Row.MergedBy or idx.parent().row() == Row.MergedPlugins:
             name = self.infoModel().sourceModel().data(idx.siblingAtColumn(1))
             if name:
                 self.doubleClicked.emit(name)
コード例 #5
0
    def _recalculate_amount_item(self, ingredient_index: QtCore.QModelIndex):
        """
        Recalulate one amount item

        Args:
            ingredient_index (): The index of the ingredient item

        Returns:

        """
        ingedient_list_index = ingredient_index.siblingAtColumn(
            self.IngredientColumns.INGREDIENTLISTROW)
        ingredient = self._recipe.ingredientlist[ingedient_list_index.data(
            int(QtCore.Qt.DisplayRole))]
        amount_index = ingedient_list_index.siblingAtColumn(
            self.IngredientColumns.AMOUNT)

        self.setData(amount_index,
                     ingredient.amount_string(factor=self.factor),
                     QtCore.Qt.DisplayRole)

        # Display a small icon to indicate that the amount is calculated and not the amount stored in the database
        if math.isclose(self.factor, 1.0):
            self.itemFromIndex(amount_index).setIcon(QtGui.QIcon())

            # (Re)set the user data - otherwise the editor will do odd things when the amounts have been scaled
            self.setData(amount_index,
                         ((ingredient.amount, ingredient.range_amount),
                          ingredient.unit.unit_string()), QtCore.Qt.UserRole)
        else:
            if ingredient.amount:
                self.itemFromIndex(amount_index).setIcon(
                    QtGui.QIcon(":/icons/calculator.png"))
コード例 #6
0
    def setData(self,
                index: QtCore.QModelIndex,
                value: typing.Any,
                role: int = ...) -> bool:
        if self.immutable:
            return False

        if index.isValid():
            if role in (QtCore.Qt.EditRole, QtCore.Qt.CheckStateRole,
                        QtCore.Qt.UserRole):

                # For the optional column. Otherwise ingredient and amount have told the controller that something
                # is going to change
                self.dataToBeChanged.emit()

                column = index.column()

                # The item to manipulate
                ingredient_list_item = self._recipe.ingredientlist[int(
                    index.siblingAtColumn(
                        self.IngredientColumns.INGREDIENTLISTROW).data(
                            role=QtCore.Qt.DisplayRole))]
                if column == self.IngredientColumns.OPTIONAL and role == QtCore.Qt.CheckStateRole:
                    ingredient_list_item.optional = (
                        value == QtCore.Qt.Checked)

                if column == self.IngredientColumns.INGREDIENT and role == QtCore.Qt.EditRole:
                    new_name = nullify(value)

                    # There's no point in having a empty name - well, in that case we could
                    # display/use the ingredient's generic name, but this might be quite confusing
                    # for the user
                    if new_name is None:
                        return False

                    old_name = ingredient_list_item.name

                    # This means that a change in the group's name will be visible to all
                    # recipes having this pseudo ingredient. Not exactly sure if it's the
                    # right thing to to do, on the other hand it's more consistent
                    if old_name is None and ingredient_list_item.ingredient.is_group:
                        ingredient_list_item.ingredient.name = new_name
                    else:
                        ingredient_list_item.name = new_name

                if column == self.IngredientColumns.AMOUNT and role == QtCore.Qt.UserRole:
                    (amount, range_amount), unit_string = value
                    ingredient_list_item.amount = amount
                    ingredient_list_item.range_amount = range_amount
                    ingredient_list_item.unit = data.IngredientUnit.unit_dict[
                        unit_string]

                    self.setData(
                        index,
                        QtCore.QVariant(ingredient_list_item.amount_string()),
                        QtCore.Qt.DisplayRole)

            return super().setData(index, value, role)
        return False
コード例 #7
0
 def setData(self, idx: QModelIndex, value, role: int = Qt.EditRole):
     if self._readonly:
         return False
     if role == Qt.CheckStateRole and self._displayCheckbox:
         if idx.column() == Column.PluginName:
             return super().setData(
                 idx.siblingAtColumn(Column.IsSelected),
                 value == Qt.Checked,
                 Qt.EditRole,
             )
     return super().setData(idx, value, role)
コード例 #8
0
    def updateWidgetDataFromRow(self, index: QModelIndex) -> None:
        """
        Updates the Scantable widget after clicking on a new row by updating
        the spectrum, error plot, peptide sequence

        Parameter
        -------
        index : QModelIndex
            The index of the new selected row.

        """
        self.seleTableRT = round(index.siblingAtColumn(2).data(), 3)

        # set new spectrum with setting that all peaks should be displayed
        self.spectrum_widget.setSpectrum(self.scan_widget.curr_spec,
                                         zoomToFullRange=True)

        # only draw sequence with given ions for MS2 and error plot
        if index.siblingAtColumn(0).data() == "MS2":
            self.drawSeqIons(
                index.siblingAtColumn(6).data(),
                index.siblingAtColumn(7).data())
            self.errorData(index.siblingAtColumn(7).data())
            if (self.peakAnnoData is not None
                ):  # peakAnnoData created with existing ions in errorData
                # (bc of coloring)
                self.spectrum_widget.setPeakAnnotations(
                    self.createPeakAnnotation())
                self.spectrum_widget.redrawPlot()
            else:
                self.spectrum_widget._clear_peak_annotations()
                self.spectrum_widget.redrawPlot()

        # otherwise delete old data
        elif index.siblingAtColumn(0).data() == "MS1":
            self.seqIons_widget.clear()
            self.error_widget.clear()
            self.peakAnnoData = None
            self.spectrum_widget._clear_peak_annotations()
            self.spectrum_widget.redrawPlot()
コード例 #9
0
ファイル: table_standard.py プロジェクト: zrgt/pygui40aas
    def addItem(self,
                obj: Union[Package, 'SubmodelElement', Iterable],
                parent: QModelIndex = QModelIndex()):
        parent = parent.siblingAtColumn(0)
        parentItem = self.objByIndex(parent)
        parentObj = parentItem.data(OBJECT_ROLE)
        parentObjCls = type(parentObj)
        parentName = parent.data(NAME_ROLE)

        kwargs = {
            "obj": obj,
            "parent": parentItem,
        }
        if isinstance(obj, Package):
            kwargs["parent"] = self._rootItem
            kwargs["new"] = False
            itemTyp = PackTreeViewItem
        elif parentName in Package.addableAttrs():
            package: Package = parent.data(PACKAGE_ROLE)
            package.add(obj)
            itemTyp = PackTreeViewItem
        elif ClassesInfo.changedParentObject(parentObjCls):
            parentObj = getattr(parentObj,
                                ClassesInfo.changedParentObject(parentObjCls))
            parentObj.add(obj)
            itemTyp = PackTreeViewItem
        elif isinstance(parentObj, AbstractSet):
            parentObj.add(obj)
            itemTyp = DetailedInfoItem
        elif isinstance(parentObj, list):
            parentObj.append(obj)
            itemTyp = DetailedInfoItem
        elif isinstance(parentObj, dict):
            parentObj[obj.key] = obj.value
            itemTyp = DetailedInfoItem
        else:
            raise AttributeError(
                f"Object couldn't be added: parent obj type is not appendable: {type(parentObj)}"
            )
        self.beginInsertRows(parent, self.rowCount(parent),
                             self.rowCount(parent))
        item = itemTyp(**kwargs)
        self.endInsertRows()
        itemIndex = self.index(item.row(), 0, parent)
        self.undo.append(
            SetDataItem(index=QPersistentModelIndex(itemIndex),
                        value=NOT_GIVEN,
                        role=CLEAR_ROW_ROLE))
        self.redo.clear()
        return itemIndex
コード例 #10
0
    def setData(self,
                index: QtCore.QModelIndex,
                value: typing.Any,
                role: int = ...) -> bool:
        column = index.column()
        row = index.row()

        if row >= 0 and column == self.ImageTableColumns.DESCRIPTION:
            imagelist_row = int(
                index.siblingAtColumn(self.ImageTableColumns.IMAGE).data(
                    QtCore.Qt.UserRole))
            self._recipe.imagelist[imagelist_row].description = nullify(value)

        return super().setData(index, value, role)
コード例 #11
0
ファイル: treeview_detailed.py プロジェクト: zrgt/pygui40aas
    def updateActions(self, index: QModelIndex):
        super(AttrsTreeView, self).updateActions(index)

        # update edit action
        if index.flags() & Qt.ItemIsEditable:
            self.editAct.setEnabled(True)
        elif index.siblingAtColumn(VALUE_COLUMN).flags() & Qt.ItemIsEditable:
            valColIndex = index.siblingAtColumn(VALUE_COLUMN)
            self.setCurrentIndex(valColIndex)
            self.editAct.setEnabled(True)
        else:
            self.editAct.setEnabled(False)

        # update open actions
        indexIsLink = bool(index.data(IS_LINK_ROLE))
        self.openInCurrTabAct.setEnabled(indexIsLink)
        self.openInBackgroundAct.setEnabled(indexIsLink)
        self.openInNewTabAct.setEnabled(indexIsLink)
        self.openInNewWindowAct.setEnabled(indexIsLink)

        self.openInCurrTabAct.setVisible(indexIsLink)
        self.openInBackgroundAct.setVisible(indexIsLink)
        self.openInNewTabAct.setVisible(indexIsLink)
        self.openInNewWindowAct.setVisible(indexIsLink)
コード例 #12
0
 def from_checklist_item(
     cls,
     checklist_item: QtCore.QModelIndex,
     resource: typing.Union[str, Path, QgsMapLayer],
 ):
     checklist_item_head: models.ChecklistItemHead = (
         checklist_item.internalPointer().ref)
     automation: models.ChecklistAutomationProperty = (
         checklist_item_head.automation)
     model = checklist_item.model()
     notes_idx = model.index(
         ChecklistItemPropertyColumn.VALIDATION_NOTES.value, 1,
         checklist_item)
     validated_idx = checklist_item.siblingAtColumn(1)
     return cls(automation.algorithm_id,
                automation.artifact_parameter_name,
                automation.output_name,
                automation.negate_output,
                artifact_path=resource,
                model=model,
                validated_idx=validated_idx,
                notes_idx=notes_idx,
                execution_params=automation.extra_parameters)
コード例 #13
0
ファイル: treeview_basic.py プロジェクト: zrgt/pygui40aas
 def expand(self, index: QtCore.QModelIndex) -> None:
     newIndex = index.siblingAtColumn(0)
     super(BasicTreeView, self).expand(newIndex)
コード例 #14
0
ファイル: treeview_basic.py プロジェクト: zrgt/pygui40aas
 def collapse(self, index: QtCore.QModelIndex) -> None:
     newIndex = index.siblingAtColumn(0)
     super(BasicTreeView, self).collapse(newIndex)
コード例 #15
0
 def autocomplete_activated(self, index: QModelIndex):
     """ Called when the autocomplete is activated """
     pointer = index.siblingAtColumn(self.pointer_column).data()
     self.link_updated.emit(pointer)
コード例 #16
0
 def removePackTab(self, packItem: QModelIndex):
     for tabIndex in range(self.count() - 1, -1, -1):
         tab: Tab = self.widget(tabIndex)
         if QModelIndex(tab.packItem).siblingAtColumn(
                 0) == packItem.siblingAtColumn(0):
             self.removeTab(tabIndex)
コード例 #17
0
ファイル: treeview_detailed.py プロジェクト: zrgt/pygui40aas
 def toggleFold(self, index: QModelIndex):
     index = index.siblingAtColumn(0)
     if self.isExpanded(index):
         self.collapse(index)
     else:
         self.expand(index)
コード例 #18
0
 def setPluginOrder(self, idx: QModelIndex, position: int):
     self.setPluginsOrder([idx.siblingAtColumn(0)], position)