[qet] [3183] Xref item: item position can be set under the texte field "label" of master element. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3183
Author: blacksun
Date: 2014-06-27 20:34:18 +0200 (Fri, 27 Jun 2014)
Log Message:
-----------
Xref item: item position can be set under the texte field "label" of master element.
Double clic in xref open the properties dialog of master.
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/properties/xrefproperties.cpp
trunk/sources/properties/xrefproperties.h
trunk/sources/qetgraphicsitem/crossrefitem.cpp
trunk/sources/qetgraphicsitem/crossrefitem.h
trunk/sources/qetgraphicsitem/customelement.cpp
trunk/sources/qetgraphicsitem/customelement.h
trunk/sources/qetgraphicsitem/element.h
trunk/sources/qetgraphicsitem/masterelement.cpp
trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
trunk/sources/ui/xrefpropertieswidget.cpp
trunk/sources/ui/xrefpropertieswidget.ui
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/diagram.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -33,7 +33,6 @@
#include "qetapp.h"
#include "qetgraphicsitem/diagramimageitem.h"
#include "qetgraphicsitem/qetshapeitem.h"
-#include "qetgraphicsitem/crossrefitem.h"
const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10;
@@ -101,8 +100,6 @@
foreach(QGraphicsItem *qgi, items()) {
if (qgi -> parentItem()) continue;
if (qgraphicsitem_cast<Conductor *>(qgi)) continue;
- else if (qgraphicsitem_cast<CrossRefItem *>(qgi)) continue;
-
deletable_items << qgi;
}
Modified: trunk/sources/properties/xrefproperties.cpp
===================================================================
--- trunk/sources/properties/xrefproperties.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/properties/xrefproperties.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -22,8 +22,7 @@
* Default Constructor
*/
XRefProperties::XRefProperties()
-{
-}
+{}
/**
* @brief XRefProperties::toSettings
@@ -35,6 +34,8 @@
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
QString display = m_display == Cross? "cross" : "contacts";
settings.setValue(prefix + "displayhas", display);
+ QString snap = m_snap_to == Bottom? "bottom" : "label";
+ settings.setValue(prefix + "snapto", snap);
settings.setValue(prefix + "powerprefix", m_prefix.value("power"));
settings.setValue(prefix + "delayprefix", m_prefix.value("delay"));
}
@@ -49,6 +50,8 @@
m_show_power_ctc = settings.value(prefix + "showpowerctc", false).toBool();
QString display = settings.value(prefix + "displayhas", "cross").toString();
display == "cross"? m_display = Cross : m_display = Contacts;
+ QString snap = settings.value(prefix + "snapto", "label").toString();
+ snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
m_prefix.insert("power", settings.value(prefix + "powerprefix").toString());
m_prefix.insert("delay", settings.value(prefix + "delayprefix").toString());
}
@@ -62,6 +65,8 @@
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "fasle");
QString display = m_display == Cross? "cross" : "contacts";
xml_element.setAttribute("displayhas", display);
+ QString snap = m_snap_to == Bottom? "bottom" : "label";
+ xml_element.setAttribute("snapto", snap);
xml_element.setAttribute("powerprefix", m_prefix.value("power"));
xml_element.setAttribute("delayprefix", m_prefix.value("delay"));
}
@@ -75,6 +80,8 @@
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
QString display = xml_element.attribute("displayhas", "cross");
display == "cross"? m_display = Cross : m_display = Contacts;
+ QString snap = xml_element.attribute("snapto", "label");
+ snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
m_prefix.insert("power", xml_element.attribute("powerprefix"));
m_prefix.insert("delay", xml_element.attribute("delayprefix"));
}
@@ -82,6 +89,7 @@
bool XRefProperties::operator ==(const XRefProperties &xrp) const{
return (m_show_power_ctc == xrp.m_show_power_ctc &&
m_display == xrp.m_display &&
+ m_snap_to == xrp.m_snap_to &&
m_prefix == xrp.m_prefix);
}
Modified: trunk/sources/properties/xrefproperties.h
===================================================================
--- trunk/sources/properties/xrefproperties.h 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/properties/xrefproperties.h 2014-06-27 18:34:18 UTC (rev 3183)
@@ -34,6 +34,11 @@
Contacts
};
+ enum SnapTo {
+ Bottom,
+ Label
+ };
+
virtual void toSettings (QSettings &settings, const QString = QString()) const;
virtual void fromSettings (const QSettings &settings, const QString = QString());
virtual void toXml (QDomElement &xml_element) const;
@@ -45,15 +50,19 @@
void setShowPowerContac (const bool a) {m_show_power_ctc = a;}
bool showPowerContact () const {return m_show_power_ctc;}
- void setDisplayHas (const DisplayHas dh) {m_display = dh;}
- DisplayHas displayHas () const {return m_display;}
+ void setDisplayHas (const DisplayHas dh) {m_display = dh;}
+ DisplayHas displayHas () const {return m_display;}
+ void setSnapTo (const SnapTo st) {m_snap_to = st;}
+ SnapTo snapTo () const {return m_snap_to;}
+
void setPrefix (const QString &key, const QString &value) {m_prefix.insert(key, value);}
QString prefix (const QString &key) const {return m_prefix.value(key);}
private:
bool m_show_power_ctc;
DisplayHas m_display;
+ SnapTo m_snap_to;
QHash <QString, QString> m_prefix;
};
Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -19,6 +19,7 @@
#include "element.h"
#include "qetapp.h"
#include "diagramposition.h"
+#include "elementtextitem.h"
//define the height of the header.
#define header 5
@@ -28,19 +29,24 @@
/**
* @brief CrossRefItem::CrossRefItem
* Default constructor
- * @param elmt element to dispaly the cross ref
- * @param parent parent QetGraphicsItem
+ * @param elmt element to display the cross ref and also parent item.
*/
-CrossRefItem::CrossRefItem(Element *elmt, QGraphicsItem *parent) :
- QGraphicsObject(parent),
+CrossRefItem::CrossRefItem(Element *elmt) :
+ QGraphicsObject(elmt),
m_element (elmt)
{
m_properties = elmt->diagram()->defaultXRefProperties();
- setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
- connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos()));
connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
connect(elmt->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
connect(elmt->diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(setProperties(XRefProperties)));
+
+ //set specific behavior related to the parent item.
+ if(m_properties.snapTo() == XRefProperties::Bottom) {
+ connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos()));
+ connect(elmt, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
+ } else {
+ setTextParent();
+ }
updateLabel();
}
@@ -49,7 +55,10 @@
* Default destructor
*/
CrossRefItem::~CrossRefItem() {
- disconnect(m_element, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos()));
+ if(m_properties.snapTo() == XRefProperties::Bottom) {
+ disconnect(m_element, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos()));
+ disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
+ }
disconnect(m_element, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
disconnect(m_element->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
disconnect(m_element->diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(setProperties(XRefProperties)));
@@ -112,6 +121,17 @@
void CrossRefItem::setProperties(const XRefProperties &xrp) {
if (m_properties != xrp) {
+ if (m_properties.snapTo() != xrp.snapTo()) {
+ if (xrp.snapTo() == XRefProperties::Bottom) {
+ setParentItem(m_element);
+ connect(m_element, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos()));
+ connect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
+ } else {
+ setTextParent();
+ disconnect(m_element, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos()));
+ disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
+ }
+ }
m_properties = xrp;
updateLabel();
}
@@ -153,24 +173,28 @@
* Calculate and set position automaticaly.
*/
void CrossRefItem::autoPos() {
- if (isSelected() && m_element->isSelected()) return;
- QRectF border= m_element->diagram()->border();
- QPointF point;
+ //We calcul the position according to the @snapTo of the xrefproperties
+ if (m_properties.snapTo() == XRefProperties::Bottom) {
+ QRectF border = m_element->diagram()->border();
+ QPointF point = m_element->sceneBoundingRect().center();
- //if this item have parent calcule the position by using mapped point.
- if(parentItem()) {
- point = m_element->boundingRect().center();
- QPointF ypoint_ = mapToParent(mapFromScene(0, border.height() - m_element->diagram()->border_and_titleblock.titleBlockHeight() - boundingRect().height()));
- point.setY(ypoint_.y());
+ point.setY(border.height() - m_element->diagram()->border_and_titleblock.titleBlockHeight() - boundingRect().height());
+ point.rx() -= (m_bounding_rect.width()/2 + m_bounding_rect.left()); //< we add boundingrect.left because this value can be négative
+
+ setPos(0,0); //Due to a weird behavior or bug, before set the new position and rotation,
+ setRotation(0); //we must to set the position and rotation at 0.
+ setPos(mapFromScene(point));
+ if (rotation() != - m_element->rotation()) {
+ setRotation(0);
+ setRotation(- m_element->rotation());
+ }
}
else {
- point = m_element->sceneBoundingRect().center();
- point.setY(border.height() - m_element->diagram()->border_and_titleblock.titleBlockHeight() - boundingRect().height());
+ QPointF p = parentItem()->boundingRect().center();
+ p.ry() += parentItem()->boundingRect().height()/2;
+ p.rx() -= (m_bounding_rect.width()/2 + m_bounding_rect.left()); //< we add boundingrect.left because this value can be négative
+ setPos(p);
}
-
- qreal offset = m_bounding_rect.topLeft().x() < 0 ? m_bounding_rect.topLeft().x() : 0;
- point.setX(point.x() - m_bounding_rect.width()/2 - offset);
- setPos(point);
}
/**
@@ -183,42 +207,19 @@
void CrossRefItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(option);
Q_UNUSED(widget);
-
- //draw the selection rect
- if (isSelected()) {
- painter->save();
- QPen t(Qt::black);
- t.setStyle(Qt::DashLine);
- t.setCosmetic(true);
- painter -> setPen(t);
- painter -> setRenderHint(QPainter::Antialiasing, false);
- painter -> drawPath(m_shape_path);
- painter -> restore();
- }
m_drawing.play(painter);
}
/**
- * @brief CrossRefItem::mouseMoveEvent
- * handle mouse move event
- * @param e event
+ * @brief CrossRefItem::mouseDoubleClickEvent
+ * @param event
*/
-void CrossRefItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
- m_element->setHighlighted(true);
- QGraphicsObject::mouseMoveEvent(e);
+void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+ event->accept();
+ m_element->editProperty();
}
/**
- * @brief CrossRefItem::mouseReleaseEvent
- * handle mouse release event
- * @param e event
- */
-void CrossRefItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
- m_element->setHighlighted(false);
- QGraphicsObject::mouseReleaseEvent(e);
-}
-
-/**
* @brief CrossRefItem::buildHeaderContact
* Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc
*/
@@ -526,3 +527,14 @@
}
}
+/**
+ * @brief CrossRefItem::setTextParent
+ * Set the text field tagged "label" of m_element
+ * parent of this item
+ */
+void CrossRefItem::setTextParent() {
+ ElementTextItem *eti = m_element->taggedText("label");
+ if (eti) setParentItem(eti);
+ else qDebug() << "CrossRefItem,no texte tagged 'label' found to set has parent";
+}
+
Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h 2014-06-27 18:34:18 UTC (rev 3183)
@@ -27,8 +27,11 @@
* This clas provide an item, for show the cross reference, like the contacts linked to a coil.
* The item setpos automaticaly when parent move.
* All slave displayed in cross ref will be updated when folio position change in the project.
- * It's the responsability of the parent to informe displayed slave are moved,
+ * It's the responsability of the master element to informe displayed slave are moved,
* by calling the slot @updateLabel
+ * By default master element is the parent graphics item of this Xref,
+ * but if the Xref must be snap to the label of master, the label become the parent of this Xref.
+ * This behavior can be changed at anytime by calling setProperties.
*/
class CrossRefItem : public QGraphicsObject
{
@@ -36,7 +39,7 @@
//Methods
public:
- explicit CrossRefItem(Element *elmt, QGraphicsItem *parent = 0);
+ explicit CrossRefItem(Element *elmt);
~CrossRefItem();
enum { Type = UserType + 1009 };
@@ -63,9 +66,8 @@
void autoPos ();
protected:
- virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
- virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *e);
- virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *e);
+ virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
private:
void buildHeaderContact ();
@@ -76,6 +78,7 @@
void fillCrossRef (QPainter &painter);
void AddExtraInfo (QPainter &painter);
void checkMustShow ();
+ void setTextParent ();
//Attributes
private:
Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/customelement.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -910,18 +910,28 @@
/**
* @brief CustomElement::setTaggedText
* Set text @newstr to the text tagged with @tagg.
- * If tagg is found return the text item, else return 0.
+ * If tagg is found return the text item, else return NULL.
* @param tagg required tagg
* @param newstr new label
* @param noeditable set editable or not (by default, set editable)
*/
ElementTextItem* CustomElement::setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable) {
+ ElementTextItem *eti = taggedText(tagg);
+ if (eti) {
+ eti -> setPlainText(newstr);
+ eti -> setNoEditable(noeditable);
+ }
+ return eti;
+}
+
+/**
+ * @brief CustomElement::taggedText
+ * return the text field tagged with @tagg or NULL if text field isn't found
+ * @param tagg
+ */
+ElementTextItem* CustomElement::taggedText(const QString &tagg) const {
foreach (ElementTextItem *eti, list_texts_) {
- if (eti -> tagg() == tagg) {
- eti -> setPlainText(newstr);
- eti -> setNoEditable(noeditable);
- return eti;
- }
+ if (eti -> tagg() == tagg) return eti;
}
- return 0;
+ return NULL;
}
Modified: trunk/sources/qetgraphicsitem/customelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.h 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/customelement.h 2014-06-27 18:34:18 UTC (rev 3183)
@@ -74,6 +74,7 @@
bool isNull() const;
int state() const;
QString name() const;
+ ElementTextItem* taggedText(const QString &tagg) const;
protected:
virtual bool buildFromXml(const QDomElement &, int * = 0);
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/element.h 2014-06-27 18:34:18 UTC (rev 3183)
@@ -74,6 +74,8 @@
virtual QList<Conductor *> conductors() const = 0;
/// @return the list of text items attached to this element
virtual QList<ElementTextItem *> texts() const = 0;
+ /// @return the text field tagged with @tagg or NULL if text field isn't found
+ virtual ElementTextItem* taggedText(const QString &tagg) const = 0;
/// @return the list of lines items in this element
virtual QList<QLineF *> lines() const = 0;
/// @return the list of rectangles items in this element
Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -54,10 +54,7 @@
connected_elements << elmt;
elmt->linkToElement(this);
- if (!cri_) {
- cri_ = new CrossRefItem(this); //create cross ref item if not yet
- diagram()->addItem(cri_);
- }
+ if (!cri_) cri_ = new CrossRefItem(this); //create cross ref item if not yet
connect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
cri_->updateLabel();
}
@@ -91,7 +88,6 @@
disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
if (linkedElements().isEmpty()) {
- diagram()->removeItem(cri_);
delete cri_;
cri_ = nullptr;
}
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -48,11 +48,12 @@
* @param p the new position of item
*/
void QetGraphicsItem::setPos(const QPointF &p) {
- if (p == pos() || !is_movable_) return;
+ QPointF pp = Diagram::snapToGrid(p);
+ if (pp == pos() || !is_movable_) return;
if (scene() && snap_to_grid_) {
- QGraphicsItem::setPos(Diagram::snapToGrid(p));
+ QGraphicsItem::setPos(pp);
emit positionChange(pos());
- } else QGraphicsItem::setPos(p);
+ } else QGraphicsItem::setPos(pp);
}
/**
Modified: trunk/sources/ui/xrefpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/xrefpropertieswidget.cpp 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/ui/xrefpropertieswidget.cpp 2014-06-27 18:34:18 UTC (rev 3183)
@@ -31,6 +31,9 @@
m_properties(properties)
{
ui->setupUi(this);
+
+ ui->m_snap_to_cb->addItem(tr("En bas de page"), "bottom");
+ ui->m_snap_to_cb->addItem(tr("Sous le label de l'\351l\351ment"), "label");
connect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool)));
updateDisplay();
}
@@ -62,6 +65,9 @@
XRefProperties XRefPropertiesWidget::properties() {
if (ui->m_display_has_cross_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Cross);
else if (ui->m_display_has_contacts_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Contacts);
+ if (ui->m_snap_to_cb->itemData(ui->m_snap_to_cb->currentIndex()).toString() == "bottom")
+ m_properties.setSnapTo(XRefProperties::Bottom);
+ else m_properties.setSnapTo(XRefProperties::Label);
m_properties.setShowPowerContac(ui->m_show_power_cb->isChecked());
m_properties.setPrefix("power", ui->m_power_prefix_le->text());
m_properties.setPrefix("delay", ui->m_delay_prefix_le->text());
@@ -97,6 +103,9 @@
ui->m_display_has_contacts_rb->setChecked(true);
}
+ if (m_properties.snapTo() == XRefProperties::Bottom)
+ ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("bottom"));
+ else ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("label"));
ui->m_show_power_cb->setChecked(m_properties.showPowerContact());
ui->m_power_prefix_le->setText(m_properties.prefix("power"));
ui->m_delay_prefix_le->setText(m_properties.prefix("delay"));
Modified: trunk/sources/ui/xrefpropertieswidget.ui
===================================================================
--- trunk/sources/ui/xrefpropertieswidget.ui 2014-06-27 12:06:37 UTC (rev 3182)
+++ trunk/sources/ui/xrefpropertieswidget.ui 2014-06-27 18:34:18 UTC (rev 3183)
@@ -21,6 +21,20 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Positionner :</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="m_snap_to_cb"/>
+ </item>
+ </layout>
+ </item>
+ <item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="m_display_has_cross_rb">