User can now undo changes to application list by clicking cancel.
This commit is contained in:
parent
9bb0cff511
commit
04b23b582c
|
@ -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;i<list.GetApplicationCount();i++)
|
||||
{
|
||||
AddApplicationType(list.GetApplicationName(i),list.GetApplicationPath(i));
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationList::Clear()
|
||||
{
|
||||
mApplications.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -138,8 +138,20 @@ public:
|
|||
* @param index Index of the application to make the default one
|
||||
*/
|
||||
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:
|
||||
|
||||
/**
|
||||
* @brief Clear the list
|
||||
*
|
||||
*/
|
||||
void Clear();
|
||||
/**
|
||||
* @brief List of applications
|
||||
*
|
||||
|
|
|
@ -28,6 +28,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
|
|||
mSettings(programSettings),
|
||||
mApplications(list)
|
||||
{
|
||||
mTempApplications.Copy(list);
|
||||
//Create a layout for the settings dialog
|
||||
QVBoxLayout *dialoglayout = new QVBoxLayout();
|
||||
|
||||
|
@ -49,7 +50,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
|
|||
|
||||
//Connect OK buttons
|
||||
connect(ok, SIGNAL(clicked()),
|
||||
this, SLOT(accept()));
|
||||
this, SLOT(Ok()));
|
||||
connect(cancel, SIGNAL(clicked()),
|
||||
this, SLOT(reject()));
|
||||
|
||||
|
@ -194,7 +195,7 @@ void SettingsDialog::AddApplication()
|
|||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
mApplications.AddApplicationType(dialog.GetName(), dialog.GetPath());
|
||||
mTempApplications.AddApplicationType(dialog.GetName(), dialog.GetPath());
|
||||
mListWidget->addItem(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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue