mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Display Location Field in Diagram and assign Folio Variables to Element's Information Fields
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4546 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -97,6 +97,10 @@ class BorderTitleBlock : public QObject
|
|||||||
QString folio() const { return(btb_folio_); }
|
QString folio() const { return(btb_folio_); }
|
||||||
/// @return the value of the title block "File" field
|
/// @return the value of the title block "File" field
|
||||||
QString fileName() const { return(btb_filename_); }
|
QString fileName() const { return(btb_filename_); }
|
||||||
|
/// @return the value of the title block Additional Fields
|
||||||
|
DiagramContext additionalFields() const { return (additional_fields_); }
|
||||||
|
/// @return the value of the title block
|
||||||
|
QString autoPageNum() const { return(btb_auto_page_num_); }
|
||||||
|
|
||||||
// methods to get display options
|
// methods to get display options
|
||||||
/// @return true si le cartouche est affiche, false sinon
|
/// @return true si le cartouche est affiche, false sinon
|
||||||
@@ -108,8 +112,6 @@ class BorderTitleBlock : public QObject
|
|||||||
/// @return true si la bordure est affichee, false sinon
|
/// @return true si la bordure est affichee, false sinon
|
||||||
bool borderIsDisplayed() const { return(display_border_); }
|
bool borderIsDisplayed() const { return(display_border_); }
|
||||||
|
|
||||||
QString autoPageNum() const { return(btb_auto_page_num_); }
|
|
||||||
|
|
||||||
// methods to set dimensions
|
// methods to set dimensions
|
||||||
void setColumnsCount(int);
|
void setColumnsCount(int);
|
||||||
void setRowsCount(int);
|
void setRowsCount(int);
|
||||||
|
|||||||
@@ -183,9 +183,10 @@ void PasteDiagramCommand::redo()
|
|||||||
if (e->texts().size())
|
if (e->texts().size())
|
||||||
e->texts().first()->setPlainText("/");
|
e->texts().first()->setPlainText("/");
|
||||||
} else {
|
} else {
|
||||||
//Reset the information about the label and the comment
|
//Reset the information about the label, the comment and location
|
||||||
e -> rElementInformations().addValue("label", "");
|
e -> rElementInformations().addValue("label", "");
|
||||||
e -> rElementInformations().addValue("comment", "");
|
e -> rElementInformations().addValue("comment", "");
|
||||||
|
e -> rElementInformations().addValue("location", "");
|
||||||
|
|
||||||
//Reset the text field tagged "label
|
//Reset the text field tagged "label
|
||||||
if (ElementTextItem *eti = e ->taggedText("label"))
|
if (ElementTextItem *eti = e ->taggedText("label"))
|
||||||
|
|||||||
@@ -107,31 +107,78 @@ bool CommentItem::setTextParent() {
|
|||||||
*/
|
*/
|
||||||
void CommentItem::updateLabel()
|
void CommentItem::updateLabel()
|
||||||
{
|
{
|
||||||
QString comment = m_element -> elementInformations()["comment"].toString();
|
QString comment = m_element -> elementInformations()["comment"]. toString();
|
||||||
|
|
||||||
if (comment == m_comment && !m_text_parent) return;
|
QString location = m_element -> elementInformations()["location"].toString();
|
||||||
|
|
||||||
|
QPainterPath m_shape_path_ = QPainterPath();
|
||||||
|
prepareGeometryChange();
|
||||||
|
m_bounding_rect = QRectF();
|
||||||
|
|
||||||
|
QPainter painter_;
|
||||||
|
painter_.begin(&m_picture);
|
||||||
|
|
||||||
|
if (comment == m_comment && !m_text_parent && location == m_location)
|
||||||
|
return;
|
||||||
|
|
||||||
if (comment != m_comment)
|
if (comment != m_comment)
|
||||||
{
|
{
|
||||||
m_comment = comment;
|
m_comment = comment;
|
||||||
|
addInfo(painter_, "comment");
|
||||||
|
}
|
||||||
|
else if (comment == m_comment)
|
||||||
|
addInfo(painter_, "comment");
|
||||||
|
|
||||||
|
if (location != m_location)
|
||||||
|
{
|
||||||
|
m_location = location;
|
||||||
|
addInfo(painter_, "location");
|
||||||
|
}
|
||||||
|
else if (location == m_location){
|
||||||
|
addInfo(painter_, "location");
|
||||||
|
}
|
||||||
|
painter_.end();
|
||||||
|
|
||||||
|
autoPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CommentItem::addInfo
|
||||||
|
* @param painter
|
||||||
|
* @param type e.g. comment, location
|
||||||
|
* Draw Info to item text.
|
||||||
|
* (draw this item in a QPicture)
|
||||||
|
*/
|
||||||
|
void CommentItem::addInfo(QPainter &painter, QString type){
|
||||||
|
|
||||||
|
QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element);
|
||||||
|
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
||||||
|
|
||||||
|
if (!text.isEmpty() && must_show)
|
||||||
|
{
|
||||||
|
painter.save();
|
||||||
|
painter.setFont (QETApp::diagramTextsFont(6));
|
||||||
|
|
||||||
QPen pen(Qt::black);
|
QPen pen(Qt::black);
|
||||||
pen.setWidthF (0.5);
|
pen.setWidthF (0.5);
|
||||||
|
|
||||||
QPainter painter(&m_picture);
|
|
||||||
painter.setPen (pen);
|
painter.setPen (pen);
|
||||||
painter.setFont (QETApp::diagramTextsFont(6));
|
|
||||||
|
|
||||||
QRectF text_bounding = painter.boundingRect(QRectF(QPointF(0,0), QSizeF(70, 1)), Qt::TextWordWrap | Qt::AlignHCenter, m_comment);
|
QRectF r, text_bounding;
|
||||||
|
qreal center = boundingRect().center().x();
|
||||||
|
|
||||||
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, m_comment);
|
r = QRectF(QPointF(center - 35, boundingRect().bottom()),
|
||||||
|
QPointF(center + 35, boundingRect().bottom() + 1));
|
||||||
|
|
||||||
|
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, text);
|
||||||
|
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, text);
|
||||||
|
|
||||||
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
|
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
|
||||||
painter.drawRoundedRect(text_bounding, 2, 2);
|
|
||||||
|
|
||||||
|
m_shape_path.addRect(text_bounding);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_bounding_rect = text_bounding;
|
m_bounding_rect = m_bounding_rect.united(text_bounding);
|
||||||
|
if (type == "comment") painter.drawRoundedRect(text_bounding, 2, 2);
|
||||||
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
autoPos();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,11 +47,16 @@ class CommentItem : public QGraphicsObject
|
|||||||
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
|
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
|
||||||
virtual bool setTextParent ();
|
virtual bool setTextParent ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addInfo(QPainter &, QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Element *m_element;
|
Element *m_element;
|
||||||
QPicture m_picture;
|
QPicture m_picture;
|
||||||
QRectF m_bounding_rect;
|
QRectF m_bounding_rect;
|
||||||
QString m_comment;
|
QString m_comment;
|
||||||
|
QString m_location;
|
||||||
|
QPainterPath m_shape_path;
|
||||||
bool m_text_parent;
|
bool m_text_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,8 @@ void CrossRefItem::updateLabel() {
|
|||||||
drawHasContacts(qp);
|
drawHasContacts(qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddExtraInfo(qp);
|
AddExtraInfo(qp, "comment");
|
||||||
|
AddExtraInfo(qp, "location");
|
||||||
qp.end();
|
qp.end();
|
||||||
|
|
||||||
autoPos();
|
autoPos();
|
||||||
@@ -532,30 +533,33 @@ void CrossRefItem::fillCrossRef(QPainter &painter) {
|
|||||||
* @brief CrossRefItem::AddExtraInfo
|
* @brief CrossRefItem::AddExtraInfo
|
||||||
* Add the comment info of the parent item if needed.
|
* Add the comment info of the parent item if needed.
|
||||||
* @param painter painter to use for draw the text
|
* @param painter painter to use for draw the text
|
||||||
|
* @param type type of Info do be draw e.g. comment, location.
|
||||||
*/
|
*/
|
||||||
void CrossRefItem::AddExtraInfo(QPainter &painter)
|
void CrossRefItem::AddExtraInfo(QPainter &painter, QString type)
|
||||||
{
|
{
|
||||||
QString comment = m_element -> assignVariables(m_element -> elementInformations()["comment"].toString(), m_element);
|
QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element);
|
||||||
bool must_show = m_element -> elementInformations().keyMustShow("comment");
|
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
||||||
|
|
||||||
if (!comment.isEmpty() && must_show)
|
if (!text.isEmpty() && must_show)
|
||||||
{
|
{
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setFont(QETApp::diagramTextsFont(6));
|
painter.setFont(QETApp::diagramTextsFont(6));
|
||||||
|
|
||||||
QRectF r, text_bounding;
|
QRectF r, text_bounding;
|
||||||
qreal center = boundingRect().center().x();
|
qreal center = boundingRect().center().x();
|
||||||
|
|
||||||
r = QRectF(QPointF(center - 35, boundingRect().bottom()),
|
r = QRectF(QPointF(center - 35, boundingRect().bottom()),
|
||||||
QPointF(center + 35, boundingRect().bottom() + 1));
|
QPointF(center + 35, boundingRect().bottom() + 1));
|
||||||
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, comment);
|
|
||||||
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, comment);
|
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, text);
|
||||||
|
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, text);
|
||||||
|
|
||||||
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
|
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
|
||||||
|
|
||||||
m_shape_path.addRect(text_bounding);
|
m_shape_path.addRect(text_bounding);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_bounding_rect = m_bounding_rect.united(text_bounding);
|
m_bounding_rect = m_bounding_rect.united(text_bounding);
|
||||||
painter.drawRoundedRect(text_bounding, 2, 2);
|
if (type == "comment") painter.drawRoundedRect(text_bounding, 2, 2);
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class CrossRefItem : public QGraphicsObject
|
|||||||
void drawHasContacts (QPainter &painter);
|
void drawHasContacts (QPainter &painter);
|
||||||
void drawContact (QPainter &painter, int flags, QString str = QString());
|
void drawContact (QPainter &painter, int flags, QString str = QString());
|
||||||
void fillCrossRef (QPainter &painter);
|
void fillCrossRef (QPainter &painter);
|
||||||
void AddExtraInfo (QPainter &painter);
|
void AddExtraInfo (QPainter &painter, QString);
|
||||||
void setTextParent ();
|
void setTextParent ();
|
||||||
|
|
||||||
//Attributes
|
//Attributes
|
||||||
|
|||||||
@@ -643,6 +643,18 @@ void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
|
|||||||
* @param elmt, element to extract variables values
|
* @param elmt, element to extract variables values
|
||||||
*/
|
*/
|
||||||
QString Element::assignVariables(QString label, Element *elmt){
|
QString Element::assignVariables(QString label, Element *elmt){
|
||||||
|
|
||||||
|
for (int i = 0; i < elmt->diagram()->border_and_titleblock.additionalFields().count(); i++)
|
||||||
|
{
|
||||||
|
QString folio_variable = elmt->diagram()->border_and_titleblock.additionalFields().keys().at(i);
|
||||||
|
QVariant folio_value = elmt->diagram()->border_and_titleblock.additionalFields().operator [](folio_variable);
|
||||||
|
|
||||||
|
if (label.contains(folio_variable)) {
|
||||||
|
label.replace("%{" + folio_variable + "}", folio_value.toString());
|
||||||
|
label.replace("%" + folio_variable , folio_value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
label.replace("%f", QString::number(elmt->diagram()->folioIndex()+1));
|
label.replace("%f", QString::number(elmt->diagram()->folioIndex()+1));
|
||||||
label.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
|
label.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
|
||||||
label.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
|
label.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
|
||||||
|
|||||||
@@ -161,9 +161,12 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QString comment = elementInformations()["comment"].toString();
|
QString comment = elementInformations()["comment"].toString();
|
||||||
bool must_show = elementInformations().keyMustShow("comment");
|
bool must_show_comment = elementInformations().keyMustShow("comment");
|
||||||
|
|
||||||
if (! (comment.isEmpty() || !must_show)) {
|
QString location = elementInformations()["location"].toString();
|
||||||
|
bool must_show_location = elementInformations().keyMustShow("location");
|
||||||
|
|
||||||
|
if (! (comment.isEmpty() || !must_show_comment) || !(location.isEmpty() || !must_show_location)) {
|
||||||
cri_ = new CrossRefItem(this);
|
cri_ = new CrossRefItem(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
*/
|
*/
|
||||||
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
||||||
CustomElement(location, qgi, state),
|
CustomElement(location, qgi, state),
|
||||||
m_comment_item (nullptr)
|
m_comment_item (nullptr),
|
||||||
|
m_location_item (nullptr)
|
||||||
{
|
{
|
||||||
link_type_ = Simple;
|
link_type_ = Simple;
|
||||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||||
@@ -88,14 +89,16 @@ void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
|||||||
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Comment of element
|
//Comment and Location of element
|
||||||
QString comment = new_info["comment"].toString();
|
QString comment = new_info["comment"].toString();
|
||||||
bool must_show = new_info.keyMustShow("comment");
|
bool must_show = new_info.keyMustShow("comment");
|
||||||
|
QString location = new_info["location"].toString();
|
||||||
|
bool must_show_location = new_info.keyMustShow("location");
|
||||||
|
|
||||||
if (!(comment.isEmpty() || !must_show) && !m_comment_item) {
|
if ((!(comment.isEmpty() || !must_show) && !m_comment_item)||(!(location.isEmpty() || !must_show_location) && !m_comment_item)) {
|
||||||
m_comment_item = new CommentItem(this);
|
m_comment_item = new CommentItem(this);
|
||||||
}
|
}
|
||||||
else if ((comment.isEmpty() || !must_show) && m_comment_item) {
|
else if (((comment.isEmpty() || !must_show) && m_comment_item) && ((location.isEmpty() || !must_show_location) && m_comment_item)) {
|
||||||
delete m_comment_item;
|
delete m_comment_item;
|
||||||
m_comment_item = nullptr;
|
m_comment_item = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class SimpleElement : public CustomElement {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CommentItem *m_comment_item;
|
CommentItem *m_comment_item;
|
||||||
|
CommentItem *m_location_item;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ void ElementInfoWidget::updateUi()
|
|||||||
|
|
||||||
//If the current eipw is for label or comment and the text is empty
|
//If the current eipw is for label or comment and the text is empty
|
||||||
//we force the checkbox to ckecked
|
//we force the checkbox to ckecked
|
||||||
if (eipw -> key() == "label" || eipw -> key() == "comment") {
|
if (eipw -> key() == "label" || eipw -> key() == "comment" || eipw -> key() == "location" ) {
|
||||||
if (element_info[eipw->key()].toString().isEmpty())
|
if (element_info[eipw->key()].toString().isEmpty())
|
||||||
eipw->setShow(true);
|
eipw->setShow(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ void ElementSelectorWidget::buildInterface() {
|
|||||||
if (!dc["comment"].toString().isEmpty())
|
if (!dc["comment"].toString().isEmpty())
|
||||||
button_text += dc["comment"].toString();
|
button_text += dc["comment"].toString();
|
||||||
|
|
||||||
|
if (!dc["location"].toString().isEmpty())
|
||||||
|
button_text += dc["location"].toString();
|
||||||
|
|
||||||
if (!button_text.isEmpty())
|
if (!button_text.isEmpty())
|
||||||
button_text += "\n";
|
button_text += "\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user