~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to kexi/kexidb/fieldlist.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2003-2012 Jarosław Staniek <staniek@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2 of the License, or (at your option) any later version.
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
 
#ifndef KEXIDB_FIELDLIST_H
21
 
#define KEXIDB_FIELDLIST_H
22
 
 
23
 
#include <QList>
24
 
#include <QHash>
25
 
#include <QString>
26
 
 
27
 
#include "field.h"
28
 
#include "driver.h"
29
 
 
30
 
namespace KexiDB
31
 
{
32
 
 
33
 
class Connection;
34
 
 
35
 
/*! Helper class that stores list of fields.
36
 
*/
37
 
 
38
 
class KEXI_DB_EXPORT FieldList
39
 
{
40
 
public:
41
 
    /*! Creates empty list of fields. If \a owner is true, the list will be
42
 
     owner of any added field, what means that these field
43
 
     will be removed on the list destruction. Otherwise, the list
44
 
     just points any field that was added.
45
 
     \sa isOwner()
46
 
    */
47
 
    FieldList(bool owner = false);
48
 
 
49
 
    /*! Copy constructor.
50
 
     If \a deepCopyFields is true, all fields are deeply copied, else only pointer are copied.
51
 
     Reimplemented in QuerySchema constructor. */
52
 
    FieldList(const FieldList& fl, bool deepCopyFields = true);
53
 
 
54
 
    /*! Destroys the list. If the list owns fields (see constructor),
55
 
     these are also deleted. */
56
 
    virtual ~FieldList();
57
 
 
58
 
    /*! \return number of fields in the list. */
59
 
    inline uint fieldCount() const {
60
 
        return m_fields.count();
61
 
    }
62
 
 
63
 
    /*! Adds \a field at the and of field list. */
64
 
    FieldList& addField(Field *field);
65
 
 
66
 
    /*! Inserts \a field into a specified position (\a index).
67
 
 
68
 
     Note: You can reimplement this method but you should still call
69
 
     this implementation in your subclass. */
70
 
    virtual FieldList& insertField(uint index, Field *field);
71
 
 
72
 
    /*! Removes field from the field list. Use with care.
73
 
 
74
 
     Note: You can reimplement this method but you should still call
75
 
     this implementation in your subclass. */
76
 
    virtual void removeField(KexiDB::Field *field);
77
 
 
78
 
    /*! \return field id or NULL if there is no such a field. */
79
 
    inline Field* field(uint id) {
80
 
        return m_fields.value(id);
81
 
    }
82
 
 
83
 
    /*! \return field with name \a name or NULL if there is no such a field. */
84
 
    virtual Field* field(const QString& name);
85
 
 
86
 
    /*! \return true if this list contains given \a field. */
87
 
    inline bool hasField(Field* field) const {
88
 
        return m_fields.contains(field);
89
 
    }
90
 
 
91
 
    /*! \return first occurrence of \a field in the list
92
 
     or -1 if this list does not contain this field. */
93
 
    inline int indexOf(Field* field) const {
94
 
        return m_fields.indexOf(field);
95
 
    }
96
 
 
97
 
    /*! \return list of field names for this list. */
98
 
    QStringList names() const;
99
 
 
100
 
    inline Field::ListIterator fieldsIterator() const {
101
 
        return m_fields.constBegin();
102
 
    }
103
 
    inline Field::ListIterator fieldsIteratorConstEnd() const {
104
 
        return m_fields.constEnd();
105
 
    }
106
 
 
107
 
    inline const Field::List* fields() {
108
 
        return &m_fields;
109
 
    }
110
 
 
111
 
    /*! \return list of autoincremented fields. The list is owned by this FieldList object. */
112
 
    Field::List* autoIncrementFields();
113
 
 
114
 
    /*! \return true if fields in the list are owned by this list. */
115
 
    inline bool isOwner() const {
116
 
        return m_fields.autoDelete();
117
 
    }
118
 
 
119
 
    /*! Removes all fields from the list. */
120
 
    virtual void clear();
121
 
 
122
 
    /*! \return String for debugging purposes. */
123
 
    virtual QString debugString();
124
 
 
125
 
    /*! Shows debug information about all fields in the list. */
126
 
    void debug();
127
 
 
128
 
    /*! Creates and returns a list that contain fields selected by name.
129
 
     At least one field (exising on this list) should be selected, otherwise 0 is
130
 
     returned. Returned FieldList object is not owned by any parent (so you need
131
 
     to destroy yourself) and Field objects included in it are not owned by it
132
 
     (but still as before, by 'this' object).
133
 
     Returned list can be usable e.g. as argument for Connection::insertRecord().
134
 
     0 is returned if at least one name cannot be found.
135
 
    */
136
 
    FieldList* subList(const QString& n1, const QString& n2 = QString(),
137
 
                       const QString& n3 = QString(), const QString& n4 = QString(),
138
 
                       const QString& n5 = QString(), const QString& n6 = QString(),
139
 
                       const QString& n7 = QString(), const QString& n8 = QString(),
140
 
                       const QString& n9 = QString(), const QString& n10 = QString(),
141
 
                       const QString& n11 = QString(), const QString& n12 = QString(),
142
 
                       const QString& n13 = QString(), const QString& n14 = QString(),
143
 
                       const QString& n15 = QString(), const QString& n16 = QString(),
144
 
                       const QString& n17 = QString(), const QString& n18 = QString()
145
 
                      );
146
 
 
147
 
    /*! Like above, but with a QStringList */
148
 
    FieldList* subList(const QStringList& list);
149
 
 
150
 
    /*! Like above, but with a list of field indices */
151
 
    FieldList* subList(const QList<uint>& list);
152
 
 
153
 
    /*! \return a string that is a result of all field names concatenated
154
 
     and with \a separator. This is usable e.g. as argument like "field1,field2"
155
 
     for "INSERT INTO (xxx) ..". The result of this method is effectively cached,
156
 
     and it is invalidated when set of fields changes (e.g. using clear()
157
 
     or addField()).
158
 
     \a tableAlias, if provided is prepended to each field, so the resulting
159
 
     names will be in form tableAlias.fieldName. This option is used for building
160
 
     queries with joins, where fields have to be spicified without ambiguity.
161
 
     See @ref Connection::selectStatement() for example use.
162
 
     \a drvEscaping can be used to alter default escaping type.
163
 
     \a driver is used for escaping identifiers, if 0, Kexi escaping is used.
164
 
    */
165
 
    QString sqlFieldsList(const Driver *driver, const QString& separator = QString::fromLatin1(","),
166
 
                          const QString& tableAlias = QString(),
167
 
                          int drvEscaping = Driver::EscapeDriver | Driver::EscapeAsNecessary);
168
 
 
169
 
    /*! Like above, but this is convenient static function, so you can pass any \a list here. */
170
 
    static QString sqlFieldsList(Field::List* list, const Driver *driver,
171
 
                                 const QString& separator = QString::fromLatin1(","), const QString& tableAlias = QString(),
172
 
                                 int drvEscaping = Driver::EscapeDriver | Driver::EscapeAsNecessary);
173
 
 
174
 
    /*! @internal Renames field \a oldName to \a newName.
175
 
     Do not use this for physical renaming columns. Use AlterTableHandler instead. */
176
 
    void renameField(const QString& oldName, const QString& newName);
177
 
 
178
 
    /*! @internal
179
 
     \overload void renameField(const QString& oldName, const QString& newName) */
180
 
    void renameField(KexiDB::Field *field, const QString& newName);
181
 
 
182
 
protected:
183
 
    Field::List m_fields;
184
 
    QHash<QString, Field*> m_fields_by_name; //!< Fields collected by name. Not used by QuerySchema.
185
 
    Field::List *m_autoinc_fields;
186
 
 
187
 
private:
188
 
    void renameFieldInternal(KexiDB::Field *field, const QString& newNameLower);
189
 
 
190
 
    //! cached
191
 
    QString m_sqlFields;
192
 
};
193
 
 
194
 
} //namespace KexiDB
195
 
 
196
 
#endif