1
/* This file is part of the KDE project
2
Copyright (C) 2009 Adam Pigg <adam@piggz.co.uk>
3
Copyright (C) 2009 Jarosław Staniek <staniek@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "AlterSchemaTableModel.h"
21
#include <kexidb/tableschema.h>
24
AlterSchemaTableModel::AlterSchemaTableModel ( QObject* parent ) : QAbstractTableModel ( parent )
31
AlterSchemaTableModel::~AlterSchemaTableModel()
36
QVariant AlterSchemaTableModel::data ( const QModelIndex& index, int role ) const
41
if (index.row() >= (int)m_schema->fieldCount())
44
if (role == Qt::DisplayRole) {
45
if (m_data.length() > index.row()) {
46
const KexiDB::RecordData r( m_data[index.row()] );
47
if (r.size() <= index.column())
49
return r[index.column()];
59
QVariant AlterSchemaTableModel::headerData(int section, Qt::Orientation orientation, int role) const
61
if (role != Qt::DisplayRole)
64
if (orientation == Qt::Horizontal) {
66
KexiDB::Field *fld = m_schema->field(section);
68
return m_schema->field(section)->captionOrName();
70
return QString("Column %1").arg(section);
72
return QString("Row %1").arg(section);
75
int AlterSchemaTableModel::columnCount ( const QModelIndex& parent ) const
79
return m_schema->fieldCount();
84
int AlterSchemaTableModel::rowCount ( const QModelIndex& parent ) const
90
void AlterSchemaTableModel::setSchema(KexiDB::TableSchema *ts)
93
kDebug() << m_schema->fieldCount();
95
beginInsertColumns(QModelIndex(), 0, m_schema->fieldCount() - 1);
99
void AlterSchemaTableModel::setData(const QList<KexiDB::RecordData>& data)