This commit is contained in:
Martin Marmsoler
2020-09-14 21:21:32 +02:00
parent c5f1705745
commit 6080a7b9c9
34 changed files with 237 additions and 198 deletions

View File

@@ -46,7 +46,7 @@ class QetGraphicsHandlerItem : public QGraphicsItem
QRectF m_handler_rect, QRectF m_handler_rect,
m_br; m_br;
qreal m_size; qreal m_size;
QColor m_color; QColor m_color{Qt::black};
QPen m_pen; QPen m_pen;
public: public:

View File

@@ -32,15 +32,7 @@
- 17 colonnes affichees de 60.0 px de large pour 20.0px de haut - 17 colonnes affichees de 60.0 px de large pour 20.0px de haut
- 8 lignes affichees de 80.0 px de haut pour 20.0px de large - 8 lignes affichees de 80.0 px de haut pour 20.0px de large
*/ */
BorderProperties::BorderProperties() : BorderProperties::BorderProperties()
columns_count(17),
columns_width(60.0),
columns_header_height(20.0),
display_columns(true),
rows_count(8),
rows_height(80.0),
rows_header_width(20.0),
display_rows(true)
{ {
} }
@@ -103,11 +95,12 @@ QDomElement BorderProperties::toXml(QDomDocument &dom_doc) const {
e.appendChild(createXmlProperty(dom_doc, "rows", rows_count)); e.appendChild(createXmlProperty(dom_doc, "rows", rows_count));
e.appendChild(createXmlProperty(dom_doc, "rowsize", rows_height)); e.appendChild(createXmlProperty(dom_doc, "rowsize", rows_height));
e.appendChild(createXmlProperty(dom_doc, "displayrows", display_rows)); e.appendChild(createXmlProperty(dom_doc, "displayrows", display_rows));
e.appendChild(createXmlProperty(dom_doc, "displaycols", display_columns));
return e; return e;
} }
/** /**RETURNS True
@brief BorderProperties::fromXml @brief BorderProperties::fromXml
- Import dimensions from XML attributes of element e - Import dimensions from XML attributes of element e
- Importe les dimensions a partir des attributs XML de l'element e - Importe les dimensions a partir des attributs XML de l'element e
@@ -137,6 +130,7 @@ bool BorderProperties::valideXml(QDomElement& e) {
propertyBool(e, "displaycols") == PropertyFlags::Success || propertyBool(e, "displaycols") == PropertyFlags::Success ||
propertyBool(e, "displayrows") == PropertyFlags::Success) propertyBool(e, "displayrows") == PropertyFlags::Success)
return true; return true;
return false;
} }
/** /**

View File

@@ -46,14 +46,14 @@ class BorderProperties : public PropertiesInterface {
static BorderProperties defaultProperties(); static BorderProperties defaultProperties();
// attributes // attributes
int columns_count; ///< Columns count int columns_count{17}; ///< Columns count
qreal columns_width; ///< Columns width qreal columns_width{60.0}; ///< Columns width
qreal columns_header_height; ///< Column headers height qreal columns_header_height{20.0}; ///< Column headers height
bool display_columns; ///< Whether to display column headers bool display_columns{true}; ///< Whether to display column headers
int rows_count; ///< Rows count int rows_count{8}; ///< Rows count
qreal rows_height; ///< Rows height qreal rows_height{80.0}; ///< Rows height
qreal rows_header_width; ///< Row headers width qreal rows_header_width{20.0}; ///< Row headers width
bool display_rows; ///< Whether to display row headers bool display_rows{true}; ///< Whether to display row headers
}; };
#endif #endif

View File

@@ -22,11 +22,7 @@
/** /**
Constructeur par defaut Constructeur par defaut
*/ */
SingleLineProperties::SingleLineProperties() : SingleLineProperties::SingleLineProperties()
hasGround(true),
hasNeutral(true),
is_pen(false),
phases(1)
{ {
} }
@@ -282,8 +278,6 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const
QDomElement e = doc.createElement("defaultconductor"); QDomElement e = doc.createElement("defaultconductor");
e.appendChild(createXmlProperty(doc, "type", typeToString(type))); e.appendChild(createXmlProperty(doc, "type", typeToString(type)));
if (color != QColor(Qt::black))
e.appendChild(createXmlProperty(doc, "color", color)); e.appendChild(createXmlProperty(doc, "color", color));
e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor)); e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor));
@@ -294,7 +288,7 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const
e.appendChild(singleLineProperties.toXml(doc)); e.appendChild(singleLineProperties.toXml(doc));
e.appendChild(createXmlProperty(doc, "num", text)); e.appendChild(createXmlProperty(doc, "num", text));
e.appendChild(createXmlProperty(doc, "text_color", text_color.name())); e.appendChild(createXmlProperty(doc, "text_color", text_color));
e.appendChild(createXmlProperty(doc, "formula", m_formula)); e.appendChild(createXmlProperty(doc, "formula", m_formula));
e.appendChild(createXmlProperty(doc, "function", m_function)); e.appendChild(createXmlProperty(doc, "function", m_function));
e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol)); e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol));
@@ -319,7 +313,7 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const
} }
/** /** RETURNS True
* @brief ConductorProperties::fromXml * @brief ConductorProperties::fromXml
* Import conductor propertie, from the attribute of the xml element 'e' * Import conductor propertie, from the attribute of the xml element 'e'
* @param e the xml document * @param e the xml document
@@ -328,9 +322,9 @@ bool ConductorProperties::fromXml(const QDomElement &e)
{ {
// get conductor color // get conductor color
propertyColor(e, "color", &color); propertyColor(e, "color", &color);
propertyBool(e, "bicolor", &m_bicolor, false); propertyBool(e, "bicolor", &m_bicolor);
propertyColor(e, "color2", &m_color_2); propertyColor(e, "color2", &m_color_2);
propertyInteger(e, "dash-size", &m_dash_size, 1); propertyInteger(e, "dash-size", &m_dash_size);
// read style of conductor // read style of conductor
readStyle(e.attribute("style")); readStyle(e.attribute("style"));
@@ -356,10 +350,10 @@ bool ConductorProperties::fromXml(const QDomElement &e)
propertyString(e, "tension_protocol", &m_tension_protocol); propertyString(e, "tension_protocol", &m_tension_protocol);
propertyString(e, "conductor_color", &m_wire_color); propertyString(e, "conductor_color", &m_wire_color);
propertyString(e, "conductor_section", &m_wire_section); propertyString(e, "conductor_section", &m_wire_section);
propertyInteger(e, "numsize", &text_size, 9); propertyInteger(e, "numsize", &text_size);
propertyDouble(e, "condsize", &cond_size, 1); propertyDouble(e, "condsize", &cond_size);
propertyBool(e, "displaytext", &m_show_text, true); propertyBool(e, "displaytext", &m_show_text);
propertyBool(e, "onetextperfolio", &m_one_text_per_folio, 0); propertyBool(e, "onetextperfolio", &m_one_text_per_folio);
propertyDouble(e, "vertirotatetext", &verti_rotate_text); propertyDouble(e, "vertirotatetext", &verti_rotate_text);
propertyDouble(e, "horizrotatetext", &horiz_rotate_text); propertyDouble(e, "horizrotatetext", &horiz_rotate_text);
@@ -376,6 +370,8 @@ bool ConductorProperties::fromXml(const QDomElement &e)
//@TODO remove this code for qet 0.6 or later //@TODO remove this code for qet 0.6 or later
if (type_t == "simple") m_show_text = false; if (type_t == "simple") m_show_text = false;
return true;
} }
bool ConductorProperties::valideXml(QDomElement& e) { bool ConductorProperties::valideXml(QDomElement& e) {

View File

@@ -45,17 +45,17 @@ class SingleLineProperties: public PropertiesInterface {
void fromSettings(const QSettings &, const QString & = QString()) override; void fromSettings(const QSettings &, const QString & = QString()) override;
/// Whether the singleline conductor should display the ground symbol /// Whether the singleline conductor should display the ground symbol
bool hasGround; bool hasGround{true};
/// Whether the singleline conductor should display the neutral symbol /// Whether the singleline conductor should display the neutral symbol
bool hasNeutral; bool hasNeutral{true};
/// Protective Earth Neutral: visually merge neutral and ground /// Protective Earth Neutral: visually merge neutral and ground
bool is_pen; bool is_pen{false};
int operator==(const SingleLineProperties &) const; int operator==(const SingleLineProperties &) const;
int operator!=(const SingleLineProperties &) const; int operator!=(const SingleLineProperties &) const;
private: private:
unsigned short int phases; unsigned short int phases{1};
void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal);
void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
void drawPen(QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawPen(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
@@ -80,11 +80,12 @@ class ConductorProperties: public PropertiesInterface
//Attributes //Attributes
ConductorType type; ConductorType type{ConductorType::Single};
QColor color, // TODO: set default values!
m_color_2, QColor color{QColor(Qt::black)},
text_color; m_color_2{QColor(Qt::black)},
text_color{QColor(Qt::black)};
QString text, QString text,
m_function, m_function,
@@ -93,21 +94,21 @@ class ConductorProperties: public PropertiesInterface
m_wire_section, m_wire_section,
m_formula; m_formula;
int text_size, int text_size{9},
m_dash_size = 1; m_dash_size = 1;
double cond_size, double cond_size{1},
verti_rotate_text, verti_rotate_text,
horiz_rotate_text; horiz_rotate_text;
bool m_show_text, bool m_show_text{true},
m_one_text_per_folio, m_one_text_per_folio{true},
m_bicolor = false; m_bicolor = false;
Qt::Alignment m_horizontal_alignment = Qt::AlignBottom, Qt::Alignment m_horizontal_alignment = Qt::AlignBottom,
m_vertical_alignment = Qt::AlignRight; m_vertical_alignment = Qt::AlignRight;
Qt::PenStyle style; Qt::PenStyle style{Qt::PenStyle::SolidLine};
SingleLineProperties singleLineProperties; SingleLineProperties singleLineProperties;

View File

@@ -928,6 +928,8 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
// The first element must be a diagram // The first element must be a diagram
if (root.tagName() != "diagram") return(false); if (root.tagName() != "diagram") return(false);
qDebug() << "Diagram::fromXml; Diagram: " << root.attribute("title");
// Read attributes of this diagram // Read attributes of this diagram
if (consider_informations) { if (consider_informations) {
// Version of diagram // Version of diagram

View File

@@ -96,7 +96,7 @@ class Diagram : public QGraphicsScene
/// margin around the diagram /// margin around the diagram
static const qreal margin; static const qreal margin;
/// background color of diagram /// background color of diagram
static QColor background_color; static QColor background_color; // default value set in cpp file
/// Hash containing max values for folio sequential autonums in this diagram /// Hash containing max values for folio sequential autonums in this diagram
QHash <QString, QStringList> m_elmt_unitfolio_max; QHash <QString, QStringList> m_elmt_unitfolio_max;
QHash <QString, QStringList> m_elmt_tenfolio_max; QHash <QString, QStringList> m_elmt_tenfolio_max;

View File

@@ -41,7 +41,6 @@ DiagramPrintDialog::DiagramPrintDialog(QETProject *project, QWidget *parent) :
// orientation paysage par defaut // orientation paysage par defaut
printer_ -> setOrientation(QPrinter::Landscape); printer_ -> setOrientation(QPrinter::Landscape);
backup_diagram_background_color = Diagram::background_color;
Diagram::background_color = Qt::white; Diagram::background_color = Qt::white;
} }

View File

@@ -88,6 +88,6 @@ class DiagramPrintDialog : public QWidget
QLineEdit *filepath_field_; QLineEdit *filepath_field_;
QPushButton *browse_button_; QPushButton *browse_button_;
QDialogButtonBox *buttons_; QDialogButtonBox *buttons_;
QColor backup_diagram_background_color; QColor backup_diagram_background_color{Diagram::background_color};
}; };
#endif #endif

View File

@@ -139,6 +139,8 @@ bool PartArc::fromXml(const QDomElement &qde) {
if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion) if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion)
return false; return false;
m_span_angle *= 16; m_span_angle *= 16;
return true;
} }
bool PartArc::valideXml(QDomElement& element) { bool PartArc::valideXml(QDomElement& element) {

View File

@@ -160,12 +160,12 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
return false; return false;
} }
double x, y, z, rot; double x=0, y=0, z=0, rot=0;
if (propertyDouble(dom_elmt, "x", &x, 0) == PropertyFlags::NoValidConversion || if (propertyDouble(dom_elmt, "x", &x) == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "y", &y, 0) == PropertyFlags::NoValidConversion || propertyDouble(dom_elmt, "y", &y) == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "z", &z, 0) == PropertyFlags::NoValidConversion || propertyDouble(dom_elmt, "z", &z) == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "rotation", &rot, 0) == PropertyFlags::NoValidConversion) propertyDouble(dom_elmt, "rotation", &rot) == PropertyFlags::NoValidConversion)
return false; return false;
QGraphicsTextItem::setPos(x, y); QGraphicsTextItem::setPos(x, y);
@@ -182,12 +182,12 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
setFont(QETApp::dynamicTextsItemFont(9)); setFont(QETApp::dynamicTextsItemFont(9));
} }
propertyUuid(dom_elmt, "uuid", &m_uuid, QUuid::createUuid()); propertyUuid(dom_elmt, "uuid", &m_uuid);
bool frame; bool frame;
propertyBool(dom_elmt, "frame", &frame); propertyBool(dom_elmt, "frame", &frame);
double text_width; double text_width;
propertyDouble(dom_elmt, "text_width", &text_width, -1); propertyDouble(dom_elmt, "text_width", &text_width, true, -1);
setTextWidth(text_width); setTextWidth(text_width);
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
@@ -226,6 +226,8 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
QDomElement dom_color = dom_elmt.firstChildElement("color"); QDomElement dom_color = dom_elmt.firstChildElement("color");
if(!dom_color.isNull()) if(!dom_color.isNull())
setColor(QColor(dom_color.text())); setColor(QColor(dom_color.text()));
return true;
} }
bool PartDynamicTextField::valideXml(QDomElement& dom_elmt) { bool PartDynamicTextField::valideXml(QDomElement& dom_elmt) {

View File

@@ -117,7 +117,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
m_info_name, m_info_name,
m_composite_text; m_composite_text;
DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText; DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText;
QUuid m_uuid; QUuid m_uuid{QUuid::createUuid()};
bool m_frame = false, bool m_frame = false,
m_first_add = true, m_first_add = true,
m_block_alignment = false; m_block_alignment = false;

View File

@@ -17,6 +17,8 @@
*/ */
#include "propertiesinterface.h" #include "propertiesinterface.h"
#include <QDebug>
/*! /*!
* Available property types * Available property types
*/ */
@@ -46,6 +48,14 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QStr
return p; return p;
} }
QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) const {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", stringS);
p.setAttribute("value", value);
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) const { QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) const {
QDomElement p = doc.createElement("property"); QDomElement p = doc.createElement("property");
p.setAttribute("name", name); p.setAttribute("name", name);
@@ -112,14 +122,18 @@ bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribu
if (p.isNull()) { if (p.isNull()) {
// check if legacy property is available, // check if legacy property is available,
// where the property is inside the element as attribute // where the property is inside the element as attribute
if (!e.hasAttribute(attribute_name)) if (!e.hasAttribute(attribute_name)) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available";
return false; return false;
}
*attr = e.attribute(attribute_name); *attr = e.attribute(attribute_name);
} else { } else {
if (p.attribute("type") != type) if (p.attribute("type") != type) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type;
return false; return false;
}
*attr = p.attribute("value"); *attr = p.attribute("value");
@@ -136,11 +150,12 @@ bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribu
* \return True if reading an integer was successful, else False. If the attribute was not found, * \return True if reading an integer was successful, else False. If the attribute was not found,
* \p entier is not valid and the return value is False * \p entier is not valid and the return value is False
*/ */
PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier, int defaultValue) { PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier, bool setDefaultValue, int defaultValue) {
QString attr; QString attr;
if (!attribute(e, attribute_name, integerS, &attr)) { if (!attribute(e, attribute_name, integerS, &attr)) {
if (entier && setDefaultValue)
*entier = defaultValue; *entier = defaultValue;
return PropertyFlags::NotFound; return PropertyFlags::NotFound;
} }
@@ -148,8 +163,10 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QD
// verifie la validite de l'attribut // verifie la validite de l'attribut
bool ok; bool ok;
int tmp = attr.toInt(&ok); int tmp = attr.toInt(&ok);
if (!ok) if (!ok) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
return PropertyFlags::NoValidConversion; return PropertyFlags::NoValidConversion;
}
if (entier != nullptr) if (entier != nullptr)
*entier = tmp; *entier = tmp;
@@ -157,11 +174,12 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QD
return PropertyFlags::Success; return PropertyFlags::Success;
} }
PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel, double defaultValue) { PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel, bool setDefaultValue, double defaultValue) {
QString attr; QString attr;
if (!attribute(e, attribute_name, doubleS, &attr)) { if (!attribute(e, attribute_name, doubleS, &attr)) {
if (reel && setDefaultValue)
*reel = defaultValue; *reel = defaultValue;
return PropertyFlags::NotFound; return PropertyFlags::NotFound;
} }
@@ -169,8 +187,10 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo
// verifie la validite de l'attribut // verifie la validite de l'attribut
bool ok; bool ok;
double tmp = attr.toDouble(&ok); double tmp = attr.toDouble(&ok);
if (!ok) if (!ok) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << doubleS << ". value: " << attr;
return PropertyFlags::NoValidConversion; return PropertyFlags::NoValidConversion;
}
if (reel != nullptr) if (reel != nullptr)
*reel = tmp; *reel = tmp;
@@ -178,11 +198,12 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo
return PropertyFlags::Success; return PropertyFlags::Success;
} }
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool defaultValue) { PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool setDefaultValue, bool defaultValue) {
QString attr; QString attr;
if (!attribute(e, attribute_name, integerS, &attr)) { if (!attribute(e, attribute_name, boolS, &attr)) {
if (boolean && setDefaultValue)
*boolean = defaultValue; *boolean = defaultValue;
return PropertyFlags::NotFound; return PropertyFlags::NotFound;
} }
@@ -190,8 +211,16 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE
// verifie la validite de l'attribut // verifie la validite de l'attribut
bool ok; bool ok;
bool tmp = attr.toInt(&ok); bool tmp = attr.toInt(&ok);
if (!ok) if (!ok) {
if (attr == "true")
tmp = true;
else if (attr == "false")
tmp = false;
else {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
return PropertyFlags::NoValidConversion; return PropertyFlags::NoValidConversion;
}
}
if (boolean != nullptr) if (boolean != nullptr)
*boolean = tmp; *boolean = tmp;
@@ -199,19 +228,22 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE
return PropertyFlags::Success; return PropertyFlags::Success;
} }
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, QColor defaultValue) { PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, bool setDefaultValue, QColor defaultValue) {
QString attr; QString attr;
if (!attribute(e, attribute_name, colorS, &attr)) { if (!attribute(e, attribute_name, colorS, &attr)) {
if (color && setDefaultValue)
*color = defaultValue; *color = defaultValue;
return PropertyFlags::NotFound; return PropertyFlags::NotFound;
} }
// verifie la validite de l'attribut // verifie la validite de l'attribut
QColor tmp = QColor(attr); QColor tmp = QColor(attr);
if (!tmp.isValid()) if (!tmp.isValid()) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << colorS << ". value: " << attr;
return PropertyFlags::NoValidConversion; return PropertyFlags::NoValidConversion;
}
if (color != nullptr) if (color != nullptr)
*color = tmp; *color = tmp;
@@ -219,24 +251,32 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDom
return PropertyFlags::Success; return PropertyFlags::Success;
} }
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, QUuid defaultValue) { PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, bool setDefaultValue, QUuid defaultValue) {
QString attr; QString attr;
if (!attribute(e, attribute_name, uuidS, &attr)) { if (!attribute(e, attribute_name, uuidS, &attr)) {
if (uuid && setDefaultValue)
*uuid = defaultValue; *uuid = defaultValue;
return PropertyFlags::NotFound; return PropertyFlags::NotFound;
} }
if (QUuid(attr).isNull()){
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << uuidS << ". value: " << attr;
return PropertyFlags::NoValidConversion;
}
if (uuid != nullptr) if (uuid != nullptr)
*uuid = QUuid(attr); *uuid = QUuid(attr);
return PropertyFlags::Success; return PropertyFlags::Success;
} }
PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, QString defaultValue) { PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, bool setDefaultValue, QString defaultValue) {
QString attr; QString attr;
if (!attribute(e, attribute_name, stringS, &attr)) { if (!attribute(e, attribute_name, stringS, &attr)) {
if (string && setDefaultValue)
*string = defaultValue; *string = defaultValue;
return PropertyFlags::NotFound; return PropertyFlags::NotFound;
} }
@@ -263,6 +303,8 @@ bool PropertiesInterface::validXmlProperty(const QDomElement& e) {
if (!e.hasAttribute("value")) if (!e.hasAttribute("value"))
return false; return false;
return true;
} }
/** /**
@@ -275,10 +317,12 @@ bool PropertiesInterface::validXmlProperty(const QDomElement& e) {
*/ */
Qet::Orientation PropertiesInterface::orientationFromString(const QString &s) { Qet::Orientation PropertiesInterface::orientationFromString(const QString &s) {
QChar c = s[0]; QChar c = s[0];
if (c == 'e') return(Qet::East); // in some cases/ old projects? (affuteuse_250h.qet) numbers instead of characters are
else if (c == 's') return(Qet::South); // used for the orientation
else if (c == 'w') return (Qet::West); if (c == 'e' || c == '1') return(Qet::East);
else return(Qet::North); else if (c == 's' || c == '2') return(Qet::South);
else if (c == 'w' || c == '3') return (Qet::West);
else return(Qet::North); // c == '0'
} }
/** /**

View File

@@ -46,6 +46,7 @@ class PropertiesInterface
* Use this functions to add properties to the xml document * Use this functions to add properties to the xml document
*/ */
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value) const;
QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value) const;
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const;
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const;
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const;
@@ -62,12 +63,15 @@ class PropertiesInterface
// = 4 // = 4
}; };
static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits<int>::quiet_NaN()); /*!
static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, double defaultValue = std::numeric_limits<double>::quiet_NaN()); * Try not using the default Value feature. It is better to initialize the class members in the class definition!
static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, QString defaultValue = QString()); */
static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaultValue = false); static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, bool setDefaultValue = false, int defaultValue = std::numeric_limits<int>::quiet_NaN());
static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, QUuid defaultValue = QUuid()); static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, bool setDefaultValue = false, double defaultValue = std::numeric_limits<double>::quiet_NaN());
static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, QColor defaultValue = QColor()); static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, bool setDefaultValue = false, QString defaultValue = QString());
static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool setDefaultValue = false, bool defaultValue = false);
static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, bool setDefaultValue = false, QUuid defaultValue = QUuid());
static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, bool setDefaultValue = false, QColor defaultValue = QColor());
static bool validXmlProperty(const QDomElement& e); static bool validXmlProperty(const QDomElement& e);

