summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/scripting/kexidb/kexidbfieldlist.cpp
blob: 4e07e166814788ce6787b674ca9b86e84353f560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/***************************************************************************
 * kexidbfieldlist.cpp
 * This file is part of the KDE project
 * copyright (C)2004-2005 by Sebastian Sauer ([email protected])
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 ***************************************************************************/

#include "kexidbfieldlist.h"
#include "kexidbfield.h"

#include <api/variant.h>
#include <api/exception.h>

#include <kdebug.h>

using namespace Kross::KexiDB;

KexiDBFieldList::KexiDBFieldList(::KexiDB::FieldList* fieldlist)
    : Kross::Api::Class<KexiDBFieldList>("KexiDBFieldList")
    , m_fieldlist(fieldlist)
{
    this->addFunction0< Kross::Api::Variant >("fieldCount", this, &KexiDBFieldList::fieldCount);
    this->addFunction1< KexiDBField, Kross::Api::Variant >("field", this, &KexiDBFieldList::field);
    this->addFunction1< KexiDBField, Kross::Api::Variant >("fieldByName", this, &KexiDBFieldList::fieldByName);

    this->addFunction0< Kross::Api::List >("fields", this, &KexiDBFieldList::fields);

    this->addFunction1< Kross::Api::Variant, KexiDBField >("hasField", this, &KexiDBFieldList::hasField);
    this->addFunction0< Kross::Api::Variant >("names", this, &KexiDBFieldList::names);

    this->addFunction1< void, KexiDBField >("addField", this, &KexiDBFieldList::addField);
    this->addFunction2< void, Kross::Api::Variant, KexiDBField >("insertField", this, &KexiDBFieldList::insertField);
    this->addFunction1< void, KexiDBField >("removeField", this, &KexiDBFieldList::removeField);
    this->addFunction0< void >("clear", this, &KexiDBFieldList::clear);
    this->addFunction1< void, KexiDBFieldList >("setFields", this, &KexiDBFieldList::setFields);

    this->addFunction1< KexiDBFieldList, Kross::Api::Variant >("subList", this, &KexiDBFieldList::subList);
}

KexiDBFieldList::~KexiDBFieldList()
{
}

const TQString KexiDBFieldList::getClassName() const
{
    return "Kross::KexiDB::KexiDBFieldList";
}

uint KexiDBFieldList::fieldCount() {
    return m_fieldlist->fieldCount();
}

KexiDBField* KexiDBFieldList::field(uint index) {
    ::KexiDB::Field* field = m_fieldlist->field(index);
    return field ? new KexiDBField(field) : 0;
}

KexiDBField* KexiDBFieldList::fieldByName(const TQString& name) {
    ::KexiDB::Field* field = m_fieldlist->field(name);
    return field ? new KexiDBField(field) : 0;
}

Kross::Api::List* KexiDBFieldList::fields() {
    return new Kross::Api::ListT<KexiDBField>( *m_fieldlist->fields() );
}

bool KexiDBFieldList::hasField(KexiDBField* field) { return m_fieldlist->hasField( field->field() ); }
const TQStringList KexiDBFieldList::names() const { return m_fieldlist->names(); }
void KexiDBFieldList::addField(KexiDBField* field) { m_fieldlist->addField( field->field() ); }
void KexiDBFieldList::insertField(uint index, KexiDBField* field) { m_fieldlist->insertField(index, field->field()); }
void KexiDBFieldList::removeField(KexiDBField* field) { m_fieldlist->removeField( field->field() ); }
void KexiDBFieldList::clear() { m_fieldlist->clear(); }

void KexiDBFieldList::setFields(KexiDBFieldList* fieldlist) {
    m_fieldlist->clear();
    ::KexiDB::FieldList* fl = fieldlist->fieldlist();
    for(::KexiDB::Field::ListIterator it = *fl->fields(); it.current(); ++it)
        m_fieldlist->addField( it.current() );
}

KexiDBFieldList* KexiDBFieldList::subList(TQValueList<TQVariant> list) {
    TQValueList<TQVariant>::ConstIterator it( list.constBegin() ), end( list.constEnd() );
    TQStringList sl;
    for(; it != end; ++it) sl.append( (*it).toString() );
    ::KexiDB::FieldList* fl = m_fieldlist->subList(sl);
    return fl ? new Kross::KexiDB::KexiDBFieldList(fl) : 0;
}