[qet] qet/qet: [5462] re-enable the possibility to define the path of elements collections.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5462
Author:   blacksun
Date:     2018-08-03 18:35:40 +0200 (Fri, 03 Aug 2018)
Log Message:
-----------
re-enable the possibility to define the path of elements collections.
Add variables for common and custom elements collections, to avoid multiple access to QSettings and so reduce the loading of collections.  

Modified Paths:
--------------
    trunk/sources/qetapp.cpp
    trunk/sources/qetapp.h
    trunk/sources/ui/configpage/generalconfigurationpage.cpp

Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp	2018-07-30 15:24:29 UTC (rev 5461)
+++ trunk/sources/qetapp.cpp	2018-08-03 16:35:40 UTC (rev 5462)
@@ -58,6 +58,8 @@
 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,18 +465,27 @@
  */
 QString QETApp::commonElementsDir()
 {
-	//@todo: fix me " Load time from elements is very slow "
+	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;
+	}
 	
-//	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;
-//		}
-//	}
-	
 #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
 	if (common_elements_dir != QString()) return(common_elements_dir);
 #endif
@@ -498,17 +509,26 @@
  */
 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/");
 }
@@ -538,6 +558,17 @@
 }
 
 /**
+ * @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.
 */

Modified: trunk/sources/qetapp.h
===================================================================
--- trunk/sources/qetapp.h	2018-07-30 15:24:29 UTC (rev 5461)
+++ trunk/sources/qetapp.h	2018-08-03 16:35:40 UTC (rev 5462)
@@ -86,6 +86,7 @@
 		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 @@
 		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);

Modified: trunk/sources/ui/configpage/generalconfigurationpage.cpp
===================================================================
--- trunk/sources/ui/configpage/generalconfigurationpage.cpp	2018-07-30 15:24:29 UTC (rev 5461)
+++ trunk/sources/ui/configpage/generalconfigurationpage.cpp	2018-08-03 16:35:40 UTC (rev 5462)
@@ -79,12 +79,7 @@
 		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 @@
 	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 @@
 	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 @@
 	else {
 		settings.setValue("elements-collections/custom-collection-path", "default");
 	}
+	if (path != settings.value("elements-collections/custom-collection-path").toString()) {
+		QETApp::resetUserElementsDir();
+	}
 }
 
 /**


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/