00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "BarEdit.h"
00023 #include "PrefDialog.h"
00024 #include "../pics/delete.xpm"
00025 #include "../pics/export.xpm"
00026 #include "../pics/search.xpm"
00027 #include "../pics/start.xpm"
00028 #include "../pics/next.xpm"
00029 #include "../pics/previous.xpm"
00030 #include "../pics/end.xpm"
00031 #include <qlabel.h>
00032 #include <qvalidator.h>
00033 #include <qmessagebox.h>
00034 #include <qpushbutton.h>
00035 #include <qtooltip.h>
00036 #include <qpixmap.h>
00037
00038 BarEdit::BarEdit (QWidget *w) : QWidget (w)
00039 {
00040 saveRecordFlag = FALSE;
00041 ignoreSaveRecordFlag = FALSE;
00042 editList.setAutoDelete(TRUE);
00043 saveLabel = "save";
00044 deleteLabel = "delete";
00045 QString searchLabel = "search";
00046
00047
00048
00049
00050
00051
00052 toolbar = new Toolbar(this, Toolbar::Horizontal);
00053
00054
00055
00056 QString s = tr("Search");
00057 toolbar->addButton(searchLabel, QPixmap(search), s);
00058 connect(toolbar->getButton(searchLabel), SIGNAL(clicked()), this, SLOT(slotDateSearch()));
00059 toolbar->getButton(searchLabel)->setAccel(CTRL+Key_R);
00060
00061 s = tr("Save Record");
00062 toolbar->addButton(saveLabel, QPixmap(exportfile), s);
00063 connect(toolbar->getButton(saveLabel), SIGNAL(clicked()), this, SLOT(saveRecord()));
00064 toolbar->setButtonStatus(saveLabel, FALSE);
00065 toolbar->getButton(saveLabel)->setAccel(CTRL+Key_S);
00066
00067 s = tr("Delete Record");
00068 toolbar->addButton(deleteLabel, QPixmap(deleteitem), s);
00069 connect(toolbar->getButton(deleteLabel), SIGNAL(clicked()), this, SLOT(deleteRecord()));
00070 toolbar->setButtonStatus(deleteLabel, FALSE);
00071 toolbar->getButton(deleteLabel)->setAccel(CTRL+Key_D);
00072
00073
00074
00075
00076
00077 QString frLabel = "fr";
00078 s = tr("First Record");
00079 toolbar->addButton(frLabel, QPixmap(start), s);
00080 connect(toolbar->getButton(frLabel), SIGNAL(clicked()), this, SLOT(slotFirstRecord()));
00081
00082
00083 QString prLabel = "pr";
00084 s = tr("Previous Record");
00085 toolbar->addButton(prLabel, QPixmap(previous), s);
00086 connect(toolbar->getButton(prLabel), SIGNAL(clicked()), this, SLOT(slotPrevRecord()));
00087
00088
00089 QString nrLabel = "nr";
00090 s = tr("Next Record");
00091 toolbar->addButton(nrLabel, QPixmap(next), s);
00092 connect(toolbar->getButton(nrLabel), SIGNAL(clicked()), this, SLOT(slotNextRecord()));
00093
00094
00095 QString lrLabel = "lr";
00096 s = tr("Last Record");
00097 toolbar->addButton(lrLabel, QPixmap(end), s);
00098 connect(toolbar->getButton(lrLabel), SIGNAL(clicked()), this, SLOT(slotLastRecord()));
00099
00100
00101 QVBoxLayout *vbox = new QVBoxLayout(this);
00102 grid = new QGridLayout(vbox, 1, 3);
00103 grid->setColStretch(1, 1);
00104 grid->setColStretch(2, 1);
00105
00106 grid->setSpacing(2);
00107 grid->addMultiCellWidget(toolbar, 0, 0, 0, 1);
00108 grid->expand(grid->numRows() + 1, grid->numCols());
00109
00110 QLabel *label = new QLabel(tr("Date"), this);
00111 date = new QLineEdit(this);
00112 date->setReadOnly(TRUE);
00113
00114 grid->addWidget(label, grid->numRows() -1, 0);
00115 grid->addMultiCellWidget(date, grid->numRows() -1, grid->numRows() -1, 1, 2);
00116
00117
00118 grid->expand(grid->numRows() + 1, grid->numCols());
00119
00120
00121 }
00122
00123 BarEdit::~BarEdit ()
00124 {
00125 }
00126
00127 void BarEdit::createField (QString &l, QString &d, bool f)
00128 {
00129 QLabel *label = new QLabel(l, this);
00130 grid->addWidget(label, grid->numRows() - 1, 0);
00131
00132 QLineEdit *edit = new QLineEdit(this);
00133 editList.replace(d, edit);
00134
00135 if (f)
00136 {
00137 QIntValidator *iv = new QIntValidator(0, 999999999, this);
00138 edit->setValidator(iv);
00139 connect(edit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
00140
00141 grid->addMultiCellWidget(edit, grid->numRows() -1, grid->numRows() -1, 1, 2);
00142 }
00143 else
00144 {
00145 QDoubleValidator *dv = new QDoubleValidator(0, 99999999999.0, 4, this, 0);
00146 edit->setValidator(dv);
00147 connect(edit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
00148
00149 grid->addMultiCellWidget(edit, grid->numRows() -1, grid->numRows() -1, 1, 2);
00150 }
00151
00152 grid->expand(grid->numRows() + 1, grid->numCols());
00153 }
00154
00155 void BarEdit::deleteRecord ()
00156 {
00157 int rc = QMessageBox::warning(this,
00158 tr("Delete record."),
00159 tr("Are you sure you want to delete record?"),
00160 QMessageBox::Yes,
00161 QMessageBox::No,
00162 QMessageBox::NoButton);
00163
00164 if (rc == QMessageBox::No)
00165 return;
00166
00167 emit signalDeleteRecord();
00168
00169 clearRecordFields();
00170
00171 toolbar->setButtonStatus(deleteLabel, FALSE);
00172 toolbar->setButtonStatus(saveLabel, FALSE);
00173
00174 saveRecordFlag = FALSE;
00175 }
00176
00177 void BarEdit::saveRecord ()
00178 {
00179 emit signalSaveRecord();
00180 toolbar->setButtonStatus(saveLabel, FALSE);
00181 saveRecordFlag = FALSE;
00182 }
00183
00184 void BarEdit::slotDateSearch ()
00185 {
00186 saveRecordDialog();
00187
00188 QString pl = QObject::tr("Parms");
00189 QString dl = QObject::tr("Date");
00190 QString tl = QObject::tr("Time");
00191 QDateTime dt = QDateTime::currentDateTime();
00192
00193 PrefDialog *dialog = new PrefDialog(this);
00194 dialog->setCaption(QObject::tr("Date Search"));
00195 dialog->createPage (pl);
00196 dialog->addDateItem(dl, pl, dt);
00197 dialog->addTimeItem(tl, pl, dt);
00198 int rc = dialog->exec();
00199 if (rc != QDialog::Accepted)
00200 {
00201 delete dialog;
00202 return;
00203 }
00204
00205 dialog->getDate(dl, dt);
00206 dialog->getTime(tl, dt);
00207 delete dialog;
00208
00209 clearRecordFields();
00210
00211 emit signalSearch(dt);
00212
00213 toolbar->setButtonStatus(deleteLabel, FALSE);
00214 toolbar->setButtonStatus(saveLabel, FALSE);
00215 }
00216
00217 void BarEdit::clearRecordFields ()
00218 {
00219 ignoreSaveRecordFlag = TRUE;
00220
00221 date->clear();
00222
00223 QDictIterator<QLineEdit> it(editList);
00224 for(; it.current(); ++it)
00225 it.current()->clear();
00226
00227 ignoreSaveRecordFlag = FALSE;
00228
00229 saveRecordFlag = FALSE;
00230 }
00231
00232 void BarEdit::textChanged (const QString &)
00233 {
00234 if (! ignoreSaveRecordFlag)
00235 {
00236 saveRecordFlag = TRUE;
00237 toolbar->setButtonStatus(saveLabel, TRUE);
00238 }
00239 }
00240
00241 void BarEdit::setField (QString &k, QString &d)
00242 {
00243 ignoreSaveRecordFlag = TRUE;
00244
00245 QLineEdit *edit = editList[k];
00246 if (edit)
00247 edit->setText(d);
00248
00249 ignoreSaveRecordFlag = FALSE;
00250 }
00251
00252 void BarEdit::setDate (QString &d, bool)
00253 {
00254 date->setText(d);
00255 }
00256
00257 void BarEdit::getField (QString &d, QString &r)
00258 {
00259 r.truncate(0);;
00260 QLineEdit *edit = editList[d];
00261 if (edit)
00262 r = edit->text();
00263 }
00264
00265 void BarEdit::getDate (QString &r)
00266 {
00267 r = date->text();
00268 }
00269
00270 bool BarEdit::getSaveFlag ()
00271 {
00272 return saveRecordFlag;
00273 }
00274
00275 void BarEdit::slotFirstRecord ()
00276 {
00277 saveRecordDialog();
00278 emit signalFirstRecord();
00279 }
00280
00281 void BarEdit::slotLastRecord ()
00282 {
00283 saveRecordDialog();
00284 emit signalLastRecord();
00285 }
00286
00287 void BarEdit::slotNextRecord ()
00288 {
00289 saveRecordDialog();
00290 emit signalNextRecord();
00291 }
00292
00293 void BarEdit::slotPrevRecord ()
00294 {
00295 saveRecordDialog();
00296 emit signalPrevRecord();
00297 }
00298
00299 void BarEdit::saveRecordDialog ()
00300 {
00301 if (! saveRecordFlag)
00302 return;
00303
00304 int rc = QMessageBox::warning(this,
00305 tr("Warning"),
00306 tr("Record has been modified.\nSave changes?"),
00307 QMessageBox::Yes,
00308 QMessageBox::No,
00309 QMessageBox::NoButton);
00310
00311 if (rc == QMessageBox::Yes)
00312 saveRecord();
00313 else
00314 {
00315 saveRecordFlag = FALSE;
00316 toolbar->setButtonStatus(saveLabel, FALSE);
00317 }
00318 }
00319
00320 void BarEdit::clearButtons ()
00321 {
00322 toolbar->setButtonStatus(saveLabel, FALSE);
00323 toolbar->setButtonStatus(deleteLabel, TRUE);
00324 }
00325
00326