mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +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 "xmlelementcollection.h"
|
||||
#include "autoNum/assignvariables.h"
|
||||
#include "dialogwaiting.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -844,12 +845,29 @@ void ProjectView::initLayout() {
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -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 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
|
||||
{
|
||||
//So we open this files
|
||||
foreach(QString file, files)
|
||||
if (openAndAddProject(file, false))
|
||||
if (openAndAddProject(file))
|
||||
++ opened_projects;
|
||||
}
|
||||
|
||||
@@ -857,33 +858,39 @@ bool QETDiagramEditor::closeCurrentProject() {
|
||||
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 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
||||
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 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
||||
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 @@ 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);
|
||||
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 @@ bool QETDiagramEditor::openAndAddProject(const QString &filepath, bool interacti
|
||||
);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,7 +64,7 @@ class QETDiagramEditor : public QETMainWindow {
|
||||
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 ();
|
||||
|
||||
@@ -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
|
||||
//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 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
|
||||
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 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 @@ void DialogWaiting::setProgressBarRange(int min, int max){
|
||||
* @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 @@ void DialogWaiting::setDetail(const QString& 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
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMutex>
|
||||
|
||||
namespace Ui {
|
||||
class DialogWaiting;
|
||||
@@ -28,19 +29,56 @@ namespace Ui {
|
||||
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;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit DialogWaiting(QWidget *parent = nullptr);
|
||||
~DialogWaiting() override;
|
||||
static bool hasInstance()
|
||||
{
|
||||
if(m_static_dialog == nullptr)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void setProgressBar(int val);
|
||||
void setProgressBarRange(int min, int max);
|
||||
void setProgressReset();
|
||||
void setTitle(const QString& val);
|
||||
void setDetail(const QString& val);
|
||||
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);
|
||||
int progressBarValue() const;
|
||||
|
||||
private:
|
||||
Ui::DialogWaiting *ui;
|
||||
Ui::DialogWaiting *ui;
|
||||
};
|
||||
|
||||
#endif // DIALOGWAITING_H
|
||||
|
||||
Reference in New Issue
Block a user