mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50: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
|
||||
deja ete defini.
|
||||
@param project projet a visualiser
|
||||
*/
|
||||
void ProjectView::setProject(QETProject *project) {
|
||||
if (!m_project) {
|
||||
* @brief ProjectView::setProject
|
||||
* Set the project display by the project view
|
||||
* @param project
|
||||
*/
|
||||
void ProjectView::setProject(QETProject *project)
|
||||
{
|
||||
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()));
|
||||
connect(m_project, &QETProject::projectTitleChanged, this, &ProjectView::updateWindowTitle);
|
||||
connect(m_project, &QETProject::projectModified, this, &ProjectView::updateWindowTitle);
|
||||
connect(m_project, &QETProject::readOnlyChanged, this, &ProjectView::adjustReadOnlyState);
|
||||
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();
|
||||
loadDiagrams();
|
||||
}
|
||||
@@ -337,22 +345,6 @@ QETResult ProjectView::noProjectResult() const {
|
||||
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
|
||||
* Add new diagram folio list to project
|
||||
@@ -362,50 +354,12 @@ void ProjectView::addNewDiagramFolioList() {
|
||||
QSettings settings;
|
||||
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
|
||||
foreach (Diagram *d, m_project -> addNewDiagramFolioList()) {
|
||||
DiagramView *new_diagram_view = new DiagramView(d);
|
||||
addDiagram(new_diagram_view);
|
||||
showDiagram(new_diagram_view);
|
||||
auto count = m_project->addNewDiagramFolioList().size();
|
||||
for (auto j=0 ; j<count ; ++j) {
|
||||
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
|
||||
* Remove a diagram (folio) of the project
|
||||
@@ -780,9 +734,10 @@ int ProjectView::cleanProject() {
|
||||
/**
|
||||
Initialize actions for this widget.
|
||||
*/
|
||||
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()));
|
||||
void ProjectView::initActions()
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
m_tab -> setCornerWidget(add_new_diagram_button, Qt::TopRightCorner);
|
||||
|
||||
@@ -870,9 +825,7 @@ void ProjectView::loadDiagrams()
|
||||
dialog->setDetail(diagram->title());
|
||||
dialog->setProgressBar(dialog->progressBarValue()+1);
|
||||
}
|
||||
|
||||
DiagramView *sv = new DiagramView(diagram);
|
||||
addDiagram(sv);
|
||||
diagramAdded(diagram);
|
||||
}
|
||||
|
||||
if (DiagramView *dv = currentDiagram())
|
||||
@@ -914,12 +867,45 @@ void ProjectView::adjustReadOnlyState() {
|
||||
// prevent users from moving existing diagrams
|
||||
m_tab -> setMovable(editable);
|
||||
// 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
|
||||
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
|
||||
* Update the title of the tab which display the diagram view @diagram_view.
|
||||
|
||||
@@ -98,9 +98,7 @@ class ProjectView : public QWidget
|
||||
void changeLastTab();
|
||||
|
||||
public slots:
|
||||
void addNewDiagram();
|
||||
void addNewDiagramFolioList();
|
||||
void addDiagram(DiagramView *);
|
||||
void removeDiagram(DiagramView *);
|
||||
void removeDiagram(Diagram *);
|
||||
void showDiagram(DiagramView *);
|
||||
@@ -162,10 +160,11 @@ class ProjectView : public QWidget
|
||||
void tabDoubleClicked(int);
|
||||
void setDisplayFallbackWidget(bool);
|
||||
void adjustReadOnlyState();
|
||||
void diagramAdded(Diagram *diagram);
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QAction *add_new_diagram_;
|
||||
QAction *m_add_new_diagram;
|
||||
QETProject *m_project;
|
||||
QVBoxLayout *layout_;
|
||||
QWidget *fallback_widget_;
|
||||
|
||||
@@ -363,7 +363,7 @@ void QETDiagramEditor::setUpActions()
|
||||
m_project_add_diagram->setShortcut(QKeySequence(tr("Ctrl+T")));
|
||||
connect(m_project_add_diagram, &QAction::triggered, [this]() {
|
||||
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
|
||||
@param project Projet auquel il faut ajouter un schema
|
||||
*/
|
||||
void QETDiagramEditor::addDiagramToProject(QETProject *project) {
|
||||
if (!project) return;
|
||||
* @brief QETDiagramEditor::addDiagramToProject
|
||||
* Add a diagram to project
|
||||
* @param project
|
||||
*/
|
||||
void QETDiagramEditor::addDiagramToProject(QETProject *project)
|
||||
{
|
||||
if (!project) {
|
||||
return;
|
||||
}
|
||||
|
||||
// recupere le ProjectView visualisant ce projet
|
||||
if (ProjectView *project_view = findProject(project)) {
|
||||
|
||||
// affiche le projet en question
|
||||
if (ProjectView *project_view = findProject(project))
|
||||
{
|
||||
activateProject(project);
|
||||
|
||||
// ajoute un schema au projet
|
||||
project_view -> addNewDiagram();
|
||||
project_view->project()->addNewDiagram();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1145,21 +1145,24 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute un nouveau schema au projet et emet le signal diagramAdded
|
||||
*/
|
||||
Diagram *QETProject::addNewDiagram() {
|
||||
// ne fait rien si le projet est en lecture seule
|
||||
if (isReadOnly()) return(nullptr);
|
||||
* @brief QETProject::addNewDiagram
|
||||
* Add a new diagram in project at position pos.
|
||||
* @param pos
|
||||
* @return the new created diagram
|
||||
*/
|
||||
Diagram *QETProject::addNewDiagram(int pos)
|
||||
{
|
||||
if (isReadOnly()) {
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
// cree un nouveau schema
|
||||
Diagram *diagram = new Diagram(this);
|
||||
|
||||
// lui transmet les parametres par defaut
|
||||
diagram -> border_and_titleblock.importBorder(defaultBorderProperties());
|
||||
diagram -> border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
|
||||
diagram -> defaultConductorProperties = defaultConductorProperties();
|
||||
|
||||
addDiagram(diagram);
|
||||
diagram->border_and_titleblock.importBorder(defaultBorderProperties());
|
||||
diagram->border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
|
||||
diagram->defaultConductorProperties = defaultConductorProperties();
|
||||
|
||||
addDiagram(diagram, pos);
|
||||
emit(diagramAdded(this, diagram));
|
||||
return(diagram);
|
||||
}
|
||||
@@ -1169,7 +1172,8 @@ Diagram *QETProject::addNewDiagram() {
|
||||
* Add new diagram folio list
|
||||
* @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
|
||||
QList <Diagram *> diagram_list;
|
||||
|
||||
@@ -1624,35 +1628,29 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) {
|
||||
xml_element.appendChild(element_autonums);
|
||||
}
|
||||
|
||||
/**
|
||||
Cette methode ajoute un schema donne au projet
|
||||
@param diagram Schema a ajouter
|
||||
*/
|
||||
/**
|
||||
* @brief QETProject::addDiagram
|
||||
* Add a diagram in this project
|
||||
* @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) {
|
||||
if (!diagram) return;
|
||||
void QETProject::addDiagram(Diagram *diagram, int pos)
|
||||
{
|
||||
if (!diagram) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure diagram know is parent project
|
||||
diagram -> setProject(this);
|
||||
|
||||
connect(
|
||||
&(diagram -> border_and_titleblock),
|
||||
SIGNAL(needFolioData()),
|
||||
this,
|
||||
SLOT(updateDiagramsFolioData())
|
||||
);
|
||||
connect(
|
||||
diagram, SIGNAL(usedTitleBlockTemplateChanged(const QString &)),
|
||||
this, SLOT(usedTitleBlockTemplateChanged(const QString &))
|
||||
);
|
||||
|
||||
// add diagram to project
|
||||
// Ensure diagram know is parent project
|
||||
diagram->setProject(this);
|
||||
|
||||
connect(&diagram->border_and_titleblock, &BorderTitleBlock::needFolioData, this, &QETProject::updateDiagramsFolioData);
|
||||
connect(diagram, &Diagram::usedTitleBlockTemplateChanged, this, &QETProject::usedTitleBlockTemplateChanged);
|
||||
|
||||
if (pos == -1) {
|
||||
m_diagrams_list << diagram;
|
||||
} else {
|
||||
m_diagrams_list.insert(pos, diagram);
|
||||
}
|
||||
|
||||
updateDiagramsFolioData();
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class QETProject : public QObject
|
||||
QUndoStack* undoStack() {return m_undo_stack;}
|
||||
|
||||
public slots:
|
||||
Diagram *addNewDiagram();
|
||||
Diagram *addNewDiagram(int pos = -1);
|
||||
QList <Diagram *> addNewDiagramFolioList();
|
||||
void removeDiagram(Diagram *);
|
||||
void diagramOrderChanged(int, int);
|
||||
@@ -213,7 +213,7 @@ class QETProject : public QObject
|
||||
|
||||
void writeProjectPropertiesXml(QDomElement &);
|
||||
void writeDefaultPropertiesXml(QDomElement &);
|
||||
void addDiagram(Diagram *);
|
||||
void addDiagram(Diagram *diagram, int pos = -1);
|
||||
NamesList namesListForIntegrationCategory();
|
||||
void writeBackup();
|
||||
void init();
|
||||
|
||||
@@ -233,6 +233,7 @@ DiagramContext ElementInfoWidget::currentInfo() const
|
||||
|
||||
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
||||
{
|
||||
|
||||
//add value only if they're something to store
|
||||
if (!eipw->text().isEmpty())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user