1
/* This file is part of the KDE project
2
Copyright (C) 2005 Hamish Rodda <rodda@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#include "codecompletiontestmodel.h"
21
#include <ktexteditor/view.h>
22
#include <ktexteditor/document.h>
23
#include <ktexteditor/codecompletioninterface.h>
24
#include <ktexteditor/smartrange.h>
26
CodeCompletionTestModel::CodeCompletionTestModel(KTextEditor::View* parent, const QString &startText)
27
: KTextEditor::CodeCompletionModel(parent), m_startText(startText), m_autoStartText(m_startText.isEmpty())
33
cc()->setAutomaticInvocationEnabled(true);
34
cc()->registerCompletionModel(this);
37
// Fake a series of completions
38
QVariant CodeCompletionTestModel::data( const QModelIndex & index, int role ) const
42
if (index.row() < rowCount() / 2)
43
switch (index.column()) {
45
switch (index.row() % 3) {
49
return "const QString& ";
52
return "inline virtual bool ";
53
return "virtual bool ";
57
switch (index.row() % 4) {
61
return "KTextEditor::";
69
return m_startText + QString("%1%2%3").arg(QChar('a' + (index.row() % 3))).arg(QChar('a' + index.row())).arg(index.row());
72
switch (index.row() % 5) {
76
return "(bool trigger)";
78
return "(const QString& name, Qt::CaseSensitivity cs)";
84
switch (index.row() % 3) {
88
return " KDE_DEPRECATED";
94
switch (index.column()) {
96
switch (index.row() % 3) {
100
return "const QString ";
106
switch (index.row() % 4) {
110
return "KTextEditor::";
118
return m_startText + QString("%1%2%3").arg(QChar('a' + (index.row() % 3))).arg(QChar('a' + index.row())).arg(index.row());
125
case Qt::DecorationRole:
128
case CompletionRole: {
129
CompletionProperties p;
130
if (index.row() < rowCount() / 2)
134
switch (index.row() % 3) {
149
return (index.row() % 4 ) - 1;
155
KTextEditor::View* CodeCompletionTestModel::view( ) const
157
return static_cast<KTextEditor::View*>(const_cast<QObject*>(QObject::parent()));
160
KTextEditor::CodeCompletionInterface * CodeCompletionTestModel::cc( ) const
162
return dynamic_cast<KTextEditor::CodeCompletionInterface*>(const_cast<QObject*>(QObject::parent()));
165
void CodeCompletionTestModel::completionInvoked(KTextEditor::View* view, const KTextEditor::Range& range, InvocationType invocationType)
167
Q_UNUSED(invocationType)
169
if (m_autoStartText) {
170
m_startText = view->document()->text(KTextEditor::Range(range.start(), view->cursorPosition()));
172
kDebug() << m_startText;
176
#include "codecompletiontestmodel.moc"