diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-05 15:23:26 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-05 15:23:26 -0500 |
| commit | 48769da9bfbf905fab2e6ee1fa45cd9a7cda37a5 (patch) | |
| tree | 3749fd721ae1279e31092de6a25c8ec50a861a89 | |
| parent | 6e43bdc93569f9fdfa6747b2c215a74b8780886c (diff) | |
| download | sigen-48769da9bfbf905fab2e6ee1fa45cd9a7cda37a5.tar.gz sigen-48769da9bfbf905fab2e6ee1fa45cd9a7cda37a5.tar.xz sigen-48769da9bfbf905fab2e6ee1fa45cd9a7cda37a5.zip | |
Fix management of the editor widget when changing widgets and closing games
| -rw-r--r-- | sigmodr/SigmodrUI.cpp | 44 | ||||
| -rw-r--r-- | sigmodr/SigmodrUI.h | 1 |
2 files changed, 28 insertions, 17 deletions
diff --git a/sigmodr/SigmodrUI.cpp b/sigmodr/SigmodrUI.cpp index 7a0afc9b..98dfdf5a 100644 --- a/sigmodr/SigmodrUI.cpp +++ b/sigmodr/SigmodrUI.cpp @@ -355,6 +355,29 @@ void SigmodrUI::uploadGame(const Game* game) } } +bool SigmodrUI::closeWidget() +{ + bool closed = true; + if (formPanel->widget() && boxButtons->isEnabled()) + { + switch (KMessageBox::questionYesNoCancel(this, "You have unsaved changes, would you like to save them?", QString("Unsaved %1").arg(qobject_cast<ObjectUI*>(formPanel->widget())->object()->className()))) + { + case KMessageBox::Yes: + qobject_cast<ObjectUI*>(formPanel->widget())->apply(); + break; + case KMessageBox::No: + qobject_cast<ObjectUI*>(formPanel->widget())->discard(); + break; + case KMessageBox::Cancel: + closed = false; + break; + } + } + if (closed) + delete formPanel->takeWidget(); + return closed; +} + void SigmodrUI::closeGame() { closeGame(treeSigmod->currentGame()); @@ -365,6 +388,9 @@ bool SigmodrUI::closeGame(const Game* game, const bool force) { if (game) { + const ObjectUI* widget = qobject_cast<ObjectUI*>(formPanel->widget()); + if (widget && (game == widget->object()->game()) && !closeWidget()) + return false; if (treeSigmod->dirty(game)) { int result; @@ -383,8 +409,6 @@ bool SigmodrUI::closeGame(const Game* game, const bool force) } } treeSigmod->deleteGame(game); - if (formPanel->widget()) - delete formPanel->takeWidget(); } return true; } @@ -446,22 +470,8 @@ void Sigmodr::SigmodrUI::on_treeSigmod_clicked(const QModelIndex& index) if (!(treeSigmod->model()->flags(index) & Qt::ItemIsSelectable)) return; ObjectUI* widget = treeSigmod->editorWidget(index); - if (widget) + if (widget && closeWidget()) { - if (formPanel->widget() && boxButtons->isEnabled()) - { - switch (KMessageBox::questionYesNoCancel(this, "You have unsaved changes, would you like to save them?", QString("Unsaved %1").arg(qobject_cast<ObjectUI*>(formPanel->widget())->object()->className()))) - { - case KMessageBox::Yes: - qobject_cast<ObjectUI*>(formPanel->widget())->apply(); - break; - case KMessageBox::No: - qobject_cast<ObjectUI*>(formPanel->widget())->discard(); - break; - case KMessageBox::Cancel: - return; - } - } boxButtons->setEnabled(false); connect(widget, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool))); connect(widget, SIGNAL(saved()), this, SLOT(setDirty())); diff --git a/sigmodr/SigmodrUI.h b/sigmodr/SigmodrUI.h index 475fe7fb..3713b80f 100644 --- a/sigmodr/SigmodrUI.h +++ b/sigmodr/SigmodrUI.h @@ -76,6 +76,7 @@ class SigmodrUI : public KXmlGuiWindow, private Ui::formSigmodr void downloadGame(); void uploadGame(); void uploadGame(const Sigmod::Game* game); + bool closeWidget(); void closeGame(); bool closeGame(const Sigmod::Game* game, const bool force = false); bool closeAllGames(const bool force = false); |
