diff --git a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp index 9e0926409..c1cb7ff4d 100644 --- a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp @@ -63,6 +63,7 @@ void PreferencesPathPage::Apply() settings->SetPathPattern(ui->pathTable->item(2, 1)->text()); settings->SetPathLayout(ui->pathTable->item(3, 1)->text()); settings->SetPathTemplate(ui->pathTable->item(4, 1)->text()); + settings->SetPathLabelTemplate(ui->pathTable->item(5, 1)->text()); } //--------------------------------------------------------------------------------------------------------------------- @@ -91,6 +92,9 @@ void PreferencesPathPage::DefaultPath() case 4: // templates path = VCommonSettings::GetDefPathTemplate(); break; + case 5: // label templates + path = VSettings::GetDefPathLabelTemplate(); + break; default: break; } @@ -125,6 +129,9 @@ void PreferencesPathPage::EditPath() case 4: // templates path = qApp->ValentinaSettings()->GetPathTemplate(); break; + case 5: // label templates + path = qApp->ValentinaSettings()->GetPathLabelTemplate(); + break; default: break; } @@ -164,7 +171,7 @@ void PreferencesPathPage::EditPath() //--------------------------------------------------------------------------------------------------------------------- void PreferencesPathPage::InitTable() { - ui->pathTable->setRowCount(5); + ui->pathTable->setRowCount(6); ui->pathTable->setColumnCount(2); const VSettings *settings = qApp->ValentinaSettings(); @@ -204,6 +211,13 @@ void PreferencesPathPage::InitTable() ui->pathTable->setItem(4, 1, item); } + { + ui->pathTable->setItem(5, 0, new QTableWidgetItem(tr("My label templates"))); + QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathLabelTemplate()); + item->setToolTip(settings->GetPathLabelTemplate()); + ui->pathTable->setItem(5, 1, item); + } + ui->pathTable->verticalHeader()->setDefaultSectionSize(20); ui->pathTable->resizeColumnsToContents(); ui->pathTable->resizeRowsToContents(); diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 4a38fef82..f70e61024 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -46,8 +46,9 @@ #include "../vpatterndb/pmsystems.h" const QString settingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements"); -const QString settingPathsMultisizeMeasurements = QStringLiteral("paths/standard_measurements"); +const QString settingPathsMultisizeMeasurements = QStringLiteral("paths/standard_measurements"); const QString settingPathsTemplates = QStringLiteral("paths/templates"); +const QString settingPathsLabelTemplate = QStringLiteral("paths/labelTemplate"); const QString settingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator"); const QString settingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state"); @@ -314,6 +315,24 @@ void VCommonSettings::SetPathTemplate(const QString &value) settings.sync(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VCommonSettings::GetDefPathLabelTemplate() +{ + return QDir::homePath() + QLatin1String("/valentina/") + tr("label templates"); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VCommonSettings::GetPathLabelTemplate() const +{ + return value(settingPathsLabelTemplate, GetDefPathLabelTemplate()).toString(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetPathLabelTemplate(const QString &value) +{ + setValue(settingPathsLabelTemplate, value); +} + //--------------------------------------------------------------------------------------------------------------------- bool VCommonSettings::GetOsSeparator() const { diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index fb2c79bba..c5d7d153d 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -66,6 +66,10 @@ public: QString GetPathTemplate() const; void SetPathTemplate(const QString &value); + static QString GetDefPathLabelTemplate(); + QString GetPathLabelTemplate() const; + void SetPathLabelTemplate(const QString &value); + bool GetOsSeparator() const; void SetOsSeparator(const bool &value); diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 08fee00ac..74b60697f 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -53,6 +53,7 @@ DialogEditLabel::DialogEditLabel(QWidget *parent) connect(ui->toolButtonTextRight, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating); connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails); connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate); + connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate); } //--------------------------------------------------------------------------------------------------------------------- @@ -262,7 +263,56 @@ void DialogEditLabel::NewTemplate() //--------------------------------------------------------------------------------------------------------------------- void DialogEditLabel::ExportTemplate() { + QString filters(tr("Label template") + QLatin1String("(*.xml)")); + QString dir = 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"), + dir + QLatin1String("/") + tr("template") + QLatin1String(".xml"), + filters, nullptr, QFileDialog::DontUseNativeDialog); + + auto RemoveTempDir = [usedNotExistedDir, dir]() + { + if (usedNotExistedDir) + { + QDir directory(dir); + directory.rmpath("."); + } + }; + + if (fileName.isEmpty()) + { + RemoveTempDir(); + return; + } + + QFileInfo f( fileName ); + if (f.suffix().isEmpty() && f.suffix() != QLatin1String("xml")) + { + fileName += QLatin1String(".xml"); + } + +// QString error; +// const bool result = doc->SaveDocument(fileName, error); +// if (result == false) +// { +// QMessageBox messageBox(this); +// messageBox.setIcon(QMessageBox::Warning); +// messageBox.setInformativeText(tr("Could not save file")); +// messageBox.setDefaultButton(QMessageBox::Ok); +// messageBox.setDetailedText(error); +// messageBox.setStandardButtons(QMessageBox::Ok); +// messageBox.exec(); +// } + + RemoveTempDir(); + return; } //---------------------------------------------------------------------------------------------------------------------