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

« back to all changes in this revision

Viewing changes to kexi/kexidb/roweditbuffer.cpp

  • 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,2006 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
 
#include "roweditbuffer.h"
21
 
#include "utils.h"
22
 
 
23
 
#include <kdebug.h>
24
 
 
25
 
using namespace KexiDB;
26
 
 
27
 
 
28
 
RowEditBuffer::RowEditBuffer(bool dbAwareBuffer)
29
 
        : m_simpleBuffer(dbAwareBuffer ? 0 : new SimpleMap())
30
 
        , m_simpleBufferIt(dbAwareBuffer ? 0 : new SimpleMap::ConstIterator())
31
 
        , m_dbBuffer(dbAwareBuffer ? new DBMap() : 0)
32
 
        , m_dbBufferIt(dbAwareBuffer ? new DBMap::Iterator() : 0)
33
 
        , m_defaultValuesDbBuffer(dbAwareBuffer ? new QMap<QueryColumnInfo*, bool>() : 0)
34
 
        , m_defaultValuesDbBufferIt(dbAwareBuffer ? new QMap<QueryColumnInfo*, bool>::ConstIterator() : 0)
35
 
{
36
 
}
37
 
 
38
 
RowEditBuffer::~RowEditBuffer()
39
 
{
40
 
    delete m_simpleBuffer;
41
 
    delete m_simpleBufferIt;
42
 
    delete m_dbBuffer;
43
 
    delete m_dbBufferIt;
44
 
    delete m_defaultValuesDbBuffer;
45
 
    delete m_defaultValuesDbBufferIt;
46
 
}
47
 
 
48
 
const QVariant* RowEditBuffer::at(QueryColumnInfo& ci, bool useDefaultValueIfPossible) const
49
 
{
50
 
    if (!m_dbBuffer) {
51
 
        KexiDBWarn << "RowEditBuffer::at(QueryColumnInfo&): not db-aware buffer!";
52
 
        return 0;
53
 
    }
54
 
    *m_dbBufferIt = m_dbBuffer->find(&ci);
55
 
    QVariant* result = 0;
56
 
    if (*m_dbBufferIt != m_dbBuffer->end())
57
 
        result = &(*m_dbBufferIt).value();
58
 
    if (useDefaultValueIfPossible
59
 
            && (!result || result->isNull())
60
 
            && ci.field && !ci.field->defaultValue().isNull() && KexiDB::isDefaultValueAllowed(ci.field)
61
 
            && !hasDefaultValueAt(ci)) {
62
 
        //no buffered or stored value: try to get a default value declared in a field, so user can modify it
63
 
        if (!result)
64
 
            m_dbBuffer->insert(&ci, ci.field->defaultValue());
65
 
        result = &(*m_dbBuffer)[ &ci ];
66
 
        m_defaultValuesDbBuffer->insert(&ci, true);
67
 
    }
68
 
    return (const QVariant*)result;
69
 
}
70
 
 
71
 
const QVariant* RowEditBuffer::at(Field& f) const
72
 
{
73
 
    if (!m_simpleBuffer) {
74
 
        KexiDBWarn << "RowEditBuffer::at(Field&): this is db-aware buffer!";
75
 
        return 0;
76
 
    }
77
 
    *m_simpleBufferIt = m_simpleBuffer->constFind(f.name());
78
 
    if (*m_simpleBufferIt == m_simpleBuffer->constEnd())
79
 
        return 0;
80
 
    return &(*m_simpleBufferIt).value();
81
 
}
82
 
 
83
 
const QVariant* RowEditBuffer::at(const QString& fname) const
84
 
{
85
 
    if (!m_simpleBuffer) {
86
 
        KexiDBWarn << "RowEditBuffer::at(Field&): this is db-aware buffer!";
87
 
        return 0;
88
 
    }
89
 
    *m_simpleBufferIt = m_simpleBuffer->constFind(fname);
90
 
    if (*m_simpleBufferIt == m_simpleBuffer->constEnd())
91
 
        return 0;
92
 
    return &(*m_simpleBufferIt).value();
93
 
}
94
 
 
95
 
void RowEditBuffer::removeAt(QueryColumnInfo& ci)
96
 
{
97
 
    if (!m_dbBuffer) {
98
 
        KexiDBWarn << "not db-aware buffer!";
99
 
        return;
100
 
    }
101
 
    m_dbBuffer->remove(&ci);
102
 
}
103
 
 
104
 
void RowEditBuffer::removeAt(Field& f)
105
 
{
106
 
    if (!m_simpleBuffer) {
107
 
        KexiDBWarn << "this is db-aware buffer!";
108
 
        return;
109
 
    }
110
 
    m_simpleBuffer->remove(f.name());
111
 
}
112
 
 
113
 
void RowEditBuffer::removeAt(const QString& fname)
114
 
{
115
 
    if (!m_simpleBuffer) {
116
 
        KexiDBWarn << "this is db-aware buffer!";
117
 
        return;
118
 
    }
119
 
    m_simpleBuffer->remove(fname);
120
 
}
121
 
 
122
 
void RowEditBuffer::clear()
123
 
{
124
 
    if (m_dbBuffer) {
125
 
        m_dbBuffer->clear();
126
 
        m_defaultValuesDbBuffer->clear();
127
 
    }
128
 
    if (m_simpleBuffer)
129
 
        m_simpleBuffer->clear();
130
 
}
131
 
 
132
 
bool RowEditBuffer::isEmpty() const
133
 
{
134
 
    if (m_dbBuffer)
135
 
        return m_dbBuffer->isEmpty();
136
 
    if (m_simpleBuffer)
137
 
        return m_simpleBuffer->isEmpty();
138
 
    return true;
139
 
}
140
 
 
141
 
void RowEditBuffer::debug()
142
 
{
143
 
    if (isDBAware()) {
144
 
        KexiDBDbg << "RowEditBuffer type=DB-AWARE, " << m_dbBuffer->count() << " items";
145
 
        for (DBMap::ConstIterator it = m_dbBuffer->constBegin(); it != m_dbBuffer->constEnd(); ++it) {
146
 
            KexiDBDbg << "* field name=" << it.key()->field->name() << " val="
147
 
            << (it.value().isNull() ? QString("<NULL>") : it.value().toString())
148
 
            << (hasDefaultValueAt(*it.key()) ? " DEFAULT" : "");
149
 
        }
150
 
        return;
151
 
    }
152
 
    KexiDBDbg << "RowEditBuffer type=SIMPLE, " << m_simpleBuffer->count() << " items";
153
 
    for (SimpleMap::ConstIterator it = m_simpleBuffer->constBegin(); it != m_simpleBuffer->constEnd(); ++it) {
154
 
        KexiDBDbg << "* field name=" << it.key() << " val="
155
 
        << (it.value().isNull() ? QString("<NULL>") : it.value().toString());
156
 
    }
157
 
}