Ejemplo n.º 1
0
 def onSaveBtClicked(self):
     rtn = QMessageBox.question(self, 'Confirm', 'Save position changes ?',
                                QMessageBox.Yes, QMessageBox.No)
     if rtn == QMessageBox.Yes:
         data = TableHandler()
         data.copy(self.model.data)
         invalid_rows = PosEditor.findInvalidRows(data)
         if invalid_rows:
             data.delRows(invalid_rows)
         if data.rows > 0:
             self.controler.onEditorClickBtSaveAll(data)
             self.close()
         else:
             cf = QMessageBox.warning(self, 'Error',
                                      'position record invalid !', QMessageBox.Yes)
     return
Ejemplo n.º 2
0
 def onSaveAllBtClicked(self):
     rtn = QMessageBox.question(self, 'Confirm', 'Save position changes?',
                                QMessageBox.Yes, QMessageBox.No)
     if rtn == QMessageBox.Yes:
         data = TableHandler()
         data.copy(self.model.data)
         invalid_rows = PosEditor.findInvalidRows(data)
         if invalid_rows:
             data.delRows(invalid_rows)
         if data.rows > 0:
             self.controler.onEditorClickBtSaveAll(data)
         else:
             QMessageBox.warning(self, 'Error',
                                 'None valid records!', QMessageBox.Yes)
         #notify
         if invalid_rows:
             info_str = 'Invalid rows deleted:\n%s' % str([i+1 for i in invalid_rows])
             QMessageBox.warning(self, 'Warning', info_str, QMessageBox.Yes)
         else:
             self.close()
     return
Ejemplo n.º 3
0
 def onSaveAllBtClicked(self):
     rtn = QMessageBox.question(self, 'Confirm', 'Save position changes?',
                                QMessageBox.Yes, QMessageBox.No)
     if rtn == QMessageBox.Yes:
         data = TableHandler()
         data.copy(self.model.data)
         invalid_rows = PosEditor.findInvalidRows(data)
         if invalid_rows:
             data.delRows(invalid_rows)
         if data.rows > 0:
             self.controler.onEditorClickBtSaveAll(data)
         else:
             QMessageBox.warning(self, 'Error', 'None valid records!',
                                 QMessageBox.Yes)
         #notify
         if invalid_rows:
             info_str = 'Invalid rows deleted:\n%s' % str(
                 [i + 1 for i in invalid_rows])
             QMessageBox.warning(self, 'Warning', info_str, QMessageBox.Yes)
         else:
             self.close()
     return
Ejemplo n.º 4
0
class MatrixModel(QAbstractTableModel):
    def __init__(self, parent=None):
        super(MatrixModel, self).__init__(parent)
        self.data = TableHandler()
        #signal&slot
        return

    def clearAll(self):
        self.data.clear()
        self.emit(SIGNAL('modelReset()'))

    def clearContent(self):
        self.data.clearContent()
        self.emit(SIGNAL('modelReset()'))

    def setSize(self, rows, col_headers):
        self.data.reset(rows, col_headers)
        self.emit(SIGNAL('modelReset()'))
        return

    def setTableContent(self, table_handler_inst):
        self.data.copyContent(table_handler_inst)
        self.emit(SIGNAL('modelReset()'))
        return

    def appendRows(self, n=1):
        self.data.addRows(n)
        self.emit(SIGNAL('rowsInserted(const QModelIndex &, int, int)'),
                  QModelIndex(), self.data.rows, self.data.rows + n - 1)

    def deleteRows(self, row_list):
        self.data.delRows(row_list)
        self.emit(SIGNAL('modelReset()'))

    def getValue(self, row, column):
        return self.data.get(row, column)

    def getValueByHeader(self, row, header):
        return self.data.getByHeader(row, header)

    #qt inherit & override
    #-----------------------------------------------------------
    def rowCount(self, QModelIndex_parent=None, *args, **kwargs):
        return self.data.rows

    def columnCount(self, QModelIndex_parent=None, *args, **kwargs):
        return self.data.columns

    def headerData(self, p_int, Qt_Orientation, int_role=None):
        if int_role == Qt.DisplayRole:
            if Qt_Orientation == Qt.Horizontal:
                return self.data.getHoriHeader(p_int)
            elif Qt_Orientation == Qt.Vertical:
                return str(p_int + 1)
        return None

    def data(self, QModelIndex, int_role=None):
        if QModelIndex.isValid():
            if int_role == Qt.DisplayRole:
                return self.data.get(QModelIndex.row(), QModelIndex.column())
        return None

    def setData(self, QModelIndex, p_object, int_role=None):
        if int_role == Qt.EditRole:
            self.data.set(QModelIndex.row(), QModelIndex.column(), p_object)
        return True

    def flags(self, QModelIndex):
        return Qt.ItemIsEditable | super(MatrixModel, self).flags(QModelIndex)