예제 #1
0
    def dropMimeData(
            self, mimeData: QMimeData, action: Qt.DropAction, row: int,
            column: int, index: QModelIndex) -> bool:
        """
        Drop MIME data.
        """
        # pylint: disable=W0613
        if mimeData.hasFormat(mime_types['list']):
            mime_type = mime_types['list']
        elif mimeData.hasFormat(mime_types['colrow']):
            mime_type = mime_types['colrow']
        elif mimeData.hasFormat(mime_types['value']):
            mime_type = mime_types['value']
        else:
            return False

        data = mimeData.data(mime_type)
        stream = QDataStream(data, QIODevice.ReadOnly)
        data_set = []

        while not stream.atEnd():
            stream_type = stream.readBytes().decode('utf-8')
            name = stream.readBytes().decode('utf-8')
            id = stream.readInt16()  # pylint: disable=W0622
            field = (stream_type, name, id)
            modelRCV = self.modelRC + self.modelValue

            if stream_type == 'calculation' and \
                stream_type in [x[0] for x in modelRCV] and \
                    mime_type == mime_types['list']:
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'Function can be droped in only one area.'
                    ), 15000)
                return False

            elif (field in self.modelRC or field in self.tab) and \
                    mime_type in [mime_types['list'], mime_types['value']]:
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'This field has already been droped.'
                    ), 15000)
                return False

            elif stream_type == 'calculation' and \
                id not in self.calculation.listText and \
                    'text' in [x[0] for x in self.modelValue]:
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'For the text value, function can only be one of '
                        '{}.'.format(self.calculation.textName)
                    ), 15000)
                return False

            data_set.append(field)

        self.insertRows(row, len(data_set), index, data_set)
        return True
예제 #2
0
    def dropMimeData(
            self, mimeData: QMimeData, action: Qt.DropAction, row: int,
            column: int, index: QModelIndex) -> bool:
        """
        Drop MIME data.
        """
        # pylint: disable=W0613
        if mimeData.hasFormat(mime_types['list']):
            mime_type = mime_types['list']
        elif mimeData.hasFormat(mime_types['colrow']):
            mime_type = mime_types['colrow']
        elif mimeData.hasFormat(mime_types['value']):
            mime_type = mime_types['value']
        else:
            return False

        data = mimeData.data(mime_type)
        stream = QDataStream(data, QIODevice.ReadOnly)
        data_set = []
        while not stream.atEnd():
            stream_type = stream.readBytes().decode('utf-8')
            name = stream.readBytes().decode('utf-8')
            id = stream.readInt16()  # pylint: disable=W0622
            field = (stream_type, name, id)
            dataRC = self.modelRows + self.modelColumns
            all_data = dataRC + self.tab

            if len(self.tab) >= 2:
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'Value field may contain a maximum of two entries.'
                    ), 15000)
                return False

            elif stream_type == 'calculation' and \
                stream_type in [x[0] for x in all_data] and \
                    mime_type == mime_types['list']:
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'Function can be droped in only one area.'
                    ), 15000)
                return False

            elif len(self.tab) == 1 and stream_type != 'calculation' and \
                    self.tab[0][0] != 'calculation':
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'One of the items in the Value field must be a '
                        'function.'
                    ), 15000)
                return False

            elif len(self.tab) == 1 and \
                    ((stream_type == 'text' and
                      self.tab[0][2] not in self.calculation.listText) or
                     (id not in self.calculation.listText and
                      self.tab[0][0] == 'text')):
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'For the text value, function can only be one of '
                        '{}.'.format(self.calculation.textName)
                    ), 15000)
                return False

            elif stream_type == 'text' and \
                    [x for x in dataRC if x[0] == 'calculation' and
                     x[2] not in self.calculation.listText]:
                self.main_window.statusBar() \
                    .showMessage(QCoreApplication.translate(
                        'GroupStats',
                        'For the text value function can only be one of '
                        '{}.'.format(self.calculation.textName)
                    ), 15000)
                return False

            data_set.append(field)

        self.insertRows(row, len(data_set), index, data_set)
        return True