Commit 951b1120 authored by Daniel Teske's avatar Daniel Teske

Preserve user changes in custom wizard on back

Task-number: QTCREATORBUG-6774
Change-Id: I7c06f794f04b6e019a7d8b65d810096a1d9ebf82
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent 50b1d674
......@@ -356,18 +356,19 @@ void CustomWizardFieldPage::initializePage()
{
QWizardPage::initializePage();
clearError();
// Note that the field mechanism will always restore the value
// set on it when entering the page, so, there is no point in
// trying to preserve user modifications of the text.
foreach(const LineEditData &led, m_lineEdits) {
if (!led.defaultText.isEmpty()) {
if (!led.userChange.isNull()) {
led.lineEdit->setText(led.userChange);
} else if (!led.defaultText.isEmpty()) {
QString defaultText = led.defaultText;
CustomWizardContext::replaceFields(m_context->baseReplacements, &defaultText);
led.lineEdit->setText(defaultText);
}
}
foreach(const TextEditData &ted, m_textEdits) {
if (!ted.defaultText.isEmpty()) {
if (!ted.userChange.isNull()) {
ted.textEdit->setText(ted.userChange);
} else if (!ted.defaultText.isEmpty()) {
QString defaultText = ted.defaultText;
CustomWizardContext::replaceFields(m_context->baseReplacements, &defaultText);
ted.textEdit->setText(defaultText);
......@@ -375,6 +376,30 @@ void CustomWizardFieldPage::initializePage()
}
}
void CustomWizardFieldPage::cleanupPage()
{
for (int i = 0; i < m_lineEdits.count(); ++i) {
LineEditData &led = m_lineEdits[i];
QString defaultText = led.defaultText;
CustomWizardContext::replaceFields(m_context->baseReplacements, &defaultText);
if (led.lineEdit->text() != defaultText)
led.userChange = led.lineEdit->text();
else
led.userChange.clear();
}
for (int i= 0; i < m_textEdits.count(); ++i) {
TextEditData &ted = m_textEdits[i];
QString defaultText = ted.defaultText;
CustomWizardContext::replaceFields(m_context->baseReplacements, &defaultText);
if (ted.textEdit->toHtml() != ted.defaultText && ted.textEdit->toPlainText() != ted.defaultText)
ted.userChange = ted.textEdit->toHtml();
else
ted.userChange.clear();
}
QWizardPage::cleanupPage();
}
bool CustomWizardFieldPage::validatePage()
{
clearError();
......
......@@ -119,6 +119,7 @@ public:
virtual bool validatePage();
virtual void initializePage();
virtual void cleanupPage();
static QMap<QString, QString> replacementMap(const QWizard *w,
const QSharedPointer<CustomWizardContext> &ctx,
......@@ -133,11 +134,13 @@ private:
explicit LineEditData(QLineEdit* le = 0, const QString &defText = QString());
QLineEdit* lineEdit;
QString defaultText;
QString userChange;
};
struct TextEditData {
explicit TextEditData(QTextEdit* le = 0, const QString &defText = QString());
QTextEdit* textEdit;
QString defaultText;
QString userChange;
};
typedef QList<LineEditData> LineEditDataList;
typedef QList<TextEditData> TextEditDataList;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment