~ubuntu-branches/ubuntu/jaunty/kde4libs/jaunty-updates

« back to all changes in this revision

Viewing changes to kate/tests/codecompletiontestmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-12-11 18:26:08 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20081211182608-tsu6p8ncbw1gnqxt
Tags: 4:4.1.85-0ubuntu1
* New upstream release
* Patches:
  + Removed 15_kfreebsd_support.diff from patches/series (doesn't apply and
    has no use for Ubuntu)
  + Redid 20_use_dejavu_as_default_font.diff
  + Completely removed kubuntu_09_fix_application_menu.diff (applied upstream)
  + Refreshed kubuntu_54_use_xdg_menu_prefix.diff
  + Dropped plasma/widgets/toolbutton.cpp from kubuntu_qt_ftbfs.diff (applied
    upstream)
  + Global quilt refresh

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2005 Hamish Rodda <rodda@kde.org>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
#include "codecompletiontestmodel.h"
 
20
 
 
21
#include <ktexteditor/view.h>
 
22
#include <ktexteditor/document.h>
 
23
#include <ktexteditor/codecompletioninterface.h>
 
24
#include <ktexteditor/smartrange.h>
 
25
 
 
26
CodeCompletionTestModel::CodeCompletionTestModel(KTextEditor::View* parent, const QString &startText)
 
27
  : KTextEditor::CodeCompletionModel(parent), m_startText(startText), m_autoStartText(m_startText.isEmpty())
 
28
{
 
29
  setRowCount(40);
 
30
 
 
31
  Q_ASSERT(cc());
 
32
 
 
33
  cc()->setAutomaticInvocationEnabled(true);
 
34
  cc()->registerCompletionModel(this);
 
35
}
 
36
 
 
37
// Fake a series of completions
 
38
QVariant CodeCompletionTestModel::data( const QModelIndex & index, int role ) const
 
39
{
 
40
  switch (role) {
 
41
    case Qt::DisplayRole:
 
42
      if (index.row() < rowCount() / 2)
 
43
      switch (index.column()) {
 
44
        case Prefix:
 
45
          switch (index.row() % 3) {
 
46
            default:
 
47
              return "void ";
 
48
            case 1:
 
49
              return "const QString& ";
 
50
            case 2:
 
51
              if (index.row() % 6)
 
52
                return "inline virtual bool ";
 
53
              return "virtual bool ";
 
54
          }
 
55
 
 
56
        case Scope:
 
57
          switch (index.row() % 4) {
 
58
            default:
 
59
              return QString();
 
60
            case 1:
 
61
              return "KTextEditor::";
 
62
            case 2:
 
63
              return "::";
 
64
            case 3:
 
65
              return "std::";
 
66
          }
 
67
 
 
68
        case Name:
 
69
          return m_startText + QString("%1%2%3").arg(QChar('a' + (index.row() % 3))).arg(QChar('a' + index.row())).arg(index.row());
 
70
 
 
71
        case Arguments:
 
72
          switch (index.row() % 5) {
 
73
            default:
 
74
              return "()";
 
75
            case 1:
 
76
              return "(bool trigger)";
 
77
            case 4:
 
78
              return "(const QString& name, Qt::CaseSensitivity cs)";
 
79
            case 5:
 
80
              return "(int count)";
 
81
          }
 
82
 
 
83
        case Postfix:
 
84
          switch (index.row() % 3) {
 
85
            default:
 
86
              return " const";
 
87
            case 1:
 
88
              return " KDE_DEPRECATED";
 
89
            case 2:
 
90
              return "";
 
91
          }
 
92
      }
 
93
      else
 
94
      switch (index.column()) {
 
95
        case Prefix:
 
96
          switch (index.row() % 3) {
 
97
            default:
 
98
              return "void ";
 
99
            case 1:
 
100
              return "const QString ";
 
101
            case 2:
 
102
              return "bool ";
 
103
          }
 
104
 
 
105
        case Scope:
 
106
          switch (index.row() % 4) {
 
107
            default:
 
108
              return QString();
 
109
            case 1:
 
110
              return "KTextEditor::";
 
111
            case 2:
 
112
              return "::";
 
113
            case 3:
 
114
              return "std::";
 
115
          }
 
116
 
 
117
        case Name:
 
118
          return m_startText + QString("%1%2%3").arg(QChar('a' + (index.row() % 3))).arg(QChar('a' + index.row())).arg(index.row());
 
119
 
 
120
        default:
 
121
          return "";
 
122
      }
 
123
        break;
 
124
 
 
125
    case Qt::DecorationRole:
 
126
      break;
 
127
 
 
128
    case CompletionRole: {
 
129
      CompletionProperties p;
 
130
      if (index.row() < rowCount() / 2)
 
131
        p |= Function;
 
132
      else
 
133
        p |= Variable;
 
134
      switch (index.row() % 3) {
 
135
        case 0:
 
136
          p |= Const | Public;
 
137
          break;
 
138
        case 1:
 
139
          p |= Protected;
 
140
          break;
 
141
        case 2:
 
142
          p |= Private;
 
143
          break;
 
144
      }
 
145
      return (int)p;
 
146
    }
 
147
 
 
148
    case ScopeIndex:
 
149
      return (index.row() % 4 ) - 1;  
 
150
  }
 
151
 
 
152
  return QVariant();
 
153
}
 
154
 
 
155
KTextEditor::View* CodeCompletionTestModel::view( ) const
 
156
{
 
157
  return static_cast<KTextEditor::View*>(const_cast<QObject*>(QObject::parent()));
 
158
}
 
159
 
 
160
KTextEditor::CodeCompletionInterface * CodeCompletionTestModel::cc( ) const
 
161
{
 
162
  return dynamic_cast<KTextEditor::CodeCompletionInterface*>(const_cast<QObject*>(QObject::parent()));
 
163
}
 
164
 
 
165
void CodeCompletionTestModel::completionInvoked(KTextEditor::View* view, const KTextEditor::Range& range, InvocationType invocationType)
 
166
{
 
167
  Q_UNUSED(invocationType)
 
168
 
 
169
  if (m_autoStartText) {
 
170
    m_startText = view->document()->text(KTextEditor::Range(range.start(), view->cursorPosition()));
 
171
  }
 
172
  kDebug() << m_startText;
 
173
}
 
174
 
 
175
 
 
176
#include "codecompletiontestmodel.moc"