From 46464a67a6142f292a167aa10d6d318f7a6b2895 Mon Sep 17 00:00:00 2001 From: dfochi Date: Tue, 7 Jun 2016 12:55:05 +0000 Subject: [PATCH] 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 --- sources/bordertitleblock.h | 6 +- sources/diagramcommands.cpp | 3 +- sources/qetdiagrameditor.cpp | 2 +- sources/qetgraphicsitem/commentitem.cpp | 85 ++++++++++++++++++----- sources/qetgraphicsitem/commentitem.h | 5 ++ sources/qetgraphicsitem/crossrefitem.cpp | 20 +++--- sources/qetgraphicsitem/crossrefitem.h | 2 +- sources/qetgraphicsitem/element.cpp | 12 ++++ sources/qetgraphicsitem/masterelement.cpp | 7 +- sources/qetgraphicsitem/simpleelement.cpp | 11 +-- sources/qetgraphicsitem/simpleelement.h | 1 + sources/ui/elementinfowidget.cpp | 2 +- sources/ui/elementselectorwidget.cpp | 3 + 13 files changed, 120 insertions(+), 39 deletions(-) diff --git a/sources/bordertitleblock.h b/sources/bordertitleblock.h index 588985e3c..7d41cb1a5 100644 --- a/sources/bordertitleblock.h +++ b/sources/bordertitleblock.h @@ -97,6 +97,10 @@ class BorderTitleBlock : public QObject QString folio() const { return(btb_folio_); } /// @return the value of the title block "File" field 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 /// @return true si le cartouche est affiche, false sinon @@ -107,8 +111,6 @@ class BorderTitleBlock : public QObject bool rowsAreDisplayed() const { return(display_rows_); } /// @return true si la bordure est affichee, false sinon bool borderIsDisplayed() const { return(display_border_); } - - QString autoPageNum() const { return(btb_auto_page_num_); } // methods to set dimensions void setColumnsCount(int); diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 6b66199da..d782a56cf 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -183,9 +183,10 @@ void PasteDiagramCommand::redo() if (e->texts().size()) e->texts().first()->setPlainText("/"); } 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("comment", ""); + e -> rElementInformations().addValue("location", ""); //Reset the text field tagged "label if (ElementTextItem *eti = e ->taggedText("label")) diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index f6f8eea1e..b72daefc9 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -99,7 +99,7 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) : connect (&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(subWindowActivated(QMdiSubWindow*))); connect (QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slot_updatePasteAction())); connect (&undo_group, SIGNAL(cleanChanged(bool)), this, SLOT(activeUndoStackCleanChanged(bool))); - + readSettings(); show(); diff --git a/sources/qetgraphicsitem/commentitem.cpp b/sources/qetgraphicsitem/commentitem.cpp index e88d5556f..03440b94b 100644 --- a/sources/qetgraphicsitem/commentitem.cpp +++ b/sources/qetgraphicsitem/commentitem.cpp @@ -107,31 +107,78 @@ bool CommentItem::setTextParent() { */ 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) { m_comment = comment; - - QPen pen(Qt::black); - pen.setWidthF (0.5); - - QPainter painter(&m_picture); - 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); - - painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, m_comment); - - text_bounding.adjust(-1,0,1,0); //adjust only for better visual - painter.drawRoundedRect(text_bounding, 2, 2); - - prepareGeometryChange(); - m_bounding_rect = text_bounding; + 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); + pen.setWidthF (0.5); + + painter.setPen (pen); + + QRectF r, text_bounding; + qreal center = boundingRect().center().x(); + + 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 + + m_shape_path.addRect(text_bounding); + prepareGeometryChange(); + m_bounding_rect = m_bounding_rect.united(text_bounding); + if (type == "comment") painter.drawRoundedRect(text_bounding, 2, 2); + painter.restore(); + } +} diff --git a/sources/qetgraphicsitem/commentitem.h b/sources/qetgraphicsitem/commentitem.h index c183831ff..74767f4ea 100644 --- a/sources/qetgraphicsitem/commentitem.h +++ b/sources/qetgraphicsitem/commentitem.h @@ -47,11 +47,16 @@ class CommentItem : public QGraphicsObject virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event ); virtual bool setTextParent (); + private: + void addInfo(QPainter &, QString); + private: Element *m_element; QPicture m_picture; QRectF m_bounding_rect; QString m_comment; + QString m_location; + QPainterPath m_shape_path; bool m_text_parent; }; diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 653c2a092..2f2a1d930 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -203,7 +203,8 @@ void CrossRefItem::updateLabel() { drawHasContacts(qp); } - AddExtraInfo(qp); + AddExtraInfo(qp, "comment"); + AddExtraInfo(qp, "location"); qp.end(); autoPos(); @@ -532,30 +533,33 @@ void CrossRefItem::fillCrossRef(QPainter &painter) { * @brief CrossRefItem::AddExtraInfo * Add the comment info of the parent item if needed. * @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); - bool must_show = m_element -> elementInformations().keyMustShow("comment"); + QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element); + bool must_show = m_element -> elementInformations().keyMustShow(type); - if (!comment.isEmpty() && must_show) + if (!text.isEmpty() && must_show) { painter.save(); painter.setFont(QETApp::diagramTextsFont(6)); QRectF r, text_bounding; qreal center = boundingRect().center().x(); + r = QRectF(QPointF(center - 35, boundingRect().bottom()), 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 m_shape_path.addRect(text_bounding); prepareGeometryChange(); 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(); } } diff --git a/sources/qetgraphicsitem/crossrefitem.h b/sources/qetgraphicsitem/crossrefitem.h index d1737ff38..96d2af370 100644 --- a/sources/qetgraphicsitem/crossrefitem.h +++ b/sources/qetgraphicsitem/crossrefitem.h @@ -83,7 +83,7 @@ class CrossRefItem : public QGraphicsObject void drawHasContacts (QPainter &painter); void drawContact (QPainter &painter, int flags, QString str = QString()); void fillCrossRef (QPainter &painter); - void AddExtraInfo (QPainter &painter); + void AddExtraInfo (QPainter &painter, QString); void setTextParent (); //Attributes diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index dfa07645a..346972484 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -643,6 +643,18 @@ void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { * @param elmt, element to extract variables values */ 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", elmt->diagram() -> border_and_titleblock.folio()); label.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number())); diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index ea073002d..b2b461278 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -161,9 +161,12 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info } else { 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); } } diff --git a/sources/qetgraphicsitem/simpleelement.cpp b/sources/qetgraphicsitem/simpleelement.cpp index 1dcec11ca..fcd9519ed 100644 --- a/sources/qetgraphicsitem/simpleelement.cpp +++ b/sources/qetgraphicsitem/simpleelement.cpp @@ -28,7 +28,8 @@ */ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) : CustomElement(location, qgi, state), - m_comment_item (nullptr) + m_comment_item (nullptr), + m_location_item (nullptr) { link_type_ = Simple; 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")); } - //Comment of element + //Comment and Location of element QString comment = new_info["comment"].toString(); 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); } - 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; m_comment_item = nullptr; } diff --git a/sources/qetgraphicsitem/simpleelement.h b/sources/qetgraphicsitem/simpleelement.h index 6329adb97..d73825ef4 100644 --- a/sources/qetgraphicsitem/simpleelement.h +++ b/sources/qetgraphicsitem/simpleelement.h @@ -45,6 +45,7 @@ class SimpleElement : public CustomElement { private: CommentItem *m_comment_item; + CommentItem *m_location_item; }; diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 7eff46574..a9590a781 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -195,7 +195,7 @@ void ElementInfoWidget::updateUi() //If the current eipw is for label or comment and the text is empty //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()) eipw->setShow(true); } diff --git a/sources/ui/elementselectorwidget.cpp b/sources/ui/elementselectorwidget.cpp index fa925dd60..53148124d 100644 --- a/sources/ui/elementselectorwidget.cpp +++ b/sources/ui/elementselectorwidget.cpp @@ -139,6 +139,9 @@ void ElementSelectorWidget::buildInterface() { if (!dc["comment"].toString().isEmpty()) button_text += dc["comment"].toString(); + if (!dc["location"].toString().isEmpty()) + button_text += dc["location"].toString(); + if (!button_text.isEmpty()) button_text += "\n";