summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/luadb.cc32
-rw-r--r--client/luawidget.cc32
-rw-r--r--client/widgets/combobox.cc32
-rw-r--r--client/widgets/combobox.h4
4 files changed, 91 insertions, 9 deletions
diff --git a/client/luadb.cc b/client/luadb.cc
index 8666f98..a9e77e6 100644
--- a/client/luadb.cc
+++ b/client/luadb.cc
@@ -48,9 +48,12 @@ public:
db.setUserName(user);
if(password != "") db.setPassword(password);
db.setConnectOptions("connect_timeout=2000");
+ db.open();
}
- ~DB() { }
+ ~DB() {
+ db.close();
+ }
void exec(const QString &querystr) {
query = db.exec(querystr);
@@ -118,13 +121,20 @@ static int db_next(lua_State *L)
static int db_new(lua_State *L)
{
+ const char *driver = luaL_checkstring(L, 1);
+ const char *host = luaL_checkstring(L, 2);
+ const char *database = luaL_checkstring(L, 3);
+ const char *user = luaL_checkstring(L, 4);
+ const char *password = luaL_checkstring(L, 5);
+ int port = luaL_checknumber(L, 6);
+
db_userdata *dbu;
dbu = (db_userdata *)lua_newuserdata(L, sizeof(db_userdata));
luaL_getmetatable(L, "DB");
lua_setmetatable(L, -2);
- dbu->db = new DB("", "", "", "");
+ dbu->db = new DB(driver, host, database, user, password, port);
return 1;
}
@@ -142,7 +152,7 @@ static int db_gc(lua_State *L)
}
static const struct luaL_Reg db_meths[] = {
- {"__new", db_new},
+ // {"__new", db_new},
{"__gc" ,db_gc},
{"value", db_value},
{"next", db_next},
@@ -150,6 +160,11 @@ static const struct luaL_Reg db_meths[] = {
{NULL, NULL}
};
+static const struct luaL_reg db_funcs[] = {
+ {"new", db_new},
+ {NULL, NULL}
+};
+
void register_db(lua_State *L)
{
luaL_newmetatable(L, "DB");
@@ -157,19 +172,20 @@ void register_db(lua_State *L)
lua_pushvalue(L, -2);
lua_rawset(L, -3);
luaL_register(L, NULL, db_meths);
+ luaL_openlib (L, "DB", db_funcs, 0);
}
/*
Example:
--------
-db = DB:new(...)
-db.exec('...')
+db = DB.new(...)
+db:exec('...')
-while db.next()
+while db:next()
do
- val0 = db.value(0)
- val1 = db.value(1)
+ val0 = db:value(0)
+ val1 = db:value(1)
...
end
diff --git a/client/luawidget.cc b/client/luawidget.cc
index 5abc236..86dc2bb 100644
--- a/client/luawidget.cc
+++ b/client/luawidget.cc
@@ -280,9 +280,39 @@ static int cmb_add_item(lua_State *L)
return 0;
}
+static int cmb_le_value(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ luaL_argcheck(L, wdgu, 1, "combobox expected");
+
+ ComboBox *cmb = (ComboBox*)wdgu->widget;
+ lua_pushstring(L, cmb->lineEditValue().toStdString().c_str());
+
+ return 1;
+}
+
+static int cmb_le_set_value(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ luaL_argcheck(L, wdgu, 1, "combobox expected");
+
+ const char *val = luaL_checkstring(L, 2);
+
+ ComboBox *cmb = (ComboBox*)wdgu->widget;
+ cmb->setLineEditValue(val);
+
+ return 0;
+}
+
#define CMBBOX_METHS \
{"clear", cmb_clear},\
- {"addItem", cmb_add_item}
+ {"addItem", cmb_add_item},\
+ {"lineEditValue", cmb_le_value},\
+ {"setLineEditValue", cmb_le_set_value}
static const struct luaL_Reg wdg_meths[] =
{ WDG_METHS, {NULL, NULL} };
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc
index b625848..9d783a2 100644
--- a/client/widgets/combobox.cc
+++ b/client/widgets/combobox.cc
@@ -64,6 +64,8 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
combobox = new MyQComboBox();
widget = combobox;
+ ignoreChangeEvents = false;
+
setCommonAttributes(combobox, node);
#ifdef STYLE_HACK
@@ -191,12 +193,18 @@ bool ComboBox::preValid()
void ComboBox::changed()
{
+ if(ignoreChangeEvents == true) return;
+
+ WARN(ComboBox, "changed");
if(ischangingbyuser) emit wasChanged();
emit eventOnChange();
}
bool ComboBox::eventFilter(QObject *obj, QEvent *event)
{
+ if(ignoreChangeEvents == true) return false;
+
+ WARN(ComboBox, "eventFilter");
if(combotype == SELECT) {
if(event->type() == QEvent::MouseButtonRelease) {
if(enabled()) combobox->showPopup();
@@ -208,6 +216,9 @@ bool ComboBox::eventFilter(QObject *obj, QEvent *event)
void ComboBox::changeEvent(QEvent *event)
{
+ if(ignoreChangeEvents == true) return;
+
+ WARN(ComboBox, "changeEvent");
if(event->type() == QEvent::EnabledChange) {
changed();
}
@@ -231,10 +242,31 @@ void ComboBox::setWdgValid(bool valid)
void ComboBox::clear()
{
+ ignoreChangeEvents = true;
+ WARN(ComboBox, "clear");
combobox->clear();
+ ignoreChangeEvents = false;
}
void ComboBox::addItem(QString item)
{
+ ignoreChangeEvents = true;
combobox->addItem(item, item);
+ ignoreChangeEvents = false;
+}
+
+QString ComboBox::lineEditValue()
+{
+ if(combobox->lineEdit()) return combobox->lineEdit()->text();
+ return "";
+
+}
+
+void ComboBox::setLineEditValue(QString value)
+{
+ if(combobox->lineEdit()) {
+ ignoreChangeEvents = true;
+ combobox->lineEdit()->setText(value);
+ ignoreChangeEvents = false;
+ }
}
diff --git a/client/widgets/combobox.h b/client/widgets/combobox.h
index 02b4ccd..ec8c9ba 100644
--- a/client/widgets/combobox.h
+++ b/client/widgets/combobox.h
@@ -50,6 +50,9 @@ public:
QString value();
void setValue(QString value, QString source = "");
+ QString lineEditValue();
+ void setLineEditValue(QString value);
+
bool preValid();
void setWdgValid(bool valid);
@@ -71,6 +74,7 @@ private:
bool ischangingbyuser;
QComboBox *combobox;
+ bool ignoreChangeEvents;
};
#endif/*__PRACRO_COMBOBOX_H__*/