diff options
Diffstat (limited to 'client/widgets/dbwidget.cc')
-rw-r--r-- | client/widgets/dbwidget.cc | 162 |
1 files changed, 50 insertions, 112 deletions
diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc index 31a6a42..3852b21 100644 --- a/client/widgets/dbwidget.cc +++ b/client/widgets/dbwidget.cc @@ -34,12 +34,19 @@ #include <QSqlQuery> #include <QSqlError> #include <QLineEdit> +#include <QComboBox> + #include "formatparser.h" #include "common.h" +#define EMPTY_STRING "Write something in the searchfield" + DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow) - : QComboBox(), Widget(node, macrowindow) + : Widget(node, macrowindow) { + combobox = new QComboBox(); + widget = combobox; + changedByUser = true; QDomElement elem = node.toElement(); @@ -72,24 +79,25 @@ DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow) printf("DB connect failed!\n"); } - setCommonAttributes(this, node); + setCommonAttributes(combobox, node); - setInsertPolicy(QComboBox::InsertAlphabetically); - setEditable(true); + combobox->setInsertPolicy(QComboBox::InsertAlphabetically); + combobox->setEditable(true); // Make empty default selection. - addItem(tr("Write something in the searchfield")); - setCurrentIndex(-1); + combobox->addItem(tr("Write something in the searchfield")); + combobox->setCurrentIndex(-1); QStringListModel *strlst = new QStringListModel(); QCompleter *completer = new QCompleter(this); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setCompletionMode(QCompleter::PopupCompletion); completer->setModel(strlst); - setCompleter(completer); + combobox->setCompleter(completer); - connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); - connect((QWidget*)lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(update_list(QString))); + connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); + connect((QWidget*)combobox->lineEdit(), SIGNAL(textEdited(QString)), + this, SLOT(update_list(QString))); changed(); } @@ -98,14 +106,15 @@ DBWidget::~DBWidget() { db.close(); db = QSqlDatabase(); + // delete combobox; } -QString DBWidget::getValue() +QString DBWidget::value() { QString value; - value = currentText(); + value = combobox->currentText(); return value; } @@ -115,52 +124,39 @@ void DBWidget::setValue(QString value, QString source) changedByUser = false; if(isUserSource(source)) emit wasChanged(); - setEditText(value); + combobox->setEditText(value); setInitialValue(value); changedByUser = true; } -bool DBWidget::isValid() +bool DBWidget::preValid() { - - return currentText() != tr("Write something in the searchfield") - && findText(currentText()) != -1; - - /* - QSqlQuery query = db.exec("SELECT " + select + " FROM " + from + " WHERE LOWER(" + where + ") = '" + currentText().toLower() + "';"); - - return query.size() != 0; - */ + return combobox->currentText() != tr(EMPTY_STRING) && + combobox->currentText() != "" && + combobox->findText(combobox->currentText()) != -1 + ; } void DBWidget::changed() { - QPalette palette; - - if(isValid() && luaValidator()) { - // valid string - palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); - } else { - // invalid string - palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); - } - - lineEdit()->setPalette(palette); - if(changedByUser) emit wasChanged(); + eventOnChange(); } void DBWidget::update_list(QString prefix) { if(prefix == "") { - clear(); - addItem(tr("Write something in the searchfield")); - setCurrentIndex(-1); + combobox->clear(); + combobox->addItem(tr(EMPTY_STRING)); + combobox->setCurrentIndex(-1); return; } - QSqlQuery query = db.exec("SELECT " + select + " FROM " + from + " WHERE LOWER(" + where + ") LIKE '" + prefix.toLower() + "%';"); + QSqlQuery query = db.exec("SELECT " + select + + " FROM " + from + + " WHERE LOWER(" + where + ")" + " LIKE '" + prefix.toLower() + "%';"); QStringList lst; while(query.next()) { @@ -169,88 +165,30 @@ void DBWidget::update_list(QString prefix) lst.sort(); - QStringListModel *mdl = (QStringListModel *)completer()->model(); + QStringListModel *mdl = (QStringListModel *)combobox->completer()->model(); if(mdl->stringList() != lst) { - QString val = currentText(); - clear(); + QString val = combobox->currentText(); + combobox->clear(); if(lst.size() == 0) lst << "Søgningen passede ikke på noget."; - addItems(lst); - setEditText(val); + combobox->addItems(lst); + combobox->setEditText(val); mdl->setStringList(lst); //showPopup(); } } -void DBWidget::enable() +void DBWidget::setWdgValid(bool valid) { - setEnabled(true); -} - -void DBWidget::disable() -{ - setEnabled(false); -} - -bool DBWidget::isDisabled() -{ - return isEnabled() == false; -} - -void DBWidget::connectFrom(const char *signal, - const QObject *receiver, const char *method) -{ - connect(this, signal, receiver, method); -} - -void DBWidget::connectTo(const QObject *sender, const char *signal, - const char *method) -{ - connect(sender, signal, this, method); -} + QPalette palette; -bool DBWidget::setKeyboardFocus() -{ - setFocus(); - return true; -} + if(valid) { + // valid string + palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + } else { + // invalid string + palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); + } -void DBWidget::setVisibility(bool visible) -{ - setVisible(visible); + combobox->lineEdit()->setPalette(palette); + combobox->setPalette(palette); } -/* -$ psql -h sensei -d lms -U postgres -=================================================================== - List of relations - Schema | Name | Type | Owner ---------+-------+-------+---------- - public | lms01 | table | postgres -(1 row) - -lms=# \d lms01 - Table "public.lms01" - Column | Type | Modifiers --------------------------------+-----------------------+----------- - drugid | character varying(32) | - producttype | character varying(14) | - productsubtype | character varying(14) | - sequencetext | character varying(28) | - specialitynumber | character varying(20) | - drugname | character varying(70) | - dosageform_text | character varying(50) | - dosageform_code | character varying(24) | - further_dos_info | character varying(24) | - strength_text | character varying(50) | - strength_numeric | character varying(30) | - strength_unit | character varying(16) | - marketing_authorisation_owner | character varying(22) | - importer | character varying(22) | - atc | character varying(26) | - route_of_administration | character varying(26) | - traffic_warning | character varying(12) | - substitution | character varying(12) | - substitution_group | character varying(18) | - dose_dispensing | character varying(12) | - deregistration_date | character varying(26) | - quarantine_date | character varying(26) | -*/ |