当前位置: 首页>>代码示例>>C++>>正文


C++ QTextBlock::text方法代码示例

本文整理汇总了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;
}
开发者ID:,项目名称:,代码行数:60,代码来源:

示例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 &reg = 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);
    }
}
开发者ID:getwindow,项目名称:vnote,代码行数:57,代码来源:vpreviewmanager.cpp

示例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();
}
开发者ID:quickhand,项目名称:Prosit,代码行数:9,代码来源:document.cpp

示例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();
}
开发者ID:AsamQi,项目名称:vlc,代码行数:57,代码来源:messages.cpp

示例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;
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例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
}
开发者ID:Wushaowei001,项目名称:NAF,代码行数:10,代码来源:CodeEditor.cpp

示例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;
}
开发者ID:ololoepepe,项目名称:BeQt,代码行数:10,代码来源:babstractfiletype.cpp

示例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));
}
开发者ID:Bramas,项目名称:texiteasy,代码行数:10,代码来源:textdocumentlayout.cpp

示例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);
    }
}
开发者ID:aschet,项目名称:qsaqt5,代码行数:12,代码来源:qsaeditor.cpp

示例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 );
}
开发者ID:Wushaowei001,项目名称:NAF,代码行数:53,代码来源:CodeEditor.cpp

示例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));
}
开发者ID:AvatarSD,项目名称:cmakeprojectmanager2,代码行数:21,代码来源:cmakeindenter.cpp

示例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();
}
开发者ID:XavierCLL,项目名称:QOwnNotes,代码行数:55,代码来源:navigationwidget.cpp

示例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;
}
开发者ID:,项目名称:,代码行数:13,代码来源:

示例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();
}
开发者ID:DuinoDu,项目名称:qt-creator,代码行数:13,代码来源:giteditor.cpp

示例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();
}
开发者ID:hagemt,项目名称:Lirch,代码行数:13,代码来源:lirch_channel.cpp


注:本文中的QTextBlock::text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。