Beispiel #1
0
    def test_batch_set_data(self):
        """Test the batch_set_data() method of MinimalTableModel."""
        model = MinimalTableModel()

        n_rows = 3
        model.insertRows(0, n_rows)
        n_columns = 3
        model.insertColumns(0, n_columns)
        background = n_rows * n_columns * ['0xdeadbeef']
        indices = list()
        for row in range(n_rows):
            for column in range(n_columns):
                indices.append(model.index(row, column))

        def _handle_data_changed(top_left, bottom_right, roles):
            self.assertEqual(top_left, indices[0])
            self.assertEqual(bottom_right, indices[-1])
            self.assertTrue(Qt.EditRole in roles)
            self.assertTrue(Qt.DisplayRole in roles)

        model.dataChanged.connect(_handle_data_changed)
        self.assertTrue(model.batch_set_data(indices, background))
        for row in range(n_rows):
            for column in range(n_columns):
                index = model.index(row, column)
                self.assertEqual(model.data(index), '0xdeadbeef')
Beispiel #2
0
 def test_setData(self):
     """Test the setData() method of MinimalTableModel."""
     model = MinimalTableModel()
     model.insertRows(0, 1)
     index = model.index(0, 0)
     self.assertTrue(model.setData(index, 'a'))
     self.assertEqual(model.data(index), 'a')
Beispiel #3
0
 def test_reset_model(self):
     """Test the reset_model() method of MinimalTableModel."""
     model = MinimalTableModel()
     data = [['a', 'b', 'c'], ['d', 'e', 'f']]
     model.reset_model(data)
     for row, row_data in enumerate(data):
         for column, value in enumerate(row_data):
             index = model.index(row, column)
             self.assertEqual(model.data(index), value)