View File

@@ -45,42 +45,41 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x())); xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x()));
xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y())); xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y()));
xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid.toString())); xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid));
xml_element.appendChild(createXmlProperty(xml_document, "name", m_name)); xml_element.appendChild(createXmlProperty(xml_document, "name", m_name));
xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation))); xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation)));
return(xml_element); return(xml_element);
} }
bool TerminalData::fromXml (const QDomElement &xml_element) bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True
{ {
// lit la position de la borne // lit la position de la borne
qreal term_x = 0.0, term_y = 0.0; qreal term_x = 0.0, term_y = 0.0;
if (!propertyDouble(xml_element, "x", &term_x)) if (propertyDouble(xml_element, "x", &term_x))
return false; return false;
if (!propertyDouble(xml_element, "y", &term_y)) if (propertyDouble(xml_element, "y", &term_y))
return false; return false;
m_pos = QPointF(term_x, term_y); m_pos = QPointF(term_x, term_y);
//emit posFromXML(QPointF(term_x, term_y)); //emit posFromXML(QPointF(term_x, term_y));
QString uuid; QUuid uuid;
if (!propertyString(xml_element, "uuid", &uuid))
return false;
// update part and add uuid, which is used in the new version to connect terminals together // update part and add uuid, which is used in the new version to connect terminals together
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach // if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
// to identify terminals // to identify terminals
if (!uuid.isEmpty()) if (propertyUuid(xml_element, "uuid", &uuid) == PropertyFlags::Success)
m_uuid = QUuid(uuid); m_uuid = QUuid(uuid);
if (!propertyString(xml_element, "name", &m_name))
return false; //if (propertyString(xml_element, "name", &m_name))
// return false;
propertyString(xml_element, "name", &m_name); // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
QString o; QString o;
if (!propertyString(xml_element, "orientation", &o)) if (propertyString(xml_element, "orientation", &o))
return false; return false;
// lit l'orientation de la borne // lit l'orientation de la borne
@@ -89,18 +88,19 @@ bool TerminalData::fromXml (const QDomElement &xml_element)
return true; return true;
} }
bool TerminalData::valideXml(QDomElement& xml_element) { bool TerminalData::valideXml(const QDomElement& xml_element) {
if (propertyDouble(xml_element, "x")) if (propertyDouble(xml_element, "x"))
return false; return false;
if (propertyDouble(xml_element, "y")) if (propertyDouble(xml_element, "y"))
return false; return false;
if (propertyString(xml_element, "uuid")) // legacy elements do not have an uuid
return false; // if (propertyUuid(xml_element, "uuid"))
// return false;
if (propertyString(xml_element, "name")) //if (propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
return false; // return false;
if (propertyString(xml_element, "orientation")) if (propertyString(xml_element, "orientation"))
return false; return false;

View File

@@ -35,7 +35,7 @@ public:
QDomElement toXml(QDomDocument &xml_element) const override; QDomElement toXml(QDomDocument &xml_element) const override;
bool fromXml(const QDomElement &xml_element) override; bool fromXml(const QDomElement &xml_element) override;
static bool valideXml(QDomElement &xml_element); static bool valideXml(const QDomElement &xml_element);
// must be public, because this class is a private member of PartTerminal/Terminal and they must // must be public, because this class is a private member of PartTerminal/Terminal and they must
// access this data // access this data
@@ -44,12 +44,12 @@ public:
* \brief m_orientation * \brief m_orientation
* Orientation of the terminal * Orientation of the terminal
*/ */
Qet::Orientation m_orientation; Qet::Orientation m_orientation{Qet::Orientation::North};
/*! /*!
* \brief second_point * \brief second_point
* Position of the second point of the terminal in scene coordinates * Position of the second point of the terminal in scene coordinates
*/ */
QPointF second_point; QPointF second_point{0,0};
/*! /*!
* \brief m_uuid * \brief m_uuid
* Uuid of the terminal. * Uuid of the terminal.
@@ -60,7 +60,7 @@ public:
* uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists, * uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists,
* use this one and don't create a new one. * use this one and don't create a new one.
*/ */
QUuid m_uuid; QUuid m_uuid; // default is an invalid uuid.
/*! /*!
* \brief m_name * \brief m_name
* Name of the element. It can be used to create wiring harness tables * Name of the element. It can be used to create wiring harness tables
@@ -73,7 +73,7 @@ public:
* Important: this variable is only updated during read from xml and not during mouse move! * Important: this variable is only updated during read from xml and not during mouse move!
* It is used to store the initial position so that PartTerminal and Terminal have access to it. * It is used to store the initial position so that PartTerminal and Terminal have access to it.
*/ */
QPointF m_pos; QPointF m_pos{0,0};
private: private:
QGraphicsObject* q{nullptr}; QGraphicsObject* q{nullptr};
}; };

