Esempio n. 1
0
    def replace_command(self,
                        index: QModelIndex,
                        undo_parent: QUndoCommand = None):
        search_txt = self.edit_search.text()
        replace_txt = self.edit_replace.text()
        item_text = index.data(role=Qt.DisplayRole)

        if self.check_case.isChecked():
            flags = 0
        else:
            flags = re.IGNORECASE

        try:
            new_text = re.sub(QRegularExpression.escape(search_txt),
                              replace_txt,
                              item_text,
                              flags=flags)
        except Exception as e:
            LOGGER.error(e)
            return

        if new_text == item_text:
            return

        return ItemEditUndoCommand(item_text,
                                   new_text,
                                   index,
                                   undo_parent,
                                   editing_done=False)
Esempio n. 2
0
    def filterRegExpChanged(self):
        syntax_nr = self.filterSyntaxComboBox.currentData()
        pattern = self.filterPatternLineEdit.text()
        if syntax_nr == WILDCARD:
            pattern = QRegularExpression.wildcardToRegularExpression(pattern)
        elif syntax_nr == FIXED_STRING:
            pattern = QRegularExpression.escape(pattern)

        regExp = QRegularExpression(pattern)
        if not self.filterCaseSensitivityCheckBox.isChecked():
            options = regExp.patternOptions()
            options |= QRegularExpression.CaseInsensitiveOption
            regExp.setPatternOptions(options)
        self.proxyModel.setFilterRegularExpression(regExp)