[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();

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>795</height>
<width>835</width>
<height>956</height>
</rect>
</property>
<property name="sizePolicy">
@@ -28,231 +28,6 @@
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="2,0,1">
<item row="9" column="2">
<widget class="Gui::PrefUnitSpinBox" name="pdsbBalloonKink">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Length of balloon leader line kink</string>
</property>
<property name="value">
<double>5.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>BalloonKink</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Dimensions</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="Gui::PrefCheckBox" name="pcbDetailHighlight">
<property name="toolTip">
<string>This checkbox controls whether or not to display a highlight around the detail area in the detail's source view.</string>
</property>
<property name="text">
<string>Detail Source Show Highlight</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowDetailHighlight</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_19">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Section Cut Surface</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="Gui::PrefComboBox" name="pcbBalloonArrow">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Style for balloon leader line ends</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>BalloonArrow</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Balloon Leader End</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Gui::PrefCheckBox" name="cb_IncludeCutLine">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>If checked, the cut line will be drawn on the Source view. If unchecked, only the change marks, arrows and symbols will be displayed.</string>
</property>
<property name="text">
<string>Include Cut Line in Section Annotation</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>IncludeCutLine</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="Gui::PrefCheckBox" name="cbComplexMarks">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>Show or hide marks at direction changes on ComplexSection lines.</string>
</property>
<property name="text">
<string>Complex Section Line Marks</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>SectionLineMarks</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="Gui::PrefCheckBox" name="pcbDetailMatting">
<property name="toolTip">
<string>This checkbox controls whether or not to display the outline around a detail view.</string>
</property>
<property name="text">
<string>Detail View Show Matting</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowDetailMatting</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Gui::PrefCheckBox" name="cb_ShowSectionLine">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>If checked, the section annotation will be drawn on the Source view. If unchecked, no section line, arrows or symbol will be shown in the Source view.</string>
</property>
<property name="text">
<string>Show Section Line in Source View</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowSectionLine</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<italic>false</italic>
</font>
</property>
<property name="text">
<string>Detail View Outline Shape</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="Gui::PrefCheckBox" name="cbPyramidOrtho">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Restrict Filled Triangle line end to vertical or horizontal directions</string>
</property>
<property name="text">
<string>Balloon Orthogonal Triangle</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>PyramidOrtho</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="12" column="2">
<widget class="Gui::PrefCheckBox" name="cbPrintCenterMarks">
<property name="sizePolicy">
@@ -275,36 +50,6 @@
</property>
</widget>
</item>
<item row="10" column="2">
<widget class="Gui::PrefCheckBox" name="cbAutoHoriz">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>Forces last leader line segment to be horizontal</string>
</property>
<property name="text">
<string>Leader Line Auto Horizontal</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>AutoHorizontal</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/LeaderLine</cstring>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="Gui::PrefCheckBox" name="cbShowCenterMarks">
<property name="sizePolicy">
@@ -335,15 +80,141 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<item row="1" column="0">
<widget class="Gui::PrefCheckBox" name="cb_ShowSectionLine">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>If checked, the section annotation will be drawn on the Source view. If unchecked, no section line, arrows or symbol will be shown in the Source view.</string>
</property>
<property name="text">
<string>Show Section Line in Source View</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowSectionLine</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="Gui::PrefComboBox" name="pcbBalloonShape">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Shape of balloon annotations</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>BalloonShape</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Gui::PrefCheckBox" name="cb_IncludeCutLine">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>If checked, the cut line will be drawn on the Source view. If unchecked, only the change marks, arrows and symbols will be displayed.</string>
</property>
<property name="text">
<string>Include Cut Line in Section Annotation</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>IncludeCutLine</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="Gui::PrefComboBox" name="pcbBalloonArrow">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Style for balloon leader line ends</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>BalloonArrow</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_18">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>Length of horizontal portion of Balloon leader</string>
</property>
<property name="text">
<string>Balloon Leader Kink Length</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Balloon Shape</string>
<string>Broken View Break Type</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="Gui::PrefCheckBox" name="cbPyramidOrtho">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Restrict Filled Triangle line end to vertical or horizontal directions</string>
</property>
<property name="text">
<string>Balloon Orthogonal Triangle</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>PyramidOrtho</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
@@ -383,68 +254,108 @@
</item>
</widget>
</item>
<item row="4" column="2">
<widget class="Gui::PrefComboBox" name="pcbMatting">
<item row="5" column="0">
<widget class="Gui::PrefCheckBox" name="pcbDetailMatting">
<property name="toolTip">
<string>This checkbox controls whether or not to display the outline around a detail view.</string>
</property>
<property name="text">
<string>Detail View Show Matting</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowDetailMatting</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="Gui::PrefCheckBox" name="pcbDetailHighlight">
<property name="toolTip">
<string>This checkbox controls whether or not to display a highlight around the detail area in the detail's source view.</string>
</property>
<property name="text">
<string>Detail Source Show Highlight</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowDetailHighlight</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<italic>false</italic>
</font>
</property>
<property name="text">
<string>Detail View Outline Shape</string>
</property>
</widget>
</item>
<item row="10" column="2">
<widget class="Gui::PrefCheckBox" name="cbAutoHoriz">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Outline shape for detail views</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>MattingStyle</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="Gui::PrefComboBox" name="pcbBalloonShape">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Shape of balloon annotations</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>BalloonShape</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_18">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>Length of horizontal portion of Balloon leader</string>
<string>Forces last leader line segment to be horizontal</string>
</property>
<property name="text">
<string>Balloon Leader Kink Length</string>
<string>Leader Line Auto Horizontal</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>AutoHorizontal</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/LeaderLine</cstring>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_11">
<item row="4" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Broken View Break Type</string>
<string>Balloon Leader End</string>
</property>
</widget>
</item>
@@ -476,6 +387,111 @@
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Balloon Shape</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_19">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Section Cut Surface</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="Gui::PrefComboBox" name="pcbMatting">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Outline shape for detail views</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>MattingStyle</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="Gui::PrefCheckBox" name="cbComplexMarks">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>Show or hide marks at direction changes on ComplexSection lines.</string>
</property>
<property name="text">
<string>Complex Section Line Marks</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>SectionLineMarks</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="Gui::PrefUnitSpinBox" name="pdsbBalloonKink" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Length of balloon leader line kink</string>
</property>
<property name="value" stdset="0">
<double>5.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>BalloonKink</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Dimensions</cstring>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="Gui::PrefCheckBox" name="cbISODates">
<property name="toolTip">
<string>If this box is checked, templates will auto fill date fields using ccyy-mm-dd format even if that is not the standard format for the current locale.</string>
</property>
<property name="text">
<string>Enforce ISO 8601 Date Format</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>EnforceISODate</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Standards</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@@ -507,7 +523,7 @@
<number>6</number>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
</property>
<property name="iconSize">
<size>
@@ -775,7 +791,7 @@ if you are planning to use a drawing as a 1:1 cutting guide.
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -837,7 +853,7 @@ if you are planning to use a drawing as a 1:1 cutting guide.
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -871,8 +887,6 @@ if you are planning to use a drawing as a 1:1 cutting guide.
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Resources/TechDraw.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

View File

@@ -127,6 +127,7 @@ void DlgPrefsTechDrawAnnotationImp::saveSettings()
ui->pcbBreakType->onSave();
ui->pcbBreakStyle->onSave();
ui->cbISODates->onSave();
}
void DlgPrefsTechDrawAnnotationImp::loadSettings()
@@ -186,6 +187,7 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings()
loadLineStyleBoxes();
ui->pcbBreakType->onRestore();
ui->cbISODates->onRestore();
}
/**

View File

@@ -77,14 +77,21 @@ void TemplateTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
ui.setFieldName(fieldNameStr);
ui.setFieldContent(tmplte->EditableTexts[fieldNameStr]);
auto qName = QString::fromStdString(fieldNameStr);
auto svgTemplate = dynamic_cast<DrawSVGTemplate*>(tmplte);
if (svgTemplate) {
// preset the autofill with the current value - something might have changed since this field was created
m_autofillString = svgTemplate->getAutofillByEditableName(qName);
}
ui.setAutofillContent(m_autofillString.toStdString());
if (ui.exec() == QDialog::Accepted) {
QString qsClean = ui.getFieldContent();
std::string utf8Content = qsClean.toUtf8().constData();
if (ui.getAutofillState()) {
auto svgTemplate = dynamic_cast<DrawSVGTemplate*>(tmplte);
if (svgTemplate) {
// unlikely, but something could have changed since we grabbed the autofill value
QString fieldName = QString::fromStdString(fieldNameStr);
QString autofillValue = svgTemplate->getAutofillByEditableName(fieldName);
if (!autofillValue.isEmpty()) {