Label %mFileName% file name punctuation. Closes #188

This commit is contained in:
Roman Telezhynskyi 2023-11-16 12:16:20 +02:00
parent c026f42689
commit 111d8950fd
3 changed files with 58 additions and 8 deletions

View File

@ -54,6 +54,7 @@
- Support for custom known measurements.
- Allow negative values.
- Tape app. New feature: Always keep on top.
- [smart-pattern/valentina#188] Label %mFileName% file name punctuation.
# Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru.

View File

@ -66,6 +66,31 @@ Q_GLOBAL_STATIC(QVector<TextLine>, m_patternLabelLinesCache) // NOLINT
QT_WARNING_POP
//---------------------------------------------------------------------------------------------------------------------
auto FileBaseName(const QString &filePath) -> QString
{
// Known suffixes to check for
QStringList knownSuffixes = {".val", ".vst", ".vit"};
QFileInfo fileInfo(filePath);
// Check if the file has one of the known suffixes
for (const QString &suffix : knownSuffixes)
{
if (fileInfo.completeSuffix().endsWith(suffix, Qt::CaseInsensitive))
{
// Remove the known suffix and return the modified file name
QString modifiedFileName = fileInfo.fileName();
modifiedFileName.chop(suffix.length());
return modifiedFileName;
}
}
// Fallback to QFileInfo::baseName if no known suffix is found
return fileInfo.baseName();
}
//---------------------------------------------------------------------------------------------------------------------
auto SplitTextByWidth(const QString &text, const QFont &font, int maxWidth) -> QStringList
{
QFontMetrics fontMetrics(font);
@ -467,8 +492,8 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data, bo
PrepareCustomerPlaceholders(doc, placeholders);
placeholders.insert(pl_pExt, QStringLiteral("val"));
placeholders.insert(pl_pFileName, QFileInfo(VAbstractValApplication::VApp()->GetPatternPath()).baseName());
placeholders.insert(pl_mFileName, QFileInfo(doc->MPath()).baseName());
placeholders.insert(pl_pFileName, FileBaseName(VAbstractValApplication::VApp()->GetPatternPath()));
placeholders.insert(pl_mFileName, FileBaseName(doc->MPath()));
PrepareDimensionPlaceholders(placeholders);

View File

@ -55,6 +55,33 @@
using namespace Qt::Literals::StringLiterals;
namespace
{
//---------------------------------------------------------------------------------------------------------------------
auto FileBaseName(const QString &filePath) -> QString
{
// Known suffixes to check for
QStringList knownSuffixes = {".val", ".vst", ".vit"};
QFileInfo fileInfo(filePath);
// Check if the file has one of the known suffixes
for (const QString &suffix : knownSuffixes)
{
if (fileInfo.completeSuffix().endsWith(suffix, Qt::CaseInsensitive))
{
// Remove the known suffix and return the modified file name
QString modifiedFileName = fileInfo.fileName();
modifiedFileName.chop(suffix.length());
return modifiedFileName;
}
}
// Fallback to QFileInfo::baseName if no known suffix is found
return fileInfo.baseName();
}
} // namespace
//---------------------------------------------------------------------------------------------------------------------
DialogEditLabel::DialogEditLabel(const VAbstractPattern *doc, const VContainer *data, QWidget *parent)
: QDialog(parent),
@ -556,12 +583,9 @@ void DialogEditLabel::InitPlaceholders()
}
m_placeholders.insert(pl_pExt, qMakePair(tr("Pattern extension"), QStringLiteral("val")));
const QString patternFilePath = QFileInfo(VAbstractValApplication::VApp()->GetPatternPath()).baseName();
m_placeholders.insert(pl_pFileName, qMakePair(tr("Pattern file name"), patternFilePath));
const QString measurementsFilePath = QFileInfo(m_doc->MPath()).baseName();
m_placeholders.insert(pl_mFileName, qMakePair(tr("Measurements file name"), measurementsFilePath));
m_placeholders.insert(pl_pFileName, qMakePair(tr("Pattern file name"),
FileBaseName(VAbstractValApplication::VApp()->GetPatternPath())));
m_placeholders.insert(pl_mFileName, qMakePair(tr("Measurements file name"), FileBaseName(m_doc->MPath())));
QString heightValue = QString::number(VAbstractValApplication::VApp()->GetDimensionHeight());
m_placeholders.insert(pl_height, qMakePair(tr("Height", "dimension"), heightValue));