kexi

kexidataiteminterface.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005-2006 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() const = 0;
00048 };
00049 
00051 class KEXICORE_EXPORT KexiDataItemInterface
00052 {
00053     public:
00054         KexiDataItemInterface();
00055         virtual ~KexiDataItemInterface();
00056 
00069         void setValue(const QVariant& value, const QVariant& add = QVariant(), bool removeOld = false, 
00070             const QVariant* visibleValue = 0);
00071 
00073         virtual KexiDB::Field *field() const = 0;
00074 
00076         virtual KexiDB::QueryColumnInfo* columnInfo() const = 0;
00077 
00079         virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo) = 0;
00080 
00082         virtual void installListener(KexiDataItemChangesListener* listener);
00083 
00084 //      //! Sets value \a value for a widget. 
00085 //      //! Just calls setValueInternal(), but also blocks valueChanged() 
00086 //      //! as you we don't want to react on our own change
00087 //      void setValue(const QVariant& value);
00088 
00090         virtual QVariant value() = 0;
00091 
00097         virtual bool valueIsValid();
00098 
00101         virtual bool valueIsNull() = 0;
00102 
00107         virtual bool valueIsEmpty() = 0;
00108 
00112         virtual QVariant visibleValue() { return QVariant(); }
00113 
00117         virtual bool isReadOnly() const { return false; }
00118 
00120         virtual QWidget* widget() = 0;
00121 
00123         virtual void hideWidget() { if (widget()) widget()->hide(); }
00124 
00126         virtual void showWidget() { if (widget()) widget()->show(); }
00127 
00129         virtual bool valueChanged();
00130 
00134         virtual bool cursorAtStart() = 0;
00135 
00139         virtual bool cursorAtEnd() = 0;
00140 
00143         virtual void moveCursorToEnd() {};
00144 
00147         virtual void moveCursorToStart() {};
00148 
00151         virtual void selectAll() {};
00152 
00154         virtual void clear() = 0;
00155 
00160         inline bool hasFocusableWidget() const { return m_hasFocusableWidget; }
00161 
00168         virtual void showFocus( const QRect& r, bool readOnly );
00169 
00173         virtual void hideFocus();
00174 
00179         virtual void clickedOnContents();
00180 
00184         bool acceptEditorAfterDeleteContents() const { return m_acceptEditorAfterDeleteContents; }
00185 
00186         inline virtual void setFocus() { if (widget()) widget()->setFocus(); }
00187 
00188         bool cursorAtNewRow();
00189 
00195         void setParentDataItemInterface(KexiDataItemInterface* parentDataItemInterface);
00196 
00199         inline KexiDataItemInterface* parentInterface() const { return m_parentDataItemInterface; }
00200 
00204         virtual void handleAction(const QString& actionName) { Q_UNUSED(actionName); }
00205 
00206     protected:
00212         virtual void setValueInternal(const QVariant& add, bool removeOld) = 0;
00213 
00218         virtual void setVisibleValueInternal(const QVariant& value);
00219 
00220 //      //! Sets value \a value for a widget. 
00221 //      //! Implement this method to allow setting value for this widget item.
00222 //      virtual void setValueInternal(const QVariant& value) = 0;
00223 
00227         virtual void signalValueChanged();
00228 
00232         virtual void beforeSignalValueChanged() {};
00233 
00234         KexiDataItemChangesListener* listener();
00235 
00236 //moved to KexiFormDataItemInterface: QString m_dataSource;
00237         QGuardedPtr<QObject> m_listenerObject;
00238         KexiDataItemChangesListener* m_listener;
00239         bool m_listenerIsQObject;
00240         QVariant m_origValue;
00241 
00243         KexiDataItemInterface* m_parentDataItemInterface;
00244         bool m_hasFocusableWidget : 1;
00245         bool m_disable_signalValueChanged : 1;
00246         bool m_acceptEditorAfterDeleteContents : 1;
00247 };
00248 
00249 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys