00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "filterkeyentry.h"
00021 #include "commonwidgets.h"
00022
00023
00024 #include <opie2/odebug.h>
00025 using namespace Opie::Core;
00026
00027
00028 #include <qwidgetstack.h>
00029 #include <qcombobox.h>
00030 #include <qlayout.h>
00031 #include <qlineedit.h>
00032 #include <qsizepolicy.h>
00033 #include <qdatetime.h>
00034 #include <qhbox.h>
00035
00036 TVFilterKeyEntry::TVFilterKeyEntry(QWidget *parent, const char *name, WFlags f)
00037 : QWidget(parent, name, f)
00038 {
00039 int stack_elem = 0;
00040
00041 layout = new QHBoxLayout(this, 0);
00042 layout->setSpacing(0);
00043 layout->setMargin(0);
00044
00045 textEntry = new QHBox(this, 0);
00046 textEntry->setSpacing(0);
00047 textEntry->setMargin(0);
00048
00049 intEntry = new QHBox(this, 0);
00050 intEntry->setSpacing(0);
00051 intEntry->setMargin(0);
00052
00053 timeEntry = new QHBox(this, 0);
00054 timeEntry->setSpacing(0);
00055 timeEntry->setMargin(0);
00056
00057 dateEntry = new QHBox(this, 0);
00058 dateEntry->setSpacing(0);
00059 dateEntry->setMargin(0);
00060
00061 textCombo = new QComboBox(textEntry, 0);
00062 textKey = new QLineEdit(textEntry, 0);
00063
00064
00065 textCombo->insertItem("less than");
00066 textCombo->insertItem("more than");
00067 textCombo->insertItem("equal to");
00068 textCombo->insertItem("containing");
00069 textCombo->insertItem("starting with");
00070 textCombo->insertItem("ending with");
00071
00072 intCombo = new QComboBox(intEntry, 0);
00073 intKey = new IntEdit(intEntry, 0);
00074
00075
00076 intCombo->insertItem("less than");
00077 intCombo->insertItem("more than");
00078 intCombo->insertItem("equal to");
00079
00080 timeCombo = new QComboBox(timeEntry, 0);
00081 timeKey = new TimeEdit(timeEntry, 0);
00082
00083
00084 timeCombo->insertItem("less than");
00085 timeCombo->insertItem("more than");
00086 timeCombo->insertItem("equal to");
00087
00088 dateCombo = new QComboBox(dateEntry, 0);
00089 dateKey = new DateEdit(dateEntry, 0);
00090
00091
00092 dateCombo->insertItem("less than");
00093 dateCombo->insertItem("more than");
00094 dateCombo->insertItem("equal to");
00095
00096 ts = 0;
00097
00098 ws = new QWidgetStack(this, 0);
00099 ws->setMargin(0);
00100 ws->addWidget(textEntry, TVVariant::String);
00101 ws->addWidget(intEntry, TVVariant::Int);
00102 ws->addWidget(timeEntry, TVVariant::Time);
00103 ws->addWidget(dateEntry, TVVariant::Date);
00104
00105
00106 connect(textKey, SIGNAL(textChanged(const QString&)),
00107 this, SIGNAL(valueChanged()));
00108 connect(intKey, SIGNAL(valueChanged(int)),
00109 this, SIGNAL(valueChanged()));
00110 connect(dateKey, SIGNAL(valueChanged(const QDate&)),
00111 this, SIGNAL(valueChanged()));
00112 connect(timeKey, SIGNAL(valueChanged(const QTime&)),
00113 this, SIGNAL(valueChanged()));
00114
00115 connect(intCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
00116 connect(textCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
00117 connect(timeCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
00118 connect(dateCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
00119
00120 ws->raiseWidget(TVVariant::String);
00121 layout->addWidget(ws);
00122
00123 current_type = TVVariant::String;
00124 }
00125
00129 TVFilterKeyEntry::~TVFilterKeyEntry()
00130 {
00131 }
00132
00133 void TVFilterKeyEntry::setKey(int i)
00134 {
00135
00136 if (!ts) return;
00137 if (!ts->kRep) return;
00138
00139
00140 if (current_type != ts->kRep->getKeyType(i)) {
00141 current_type = ts->kRep->getKeyType(i);
00142 ws->raiseWidget(current_type);
00143 }
00144 }
00145
00146 void TVFilterKeyEntry::setTableState(TableState *t) {
00147 int i;
00148 ts = t;
00149 if(!t) return;
00150 if (!t->kRep)
00151 return;
00152 if (t->kRep->getNumFields() < 1)
00153 return;
00154 setKey(0);
00155
00156 }
00157
00158 CmpType TVFilterKeyEntry::getCompareType()
00159 {
00160
00161 switch(current_type) {
00162 case TVVariant::String: {
00163 CmpType k = (CmpType) textCombo->currentItem();
00164 return k;
00165 }
00166 case TVVariant::Int: {
00167 CmpType k = (CmpType) intCombo->currentItem();
00168 return k;
00169 }
00170 case TVVariant::Time: {
00171 CmpType k = (CmpType) timeCombo->currentItem();
00172 return k;
00173 }
00174 case TVVariant::Date: {
00175 CmpType k = (CmpType) dateCombo->currentItem();
00176 return k;
00177 }
00178 default:
00179 break;
00180 }
00181 return ct_equal;
00182 }
00183
00184
00185 TVVariant TVFilterKeyEntry::getCompareValue()
00186 {
00187 TVVariant sendkey;
00188 int tmp;
00189
00190 switch(current_type) {
00191 case TVVariant::String:
00192 sendkey = TVVariant(QString(textKey->text()));
00193 break;
00194 case TVVariant::Int: {
00195 sendkey = TVVariant(intKey->value());
00196 break;
00197 }
00198 case TVVariant::Time: {
00199 sendkey = TVVariant(QTime(timeKey->time()));
00200 break;
00201 }
00202 case TVVariant::Date: {
00203 sendkey = TVVariant(QDate(dateKey->date()));
00204 break;
00205 }
00206 default: {
00207 sendkey = TVVariant(0);
00208 owarn << "TVFilterKeyEntry::getCompareValue() cannot work out data type" << oendl;
00209 }
00210 }
00211 return sendkey;
00212 }