本文整理汇总了C++中ktexteditor::Range类的典型用法代码示例。如果您正苦于以下问题:C++ Range类的具体用法?C++ Range怎么用?C++ Range使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Range类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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));
}
}
示例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);
}
示例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 + ' ');
}
}
示例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;
}
示例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.";
}
示例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);
}
}
示例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());
}
示例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 ();
}