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

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

View File

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

View File

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

View File

@@ -65,6 +65,7 @@ class ElementXmlRetroCompatibility
/**
* @brief Element::Element
* New element from xml
* @param location, location of this element
* @param parent, parent graphics item
* @param state, state of the instanciation
@@ -83,6 +84,7 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s
}
}
int elmt_state;
qDebug() << "\tCollection Path: " << location.collectionPath();
buildFromXml(location.xml(), &elmt_state);
if (state) {
*state = elmt_state;
@@ -438,12 +440,16 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
QDomElement qde = n.toElement();
if (qde.isNull())
continue;
qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName();
if (parseElement(qde)) {
qDebug() << "\t\t\tParsing Element success";
++ parsed_elements_count;
}
else
{
qDebug() << "\t\t\tParsing Element no success";
if (state)
*state = 7;
m_state = QET::GIOK;
@@ -467,13 +473,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
m_state = QET::GIOK;
return(false);
}
else
{
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
/**
@@ -570,11 +574,11 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
Terminal *Element::parseTerminal(const QDomElement &dom_element)
{
TerminalData* data = new TerminalData();
if (!data->fromXml(dom_element)) {
delete data;
if (!TerminalData::valideXml(dom_element))
return nullptr;
}
TerminalData* data = new TerminalData();
data->fromXml(dom_element);
Terminal *new_terminal = new Terminal(data, this);
m_terminals << new_terminal;
@@ -643,17 +647,20 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
QHash<int, Terminal *> priv_id_adr;
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)) {
bool terminal_trouvee = false;
foreach(QDomElement qde, liste_terminals) {
if (p -> fromXml(qde)) {
qDebug() << "Matching Terminal found.";
priv_id_adr.insert(qde.attribute("id").toInt(), p);
terminal_trouvee = true;
// We used to break here, because we did not expect
// several terminals to share the same position.
// Of course, it finally happened.
}
}
}
if (!terminal_trouvee) ++ terminals_non_trouvees;
}
@@ -661,6 +668,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
if (terminals_non_trouvees > 0)
{
qDebug() << "element.cpp: Element::fromXML; Elements not found: " << terminals_non_trouvees;
m_state = QET::GIOK;
return(false);
}

View File

@@ -384,6 +384,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
return dom_element;
}
// TOOD: inherit from propertiesinterface
/**
* @brief ElementTextItemGroup::fromXml
* 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_block_alignment_update = false,
m_frame = false;
QPointF m_initial_position;
QPointF m_initial_position{QPointF(0,0)};
int m_vertical_adjustment = 0;
CrossRefItem *m_Xref_item = nullptr;
Element *m_parent_element = nullptr;

View File

@@ -49,6 +49,7 @@ IndependentTextItem::IndependentTextItem(const QString &text) :
IndependentTextItem::~IndependentTextItem() {
}
// TODO: inherit from PropertiesInterface
/**
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

View File

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

View File

@@ -53,10 +53,10 @@ class QetGraphicsItem : public QGraphicsObject
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected:
bool is_movable_;
bool m_first_move;
bool snap_to_grid_;
QPointF m_mouse_to_origin_movement;
bool is_movable_{true};
bool m_first_move{true};
bool snap_to_grid_{true};
QPointF m_mouse_to_origin_movement{QPointF(0,0)};
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
* Build this item from the xml description

View File

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

View File

@@ -109,9 +109,10 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
static const qreal terminalSize;
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
static QColor neutralColor;
static QColor neutralColor;
/// color for legal actions
static QColor allowedColor;
/// color for allowed but fuzzy or not recommended actions
@@ -140,11 +141,11 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
*/
QRectF *br_{nullptr};
/// Last terminal seen through an attached conductor
Terminal *previous_terminal_;
Terminal *previous_terminal_{nullptr};
/// Whether the mouse pointer is hovering the terminal
bool hovered_;
bool hovered_{false};
/// Color used for the hover effect
QColor hovered_color_;
QColor hovered_color_{Terminal::hovered_color_};
/// Number of Terminal
QString number_terminal_;
/// Name of Terminal