Esempio n. 1
0
    def select(self, selection, command):
        '''
        overwrite the select function
        selection is either a QModelIndex, (handled normally),
        or a QItemSelection
        '''
        if isinstance(selection, QtCore.QModelIndex):
            QtCore.QItemSelectionModel.select(self, selection, command)
            return
        if len(selection.indexes()) > 2:
            LOGGER.debug("restricting appointment selection to 2 items")
            new_selection = QtCore.QItemSelection()
            new_selection.append(
                QtCore.QItemSelectionRange(selection.indexes()[0]))
            new_selection.append(
                QtCore.QItemSelectionRange(selection.last().indexes()[0]))
            selection = new_selection

        # now some openmolar specific code... I want scheduled appointment
        # to take priority
        if len(selection.indexes()) == 2:
            index1, index2 = selection.indexes()
            app1 = index1.model().data(index1, QtCore.Qt.UserRole)
            app2 = index2.model().data(index2, QtCore.Qt.UserRole)
            swap_required = app1.unscheduled and not app2.unscheduled
            LOGGER.debug("swap required = %s", swap_required)
            if swap_required:
                selection.swap(0, 1)
            if app1.dent == app2.dent:
                # joint appointments are dumb if dentist is the same!
                selection.removeAt(1)

        # send via base class
        QtCore.QItemSelectionModel.select(self, selection, command)
Esempio n. 2
0
    def select(self, selection, command):
        '''
        overwrite the select function
        selection is either a QModelIndex, (handled normally),
        or a QItemSelection
        '''
        self.is_reversed = False
        LOGGER.debug("DoubleRowSelectionModel.select %s,%s", selection,
                     command)
        if isinstance(selection, QtCore.QModelIndex):
            LOGGER.debug("Model Index selected")
        elif len(selection.indexes()) >= 2:
            LOGGER.debug("restricting appointment selection to 2 items")
            new_selection = QtCore.QItemSelection()
            index1 = selection.indexes()[0]
            index2 = self.currentIndex()
            if index2.row() == index1.row():
                index2 = selection.last().indexes()[-1]
                self.is_reversed = True
            new_selection.append(QtCore.QItemSelectionRange(index1))
            new_selection.append(QtCore.QItemSelectionRange(index2))
            selection = new_selection
        else:
            for index in selection.indexes():
                LOGGER.debug("index = %s", index)

        QtCore.QItemSelectionModel.select(self, selection, command)
Esempio n. 3
0
    def selectionChanged(self, topLeft, bottomRight):
        '''срабатывает, когда пользователь выбирает какой-либо peer_id из списка'''

        if len(self.selectedIndexes()):
            range_ = QtCore.QItemSelectionRange(self.selectedIndexes()[0])
            self.selectedDomain = range_.bottom()
            self.changeTipedDomain()
Esempio n. 4
0
 def save_entry(self, apply_capitalization=False):
     new_row = self.editor.entry()
     new_id = self.model.create_entry(
         apply_capitalization=apply_capitalization, **new_row)
     self.table.update()
     if DEBUG:
         sys.stdout.write(("new_id {0}".format(new_id)) + os.linesep)
     for row in range(self.model.rowCount()):
         new_index = self.table.model().index(row, 0)
         if self.model.data(new_index) == new_id:
             if DEBUG:
                 sys.stdout.write(
                     ("new_index {0}, row {1}".format(new_index, row)) +
                     os.linesep)
             break
     else:
         row = None
         if DEBUG:
             sys.stdout.write("row not found" + os.linesep)
     if row is not None:
         selection = core.QItemSelection()
         selection.append(
             core.QItemSelectionRange(
                 self.table.model().index(new_index.row(), 0),
                 self.table.model().index(
                     new_index.row(),
                     self.table.model().columnCount() - 1)))
         self.table.selectionModel().select(
             selection, core.QItemSelectionModel.ClearAndSelect)
         self.table.scrollTo(new_index)
     self.editor.update_completer(new_row['activity'])
     self._db.save_changes()
     self.update_interface()
     core.QTimer.singleShot(0, partial(self.clear_entry, False))
Esempio n. 5
0
 def set_selected_appointments(self, selected_apps):
     '''
     programatically make a selection (to sync with other ways of selecting
     an appointment, eg pt_diary)
     '''
     selection = QtCore.QItemSelection()
     # for app in sorted(selected_apps,
     #                   key=lambda x: x.unscheduled, reverse=True):
     for app in selected_apps:
         LOGGER.debug("Need to reselect appointment %s", app)
         try:
             row = self.items.index(app)
             index = self.index(row)
             selection.append(QtCore.QItemSelectionRange(index))
         except ValueError:  # app not in list
             pass
     self.selection_model.select(selection,
                                 QtCore.QItemSelectionModel.Select)
Esempio n. 6
0
 def __updateSelectionInView(self, page):
     """ Makes the current selection in internal widget used to display the
     data values """
     selModel = self._tableView.selectionModel()
     if selModel is not None:
         pageSize = self._pagingInfo.pageSize
         m = self._pageItemModel
         sel = qtc.QItemSelection()
         for row in range(page * pageSize, (page + 1) * pageSize):
             if row in self._selection:
                 sel.append(
                     qtc.QItemSelectionRange(
                         m.index(row % pageSize, 0),
                         m.index(row % pageSize,
                                 m.columnCount() - 1)))
         allSel = qtc.QItemSelection(
             m.index(0, 0), m.index(pageSize - 1,
                                    m.columnCount() - 1))
         selModel.select(allSel, qtc.QItemSelectionModel.Deselect)
         if not sel.isEmpty():
             selModel.select(sel, qtc.QItemSelectionModel.Select)