kexi
kexidbcheckbox.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 , m_invalidState(false)
00029 , m_tristateChanged(false)
00030 , m_tristate(TristateDefault)
00031 {
00032 setFocusPolicy(QWidget::StrongFocus);
00033 updateTristate();
00034 connect(this, SIGNAL(stateChanged(int)), this, SLOT(slotStateChanged(int)));
00035 }
00036
00037 KexiDBCheckBox::~KexiDBCheckBox()
00038 {
00039 }
00040
00041 void KexiDBCheckBox::setInvalidState( const QString& displayText )
00042 {
00043 setEnabled(false);
00044 setState(NoChange);
00045 m_invalidState = true;
00047 if (focusPolicy() & TabFocus)
00048 setFocusPolicy(QWidget::ClickFocus);
00049 setText(displayText);
00050 }
00051
00052 void
00053 KexiDBCheckBox::setEnabled(bool enabled)
00054 {
00055 if(enabled && m_invalidState)
00056 return;
00057 QCheckBox::setEnabled(enabled);
00058 }
00059
00060 void
00061 KexiDBCheckBox::setReadOnly(bool readOnly)
00062 {
00063 setEnabled(!readOnly);
00064 }
00065
00066 void KexiDBCheckBox::setValueInternal(const QVariant &add, bool removeOld)
00067 {
00068 Q_UNUSED(add);
00069 Q_UNUSED(removeOld);
00070 if (isTristateInternal())
00071 setState( m_origValue.isNull() ? NoChange : (m_origValue.toBool() ? On : Off) );
00072 else
00073 setState( m_origValue.toBool() ? On : Off );
00074 }
00075
00076 QVariant
00077 KexiDBCheckBox::value()
00078 {
00079 if (state()==NoChange)
00080 return QVariant();
00081 return QVariant(state()==On, 1);
00082 }
00083
00084 void KexiDBCheckBox::slotStateChanged(int )
00085 {
00086 signalValueChanged();
00087 }
00088
00089 bool KexiDBCheckBox::valueIsNull()
00090 {
00091 return state() == NoChange;
00092 }
00093
00094 bool KexiDBCheckBox::valueIsEmpty()
00095 {
00096 return false;
00097 }
00098
00099 bool KexiDBCheckBox::isReadOnly() const
00100 {
00101 return !isEnabled();
00102 }
00103
00104 QWidget*
00105 KexiDBCheckBox::widget()
00106 {
00107 return this;
00108 }
00109
00110 bool KexiDBCheckBox::cursorAtStart()
00111 {
00112 return false;
00113 }
00114
00115 bool KexiDBCheckBox::cursorAtEnd()
00116 {
00117 return false;
00118 }
00119
00120 void KexiDBCheckBox::clear()
00121 {
00122 setState(NoChange);
00123 }
00124
00125 void KexiDBCheckBox::setTristate(KexiDBCheckBox::Tristate tristate)
00126 {
00127 m_tristateChanged = true;
00128 m_tristate = tristate;
00129 updateTristate();
00130 }
00131
00132 KexiDBCheckBox::Tristate KexiDBCheckBox::isTristate() const
00133 {
00134 return m_tristate;
00135 }
00136
00137 bool KexiDBCheckBox::isTristateInternal() const
00138 {
00139 if (m_tristate == TristateDefault)
00140 return !dataSource().isEmpty();
00141
00142 return m_tristate == TristateOn;
00143 }
00144
00145 void KexiDBCheckBox::updateTristate()
00146 {
00147 if (m_tristate == TristateDefault) {
00149 QCheckBox::setTristate( !dataSource().isEmpty() );
00150 }
00151 else {
00152 QCheckBox::setTristate( m_tristate == TristateOn );
00153 }
00154 }
00155
00156 void KexiDBCheckBox::setDataSource(const QString &ds)
00157 {
00158 KexiFormDataItemInterface::setDataSource(ds);
00159 updateTristate();
00160 }
00161
00162 void KexiDBCheckBox::setDisplayDefaultValue(QWidget *widget, bool displayDefaultValue)
00163 {
00164 KexiFormDataItemInterface::setDisplayDefaultValue(widget, displayDefaultValue);
00165
00166 KexiDisplayUtils::DisplayParameters * const params
00167 = displayDefaultValue ? m_displayParametersForDefaultValue : m_displayParametersForEnteredValue;
00168
00169 QPalette pal(palette());
00170
00171 pal.setColor(QPalette::Active, QColorGroup::Foreground, params->textColor);
00172 setPalette(pal);
00173 }
00174
00175 #include "kexidbcheckbox.moc"
|