2009-04-03 19:30:25 +00:00
|
|
|
/*
|
2019-01-13 16:56:12 +00:00
|
|
|
Copyright 2006-2019 The QElectroTech Team
|
2009-04-03 19:30:25 +00:00
|
|
|
This file is part of QElectroTech.
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "projectview.h"
|
|
|
|
#include "qetproject.h"
|
|
|
|
#include "diagramview.h"
|
|
|
|
#include "diagram.h"
|
|
|
|
#include "diagramprintdialog.h"
|
|
|
|
#include "exportdialog.h"
|
|
|
|
#include "qetapp.h"
|
|
|
|
#include "qetelementeditor.h"
|
|
|
|
#include "borderpropertieswidget.h"
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "titleblockpropertieswidget.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "conductorpropertieswidget.h"
|
2009-05-01 14:41:33 +00:00
|
|
|
#include "qeticons.h"
|
2009-08-09 16:02:14 +00:00
|
|
|
#include "qetmessagebox.h"
|
2011-12-27 01:40:32 +00:00
|
|
|
#include "qettemplateeditor.h"
|
2014-02-08 18:17:10 +00:00
|
|
|
#include "diagramfoliolist.h"
|
2014-08-15 13:16:58 +00:00
|
|
|
#include "projectpropertiesdialog.h"
|
2016-07-09 18:24:40 +00:00
|
|
|
#include "xmlelementcollection.h"
|
2017-02-18 13:30:38 +00:00
|
|
|
#include "autoNum/assignvariables.h"
|
2018-04-04 15:07:52 +00:00
|
|
|
#include "dialogwaiting.h"
|
2015-03-05 13:11:38 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param project projet a visualiser
|
|
|
|
@param parent Widget parent
|
|
|
|
*/
|
|
|
|
ProjectView::ProjectView(QETProject *project, QWidget *parent) :
|
|
|
|
QWidget(parent),
|
2017-08-05 02:06:59 +00:00
|
|
|
m_project(nullptr)
|
2009-04-03 19:30:25 +00:00
|
|
|
{
|
2012-07-08 13:00:14 +00:00
|
|
|
initActions();
|
|
|
|
initWidgets();
|
|
|
|
initLayout();
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
setProject(project);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructeur
|
|
|
|
Supprime les DiagramView embarquees
|
|
|
|
*/
|
|
|
|
ProjectView::~ProjectView() {
|
|
|
|
// qDebug() << "Suppression du ProjectView" << ((void *)this);
|
2017-02-18 13:30:38 +00:00
|
|
|
foreach(int id, m_diagram_ids.keys()) {
|
|
|
|
DiagramView *diagram_view = m_diagram_ids.take(id);
|
2009-04-03 19:30:25 +00:00
|
|
|
delete diagram_view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return le projet actuellement visualise par le ProjectView
|
|
|
|
*/
|
|
|
|
QETProject *ProjectView::project() {
|
2016-06-30 09:12:25 +00:00
|
|
|
return(m_project);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Definit le projet visualise par le ProjectView. Ne fait rien si le projet a
|
|
|
|
deja ete defini.
|
|
|
|
@param project projet a visualiser
|
|
|
|
*/
|
|
|
|
void ProjectView::setProject(QETProject *project) {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) {
|
|
|
|
m_project = project;
|
|
|
|
connect(m_project, SIGNAL(projectTitleChanged(QETProject *, const QString &)), this, SLOT(updateWindowTitle()));
|
|
|
|
connect(m_project, SIGNAL(projectModified (QETProject *, bool)), this, SLOT(updateWindowTitle()));
|
|
|
|
connect(m_project, SIGNAL(readOnlyChanged (QETProject *, bool)), this, SLOT(adjustReadOnlyState()));
|
|
|
|
connect(m_project, SIGNAL(addAutoNumDiagram()), this, SLOT(addNewDiagram()));
|
2010-02-28 16:13:45 +00:00
|
|
|
adjustReadOnlyState();
|
2009-04-03 19:30:25 +00:00
|
|
|
loadDiagrams();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la liste des schemas ouverts dans le projet
|
|
|
|
*/
|
2017-02-18 13:30:38 +00:00
|
|
|
QList<DiagramView *> ProjectView::diagram_views() const {
|
2016-08-10 06:55:16 +00:00
|
|
|
return(m_diagram_view_list);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-17 13:00:32 +00:00
|
|
|
* @brief ProjectView::currentDiagram
|
|
|
|
* @return The current active diagram view or nullptr if there isn't diagramView in this project view.
|
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
DiagramView *ProjectView::currentDiagram() const {
|
2015-03-05 13:11:38 +00:00
|
|
|
int current_tab_index = m_tab -> currentIndex();
|
2016-08-17 13:00:32 +00:00
|
|
|
if (current_tab_index == -1)
|
|
|
|
return nullptr;
|
2017-02-18 13:30:38 +00:00
|
|
|
return(m_diagram_ids[current_tab_index]);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gere la fermeture du schema.
|
2009-11-22 16:12:22 +00:00
|
|
|
@param qce Le QCloseEvent decrivant l'evenement
|
2009-04-03 19:30:25 +00:00
|
|
|
*/
|
|
|
|
void ProjectView::closeEvent(QCloseEvent *qce) {
|
2012-07-13 07:21:19 +00:00
|
|
|
bool can_close_project = tryClosing();
|
2009-04-03 19:30:25 +00:00
|
|
|
if (can_close_project) {
|
|
|
|
qce -> accept();
|
|
|
|
emit(projectClosed(this));
|
|
|
|
} else {
|
|
|
|
qce -> ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 15:00:22 +00:00
|
|
|
/**
|
|
|
|
@brief change current diagramview to next folio
|
|
|
|
*/
|
|
|
|
void ProjectView::changeTabDown(){
|
|
|
|
DiagramView *nextDiagramView = this->nextDiagram();
|
2017-08-05 02:06:59 +00:00
|
|
|
if (nextDiagramView!=nullptr){
|
2016-05-13 15:00:22 +00:00
|
|
|
rebuildDiagramsMap();
|
|
|
|
m_tab -> setCurrentWidget(nextDiagramView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return next folio of current diagramview
|
|
|
|
*/
|
|
|
|
DiagramView *ProjectView::nextDiagram() {
|
|
|
|
int current_tab_index = m_tab -> currentIndex();
|
|
|
|
int next_tab_index = current_tab_index + 1; //get next tab index
|
2017-02-18 13:30:38 +00:00
|
|
|
if (next_tab_index<m_diagram_ids.count()) //if next tab index >= greatest tab the last tab is activated so no need to change tab.
|
|
|
|
return(m_diagram_ids[next_tab_index]);
|
2016-05-13 15:00:22 +00:00
|
|
|
else
|
2017-08-05 02:06:59 +00:00
|
|
|
return nullptr;
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief change current diagramview to previous tab
|
|
|
|
*/
|
|
|
|
void ProjectView::changeTabUp(){
|
|
|
|
DiagramView *previousDiagramView = this->previousDiagram();
|
2017-08-05 02:06:59 +00:00
|
|
|
if (previousDiagramView!=nullptr){
|
2016-05-13 15:00:22 +00:00
|
|
|
rebuildDiagramsMap();
|
|
|
|
m_tab -> setCurrentWidget(previousDiagramView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return previous folio of current diagramview
|
|
|
|
*/
|
|
|
|
DiagramView *ProjectView::previousDiagram() {
|
|
|
|
int current_tab_index = m_tab -> currentIndex();
|
|
|
|
int previous_tab_index = current_tab_index - 1; //get previous tab index
|
|
|
|
if (previous_tab_index>=0) //if previous tab index = 0 then the first tab is activated so no need to change tab.
|
2017-02-18 13:30:38 +00:00
|
|
|
return(m_diagram_ids[previous_tab_index]);
|
2016-05-13 15:00:22 +00:00
|
|
|
else
|
2017-08-05 02:06:59 +00:00
|
|
|
return nullptr;
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief change current diagramview to last tab
|
|
|
|
*/
|
|
|
|
void ProjectView::changeLastTab(){
|
|
|
|
DiagramView *lastDiagramView = this->lastDiagram();
|
|
|
|
m_tab->setCurrentWidget(lastDiagramView);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return last folio of current project
|
|
|
|
*/
|
|
|
|
DiagramView *ProjectView::lastDiagram(){
|
2017-02-18 13:30:38 +00:00
|
|
|
return(m_diagram_ids.last());
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief change current diagramview to first tab
|
|
|
|
*/
|
|
|
|
void ProjectView::changeFirstTab(){
|
|
|
|
DiagramView *firstDiagramView = this->firstDiagram();
|
|
|
|
m_tab->setCurrentWidget(firstDiagramView);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return first folio of current project
|
|
|
|
*/
|
|
|
|
DiagramView *ProjectView::firstDiagram(){
|
2017-02-18 13:30:38 +00:00
|
|
|
return(m_diagram_ids.first());
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
Cette methode essaye de fermer successivement les editeurs d'element puis
|
|
|
|
les schemas du projet. L'utilisateur peut refuser de fermer un schema ou un
|
|
|
|
editeur.
|
|
|
|
@return true si tout a pu etre ferme, false sinon
|
|
|
|
@see tryClosingElementEditors()
|
|
|
|
@see tryClosingDiagrams()
|
|
|
|
*/
|
|
|
|
bool ProjectView::tryClosing() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return(true);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
// First step: require external editors closing -- users may either cancel
|
|
|
|
// the whole closing process or save (and therefore add) content into this
|
|
|
|
// project. Of course, they may also discard them.
|
2009-04-03 19:30:25 +00:00
|
|
|
if (!tryClosingElementEditors()) {
|
|
|
|
return(false);
|
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
// Check how different the current situation is from a brand new, untouched project
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> filePath().isEmpty() && !m_project -> projectWasModified()) {
|
2012-07-13 07:21:19 +00:00
|
|
|
return(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
// Second step: users are presented with a dialog that enables them to
|
|
|
|
// choose whether they want to:
|
|
|
|
// - cancel the closing process,
|
|
|
|
// - discard all modifications,
|
|
|
|
// - or specify what is to be saved, i.e. they choose whether they wants to
|
|
|
|
// save/give up/remove diagrams considered as modified.
|
|
|
|
int user_input = tryClosingDiagrams();
|
2014-01-05 15:00:46 +00:00
|
|
|
if (user_input == QMessageBox::Cancel) {
|
2012-07-13 07:21:19 +00:00
|
|
|
return(false); // the closing process was cancelled
|
2014-01-05 15:00:46 +00:00
|
|
|
} else if (user_input == QMessageBox::Discard) {
|
2012-07-13 07:21:19 +00:00
|
|
|
return(true); // all modifications were discarded
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
// Check how different the current situation is from a brand new, untouched project (yes , again)
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> filePath().isEmpty() && !m_project -> projectWasModified()) {
|
2012-07-13 07:21:19 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> filePath().isEmpty()) {
|
2012-07-13 07:21:19 +00:00
|
|
|
QString filepath = askUserForFilePath();
|
|
|
|
if (filepath.isEmpty()) return(false); // users may cancel the closing
|
|
|
|
}
|
2016-06-30 09:12:25 +00:00
|
|
|
QETResult result = m_project -> write();
|
2012-07-13 07:21:19 +00:00
|
|
|
updateWindowTitle();
|
|
|
|
if (!result.isOk()) emit(errorEncountered(result.errorMessage()));
|
|
|
|
return(result.isOk());
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Un projet comporte des elements integres. Cette methode ferme les editeurs
|
|
|
|
d'elements associes a ce projet. L'utilisateur peut refuser la fermeture
|
|
|
|
d'un editeur d'element.
|
|
|
|
@return true si tous les editeurs d'element ont pu etre fermes, false sinon
|
|
|
|
*/
|
|
|
|
bool ProjectView::tryClosingElementEditors() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
/*
|
|
|
|
La QETApp permet d'acceder rapidement aux editeurs d'element
|
|
|
|
editant un element du projet.
|
|
|
|
*/
|
2016-06-30 09:12:25 +00:00
|
|
|
QList<QETElementEditor *> editors = QETApp::elementEditors(m_project);
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETElementEditor *editor, editors) {
|
2009-04-03 19:30:25 +00:00
|
|
|
if (!editor -> close()) return(false);
|
2011-12-27 01:40:32 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
QList<QETTitleBlockTemplateEditor *> template_editors = QETApp::titleBlockTemplateEditors(m_project);
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETTitleBlockTemplateEditor *template_editor, template_editors) {
|
2011-12-27 01:40:32 +00:00
|
|
|
if (!template_editor -> close()) return(false);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-05 15:00:46 +00:00
|
|
|
* @brief ProjectView::tryClosingDiagrams
|
|
|
|
* try to close this project, if diagram or project option are changed
|
|
|
|
* a dialog ask if user want to save the modification.
|
|
|
|
* @return the answer of dialog or discard if no change.
|
|
|
|
*/
|
2012-07-13 07:21:19 +00:00
|
|
|
int ProjectView::tryClosingDiagrams() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return(QMessageBox::Discard);
|
2014-01-05 15:00:46 +00:00
|
|
|
|
|
|
|
if (!project()->projectOptionsWereModified() &&
|
|
|
|
project()->undoStack()->isClean() &&
|
|
|
|
!project()->filePath().isEmpty()) {
|
2012-07-13 07:21:19 +00:00
|
|
|
// nothing was modified, and we have a filepath, i.e. everything was already
|
|
|
|
// saved, i.e we can close the project right now
|
2014-01-05 15:00:46 +00:00
|
|
|
return(QMessageBox::Discard);
|
2012-07-13 07:21:19 +00:00
|
|
|
}
|
2014-01-05 15:00:46 +00:00
|
|
|
|
2014-01-16 09:44:11 +00:00
|
|
|
QString title = project()->title();
|
2014-01-23 21:43:14 +00:00
|
|
|
if (title.isEmpty()) title = "QElectroTech ";
|
2014-01-16 09:44:11 +00:00
|
|
|
|
|
|
|
int close_dialog = QMessageBox::question(this, title,
|
2015-03-02 20:14:56 +00:00
|
|
|
tr("Le projet à été modifié.\n"
|
2014-01-05 15:00:46 +00:00
|
|
|
"Voulez-vous enregistrer les modifications ?"),
|
|
|
|
QMessageBox::Save | QMessageBox::Discard
|
|
|
|
| QMessageBox::Cancel,
|
|
|
|
QMessageBox::Save);
|
|
|
|
|
|
|
|
return(close_dialog);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 05:54:45 +00:00
|
|
|
/**
|
|
|
|
Ask the user to provide a file path in which the currently edited project will
|
|
|
|
be saved.
|
|
|
|
@param assign When true, assign the provided filepath to the project through
|
|
|
|
setFilePath(). Defaults to true.
|
|
|
|
@return the file path, or an empty string if none were provided
|
|
|
|
*/
|
|
|
|
QString ProjectView::askUserForFilePath(bool assign) {
|
|
|
|
// ask the user for a filepath in order to save the project
|
|
|
|
QString filepath = QFileDialog::getSaveFileName(
|
|
|
|
this,
|
|
|
|
tr("Enregistrer sous", "dialog title"),
|
2016-06-30 09:12:25 +00:00
|
|
|
m_project -> currentDir(),
|
2016-05-13 15:00:22 +00:00
|
|
|
tr("Projet QElectroTech (*.qet)", "filetypes allowed when saving a project file")
|
2012-07-05 05:54:45 +00:00
|
|
|
);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-05 05:54:45 +00:00
|
|
|
// if no filepath is provided, return an empty string
|
|
|
|
if (filepath.isEmpty()) return(filepath);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2019-09-03 22:54:09 +02:00
|
|
|
// // if the name does not end with the .qet extension, append it
|
|
|
|
// if (!filepath.endsWith(".qet", Qt::CaseInsensitive)) filepath += ".qet";
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-05 05:54:45 +00:00
|
|
|
if (assign) {
|
|
|
|
// assign the provided filepath to the currently edited project
|
2016-06-30 09:12:25 +00:00
|
|
|
m_project -> setFilePath(filepath);
|
2012-07-05 05:54:45 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-05 05:54:45 +00:00
|
|
|
return(filepath);
|
|
|
|
}
|
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
/**
|
|
|
|
@return the QETResult object to be returned when it appears this project
|
|
|
|
view is not associated to any project.
|
|
|
|
*/
|
|
|
|
QETResult ProjectView::noProjectResult() const {
|
2015-03-02 20:14:56 +00:00
|
|
|
QETResult no_project(tr("aucun projet affiché", "error message"), false);
|
2012-07-13 07:21:19 +00:00
|
|
|
return(no_project);
|
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2014-09-18 18:12:05 +00:00
|
|
|
* @brief ProjectView::addNewDiagram
|
|
|
|
* Add new diagram to project view
|
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
void ProjectView::addNewDiagram() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> isReadOnly()) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
Diagram *new_diagram = m_project -> addNewDiagram();
|
2018-07-30 15:24:29 +00:00
|
|
|
DiagramView *new_diagram_view = new DiagramView(new_diagram);
|
2009-04-03 19:30:25 +00:00
|
|
|
addDiagram(new_diagram_view);
|
2014-02-08 18:17:10 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> diagrams().size() % 58 == 1 && m_project -> getFolioSheetsQuantity() != 0)
|
2014-02-08 18:17:10 +00:00
|
|
|
addNewDiagramFolioList();
|
2009-04-03 19:30:25 +00:00
|
|
|
showDiagram(new_diagram_view);
|
|
|
|
}
|
|
|
|
|
2014-09-18 18:12:05 +00:00
|
|
|
/**
|
|
|
|
* @brief ProjectView::addNewDiagramFolioList
|
|
|
|
* Add new diagram folio list to project
|
|
|
|
*/
|
2014-02-07 07:54:54 +00:00
|
|
|
void ProjectView::addNewDiagramFolioList() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> isReadOnly()) return;
|
2019-08-17 11:41:59 +02:00
|
|
|
QSettings settings;
|
2019-08-20 13:11:23 +02:00
|
|
|
int i = (settings.value("projectview/foliolist_position").toInt() -1); //< Each new diagram is added to the end of the project.
|
2014-11-17 10:10:00 +00:00
|
|
|
//< We use @i to move the folio list at second position in the project
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Diagram *d, m_project -> addNewDiagramFolioList()) {
|
2018-07-30 15:24:29 +00:00
|
|
|
DiagramView *new_diagram_view = new DiagramView(d);
|
2014-09-19 10:22:57 +00:00
|
|
|
addDiagram(new_diagram_view);
|
2014-09-18 18:12:05 +00:00
|
|
|
showDiagram(new_diagram_view);
|
2017-02-18 13:30:38 +00:00
|
|
|
m_tab->tabBar()->moveTab(diagram_views().size()-1, i);
|
2014-09-19 10:22:57 +00:00
|
|
|
i++;
|
2019-08-17 11:41:59 +02:00
|
|
|
m_project->setModified(true);
|
2014-09-18 18:12:05 +00:00
|
|
|
}
|
2014-02-07 07:54:54 +00:00
|
|
|
}
|
|
|
|
|
2014-02-08 23:54:15 +00:00
|
|
|
/**
|
|
|
|
* @brief ProjectView::addDiagram
|
2017-02-18 13:30:38 +00:00
|
|
|
* Add diagram view to this project view
|
|
|
|
* @param diagram_view
|
2014-02-08 23:54:15 +00:00
|
|
|
*/
|
2017-02-18 13:30:38 +00:00
|
|
|
void ProjectView::addDiagram(DiagramView *diagram_view)
|
|
|
|
{
|
|
|
|
if (!diagram_view)
|
|
|
|
return;
|
2014-02-08 23:54:15 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
//Check if diagram isn't present in the project
|
|
|
|
if (m_diagram_ids.values().contains(diagram_view))
|
|
|
|
return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
// Add new tab for the diagram
|
2019-08-17 11:41:59 +02:00
|
|
|
m_tab->addTab(diagram_view, QET::Icons::Diagram, diagram_view -> title());
|
2017-02-18 13:30:38 +00:00
|
|
|
diagram_view->setFrameStyle(QFrame::Plain | QFrame::NoFrame);
|
2014-02-10 11:48:05 +00:00
|
|
|
|
2016-08-10 06:55:16 +00:00
|
|
|
m_diagram_view_list << diagram_view;
|
2014-02-10 11:48:05 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
rebuildDiagramsMap();
|
2017-06-20 19:15:39 +00:00
|
|
|
updateAllTabsTitle();
|
2017-02-18 13:30:38 +00:00
|
|
|
|
2016-08-10 06:55:16 +00:00
|
|
|
connect(diagram_view, SIGNAL(showDiagram(Diagram*)), this, SLOT(showDiagram(Diagram*)));
|
2017-02-18 13:30:38 +00:00
|
|
|
connect(diagram_view, SIGNAL(titleChanged(DiagramView *, const QString &)), this, SLOT(updateTabTitle(DiagramView *)));
|
2016-08-10 06:55:16 +00:00
|
|
|
connect(diagram_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SIGNAL(findElementRequired(const ElementsLocation &)));
|
|
|
|
connect(diagram_view, SIGNAL(editElementRequired(const ElementsLocation &)), this, SIGNAL(editElementRequired(const ElementsLocation &)));
|
2017-02-18 13:30:38 +00:00
|
|
|
connect(&diagram_view->diagram()->border_and_titleblock , &BorderTitleBlock::titleBlockFolioChanged, [this, diagram_view]() {this->updateTabTitle(diagram_view);});
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
// signal diagram view was added
|
2016-08-10 06:55:16 +00:00
|
|
|
emit(diagramAdded(diagram_view));
|
2019-06-12 00:48:36 +00:00
|
|
|
m_project -> setModified(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-20 19:15:39 +00:00
|
|
|
* @brief ProjectView::removeDiagram
|
|
|
|
* Remove a diagram (folio) of the project
|
|
|
|
* @param diagram_view : diagram view to remove
|
|
|
|
*/
|
|
|
|
void ProjectView::removeDiagram(DiagramView *diagram_view)
|
|
|
|
{
|
|
|
|
if (!diagram_view)
|
|
|
|
return;
|
|
|
|
if (m_project -> isReadOnly())
|
|
|
|
return;
|
|
|
|
if (!m_diagram_ids.values().contains(diagram_view))
|
|
|
|
return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2014-11-27 17:57:10 +00:00
|
|
|
|
2017-06-20 19:15:39 +00:00
|
|
|
//Ask confirmation to user.
|
2015-03-02 20:14:56 +00:00
|
|
|
int answer = QET::QetMessageBox::question(
|
2014-11-27 17:57:10 +00:00
|
|
|
this,
|
2016-05-13 15:00:22 +00:00
|
|
|
tr("Supprimer le folio ?", "message box title"),
|
|
|
|
tr("Êtes-vous sûr de vouloir supprimer ce folio du projet ? Ce changement est irréversible.", "message box content"),
|
2014-11-27 17:57:10 +00:00
|
|
|
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
|
|
|
QMessageBox::No
|
|
|
|
);
|
|
|
|
if (answer != QMessageBox::Yes) {
|
|
|
|
return;
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2017-06-20 19:15:39 +00:00
|
|
|
//Remove the diagram view of the tabs widget
|
|
|
|
int index_to_remove = m_diagram_ids.key(diagram_view);
|
|
|
|
m_tab->removeTab(index_to_remove);
|
2016-08-10 06:55:16 +00:00
|
|
|
m_diagram_view_list.removeAll(diagram_view);
|
2009-04-03 19:30:25 +00:00
|
|
|
rebuildDiagramsMap();
|
2017-06-20 19:15:39 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
m_project -> removeDiagram(diagram_view -> diagram());
|
2009-04-03 19:30:25 +00:00
|
|
|
delete diagram_view;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
emit(diagramRemoved(diagram_view));
|
2019-06-12 00:48:36 +00:00
|
|
|
|
2017-06-20 19:15:39 +00:00
|
|
|
//Make definitve the withdrawal
|
2016-06-30 09:12:25 +00:00
|
|
|
m_project -> write();
|
2017-06-20 19:15:39 +00:00
|
|
|
updateAllTabsTitle();
|
2019-06-12 00:48:36 +00:00
|
|
|
m_project -> setModified(true);
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enleve un schema du ProjectView
|
2009-11-22 16:12:22 +00:00
|
|
|
@param diagram Schema a enlever
|
2009-04-03 19:30:25 +00:00
|
|
|
*/
|
|
|
|
void ProjectView::removeDiagram(Diagram *diagram) {
|
|
|
|
if (!diagram) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
if (DiagramView *diagram_view = findDiagram(diagram)) {
|
|
|
|
removeDiagram(diagram_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Active l'onglet adequat pour afficher le schema passe en parametre
|
|
|
|
@param diagram Schema a afficher
|
|
|
|
*/
|
|
|
|
void ProjectView::showDiagram(DiagramView *diagram) {
|
|
|
|
if (!diagram) return;
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setCurrentWidget(diagram);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Active l'onglet adequat pour afficher le schema passe en parametre
|
|
|
|
@param diagram Schema a afficher
|
|
|
|
*/
|
|
|
|
void ProjectView::showDiagram(Diagram *diagram) {
|
|
|
|
if (!diagram) return;
|
|
|
|
if (DiagramView *diagram_view = findDiagram(diagram)) {
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setCurrentWidget(diagram_view);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-29 05:21:41 +00:00
|
|
|
Enable the user to edit properties of the current project through a
|
|
|
|
configuration dialog.
|
2009-04-03 19:30:25 +00:00
|
|
|
*/
|
|
|
|
void ProjectView::editProjectProperties() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return;
|
|
|
|
ProjectPropertiesDialog dialog(m_project, parentWidget());
|
2014-08-15 13:16:58 +00:00
|
|
|
dialog.exec();
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Edite les proprietes du schema courant
|
|
|
|
*/
|
|
|
|
void ProjectView::editCurrentDiagramProperties() {
|
|
|
|
editDiagramProperties(currentDiagram());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Edite les proprietes du schema diagram_view
|
|
|
|
*/
|
|
|
|
void ProjectView::editDiagramProperties(DiagramView *diagram_view) {
|
|
|
|
if (!diagram_view) return;
|
|
|
|
showDiagram(diagram_view);
|
|
|
|
diagram_view -> editDiagramProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Edite les proprietes du schema diagram
|
|
|
|
*/
|
|
|
|
void ProjectView::editDiagramProperties(Diagram *diagram) {
|
|
|
|
editDiagramProperties(findDiagram(diagram));
|
|
|
|
}
|
|
|
|
|
2010-02-28 16:13:45 +00:00
|
|
|
/**
|
|
|
|
Deplace le schema diagram_view vers le haut / la gauche
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramUp(DiagramView *diagram_view) {
|
|
|
|
if (!diagram_view) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
int diagram_view_position = m_diagram_ids.key(diagram_view);
|
2010-02-28 16:13:45 +00:00
|
|
|
if (!diagram_view_position) {
|
|
|
|
// le schema est le premier du projet
|
|
|
|
return;
|
|
|
|
}
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position - 1);
|
2010-02-28 16:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deplace le schema diagram vers le haut / la gauche
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramUp(Diagram *diagram) {
|
|
|
|
moveDiagramUp(findDiagram(diagram));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deplace le schema diagram_view vers le bas / la droite
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramDown(DiagramView *diagram_view) {
|
|
|
|
if (!diagram_view) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
int diagram_view_position = m_diagram_ids.key(diagram_view);
|
|
|
|
if (diagram_view_position + 1 == m_diagram_ids.count()) {
|
2010-02-28 16:13:45 +00:00
|
|
|
// le schema est le dernier du projet
|
|
|
|
return;
|
|
|
|
}
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position + 1);
|
2010-02-28 16:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deplace le schema diagram vers le bas / la droite
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramDown(Diagram *diagram) {
|
|
|
|
moveDiagramDown(findDiagram(diagram));
|
|
|
|
}
|
|
|
|
|
2015-03-05 13:31:56 +00:00
|
|
|
/*
|
|
|
|
* Deplace le schema diagram_view vers le haut / la gauche en position 0
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramUpTop(DiagramView *diagram_view)
|
|
|
|
{
|
|
|
|
if (!diagram_view) return;
|
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
int diagram_view_position = m_diagram_ids.key(diagram_view);
|
2015-03-05 13:31:56 +00:00
|
|
|
if (!diagram_view_position) {
|
|
|
|
// le schema est le premier du projet
|
|
|
|
return;
|
|
|
|
}
|
2017-02-18 13:30:38 +00:00
|
|
|
m_tab -> tabBar() -> moveTab(diagram_view_position, (diagram_views().size(), 0));
|
2015-03-05 13:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deplace le schema diagram vers le haut / la gauche en position 0
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramUpTop(Diagram *diagram)
|
|
|
|
{
|
|
|
|
moveDiagramUpTop(findDiagram(diagram));
|
|
|
|
}
|
|
|
|
|
2014-12-14 17:01:11 +00:00
|
|
|
/**
|
|
|
|
Deplace le schema diagram_view vers le haut / la gauche x10
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramUpx10(DiagramView *diagram_view) {
|
|
|
|
if (!diagram_view) return;
|
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
int diagram_view_position = m_diagram_ids.key(diagram_view);
|
2014-12-14 17:01:11 +00:00
|
|
|
if (!diagram_view_position) {
|
|
|
|
// le schema est le premier du projet
|
|
|
|
return;
|
|
|
|
}
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position - 10);
|
2014-12-14 17:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deplace le schema diagram vers le haut / la gauche x10
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramUpx10(Diagram *diagram) {
|
|
|
|
moveDiagramUpx10(findDiagram(diagram));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deplace le schema diagram_view vers le bas / la droite x10
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramDownx10(DiagramView *diagram_view) {
|
|
|
|
if (!diagram_view) return;
|
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
int diagram_view_position = m_diagram_ids.key(diagram_view);
|
|
|
|
if (diagram_view_position + 1 == m_diagram_ids.count()) {
|
2014-12-14 17:01:11 +00:00
|
|
|
// le schema est le dernier du projet
|
|
|
|
return;
|
|
|
|
}
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position + 10);
|
2014-12-14 17:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deplace le schema diagram vers le bas / la droite x10
|
|
|
|
*/
|
|
|
|
void ProjectView::moveDiagramDownx10(Diagram *diagram) {
|
|
|
|
moveDiagramDownx10(findDiagram(diagram));
|
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
Ce slot demarre un dialogue permettant a l'utilisateur de parametrer et de
|
|
|
|
lancer l'impression de toute ou partie du projet.
|
|
|
|
*/
|
|
|
|
void ProjectView::printProject() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// transforme le titre du projet en nom utilisable pour le document
|
|
|
|
QString doc_name;
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!(m_project -> title().isEmpty())) {
|
|
|
|
doc_name = m_project -> title();
|
|
|
|
} else if (!m_project -> filePath().isEmpty()) {
|
|
|
|
doc_name = QFileInfo(m_project -> filePath()).baseName();
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
doc_name = QET::stringToFileName(doc_name);
|
|
|
|
if (doc_name.isEmpty()) {
|
|
|
|
doc_name = tr("projet", "string used to generate a filename");
|
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// recupere le dossier contenant le fichier courant
|
2016-06-30 09:12:25 +00:00
|
|
|
QString dir_path = m_project -> currentDir();
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// determine un chemin pour le pdf / ps
|
2010-01-03 19:51:02 +00:00
|
|
|
QString file_name = QDir::toNativeSeparators(QDir::cleanPath(dir_path + "/" + doc_name));
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
DiagramPrintDialog print_dialog(m_project, this);
|
2009-04-03 19:30:25 +00:00
|
|
|
print_dialog.setDocName(doc_name);
|
|
|
|
print_dialog.setFileName(file_name);
|
|
|
|
print_dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Exporte le schema.
|
|
|
|
*/
|
|
|
|
void ProjectView::exportProject() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
ExportDialog ed(m_project, parentWidget());
|
2019-09-08 18:29:29 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2009-08-09 19:20:21 +00:00
|
|
|
ed.setWindowFlags(Qt::Sheet);
|
2009-08-09 16:43:03 +00:00
|
|
|
#endif
|
2009-04-03 19:30:25 +00:00
|
|
|
ed.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-13 07:21:19 +00:00
|
|
|
Save project properties along with all modified diagrams.
|
2009-04-03 19:30:25 +00:00
|
|
|
@see filePath()
|
|
|
|
@see setFilePath()
|
2012-07-13 07:21:19 +00:00
|
|
|
@return a QETResult object reflecting the situation
|
|
|
|
*/
|
|
|
|
QETResult ProjectView::save() {
|
2017-03-05 12:24:33 +00:00
|
|
|
return(doSave());
|
2012-07-13 07:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ask users for a filepath in order to save the project.
|
|
|
|
@param options May be used to specify what should be saved; defaults to
|
|
|
|
all modified diagrams.
|
|
|
|
@return a QETResult object reflecting the situation; note that a valid
|
|
|
|
QETResult object is returned if the operation was cancelled.
|
|
|
|
*/
|
2017-03-05 12:24:33 +00:00
|
|
|
QETResult ProjectView::saveAs()
|
|
|
|
{
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return(noProjectResult());
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
QString filepath = askUserForFilePath();
|
|
|
|
if (filepath.isEmpty()) return(QETResult());
|
2017-03-05 12:24:33 +00:00
|
|
|
return(doSave());
|
2012-07-13 07:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-05 12:24:33 +00:00
|
|
|
Save project content, then write the project file. May
|
2012-07-13 07:21:19 +00:00
|
|
|
call saveAs if no filepath was provided before.
|
|
|
|
@return a QETResult object reflecting the situation; note that a valid
|
|
|
|
QETResult object is returned if the operation was cancelled.
|
|
|
|
*/
|
2017-03-05 12:24:33 +00:00
|
|
|
QETResult ProjectView::doSave()
|
|
|
|
{
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return(noProjectResult());
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> filePath().isEmpty()) {
|
2012-07-13 07:21:19 +00:00
|
|
|
// The project has not been saved to a file yet,
|
|
|
|
// so save() actually means saveAs().
|
2017-03-05 12:24:33 +00:00
|
|
|
return(saveAs());
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-13 07:21:19 +00:00
|
|
|
// write to file
|
2016-06-30 09:12:25 +00:00
|
|
|
QETResult result = m_project -> write();
|
2012-07-07 19:45:32 +00:00
|
|
|
updateWindowTitle();
|
2017-03-05 12:24:33 +00:00
|
|
|
project()->undoStack()->clear();
|
2012-07-07 19:45:32 +00:00
|
|
|
return(result);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-24 07:11:19 +00:00
|
|
|
Allow the user to clean the project, which includes:
|
|
|
|
* deleting unused title block templates
|
|
|
|
* deleting unused elements
|
|
|
|
* deleting empty categories
|
|
|
|
@return an integer value above zero if elements and/or categories were
|
|
|
|
cleaned.
|
2009-04-03 19:30:25 +00:00
|
|
|
*/
|
|
|
|
int ProjectView::cleanProject() {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return(0);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// s'assure que le schema n'est pas en lecture seule
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> isReadOnly()) {
|
2015-03-02 20:14:56 +00:00
|
|
|
QET::QetMessageBox::critical(
|
2009-04-03 19:30:25 +00:00
|
|
|
this,
|
|
|
|
tr("Projet en lecture seule", "message box title"),
|
|
|
|
tr("Ce projet est en lecture seule. Il n'est donc pas possible de le nettoyer.", "message box content")
|
|
|
|
);
|
|
|
|
return(0);
|
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// construit un petit dialogue pour parametrer le nettoyage
|
2016-05-13 15:00:22 +00:00
|
|
|
QCheckBox *clean_tbt = new QCheckBox(tr("Supprimer les modèles de cartouche inutilisés dans le projet"));
|
2015-03-02 20:14:56 +00:00
|
|
|
QCheckBox *clean_elements = new QCheckBox(tr("Supprimer les éléments inutilisés dans le projet"));
|
|
|
|
QCheckBox *clean_categories = new QCheckBox(tr("Supprimer les catégories vides"));
|
2009-04-03 19:30:25 +00:00
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
|
|
|
clean_tbt -> setChecked(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
clean_elements -> setChecked(true);
|
|
|
|
clean_categories -> setChecked(true);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-08-09 16:43:03 +00:00
|
|
|
QDialog clean_dialog(parentWidget());
|
2019-09-08 18:29:29 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2009-08-09 16:43:03 +00:00
|
|
|
clean_dialog.setWindowFlags(Qt::Sheet);
|
|
|
|
#endif
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
clean_dialog.setWindowTitle(tr("Nettoyer le projet", "window title"));
|
2018-07-30 15:24:29 +00:00
|
|
|
QVBoxLayout *clean_dialog_layout = new QVBoxLayout();
|
2012-01-24 07:11:19 +00:00
|
|
|
clean_dialog_layout -> addWidget(clean_tbt);
|
2009-04-03 19:30:25 +00:00
|
|
|
clean_dialog_layout -> addWidget(clean_elements);
|
|
|
|
clean_dialog_layout -> addWidget(clean_categories);
|
|
|
|
clean_dialog_layout -> addWidget(buttons);
|
|
|
|
clean_dialog.setLayout(clean_dialog_layout);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
connect(buttons, SIGNAL(accepted()), &clean_dialog, SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), &clean_dialog, SLOT(reject()));
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
int clean_count = 0;
|
2015-11-16 08:59:43 +00:00
|
|
|
if (clean_dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
2012-01-24 07:11:19 +00:00
|
|
|
if (clean_tbt -> isChecked()) {
|
2016-06-30 09:12:25 +00:00
|
|
|
m_project->embeddedTitleBlockTemplatesCollection()->deleteUnusedTitleBlocKTemplates();
|
2012-01-24 07:11:19 +00:00
|
|
|
}
|
2016-07-09 18:24:40 +00:00
|
|
|
if (clean_elements->isChecked()) {
|
|
|
|
m_project->embeddedElementCollection()->cleanUnusedElement();
|
|
|
|
}
|
|
|
|
if (clean_categories->isChecked()) {
|
|
|
|
m_project->embeddedElementCollection()->cleanUnusedDirectory();
|
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
2019-06-12 01:03:02 +00:00
|
|
|
|
|
|
|
m_project -> setModified(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
return(clean_count);
|
|
|
|
}
|
|
|
|
|
2012-07-08 13:00:14 +00:00
|
|
|
/**
|
|
|
|
Initialize actions for this widget.
|
|
|
|
*/
|
|
|
|
void ProjectView::initActions() {
|
2016-05-13 15:00:22 +00:00
|
|
|
add_new_diagram_ = new QAction(QET::Icons::AddFolio, tr("Ajouter un folio"), this);
|
2012-07-08 13:00:14 +00:00
|
|
|
connect(add_new_diagram_, SIGNAL(triggered()), this, SLOT(addNewDiagram()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize child widgets for this widget.
|
|
|
|
*/
|
|
|
|
void ProjectView::initWidgets() {
|
|
|
|
setObjectName("ProjectView");
|
2015-03-12 15:31:41 +00:00
|
|
|
setWindowIcon(QET::Icons::ProjectFileGP);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-08 13:00:14 +00:00
|
|
|
// initialize the "fallback" widget
|
|
|
|
fallback_widget_ = new QWidget();
|
|
|
|
fallback_label_ = new QLabel(
|
|
|
|
tr(
|
2016-05-13 15:00:22 +00:00
|
|
|
"Ce projet ne contient aucun folio",
|
2012-07-08 13:00:14 +00:00
|
|
|
"label displayed when a project contains no diagram"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
fallback_label_ -> setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-08 13:00:14 +00:00
|
|
|
// initialize tabs
|
2019-09-08 18:06:52 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
m_tab = new WheelEnabledTabBar(this);
|
|
|
|
#else
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab = new QTabWidget(this);
|
2019-09-08 18:06:52 +02:00
|
|
|
#endif
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setMovable(true);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QToolButton *add_new_diagram_button = new QToolButton;
|
2012-07-08 13:00:14 +00:00
|
|
|
add_new_diagram_button -> setDefaultAction(add_new_diagram_);
|
|
|
|
add_new_diagram_button -> setAutoRaise(true);
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setCornerWidget(add_new_diagram_button, Qt::TopRightCorner);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2015-03-05 13:11:38 +00:00
|
|
|
connect(m_tab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
|
|
|
|
connect(m_tab, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(tabDoubleClicked(int)));
|
|
|
|
connect(m_tab->tabBar(), SIGNAL(tabMoved(int, int)), this, SLOT(tabMoved(int, int)));
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-08 13:00:14 +00:00
|
|
|
fallback_widget_ -> setVisible(false);
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setVisible(false);
|
2012-07-08 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize layout for this widget.
|
|
|
|
*/
|
|
|
|
void ProjectView::initLayout() {
|
2018-07-30 15:24:29 +00:00
|
|
|
QVBoxLayout *fallback_widget_layout_ = new QVBoxLayout(fallback_widget_);
|
2012-07-08 13:00:14 +00:00
|
|
|
fallback_widget_layout_ -> addWidget(fallback_label_);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-08 13:00:14 +00:00
|
|
|
layout_ = new QVBoxLayout(this);
|
2019-09-08 18:29:29 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2012-07-08 13:00:14 +00:00
|
|
|
layout_ -> setContentsMargins(0, 8, 0, 0);
|
|
|
|
#else
|
|
|
|
layout_ -> setContentsMargins(0, 0, 0, 0);
|
|
|
|
#endif
|
|
|
|
layout_ -> setSpacing(0);
|
|
|
|
layout_ -> addWidget(fallback_widget_);
|
2015-03-05 13:11:38 +00:00
|
|
|
layout_ -> addWidget(m_tab);
|
2012-07-08 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 10:22:57 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2014-09-19 10:22:57 +00:00
|
|
|
* @brief ProjectView::loadDiagrams
|
|
|
|
* Load diagrams of project.
|
|
|
|
* We create a diagram view for each diagram,
|
|
|
|
* and add it to the project view.
|
|
|
|
*/
|
2018-04-04 15:07:52 +00:00
|
|
|
void ProjectView::loadDiagrams()
|
|
|
|
{
|
2016-06-30 09:12:25 +00:00
|
|
|
if (!m_project) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
setDisplayFallbackWidget(m_project -> diagrams().isEmpty());
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2018-04-04 15:07:52 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
DiagramView *sv = new DiagramView(diagram);
|
2009-04-03 19:30:25 +00:00
|
|
|
addDiagram(sv);
|
|
|
|
}
|
2014-09-19 10:22:57 +00:00
|
|
|
|
2019-09-27 19:25:38 +02:00
|
|
|
if (DiagramView *dv = currentDiagram())
|
|
|
|
{
|
|
|
|
dv->diagram()->loadElmtFolioSeq();
|
|
|
|
dv->diagram()->loadCndFolioSeq();
|
|
|
|
}
|
2019-08-17 11:41:59 +02:00
|
|
|
|
|
|
|
QSettings settings;
|
2019-09-27 19:25:38 +02:00
|
|
|
// If project have the folios list, move it at the beginning of the project
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project -> getFolioSheetsQuantity()) {
|
|
|
|
for (int i = 0; i < m_project->getFolioSheetsQuantity(); i++)
|
2019-08-20 13:11:23 +02:00
|
|
|
m_tab -> tabBar() -> moveTab(diagram_views().size()-1, + (settings.value("projectview/foliolist_position").toInt() -1));
|
2019-06-10 11:34:57 +00:00
|
|
|
m_project->setModified(false);
|
2014-09-19 10:22:57 +00:00
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-19 10:22:57 +00:00
|
|
|
* @brief ProjectView::updateWindowTitle
|
|
|
|
* Update the project view title
|
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
void ProjectView::updateWindowTitle() {
|
|
|
|
QString title;
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_project) {
|
|
|
|
title = m_project -> pathNameTitle();
|
2009-04-03 19:30:25 +00:00
|
|
|
} else {
|
|
|
|
title = tr("Projet", "window title for a project-less ProjectView");
|
|
|
|
}
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
2010-02-28 16:13:45 +00:00
|
|
|
/**
|
|
|
|
Effectue les actions necessaires lorsque le projet visualise entre ou sort
|
|
|
|
du mode lecture seule.
|
|
|
|
*/
|
|
|
|
void ProjectView::adjustReadOnlyState() {
|
2016-06-30 09:12:25 +00:00
|
|
|
bool editable = !(m_project -> isReadOnly());
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2012-07-08 13:00:14 +00:00
|
|
|
// prevent users from moving existing diagrams
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setMovable(editable);
|
2012-07-08 13:00:14 +00:00
|
|
|
// prevent users from adding new diagrams
|
|
|
|
add_new_diagram_ -> setEnabled(editable);
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2010-02-28 16:13:45 +00:00
|
|
|
// on met a jour le titre du widget, qui reflete l'etat de lecture seule
|
|
|
|
updateWindowTitle();
|
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2017-02-18 13:30:38 +00:00
|
|
|
* @brief ProjectView::updateTabTitle
|
|
|
|
* Update the title of the tab which display the diagram view @diagram_view.
|
|
|
|
* @param diagram : The diagram view.
|
|
|
|
*/
|
|
|
|
void ProjectView::updateTabTitle(DiagramView *diagram_view)
|
|
|
|
{
|
2017-06-20 19:15:39 +00:00
|
|
|
int diagram_tab_id = m_diagram_ids.key(diagram_view, -1);
|
|
|
|
|
|
|
|
if (diagram_tab_id != -1)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
QString title;
|
|
|
|
Diagram *diagram = diagram_view->diagram();
|
|
|
|
|
|
|
|
if (settings.value("genericpanel/folio", false).toBool())
|
|
|
|
{
|
|
|
|
QString formula = diagram->border_and_titleblock.folio();
|
|
|
|
autonum::sequentialNumbers seq;
|
|
|
|
title = autonum::AssignVariables::formulaToLabel(formula, seq, diagram);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
title = QString::number(diagram->folioIndex() + 1);
|
|
|
|
|
|
|
|
title += " - ";
|
|
|
|
title += diagram->title();
|
|
|
|
m_tab->setTabText(diagram_tab_id ,title);
|
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
/**
|
|
|
|
* @brief ProjectView::updateAllTabsTitle
|
|
|
|
* Update all tabs title
|
|
|
|
*/
|
|
|
|
void ProjectView::updateAllTabsTitle()
|
|
|
|
{
|
|
|
|
for (DiagramView *dv : m_diagram_ids.values())
|
|
|
|
updateTabTitle(dv);
|
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
@param from Index de l'onglet avant le deplacement
|
|
|
|
@param to Index de l'onglet apres le deplacement
|
|
|
|
*/
|
2017-02-18 13:30:38 +00:00
|
|
|
void ProjectView::tabMoved(int from, int to)
|
|
|
|
{
|
|
|
|
if (!m_project)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_project->diagramOrderChanged(from, to);
|
2009-04-03 19:30:25 +00:00
|
|
|
rebuildDiagramsMap();
|
2017-02-18 13:30:38 +00:00
|
|
|
|
|
|
|
//Rebuild the title of each diagram in range from - to
|
|
|
|
for (int i= qMin(from,to) ; i< qMax(from,to)+1 ; ++i)
|
|
|
|
{
|
|
|
|
DiagramView *dv = m_diagram_ids.value(i);
|
|
|
|
updateTabTitle(dv);
|
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param diagram Schema a trouver
|
|
|
|
@return le DiagramView correspondant au schema passe en parametre, ou 0 si
|
|
|
|
le schema n'est pas trouve
|
|
|
|
*/
|
|
|
|
DiagramView *ProjectView::findDiagram(Diagram *diagram) {
|
2017-02-18 13:30:38 +00:00
|
|
|
foreach(DiagramView *diagram_view, diagram_views()) {
|
2009-04-03 19:30:25 +00:00
|
|
|
if (diagram_view -> diagram() == diagram) {
|
|
|
|
return(diagram_view);
|
|
|
|
}
|
|
|
|
}
|
2017-08-05 02:06:59 +00:00
|
|
|
return(nullptr);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reconstruit la map associant les index des onglets avec les DiagramView
|
|
|
|
*/
|
|
|
|
void ProjectView::rebuildDiagramsMap() {
|
|
|
|
// vide la map
|
2017-02-18 13:30:38 +00:00
|
|
|
m_diagram_ids.clear();
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(DiagramView *diagram_view, m_diagram_view_list) {
|
2015-03-05 13:11:38 +00:00
|
|
|
int dv_idx = m_tab -> indexOf(diagram_view);
|
2009-04-03 19:30:25 +00:00
|
|
|
if (dv_idx == -1) continue;
|
2017-02-18 13:30:38 +00:00
|
|
|
m_diagram_ids.insert(dv_idx, diagram_view);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-05 13:11:38 +00:00
|
|
|
* @brief ProjectView::tabChanged
|
|
|
|
* Manage the tab change.
|
|
|
|
* If tab_id == -1 (there is no diagram opened),
|
|
|
|
* we display the fallback widget.
|
|
|
|
* @param tab_id
|
|
|
|
*/
|
2017-07-26 08:55:32 +00:00
|
|
|
void ProjectView::tabChanged(int tab_id)
|
|
|
|
{
|
2015-03-05 13:11:38 +00:00
|
|
|
if (tab_id == -1)
|
|
|
|
setDisplayFallbackWidget(true);
|
|
|
|
else if(m_tab->count() == 1)
|
|
|
|
setDisplayFallbackWidget(false);
|
2017-07-26 08:55:32 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
emit(diagramActivated(m_diagram_ids[tab_id]));
|
2017-07-26 08:55:32 +00:00
|
|
|
|
2017-02-18 13:30:38 +00:00
|
|
|
if (m_diagram_ids[tab_id] != nullptr)
|
|
|
|
m_diagram_ids[tab_id]->diagram()->diagramActivated();
|
2017-07-26 08:55:32 +00:00
|
|
|
|
|
|
|
//Clear the event interface of the previous diagram
|
|
|
|
if (DiagramView *dv = m_diagram_ids[m_previous_tab_index])
|
|
|
|
dv->diagram()->clearEventInterface();
|
|
|
|
m_previous_tab_index = tab_id;
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gere le double-clic sur un onglet : edite les proprietes du schema
|
|
|
|
@param tab_id Index de l'onglet concerne
|
|
|
|
*/
|
|
|
|
void ProjectView::tabDoubleClicked(int tab_id) {
|
|
|
|
// repere le schema concerne
|
2017-02-18 13:30:38 +00:00
|
|
|
DiagramView *diagram_view = m_diagram_ids[tab_id];
|
2009-04-03 19:30:25 +00:00
|
|
|
if (!diagram_view) return;
|
2016-05-13 15:00:22 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
diagram_view -> editDiagramProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param fallback true pour afficher le widget de fallback, false pour
|
|
|
|
afficher les onglets.
|
|
|
|
Le widget de Fallback est le widget affiche lorsque le projet ne comporte
|
|
|
|
aucun schema.
|
|
|
|
*/
|
|
|
|
void ProjectView::setDisplayFallbackWidget(bool fallback) {
|
|
|
|
fallback_widget_ -> setVisible(fallback);
|
2015-03-05 13:11:38 +00:00
|
|
|
m_tab -> setVisible(!fallback);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|