Exemple #1
0
    def sceneSelectionChanged(self):
        '''
        C++: void sceneSelectionChanged()
        
        This syncs the selection 
        NetworkView -> (Model)View
        To do this it uses the QSelectionModel that the ModelController
        has as a reference.
        '''
        if self.modelSelectionInProgress:   # don't create an selection update loop
            return
        
        itemSelection = QItemSelection()
        selectionModel = self.controller.getGlobalSelectionModel()

        if not self.graphicsScene:
            return

        selectedItems = self.graphicsScene.selectedItems()
        #logging.debug("Creating model selection for %s items" % len(selectedItems))
        for item in selectedItems:
            index = self.findItemInModel(item)
            if index is not None:
                itemSelection.select(index, index)
            
        selectionModel.select(itemSelection, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
Exemple #2
0
    def testOperators(self):
        model = QStandardItemModel()
        for i in range(100):
            model.appendRow(QStandardItem("Item: %d"%i))

        first = model.index(0, 0)
        second = model.index(10, 0)
        third = model.index(20, 0)
        fourth = model.index(30, 0)

        sel = QItemSelection(first, second)
        sel2 = QItemSelection()
        sel2.select(third, fourth)

        sel3 = sel + sel2 #check operator +
        self.assertEqual(len(sel3), 2)
        sel4 = sel
        sel4 += sel2 #check operator +=
        self.assertEqual(len(sel4), 2)
        self.assertEqual(sel4, sel3)
Exemple #3
0
    def testOperators(self):
        model = QStandardItemModel()
        for i in range(100):
            model.appendRow(QStandardItem("Item: %d" % i))

        first = model.index(0, 0)
        second = model.index(10, 0)
        third = model.index(20, 0)
        fourth = model.index(30, 0)

        sel = QItemSelection(first, second)
        sel2 = QItemSelection()
        sel2.select(third, fourth)

        sel3 = sel + sel2  # check operator +
        self.assertEqual(len(sel3), 2)
        sel4 = sel
        sel4 += sel2  # check operator +=
        self.assertEqual(len(sel4), 2)
        self.assertEqual(sel4, sel3)