kexi

kexidataiteminterface.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program 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 program 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 program; see the file COPYING.  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 KEXIDATAITEMINTERFACE_H
00021 #define KEXIDATAITEMINTERFACE_H
00022 
00023 #include <qvariant.h>
00024 #include <qwidget.h>
00025 #include <qguardedptr.h>
00026 
00027 class KexiDataItemInterface;
00028 namespace KexiDB {
00029     class Field;
00030     class QueryColumnInfo;
00031 }
00032 
00034 class KEXICORE_EXPORT KexiDataItemChangesListener
00035 {
00036     public:
00037         KexiDataItemChangesListener();
00038         virtual ~KexiDataItemChangesListener();
00039 
00042         virtual void valueChanged(KexiDataItemInterface* item) = 0;
00043 
00047         virtual bool cursorAtNewRow() = 0;
00048 };
00049 
00051 class KEXICORE_EXPORT KexiDataItemInterface
00052 {
00053     public:
00054         KexiDataItemInterface();
00055         virtual ~KexiDataItemInterface();
00056 
00064         void setValue(const QVariant& value, const QVariant& add = QVariant(), bool removeOld = false);
00065 
00067         virtual KexiDB::Field *field() const = 0;
00068 
00070         virtual KexiDB::QueryColumnInfo* columnInfo() const = 0;
00071 
00073         virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo) = 0;
00074 
00076         virtual void installListener(KexiDataItemChangesListener* listener);
00077 
00078 //      //! Sets value \a value for a widget. 
00079 //      //! Just calls setValueInternal(), but also blocks valueChanged() 
00080 //      //! as you we don't want to react on our own change
00081 //      void setValue(const QVariant& value);
00082 
00084         virtual QVariant value() = 0;
00085 
00091         virtual bool valueIsValid();
00092 
00095         virtual bool valueIsNull() = 0;
00096 
00101         virtual bool valueIsEmpty() = 0;
00102 
00106         virtual bool isReadOnly() const { return false; }
00107 
00109         virtual QWidget* widget() = 0;
00110 
00112         virtual void hideWidget() { if (widget()) widget()->hide(); }
00113 
00115         virtual void showWidget() { if (widget()) widget()->show(); }
00116 
00118         virtual bool valueChanged();
00119 
00123         virtual bool cursorAtStart() = 0;
00124 
00128         virtual bool cursorAtEnd() = 0;
00129 
00131         virtual void clear() = 0;
00132 
00137         inline bool hasFocusableWidget() const { return m_hasFocusableWidget; }
00138 
00145         virtual void showFocus( const QRect& r, bool readOnly );
00146 
00150         virtual void hideFocus();
00151 
00156         virtual void clickedOnContents();
00157 
00161         bool acceptEditorAfterDeleteContents() const { return m_acceptEditorAfterDeleteContents; }
00162 
00163         inline virtual void setFocus() { if (widget()) widget()->setFocus(); }
00164 
00165         inline bool cursorAtNewRow() { return m_listener ? m_listener->cursorAtNewRow() : false; }
00166 
00172         void setParentDataItemInterface(KexiDataItemInterface* parentDataItemInterface) {
00173             m_parentDataItemInterface = parentDataItemInterface;
00174         }
00175 
00178         inline KexiDataItemInterface* parentInterface() const { return m_parentDataItemInterface; }
00179 
00180     protected:
00186         virtual void setValueInternal(const QVariant& add, bool removeOld) = 0;
00187 
00188 //      //! Sets value \a value for a widget. 
00189 //      //! Implement this method to allow setting value for this widget item.
00190 //      virtual void setValueInternal(const QVariant& value) = 0;
00191 
00195         void signalValueChanged();
00196 
00197 //moved to KexiFormDataItemInterface: QString m_dataSource;
00198         KexiDataItemChangesListener* m_listener;
00199         QVariant m_origValue;
00200 
00202         KexiDataItemInterface* m_parentDataItemInterface;
00203         bool m_hasFocusableWidget : 1;
00204         bool m_disable_signalValueChanged : 1;
00205         bool m_acceptEditorAfterDeleteContents : 1;
00206 };
00207 
00208 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys