mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
improve waiting dialog when open a project
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5295 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include "projectpropertiesdialog.h"
|
#include "projectpropertiesdialog.h"
|
||||||
#include "xmlelementcollection.h"
|
#include "xmlelementcollection.h"
|
||||||
#include "autoNum/assignvariables.h"
|
#include "autoNum/assignvariables.h"
|
||||||
|
#include "dialogwaiting.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -844,12 +845,29 @@ void ProjectView::initLayout() {
|
|||||||
* We create a diagram view for each diagram,
|
* We create a diagram view for each diagram,
|
||||||
* and add it to the project view.
|
* and add it to the project view.
|
||||||
*/
|
*/
|
||||||
void ProjectView::loadDiagrams() {
|
void ProjectView::loadDiagrams()
|
||||||
|
{
|
||||||
if (!m_project) return;
|
if (!m_project) return;
|
||||||
|
|
||||||
setDisplayFallbackWidget(m_project -> diagrams().isEmpty());
|
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);
|
DiagramView *sv = new DiagramView(diagram);
|
||||||
addDiagram(sv);
|
addDiagram(sv);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "undocommand/rotateselectioncommand.h"
|
#include "undocommand/rotateselectioncommand.h"
|
||||||
#include "rotatetextscommand.h"
|
#include "rotatetextscommand.h"
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
|
#include "dialogwaiting.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
@@ -114,7 +115,7 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
|
|||||||
{
|
{
|
||||||
//So we open this files
|
//So we open this files
|
||||||
foreach(QString file, files)
|
foreach(QString file, files)
|
||||||
if (openAndAddProject(file, false))
|
if (openAndAddProject(file))
|
||||||
++ opened_projects;
|
++ opened_projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -857,33 +858,39 @@ bool QETDiagramEditor::closeCurrentProject() {
|
|||||||
Ouvre un projet depuis un fichier et l'ajoute a cet editeur
|
Ouvre un projet depuis un fichier et l'ajoute a cet editeur
|
||||||
@param filepath Chemin du projet a ouvrir
|
@param filepath Chemin du projet a ouvrir
|
||||||
@param interactive true pour afficher des messages a l'utilisateur, false sinon
|
@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
|
@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);
|
if (filepath.isEmpty()) return(false);
|
||||||
|
|
||||||
QFileInfo filepath_info(filepath);
|
QFileInfo filepath_info(filepath);
|
||||||
// verifie que le projet n'est pas deja ouvert dans un editeur
|
|
||||||
QString my_filepath = filepath_info.canonicalFilePath();
|
//Check if project is not open in another editor
|
||||||
if (QETDiagramEditor *diagram_editor = QETApp::diagramEditorForFile(filepath)) {
|
if (QETDiagramEditor *diagram_editor = QETApp::diagramEditorForFile(filepath))
|
||||||
if (diagram_editor == this) {
|
{
|
||||||
if (ProjectView *project_view = viewForFile(filepath)) {
|
if (diagram_editor == this)
|
||||||
|
{
|
||||||
|
if (ProjectView *project_view = viewForFile(filepath))
|
||||||
|
{
|
||||||
activateWidget(project_view);
|
activateWidget(project_view);
|
||||||
show();
|
show();
|
||||||
activateWindow();
|
activateWindow();
|
||||||
}
|
}
|
||||||
return(false);
|
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));
|
return(diagram_editor -> openAndAddProject(filepath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the file exists
|
// check the file exists
|
||||||
if (!filepath_info.exists()) {
|
if (!filepath_info.exists())
|
||||||
if (interactive) {
|
{
|
||||||
|
if (interactive)
|
||||||
|
{
|
||||||
QET::QetMessageBox::critical(
|
QET::QetMessageBox::critical(
|
||||||
this,
|
this,
|
||||||
tr("Impossible d'ouvrir le fichier", "message box title"),
|
tr("Impossible d'ouvrir le fichier", "message box title"),
|
||||||
@@ -896,8 +903,9 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
|||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifie que le fichier est accessible en lecture
|
//Check if file readable
|
||||||
if (!filepath_info.isReadable()) {
|
if (!filepath_info.isReadable())
|
||||||
|
{
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
QET::QetMessageBox::critical(
|
QET::QetMessageBox::critical(
|
||||||
this,
|
this,
|
||||||
@@ -910,8 +918,9 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
|||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// gere le fait que le fichier puisse etre en lecture seule
|
//Check if file is read only
|
||||||
if (!filepath_info.isWritable()) {
|
if (!filepath_info.isWritable())
|
||||||
|
{
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
QET::QetMessageBox::warning(
|
QET::QetMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
@@ -923,10 +932,14 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cree le projet a partir du fichier
|
//Create the project
|
||||||
|
DialogWaiting::instance(this);
|
||||||
|
|
||||||
QETProject *project = new QETProject(filepath);
|
QETProject *project = new QETProject(filepath);
|
||||||
if (project -> state() != QETProject::Ok) {
|
if (project -> state() != QETProject::Ok)
|
||||||
if (interactive && project -> state() != QETProject::FileOpenDiscard) {
|
{
|
||||||
|
if (interactive && project -> state() != QETProject::FileOpenDiscard)
|
||||||
|
{
|
||||||
QET::QetMessageBox::warning(
|
QET::QetMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
tr("Échec de l'ouverture du projet", "message box title"),
|
tr("Échec de l'ouverture du projet", "message box title"),
|
||||||
@@ -940,16 +953,14 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
delete project;
|
delete project;
|
||||||
|
DialogWaiting::dropInstance();
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// a ce stade, l'ouverture du fichier a reussi
|
|
||||||
// on l'ajoute a la liste des fichiers recents
|
|
||||||
QETApp::projectsRecentFiles() -> fileWasOpened(filepath);
|
QETApp::projectsRecentFiles() -> fileWasOpened(filepath);
|
||||||
// ... et on l'ajoute dans l'application
|
addProject(project);
|
||||||
// Note: we require the panel not to be updated when the project is added
|
DialogWaiting::dropInstance();
|
||||||
// because it will update itself as soon as it becomes visible
|
return true;
|
||||||
return(addProject(project), update_panel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class QETDiagramEditor : public QETMainWindow {
|
|||||||
void closeEvent (QCloseEvent *) override;
|
void closeEvent (QCloseEvent *) override;
|
||||||
QList<ProjectView *> openedProjects () const;
|
QList<ProjectView *> openedProjects () const;
|
||||||
void addProjectView (ProjectView *);
|
void addProjectView (ProjectView *);
|
||||||
bool openAndAddProject (const QString &, bool = true, bool = true);
|
bool openAndAddProject (const QString &, bool = true);
|
||||||
QList<QString> editedFiles () const;
|
QList<QString> editedFiles () const;
|
||||||
ProjectView *viewForFile (const QString &) const;
|
ProjectView *viewForFile (const QString &) const;
|
||||||
ProjectView *acessCurrentProject ();
|
ProjectView *acessCurrentProject ();
|
||||||
|
|||||||
@@ -1247,17 +1247,29 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
|
|||||||
|
|
||||||
//@TODO try to solve a weird bug (dialog is black) since port to Qt5 with the DialogWaiting
|
//@TODO try to solve a weird bug (dialog is black) since port to Qt5 with the DialogWaiting
|
||||||
//show DialogWaiting
|
//show DialogWaiting
|
||||||
DialogWaiting* dlgWaiting = new DialogWaiting();
|
DialogWaiting *dlgWaiting = nullptr;
|
||||||
dlgWaiting -> setModal(true);
|
if(DialogWaiting::hasInstance())
|
||||||
dlgWaiting -> show();
|
{
|
||||||
dlgWaiting -> setTitle( tr("<b>Ouverture du projet en cours...</b>") );
|
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
|
//Search the diagrams in the project
|
||||||
QDomNodeList diagram_nodes = xml_project.elementsByTagName("diagram");
|
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)
|
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())
|
if (diagram_nodes.at(i).isElement())
|
||||||
{
|
{
|
||||||
QDomElement diagram_xml_element = diagram_nodes.at(i).toElement();
|
QDomElement diagram_xml_element = diagram_nodes.at(i).toElement();
|
||||||
@@ -1265,7 +1277,9 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
|
|||||||
bool diagram_loading = diagram -> initFromXml(diagram_xml_element);
|
bool diagram_loading = diagram -> initFromXml(diagram_xml_element);
|
||||||
if (diagram_loading)
|
if (diagram_loading)
|
||||||
{
|
{
|
||||||
dlgWaiting->setDetail( diagram->title() );
|
if(dlgWaiting)
|
||||||
|
dlgWaiting->setDetail( diagram->title() );
|
||||||
|
|
||||||
//Get the attribute "order" of the diagram
|
//Get the attribute "order" of the diagram
|
||||||
int diagram_order = -1;
|
int diagram_order = -1;
|
||||||
if (!QET::attributeIsAnInteger(diagram_xml_element, "order", &diagram_order)) diagram_order = 500000;
|
if (!QET::attributeIsAnInteger(diagram_xml_element, "order", &diagram_order)) diagram_order = 500000;
|
||||||
@@ -1284,10 +1298,22 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
|
|||||||
|
|
||||||
//Initialise links between elements in this project
|
//Initialise links between elements in this project
|
||||||
//and refresh the text of conductor
|
//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();
|
d->refreshContents();
|
||||||
|
}
|
||||||
delete dlgWaiting;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#include "ui_dialogwaiting.h"
|
#include "ui_dialogwaiting.h"
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
|
||||||
|
DialogWaiting *DialogWaiting::m_static_dialog = nullptr;
|
||||||
/**
|
/**
|
||||||
* @brief DialogWaiting::DialogWaiting
|
* @brief DialogWaiting::DialogWaiting
|
||||||
* @param parent
|
* @param parent
|
||||||
@@ -70,8 +72,7 @@ void DialogWaiting::setProgressBarRange(int min, int max){
|
|||||||
* @param val is the string of action
|
* @param val is the string of action
|
||||||
*/
|
*/
|
||||||
void DialogWaiting::setTitle(const QString& val){
|
void DialogWaiting::setTitle(const QString& val){
|
||||||
QString title="<b> "+val+" </b>";
|
ui->labelTitle->setText(val);
|
||||||
ui->labelTitle->setText(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,3 +83,12 @@ void DialogWaiting::setDetail(const QString& val){
|
|||||||
ui->label_detail->setText(val);
|
ui->label_detail->setText(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DialogWaiting::progressBarValue
|
||||||
|
* @return The current vcalue of the progress bar
|
||||||
|
*/
|
||||||
|
int DialogWaiting::progressBarValue() const
|
||||||
|
{
|
||||||
|
ui->progressBar->value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#define DIALOGWAITING_H
|
#define DIALOGWAITING_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DialogWaiting;
|
class DialogWaiting;
|
||||||
@@ -28,19 +29,56 @@ namespace Ui {
|
|||||||
class DialogWaiting : public QDialog
|
class DialogWaiting : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
static bool hasInstance()
|
||||||
explicit DialogWaiting(QWidget *parent = nullptr);
|
{
|
||||||
~DialogWaiting() override;
|
if(m_static_dialog == nullptr)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void setProgressBar(int val);
|
static void dropInstance()
|
||||||
void setProgressBarRange(int min, int max);
|
{
|
||||||
void setProgressReset();
|
static QMutex mutex;
|
||||||
void setTitle(const QString& val);
|
if(m_static_dialog)
|
||||||
void setDetail(const QString& val);
|
{
|
||||||
|
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);
|
||||||
|
int progressBarValue() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::DialogWaiting *ui;
|
Ui::DialogWaiting *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIALOGWAITING_H
|
#endif // DIALOGWAITING_H
|
||||||
|
|||||||
Reference in New Issue
Block a user