[qet] [4546] Display Location Field in Diagram and assign Folio Variables to Element' s Information Fields |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4546
Author: dfochi
Date: 2016-06-07 14:55:05 +0200 (Tue, 07 Jun 2016)
Log Message:
-----------
Display Location Field in Diagram and assign Folio Variables to Element's Information Fields
Modified Paths:
--------------
trunk/sources/bordertitleblock.h
trunk/sources/diagramcommands.cpp
trunk/sources/qetdiagrameditor.cpp
trunk/sources/qetgraphicsitem/commentitem.cpp
trunk/sources/qetgraphicsitem/commentitem.h
trunk/sources/qetgraphicsitem/crossrefitem.cpp
trunk/sources/qetgraphicsitem/crossrefitem.h
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/masterelement.cpp
trunk/sources/qetgraphicsitem/simpleelement.cpp
trunk/sources/qetgraphicsitem/simpleelement.h
trunk/sources/ui/elementinfowidget.cpp
trunk/sources/ui/elementselectorwidget.cpp
Modified: trunk/sources/bordertitleblock.h
===================================================================
--- trunk/sources/bordertitleblock.h 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/bordertitleblock.h 2016-06-07 12:55:05 UTC (rev 4546)
@@ -97,6 +97,10 @@
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 @@
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);
Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/diagramcommands.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -183,9 +183,10 @@
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"))
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetdiagrameditor.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -99,7 +99,7 @@
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();
Modified: trunk/sources/qetgraphicsitem/commentitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/commentitem.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/commentitem.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -107,31 +107,78 @@
*/
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;
+ 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);
+ pen.setWidthF (0.5);
- QPainter painter(&m_picture);
- painter.setPen (pen);
- painter.setFont (QETApp::diagramTextsFont(6));
+ painter.setPen (pen);
- 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
- painter.drawRoundedRect(text_bounding, 2, 2);
+ m_shape_path.addRect(text_bounding);
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();
}
Modified: trunk/sources/qetgraphicsitem/commentitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/commentitem.h 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/commentitem.h 2016-06-07 12:55:05 UTC (rev 4546)
@@ -48,10 +48,15 @@
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;
};
Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -203,7 +203,8 @@
drawHasContacts(qp);
}
- AddExtraInfo(qp);
+ AddExtraInfo(qp, "comment");
+ AddExtraInfo(qp, "location");
qp.end();
autoPos();
@@ -532,30 +533,33 @@
* @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();
}
}
Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h 2016-06-07 12:55:05 UTC (rev 4546)
@@ -83,7 +83,7 @@
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
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/element.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -643,6 +643,18 @@
* @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()));
Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -161,9 +161,12 @@
}
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);
}
}
Modified: trunk/sources/qetgraphicsitem/simpleelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/simpleelement.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -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 @@
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;
}
Modified: trunk/sources/qetgraphicsitem/simpleelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.h 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/qetgraphicsitem/simpleelement.h 2016-06-07 12:55:05 UTC (rev 4546)
@@ -45,6 +45,7 @@
private:
CommentItem *m_comment_item;
+ CommentItem *m_location_item;
};
Modified: trunk/sources/ui/elementinfowidget.cpp
===================================================================
--- trunk/sources/ui/elementinfowidget.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/ui/elementinfowidget.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -195,7 +195,7 @@
//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);
}
Modified: trunk/sources/ui/elementselectorwidget.cpp
===================================================================
--- trunk/sources/ui/elementselectorwidget.cpp 2016-06-07 11:07:34 UTC (rev 4545)
+++ trunk/sources/ui/elementselectorwidget.cpp 2016-06-07 12:55:05 UTC (rev 4546)
@@ -139,6 +139,9 @@
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";