426 lines
12 KiB
C
Raw Normal View History

/*
2020-06-15 17:42:37 +02:00
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
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.
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.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DIAGRAM_H
#define DIAGRAM_H
Merge Qt5 branch sources folder to trunk -Cette ligne, et les suivantes ci-dessous, seront ignorées-- M sources/aboutqet.cpp M sources/bordertitleblock.cpp M sources/conductorproperties.h M sources/configdialog.cpp M sources/configpages.cpp M sources/configpages.h M sources/createdxf.h M sources/diagram.cpp M sources/diagram.h M sources/diagramcommands.cpp M sources/diagramcommands.h M sources/diagramprintdialog.cpp M sources/diagramprintdialog.h M sources/diagramschooser.cpp M sources/diagramschooser.h M sources/diagramview.cpp M sources/diagramview.h M sources/dvevent/dveventaddimage.cpp M sources/dvevent/dveventaddshape.cpp M sources/editor/arceditor.cpp M sources/editor/arceditor.h M sources/editor/editorcommands.cpp M sources/editor/editorcommands.h M sources/editor/elementitemeditor.h M sources/editor/elementprimitivedecorator.cpp M sources/editor/elementscene.cpp M sources/editor/elementscene.h M sources/editor/elementview.cpp M sources/editor/ellipseeditor.cpp M sources/editor/ellipseeditor.h M sources/editor/esevent/eseventaddtext.cpp M sources/editor/esevent/eseventaddtextfield.cpp M sources/editor/esevent/eseventinterface.cpp M sources/editor/graphicspart/customelementpart.h M sources/editor/graphicspart/parttext.cpp M sources/editor/graphicspart/parttext.h M sources/editor/graphicspart/parttextfield.cpp M sources/editor/graphicspart/parttextfield.h M sources/editor/lineeditor.cpp M sources/editor/lineeditor.h M sources/editor/polygoneditor.cpp M sources/editor/qetelementeditor.cpp M sources/editor/qetelementeditor.h M sources/editor/rectangleeditor.cpp M sources/editor/rectangleeditor.h M sources/editor/styleeditor.cpp M sources/editor/styleeditor.h M sources/editor/terminaleditor.cpp M sources/editor/terminaleditor.h M sources/editor/texteditor.cpp M sources/editor/texteditor.h M sources/editor/textfieldeditor.cpp M sources/editor/textfieldeditor.h M sources/editor/ui/elementpropertieseditorwidget.cpp M sources/elementdefinition.cpp M sources/elementdeleter.cpp M sources/elementdeleter.h M sources/elementdialog.cpp M sources/elementscategorieslist.h M sources/elementscategorieswidget.cpp M sources/elementscategorieswidget.h M sources/elementscategory.cpp M sources/elementscategorydeleter.cpp M sources/elementscategorydeleter.h M sources/elementscategoryeditor.cpp M sources/elementscategoryeditor.h M sources/elementscollection.cpp M sources/elementscollectioncache.cpp M sources/elementspanel.cpp M sources/elementspanel.h M sources/elementspanelwidget.cpp M sources/elementspanelwidget.h M sources/elementtextsmover.h M sources/exportdialog.cpp M sources/exportdialog.h M sources/exportproperties.cpp M sources/exportpropertieswidget.cpp M sources/exportpropertieswidget.h M sources/genericpanel.cpp M sources/integrationmoveelementshandler.cpp M sources/integrationmoveelementshandler.h M sources/interactivemoveelementshandler.cpp M sources/nameslistwidget.cpp M sources/nameslistwidget.h M sources/newelementwizard.cpp M sources/newelementwizard.h M sources/nomenclature.cpp M sources/nomenclature.h M sources/projectconfigpages.cpp M sources/projectview.cpp M sources/projectview.h M sources/qet.cpp M sources/qetapp.cpp M sources/qetapp.h M sources/qetdiagrameditor.cpp M sources/qetdiagrameditor.h M sources/qetgraphicsitem/conductor.cpp M sources/qetgraphicsitem/conductortextitem.cpp M sources/qetgraphicsitem/customelement.cpp M sources/qetgraphicsitem/diagramimageitem.cpp M sources/qetgraphicsitem/diagramtextitem.cpp M sources/qetgraphicsitem/diagramtextitem.h M sources/qetgraphicsitem/element.cpp M sources/qetgraphicsitem/ghostelement.cpp M sources/qetgraphicsitem/qetshapeitem.cpp M sources/qetgraphicsitem/terminal.cpp M sources/qetgraphicsitem/terminal.h M sources/qeticons.cpp M sources/qeticons.h M sources/qetmainwindow.cpp M sources/qetmessagebox.cpp M sources/qetmessagebox.h M sources/qetprintpreviewdialog.cpp M sources/qetprintpreviewdialog.h M sources/qetproject.cpp M sources/qetsingleapplication.cpp M sources/qettabbar.h M sources/qfilenameedit.cpp M sources/qtextorientationspinboxwidget.cpp M sources/qtextorientationspinboxwidget.h M sources/qtextorientationwidget.cpp M sources/qtextorientationwidget.h M sources/richtext/richtexteditor.cpp M sources/richtext/richtexteditor_p.h M sources/richtext/ui_addlinkdialog.h M sources/titleblock/dimensionwidget.h M sources/titleblock/gridlayoutanimation.h M sources/titleblock/helpercell.h M sources/titleblock/integrationmovetemplateshandler.cpp M sources/titleblock/integrationmovetemplateshandler.h M sources/titleblock/qettemplateeditor.cpp M sources/titleblock/qettemplateeditor.h M sources/titleblock/templatecellsset.h M sources/titleblock/templatecellwidget.cpp M sources/titleblock/templatecellwidget.h M sources/titleblock/templatecommands.cpp M sources/titleblock/templatedeleter.cpp M sources/titleblock/templatedeleter.h M sources/titleblock/templatelocationchooser.cpp M sources/titleblock/templatelocationchooser.h M sources/titleblock/templatelocationsaver.cpp M sources/titleblock/templatelocationsaver.h M sources/titleblock/templatelogomanager.cpp M sources/titleblock/templatelogomanager.h M sources/titleblock/templateview.cpp M sources/titleblock/templatevisualcell.h M sources/titleblockcell.cpp M sources/titleblocktemplate.cpp M sources/treecoloranimation.h M sources/ui/conductorpropertieswidget.cpp M sources/ui/diagrampropertiesdialog.cpp M sources/ui/diagramselection.cpp M sources/ui/dialogautonum.cpp M sources/ui/dialogwaiting.cpp M sources/ui/elementpropertieswidget.cpp M sources/ui/elementselectorwidget.cpp M sources/ui/linksingleelementwidget.cpp M sources/ui/masterpropertieswidget.cpp M sources/ui/potentialtextsdialog.cpp M sources/ui/projectpropertiesdialog.cpp M sources/ui/selectautonumw.cpp M sources/ui/titleblockpropertieswidget.cpp M sources/ui/xrefpropertieswidget.cpp M sources/undocommand/changeelementinformationcommand.cpp git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3783 bfdf4180-ca20-0410-9c96-a3a8aa849046
2015-03-02 20:14:56 +00:00
#include <QtWidgets>
#include <QtXml>
#include <QHash>
#include <QUuid>
#include "bordertitleblock.h"
#include "conductorproperties.h"
#include "exportproperties.h"
#include "qgimanager.h"
#include "numerotationcontext.h"
#include "qetproject.h"
#include "properties/xrefproperties.h"
#include "elementsmover.h"
#include "elementtextsmover.h"
class Conductor;
class CustomElement;
class DiagramContent;
class DiagramPosition;
class DiagramTextItem;
class Element;
class ElementsLocation;
class QETProject;
class Terminal;
class DiagramImageItem;
class DiagramEventInterface;
2020-07-15 17:43:20 +02:00
class DiagramFolioList;
class QETProject;
2020-07-14 20:56:53 +02:00
/**
@brief The Diagram class
This class represents an electric diagram.
It manages its various child elements,
conductors and texts and handles their graphic rendering.
*/
class Diagram : public QGraphicsScene
{
2020-07-15 17:43:20 +02:00
friend DiagramFolioList;
friend QETProject;
Q_OBJECT
// constructors, destructor
private:
Diagram(QETProject *project);
~Diagram() override;
Diagram(const Diagram &diagram);
// ATTRIBUTES
public:
/**
2020-07-14 21:39:47 +02:00
@brief The BorderOptions enum
Represents available options when rendering a particular diagram:
2020-07-14 21:39:47 +02:00
EmptyBorder: display border only
TitleBlock: display title block
Columns: display columns
*/
enum BorderOptions { EmptyBorder, TitleBlock, Columns };
/// Represents available option of Numerotation type.
enum NumerotationType { Conductors };
/// Default properties for new conductors
ConductorProperties defaultConductorProperties;
/// Diagram dimensions and title block
BorderTitleBlock border_and_titleblock;
/// abscissa grid step size
static int xGrid;
/// ordinate grid step size
static int yGrid;
/// Key grid x step size
static int xKeyGrid;
/// Key grid y step size
static int yKeyGrid;
2020-07-14 21:51:15 +02:00
/// Key grid fine x step size
static int xKeyGridFine;
/// Key grid fine y step size
static int yKeyGridFine;
/// margin around the diagram
static const qreal margin;
/// background color of diagram
static QColor background_color;
/// Hash containing max values for folio sequential autonums in this diagram
QHash <QString, QStringList> m_elmt_unitfolio_max;
QHash <QString, QStringList> m_elmt_tenfolio_max;
QHash <QString, QStringList> m_elmt_hundredfolio_max;
/// Hash containing max values for folio sequential autonums in this diagram
QHash <QString, QStringList> m_cnd_unitfolio_max;
QHash <QString, QStringList> m_cnd_tenfolio_max;
QHash <QString, QStringList> m_cnd_hundredfolio_max;
private:
QGraphicsLineItem *conductor_setter_;
ElementsMover m_elements_mover;
ElementTextsMover m_element_texts_mover;
QGIManager *qgi_manager_;
QETProject *m_project;
QDomDocument xml_document_;
qreal diagram_qet_version_;
bool draw_grid_;
bool use_border_;
bool draw_terminals_;
bool draw_colored_conductors_;
QString m_conductors_autonum_name;
DiagramEventInterface *m_event_interface;
bool m_freeze_new_elements;
bool m_freeze_new_conductors_;
QUuid m_uuid = QUuid::createUuid();
// METHODS
protected:
void drawBackground(QPainter *, const QRectF &) override;
2020-08-20 21:58:23 +02:00
void mouseDoubleClickEvent (
QGraphicsSceneMouseEvent *event) override;
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent (
QGraphicsSceneMouseEvent *event) override;
void wheelEvent (QGraphicsSceneWheelEvent *event) override;
void keyPressEvent (QKeyEvent *event) override;
void keyReleaseEvent (QKeyEvent *) override;
public:
QUuid uuid();
void setEventInterface (DiagramEventInterface *event_interface);
void clearEventInterface();
2020-07-14 21:51:15 +02:00
//methods related to autonum
QString conductorsAutonumName() const;
void setConductorsAutonumName(const QString &name);
static bool clipboardMayContainDiagram();
2020-07-14 21:51:15 +02:00
// methods related to parent project
QETProject *project() const;
int folioIndex() const;
qreal declaredQElectroTechVersion(bool = true) const;
void showMe() {emit showDiagram(this);}
bool isReadOnly() const;
2020-07-14 21:51:15 +02:00
// methods related to conductor creation
void setConductor(bool);
void setConductorStart (QPointF);
void setConductorStop(QPointF);
QList < QSet <Conductor *> > potentials();
// methods related to XML import/export
QDomDocument toXml(bool = true);
2020-08-20 21:58:23 +02:00
bool initFromXml(QDomElement &,
QPointF = QPointF(),
bool = true,
DiagramContent * = nullptr);
bool fromXml(QDomDocument &,
QPointF = QPointF(),
bool = true,
DiagramContent * = nullptr);
bool fromXml(QDomElement &,
QPointF = QPointF(),
bool = true,
DiagramContent * = nullptr);
void folioSequentialsToXml(QHash<QString,
QStringList>*,
QDomElement *,
const QString&,
const QString&,
QDomDocument *);
void folioSequentialsFromXml(const QDomElement&,
QHash<QString,
QStringList>*,
const QString&,
const QString&,
const QString&,
2020-07-14 22:05:24 +02:00
const QString&);
void refreshContents();
2020-07-14 21:51:15 +02:00
// methods related to graphics items addition/removal on the diagram
virtual void addItem (QGraphicsItem *item);
virtual void removeItem (QGraphicsItem *item);
2020-07-14 21:51:15 +02:00
// methods related to graphics options
ExportProperties applyProperties(const ExportProperties &);
void setDisplayGrid(bool);
bool displayGrid();
void setUseBorder(bool);
bool useBorder();
void setBorderOptions(BorderOptions);
BorderOptions borderOptions();
DiagramPosition convertPosition(const QPointF &);
static QPointF snapToGrid(const QPointF &p);
bool drawTerminals() const;
void setDrawTerminals(bool);
bool drawColoredConductors() const;
void setDrawColoredConductors(bool);
QString title() const;
2020-07-14 22:05:24 +02:00
bool toPaintDevice(QPaintDevice &, int = -1, int = -1,
Qt::AspectRatioMode = Qt::KeepAspectRatio);
QSize imageSize() const;
bool isEmpty() const;
QList<Element *> elements() const;
QList<Conductor *> conductors() const;
QSet<Conductor *> selectedConductors() const;
DiagramContent content() const;
bool canRotateSelection() const;
ElementsMover &elementsMover();
ElementTextsMover &elementTextsMover();
bool usesElement(const ElementsLocation &);
bool usesTitleBlockTemplate(const QString &);
QUndoStack &undoStack();
QGIManager &qgiManager();
2020-07-14 21:51:15 +02:00
//methods related to element label Update Policy
void freezeElements(bool freeze);
void unfreezeElements();
void setFreezeNewElements(bool);
bool freezeNewElements();
2020-07-14 21:51:15 +02:00
//methods related to conductor label Update Policy
void freezeConductors(bool freeze);
void setFreezeNewConductors(bool);
bool freezeNewConductors();
2020-07-14 22:05:24 +02:00
//methods related to insertion and loading of folio sequential
void insertFolioSeqHash (QHash<QString, QStringList> *hash,
const QString& title,
const QString& seq,
NumerotationContext *nc);
void loadFolioSeqHash (QHash<QString, QStringList> *hash,
const QString& title, const QString& seq,
NumerotationContext *nc);
void changeZValue(QET::DepthOption option);
public slots:
void adjustSceneRect ();
void titleChanged(const QString &);
void titleBlockTemplateChanged(const QString &);
2020-07-14 22:05:24 +02:00
void titleBlockTemplateRemoved(const QString &,
const QString & = QString());
void setTitleBlockTemplate(const QString &);
void updateLabels();
void loadElmtFolioSeq();
void loadCndFolioSeq();
2020-07-14 21:51:15 +02:00
// methods related to graphics items selection
void selectAll();
void deselectAll();
void invertSelection();
signals:
void showDiagram (Diagram *);
void usedTitleBlockTemplateChanged(const QString &);
void diagramTitleChanged(Diagram *, const QString &);
2020-07-14 22:05:24 +02:00
/// Signal emitted when users wish to locate an element
/// from the diagram within elements collection
void findElementRequired(const ElementsLocation &);
/// Signal emitted when users wish to edit an element from the diagram
void editElementRequired(const ElementsLocation &);
void diagramActivated();
};
Q_DECLARE_METATYPE(Diagram *)
/**
2020-07-14 22:05:24 +02:00
@brief Diagram::setConductor
Display or hide the conductor setter,
i.e. a dashed conductor stub which appears
when creating a conductor between two terminals.
@param adding true add conductor ,false remove conductor
*/
inline void Diagram::setConductor(bool adding) {
if (adding) {
if (!conductor_setter_ -> scene()) addItem(conductor_setter_);
} else {
if (conductor_setter_ -> scene()) removeItem(conductor_setter_);
}
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::setConductorStart
Set the start point of the conductor setter.
@param start the point (in scene coordinates) which the newly created
conductor should start from.
*/
inline void Diagram::setConductorStart(QPointF start) {
conductor_setter_ -> setLine(QLineF(start, conductor_setter_ -> line().p2()));
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::setConductorStop
Set the end point of the conductor setter.
@param end the point (in scene coordinates) upon to which the newly created
conductor should be drawn.
*/
inline void Diagram::setConductorStop(QPointF end) {
conductor_setter_ -> setLine(QLineF(conductor_setter_ -> line().p1(), end));
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::setDisplayGrid
Set whether the diagram grid should be drawn.
@param dg true to render the grid, false otherwise.
*/
inline void Diagram::setDisplayGrid(bool dg) {
draw_grid_ = dg;
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::displayGrid
@return draw_grid_ true if the grid is drawn, false otherwise.
*/
inline bool Diagram::displayGrid() {
return(draw_grid_);
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::setUseBorder
Set whether the diagram border (including rows/colums headers and the title
block) should be rendered along with the diagram. When set to false, the size
of the smallest rectangle containing all items is considered as the diagram
size.
@param ub true to take the border into account, false otherwise
*/
inline void Diagram::setUseBorder(bool ub) {
use_border_ = ub;
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::useBorder
@return use_border_ true if the border is rendered and take into account,
false otherwise.
*/
inline bool Diagram::useBorder() {
return(use_border_);
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::setBorderOptions
Set the rendering options for the diagram border (including rows/colums
headers and the title block)
@param bo Enabled options ORed together
@see BorderOptions
*/
inline void Diagram::setBorderOptions(Diagram::BorderOptions bo) {
border_and_titleblock.displayBorder(!(bo & EmptyBorder));
border_and_titleblock.displayColumns(bo & Columns);
border_and_titleblock.displayTitleBlock(bo & TitleBlock);
}
/**
2020-07-15 18:02:11 +02:00
@brief Diagram::borderOptions
@return The rendering optios for the diagram border
@see setBorderOptions
*/
inline Diagram::BorderOptions Diagram::borderOptions() {
BorderOptions options = EmptyBorder;
2020-07-14 22:05:24 +02:00
if (border_and_titleblock.titleBlockIsDisplayed())
options = (BorderOptions)(options|TitleBlock);
if (border_and_titleblock.columnsAreDisplayed())
options = (BorderOptions)(options|Columns);
return(options);
}
2020-07-15 18:02:11 +02:00
/**
@brief Diagram::undoStack
@return the diagram undo stack
*/
inline QUndoStack &Diagram::undoStack() {
return *(project()->undoStack());
}
2020-07-15 18:02:11 +02:00
/**
@brief Diagram::qgiManager
@return the diagram graphics item manager
*/
inline QGIManager &Diagram::qgiManager() {
return(*qgi_manager_);
}
2020-07-15 18:02:11 +02:00
/**
@brief Diagram::drawTerminals
@return true if terminals are rendered, false otherwise
*/
inline bool Diagram::drawTerminals() const {
return(draw_terminals_);
}
2020-07-15 18:02:11 +02:00
/**
@brief Diagram::drawColoredConductors
@return true if conductors colors are rendered, false otherwise.
*/
inline bool Diagram::drawColoredConductors() const {
return(draw_colored_conductors_);
}
#endif