diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index dc0e6e891..45115ccd3 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -58,6 +58,8 @@ uint QETApp::next_project_id = 0; RecentFiles *QETApp::m_projects_recent_files = nullptr; RecentFiles *QETApp::m_elements_recent_files = nullptr; TitleBlockTemplate *QETApp::default_titleblock_template_ = nullptr; +QString QETApp::m_user_common_elements_dir = QString(); +QString QETApp::m_user_custom_elements_dir = QString(); /** @@ -463,17 +465,26 @@ QString QETApp::userName() { */ QString QETApp::commonElementsDir() { - //@todo: fix me " Load time from elements is very slow " - -// QSettings settings; -// QString path = settings.value("elements-collections/common-collection-path", "default").toString(); -// if (path != "default" && !path.isEmpty()) -// { -// QDir dir(path); -// if (dir.exists()) { -// return path; -// } -// } + if (m_user_common_elements_dir.isEmpty()) + { + QSettings settings; + QString path = settings.value("elements-collections/common-collection-path", "default").toString(); + if (path != "default" && !path.isEmpty()) + { + QDir dir(path); + if (dir.exists()) + { + m_user_common_elements_dir = path; + return m_user_common_elements_dir; + } + } + else { + m_user_common_elements_dir = "default"; + } + } + else if (m_user_common_elements_dir != "default") { + return m_user_common_elements_dir; + } #ifdef QET_ALLOW_OVERRIDE_CED_OPTION if (common_elements_dir != QString()) return(common_elements_dir); @@ -498,17 +509,26 @@ QString QETApp::commonElementsDir() */ QString QETApp::customElementsDir() { - //@todo: fix me " Load time from elements is very slow " - -// QSettings settings; -// QString path = settings.value("elements-collections/custom-collection-path", "default").toString(); -// if (path != "default" && !path.isEmpty()) -// { -// QDir dir(path); -// if (dir.exists()) { -// return path; -// } -// } + if (m_user_custom_elements_dir.isEmpty()) + { + QSettings settings; + QString path = settings.value("elements-collections/custom-collection-path", "default").toString(); + if (path != "default" && !path.isEmpty()) + { + QDir dir(path); + if (dir.exists()) + { + m_user_custom_elements_dir = path; + return m_user_custom_elements_dir; + } + } + else { + m_user_custom_elements_dir = "default"; + } + } + else if (m_user_custom_elements_dir != "default") { + return m_user_custom_elements_dir; + } return(configDir() + "elements/"); } @@ -537,6 +557,17 @@ QString QETApp::customElementsDirN() return path; } +/** + * @brief QETApp::resetUserElementsDir + * Reset the path of the user common and custom elements dir. + * Use this function when the user path (common and/or custom) change. + */ +void QETApp::resetUserElementsDir() +{ + m_user_common_elements_dir.clear(); + m_user_custom_elements_dir.clear(); +} + /** @return the path of the directory containing the common title block templates collection. diff --git a/sources/qetapp.h b/sources/qetapp.h index f439e8146..5250d8066 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -86,6 +86,7 @@ class QETApp : public QETSingleApplication static QString customElementsDir(); static QString commonElementsDirN(); static QString customElementsDirN(); + static void resetUserElementsDir(); static QString commonTitleBlockTemplatesDir(); static QString customTitleBlockTemplatesDir(); static bool registerProject(QETProject *); @@ -185,6 +186,8 @@ class QETApp : public QETSingleApplication static RecentFiles *m_projects_recent_files; static RecentFiles *m_elements_recent_files; static TitleBlockTemplate *default_titleblock_template_; + static QString m_user_common_elements_dir; + static QString m_user_custom_elements_dir; public slots: void systray(QSystemTrayIcon::ActivationReason); diff --git a/sources/ui/configpage/generalconfigurationpage.cpp b/sources/ui/configpage/generalconfigurationpage.cpp index fd48917eb..de129fd03 100644 --- a/sources/ui/configpage/generalconfigurationpage.cpp +++ b/sources/ui/configpage/generalconfigurationpage.cpp @@ -79,12 +79,7 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : ui->m_custom_elmt_path_cb->blockSignals(false); } - fillLang(); - - //@todo: fix me " Load time from elements is very slow " -> Disable dialog buttons for define the file system path of the common and custom elements - ui->m_common_elmt_path_cb ->setDisabled(true); - ui->m_custom_elmt_path_cb ->setDisabled(true); - + fillLang(); } GeneralConfigurationPage::~GeneralConfigurationPage() @@ -121,6 +116,7 @@ void GeneralConfigurationPage::applyConf() settings.setValue("nomenclature/terminal-exportlist",ui->m_export_terminal->isChecked()); settings.setValue("diagrameditor/autosave-interval", ui->m_autosave_sb->value()); + QString path = settings.value("elements-collections/common-collection-path").toString(); if (ui->m_common_elmt_path_cb->currentIndex() == 1) { QString path = ui->m_common_elmt_path_cb->currentText(); @@ -131,7 +127,11 @@ void GeneralConfigurationPage::applyConf() else { settings.setValue("elements-collections/common-collection-path", "default"); } + if (path != settings.value("elements-collections/common-collection-path").toString()) { + QETApp::resetUserElementsDir(); + } + path = settings.value("elements-collections/custom-collection-path").toString(); if (ui->m_custom_elmt_path_cb->currentIndex() == 1) { QString path = ui->m_custom_elmt_path_cb->currentText(); @@ -142,6 +142,9 @@ void GeneralConfigurationPage::applyConf() else { settings.setValue("elements-collections/custom-collection-path", "default"); } + if (path != settings.value("elements-collections/custom-collection-path").toString()) { + QETApp::resetUserElementsDir(); + } } /**