kexi

roweditbuffer.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <kexidb/roweditbuffer.h>
00021 
00022 #include <kdebug.h>
00023 
00024 using namespace KexiDB;
00025 
00026 
00027 RowEditBuffer::RowEditBuffer(bool dbAwareBuffer)
00028 : m_simpleBuffer(dbAwareBuffer ? 0 : new SimpleMap())
00029 , m_simpleBufferIt(dbAwareBuffer ? 0 : new SimpleMap::ConstIterator())
00030 , m_dbBuffer(dbAwareBuffer ? new DBMap() : 0)
00031 , m_dbBufferIt(dbAwareBuffer ? new DBMap::ConstIterator() : 0)
00032 {
00033 }
00034 
00035 RowEditBuffer::~RowEditBuffer()
00036 {
00037     delete m_simpleBuffer;
00038     delete m_simpleBufferIt;
00039     delete m_dbBuffer;
00040     delete m_dbBufferIt;
00041 }
00042 
00043 const QVariant* RowEditBuffer::at( QueryColumnInfo& fi ) const
00044 { 
00045     if (!m_dbBuffer) {
00046         KexiDBWarn << "RowEditBuffer::at(QueryColumnInfo&): not db-aware buffer!" << endl;
00047         return 0;
00048     }
00049     *m_dbBufferIt = m_dbBuffer->find( &fi );
00050     if (*m_dbBufferIt==m_dbBuffer->constEnd())
00051         return 0;
00052     return &(*m_dbBufferIt).data();
00053 }
00054 
00055 const QVariant* RowEditBuffer::at( Field& f ) const
00056 {
00057     if (!m_simpleBuffer) {
00058         KexiDBWarn << "RowEditBuffer::at(Field&): this is db-aware buffer!" << endl;
00059         return 0;
00060     }
00061     *m_simpleBufferIt = m_simpleBuffer->find( f.name() );
00062     if (*m_simpleBufferIt==m_simpleBuffer->constEnd())
00063         return 0;
00064     return &(*m_simpleBufferIt).data();
00065 }
00066 
00067 const QVariant* RowEditBuffer::at( const QString& fname ) const
00068 {
00069     if (!m_simpleBuffer) {
00070         KexiDBWarn << "RowEditBuffer::at(Field&): this is db-aware buffer!" << endl;
00071         return 0;
00072     }
00073     *m_simpleBufferIt = m_simpleBuffer->find( fname );
00074     if (*m_simpleBufferIt==m_simpleBuffer->constEnd())
00075         return 0;
00076     return &(*m_simpleBufferIt).data();
00077 }
00078 
00079 void RowEditBuffer::clear() {
00080     if (m_dbBuffer)
00081         m_dbBuffer->clear(); 
00082     if (m_simpleBuffer)
00083         m_simpleBuffer->clear();
00084 }
00085 
00086 bool RowEditBuffer::isEmpty() const
00087 {
00088     if (m_dbBuffer)
00089         return m_dbBuffer->isEmpty(); 
00090     if (m_simpleBuffer)
00091         return m_simpleBuffer->isEmpty();
00092     return true;
00093 }
00094 
00095 void RowEditBuffer::debug()
00096 {
00097     if (isDBAware()) {
00098         kdDebug() << "RowEditBuffer type=DB-AWARE, " << m_dbBuffer->count() <<" items"<< endl;
00099         for (DBMap::ConstIterator it = m_dbBuffer->constBegin(); it!=m_dbBuffer->constEnd(); ++it) {
00100             kdDebug() << "* field name=" <<it.key()->field->name()<<" val="
00101                 << (it.data().isNull() ? QString("<NULL>") : it.data().toString()) <<endl;
00102         }
00103         return;
00104     }
00105     kdDebug() << "RowEditBuffer type=SIMPLE, " << m_simpleBuffer->count() <<" items"<< endl;
00106     for (SimpleMap::ConstIterator it = m_simpleBuffer->constBegin(); it!=m_simpleBuffer->constEnd(); ++it) {
00107         kdDebug() << "* field name=" <<it.key()<<" val="
00108             << (it.data().isNull() ? QString("<NULL>") : it.data().toString()) <<endl;
00109     }
00110 }
KDE Home | KDE Accessibility Home | Description of Access Keys