Esempio n. 1
0
    def testSort(self):
        """ test sort logic """
        w = QTreeWidget()

        i1 = QgsTreeWidgetItem(w)
        i2 = QgsTreeWidgetItem(w)

        # should default to search by display text
        i1.setText(0, '2')
        i1.setText(1, 'b')
        i1.setText(2, 'c')
        i2.setText(0, '1')
        i2.setText(1, 'a')
        i2.setText(2, 'd')

        w.sortItems(0, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        w.sortItems(1, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        w.sortItems(2, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)

        # sortData should take precedence over display text
        i1.setText(1, '2')
        i1.setSortData(1, '200')
        i2.setText(1, '3')
        w.sortItems(1, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        i2.setSortData(1, '300')
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)

        # test that nulls are sorted before other values
        i1.setSortData(0, '2')
        i2.setSortData(0, NULL)
        w.sortItems(0, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)

        # test numeric sorting
        i1.setSortData(0, '02')
        i2.setSortData(0, '005')
        w.sortItems(0, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)
        # numbers should come first
        i2.setSortData(0, 'a')
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)
        i1.setSortData(0, 'a')
        i2.setSortData(0, '5')
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)

        # always on top items should be first
        i1.setSortData(0, 'a')
        i2.setSortData(0, 'b')
        i2.setAlwaysOnTopPriority(5)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        i1.setAlwaysOnTopPriority(3)
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)
        # otherwise fall back to sort order
        i2.setAlwaysOnTopPriority(3)
        i1.setSortData(0, 'c')
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
Esempio n. 2
0
    def testGettersSetters(self):
        """ test getters and setters """
        i = QgsTreeWidgetItem()

        # sort data should be empty by default
        self.assertEqual(i.sortData(0), NULL)
        i.setSortData(0, '5')
        self.assertEqual(i.sortData(0), '5')
        self.assertEqual(i.sortData(1), NULL)
        i.setSortData(1, 'a')
        self.assertEqual(i.sortData(0), '5')
        self.assertEqual(i.sortData(1), 'a')

        # should not be always on top by default
        self.assertEqual(i.alwaysOnTopPriority(), -1)
        i.setAlwaysOnTopPriority(1)
        self.assertEqual(i.alwaysOnTopPriority(), 1)
Esempio n. 3
0
    def testGettersSetters(self):
        """ test getters and setters """
        i = QgsTreeWidgetItem()

        # sort data should be empty by default
        self.assertEqual(i.sortData(0), NULL)
        i.setSortData(0, '5')
        self.assertEqual(i.sortData(0), '5')
        self.assertEqual(i.sortData(1), NULL)
        i.setSortData(1, 'a')
        self.assertEqual(i.sortData(0), '5')
        self.assertEqual(i.sortData(1), 'a')

        # should not be always on top by default
        self.assertEqual(i.alwaysOnTopPriority(), -1)
        i.setAlwaysOnTopPriority(1)
        self.assertEqual(i.alwaysOnTopPriority(), 1)
Esempio n. 4
0
    def testSort(self):
        """ test sort logic """
        w = QTreeWidget()

        i1 = QgsTreeWidgetItem(w)
        i2 = QgsTreeWidgetItem(w)

        # should default to search by display text
        i1.setText(0, '2')
        i1.setText(1, 'b')
        i1.setText(2, 'c')
        i2.setText(0, '1')
        i2.setText(1, 'a')
        i2.setText(2, 'd')

        w.sortItems(0, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        w.sortItems(1, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        w.sortItems(2, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)

        # sortData should take precedence over display text
        i1.setText(1, '2')
        i1.setSortData(1, '200')
        i2.setText(1, '3')
        w.sortItems(1, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        i2.setSortData(1, '300')
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)

        # test that nulls are sorted before other values
        i1.setSortData(0, '2')
        i2.setSortData(0, NULL)
        w.sortItems(0, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)

        # test numeric sorting
        i1.setSortData(0, '02')
        i2.setSortData(0, '005')
        w.sortItems(0, Qt.AscendingOrder)
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)
        # numbers should come first
        i2.setSortData(0, 'a')
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)
        i1.setSortData(0, 'a')
        i2.setSortData(0, '5')
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)

        # always on top items should be first
        i1.setSortData(0, 'a')
        i2.setSortData(0, 'b')
        i2.setAlwaysOnTopPriority(5)
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)
        i1.setAlwaysOnTopPriority(3)
        self.assertEqual(i1 < i2, True)
        self.assertEqual(i2 < i1, False)
        # otherwise fall back to sort order
        i2.setAlwaysOnTopPriority(3)
        i1.setSortData(0, 'c')
        self.assertEqual(i1 < i2, False)
        self.assertEqual(i2 < i1, True)