mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02: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:
parent
b4b63446c7
commit
46464a67a6
@ -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);
|
||||
|
@ -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"))
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ class SimpleElement : public CustomElement {
|
||||
|
||||
private:
|
||||
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
|
||||
//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);
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user