New standard path for label templates.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-10 14:51:17 +03:00
parent 7f570106db
commit 209a281cdc
4 changed files with 89 additions and 2 deletions

View File

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

View File

@ -48,6 +48,7 @@
const QString settingPathsIndividualMeasurements = QStringLiteral("paths/individual_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
{

View File

@ -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);

View File

@ -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;
}
//---------------------------------------------------------------------------------------------------------------------