From 04b23b582c5af6e3db6d3d4ecce497a0d5b84eb2 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 24 May 2009 12:08:51 +0300 Subject: [PATCH] User can now undo changes to application list by clicking cancel. --- gui/applicationlist.cpp | 17 ++++++++++++++++- gui/applicationlist.h | 12 ++++++++++++ gui/settingsdialog.cpp | 26 +++++++++++++++++--------- gui/settingsdialog.h | 18 ++++++++++++++++++ 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index 3bc08f635..7201a3f18 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -27,7 +27,7 @@ ApplicationList::ApplicationList() ApplicationList::~ApplicationList() { - //dtor + Clear(); } void ApplicationList::LoadSettings(QSettings &programSettings) @@ -125,3 +125,18 @@ void ApplicationList::MoveFirst(const int index) } } + +void ApplicationList::Copy(ApplicationList &list) +{ + Clear(); + for (int i=0;iaddItem(dialog.GetName()); } } @@ -207,7 +208,7 @@ void SettingsDialog::DeleteApplication() foreach(item, selected) { - mApplications.RemoveApplication(mListWidget->row(item)); + mTempApplications.RemoveApplication(mListWidget->row(item)); mListWidget->clear(); PopulateListWidget(); } @@ -221,13 +222,13 @@ void SettingsDialog::ModifyApplication() { int row = mListWidget->row(item); - ApplicationDialog dialog(mApplications.GetApplicationName(row), - mApplications.GetApplicationPath(row), + ApplicationDialog dialog(mTempApplications.GetApplicationName(row), + mTempApplications.GetApplicationPath(row), tr("Modify an application")); if (dialog.exec() == QDialog::Accepted) { - mApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath()); + mTempApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath()); item->setText(dialog.GetName()); } } @@ -239,7 +240,7 @@ void SettingsDialog::DefaultApplication() if (selected.size() > 0) { int index = mListWidget->row(selected[0]); - mApplications.MoveFirst(index); + mTempApplications.MoveFirst(index); mListWidget->clear(); PopulateListWidget(); } @@ -247,9 +248,16 @@ void SettingsDialog::DefaultApplication() void SettingsDialog::PopulateListWidget() { - for (int i = 0;i < mApplications.GetApplicationCount();i++) + for (int i = 0;i < mTempApplications.GetApplicationCount();i++) { - mListWidget->addItem(mApplications.GetApplicationName(i)); + mListWidget->addItem(mTempApplications.GetApplicationName(i)); } } +void SettingsDialog::Ok() +{ + mApplications.Copy(mTempApplications); + accept(); +} + + diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index c99eadb20..7a086971a 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -52,6 +52,11 @@ public: void SaveCheckboxValues(); protected slots: + /** + * @brief Slot for clicking OK. + * + */ + void Ok(); /** * @brief Slot for adding a new application to the list @@ -77,7 +82,13 @@ protected slots: */ void DefaultApplication(); protected: + + /** + * @brief Clear all applications from the list and re insert them from mTempApplications + * + */ void PopulateListWidget(); + /** * @brief Load saved values * Loads dialog size and column widths. @@ -160,6 +171,13 @@ protected: * */ ApplicationList &mApplications; + + /** + * @brief Temporary list of applications + * This will be copied to actual list of applications (mApplications) + * when user clicks ok. + */ + ApplicationList mTempApplications; private: };