Fixed bug "Can't get Valentina to pick the .vst initial file (OSX)".

--HG--
branch : develop
This commit is contained in:
dismine 2015-01-28 16:46:41 +02:00
parent f8c62b9b25
commit d70879276e
9 changed files with 153 additions and 53 deletions

View File

@ -376,36 +376,6 @@ bool VApplication::TryLock(QLockFile *lock)
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VApplication::pathToTables() const
{
if (_patternType == MeasurementsType::Individual)
{
return QStringLiteral("://tables/individual/individual.vit");
}
else
{
const QString stPath = QStringLiteral("/tables/standard");
#ifdef Q_OS_WIN
return QApplication::applicationDirPath() + stPath;
#else
#ifdef QT_DEBUG
return QApplication::applicationDirPath() + stPath;
#else
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return QStringLiteral("/usr/share/valentina/tables/standard");
}
#endif
#endif
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VApplication::translationsPath() const
{

View File

@ -74,7 +74,6 @@ public:
static const qreal PrintDPI;
QString translationsPath() const;
QString pathToTables() const;
qreal widthMainLine() const;
qreal widthHairLine() const;
QString VarToUser(const QString &var) const;

View File

@ -31,6 +31,7 @@
#include <QDir>
#include <QDebug>
#include <QLocale>
#include <QApplication>
const QString VSettings::SettingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator");
const QString VSettings::SettingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state");
@ -41,6 +42,7 @@ const QString VSettings::SettingConfigurationUnit = QStringLiteral("
const QString VSettings::SettingConfigurationLabelLanguage = QStringLiteral("configuration/label_language");
const QString VSettings::SettingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements");
const QString VSettings::SettingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements");
const QString VSettings::SettingPathsPattern = QStringLiteral("paths/pattern");
const QString VSettings::SettingPathsLayout = QStringLiteral("paths/layout");
@ -174,6 +176,18 @@ void VSettings::SetPathIndividualMeasurements(const QString &value)
setValue(SettingPathsIndividualMeasurements, value);
}
//---------------------------------------------------------------------------------------------------------------------
QString VSettings::GetPathStandardMeasurements() const
{
return value(SettingPathsStandardMeasurements, StandardTablesPath()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetPathStandardMeasurements(const QString &value)
{
setValue(SettingPathsStandardMeasurements, value);
}
//---------------------------------------------------------------------------------------------------------------------
QString VSettings::GetPathPattern() const
{
@ -415,3 +429,44 @@ void VSettings::SetUserPassword(const QString &value)
{
setValue(SettingCommunityUserPassword, value);
}
//---------------------------------------------------------------------------------------------------------------------
QString VSettings::StandardTablesPath()
{
const QString stPath = QStringLiteral("/tables/standard");
#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 QStringLiteral("/usr/share/valentina/tables/standard");
}
}
#else // Unix
#ifdef QT_DEBUG
return QApplication::applicationDirPath() + stPath;
#else
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return QStringLiteral("/usr/share/valentina/tables/standard");
}
#endif
#endif
}

View File

@ -38,6 +38,8 @@ public:
VSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(),
QObject *parent = 0);
static QString StandardTablesPath();
bool GetOsSeparator() const;
void SetOsSeparator(const bool &value);
@ -62,6 +64,9 @@ public:
QString GetPathIndividualMeasurements() const;
void SetPathIndividualMeasurements(const QString &value);
QString GetPathStandardMeasurements() const;
void SetPathStandardMeasurements(const QString &value);
QString GetPathPattern() const;
void SetPathPattern(const QString &value);
@ -130,6 +135,7 @@ private:
static const QString SettingConfigurationLabelLanguage;
static const QString SettingPathsIndividualMeasurements;
static const QString SettingPathsStandardMeasurements;
static const QString SettingPathsPattern;
static const QString SettingPathsLayout;

View File

@ -63,8 +63,9 @@ PathPage::PathPage(QWidget *parent)
void PathPage::Apply()
{
qApp->getSettings()->SetPathIndividualMeasurements(pathTable->item(0, 1)->text());
qApp->getSettings()->SetPathPattern(pathTable->item(1, 1)->text());
qApp->getSettings()->SetPathLayout(pathTable->item(2, 1)->text());
qApp->getSettings()->SetPathStandardMeasurements(pathTable->item(1, 1)->text());
qApp->getSettings()->SetPathPattern(pathTable->item(2, 1)->text());
qApp->getSettings()->SetPathLayout(pathTable->item(3, 1)->text());
}
//---------------------------------------------------------------------------------------------------------------------
@ -80,24 +81,62 @@ void PathPage::TableActivated()
//---------------------------------------------------------------------------------------------------------------------
void PathPage::DefaultPath()
{
QTableWidgetItem *item = pathTable->item(pathTable->currentRow(), 1);
const int row = pathTable->currentRow();
QTableWidgetItem *item = pathTable->item(row, 1);
SCASSERT(item != nullptr);
item->setText(QDir::homePath());
switch(row)
{
case 1: // standard measurements
item->setText(VSettings::StandardTablesPath());
item->setToolTip(VSettings::StandardTablesPath());
break;
case 0: // individual measurements
case 2: // pattern path
case 3: // layout path
item->setText(QDir::homePath());
item->setToolTip(QDir::homePath());
break;
default:
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
void PathPage::EditPath()
{
QTableWidgetItem *item = pathTable->item(pathTable->currentRow(), 1);
const int row = pathTable->currentRow();
QTableWidgetItem *item = pathTable->item(row, 1);
SCASSERT(item != nullptr);
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), QDir::homePath(),
QString path;
switch(row)
{
case 0: // individual measurements
path = qApp->getSettings()->GetPathIndividualMeasurements();
break;
case 1: // standard measurements
path = qApp->getSettings()->GetPathStandardMeasurements();
break;
case 2: // pattern path
path = qApp->getSettings()->GetPathPattern();
break;
case 3: // layout path
path = qApp->getSettings()->GetPathLayout();
break;
default:
break;
}
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir.isEmpty())
{
dir = QDir::homePath();
DefaultPath();
return;
}
item->setText(dir);
item->setToolTip(dir);
}
//---------------------------------------------------------------------------------------------------------------------
@ -130,7 +169,7 @@ QGroupBox *PathPage::PathGroup()
void PathPage::InitTable()
{
pathTable = new QTableWidget();
pathTable->setRowCount(3);
pathTable->setRowCount(4);
pathTable->setColumnCount(2);
pathTable->verticalHeader()->setVisible(false);
pathTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
@ -141,14 +180,33 @@ void PathPage::InitTable()
QStringList tableHeader = QStringList() << tr("Type") << tr("Path");
pathTable->setHorizontalHeaderLabels(tableHeader);
pathTable->setItem(0, 0, new QTableWidgetItem(tr("Individual measurements")));
pathTable->setItem(0, 1, new QTableWidgetItem(qApp->getSettings()->GetPathIndividualMeasurements()));
{
pathTable->setItem(0, 0, new QTableWidgetItem(tr("Individual measurements")));
QTableWidgetItem *item = new QTableWidgetItem(qApp->getSettings()->GetPathIndividualMeasurements());
item->setToolTip(qApp->getSettings()->GetPathIndividualMeasurements());
pathTable->setItem(0, 1, item);
}
pathTable->setItem(1, 0, new QTableWidgetItem(tr("Patterns")));
pathTable->setItem(1, 1, new QTableWidgetItem(qApp->getSettings()->GetPathPattern()));
{
pathTable->setItem(1, 0, new QTableWidgetItem(tr("Standard measurements")));
QTableWidgetItem *item = new QTableWidgetItem(qApp->getSettings()->GetPathStandardMeasurements());
item->setToolTip(qApp->getSettings()->GetPathStandardMeasurements());
pathTable->setItem(1, 1, item);
}
pathTable->setItem(2, 0, new QTableWidgetItem(tr("Layout")));
pathTable->setItem(2, 1, new QTableWidgetItem(qApp->getSettings()->GetPathLayout()));
{
pathTable->setItem(2, 0, new QTableWidgetItem(tr("Patterns")));
QTableWidgetItem *item = new QTableWidgetItem(qApp->getSettings()->GetPathPattern());
item->setToolTip(qApp->getSettings()->GetPathPattern());
pathTable->setItem(2, 1, item);
}
{
pathTable->setItem(3, 0, new QTableWidgetItem(tr("Layout")));
QTableWidgetItem *item = new QTableWidgetItem(qApp->getSettings()->GetPathLayout());
item->setToolTip(qApp->getSettings()->GetPathLayout());
pathTable->setItem(3, 1, item);
}
pathTable->verticalHeader()->setDefaultSectionSize(20);
pathTable->resizeColumnsToContents();

View File

@ -506,7 +506,7 @@ void DialogIncrements::SaveBirthDate(const QDate & date)
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::OpenTable()
{
QString text = tr("Measurements use different units than pattern. This pattern required measurements in %1")
const QString text = tr("Measurements use different units than pattern. This pattern required measurements in %1")
.arg(doc->UnitsToStr(qApp->patternUnit()));
if (qApp->patternType() == MeasurementsType::Individual)
{
@ -555,7 +555,9 @@ void DialogIncrements::OpenTable()
else
{
const QString filter(tr("Standard measurements (*.vst)"));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), qApp->pathToTables(), filter);
//Use standard path to standard measurements
const QString path = qApp->getSettings()->GetPathStandardMeasurements();
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
if (filePath.isEmpty())
{
return;

View File

@ -98,8 +98,9 @@ void DialogIndividualMeasurements::DialogAccepted()
}
//just in case
VDomDocument::ValidateXML("://schema/individual_measurements.xsd", qApp->pathToTables());
QFile iMeasur(qApp->pathToTables());
const QString path = QStringLiteral("://tables/individual/individual.vit");
VDomDocument::ValidateXML("://schema/individual_measurements.xsd", path);
QFile iMeasur(path);
//TODO maybe make copy save?
if ( iMeasur.copy(_tablePath) == false )
{

View File

@ -33,6 +33,7 @@
#include <QDesktopWidget>
#include "../../xml/vstandardmeasurements.h"
#include "../../core/vapplication.h"
#include "../../core/vsettings.h"
#include "../../container/vcontainer.h"
#include <QLoggingCategory>
@ -149,14 +150,16 @@ void DialogStandardMeasurements::LoadStandardTables()
{
qCDebug(vStMeasur)<<"Loading standard table.";
QStringList filters{"*.vst"};
QDir tablesDir(qApp->pathToTables());
//Use standard path to standard measurements
const QString path = qApp->getSettings()->GetPathStandardMeasurements();
QDir tablesDir(path);
tablesDir.setNameFilters(filters);
tablesDir.setCurrent(qApp->pathToTables());
tablesDir.setCurrent(path);
const QStringList allFiles = tablesDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
if (allFiles.isEmpty() == true)
{
qCDebug(vStMeasur)<<"Can't find standard measurements in path"<<qApp->pathToTables();
qCDebug(vStMeasur)<<"Can't find standard measurements in path"<<path;
ui->comboBoxTables->clear();
CheckState();
return;

View File

@ -2574,15 +2574,21 @@ QString MainWindow::CheckPathToMeasurements(const QString &path, const Measureme
else
{
QString filter;
QString mPath;
if (patternType == MeasurementsType::Standard)
{
filter = tr("Standard measurements (*.vst)");
//Use standard path to standard measurements
const QString path = qApp->getSettings()->GetPathStandardMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
}
else
{
filter = tr("Individual measurements (*.vit)");
//Use standard path to individual measurements
const QString path = qApp->getSettings()->GetPathIndividualMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
}
QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), qApp->pathToTables(), filter);
if (mPath.isEmpty())
{