Resolved issue #388. Add field for measurement template directory in Valentina.exe, 'File', 'Preferences', 'Paths'

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2015-10-18 13:01:38 +03:00
parent de12c77aa4
commit e16943cfa2
5 changed files with 79 additions and 62 deletions

View file

@ -66,6 +66,7 @@ void PathPage::Apply()
qApp->ValentinaSettings()->SetPathStandardMeasurements(pathTable->item(1, 1)->text());
qApp->ValentinaSettings()->SetPathPattern(pathTable->item(2, 1)->text());
qApp->ValentinaSettings()->SetPathLayout(pathTable->item(3, 1)->text());
qApp->ValentinaSettings()->SetPathTemplate(pathTable->item(4, 1)->text());
}
//---------------------------------------------------------------------------------------------------------------------
@ -97,6 +98,10 @@ void PathPage::DefaultPath()
item->setText(QDir::homePath());
item->setToolTip(QDir::homePath());
break;
case 4: // templates
item->setText(qApp->ValentinaSettings()->TemplatesPath());
item->setToolTip(qApp->ValentinaSettings()->TemplatesPath());
break;
default:
break;
}
@ -124,6 +129,9 @@ void PathPage::EditPath()
case 3: // layout path
path = qApp->ValentinaSettings()->GetPathLayout();
break;
case 4: // templates
path = qApp->ValentinaSettings()->GetPathTemplate();
break;
default:
break;
}
@ -169,7 +177,7 @@ QGroupBox *PathPage::PathGroup()
void PathPage::InitTable()
{
pathTable = new QTableWidget();
pathTable->setRowCount(4);
pathTable->setRowCount(5);
pathTable->setColumnCount(2);
pathTable->verticalHeader()->setVisible(false);
pathTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
@ -208,6 +216,13 @@ void PathPage::InitTable()
pathTable->setItem(3, 1, item);
}
{
pathTable->setItem(4, 0, new QTableWidgetItem(tr("Templates")));
QTableWidgetItem *item = new QTableWidgetItem(qApp->ValentinaSettings()->GetPathTemplate());
item->setToolTip(qApp->ValentinaSettings()->GetPathTemplate());
pathTable->setItem(4, 1, item);
}
pathTable->verticalHeader()->setDefaultSectionSize(20);
pathTable->resizeColumnsToContents();
pathTable->resizeRowsToContents();

View file

@ -43,6 +43,7 @@
const QString VCommonSettings::SettingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements");
const QString VCommonSettings::SettingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements");
const QString VCommonSettings::SettingPathsTemplates = QStringLiteral("paths/templates");
const QString VCommonSettings::SettingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator");
const QString VCommonSettings::SettingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state");
@ -96,6 +97,63 @@ void VCommonSettings::SetPathStandardMeasurements(const QString &value)
commonSettings.setValue(SettingPathsStandardMeasurements, value);
}
//---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::GetPathTemplate() const
{
QSettings settings(commonSettings.format(), commonSettings.scope(), commonSettings.organizationName());
return settings.value(SettingPathsTemplates, TemplatesPath()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathTemplate(const QString &value)
{
commonSettings.setValue(SettingPathsTemplates, value);
}
//---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::TemplatesPath() const
{
const QString stPath = QStringLiteral("/tables/templates");
const QString unixFullPath = QStringLiteral("/usr/share/valentina/tables/templates");
#ifdef Q_OS_WIN
return QApplication::applicationDirPath() + stPath;
#elif defined(Q_OS_MAC)
QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + stPath);
if (dirBundle.exists())
{
return dirBundle.absolutePath();
}
else
{
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return unixFullPath;
}
}
#else // Unix
#ifdef QT_DEBUG
Q_UNUSED(unixFullPath);
return QApplication::applicationDirPath() + stPath;
#else
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return unixFullPath;
}
#endif
#endif
}
//---------------------------------------------------------------------------------------------------------------------
bool VCommonSettings::GetOsSeparator() const
{

View file

@ -40,6 +40,7 @@ public:
QObject *parent = 0);
virtual QString StandardTablesPath()const=0 ;
QString TemplatesPath() const;
QString GetPathIndividualMeasurements() const;
void SetPathIndividualMeasurements(const QString &value);
@ -47,6 +48,9 @@ public:
QString GetPathStandardMeasurements() const;
void SetPathStandardMeasurements(const QString &value);
QString GetPathTemplate() const;
void SetPathTemplate(const QString &value);
bool GetOsSeparator() const;
void SetOsSeparator(const bool &value);
@ -102,6 +106,7 @@ private:
static const QString SettingPathsIndividualMeasurements;
static const QString SettingPathsStandardMeasurements;
static const QString SettingPathsTemplates;
static const QString SettingConfigurationOsSeparator;
static const QString SettingConfigurationAutosaveState;

View file

@ -31,7 +31,6 @@
#include <QApplication>
#include <QDir>
const QString VTapeSettings::SettingPathsTemplates = QStringLiteral("paths/templates");
const QString VTapeSettings::SettingDataBaseGeometry = QStringLiteral("database/geometry");
//---------------------------------------------------------------------------------------------------------------------
@ -110,61 +109,6 @@ QString VTapeSettings::StandardTablesPath() const
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QString VTapeSettings::TemplatesPath() const
{
const QString stPath = QStringLiteral("/tables/templates");
const QString unixFullPath = QStringLiteral("/usr/share/valentina/tables/templates");
#ifdef Q_OS_WIN
return QApplication::applicationDirPath() + stPath;
#elif defined(Q_OS_MAC)
QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + stPath);
if (dirBundle.exists())
{
return dirBundle.absolutePath();
}
else
{
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return unixFullPath;
}
}
#else // Unix
#ifdef QT_DEBUG
Q_UNUSED(unixFullPath);
return QApplication::applicationDirPath() + stPath;
#else
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return unixFullPath;
}
#endif
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QString VTapeSettings::GetPathTemplate() const
{
return value(SettingPathsTemplates, TemplatesPath()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VTapeSettings::SetPathTemplate(const QString &value)
{
setValue(SettingPathsTemplates, value);
}
//---------------------------------------------------------------------------------------------------------------------
QByteArray VTapeSettings::GetDataBaseGeometry() const
{

View file

@ -39,10 +39,6 @@ public:
QObject *parent = 0);
virtual QString StandardTablesPath()const Q_DECL_OVERRIDE;
QString TemplatesPath() const;
QString GetPathTemplate() const;
void SetPathTemplate(const QString &value);
QByteArray GetDataBaseGeometry() const;
void SetDataBaseGeometry(const QByteArray &value);
@ -50,7 +46,6 @@ public:
private:
Q_DISABLE_COPY(VTapeSettings)
static const QString SettingPathsTemplates;
static const QString SettingDataBaseGeometry;
};