[qet] qet/qet: [5295] improve waiting dialog when open a project

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


Revision: 5295
Author:   blacksun
Date:     2018-04-04 17:07:52 +0200 (Wed, 04 Apr 2018)
Log Message:
-----------
improve waiting dialog when open a project

Modified Paths:
--------------
    trunk/sources/projectview.cpp
    trunk/sources/qetdiagrameditor.cpp
    trunk/sources/qetdiagrameditor.h
    trunk/sources/qetproject.cpp
    trunk/sources/ui/dialogwaiting.cpp
    trunk/sources/ui/dialogwaiting.h

Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp	2018-04-04 11:02:40 UTC (rev 5294)
+++ trunk/sources/projectview.cpp	2018-04-04 15:07:52 UTC (rev 5295)
@@ -33,6 +33,7 @@
 #include "projectpropertiesdialog.h"
 #include "xmlelementcollection.h"
 #include "autoNum/assignvariables.h"
+#include "dialogwaiting.h"
 
 /**
 	Constructeur
@@ -844,12 +845,29 @@
  * We create a diagram view for each diagram,
  * and add it to the project view.
  */
-void ProjectView::loadDiagrams() {
+void ProjectView::loadDiagrams()
+{
 	if (!m_project) return;
 
 	setDisplayFallbackWidget(m_project -> diagrams().isEmpty());
 
-	foreach(Diagram *diagram, m_project -> diagrams()) {
+	DialogWaiting *dialog = nullptr;
+	if(DialogWaiting::hasInstance())
+	{
+		dialog = DialogWaiting::instance();
+		dialog->setTitle( tr("<p align=\"center\">"
+												"<b>Ouverture du projet en cours...</b><br/>"
+												"Création des onglets de folio :"
+												"</p>"));
+	}
+	for(Diagram *diagram : m_project->diagrams())
+	{
+		if(dialog)
+		{
+			dialog->setDetail(diagram->title());
+			dialog->setProgressBar(dialog->progressBarValue()+1);
+		}
+		
 		DiagramView *sv = new DiagramView(diagram);
 		addDiagram(sv);
 	}

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2018-04-04 11:02:40 UTC (rev 5294)
+++ trunk/sources/qetdiagrameditor.cpp	2018-04-04 15:07:52 UTC (rev 5295)
@@ -47,6 +47,7 @@
 #include "undocommand/rotateselectioncommand.h"
 #include "rotatetextscommand.h"
 #include "diagramcommands.h"
+#include "dialogwaiting.h"
 
 #include <QMessageBox>
 #include <QStandardPaths>
@@ -114,7 +115,7 @@
 	{
 			//So we open this files
 		foreach(QString file, files)
-			if (openAndAddProject(file, false))
+			if (openAndAddProject(file))
 				++ opened_projects;
 	}
 
@@ -857,33 +858,39 @@
 	Ouvre un projet depuis un fichier et l'ajoute a cet editeur
 	@param filepath Chemin du projet a ouvrir
 	@param interactive true pour afficher des messages a l'utilisateur, false sinon
-	@param update_panel Whether the elements panel should be warned this
-	project has been added. Defaults to true.
 	@return true si l'ouverture a reussi, false sinon
 */
-bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interactive, bool update_panel) {
+bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interactive)
+{
 	if (filepath.isEmpty()) return(false);
 	
 	QFileInfo filepath_info(filepath);
-	// verifie que le projet n'est pas deja ouvert dans un editeur
-	QString my_filepath = filepath_info.canonicalFilePath();
-	if (QETDiagramEditor *diagram_editor = QETApp::diagramEditorForFile(filepath)) {
-		if (diagram_editor == this) {
-			if (ProjectView *project_view = viewForFile(filepath)) {
+
+		//Check if project is not open in another editor
+	if (QETDiagramEditor *diagram_editor = QETApp::diagramEditorForFile(filepath))
+	{
+		if (diagram_editor == this)
+		{
+			if (ProjectView *project_view = viewForFile(filepath))
+			{
 				activateWidget(project_view);
 				show();
 				activateWindow();
 			}
 			return(false);
-		} else {
-			// demande a l'autre editeur d'afficher le fichier
+		}
+		else
+		{
+				//Ask to the other editor to display the file
 			return(diagram_editor -> openAndAddProject(filepath));
 		}
 	}
 	
-	// check the file exists
-	if (!filepath_info.exists()) {
-		if (interactive) {
+		// check the file exists
+	if (!filepath_info.exists())
+	{
+		if (interactive)
+		{
 			QET::QetMessageBox::critical(
 				this,
 				tr("Impossible d'ouvrir le fichier", "message box title"),
@@ -896,8 +903,9 @@
 		return(false);
 	}
 	
-	// verifie que le fichier est accessible en lecture
-	if (!filepath_info.isReadable()) {
+		//Check if file readable
+	if (!filepath_info.isReadable())
+	{
 		if (interactive) {
 			QET::QetMessageBox::critical(
 				this,
@@ -910,8 +918,9 @@
 		return(false);
 	}
 	
-	// gere le fait que le fichier puisse etre en lecture seule
-	if (!filepath_info.isWritable()) {
+		//Check if file is read only
+	if (!filepath_info.isWritable())
+	{
 		if (interactive) {
 			QET::QetMessageBox::warning(
 				this,
@@ -923,10 +932,14 @@
 		}
 	}
 	
-	// cree le projet a partir du fichier
+		//Create the project
+	DialogWaiting::instance(this);
+	
 	QETProject *project = new QETProject(filepath);
-	if (project -> state() != QETProject::Ok) {
-		if (interactive && project -> state() != QETProject::FileOpenDiscard) {
+	if (project -> state() != QETProject::Ok)
+	{
+		if (interactive && project -> state() != QETProject::FileOpenDiscard)
+		{
 			QET::QetMessageBox::warning(
 				this,
 				tr("Échec de l'ouverture du projet", "message box title"),
@@ -940,16 +953,14 @@
 			);
 		}
 		delete project;
+		DialogWaiting::dropInstance();
 		return(false);
 	}
 
-	// a ce stade, l'ouverture du fichier a reussi
-	// on l'ajoute a la liste des fichiers recents
 	QETApp::projectsRecentFiles() -> fileWasOpened(filepath);
-	// ... et on l'ajoute dans l'application
-	// Note: we require the panel not to be updated when the project is added
-	// because it will update itself as soon as it becomes visible
-	return(addProject(project), update_panel);
+	addProject(project);
+	DialogWaiting::dropInstance();
+	return true;
 }
 
 /**

Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h	2018-04-04 11:02:40 UTC (rev 5294)
+++ trunk/sources/qetdiagrameditor.h	2018-04-04 15:07:52 UTC (rev 5295)
@@ -64,7 +64,7 @@
 		void                 closeEvent        (QCloseEvent *) override;
 		QList<ProjectView *> openedProjects    () const;
 		void                 addProjectView    (ProjectView *);
-		bool                 openAndAddProject (const QString &, bool = true, bool = true);
+		bool                 openAndAddProject (const QString &, bool = true);
 		QList<QString>       editedFiles       () const;
 		ProjectView         *viewForFile       (const QString &) const;
 		ProjectView         *acessCurrentProject ();

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2018-04-04 11:02:40 UTC (rev 5294)
+++ trunk/sources/qetproject.cpp	2018-04-04 15:07:52 UTC (rev 5295)
@@ -1247,17 +1247,29 @@
 	
 	//@TODO try to solve a weird bug (dialog is black) since port to Qt5 with the DialogWaiting
 	//show DialogWaiting
-	DialogWaiting* dlgWaiting = new DialogWaiting();
-	dlgWaiting -> setModal(true);
-	dlgWaiting -> show();
-	dlgWaiting -> setTitle( tr("<b>Ouverture du projet en cours...</b>") );
+	DialogWaiting *dlgWaiting = nullptr;
+	if(DialogWaiting::hasInstance())
+	{
+		dlgWaiting = DialogWaiting::instance();
+		dlgWaiting -> setModal(true);
+		dlgWaiting -> show();
+		dlgWaiting -> setTitle( tr("<p align=\"center\">"
+								   "<b>Ouverture du projet en cours...</b><br/>"
+								   "Création des folios"
+								   "</p>"));
+	}
 	
 		//Search the diagrams in the project
 	QDomNodeList diagram_nodes = xml_project.elementsByTagName("diagram");
-	dlgWaiting->setProgressBarRange(0, diagram_nodes.length());
+	
+	if(dlgWaiting)
+		dlgWaiting->setProgressBarRange(0, diagram_nodes.length()*3);
+	
 	for (int i = 0 ; i < diagram_nodes.length() ; ++ i)
 	{
-		dlgWaiting->setProgressBar(i+1);
+		if(dlgWaiting)
+			dlgWaiting->setProgressBar(i+1);
+		
 		if (diagram_nodes.at(i).isElement())
 		{
 			QDomElement diagram_xml_element = diagram_nodes.at(i).toElement();
@@ -1265,7 +1277,9 @@
 			bool diagram_loading = diagram -> initFromXml(diagram_xml_element);
 			if (diagram_loading)
 			{
-				dlgWaiting->setDetail( diagram->title() );
+				if(dlgWaiting)
+					dlgWaiting->setDetail( diagram->title() );
+				
 					//Get the attribute "order" of the diagram
 				int diagram_order = -1;
 				if (!QET::attributeIsAnInteger(diagram_xml_element, "order", &diagram_order)) diagram_order = 500000;
@@ -1284,10 +1298,22 @@
 
 		//Initialise links between elements in this project
 		//and refresh the text of conductor
-	foreach (Diagram *d, diagrams())
+	if(dlgWaiting)
+	{
+		dlgWaiting->setTitle( tr("<p align=\"center\">"
+								 "<b>Ouverture du projet en cours...</b><br/>"
+								 "Mise en place des références croisées"
+								 "</p>"));
+	}
+	for(Diagram *d : diagrams())
+	{
+		if(dlgWaiting)
+		{
+			dlgWaiting->setProgressBar(dlgWaiting->progressBarValue()+1);
+			dlgWaiting->setDetail(d->title());
+		}
 		d->refreshContents();
-
-	delete dlgWaiting;
+	}
 }
 
 /**

Modified: trunk/sources/ui/dialogwaiting.cpp
===================================================================
--- trunk/sources/ui/dialogwaiting.cpp	2018-04-04 11:02:40 UTC (rev 5294)
+++ trunk/sources/ui/dialogwaiting.cpp	2018-04-04 15:07:52 UTC (rev 5295)
@@ -20,6 +20,8 @@
 #include "ui_dialogwaiting.h"
 #include <QPushButton>
 
+
+DialogWaiting *DialogWaiting::m_static_dialog = nullptr;
 /**
  * @brief DialogWaiting::DialogWaiting
  * @param parent
@@ -70,8 +72,7 @@
  * @param val is the string of action
  */
 void DialogWaiting::setTitle(const QString& val){
-	QString title="<b> "+val+" </b>";
-	ui->labelTitle->setText(title);
+	ui->labelTitle->setText(val);
 }
 
 /**
@@ -82,3 +83,12 @@
 	ui->label_detail->setText(val);
 }
 
+/**
+ * @brief DialogWaiting::progressBarValue
+ * @return The current vcalue of the progress bar
+ */
+int DialogWaiting::progressBarValue() const
+{
+	ui->progressBar->value();
+}
+

Modified: trunk/sources/ui/dialogwaiting.h
===================================================================
--- trunk/sources/ui/dialogwaiting.h	2018-04-04 11:02:40 UTC (rev 5294)
+++ trunk/sources/ui/dialogwaiting.h	2018-04-04 15:07:52 UTC (rev 5295)
@@ -20,6 +20,7 @@
 #define DIALOGWAITING_H
 
 #include <QDialog>
+#include <QMutex>
 
 namespace Ui {
 	class DialogWaiting;
@@ -28,19 +29,56 @@
 class DialogWaiting : public QDialog
 {
 	Q_OBJECT
+	public:
+		static DialogWaiting* instance(QWidget *parent = nullptr)
+		{
+			static QMutex mutex;
+			if(!m_static_dialog)
+			{
+				mutex.lock();
+				if(!m_static_dialog)
+					m_static_dialog = new DialogWaiting(parent);
+				mutex.unlock();
+			}
+			return m_static_dialog;
+		}
+		
+		static bool hasInstance()
+		{
+			if(m_static_dialog == nullptr)
+				return false;
+			else
+				return true;
+		}
+		
+		static void dropInstance()
+		{
+			static QMutex mutex;
+			if(m_static_dialog)
+			{
+				mutex.lock();
+				m_static_dialog->deleteLater();
+				m_static_dialog = nullptr;
+				mutex.unlock();
+			}
+		}
+	private:
+		static DialogWaiting *m_static_dialog;
+	
 
-public:
-	explicit DialogWaiting(QWidget *parent = nullptr);
-	~DialogWaiting() override;
-
-	void setProgressBar(int val);
-	void setProgressBarRange(int min, int max);
-	void setProgressReset();
-	void setTitle(const QString& val);
-	void setDetail(const QString& val);
-
+	public:
+		explicit DialogWaiting(QWidget *parent = nullptr);
+		~DialogWaiting() override;
+	
+		void setProgressBar(int val);
+		void setProgressBarRange(int min, int max);
+		void setProgressReset();
+		void setTitle(const QString& val);
+		void setDetail(const QString& val);
+		int progressBarValue() const;
+	
 	private:
-	Ui::DialogWaiting *ui;
+		Ui::DialogWaiting *ui;
 };
 
 #endif // DIALOGWAITING_H


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