mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Change the way how a diagram is added
Now it's the project itself who manage the adding of diagram instead of the diagram view, it's more coherent
This commit is contained in:
@@ -68,17 +68,25 @@ QETProject *ProjectView::project() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Definit le projet visualise par le ProjectView. Ne fait rien si le projet a
|
* @brief ProjectView::setProject
|
||||||
deja ete defini.
|
* Set the project display by the project view
|
||||||
@param project projet a visualiser
|
* @param project
|
||||||
*/
|
*/
|
||||||
void ProjectView::setProject(QETProject *project) {
|
void ProjectView::setProject(QETProject *project)
|
||||||
if (!m_project) {
|
{
|
||||||
|
if (!m_project)
|
||||||
|
{
|
||||||
m_project = project;
|
m_project = project;
|
||||||
connect(m_project, SIGNAL(projectTitleChanged(QETProject *, const QString &)), this, SLOT(updateWindowTitle()));
|
connect(m_project, &QETProject::projectTitleChanged, this, &ProjectView::updateWindowTitle);
|
||||||
connect(m_project, SIGNAL(projectModified (QETProject *, bool)), this, SLOT(updateWindowTitle()));
|
connect(m_project, &QETProject::projectModified, this, &ProjectView::updateWindowTitle);
|
||||||
connect(m_project, SIGNAL(readOnlyChanged (QETProject *, bool)), this, SLOT(adjustReadOnlyState()));
|
connect(m_project, &QETProject::readOnlyChanged, this, &ProjectView::adjustReadOnlyState);
|
||||||
connect(m_project, SIGNAL(addAutoNumDiagram()), this, SLOT(addNewDiagram()));
|
connect(m_project, &QETProject::addAutoNumDiagram, [this](){this->project()->addNewDiagram();});
|
||||||
|
|
||||||
|
connect(m_project, &QETProject::diagramAdded, [this](QETProject *project, Diagram *diagram) {
|
||||||
|
Q_UNUSED(project)
|
||||||
|
this->diagramAdded(diagram);
|
||||||
|
});
|
||||||
|
|
||||||
adjustReadOnlyState();
|
adjustReadOnlyState();
|
||||||
loadDiagrams();
|
loadDiagrams();
|
||||||
}
|
}
|
||||||
@@ -337,22 +345,6 @@ QETResult ProjectView::noProjectResult() const {
|
|||||||
return(no_project);
|
return(no_project);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ProjectView::addNewDiagram
|
|
||||||
* Add new diagram to project view
|
|
||||||
*/
|
|
||||||
void ProjectView::addNewDiagram() {
|
|
||||||
if (m_project -> isReadOnly()) return;
|
|
||||||
|
|
||||||
Diagram *new_diagram = m_project -> addNewDiagram();
|
|
||||||
DiagramView *new_diagram_view = new DiagramView(new_diagram);
|
|
||||||
addDiagram(new_diagram_view);
|
|
||||||
|
|
||||||
if (m_project -> diagrams().size() % 58 == 1 && m_project -> getFolioSheetsQuantity() != 0)
|
|
||||||
addNewDiagramFolioList();
|
|
||||||
showDiagram(new_diagram_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ProjectView::addNewDiagramFolioList
|
* @brief ProjectView::addNewDiagramFolioList
|
||||||
* Add new diagram folio list to project
|
* Add new diagram folio list to project
|
||||||
@@ -362,50 +354,12 @@ void ProjectView::addNewDiagramFolioList() {
|
|||||||
QSettings settings;
|
QSettings settings;
|
||||||
int i = (settings.value("projectview/foliolist_position").toInt() -1); //< Each new diagram is added to the end of the project.
|
int i = (settings.value("projectview/foliolist_position").toInt() -1); //< Each new diagram is added to the end of the project.
|
||||||
//< We use @i to move the folio list at second position in the project
|
//< We use @i to move the folio list at second position in the project
|
||||||
foreach (Diagram *d, m_project -> addNewDiagramFolioList()) {
|
auto count = m_project->addNewDiagramFolioList().size();
|
||||||
DiagramView *new_diagram_view = new DiagramView(d);
|
for (auto j=0 ; j<count ; ++j) {
|
||||||
addDiagram(new_diagram_view);
|
|
||||||
showDiagram(new_diagram_view);
|
|
||||||
m_tab->tabBar()->moveTab(diagram_views().size()-1, i);
|
m_tab->tabBar()->moveTab(diagram_views().size()-1, i);
|
||||||
i++;
|
|
||||||
m_project->setModified(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ProjectView::addDiagram
|
|
||||||
* Add diagram view to this project view
|
|
||||||
* @param diagram_view
|
|
||||||
*/
|
|
||||||
void ProjectView::addDiagram(DiagramView *diagram_view)
|
|
||||||
{
|
|
||||||
if (!diagram_view)
|
|
||||||
return;
|
|
||||||
|
|
||||||
//Check if diagram isn't present in the project
|
|
||||||
if (m_diagram_ids.values().contains(diagram_view))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Add new tab for the diagram
|
|
||||||
m_tab->addTab(diagram_view, QET::Icons::Diagram, diagram_view -> title());
|
|
||||||
diagram_view->setFrameStyle(QFrame::Plain | QFrame::NoFrame);
|
|
||||||
|
|
||||||
m_diagram_view_list << diagram_view;
|
|
||||||
|
|
||||||
rebuildDiagramsMap();
|
|
||||||
updateAllTabsTitle();
|
|
||||||
|
|
||||||
connect(diagram_view, SIGNAL(showDiagram(Diagram*)), this, SLOT(showDiagram(Diagram*)));
|
|
||||||
connect(diagram_view, SIGNAL(titleChanged(DiagramView *, const QString &)), this, SLOT(updateTabTitle(DiagramView *)));
|
|
||||||
connect(diagram_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SIGNAL(findElementRequired(const ElementsLocation &)));
|
|
||||||
connect(diagram_view, SIGNAL(editElementRequired(const ElementsLocation &)), this, SIGNAL(editElementRequired(const ElementsLocation &)));
|
|
||||||
connect(&diagram_view->diagram()->border_and_titleblock , &BorderTitleBlock::titleBlockFolioChanged, [this, diagram_view]() {this->updateTabTitle(diagram_view);});
|
|
||||||
|
|
||||||
// signal diagram view was added
|
|
||||||
emit(diagramAdded(diagram_view));
|
|
||||||
m_project -> setModified(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ProjectView::removeDiagram
|
* @brief ProjectView::removeDiagram
|
||||||
* Remove a diagram (folio) of the project
|
* Remove a diagram (folio) of the project
|
||||||
@@ -780,9 +734,10 @@ int ProjectView::cleanProject() {
|
|||||||
/**
|
/**
|
||||||
Initialize actions for this widget.
|
Initialize actions for this widget.
|
||||||
*/
|
*/
|
||||||
void ProjectView::initActions() {
|
void ProjectView::initActions()
|
||||||
add_new_diagram_ = new QAction(QET::Icons::AddFolio, tr("Ajouter un folio"), this);
|
{
|
||||||
connect(add_new_diagram_, SIGNAL(triggered()), this, SLOT(addNewDiagram()));
|
m_add_new_diagram = new QAction(QET::Icons::AddFolio, tr("Ajouter un folio"), this);
|
||||||
|
connect(m_add_new_diagram, &QAction::triggered, [this](){this->m_project->addNewDiagram();});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -811,7 +766,7 @@ void ProjectView::initWidgets() {
|
|||||||
m_tab -> setMovable(true);
|
m_tab -> setMovable(true);
|
||||||
|
|
||||||
QToolButton *add_new_diagram_button = new QToolButton;
|
QToolButton *add_new_diagram_button = new QToolButton;
|
||||||
add_new_diagram_button -> setDefaultAction(add_new_diagram_);
|
add_new_diagram_button -> setDefaultAction(m_add_new_diagram);
|
||||||
add_new_diagram_button -> setAutoRaise(true);
|
add_new_diagram_button -> setAutoRaise(true);
|
||||||
m_tab -> setCornerWidget(add_new_diagram_button, Qt::TopRightCorner);
|
m_tab -> setCornerWidget(add_new_diagram_button, Qt::TopRightCorner);
|
||||||
|
|
||||||
@@ -870,9 +825,7 @@ void ProjectView::loadDiagrams()
|
|||||||
dialog->setDetail(diagram->title());
|
dialog->setDetail(diagram->title());
|
||||||
dialog->setProgressBar(dialog->progressBarValue()+1);
|
dialog->setProgressBar(dialog->progressBarValue()+1);
|
||||||
}
|
}
|
||||||
|
diagramAdded(diagram);
|
||||||
DiagramView *sv = new DiagramView(diagram);
|
|
||||||
addDiagram(sv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DiagramView *dv = currentDiagram())
|
if (DiagramView *dv = currentDiagram())
|
||||||
@@ -914,12 +867,45 @@ void ProjectView::adjustReadOnlyState() {
|
|||||||
// prevent users from moving existing diagrams
|
// prevent users from moving existing diagrams
|
||||||
m_tab -> setMovable(editable);
|
m_tab -> setMovable(editable);
|
||||||
// prevent users from adding new diagrams
|
// prevent users from adding new diagrams
|
||||||
add_new_diagram_ -> setEnabled(editable);
|
m_add_new_diagram -> setEnabled(editable);
|
||||||
|
|
||||||
// on met a jour le titre du widget, qui reflete l'etat de lecture seule
|
// on met a jour le titre du widget, qui reflete l'etat de lecture seule
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ProjectView::diagramAdded
|
||||||
|
* Slot called when qetproject emit diagramAdded
|
||||||
|
* @param diagram
|
||||||
|
*/
|
||||||
|
void ProjectView::diagramAdded(Diagram *diagram)
|
||||||
|
{
|
||||||
|
auto dv = new DiagramView(diagram);
|
||||||
|
auto index = m_project->folioIndex(diagram);
|
||||||
|
m_tab->insertTab(index, dv, QET::Icons::Diagram, dv->title());
|
||||||
|
dv->setFrameStyle(QFrame::Plain | QFrame::NoFrame);
|
||||||
|
|
||||||
|
m_diagram_view_list.insert(index, dv);
|
||||||
|
|
||||||
|
rebuildDiagramsMap();
|
||||||
|
updateAllTabsTitle();
|
||||||
|
|
||||||
|
connect(dv, &DiagramView::showDiagram, this, QOverload<Diagram*>::of(&ProjectView::showDiagram));
|
||||||
|
connect(dv, &DiagramView::titleChanged, this, &ProjectView::updateTabTitle);
|
||||||
|
connect(dv, &DiagramView::findElementRequired, this, &ProjectView::findElementRequired);
|
||||||
|
connect(dv, &DiagramView::editElementRequired, this, &ProjectView::editElementRequired);
|
||||||
|
connect(&dv->diagram()->border_and_titleblock , &BorderTitleBlock::titleBlockFolioChanged, [this, dv]() {this->updateTabTitle(dv);});
|
||||||
|
|
||||||
|
// signal diagram view was added
|
||||||
|
emit(diagramAdded(dv));
|
||||||
|
m_project->setModified(true);
|
||||||
|
|
||||||
|
if (m_project->diagrams().size() % 58 == 1 && m_project->getFolioSheetsQuantity() != 0) {
|
||||||
|
addNewDiagramFolioList();
|
||||||
|
}
|
||||||
|
showDiagram(dv);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ProjectView::updateTabTitle
|
* @brief ProjectView::updateTabTitle
|
||||||
* Update the title of the tab which display the diagram view @diagram_view.
|
* Update the title of the tab which display the diagram view @diagram_view.
|
||||||
|
|||||||
@@ -98,9 +98,7 @@ class ProjectView : public QWidget
|
|||||||
void changeLastTab();
|
void changeLastTab();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addNewDiagram();
|
|
||||||
void addNewDiagramFolioList();
|
void addNewDiagramFolioList();
|
||||||
void addDiagram(DiagramView *);
|
|
||||||
void removeDiagram(DiagramView *);
|
void removeDiagram(DiagramView *);
|
||||||
void removeDiagram(Diagram *);
|
void removeDiagram(Diagram *);
|
||||||
void showDiagram(DiagramView *);
|
void showDiagram(DiagramView *);
|
||||||
@@ -162,10 +160,11 @@ class ProjectView : public QWidget
|
|||||||
void tabDoubleClicked(int);
|
void tabDoubleClicked(int);
|
||||||
void setDisplayFallbackWidget(bool);
|
void setDisplayFallbackWidget(bool);
|
||||||
void adjustReadOnlyState();
|
void adjustReadOnlyState();
|
||||||
|
void diagramAdded(Diagram *diagram);
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
QAction *add_new_diagram_;
|
QAction *m_add_new_diagram;
|
||||||
QETProject *m_project;
|
QETProject *m_project;
|
||||||
QVBoxLayout *layout_;
|
QVBoxLayout *layout_;
|
||||||
QWidget *fallback_widget_;
|
QWidget *fallback_widget_;
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ void QETDiagramEditor::setUpActions()
|
|||||||
m_project_add_diagram->setShortcut(QKeySequence(tr("Ctrl+T")));
|
m_project_add_diagram->setShortcut(QKeySequence(tr("Ctrl+T")));
|
||||||
connect(m_project_add_diagram, &QAction::triggered, [this]() {
|
connect(m_project_add_diagram, &QAction::triggered, [this]() {
|
||||||
if (ProjectView *current_project = currentProjectView()) {
|
if (ProjectView *current_project = currentProjectView()) {
|
||||||
current_project->addNewDiagram();
|
current_project->project()->addNewDiagram();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1972,20 +1972,20 @@ void QETDiagramEditor::editProjectProperties(QETProject *project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ajoute un nouveau schema a un projet
|
* @brief QETDiagramEditor::addDiagramToProject
|
||||||
@param project Projet auquel il faut ajouter un schema
|
* Add a diagram to project
|
||||||
*/
|
* @param project
|
||||||
void QETDiagramEditor::addDiagramToProject(QETProject *project) {
|
*/
|
||||||
if (!project) return;
|
void QETDiagramEditor::addDiagramToProject(QETProject *project)
|
||||||
|
{
|
||||||
|
if (!project) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// recupere le ProjectView visualisant ce projet
|
if (ProjectView *project_view = findProject(project))
|
||||||
if (ProjectView *project_view = findProject(project)) {
|
{
|
||||||
|
|
||||||
// affiche le projet en question
|
|
||||||
activateProject(project);
|
activateProject(project);
|
||||||
|
project_view->project()->addNewDiagram();
|
||||||
// ajoute un schema au projet
|
|
||||||
project_view -> addNewDiagram();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1145,21 +1145,24 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ajoute un nouveau schema au projet et emet le signal diagramAdded
|
* @brief QETProject::addNewDiagram
|
||||||
*/
|
* Add a new diagram in project at position pos.
|
||||||
Diagram *QETProject::addNewDiagram() {
|
* @param pos
|
||||||
// ne fait rien si le projet est en lecture seule
|
* @return the new created diagram
|
||||||
if (isReadOnly()) return(nullptr);
|
*/
|
||||||
|
Diagram *QETProject::addNewDiagram(int pos)
|
||||||
|
{
|
||||||
|
if (isReadOnly()) {
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// cree un nouveau schema
|
|
||||||
Diagram *diagram = new Diagram(this);
|
Diagram *diagram = new Diagram(this);
|
||||||
|
|
||||||
// lui transmet les parametres par defaut
|
diagram->border_and_titleblock.importBorder(defaultBorderProperties());
|
||||||
diagram -> border_and_titleblock.importBorder(defaultBorderProperties());
|
diagram->border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
|
||||||
diagram -> border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
|
diagram->defaultConductorProperties = defaultConductorProperties();
|
||||||
diagram -> defaultConductorProperties = defaultConductorProperties();
|
|
||||||
|
|
||||||
addDiagram(diagram);
|
addDiagram(diagram, pos);
|
||||||
emit(diagramAdded(this, diagram));
|
emit(diagramAdded(this, diagram));
|
||||||
return(diagram);
|
return(diagram);
|
||||||
}
|
}
|
||||||
@@ -1169,7 +1172,8 @@ Diagram *QETProject::addNewDiagram() {
|
|||||||
* Add new diagram folio list
|
* Add new diagram folio list
|
||||||
* @return the created diagram
|
* @return the created diagram
|
||||||
*/
|
*/
|
||||||
QList <Diagram *> QETProject::addNewDiagramFolioList() {
|
QList <Diagram *> QETProject::addNewDiagramFolioList()
|
||||||
|
{
|
||||||
// do nothing if project is read only or folio sheet is alredy created
|
// do nothing if project is read only or folio sheet is alredy created
|
||||||
QList <Diagram *> diagram_list;
|
QList <Diagram *> diagram_list;
|
||||||
|
|
||||||
@@ -1624,35 +1628,29 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) {
|
|||||||
xml_element.appendChild(element_autonums);
|
xml_element.appendChild(element_autonums);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Cette methode ajoute un schema donne au projet
|
|
||||||
@param diagram Schema a ajouter
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* @brief QETProject::addDiagram
|
* @brief QETProject::addDiagram
|
||||||
* Add a diagram in this project
|
* Add a diagram in this project
|
||||||
* @param diagram added diagram
|
* @param diagram added diagram
|
||||||
* @param position postion of the new diagram, by default at the end
|
* @param pos postion of the new diagram, by default at the end
|
||||||
*/
|
*/
|
||||||
void QETProject::addDiagram(Diagram *diagram) {
|
void QETProject::addDiagram(Diagram *diagram, int pos)
|
||||||
if (!diagram) return;
|
{
|
||||||
|
if (!diagram) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure diagram know is parent project
|
// Ensure diagram know is parent project
|
||||||
diagram -> setProject(this);
|
diagram->setProject(this);
|
||||||
|
|
||||||
connect(
|
connect(&diagram->border_and_titleblock, &BorderTitleBlock::needFolioData, this, &QETProject::updateDiagramsFolioData);
|
||||||
&(diagram -> border_and_titleblock),
|
connect(diagram, &Diagram::usedTitleBlockTemplateChanged, this, &QETProject::usedTitleBlockTemplateChanged);
|
||||||
SIGNAL(needFolioData()),
|
|
||||||
this,
|
|
||||||
SLOT(updateDiagramsFolioData())
|
|
||||||
);
|
|
||||||
connect(
|
|
||||||
diagram, SIGNAL(usedTitleBlockTemplateChanged(const QString &)),
|
|
||||||
this, SLOT(usedTitleBlockTemplateChanged(const QString &))
|
|
||||||
);
|
|
||||||
|
|
||||||
// add diagram to project
|
if (pos == -1) {
|
||||||
m_diagrams_list << diagram;
|
m_diagrams_list << diagram;
|
||||||
|
} else {
|
||||||
|
m_diagrams_list.insert(pos, diagram);
|
||||||
|
}
|
||||||
|
|
||||||
updateDiagramsFolioData();
|
updateDiagramsFolioData();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ class QETProject : public QObject
|
|||||||
QUndoStack* undoStack() {return m_undo_stack;}
|
QUndoStack* undoStack() {return m_undo_stack;}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
Diagram *addNewDiagram();
|
Diagram *addNewDiagram(int pos = -1);
|
||||||
QList <Diagram *> addNewDiagramFolioList();
|
QList <Diagram *> addNewDiagramFolioList();
|
||||||
void removeDiagram(Diagram *);
|
void removeDiagram(Diagram *);
|
||||||
void diagramOrderChanged(int, int);
|
void diagramOrderChanged(int, int);
|
||||||
@@ -213,7 +213,7 @@ class QETProject : public QObject
|
|||||||
|
|
||||||
void writeProjectPropertiesXml(QDomElement &);
|
void writeProjectPropertiesXml(QDomElement &);
|
||||||
void writeDefaultPropertiesXml(QDomElement &);
|
void writeDefaultPropertiesXml(QDomElement &);
|
||||||
void addDiagram(Diagram *);
|
void addDiagram(Diagram *diagram, int pos = -1);
|
||||||
NamesList namesListForIntegrationCategory();
|
NamesList namesListForIntegrationCategory();
|
||||||
void writeBackup();
|
void writeBackup();
|
||||||
void init();
|
void init();
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ DiagramContext ElementInfoWidget::currentInfo() const
|
|||||||
|
|
||||||
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
||||||
{
|
{
|
||||||
|
|
||||||
//add value only if they're something to store
|
//add value only if they're something to store
|
||||||
if (!eipw->text().isEmpty())
|
if (!eipw->text().isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user