~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kexi/migration/AlterSchemaTableModel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include "AlterSchemaTableModel.h"
 
21
#include <kexidb/tableschema.h>
 
22
#include <kdebug.h>
 
23
 
 
24
AlterSchemaTableModel::AlterSchemaTableModel ( QObject* parent ) : QAbstractTableModel ( parent )
 
25
{
 
26
    kDebug();
 
27
    m_schema = 0;
 
28
}
 
29
 
 
30
 
 
31
AlterSchemaTableModel::~AlterSchemaTableModel()
 
32
{
 
33
    kDebug();
 
34
}
 
35
 
 
36
QVariant AlterSchemaTableModel::data ( const QModelIndex& index, int role ) const
 
37
{
 
38
    if (!index.isValid())
 
39
        return QVariant();
 
40
    
 
41
    if (index.row() >= (int)m_schema->fieldCount())
 
42
        return QVariant();
 
43
    
 
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())
 
48
                return QVariant();
 
49
            return r[index.column()];
 
50
        }
 
51
        else {
 
52
            return QVariant();
 
53
        }
 
54
    }
 
55
    else
 
56
        return QVariant();
 
57
}
 
58
 
 
59
QVariant AlterSchemaTableModel::headerData(int section, Qt::Orientation orientation, int role) const
 
60
{
 
61
    if (role != Qt::DisplayRole)
 
62
        return QVariant();
 
63
 
 
64
    if (orientation == Qt::Horizontal) {
 
65
        if (m_schema) {
 
66
            KexiDB::Field *fld = m_schema->field(section);
 
67
            if (fld)
 
68
                return m_schema->field(section)->captionOrName();
 
69
        }
 
70
        return QString("Column %1").arg(section);
 
71
    }
 
72
    return QString("Row %1").arg(section);
 
73
}
 
74
 
 
75
int AlterSchemaTableModel::columnCount ( const QModelIndex& parent ) const
 
76
{
 
77
    Q_UNUSED(parent);
 
78
    if (m_schema) {
 
79
        return m_schema->fieldCount();
 
80
    }
 
81
    return 0;
 
82
}
 
83
 
 
84
int AlterSchemaTableModel::rowCount ( const QModelIndex& parent ) const
 
85
{
 
86
    Q_UNUSED(parent);
 
87
    return 3;
 
88
}
 
89
 
 
90
void AlterSchemaTableModel::setSchema(KexiDB::TableSchema *ts)
 
91
{
 
92
    m_schema = ts;
 
93
    kDebug() << m_schema->fieldCount();
 
94
 
 
95
    beginInsertColumns(QModelIndex(), 0, m_schema->fieldCount() - 1);
 
96
    endInsertColumns();
 
97
}
 
98
 
 
99
void AlterSchemaTableModel::setData(const QList<KexiDB::RecordData>& data)
 
100
{
 
101
    m_data = data;
 
102
}