kexi

roweditbuffer.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003, 2006 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 #ifndef KEXIDB_ROWEDITBUFFER_H
00021 #define KEXIDB_ROWEDITBUFFER_H
00022 
00023 #include <qmap.h>
00024 
00025 #include <kexidb/field.h>
00026 #include <kexidb/queryschema.h>
00027 
00028 namespace KexiDB {
00029 
00074 class KEXI_DB_EXPORT RowEditBuffer {
00075 public:
00076     typedef QMap<QString,QVariant> SimpleMap;
00077     typedef QMap<QueryColumnInfo*,QVariant> DBMap;
00078 
00079     RowEditBuffer(bool dbAwareBuffer);
00080     ~RowEditBuffer();
00081 
00082     inline bool isDBAware() const { return m_dbBuffer!=0; }
00083 
00084     void clear();
00085 
00086     bool isEmpty() const;
00087 
00089     inline void insert( QueryColumnInfo& ci, QVariant &val ) {
00090         if (m_dbBuffer) {
00091             m_dbBuffer->insert(&ci, val);
00092             m_defaultValuesDbBuffer->remove(&ci);
00093         }
00094     }
00095 
00097     inline void insert( const QString& fname, QVariant &val ) 
00098         { if (m_simpleBuffer) m_simpleBuffer->insert(fname,val); }
00099 
00105     const QVariant* at( QueryColumnInfo& ci, bool useDefaultValueIfPossible = true ) const;
00106     
00108     const QVariant* at( Field& f ) const;
00109 
00111     const QVariant* at( const QString& fname ) const;
00112 
00115     inline bool hasDefaultValueAt( QueryColumnInfo& ci ) const {
00116         return m_defaultValuesDbBuffer->contains(&ci) && (*m_defaultValuesDbBuffer)[ &ci ];
00117     }
00118 
00119     inline const SimpleMap simpleBuffer() { return *m_simpleBuffer; }
00120     inline const DBMap dbBuffer() { return *m_dbBuffer; }
00121 
00123     void debug();
00124 
00125 protected:
00126     SimpleMap *m_simpleBuffer;
00127     SimpleMap::ConstIterator *m_simpleBufferIt;
00128     DBMap *m_dbBuffer;
00129     DBMap::Iterator *m_dbBufferIt;
00130     QMap<QueryColumnInfo*,bool> *m_defaultValuesDbBuffer;
00131     QMap<QueryColumnInfo*,bool>::ConstIterator *m_defaultValuesDbBufferIt;
00132 };
00133 
00134 } //namespace KexiDB
00135 
00136 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys