kexi

kexidbcheckbox.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this program; see the file COPYING.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kexidbcheckbox.h"
00022 
00023 #include <kexiutils/utils.h>
00024 #include <kexidb/queryschema.h>
00025 
00026 KexiDBCheckBox::KexiDBCheckBox(const QString &text, QWidget *parent, const char *name)
00027  : QCheckBox(text, parent, name), KexiFormDataItemInterface()
00028 {
00029     m_invalidState = false;
00031     setTristate(true);
00032     setFocusPolicy(QWidget::StrongFocus);
00033     connect(this, SIGNAL(stateChanged(int)), this, SLOT(slotStateChanged(int)));
00034 }
00035 
00036 KexiDBCheckBox::~KexiDBCheckBox()
00037 {
00038 }
00039 
00040 void KexiDBCheckBox::setInvalidState( const QString& displayText )
00041 {
00042     setEnabled(false);
00043     setState(NoChange);
00044     m_invalidState = true;
00046     if (focusPolicy() & TabFocus)
00047         setFocusPolicy(QWidget::ClickFocus);
00048     setText(displayText);
00049 }
00050 
00051 void
00052 KexiDBCheckBox::setEnabled(bool enabled)
00053 {
00054     if(enabled && m_invalidState)
00055         return;
00056     QCheckBox::setEnabled(enabled);
00057 }
00058 
00059 void KexiDBCheckBox::setValueInternal(const QVariant &add, bool )
00060 {
00061 //  setState( add.isNull() ? NoChange : (add.toBool() ? On : Off) );
00062     setState( m_origValue.isNull() ? NoChange : (m_origValue.toBool() ? On : Off) );
00063 }
00064 
00065 QVariant
00066 KexiDBCheckBox::value()
00067 {
00068     if (state()==NoChange)
00069         return QVariant();
00070     return QVariant(state()==On, 1);
00071 }
00072 
00073 void KexiDBCheckBox::slotStateChanged(int )
00074 {
00075     signalValueChanged();
00076 }
00077 
00078 bool KexiDBCheckBox::valueIsNull()
00079 {
00080     return state() == NoChange;
00081 }
00082 
00083 bool KexiDBCheckBox::valueIsEmpty()
00084 {
00085     return false;
00086 }
00087 
00088 bool KexiDBCheckBox::isReadOnly() const
00089 {
00090     return !isEnabled();
00091 }
00092 
00093 QWidget*
00094 KexiDBCheckBox::widget()
00095 {
00096     return this;
00097 }
00098 
00099 bool KexiDBCheckBox::cursorAtStart()
00100 {
00101     return false; 
00102 }
00103 
00104 bool KexiDBCheckBox::cursorAtEnd()
00105 {
00106     return false; 
00107 }
00108 
00109 void KexiDBCheckBox::clear()
00110 {
00111     setState(NoChange);
00112 }
00113 
00114 #include "kexidbcheckbox.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys