• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ktexteditor::Range类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ktexteditor::Range的典型用法代码示例。如果您正苦于以下问题:C++ Range类的具体用法?C++ Range怎么用?C++ Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Range类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: rangeFromScriptValue

/** Conversion function from QtScript range to KTextEditor::Range */
static void rangeFromScriptValue(const QScriptValue &obj, KTextEditor::Range &range)
{
  range.start().setPosition(obj.property("start").property("line").toInt32(),
                            obj.property("start").property("column").toInt32());
  range.end().setPosition(obj.property("end").property("line").toInt32(),
                          obj.property("end").property("column").toInt32());
}
开发者ID:fagu,项目名称:kileip,代码行数:8,代码来源:script.cpp


示例2: getItemBoundingRect

QRect KTextEditorHelpers::getItemBoundingRect(const KTextEditor::View* view, const KTextEditor::Range& itemRange)
{
  QPoint startPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.start()));
  QPoint endPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.end()));
  endPoint.ry() += getLineHeight(view, itemRange.start().line());
  return QRect(startPoint, endPoint);
}
开发者ID:KDE,项目名称:kdevplatform,代码行数:7,代码来源:texteditorhelpers.cpp


示例3: rangeToScriptValue

/** Conversion function from QtScript range to KTextEditor::Range */
static QScriptValue rangeToScriptValue(QScriptEngine *engine, const KTextEditor::Range &range)
{
  QString code = QString("new Range(%1, %2, %3, %4);").arg(range.start().line())
                                                      .arg(range.start().column())
                                                      .arg(range.end().line())
                                                      .arg(range.end().column());
  return engine->evaluate(code);
}
开发者ID:fagu,项目名称:kileip,代码行数:9,代码来源:script.cpp


示例4: assert

void ClangCodeCompletionModel::executeCompletionItem2(
    KTextEditor::Document* const doc
  , const KTextEditor::Range& word
  , const QModelIndex& index
  ) const
{
    assert("Active view expected to be equal to the stored one" && doc->activeView() == m_current_view);
    assert("Invalid index is not expected here!" && index.isValid());
    assert("Parent index is not valid" && index.parent().isValid());
    assert("Parent index must be GROUP" && index.parent().internalId() == Level::GROUP);
    assert(
        "Parent index points to invalid group"
      && 0 <= index.internalId()
      && unsigned(index.internalId()) < m_groups.size()
      );
    assert(
        "Index points to invalid item"
      && 0 <= index.row()
      && unsigned(index.row()) < m_groups[index.internalId()].second.m_completions.size()
      );

    auto* const template_iface = qobject_cast<KTextEditor::TemplateInterface2*>(m_current_view);
    if (template_iface)
    {
        kDebug(DEBUG_AREA) << "TemplateInterface available for a view" << m_current_view;
        const auto result = m_groups[index.internalId()]
          .second.m_completions[index.row()]
          .getCompletionTemplate();
        kDebug(DEBUG_AREA) << "Template:" << result.m_tpl;
        kDebug(DEBUG_AREA) << "Values:" << result.m_values;
        // Check if current template is a function and there is a '()' right after cursor
        auto range = word;
        if (result.m_is_function)
        {
            const auto next_word_range = DocumentProxy(doc).firstWordAfterCursor(word.end());
            kDebug(DEBUG_AREA) << "OK THIS IS FUNCTION TEMPLATE: next word range" << next_word_range;
            kDebug(DEBUG_AREA) << "replace range before:" << range;
            if (next_word_range.isValid() && doc->text(next_word_range).startsWith(QLatin1String("()")))
            {
                range.end().setColumn(next_word_range.start().column() + 2);
                kDebug(DEBUG_AREA) << "replace range after:" << range;
            }
        }
        doc->removeText(range);
        template_iface->insertTemplateText(range.start(), result.m_tpl, result.m_values, nullptr);
    }
    else
    {
        kDebug(DEBUG_AREA) << "No TemplateInterface for a view" << m_current_view;
        const auto p = m_groups[index.internalId()].second.m_completions[index.row()].executeCompletion();
        doc->replaceText(word, p.first);
        // Try to reposition a cursor inside a current (hope it still is) view
        auto pos = word.start();
        pos.setColumn(pos.column() + p.second);
        m_current_view->setCursorPosition(pos);
    }
}
开发者ID:zaufi,项目名称:kate-cpp-helper-plugin,代码行数:57,代码来源:clang_code_completion_model.cpp


