summaryrefslogtreecommitdiff
path: root/client/widgets
diff options
context:
space:
mode:
authordeva <deva>2008-09-03 15:07:50 +0000
committerdeva <deva>2008-09-03 15:07:50 +0000
commit4dd7add65ed2648e7c139df3138e489f8dbd8e43 (patch)
treeb30eea7c4b49fce9fe329c7a3d955627167f26a1 /client/widgets
parent4549daa34926ca806daf6cbf4aea70bf24338f4a (diff)
The dbwidget now work generally, controlled by the xml.
Diffstat (limited to 'client/widgets')
-rw-r--r--client/widgets/dbwidget.cc49
-rw-r--r--client/widgets/dbwidget.h5
2 files changed, 35 insertions, 19 deletions
diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc
index d0f4def..69c868e 100644
--- a/client/widgets/dbwidget.cc
+++ b/client/widgets/dbwidget.cc
@@ -34,7 +34,7 @@
#include <QSqlQuery>
#include <QSqlError>
#include <QLineEdit>
-
+#include "formatparser.h"
#include "common.h"
DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow)
@@ -42,11 +42,28 @@ DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow)
{
QDomElement elem = node.toElement();
- db = QSqlDatabase::addDatabase("QPSQL");
- db.setHostName("sensei.j.auh.dk");
- db.setDatabaseName("lms");
- db.setUserName("postgres");
- // db.setPassword("");
+ if(!elem.hasAttribute("driver") ||
+ !elem.hasAttribute("server") ||
+ !elem.hasAttribute("user") ||
+ !elem.hasAttribute("database") ||
+ !elem.hasAttribute("select") ||
+ !elem.hasAttribute("from") ||
+ !elem.hasAttribute("where") ||
+ !elem.hasAttribute("format")) {
+ printf("Error: missing tag!\n");
+ }
+
+ select = elem.attribute("select");
+ from = elem.attribute("from");
+ where = elem.attribute("where");
+ format = elem.attribute("format");
+
+ db = QSqlDatabase::addDatabase(elem.attribute("driver"));
+ db.setHostName(elem.attribute("server"));
+ if(elem.hasAttribute("port")) db.setPort(elem.attribute("port").toInt());
+ db.setDatabaseName(elem.attribute("database"));
+ db.setUserName(elem.attribute("user"));
+ if(elem.hasAttribute("password")) db.setPassword(elem.attribute("password"));
bool ok = db.open();
if(!ok) {
printf("DB connect failed!\n");
@@ -108,9 +125,7 @@ void DBWidget::setValue(QString value)
bool DBWidget::isValid()
{
- QSqlQuery query = db.exec("SELECT drugname, dosageform_code, strength_text FROM lms01 WHERE"
- " LOWER(drugname || ' ' || strength_text || ' (' || dosageform_code || ')' )"
- " = '" + currentText().toLower() + "';");
+ QSqlQuery query = db.exec("SELECT " + select + " FROM " + from + " WHERE LOWER(" + where + ") = '" + currentText().toLower() + "';");
return query.size() != 0;
}
@@ -121,7 +136,7 @@ void DBWidget::changed()
if(isValid() && luaValidator()) {
// valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(128, 255, 128)));
+ palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
} else {
// invalid string
palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
@@ -140,16 +155,11 @@ void DBWidget::update_list(QString prefix)
return;
}
*/
- QSqlQuery query = db.exec("SELECT drugname, dosageform_code, strength_text FROM lms01 WHERE"
- " LOWER(drugname || ' ' || strength_text || ' (' || dosageform_code || ')' )"
- " LIKE '" + prefix.toLower() + "%';");
+ QSqlQuery query = db.exec("SELECT " + select + " FROM " + from + " WHERE LOWER(" + where + ") LIKE '" + prefix.toLower() + "%';");
QStringList lst;
while(query.next()) {
- QString drugname = query.value(0).toString();
- QString dosageform = query.value(1).toString();
- QString strength = query.value(2).toString();
- lst << drugname + " " + strength + " (" + dosageform + ")";
+ lst << format_parser(format, query);
}
lst.sort();
@@ -158,10 +168,11 @@ void DBWidget::update_list(QString prefix)
if(mdl->stringList() != lst) {
QString val = currentText();
clear();
- if(lst.size() != 0) addItems(lst);
- else addItem("Søgningen passede ikke på noget.");
+ if(lst.size() == 0) lst << "Søgningen passede ikke på noget.";
+ addItems(lst);
setEditText(val);
mdl->setStringList(lst);
+ //showPopup();
}
}
diff --git a/client/widgets/dbwidget.h b/client/widgets/dbwidget.h
index 0438ca5..98499b9 100644
--- a/client/widgets/dbwidget.h
+++ b/client/widgets/dbwidget.h
@@ -59,6 +59,11 @@ protected:
private:
QSqlDatabase db;
+
+ QString select;
+ QString from;
+ QString where;
+ QString format;
};
#endif/*__PRACRO_DBWIDGET_H__*/