[TD]allow template fields to re-apply autofill

This commit is contained in:
wandererfan
2024-06-22 18:53:13 -04:00
committed by WandererFan
parent cb2573844f
commit 55515b1e7f
6 changed files with 67 additions and 5 deletions

View File

@@ -67,6 +67,11 @@ QString DlgTemplateField::getFieldContent()
return ui->leInput->text();
}
bool DlgTemplateField::getAutofillState()
{
return ui->cbAutofill->isChecked();
}
void DlgTemplateField::accept()
{
QDialog::accept();

View File

@@ -45,6 +45,7 @@ public:
void setFieldLength(int length);
void setFieldContent(std::string content);
QString getFieldContent();
bool getAutofillState();
public Q_SLOTS:
void accept() override;

View File

@@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>340</width>
<height>90</height>
<height>127</height>
</rect>
</property>
<property name="windowTitle">
@@ -46,6 +46,16 @@
<item row="1" column="1">
<widget class="QLineEdit" name="leInput"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cbAutofill">
<property name="toolTip">
<string>Check this box to reapply autofill to this field. </string>
</property>
<property name="text">
<string>Autofill</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@@ -30,12 +30,16 @@
#endif // #ifndef _PreCmp_
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
#include <Mod/TechDraw/App/DrawSVGTemplate.h>
#include "DlgTemplateField.h"
#include "TemplateTextField.h"
using namespace TechDrawGui;
using namespace TechDraw;
TemplateTextField::TemplateTextField(QGraphicsItem *parent,
TechDraw::DrawTemplate *myTmplte,
@@ -76,12 +80,18 @@ void TemplateTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
ui.setFieldContent(tmplte->EditableTexts[fieldNameStr]);
if (ui.exec() == QDialog::Accepted) {
//WF: why is this escaped?
// "<" is converted elsewhere and no other characters cause problems.
// escaping causes "&" to appear as "&amp;" etc
// QString qsClean = ui.getFieldContent().toHtmlEscaped();
QString qsClean = ui.getFieldContent();
std::string utf8Content = qsClean.toUtf8().constData();
if (ui.getAutofillState()) {
auto svgTemplate = dynamic_cast<DrawSVGTemplate*>(tmplte);
if (svgTemplate) {
QString fieldName = Base::Tools::fromStdString(fieldNameStr);
QString autofillValue = svgTemplate->getAutofillByEditableName(fieldName);
if (!autofillValue.isEmpty()) {
utf8Content = autofillValue.toUtf8().constData();
}
}
}
tmplte->EditableTexts.setValue(fieldNameStr, utf8Content);
}