• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • interfaces
  • ktexteditor
codecompletionmodel.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005-2006 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 "codecompletionmodel.h"
20 
21 #include "document.h"
22 
23 using namespace KTextEditor;
24 
25 class KTextEditor::CodeCompletionModelPrivate
26 {
27 public:
28  CodeCompletionModelPrivate()
29  : rowCount(0),hasGroups(true)
30  {}
31 
32  int rowCount;
33  bool hasGroups;
34 };
35 
36 CodeCompletionModel::CodeCompletionModel(QObject* parent)
37  : QAbstractItemModel(parent)
38  , d(new CodeCompletionModelPrivate)
39 {
40 }
41 
42 CodeCompletionModel::~ CodeCompletionModel()
43 {
44  delete d;
45 }
46 
47 int CodeCompletionModel::columnCount( const QModelIndex & ) const
48 {
49  return ColumnCount;
50 }
51 
52 QModelIndex CodeCompletionModel::index( int row, int column, const QModelIndex & parent ) const
53 {
54  if (row < 0 || row >= d->rowCount || column < 0 || column >= ColumnCount || parent.isValid())
55  return QModelIndex();
56 
57  return createIndex(row, column, 0);
58 }
59 
60 QMap< int, QVariant > CodeCompletionModel::itemData( const QModelIndex & index ) const
61 {
62  QMap<int, QVariant> ret = QAbstractItemModel::itemData(index);
63 
64  for (int i = CompletionRole; i <= LastItemDataRole; ++i) {
65  QVariant v = data(index, i);
66  if (v.isValid())
67  ret.insert(i, v);
68  }
69 
70  return ret;
71 }
72 
73 QModelIndex CodeCompletionModel::parent( const QModelIndex & ) const
74 {
75  return QModelIndex();
76 }
77 
78 void CodeCompletionModel::setRowCount( int rowCount )
79 {
80  d->rowCount = rowCount;
81 }
82 
83 int CodeCompletionModel::rowCount( const QModelIndex & parent ) const
84 {
85  if (parent.isValid())
86  return 0;
87 
88  return d->rowCount;
89 }
90 
91 void CodeCompletionModel::completionInvoked(KTextEditor::View* view, const Range& range, InvocationType invocationType)
92 {
93  Q_UNUSED(view)
94  Q_UNUSED(range)
95  Q_UNUSED(invocationType)
96 }
97 
98 void CodeCompletionModel::executeCompletionItem(Document* document, const Range& word, int row) const
99 {
100  document->replaceText(word, data(index(row, Name, QModelIndex())).toString());
101 }
102 
103 bool CodeCompletionModel::hasGroups() const {
104  return d->hasGroups;
105 }
106 
107 void CodeCompletionModel::setHasGroups(bool hasGroups)
108 {
109  if (d->hasGroups!=hasGroups) {
110  d->hasGroups=hasGroups;
111  emit hasGroupsChanged(this,hasGroups);
112  }
113 }
114 
115 CodeCompletionModel2::CodeCompletionModel2(QObject* parent) : CodeCompletionModel(parent)
116 {
117 }
118 
119 void CodeCompletionModel2::executeCompletionItem2(Document* document, const Range& word, const QModelIndex& index) const
120 {
121  document->replaceText(word, data(index.sibling(index.row(), Name)).toString());
122 }
123 
124 #include "codecompletionmodel.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Apr 20 2013 06:07:23 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.10.2 API Reference

Skip menu "kdelibs-4.10.2 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal