[TD]respect locale for date autofill (#18132)

* [TD]respect locale for date autofill

* [TD]fix merge conflict

* Apply suggestions from code review

---------

Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
WandererFan
2024-12-13 12:07:54 -05:00
committed by GitHub
parent d835cde3a5
commit 8b7cbae43b
6 changed files with 344 additions and 307 deletions

View File

@@ -37,6 +37,7 @@
#include "DrawTemplatePy.h"
#include "DrawPage.h"
#include "DrawUtil.h"
#include "Preferences.h"
using namespace TechDraw;
@@ -129,6 +130,7 @@ std::pair<int, int> DrawTemplate::getPageNumbers() const
//! get replacement values from document
QString DrawTemplate::getAutofillValue(const QString &id) const
{
constexpr int ISODATELENGTH {10};
auto doc = getDocument();
if (!doc) {
return QString();
@@ -142,8 +144,14 @@ QString DrawTemplate::getAutofillValue(const QString &id) const
}
// date
else if (id.compare(QString::fromUtf8(Autofill::Date)) == 0) {
auto timeLocale = std::setlocale(LC_TIME, nullptr);
QDateTime date = QDateTime::currentDateTime();
return date.toString(QLocale().dateFormat(QLocale::ShortFormat));
if (Preferences::enforceISODate()) {
auto rawDate = date.toString(Qt::ISODate);
return rawDate.left(ISODATELENGTH);
}
auto qTimeLocale = QString::fromUtf8(timeLocale);
return date.toString(QLocale(qTimeLocale).dateFormat(QLocale::ShortFormat));
}
// organization ( also organisation/owner/company )
else if (id.compare(QString::fromUtf8(Autofill::Organization)) == 0 ||

View File

@@ -650,6 +650,11 @@ void Preferences::setBalloonDragModifiers(Qt::KeyboardModifiers newModifiers)
getPreferenceGroup("General")->SetUnsigned("BalloonDragModifier", (uint)newModifiers);
}
bool Preferences::enforceISODate()
{
return getPreferenceGroup("Standards")->GetBool("EnforceISODate", false);
}
//! if true, shapes are validated before use and problematic ones are skipped.
//! validating shape takes time, but can prevent crashes/bad results in occt.
//! this would normally be set to false and set to true to aid in debugging/support.

View File

@@ -151,6 +151,7 @@ public:
static Qt::KeyboardModifiers balloonDragModifiers();
static void setBalloonDragModifiers(Qt::KeyboardModifiers newModifiers);
static bool enforceISODate();
static bool switchOnClick();
static bool checkShapesBeforeUse();