Conductor : minor change

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4203 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-09-15 08:20:39 +00:00
parent 15b8fff00d
commit 65862756cb
6 changed files with 219 additions and 406 deletions

View File

@@ -26,7 +26,6 @@
@param an project (QETProject) of QET file @param an project (QETProject) of QET file
*/ */
nomenclature::nomenclature(QETProject *project, QWidget *parent): nomenclature::nomenclature(QETProject *project, QWidget *parent):
QObject(),
m_project(project) m_project(project)
{ {
m_parent = parent; m_parent = parent;
@@ -44,20 +43,21 @@ nomenclature::~nomenclature() {
Save to csv file Save to csv file
@param true if success @param true if success
*/ */
bool nomenclature::saveToCSVFile() { bool nomenclature::saveToCSVFile()
{
// SAVE IN FILE // SAVE IN FILE
QString name = tr("nomenclature_") + QString(m_project -> title()); QString name = QObject::tr("nomenclature_") + QString(m_project -> title());
if (!name.endsWith(".csv")) { if (!name.endsWith(".csv")) {
name += ".csv"; name += ".csv";
} }
QString filename = QFileDialog::getSaveFileName(this->m_parent, tr("Enregister sous... "), name, tr("Fichiers csv (*.csv)")); QString filename = QFileDialog::getSaveFileName(this->m_parent, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)"));
QFile file(filename); QFile file(filename);
if( !filename.isEmpty() ) { if( !filename.isEmpty() ) {
if(QFile::exists ( filename )){ if(QFile::exists ( filename )){
// if file already exist -> delete it // if file already exist -> delete it
if(!QFile::remove ( filename ) ){ if(!QFile::remove ( filename ) ){
QMessageBox::critical(this->m_parent, tr("Erreur"), QMessageBox::critical(this->m_parent, QObject::tr("Erreur"),
tr("Impossible de remplacer le fichier!\n\n")+ QObject::tr("Impossible de remplacer le fichier!\n\n")+
"Destination: "+filename+"\n"); "Destination: "+filename+"\n");
return false; return false;
} }
@@ -78,23 +78,22 @@ bool nomenclature::saveToCSVFile() {
* Create and formated a nomenclature to csv file. * Create and formated a nomenclature to csv file.
* @return The QString of nomenclature * @return The QString of nomenclature
*/ */
QString nomenclature::getNomenclature() { QString nomenclature::getNomenclature()
{
//Process... //Process...
QString data = tr("NOMENCLATURE : ") + m_project -> title() + "\n\n"; QString data = QObject::tr("NOMENCLATURE : ") + m_project -> title() + "\n\n";
data += tr("N° de folio") +";" data += QObject::tr("N° de folio") +";"
""+ tr("Titre de folio") +";" ""+ QObject::tr("Titre de folio") +";"
""+ tr("Désignation qet") +";" ""+ QObject::tr("Désignation qet") +";"
""+ tr("Position") +";" ""+ QObject::tr("Position") +";"
""+ tr("Label") +";" ""+ QObject::tr("Label") +";"
""+ tr("Désignation") +";" ""+ QObject::tr("Désignation") +";"
""+ tr("Commentaire") +";" ""+ QObject::tr("Commentaire") +";"
""+ tr("Fabricant") +";" ""+ QObject::tr("Fabricant") +";"
""+ tr("Reference") +";" ""+ QObject::tr("Reference") +";"
""+ tr("Bloc auxilliaire 1") +";" ""+ QObject::tr("Machine-reference") +";"
""+ tr("Bloc auxilliaire 2") +";" ""+ QObject::tr("Localisation") +";"
""+ tr("Machine-reference") +";" ""+ QObject::tr("Fonction") +"\n";
""+ tr("Localisation") +";"
""+ tr("Fonction") +"\n";
if(m_list_diagram.isEmpty()) return data; if(m_list_diagram.isEmpty()) return data;
@@ -134,8 +133,6 @@ QString nomenclature::getElementInfo(const Element *elmt) {
info += elmt_info["comment"].toString() + ";"; info += elmt_info["comment"].toString() + ";";
info += elmt_info["manufacturer"].toString() + ";"; info += elmt_info["manufacturer"].toString() + ";";
info += elmt_info["manufacturer-reference"].toString() + ";"; info += elmt_info["manufacturer-reference"].toString() + ";";
info += elmt_info["Auxiliary_1-contact-bloc"].toString() + ";";
info += elmt_info["Auxiliary_2-contact-bloc"].toString() + ";";
info += elmt_info["machine-manufacturer-reference"].toString() + ";"; info += elmt_info["machine-manufacturer-reference"].toString() + ";";
info += elmt_info["location"].toString() + ";"; info += elmt_info["location"].toString() + ";";
info += elmt_info["function"].toString() + "\n"; info += elmt_info["function"].toString() + "\n";

View File

@@ -30,15 +30,12 @@
class QETProject; class QETProject;
class Diagram; class Diagram;
class Element; class Element;
class DiagramContent;
class CustomeElement;
/** /**
This class represents a nomenclature... This class represents a nomenclature...
*/ */
class nomenclature : public QObject { class nomenclature
Q_OBJECT {
private: private:
QETProject *m_project; QETProject *m_project;
QList<Diagram *> m_list_diagram; QList<Diagram *> m_list_diagram;

View File

@@ -34,7 +34,6 @@
bool Conductor::pen_and_brush_initialized = false; bool Conductor::pen_and_brush_initialized = false;
QPen Conductor::conductor_pen = QPen(); QPen Conductor::conductor_pen = QPen();
QBrush Conductor::conductor_brush = QBrush(); QBrush Conductor::conductor_brush = QBrush();
QBrush Conductor::square_brush = QBrush(Qt::darkGreen);
/** /**
* @brief Conductor::Conductor * @brief Conductor::Conductor
@@ -48,14 +47,12 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal1(p1), terminal1(p1),
terminal2(p2), terminal2(p2),
bMouseOver(false), bMouseOver(false),
destroyed_(false), m_handler(10),
text_item(0), text_item(0),
segments(NULL), segments(NULL),
moving_point(false),
moving_segment(false), moving_segment(false),
modified_path(false), modified_path(false),
has_to_save_profile(false), has_to_save_profile(false),
segments_squares_scale_(1.0),
must_highlight_(Conductor::None) must_highlight_(Conductor::None)
{ {
//Set the default conductor properties. //Set the default conductor properties.
@@ -106,15 +103,13 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
} }
/** /**
Destructeur * @brief Conductor::~Conductor
Detruit le conducteur ainsi que ses segments. Il ne detruit pas les bornes * Destructor. The conductor is removed from is terminal
mais s'en detache */
*/ Conductor::~Conductor()
Conductor::~Conductor() { {
// se detache des bornes terminal1->removeConductor(this);
if (!isDestroyed()) destroy(); terminal2->removeConductor(this);
// supprime les segments
deleteSegments(); deleteSegments();
} }
@@ -437,7 +432,8 @@ QPointF Conductor::extendTerminal(const QPointF &terminal, Qet::Orientation term
@param options Les options de style pour le conducteur @param options Les options de style pour le conducteur
@param qw Le QWidget sur lequel on dessine @param qw Le QWidget sur lequel on dessine
*/ */
void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWidget *qw) { void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWidget *qw)
{
Q_UNUSED(qw); Q_UNUSED(qw);
qp -> save(); qp -> save();
qp -> setRenderHint(QPainter::Antialiasing, false); qp -> setRenderHint(QPainter::Antialiasing, false);
@@ -458,9 +454,8 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
} }
} }
// if mouse over conductor change size //Draw the conductor bigger when is hovered
if ( bMouseOver ) conductor_pen.setWidthF(3.0); conductor_pen.setWidth(bMouseOver? 5 : 1);
else conductor_pen.setWidthF(1.0);
// affectation du QPen et de la QBrush modifies au QPainter // affectation du QPen et de la QBrush modifies au QPainter
qp -> setBrush(conductor_brush); qp -> setBrush(conductor_brush);
@@ -490,31 +485,9 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
if (isSelected()) qp -> setBrush(Qt::NoBrush); if (isSelected()) qp -> setBrush(Qt::NoBrush);
} }
// decalage ideal pour le rendu centre d'un carre / cercle de 2.0 px de cote / diametre //Draw the squares used to modify the path of conductor when he is selected
qreal pretty_offset = 1.0; if (isSelected())
m_handler.drawHandler(qp, handlerPoints());
// dessin des points d'accroche du conducteur si celui-ci est selectionne
if (isSelected()) {
QList<QPointF> points = segmentsToPoints();
QPointF previous_point;
for (int i = 1 ; i < (points.size() -1) ; ++ i) {
QPointF point = points.at(i);
// dessine le carre de saisie du segment
if (i > 1) {
qp -> fillRect(
QRectF(
((previous_point.x() + point.x()) / 2.0 ) - pretty_offset * segments_squares_scale_,
((previous_point.y() + point.y()) / 2.0 ) - pretty_offset * segments_squares_scale_,
2.0 * segments_squares_scale_,
2.0 * segments_squares_scale_
),
square_brush
);
}
previous_point = point;
}
}
// dessine les eventuelles jonctions // dessine les eventuelles jonctions
QList<QPointF> junctions_list = junctions(); QList<QPointF> junctions_list = junctions();
@@ -525,21 +498,12 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
qp -> setBrush(junction_brush); qp -> setBrush(junction_brush);
qp -> setRenderHint(QPainter::Antialiasing, true); qp -> setRenderHint(QPainter::Antialiasing, true);
foreach(QPointF point, junctions_list) { foreach(QPointF point, junctions_list) {
qp -> drawEllipse(QRectF(point.x() - pretty_offset, point.y() - pretty_offset, 2.0, 2.0)); qp -> drawEllipse(QRectF(point.x() - 1, point.y() - 1, 2.0, 2.0));
} }
} }
qp -> restore(); qp -> restore();
} }
/**
Methode de preparation a la destruction du conducteur ; le conducteur se detache de ses deux bornes
*/
void Conductor::destroy() {
destroyed_ = true;
terminal1 -> removeConductor(this);
terminal2 -> removeConductor(this);
}
/// @return le Diagram auquel ce conducteur appartient, ou 0 si ce conducteur est independant /// @return le Diagram auquel ce conducteur appartient, ou 0 si ce conducteur est independant
Diagram *Conductor::diagram() const { Diagram *Conductor::diagram() const {
return(qobject_cast<Diagram *>(scene())); return(qobject_cast<Diagram *>(scene()));
@@ -578,143 +542,107 @@ bool Conductor::valideXml(QDomElement &e){
/** /**
* @brief Conductor::mouseDoubleClickEvent * @brief Conductor::mouseDoubleClickEvent
* Action at double click on this item * Manage the mouse double click
* @param e * @param event
*/ */
void Conductor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { void Conductor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
e->accept(); event->accept();
editProperty(); editProperty();
} }
/** /**
Gere les clics sur le conducteur. * @brief Conductor::mousePressEvent
@param e L'evenement decrivant le clic. * Manage the mouse press event
*/ * @param event
void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *e) {
// clic gauche
if (e -> buttons() & Qt::LeftButton) {
// recupere les coordonnees du clic
press_point = e -> pos();
/*
parcourt les segments pour determiner si le clic a eu lieu
- sur l'extremite d'un segment
- sur le milieu d'un segment
- ailleurs
*/ */
ConductorSegment *segment = segments; void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *event)
while (segment -> hasNextSegment()) { {
if (hasClickedOn(press_point, segment -> secondPoint())) { //Left clic
moving_point = true; if (event->buttons() & Qt::LeftButton)
moving_segment = false; {
moved_segment = segment; //If user click on a handler (square used to modify the path of conductor),
break; //we get the segment corresponding to the handler
} else if (hasClickedOn(press_point, segment -> middle())) { int index = m_handler.pointIsHoverHandler(event->pos(), handlerPoints());
moving_point = false; if (index > -1)
{
moving_segment = true; moving_segment = true;
moved_segment = segment; moved_segment = segmentsList().at(index+1);
break;
}
segment = segment -> nextSegment();
}
if (moving_segment || moving_point) {
// en cas de debut de modification de conducteur, on memorise la position du champ de texte
before_mov_text_pos_ = text_item -> pos(); before_mov_text_pos_ = text_item -> pos();
} }
} }
QGraphicsPathItem::mousePressEvent(e);
if (e -> modifiers() & Qt::ControlModifier) { QGraphicsPathItem::mousePressEvent(event);
if (event -> modifiers() & Qt::ControlModifier)
setSelected(!isSelected()); setSelected(!isSelected());
}
} }
/** /**
Gere les deplacements de souris sur le conducteur. * @brief Conductor::mouseMoveEvent
@param e L'evenement decrivant le deplacement de souris. * Manage the mouse move event
*/ * @param event
void Conductor::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
// clic gauche
if (e -> buttons() & Qt::LeftButton) {
// position pointee par la souris
qreal mouse_x = e -> pos().x();
qreal mouse_y = e -> pos().y();
bool snap_conductors_to_grid = e -> modifiers() ^ Qt::ShiftModifier;
if (snap_conductors_to_grid) {
mouse_x = qRound(mouse_x / (Diagram::xGrid * 1.0)) * Diagram::xGrid;
mouse_y = qRound(mouse_y / (Diagram::yGrid * 1.0)) * Diagram::yGrid;
}
if (moving_point) {
// la modification par points revient bientot
/*
// position precedente du point
QPointF p = moved_segment -> secondPoint();
qreal p_x = p.x();
qreal p_y = p.y();
// calcul du deplacement
moved_segment -> moveX(mouse_x - p_x());
moved_segment -> moveY(mouse_y - p_y());
// application du deplacement
modified_path = true;
updatePoints();
segmentsToPath();
*/ */
} else if (moving_segment) { void Conductor::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
// position precedente du point {
//Left clic
if ((event->buttons() & Qt::LeftButton) && moving_segment)
{
//Snap the mouse pos to grid
QPointF pos_ = Diagram::snapToGrid(event->pos());
//Position of the last point
QPointF p = moved_segment -> middle(); QPointF p = moved_segment -> middle();
// calcul du deplacement //Calcul the movement
moved_segment -> moveX(mouse_x - p.x()); moved_segment -> moveX(pos_.x() - p.x());
moved_segment -> moveY(mouse_y - p.y()); moved_segment -> moveY(pos_.y() - p.y());
// application du deplacement //Apply the movement
modified_path = true; modified_path = true;
has_to_save_profile = true; has_to_save_profile = true;
segmentsToPath(); segmentsToPath();
calculateTextItemPosition(); calculateTextItemPosition();
} }
}
QGraphicsPathItem::mouseMoveEvent(e); QGraphicsPathItem::mouseMoveEvent(event);
} }
/** /**
Gere les relachements de boutons de souris sur le conducteur * @brief Conductor::mouseReleaseEvent
@param e L'evenement decrivant le lacher de bouton. * Manage the mouse release event
*/ * @param event
void Conductor::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { */
// clic gauche void Conductor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
moving_point = false; {
moving_segment = false; moving_segment = false;
if (has_to_save_profile) { if (has_to_save_profile)
{
saveProfile(); saveProfile();
has_to_save_profile = false; has_to_save_profile = false;
} }
if (!(e -> modifiers() & Qt::ControlModifier)) {
QGraphicsPathItem::mouseReleaseEvent(e); if (!(event -> modifiers() & Qt::ControlModifier))
} QGraphicsPathItem::mouseReleaseEvent(event);
} }
/** /**
Gere l'entree de la souris dans la zone du conducteur * @brief Conductor::hoverEnterEvent
@param e Le QGraphicsSceneHoverEvent decrivant l'evenement * Manage the hover enter event
*/ * @param event
void Conductor::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { */
Q_UNUSED(e); void Conductor::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
segments_squares_scale_ = 2.0; Q_UNUSED(event);
bMouseOver = true; bMouseOver = true;
update(); update();
} }
/** /**
Gere la sortie de la souris de la zone du conducteur * @brief Conductor::hoverLeaveEvent
@param e Le QGraphicsSceneHoverEvent decrivant l'evenement * Manage the mouse leave event
*/ * @param event
void Conductor::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { */
Q_UNUSED(e); void Conductor::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
segments_squares_scale_ = 1.0; Q_UNUSED(event);
update(); update();
bMouseOver = false; bMouseOver = false;
} }
@@ -723,26 +651,26 @@ void Conductor::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
* @brief Conductor::hoverMoveEvent conductor * @brief Conductor::hoverMoveEvent conductor
* @param e QGraphicsSceneHoverEvent describing the event * @param e QGraphicsSceneHoverEvent describing the event
*/ */
void Conductor::hoverMoveEvent(QGraphicsSceneHoverEvent *e) { void Conductor::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
if (isSelected()) { if (isSelected())
QPointF hover_point = mapFromScene(e -> pos()) + scenePos(); {
ConductorSegment *segment = segments; //If user hover an handler (square used to modify the path of conductor),
bool cursor_set = false; //we get the segment corresponding to the handler
while (segment -> hasNextSegment()) { int index = m_handler.pointIsHoverHandler(event->pos(), handlerPoints());
if (hasClickedOn(hover_point, segment -> secondPoint())) { if (index > -1)
{
ConductorSegment *segment_ = segmentsList().at(index+1);
if (m_handler.pointIsInHandler(event->pos(), segment_->secondPoint()))
setCursor(Qt::ForbiddenCursor); setCursor(Qt::ForbiddenCursor);
cursor_set = true; else if (m_handler.pointIsInHandler(event->pos(), segment_->middle()))
} else if (hasClickedOn(hover_point, segment -> middle())) { setCursor(segmentsList().at(index+1)->isVertical() ? Qt::SplitHCursor : Qt::SplitVCursor);
setCursor(segment -> isVertical() ? Qt::SplitHCursor : Qt::SplitVCursor);
cursor_set = true;
} }
segment = segment -> nextSegment(); else
} setCursor(Qt::ArrowCursor);
if (!cursor_set) setCursor(Qt::ArrowCursor);
} }
QGraphicsPathItem::hoverMoveEvent(e); QGraphicsPathItem::hoverMoveEvent(event);
} }
/** /**
@@ -773,122 +701,45 @@ QVariant Conductor::itemChange(GraphicsItemChange change, const QVariant &value)
} }
/** /**
@return Le rectangle delimitant l'espace de dessin du conducteur * @brief Conductor::boundingRect
*/ * @return
QRectF Conductor::boundingRect() const { */
QRectF retour = QGraphicsPathItem::boundingRect(); QRectF Conductor::boundingRect() const
retour.adjust(-11.0, -11.0, 11.0, 11.0); {
return(retour); QRectF br = shape().boundingRect();
return br.adjusted(-10, -10, 10, 10);
} }
/** /**
@return La forme / zone "cliquable" du conducteur (epaisseur : 5.0px). * @brief Conductor::shape
@see variableShape() * @return the shape of conductor.
*/ * The shape thickness is bigger when conductor is hovered
QPainterPath Conductor::shape() const { */
return(variableShape(5.0)); QPainterPath Conductor::shape() const
{
QPainterPathStroker pps;
pps.setWidth(bMouseOver? 5 : 1);
pps.setJoinStyle(conductor_pen.joinStyle());
QPainterPath shape_(pps.createStroke(path()));
if (isSelected())
foreach (QRectF rect, m_handler.handlerRect(handlerPoints()))
shape_.addRect(rect);
return shape_;
} }
/** /**
@return la distance en dessous de laquelle on considere qu'un point est a * @brief Conductor::nearShape
proximite du trajet du conducteur. La valeur est actuellement fixee a * @return : An area in which it is considered a point is near this conductor.
60.0px. */
*/ QPainterPath Conductor::nearShape() const
qreal Conductor::nearDistance() const { {
return(60.0); QPainterPathStroker pps;
} pps.setWidth(120);
pps.setJoinStyle(conductor_pen.joinStyle());
/** return pps.createStroke(path());
@return la zone dans laquelle dont on considere que tous les points sont a
proximite du trajet du conducteur.
@see nearDistance()
@see variableShape()
*/
QPainterPath Conductor::nearShape() const {
return(variableShape(nearDistance()));
}
/**
@return la forme du conducteur
@param thickness la moitie de l'epaisseur voulue pour cette forme
*/
QPainterPath Conductor::variableShape(const qreal &thickness) const {
qreal my_thickness = qAbs(thickness);
QList<QPointF> points = segmentsToPoints();
QPainterPath area;
QPointF previous_point;
QPointF *point1, *point2;
foreach(QPointF point, points) {
if (!previous_point.isNull()) {
if (point.x() == previous_point.x()) {
if (point.y() <= previous_point.y()) {
point1 = &point;
point2 = &previous_point;
} else {
point1 = &previous_point;
point2 = &point;
}
} else {
if (point.x() <= previous_point.x()) {
point1 = &point;
point2 = &previous_point;
} else {
point1 = &previous_point;
point2 = &point;
}
}
qreal p1_x = point1 -> x();
qreal p1_y = point1 -> y();
qreal p2_x = point2 -> x();
qreal p2_y = point2 -> y();
area.setFillRule(Qt::OddEvenFill);
area.addRect(p1_x - my_thickness, p1_y - my_thickness, my_thickness * 2.0 + p2_x - p1_x, my_thickness * 2.0 + p2_y - p1_y);
}
previous_point = point;
area.setFillRule(Qt::WindingFill);
area.addRect(point.x() - my_thickness, point.y() - my_thickness, my_thickness * 2.0, my_thickness * 2.0 );
}
return(area);
}
/**
@param point un point, exprime dans les coordonnees du conducteur
@return true si le point est a proximite du conducteur, c-a-d a moins de
60px du conducteur.
*/
bool Conductor::isNearConductor(const QPointF &point) {
return(variableShape(60.1).contains(point));
}
/**
Renvoie une valeur donnee apres l'avoir bornee entre deux autres valeurs,
en y ajoutant une marge interne.
@param tobound valeur a borner
@param bound1 borne 1
@param bound2 borne 2
@param space marge interne ajoutee
@return La valeur bornee
*/
qreal Conductor::conductor_bound(qreal tobound, qreal bound1, qreal bound2, qreal space) {
qDebug() << "will bound" << tobound << "between" << bound1 << "and" << bound2 ;
if (bound1 < bound2) {
return(qBound(bound1 + space, tobound, bound2 - space));
} else {
return(qBound(bound2 + space, tobound, bound1 - space));
}
}
/**
Renvoie une valeur donnee apres l'avoir bornee avant ou apres une valeur.
@param tobound valeur a borner
@param bound borne
@param positive true pour borner la valeur avant la borne, false sinon
@return La valeur bornee
*/
qreal Conductor::conductor_bound(qreal tobound, qreal bound, bool positive) {
qreal space = 5.0;
return(positive ? qMax(tobound, bound + space) : qMin(tobound, bound - space));
} }
/** /**
@@ -949,22 +800,6 @@ void Conductor::pointsToSegments(QList<QPointF> points_list) {
} }
} }
/**
Permet de savoir si un point est tres proche d'un autre. Cela sert surtout
pour determiner si un clic a ete effectue pres d'un point donne.
@param press_point Point effectivement clique
@param point point cliquable
@return true si l'on peut considerer que le point a ete clique, false sinon
*/
bool Conductor::hasClickedOn(QPointF press_point, QPointF point) const {
return (
press_point.x() >= point.x() - 5.0 &&\
press_point.x() < point.x() + 5.0 &&\
press_point.y() >= point.y() - 5.0 &&\
press_point.y() < point.y() + 5.0
);
}
/** /**
* @brief Conductor::fromXml * @brief Conductor::fromXml
* Load the conductor and her information from xml element * Load the conductor and her information from xml element
@@ -978,8 +813,9 @@ bool Conductor::fromXml(QDomElement &e) {
bool return_ = pathFromXml(e); bool return_ = pathFromXml(e);
text_item -> fromXml(e); text_item -> fromXml(e);
properties_. fromXml(e); ConductorProperties pr;
readProperties(); pr.fromXml(e);
setProperties(pr);
return return_; return return_;
} }
@@ -1096,6 +932,30 @@ bool Conductor::pathFromXml(const QDomElement &e) {
return(true); return(true);
} }
/**
* @brief Conductor::handlerPoints
* @return The points used to draw the handler square, used to modify
* the path of the conductor.
* The points stored in the QVector are the middle point of each segments that compose the conductor,
* at exception of the first and last segment because there just here to extend the terminal.
*/
QVector<QPointF> Conductor::handlerPoints() const
{
QList <ConductorSegment *> sl = segmentsList();
if (sl.size() >= 3)
{
sl.removeFirst();
sl.removeLast();
}
QVector <QPointF> middle_points;
foreach(ConductorSegment *segment, sl)
middle_points.append(segment->middle());
return middle_points;
}
/// @return les segments de ce conducteur /// @return les segments de ce conducteur
const QList<ConductorSegment *> Conductor::segmentsList() const { const QList<ConductorSegment *> Conductor::segmentsList() const {
if (segments == NULL) return(QList<ConductorSegment *>()); if (segments == NULL) return(QList<ConductorSegment *>());
@@ -1365,7 +1225,15 @@ void Conductor::setProperties(const ConductorProperties &properties)
other_conductor->setProperties(other_properties); other_conductor->setProperties(other_properties);
} }
readProperties(); setText(properties_.text);
text_item -> setFontSize(properties_.text_size);
if (properties_.type != ConductorProperties::Multi)
text_item -> setVisible(false);
else
text_item -> setVisible(properties_.m_show_text);
calculateTextItemPosition();
update();
emit propertiesChange(); emit propertiesChange();
} }
@@ -1377,22 +1245,6 @@ ConductorProperties Conductor::properties() const {
return(properties_); return(properties_);
} }
/**
* @brief Conductor::readProperties
* Read and apply properties
*/
void Conductor::readProperties() {
setText(properties_.text);
text_item -> setFontSize(properties_.text_size);
if (properties_.type != ConductorProperties::Multi) {
text_item -> setVisible(false);
} else {
text_item -> setVisible(properties_.m_show_text);
}
calculateTextItemPosition();
update();
}
/** /**
@return true si le conducteur est mis en evidence @return true si le conducteur est mis en evidence
*/ */
@@ -1644,21 +1496,6 @@ QList<ConductorBend> Conductor::bends() const {
return(points); return(points);
} }
/**
@param p Point, en coordonnees locales
@return true si le point p appartient au trajet du conducteur
*/
bool Conductor::containsPoint(const QPointF &p) const {
if (!segments) return(false);
ConductorSegment *segment = segments;
while (segment -> hasNextSegment()) {
QRectF rect(segment -> firstPoint(), segment -> secondPoint());
if (rect.contains(p)) return(true);
segment = segment -> nextSegment();
}
return(false);
}
/** /**
@param start Point de depart @param start Point de depart
@param end Point d'arrivee @param end Point d'arrivee

View File

@@ -20,6 +20,7 @@
#include "conductorproperties.h" #include "conductorproperties.h"
#include <QGraphicsPathItem> #include <QGraphicsPathItem>
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
class ConductorProfile; class ConductorProfile;
class ConductorSegmentProfile; class ConductorSegmentProfile;
@@ -74,9 +75,6 @@ class Conductor : public QObject, public QGraphicsPathItem
@return the QGraphicsItem type @return the QGraphicsItem type
*/ */
virtual int type() const { return Type; } virtual int type() const { return Type; }
void destroy();
/// @return true if this conductor is destroyed
bool isDestroyed() const { return(destroyed_); }
Diagram *diagram() const; Diagram *diagram() const;
ConductorTextItem *textItem() const; ConductorTextItem *textItem() const;
void updatePath(const QRectF & = QRectF()); void updatePath(const QRectF & = QRectF());
@@ -89,14 +87,10 @@ class Conductor : public QObject, public QGraphicsPathItem
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
QRectF boundingRect() const; QRectF boundingRect() const;
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
virtual qreal nearDistance() const;
virtual QPainterPath nearShape() const; virtual QPainterPath nearShape() const;
virtual QPainterPath variableShape(const qreal &) const;
virtual bool isNearConductor(const QPointF &);
qreal length() const; qreal length() const;
ConductorSegment *middleSegment(); ConductorSegment *middleSegment();
QPointF posForText(Qt::Orientations &flag); QPointF posForText(Qt::Orientations &flag);
bool containsPoint(const QPointF &) const;
QString text() const; QString text() const;
void setText(const QString &); void setText(const QString &);
@@ -108,6 +102,7 @@ class Conductor : public QObject, public QGraphicsPathItem
bool pathFromXml(const QDomElement &); bool pathFromXml(const QDomElement &);
public: public:
QVector <QPointF> handlerPoints() const;
const QList<ConductorSegment *> segmentsList() const; const QList<ConductorSegment *> segmentsList() const;
void setProperties(const ConductorProperties &properties); void setProperties(const ConductorProperties &properties);
ConductorProperties properties() const; ConductorProperties properties() const;
@@ -115,7 +110,6 @@ class Conductor : public QObject, public QGraphicsPathItem
ConductorProfile profile(Qt::Corner) const; ConductorProfile profile(Qt::Corner) const;
void setProfiles(const ConductorProfilesGroup &); void setProfiles(const ConductorProfilesGroup &);
ConductorProfilesGroup profiles() const; ConductorProfilesGroup profiles() const;
void readProperties();
void calculateTextItemPosition(); void calculateTextItemPosition();
virtual Highlight highlight() const; virtual Highlight highlight() const;
virtual void setHighlighted(Highlight); virtual void setHighlighted(Highlight);
@@ -127,29 +121,26 @@ class Conductor : public QObject, public QGraphicsPathItem
void displayedTextChanged(); void displayedTextChanged();
protected: protected:
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual QVariant itemChange(GraphicsItemChange, const QVariant &); virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
bool bMouseOver; bool bMouseOver;
private: private:
QetGraphicsHandlerUtility m_handler;
/// Functional properties /// Functional properties
ConductorProperties properties_; ConductorProperties properties_;
/// Whether this conductor is still valid
bool destroyed_;
/// Text input for non simple, non-singleline conductors /// Text input for non simple, non-singleline conductors
ConductorTextItem *text_item; ConductorTextItem *text_item;
/// Segments composing the conductor /// Segments composing the conductor
ConductorSegment *segments; ConductorSegment *segments;
/// Attributs related to mouse interaction /// Attributs related to mouse interaction
QPointF press_point;
bool moving_point;
bool moving_segment; bool moving_segment;
int moved_point; int moved_point;
qreal previous_z_value; qreal previous_z_value;
@@ -165,10 +156,7 @@ class Conductor : public QObject, public QGraphicsPathItem
/// QPen et QBrush objects used to draw conductors /// QPen et QBrush objects used to draw conductors
static QPen conductor_pen; static QPen conductor_pen;
static QBrush conductor_brush; static QBrush conductor_brush;
static QBrush square_brush;
static bool pen_and_brush_initialized; static bool pen_and_brush_initialized;
/// Scale factor to render square used to move segments
qreal segments_squares_scale_;
/// Define whether and how the conductor should be highlighted /// Define whether and how the conductor should be highlighted
Highlight must_highlight_; Highlight must_highlight_;
bool m_valid; bool m_valid;
@@ -183,15 +171,12 @@ class Conductor : public QObject, public QGraphicsPathItem
QList<ConductorBend> bends() const; QList<ConductorBend> bends() const;
QList<QPointF> junctions() const; QList<QPointF> junctions() const;
void pointsToSegments(QList<QPointF>); void pointsToSegments(QList<QPointF>);
bool hasClickedOn(QPointF, QPointF) const;
Qt::Corner currentPathType() const; Qt::Corner currentPathType() const;
void deleteSegments(); void deleteSegments();
static int getCoeff(const qreal &, const qreal &); static int getCoeff(const qreal &, const qreal &);
static int getSign(const qreal &); static int getSign(const qreal &);
QHash<ConductorSegmentProfile *, qreal> shareOffsetBetweenSegments(const qreal &offset, const QList<ConductorSegmentProfile *> &, const qreal & = 0.01) const; QHash<ConductorSegmentProfile *, qreal> shareOffsetBetweenSegments(const qreal &offset, const QList<ConductorSegmentProfile *> &, const qreal & = 0.01) const;
static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0); static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0);
static qreal conductor_bound(qreal, qreal, qreal, qreal = 0.0);
static qreal conductor_bound(qreal, qreal, bool);
static Qt::Corner movementType(const QPointF &, const QPointF &); static Qt::Corner movementType(const QPointF &, const QPointF &);
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &); static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
}; };