示例5: updateContextRange

void CodeCompletionWorker::updateContextRange(KTextEditor::Range& contextRange, KTextEditor::View* /*view*/, DUContextPointer context) const
{
  if(context && context->owner() && context->owner()->type<FunctionType>()) {
    if(!context->owner()->type<FunctionType>()->returnType()) {
      //For constructor completion, we need some more context
      contextRange.start().setLine(contextRange.start().line() > 30 ? contextRange.start().line()-30 : 0);
      contextRange.start().setColumn(0);
    }
  }
}
开发者ID:krf,项目名称:kdevelop,代码行数:10,代码来源:worker.cpp


示例6: allMatches

// Scan throughout the entire document for possible completions,
// ignoring any dublets
const QStringList KateWordCompletionModel::allMatches( KTextEditor::View *view, const KTextEditor::Range &range ) const
{
  KTextEditor::Document *doc = view->document();
  QString match_str = doc->text(range);
  QString s, m;
  QSet<QString> seen;
  QStringList l;

  int i( 0 );
  int pos( 0 );

  QRegExp re( "\\b(" + match_str + "\\w{1,})" );

  while( i < doc->lines() )
  {
      s = doc->line( i );
      pos = 0;
      while ( pos >= 0 )
      {
        pos = re.indexIn( s, pos );
        if ( pos >= 0 )
        {
          // typing in the middle of a word
          if ( ! ( i == range.start().line() && pos == range.start().column() ) )
          {
            m = re.cap( 1 );
            if ( ! seen.contains( m ) ) {
              seen.insert( m );
              l << m;
            }
          }
          pos += re.matchedLength();
        }
      }
    i++;
  }

  // Global completion
  // int db_area = KDebug::registerArea("ktuan-debug");
  QMap<QString, QStringList>::const_iterator ci = doc_word_list.constBegin();
  while (ci != doc_word_list.constEnd()) {
  if (ci.key() != doc->url().prettyUrl()) {
    QStringList list = ci.value();
    foreach (QString word, list) {
      // kDebug(db_area) << "complete word " << word;
      if (word.startsWith(match_str) && !seen.contains(word)) {
        // kDebug(db_area) << "Global completion";
        seen.insert(word);
        l << word;
      }
    }
  }
  ++ci;
  }
开发者ID:ktuan89,项目名称:kate-4.8.0,代码行数:56,代码来源:katewordcompletion.cpp


示例7: removeText

void TextHistory::removeText(const KTextEditor::Range &range, int oldLineLength)
{
    // create and add new entry
    Entry entry;
    entry.type = Entry::RemoveText;
    entry.line = range.start().line();
    entry.column = range.start().column();
    entry.length = range.end().column() - range.start().column();
    entry.oldLineLength = oldLineLength;
    addEntry(entry);
}
开发者ID:KDE,项目名称:ktexteditor,代码行数:11,代码来源:katetexthistory.cpp


示例8: execute

void ImplementFunctionCompletionItem::execute(KTextEditor::Document* document, const KTextEditor::Range& word)
{
    const QString finalText = m_name + "(" + m_arguments.join(", ") + "):";
    document->replaceText(word, finalText);
    // 4 spaces is indentation for python. everyone does it like this. you must, too.
    // TODO use kate settings
    document->insertLine(word.start().line() + 1, m_previousIndent + "    ");
    if ( View* view = document->activeView() ) {
        view->setCursorPosition(Cursor(word.end().line() + 1, m_previousIndent.length() + 4));
    }
}
开发者ID:kensington,项目名称:kdevelop-python,代码行数:11,代码来源:implementfunction.cpp


示例9: startLaTeXCompletion

void LaTeXInfo::startLaTeXCompletion(KTextEditor::View *view)
{
	KTextEditor::CodeCompletionInterface* completionInterface = qobject_cast<KTextEditor::CodeCompletionInterface*>(view);
	if(!completionInterface) {
		return;
	}
	KTextEditor::Range range = m_latexCompletionModel->completionRange(view, view->cursorPosition());
	if(!range.isValid()) {
		range = KTextEditor::Range(view->cursorPosition(), view->cursorPosition());
	}
	completionInterface->startCompletion(range, m_latexCompletionModel);
}
开发者ID:KDE,项目名称:kile,代码行数:12,代码来源:documentinfo.cpp


示例10: execute

void KeywordItem::execute(KTextEditor::View* view, const KTextEditor::Range& word)
{
    KTextEditor::Document *document = view->document();
    if ( !m_replacement.isEmpty() ) {
        QString replacement = m_replacement;
        replacement = replacement.replace('\n', '\n' + getIndendation(document->line(word.start().line())));
        replacement = replacement.replace(QLatin1String("%INDENT%"), indentString(document));

        int cursorPos = replacement.indexOf(QStringLiteral("%CURSOR%"));
        int selectionEnd = -1;
        if ( cursorPos != -1 ) {
            replacement.remove(QStringLiteral("%CURSOR%"));
        } else {
            cursorPos = replacement.indexOf(QStringLiteral("%SELECT%"));
            if ( cursorPos != -1 ) {
                replacement.remove(QStringLiteral("%SELECT%"));
                selectionEnd = replacement.indexOf(QStringLiteral("%ENDSELECT%"), cursorPos + 1);
                if ( selectionEnd == -1 ) {
                    selectionEnd = replacement.length();
                }
                replacement.remove(QStringLiteral("%ENDSELECT%"));
            }
        }

        document->replaceText(word, replacement);

        if ( cursorPos != -1 ) {
            if (view) {
                replacement = replacement.left(cursorPos);
                KTextEditor::Cursor newPos(
                    word.start().line() + replacement.count('\n'),
                    word.start().column() + replacement.length() - replacement.lastIndexOf('\n') - 1
                );
                view->setCursorPosition(newPos);
                if ( selectionEnd != -1 ) {
                    ///TODO: maybe we want to support multi-line selections in the future?
                    view->setSelection(
                        KTextEditor::Range(
                            newPos,
                            KTextEditor::Cursor(
                                newPos.line(),
                                newPos.column() + selectionEnd - cursorPos
                            )
                        )
                    );
                }
            }
        }
    } else {
        document->replaceText(word, m_keyword + ' ');
    }
}
开发者ID:KDE,项目名称:kdev-php,代码行数:52,代码来源:keyworditem.cpp


示例11: removeText

void SwapFile::removeText (const KTextEditor::Range &range)
{
  // skip if not open
  if (!m_swapfile.isOpen ())
    return;
  
  // format: qint8, int, int, int
  Q_ASSERT (range.start().line() == range.end().line());
  m_stream << EA_RemoveText
            << range.start().line() << range.start().column()
            << range.end().column();

  m_needSync = true;
}
开发者ID:dividedmind,项目名称:kate,代码行数:14,代码来源:kateswapfile.cpp


示例12: localTextRemoved

void KDocumentTextBuffer::localTextRemoved( KTextEditor::Document *document,
    const KTextEditor::Range &range, const QString& oldText )
{
    if ( m_aboutToClose ) return;

    kDebug() << "local text removed:" << kDocument() << range;
    emit localChangedText(range, user(), true);

    Q_UNUSED(document)

    textOpPerformed();
    if( !m_user.isNull() )
    {
        unsigned int offset = cursorToOffset_kte( range.start() );
        unsigned int len = countUnicodeCharacters(oldText);
        blockRemoteRemove = true;
        kDebug() << "ERASING TEXT" << oldText << "with len" << len << "offset" << offset << "range" << range;
        kDebug() << offset << len << length();
        if( len > 0 )
            eraseText( offset, len, m_user );
        else
            kDebug() << "0 legth delete operation. Skipping.";
        checkConsistency();
    }
    else
        kDebug() << "Could not remove text: No local user set.";

}
开发者ID:KDE,项目名称:kte-collaborative,代码行数:28,代码来源:document.cpp


示例13: assert

void PreprocessorCompletionModel::executeCompletionItem2(
    KTextEditor::Document* const doc
  , const KTextEditor::Range& word
  , const QModelIndex& index
  ) const
{
    assert("Invalid index is not expected here!" && index.isValid());
    assert("Parent index is not valid" && index.parent().isValid());
    assert("Parent index must be GROUP" && index.parent().internalId() == Level::GROUP);
    assert("Index points to invalid item" && unsigned(index.row()) < COMPLETIONS.size());

    auto text = COMPLETIONS[index.row()].text;
    const auto column = text.indexOf('|');
    if (column != -1)
        text.remove(column, 1);

    doc->replaceText(word, text);

    // Try to reposition a cursor inside a current view
    if (column != -1)
    {
        auto pos = word.start();
        pos.setColumn(pos.column() + column);
        doc->activeView()->setCursorPosition(pos);
    }
}
开发者ID:zaufi,项目名称:kate-cpp-helper-plugin,代码行数:26,代码来源:preprocessor_completion_model.cpp


示例14: execute

void SnippetCompletionItem::execute( KTextEditor::View* view, const KTextEditor::Range& word )
{
    QMap< QString, QString > values = QMap<QString, QString>();
    KTextEditor::TemplateInterface2* templateIface2 = qobject_cast<KTextEditor::TemplateInterface2*>(view);
    if (templateIface2)
      templateIface2->insertTemplateText(word.start(), m_snippet, values, m_repo->registeredScript());
}
开发者ID:mkhoeini,项目名称:kate,代码行数:7,代码来源:snippetcompletionitem.cpp


示例15: checkValidity

TextRange::TextRange (TextBuffer &buffer, const KTextEditor::Range &range, InsertBehaviors insertBehavior, EmptyBehavior emptyBehavior)
  : m_buffer (buffer)
  , m_start (buffer, this, range.start(), (insertBehavior & ExpandLeft) ? Kate::TextCursor::StayOnInsert : Kate::TextCursor::MoveOnInsert)
  , m_end (buffer, this, range.end(), (insertBehavior & ExpandRight) ? Kate::TextCursor::MoveOnInsert : Kate::TextCursor::StayOnInsert)
  , m_view (0)
  , m_feedback (0)
  , m_zDepth (0.0)
  , m_attributeOnlyForViews (false)
  , m_invalidateIfEmpty (emptyBehavior == InvalidateIfEmpty)
{
  // remember this range in buffer
  m_buffer.m_ranges.insert (this);

  // check if range now invalid, there can happen no feedback, as m_feedback == 0
  checkValidity ();
}
开发者ID:UIKit0,项目名称:kate,代码行数:16,代码来源:katetextrange.cpp


示例16: textInserted

void KateViInsertMode::textInserted(KTextEditor::Document* document, KTextEditor::Range range)
{
  if (m_isExecutingCompletion)
  {
    m_textInsertedByCompletion += document->text(range);
    m_textInsertedByCompletionEndPos = range.end();
  }
}
开发者ID:dividedmind,项目名称:kate,代码行数:8,代码来源:kateviinsertmode.cpp


示例17: setRange

void TextRange::setRange (const KTextEditor::Range &range)
{
  // avoid work if nothing changed!
  if (range == toRange())
    return;

  // remember old line range
  int oldStartLine = m_start.line();
  int oldEndLine = m_end.line();

  // change start and end cursor
  m_start.setPosition (range.start ());
  m_end.setPosition (range.end ());

  // check if range now invalid, don't emit feedback here, will be handled below
  // otherwise you can't delete ranges in feedback!
  checkValidity (oldStartLine, oldEndLine, false);

  // no attribute or feedback set, be done
  if (!m_attribute && !m_feedback)
    return;

  // get full range
  int startLineMin = oldStartLine;
  if (oldStartLine == -1 || (m_start.line() != -1 && m_start.line() < oldStartLine))
    startLineMin = m_start.line();

  int endLineMax = oldEndLine;
  if (oldEndLine == -1 || m_end.line() > oldEndLine)
    endLineMax = m_end.line();

  /**
   * notify buffer about attribute change, it will propagate the changes
   * notify right view
   */
  m_buffer.notifyAboutRangeChange (m_view, startLineMin, endLineMax, m_attribute);

  // perhaps need to notify stuff!
  if (m_feedback) {
    // do this last: may delete this range
    if (!toRange().isValid())
      m_feedback->rangeInvalid (this);
    else if (toRange().isEmpty())
      m_feedback->rangeEmpty (this);
  }
}
开发者ID:UIKit0,项目名称:kate,代码行数:46,代码来源:katetextrange.cpp


示例18: completionInvoked

void PreprocessorCompletionModel::completionInvoked(
    KTextEditor::View* const view
  , const KTextEditor::Range& word
  , InvocationType /*itype*/
  )
{
    // Reuse shouldStartCompletion to disable/enable completion
    m_should_complete = shouldStartCompletion(view, QString{}, false, word.end());
}
开发者ID:zaufi,项目名称:kate-cpp-helper-plugin,代码行数:9,代码来源:preprocessor_completion_model.cpp


示例19: execute

    void execute(KTextEditor::View* view, const KTextEditor::Range& word) override
    {
        auto document = view->document();
        auto range = word;
        const int lineNumber = word.end().line();
        const QString line = document->line(lineNumber);
        const auto properties = includePathProperties(line, word.end().column());
        if (!properties.valid) {
            return;
        }

        QString newText = includeItem.isDirectory ? (includeItem.name + QLatin1Char('/')) : includeItem.name;

        if (properties.inputFrom == -1) {
            newText.prepend(QLatin1Char('<'));
        } else {
            range.setStart({lineNumber, properties.inputFrom});
        }
        if (properties.inputTo == -1) {
            // Add suffix
            if (properties.local) {
                newText += QLatin1Char('"');
            } else {
                newText += QLatin1Char('>');
            }

            // replace the whole line
            range.setEnd({lineNumber, line.size()});
        } else {
            range.setEnd({lineNumber, properties.inputTo});
        }

        document->replaceText(range, newText);

        if (includeItem.isDirectory) {
            // ensure we can continue to add files/paths when we just added a directory
            int offset = (properties.inputTo == -1) ? 1 : 0;
            view->setCursorPosition(range.start() + KTextEditor::Cursor(0, newText.length() - offset));
        } else {
            // place cursor at end of line
            view->setCursorPosition({lineNumber, document->lineLength(lineNumber)});
        }
    }
开发者ID:alstef,项目名称:kdevelop,代码行数:43,代码来源:includepathcompletioncontext.cpp


示例20: sizeHint

QSize GrepOutputDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    const GrepOutputModel *model = dynamic_cast<const GrepOutputModel *>(index.model());
    const GrepOutputItem  *item  = model ? dynamic_cast<const GrepOutputItem *>(model->itemFromIndex(index)) : nullptr;

    QSize ret = QStyledItemDelegate::sizeHint(option, index);

    //take account of additional width required for highlighting (bold text)
    //and line numbers. These are not included in the default Qt size calculation.
    if(item && item->isText())
    {
        QFont font = option.font;
        QFontMetrics metrics(font);
        font.setBold(true);
        QFontMetrics bMetrics(font);

        const KTextEditor::Range rng = item->change()->m_range;

        int width = metrics.width(item->text().left(rng.start().column())) +
                    metrics.width(item->text().right(item->text().length() - rng.end().column())) +
                    bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) +
                    option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) +
                    std::max(option.decorationSize.width(), 0);
        ret.setWidth(width);
    }else{
        // This is only used for titles, so not very performance critical
        QString text;
        if(item)
            text = item->text();
        else
            text = index.data().toString();
        
        QTextDocument doc;
        doc.setDocumentMargin(0);
        doc.setHtml(text);
        QSize newSize = doc.size().toSize();
        if(newSize.height() > ret.height())
            ret.setHeight(newSize.height());
    }
    return ret;
}
开发者ID:KDE,项目名称:kdevplatform,代码行数:41,代码来源:grepoutputdelegate.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ktexteditor::View类代码示例发布时间:2022-05-31
下一篇:
C++ ktexteditor::MarkInterface类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap