KTextEditor

codecompletionmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "codecompletionmodel.h"
8
9#include "document.h"
10#include "view.h"
11
12using namespace KTextEditor;
13
14class KTextEditor::CodeCompletionModelPrivate
15{
16public:
17 CodeCompletionModelPrivate()
18 {
19 }
20
21 int rowCount = 0;
22 bool hasGroups = false;
23};
24
25CodeCompletionModel::CodeCompletionModel(QObject *parent)
26 : QAbstractItemModel(parent)
27 , d(new CodeCompletionModelPrivate)
28{
29}
30
31CodeCompletionModel::~CodeCompletionModel()
32{
33 delete d;
34}
35
37{
38 return ColumnCount;
39}
40
41QModelIndex CodeCompletionModel::index(int row, int column, const QModelIndex &parent) const
42{
43 if (row < 0 || row >= d->rowCount || column < 0 || column >= ColumnCount || parent.isValid()) {
44 return QModelIndex();
45 }
46
47 return createIndex(row, column, (void *)nullptr);
48}
49
51{
53
54 for (int i = CompletionRole; i <= AccessibilityAccept; ++i) {
55 QVariant v = data(index, i);
56 if (v.isValid()) {
57 ret.insert(i, v);
58 }
59 }
60
61 return ret;
62}
63
68
69void CodeCompletionModel::setRowCount(int rowCount)
70{
71 d->rowCount = rowCount;
72}
73
75{
76 if (parent.isValid()) {
77 return 0;
78 }
79
80 return d->rowCount;
81}
82
83void CodeCompletionModel::completionInvoked(KTextEditor::View *view, const Range &range, InvocationType invocationType)
84{
85 Q_UNUSED(view)
86 Q_UNUSED(range)
87 Q_UNUSED(invocationType)
88}
89
91{
92 view->document()->replaceText(word, data(index.sibling(index.row(), Name)).toString());
93}
94
96{
97 return d->hasGroups;
98}
99
100void CodeCompletionModel::setHasGroups(bool hasGroups)
101{
102 if (d->hasGroups != hasGroups) {
103 d->hasGroups = hasGroups;
105 }
106}
bool hasGroups() const
This function returns true if the model needs grouping, otherwise false.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Reimplemented from QAbstractItemModel::rowCount().
virtual void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, InvocationType invocationType)
This function is responsible to generating / updating the list of current completions.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Reimplemented from QAbstractItemModel::columnCount().
void hasGroupsChanged(KTextEditor::CodeCompletionModel *model, bool hasGroups)
Internal.
@ CompletionRole
The model should return a set of CompletionProperties.
@ AccessibilityAccept
AccessibilityAccept will be requested on an item if it is expanded, contains an expanding-widget,...
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Reimplemented from QAbstractItemModel::index().
QMap< int, QVariant > itemData(const QModelIndex &index) const override
Reimplemented from QAbstractItemModel::itemData().
virtual void executeCompletionItem(KTextEditor::View *view, const Range &word, const QModelIndex &index) const
This function is responsible for inserting a selected completion into the view.
virtual bool replaceText(Range range, const QString &text, bool block=false)
Replace text from range with specified text.
Definition document.cpp:85
An object representing a section of text, from one Cursor to another.
A text widget with KXMLGUIClient that represents a Document.
Definition view.h:244
virtual Document * document() const =0
Get the view's document, that means the view is a view of the returned document.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
QModelIndex createIndex(int row, int column, const void *ptr) const const
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual QMap< int, QVariant > itemData(const QModelIndex &index) const const
iterator insert(const Key &key, const T &value)
int row() const const
QModelIndex sibling(int row, int column) const const
Q_EMITQ_EMIT
QObject * parent() const const
bool isValid() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.