View File

@@ -161,7 +161,7 @@ void ConductorTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
QPointF intended_pos = event ->scenePos() + m_mouse_to_origin_movement; QPointF intended_pos = event ->scenePos() + m_mouse_to_origin_movement;
if (parent_conductor_) { if (parent_conductor_) {
if (parent_conductor_ -> isNearConductor(intended_pos)) { if (parent_conductor_->nearShape().contains(intended_pos)) {
event->modifiers() == Qt::ControlModifier ? setPos(intended_pos) : setPos(Diagram::snapToGrid(intended_pos)); event->modifiers() == Qt::ControlModifier ? setPos(intended_pos) : setPos(Diagram::snapToGrid(intended_pos));
parent_conductor_ -> setHighlighted(Conductor::Normal); parent_conductor_ -> setHighlighted(Conductor::Normal);
} else { } else {

View File

@@ -637,15 +637,12 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
} }
/** /**
Met a jour l'eventuel conducteur relie a la borne. * @brief Terminal::updateConductor
@param newpos Position de l'element parent a prendre en compte * Update the path of conductor docked to this terminal
*/ */
void Terminal::updateConductor() { void Terminal::updateConductor() {
if (!scene() || !parentItem()) return; foreach (Conductor *conductor, conductors_)
foreach (Conductor *conductor, conductors_) { conductor->updatePath();
if (conductor -> isDestroyed()) continue;
conductor -> updatePath();
}
} }
/** /**