From e1430e95969a68d7a62c5e0802fcfd606f0509d9 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 17 Mar 2009 14:35:09 +0000 Subject: A first shot at making noise when innerwidget has changed, but not added to the multilist. --- client/widgets/multilist.cc | 44 +++++++++++++++++++++++++++++++++++++++++++- client/widgets/multilist.h | 3 +++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'client') diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index dbc23b9..4d34691 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -26,6 +26,7 @@ */ #include "multilist.h" +#include #include #include #include @@ -38,6 +39,8 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { + innerwidget_has_changes = false; + setCommonAttributes(this, node); QGridLayout *layout = new QGridLayout(); @@ -97,7 +100,10 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) QString iwname = elem.attribute("innerwidget"); QVector< Widget* >::iterator ws = widgets.begin(); while(ws != widgets.end()) { - if((*ws)->getName() == iwname) innerwidget = *ws; + if((*ws)->getName() == iwname) { + innerwidget = *ws; + innerwidget->connectFrom(SIGNAL(wasChanged()), this, SLOT(changed())); + } ws++; } if(innerwidget == NULL) { @@ -113,6 +119,41 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) void MultiList::changed() { + innerwidget_has_changes = true; + printf("Multilist innerwidget was changed\n"); +} + + +bool MultiList::isValid() +{ + if(innerwidget_has_changes) { + switch(QMessageBox::warning(NULL, + "Gem ændringerne i listen?", + "Der er lavet en ændring som ikke er tilføjet til listen.\n" + "Ønsker du at tilføje ændringen til listen inden du gemmer makroen?", + QMessageBox::Save | QMessageBox::Close | QMessageBox::Cancel)) { + case QMessageBox::Save: + if(innerwidget && innerwidget->isValid()) { + add(); + } else { + QMessageBox::critical(NULL, + "Fejl", + "Der er fejl i ændringen, og den kan ikke tilføjes til listen.\n", + QMessageBox::Ok); + return false; + } + break; + case QMessageBox::Close: + break; + case QMessageBox::Cancel: + default: + // FIXME: How to we actually block the commit and return to the editor? + return false; + break; + } + } + + return regexpValidator() && luaValidator(); } QString MultiList::getValue() @@ -166,6 +207,7 @@ void MultiList::add() emit wasChanged(); innerwidget->reset(); + innerwidget_has_changes = false; } } diff --git a/client/widgets/multilist.h b/client/widgets/multilist.h index 1e8b4bd..3b0f51e 100644 --- a/client/widgets/multilist.h +++ b/client/widgets/multilist.h @@ -56,6 +56,8 @@ public: void enable(); bool isDisabled(); + bool isValid(); + public slots: void changed(); void remove(); @@ -71,6 +73,7 @@ private: QListWidget *list; Widget *innerwidget; QString format; + bool innerwidget_has_changes; }; #endif/*__PRACRO_MULTILIST_H__*/ -- cgit v1.2.3