• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KTextEditor

codecompletionmodel.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2005-2006 Hamish Rodda <rodda@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "codecompletionmodel.h"
00020 
00021 #include "document.h"
00022 
00023 using namespace KTextEditor;
00024 
00025 class KTextEditor::CodeCompletionModelPrivate
00026 {
00027 public:
00028   CodeCompletionModelPrivate()
00029     : rowCount(0),hasGroups(true)
00030   {}
00031 
00032   int rowCount;
00033   bool hasGroups;
00034 };
00035 
00036 CodeCompletionModel::CodeCompletionModel(QObject* parent)
00037   : QAbstractItemModel(parent)
00038   , d(new CodeCompletionModelPrivate)
00039 {
00040 }
00041 
00042 CodeCompletionModel::~ CodeCompletionModel()
00043 {
00044   delete d;
00045 }
00046 
00047 int CodeCompletionModel::columnCount( const QModelIndex & ) const
00048 {
00049   return ColumnCount;
00050 }
00051 
00052 QModelIndex CodeCompletionModel::index( int row, int column, const QModelIndex & parent ) const
00053 {
00054   if (row < 0 || row >= d->rowCount || column < 0 || column >= ColumnCount || parent.isValid())
00055     return QModelIndex();
00056 
00057   return createIndex(row, column, 0);
00058 }
00059 
00060 QMap< int, QVariant > CodeCompletionModel::itemData( const QModelIndex & index ) const
00061 {
00062   QMap<int, QVariant> ret = QAbstractItemModel::itemData(index);
00063 
00064   for (int i = CompletionRole; i <= LastItemDataRole; ++i) {
00065     QVariant v = data(index, i);
00066     if (v.isValid())
00067       ret.insert(i, v);
00068   }
00069 
00070   return ret;
00071 }
00072 
00073 QModelIndex CodeCompletionModel::parent( const QModelIndex & ) const
00074 {
00075   return QModelIndex();
00076 }
00077 
00078 void CodeCompletionModel::setRowCount( int rowCount )
00079 {
00080   d->rowCount = rowCount;
00081 }
00082 
00083 int CodeCompletionModel::rowCount( const QModelIndex & parent ) const
00084 {
00085   if (parent.isValid())
00086     return 0;
00087 
00088   return d->rowCount;
00089 }
00090 
00091 void CodeCompletionModel::completionInvoked(KTextEditor::View* view, const Range& range, InvocationType invocationType)
00092 {
00093   Q_UNUSED(view)
00094   Q_UNUSED(range)
00095   Q_UNUSED(invocationType)
00096 }
00097 
00098 void CodeCompletionModel::executeCompletionItem(Document* document, const Range& word, int row) const
00099 {
00100   document->replaceText(word, data(index(row, Name, QModelIndex())).toString());
00101 }
00102 
00103 bool CodeCompletionModel::hasGroups() const {
00104   return d->hasGroups;
00105 }
00106 
00107 void CodeCompletionModel::setHasGroups(bool hasGroups)
00108 {
00109   if (d->hasGroups!=hasGroups) {
00110     d->hasGroups=hasGroups;
00111     emit hasGroupsChanged(this,hasGroups);
00112   }
00113 }
00114 
00115 CodeCompletionModel2::CodeCompletionModel2(QObject* parent) : CodeCompletionModel(parent)
00116 {
00117 }
00118 
00119 void CodeCompletionModel2::executeCompletionItem2(Document* document, const Range& word, const QModelIndex& index) const
00120 {
00121   document->replaceText(word, data(index.sibling(index.row(), Name)).toString());
00122 }
00123 
00124 #include "codecompletionmodel.moc"

KTextEditor

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal