[qet] qet/qet: [5452] let user define the file system path of the common and custom elements collections

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


Revision: 5452
Author:   blacksun
Date:     2018-07-25 19:34:50 +0200 (Wed, 25 Jul 2018)
Log Message:
-----------
let user define the file system path of the common and custom elements collections

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

Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp	2018-07-24 14:10:08 UTC (rev 5451)
+++ trunk/sources/qetapp.cpp	2018-07-25 17:34:50 UTC (rev 5452)
@@ -59,6 +59,7 @@
 RecentFiles *QETApp::m_elements_recent_files = nullptr;
 TitleBlockTemplate *QETApp::default_titleblock_template_ = nullptr;
 
+
 /**
 	Constructeur
 	@param argc Nombre d'arguments passes a l'application
@@ -455,12 +456,23 @@
 #endif
 }
 
+
 /**
-	Renvoie le dossier des elements communs, c-a-d le chemin du dossier dans
-	lequel QET doit chercher les definitions XML des elements de la collection QET.
-	@return Le chemin du dossier des elements communs
-*/
-QString QETApp::commonElementsDir() {
+ * @brief QETApp::commonElementsDir
+ * @return the dir path of the common elements collection.
+ */
+QString QETApp::commonElementsDir()
+{
+	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
@@ -479,12 +491,21 @@
 }
 
 /**
-	Renvoie le dossier des elements de l'utilisateur, c-a-d le chemin du dossier
-	dans lequel QET chercher les definitions XML des elements propres a
-	l'utilisateur.
-	@return Le chemin du dossier des elements persos
-*/
-QString QETApp::customElementsDir() {
+ * @brief QETApp::customElementsDir
+ * @return the dir path of user elements collection
+ */
+QString QETApp::customElementsDir()
+{
+	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;
+		}
+	}
+	
 	return(configDir() + "elements/");
 }
 

Modified: trunk/sources/ui/configpage/generalconfigurationpage.cpp
===================================================================
--- trunk/sources/ui/configpage/generalconfigurationpage.cpp	2018-07-24 14:10:08 UTC (rev 5451)
+++ trunk/sources/ui/configpage/generalconfigurationpage.cpp	2018-07-25 17:34:50 UTC (rev 5452)
@@ -61,6 +61,24 @@
 	ui->m_highlight_integrated_elements->setChecked(settings.value("diagrameditor/highlight-integrated-elements", true).toBool());
 	ui->m_default_elements_info->setPlainText(settings.value("elementeditor/default-informations", "").toString());
 	
+	QString path = settings.value("elements-collections/common-collection-path", "default").toString();
+	if (path != "default")
+	{
+		ui->m_common_elmt_path_cb->blockSignals(true);
+		ui->m_common_elmt_path_cb->setCurrentIndex(1);
+		ui->m_common_elmt_path_cb->setItemData(1, path, Qt::DisplayRole);
+		ui->m_common_elmt_path_cb->blockSignals(false);
+	}
+
+	path = settings.value("elements-collections/custom-collection-path", "default").toString();
+	if (path != "default")
+	{
+		ui->m_custom_elmt_path_cb->blockSignals(true);
+		ui->m_custom_elmt_path_cb->setCurrentIndex(1);
+		ui->m_custom_elmt_path_cb->setItemData(1, path, Qt::DisplayRole);
+		ui->m_custom_elmt_path_cb->blockSignals(false);
+	}
+	
 	fillLang();
 }
 
@@ -97,6 +115,28 @@
 	settings.setValue("genericpanel/folio",ui->m_use_folio_label->isChecked());
 	settings.setValue("nomenclature/terminal-exportlist",ui->m_export_terminal->isChecked());
 	settings.setValue("diagrameditor/autosave-interval", ui->m_autosave_sb->value());
+	
+	if (ui->m_common_elmt_path_cb->currentIndex() == 1)
+	{
+		QString path = ui->m_common_elmt_path_cb->currentText();
+		QDir dir(path);
+		settings.setValue("elements-collections/common-collection-path",
+						  dir.exists() ? path : "default");
+	}
+	else {
+		settings.setValue("elements-collections/common-collection-path", "default");
+	}
+	
+	if (ui->m_custom_elmt_path_cb->currentIndex() == 1)
+	{
+		QString path = ui->m_custom_elmt_path_cb->currentText();
+		QDir dir(path);
+		settings.setValue("elements-collections/custom-collection-path",
+						  dir.exists() ? path : "default");
+	}
+	else {
+		settings.setValue("elements-collections/custom-collection-path", "default");
+	}
 }
 
 /**
@@ -202,3 +242,32 @@
         ui->m_folio_list_pb->setText(fontInfos);
 	}
 }
+
+#include <QFileDialog>
+void GeneralConfigurationPage::on_m_common_elmt_path_cb_currentIndexChanged(int index)
+{
+    if (index == 1)
+	{
+		QString path = QFileDialog::getExistingDirectory(this, tr("Chemin de la collection commune"), QDir::homePath());
+		if (!path.isEmpty()) {
+			ui->m_common_elmt_path_cb->setItemData(1, path, Qt::DisplayRole);
+		}
+		else {
+			ui->m_common_elmt_path_cb->setCurrentIndex(0);
+		}
+	}
+}
+
+void GeneralConfigurationPage::on_m_custom_elmt_path_cb_currentIndexChanged(int index)
+{
+    if (index == 1)
+	{
+		QString path = QFileDialog::getExistingDirectory(this, tr("Chemin de la collection utilisateur"), QDir::homePath());
+		if (!path.isEmpty()) {
+			ui->m_custom_elmt_path_cb->setItemData(1, path, Qt::DisplayRole);
+		}
+		else {
+			ui->m_custom_elmt_path_cb->setCurrentIndex(0);
+		}
+	}
+}

Modified: trunk/sources/ui/configpage/generalconfigurationpage.h
===================================================================
--- trunk/sources/ui/configpage/generalconfigurationpage.h	2018-07-24 14:10:08 UTC (rev 5451)
+++ trunk/sources/ui/configpage/generalconfigurationpage.h	2018-07-25 17:34:50 UTC (rev 5452)
@@ -40,6 +40,8 @@
 	private slots:
 		void on_m_font_pb_clicked();
 		void on_m_folio_list_pb_clicked();
+		void on_m_common_elmt_path_cb_currentIndexChanged(int index);
+		void on_m_custom_elmt_path_cb_currentIndexChanged(int index);
 		
 		private:
 		void fillLang();

Modified: trunk/sources/ui/configpage/generalconfigurationpage.ui
===================================================================
--- trunk/sources/ui/configpage/generalconfigurationpage.ui	2018-07-24 14:10:08 UTC (rev 5451)
+++ trunk/sources/ui/configpage/generalconfigurationpage.ui	2018-07-25 17:34:50 UTC (rev 5452)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>916</width>
-    <height>747</height>
+    <width>827</width>
+    <height>779</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -45,6 +45,64 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="groupBox_5">
+     <property name="title">
+      <string>Collections d'éléments</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_8">
+        <property name="text">
+         <string>Chemin de la collection utilisateur</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_7">
+        <property name="text">
+         <string>Chemin de la collection commune</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QComboBox" name="m_common_elmt_path_cb">
+        <item>
+         <property name="text">
+          <string>Par defaut</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Parcourir...</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QComboBox" name="m_custom_elmt_path_cb">
+        <item>
+         <property name="text">
+          <string>Par defaut</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Parcourir...</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QLabel" name="label_9">
+        <property name="text">
+         <string>(Recharger les collections d'éléments pour appliquer les changements)</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QGroupBox" name="groupBox_2">
      <property name="title">
       <string>Projets</string>


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