diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index b6b3bc84b..6d47aa27f 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -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 { diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 93a864d50..b3e944d05 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -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; diff --git a/src/app/core/vsettings.cpp b/src/app/core/vsettings.cpp index 0dd1fa4ec..884695fc2 100644 --- a/src/app/core/vsettings.cpp +++ b/src/app/core/vsettings.cpp @@ -31,6 +31,7 @@ #include #include #include +#include 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 +} diff --git a/src/app/core/vsettings.h b/src/app/core/vsettings.h index cb240b73c..c00fe4b6a 100644 --- a/src/app/core/vsettings.h +++ b/src/app/core/vsettings.h @@ -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; diff --git a/src/app/dialogs/app/configpages/pathpage.cpp b/src/app/dialogs/app/configpages/pathpage.cpp index fd55446a7..72aab21d6 100644 --- a/src/app/dialogs/app/configpages/pathpage.cpp +++ b/src/app/dialogs/app/configpages/pathpage.cpp @@ -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(); diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index 055979b35..62f5d47fb 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -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; diff --git a/src/app/dialogs/app/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index 8adcc8649..8fedf9f43 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -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 ) { diff --git a/src/app/dialogs/app/dialogstandardmeasurements.cpp b/src/app/dialogs/app/dialogstandardmeasurements.cpp index 356074ed7..f3a8fc4f1 100644 --- a/src/app/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/app/dialogs/app/dialogstandardmeasurements.cpp @@ -33,6 +33,7 @@ #include #include "../../xml/vstandardmeasurements.h" #include "../../core/vapplication.h" +#include "../../core/vsettings.h" #include "../../container/vcontainer.h" #include @@ -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"<pathToTables(); + qCDebug(vStMeasur)<<"Can't find standard measurements in path"<comboBoxTables->clear(); CheckState(); return; diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 22fa7668c..e13907407 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -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()) {