summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/macrowindow.cc45
-rw-r--r--client/macrowindow.h5
-rw-r--r--client/netcom.cc22
-rw-r--r--client/netcom.h4
-rw-r--r--client/widgets/lineedit.cc5
-rw-r--r--client/widgets/widget.cc22
6 files changed, 43 insertions, 60 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index efabbd1..38e466d 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -48,6 +48,7 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ,
: Collapser(), netcom(n)
{
mainwidget = NULL;
+ this->lua = new LUA(&mainwidget);
waschanged = false;
@@ -55,15 +56,11 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ,
setCollapsedWidget(new ResumeWidget(compact));
- this->lua = new LUA(&mainwidget);
update(xml_doc);
setCollapsed(collapsed);
active = true;
-
- connect(this, SIGNAL(doneCollapsing()), this, SLOT(collapsed()));
- connect(this, SIGNAL(doneExpanding()), this, SLOT(expanded()));
}
MacroWindow::~MacroWindow()
@@ -74,7 +71,6 @@ MacroWindow::~MacroWindow()
void MacroWindow::update(QDomNode &node)
{
- // clear();
initMacro(node);
if(mainwidget) setExpandedWidget(mainwidget->qwidget());
@@ -123,14 +119,8 @@ void MacroWindow::initMacro(QDomNode &node)
Window *window = new Window(xml_elem, this);
connect(window, SIGNAL(wasChanged()), this, SLOT(macroChanged()));
macrotitle = xml_elem.attribute("caption");
- //clear();
- /*
- if(mainwidget) {
- setExpandedWidget(NULL);
- delete mainwidget;
- mainwidget = NULL;
- }
- */
+
+ clear();
mainwidget = window;
QDomNodeList children = node.childNodes();
@@ -158,8 +148,8 @@ void MacroWindow::initMacro(QDomNode &node)
bool MacroWindow::doCommit()
{
if(mainwidget->valid()) {
- QDomDocument doc = netcom.send(mainwidget->widgetList(),
- templ, macro, version);
+ QVector< Widget* > wlist = mainwidget->widgetList();
+ QDomDocument doc = netcom.send(wlist, templ, macro, version);
QDomNodeList nl = doc.documentElement().childNodes();
QDomNode n = nl.at(0); // There can be only one! (Swush, flomp)
@@ -170,9 +160,11 @@ bool MacroWindow::doCommit()
return false;
}
- emit updateOnCommit();
+ qApp->processEvents();
- setCollapsed(true);
+ emit updateOnCommit();
+ // setCollapsed(true);
+ collapse();
return true;
} else {
@@ -239,8 +231,10 @@ void MacroWindow::expandWrapper()
QVector< Widget* > widgets = mainwidget->widgetList(true);
QVector< Widget* >::iterator i = widgets.begin();
while (i != widgets.end()) {
- Widget* w = *i;
- if(w->setKeyboardFocus()) break;
+ if(*i) {
+ Widget* w = *i;
+ if(w->setKeyboardFocus()) break;
+ }
i++;
}
@@ -309,7 +303,7 @@ void MacroWindow::setActive(bool active)
void MacroWindow::clear()
{
- if(mainwidget) delete mainwidget;
+ if(mainwidget) mainwidget->deleteLater();
mainwidget = NULL;
setExpandedWidget(NULL);
@@ -317,14 +311,3 @@ void MacroWindow::clear()
luaprograms.clear();
}
-void MacroWindow::collapsed()
-{
- printf("======== Collapsed ========\n");
-
- clear();
-}
-
-void MacroWindow::expanded()
-{
- printf("======== Expanded ========\n");
-}
diff --git a/client/macrowindow.h b/client/macrowindow.h
index 803bf62..3bc02f2 100644
--- a/client/macrowindow.h
+++ b/client/macrowindow.h
@@ -48,8 +48,6 @@ public:
LUA *lua;
- // Widget *getWidget(QString name);
-
void update(QDomNode &xml_doc);
void setActive(bool active);
@@ -67,9 +65,6 @@ public slots:
void collapseWrapper();
void expandWrapper();
- void collapsed();
- void expanded();
-
signals:
void updateOnCommit();
void macroHasChanged();
diff --git a/client/netcom.cc b/client/netcom.cc
index 9056ec3..a606c62 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -48,8 +48,8 @@
#endif
#endif
-//#define DEBUG(fmt...) printf(fmt)
-#define DEBUG(ftm...)
+#define DEBUG(fmt...) printf(fmt)
+//#define DEBUG(ftm...)
NetCom::NetCom(QString host, quint16 port)
{
@@ -192,15 +192,17 @@ QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ,
// the commit string
QVector< Widget* >::iterator i = widgets.begin();
while (i != widgets.end()) {
- Widget* w = *i;
-
- if(w->enabled() && w->name() != "" && w->local() == false) {
- QDomElement field_elem = doc.createElement("field");
- field_elem.setAttribute("name", w->name());
- field_elem.setAttribute("value", w->value());
- commit_elem.appendChild(field_elem);
+ if(*i) {
+ Widget* w = *i;
+ DEBUG("W: %s: %s\n", w->name().toStdString().c_str(),
+ w->value().toStdString().c_str());
+ if(w->enabled() && w->name() != "" && w->local() == false) {
+ QDomElement field_elem = doc.createElement("field");
+ field_elem.setAttribute("name", w->name());
+ field_elem.setAttribute("value", w->value());
+ commit_elem.appendChild(field_elem);
+ }
}
-
i++;
}
diff --git a/client/netcom.h b/client/netcom.h
index 88b604e..79bb78f 100644
--- a/client/netcom.h
+++ b/client/netcom.h
@@ -46,8 +46,8 @@ public:
~NetCom();
QDomDocument send(QString templ, QString macro = "", bool lockgui = true);
- QDomDocument send(QVector< Widget* > widgets, QString templ, QString macro,
- QString version);
+ QDomDocument send(QVector< Widget* > widgets, QString templ,
+ QString macro, QString version);
QDomDocument initConnection();
QDomDocument commit();
QDomDocument discard();
diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc
index 918f152..6b231f3 100644
--- a/client/widgets/lineedit.cc
+++ b/client/widgets/lineedit.cc
@@ -89,8 +89,9 @@ void LineEdit::setValue(QString value, QString source)
{
if(isUserSource(source)) emit wasChanged();
- if(lineedit->text() == value)
- lineedit->setText(value + " "); // Hack to make sure the textChanged signal is emitted.
+ // Hack to make sure the textChanged signal is emitted.
+ if(lineedit->text() == value) lineedit->setText(value + " ");
+
lineedit->setText(value);
setInitialValue(value);
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index af03843..2205beb 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -75,12 +75,6 @@ Widget::~Widget()
name().toStdString().c_str(),
type().toStdString().c_str());
- /* // This is done by Qt
- if(widget) {
- delete widget;
- widget = NULL;
- }
- */
QVector< Widget* >::iterator i = children.begin();
while(i != children.end()) {
if(*i) delete *i;
@@ -88,6 +82,12 @@ Widget::~Widget()
}
children.clear();
+
+ // This MUST be done after the deletion of the children Widget list.
+ if(widget) {
+ delete widget;
+ widget = NULL;
+ }
}
void Widget::addChildren(QDomNode &node)
@@ -121,7 +121,7 @@ bool Widget::valid()
QVector< Widget* >::iterator i = children.begin();
while(i != children.end()) {
- if((*i)->valid() == false) return false;
+ if(*i && (*i)->valid() == false) return false;
i++;
}
@@ -194,8 +194,10 @@ Widget *Widget::findWidget(QString n, bool deep)
QVector< Widget* >::iterator i = children.begin();
while(i != children.end()) {
- Widget *w = (*i)->findWidget(n, deep);
- if(w) return w;
+ if(*i) {
+ Widget *w = (*i)->findWidget(n, deep);
+ if(w) return w;
+ }
i++;
}
@@ -212,7 +214,7 @@ QVector< Widget* > Widget::widgetList(bool deep)
QVector< Widget* >::iterator i = children.begin();
while(i != children.end()) {
- lst += (*i)->widgetList(deep);
+ if(*i) lst += (*i)->widgetList(deep);
i++;
}