kexi

kexidataiteminterface.cpp

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 #include "kexidataiteminterface.h"
00021 
00022 #include <kdebug.h>
00023 
00024 KexiDataItemChangesListener::KexiDataItemChangesListener()
00025 {
00026 }
00027 
00028 KexiDataItemChangesListener::~KexiDataItemChangesListener()
00029 {
00030 }
00031 
00032 //-----------------------------------------------
00033 
00034 KexiDataItemInterface::KexiDataItemInterface()
00035  : m_listener(0)
00036  , m_listenerIsQObject(false)
00037  , m_parentDataItemInterface(0)
00038  , m_hasFocusableWidget(true)
00039  , m_disable_signalValueChanged(false)
00040  , m_acceptEditorAfterDeleteContents(false)
00041 {
00042 }
00043 
00044 KexiDataItemInterface::~KexiDataItemInterface()
00045 {
00046 }
00047 
00048 void KexiDataItemInterface::setValue(const QVariant& value, const QVariant& add, 
00049     bool removeOld, const QVariant* visibleValue)
00050 {
00051     m_disable_signalValueChanged = true; //to prevent emmiting valueChanged()
00052 //needed?   clear();
00053     if (dynamic_cast<QObject*>(this)) {
00054         kdDebug() << "KexiDataItemInterface::setValue(): " <<
00055             dynamic_cast<QObject*>(this)->className() << " " 
00056             << dynamic_cast<QWidget*>(this)->name()
00057             << " value=" << value << " add=" << add << endl;
00058     }
00059     m_origValue = value;
00060     setValueInternal(add, removeOld);
00061     if (visibleValue)
00062         setVisibleValueInternal(*visibleValue);
00063     m_disable_signalValueChanged = false;
00064 }
00065 
00066 void KexiDataItemInterface::setVisibleValueInternal(const QVariant& value)
00067 {
00068     Q_UNUSED(value);
00069 }
00070 
00071 void KexiDataItemInterface::signalValueChanged()
00072 {
00073     if (m_disable_signalValueChanged || isReadOnly())
00074         return;
00075     if (m_parentDataItemInterface) {
00076         m_parentDataItemInterface->signalValueChanged();
00077         return;
00078     }
00079     if (m_listener) {
00080         beforeSignalValueChanged();
00081         m_listener->valueChanged(this);
00082     }
00083 }
00084 
00085 bool KexiDataItemInterface::valueChanged()
00086 {
00087 //  bool ok;
00088 //  kdDebug() << m_origValue.toString() << " ? " << value(ok).toString() << endl;
00089 //  return (m_origValue != value(ok)) && ok;
00090     kdDebug() << "KexiDataItemInterface::valueChanged(): " << m_origValue.toString() << " ? " << value().toString() << endl;
00091     return m_origValue != value();
00092 }
00093 
00094 /*
00095 void KexiDataItemInterface::setValue(const QVariant& value)
00096 {
00097     m_disable_signalValueChanged = true; //to prevent emmiting valueChanged()
00098     setValueInternal( value );
00099     m_disable_signalValueChanged = false;
00100 }*/
00101 
00102 KexiDataItemChangesListener* KexiDataItemInterface::listener()
00103 {
00104     if (!m_listener || !m_listenerIsQObject)
00105         return m_listener;
00106     if (!m_listenerObject)
00107         m_listener = 0; //destroyed, update pointer
00108     return m_listener;
00109 }
00110 
00111 void KexiDataItemInterface::installListener(KexiDataItemChangesListener* listener)
00112 {
00113     m_listener = listener;
00114     m_listenerIsQObject = dynamic_cast<QObject*>(listener);
00115     if (m_listenerIsQObject)
00116         m_listenerObject = dynamic_cast<QObject*>(listener);
00117 }
00118 
00119 void KexiDataItemInterface::showFocus( const QRect& r, bool readOnly )
00120 {
00121     Q_UNUSED(r);
00122     Q_UNUSED(readOnly);
00123 }
00124 
00125 void KexiDataItemInterface::hideFocus()
00126 {
00127 }
00128 
00129 void KexiDataItemInterface::clickedOnContents()
00130 {
00131 }
00132 
00133 bool KexiDataItemInterface::valueIsValid()
00134 {
00135     return true;
00136 }
00137 
00138 void KexiDataItemInterface::setParentDataItemInterface(KexiDataItemInterface* parentDataItemInterface)
00139 {
00140     m_parentDataItemInterface = parentDataItemInterface;
00141 }
00142 
00143 bool KexiDataItemInterface::cursorAtNewRow()
00144 {
00145     return listener() ? listener()->cursorAtNewRow() : false;
00146 }
KDE Home | KDE Accessibility Home | Description of Access Keys