Esempio n. 1
0
    def setData(self, index: QModelIndex, value, role=Qt.EditRole):
        if not index.isValid():
            return False

        node = index.internalPointer()

        if role == Qt.EditRole:
            if isinstance(node, JsonItem):
                if node.type in ('float', 'int', None):
                    node.value = value
                try:  # PyQt5
                    self.dataChanged.emit(index, index, [Qt.EditRole])
                except TypeError:  # PyQt4, PySide
                    self.dataChanged.emit(index, index)

        elif role == Qt.CheckStateRole:
            if isinstance(node, JsonItem):
                if node.type == 'bool':
                    node.value = value == Qt.Checked
                    try:  # PyQt5
                        self.dataChanged.emit(
                            index, index, [Qt.CheckStateRole])
                    except TypeError:  # PyQt4, PySide
                        self.dataChanged.emit(index, index)
                    return True
        return False
Esempio n. 2
0
    def flags(self, index: QModelIndex):
        flags = (Qt.NoItemFlags | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable |
                 Qt.ItemIsEnabled)

        if index.isValid():
            node = self.node_from_index(index)
            column = self.columns[index.column()].name

            if isinstance(node, JsonItem):
                if column == 'value' and not node.readonly:
                    if not node.type == 'bool':
                        flags |= Qt.ItemIsEditable
                    else:
                        flags |= Qt.ItemIsUserCheckable
        return flags
Esempio n. 3
0
 def rowCount(self, index=QModelIndex()):
     """Override Qt method"""
     return len(self._rows)
Esempio n. 4
0
 def __select_first_device(self):
     self.devices_view.setCurrentIndex(
         QModelIndex(self.devices_view.model().index(0, 0)))
Esempio n. 5
0
 def columnCount(self, index=QModelIndex()):
     """Qt Override."""
     return 3
