Commit 497b2ae4 authored by Lorenz Haas's avatar Lorenz Haas Committed by Eike Ziller

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: default avatarLorenz Haas <lykurg@gmail.com>
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 15086363
......@@ -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
......
......@@ -498,12 +498,6 @@ QMap<QString, QString> 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;
}
......
......@@ -37,17 +37,18 @@
#include <utils/qtcassert.h>
#include <QDebug>
#include <QCoreApplication>
#include <QFile>
#include <QDate>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QXmlStreamReader>
#include <QXmlStreamAttribute>
#include <QTemporaryFile>
#include <QScriptEngine>
#include <QIcon>
#include <QScriptEngine>
#include <QTemporaryFile>
#include <QTime>
#include <QXmlStreamAttribute>
#include <QXmlStreamReader>
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();
......
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