From 497b2ae45dbc996a9a8e7a655734eaf25124c549 Mon Sep 17 00:00:00 2001 From: Lorenz Haas Date: Mon, 12 Aug 2013 15:59:52 +0200 Subject: [PATCH] CustomWizard: Support current date and time in default texts This provides the functionality for the documented, but not working, %CurrentDate% and %CurrentTime%. Changes these two to locale independent format YYYY-MM-DD and HH:MM:SS. Also adds explicit variants %CurrentDate:ISO%, %CurrentTime:ISO%, %CurrentDate:RFC%, %CurrentTime:RFC%, %CurrentDate:Locale% and %CurrentTime:Locale% which format the date and time as described by ISO 8601, RFC 2822 and the Locale respectively. Task-number: QTCREATORBUG-9963 Change-Id: I39a5c0f3b606559bf4f5c5e40e421f338de4c5a4 Reviewed-by: Lorenz Haas Reviewed-by: Leena Miettinen Reviewed-by: Eike Ziller --- .../creator-projects-custom-wizards.qdoc | 24 +++++++++++-- .../customwizard/customwizardpage.cpp | 6 ---- .../customwizard/customwizardparameters.cpp | 35 ++++++++++++++----- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/doc/src/projects/creator-projects-custom-wizards.qdoc b/doc/src/projects/creator-projects-custom-wizards.qdoc index 943d5572068..d4fc42504cb 100644 --- a/doc/src/projects/creator-projects-custom-wizards.qdoc +++ b/doc/src/projects/creator-projects-custom-wizards.qdoc @@ -585,10 +585,28 @@ which is also defined in \gui {File Naming}. \li \c {%CurrentDate%} is replaced by the current date in the format - \c {yyyy-MM-dd}. + \c {YYYY-MM-DD} as specified by ISO 8601. - \li \c {%CurrentTime%} is replaced by the current time in the short - format of the locale. + \li \c {%CurrentTime%} is replaced by the current time in the format + \c {HH:MM:SS} as specified by ISO 8601. + + \li \c {%CurrentDate:Locale%} is replaced by the current date in the short format + specified by the application's locale. + + \li \c {%CurrentTime:Locale%} is replaced by the current time in the short format + specified by the application's locale. + + \li \c {%CurrentDate:ISO%} is replaced by the current date in the format + \c {YYYY-MM-DD} as specified by ISO 8601. + + \li \c {%CurrentTime:ISO%} is replaced by the current time in the format + \c {HH:MM:SS} as specified by ISO 8601. + + \li \c {%CurrentDate:RFC%} is replaced by the current date in the format + \c {DD Mon YYYY}, where \c {Mon} is the three letter month name, as specified by RFC 2822. + + \li \c {%CurrentTime:RFC%} is replaced by the current time in the format + \c {HH:MM:SS} as specified by RFC 2822. \endlist diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp index 379819824ff..18819336233 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp @@ -498,12 +498,6 @@ QMap CustomWizardFieldPage::replacementMap(const QWizard *w, fieldReplacementMap.insert(QLatin1String("Path"), QDir::toNativeSeparators(ctx->path)); fieldReplacementMap.insert(QLatin1String("TargetPath"), QDir::toNativeSeparators(ctx->targetPath)); - // Insert additional pre-defined variables - fieldReplacementMap.insert(QLatin1String("CurrentDate"), - QDate::currentDate().toString(QLatin1String("yyyy-MM-dd"))); - fieldReplacementMap.insert(QLatin1String("CurrentTime"), - QTime::currentTime().toString(QLocale::system(). - timeFormat(QLocale::ShortFormat))); return fieldReplacementMap; } diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp index ff45d9b0466..46ae852e3cb 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp @@ -37,17 +37,18 @@ #include -#include #include -#include +#include +#include #include +#include #include -#include -#include -#include -#include - #include +#include +#include +#include +#include +#include enum { debug = 0 }; @@ -969,12 +970,30 @@ bool CustomWizardContext::replaceFields(const FieldReplacementMap &fm, QString * void CustomWizardContext::reset() { - // Basic replacement fields: Suffixes. + // Basic replacement fields: Suffixes and date/time. + const QDate currentDate = QDate::currentDate(); + const QTime currentTime = QTime::currentTime(); baseReplacements.clear(); baseReplacements.insert(QLatin1String("CppSourceSuffix"), MimeDatabase::preferredSuffixByType(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE))); baseReplacements.insert(QLatin1String("CppHeaderSuffix"), MimeDatabase::preferredSuffixByType(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))); + baseReplacements.insert(QLatin1String("CurrentDate"), + currentDate.toString(Qt::ISODate)); + baseReplacements.insert(QLatin1String("CurrentTime"), + currentTime.toString(Qt::ISODate)); + baseReplacements.insert(QLatin1String("CurrentDate:ISO"), + currentDate.toString(Qt::ISODate)); + baseReplacements.insert(QLatin1String("CurrentTime:ISO"), + currentTime.toString(Qt::ISODate)); + baseReplacements.insert(QLatin1String("CurrentDate:RFC"), + currentDate.toString(Qt::RFC2822Date)); + baseReplacements.insert(QLatin1String("CurrentTime:RFC"), + currentTime.toString(Qt::RFC2822Date)); + baseReplacements.insert(QLatin1String("CurrentDate:Locale"), + currentDate.toString(Qt::DefaultLocaleShortDate)); + baseReplacements.insert(QLatin1String("CurrentTime:Locale"), + currentTime.toString(Qt::DefaultLocaleShortDate)); replacements.clear(); path.clear(); targetPath.clear();