User "home" folder now supports label templates.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-09-12 11:50:23 +03:00
parent eec51d8670
commit d820191e8a
3 changed files with 19 additions and 23 deletions

View File

@ -255,6 +255,12 @@ QString VCommonSettings::StandardTemplatesPath()
return SharePath(QStringLiteral("/tables/templates")); return SharePath(QStringLiteral("/tables/templates"));
} }
//---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::LabelTemplatesPath()
{
return SharePath(QStringLiteral("/labels"));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::PrepareStandardTemplates(const QString & currentPath) QString VCommonSettings::PrepareStandardTemplates(const QString & currentPath)
{ {
@ -267,6 +273,12 @@ QString VCommonSettings::PrepareMultisizeTables(const QString &currentPath)
return PrepareStandardFiles(currentPath, MultisizeTablesPath(), GetDefPathMultisizeMeasurements()); return PrepareStandardFiles(currentPath, MultisizeTablesPath(), GetDefPathMultisizeMeasurements());
} }
//---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::PrepareLabelTemplates(const QString &currentPath)
{
return PrepareStandardFiles(currentPath, LabelTemplatesPath(), GetDefPathLabelTemplate());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::GetDefPathIndividualMeasurements() QString VCommonSettings::GetDefPathIndividualMeasurements()
{ {

View File

@ -50,9 +50,11 @@ public:
static QString SharePath(const QString &shareItem); static QString SharePath(const QString &shareItem);
static QString MultisizeTablesPath(); static QString MultisizeTablesPath();
static QString StandardTemplatesPath(); static QString StandardTemplatesPath();
static QString LabelTemplatesPath();
static QString PrepareStandardTemplates(const QString &currentPath); static QString PrepareStandardTemplates(const QString &currentPath);
static QString PrepareMultisizeTables(const QString &currentPath); static QString PrepareMultisizeTables(const QString &currentPath);
static QString PrepareLabelTemplates(const QString &currentPath);
static QString GetDefPathIndividualMeasurements(); static QString GetDefPathIndividualMeasurements();
QString GetPathIndividualMeasurements() const; QString GetPathIndividualMeasurements() const;

View File

@ -287,31 +287,14 @@ void DialogEditLabel::NewTemplate()
void DialogEditLabel::ExportTemplate() void DialogEditLabel::ExportTemplate()
{ {
QString filters(tr("Label template") + QLatin1String("(*.xml)")); QString filters(tr("Label template") + QLatin1String("(*.xml)"));
QString dir = qApp->Settings()->GetPathLabelTemplate(); const QString path = VCommonSettings::PrepareLabelTemplates(qApp->Settings()->GetPathLabelTemplate());
bool usedNotExistedDir = false;
QDir directory(dir);
if (not directory.exists())
{
usedNotExistedDir = directory.mkpath(".");
}
QString fileName = QFileDialog::getSaveFileName(this, tr("Export label template"), QString fileName = QFileDialog::getSaveFileName(this, tr("Export label template"),
dir + QLatin1String("/") + tr("template") + QLatin1String(".xml"), path + QLatin1String("/") + tr("template") + QLatin1String(".xml"),
filters, nullptr, QFileDialog::DontUseNativeDialog); filters, nullptr, QFileDialog::DontUseNativeDialog);
auto RemoveTempDir = [usedNotExistedDir, dir]()
{
if (usedNotExistedDir)
{
QDir directory(dir);
directory.rmpath(".");
}
};
if (fileName.isEmpty()) if (fileName.isEmpty())
{ {
RemoveTempDir();
return; return;
} }
@ -337,8 +320,6 @@ void DialogEditLabel::ExportTemplate()
messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec(); messageBox.exec();
} }
RemoveTempDir();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -357,8 +338,9 @@ void DialogEditLabel::ImportTemplate()
} }
QString filter(tr("Label template") + QLatin1String("(*.xml)")); QString filter(tr("Label template") + QLatin1String("(*.xml)"));
const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), //Use standard path to label templates
qApp->Settings()->GetPathLabelTemplate(), filter, nullptr, const QString path = VCommonSettings::PrepareLabelTemplates(qApp->Settings()->GetPathLabelTemplate());
const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr,
QFileDialog::DontUseNativeDialog); QFileDialog::DontUseNativeDialog);
if (fileName.isEmpty()) if (fileName.isEmpty())
{ {