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)
333 QList<KTextEditor::CodeCompletionModel*> models = (modelsToStart.isEmpty() ? m_sourceModels : modelsToStart);
394 m_completionRanges[model] = view()->doc()->newMovingRange(range, KTextEditor::MovingRange::ExpandRight | KTextEditor::MovingRange::ExpandLeft);
396 //In automatic invocation mode, hide the completion widget as soon as the position where the completion was started is passed to the left
399 //In manual invocation mode, bound the activity either the point from where completion was invoked, or to the start of the range
405 kWarning(13035) << "Could not construct valid smart-range from" << range << "instead got" << *m_completionRanges[model].range;
418 //Now that all models have been notified, check whether the widget should be displayed instantly
428 KTextEditor::CodeCompletionModel* senderModel = qobject_cast<KTextEditor::CodeCompletionModel*>(sender());
469 if (m_presentationModel->rowCount() && (!m_presentationModel->shouldMatchHideCompletionList() ||
498 int x = p.x() - m_entryList->columnTextViewportPosition(m_presentationModel->translateColumn(KTextEditor::CodeCompletionModel::Name)) - 4 - (m_entryList->viewport()->pos().x());
538 //Checks whether the given model has at least "rows" rows, also searching the second level of the tree.
615 if(calculatedCustomHeight && calculatedCustomHeight > baseHeight && calculatedCustomHeight < (maxBaseHeight + model()->expandingWidgetsHeight()))
621 if( m_expandedAddedHeightBase != baseHeight && m_expandedAddedHeightBase - baseHeight > -2 && m_expandedAddedHeightBase - baseHeight < 2 )
624 //Reason: Qt seems to apply slightly wrong sizes when the completion-widget is moved out of the screen at the bottom,
625 // which completely breaks this algorithm. Solution: re-use the old base-size if it only slightly differs from the computed one.
678 for(QList<KTextEditor::CodeCompletionModel*>::iterator it = checkCompletionRanges.begin(); it != checkCompletionRanges.end(); ++it) {
695 QString currentCompletion = _filterString(model,view(), *m_completionRanges[model].range, view()->cursorPosition());
700 bool abort = _shouldAbortCompletion(model,view(), *m_completionRanges[model].range, currentCompletion);
706 //kDebug() << "aborting because of boundary: cursor:"<<view()->cursorPosition()<<"completion_Range_left_boundary:"<<m_completionRanges[*it].leftBoundary;
750 return !m_completionRanges.isEmpty() && ((!isHidden() && isVisible()) || (!m_argumentHintTree->isHidden() && m_argumentHintTree->isVisible()));
817 kWarning() << k_funcinfo << "Could not map index" << m_entryList->selectionModel()->currentIndex() << "to source index.";
826 QScopedPointer<KTextEditor::MovingCursor> oldPos (view()->doc()->newMovingCursor(view()->cursorPosition(), KTextEditor::MovingCursor::StayOnInsert));
828 KTextEditor::CodeCompletionModel* model = static_cast<KTextEditor::CodeCompletionModel*>(const_cast<QAbstractItemModel*>(toExecute.model()));
831 KTextEditor::CodeCompletionModel2* model2 = qobject_cast<KTextEditor::CodeCompletionModel2*>(model);
837 model2->executeCompletionItem2(view()->document(), *m_completionRanges[model].range, toExecute);
839 //The normale CodeCompletionInterface cannot handle feedback for hierarchical models, so just do the replacement
840 view()->document()->replaceText(*m_completionRanges[model].range, model->data(toExecute.sibling(toExecute.row(), KTextEditor::CodeCompletionModel::Name)).toString());
842 model->executeCompletionItem(view()->document(), *m_completionRanges[model].range, toExecute.row());
877 KTextEditor::MovingRange * KateCompletionWidget::completionRange(KTextEditor::CodeCompletionModel* model) const
895 QMap<KTextEditor::CodeCompletionModel*, KateCompletionWidget::CompletionRange> KateCompletionWidget::completionRanges( ) const
999 return model()->isExpandable( m_entryList->currentIndex() ) && !model()->isExpanded( m_entryList->currentIndex() );
1002 return argumentHintModel()->isExpandable( m_argumentHintTree->currentIndex() ) && !argumentHintModel()->isExpanded( m_argumentHintTree->currentIndex() );
1009 return model()->isExpandable( m_entryList->currentIndex() ) && model()->isExpanded( m_entryList->currentIndex() );
1012 return m_argumentHintModel->isExpandable( m_argumentHintTree->currentIndex() ) && m_argumentHintModel->isExpanded( m_argumentHintTree->currentIndex() );
1155 m_argumentHintTree->setCurrentIndex(m_argumentHintModel->index(m_argumentHintModel->rowCount(QModelIndex())-1, 0));
1162 if(model()->hasGroups()) //If we have groups we have to move on, because the first item is a label
1178 KTextEditor::CodeCompletionModel* model = qobject_cast<KTextEditor::CodeCompletionModel*>(sender());
1191 //kDebug() << "all completion-models we waited for are ready. Last one: " << model->objectName();
1193 //Use a queued connection once again to make sure that KateCompletionModel is notified before we are
1255 void KateCompletionWidget::insertText (const KTextEditor::Cursor &position, const QString &text)
1308 start=_shouldStartCompletion(model,view(), m_automaticInvocationLine, m_lastInsertionByUser, view()->cursorPosition());
1331 QString prefix = m_presentationModel->commonPrefix((m_inCompletionList && !shellLikeTabCompletion) ? m_entryList->currentIndex() : QModelIndex());
1346 for(CompletionRangeMap::iterator it = m_completionRanges.begin(); it != m_completionRanges.end(); ++it)
1352 while(view()->cursorPosition().column() > 0 && m_presentationModel->filteredItemCount() == itemCount) {
1353 KTextEditor::Range lastcharRange = KTextEditor::Range(view()->cursorPosition()-KTextEditor::Cursor(0,1), view()->cursorPosition());
void clearCompletionModels()
Definition: katecompletionmodel.cpp:2259
void moveBottom(int y)
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:1053
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:883
virtual int rowCount(const QModelIndex &parent) const =0
QList< KTextEditor::CodeCompletionModel * > completionModels() const
Definition: katecompletionmodel.cpp:2048
const QRect screenGeometry(int screen) const
Type type() const
bool isHidden() const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
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:4741
void setCompletionModels(const QList< KTextEditor::CodeCompletionModel * > &models)
Definition: katecompletionmodel.cpp:2029
void setScrollingEnabled(bool)
Definition: katecompletiontree.cpp:73
void sendCompletionExecuted(const KTextEditor::Cursor &position, KTextEditor::CodeCompletionModel *model, const QModelIndex &index)
Definition: kateview.cpp:2389
QCursor cursor() const
QString commonPrefix(QModelIndex selectedIndex) const
Returns a common prefix for all current visible completion entries If there is no common prefix...
Definition: katecompletionmodel.cpp:1000
QModelIndex partiallyExpandedRow() const
Returns the first row that is currently partially expanded.
Definition: expandingwidgetmodel.cpp:116
Definition: kateargumenthintmodel.h:30
void setCurrentIndex(const QModelIndex &index)
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Definition: kateargumenthintmodel.cpp:39
QModelIndex currentIndex() const
int right() const
QItemSelectionModel * selectionModel() const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual void showEvent(QShowEvent *event)
Definition: katecompletionwidget.cpp:867
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Maps from this display-model into the appropriate source code-completion model.
Definition: katecompletionmodel.cpp:866
void setFocusPolicy(Qt::FocusPolicy policy)
QObject * sender() const
void waitForModelReset()
Definition: katecompletionwidget.cpp:426
int y() const
bool isVisible() const
uint filteredItemCount() const
Definition: katecompletionmodel.cpp:1719
KateCompletionWidget(KateView *parent)
Definition: katecompletionwidget.cpp:97
void argumentHintsChanged(bool hasContent)
Definition: katecompletionwidget.cpp:276
QWidget * viewport() const
void automaticInvocation()
Definition: katecompletionwidget.cpp:1292
int height() const
void setAnimated(bool enable)
This class has the responsibility for filtering, sorting, and manipulating code completion data provi...
Definition: katecompletionmodel.h:48
bool hasFocus() const
void setVerticalScrollMode(ScrollMode mode)
void resetHadNavigation()
Definition: katecompletionwidget.cpp:971
const_iterator insert(const T &value)
void setFrameStyle(int style)
void setLineWidth(int)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void setCurrentCompletion(KTextEditor::CodeCompletionModel *model, const QString &completion)
Definition: katecompletionmodel.cpp:907
const KateCompletionModel * model() const
Definition: katecompletionwidget.cpp:252
bool isExpandable(const QModelIndex &index) const
Definition: expandingwidgetmodel.cpp:290
void setParent(QWidget *parent)
~KateCompletionWidget()
Definition: katecompletionwidget.cpp:181
static void _aborted(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view)
Definition: katecompletionwidget.cpp:89
void setCurrentItemExpanded(bool)
Definition: katecompletionwidget.cpp:1016
int x() const
int y() const
Definition: kateargumenthinttree.h:30
geometry
void setAutomaticInvocationDelay(int delay)
Definition: katecompletionwidget.cpp:1233
void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionwidget.cpp:1220
void clear()
void moveTo(int x, int y)
QMap< KTextEditor::CodeCompletionModel *, CompletionRange > completionRanges() const
Definition: katecompletionwidget.cpp:895
void removeCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionmodel.cpp:2053
int width() const
static bool _shouldStartCompletion(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, QString m_automaticInvocationLine, bool m_lastInsertionByUser, const KTextEditor::Cursor &cursor)
Definition: katecompletionwidget.cpp:93
void resize(int w, int h)
static KTextEditor::Range _completionRange(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, const KTextEditor::Cursor &cursor)
Definition: katecompletionwidget.cpp:73
bool isValid() const
bool toggleExpanded(bool forceExpand=false, bool forceUnExpand=false)
Returns whether the current item was expanded/unexpanded.
Definition: katecompletionwidget.cpp:983
QWidget * activeWindow()
void setColumnWidth(int column, int width)
virtual void showEvent(QShowEvent *event)
void append(const T &value)
KateArgumentHintTree * argumentHintTree() const
Definition: katecompletionwidget.cpp:244
void installEventFilter(QObject *filterObj)
int x() const
int top() const
virtual int rowCount(const QModelIndex &parent) const
Definition: kateargumenthintmodel.cpp:226
void setUpdatesEnabled(bool enable)
int left() const
QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const
Definition: kateview.cpp:2433
bool hasAtLeastNRows(int rows, QAbstractItemModel *model)
Definition: katecompletionwidget.cpp:539
QWidget * expandingWidget(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:431
bool isEmpty() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:838
void setWidth(int width)
bool isEmpty() const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:373
int removeAll(const T &value)
int row() const
bool previousCompletion()
Definition: kateargumenthinttree.cpp:218
void move(int x, int y)
void registerCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionwidget.cpp:1203
virtual bool eventFilter(QObject *watched, QEvent *event)
void hide()
QModelIndex parent() const
QSize sizeHintForIndex(const QModelIndex &index) const
QScrollBar * verticalScrollBar() const
bool isExpanded(const QModelIndex &index) const
bool updatePosition(bool force=false)
Definition: katecompletionwidget.cpp:482
bool canCollapseCurrentItem() const
Definition: katecompletionwidget.cpp:1006
bool isExpanded(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:305
Definition: kateview.h:77
const bool hideAutomaticCompletionOnExactMatch
Definition: katecompletionwidget.cpp:56
iterator end()
void updateHeight()
Called by KateViewInternal, because we need the specific information from the event.
Definition: katecompletionwidget.cpp:554
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:407
void userInvokedCompletion()
Definition: katecompletionwidget.cpp:1322
bool contains(const T &value) const
void stop()
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
int translateColumn(int sourceColumn) const
Definition: katecompletionmodel.cpp:1258
bool contains(const T &value) const
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:2008
KateArgumentHintModel * argumentHintModel() const
Definition: katecompletionwidget.cpp:248
bool isCompletionActive() const
Definition: katecompletionwidget.cpp:748
virtual void resizeEvent(QResizeEvent *event)
Definition: katecompletionwidget.cpp:862
const QAbstractItemModel * model() const
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
QFontMetrics fontMetrics() const
bool shouldMatchHideCompletionList() const
Returns whether one of the filtered items exactly matches its completion string.
Definition: katecompletionmodel.cpp:1728
bool remove(const T &value)
int frameWidth() const
QVariant data(int role) const
virtual int sizeHintForRow(int row) const
void updatePositionSlot()
Definition: katecompletionwidget.cpp:477
QDesktopWidget * desktop()
void sendPostedEvents()
QModelIndex sibling(int row, int column) const
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: katecompletionwidget.cpp:1027
void setHeight(int height)
virtual void setModel(QAbstractItemModel *model)
bool hadNavigation() const
Definition: katecompletionwidget.cpp:967
void startCompletion(KTextEditor::CodeCompletionModel::InvocationType invocationType, const QList< KTextEditor::CodeCompletionModel * > &models=QList< KTextEditor::CodeCompletionModel * >())
Definition: katecompletionwidget.cpp:286
KTextEditor::MovingRange * range
Definition: katecompletionwidget.h:103
static KTextEditor::Range _updateRange(KTextEditor::CodeCompletionModel *model, KTextEditor::View *view, KTextEditor::Range &range)
Definition: katecompletionwidget.cpp:77
int bottom() const
int length() const
virtual QString text(const KTextEditor::Range &range, bool blockwise=false) const
Definition: katedocument.cpp:337
bool isEmpty() const
QScrollBar * horizontalScrollBar() const
void start(int msec)
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
void show()
const QFontMetricsF & fontMetrics() const
Definition: kateconfig.cpp:2284
virtual void resizeEvent(QResizeEvent *event)
void expand(const QModelIndex &index)
QAbstractItemModel * model() const
void editStart()
Enclose editor actions with editStart() and editEnd() to group them.
Definition: katedocument.cpp:776
QModelIndex currentIndex() const
bool canExpandCurrentItem() const
Definition: katecompletionwidget.cpp:996
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Definition: katecompletiontree.h:32
QObject * parent() const
KateCompletionTree * treeView() const
Definition: katecompletionwidget.cpp:923
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
iterator begin()
int automaticInvocationDelay() const
Definition: katecompletionwidget.cpp:1229
int expandingWidgetsHeight() const
Returns the total height added through all open expanding-widgets.
Definition: expandingwidgetmodel.cpp:420
void destroyed(QObject *obj)
int height() const
qreal height() const
KTextEditor::MovingRange * completionRange(KTextEditor::CodeCompletionModel *model=0) const
Definition: katecompletionwidget.cpp:877
void setSingleShot(bool singleShot)
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-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.