本文整理汇总了C++中QTextBlock::text方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::text方法的具体用法?C++ QTextBlock::text怎么用?C++ QTextBlock::text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: event
/*!
\reimp
*/
bool QScriptDebuggerCodeView::event(QEvent *e)
{
Q_D(QScriptDebuggerCodeView);
if (e->type() == QEvent::ToolTip) {
if (d->editor->executionLineNumber() == -1)
return false;
QHelpEvent *he = static_cast<QHelpEvent*>(e);
QPoint pt = he->pos();
pt.rx() -= d->editor->extraAreaWidth();
pt.ry() -= 8;
QTextCursor cursor = d->editor->cursorForPosition(pt);
QTextBlock block = cursor.block();
QString contents = block.text();
if (contents.isEmpty())
return false;
int linePosition = cursor.position() - block.position();
linePosition -= 3;
if (linePosition < 0)
linePosition = 0;
// ### generalize -- same as in completiontask
int pos = linePosition;
if ((pos > 0) && contents.at(pos-1).isNumber()) {
// tooltips for numbers is pointless
return false;
}
while ((pos > 0) && isIdentChar(contents.at(pos-1)))
--pos;
if ((pos > 0) && ((contents.at(pos-1) == QLatin1Char('\''))
|| (contents.at(pos-1) == QLatin1Char('\"')))) {
// ignore string literals
return false;
}
int pos2 = linePosition;
while ((pos2 < contents.size()-1) && isIdentChar(contents.at(pos2+1)))
++pos2;
QString ident = contents.mid(pos, pos2 - pos + 1);
QStringList path;
path.append(ident);
while ((pos > 0) && (contents.at(pos-1) == QLatin1Char('.'))) {
--pos;
pos2 = pos;
while ((pos > 0) && isIdentChar(contents.at(pos-1)))
--pos;
path.prepend(contents.mid(pos, pos2 - pos));
}
if (!path.isEmpty()) {
int lineNumber = cursor.blockNumber() + d->editor->baseLineNumber();
emit toolTipRequest(he->globalPos(), lineNumber, path);
}
}
return false;
}
示例2: fetchImageLinksFromRegions
void VPreviewManager::fetchImageLinksFromRegions(QVector<VElementRegion> p_imageRegions,
QVector<ImageLinkInfo> &p_imageLinks)
{
p_imageLinks.clear();
if (p_imageRegions.isEmpty()) {
return;
}
p_imageLinks.reserve(p_imageRegions.size());
QTextDocument *doc = m_editor->document();
for (int i = 0; i < p_imageRegions.size(); ++i) {
const VElementRegion ® = p_imageRegions[i];
QTextBlock block = doc->findBlock(reg.m_startPos);
if (!block.isValid()) {
continue;
}
int blockStart = block.position();
int blockEnd = blockStart + block.length() - 1;
QString text = block.text();
// Since the image links update signal is emitted after a timer, during which
// the content may be changed.
if (reg.m_endPos > blockEnd) {
continue;
}
ImageLinkInfo info(reg.m_startPos,
reg.m_endPos,
blockStart,
block.blockNumber(),
calculateBlockMargin(block, m_editor->tabStopWidthW()));
if ((reg.m_startPos == blockStart
|| isAllSpaces(text, 0, reg.m_startPos - blockStart))
&& (reg.m_endPos == blockEnd
|| isAllSpaces(text, reg.m_endPos - blockStart, blockEnd - blockStart))) {
// Image block.
info.m_isBlock = true;
fetchImageInfoToPreview(text, info);
} else {
// Inline image.
info.m_isBlock = false;
fetchImageInfoToPreview(text.mid(reg.m_startPos - blockStart,
reg.m_endPos - reg.m_startPos),
info);
}
if (info.m_linkUrl.isEmpty() || info.m_linkShortUrl.isEmpty()) {
continue;
}
p_imageLinks.append(info);
}
}
示例3: dictionaryChanged
void Document::dictionaryChanged()
{
for (QTextBlock i = m_text->document()->begin(); i != m_text->document()->end(); i = i.next()) {
if (i.userData()) {
static_cast<BlockStats*>(i.userData())->checkSpelling(i.text(), m_dictionary);
}
}
m_highlighter->rehighlight();
}
示例4: sinkMessage
void MessagesDialog::sinkMessage( const MsgEvent *msg )
{
QMutexLocker locker( &messageLocker );
QPlainTextEdit *messages = ui.messages;
/* Only scroll if the viewport is at the end.
Don't bug user by auto-changing/losing viewport on insert(). */
bool b_autoscroll = ( messages->verticalScrollBar()->value()
+ messages->verticalScrollBar()->pageStep()
>= messages->verticalScrollBar()->maximum() );
/* Copy selected text to the clipboard */
if( messages->textCursor().hasSelection() )
messages->copy();
/* Fix selected text bug */
if( !messages->textCursor().atEnd() ||
messages->textCursor().anchor() != messages->textCursor().position() )
messages->moveCursor( QTextCursor::End );
/* Start a new logic block so we can hide it on-demand */
messages->textCursor().insertBlock();
QString buf = QString( "<i><font color='darkblue'>%1</font>" ).arg( msg->module );
switch ( msg->priority )
{
case VLC_MSG_INFO:
buf += "<font color='blue'> info: </font>";
break;
case VLC_MSG_ERR:
buf += "<font color='red'> error: </font>";
break;
case VLC_MSG_WARN:
buf += "<font color='green'> warning: </font>";
break;
case VLC_MSG_DBG:
default:
buf += "<font color='grey'> debug: </font>";
break;
}
/* Insert the prefix */
messages->textCursor().insertHtml( buf /* + "</i>" */ );
/* Insert the message */
messages->textCursor().insertHtml( msg->text );
/* Pass the new message thru the filter */
QTextBlock b = messages->document()->lastBlock();
b.setVisible( matchFilter( b.text() ) );
/* Tell the QTextDocument to recompute the size of the given area */
messages->document()->markContentsDirty( b.position(), b.length() );
if ( b_autoscroll ) messages->ensureCursorVisible();
}
示例5:
std::vector<std::string> CodeEditor::getEditorContent()
{
std::vector<std::string> list;
for (QTextBlock block = document()->begin(); block.isValid(); block = block.next())
{
list.push_back(block.text().toStdString());
}
return list;
}
示例6:
static inline int _firstNwsPos( const QTextBlock& b )
{
const QString str = b.text();
for( int i = 0; i < str.size(); i++ )
{
if( !str[i].isSpace() )
return b.position() + i;
}
return b.position() + b.length(); // Es ist nur WS vorhanden
}
示例7: indentation
int BAbstractFileType::indentation(const QTextBlock &previousBlock) const
{
if (!previousBlock.isValid())
return 0;
QString text = previousBlock.text();
int i = 0;
while (i < text.length() && text.at(i) == ' ')
++i;
return i;
}
示例8: indentWidth
qreal TextDocumentLayout::indentWidth(const QTextBlock &block)
{
QRegExp exp("^[ \\t]*");
if(exp.indexIn(block.text()) == -1)
{
return 0;
}
QFontMetrics fm(block.charFormat().font());
return fm.width(exp.capturedTexts().at(0));
}
示例9: indentDocument
static void indentDocument(QTextDocument *doc)
{
QStringList allCode;
for (QTextBlock block = doc->begin(); block.isValid(); block = block.next())
allCode << block.text();
QTextBlock block = doc->begin();
for (int line = 0; line < allCode.count() && block.isValid(); ++line, block = block.next()) {
const QStringList previousCode = allCode.mid(0, line + 1);
indent(block, previousCode);
}
}
示例10: keyPressEvent
void CodeEditor::keyPressEvent(QKeyEvent *e)
{
// SHIFT+TAB kommt hier nie an aus nicht nachvollziehbaren Grnden. Auch in event und viewPortEvent nicht.
// NOTE: Qt macht daraus automatisch BackTab und versendet das!
if( e->key() == Qt::Key_Tab )
{
if( e->modifiers() & Qt::ControlModifier )
{
// Wir brauchen CTRL+TAB fr Umschalten der Scripts
e->ignore();
return;
}
if( !isReadOnly() && ( hasSelection() || textCursor().position() <= _firstNwsPos( textCursor().block() ) ) )
{
if( e->modifiers() == Qt::NoModifier )
{
indent();
e->accept();
return;
}
}
}else if( e->key() == Qt::Key_Backtab )
{
if( e->modifiers() & Qt::ControlModifier )
{
// Wir brauchen CTRL+TAB fr Umschalten der Scripts
e->ignore();
return;
}
if( !isReadOnly() && ( hasSelection() || textCursor().position() <= _firstNwsPos( textCursor().block() ) ) )
{
unindent();
e->accept();
return;
}
}else if( !isReadOnly() && ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) )
{
e->accept();
if( e->modifiers() != Qt::NoModifier )
return; // Verschlucke Return mit Ctrl etc.
textCursor().beginEditBlock();
QPlainTextEdit::keyPressEvent( e ); // Lasse Qt den neuen Block einfgen
QTextBlock prev = textCursor().block().previous();
if( prev.isValid() )
{
const int ws = _firstNwsPos( prev );
textCursor().insertText( prev.text().left( ws - prev.position() ) );
}
textCursor().endEditBlock();
return;
}
QPlainTextEdit::keyPressEvent( e );
}
示例11: indentFor
int CMakeIndenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
{
QTextBlock previousBlock = block.previous();
// find the next previous block that is non-empty (contains non-whitespace characters)
while (previousBlock.isValid() && lineIsEmpty(previousBlock.text()))
previousBlock = previousBlock.previous();
if (!previousBlock.isValid())
return 0;
const QString previousLine = previousBlock.text();
const QString currentLine = block.text();
int indentation = tabSettings.indentationColumn(previousLine);
if (lineStartsBlock(previousLine))
indentation += tabSettings.m_indentSize;
if (lineEndsBlock(currentLine))
indentation = qMax(0, indentation - tabSettings.m_indentSize);
// increase/decrease/keep the indentation level depending on if we have more opening or closing parantheses
return qMax(0, indentation + tabSettings.m_indentSize * paranthesesLevel(previousLine));
}
示例12: parse
/**
* Parses a text document and builds the navigation tree for it
*/
void NavigationWidget::parse(QTextDocument *document) {
const QSignalBlocker blocker(this);
Q_UNUSED(blocker);
setDocument(document);
clear();
_lastHeadingItemList.clear();
for (int i = 0; i < document->blockCount(); i++) {
QTextBlock block = document->findBlockByNumber(i);
int elementType = block.userState();
// ignore all non headline types
if ((elementType < pmh_H1) || (elementType > pmh_H6)) {
continue;
}
QString text = block.text();
text.remove(QRegularExpression("^#+"))
.remove(QRegularExpression("#+$"))
.remove(QRegularExpression("^\\s+"))
.remove(QRegularExpression("^=+$"))
.remove(QRegularExpression("^-+$"));
if (text.isEmpty()) {
continue;
}
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, text);
item->setData(0, Qt::UserRole, block.position());
item->setToolTip(0, tr("headline %1").arg(elementType - pmh_H1 + 1));
// attempt to find a suitable parent item for the element type
QTreeWidgetItem *lastHigherItem = findSuitableParentItem(elementType);
if (lastHigherItem == NULL) {
// if there wasn't a last higher level item then add the current
// item to the top level
addTopLevelItem(item);
} else {
// if there was a last higher level item then add the current
// item as child of that item
lastHigherItem->addChild(item);
}
_lastHeadingItemList[elementType] = item;
}
expandAll();
}
示例13: main
int main(int argv, char **args)
{
QString contentString("One\nTwp\nThree");
QTextDocument *doc = new QTextDocument(contentString);
//! [0]
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
cout << it.text().toStdString() << endl;
//! [0]
return 0;
}
示例14: fileNameForLine
QString GitEditorWidget::fileNameForLine(int line) const
{
// 7971b6e7 share/qtcreator/dumper/dumper.py (hjk
QTextBlock block = document()->findBlockByLineNumber(line - 1);
QTC_ASSERT(block.isValid(), return source());
static QRegExp renameExp(QLatin1String("^" CHANGE_PATTERN "\\s+([^(]+)"));
if (renameExp.indexIn(block.text()) != -1) {
const QString fileName = renameExp.cap(1).trimmed();
if (!fileName.isEmpty())
return fileName;
}
return source();
}
示例15: persist
void LirchChannel::persist() const {
if (stream) {
int num_blocks = document->blockCount();
QTextBlock block = document->begin();
for (int i = 0; i < num_blocks; ++i) {
endl(*stream << block.text());
emit progress(i * 100 / num_blocks);
block = block.next();
}
emit progress(100);
}
emit persisted();
}