本文整理汇总了C++中QTextCursor::endEditBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::endEditBlock方法的具体用法?C++ QTextCursor::endEditBlock怎么用?C++ QTextCursor::endEditBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::endEditBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotPasteAsQuotation
void ComposerTextEdit::slotPasteAsQuotation()
{
QString text = qApp->clipboard()->text();
if (text.isEmpty())
return;
QStringList lines = text.split(QLatin1Char('\n'));
for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it) {
it->remove(QLatin1Char('\r'));
if (it->startsWith(QLatin1Char('>'))) {
*it = QLatin1Char('>') + *it;
} else {
*it = QLatin1String("> ") + *it;
}
}
text = lines.join(QStringLiteral("\n"));
if (!text.endsWith(QLatin1Char('\n'))) {
text += QLatin1Char('\n');
}
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.insertBlock();
cursor.insertText(text);
cursor.endEditBlock();
setTextCursor(cursor);
}
示例2: updatePreview
void CppCodeStylePreferencesWidget::updatePreview()
{
CppCodeStylePreferences *cppCodeStylePreferences = m_preferences
? m_preferences
: CppToolsSettings::instance()->cppCodeStyle();
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
const TabSettings ts = cppCodeStylePreferences->currentTabSettings();
QtStyleCodeFormatter formatter(ts, ccss);
foreach (SnippetEditorWidget *preview, m_previews) {
preview->textDocument()->setTabSettings(ts);
preview->setCodeStyle(cppCodeStylePreferences);
QTextDocument *doc = preview->document();
formatter.invalidateCache(doc);
QTextBlock block = doc->firstBlock();
QTextCursor tc = preview->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
preview->textDocument()->indenter()->indentBlock(doc, block, QChar::Null, ts);
block = block.next();
}
applyRefactorings(doc, preview, ccss);
tc.endEditBlock();
}
示例3: capitalize
bool Highlighter::capitalize( const QTextBlock &block,QTextCursor cursor ){
QString text=block.text();
QColor color;
int i=0,pos=cursor.position();
cursor.beginEditBlock();
for(;;){
QString t=parseToke( text,color );
if( t.isEmpty() ) break;
QString kw=keyWords().value( t.toLower() );
if( !kw.isEmpty() && t!=kw ){
int i0=block.position()+i;
int i1=i0+t.length();
cursor.setPosition( i0 );
cursor.setPosition( i1,QTextCursor::KeepAnchor );
cursor.insertText( kw );
}
i+=t.length();
}
cursor.endEditBlock();
cursor.setPosition( pos );
return true;
}
示例4: autoBackspace
bool AutoCompleter::autoBackspace(QTextCursor &cursor)
{
m_allowSkippingOfBlockEnd = false;
if (!m_autoParenthesesEnabled)
return false;
int pos = cursor.position();
if (pos == 0)
return false;
QTextCursor c = cursor;
c.setPosition(pos - 1);
QTextDocument *doc = cursor.document();
const QChar lookAhead = doc->characterAt(pos);
const QChar lookBehind = doc->characterAt(pos - 1);
const QChar lookFurtherBehind = doc->characterAt(pos - 2);
const QChar character = lookBehind;
if (character == QLatin1Char('(') || character == QLatin1Char('[')) {
QTextCursor tmp = cursor;
TextEditor::TextBlockUserData::findPreviousBlockOpenParenthesis(&tmp);
int blockStart = tmp.isNull() ? 0 : tmp.position();
tmp = cursor;
TextEditor::TextBlockUserData::findNextBlockClosingParenthesis(&tmp);
int blockEnd = tmp.isNull() ? (cursor.document()->characterCount()-1) : tmp.position();
QChar openChar = character;
QChar closeChar = (character == QLatin1Char('(')) ? QLatin1Char(')') : QLatin1Char(']');
int errors = 0;
int stillopen = 0;
countBrackets(cursor, blockStart, blockEnd, openChar, closeChar, &errors, &stillopen);
int errorsBeforeDeletion = errors + stillopen;
errors = 0;
stillopen = 0;
countBrackets(cursor, blockStart, pos - 1, openChar, closeChar, &errors, &stillopen);
countBrackets(cursor, pos, blockEnd, openChar, closeChar, &errors, &stillopen);
int errorsAfterDeletion = errors + stillopen;
if (errorsAfterDeletion < errorsBeforeDeletion)
return false; // insertion fixes parentheses or bracket errors, do not auto complete
}
// ### this code needs to be generalized
if ((lookBehind == QLatin1Char('(') && lookAhead == QLatin1Char(')'))
|| (lookBehind == QLatin1Char('[') && lookAhead == QLatin1Char(']'))
|| (lookBehind == QLatin1Char('"') && lookAhead == QLatin1Char('"')
&& lookFurtherBehind != QLatin1Char('\\'))
|| (lookBehind == QLatin1Char('\'') && lookAhead == QLatin1Char('\'')
&& lookFurtherBehind != QLatin1Char('\\'))) {
if (! isInComment(c)) {
cursor.beginEditBlock();
cursor.deleteChar();
cursor.deletePreviousChar();
cursor.endEditBlock();
return true;
}
}
return false;
}
示例5: setStyle
//段落标号、编号
void MyChild::setStyle(int style)
{
QTextCursor cursor = this->textCursor();
if (style != 0) {
QTextListFormat::Style stylename = QTextListFormat::ListDisc;
switch (style) {
default:
case 1:
stylename = QTextListFormat::ListDisc;
break;
case 2:
stylename = QTextListFormat::ListCircle;
break;
case 3:
stylename = QTextListFormat::ListSquare;
break;
case 4:
stylename = QTextListFormat::ListDecimal;
break;
case 5:
stylename = QTextListFormat::ListLowerAlpha;
break;
case 6:
stylename = QTextListFormat::ListUpperAlpha;
break;
case 7:
stylename = QTextListFormat::ListLowerRoman;
break;
case 8:
stylename = QTextListFormat::ListUpperRoman;
break;
}
cursor.beginEditBlock();
QTextBlockFormat blockFmt = cursor.blockFormat();
QTextListFormat listFmt;
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(stylename);
cursor.createList(listFmt);
cursor.endEditBlock();
} else {
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
示例6: doTrackBar
void ChatView::doTrackBar()
{
// save position, because our manipulations could change it
int scrollbarValue = verticalScrollBar()->value();
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
PsiRichText::Selection selection = PsiRichText::saveSelection(this, cursor);
//removeTrackBar(cursor);
if (oldTrackBarPosition) {
cursor.setPosition(oldTrackBarPosition, QTextCursor::KeepAnchor);
QTextBlockFormat blockFormat = cursor.blockFormat();
blockFormat.clearProperty(QTextFormat::BlockTrailingHorizontalRulerWidth);
cursor.clearSelection();
cursor.setBlockFormat(blockFormat);
}
//addTrackBar(cursor);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
oldTrackBarPosition = cursor.position();
QTextBlockFormat blockFormat = cursor.blockFormat();
blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, QVariant(true));
cursor.clearSelection();
cursor.setBlockFormat(blockFormat);
PsiRichText::restoreSelection(this, cursor, selection);
cursor.endEditBlock();
setTextCursor(cursor);
verticalScrollBar()->setValue(scrollbarValue);
}
示例7: removeMark
void LrcEditor::removeMark()
{
QTextCursor cursor = textCursor();
QString strText = cursor.block().text();
if (strText.isEmpty())
return ;
const QRegExp exp("^\\[\\d+:\\d+\\.\\d+\\]");
int index = exp.indexIn(strText);
// no time tags
if (index == -1)
return ;
strText.remove(index, exp.matchedLength());
cursor.beginEditBlock();
cursor.select(QTextCursor::LineUnderCursor);
cursor.removeSelectedText();
cursor.insertText(strText);
cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
cursor.endEditBlock();
setTextCursor(cursor);
}
示例8: indent
void CppQtStyleIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
codeFormatter.updateStateUntil(block);
QTextCursor tc = cursor;
tc.beginEditBlock();
do {
int indent;
int padding;
codeFormatter.indentFor(block, &indent, &padding);
tabSettings.indentLine(block, indent + padding, padding);
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);
tc.endEditBlock();
} else {
indentBlock(doc, cursor.block(), typedChar, tabSettings);
}
}
示例9: insertCssProperty
void StyleSheetEditorDialog::insertCssProperty(const QString &name, const QString &value)
{
if (!value.isEmpty()) {
QTextCursor cursor = m_editor->textCursor();
if (!name.isEmpty()) {
cursor.beginEditBlock();
cursor.removeSelectedText();
cursor.movePosition(QTextCursor::EndOfLine);
// Simple check to see if we're in a selector scope
const QTextDocument *doc = m_editor->document();
const QTextCursor closing = doc->find(QStringLiteral("}"), cursor, QTextDocument::FindBackward);
const QTextCursor opening = doc->find(QStringLiteral("{"), cursor, QTextDocument::FindBackward);
const bool inSelector = !opening.isNull() && (closing.isNull() ||
closing.position() < opening.position());
QString insertion;
if (m_editor->textCursor().block().length() != 1)
insertion += QLatin1Char('\n');
if (inSelector)
insertion += QLatin1Char('\t');
insertion += name;
insertion += QStringLiteral(": ");
insertion += value;
insertion += QLatin1Char(';');
cursor.insertText(insertion);
cursor.endEditBlock();
} else {
cursor.insertText(value);
}
}
}
示例10: delete_end_of_word
/**
* Delete all chars from current cursor position to end of word
*/
void HaiQTextEdit::delete_end_of_word() {
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.clearSelection();
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
cursor.removeSelectedText();
cursor.endEditBlock();
}
示例11: moveLineUpDown
void GenericCodeEditor::moveLineUpDown(bool up)
{
// directly taken from qtcreator
// Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
// GNU Lesser General Public License
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.setVisualNavigation(false); // this opens folded items instead of destroying them
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
if (cursor.hasSelection()) {
move.setPosition(cursor.selectionStart());
move.movePosition(QTextCursor::StartOfBlock);
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock,
QTextCursor::KeepAnchor);
} else {
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
QString text = move.selectedText();
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
move.removeSelectedText();
if (up) {
move.movePosition(QTextCursor::PreviousBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.movePosition(QTextCursor::EndOfBlock);
if (move.atBlockStart()) { // empty block
move.movePosition(QTextCursor::NextBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.insertBlock();
}
}
int start = move.position();
move.clearSelection();
move.insertText(text);
int end = move.position();
if (hasSelection) {
move.setPosition(start);
move.setPosition(end, QTextCursor::KeepAnchor);
}
move.endEditBlock();
setTextCursor(move);
}
示例12: rehighlight
inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) {
inReformatBlocks = true;
cursor.beginEditBlock();
int from = cursor.position();
cursor.movePosition(operation);
reformatBlocks(from, 0, cursor.position() - from);
cursor.endEditBlock();
inReformatBlocks = false;
}
示例13: toggleCommentSingleLine
void ScCodeEditor::toggleCommentSingleLine()
{
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
toggleCommentSingleLine( cursor );
cursor.endEditBlock();
}
示例14: mouseDoubleClickEvent
void PostWindow::mouseDoubleClickEvent(QMouseEvent *e)
{
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
QPlainTextEdit::mouseDoubleClickEvent(e);
extendSelectionForEnvVar(this, textCursor());
cursor.endEditBlock();
}
示例15: changeFormatType
void CreateBlogMsg::changeFormatType(int styleIndex )
{
ui.msgEdit->setFocus( Qt::OtherFocusReason );
QTextCursor cursor = ui.msgEdit->textCursor();
//QTextBlockFormat bformat = cursor.blockFormat();
QTextBlockFormat bformat;
QTextCharFormat cformat;
switch (styleIndex) {
default:
case 0:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 0 ) );
cformat.setFontWeight( QFont::Normal );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
break;
case 1:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 1 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 3 ) );
break;
case 2:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 2 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 2 ) );
break;
case 3:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 3 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 1 ) );
break;
case 4:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 4 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
break;
case 5:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 5 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -1 ) );
break;
case 6:
bformat.setProperty( TextFormat::HtmlHeading, QVariant( 6 ) );
cformat.setFontWeight( QFont::Bold );
cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -2 ) );
break;
}
//cformat.clearProperty( TextFormat::HasCodeStyle );
cursor.beginEditBlock();
cursor.mergeBlockFormat( bformat );
cursor.select( QTextCursor::BlockUnderCursor );
cursor.mergeCharFormat( cformat );
cursor.endEditBlock();
}