kexi

kexidataiteminterface.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexidataiteminterface.h"
21
22#include <kdebug.h>
23
24KexiDataItemChangesListener::KexiDataItemChangesListener()
25{
26}
27
28KexiDataItemChangesListener::~KexiDataItemChangesListener()
29{
30}
31
32//-----------------------------------------------
33
34KexiDataItemInterface::KexiDataItemInterface()
35 : m_listener(0)
36 , m_listenerIsTQObject(false)
37 , m_parentDataItemInterface(0)
38 , m_hasFocusableWidget(true)
39 , m_disable_signalValueChanged(false)
40 , m_acceptEditorAfterDeleteContents(false)
41{
42}
43
44KexiDataItemInterface::~KexiDataItemInterface()
45{
46}
47
48void KexiDataItemInterface::setValue(const TQVariant& value, const TQVariant& add,
49 bool removeOld, const TQVariant* visibleValue)
50{
51 m_disable_signalValueChanged = true; //to prevent emmiting valueChanged()
52//needed? clear();
53 if (dynamic_cast<TQObject*>(this)) {
54 kdDebug() << "KexiDataItemInterface::setValue(): " <<
55 dynamic_cast<TQObject*>(this)->className() << " "
56 << dynamic_cast<TQWidget*>(this)->name()
57 << " value=" << value << " add=" << add << endl;
58 }
59 m_origValue = value;
60 setValueInternal(add, removeOld);
61 if (visibleValue)
63 m_disable_signalValueChanged = false;
64}
65
67{
68 Q_UNUSED(value);
69}
70
72{
73 if (m_disable_signalValueChanged || isReadOnly())
74 return;
76 m_parentDataItemInterface->signalValueChanged();
77 return;
78 }
79 if (m_listener) {
81 m_listener->valueChanged(this);
82 }
83}
84
86{
87// bool ok;
88// kdDebug() << m_origValue.toString() << " ? " << value(ok).toString() << endl;
89// return (m_origValue != value(ok)) && ok;
90 kdDebug() << "KexiDataItemInterface::valueChanged(): " << m_origValue.toString() << " ? " << value().toString() << endl;
91 return m_origValue != value();
92}
93
94/*
95void KexiDataItemInterface::setValue(const TQVariant& value)
96{
97 m_disable_signalValueChanged = true; //to prevent emmiting valueChanged()
98 setValueInternal( value );
99 m_disable_signalValueChanged = false;
100}*/
101
102KexiDataItemChangesListener* KexiDataItemInterface::listener()
103{
104 if (!m_listener || !m_listenerIsTQObject)
105 return m_listener;
106 if (!m_listenerObject)
107 m_listener = 0; //destroyed, update pointer
108 return m_listener;
109}
110
112{
113 m_listener = listener;
114 m_listenerIsTQObject = dynamic_cast<TQObject*>(listener);
115 if (m_listenerIsTQObject)
116 m_listenerObject = dynamic_cast<TQObject*>(listener);
117}
118
119void KexiDataItemInterface::showFocus( const TQRect& r, bool readOnly )
120{
121 Q_UNUSED(r);
122 Q_UNUSED(readOnly);
123}
124
128
132
134{
135 return true;
136}
137
138void KexiDataItemInterface::setParentDataItemInterface(KexiDataItemInterface* parentDataItemInterface)
139{
140 m_parentDataItemInterface = parentDataItemInterface;
141}
142
143bool KexiDataItemInterface::cursorAtNewRow()
144{
145 return listener() ? listener()->cursorAtNewRow() : false;
146}
An helper class used to react on KexiDataItemInterface objects' changes.
virtual bool cursorAtNewRow() const =0
void setParentDataItemInterface(KexiDataItemInterface *parentDataItemInterface)
virtual bool isReadOnly() const
virtual void setVisibleValueInternal(const TQVariant &value)
virtual TQVariant value()=0
virtual void showFocus(const TQRect &r, bool readOnly)
void setValue(const TQVariant &value, const TQVariant &add=TQVariant(), bool removeOld=false, const TQVariant *visibleValue=0)
virtual void setValueInternal(const TQVariant &add, bool removeOld)=0
KexiDataItemInterface * m_parentDataItemInterface
virtual void installListener(KexiDataItemChangesListener *listener)
Sets listener. No need to reimplement this.
virtual void beforeSignalValueChanged()
virtual TQVariant visibleValue()