KTextEditor
codecompletionmodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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)
00030 {}
00031
00032 int rowCount;
00033 };
00034
00035 CodeCompletionModel::CodeCompletionModel(QObject* parent)
00036 : QAbstractItemModel(parent)
00037 , d(new CodeCompletionModelPrivate)
00038 {
00039 }
00040
00041 CodeCompletionModel::~ CodeCompletionModel()
00042 {
00043 delete d;
00044 }
00045
00046 int CodeCompletionModel::columnCount( const QModelIndex & ) const
00047 {
00048 return ColumnCount;
00049 }
00050
00051 QModelIndex CodeCompletionModel::index( int row, int column, const QModelIndex & parent ) const
00052 {
00053 if (row < 0 || row >= d->rowCount || column < 0 || column >= ColumnCount || parent.isValid())
00054 return QModelIndex();
00055
00056 return createIndex(row, column, 0);
00057 }
00058
00059 QMap< int, QVariant > CodeCompletionModel::itemData( const QModelIndex & index ) const
00060 {
00061 QMap<int, QVariant> ret = QAbstractItemModel::itemData(index);
00062
00063 for (int i = CompletionRole; i <= LastItemDataRole; ++i) {
00064 QVariant v = data(index, i);
00065 if (v.isValid())
00066 ret.insert(i, v);
00067 }
00068
00069 return ret;
00070 }
00071
00072 QModelIndex CodeCompletionModel::parent( const QModelIndex & ) const
00073 {
00074 return QModelIndex();
00075 }
00076
00077 void CodeCompletionModel::setRowCount( int rowCount )
00078 {
00079 d->rowCount = rowCount;
00080 }
00081
00082 int CodeCompletionModel::rowCount( const QModelIndex & parent ) const
00083 {
00084 if (parent.isValid())
00085 return 0;
00086
00087 return d->rowCount;
00088 }
00089
00090 void CodeCompletionModel::completionInvoked(KTextEditor::View* view, const Range& range, InvocationType invocationType)
00091 {
00092 Q_UNUSED(view)
00093 Q_UNUSED(range)
00094 Q_UNUSED(invocationType)
00095 }
00096
00097 void CodeCompletionModel::executeCompletionItem(Document* document, const Range& word, int row) const
00098 {
00099 document->replaceText(word, data(index(row, Name, QModelIndex())).toString());
00100 }
00101
00102 CodeCompletionModel2::CodeCompletionModel2(QObject* parent) : CodeCompletionModel(parent)
00103 {
00104 }
00105
00106 void CodeCompletionModel2::executeCompletionItem2(Document* document, const Range& word, const QModelIndex& index) const
00107 {
00108 document->replaceText(word, data(index.sibling(index.row(), Name)).toString());
00109 }
00110
00111 #include "codecompletionmodel.moc"