diff --git a/sources/diagram.cpp b/sources/diagram.cpp index ba9f5d6f1..bdd2a043e 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -41,20 +41,23 @@ const qreal Diagram::margin = 5.0; // static variable to keep track of present background color of the diagram. QColor Diagram::background_color = Qt::white; + /** - Constructeur - @param parent Le QObject parent du schema -*/ -Diagram::Diagram(QObject *parent) : - QGraphicsScene(parent), - project_(0), - diagram_qet_version_(-1), - draw_grid_(true), - use_border_(true), - draw_terminals_(true), - draw_colored_conductors_(true), - read_only_(false) + * @brief Diagram::Diagram + * Constructor + * @param project : The project of this diagram and also parent QObject + */ +Diagram::Diagram(QETProject *project) : + QGraphicsScene (project), + project_ (nullptr), + diagram_qet_version_ (-1), + draw_grid_ (true), + use_border_ (true), + draw_terminals_ (true), + draw_colored_conductors_ (true), + read_only_ (false) { + setProject(project); qgi_manager_ = new QGIManager(this); setBackgroundBrush(Qt::white); conductor_setter_ = new QGraphicsLineItem(0, 0); @@ -66,18 +69,12 @@ Diagram::Diagram(QObject *parent) : conductor_setter_ -> setPen(t); conductor_setter_ -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0))); - // initialise les objets gerant les deplacements - elements_mover_ = new ElementsMover(); // deplacements d'elements/conducteurs/textes - element_texts_mover_ = new ElementTextsMover(); // deplacements d'ElementTextItem + //Init object for manage movement + elements_mover_ = new ElementsMover(); + element_texts_mover_ = new ElementTextsMover(); - connect( - &border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)), - this, SLOT(setTitleBlockTemplate(const QString &)) - ); - connect( - &border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)), - this, SLOT(titleChanged(const QString &)) - ); + connect(&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)), this, SLOT(setTitleBlockTemplate(const QString &))); + connect(&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(titleChanged(const QString &))); } /** @@ -1203,18 +1200,24 @@ QETProject *Diagram::project() const { /** * @brief Diagram::setProject - * @param project: set parent project of this diagram or 0 if this diagram haven't got a parent project + * Set parent project of this diagram, project also become the parent QObject of this diagram + * @param project new project */ -void Diagram::setProject(QETProject *project) { - if (project_) { - disconnect (project_, SIGNAL(reportPropertiesChanged(QString)), this, SIGNAL(reportPropertiesChanged(QString))); - disconnect (project_, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged())); +void Diagram::setProject(QETProject *project) +{ + if (project_ == project) return; + + if (project_) + { + disconnect (project_, SIGNAL(reportPropertiesChanged(QString)), this, SIGNAL(reportPropertiesChanged(QString))); + disconnect (project_, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged())); } + project_ = project; - if (project_) { - connect (project_, SIGNAL(reportPropertiesChanged(QString)), this, SIGNAL(reportPropertiesChanged(QString))); - connect (project_, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged())); - } + setParent (project); + + connect (project_, SIGNAL(reportPropertiesChanged(QString)), this, SIGNAL(reportPropertiesChanged(QString))); + connect (project_, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged())); } /** diff --git a/sources/diagram.h b/sources/diagram.h index 1cb25f02b..b9b08aadd 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -47,16 +47,16 @@ class ElementTextsMover; This class represents an electric diagram. It manages its various child elements, conductors and texts and handles their graphic rendering. */ -class Diagram : public QGraphicsScene { +class Diagram : public QGraphicsScene +{ Q_OBJECT - // constructors, destructor + // constructors, destructor public: - Diagram(QObject * = 0); - virtual ~Diagram(); - + Diagram(QETProject *project); + virtual ~Diagram(); private: - Diagram(const Diagram &diagram); + Diagram(const Diagram &diagram); // ATTRIBUTES public: diff --git a/sources/diagramfoliolist.cpp b/sources/diagramfoliolist.cpp index 551f46195..728e76add 100644 --- a/sources/diagramfoliolist.cpp +++ b/sources/diagramfoliolist.cpp @@ -24,16 +24,12 @@ qreal DiagramFolioList::colWidths[4] = {0.1, 0.55, 0.2, 0.15}; /** * @brief DiagramFolioList::DiagramFolioList * Constructor - * @param project QETproject *: The project from which this constructor was called. Important to setProject(). - * @param parent parent QObject + * @param project : The project of this diagram and also parent QObject */ -DiagramFolioList::DiagramFolioList( QETProject *project, QObject *parent) : Diagram(parent) { - if (project) { - setProject(project); - id = project -> getFolioSheetsQuantity(); - } - else - id = 0; +DiagramFolioList::DiagramFolioList( QETProject *project) : + Diagram(project) +{ + id = project -> getFolioSheetsQuantity(); } /** diff --git a/sources/diagramfoliolist.h b/sources/diagramfoliolist.h index d1db855e8..efd09e1b9 100644 --- a/sources/diagramfoliolist.h +++ b/sources/diagramfoliolist.h @@ -24,7 +24,7 @@ class DiagramFolioList : public Diagram { public: - DiagramFolioList( QETProject *project = 0, QObject *parent = 0); + DiagramFolioList(QETProject *project); virtual ~DiagramFolioList(); virtual QList lines() const {return list_lines_;} virtual QList rectangles() const {return list_rectangles_;} diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 00f7b2e1f..f29f518fc 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -902,7 +902,7 @@ Diagram *QETProject::addNewDiagram() { if (isReadOnly()) return(0); // cree un nouveau schema - Diagram *diagram = new Diagram(); + Diagram *diagram = new Diagram(this); // lui transmet les parametres par defaut diagram -> border_and_titleblock.importBorder(defaultBorderProperties()); @@ -1120,8 +1120,7 @@ void QETProject::readDiagramsXml() { dlgWaiting->setProgressBar(i+1); if (diagram_nodes.at(i).isElement()) { QDomElement diagram_xml_element = diagram_nodes.at(i).toElement(); - Diagram *diagram = new Diagram(); - diagram -> setProject(this); + Diagram *diagram = new Diagram(this); bool diagram_loading = diagram -> initFromXml(diagram_xml_element); if (diagram_loading) { dlgWaiting->setDetail( diagram->title() );