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 mapSelectionToSource(self, proxySelection):
        sourceSelection = QItemSelection()
        if self.sourceModel() is None:
            return sourceSelection

        cursor = proxySelection.constBegin()
        end = proxySelection.constEnd()
        while cursor != end:
            topLeft = self.mapToSource(cursor.topLeft())
            bottomRight = self.mapToSource(cursor.bottomRight())
            sourceRange = QItemSelectionRange(topLeft, bottomRight)
            sourceSelection.append(sourceRange)
            cursor += 1
        return sourceSelection
Exemple #3
0
    def mapSelectionFromSource(self, sourceSelection):
        proxySelection = QItemSelection()
        if self.sourceModel() is None:
            return proxySelection

        cursor = sourceSelection.constBegin()
        end = sourceSelection.constEnd()
        while cursor != end:
            topLeft = self.mapFromSource(cursor.topLeft())
            bottomRight = self.mapFromSource(cursor.bottomRight())
            proxyRange = QItemSelectionRange(topLeft, bottomRight)
            proxySelection.append(proxyRange)
            cursor += 1
        return proxySelection
Exemple #4
0
    def mapSelectionToSource(self, proxySelection):
        sourceSelection = QItemSelection()
        if self.sourceModel() is None:
            return sourceSelection

        cursor = proxySelection.constBegin()
        end = proxySelection.constEnd()
        while cursor != end:
            topLeft = self.mapToSource(cursor.topLeft())
            bottomRight = self.mapToSource(cursor.bottomRight())
            sourceRange = QItemSelectionRange(topLeft, bottomRight)
            sourceSelection.append(sourceRange)
            cursor += 1
        return sourceSelection
Exemple #5
0
    def mapSelectionFromSource(self, sourceSelection):
        proxySelection = QItemSelection()
        if self.sourceModel() is None:
            return proxySelection

        cursor = sourceSelection.constBegin()
        end = sourceSelection.constEnd()
        while cursor != end:
            topLeft = self.mapFromSource(cursor.topLeft())
            bottomRight = self.mapFromSource(cursor.bottomRight())
            proxyRange = QItemSelectionRange(topLeft, bottomRight)
            proxySelection.append(proxyRange)
            cursor += 1
        return proxySelection
Exemple #6
0
 def select_all_slot(self):
     m = self.table_view.model()
     all = QItemSelection(m.index(0, 0),
                          m.index(m.rowCount() - 1,
                                  m.columnCount() - 1))
     self.table_view.selectionModel().select(all,
                                             QItemSelectionModel.Select)
Exemple #7
0
 def testLen(self):
     model = QStandardItemModel(2, 2)
     model.insertRow(0)
     model.insertRow(1)
     model.insertColumn(0)
     model.insertColumn(1)
     selection = QItemSelection(model.index(0, 0), model.index(1, 1))
     self.assertEqual(len(selection), 1)
Exemple #8
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 #9
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 #10
0
    def refresh(self,slip_id):
        filter_string = self.filter_line_edit.text()
        self.apply_filter_slot(filter_string)

        if slip_id:
            ndx = self.search_results_model.find_index( lambda s:s.delivery_slip_id == slip_id)

            r = 0
            m = self.search_results_model
            if ndx:
                r = ndx.row()

            s = QItemSelection(m.index(r,0), m.index(r, m.columnCount()-1))
            self.search_results_view.selectionModel().select(s, QItemSelectionModel.Select)