User can now undo changes to application list by clicking cancel.

This commit is contained in:
Vesa Pikki 2009-05-24 12:08:51 +03:00
parent 9bb0cff511
commit 04b23b582c
4 changed files with 63 additions and 10 deletions

View File

@ -27,7 +27,7 @@ ApplicationList::ApplicationList()
ApplicationList::~ApplicationList() ApplicationList::~ApplicationList()
{ {
//dtor Clear();
} }
void ApplicationList::LoadSettings(QSettings &programSettings) 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;i<list.GetApplicationCount();i++)
{
AddApplicationType(list.GetApplicationName(i),list.GetApplicationPath(i));
}
}
void ApplicationList::Clear()
{
mApplications.clear();
}

View File

@ -138,8 +138,20 @@ public:
* @param index Index of the application to make the default one * @param index Index of the application to make the default one
*/ */
void MoveFirst(const int index); void MoveFirst(const int index);
/**
* @brief Remove all applications from this list and copy all applications from
* list given as a parameter.
* @param list Copying source
*/
void Copy(ApplicationList &list);
protected: protected:
/**
* @brief Clear the list
*
*/
void Clear();
/** /**
* @brief List of applications * @brief List of applications
* *

View File

@ -28,6 +28,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
mSettings(programSettings), mSettings(programSettings),
mApplications(list) mApplications(list)
{ {
mTempApplications.Copy(list);
//Create a layout for the settings dialog //Create a layout for the settings dialog
QVBoxLayout *dialoglayout = new QVBoxLayout(); QVBoxLayout *dialoglayout = new QVBoxLayout();
@ -49,7 +50,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
//Connect OK buttons //Connect OK buttons
connect(ok, SIGNAL(clicked()), connect(ok, SIGNAL(clicked()),
this, SLOT(accept())); this, SLOT(Ok()));
connect(cancel, SIGNAL(clicked()), connect(cancel, SIGNAL(clicked()),
this, SLOT(reject())); this, SLOT(reject()));
@ -194,7 +195,7 @@ void SettingsDialog::AddApplication()
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
{ {
mApplications.AddApplicationType(dialog.GetName(), dialog.GetPath()); mTempApplications.AddApplicationType(dialog.GetName(), dialog.GetPath());
mListWidget->addItem(dialog.GetName()); mListWidget->addItem(dialog.GetName());
} }
} }
@ -207,7 +208,7 @@ void SettingsDialog::DeleteApplication()
foreach(item, selected) foreach(item, selected)
{ {
mApplications.RemoveApplication(mListWidget->row(item)); mTempApplications.RemoveApplication(mListWidget->row(item));
mListWidget->clear(); mListWidget->clear();
PopulateListWidget(); PopulateListWidget();
} }
@ -221,13 +222,13 @@ void SettingsDialog::ModifyApplication()
{ {
int row = mListWidget->row(item); int row = mListWidget->row(item);
ApplicationDialog dialog(mApplications.GetApplicationName(row), ApplicationDialog dialog(mTempApplications.GetApplicationName(row),
mApplications.GetApplicationPath(row), mTempApplications.GetApplicationPath(row),
tr("Modify an application")); tr("Modify an application"));
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
{ {
mApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath()); mTempApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath());
item->setText(dialog.GetName()); item->setText(dialog.GetName());
} }
} }
@ -239,7 +240,7 @@ void SettingsDialog::DefaultApplication()
if (selected.size() > 0) if (selected.size() > 0)
{ {
int index = mListWidget->row(selected[0]); int index = mListWidget->row(selected[0]);
mApplications.MoveFirst(index); mTempApplications.MoveFirst(index);
mListWidget->clear(); mListWidget->clear();
PopulateListWidget(); PopulateListWidget();
} }
@ -247,9 +248,16 @@ void SettingsDialog::DefaultApplication()
void SettingsDialog::PopulateListWidget() 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();
}

View File

@ -52,6 +52,11 @@ public:
void SaveCheckboxValues(); void SaveCheckboxValues();
protected slots: protected slots:
/**
* @brief Slot for clicking OK.
*
*/
void Ok();
/** /**
* @brief Slot for adding a new application to the list * @brief Slot for adding a new application to the list
@ -77,7 +82,13 @@ protected slots:
*/ */
void DefaultApplication(); void DefaultApplication();
protected: protected:
/**
* @brief Clear all applications from the list and re insert them from mTempApplications
*
*/
void PopulateListWidget(); void PopulateListWidget();
/** /**
* @brief Load saved values * @brief Load saved values
* Loads dialog size and column widths. * Loads dialog size and column widths.
@ -160,6 +171,13 @@ protected:
* *
*/ */
ApplicationList &mApplications; ApplicationList &mApplications;
/**
* @brief Temporary list of applications
* This will be copied to actual list of applications (mApplications)
* when user clicks ok.
*/
ApplicationList mTempApplications;
private: private:
}; };