diff options
-rw-r--r-- | client/macrowindow.cc | 2 | ||||
-rw-r--r-- | client/widgets/multilist.cc | 33 | ||||
-rw-r--r-- | client/widgets/multilist.h | 9 | ||||
-rw-r--r-- | client/widgets/widget.cc | 22 | ||||
-rw-r--r-- | client/widgets/widget.h | 14 |
5 files changed, 57 insertions, 23 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 00eb1ed..bbfab8e 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -165,6 +165,8 @@ void MacroWindow::initMacro(QDomNode &node) bool MacroWindow::doCommit() { + if(mainwidget->committable(true) == false) return false; + if(mainwidget->valid()) { QVector< Widget* > wlist; diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index 3d03ce5..e261b52 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -126,36 +126,23 @@ void MultiList::changed() DEBUG(multilist, "Multilist innerwidget was changed\n"); } - -bool MultiList::preValid() +bool MultiList::preCommit() { - return list->count() != 0; - - /* if(innerwidget_has_changes) { switch(MessageBox::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?", - MessageBox::Save | MessageBox::Close | MessageBox::Cancel)) { - case MessageBox::Save: - if(innerwidget && innerwidget->valid()) { - add(); - } else { - return false; - } - break; - case MessageBox::Close: + tr("Inner widget changed."), + tr("The inner widget changed, and you didn't add it to the list.\n" + "Do you want to continue and discard the change?"), + MessageBox::Ignore | MessageBox::Cancel)) { + case MessageBox::Ignore: break; case MessageBox::Cancel: default: - // FIXME: How to we actually block the commit and return to the editor? return false; - break; } } + return true; - */ } QString MultiList::value() @@ -218,6 +205,12 @@ void MultiList::add() } } +void MultiList::setValues() +{ + Widget::setValues(); + innerwidget_has_changes = false; +} + bool MultiList::setKeyboardFocus() { if(innerwidget) return innerwidget->setKeyboardFocus(); diff --git a/client/widgets/multilist.h b/client/widgets/multilist.h index e86df28..878603f 100644 --- a/client/widgets/multilist.h +++ b/client/widgets/multilist.h @@ -60,11 +60,12 @@ public: QString value(); void setValue(QString value, QString source = ""); - bool preValid(); void setWdgValid(bool valid); bool setKeyboardFocus(); + void setValues(); + public slots: void changed(); void remove(); @@ -73,6 +74,12 @@ public slots: protected: bool eventFilter(QObject *obj, QEvent *event); + // Implement in subclasses to be able to block commits. + bool preCommit(); + + // Don't connect children 'wasChanged' signal to parent. + void connectChild(Widget *) {} + private: QListWidget *list; Widget *innerwidget; diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index 33e4309..c0c9e81 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -118,6 +118,21 @@ bool Widget::local() return widget_local; } +bool Widget::committable(bool deep) +{ + if(preCommit() == false) return false; + + if(deep == false) return true; + + QVector< Widget* >::iterator i = children.begin(); + while(i != children.end()) { + if(*i && (*i)->committable(deep) == false) return false; + i++; + } + + return true; +} + bool Widget::valid(bool deep) { if(enabled() == false) return true; @@ -288,6 +303,11 @@ void Widget::childWasChanged() emit wasChanged(); } +void Widget::connectChild(Widget *child) +{ + connect(child, SIGNAL(wasChanged()), this, SLOT(childWasChanged())); +} + void Widget::addChild(Widget *widget) { if(widget == NULL) { @@ -296,7 +316,7 @@ void Widget::addChild(Widget *widget) return; } children.push_back(widget); - connect(widget, SIGNAL(wasChanged()), this, SLOT(childWasChanged())); + connectChild(widget); //widget->setParent(this); } diff --git a/client/widgets/widget.h b/client/widgets/widget.h index bb37c51..3de148f 100644 --- a/client/widgets/widget.h +++ b/client/widgets/widget.h @@ -52,6 +52,9 @@ * value. * @att help This attribute contains a help text for this widget. It will be * shown to the user when the mouse is hovering over the widget. + * @att local This attribute is a boolean telling wether the field can be stored + * in the database on commits. It can be either 'true' or 'false'. The default + * is 'false'. */ class QLayout; @@ -75,6 +78,9 @@ public: bool valid(bool deep = false); void setValid(bool valid, bool deep = false); + // Make sanity check before commit. + bool committable(bool deep = false); + // Implement in subclasses to contribute to the validation. virtual bool preValid() { return true; } @@ -95,7 +101,8 @@ public: Widget *findWidget(QString name, bool deep = false); QVector< Widget* > widgetList(bool deep = false); void addChild(Widget *widget); - void setValues(); + + virtual void setValues(); signals: void wasChanged(); @@ -115,6 +122,11 @@ protected: QWidget *widget; bool hideChildren; + // Implement in subclasses to be able to block commits. + virtual bool preCommit() { return true; } + + // Overload this to avoid children 'wasChanged' connection. + virtual void connectChild(Widget *child); void addChildren(QDomNode &xml_node, QLayout *layout); LUA *lua; |