summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/client.pro2
-rw-r--r--client/widgets.h1
-rw-r--r--client/widgets/dbwidget.cc193
-rw-r--r--client/widgets/dbwidget.h73
-rw-r--r--client/widgets/widget.cc35
5 files changed, 11 insertions, 293 deletions
diff --git a/client/client.pro b/client/client.pro
index 877f19f..46d0a03 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -56,7 +56,6 @@ HEADERS += \
widgets/textedit.h \
widgets/button.h \
widgets/datetime.h \
- widgets/dbwidget.h \
widgets/combobox.h \
widgets/listbox.h \
widgets/frame.h \
@@ -93,7 +92,6 @@ SOURCES += \
widgets/button.cc \
widgets/combobox.cc \
widgets/datetime.cc \
- widgets/dbwidget.cc \
widgets/listbox.cc \
widgets/frame.cc \
widgets/groupbox.cc \
diff --git a/client/widgets.h b/client/widgets.h
index bc0a83b..f705a07 100644
--- a/client/widgets.h
+++ b/client/widgets.h
@@ -33,7 +33,6 @@
#include "widgets/textedit.h"
#include "widgets/button.h"
#include "widgets/datetime.h"
-#include "widgets/dbwidget.h"
#include "widgets/combobox.h"
#include "widgets/listbox.h"
#include "widgets/multilist.h"
diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc
deleted file mode 100644
index 0708304..0000000
--- a/client/widgets/dbwidget.cc
+++ /dev/null
@@ -1,193 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * dbwidget.cc
- *
- * Mon Sep 1 16:23:54 CEST 2008
- * Copyright 2008 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Pracro.
- *
- * Pracro is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Pracro is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Pracro; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "dbwidget.h"
-
-#include <QDomNodeList>
-#include <QCompleter>
-#include <QRegExpValidator>
-#include <QRegExp>
-#include <QStringListModel>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QLineEdit>
-#include <QComboBox>
-
-#include "common.h"
-
-#define EMPTY_STRING "Write something in the searchfield"
-
-DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow)
- : Widget(node, macrowindow)
-{
- combobox = new QComboBox();
- widget = combobox;
-
- changedByUser = true;
-
- QDomElement elem = node.toElement();
-
- 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"));
- db.setConnectOptions("connect_timeout=2000");
- bool ok = db.open();
- if(!ok) {
- printf("DB connect failed!\n");
- }
-
- setCommonAttributes(combobox, node);
-
- combobox->setInsertPolicy(QComboBox::InsertAlphabetically);
- combobox->setEditable(true);
-
- // Make empty default selection.
- combobox->addItem(tr("EMPTY_STRING"));
- combobox->setCurrentIndex(-1);
-
- QStringListModel *strlst = new QStringListModel();
- QCompleter *completer = new QCompleter(this);
- completer->setCaseSensitivity(Qt::CaseInsensitive);
- completer->setCompletionMode(QCompleter::PopupCompletion);
- completer->setModel(strlst);
- combobox->setCompleter(completer);
-
- connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
- connect((QWidget*)combobox->lineEdit(), SIGNAL(textEdited(QString)),
- this, SLOT(update_list(QString)));
-
- changed();
-}
-
-DBWidget::~DBWidget()
-{
- db.close();
- db = QSqlDatabase();
- // delete combobox;
-}
-
-
-QString DBWidget::value()
-{
- QString value;
-
- value = combobox->currentText();
-
- return value;
-}
-
-void DBWidget::setValue(QString value, QString source)
-{
- changedByUser = false;
- if(isUserSource(source)) emit wasChanged();
-
- combobox->setEditText(value);
-
- // setInitialValue(value);
- changedByUser = true;
-}
-
-bool DBWidget::preValid()
-{
- return combobox->currentText() != tr(EMPTY_STRING) &&
- combobox->currentText() != "" &&
- combobox->findText(combobox->currentText()) != -1
- ;
-}
-
-void DBWidget::changed()
-{
- emit eventOnChange();
- if(changedByUser) emit wasChanged();
-}
-
-void DBWidget::update_list(QString prefix)
-{
- if(prefix == "") {
- 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() + "%';");
-
- QStringList lst;
- while(query.next()) {
- // lst << format_parser(format, query);
- }
-
- lst.sort();
-
- QStringListModel *mdl = (QStringListModel *)combobox->completer()->model();
- if(mdl->stringList() != lst) {
- QString val = combobox->currentText();
- combobox->clear();
- if(lst.size() == 0) lst << "Søgningen passede ikke på noget.";
- combobox->addItems(lst);
- combobox->setEditText(val);
- mdl->setStringList(lst);
- //showPopup();
- }
-}
-
-void DBWidget::setWdgValid(bool valid)
-{
- QPalette palette;
-
- 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)));
- }
-
- combobox->lineEdit()->setPalette(palette);
- combobox->setPalette(palette);
-}
diff --git a/client/widgets/dbwidget.h b/client/widgets/dbwidget.h
deleted file mode 100644
index 3eb8f94..0000000
--- a/client/widgets/dbwidget.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * dbwidget.h
- *
- * Mon Sep 1 16:23:53 CEST 2008
- * Copyright 2008 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Pracro.
- *
- * Pracro is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Pracro is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Pracro; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#ifndef __PRACRO_DBWIDGET_H__
-#define __PRACRO_DBWIDGET_H__
-
-#include "widget.h"
-
-#include <QDomNode>
-
-#include <QRegExp>
-#include <QSqlDatabase>
-
-#include <QEvent>
-
-class QComboBox;
-class DBWidget : public Widget
-{
-Q_OBJECT
-public:
- DBWidget(QDomNode &node, MacroWindow *macrowindow);
- ~DBWidget();
-
- QString value();
- void setValue(QString value, QString source = "");
-
- void setWdgValid(bool valid);
- bool preValid();
-
-public slots:
- void changed();
- void update_list(QString prefix);
-
-protected:
- // void focusInEvent(QFocusEvent *);
-
-private:
- QSqlDatabase db;
-
- QString select;
- QString from;
- QString where;
- QString format;
-
- bool changedByUser;
-
- QComboBox *combobox;
-};
-
-#endif/*__PRACRO_DBWIDGET_H__*/
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index b155279..dbce00c 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -54,11 +54,7 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow)
widget_local =
elem.hasAttribute("local") && elem.attribute("local") == "true";
- /*
- if(elem.hasAttribute("prefilled")) {
- prefilled = elem.attribute("prefilled");
- }
- */
+
has_lazy = elem.hasAttribute("name") && elem.hasAttribute("value");
lazy_value = elem.attribute("value", "");
lazy_source = elem.attribute("prefilled", "prefilled");
@@ -179,21 +175,17 @@ void Widget::setWdgValidRecursive(bool forcevalid)
void Widget::setEnabled(bool enabled)
{
widget->setEnabled(enabled);
- if(enabled == false) setWdgValidRecursive(true);
- else setWdgValidRecursive(false);
-
- /*
- if(enabled) {
- setValid(valid(), true);
- emit eventOnChange();
- } else setValid(true, true); // Force disabled widgets to be valid
- */
- QVector< Widget* >::iterator i = children.begin();
- while(i != children.end()) {
- if(*i) (*i)->runEventOnChange(true);
- i++;
+ if(enabled == false) {
+ setWdgValidRecursive(true); // Force all valid
+ } else {
+ setWdgValidRecursive(false);
+
+ QVector< Widget* >::iterator i = children.begin();
+ while(i != children.end()) {
+ if(*i) (*i)->runEventOnChange(true);
+ i++;
+ }
}
-
}
bool Widget::enabled()
@@ -367,11 +359,6 @@ void Widget::createWidget(QDomNode &xml_node, QLayout *layout)
ComboBox *combobox = new ComboBox(xml_elem, macrowindow);
widget = combobox;
- } else if(xml_elem.tagName() == "dbwidget") {
-
- DBWidget *dbwidget = new DBWidget(xml_elem, macrowindow);
- widget = dbwidget;
-
} else if(xml_elem.tagName() == "listbox") {
ListBox *listbox = new ListBox(xml_elem, macrowindow);