diff options
Diffstat (limited to 'client/widgets')
-rw-r--r-- | client/widgets/multilist.cc | 44 | ||||
-rw-r--r-- | client/widgets/multilist.h | 3 |
2 files changed, 46 insertions, 1 deletions
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 <QMessageBox> #include <QHBoxLayout> #include <QVBoxLayout> #include <QGridLayout> @@ -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__*/ |