Kate
katecompletionmodel.cpp
Go to the documentation of this file.
113 QVariant HierarchicalModelHandler::getData(CodeCompletionModel::ExtraItemDataRoles role, const QModelIndex& index) const {
121 HierarchicalModelHandler::HierarchicalModelHandler(CodeCompletionModel* model) : m_groupSortingKey(-1), m_model(model) {
124 void HierarchicalModelHandler::addValue(CodeCompletionModel::ExtraItemDataRoles role, const QVariant& value) {
188 if( role == Qt::DecorationRole && index.column() == KTextEditor::CodeCompletionModel::Prefix && isExpandable(index) )
198 //groupOfParent returns a group when the index is a member of that group, but not the group head/label.
216 } else if ((!isColumnMergingEnabled() || m_columnMerges.isEmpty()) && index.column() == CodeCompletionModel::Scope) {
228 QModelIndex sourceIndex = mapToSource(createIndex(index.row(), column, index.internalPointer()));
237 //Return that we are doing custom-highlighting of one of the sub-strings does it. Unfortunately internal highlighting does not work for the other substrings.
239 QModelIndex sourceIndex = mapToSource(createIndex(index.row(), column, index.internalPointer()));
241 if( method.type() == QVariant::Int && method.toInt() == CodeCompletionModel::CustomHighlighting)
253 strings << mapToSource(createIndex(index.row(), column, index.internalPointer())).data(Qt::DisplayRole).toString();
259 highlights << mapToSource(createIndex(index.row(), column, index.internalPointer())).data(CodeCompletionModel::CustomHighlight).toList();
277 //We return the group-header for all columns, ExpandingDelegate will paint them properly over the whole space
324 continue; //Only match completion-items to argument-hints of depth 1(the ones the item will be given to as argument)
375 return isColumnMergingEnabled() && !m_columnMerges.isEmpty() ? m_columnMerges.count() : KTextEditor::CodeCompletionModel::ColumnCount;
380 return qMakePair(static_cast<CodeCompletionModel*>(const_cast<QAbstractItemModel*>(index.model())), index);
422 //kWarning() << "Invalid index requested: row " << row << " beyond indivdual range in group " << g;
439 /*QModelIndex KateCompletionModel::sibling( int row, int column, const QModelIndex & index ) const
541 QSet<KateCompletionModel::Group*> KateCompletionModel::createItems(const HierarchicalModelHandler& _handler, const QModelIndex& i, bool notifyModel) {
565 g->removeItem(ModelRow(const_cast<CodeCompletionModel*>(static_cast<const CodeCompletionModel*>(i.model())), i));
578 //After clearing the model, it has to be reset, else we will be in an invalid state while inserting
604 KateCompletionModel::Group* KateCompletionModel::createItem(const HierarchicalModelHandler& handler, const QModelIndex& sourceIndex, bool notifyModel)
608 int completionFlags = handler.getData(CodeCompletionModel::CompletionRole, sourceIndex).toInt();
611 QString scopeIfNeeded = (groupingMethod() & Scope) ? sourceIndex.sibling(sourceIndex.row(), CodeCompletionModel::Scope).data(Qt::DisplayRole).toString() : QString();
613 int argumentHintDepth = handler.getData(CodeCompletionModel::ArgumentHintDepth, sourceIndex).toInt();
655 affectedGroups += createItems(handler, parent.isValid() ? parent.child(i, 0) : handler.model()->index(i, 0), true);
677 KateCompletionModel::Group* KateCompletionModel::fetchGroup( int attribute, const QString& scope, bool forceGrouping )
690 for (QHash<int, Group*>::ConstIterator it = m_groupHash.constFind(groupingAttribute); it != m_groupHash.constEnd() && it.key() == groupingAttribute; ++it)
780 // Proper solution: Ask all attached code-models(Through a new interface) whether they want to use grouping,
785 KateCompletionModel::Group* KateCompletionModel::groupForIndex( const QModelIndex & index ) const
845 //kDebug( 13035 ) << "Returning ungrouped row count for toplevel " << m_ungrouped->filtered.count();
889 return index(m_ungrouped->rowOf(modelRowPair(sourceIndex)), sourceIndex.column(), QModelIndex());
907 void KateCompletionModel::setCurrentCompletion( KTextEditor::CodeCompletionModel* model, const QString & completion )
919 if (m_currentMatch[model].length() > completion.length() && m_currentMatch[model].startsWith(completion, m_matchCaseSensitivity)) {
923 } else if (m_currentMatch[model].length() < completion.length() && completion.startsWith(m_currentMatch[model], m_matchCaseSensitivity)) {
928 //kDebug( 13035 ) << model << "Old match: " << m_currentMatch[model] << ", new: " << completion << ", type: " << changeType;
1021 void KateCompletionModel::changeCompletions( Group * g, changeTypes changeType, bool notifyModel )
1029 //This code determines what of the filtered items still fit, and computes the ranges that were removed, giving
1033 int deleteUntil = -1; //In each state, the range [currentRow+1, deleteUntil] needs to be deleted
1036 //This row does not need to be deleted, which means that currentRow+1 to deleteUntil need to be deleted now
1094 m_updateBestMatchesTimer->start(200); //We have new argument-hints, so we have new best matches
1293 kWarning() << "Invalid completion model metadata: more than one scope type modifier provided.";
1305 kWarning() << "Invalid completion model metadata: more than one access type modifier provided.";
1432 KateCompletionModel::Item::Item( bool doInitialMatch, KateCompletionModel* m, const HierarchicalModelHandler& handler, ModelRow sr )
1440 inheritanceDepth = handler.getData(CodeCompletionModel::InheritanceDepth, m_sourceRow.second).toInt();
1455 //kDebug( 13035 ) << c1 << " c/w " << c2 << " -> " << (model->isSortingReverse() ? ret > 0 : ret < 0) << " (" << ret << ")";
1458 const bool otherIsBad = rhs.m_sourceRow.second.data(CodeCompletionModel::UnimportantItemRole).toBool();
1634 KTextEditor::CodeCompletionModel::CompletionProperties KateCompletionModel::filterAttributes( ) const
1639 void KateCompletionModel::setFilterAttributes( KTextEditor::CodeCompletionModel::CompletionProperties attributes )
1692 QModelIndex sourceIndex = m_sourceRow.second.sibling(m_sourceRow.second.row(), CodeCompletionModel::Name);
1738 KTextEditor::CodeCompletionModelControllerInterface3* iface3 = dynamic_cast<KTextEditor::CodeCompletionModelControllerInterface3*>(item.sourceRow().first);
1741 if(iface3 && iface3->matchingItem(item.sourceRow().second) == KTextEditor::CodeCompletionModelControllerInterface3::HideListIfAutomaticInvocation)
1762 static inline bool matchesAbbreviationHelper(const QString& word, const QString& typed, const QVarLengthArray<int, 32>& offsets,
1784 if ( haveNextWord && matchesAbbreviationHelper(word, typed, offsets, depth, atWord + 1, i + 1) ) {
1845 static inline bool containsAtWordBeginning(const QString& word, const QString& typed, Qt::CaseSensitivity caseSensitive) {
1865 QModelIndex sourceIndex = m_sourceRow.second.sibling(m_sourceRow.second.row(), CodeCompletionModel::Name);
1877 matchCompletion = (m_nameColumn.startsWith(match, model->matchCaseSensitivity()) ? StartsWithMatch : NoMatch);
1904 QString KateCompletionModel::propertyName( KTextEditor::CodeCompletionModel::CompletionProperty property )
1998 QString KateCompletionModel::currentCompletion( KTextEditor::CodeCompletionModel* model ) const
2015 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotRowsInserted(QModelIndex,int,int)));
2016 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(slotRowsRemoved(QModelIndex,int,int)));
2029 void KateCompletionModel::setCompletionModels(const QList<KTextEditor::CodeCompletionModel*>& models)
2039 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotRowsInserted(QModelIndex,int,int)));
2040 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(slotRowsRemoved(QModelIndex,int,int)));
2077 FilterItems(KateCompletionModel& model, const QVector<KTextEditor::CodeCompletionModel*>& needShadowing) : m_model(model), m_needShadowing(needShadowing) {
2090 if(it != had.constEnd() && *it != item.sourceRow().first && m_needShadowing.contains(item.sourceRow().first))
2123 KTextEditor::CodeCompletionModelControllerInterface4* v4 = dynamic_cast<KTextEditor::CodeCompletionModelControllerInterface4*>(model);
2142 int maxMatches = 300; //We cannot do too many operations here, because they are all executed whenever a character is added. Would be nice if we could split the operations up somewhat using a timer.
2145 //Maps match-qualities to ModelRows paired together with the BestMatchesCount returned by the items.
2150 //If there is no grouping, just change the order of the items, moving the best matching ones to the front
2175 for(QMultiMap<int, int>::const_iterator it = rowsForQuality.constBegin(); it != rowsForQuality.constEnd(); ++it) {
2240 m_bestMatches->filtered.append( Item( true, this, HierarchicalModelHandler((*it).second.first), (*it).second) );
bool operator<(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:78
void clearCompletionModels()
Definition: katecompletionmodel.cpp:2259
bool canConvert(Type t) const
virtual bool indexIsItem(const QModelIndex &index) const
Should return true if the given row should be painted like a contained item(as opposed to label-rows ...
Definition: katecompletionmodel.cpp:1144
void setMaximumInheritanceDepth(int maxDepth)
Definition: katecompletionmodel.cpp:1652
bool filterContextMatchesOnly() const
Definition: katecompletionmodel.cpp:1608
void setFilterAttributes(KTextEditor::CodeCompletionModel::CompletionProperties attributes)
Definition: katecompletionmodel.cpp:1639
void clear()
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Does not request data from index, this only returns local data like highlighting for expanded rows an...
Definition: katecompletionmodel.cpp:183
const T & at(int i) const
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
int customSortingKey
Definition: katecompletionmodel.h:306
virtual int rowCount(const QModelIndex &parent) const =0
QList< KTextEditor::CodeCompletionModel * > completionModels() const
Definition: katecompletionmodel.cpp:2048
void setFilterContextMatchesOnly(bool filter)
Definition: katecompletionmodel.cpp:1613
QString & append(QChar ch)
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
KateCompletionModel(KateCompletionWidget *parent=0L)
Definition: katecompletionmodel.cpp:128
bool accessIncludeConst() const
Definition: katecompletionmodel.cpp:1355
void setCompletionModels(const QList< KTextEditor::CodeCompletionModel * > &models)
Definition: katecompletionmodel.cpp:2029
virtual void rowSelected(const QModelIndex &row)
Notifies underlying models that the item was selected, collapses any previous partially expanded line...
Definition: expandingwidgetmodel.cpp:157
Qt::CaseSensitivity matchCaseSensitivity() const
Definition: katecompletionmodel.cpp:2003
static bool containsAtWordBeginning(const QString &word, const QString &typed, Qt::CaseSensitivity caseSensitive)
Definition: katecompletionmodel.cpp:1845
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
void clearExpanding()
Unexpand all rows and clear all cached information about them(this includes deleting the expanding-wi...
Definition: expandingwidgetmodel.cpp:123
virtual int contextMatchQuality(const QModelIndex &index) const
Definition: katecompletionmodel.cpp:299
void layoutChanged()
bool accessIncludeSignalSlot() const
Definition: katecompletionmodel.cpp:1385
void push_back(const T &value)
void append(const T &t)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Maps from this display-model into the appropriate source code-completion model.
Definition: katecompletionmodel.cpp:866
QList< QVariant > toList() const
QObject * sender() const
QList< QVariant > mergeCustomHighlighting(int leftSize, const QList< QVariant > &left, int rightSize, const QList< QVariant > &right)
Definition: expandingwidgetmodel.cpp:449
const_iterator constBegin() const
void setFilteringEnabled(bool enable)
Definition: katecompletionmodel.cpp:1178
int size() const
void setColumnMerges(const QList< QList< int > > &columnMerges)
Definition: katecompletionmodel.cpp:1251
void setSortingCaseSensitivity(Qt::CaseSensitivity cs)
Definition: katecompletionmodel.cpp:1574
uint filteredItemCount() const
Definition: katecompletionmodel.cpp:1719
void setGroupingEnabled(bool enable)
Definition: katecompletionmodel.cpp:1194
static QIcon m_collapsedIcon
Definition: expandingwidgetmodel.h:136
This class has the responsibility for filtering, sorting, and manipulating code completion data provi...
Definition: katecompletionmodel.h:48
QString currentCompletion(KTextEditor::CodeCompletionModel *model) const
Definition: katecompletionmodel.cpp:1998
void modelReset()
const_iterator insert(const T &value)
bool accessIncludeStatic() const
Definition: katecompletionmodel.cpp:1370
GroupingMethods groupingMethod() const
Definition: katecompletionmodel.cpp:1410
void clear()
static const int AccessTypeMask
Definition: katecompletionmodel.h:153
static QString propertyName(KTextEditor::CodeCompletionModel::CompletionProperty property)
Definition: katecompletionmodel.cpp:1904
void setCurrentCompletion(KTextEditor::CodeCompletionModel *model, const QString &completion)
Definition: katecompletionmodel.cpp:907
static QString columnName(int column)
Definition: katecompletionmodel.cpp:1226
bool isExpandable(const QModelIndex &index) const
Definition: expandingwidgetmodel.cpp:290
void setAccessIncludeStatic(bool include)
Definition: katecompletionmodel.cpp:1375
int size() const
bool isFilteringEnabled() const
Definition: katecompletionmodel.cpp:1216
bool isNull() const
void removeCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionmodel.cpp:2053
virtual bool hasIndex(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:463
void setBold(bool enable)
void beginResetModel()
void addItem(Item i, bool notifyModel=false)
Definition: katecompletionmodel.cpp:1497
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, QFlags< Qt::MatchFlag > flags) const
KateCompletionWidget * completionWidget() const
Definition: kateview.cpp:2346
bool isValid() const
int count(const T &value) const
void append(const T &value)
This is the code completion's main widget, and also contains the core interface logic.
Definition: katecompletionwidget.h:55
QString & insert(int position, QChar ch)
QVariant property(const char *name) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Does not request data from index, this only returns local data like highlighting for expanded rows an...
Definition: expandingwidgetmodel.cpp:88
void argumentHintsChanged()
int toInt(bool *ok) const
const QList< QList< int > > & columnMerges() const
Definition: katecompletionmodel.cpp:1246
void endInsertRows()
void setMatchCaseSensitivity(Qt::CaseSensitivity cs)
Definition: katecompletionmodel.cpp:368
virtual int rowCount(const QModelIndex &parent) const
Definition: kateargumenthintmodel.cpp:226
virtual void rowSelected(const QModelIndex &row)
Notifies underlying models that the item was selected, collapses any previous partially expanded line...
Definition: katecompletionmodel.cpp:2246
bool isSortingEnabled() const
Definition: katecompletionmodel.cpp:1221
int rowOf(ModelRow item)
Returns the row in the this group's filtered list of the given model-row in a source-model -1 if the ...
Definition: katecompletionmodel.h:292
bool isEmpty() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:838
bool isEmpty() const
int removeAll(const T &value)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:373
const_iterator constEnd() const
bool isUpper() const
void beginRemoveRows(const QModelIndex &parent, int first, int last)
int row() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionmodel.cpp:2023
void * internalPointer() const
virtual void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Definition: katecompletionmodel.cpp:860
QMap< Key, T >::iterator insert(const Key &key, const T &value)
KateCompletionWidget * widget() const
Definition: katecompletionmodel.cpp:359
void setSortingAlphabetical(bool alphabetical)
Definition: katecompletionmodel.cpp:1558
int maximumInheritanceDepth() const
Definition: katecompletionmodel.cpp:1647
bool isSortingByInheritanceDepth() const
Definition: katecompletionmodel.cpp:1415
static bool matchesAbbreviationHelper(const QString &word, const QString &typed, const QVarLengthArray< int, 32 > &offsets, int &depth, int atWord=-1, int i=0)
Definition: katecompletionmodel.cpp:1762
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: katecompletionmodel.cpp:348
QModelIndex parent() const
void rowsRemoved(const QModelIndex &parent, int start, int end)
bool isExpanded(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:305
void setColumnMergingEnabled(bool enable)
Definition: katecompletionmodel.cpp:1200
Definition: kateview.h:77
QModelIndex createIndex(int row, int column, void *ptr) const
Extension of CodeCompletionModelControllerInterface3.
Definition: codecompletionmodelcontrollerinterfacev4.h:32
void setAccessIncludeConst(bool include)
Definition: katecompletionmodel.cpp:1360
iterator end()
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:407
bool startsWith(const QString &str, Qt::CaseSensitivity cs) const
bool contains(const T &value) const
QStringRef midRef(int position, int n) const
void stop()
QChar toLower() const
void setAccessIncludeSignalSlot(bool include)
Definition: katecompletionmodel.cpp:1390
int translateColumn(int sourceColumn) const
Definition: katecompletionmodel.cpp:1258
bool contains(const T &value) const
void emitDataChanged(const QModelIndex &start, const QModelIndex &end)
Definition: kateargumenthintmodel.cpp:249
static const int ScopeTypeMask
Definition: katecompletionmodel.h:152
QModelIndex child(int row, int column) const
void beginInsertRows(const QModelIndex &parent, int first, int last)
void addCompletionModel(KTextEditor::CodeCompletionModel *model)
Definition: katecompletionmodel.cpp:2008
KateArgumentHintModel * argumentHintModel() const
Definition: katecompletionwidget.cpp:248
bool isColumnMergingEnabled() const
Definition: katecompletionmodel.cpp:1206
bool isGroupingEnabled() const
Definition: katecompletionmodel.cpp:1211
void setFilterByAttribute(bool filter)
Definition: katecompletionmodel.cpp:1626
const QAbstractItemModel * model() const
QString mid(int position, int n) const
bool shouldMatchHideCompletionList() const
Returns whether one of the filtered items exactly matches its completion string.
Definition: katecompletionmodel.cpp:1728
QVariant data(int role) const
void setSortingEnabled(bool enable)
Definition: katecompletionmodel.cpp:1184
bool removeItem(const ModelRow &row)
Removes the item specified by row. Returns true if a change was made to rows.
Definition: katecompletionmodel.cpp:1529
void insert(int i, const T &value)
bool isEmpty() const
QModelIndex sibling(int row, int column) const
void setGroupingMethod(GroupingMethods m)
Definition: katecompletionmodel.cpp:1348
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Definition: katecompletionmodel.cpp:383
const QChar at(int position) const
int column() const
int length() const
QString left(int n) const
Qt::CaseSensitivity sortingCaseSensitivity() const
Definition: katecompletionmodel.cpp:1427
void push_back(const T &value)
~KateCompletionModel()
Definition: katecompletionmodel.cpp:172
void start(int msec)
bool isValid() const
void prepend(const T &value)
bool isEmpty() const
bool isSortingAlphabetical() const
Definition: katecompletionmodel.cpp:1422
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
void endRemoveRows()
Type type() const
void rowsInserted(const QModelIndex &parent, int start, int end)
void endResetModel()
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool orderBefore(Group *other) const
Definition: katecompletionmodel.cpp:1086
QObject * parent() const
KateCompletionTree * treeView() const
Definition: katecompletionwidget.cpp:923
KTextEditor::CodeCompletionModel::CompletionProperties filterAttributes() const
Definition: katecompletionmodel.cpp:1634
int compare(const QString &other) const
static QIcon m_expandedIcon
Definition: expandingwidgetmodel.h:135
QString toString() const
int size() const
void setSortingByInheritanceDepth(bool byIneritance)
Definition: katecompletionmodel.cpp:1418
bool filterByAttribute() const
Definition: katecompletionmodel.cpp:1621
iterator begin()
virtual bool shouldHideItemsWithEqualNames() const
When multiple completion models are used at the same time, it may happen that multiple models add ite...
Definition: codecompletionmodelcontrollerinterfacev4.cpp:25
const T value(const Key &key) const
int remove(const Key &key)
void setSingleShot(bool singleShot)
Group(KateCompletionModel *model)
Definition: katecompletionmodel.cpp:1550
int orderNumber() const
Definition: katecompletionmodel.cpp:1059
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
typedef ItemFlags
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.