Esempio n. 6
0
def test_filtering_with_large_rows(qtbot):
    """
    Test that filtering works when there's a large number of rows.
    """
    browser = NamespaceBrowser(None)
    qtbot.addWidget(browser)
    browser.set_shellwidget(Mock())
    browser.setup()
    text_finder = NamespacesBrowserFinder(browser.editor,
                                          callback=browser.editor.set_regex,
                                          main=browser,
                                          regex_base=VALID_VARIABLE_CHARS)
    browser.set_text_finder(text_finder)

    # Create data
    variables = {}
    for i in range(200):
        letter = string.ascii_lowercase[i // 10]
        var = letter + str(i)
        variables[var] = ({
            'type': 'int',
            'size': 1,
            'view': '1',
            'python_type': 'int',
            'numpy_type': 'Unknown'
        })

    # Set data
    browser.set_data(variables)

    # Assert we loaded the expected amount of data and that we can fetch
    # more data.
    model = browser.editor.model
    assert model.rowCount() == ROWS_TO_LOAD
    assert model.canFetchMore(QModelIndex())
    assert data(model, 49, 0) == 'e49'

    # Assert we can filter variables not loaded yet.
    qtbot.keyClicks(text_finder, "t19")
    assert model.rowCount() == 10

    # Assert all variables effectively start with 't19'.
    for i in range(10):
        assert data(model, i, 0) == 't19{}'.format(i)

    # Reset text_finder widget.
    text_finder.setText('')

    # Create a new variable that starts with a different letter than
    # the rest.
    new_variables = variables.copy()
    new_variables['z'] = ({
        'type': 'int',
        'size': 1,
        'view': '1',
        'python_type': 'int',
        'numpy_type': 'Unknown'
    })

    # Emulate the process of loading those variables after the
    # namespace view is sent from the kernel.
    browser.process_remote_view(new_variables)

    # Assert that can find 'z' among the declared variables.
    qtbot.keyClicks(text_finder, "z")
    assert model.rowCount() == 1
Esempio n. 7
0
 def rowCount(self, qindex=QModelIndex()):
     """Array row number"""
     return len(self.breakpoints)
Esempio n. 8
0
 def index(self, row, column, parent):      # pure virtual
     if self.hasIndex(row, column, parent):
         return self.createIndex(row, column, self.spec)
     else:
         return QModelIndex()
Esempio n. 9
0
    def rowCount(self, parent=QModelIndex()):
        if parent.isValid():
            return 0

        return len(self._app_interface.watched)
Esempio n. 10
0
 def columnCount(self, _parent=QModelIndex()):
     return len(self.role_names())
Esempio n. 11
0
    def index(self, row, column, parent=QModelIndex()):
        if not self.hasIndex(row, column, parent=QModelIndex()):
            return QModelIndex()

        item = self._app_interface.watched[row]
        return self.createIndex(row, column, item)
Esempio n. 12
0
 def columnCount(index=QModelIndex()):
     """Override Qt method."""
     return len(C.COLUMNS)
Esempio n. 13
0
 def currentChanged(
     self: QAbstractItemView, current: QModelIndex, previous: QModelIndex
 ):
     """The Qt current item has changed. Update the python model."""
     self._root.selection._current = current.internalPointer()
     return super().currentChanged(current, previous)
Esempio n. 14
0
 def clearToolTable(self):
     self.beginRemoveRows(QModelIndex(), 0, 100)
     # delete all but the spindle, which can't be deleted
     self._tool_table = {0: self._tool_table[0]}
     self.endRemoveRows()
     return True
Esempio n. 15
0
 def removeTool(self, row):
     self.beginRemoveRows(QModelIndex(), row, row)
     tnum = sorted(self._tool_table)[row + 1]
     del self._tool_table[tnum]
     self.endRemoveRows()
     return True
Esempio n. 16
0
 def on_botTable_doubleClicked(self, index: QModelIndex):
     self.bot_double_clicked.emit(
         self.table_model.getDeviceById(
             self.table_model.index(index.row(), 0).data()))
Esempio n. 17
0
 def index(self, row: int, column: int, parent=QModelIndex()) -> QModelIndex:
     if parent.isValid():
         return QModelIndex()
     job_index = self.mapToSource(self.createIndex(row, column, parent))
     ret_index = self.createIndex(row, column, job_index.data(NodeRole))
     return ret_index
Esempio n. 18
0
 def rowCount(self, parent=QModelIndex()):
     """Return row count"""
     return len(self._data)
Esempio n. 19
0
 def parent(self, index):        # pure virtual
     return QModelIndex()
Esempio n. 20
0
 def columnCount(self, parent=QModelIndex()):
     """Return column count"""
     return len(self._data[0])
Esempio n. 21
0
 def columnCount(self, qindex=QModelIndex()):
     """Array column count"""
     return 4
Esempio n. 22
0
 def rootIndex(self):  # TODO: needed?
     """
     The index that returns the root element
     (same as an invalid index).
     """
     return QModelIndex()
Esempio n. 23
0
 def rowCount(self, index=QModelIndex()):
     """Qt Override."""
     return len(self.servers)
Esempio n. 24
0
 def hasChildren(self, parent=None):
     parent = QModelIndex() if parent is None else parent
     if parent.column() > 0:
         return 0
     else:
         return self.treeItem(parent).has_children
Esempio n. 25
0
 def rowCount(self, index=QModelIndex()):
     """DataFrame row number"""
     if self.total_rows <= self.rows_loaded:
         return self.total_rows
     else:
         return self.rows_loaded
Esempio n. 26
0
 def columnCount(self, parent=QModelIndex()):
     return 2
Esempio n. 27
0
 def columnCount(self, index=QModelIndex()):
     """Override Qt method"""
     return 2
Esempio n. 28
0
 def columnCount(self, qindex=QModelIndex()):
     """Array column number"""
     if self.total_cols <= self.cols_loaded:
         return self.total_cols
     else:
         return self.cols_loaded
Esempio n. 29
0
 def rowCount(self, parent=QModelIndex()):
     if parent.isValid():
         return parent.internalPointer().child_count()
     elif not parent.isValid():
         return self._run_tree.count()
     return 0
Esempio n. 30
0
 def rowCount(self, qindex=QModelIndex()):
     """Array row number"""
     if self.total_rows <= self.rows_loaded:
         return self.total_rows
     else:
         return self.rows_loaded
Esempio n. 31
0
 def parent(self, index: QModelIndex):
     return QModelIndex()
Esempio n. 32
0
    def resolveChecks(self, index: QModelIndex):
        """
        Logic that controls how a clicked item and children items are checked and unchecked.

        When the clicked item is checked or unchecked (and when any children need to be checked or unchecked), this
        implicitly emits the itemChanged() signal (since the Qt.CheckStatRole data is changed). This is captured by
        the HintTabView to visualize and remove Hints as appropriate.

        Parameters
        ----------
        index
            The index of the item that was clicked.
        """

        if not self.model():
            return

        item = self.model().itemFromIndex(index)
        # The item has been clicked and its previous state is unchecked (going to be checking items)
        if item.data(Qt.CheckStateRole) == Qt.Unchecked:
            # TODO: Potential duplicate signal emissions (dataChanged on setCheckState())
            if item.isCheckable():
                # First, check the clicked item
                item.setCheckState(Qt.Checked)

            # All children should be checked if the clicked item is a parent item
            if self.model().hasChildren(index):
                numChildren = self.model().rowCount(index)
                childrenIndexes = [
                    self.model().index(row, 0, index)
                    for row in range(numChildren)
                ]
                for childIndex in childrenIndexes:
                    childItem = self.model().itemFromIndex(childIndex)
                    if childItem.isCheckable():
                        childItem.setCheckState(Qt.Checked)
            else:  # Item is a child item
                parentIndex = index.parent()
                numChildren = self.model().rowCount(parentIndex)
                childrenIndexes = [
                    self.model().index(row, 0, parentIndex)
                    for row in range(numChildren)
                ]
                # When all other siblings are already checked, update parent item to be checked as well
                if all([
                        self.model().itemFromIndex(index).checkState() ==
                        Qt.Checked for index in childrenIndexes
                ]):
                    self.model().itemFromIndex(parentIndex).setCheckState(
                        Qt.Checked)
                else:  # Not all siblings are checked, indicate with parent item being partially checked
                    self.model().itemFromIndex(parentIndex).setCheckState(
                        Qt.PartiallyChecked)

        else:  # The item has been clicked and its previous state is checked (going to be unchecking items)
            if item.isCheckable():
                # First, uncheck the clicked item
                item.setCheckState(Qt.Unchecked)

            # All children should be unchecked if the clicked item is a parent item
            if self.model().hasChildren(index):
                if self.model().itemFromIndex(
                        index).checkState() == Qt.PartiallyChecked:
                    raise NotImplementedError
                numChildren = self.model().rowCount(index)
                childrenIndexes = [
                    self.model().index(row, 0, index)
                    for row in range(numChildren)
                ]
                for childIndex in childrenIndexes:
                    childItem = self.model().itemFromIndex(childIndex)
                    if childItem.isCheckable():
                        childItem.setCheckState(Qt.Unchecked)
            else:  # The clicked item is a child item
                parentIndex = index.parent()
                numChildren = self.model().rowCount(parentIndex)
                childrenIndexes = [
                    self.model().index(row, 0, parentIndex)
                    for row in range(numChildren)
                ]
                # If any other sibling is unchecked, partially check the parent item
                if any([
                        self.model().itemFromIndex(index).checkState() ==
                        Qt.Checked for index in childrenIndexes
                ]):
                    self.model().itemFromIndex(parentIndex).setCheckState(
                        Qt.PartiallyChecked)
                else:  # No other siblings are checked, so uncheck the parent item
                    self.model().itemFromIndex(parentIndex).setCheckState(
                        Qt.Unchecked)