summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2009-03-17 14:35:09 +0000
committerdeva <deva>2009-03-17 14:35:09 +0000
commite1430e95969a68d7a62c5e0802fcfd606f0509d9 (patch)
tree2c2424c9be93a10fcfeca1ed25f57a63c880c425
parentac305d7f0df02add5f991d6d9ff01fc2fc26f02f (diff)
A first shot at making noise when innerwidget has changed, but not added to the multilist.
-rw-r--r--client/widgets/multilist.cc44
-rw-r--r--client/widgets/multilist.h3
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__*/