View File

@@ -116,14 +116,14 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
return xml_element; return xml_element;
} }
/** /** RETURNS True
* @brief XRefProperties::fromXml * @brief XRefProperties::fromXml
* Load from xml * Load from xml
* @param xml_element: QDomElement to use for load * @param xml_element: QDomElement to use for load
*/ */
bool XRefProperties::fromXml(const QDomElement &xml_element) { bool XRefProperties::fromXml(const QDomElement &xml_element) {
if (!propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
return false; return false;
QString display; QString display;

View File

@@ -76,14 +76,7 @@ class ConductorXmlRetroCompatibility
*/ */
Conductor::Conductor(Terminal *p1, Terminal* p2) : Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal1(p1), terminal1(p1),
terminal2(p2), terminal2(p2)
m_mouse_over(false),
m_text_item(nullptr),
segments(nullptr),
m_moving_segment(false),
modified_path(false),
has_to_save_profile(false),
must_highlight_(Conductor::None)
{ {
//set Zvalue at 11 to be upper than the DiagramImageItem and element //set Zvalue at 11 to be upper than the DiagramImageItem and element
setZValue(11); setZValue(11);
@@ -574,13 +567,13 @@ ConductorTextItem *Conductor::textItem() const {
*/ */
bool Conductor::valideXml(QDomElement &e){ bool Conductor::valideXml(QDomElement &e){
// TODO: seems to short! (see fromXML) // // TODO: seems to short! (see fromXML)
if (propertyDouble(e, "x") || // if (propertyDouble(e, "x") ||
propertyDouble(e, "y")) // propertyDouble(e, "y"))
return false; // return false;
if (propertyBool(e, "freezeLabel")) // if (propertyBool(e, "freezeLabel"))
return false; // return false;
return true; return true;
} }
@@ -956,8 +949,11 @@ void Conductor::pointsToSegments(const QList<QPointF>& points_list) {
bool Conductor::fromXml(const QDomElement &dom_element) bool Conductor::fromXml(const QDomElement &dom_element)
{ {
// TODO: seems to short! // TODO: seems to short!
setPos(dom_element.attribute("x", nullptr).toDouble(), double x, y;
dom_element.attribute("y", nullptr).toDouble()); propertyDouble(dom_element, "x", &x);
propertyDouble(dom_element, "y", &y);
setPos(x, y);
bool return_ = pathFromXml(dom_element); bool return_ = pathFromXml(dom_element);
@@ -971,8 +967,7 @@ bool Conductor::fromXml(const QDomElement &dom_element)
else else
m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers")); m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers"));
m_freeze_label = dom_element.attribute("freezeLabel") == "true"? true : false; propertyBool(dom_element, "freezeLabel", &m_freeze_label, false);
setProperties(pr); setProperties(pr);
return return_; return return_;

View File

@@ -156,28 +156,28 @@ class Conductor : public QGraphicsObject, public PropertiesInterface
QVector<QetGraphicsHandlerItem *> m_handler_vector; QVector<QetGraphicsHandlerItem *> m_handler_vector;
int m_vector_index = -1; int m_vector_index = -1;
bool m_mouse_over; bool m_mouse_over{false};
/// Functional properties /// Functional properties
ConductorProperties m_properties; ConductorProperties m_properties;
/// Text input for non simple, non-singleline conductors /// Text input for non simple, non-singleline conductors
ConductorTextItem *m_text_item; ConductorTextItem *m_text_item{nullptr};
/// Segments composing the conductor /// Segments composing the conductor
ConductorSegment *segments; ConductorSegment *segments{nullptr};
/// Attributs related to mouse interaction /// Attributs related to mouse interaction
bool m_moving_segment; bool m_moving_segment{false};
int moved_point; int moved_point;
qreal m_previous_z_value; qreal m_previous_z_value;
ConductorSegment *m_moved_segment; ConductorSegment *m_moved_segment;
QPointF before_mov_text_pos_; QPointF before_mov_text_pos_;
/// Whether the conductor was manually modified by users /// Whether the conductor was manually modified by users
bool modified_path; bool modified_path{false};
/// Whether the current profile should be saved as soon as possible /// Whether the current profile should be saved as soon as possible
bool has_to_save_profile; bool has_to_save_profile{false};
/// conductor profile: "photography" of what the conductor is supposed to look /// conductor profile: "photography" of what the conductor is supposed to look
/// like - there is one profile per kind of traject /// like - there is one profile per kind of traject
ConductorProfilesGroup conductor_profiles; ConductorProfilesGroup conductor_profiles;
/// Define whether and how the conductor should be highlighted /// Define whether and how the conductor should be highlighted
Highlight must_highlight_; Highlight must_highlight_{Conductor::None};
bool m_valid; bool m_valid;
bool m_freeze_label = false; bool m_freeze_label = false;

View File

@@ -150,7 +150,7 @@ class DynamicElementTextItem : public DiagramTextItem
QMetaObject::Connection m_report_formula_con; QMetaObject::Connection m_report_formula_con;
QList<QMetaObject::Connection> m_formula_connection, QList<QMetaObject::Connection> m_formula_connection,
m_update_slave_Xref_connection; m_update_slave_Xref_connection;
QColor m_user_color; QColor m_user_color{QColor()};
bool m_frame = false, bool m_frame = false,
m_first_scene_change = true; m_first_scene_change = true;
CrossRefItem *m_Xref_item = nullptr; CrossRefItem *m_Xref_item = nullptr;

View File

@@ -65,6 +65,7 @@ class ElementXmlRetroCompatibility
/** /**
* @brief Element::Element * @brief Element::Element
* New element from xml
* @param location, location of this element * @param location, location of this element
* @param parent, parent graphics item * @param parent, parent graphics item
* @param state, state of the instanciation * @param state, state of the instanciation
@@ -83,6 +84,7 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s
} }
} }
int elmt_state; int elmt_state;
qDebug() << "\tCollection Path: " << location.collectionPath();
buildFromXml(location.xml(), &elmt_state); buildFromXml(location.xml(), &elmt_state);
if (state) { if (state) {
*state = elmt_state; *state = elmt_state;
@@ -439,11 +441,15 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (qde.isNull()) if (qde.isNull())
continue; continue;
qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName();
if (parseElement(qde)) { if (parseElement(qde)) {
qDebug() << "\t\t\tParsing Element success";
++ parsed_elements_count; ++ parsed_elements_count;
} }
else else
{ {
qDebug() << "\t\t\tParsing Element no success";
if (state) if (state)
*state = 7; *state = 7;
m_state = QET::GIOK; m_state = QET::GIOK;
@@ -467,13 +473,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
m_state = QET::GIOK; m_state = QET::GIOK;
return(false); return(false);
} }
else
{
if (state) if (state)
*state = 0; *state = 0;
m_state = QET::GIOK; m_state = QET::GIOK;
return(true); return(true);
}
} }
/** /**
@@ -570,11 +574,11 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
Terminal *Element::parseTerminal(const QDomElement &dom_element) Terminal *Element::parseTerminal(const QDomElement &dom_element)
{ {
TerminalData* data = new TerminalData(); if (!TerminalData::valideXml(dom_element))
if (!data->fromXml(dom_element)) {
delete data;
return nullptr; return nullptr;
}
TerminalData* data = new TerminalData();
data->fromXml(dom_element);
Terminal *new_terminal = new Terminal(data, this); Terminal *new_terminal = new Terminal(data, this);
m_terminals << new_terminal; m_terminals << new_terminal;
@@ -643,11 +647,14 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
QHash<int, Terminal *> priv_id_adr; QHash<int, Terminal *> priv_id_adr;
int terminals_non_trouvees = 0; int terminals_non_trouvees = 0;
foreach(QGraphicsItem *qgi, childItems()) { // The added childs from the collection now must match with the terminals from the diagram. Iterate through
// all Terminals in the collection and in the diagram to link them together
foreach(QGraphicsItem *qgi, childItems()) { // Where the Terminals are added as childs?
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) { if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
bool terminal_trouvee = false; bool terminal_trouvee = false;
foreach(QDomElement qde, liste_terminals) { foreach(QDomElement qde, liste_terminals) {
if (p -> fromXml(qde)) { if (p -> fromXml(qde)) {
qDebug() << "Matching Terminal found.";
priv_id_adr.insert(qde.attribute("id").toInt(), p); priv_id_adr.insert(qde.attribute("id").toInt(), p);
terminal_trouvee = true; terminal_trouvee = true;
// We used to break here, because we did not expect // We used to break here, because we did not expect
@@ -661,6 +668,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
if (terminals_non_trouvees > 0) if (terminals_non_trouvees > 0)
{ {
qDebug() << "element.cpp: Element::fromXML; Elements not found: " << terminals_non_trouvees;
m_state = QET::GIOK; m_state = QET::GIOK;
return(false); return(false);
} }

View File

@@ -384,6 +384,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
return dom_element; return dom_element;
} }
// TOOD: inherit from propertiesinterface
/** /**
* @brief ElementTextItemGroup::fromXml * @brief ElementTextItemGroup::fromXml
* Import data of this group from xml * Import data of this group from xml

View File

@@ -108,7 +108,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO:
m_hold_to_bottom_of_page = false, m_hold_to_bottom_of_page = false,
m_block_alignment_update = false, m_block_alignment_update = false,
m_frame = false; m_frame = false;
QPointF m_initial_position; QPointF m_initial_position{QPointF(0,0)};
int m_vertical_adjustment = 0; int m_vertical_adjustment = 0;
CrossRefItem *m_Xref_item = nullptr; CrossRefItem *m_Xref_item = nullptr;
Element *m_parent_element = nullptr; Element *m_parent_element = nullptr;

View File

@@ -49,6 +49,7 @@ IndependentTextItem::IndependentTextItem(const QString &text) :
IndependentTextItem::~IndependentTextItem() { IndependentTextItem::~IndependentTextItem() {
} }
// TODO: inherit from PropertiesInterface
/** /**
Permet de lire le texte a mettre dans le champ a partir d'un element XML. Permet de lire le texte a mettre dans le champ a partir d'un element XML.
Cette methode se base sur la position du champ pour assigner ou non la Cette methode se base sur la position du champ pour assigner ou non la

View File

@@ -25,10 +25,7 @@
* @param parent, Parent Item * @param parent, Parent Item
*/ */
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent): QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
QGraphicsObject(parent), QGraphicsObject(parent)
is_movable_(true),
m_first_move(true),
snap_to_grid_(true)
{} {}
QetGraphicsItem::~QetGraphicsItem() QetGraphicsItem::~QetGraphicsItem()

View File

@@ -53,10 +53,10 @@ class QetGraphicsItem : public QGraphicsObject
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected: protected:
bool is_movable_; bool is_movable_{true};
bool m_first_move; bool m_first_move{true};
bool snap_to_grid_; bool snap_to_grid_{true};
QPointF m_mouse_to_origin_movement; QPointF m_mouse_to_origin_movement{QPointF(0,0)};
QET::GraphicsItemState m_state = QET:: GIOK; QET::GraphicsItemState m_state = QET:: GIOK;
}; };

View File

@@ -830,6 +830,7 @@ void QetShapeItem::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraph
} }
} }
// TODO: inherit from Propertiesinterface!
/** /**
* @brief QetShapeItem::fromXml * @brief QetShapeItem::fromXml
* Build this item from the xml description * Build this item from the xml description

View File

@@ -42,8 +42,6 @@ const qreal Terminal::Z = 1000;
*/ */
void Terminal::init(QString number, QString name, bool hiddenName) { void Terminal::init(QString number, QString name, bool hiddenName) {
hovered_color_ = Terminal::neutralColor;
// calcul de la position du point d'amarrage a l'element // calcul de la position du point d'amarrage a l'element
dock_elmt_ = d->m_pos; dock_elmt_ = d->m_pos;
switch(d->m_orientation) { switch(d->m_orientation) {
@@ -62,11 +60,9 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
// QRectF null // QRectF null
br_ = new QRectF(); br_ = new QRectF();
previous_terminal_ = nullptr;
// divers // divers
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
hovered_ = false;
setToolTip(QObject::tr("Borne", "tooltip")); setToolTip(QObject::tr("Borne", "tooltip"));
setZValue(Z); setZValue(Z);
} }
@@ -753,7 +749,7 @@ bool Terminal::valideXml(QDomElement &terminal) {
return false; return false;
QString o; QString o;
if (!propertyString(terminal, "orientation", &o)) if (propertyString(terminal, "orientation", &o))
return false; return false;
Qet::Orientation terminal_or = orientationFromString(o); Qet::Orientation terminal_or = orientationFromString(o);
@@ -767,7 +763,7 @@ bool Terminal::valideXml(QDomElement &terminal) {
return true; return true;
} }
/** /** RETURNS True
@brief Terminal::fromXml @brief Terminal::fromXml
Permet de savoir si un element XML represente cette borne. Attention, Permet de savoir si un element XML represente cette borne. Attention,
l'element XML n'est pas verifie l'element XML n'est pas verifie
@@ -795,11 +791,12 @@ bool Terminal::fromXml(const QDomElement &terminal) {
if (propertyString(terminal, "orientation", &o)) if (propertyString(terminal, "orientation", &o))
return false; return false;
return ( if (!qFuzzyCompare(x, dock_elmt_.x()) ||
qFuzzyCompare(x, dock_elmt_.x()) && !qFuzzyCompare(y, dock_elmt_.y()) ||
qFuzzyCompare(y, dock_elmt_.y()) && orientationFromString(o) != d->m_orientation)
(orientationFromString(o) == d->m_orientation) return false;
);
return true;
} }
/** /**

View File

@@ -109,7 +109,8 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
static const qreal terminalSize; static const qreal terminalSize;
static const qreal Z; static const qreal Z;
// Various static colors used for hover effects // Various static colors used for hover effects.
// The assignement is in the cpp file
/// default color /// default color
static QColor neutralColor; static QColor neutralColor;
/// color for legal actions /// color for legal actions
@@ -140,11 +141,11 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
*/ */
QRectF *br_{nullptr}; QRectF *br_{nullptr};
/// Last terminal seen through an attached conductor /// Last terminal seen through an attached conductor
Terminal *previous_terminal_; Terminal *previous_terminal_{nullptr};
/// Whether the mouse pointer is hovering the terminal /// Whether the mouse pointer is hovering the terminal
bool hovered_; bool hovered_{false};
/// Color used for the hover effect /// Color used for the hover effect
QColor hovered_color_; QColor hovered_color_{Terminal::hovered_color_};
/// Number of Terminal /// Number of Terminal
QString number_terminal_; QString number_terminal_;
/// Name of Terminal /// Name of Terminal

View File

@@ -23,12 +23,7 @@
*/ */
HelperCell::HelperCell(QGraphicsItem *parent) : HelperCell::HelperCell(QGraphicsItem *parent) :
QGraphicsObject(parent), QGraphicsObject(parent),
QGraphicsLayoutItem(), QGraphicsLayoutItem()
background_color(Qt::white),
foreground_color(Qt::black),
label(),
orientation(Qt::Horizontal),
index(-1)
{ {
setGraphicsItem(this); setGraphicsItem(this);
setFlag(QGraphicsItem::ItemIsSelectable, false); setFlag(QGraphicsItem::ItemIsSelectable, false);

View File

@@ -37,11 +37,11 @@ class HelperCell : public QGraphicsObject, public QGraphicsLayoutItem {
// attributes // attributes
public: public:
QColor background_color; ///< Background color when rendering this cell QColor background_color{Qt::white}; ///< Background color when rendering this cell
QColor foreground_color; ///< Text color when rendering this cell QColor foreground_color{Qt::black}; ///< Text color when rendering this cell
QString label; ///< Label displayed in this cell QString label; ///< Label displayed in this cell
Qt::Orientation orientation; ///< Orientation of this cell Qt::Orientation orientation{Qt::Horizontal}; ///< Orientation of this cell
int index; ///< Index of this cell int index{-1}; ///< Index of this cell
// methods // methods
public: public:

View File

@@ -36,6 +36,7 @@ class SplittedHelperCell : public HelperCell {
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
// attributes // attributes
// colors are set in the constructor
QColor split_background_color; ///< Background color on the split side QColor split_background_color; ///< Background color on the split side
QColor split_foreground_color; ///< Text color on the split side QColor split_foreground_color; ///< Text color on the split side
QString split_label; ///< Text displayed on the split side QString split_label; ///< Text displayed on the split side

View File

@@ -23,11 +23,7 @@
Constructeur. Initialise un objet TitleBlockProperties avec tous les champs Constructeur. Initialise un objet TitleBlockProperties avec tous les champs
vides (date vide + useDate a UseDateValue). vides (date vide + useDate a UseDateValue).
*/ */
TitleBlockProperties::TitleBlockProperties() : TitleBlockProperties::TitleBlockProperties()
date(),
useDate(UseDateValue),
display_at(Qt::BottomEdge),
collection (QET::QetCollection::Common)
{ {
} }
@@ -87,7 +83,8 @@ QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const {
e.appendChild(createXmlProperty(xml_document, "folio", folio)); e.appendChild(createXmlProperty(xml_document, "folio", folio));
e.appendChild(createXmlProperty(xml_document, "auto_page_num", auto_page_num)); e.appendChild(createXmlProperty(xml_document, "auto_page_num", auto_page_num));
e.appendChild(createXmlProperty(xml_document, "date", exportDate())); e.appendChild(createXmlProperty(xml_document, "date", exportDate()));
e.appendChild(createXmlProperty(xml_document, "displayAt", display_at == Qt::BottomEdge? "bottom" : "right")); QString disp_at = display_at == Qt::BottomEdge? "bottom" : "right";
e.appendChild(createXmlProperty(xml_document, "displayAt", disp_at));
if (!template_name.isEmpty()) if (!template_name.isEmpty())
{ {
@@ -104,7 +101,7 @@ QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const {
return e; return e;
} }
/** /** RETURNS True
Importe le cartouche a partir des attributs XML de l'element e Importe le cartouche a partir des attributs XML de l'element e
@param e Element XML dont les attributs seront lus @param e Element XML dont les attributs seront lus
*/ */
@@ -141,6 +138,7 @@ bool TitleBlockProperties::fromXml(const QDomElement &e) {
foreach (QDomElement e, QET::findInDomElement(e, "properties")) { foreach (QDomElement e, QET::findInDomElement(e, "properties")) {
context.fromXml(e); context.fromXml(e);
} }
return true;
} }
/** /**

View File

@@ -63,11 +63,11 @@ class TitleBlockProperties: public PropertiesInterface {
QString version; ///< Version (displayed by the default template) QString version; ///< Version (displayed by the default template)
QString folio; ///< Folio information (displayed by the default template) QString folio; ///< Folio information (displayed by the default template)
QString auto_page_num; QString auto_page_num;
DateManagement useDate; ///< Wheter to use the date attribute DateManagement useDate{UseDateValue}; ///< Wheter to use the date attribute
QString template_name; ///< Name of the template used to render the title block - an empty string means "the default template provided by the application" QString template_name; ///< Name of the template used to render the title block - an empty string means "the default template provided by the application"
DiagramContext context; ///< Container for the additional, user-defined fields DiagramContext context; ///< Container for the additional, user-defined fields
Qt::Edge display_at; ///< Edge to display the titleblock Qt::Edge display_at{Qt::Edge::BottomEdge}; ///< Edge to display the titleblock
QET::QetCollection collection; ///<Specify the location of the title block QET::QetCollection collection{QET::QetCollection::Common}; ///<Specify the location of the title block
private: private:
QString exportDate() const; QString exportDate() const;