Kate
katecompletionwidget.cpp
Go to the documentation of this file.
58 //If this is true, the completion-list is navigated up/down when 'tab' is pressed, instead of doing partial completion
73 static KTextEditor::Range _completionRange(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, const KTextEditor::Cursor& cursor){
77 static KTextEditor::Range _updateRange(KTextEditor::CodeCompletionModel *model,KTextEditor::View *view, KTextEditor::Range& range) {
81 static QString _filterString(KTextEditor::CodeCompletionModel *model,KTextEditor::View *view, const KTextEditor::Range& range, const KTextEditor::Cursor& cursor) {
85 static bool _shouldAbortCompletion(KTextEditor::CodeCompletionModel *model,KTextEditor::View *view, const KTextEditor::Range& range, const QString& currentCompletion) {
93 static bool _shouldStartCompletion(KTextEditor::CodeCompletionModel *model,KTextEditor::View *view, QString m_automaticInvocationLine,bool m_lastInsertionByUser, const KTextEditor::Cursor& cursor) {
94 CALLCI(return,,return,model,shouldStartCompletion(view, m_automaticInvocationLine, m_lastInsertionByUser, cursor));
131 m_entryList->setColumnWidth(0, 0); //These will be determined automatically in KateCompletionTree::resizeColumns
143 connect(m_entryList->verticalScrollBar(), SIGNAL(valueChanged(int)), m_presentationModel, SLOT(placeExpandingWidgets()));
144 connect(m_argumentHintTree->verticalScrollBar(), SIGNAL(valueChanged(int)), m_argumentHintModel, SLOT(placeExpandingWidgets()));
153 connect(m_presentationModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(rowsInserted(QModelIndex,int,int)));
154 connect(m_argumentHintModel, SIGNAL(contentStateChanged(bool)), this, SLOT(argumentHintsChanged(bool)));
157 connect(view(), SIGNAL(cursorPositionChanged(KTextEditor::View*,KTextEditor::Cursor)), this, SLOT(cursorPositionChanged()));
158 connect(view(), SIGNAL(verticalScrollPositionChanged(KTextEditor::View*,KTextEditor::Cursor)), this, SLOT(updatePositionSlot()));
163 connect(&view()->doc()->buffer(), SIGNAL(lineWrapped(KTextEditor::Cursor)), this, SLOT(wrapLine(KTextEditor::Cursor)));
165 connect(&view()->doc()->buffer(), SIGNAL(textInserted(KTextEditor::Cursor,QString)), this, SLOT(insertText(KTextEditor::Cursor,QString)));
166 connect(&view()->doc()->buffer(), SIGNAL(textRemoved(KTextEditor::Range,QString)), this, SLOT(removeText(KTextEditor::Range)));
170 //We need to do this, because else the focus goes to nirvana without any control when the completion-widget is clicked.
209 if( !m_isSuspended && ((isHidden() && m_argumentHintTree->isHidden()) || m_needShow) && realItemCount != 0 ) {
221 //With each filtering items can be added or removed, so we have to reset the current index here so we always have a selected item
232 if( m_argumentHintTree->isHidden() && !m_dontShowArgumentHints && m_argumentHintModel->rowCount(QModelIndex()) != 0 )
286 void KateCompletionWidget::startCompletion(KTextEditor::CodeCompletionModel::InvocationType invocationType, const QList<KTextEditor::CodeCompletionModel*>& models)
292 startCompletion(KTextEditor::Range(KTextEditor::Cursor(-1, -1), KTextEditor::Cursor(-1, -1)), models, invocationType);
303 void KateCompletionWidget::startCompletion(const KTextEditor::Range& word, KTextEditor::CodeCompletionModel* model, KTextEditor::CodeCompletionModel::InvocationType invocationType)
314 void KateCompletionWidget::startCompletion(const KTextEditor::Range& word, const QList<KTextEditor::CodeCompletionModel*>& modelsToStart, KTextEditor::CodeCompletionModel::InvocationType invocationType)
332 QList<KTextEditor::CodeCompletionModel*> models = (modelsToStart.isEmpty() ? m_sourceModels : modelsToStart);
393 m_completionRanges[model] = view()->doc()->newMovingRange(range, KTextEditor::MovingRange::ExpandRight | KTextEditor::MovingRange::ExpandLeft);
395 //In automatic invocation mode, hide the completion widget as soon as the position where the completion was started is passed to the left
398 //In manual invocation mode, bound the activity either the the point from where completion was invoked, or to the start of the range
404 kWarning(13035) << "Could not construct valid smart-range from" << range << "instead got" << *m_completionRanges[model].range;
416 //Now that all models have been notified, check whether the widget should be displayed instantly
426 KTextEditor::CodeCompletionModel* senderModel = qobject_cast<KTextEditor::CodeCompletionModel*>(sender());
467 if (m_presentationModel->rowCount() && (!m_presentationModel->shouldMatchHideCompletionList() ||
496 int x = p.x() - m_entryList->columnTextViewportPosition(m_presentationModel->translateColumn(KTextEditor::CodeCompletionModel::Name)) - 4 - (m_entryList->viewport()->pos().x());
536 //Checks whether the given model has at least "rows" rows, also searching the second level of the tree.
613 if(calculatedCustomHeight && calculatedCustomHeight > baseHeight && calculatedCustomHeight < (maxBaseHeight + model()->expandingWidgetsHeight()))
619 if( m_expandedAddedHeightBase != baseHeight && m_expandedAddedHeightBase - baseHeight > -2 && m_expandedAddedHeightBase - baseHeight < 2 )
622 //Reason: Qt seems to apply slightly wrong sizes when the completion-widget is moved out of the screen at the bottom,
623 // which completely breaks this algorithm. Solution: re-use the old base-size if it only slightly differs from the computed one.
676 for(QList<KTextEditor::CodeCompletionModel*>::iterator it = checkCompletionRanges.begin(); it != checkCompletionRanges.end(); ++it) {
693 QString currentCompletion = _filterString(model,view(), *m_completionRanges[model].range, view()->cursorPosition());
698 bool abort = _shouldAbortCompletion(model,view(), *m_completionRanges[model].range, currentCompletion);
704 //kDebug() << "aborting because of boundary: cursor:"<<view()->cursorPosition()<<"completion_Range_left_boundary:"<<m_completionRanges[*it].leftBoundary;
748 return !m_completionRanges.isEmpty() && ((!isHidden() && isVisible()) || (!m_argumentHintTree->isHidden() && m_argumentHintTree->isVisible()));
815 kWarning() << k_funcinfo << "Could not map index" << m_entryList->selectionModel()->currentIndex() << "to source index.";
824 QScopedPointer<KTextEditor::MovingCursor> oldPos (view()->doc()->newMovingCursor(view()->cursorPosition(), KTextEditor::MovingCursor::StayOnInsert));
826 KTextEditor::CodeCompletionModel* model = static_cast<KTextEditor::CodeCompletionModel*>(const_cast<QAbstractItemModel*>(toExecute.model()));
829 KTextEditor::CodeCompletionModel2* model2 = qobject_cast<KTextEditor::CodeCompletionModel2*>(model);
835 model2->executeCompletionItem2(view()->document(), *m_completionRanges[model].range, toExecute);
837 //The normale CodeCompletionInterface cannot handle feedback for hierarchical models, so just do the replacement
838 view()->document()->replaceText(*m_completionRanges[model].range, model->data(toExecute.sibling(toExecute.row(), KTextEditor::CodeCompletionModel::Name)).toString());
840 model->executeCompletionItem(view()->document(), *m_completionRanges[model].range, toExecute.row());
875 KTextEditor::MovingRange * KateCompletionWidget::completionRange(KTextEditor::CodeCompletionModel* model) const
893 QMap<KTextEditor::CodeCompletionModel*, KateCompletionWidget::CompletionRange> KateCompletionWidget::completionRanges( ) const
997 return model()->isExpandable( m_entryList->currentIndex() ) && !model()->isExpanded( m_entryList->currentIndex() );
1000 return argumentHintModel()->isExpandable( m_argumentHintTree->currentIndex() ) && !argumentHintModel()->isExpanded( m_argumentHintTree->currentIndex() );
1007 return model()->isExpandable( m_entryList->currentIndex() ) && model()->isExpanded( m_entryList->currentIndex() );
1010 return m_argumentHintModel->isExpandable( m_argumentHintTree->currentIndex() ) && m_argumentHintModel->isExpanded( m_argumentHintTree->currentIndex() );
1153 m_argumentHintTree->setCurrentIndex(m_argumentHintModel->index(m_argumentHintModel->rowCount(QModelIndex())-1, 0));
1160 if(model()->hasGroups()) //If we have groups we have to move on, because the first item is a label
1176 KTextEditor::CodeCompletionModel* model = qobject_cast<KTextEditor::CodeCompletionModel*>(sender());
1189 //kDebug() << "all completion-models we waited for are ready. Last one: " << model->objectName();
1191 //Use a queued connection once again to make sure that KateCompletionModel is notified before we are
1253 void KateCompletionWidget::insertText (const KTextEditor::Cursor &position, const QString &text)
1306 start=_shouldStartCompletion(model,view(), m_automaticInvocationLine, m_lastInsertionByUser, view()->cursorPosition());
1329 QString prefix = m_presentationModel->commonPrefix((m_inCompletionList && !shellLikeTabCompletion) ? m_entryList->currentIndex() : QModelIndex());
1344 for(CompletionRangeMap::iterator it = m_completionRanges.begin(); it != m_completionRanges.end(); ++it)
1350 while(view()->cursorPosition().column() > 0 && m_presentationModel->filteredItemCount() == itemCount) {
1351 KTextEditor::Range lastcharRange = KTextEditor::Range(view()->cursorPosition()-KTextEditor::Cursor(0,1), view()->cursorPosition());
void clearCompletionModels()
Definition: katecompletionmodel.cpp:2253
static bool _shouldAbortCompletion(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, const KTextEditor::Range &range, const QString ¤tCompletion)
Definition: katecompletionwidget.cpp:85
QWidget * currentEmbeddedWidget()
Definition: katecompletionwidget.cpp:1051
Cursor & start()
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Maps from an index in a source-model to the index of the item in this display-model.
Definition: katecompletionmodel.cpp:892
QList< KTextEditor::CodeCompletionModel * > completionModels() const
Definition: katecompletionmodel.cpp:2041
virtual KTextEditor::MovingRange * newMovingRange(const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty)
Create a new moving range for this document.
Definition: katedocument.cpp:4742
void setCompletionModels(const QList< KTextEditor::CodeCompletionModel * > &models)
Definition: katecompletionmodel.cpp:2022
void setScrollingEnabled(bool)
Definition: katecompletiontree.cpp:73
void sendCompletionExecuted(const KTextEditor::Cursor &position, KTextEditor::CodeCompletionModel *model, const QModelIndex &index)
Definition: kateview.cpp:2364
QString commonPrefix(QModelIndex selectedIndex) const
Returns a common prefix for all current visible completion entries If there is no common prefix...
Definition: katecompletionmodel.cpp:1006
QModelIndex partiallyExpandedRow() const
Returns the first row that is currently partially expanded.
Definition: expandingwidgetmodel.cpp:116
Definition: kateargumenthintmodel.h:30
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Definition: kateargumenthintmodel.cpp:39
virtual void showEvent(QShowEvent *event)
Definition: katecompletionwidget.cpp:865
virtual bool isValid() const
InvocationType
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Maps from this display-model into the appropriate source code-completion model.
Definition: katecompletionmodel.cpp:875
int timeout
void waitForModelReset()
Definition: katecompletionwidget.cpp:424
virtual void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, InvocationType invocationType)
uint filteredItemCount() const
Definition: katecompletionmodel.cpp:1712
KateCompletionWidget(KateView *parent)
Definition: katecompletionwidget.cpp:97
void argumentHintsChanged(bool hasContent)
Definition: katecompletionwidget.cpp:276
void automaticInvocation()
Definition: katecompletionwidget.cpp:1290
This class has the responsibility for filtering, sorting, and manipulating code completion data provi...
Definition: katecompletionmodel.h:48
void resetHadNavigation()
Definition: katecompletionwidget.cpp:969
virtual void executeCompletionItem2(Document *document, const Range &word, const QModelIndex &index) const
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void setCurrentCompletion(KTextEditor::CodeCompletionModel *model, const QString &completion)
Definition: katecompletionmodel.cpp:916
#define k_funcinfo
const KateCompletionModel * model() const
Definition: katecompletionwidget.cpp:252
bool isExpandable(const QModelIndex &index) const
Definition: expandingwidgetmodel.cpp:290
~KateCompletionWidget()
Definition: katecompletionwidget.cpp:181
static void _aborted(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view)
Definition: katecompletionwidget.cpp:89
void setCurrentItemExpanded(bool)
Definition: katecompletionwidget.cpp:1014
Definition: kateargumenthinttree.h:30
QString prefix()
KSharedConfigPtr config()
void setAutomaticInvocationDelay(int delay)
Definition: katecompletionwidget.cpp:1231
void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionwidget.cpp:1218
QMap< KTextEditor::CodeCompletionModel *, CompletionRange > completionRanges() const
Definition: katecompletionwidget.cpp:893
void removeCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionmodel.cpp:2046
static bool _shouldStartCompletion(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, QString m_automaticInvocationLine, bool m_lastInsertionByUser, const KTextEditor::Cursor &cursor)
Definition: katecompletionwidget.cpp:93
static KTextEditor::Range _completionRange(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, const KTextEditor::Cursor &cursor)
Definition: katecompletionwidget.cpp:73
bool toggleExpanded(bool forceExpand=false, bool forceUnExpand=false)
Returns whether the current item was expanded/unexpanded.
Definition: katecompletionwidget.cpp:981
KateArgumentHintTree * argumentHintTree() const
Definition: katecompletionwidget.cpp:244
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual bool removeText(const Range &range, bool block=false)=0
virtual int rowCount(const QModelIndex &parent) const
Definition: kateargumenthintmodel.cpp:226
QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const
Definition: kateview.cpp:2408
bool hasAtLeastNRows(int rows, QAbstractItemModel *model)
Definition: katecompletionwidget.cpp:537
QWidget * expandingWidget(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:431
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:847
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:373
bool previousCompletion()
Definition: kateargumenthinttree.cpp:218
void registerCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionwidget.cpp:1201
bool updatePosition(bool force=false)
Definition: katecompletionwidget.cpp:480
bool canCollapseCurrentItem() const
Definition: katecompletionwidget.cpp:1004
bool isExpanded(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:305
Definition: kateview.h:78
virtual QString text() const =0
CopyJob * move(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
const bool hideAutomaticCompletionOnExactMatch
Definition: katecompletionwidget.cpp:56
void updateHeight()
Called by KateViewInternal, because we need the specific information from the event.
Definition: katecompletionwidget.cpp:552
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:407
void userInvokedCompletion()
Definition: katecompletionwidget.cpp:1320
int translateColumn(int sourceColumn) const
Definition: katecompletionmodel.cpp:1263
void resizeColumns(bool firstShow=false, bool forceResize=false)
Definition: katecompletiontree.cpp:114
static QString _filterString(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, const KTextEditor::Range &range, const KTextEditor::Cursor &cursor)
Definition: katecompletionwidget.cpp:81
void addCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionmodel.cpp:2001
KateArgumentHintModel * argumentHintModel() const
Definition: katecompletionwidget.cpp:248
bool isCompletionActive() const
Definition: katecompletionwidget.cpp:746
virtual const MovingCursor & start() const =0
virtual bool insertText(const QString &text)
virtual void resizeEvent(QResizeEvent *event)
Definition: katecompletionwidget.cpp:860
void setExpanded(QModelIndex index, bool expanded)
Change the expand-state of the row given through index. The display will be updated.
Definition: expandingwidgetmodel.cpp:311
bool shouldMatchHideCompletionList() const
Returns whether one of the filtered items exactly matches its completion string.
Definition: katecompletionmodel.cpp:1721
void updatePositionSlot()
Definition: katecompletionwidget.cpp:475
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: katecompletionwidget.cpp:1025
bool hadNavigation() const
Definition: katecompletionwidget.cpp:965
void startCompletion(KTextEditor::CodeCompletionModel::InvocationType invocationType, const QList< KTextEditor::CodeCompletionModel * > &models=QList< KTextEditor::CodeCompletionModel * >())
Definition: katecompletionwidget.cpp:286
virtual void executeCompletionItem(Document *document, const Range &word, int row) const
KTextEditor::MovingRange * range
Definition: katecompletionwidget.h:103
static KTextEditor::Range _updateRange(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, KTextEditor::Range &range)
Definition: katecompletionwidget.cpp:77
virtual QString text(const KTextEditor::Range &range, bool blockwise=false) const
Definition: katedocument.cpp:337
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
int columnTextViewportPosition(int column) const
Returns the approximated viewport position of the text in the given column, skipping an eventual icon...
Definition: katecompletiontree.cpp:86
bool previousCompletion()
Definition: katecompletiontree.cpp:320
Definition: katecompletionconfig.h:36
const QFontMetricsF & fontMetrics() const
Definition: kateconfig.cpp:2135
void editStart()
Enclose editor actions with editStart() and editEnd() to group them.
Definition: katedocument.cpp:776
bool canExpandCurrentItem() const
Definition: katecompletionwidget.cpp:994
Definition: katecompletiontree.h:32
KateCompletionTree * treeView() const
Definition: katecompletionwidget.cpp:921
virtual void setColumn(int column)
int column() const
virtual bool replaceText(const Range &range, const QString &text, bool block=false)
int automaticInvocationDelay() const
Definition: katecompletionwidget.cpp:1227
int expandingWidgetsHeight() const
Returns the total height added through all open expanding-widgets.
Definition: expandingwidgetmodel.cpp:420
KTextEditor::MovingRange * completionRange(KTextEditor::CodeCompletionModel *model=0) const
Definition: katecompletionwidget.cpp:875
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.